It??™s pretty clear in this case that the index_to_the_moon() function is suspect, but
depending on experience, some people may not see the exact problem within the function.
In the case of arrays, a command that prints the values in an array, such as print ary[1]@5 in
the preceding example, enables you to confirm at a glance that the values are what you expect them
to be. If the values don??™t match up with your expectations, however, that is a clue that some code is
altering the array in a way you didn??™t intend. As a result, you can focus your bug hunting on a
specific section of code.
GDB also can tell you the types of variables using the whatis command. GDB??™s whatis command
is comparable to the man -f command, which searches the whatis database of system commands
for short descriptions of those system commands (the manual page whatis database is totally separate
from the whatis command used by GDB). While man??™s whatis database works on system
commands, GDB??™s whatis command describes the types of variables and other data structures
used in a program.
(gdb) whatis i
type = int
(gdb) whatis ary
type = int *
(gdb) whatis index_to_the_moon
type = void (int *)
This feature may seem rather useless because, of course, you know the types of all the variables
in your program (yeah, right!).
Pages:
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455