Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / mingw / info / gdb / Debug-Session.html
blob177c1fca087ea67602ae8acc2ab36853acc90b80
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="Debug%20Session">Debug Session</a>,
13 Previous:<a rel="previous" accesskey="p" href="Bootstrapping.html#Bootstrapping">Bootstrapping</a>,
14 Up:<a rel="up" accesskey="u" href="remote-stub.html#remote%20stub">remote stub</a>
15 <hr><br>
16 </div>
18 <h4 class="subsection">Putting it all together</h4>
20 <p>In summary, when your program is ready to debug, you must follow these
21 steps.
23 <ol type=1 start=1>
24 <li>Make sure you have defined the supporting low-level routines
25 (see <a href="Bootstrapping.html#Bootstrapping">What you must do for the stub</a>):
26 <pre class="display"> <code>getDebugChar</code>, <code>putDebugChar</code>,
27 <code>flush_i_cache</code>, <code>memset</code>, <code>exceptionHandler</code>.
28 </pre>
30 <li>Insert these lines near the top of your program:
32 <pre class="example"> set_debug_traps();
33 breakpoint();
34 </pre>
36 <li>For the 680x0 stub only, you need to provide a variable called
37 <code>exceptionHook</code>. Normally you just use:
39 <pre class="example"> void (*exceptionHook)() = 0;
40 </pre>
42 <p>but if before calling <code>set_debug_traps</code>, you set it to point to a
43 function in your program, that function is called when
44 <code>GDB</code> continues after stopping on a trap (for example, bus
45 error). The function indicated by <code>exceptionHook</code> is called with
46 one parameter: an <code>int</code> which is the exception number.
48 </p><li>Compile and link together: your program, the GDB debugging stub for
49 your target architecture, and the supporting subroutines.
51 <li>Make sure you have a serial connection between your target machine and
52 the GDB host, and identify the serial port on the host.
54 <li>Download your program to your target machine (or get it there by
55 whatever means the manufacturer provides), and start it.
57 <li>To start remote debugging, run GDB on the host machine, and specify
58 as an executable file the program that is running in the remote machine.
59 This tells GDB how to find your program's symbols and the contents
60 of its pure text.
62 <li>Establish communication using the <code>target remote</code> command.
63 Its argument specifies how to communicate with the target
64 machine--either via a devicename attached to a direct serial line, or a
65 TCP port (usually to a terminal server which in turn has a serial line
66 to the target). For example, to use a serial line connected to the
67 device named <code>/dev/ttyb</code>:
69 <pre class="example"> target remote /dev/ttyb
70 </pre>
72 <p>To use a TCP connection, use an argument of the form
73 <code></code><var>host</var><code>:port</code>. For example, to connect to port 2828 on a
74 terminal server named <code>manyfarms</code>:
76 <pre class="example"> target remote manyfarms:2828
77 </pre>
79 <p>If your remote target is actually running on the same machine as
80 your debugger session (e.g. a simulator of your target running on
81 the same host), you can omit the hostname. For example, to connect
82 to port 1234 on your local machine:
84 <pre class="example"> target remote :1234
85 </pre>
87 <p>Note that the colon is still required here.
88 </ol>
90 <p>Now you can use all the usual commands to examine and change data and to
91 step and continue the remote program.
93 <p>To resume the remote program and stop debugging it, use the <code>detach</code>
94 command.
96 <p>Whenever GDB is waiting for the remote program, if you type the
97 interrupt character (often &lt;C-C&gt;), GDB attempts to stop the
98 program. This may or may not succeed, depending in part on the hardware
99 and the serial drivers the remote system uses. If you type the
100 interrupt character once again, GDB displays this prompt:
102 <pre class="example"> Interrupted while waiting for the program.
103 Give up (and stop debugging it)? (y or n)
104 </pre>
106 <p>If you type <kbd>y</kbd>, GDB abandons the remote debugging session.
107 (If you decide you want to try again later, you can use <code>target
108 remote</code> again to connect once more.) If you type <kbd>n</kbd>, GDB
109 goes back to waiting.
111 </body></html>