Convenience Variables and Machine Registers
GDB lets you create convenience
variables . These are variables you can use to store values as
you need them. Their names begin with a $ and consist of alphanumeric characters
and underscores. They should start with a letter or underscore.
(Note that values in the value history have names that are numeric.)
You might want to use a convenience variable as an array
index:
(gdb)set $j = 0(gdb)print data[$j++]
After these two commands, simply hitting the ENTER key repeats the last command, stepping through the array one element at a time.
GDB predefines several convenience variables. It also enables you to access the machine registers using predefined register names. Register names vary with machine architecture, of course, but there are four predefined registers available on every architecture. The following list summarizes the convenience variables and predefined registers. The last four entries in the list are the registers that are always available.
|
|
The most recent value in the value history. |
|
|
Item n in the value history. |
|
|
The next to last item in the value history. |
|
|
Item n in the value history, counting from the end. |
|
|
The address last printed by the
|
|
|
The contents
of the address last printed by the |
|
|
The exit status that the debuggee returned when it exited. |
|
|
The breakpoint number of the most recently set breakpoint. |
|
|
The compilation directory ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access