Work around MinGW mangling of "host:/path"
[msysgit/historical-msysgit.git] / mingw / info / gdb / Assignment.html
blob82a90e42abc0392fef2c45b0fafd2bccf5b4a430
1 <html lang="en">
2 <head>
3 <title>Debugging with GDB</title>
4 <meta http-equiv="Content-Type" content="text/html">
5 <meta name="description" content="Debugging with GDB">
6 <meta name="generator" content="makeinfo 4.3">
7 <link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
8 </head>
9 <body>
10 <div class="node">
11 <p>
12 Node:<a name="Assignment">Assignment</a>,
13 Next:<a rel="next" accesskey="n" href="Jumping.html#Jumping">Jumping</a>,
14 Up:<a rel="up" accesskey="u" href="Altering.html#Altering">Altering</a>
15 <hr><br>
16 </div>
18 <h3 class="section">Assignment to variables</h3>
20 <p>To alter the value of a variable, evaluate an assignment expression.
21 See <a href="Expressions.html#Expressions">Expressions</a>. For example,
23 <pre class="example"> print x=4
24 </pre>
26 <p>stores the value 4 into the variable <code>x</code>, and then prints the
27 value of the assignment expression (which is 4).
28 See <a href="Languages.html#Languages">Using GDB with Different Languages</a>, for more
29 information on operators in supported languages.
31 <p>If you are not interested in seeing the value of the assignment, use the
32 <code>set</code> command instead of the <code>print</code> command. <code>set</code> is
33 really the same as <code>print</code> except that the expression's value is
34 not printed and is not put in the value history (see <a href="Value-History.html#Value%20History">Value history</a>). The expression is evaluated only for its effects.
36 <p>If the beginning of the argument string of the <code>set</code> command
37 appears identical to a <code>set</code> subcommand, use the <code>set
38 variable</code> command instead of just <code>set</code>. This command is identical
39 to <code>set</code> except for its lack of subcommands. For example, if your
40 program has a variable <code>width</code>, you get an error if you try to set
41 a new value with just <code>set width=13</code>, because GDB has the
42 command <code>set width</code>:
44 <pre class="example"> (gdb) whatis width
45 type = double
46 (gdb) p width
47 $4 = 13
48 (gdb) set width=47
49 Invalid syntax in expression.
50 </pre>
52 <p>The invalid expression, of course, is <code>=47</code>. In
53 order to actually set the program's variable <code>width</code>, use
55 <pre class="example"> (gdb) set var width=47
56 </pre>
58 <p>Because the <code>set</code> command has many subcommands that can conflict
59 with the names of program variables, it is a good idea to use the
60 <code>set variable</code> command instead of just <code>set</code>. For example, if
61 your program has a variable <code>g</code>, you run into problems if you try
62 to set a new value with just <code>set g=4</code>, because GDB has
63 the command <code>set gnutarget</code>, abbreviated <code>set g</code>:
65 <pre class="example"> (gdb) whatis g
66 type = double
67 (gdb) p g
68 $1 = 1
69 (gdb) set g=4
70 (gdb) p g
71 $2 = 1
72 (gdb) r
73 The program being debugged has been started already.
74 Start it from the beginning? (y or n) y
75 Starting program: /home/smith/cc_progs/a.out
76 "/home/smith/cc_progs/a.out": can't open to read symbols:
77 Invalid bfd target.
78 (gdb) show g
79 The current BFD target is "=4".
80 </pre>
82 <p>The program variable <code>g</code> did not change, and you silently set the
83 <code>gnutarget</code> to an invalid value. In order to set the variable
84 <code>g</code>, use
86 <pre class="example"> (gdb) set var g=4
87 </pre>
89 GDB allows more implicit conversions in assignments than C; you can
90 freely store an integer value into a pointer variable or vice versa,
91 and you can convert any structure to any other structure that is the
92 same length or shorter.
94 <p>To store values into arbitrary places in memory, use the <code>{...}</code>
95 construct to generate a value of specified type at a specified address
96 (see <a href="Expressions.html#Expressions">Expressions</a>). For example, <code>{int}0x83040</code> refers
97 to memory location <code>0x83040</code> as an integer (which implies a certain size
98 and representation in memory), and
100 <pre class="example"> set {int}0x83040 = 4
101 </pre>
103 <p>stores the value 4 into that memory location.
105 </body></html>