Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / mingw / info / gdb / Machine-Code.html
blob5cafe9fbb532be3addcd1c09a5622f51a3509e50
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="Machine%20Code">Machine Code</a>,
13 Previous:<a rel="previous" accesskey="p" href="Source-Path.html#Source%20Path">Source Path</a>,
14 Up:<a rel="up" accesskey="u" href="Source.html#Source">Source</a>
15 <hr><br>
16 </div>
18 <h3 class="section">Source and machine code</h3>
20 <p>You can use the command <code>info line</code> to map source lines to program
21 addresses (and vice versa), and the command <code>disassemble</code> to display
22 a range of addresses as machine instructions. When run under <small>GNU</small> Emacs
23 mode, the <code>info line</code> command causes the arrow to point to the
24 line specified. Also, <code>info line</code> prints addresses in symbolic form as
25 well as hex.
27 <dl>
28 <dt><code>info line </code><var>linespec</var><code></code>
29 <dd>Print the starting and ending addresses of the compiled code for
30 source line <var>linespec</var>. You can specify source lines in any of
31 the ways understood by the <code>list</code> command (see <a href="List.html#List">Printing source lines</a>).
32 </dl>
34 <p>For example, we can use <code>info line</code> to discover the location of
35 the object code for the first line of function
36 <code>m4_changequote</code>:
38 <pre class="smallexample"> (gdb) info line m4_changequote
39 Line 895 of "builtin.c" starts at pc 0x634c and ends at 0x6350.
40 </pre>
42 <p>We can also inquire (using <code>*</code><var>addr</var><code></code> as the form for
43 <var>linespec</var>) what source line covers a particular address:
44 <pre class="smallexample"> (gdb) info line *0x63ff
45 Line 926 of "builtin.c" starts at pc 0x63e4 and ends at 0x6404.
46 </pre>
48 <p>After <code>info line</code>, the default address for the <code>x</code> command
49 is changed to the starting address of the line, so that <code>x/i</code> is
50 sufficient to begin examining the machine code (see <a href="Memory.html#Memory">Examining memory</a>). Also, this address is saved as the value of the
51 convenience variable <code>$_</code> (see <a href="Convenience-Vars.html#Convenience%20Vars">Convenience variables</a>).
53 <dl>
54 <dt><code>disassemble</code>
55 <dd>This specialized command dumps a range of memory as machine
56 instructions. The default memory range is the function surrounding the
57 program counter of the selected frame. A single argument to this
58 command is a program counter value; GDB dumps the function
59 surrounding this value. Two arguments specify a range of addresses
60 (first inclusive, second exclusive) to dump.
61 </dl>
63 <p>The following example shows the disassembly of a range of addresses of
64 HP PA-RISC 2.0 code:
66 <pre class="smallexample"> (gdb) disas 0x32c4 0x32e4
67 Dump of assembler code from 0x32c4 to 0x32e4:
68 0x32c4 &lt;main+204&gt;: addil 0,dp
69 0x32c8 &lt;main+208&gt;: ldw 0x22c(sr0,r1),r26
70 0x32cc &lt;main+212&gt;: ldil 0x3000,r31
71 0x32d0 &lt;main+216&gt;: ble 0x3f8(sr4,r31)
72 0x32d4 &lt;main+220&gt;: ldo 0(r31),rp
73 0x32d8 &lt;main+224&gt;: addil -0x800,dp
74 0x32dc &lt;main+228&gt;: ldo 0x588(r1),r26
75 0x32e0 &lt;main+232&gt;: ldil 0x3000,r31
76 End of assembler dump.
77 </pre>
79 <p>Some architectures have more than one commonly-used set of instruction
80 mnemonics or other syntax.
82 <dl>
83 <dt><code>set disassembly-flavor </code><var>instruction-set</var><code></code>
84 <dd>Select the instruction set to use when disassembling the
85 program via the <code>disassemble</code> or <code>x/i</code> commands.
87 <p>Currently this command is only defined for the Intel x86 family. You
88 can set <var>instruction-set</var> to either <code>intel</code> or <code>att</code>.
89 The default is <code>att</code>, the AT&amp;T flavor used by default by Unix
90 assemblers for x86-based targets.
91 </dl>
93 </body></html>