今天想用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后。如下:
-
zz@ubuntu:/usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs$ gdb ./pcm_min
-
GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2
-
Copyright (C) 2010 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 "i686-linux-gnu".
-
For bug reporting instructions, please see:
-
<http://www.gnu.org/software/gdb/bugs/>...
-
Reading symbols from /usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs/pcm_min...done.
-
(gdb) b
-
No default breakpoint address now.
-
(gdb) info b
-
No breakpoints or watchpoints.
-
(gdb) b main
-
Breakpoint 1 at 0x804865e: file pcm_min.c, line 26.
-
(gdb) l
-
17 int j;
-
18 unsigned int i;
-
19 snd_pcm_t *handle;
-
20 snd_pcm_sframes_t frames;
-
21
-
22 for (i = 0; i < sizeof(buffer); i++)
-
23 {
-
24 if(i<=1024)
-
25 buffer[i] = random() & 0xff;
-
26 else
-
(gdb) b
-
No default breakpoint address now.
-
(gdb) l
-
27 buffer[i]=buffer[i-1024];
-
28 }
-
29
-
30 if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
-
31 printf("Playback open error: %s\n", snd_strerror(err));
-
32 exit(EXIT_FAILURE);
-
33 }
-
34 if ((err = snd_pcm_set_params(handle,
-
35 SND_PCM_FORMAT_S16,
-
36 SND_PCM_ACCESS_RW_INTERLEAVED,
-
(gdb) b snd_pcm_open
-
Breakpoint 2 at 0x8048518
-
(gdb) b snd_pcm_set_params
-
Breakpoint 3 at 0x8048538
-
(gdb) info b
-
Num Type Disp Enb Address What
-
1 breakpoint keep y 0x0804865e in main at pcm_min.c:26
-
2 breakpoint keep y 0x08048518 <snd_pcm_open@plt>
-
3 breakpoint keep y 0x08048538 <snd_pcm_set_params@plt>
-
(gdb) dir /usr/local/usr/my_tools/alsa-lib-1.0.24.1/src/
-
Source directories searched: /usr/local/usr/my_tools/alsa-lib-1.0.24.1/src:$cdir:$cwd
-
(gdb) show directories
-
Source directories searched: /usr/local/usr/my_tools/alsa-lib-1.0.24.1/src:$cdir:$cwd
-
(gdb) r
-
Starting program: /usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs/pcm_min
-
[Thread debugging using libthread_db enabled]
-
-
Breakpoint 1, main () at pcm_min.c:26
-
26 else
-
(gdb) l
-
21
-
22 for (i = 0; i < sizeof(buffer); i++)
-
23 {
-
24 if(i<=1024)
-
25 buffer[i] = random() & 0xff;
-
26 else
-
27 buffer[i]=buffer[i-1024];
-
28 }
-
29
-
30 if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
-
(gdb) l 10
-
5 #include "../include/asoundlib.h"
-
6 #include "sin_stereo_1s.h"
-
7
-
8 static char *device = "default"; /* playback device */
-
9
-
10 snd_output_t *output = NULL;
-
11 unsigned char buffer[16*1024]; /* some random data */
-
12 extern unsigned char data[];
-
13
-
14 int main(void)
-
(gdb)
-
15 {
-
16 int err;
-
17 int j;
-
18 unsigned int i;
-
19 snd_pcm_t *handle;
-
20 snd_pcm_sframes_t frames;
-
21
-
22 for (i = 0; i < sizeof(buffer); i++)
-
23 {
-
24 if(i<=1024)
-
(gdb)
-
25 buffer[i] = random() & 0xff;
-
26 else
-
27 buffer[i]=buffer[i-1024];
-
28 }
-
29
-
30 if ((err = snd_pcm_open(&handle, device, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
-
31 printf("Playback open error: %s\n", snd_strerror(err));
-
32 exit(EXIT_FAILURE);
-
33 }
-
34 if ((err = snd_pcm_set_params(handle,
-
(gdb) info b
-
Num Type Disp Enb Address What
-
1 breakpoint keep y 0x0804865e in main at pcm_min.c:26
-
breakpoint already hit 1 time
-
2 breakpoint keep y 0x00179c72 <snd_pcm_open+4>
-
3 breakpoint keep y 0x00181c90 <snd_pcm_set_params+5>
-
(gdb) c
-
Continuing.
-
$$...init buffer.....
-
#####################snd_pcm_open...
-
-
Breakpoint 2, 0x00179c72 in snd_pcm_open () from /usr/lib/libasound.so.2
-
(gdb) s
-
Single stepping until exit from function snd_pcm_open,
-
which has no line number information.
-
zz[snd_dlsym_verify:121],vname=[_snd_config_hook_load_dlsym_config_hook_001]
-
zz[snd_dlsym_verify:123]
-
zz[snd_dlsym_verify:121],vname=[__snd_pcm_hw_open_dlsym_pcm_001]
-
zz[snd_dlsym_verify:123]
-
main () at pcm_min.c:37
-
37 1,
-
(gdb)
我
想进入line47-line50处的的snd_pcm_xxx函数中,所以把相应的行号加入了break,但是当执行到时,在line116时已经进入
了 snd_pcm_open 处的断点,但是输入s(step)却没能进入它的源码中,而是直接执行完了再退出来了。
请教给如何进入snd_pcm_open()函数的源码呢,这个函数就是在需要调试的libasound.so库中。。。
找到了一个问题,使用info shared查看时显示:
-
zz@ubuntu:/usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs$ gdb ./pcm_min
-
GNU gdb (Ubuntu/Linaro 7.2-1ubuntu11) 7.2
-
Copyright (C) 2010 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 "i686-linux-gnu".
-
For bug reporting instructions, please see:
-
<http://www.gnu.org/software/gdb/bugs/>...
-
Reading symbols from /usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs/pcm_min...done.
-
(gdb) b main
-
Breakpoint 1 at 0x804860d: file pcm_min.c, line 22.
-
(gdb) b snd_pcm_open
-
Breakpoint 2 at 0x80484d8
-
(gdb) b snd_pcm_set_params
-
Breakpoint 3 at 0x8048518
-
(gdb) info b
-
Num Type Disp Enb Address What
-
1 breakpoint keep y 0x0804860d in main at pcm_min.c:22
-
2 breakpoint keep y 0x080484d8 <snd_pcm_open@plt>
-
3 breakpoint keep y 0x08048518 <snd_pcm_set_params@plt>
-
(gdb) r
-
Starting program: /usr/local/usr/my_tools/alsa-lib-1.0.24.1/test/.libs/pcm_min
-
[Thread debugging using libthread_db enabled]
-
-
Breakpoint 1, main () at pcm_min.c:22
-
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)
最后一句提示 共享库没有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的函数中
-
Breakpoint 2, 0x00179c72 in snd_pcm_open () from /usr/lib/libasound.so.2
-
(gdb) s
-
Single stepping until exit from function snd_pcm_open,
-
which has no line number information.
-
zz[snd_dlsym_verify:121],vname=[_snd_config_hook_load_dlsym_config_hook_001]
-
zz[snd_dlsym_verify:123]
-
zz[snd_dlsym_verify:121],vname=[__snd_pcm_hw_open_dlsym_pcm_001]
-
zz[snd_dlsym_verify:123]
-
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;重新编译。
完了。
阅读(5501) | 评论(2) | 转发(1) |