<p>When you're doing a usual gdb session on an executable file on the same computer, you can give the run command and it will start the program over again.</p>
<p>When you're running gdb on an embedded system, as with the command <code>target localhost:3210</code>, how do you start the program over again without quitting and restarting your gdb session?</p>

[{'answer_id': 76727, 'author': 'Drew Frezell', 'author_id': 10954, 'author_profile': 'https://Stackoverflow.com/users/10954', 'pm_score': 3, 'selected': False, 'text': "<p>Unfortunately, I don't know of a way to restart the application and still maintain your session.  A workaround is to set the PC back to the entry point of your program.  You can do this by either calling:</p>\n\n<p><code>jump <em>function</em></code></p>\n\n<p>or </p>\n\n<p><code>set $pc=<em>address</em></code>.</p>\n\n<p>If you munged the arguments to <code>main</code> you may need set them up again.</p>\n\n<p>Edit:</p>\n\n<p>There are a couple of caveats with the above method that could cause problems.</p>\n\n<ul>\n<li>If you are in a multi-threaded program jumping to main will jump the current thread to main, all other threads remain.  If the current thread held a lock...then you have some problems.</li>\n<li>Memory leaks, if you program flow allocates some stuff during initialization then you just leaked a bunch of memory with the jump.</li>\n<li>Open files will still remain open.  If you mmap some files or an address, the call will most likely fail.</li>\n</ul>\n\n<p>So, using jump isn't the same thing as restarting the program.</p>\n"}, {'answer_id': 346019, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Presumably you are running gdbserver on the embedded system.</p>\n\n<p>You can ask it to restart your program instead of exiting with <a href="http://web.archive.org/web/20090605020212/http://sourceware.org/gdb/current/onlinedocs/gdb_19.html" rel="nofollow noreferrer">target extended-remote</a></p>\n'}, {'answer_id': 1640110, 'author': 'Michael Snyder', 'author_id': 404880, 'author_profile': 'https://Stackoverflow.com/users/404880', 'pm_score': 2, 'selected': False, 'text': '<p>"jump _start" is the usual way.</p>\n'}, {'answer_id': 5200638, 'author': 'pdileepa', 'author_id': 55376, 'author_profile': 'https://Stackoverflow.com/users/55376', 'pm_score': 5, 'selected': True, 'text': '<p>You are looking for <a href="http://sourceware.org/gdb/onlinedocs/gdb/Server.html" rel="noreferrer">Multi-Process Mode for gdbserver</a> and <a href="http://sourceware.org/gdb/onlinedocs/gdb/Remote-Configuration.html" rel="noreferrer"><code>set remote exec-file filename</code></a></p>\n'}, {'answer_id': 35966136, 'author': 'Jehandad', 'author_id': 3840400, 'author_profile': 'https://Stackoverflow.com/users/3840400', 'pm_score': 2, 'selected': False, 'text': "<p>If you are running regular gdb you can type 'run' shortcut 'r' and gdb asks you if you wish to restart the program</p>\n"}, {'answer_id': 42813624, 'author': 'hermannk', 'author_id': 3186936, 'author_profile': 'https://Stackoverflow.com/users/3186936', 'pm_score': 2, 'selected': False, 'text': '<p>For me the method described in <a href="http://openocd.org/doc/html/GDB-and-OpenOCD.html#Sample-GDB-session-startup" rel="nofollow noreferrer">21.2 Sample GDB session startup</a> works great. When I enter <code>monitor reset halt</code> later at the “(gdb)” prompt the target hardware is reset and I can re-start the application with <code>c</code> (= continue).</p>\n\n<p>The <code>load</code> command can be omitted between the runs because there is no need to flash the program again and again.</p>\n'}, {'answer_id': 44161527, 'author': 'Ciro Santilli OurBigBook.com', 'author_id': 895245, 'author_profile': 'https://Stackoverflow.com/users/895245', 'pm_score': 2, 'selected': False, 'text': '<p><strong>Step-by-step procedure</strong></p>\n\n<p>Remote:</p>\n\n<pre><code># pwd contains cross-compiled ./myexec\ngdbserver --multi :1234\n</code></pre>\n\n<p>Local:</p>\n\n<pre><code># pwd also contains the same cross-compiled ./myexec\ngdb -ex \'target extended-remote 192.168.0.1:1234\' \\\n    -ex \'set remote exec-file ./myexec\' \\\n    --args ./myexec arg1 arg2\n(gdb) r\n[Inferior 1 (process 1234) exited normally]\n(gdb) r\n[Inferior 1 (process 1235) exited normally]\n(gdb) monitor exit\n</code></pre>\n\n<p>Tested in Ubuntu 14.04.</p>\n\n<p>It is also possible to pass CLI arguments to the program as:</p>\n\n<pre><code>gdbserver --multi :1234 ./myexec arg1 arg2\n</code></pre>\n\n<p>and the <code>./myexec</code> part removes the need for <code>set remote exec-file ./myexec</code>, but this has the following annoyances:</p>\n\n<ul>\n<li>undocumented: <a href="https://sourceware.org/bugzilla/show_bug.cgi?id=21981" rel="nofollow noreferrer">https://sourceware.org/bugzilla/show_bug.cgi?id=21981</a></li>\n<li>does not show on <code>show args</code> and does not persist across restarts: <a href="https://sourceware.org/bugzilla/show_bug.cgi?id=21980" rel="nofollow noreferrer">https://sourceware.org/bugzilla/show_bug.cgi?id=21980</a></li>\n</ul>\n\n<p>Pass environment variables and change working directory without restart: <a href="https://stackoverflow.com/questions/45149858/how-to-modify-the-environment-variables-of-gdbserver-without-restarting-it">How to modify the environment variables and working directory of gdbserver --multi without restarting it?</a></p>\n'}, {'answer_id': 44786145, 'author': 'Steven Eckhoff', 'author_id': 2511892, 'author_profile': 'https://Stackoverflow.com/users/2511892', 'pm_score': 0, 'selected': False, 'text': '<p>On EFM32 Happy Gecko none of the suggestions would work for me, so here is what I have learned from the documentation on integrating GDB into the Eclipse environment.</p>\n\n<pre><code>(gdb) mon reset 0\n(gdb) continue\n(gdb) continue\n</code></pre>\n\n<p>This puts me in the state that I would have expected when hitting reset from the IDE.</p>\n'}, {'answer_id': 67924905, 'author': 'abhiarora', 'author_id': 5735010, 'author_profile': 'https://Stackoverflow.com/users/5735010', 'pm_score': 1, 'selected': False, 'text': "<p>You can use <code>jump</code> gdb command. For that, you can check your <code>startup</code> script.\nMy <code>startup script</code> has a symbol.</p>\n<pre><code>    .section  .text.Reset_Handler\n  .weak  Reset_Handler\n  .type  Reset_Handler, %function\nReset_Handler:  \n   ldr   r0, =_estack\n   mov   sp, r0          /* set stack pointer */\n</code></pre>\n<p>I wanted to jump to start. That's why I used:</p>\n<pre><code>jump Reset_Handler\n</code></pre>\n"}]
['https://Stackoverflow.com/questions/75255', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/11138/']