Я добавил символический файл в GDB для отладки модуля ядра.Однако выходные данные GDB отличаются от адреса, который я зарегистрировал.
Почему адрес функции cardev_write () 0x13d?Я хочу сделать адрес функции cardev_write () 0xffffffffffc0904119.
Память модуля
@ubuntu:~$ sudo cat /proc/kallsyms |grep chardev
ffffffffc0904000 t chardev_release [chardev]
ffffffffc090403a t copy_overflow.constprop.0 [chardev]
ffffffffc0904056 t chardev_read [chardev]
ffffffffc0904119 t chardev_write [chardev]
ffffffffc090420c t chardev_init [chardev]
ffffffffc09065a0 b chardev_cdev [chardev]
ffffffffc0906608 b chardev_major [chardev]
ffffffffc0906580 b __key.28485 [chardev]
ffffffffc0906580 b chardev_class [chardev]
ffffffffc0904390 t chardev_exit [chardev]
ffffffffc09051d5 r .LC2 [chardev]
ffffffffc0906140 d __this_module [chardev]
ffffffffc0906000 d chardev_fops [chardev]
ffffffffc0904390 t cleanup_module [chardev]
ffffffffc090420c t init_module [chardev]
ffffffffc0906480 b G_Data [chardev]
ffffffffc04b5120 d kvm_chardev_ops [kvm]
@ubuntu:~$
Информация о системе
$ uname -a
Linux ubuntu 4.18.0-13-generic #14-Ubuntu SMP Wed Dec 5 09:04:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Установить gdb
$ gdb /usr/lib/debug/boot/vmlinux-4.18.0-13-generic
GNU gdb (Ubuntu 8.2-0ubuntu1) 8.2
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /usr/lib/debug/boot/vmlinux-4.18.0-13-generic...done.
(gdb) add-symbol-file Kernel/Module/SS/chardev.ko 0xffffffffc0904000
add symbol table from file "Kernel/Module/SS/chardev.ko" at
.text_addr = 0xffffffffc0904000
(y or n) y
Reading symbols from Kernel/Module/SS/chardev.ko...(no debugging symbols found)...done.
(gdb) b chardev_write
Breakpoint 1 at 0x13d
(gdb)
Makefile
obj-m := chardev.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean
+ Добавить информацию
Заголовки разделов
@ubuntu:~/Kernel/Module/SS$ readelf -WS chardev.ko | grep '\.text$'
@ubuntu:~/Kernel/Module/SS$ readelf -WS chardev.ko | grep '.text'
[ 2] .text PROGBITS 0000000000000000 000064 000000 00 AX 0 0 1
[ 3] .text.unlikely PROGBITS 0000000000000000 000064 0003bb 00 AX 0 0 1
[ 4] .rela.text.unlikely RELA 0000000000000000 001278 0006a8 18 I 17 3 8
@ubuntu:~/Kernel/Module/SS$
Информация о символе
@ubuntu:~/Kernel/Module/SS$ nm chardev.ko | grep ' chardev_release$'
000000000000006d t chardev_release
@ubuntu:~/Kernel/Module/SS$
/ proc / kallsyms
@ubuntu:~/Kernel/Module/SS$ sudo cat /proc/kallsyms |grep chardev
ffffffffc0587000 t device_lseek [chardev]
ffffffffc058706d t chardev_release [chardev]
ffffffffc05870a7 t chardev_write [chardev]
ffffffffc0587136 t chardev_read [chardev]
ffffffffc05871f0 t chardev_init [chardev]
ffffffffc0589460 b chardev_cdev [chardev]
ffffffffc05894c8 b chardev_major [chardev]
ffffffffc0589440 b __key.28489 [chardev]
ffffffffc0589440 b chardev_class [chardev]
ffffffffc0587348 t chardev_exit [chardev]
ffffffffc0589100 d __this_module [chardev]
ffffffffc0589000 d chardev_fops [chardev]
ffffffffc0587348 t cleanup_module [chardev]
ffffffffc05871f0 t init_module [chardev]
@ubuntu:~/Kernel/Module/SS$
Debug
(gdb) add-symbol-file Kernel/Module/SS/chardev.ko 0xffffffffc058706d
add symbol table from file "Kernel/Module/SS/chardev.ko" at
.text_addr = 0xffffffffc058706d
(y or n) y
Reading symbols from Kernel/Module/SS/chardev.ko...(no debugging symbols found)...done.
(gdb) p chardev_write
Cannot access memory at address 0x8d
(gdb)