The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]

Поиск:  Каталог документации / Документация по FreeBSD / Руководства по FreeBSD на английском

17.6 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.

This, and other documents, can be downloaded from ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.

For questions about FreeBSD, read the documentation before contacting <questions@FreeBSD.org>.
For questions about this documentation, e-mail <doc@FreeBSD.org>.




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру