{"id":204,"date":"2008-11-18T21:11:58","date_gmt":"2008-11-19T05:11:58","guid":{"rendered":"http:\/\/jaredrobinson.com\/blog\/?p=204"},"modified":"2009-07-11T04:01:15","modified_gmt":"2009-07-11T04:01:15","slug":"using-the-2626-linux-kernel-debugger-kgdb-with-vmware","status":"publish","type":"post","link":"https:\/\/jaredrobinson.com\/blog\/using-the-2626-linux-kernel-debugger-kgdb-with-vmware\/","title":{"rendered":"Using the 2.6.26 Linux Kernel Debugger (KGDB) with VMware"},"content":{"rendered":"<p>Reading the linux kernel documentation on KGDB wasn&#8217;t enough for me to be able<br \/>\nto use the newly built-in KGDB kernel debugger with version 2.6.26 or 2.6.27.<br \/>\nThe breakthrough for me was reading [part of Jason Wessel&#8217;s<br \/>\nguide](http:\/\/www.kernel.org\/pub\/linux\/kernel\/people\/jwessel\/kgdb\/ch03s03.html).<\/p>\n<p>I have two machines:<\/p>\n<p>*  developer &#8211; where I run gdb<br \/>\n*  target &#8211; where the kernel is being debugged, running in VMware<\/p>\n<p>Configure VMware on the developer machine<\/p>\n<p>* Power down the guest (target)<br \/>\n* Edit the VM guest settings<br \/>\n* Add a serial port<br \/>\n  * Use named pipe `\/tmp\/com_1` (it&#8217;s really a UNIX domain socket)<br \/>\n  * Configure it to &#8220;Yield CPU on poll&#8221; (under Advanced)<br \/>\n* Install &#8216;socat&#8217;, if not already installed<\/p>\n<p>Configure and Compile the kernel on the developer or the target machine<\/p>\n<p>&#8211; Get kernel 2.6.26 or newer<br \/>\n&#8211; `make menuconfig` # or make gconfig<br \/>\n&#8211; Under Kernel Hacking:<br \/>\n  &#8211; enable KGDB<br \/>\n  &#8211; enable the Magic SysRq key<br \/>\n  &#8211; enable &#8220;Compile the kernel with debug info&#8221;<br \/>\n&#8211; Build kernel: `make`<\/p>\n<p>Configure target<\/p>\n<p>&#8211; Enable Magic SysRq key on target:<br \/>\n  &#8211; Edit \/etc\/sysctl.conf and set `kernel.sysrq = 1`<br \/>\n  &#8211; or run `sysctl -w kernel.sysrq=1` # this doesn&#8217;t survive a reboot<br \/>\n&#8211; Install developer kernel<br \/>\n  &#8211; On the developer machine:<br \/>\n    `rsync -av &#8211;exclude .git .\/ root@target.host.name:\/mnt\/work\/linux-2.6.26`<br \/>\n  &#8211; On the target, a RedHat based system:<br \/>\n     `make install`<br \/>\n     `make modules_install`<br \/>\n&#8211; Edit \/boot\/grub\/grub.conf and set `timeout=15`<br \/>\n&#8211; Boot into the newly installed kernel<\/p>\n<p>Start debugging<\/p>\n<p>&#8211; On target:<br \/>\n  `echo ttyS0 > \/sys\/module\/kgdboc\/parameters\/kgdboc`<br \/>\n&#8211; On developer:<br \/>\n  `socat -d -d \/tmp\/com_1 PTY:`   # notice what pty is allocated &#8212; \/dev\/pts\/1 in my case<br \/>\n  `gdb vmlinux`<br \/>\n    `set remotebaud 115200`<br \/>\n    `target remote \/dev\/pts\/1`<br \/>\n&#8211; On target, do one of the following:<br \/>\n  &#8211; `echo &#8220;g&#8221; > \/proc\/sysrq-trigger`<br \/>\n  &#8211; Type ALT-SysRq-G<br \/>\n&#8211; Ready, get set, go! Go back to developer machine and use gdb to set<br \/>\n  breakpoints, continue, etc.<\/p>\n<p>I set up debugging because I wanted to understand the behavior of the kernel<br \/>\nwhen loading a module. It turns out that loading of the module failed because<br \/>\nsitting in a debugger delayed the execution, causing a timeout in module load<br \/>\nby the time I stepped through the code.  Use of printk turned out to work<br \/>\nbetter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reading the linux kernel documentation on KGDB wasn&#8217;t enough for me to be able to use the newly built-in KGDB kernel debugger with version 2.6.26 or 2.6.27. The breakthrough for me was reading [part of Jason Wessel&#8217;s guide](http:\/\/www.kernel.org\/pub\/linux\/kernel\/people\/jwessel\/kgdb\/ch03s03.html). I have two machines: * developer &#8211; where I run gdb * target &#8211; where the kernel &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/jaredrobinson.com\/blog\/using-the-2626-linux-kernel-debugger-kgdb-with-vmware\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Using the 2.6.26 Linux Kernel Debugger (KGDB) with VMware&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,17],"tags":[],"class_list":["post-204","post","type-post","status-publish","format-standard","hentry","category-linux","category-programming","category-tech"],"_links":{"self":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/comments?post=204"}],"version-history":[{"count":9,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/204\/revisions"}],"predecessor-version":[{"id":353,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/posts\/204\/revisions\/353"}],"wp:attachment":[{"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/media?parent=204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/categories?post=204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaredrobinson.com\/blog\/wp-json\/wp\/v2\/tags?post=204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}