9.7. Debugging Loadable Modules Using GDB
前一頁 | 章 9. Kernel Debugging | 下一頁

## 9.7. Debugging Loadable Modules Using GDB

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.

First, you need to build the module(s) with debugging information:

`#` `cd /sys/modules/linux` `#` `make clean; make COPTS=-g`

If you are using remote GDB, you can run `kldstat` on the target machine to find out where the module was loaded:

`#` `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

If you are debugging a crash dump, you will 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:

`#` `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 hexadecimal field (sixth field overall) is the offset of the text section within the file. Add this offset to the load address of the module to obtain the relocation address for the module's code. In our example, we get 0xc0adc000 + 0x62d0 = 0xc0ae22d0. 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 should now have access to all the symbols in the module.

前一頁 | 上一層 | 下一頁
9.6. On-Line Kernel Debugging Using Remote GDB | 起始頁 | 9.8. Debugging a Console Driver

本文及其他文件，可由此下載： ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。

若有 FreeBSD 方面疑問，請先閱讀 FreeBSD 相關文件，如不能解決的話，再洽詢 <questions@FreeBSD.org>。
關於本文件的問題，請洽詢 <doc@FreeBSD.org>。