In this new post series, I’ll show you how both existing and ad-hoc tools can be helpful to find the root cause of some problems. Here are also the older posts of this series in case you find them useful:
- GStreamer WebKit debugging tricks using GDB (1/2)
- GStreamer WebKit debugging tricks using GDB (2/2)
- GStreamer WebKit debugging by instrumenting source code (1/3)
- GStreamer WebKit debugging by instrumenting source code (2/3)
- GStreamer WebKit debugging by instrumenting source code (3/3)
Use strace to know which config/library files are used by a program
If you’re becoming crazy supposing that the program should use some config and it seems to ignore it, just use strace to check what config files, libraries or other kind of files is the program actually using. Use the grep rules you need to refine the search:
$ strace -f -e trace=%file nano 2> >(grep 'nanorc') access("/etc/nanorc", R_OK) = 0 access("/usr/share/nano/javascript.nanorc", R_OK) = 0 access("/usr/share/nano/gentoo.nanorc", R_OK) = 0 ...
Know which process is killing another one
First, try to strace -e trace=signal -p 1234
the killed process.
If that doesn’t work (eg: because it’s being killed with the uncatchable SIGKILL signal), then you can resort to modifying the kernel source code (signal.c) to log the calls to kill()
:
SYSCALL_DEFINE2(kill, pid_t, pid, int, sig) { struct task_struct *tsk_p; ... /* Log SIGKILL */ if (sig & 0x1F == 9) { tsk_p = find_task_by_vpid(pid); if (tsk_p) { printk(KERN_DEBUG "Sig: %d from pid: %d (%s) to pid: %d (%s)\n", sig, current->pid, current->comm, pid, tsk_p->comm); } else { printk(KERN_DEBUG "Sig: %d from pid: %d (%s) to pid: %d\n", sig, current->pid, current->comm, pid); } } ... }
Wrap gcc/ld/make to tweak build parameters
If you ever find yourself with little time in front of a stubborn build system and, no matter what you try, you can’t get the right flags to the compiler, think about putting something (a wrapper) between the build system and the compiler. Example for g++
:
#!/bin/bash main() { # Build up arg[] array with all options to be passed # to subcommand. i=0 for opt in "$@"; do case "$opt" in -O2) ;; # Removes this option *) arg[i]="$opt" # Keeps the others i=$((i+1)) ;; esac done EXTRA_FLAGS="-O0" # Adds extra option echo "g++ ${EXTRA_FLAGS} ${arg[@]}" # >> /tmp/build.log # Logs the command /usr/bin/ccache g++ ${EXTRA_FLAGS} "${arg[@]}" # Runs the command } main "$@"
Make sure that the wrappers appear earlier than the real commands in your PATH.
The make
wrapper can also call remake
instead. Remake is fully compatible with make but has features to help debugging compilation and makefile errors.
Analyze the structure of MP4 data
The ISOBMFF Box Structure Viewer online tool allows you to upload an MP4 file and explore its structure.