Chapter 28 . Programming Tools and Utilities 747 (Ftp web hosting)

Chapter 28 . Programming Tools and Utilities 747 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. To set command-line arguments to pass to the program, type set args arg1 arg2, where arg1 and arg2 (or any number of arguments) are options and arguments the program being debugged expects. Use set environment env1 env2 to set environment variables (again, env1 and env2 are placeholders for the environment variables you want to set or unset). Inspecting Code in the Debugger What is happening in the function index_to_the_moon that s causing the error? You can execute the backtrace (or bt or back) command to generate the function tree that led to the segmentation fault. The backtrace doesn t usually show you what the problem is, but it does show you more precisely where the problem occurred. Here s how the function trace for the example looks on my system: (gdb) backtrace #0 0×080483db index_to_the_moon (ary=0×7ffffc90) at debugme.c:24 #1 0×080483a6 in main (argc=104,argv=0×69) at debugme.c:15 A backtrace shows the chain of function calls that resulted in the error. The backtrace starts with the most recently called function index_to_the moon() in this case which resides at the hexadecimal memory address shown in the second column of the display (0×0800483db). index_to_the_moon() was called by the main() function. As you can see from the output, the most recently called function was index_to_the_moon(), so, somewhere in the function, the segmentation fault occurred. Incidentally, the backtrace also shows that index_to_the_moon() was called from line 15 of the main() function in debugme.c. It s not necessary to type complete command names while using GDB. Any sufficiently unique abbreviation works. For example, back suffices for backtrace. Tip
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Leave a Reply