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.
It would be helpful, however, to have some idea of the context in which the offending line(s) of
code exist. For this purpose, use the list command, which takes the general form, list [m,n],
where m and n are the starting and ending line numbers you want displayed. For example:
(gdb) list 10,24
would display code lines 10 through 24.
A bare list command displays 10 lines of code, including the line where the error was first
detected, as illustrated here:
(gdb) list
15 index_to_the_moon(intary);
16
17 exit(EXIT_SUCCESS);
18 }
19
20 void index_to_the_moon(int ary[])
21 {
22 int i;
23 for (i = 0; i < BIGNUM; ++I {
24 ary[i] = i;
Examining Data
One of GDB??™s most useful features is its ability to display both the type and the value of almost any
expression, variable, or array in the program being debugged. It can print the value of any legal
expression in the language in which your program is written.
Pages:
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452