使用 gdb 调试 chroot 程序

Mos*_*hev 2 c++ linux debugging gdb chroot

我的情况是我必须调试的程序必须在 chrooted 环境中运行。现在我已经在另一个根目录中安装了 gdb 并复制了源代码,这适用于基本设置,但不是很方便,因为我每次进行更改和重新编译时都必须重新同步源代码,而且我必须复制我所有的 gdb 设置等等。

有什么方法可以在我的正常环境中运行调试器来调试在 chrooted 环境中运行的程序?我在 Arch Linux 上。

rod*_*igo 5

您可以使用远程调试:

在 chroot 中,您只需要通常的运行时和程序gdbserver。然后运行:

chroot$ gdbserver :8888 myprogram
Run Code Online (Sandbox Code Playgroud)

在开发环境中,从你运行的源目录下gdb连接到服务器

$ gdb myprogram
(gdb) target remote :8888
Run Code Online (Sandbox Code Playgroud)

然后就可以开始调试了。

我喜欢br main之前做,continue因为调试器会被停止_start,太早了,没有用。

PS:使用远程调试时请注意安全问题,因为 8888 是侦听 TCP 端口。