- 论坛徽章:
- 0
|
(1)调试LKM(Loadable Kernel Module)
.在目标板上插入模块并输出map信息,查看.text入口地址:
#insmod -m hello.ko > map
#grep .text map
比如为0xc68c0060
.在gdb中转入LKM的调试信息:
(gdb) add-symbol-file hello.ko 0xc68c0060 /*注意必须是LKM .text的入口地址)
.正常调试
(2)调试共享库
.样例程序:
test.c:
#include <stdio.h>
int test(int a, int b)
{
int s = a b;
printf("%d\n", s);
return s;
}
main.c:
#include <stdio.h>
extern int test(int a, int b);
int main(int argc, char* argv[])
{
int s = test(10, 20);
return s;
}
Makefile:
all: so main
so:
armv5-linux-uclibc-gcc -g test.c -shared -o libtest.so
main:
armv5-linux-uclibc-gcc -g main.c -L./ -ltest -o test.exe
clean:
rm -f *.exe *.so
.编译并设置环境变量
#make
在目标板上:
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./
#gdbserver localhost:2345 ./test.exe
.运行gdb客户端
#armv5-linux-uclibc-gdb
(gdb)symbol-file test.exe
(gdb)target remote 192.168.0.2:2345
(gdb)b main
(gdb)c
.查看libtest.so的代码在内存中的位置。(从gdbserver的输出或者用ps可以得到test.exe的进程ID,这里假设PID是11547)
在目标板上:
#cat /proc/11547/maps
输出:
.........
0076a000-0076c000 rwxp 0076a000 00:00 0
00bbe000-00bbf000 r-xp 00bbe000 00:00 0
00fcc000-00fcd000 r-xp 00000000 03:01 1238761 /root/test/gdbservertest/libtest.so
00fcd000-00fce000 rwxp 00000000 03:01 1238761 /root/test/gdbservertest/libtest.so
08048000-08049000 r-xp 00000000 03:01 1238765 /root/test/gdbservertest/test.exe
08049000-0804a000 rw-p 00000000 03:01 1238765 /root/test/gdbservertest/test.exe
........
由此可以知道:libtest.so的代码在00fcc000-00fcd000之间。
.查看libtest.so的.text段在内存中的偏移位置:
armv5-linux-uclibc-objdump -h libtest.so |grep .text
输出:
.text 00000130 00000450 00000450 00000450 2**4
即偏移位置为0x00000450
.回到板子上的gdb窗口,加载libtest.so的符号表。
(gdb)add-symbol-file libtest.so 0x00fcc450
(这里0x00fcc450 = 0x00fcc000 0x00000450)
.在共享库的函数中设置断点
(gdb)b test
.继续调试共享库
网上的一些文章,已丢失了原始出处,很有价值 |
|