- 论坛徽章:
- 0
|
本帖最后由 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后。如下:- 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库中。 |
|