1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>4.4.�Running Applications from GDB</title><link rel="stylesheet" href="cs.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"><link rel="home" href="index.html" title="Sourcery CodeBench Lite"><link rel="up" href="chap-building.html" title="Chapter�4.�Using Sourcery CodeBench from the Command Line"><link rel="prev" href="sec-gdbsimulator.html" title="4.3.�Running Applications in the Simulator"><link rel="next" href="chap-cs3.html" title="Chapter�5.�CS3™: The CodeSourcery Common Startup Code Sequence"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">4.4.�Running Applications from GDB</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="sec-gdbsimulator.html">Prev</a>�</td><th width="60%" align="center">Chapter�4.�Using Sourcery CodeBench from the Command Line</th><td width="20%" align="right">�<a accesskey="n" href="chap-cs3.html">Next</a></td></tr></table><hr></div><div class="section" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="sec-remote-debugging"></a>4.4.�Running Applications from GDB</h2></div></div></div><p> 2 You can run GDB, the GNU Debugger, on your host system 3 to debug programs running remotely on a target board or system. 4 <span> 5 You can also run and debug programs using the GDB simulator. 6 </span> 7 8 </p><p> 9 When starting GDB, give it the pathname to the program you want to 10 debug as a command-line argument. 11 For example, if you have built the factorial program as described in 12 <a class="xref" href="chap-building.html#sec-factorial-build" title="4.1.�Building an Application">Section�4.1, “Building an Application”</a>, enter: 13 </p><pre class="screen">> arm-none-eabi-gdb factorial</pre><p> 14 15 16 </p><p> 17 While this section explains the alternatives for using GDB to run 18 and debug application programs, explaining the use of the GDB 19 command-line interface is beyond the scope of this document. Please 20 refer to the GDB manual for further instructions. 21 </p><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id524646"></a>4.4.1.�Connecting to the GDB Simulator</h3></div></div></div><p> 22 GDB includes a simulator that allows you to debug ARM EABI 23 applications without target hardware. To start and connect to 24 the simulator from within GDB, use this command: 25 </p><pre class="screen">(gdb) target sim</pre><p> 26 </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id524666"></a>4.4.2.�Connecting to the Sourcery CodeBench Debug Sprite</h3></div></div></div><p> 27 The Sourcery CodeBench Debug Sprite is a program that runs on the host system to 28 support hardware debugging devices. You can use the Debug Sprite to 29 run and debug programs on a target board without an operating system, 30 or to debug an operating system kernel. See <a class="xref" href="sprite.html" title="Chapter�6.�Sourcery CodeBench Debug Sprite">Chapter�6, “Sourcery CodeBench Debug Sprite”</a> for 31 detailed information about the supported devices. 32 </p><p> 33 You can start the Sprite directly from within GDB: 34 </p><pre class="screen">(gdb) target remote | arm-none-eabi-sprite <em class="replaceable"><code>arguments</code></em></pre><p> 35 Refer to <a class="xref" href="sec-sprite-invocation.html" title="6.3.�Invoking Sourcery CodeBench Debug Sprite">Section�6.3, “Invoking Sourcery CodeBench Debug Sprite”</a> for a full 36 description of the Sprite arguments. 37 </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="connecting-to-gdbserver"></a>4.4.3.�Connecting to an External GDB Server</h3></div></div></div><p> 38 From within GDB, you can connect to a running <code class="command">gdbserver</code> 39 or other debugging stub that uses the GDB remote protocol using: 40 </p><pre class="screen">(gdb) target remote <em class="replaceable"><code>host</code></em>:<em class="replaceable"><code>port</code></em></pre><p> 41 where <em class="replaceable"><code>host</code></em> is the host name or IP address of the 42 machine the stub is running on, and <em class="replaceable"><code>port</code></em> is the 43 port number it is listening on for TCP connections. 44 </p></div><div class="section" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id524743"></a>4.4.4.�Loading and Running Applications</h3></div></div></div><p> 45 Connecting to a bare-metal target or simulator from GDB does not 46 cause your program to be loaded into target memory. 47 You must do this explicitly from GDB after you connect: 48 </p><pre class="screen">(gdb) load</pre><p> 49 <span></span> 50 Alternatively, you can use third-party tools to load your application 51 into flash memory before starting GDB. 52 </p><p> 53 To begin execution of your application, you should generally use the 54 <code class="command">continue</code> command: 55 </p><pre class="screen">(gdb) continue</pre><p> 56 <span> 57 However, you should use <code class="command">run</code> instead of 58 <code class="command">continue</code> to start your program if you used 59 <code class="command">target sim</code> to connect: 60 <pre class="screen">(gdb) run</pre> 61 </span> 62 </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="sec-gdbsimulator.html">Prev</a>�</td><td width="20%" align="center"><a accesskey="u" href="chap-building.html">Up</a></td><td width="40%" align="right">�<a accesskey="n" href="chap-cs3.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">4.3.�Running Applications in the Simulator�</td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top">�Chapter�5.�CS3™: The CodeSourcery Common Startup Code Sequence</td></tr></table></div></body></html> 63