You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
515 lines
24 KiB
HTML
515 lines
24 KiB
HTML
<HTML>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<!-- Created on March, 27 2008 by texi2html 1.64 -->
|
|
<!--
|
|
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
|
|
Karl Berry <karl@freefriends.org>
|
|
Olaf Bachmann <obachman@mathematik.uni-kl.de>
|
|
and many others.
|
|
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
|
|
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
|
|
|
|
-->
|
|
<HEAD>
|
|
<TITLE>Debugging with GDB: Altering</TITLE>
|
|
|
|
<META NAME="description" CONTENT="Debugging with GDB: Altering">
|
|
<META NAME="keywords" CONTENT="Debugging with GDB: Altering">
|
|
<META NAME="resource-type" CONTENT="document">
|
|
<META NAME="distribution" CONTENT="global">
|
|
<META NAME="Generator" CONTENT="texi2html 1.64">
|
|
|
|
</HEAD>
|
|
|
|
<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">
|
|
|
|
<A NAME="SEC147"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_14.html#SEC146"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC148"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_3.html#SEC6"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<H1> 14. Altering Execution </H1>
|
|
<!--docid::SEC147::-->
|
|
<P>
|
|
|
|
Once you think you have found an error in your program, you might want to
|
|
find out for certain whether correcting the apparent error would lead to
|
|
correct results in the rest of the run. You can find the answer by
|
|
experiment, using the GDB features for altering execution of the
|
|
program.
|
|
</P><P>
|
|
|
|
For example, you can store new values into variables or memory
|
|
locations, give your program a signal, restart it at a different
|
|
address, or even return prematurely from a function.
|
|
</P><P>
|
|
|
|
<BLOCKQUOTE><TABLE BORDER=0 CELLSPACING=0>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC148">14.1 Assignment to Variables</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Assignment to variables</TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC149">14.2 Continuing at a Different Address</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Continuing at a different address</TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC150">14.3 Giving your Program a Signal</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Giving your program a signal</TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC151">14.4 Returning from a Function</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Returning from a function</TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC152">14.5 Calling Program Functions</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Calling your program's functions</TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC153">14.6 Patching Programs</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP">Patching your program</TD></TR>
|
|
</TABLE></BLOCKQUOTE>
|
|
<P>
|
|
|
|
<A NAME="Assignment"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC148"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC149"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<H2> 14.1 Assignment to Variables </H2>
|
|
<!--docid::SEC148::-->
|
|
<P>
|
|
|
|
<A NAME="IDX681"></A>
|
|
<A NAME="IDX682"></A>
|
|
To alter the value of a variable, evaluate an assignment expression.
|
|
See section <A HREF="gdb_9.html#SEC60">Expressions</A>. For example,
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>print x=4
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
stores the value 4 into the variable <CODE>x</CODE>, and then prints the
|
|
value of the assignment expression (which is 4).
|
|
See section <A HREF="gdb_13.html#SEC102">Using GDB with Different Languages</A>, for more
|
|
information on operators in supported languages.
|
|
</P><P>
|
|
|
|
<A NAME="IDX683"></A>
|
|
<A NAME="IDX684"></A>
|
|
If you are not interested in seeing the value of the assignment, use the
|
|
<CODE>set</CODE> command instead of the <CODE>print</CODE> command. <CODE>set</CODE> is
|
|
really the same as <CODE>print</CODE> except that the expression's value is
|
|
not printed and is not put in the value history (see section <A HREF="gdb_9.html#SEC67">Value History</A>). The expression is evaluated only for its effects.
|
|
</P><P>
|
|
|
|
If the beginning of the argument string of the <CODE>set</CODE> command
|
|
appears identical to a <CODE>set</CODE> subcommand, use the <CODE>set
|
|
variable</CODE> command instead of just <CODE>set</CODE>. This command is identical
|
|
to <CODE>set</CODE> except for its lack of subcommands. For example, if your
|
|
program has a variable <CODE>width</CODE>, you get an error if you try to set
|
|
a new value with just <SAMP>`set width=13'</SAMP>, because GDB has the
|
|
command <CODE>set width</CODE>:
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>(gdb) whatis width
|
|
type = double
|
|
(gdb) p width
|
|
$4 = 13
|
|
(gdb) set width=47
|
|
Invalid syntax in expression.
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
The invalid expression, of course, is <SAMP>`=47'</SAMP>. In
|
|
order to actually set the program's variable <CODE>width</CODE>, use
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>(gdb) set var width=47
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
Because the <CODE>set</CODE> command has many subcommands that can conflict
|
|
with the names of program variables, it is a good idea to use the
|
|
<CODE>set variable</CODE> command instead of just <CODE>set</CODE>. For example, if
|
|
your program has a variable <CODE>g</CODE>, you run into problems if you try
|
|
to set a new value with just <SAMP>`set g=4'</SAMP>, because GDB has
|
|
the command <CODE>set gnutarget</CODE>, abbreviated <CODE>set g</CODE>:
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>(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".
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
The program variable <CODE>g</CODE> did not change, and you silently set the
|
|
<CODE>gnutarget</CODE> to an invalid value. In order to set the variable
|
|
<CODE>g</CODE>, use
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>(gdb) set var g=4
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
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.
|
|
</P><P>
|
|
|
|
To store values into arbitrary places in memory, use the <SAMP>`{<small>...</small>}'</SAMP>
|
|
construct to generate a value of specified type at a specified address
|
|
(see section <A HREF="gdb_9.html#SEC60">Expressions</A>). For example, <CODE>{int}0x83040</CODE> refers
|
|
to memory location <CODE>0x83040</CODE> as an integer (which implies a certain size
|
|
and representation in memory), and
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>set {int}0x83040 = 4
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
stores the value 4 into that memory location.
|
|
</P><P>
|
|
|
|
<A NAME="Jumping"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC149"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC148"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC150"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC150"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<H2> 14.2 Continuing at a Different Address </H2>
|
|
<!--docid::SEC149::-->
|
|
<P>
|
|
|
|
Ordinarily, when you continue your program, you do so at the place where
|
|
it stopped, with the <CODE>continue</CODE> command. You can instead continue at
|
|
an address of your own choosing, with the following commands:
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX685"></A>
|
|
<DT><CODE>jump <VAR>linespec</VAR></CODE>
|
|
<DD><DT><CODE>jump <VAR>location</VAR></CODE>
|
|
<DD>Resume execution at line <VAR>linespec</VAR> or at address given by
|
|
<VAR>location</VAR>. Execution stops again immediately if there is a
|
|
breakpoint there. See section <A HREF="gdb_8.html#SEC53">7.2 Specifying a Location</A>, for a description of the
|
|
different forms of <VAR>linespec</VAR> and <VAR>location</VAR>. It is common
|
|
practice to use the <CODE>tbreak</CODE> command in conjunction with
|
|
<CODE>jump</CODE>. See section <A HREF="gdb_6.html#SEC33">Setting Breakpoints</A>.
|
|
<P>
|
|
|
|
The <CODE>jump</CODE> command does not change the current stack frame, or
|
|
the stack pointer, or the contents of any memory location or any
|
|
register other than the program counter. If line <VAR>linespec</VAR> 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 <CODE>jump</CODE> 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.
|
|
</DL>
|
|
<P>
|
|
|
|
On many systems, you can get much the same effect as the <CODE>jump</CODE>
|
|
command by storing a new value into the register <CODE>$pc</CODE>. The
|
|
difference is that this does not start your program running; it only
|
|
changes the address of where it <EM>will</EM> run when you continue. For
|
|
example,
|
|
</P><P>
|
|
|
|
<TABLE><tr><td> </td><td class=smallexample><FONT SIZE=-1><pre>set $pc = 0x485
|
|
</FONT></pre></td></tr></table></P><P>
|
|
|
|
makes the next <CODE>continue</CODE> command or stepping command execute at
|
|
address <CODE>0x485</CODE>, rather than at the address where your program stopped.
|
|
See section <A HREF="gdb_6.html#SEC43">Continuing and Stepping</A>.
|
|
</P><P>
|
|
|
|
The most common occasion to use the <CODE>jump</CODE> 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.
|
|
</P><P>
|
|
|
|
<A NAME="Signaling"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC150"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC149"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC151"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC151"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<H2> 14.3 Giving your Program a Signal </H2>
|
|
<!--docid::SEC150::-->
|
|
<P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX686"></A>
|
|
<DT><CODE>signal <VAR>signal</VAR></CODE>
|
|
<DD>Resume execution where your program stopped, but immediately give it the
|
|
signal <VAR>signal</VAR>. <VAR>signal</VAR> can be the name or the number of a
|
|
signal. For example, on many systems <CODE>signal 2</CODE> and <CODE>signal
|
|
SIGINT</CODE> are both ways of sending an interrupt signal.
|
|
<P>
|
|
|
|
Alternatively, if <VAR>signal</VAR> is zero, continue execution without
|
|
giving a signal. This is useful when your program stopped on account of
|
|
a signal and would ordinary see the signal when resumed with the
|
|
<CODE>continue</CODE> command; <SAMP>`signal 0'</SAMP> causes it to resume without a
|
|
signal.
|
|
</P><P>
|
|
|
|
<CODE>signal</CODE> does not repeat when you press <KBD>RET</KBD> a second time
|
|
after executing the command.
|
|
</DL>
|
|
<P>
|
|
|
|
Invoking the <CODE>signal</CODE> command is not the same as invoking the
|
|
<CODE>kill</CODE> utility from the shell. Sending a signal with <CODE>kill</CODE>
|
|
causes GDB to decide what to do with the signal depending on
|
|
the signal handling tables (see section <A HREF="gdb_6.html#SEC44">5.3 Signals</A>). The <CODE>signal</CODE> command
|
|
passes the signal directly to your program.
|
|
</P><P>
|
|
|
|
<A NAME="Returning"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC151"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC150"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC152"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC152"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<H2> 14.4 Returning from a Function </H2>
|
|
<!--docid::SEC151::-->
|
|
<P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX687"></A>
|
|
<A NAME="IDX688"></A>
|
|
<DT><CODE>return</CODE>
|
|
<DD><DT><CODE>return <VAR>expression</VAR></CODE>
|
|
<DD>You can cancel execution of a function call with the <CODE>return</CODE>
|
|
command. If you give an
|
|
<VAR>expression</VAR> argument, its value is used as the function's return
|
|
value.
|
|
</DL>
|
|
<P>
|
|
|
|
When you use <CODE>return</CODE>, GDB discards the selected stack frame
|
|
(and all frames within it). You can think of this as making the
|
|
discarded frame return prematurely. If you wish to specify a value to
|
|
be returned, give that value as the argument to <CODE>return</CODE>.
|
|
</P><P>
|
|
|
|
This pops the selected stack frame (see section <A HREF="gdb_7.html#SEC49">Selecting a Frame</A>), and any other frames inside of it, leaving its caller as the
|
|
innermost remaining frame. That frame becomes selected. The
|
|
specified value is stored in the registers used for returning values
|
|
of functions.
|
|
</P><P>
|
|
|
|
The <CODE>return</CODE> command does not resume execution; it leaves the
|
|
program stopped in the state that would exist if the function had just
|
|
returned. In contrast, the <CODE>finish</CODE> command (see section <A HREF="gdb_6.html#SEC43">Continuing and Stepping</A>) resumes execution until the
|
|
selected stack frame returns naturally.
|
|
</P><P>
|
|
|
|
<A NAME="Calling"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC152"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC151"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC153"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC153"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<H2> 14.5 Calling Program Functions </H2>
|
|
<!--docid::SEC152::-->
|
|
<P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX689"></A>
|
|
<A NAME="IDX690"></A>
|
|
<DT><CODE>print <VAR>expr</VAR></CODE>
|
|
<DD>Evaluate the expression <VAR>expr</VAR> and display the resulting value.
|
|
<VAR>expr</VAR> may include calls to functions in the program being
|
|
debugged.
|
|
<P>
|
|
|
|
<A NAME="IDX691"></A>
|
|
<DT><CODE>call <VAR>expr</VAR></CODE>
|
|
<DD>Evaluate the expression <VAR>expr</VAR> without displaying <CODE>void</CODE>
|
|
returned values.
|
|
<P>
|
|
|
|
You can use this variant of the <CODE>print</CODE> command if you want to
|
|
execute a function from your program that does not return anything
|
|
(a.k.a. <EM>a void function</EM>), but without cluttering the output
|
|
with <CODE>void</CODE> returned values that GDB will otherwise
|
|
print. If the result is not void, it is printed and saved in the
|
|
value history.
|
|
</DL>
|
|
<P>
|
|
|
|
It is possible for the function you call via the <CODE>print</CODE> or
|
|
<CODE>call</CODE> command to generate a signal (e.g., if there's a bug in
|
|
the function, or if you passed it incorrect arguments). What happens
|
|
in that case is controlled by the <CODE>set unwindonsignal</CODE> command.
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<DT><CODE>set unwindonsignal</CODE>
|
|
<DD><A NAME="IDX692"></A>
|
|
<A NAME="IDX693"></A>
|
|
<A NAME="IDX694"></A>
|
|
Set unwinding of the stack if a signal is received while in a function
|
|
that GDB called in the program being debugged. If set to on,
|
|
GDB unwinds the stack it created for the call and restores
|
|
the context to what it was before the call. If set to off (the
|
|
default), GDB stops in the frame where the signal was
|
|
received.
|
|
<P>
|
|
|
|
<DT><CODE>show unwindonsignal</CODE>
|
|
<DD><A NAME="IDX695"></A>
|
|
Show the current setting of stack unwinding in the functions called by
|
|
GDB.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="IDX696"></A>
|
|
Sometimes, a function you wish to call is actually a <EM>weak alias</EM>
|
|
for another function. In such case, GDB might not pick up
|
|
the type information, including the types of the function arguments,
|
|
which causes GDB to call the inferior function incorrectly.
|
|
As a result, the called function will function erroneously and may
|
|
even crash. A solution to that is to use the name of the aliased
|
|
function instead.
|
|
</P><P>
|
|
|
|
<A NAME="Patching"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC153"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC152"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<H2> 14.6 Patching Programs </H2>
|
|
<!--docid::SEC153::-->
|
|
<P>
|
|
|
|
<A NAME="IDX697"></A>
|
|
<A NAME="IDX698"></A>
|
|
<A NAME="IDX699"></A>
|
|
</P><P>
|
|
|
|
By default, GDB opens the file containing your program's
|
|
executable code (or the corefile) read-only. This prevents accidental
|
|
alterations to machine code; but it also prevents you from intentionally
|
|
patching your program's binary.
|
|
</P><P>
|
|
|
|
If you'd like to be able to patch the binary, you can specify that
|
|
explicitly with the <CODE>set write</CODE> command. For example, you might
|
|
want to turn on internal debugging flags, or even to make emergency
|
|
repairs.
|
|
</P><P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX700"></A>
|
|
<DT><CODE>set write on</CODE>
|
|
<DD><DT><CODE>set write off</CODE>
|
|
<DD>If you specify <SAMP>`set write on'</SAMP>, GDB opens executable and
|
|
core files for both reading and writing; if you specify <SAMP>`set write
|
|
off'</SAMP> (the default), GDB opens them read-only.
|
|
<P>
|
|
|
|
If you have already loaded a file, you must load it again (using the
|
|
<CODE>exec-file</CODE> or <CODE>core-file</CODE> command) after changing <CODE>set
|
|
write</CODE>, for your new setting to take effect.
|
|
</P><P>
|
|
|
|
<DT><CODE>show write</CODE>
|
|
<DD><A NAME="IDX701"></A>
|
|
Display whether executable files and core files are opened for writing
|
|
as well as reading.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="GDB Files"></A>
|
|
<HR SIZE="6">
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC147"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC154"> >> </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb.html#SEC_Top">Top</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_toc.html#SEC_Contents">Contents</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_38.html#SEC764">Index</A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_abt.html#SEC_About"> ? </A>]</TD>
|
|
</TR></TABLE>
|
|
<BR>
|
|
<FONT SIZE="-1">
|
|
|
|
<address>
|
|
|
|
<p>Please send FSF & GNU inquiries & questions to <a
|
|
href="mailto:gnu@gnu.org">gnu@gnu.org</a>. There are also <a
|
|
href="http://www.gnu.org/home.html#ContactInfo">other ways to
|
|
contact</a> the FSF.</p>
|
|
|
|
<p>These pages are maintained by <a
|
|
href="http://www.gnu.org/software/gdb/">the GDB developers</a>.</p>
|
|
|
|
<p>Copyright Free Software Foundation, Inc., 59 Temple Place - Suite
|
|
330, Boston, MA 02111, USA.</p>
|
|
|
|
<p>Verbatim copying and distribution of this entire article is
|
|
permitted in any medium, provided this notice is preserved.</p>
|
|
|
|
</address>
|
|
|
|
This document was generated
|
|
by <I>GDB Administrator</I> on <I>March, 27 2008</I>
|
|
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
|
|
"><I>texi2html</I></A>
|
|
|
|
</BODY>
|
|
</HTML>
|