As a result, you can access these computed values using aliases rather than retyping the command.
For example, the command $1-5 produces the following:
(gdb) print $1-5
$2 = 719
Notice that the alias incremented to $2. If you later need to use the value 719, you can use the
alias $2. The value history is reset each time you start GDB and the values are not accessible outside
of GDB.
You are not limited to using discrete values because gdb can display the addresses of data stored in
an arbitrary region of memory. For example, to print the first 10 memory locations associated with
ary, use the following command:
(gdb) print ary@10
$3 = {0xbffffc90, 0x40015580, 0x400115800, 0x0, 0x1, 0x2, 0c3, 0x4, 0x5}
The notation @10 means to print the 10 values that begin at ary. Say, on the other hand, that you
want to print the five values stored in ary beginning with the first element. The command for this
would be as follows:
(gdb) print ary[1]@5
$4 = {1, 2, 3, 4, 5}
Why go to the trouble of printing variable or array values? Although it isn??™t necessary in this particular
example because you know where the trouble occurs, it is often necessary to see the value
of a variable at a particular point in a program??™s execution so you can monitor what is happening to
805
Programming Tools and Utilities 29
variables.
Pages:
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454