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
TIP
803
Programming Tools and Utilities 29
precisely where the problem occurred. Here??™s how the function trace for the example looks on my
system:
(gdb) backtrace
#0 0x080483db index_to_the_moon (ary=0x7ffffc90) at debugme.c:24
#1 0x080483a6 in main (argc=104,argv=0x69) 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 (0x0800483db).
The function index_to_the_moon() was called by the main() function.
Pages:
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451