Prev | Current Page 1435 | Next

Christopher Negus

"Linux Bible, 2008 Edition: Boot up to Ubuntu, Fedora, KNOPPIX, Debian, openSUSE, and 11 Other Distributions"


800
Programming in Linux Part VI
Time and effort invested in learning GDB is well spent if you can track down and fix a serious bug
in just a few minutes. GDB can make this happen. Most of what you will need to accomplish with
GDB can be done with a surprisingly small set of commands. The rest of this chapter explores GDB
features and shows you enough GDB commands to get you going.
Effective debugging requires that your source code be compiled with the -g option to create a
binary with an extended symbol table. For example, the following command
$ gcc -g file1 file2 -o prog
causes prog to be created with debugging symbols in its symbol table. If you want, you can use
GCC??™s -ggdb option to generate still more (GDB-specific) debugging information. However, to
work most effectively, this option requires that you have access to the source code for every library
against which you link. While this can be very useful in certain situations, it can also be expensive
in terms of disk space. In most cases, you can get by with the plain -g option.
Starting GDB
To start a debugging session, simply type gdb progname, replacing progname with the name of
the program you want to debug. Using a core file is optional but will enhance GDB??™s debugging
capabilities.


Pages:
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447