Tuesday, July 26, 2016

The Beauty of Strace

Strace is a diagnostic, debugging and instructional user-space utility for Linux. It is used to monitor interactions between processes and the Linux kernel, which include system calls, signal deliveries, and changes of process state.

The following is an example of typical output of the strace command:

ioctl(13, DRM_IOCTL_TEGRA_GEM_MMAP, 0x7ffd5182d670) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_SHARED, 13, 0x137e48000) = 0x7f83d5cba000
munmap(0x7f83d5cba000, 8192)            = 0
ioctl(13, _IOC(_IOC_READ|_IOC_WRITE, 0x64, 0x43, 0x18), 0x7ffd5182d640) = 0
ioctl(13, _IOC(_IOC_READ|_IOC_WRITE, 0x64, 0x49, 0x20), 0x7ffd5182d630) = 0
ioctl(13, _IOC(_IOC_READ|_IOC_WRITE, 0x64, 0x44, 0x18), 0x7ffd5182d620) = 0
ioctl(13, _IOC(_IOC_READ|_IOC_WRITE, 0x64, 0x43, 0x18), 0x7ffd5182d670) = 0
write(10, "\0", 1)                      = 1
futex(0x5590ec432890, FUTEX_WAKE_PRIVATE, 1) = 1
write(10, "\0", 1)                      = 1
futex(0x5590ec432890, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x5590ec418784, FUTEX_CMP_REQUEUE_PRIVATE, 1, 2147483647, 0x5590ec418758, 52) = 1

user space hang issues can be analysed using Strace.

Strace will give detailed info about which modules get loaded for running the program.

Missing modules and libraries can be easily fixed with Strace.

Futext wait issues can be analysed using Strace.

How to do Strace:

$ strace  glxgears

$ strace  mpv --hwdec=vdpau -vo vdpau "filename"

$ strace -f  mpv "filename"

$ strace -p pid

$strace -f -p pid

-f = Trace child processes

For  Help:

$ man strace

# strace  -h

To get pid's of multiple threads running in a common process 

$ ps -efL | grep mpv (process name)


How to get call stack using gdb for all threads:

$ gdb -p <process pid>

(gdb) thread apply all bt    =>  gives all threads call stack under attached process.

Wednesday, July 20, 2016

Debugging SUSPEND / RESUME issues on Linux

This blog contains most of the information for suspend resume issues :
https://01.org/blogs/rzhang/2015/best-practice-debug-linux-suspend/hibernate-issues

Some more information: