免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2477 | 回复: 2
打印 上一主题 下一主题

gdbserver如何debug共享库啊 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-07-17 21:56 |只看该作者 |倒序浏览
应用程序调用了额外的共享库,但是gdbserver能在应用程序中下断点,但是无法在共享库中下断点,请教各位是如何设置的,多谢了

论坛徽章:
0
2 [报告]
发表于 2008-07-17 22:07 |只看该作者
1.樓主有沒有共享庫的源碼? -沒有即無法調試
2.樓主調試編譯時有沒有加入共享庫碼?

论坛徽章:
0
3 [报告]
发表于 2008-07-17 22:09 |只看该作者
(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

.继续调试共享库

网上的一些文章,已丢失了原始出处,很有价值
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP