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 @@ @@ -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. + + + + Debugging Loadable Modules Using GDB - Remote GDB can also be used to debug LKMs. First build the LKM with - debugging symbols: + 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. - &prompt.root; cd /usr/src/lkm/linux + First, you need to build the module(s) with debugging + information: + + &prompt.root; cd /sys/modules/linux &prompt.root; make clean; make COPTS=-g - Then install this version of the module on the target machine, load - it and use modstat to find out where it was - loaded: + If you are using remote GDB, you can run + kldstat on the target machine to find out + where the module was loaded: - &prompt.root; linux -&prompt.root; modstat -Type Id Off Loadaddr Size Info Rev Module Name -EXEC 0 4 f5109000 001c f510f010 1 linux_mod - - 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 add-symbol-file command in - GDB to tell the debugger about the module: + &prompt.root; kldstat +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 + - (kgdb) add-symbol-file /usr/src/lkm/linux/linux_mod.o 0xf5109020 -add symbol table from file "/usr/src/lkm/linux/linux_mod.o" at -text_addr = 0xf5109020? (y or n) y + If you are debugging a crash dump, you'll need to walk the + linker_files list, starting at + linker_files->tqh_first and following the + link.tqe_next pointers until you find the + entry with the filename you are looking for. + The address member of that entry is the load + address of the module. + + Next, you need to find out the offset of the text section + within the module: + + &prompt.root; objdump --section-headers /sys/modules/linux/linux.ko | grep text + 3 .rel.text 000016e0 000038e0 000038e0 000038e0 2**2 + 10 .text 00007f34 000062d0 000062d0 000062d0 2**2 + + The one you want is the .text 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 kldstat to obtain the + address of the module text in memory. + + Take the load address of the module (as reported by + kldstat) 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 add-symbol-file + command in GDB to tell the debugger about the module: + + (kgdb) add-symbol-file /sys/modules/linux/linux.ko 0xc0ae22d0 +add symbol table from file "/sys/modules/linux/linux.ko" at text_addr = 0xc0ae22d0? +(y or n) y +Reading symbols from /sys/modules/linux/linux.ko...done. (kgdb) - You now have access to all the symbols in the LKM. + You now have access to all the symbols in the module. diff --git a/en_US.ISO8859-1/books/handbook/kerneldebug/chapter.sgml b/en_US.ISO8859-1/books/handbook/kerneldebug/chapter.sgml index 4cf1b19f75..70efe283f2 100644 --- a/en_US.ISO8859-1/books/handbook/kerneldebug/chapter.sgml +++ b/en_US.ISO8859-1/books/handbook/kerneldebug/chapter.sgml @@ -1,7 +1,7 @@ @@ -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. + + + + Debugging Loadable Modules Using GDB - Remote GDB can also be used to debug LKMs. First build the LKM with - debugging symbols: + 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. - &prompt.root; cd /usr/src/lkm/linux + First, you need to build the module(s) with debugging + information: + + &prompt.root; cd /sys/modules/linux &prompt.root; make clean; make COPTS=-g - Then install this version of the module on the target machine, load - it and use modstat to find out where it was - loaded: + If you are using remote GDB, you can run + kldstat on the target machine to find out + where the module was loaded: - &prompt.root; linux -&prompt.root; modstat -Type Id Off Loadaddr Size Info Rev Module Name -EXEC 0 4 f5109000 001c f510f010 1 linux_mod - - 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 add-symbol-file command in - GDB to tell the debugger about the module: + &prompt.root; kldstat +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 + - (kgdb) add-symbol-file /usr/src/lkm/linux/linux_mod.o 0xf5109020 -add symbol table from file "/usr/src/lkm/linux/linux_mod.o" at -text_addr = 0xf5109020? (y or n) y + If you are debugging a crash dump, you'll need to walk the + linker_files list, starting at + linker_files->tqh_first and following the + link.tqe_next pointers until you find the + entry with the filename you are looking for. + The address member of that entry is the load + address of the module. + + Next, you need to find out the offset of the text section + within the module: + + &prompt.root; objdump --section-headers /sys/modules/linux/linux.ko | grep text + 3 .rel.text 000016e0 000038e0 000038e0 000038e0 2**2 + 10 .text 00007f34 000062d0 000062d0 000062d0 2**2 + + The one you want is the .text 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 kldstat to obtain the + address of the module text in memory. + + Take the load address of the module (as reported by + kldstat) 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 add-symbol-file + command in GDB to tell the debugger about the module: + + (kgdb) add-symbol-file /sys/modules/linux/linux.ko 0xc0ae22d0 +add symbol table from file "/sys/modules/linux/linux.ko" at text_addr = 0xc0ae22d0? +(y or n) y +Reading symbols from /sys/modules/linux/linux.ko...done. (kgdb) - You now have access to all the symbols in the LKM. + You now have access to all the symbols in the module. diff --git a/en_US.ISO_8859-1/books/handbook/kerneldebug/chapter.sgml b/en_US.ISO_8859-1/books/handbook/kerneldebug/chapter.sgml index 4cf1b19f75..70efe283f2 100644 --- a/en_US.ISO_8859-1/books/handbook/kerneldebug/chapter.sgml +++ b/en_US.ISO_8859-1/books/handbook/kerneldebug/chapter.sgml @@ -1,7 +1,7 @@ @@ -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. + + + + Debugging Loadable Modules Using GDB - Remote GDB can also be used to debug LKMs. First build the LKM with - debugging symbols: + 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. - &prompt.root; cd /usr/src/lkm/linux + First, you need to build the module(s) with debugging + information: + + &prompt.root; cd /sys/modules/linux &prompt.root; make clean; make COPTS=-g - Then install this version of the module on the target machine, load - it and use modstat to find out where it was - loaded: + If you are using remote GDB, you can run + kldstat on the target machine to find out + where the module was loaded: - &prompt.root; linux -&prompt.root; modstat -Type Id Off Loadaddr Size Info Rev Module Name -EXEC 0 4 f5109000 001c f510f010 1 linux_mod - - 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 add-symbol-file command in - GDB to tell the debugger about the module: + &prompt.root; kldstat +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 + - (kgdb) add-symbol-file /usr/src/lkm/linux/linux_mod.o 0xf5109020 -add symbol table from file "/usr/src/lkm/linux/linux_mod.o" at -text_addr = 0xf5109020? (y or n) y + If you are debugging a crash dump, you'll need to walk the + linker_files list, starting at + linker_files->tqh_first and following the + link.tqe_next pointers until you find the + entry with the filename you are looking for. + The address member of that entry is the load + address of the module. + + Next, you need to find out the offset of the text section + within the module: + + &prompt.root; objdump --section-headers /sys/modules/linux/linux.ko | grep text + 3 .rel.text 000016e0 000038e0 000038e0 000038e0 2**2 + 10 .text 00007f34 000062d0 000062d0 000062d0 2**2 + + The one you want is the .text 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 kldstat to obtain the + address of the module text in memory. + + Take the load address of the module (as reported by + kldstat) 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 add-symbol-file + command in GDB to tell the debugger about the module: + + (kgdb) add-symbol-file /sys/modules/linux/linux.ko 0xc0ae22d0 +add symbol table from file "/sys/modules/linux/linux.ko" at text_addr = 0xc0ae22d0? +(y or n) y +Reading symbols from /sys/modules/linux/linux.ko...done. (kgdb) - You now have access to all the symbols in the LKM. + You now have access to all the symbols in the module.