471 lines
22 KiB
HTML
471 lines
22 KiB
HTML
<HTML>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<!-- Created on November, 11 2002 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="SEC120"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_14.html#SEC119"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC121"> > </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#SEC127"> >> </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_35.html#SEC643">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::SEC120::-->
|
|
<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#SEC121">14.1 Assignment to variables</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC122">14.2 Continuing at a different address</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC123">14.3 Giving your program a signal</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC124">14.4 Returning from a function</A></TD><TD> </TD><TD ALIGN="left" VALIGN="TOP"></TD></TR>
|
|
<TR><TD ALIGN="left" VALIGN="TOP"><A HREF="gdb_15.html#SEC125">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#SEC126">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="SEC121"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC122"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC127"> >> </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_35.html#SEC643">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::SEC121::-->
|
|
<P>
|
|
|
|
<A NAME="IDX541"></A>
|
|
<A NAME="IDX542"></A>
|
|
To alter the value of a variable, evaluate an assignment expression.
|
|
See section <A HREF="gdb_9.html#SEC54">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#SEC92">Using GDB with Different Languages</A>, for more
|
|
information on operators in supported languages.
|
|
</P><P>
|
|
|
|
<A NAME="IDX543"></A>
|
|
<A NAME="IDX544"></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#SEC61">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#SEC54">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="SEC122"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC121"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC123"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC123"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC127"> >> </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_35.html#SEC643">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::SEC122::-->
|
|
<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="IDX545"></A>
|
|
<DT><CODE>jump <VAR>linespec</VAR></CODE>
|
|
<DD>Resume execution at line <VAR>linespec</VAR>. Execution stops again
|
|
immediately if there is a breakpoint there. See section <A HREF="gdb_8.html#SEC47">Printing source lines</A>, for a description of the different forms of
|
|
<VAR>linespec</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#SEC29">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.
|
|
</P><P>
|
|
|
|
<DT><CODE>jump *<VAR>address</VAR></CODE>
|
|
<DD>Resume execution at the instruction at address <VAR>address</VAR>.
|
|
</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#SEC38">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="SEC123"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC122"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC124"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC124"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC127"> >> </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_35.html#SEC643">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::SEC123::-->
|
|
<P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX546"></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#SEC39">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="SEC124"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC123"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC125"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC125"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC127"> >> </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_35.html#SEC643">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::SEC124::-->
|
|
<P>
|
|
|
|
<DL COMPACT>
|
|
<A NAME="IDX547"></A>
|
|
<A NAME="IDX548"></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#SEC44">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#SEC38">Continuing and stepping</A>) resumes execution until the
|
|
selected stack frame returns naturally.
|
|
</P><P>
|
|
|
|
<A NAME="Calling"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC125"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC124"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC126"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC126"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC127"> >> </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_35.html#SEC643">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::SEC125::-->
|
|
<P>
|
|
|
|
<A NAME="IDX549"></A>
|
|
<A NAME="IDX550"></A>
|
|
<DL COMPACT>
|
|
<DT><CODE>call <VAR>expr</VAR></CODE>
|
|
<DD>Evaluate the expression <VAR>expr</VAR> without displaying <CODE>void</CODE>
|
|
returned values.
|
|
</DL>
|
|
<P>
|
|
|
|
You can use this variant of the <CODE>print</CODE> command if you want to
|
|
execute a function from your program, but without cluttering the output
|
|
with <CODE>void</CODE> returned values. If the result is not void, it
|
|
is printed and saved in the value history.
|
|
</P><P>
|
|
|
|
<A NAME="Patching"></A>
|
|
<HR SIZE="6">
|
|
<A NAME="SEC126"></A>
|
|
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
|
|
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC125"> < </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC127"> > </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT"> <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_15.html#SEC120"> Up </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC127"> >> </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_35.html#SEC643">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::SEC126::-->
|
|
<P>
|
|
|
|
<A NAME="IDX551"></A>
|
|
<A NAME="IDX552"></A>
|
|
<A NAME="IDX553"></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="IDX554"></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="IDX555"></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#SEC120"> << </A>]</TD>
|
|
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="gdb_16.html#SEC127"> >> </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_35.html#SEC643">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>November, 11 2002</I>
|
|
using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
|
|
"><I>texi2html</I></A>
|
|
|
|
</BODY>
|
|
</HTML>
|