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.
当您在同一台计算机上的可执行文件上执行常规gdb会话时,您可以提供运行命令,它将再次启动该程序。
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?
当您在嵌入式系统上运行gdb时,与命令target localhost:3210'一样,如何在不退出并重新启动gdb会话的情况下重新启动程序?
8 个解决方案
#1
10
You are looking for Multi-Process Mode for gdbserver and set remote exec-file filename
您正在寻找gdbserver的多进程模式并设置远程exec文件filename
#2
6
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:
不幸的是,我不知道如何重新启动应用程序并仍然维护您的会话。解决方法是将PC设置回程序的入口点。您可以通过以下方式执行此操作:
jump function
or
set $pc=address
.
If you munged the arguments to main
you may need set them up again.
如果您将参数传递给main,则可能需要再次设置它们。
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.
如果你在一个多线程程序中跳转到main会将当前线程跳转到main,所有其他线程都会保留。如果当前线程持有锁...那么你有一些问题。
内存泄漏,如果程序流在初始化期间分配一些东西,那么你只是通过跳转泄漏了一堆内存。
打开的文件仍将保持打开状态。如果您映射某些文件或地址,则呼叫很可能会失败。
So, using jump isn't the same thing as restarting the program.
因此,使用jump与重新启动程序不同。
#3
4
Presumably you are running gdbserver on the embedded system.
大概是你在嵌入式系统上运行gdbserver。
You can ask it to restart your program instead of exiting with target extended-remote
您可以要求它重新启动程序,而不是退出目标扩展遥控器
#4
2
"jump _start" is the usual way.
“jump _start”是通常的方式。
#5
1
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).
对我来说,21.2示例GDB会话启动中描述的方法效果很好。当我稍后在“(gdb)”提示符处输入监视器重置停止时,目标硬件将重置,我可以使用c(= continue)重新启动应用程序。
The load
command can be omitted between the runs because there is no need to flash the program again and again.
在运行之间可以省略load命令,因为不需要一次又一次地闪烁程序。
#6
1
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.
在Ubuntu 14.04中测试过。
It is also possible to pass CLI arguments to the program as:
也可以将CLI参数传递给程序:
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:
并且./myexec部分不需要设置远程exec文件./myexec,但这有以下烦恼:
- 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
不显示在show args上并且不会在重新启动时保持不变: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?
传递环境变量并更改工作目录而不重启:如何修改gdbserver的环境变量和工作目录--multi而不重新启动它?
#7
0
If you are running regular gdb you can type 'run' shortcut 'r' and gdb asks you if you wish to restart the program
如果你正在运行常规gdb,你可以输入'run'捷径'r',gdb会询问你是否要重启程序
#8
0
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.
在EFM32上,Happy Gecko没有任何建议对我有用,所以这里是我从将GDB集成到Eclipse环境的文档中学到的。
(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.
这使我处于从IDE进行重置时我预期的状态。
#1
10
You are looking for Multi-Process Mode for gdbserver and set remote exec-file filename
您正在寻找gdbserver的多进程模式并设置远程exec文件filename
#2
6
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:
不幸的是,我不知道如何重新启动应用程序并仍然维护您的会话。解决方法是将PC设置回程序的入口点。您可以通过以下方式执行此操作:
jump function
or
set $pc=address
.
If you munged the arguments to main
you may need set them up again.
如果您将参数传递给main,则可能需要再次设置它们。
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.
如果你在一个多线程程序中跳转到main会将当前线程跳转到main,所有其他线程都会保留。如果当前线程持有锁...那么你有一些问题。
内存泄漏,如果程序流在初始化期间分配一些东西,那么你只是通过跳转泄漏了一堆内存。
打开的文件仍将保持打开状态。如果您映射某些文件或地址,则呼叫很可能会失败。
So, using jump isn't the same thing as restarting the program.
因此,使用jump与重新启动程序不同。
#3
4
Presumably you are running gdbserver on the embedded system.
大概是你在嵌入式系统上运行gdbserver。
You can ask it to restart your program instead of exiting with target extended-remote
您可以要求它重新启动程序,而不是退出目标扩展遥控器
#4
2
"jump _start" is the usual way.
“jump _start”是通常的方式。
#5
1
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).
对我来说,21.2示例GDB会话启动中描述的方法效果很好。当我稍后在“(gdb)”提示符处输入监视器重置停止时,目标硬件将重置,我可以使用c(= continue)重新启动应用程序。
The load
command can be omitted between the runs because there is no need to flash the program again and again.
在运行之间可以省略load命令,因为不需要一次又一次地闪烁程序。
#6
1
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.
在Ubuntu 14.04中测试过。
It is also possible to pass CLI arguments to the program as:
也可以将CLI参数传递给程序:
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:
并且./myexec部分不需要设置远程exec文件./myexec,但这有以下烦恼:
- 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
不显示在show args上并且不会在重新启动时保持不变: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?
传递环境变量并更改工作目录而不重启:如何修改gdbserver的环境变量和工作目录--multi而不重新启动它?
#7
0
If you are running regular gdb you can type 'run' shortcut 'r' and gdb asks you if you wish to restart the program
如果你正在运行常规gdb,你可以输入'run'捷径'r',gdb会询问你是否要重启程序
#8
0
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.
在EFM32上,Happy Gecko没有任何建议对我有用,所以这里是我从将GDB集成到Eclipse环境的文档中学到的。
(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.
这使我处于从IDE进行重置时我预期的状态。