views:

475

answers:

3

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.

When you're running gdb on an embedded system, as with the command target localhost:3210', how do you start the program over again without quitting and restarting your gdb session?

+2  A: 

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:

jump function

or

set $pc=address.

If you munged the arguments to main you may need set them up again.

Edit:

There are a couple of caveats with the above method that could cause problems.

  • 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.
  • Memory leaks, if you program flow allocates some stuff during initialization then you just leaked a bunch of memory with the jump.
  • Open files will still remain open. If you mmap some files or an address, the call will most likely fail.

So, using jump isn't the same thing as restarting the program.

Drew Frezell
+1  A: 

Presumably you are running gdbserver on the embedded system.

You can ask it to restart your program instead of exiting with target extended-remote

Helpful, didn't now about target extended-mode. Thanks.
sstock
A: 

"jump _start" is the usual way.

Michael Snyder