免费注册 查看新帖 |

Chinaunix

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

[实践] gdb可以实现源码级调试so文件吗?[己解决] [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-01-07 09:55 |显示全部楼层 |倒序浏览
本帖最后由 testh 于 2013-01-08 15:06 编辑

查了一些文章,有的说不能设置断点。
有熟悉的兄弟吗?

论坛徽章:
0
2 [报告]
发表于 2013-01-07 13:50 |显示全部楼层
本帖最后由 testh 于 2013-01-07 13:51 编辑

感谢楼上各位的回复。
是在本地调试,本来是移植到arm上的,但是想先弄清楚alsa-lib的流程,所以在哪里调试都是一样的了。

论坛徽章:
0
3 [报告]
发表于 2013-01-07 13:54 |显示全部楼层
回复 4# frogsu


    兄弟,可以描述的详细一些吗?
以前也用gdb来调试应用程序,但是这次调试时总是失败,提示找不到so,你可以把调试步骤描述一下吗?
例外,你在调试的时候可以在alsa-lib的源码里面设置断点吗?

论坛徽章:
0
4 [报告]
发表于 2013-01-07 14:12 |显示全部楼层
回复 7# T-Bagwell


    谢谢回复。
使用gdb来调试so动态库还不熟悉,可否给些操作步骤的提示

论坛徽章:
0
5 [报告]
发表于 2013-01-07 14:16 |显示全部楼层
对于alda-lib的源码目录是否需要指定路径?

论坛徽章:
0
6 [报告]
发表于 2013-01-07 16:16 |显示全部楼层
本帖最后由 testh 于 2013-01-07 16:23 编辑

我把alsa-lib-1.0.24放在/usr/local/usr/my_tools/alsa-lib-1.0.24.1下。
然后进入到alsa-lib-1.0.24.1/test/.libs/下面执行gdb ./pcm_min 。用gdb来调试pcm_min这个小的测试程序。
进入gdb后。如下:
  1. zz@ubuntu:/usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs$ gdb ./pcm_min
  2. GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2
  3. Copyright (C) 2010 Free Software Foundation, Inc.
  4. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  5. This is free software: you are free to change and redistribute it.
  6. There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  7. and "show warranty" for details.
  8. This GDB was configured as "i686-linux-gnu".
  9. For bug reporting instructions, please see:
  10. <http://www.gnu.org/software/gdb/bugs/>...
  11. Reading symbols from /usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs/pcm_min...done.
  12. (gdb) b
  13. No default breakpoint address now.
  14. (gdb) info b
  15. No breakpoints or watchpoints.
  16. (gdb) b main
  17. Breakpoint 1 at 0x804865e: file pcm_min.c, line 26.
  18. (gdb) l
  19. 17          int j;
  20. 18          unsigned int i;
  21. 19          snd_pcm_t *handle;
  22. 20          snd_pcm_sframes_t frames;
  23. 21  
  24. 22          for (i = 0; i < sizeof(buffer); i++)
  25. 23          {
  26. 24            if(i<=1024)
  27. 25                  buffer[i] = random() & 0xff;
  28. 26            else
  29. (gdb) b
  30. No default breakpoint address now.
  31. (gdb) l
  32. 27                buffer[i]=buffer[i-1024];
  33. 28          }
  34. 29  
  35. 30    if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
  36. 31      printf("Playback open error: %s\n", snd_strerror(err));
  37. 32      exit(EXIT_FAILURE);
  38. 33    }
  39. 34    if ((err = snd_pcm_set_params(handle,
  40. 35                                  SND_PCM_FORMAT_S16,
  41. 36                                  SND_PCM_ACCESS_RW_INTERLEAVED,
  42. (gdb) b snd_pcm_open
  43. Breakpoint 2 at 0x8048518
  44. (gdb) b snd_pcm_set_params
  45. Breakpoint 3 at 0x8048538
  46. (gdb) info b
  47. Num     Type           Disp Enb Address    What
  48. 1       breakpoint     keep y   0x0804865e in main at pcm_min.c:26
  49. 2       breakpoint     keep y   0x08048518 <snd_pcm_open@plt>
  50. 3       breakpoint     keep y   0x08048538 <snd_pcm_set_params@plt>
  51. (gdb) dir /usr/local/usr/my_tools/alsa-lib-1.0.24.1/src/
  52. Source directories searched: /usr/local/usr/my_tools/alsa-lib-1.0.24.1/src:$cdir:$cwd
  53. (gdb) show directories
  54. Source directories searched: /usr/local/usr/my_tools/alsa-lib-1.0.24.1/src:$cdir:$cwd
  55. (gdb) r
  56. Starting program: /usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs/pcm_min
  57. [Thread debugging using libthread_db enabled]

  58. Breakpoint 1, main () at pcm_min.c:26
  59. 26            else
  60. (gdb) l
  61. 21  
  62. 22          for (i = 0; i < sizeof(buffer); i++)
  63. 23          {
  64. 24            if(i<=1024)
  65. 25                  buffer[i] = random() & 0xff;
  66. 26            else
  67. 27                buffer[i]=buffer[i-1024];
  68. 28          }
  69. 29  
  70. 30    if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
  71. (gdb) l 10
  72. 5 #include "../include/asoundlib.h"
  73. 6 #include "sin_stereo_1s.h"
  74. 7
  75. 8 static char *device = "default";      /* playback device */
  76. 9
  77. 10  snd_output_t *output = NULL;
  78. 11  unsigned char buffer[16*1024];        /* some random data */
  79. 12  extern unsigned char data[];
  80. 13  
  81. 14  int main(void)
  82. (gdb)
  83. 15  {
  84. 16          int err;
  85. 17          int j;
  86. 18          unsigned int i;
  87. 19          snd_pcm_t *handle;
  88. 20          snd_pcm_sframes_t frames;
  89. 21  
  90. 22          for (i = 0; i < sizeof(buffer); i++)
  91. 23          {
  92. 24            if(i<=1024)
  93. (gdb)
  94. 25                  buffer[i] = random() & 0xff;
  95. 26            else
  96. 27                buffer[i]=buffer[i-1024];
  97. 28          }
  98. 29  
  99. 30    if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
  100. 31      printf("Playback open error: %s\n", snd_strerror(err));
  101. 32      exit(EXIT_FAILURE);
  102. 33    }
  103. 34    if ((err = snd_pcm_set_params(handle,
  104. (gdb) info b
  105. Num     Type           Disp Enb Address    What
  106. 1       breakpoint     keep y   0x0804865e in main at pcm_min.c:26
  107.   breakpoint already hit 1 time
  108.   2       breakpoint     keep y   0x00179c72 <snd_pcm_open+4>
  109.   3       breakpoint     keep y   0x00181c90 <snd_pcm_set_params+5>
  110.   (gdb) c
  111.   Continuing.
  112.   $$...init buffer.....
  113.   #####################snd_pcm_open...

  114.   Breakpoint 2, 0x00179c72 in snd_pcm_open () from /usr/lib/libasound.so.2
  115.   (gdb) s
  116.   Single stepping until exit from function snd_pcm_open,
  117.   which has no line number information.
  118.   zz[snd_dlsym_verify:121],vname=[_snd_config_hook_load_dlsym_config_hook_001]
  119.   zz[snd_dlsym_verify:123]
  120.   zz[snd_dlsym_verify:121],vname=[__snd_pcm_hw_open_dlsym_pcm_001]
  121.   zz[snd_dlsym_verify:123]
  122.   main () at pcm_min.c:37
  123.   37                                  1,
  124.   (gdb)

复制代码
我想进入line47-line50处的的snd_pcm_xxx函数中,所以把相应的行号加入了break,但是当执行到时,在line116时已经进入了 snd_pcm_open 处的断点,但是输入s(step)却没能进入它的源码中,而是直接执行完了再退出来了。
请教给如何进入snd_pcm_open()函数的源码呢,这个函数就是在需要调试的libasound.so库中。

论坛徽章:
0
7 [报告]
发表于 2013-01-07 16:22 |显示全部楼层
我想进入line47-line50处的的snd_pcm_xxx函数中,所以把相应的行号加入了break,但是当执行到时,在line116时已经进入了 snd_pcm_open 处的断点,但是输入s(step)却没能进入它的源码中,而是直接执行完了再退出来了。
请教给如何进入snd_pcm_open()函数的源码呢,这个函数就是在需要调试的libasound.so库中。

论坛徽章:
0
8 [报告]
发表于 2013-01-07 18:09 |显示全部楼层
现在可以跑起来,按照前面帖子的设置。
但是问题是只能在pcm_min.c这个测试程序中run,break,pcm_min.c这个测试程序调用了libasound.so.2.0.0这个动态库,而不能进入到alsa-lib的源码中,也就是生成libasound.so.2.0.0的源码中进行调试。

论坛徽章:
0
9 [报告]
发表于 2013-01-07 18:23 |显示全部楼层
回复 14# frogsu


    感谢兄弟回复,如你所说,之前我测试过了,用简单的测试例程可以进入子函数跟踪,这些没有问题,晚上我回去再接着研究一下。如果你能够有时间整理一下是再好不过了,有劳了,如果兄弟暂时没时间的话我先弄着,就这个问题我将会随时更新进度,直到解决。

论坛徽章:
0
10 [报告]
发表于 2013-01-08 10:22 |显示全部楼层
找到了一个问题,使用info shared查看时显示:
  1. zz@ubuntu:/usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs$ gdb ./pcm_min
  2. GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2
  3. Copyright (C) 2010 Free Software Foundation, Inc.
  4. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  5. This is free software: you are free to change and redistribute it.
  6. There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
  7. and "show warranty" for details.
  8. This GDB was configured as "i686-linux-gnu".
  9. For bug reporting instructions, please see:
  10. <http://www.gnu.org/software/gdb/bugs/>...
  11. Reading symbols from /usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs/pcm_min...done.
  12. (gdb) b main
  13. Breakpoint 1 at 0x804860d: file pcm_min.c, line 22.
  14. (gdb) b snd_pcm_open
  15. Breakpoint 2 at 0x80484d8
  16. (gdb) b snd_pcm_set_params
  17. Breakpoint 3 at 0x8048518
  18. (gdb) info b
  19. Num     Type           Disp Enb Address    What
  20. 1       breakpoint     keep y   0x0804860d in main at pcm_min.c:22
  21. 2       breakpoint     keep y   0x080484d8 <snd_pcm_open@plt>
  22. 3       breakpoint     keep y   0x08048518 <snd_pcm_set_params@plt>
  23. (gdb) r
  24. Starting program: /usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs/pcm_min
  25. [Thread debugging using libthread_db enabled]

  26. Breakpoint 1, main () at pcm_min.c:22
  27. 22          for (i = 0; i < sizeof(buffer); i++)
  28. (gdb) info shared
  29. From        To          Syms Read   Shared Object Library
  30. 0x00110830  0x001274cf  Yes (*)     /lib/ld-linux.so.2
  31. 0x0014d5d0  0x001f61f8  Yes (*)     /usr/lib/libasound.so.2
  32. 0x002164b0  0x00230b38  Yes (*)     /lib/i386-linux-gnu/libm.so.6
  33. 0x00239a40  0x0023a998  Yes (*)     /lib/i386-linux-gnu/libdl.so.2
  34. 0x00241610  0x0024d9d8  Yes (*)     /lib/i386-linux-gnu/libpthread.so.0
  35. 0x002578c0  0x0025b578  Yes (*)     /lib/i386-linux-gnu/librt.so.1
  36. 0x00275c10  0x00381524  Yes (*)     /lib/i386-linux-gnu/libc.so.6
  37. (*): Shared library is missing debugging information.
  38. (gdb)
复制代码
最后一句提示 共享库没有debugging information,但是我已经在alsa-lib-1.0.24-1/Makefile中的CFLAGS += -g 了,为什么还提示没有呢,然后顺着查找strip这个命令,并把STRIP=strip这句给注释了,然后对比注释前后的libasound.so.2.0.0的大小是一样的,说明没有变化。又得知alsa-lib使用的是libtool来生成的so,再继续查找一下libtool的用法。
有知道如何设置的兄弟指点下
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP