746 Part VI . Programming in Linux After (Free web hosting services)
746 Part VI . Programming in Linux After GDB initializes, the screen should resemble the one shown in Figure 28-1. Figure 28-1: GDB s startup screen. As you can see near the middle of the figure, GDB displays the name of the executable that created the core file: ` _ . Obviously, the displayed name is wrong; it should be debugme. The odd characters and the incorrect program name would give an experienced developer an immediate clue that the program has a significant memory bug. The next line in the figure, the text that reads Program terminated with signal 11, Segmentation fault explains why the program terminated. A segmentation fault occurs anytime a program attempts to access memory that doesn t explicitly belong to it. GDB also helpfully displays the function it was executing, index_to_the_moon, and the line it believes caused the fault (line 24). If you don t like the licensing messages (they annoy me), use the -q (or –quiet) option when you start GDB to suppress them. 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. 0×0804483db in index_to_the_moon (ary=0xbffff4b0) at debugme.c:24 24 ary[i] = i; Tip
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.