代码之家  ›  专栏  ›  技术社区  ›  oz10

如何让GDB在“进入”时不打印函数参数值?

  •  7
  • oz10  · 技术社区  · 17 年前

    碰巧,在我调试的程序中,其中一个参数值是一条通过引用传递的巨大记录。 gdb 打印变量名及其所有成员变量。真的需要 一两分钟打印类中包含的所有成员变量。。。这在调试时非常烦人。

    2 回复  |  直到 17 年前
        1
  •  15
  •   oz10    17 年前

    终于找到了。要完全禁用输出,请执行以下操作:

    set print frame-arguments none 
    

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

    set print frame-arguments scalars 
    

    set print frame-arguments all
    
        2
  •  1
  •   Sniggerfardimungus    17 年前

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

    您始终可以在要进入的函数内设置断点,但在执行该步骤之前,请使用“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)
    
    推荐文章