But, you will change your mind the first time you have to debug
someone else??™s code or have to fix a multi-file project for which you haven??™t seen the source files for
a couple of months. The whatis command can also help you track down bugs that result from
assigning an inappropriate value to a variable.
Setting Breakpoints
As you debug problematic code, it is often useful to halt execution at some point. Perhaps you
want to stop execution before the code enters a section that is known to have problems. In other
cases, you can set breakpoints so you can look at the values of certain variables at a given point in
the execution flow. In still other situations, you might find it useful to stop execution so you can
step through the code one instruction at a time.
GDB enables you to set breakpoints on several different kinds of code constructs, including line
numbers and function names, and enables you to set conditional breakpoints, where the code
stops only if a certain condition is met. To set a breakpoint on a line number, use the following
syntax:
(gdb) break linenum
To stop execution when the code enters a function, use the following:
(gdb) break funcname
806
Programming in Linux Part VI
In either case, GDB halts execution before executing the specified line number or entering the
specified function.
Pages:
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456