当前位置: 技术问答>linux和unix
GDB 的 s 单步命令 怎么改回不进入标准库函数。
来源: 互联网 发布时间:2017-05-29
本文导语: 本帖最后由 jiaga 于 2014-09-13 23:13:42 编辑 debian 7.6 系统 今天用 apt-get install 安装了几个东东 电脑自己下载了很多东西。 然后 GDB 调试代码的时候用 s 命令遇到每个标准库函数都要进去 想这样: 11 #inc...
今天用 apt-get install 安装了几个东东 电脑自己下载了很多东西。
然后 GDB 调试代码的时候用 s 命令遇到每个标准库函数都要进去
想这样:
11 #include
12
13 int main(void)
14 {
15 printf("hello world!n");
(gdb) l
16
17 return 0;
18 }
(gdb) b main
Breakpoint 1 at 0x400510: file test.c, line 15.
(gdb) r
Starting program: /home/jiaga/c/linked_list/void_list/test
s
Breakpoint 1, main () at test.c:15
15 printf("hello world!n");
(gdb) s
_IO_puts (str=0x4005dc "hello world!") at ioputs.c:35
35 ioputs.c: 没有那个文件或目录.
(gdb) s
37 in ioputs.c
(gdb) s
__strlen_sse2 () at ../sysdeps/x86_64/multiarch/../strlen.S:26
26 ../sysdeps/x86_64/multiarch/../strlen.S: 没有那个文件或目录.
(gdb)
弄得我操作好不自在。
只要是标准库它就要源码,我木有啊。。。 而且我也不想调试标准库啊!!
以前 s 命令都是直接跳过了标准库函数的啊!!
像这样:
15 printf("hello world!n");
(gdb) s
hello world!
17 return 0;
(gdb)
用 s 命令然后标准库函数就直接执行了啊, 都没有要进去,就直接跳自己的代码上了啊?
为什么呢??? 现在调试很麻烦了啊,刚看了几行代码又要碰到标准库函数进去 要么就要看准是标准库函数的时候用 n 命令跳过。之前习惯了一路 s 命令走下去的,现在很不习惯啊!!!
怎么改回来呢???
|
猜测楼主可能最近无意下载了glibc的debug文件 到了debug file directory
gdb 的step的实现只是简单的看当前地址是否有source line的信息
所以如果不想跳入glibc的function只需要保证gdb看不到glibc的debug info
闲话少叙, 直接上个例子
(gdb) b main
Breakpoint 1 at 0x400520: file b.C, line 5.
(gdb) r
Starting program: b
Breakpoint 1, main () at b.C:5
5 printf("hello worldn");
(gdb) step
_IO_puts (str=0x4005e4 "hello world") at ioputs.c:35
35 ioputs.c: No such file or directory.
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/usr/lib/debug".
(gdb) set debug-file-directory
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "".
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: b
Breakpoint 1, main () at b.C:5
5 printf("hello worldn");
(gdb) step
hello world
7 return 0;
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: b
Breakpoint 1, main () at b.C:5
5 printf("hello worldn");
(gdb) next
hello world
7 return 0;
如果只是简单想跳过printf,除了改变debug file directory, 也可以直接用 next,如上所示
预知详情,可参考 https://blogs.oracle.com/dbx/entry/gnu_debuglink_or_debugging_system
gdb 的step的实现只是简单的看当前地址是否有source line的信息
所以如果不想跳入glibc的function只需要保证gdb看不到glibc的debug info
闲话少叙, 直接上个例子
(gdb) b main
Breakpoint 1 at 0x400520: file b.C, line 5.
(gdb) r
Starting program: b
Breakpoint 1, main () at b.C:5
5 printf("hello worldn");
(gdb) step
_IO_puts (str=0x4005e4 "hello world") at ioputs.c:35
35 ioputs.c: No such file or directory.
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "/usr/lib/debug".
(gdb) set debug-file-directory
(gdb) show debug-file-directory
The directory where separate debug symbols are searched for is "".
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: b
Breakpoint 1, main () at b.C:5
5 printf("hello worldn");
(gdb) step
hello world
7 return 0;
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: b
Breakpoint 1, main () at b.C:5
5 printf("hello worldn");
(gdb) next
hello world
7 return 0;
如果只是简单想跳过printf,除了改变debug file directory, 也可以直接用 next,如上所示
预知详情,可参考 https://blogs.oracle.com/dbx/entry/gnu_debuglink_or_debugging_system