Topic: GDB and UML (mostly works) by Philip Ries Posted 3/31/2008 11:25:34 PM I figured out how to get GDB to debug UML, mostly based on this page: http://user-mode-linux.sourceforge.net/hacking.html After you've started UML linux, look in your home folder for the ~/.uml directory. One of its subdirectories will have the pid you want--it seems to be a directory that changes rather every time rather than the one(s) that stick around after you run UML. You can just try them out. Run 'gdb linux ' (in another terminal)-- this should cause UML to hang while it's waiting for you to "continue" in GDB. Set any breakpoints, then continue. You can get the GDB prompt back by pressing Ctrl+C in GDB (UML will hang again while it waits). So you don't have to get the right breakpoint the first time. I noticed the code jumped around a bit when stepping (as Rob was describing in an earlier thread), so I changed my UML Makefile to limit the optimizations. To do that, I deleted "-O2" from HOSTCFLAGS and HOSTCXXFLAGS. I ran a 'make clean ARCH=um' after that, though it may not be necessary. When I did this the first time, my compilation got an error on mm/slab.c. Something weird is going on there, and I #defined away the function calls that weren't linking (it's like they were intended to be optimized out). Everything seems to be running OK with this modification. GDB hasn't missed a breakpoint so far, to my knowledge. The variables are viewable, although sometimes one will give me "optimized out"--only to later appear correctly. The only real annoyance is that it doesn't deal with macros/inlines well--they will cause GDB to jump to other files inside one function. If it helps: my UML is running at SKAS3. My .config has CONFIG_CC_OPTIMIZE_FOR_SIZE=n (in addition to the plain debug options). P.S. If you need to debug something near initialization, I read that it helps to add init=/bin/sh to UML's command-line args so you can attach with GDB before the bootup passes what you're looking for.