Debugging with GDB Manual The GNU Source-Level Debugger (769148-001, March 2014)
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“Expressions” (page 58)). 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.
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 “Printing source lines” (page 54), for a
description of the different forms of linespec. It is common practice to use
the tbreak command in conjunction with jump. See “Breakpoints”
(page 36).
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 counter. If line linespec is in a different function from the one
currently executing, the results may be bizarre if the two functions expect
different patterns of arguments or of local variables. For this reason, the
jump command requests confirmation if the specified line is not in the function
currently executing. However, even bizarre results are predictable if you are
well acquainted with the machine-language code of your program.
jump *address Resume execution at the instruction at address address.
On many systems, you can get much the same effect as the jump command by storing a new value
into the register $pc. This does not start the execution of your program at the specified address,
instead only changes the program counter.
For example,
set $pc = 0x485
makes the next continue command or stepping command execute at address 0x485, rather
than at the address where your program stopped. See “Continuing and stepping” (page 45).
The most common occasion to use the jump command is to back up―perhaps with more breakpoints
set―over a portion of a program that has already executed, in order to examine its execution in
more detail.
Giving your program a signal
You can use the following command to send signals to your program:
signal signal Resume execution where your program stopped, but immediately give it the
signal signal. signal can be the name or the number of a signal. For
example, on many systems signal 2 and signal SIGINT are both ways
of sending an interrupt signal.
Continuing at a different address 85