You can then use print to display variable values, for example, or use list
to review the code that is about to be executed. If you have a multi-file project and want to halt
execution on a line of code or in a function that is not in the current source file, use the following
forms:
(gdb) break filename:linenum
(gdb) break filename:funcname
Conditional breakpoints are usually more useful. They enable you to temporarily halt program
execution if or when a particular condition is met. The correct syntax for setting conditional breakpoints
is as follows:
(gdb) break linenum if expr
(gdb) break funcname if expr
In the preceding code, expr can be any expression that evaluates to true (non-zero). For example,
the following break command stops execution at line 24 of debugme when the variable i equals 15:
(gdb) break 24 if i == 15
Breakpoint 1 at 0x80483cb: file debugme.c, line 24.
(gdb) run
Starting program: /home/kwall/code/debugme
Breakpoint 1, index_to_the_moon (ary=0xbffff4b0) at debugme.c:24
24 ary[i] = i;
Verify the line numbers as seen by gdb. In this case, gdb has line 24 as the assignment
of ary[i] to the value of i, as shown in the preceding code. Use the gdb list command
to verify the line numbers used by gdb.
Stopping when i equals 15 is an arbitrary choice to demonstrate conditional breaks.
Pages:
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457