Debugging in UML
User-Mode-Linux is a blessing for file system developers. Have been using it quiet some time now. But lately, for some reason breakpoints won't work in gdb. The execution just didn't stop at the breakpoints. I figured an alternate way to make the execution stop. Let me document it before I forget this again ;) It works like this:
Above commands tells gdb to pass the SIGUSR1 signal to the program but don't pass SIGTRAP. SIGUSR1 is used by UML internally. Recall that, SIGTRAP signal is used by the debugger to stop at various execution points in the program that is being debugged. So we don't want this signal to be passed to the program. After this, simply run the program, assuming that you want to have a breakpoint later in the program.
When you want to have a breakpoint to be placed, signal INT to the debugged program, vmlinux is this case. This can be done by firing up another terminal and giving following command:
where <PID> is pid of first vmlinux process running (there are usually multiple vmlinux process spawned by UML). With this gdb will give you a prompt where you can set up a break point, e.g.:
And continue executing. Execution will stop at the set breakpoint.
If you want to have breakpoints right while the kernel boots, pass the INT signal as soon as you run the program in gdb.
$ gdb ./vmlinux
(gdb) handle SIGUSR1 pass nostop noprint
(gdb) handle SIGTRAP nostop noprint
(gdb) run
Above commands tells gdb to pass the SIGUSR1 signal to the program but don't pass SIGTRAP. SIGUSR1 is used by UML internally. Recall that, SIGTRAP signal is used by the debugger to stop at various execution points in the program that is being debugged. So we don't want this signal to be passed to the program. After this, simply run the program, assuming that you want to have a breakpoint later in the program.
When you want to have a breakpoint to be placed, signal INT to the debugged program, vmlinux is this case. This can be done by firing up another terminal and giving following command:
(gdb) kill -INT <PID>
where <PID> is pid of first vmlinux process running (there are usually multiple vmlinux process spawned by UML). With this gdb will give you a prompt where you can set up a break point, e.g.:
(gdb) b ext2_fill_super
(gdb) continue
And continue executing. Execution will stop at the set breakpoint.
If you want to have breakpoints right while the kernel boots, pass the INT signal as soon as you run the program in gdb.