gdb-通过预定义规则跳过某些文件的进一步操作? [英] gdb - skip further step in of certain file by predefined rule?

查看:178
本文介绍了gdb-通过预定义规则跳过某些文件的进一步操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有此文件:

xb@dnxb:/tmp/c$ cat helloworld.h
void hello();
xb@dnxb:/tmp/c$ cat helloworld.c
#include <stdio.h>
void hello() {
  printf("Hello world!\n");
  printf("Next line\n");
}

xb@dnxb:/tmp/c$ cat main.c
#include <stdio.h>
#include "helloworld.h"
int
main(void) {
        hello();
        return 0;
}

并使用以下命令进行编译:

And compiled with:

xb@dnxb:/tmp/c$ gcc -g3 -shared -o libhello.so -fPIC helloworld.c -std=c11
xb@dnxb:/tmp/c$ gcc -g3 main.c -o main -Wl,-rpath,"$PWD" -L. -lhello

然后使用gdb进行调试:

Then debug with gdb:

xb@dnxb:/tmp/c$ gdb -q -n ./main
Reading symbols from ./main...done.
(gdb) b main
Breakpoint 1 at 0x40062a: file main.c, line 5.
(gdb) r
Starting program: /tmp/c/main 

Breakpoint 1, main () at main.c:5
5               hello();
(gdb) s
hello () at helloworld.c:3
3         printf("Hello world!\n");

这时,重复按 Enter (相当于键入s并反复按 Enter ):

At this point, repeatedly pressing Enter (equivalent to type s and press Enter repeatedly):

(gdb) 
_IO_puts (str=0x7ffff7bd9689 "Hello world!") at ioputs.c:33
33      ioputs.c: No such file or directory.
(gdb) 
35      in ioputs.c
(gdb) 
strlen () at ../sysdeps/x86_64/strlen.S:66
66      ../sysdeps/x86_64/strlen.S: No such file or directory.
(gdb) 

如果我只关心helloworld.c而又没有进一步进入上述printf()ioputs.c怎么办?

What if i only care about helloworld.c without further step into printf()'s ioputs.c above ?

xb@dnxb:/tmp/c$ gdb -q -n ./main
Reading symbols from ./main...done.
(gdb) b main
Breakpoint 1 at 0x40062a: file main.c, line 5.
(gdb) r
Starting program: /tmp/c/main 

Breakpoint 1, main () at main.c:5
5               hello();
(gdb) s
hello () at helloworld.c:3
3         printf("Hello world!\n");
(gdb) n
Hello world!
4         printf("Next line\n");
(gdb)

这是我想要的,但是它需要我手动发现我在helloworld.c中,现在该相应地键入n了.我想要的是:

This is what i want, but it requires me to manually spot I'm in helloworld.c and it's the time to type n accordingly. My desired is:

(gdb) s
hello () at helloworld.c:3
3         printf("Hello world!\n");

Enter 将跳过自定义文件名的导入,例如在这种情况下为helloworld.c,并直接跳至printf("Next line\n");:

Press Enter will skip step-in of custom filename, e.g. helloworld.c in this case, and direct skip to printf("Next line\n");:

(gdb) 
Hello world!
4         printf("Next line\n");
(gdb)

好处是我不必找出应该在哪里停止s并更改为n,尤其是在代码层次结构很大并且我可能会多次进入helloworld.c的情况下.我只需要反复按 Enter 并跳过不需要的深度/水平即可.

The benefit is I don't have to spot where should i stop s and change to n, especially if the code hierarchy is big and i might step into helloworld.c for many time. I just have to repeatedly pressing Enter and skip unwanted depth/level.

我应该怎么做?

推荐答案

GDB的skip命令可让您跳过单步执行的无用功能或文件.它的语法是 skip uninteresting_function skip file uninteresting.file . (完整文档此处)

GDB's skip command lets you skip stepping into uninteresting functions or files. Its syntax is skip uninteresting_function or skip file uninteresting.file. (full documentation here)

根据您的情况,您应该尝试跳过文件ioputs.c .

In your case you should try skip file ioputs.c.

Gdb 7.12在文件名和函数名上引入了模式,因此,如果需要,您应该构建/安装该版本.此版本允许您执行(例如)跳过文件-gfi/lib/* ,该文件将跳过/lib/...

Gdb 7.12 introduced patterns on file and function names, so you should build/install that version if you want that. This version allows you to do (for example) skip file -gfi /lib/*, which skips any source files located in /lib/...

这篇关于gdb-通过预定义规则跳过某些文件的进一步操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆