2014-01-30 13 views
2

我在我的gdb命令文件中編寫了以下命令。gdb命令文件錯誤while循環中的「無效類型組合」

while ($i < 3) 
s 
end 

我得到了錯誤:Invalid type combination in ordering comparison.

然後我嘗試以下內容:

while (((int) $i) < ((int) 3)) 
s 
end 

但後來我得到了錯誤:Invalid cast.

如何寫在gdb循環命令文件?

注意:i是被調試的C程序中的變量,在命令文件中被稱爲$ i。

我找不到任何例子at this site,它給出了gdb的一些參考資料。

回答

0

首先,我認爲這是更合適的是使用

watch i >= 3 

爲了打破時i變爲大於2

至於循環,直到在C語言的本地varible小於3。這是它的一個GDB腳本:

while (i < 3) 
    s 
    end 

這C++代碼,以展示出一種GDB循環:

#include <stdio.h> 

int main() 
{ 
    for (int i=0; i< 10; ++i) { 
    printf ("i: %d\n", i); 
    } 
    return 0; 
} 

這是一個GDB測試:

D:\>gdb -q a 
Reading symbols from D:\a.exe...done. 
(gdb) start 
Temporary breakpoint 1 at 0x401395: file main.cpp, line 4. 
Starting program: D:\a.exe 
[New Thread 3780.0x144] 

Temporary breakpoint 1, main() at main.cpp:4 
4  { 
(gdb) n 
5   for (int i=0; i< 10; ++i) { 
(gdb) 
6   printf ("i: %d\n", i); 
(gdb) while (i<3) 
>s 
>end 
i: 0 
5   for (int i=0; i< 10; ++i) { 
6   printf ("i: %d\n", i); 
i: 1 
5   for (int i=0; i< 10; ++i) { 
6   printf ("i: %d\n", i); 
i: 2 
5   for (int i=0; i< 10; ++i) { 
6   printf ("i: %d\n", i); 
(gdb) p i 
$1 = 3 
(gdb)