Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1071040
  • 博文数量: 132
  • 博客积分: 612
  • 博客等级: 中士
  • 技术积分: 1389
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-14 16:06
文章分类

全部博文(132)

文章存档

2015年(2)

2014年(55)

2013年(53)

2012年(2)

2011年(20)

分类: LINUX

2013-03-30 19:11:42

今天想用gdb再来调一下alsa-lib。突然想起来自己好像以前整过,但是具体的设置都忘了,于是搜了一下帖子,还好找到了。现整理一下。

在论坛中的地址:

====================开始============================
我把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库中。。。

找到了一个问题,使用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的用法。

最新进展。
已经将debug信息在编译时加入了libasound.so.2.0.0中。
在上一贴中使用info shared命令显示missing debugging information.
在刚才的显示中为:
22          for (i = 0; i < sizeof(buffer); i++)
(gdb) info shared
From        To          Syms Read   Shared Object Library
0x00110830  0x001274cf  Yes (*)     /lib/ld-linux.so.2
0x0014d5d0  0x001f61f8  Yes         /usr/lib/libasound.so.2
0x002164b0  0x00230b38  Yes (*)     /lib/i386-linux-gnu/libm.so.6
0x00239a40  0x0023a998  Yes (*)     /lib/i386-linux-gnu/libdl.so.2
0x00241610  0x0024d9d8  Yes (*)     /lib/i386-linux-gnu/libpthread.so.0
0x002578c0  0x0025b578  Yes (*)     /lib/i386-linux-gnu/librt.so.1
0x00275c10  0x00381524  Yes (*)     /lib/i386-linux-gnu/libc.so.6
(*): Shared library is missing debugging information.
(gdb) c

请注意,在蓝色的那一行中,Yes后面已经没有“*”了,有“*”意味着(*): Shared library is missing debugging information.

对比刚才的操作,刚才是直接在./configure后生成的Makefile中的CFLAGS = -D_GNU_SOURCE 加入了-g为 CFLAGS = -D_GNU_SOURCE -g.
后来仔细看了./configure --help 发现可以通过环境变量来设置 CFLAGS ,于是先 export CFLAGS = -g 然后再./configure,之后再检查生成的Makefile,它的CFLAGS=-g -D_GNU_SOURCE,然后再继续make,make install后发现,竟然已经包含了debugging information.
不知道-D_GNU_SOURCE与-g的先后顺序竟然有如此大的影响?


但是,仍然不能step 进入libasound.so.2.0.0的函数中

点击(此处)折叠或打开

  1. Breakpoint 2, 0x00179c72 in snd_pcm_open () from /usr/lib/libasound.so.2
  2. (gdb) s
  3. Single stepping until exit from function snd_pcm_open,
  4. which has no line number information.
  5. zz[snd_dlsym_verify:121],vname=[_snd_config_hook_load_dlsym_config_hook_001]
  6. zz[snd_dlsym_verify:123]
  7. zz[snd_dlsym_verify:121],vname=[__snd_pcm_hw_open_dlsym_pcm_001]
  8. zz[snd_dlsym_verify:123]
  9. main () at pcm_min.c:31
使用step的时候提示 :which has no line number information。
继续查找

。。。。

shit,原来我只在alsa-lib-1.0.24.1的topdir中的makefile中加了-g,而没有在他的递归子目录下添加,手动添加很容易忘。还是需要用策略添加,直接在环境变量中添加.

对了,如果按照上面的设置完之后仍然不能进入源码单步调试,那就make clean;重新编译。

完了。

阅读(5413) | 评论(2) | 转发(1) |
给主人留下些什么吧!~~

testh2013-11-04 09:37:04

yintree:谢谢。我在学习gdb调试。最近写了一个使用alsa-lib的app,所以也在调试alsa-lib。

-D_GNU_SOURCE与-g的先后顺序应该没有关系。正如下面一段说的,是因为手动添加,只在topdir的makefile里面添加导致的没有产生调试信息。

不客气,希望对你有帮助

回复 | 举报

yintree2013-10-31 10:33:02

谢谢。我在学习gdb调试。最近写了一个使用alsa-lib的app,所以也在调试alsa-lib。

-D_GNU_SOURCE与-g的先后顺序应该没有关系。正如下面一段说的,是因为手动添加,只在topdir的makefile里面添加导致的没有产生调试信息。