程式扎記: [gdb 命令] tbreak : 設定"暫時"中斷點

標籤

2010年11月16日 星期二

[gdb 命令] tbreak : 設定"暫時"中斷點


語法 :
tbreak { funcname | num } | Set a temporary breakpoint at specified location.

底下是該命令使用說明 :
This command sets a temporary breakpoint at the specified location, either a line number in source code, or a function.
This command differs from the break command in that the tbreak command creates a temporary breakpoint that is automatically removed after it stops program execution.


參數說明 :
funcname : The name of a function.
num : The number of a source code line.

使用範例 :
考慮代碼如下 :
- breakif.c :
  1. #include   
  2.   
  3. int main(int argc, char **argv){  
  4.         int i;  
  5.         for(i=0; i
  6.                 printf("%s\n", argv[i]);  
  7.         }  
  8.         return 0;  
  9. }  

在編譯完代碼後, 使用 gdb 執行該程式 :
(gdb) list <檢視代碼>
1 #include
2
3 int main(int argc, char **argv){
4 int i;
5 for(i=0; i6 printf("%s\n", argv[i]);
7 }
8 return 0;
9 }
(gdb) tbreak 6 <在第六行設"暫時"中斷點>
Temporary breakpoint 1 at 0x8048427: file breakif.c, line 6.
(gdb) info break <檢視中斷點設定>
Num Type Disp Enb Address What
1 breakpoint del y 0x08048427 in main at breakif.c:6
(gdb) run <執行程式>
Starting program: /root/gdbDemo/breakif
Temporary breakpoint 1, main (argc=1, argv=0xbffff524) at breakif.c:6
6 printf("%s\n", argv[i]);
(gdb) info break <檢視中斷點設定>
No breakpoints or watchpoints. <因為 tbreak, 所以中斷後就自動清除>
(gdb) break 6 <在第6行設中斷點>
Breakpoint 2 at 0x8048427: file breakif.c, line 6.
(gdb) tbreak 6 <在第6行設"暫時"中斷點>
Note: breakpoint 2 also set at pc 0x8048427.
Temporary breakpoint 3 at 0x8048427: file breakif.c, line 6.
(gdb) info break <檢視中斷點>
Num Type Disp Enb Address What
2 breakpoint keep y 0x08048427 in main at breakif.c:6
3 breakpoint del y 0x08048427 in main at breakif.c:6 <有看出 break與 tbreak 的差異了嗎?>

補充說明 :
info break 說明
This command prints information about the specified breakpoint. If you do not specify a breakpoint ID, the debugger prints information about all breakpoints...
This message was edited 5 times. Last update was at 17/11/2010 11:46:06

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!