Prev | Current Page 1438 | Next

Christopher Negus

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

Another useful
command-line option is -d dirname, where dirname is the name of a directory, which tells gdb
where to find source code (it looks in the current working directory by default).
After you load the program and its core dump into the debugger, run the program in the debugger.
To do so, type the command run at the GDB command prompt, (gdb), as the following example
shows:
(gdb) run
Starting program: /home/kwall/code/debugme
Program received signal SIGSEGV, Segmentation fault.
0x0804483db in index_to_the_moon (ary=0xbffff4b0) at debugme.c:24
24 ary[i] = i;
This short output listing shows that the segmentation fault occurred in the function
index_to_the_moon at line 24 of debugme.c. Notice the last line of the output; GDB displays
the line of code, prefixed with the line number (24), where the segmentation fault occurred. It also
shows the memory address (in hexadecimal format) at which the fault occurred: 0xbffff4b0.
You can pass any arguments to the run command that your program would ordinarily accept. GDB
also creates a full shell environment in which to run the program. Ordinarily, GDB uses the value
of the environment variable $SHELL to create the simulated environment. If you want, however, you
can use GDB??™s set and unset commands to set or unset arguments and environment variables
before you use the run command to run the program in the debugger.


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