2009-04-08 118 views
6

當碰到斷點並進入函數時,gdb版本6.8將打印函數的名稱,後跟函數參數。如何讓GDB在「踏入」時不打印函數參數值?

恰恰如此,在我正在調試的程序中,其中一個參數值是通過引用傳遞的巨大記錄。 gdb打印變量名稱,後跟所有其成員變量。它真的需要一分鐘或兩分鐘打印所有包含在類中的成員變量......這在調試時真的很煩人。

我很確定有一個設置來禁用這種行爲,那是什麼設置?

回答

10

發現了它,終於。要完全禁用輸出:

set print frame-arguments none 

要只打印標量值而忽視陣列&結構:

set print frame-arguments scalars 

要打開打印背面上:

set print frame-arguments all 
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)