Ubuntu 14.04 LTS:

peter@peterubuntu0:$ insmod mymodule peter@peterubuntu0:/sys/module/mymodule/sections$ cat .text .data .bss 0x0000000000000000 0x0000000000000000 0x0000000000000000 

So how do I tell gdb where is my module loaded on target machine when I debug remotely? Do I use just the offsets (so 0x64 or 64 decimal for .text then?)?

peter@peterubuntu0:~$ objdump mymodule.ko --section-headers mymodule.ko: file format elf64-x86-64 Sections: Idx Name Size VMA LMA File off Algn 0 .note.gnu.build-id 00000024 0000000000000000 0000000000000000 00000040 2**2 CONTENTS, ALLOC, LOAD, READONLY, DATA 1 .text 0000b345 0000000000000000 0000000000000000 00000064 2**0 CONTENTS, ALLOC, LOAD, RELOC, READONLY, CODE 12 .data 000001e4 0000000000000000 0000000000000000 00012620 2**5 CONTENTS, ALLOC, LOAD, RELOC, DATA, LINK_ONCE_DISCARD 15 .bss 00000014 0000000000000000 0000000000000000 00012a80 2**3 ALLOC 

2 Answers

I found that, when the target is another xubuntu, also following works to obtain the text addresses:

(gdb) monitor lsmod Module Size modstruct Used by iptable_mangle 16384 0xffffffffc0f57040 1 (Live) 0xffffffffc0f55000 [ ] ... 

then you can use the elsewhere documented commands to tell gdb the offset

(gdb) add-symbol-file mymodule 0xmymoduleaddress 
0

Add .gdbinit file to your home directory. Gdb sources this file when it starts. In this file you can define a macros for gdb and you can execute normal shell commands as well.

 #gdb implementation of the linux lsmod define gdblsmod set $current = modules.next set $offset = ((int)&((struct module *)0).list) printf "Module\tAddress\n" while($current.next != modules.next) printf "%s\t%p\n", \ ((struct module *) (((void *) ($current)) - $offset ) )->name ,\ ((struct module *) (((void *) ($current)) - $offset ) )->module_core set $current = $current.next end end 

This macro prints addresses of text sections for all currently loaded modules. Open gdb console and type gdblsmod to use this. You can put there also gdb commands like for instance:

set serial baud 115200 

if you are debugging remotely over serial port.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy