Debugging with GDB (September 2007)
98 Debugging with GDB
(gdb) whatis g
type = double
(gdb) p g
$1 = 1
(gdb) set g=4
(gdb) p g
$2 = 1
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/smith/cc_progs/a.out
"/home/smith/cc_progs/a.out": can’t open to read symbols:
Invalid bfd target.
(gdb) show g
The current BFD target is "=4".
The steps shown above sets the gnutarget to an invalid value in place of the program
variable g.
In order to set the variable g, use
(gdb) set var g=4
GDB allows more implicit conversions in assignments than C; you can freely store an
integer value into a pointer variable or vice versa, and you can convert any structure to any
other structure that is the same length or shorter.
To store values into arbitrary places in memory, use the ‘{...}’ construct to generate a
value of specified type at a specified address (see Section 8.1 [Expressions], page 63). For
example, {int}0x83040 refers to memory location 0x83040 as an integer (which implies a
certain size and representation in memory), and
set {int}0x83040 = 4
stores the value 4 into that memory location.
11.2 Continuing at a different address
Ordinarily, when you continue your program, you do so at the place where it stopped,
with the continue command. You can continue at a selected address using one of the
following commands:
jump linespec
Resume execution at line linespec. Execution stops again immediately if there
is a breakpoint there. See Section 7.1 [Printing source lines], page 57, for a
description of the different forms of linespec. It is common practice to use
the tbreak command in conjunction with jump. See Section 5.1.1 [Setting
breakpoints], page 33.
The jump command does not change the current stack frame, the stack pointer,
the contents of any memory location or any register other than the program