Loading a module
  Home
  Introduction
  Getting KGDB
  Documentation
  Using KGDB
  Credits
  Miscellaneous
  Troubleshooting
  FAQ
  Support
  About KGDB
  KGDB Pronew

 

A module can be loaded as usual with insmod or modprobe commands. GDB automatically detects that a module has been loaded and loads the module object file into its memory for getting debugging information. To let GDB know where module files are located, set GDB variable solib-search-path. An example shown below illustrates this. You can confirm that GDB has indeed detected loading of the module using gdb command info sharedlibrary.

(gdb) set solib-search-path /lib/modules/2.4.23/kernel/drivers/block
(gdb) c
Continuing.

Module is loaded now:

[root@old-pc root]# modprobe loop

Press Ctrl+C to confirm that the module is indeed loaded.

[New Thread 980]

Program received signal SIGTRAP, Trace/breakpoint trap.
breakpoint () at kgdbstub.c:1005
1005 atomic_set(&kgdb_setting_breakpoint, 0);
(gdb) info sharedlibrary
From To Syms Read Shared Object Library
0xc482a060 0xc482c0ef Yes /lib/modules/2.4.23/kernel/drivers/block/loop.o
(gdb) br lo_open
Breakpoint 1 at 0xc482b85c: file
loop.c, line 911.

Loading modules in kgdb 1.8 and earlier versions
kgdb versions 1.8 and earlier need a script to load a module. The procedure given below is used for this purpose. It doesn't apply to kgdb versions 1.9 and above. A module is loaded using the loadmodule.sh script. Name of the module file to be loaded on test machine is given as an argument to the script.

If a module is already loaded in the kernel you don't need to use this script. The procedure to be followed in this case is given on webpage a loading a module file in gdb.

An example of loadmodule.sh usage is shown below.

[amit@askii-pc amit]$ cd /mnt/work/build/old-pc/trfs/modules/trfs
[amit@askii-pc trfs]$ loadmodule.sh trfs
Copying /mnt/work/build/old-pc/trfs/modules/trfs/trfs to old-pc
Loading module /mnt/work/build/old-pc/trfs/modules/trfs/trfs
Warning: modutils is reading from /etc/conf.modules because
         /etc/modules.conf does not exist.  The use of /etc/conf.modules is
         deprecated, please rename /etc/conf.modules to /etc/modules.conf
         as soon as possible.  Command
         mv /etc/conf.modules /etc/modules.conf
Generating script /mnt/work/gdbscripts/loadtrfs
[amit@askii-pc trfs]$

The warning generated above is specific to modutils. It does not affect working of kgdb. You may or may not get the warning depending on whether you have changed modules.conf file after upgrading to modutils 2.3.19. If you have RH 7.0 or 7.1, the module configuration file will be modules.conf and above warning will not be generated.

This command generated a script /mnt/work/gdbscripts/loadtrfs. Contents of the script are shown below.

[amit@askii-pc trfs]$ cat /mnt/work/gdbscripts/loadtrfs
add-symbol-file /mnt/work/build/old-pc/trfs/modules/trfs/trfs 0xc1808060 -s .text.lock 0xc180968c -s .rodata 0xc18097a0 -s __ksymtab 0xc1809a44 -s .data 0xc1809bc0
[amit@askii-pc trfs]$

The script contains a gdb command add-symbol-file. Path to the module object file is first argument to the command. Second argument is address of the .text section.  Further arguments give addresses of different sections in the object file. gdb requires these addresses of sections to calculate addresses of symbols in an object file.

The module will be loaded on the test machine after this command.

[amit@askii-pc trfs]$ rsh -l root old-pc /sbin/lsmod
Module                  Size  Used by
trfs                    7504   0  (unused)
[amit@askii-pc trfs]$