How do you start running the program over again in gdb with 'target remote'?

☆樱花仙子☆ 提交于 2019-11-30 13:43:20

问题


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?


回答1:


You are looking for Multi-Process Mode for gdbserver and set remote exec-file filename




回答2:


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.




回答3:


Presumably you are running gdbserver on the embedded system.

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




回答4:


"jump _start" is the usual way.




回答5:


For me the method described in 21.2 Sample GDB session startup works great. When I enter monitor reset halt later at the “(gdb)” prompt the target hardware is reset and I can re-start the application with c (= continue).

The load command can be omitted between the runs because there is no need to flash the program again and again.




回答6:


Step-by-step procedure

Remote:

# pwd contains cross-compiled ./myexec
gdbserver --multi :1234

Local:

# pwd also contains the same cross-compiled ./myexec
gdb -ex 'target extended-remote 192.168.0.1:1234' \
    -ex 'set remote exec-file ./myexec' \
    --args ./myexec arg1 arg2
(gdb) r
[Inferior 1 (process 1234) exited normally]
(gdb) r
[Inferior 1 (process 1235) exited normally]
(gdb) monitor exit

Tested in Ubuntu 14.04.

It is also possible to pass CLI arguments to the program as:

gdbserver --multi :1234 ./myexec arg1 arg2

and the ./myexec part removes the need for set remote exec-file ./myexec, but this has the following annoyances:

  • undocumented: https://sourceware.org/bugzilla/show_bug.cgi?id=21981
  • does not show on show args and does not persist across restarts: https://sourceware.org/bugzilla/show_bug.cgi?id=21980

Pass environment variables and change working directory without restart: How to modify the environment variables and working directory of gdbserver --multi without restarting it?




回答7:


If you are running regular gdb you can type 'run' shortcut 'r' and gdb asks you if you wish to restart the program




回答8:


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.

(gdb) mon reset 0
(gdb) continue
(gdb) continue

This puts me in the state that I would have expected when hitting reset from the IDE.



来源:https://stackoverflow.com/questions/75255/how-do-you-start-running-the-program-over-again-in-gdb-with-target-remote

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!