How to debug Xorg with gdb
Our internal Xorg SUN is a patched soruce tree from open source community. So it is better to debug it with GNU tool, ie., gdb. As the usual, we should compile the source files with debug information first. Some kind of trick is used here. Let's give a example as the following, we like to know what is going on with the Intel video driver. The driver may have some dependency on other modules, so we build the full Xorg tree first. As a result, we get a compiled Xorg source tree without debug information. Under the directory "open-src/driver/xf86-video-intel", "make clean & make debug" command will give you a Intel driver with debug information. Let's have a look why you can do this. There is a "Makefile" "open-src/driver/xf86-video-intel which depends on "../Makefile.inc", and "../Makefile.inc" itself depends on "../../common/Makefile". A debug target is defined in "../../common/Makefile".
After install the new object file into target system, we can start our adventure now. If you do not tell it, GDB does not know where the source files are located. I prefer to write the source path in ".gdbinit" just as the B-shell search in path "bashrc".
-bash /usr/X11/bin/Xorg
(gdb) file /usr/X11/bin/Xorg
(gdb) file /usr/X11/bin/Xorg
Load new symbol table from "/usr/X11/bin/Xorg"? (y or n)
Reading symbols from /usr/X11/bin/Xorg...done.
(gdb) break i830_dri.c:I830DRIScreenInit
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (i830_dri.c:I830DRIScreenInit) pending.
(gdb)
Fourtunately, "defered breakpoints" is supported by gdb, so we can set the breakpoint on the share library which haven't been loaded yet.
Which compiler are you using? GCC? Does gdb support the debug info provided by SunStudio compiler?
Posted by Yong Sun on December 19, 2007 at 01:20 PM CST #