程式扎記: [gdb 命令] continue : 從上次斷(停頓)點, 繼續執行程式

標籤

2010年11月18日 星期四

[gdb 命令] continue : 從上次斷(停頓)點, 繼續執行程式


語法 :
continue, c | Continue program being debugged, after signal or breakpoint.
continue [number] | Continue program execution.

底下是該命令使用說明 :
This command continues program execution until the debugger encounters a breakpoint, a signal, an error, or normal process termination.
The number parameter specifies the number of times to subsequently ignore a breakpoint at this location.

參數說明 :
number : The number of times to ignore a breakpoint at this location.

使用範例 :
考慮代碼如下 :
- continue.c :
  1. #include   
  2.   
  3. void swap(int* pa, int* pb) {  
  4.         int temp=*pa;  
  5.         *pa = *pb;  
  6.         *pb = temp;  
  7. }  
  8. void myPrint(int a, int b) {  
  9.         printf("a=%d, b=%d\n",a ,b);  
  10. }  
  11. int main(void) {  
  12.         int a=5, b=3;  
  13.         printf("Before swapping: ");  
  14.         myPrint(a,b);  
  15.         swap(&a, &b);  
  16.         myPrint(a,b);  
  17.         return 0;  
  18. }  

接著請編譯該代碼, 並以 gdb 執行該程式 :
linux-tl0r:~/gdbDemo # gcc -g continue.c -o continue <編譯程式>
linux-tl0r:~/gdbDemo # gdb continue <進入gdb mode>
(gdb) list 12 <檢視12行附近代碼>
7 }
8 void myPrint(int a, int b) {
9 printf("a=%d, b=%d\n",a ,b);
10 }
11 int main(void) {
12 int a=5, b=3;
13 printf("Before swapping: ");
14 myPrint(a,b);
15 swap(&a, &b);
16 myPrint(a,b);
(gdb) break 14 <接著連下3個斷點在14, 15, 16行>
Breakpoint 1 at 0x804848f: file continue.c, line 14.
(gdb) break 15
Breakpoint 2 at 0x80484a3: file continue.c, line 15.
(gdb) break 16
Breakpoint 3 at 0x80484b7: file continue.c, line 16.
(gdb) r <執行程式, 會停在第一個斷點>
Starting program: /root/gdbDemo/continue
Breakpoint 1, main () at continue.c:14
14 myPrint(a,b);
(gdb) c <繼續執行程式 c = continue, 會停在第二個斷點>
Continuing.
Before swapping: a=5, b=3

Breakpoint 2, main () at continue.c:15
15 swap(&a, &b);
(gdb) c <繼續執行, 會停在第三個斷點>
Continuing.

Breakpoint 3, main () at continue.c:16
16 myPrint(a,b);
(gdb)
This message was edited 7 times. Last update was at 17/11/2010 12:02:51

沒有留言:

張貼留言

網誌存檔

關於我自己

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