8

当遇到断点并单步执行函数时,gdb 6.8 版会打印函数名称,后跟函数参数。

碰巧的是,在我正在调试的程序中,参数值之一是通过引用传递的巨大记录。gdb打印变量名,后跟其所有成员变量。从字面上看,gdb需要一两分钟来打印类中包含的所有成员变量......这在调试时真的很烦人。

我很确定有一个设置可以禁用此行为,该设置是什么?

4

2 回答 2

15

终于找到了 要完全禁用输出:

set print frame-arguments none 

仅打印标量值并忽略数组和结构:

set print frame-arguments scalars 

要重新打开打印:

set print frame-arguments all
于 2009-04-08T19:04:26.227 回答
1

我有一种我一直这样做的方法,但是看到你的问题让我很好奇是否有更好的机制。我什么也没找到。

你总是可以在你要进入的函数中设置一个断点,但是在你执行这个步骤之前,使用'commands'命令告诉gdb你不希望它在遇到那个断点时打印任何东西。一个例子将使事情更清楚......

您会注意到,当我运行程序时,我在第 10 行的断点处停止(对 foo 的调用)并打印我当前的上下文。在发出“commands 2”命令并告诉 gdb 对该断点保持沉默后,当我点击它时,什么都没有打印出来。我做了回溯(bt)只是为了表明我在我想去的地方。

希望这可以帮助:

> cat tmp.cpp

#include <stdio.h>

void foo(int a)
{
        printf ("%d\n", a);
}

int main()
{
        foo(0);

        return 0;
}

> g++ -g tmp.cpp
> gdb a.out
GNU gdb Fedora (6.8-27.el5)
Copyright (C) 2008 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 "i386-redhat-linux-gnu"...
(gdb) break 10
Breakpoint 1 at 0x8048491: file tmp.cpp, line 10.
(gdb) break 5
Breakpoint 2 at 0x804846a: file tmp.cpp, line 5.
(gdb) run
Starting program: /home/ronb/software/a.out

Breakpoint 1, main () at tmp.cpp:10
10              foo(0);
(gdb) commands 2
Type commands for when breakpoint 2 is hit, one per line.
End with a line saying just "end".
>silent
>end
(gdb) c
Continuing.
(gdb) bt
#0  foo (a=0) at tmp.cpp:5
#1  0x0804849d in main () at tmp.cpp:10
(gdb)
于 2009-04-08T18:45:05.913 回答