如何使用“目标远程”在 gdb 中重新运行该程序?

发布于 2024-07-06 01:47:50 字数 161 浏览 5 评论 0原文

当您在同一台计算机上的可执行文件上执行常规 gdb 会话时,您可以发出 run 命令,它将再次启动程序。

当您在嵌入式系统上运行 gdb 时,就像使用命令 target localhost:3210 一样,如何在不退出并重新启动 gdb 会话的情况下重新启动程序?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

豆芽 2024-07-13 01:47:50

“jump_start”是通常的方式。

"jump _start" is the usual way.

天暗了我发光 2024-07-13 01:47:50

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.

为你鎻心 2024-07-13 01:47:50

假设您正在嵌入式系统上运行 gdbserver。

您可以要求它重新启动程序,而不是使用 目标扩展远程

Presumably you are running gdbserver on the embedded system.

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

反差帅 2024-07-13 01:47:50

分步过程

远程:

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

本地:

# 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

在 Ubuntu 14.04 中测试。

也可以将 CLI 参数传递给程序:

gdbserver --multi :1234 ./myexec arg1 arg2

并且 ./myexec 部分消除了 set Remote exec-file ./myexec 的需要,但这有以下烦恼:

传递环境变量并更改工作目录而不重新启动:如何在不重新启动的情况下修改gdbserver --multi的环境变量和工作目录?

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:

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

澉约 2024-07-13 01:47:50

在 EFM32 Happy Gecko 上,所有建议都不适合我,因此以下是我从有关将 GDB 集成到 Eclipse 环境的文档中学到的内容。

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

这使我处于从 IDE 中点击重置时所期望的状态。

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.

驱逐舰岛风号 2024-07-13 01:47:50

您可以使用jump gdb命令。 为此,您可以检查您的启动脚本。
我的启动脚本有一个符号。

    .section  .text.Reset_Handler
  .weak  Reset_Handler
  .type  Reset_Handler, %function
Reset_Handler:  
   ldr   r0, =_estack
   mov   sp, r0          /* set stack pointer */

我想跳起来开始。 这就是我使用的原因:

jump Reset_Handler

You can use jump gdb command. For that, you can check your startup script.
My startup script has a symbol.

    .section  .text.Reset_Handler
  .weak  Reset_Handler
  .type  Reset_Handler, %function
Reset_Handler:  
   ldr   r0, =_estack
   mov   sp, r0          /* set stack pointer */

I wanted to jump to start. That's why I used:

jump Reset_Handler
五里雾 2024-07-13 01:47:50

如果您正在运行常规 gdb,您可以输入“运行”快捷方式“r”,gdb 会询问您是否要重新启动程序

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

浮生面具三千个 2024-07-13 01:47:50

不幸的是,我不知道如何重新启动应用程序并仍然保持会话。 解决方法是将 PC 设置回程序的入口点。 您可以通过调用:

jump function

set $pc=address 来完成此操作。

如果您将参数修改为 main,您可能需要再次设置它们。

编辑:

上述方法有一些警告可能会导致问题。

  • 如果您在多线程程序中跳转到main,则会将当前线程跳转到main,所有其他线程保持不变。 如果当前线程持有锁......那么你就会遇到一些问题。
  • 内存泄漏,如果您的程序流在初始化期间分配了一些东西,那么您只是在跳转时泄漏了一堆内存。
  • 打开的文件仍将保持打开状态。 如果您映射某些文件或地址,调用很可能会失败。

因此,使用跳转与重新启动程序不同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文