(gdb) l
2 {
3 int i;
4 int k = 0;
5 for(i = 0; i < 10; i++)
6 {
7 k = i * i;
8 }
9
10 return 0;
11 }
(gdb) break 7 if i == 5 //此处的7为行号
Breakpoint 4 at 0x80483ca: file testloop.c, line 7.
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/charles/code/testloop
Breakpoint 4, main () at testloop.c:7
7 k = i * i;
(gdb) p i
$7 = 5
(gdb)
4.2 使用 condition N condition. N是一个 breakpoint number.
(gdb) l
1 int main(void)
2 {
3 int i;
4 int k = 0;
5 for(i = 0; i < 10; i++)
6 {
7 k = i * i;
8 }
9
10 return 0;
(gdb) break 7
Breakpoint 1 at 0x80483ca: file testloop.c, line 7.
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x080483ca in main at testloop.c:7
(gdb) help condition
Specify breakpoint number N to break only if COND is true.
Usage is `condition N COND’, where N is an integer and COND is an
expression to be evaluated whenever breakpoint N is reached.
(gdb) condition 1 i == 4 //此处的1为info break中的断点号
(gdb) info breakpoints
Num Type Disp Enb Address What
1 breakpoint keep y 0x080483ca in main at testloop.c:7
stop only if i == 4
(gdb) r
Starting program: /home/charles/code/testloop
Breakpoint 1, main () at testloop.c:7
7 k = i * i;
(gdb) p i
$1 = 4