aboutsummaryrefslogtreecommitdiff
path: root/en_US.ISO8859-1/books/developers-handbook/kerneldebug/chapter.sgml
diff options
context:
space:
mode:
authorDag-Erling Smørgrav <des@FreeBSD.org>2000-11-15 12:40:05 +0000
committerDag-Erling Smørgrav <des@FreeBSD.org>2000-11-15 12:40:05 +0000
commita43d4233cad387781b85ced3e20c226ce643ddf7 (patch)
treeadbd7d3383cd1554cea0cc6558a7694cb6d117e5 /en_US.ISO8859-1/books/developers-handbook/kerneldebug/chapter.sgml
parentb964e8e3e053e7701fb5f7b11701265a7eef7048 (diff)
downloaddoc-a43d4233cad387781b85ced3e20c226ce643ddf7.tar.gz
doc-a43d4233cad387781b85ced3e20c226ce643ddf7.zip
Update the description of how to load modules in gdb, and separate it from
the section on remote debugging since it also applies to crash dumps. Thanks to grog for his gdb macros, which pointed me in the right direction. Reviewed by: nik
Notes
Notes: svn path=/head/; revision=8368
Diffstat (limited to 'en_US.ISO8859-1/books/developers-handbook/kerneldebug/chapter.sgml')
-rw-r--r--en_US.ISO8859-1/books/developers-handbook/kerneldebug/chapter.sgml81
1 files changed, 59 insertions, 22 deletions
diff --git a/en_US.ISO8859-1/books/developers-handbook/kerneldebug/chapter.sgml b/en_US.ISO8859-1/books/developers-handbook/kerneldebug/chapter.sgml
index 4cf1b19f75..70efe283f2 100644
--- a/en_US.ISO8859-1/books/developers-handbook/kerneldebug/chapter.sgml
+++ b/en_US.ISO8859-1/books/developers-handbook/kerneldebug/chapter.sgml
@@ -1,7 +1,7 @@
<!--
The FreeBSD Documentation Project
- $FreeBSD: doc/en_US.ISO_8859-1/books/handbook/kerneldebug/chapter.sgml,v 1.25 2000/07/14 21:57:34 ben Exp $
+ $FreeBSD: doc/en_US.ISO_8859-1/books/handbook/kerneldebug/chapter.sgml,v 1.26 2000/11/07 09:08:11 jkoshy Exp $
-->
<chapter id="kerneldebug">
@@ -554,33 +554,70 @@ Debugger (msg=0xf01b0383 "Boot flags requested debugger")
full access to the source, running it in gud-mode inside an Emacs window
(which gives you an automatic source code display in another Emacs
window) etc.</para>
+ </sect1>
+
+ <sect1>
+ <title>Debugging Loadable Modules Using GDB</title>
- <para>Remote GDB can also be used to debug LKMs. First build the LKM with
- debugging symbols:</para>
+ <para>When debugging a panic that occurred within a module, or
+ using remote GDB against a machine that uses dynamic modules,
+ you need to tell GDB how to obtain symbol information for those
+ modules.</para>
- <screen>&prompt.root; <userinput>cd /usr/src/lkm/linux</userinput>
+ <para>First, you need to build the module(s) with debugging
+ information:</para>
+
+ <screen>&prompt.root; <userinput>cd /sys/modules/linux</userinput>
&prompt.root; <userinput>make clean; make COPTS=-g</userinput></screen>
- <para>Then install this version of the module on the target machine, load
- it and use <command>modstat</command> to find out where it was
- loaded:</para>
-
- <screen>&prompt.root; <userinput>linux</userinput>
-&prompt.root; <userinput>modstat</userinput>
-Type Id Off Loadaddr Size Info Rev Module Name
-EXEC 0 4 f5109000 001c f510f010 1 linux_mod</screen>
-
- <para>Take the load address of the module and add 0x20 (probably to
- account for the a.out header). This is the address that the module code
- was relocated to. Use the <command>add-symbol-file</command> command in
- GDB to tell the debugger about the module:</para>
-
- <screen><prompt>(kgdb)</prompt> <userinput>add-symbol-file /usr/src/lkm/linux/linux_mod.o 0xf5109020</userinput>
-add symbol table from file "/usr/src/lkm/linux/linux_mod.o" at
-text_addr = 0xf5109020? (y or n) <userinput>y</userinput>
+ <para>If you are using remote GDB, you can run
+ <command>kldstat</command> on the target machine to find out
+ where the module was loaded:</para>
+
+ <screen>&prompt.root; <userinput>kldstat</userinput>
+Id Refs Address Size Name
+ 1 4 0xc0100000 1c1678 kernel
+ 2 1 0xc0a9e000 6000 linprocfs.ko
+ 3 1 0xc0ad7000 2000 warp_saver.ko
+ 4 1 0xc0adc000 11000 linux.ko
+</screen>
+
+ <para>If you are debugging a crash dump, you'll need to walk the
+ <literal>linker_files</literal> list, starting at
+ <literal>linker_files->tqh_first</literal> and following the
+ <literal>link.tqe_next</literal> pointers until you find the
+ entry with the <literal>filename</literal> you are looking for.
+ The <literal>address</literal> member of that entry is the load
+ address of the module.</para>
+
+ <para>Next, you need to find out the offset of the text section
+ within the module:</para>
+
+ <screen>&prompt.root; <userinput>objdump --section-headers /sys/modules/linux/linux.ko | grep text</userinput>
+ 3 .rel.text 000016e0 000038e0 000038e0 000038e0 2**2
+ 10 .text 00007f34 000062d0 000062d0 000062d0 2**2</screen>
+
+ <para>The one you want is the <literal>.text</literal> section,
+ section 10 in the above example. The fourth numerical field
+ (sixth field overall) is the offset in hex of the text section
+ within the file (0x62d0 in our example). Add this to the load
+ address reported by <command>kldstat</command> to obtain the
+ address of the module text in memory.</para>
+
+ <para>Take the load address of the module (as reported by
+ <command>kldstat</command>) and add the offset of the text
+ section within the module (0x62d0 + 0xc0adc000 = c0ae22d0 in our
+ example). This is the address that the module code was
+ relocated to. Use the <command>add-symbol-file</command>
+ command in GDB to tell the debugger about the module:</para>
+
+ <screen><prompt>(kgdb)</prompt> <userinput>add-symbol-file /sys/modules/linux/linux.ko 0xc0ae22d0</userinput>
+add symbol table from file "/sys/modules/linux/linux.ko" at text_addr = 0xc0ae22d0?
+(y or n) <userinput>y</userinput>
+Reading symbols from /sys/modules/linux/linux.ko...done.
<prompt>(kgdb)</prompt></screen>
- <para>You now have access to all the symbols in the LKM.</para>
+ <para>You now have access to all the symbols in the module.</para>
</sect1>
<sect1>