KDB

From eLinux.org
Revision as of 02:39, 23 June 2011 by Tim Bird (Talk | contribs)

Jump to: navigation, search

Introduction and basic resources

Here is some information about KDB - the in-kernel debugger for the Linux kernel.

The KDB and KGDB official wiki: https://kgdb.wiki.kernel.org/

Jason Wessel is the current KDB maintainer. Here is a presentation from him at LinuxCon 2010 (August 2010): http://kernel.org/pub/linux/kernel/people/jwessel/dbg_webinar/State_Of_kernel_debugging_LinuxCon2010.pdf

Here are some videos showing use of KDB and KGDB:

Documentation, up-to-date as of 2010, for KDB and KGDB is at: http://kernel.org/pub/linux/kernel/people/jwessel/kdb/

Older Information

See http://www.ibm.com/developerworks/linux/library/l-kdbug/ for a tutorial for the 2.4.20 kernel (from June 2003)

Here's an article from 2002 on KDB vs. KGDB: http://kerneltrap.org/node/112 It has a good discussion excerpt between Andrew Morton and Keith Owens about the relative merits of KDB versus KGDB.

Questions

Here are some questions to answer:

  • What kernel versions are supported?
    • 2.6.35 and on
  • what kernel configs are required to be set?
    • see below
  • how to invoke the debugger?
    • sysrq trigger ('echo g >/proc/sysrq-trigger')
    • sysrq serial console combo (in minicom, ctrl-a f g (quickly))
    • panic
    • breakpoint

Kernel configuration

The following descriptions are for a 2.6.35 kernel, using KDB over a serial line between host and target:

All these options on are the "Kernel Hacking" menu.

In order to support KDB, "KGDB" support must be turned on first (even if you aren't using kgdb/gdb)

  • CONFIG_DEBUG_KERNEL=y - includes debug information in the kernel compilation - required for basic kernel debugging support
  • CONFIG_KGDB=Y - turn on basic kernel debug agent support
  • CONFIG_KGDB_SERIAL_CONSOLE=Y - to share a serial console with kgdb.
    • Sysrq-g must be used to break in initially.
    • Selecting this will automatically set:
      • CONFIG_CONSOLE_POLL=N
      • CONFIG_MAGIC_SYSRQ=Y - turn on MAGIC-SYSRQ key support
  • CONFIG_KGDB_KDB=Y - actually turn on the KDB debugger feature

Optional other configuration settings:

  • CONFIG_FRAME_POINTER=Y - this allows for better backtrace support in KDB
  • CONFIG_DEBUG_RODATA=N - disable this in order to support hardware breakpoints on data accesses
  • CONFIG_KALLSYMS=Y - this adds symbolic information to the kernel, useful to see symbols instead of addresses
  • CONFIG_KDB_KEYBOARD - use KDB with an attached keyboard (not for use with serial console)
  • CONFIG_KGDB_TESTS - used to turn on kgdb internal self-tests - see the config help for this for more information

Using gdb to see the kernel source listing

KDB environment variables

  • LINES - set the number of lines for paging output from KDB
{"cc_re__cc_re__cc_by_sa_3_0": ["i>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<li id=\"t-permalink\"><a href=\"/index.php?title=KDB&amp;oldid=52447\" title=\"Permanent link to this revision of the page\">Permanent link</a></li>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<li id=\"t-info\"><a href=\"/index.php?title=KDB&amp;action=info\" title=\"More information about this page\">Page information</a></li>\n\t\t\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t</div>\n\t\t</div>\n\t\t\t\t</div>\n\t\t</div>\n\t\t<div id=\"footer\" role=\"contentinfo\">\n\t\t\t\t\t\t\t<ul id=\"footer-info\">\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-info-copyright\">Content is available under <a class=\"external\" rel=\"nofollow\" href=\"http://creativecommons.org/licenses/by-sa/3.0/\">a Creative Commons Attribution-ShareAlike 3.0 Unported License</a> unless otherwise noted.</li>\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t<ul id=\"footer-places\">\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-privacy\"><a href=\"/eLinux.org:Privacy_policy\" title=\"eLinux.org:Privacy policy\">Privacy policy</a></li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-about\"><a href=\"/eLinux.org:About\" title=\"eLinux.org:About\">About eLinux.org</a></li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-disclaimer\"><a href=\"/eLinux.org:General_disclaimer\" title=\"eLinux.or", "oter-places-privacy\"><a href=\"/eLinux.org:Privacy_policy\" title=\"eLinux.org:Privacy policy\">Privacy policy</a></li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-about\"><a href=\"/eLinux.org:About\" title=\"eLinux.org:About\">About eLinux.org</a></li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-places-disclaimer\"><a href=\"/eLinux.org:General_disclaimer\" title=\"eLinux.org:General disclaimer\">Disclaimers</a></li>\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t\t\t\t\t<ul id=\"footer-icons\" class=\"noprint\">\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-copyrightico\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"http://creativecommons.org/licenses/by-sa/3.0/\"><img src=\"http://i.creativecommons.org/l/by-sa/3.0/88x31.png\" alt=\"a Creative Commons Attribution-ShareAlike 3.0 Unported License\" width=\"88\" height=\"31\" /></a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t\t\t<li id=\"footer-poweredbyico\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"//www.mediawiki.org/\"><img src=\"/resources/assets/poweredby_mediawiki_88x31.png\" alt=\"Powered by MediaWiki\" width=\"88\" height=\"31\" /></a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t</li>\n\t\t\t\t\t\t\t\t\t</ul>\n\t\t\t\t\t\t<div style=\"clear:both\"></div>\n\t\t</div>\n\t\t<script>/*<![CDATA[*/window.jQuery "], "copyright__copyright__copyright": ["", "ort hardware breakpoints on data accesses\n  \u2022 CONFIG_KALLSYMS=Y - this adds symbolic information to the kernel, useful to see symbols instead of addresses\n  \u2022 CONFIG_KDB_KEYBOARD - use KDB with an attached keyboard (not for use with serial console)\n  \u2022 CONFIG_KGDB_TESTS - used to turn on kgdb internal self-tests - see the config help for this for more information\n\nUsing gdb to see the kernel source listing\n\nKDB environment variables\n\n  \u2022 LINES - set the number of lines for paging output from KDB", "ort hardware breakpoints on data accesses\n  \u2022 CONFIG_KALLSYMS=Y - this adds symbolic information to the kernel, useful to see symbols instead of addresses\n  \u2022 CONFIG_KDB_KEYBOARD - use KDB with an attached keyboard (not for use with serial console)\n  \u2022 CONFIG_KGDB_TESTS - used to turn on kgdb internal self-tests - see the config help for this for more information\n\nUsing gdb to see the kernel source listing\n\nKDB environment variables\n\n  \u2022 LINES - set the number of lines for paging output from KDB"]}