如何设置 Eclipse 使用 gdbserver 进行远程 C 调试?
我对 Eclipse 还很陌生。尝试设置进行远程调试。
这是情况,我正在连接到运行 Linux 的远程计算机,我正在运行 Windows。
1)我已经安装了Eclipse所需的所有工具,并且能够连接到Linux机器。
2) 远程计算机有 gdbserver
linux1[1]% gdbserver
Usage: gdbserver [OPTIONS] COMM PROG [ARGS ...]
gdbserver [OPTIONS] --attach COMM PID
gdbserver [OPTIONS] --multi COMM
COMM may either be a tty device (for serial debugging), or
HOST:PORT to listen for a TCP connection.
Options:
--debug Enable debugging output.
我需要在 gdbserver
中配置任何内容吗???
3)我还应该在Eclipse中配置什么?用于远程调试?
4)我的GDB版本与远程机器GDB不同有什么关系吗?
I am pretty new to Eclipse. Trying to set up to do remote debugging.
Here is situation, I am connecting to remote machine running Linux, I am running Windows.
1) I have installed all the necessary tool for Eclipse, and was able to connect to Linux machine.
2) Remote machine has gdbserver
linux1[1]% gdbserver
Usage: gdbserver [OPTIONS] COMM PROG [ARGS ...]
gdbserver [OPTIONS] --attach COMM PID
gdbserver [OPTIONS] --multi COMM
COMM may either be a tty device (for serial debugging), or
HOST:PORT to listen for a TCP connection.
Options:
--debug Enable debugging output.
Do I need to configure anything in gdbserver
???
3) What else should I configure in Eclipse ? for remote debugging ?
4) Does it matter that my GDB version is different from remote Machine GDB ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
CLI 健全性检查
在执行任何操作之前,请确保:
这个答案假设您可以在开发板上执行:
并在主机上执行:
然后正确地单步调试所有内容。
Eclipse 设置
在 Ubuntu 16.04 主机、Eclipse Oxygen 4.7.0(从网站下载)、
gdbserver
7.12、aarch64-linux-gnu-gdb
中测试7.6。我已成功使用以下所有方法:
手动
使用这种方法,我们必须在 Eclipse 上运行调试之前在目标上启动
gdbserver
。Pro:无需通过 Eclipse 配置 SSH 连接以允许 Eclipse 运行 gdbserver,这是另一个可能的故障点。
缺点:每次调试开始时,您都必须重新启动
gdbserver
。如果 Eclipse 理解 gdbserver --multi ,这个问题就可以克服,但我不认为它能理解?由于其简单性,我建议您首先使用此方法。
打开调试配置,然后创建一个新的“C / C++ 远程应用程序”。
在“Main”选项卡下:
像往常一样选择“Name”、“Project”和“C/C++ Application”以进行本地调试
在底部启动器中单击“选择其他”,选中“使用特定于配置的设置”并选择“GDB (DSF) 手动远程调试启动器”
我们这样做的原因:自动启动器首先使用 SSH 连接到开发板,并为您启动
gdbserver
。在“调试器”选项卡下:
“GDB 调试器”:与主机上 CLI 中使用的相同,本例中为
aarch64-linux-gnu-gdb
子选项卡“连接”:设置传递给主机的主机名和端口在 CLI 上(
board-hostname
和1234
)最后,像我们在 CLI 中所做的那样在目标上手动启动
gdbserver
:并正常从 Eclipse 启动调试器。
每次终止程序时都必须重新启动
gdbserver
。自动密码验证
对于具有固定公开密码的开发板来说,这是最好的方法。
它通过 SSH 和密码连接到目标,并且每次都会自动在目标上启动
gdbserver
,这非常方便!目标
gdbserver
stdout转到Eclipse“控制台”窗口,这进一步减少了窗口切换。在 Eclipse 集中:
对于 C/C++ 应用程序”到
/root/path/to/project/path/to/executable
使用公钥自动
与密码身份验证非常相似,不同之处在于您必须转到:“连接”、“新建”,然后选择“基于公钥的身份验证”
优点:
缺点:
,所以我更喜欢这种服务器方法 ,则
SSH 无需密码即可连接:
~/.ssh/authorized_keys
以包含来自主机的~/.ssh/id_rsa.pub
在使用此方法之前,请确保您的授权密钥可以在命令行中使用,即您现在应该能够执行以下操作:
无需输入任何密码。
CLI sanity check
Before you do anything, make sure you:
This answer supposes that you can do on the development board:
And on host:
and then step debug everything correctly.
Eclipse setup
Tested in Ubuntu 16.04 host, Eclipse Oxygen 4.7.0 (downloaded from website),
gdbserver
7.12,aarch64-linux-gnu-gdb
7.6.I have successfully used all of the following methods:
Manual
With this method, we have to launch
gdbserver
on the target before running debug on Eclipse.Pro: dispenses configuring SSH connections through Eclipse to allow Eclipse to run
gdbserver
, which is another possible point of failure.Con: you have to relaunch
gdbserver
every time debugging starts. This could be overcome if Eclipse understoodgdbserver --multi
, but I don't think it does?Due to its simplicity, I recommend that you get this method working first.
Open the debug configurations, then create a new "C / C++ Remote Application".
Under the tab "Main":
select the "Name", "Project" and "C/C++ Application" as usual for a local debug
at the bottom launcher, click "Select other", check "Use configuration specific settings" and pick "GDB (DSF) Manual Remote Debugging Launcher"
Why we do this: the automatic launcher first connects to the board with SSH and launches the
gdbserver
for you.Under the tab "Debugger":
"GDB debugger": same as used from CLI on host,
aarch64-linux-gnu-gdb
for this exampleSub-tab "Connection": set hostname and port as passed to the host on CLI (
board-hostname
and1234
)Finally, manually launch
gdbserver
on the target just as we did from the CLI:and start the debugger from Eclipse normally.
You have to restart
gdbserver
every time you terminate the program.Automatic with password auth
This is the best method for development boards, which have fixed publicly known passwords.
It connects to the target with SSH and a password, and launches
gdbserver
on the target automatically every time, which is super convenient!Target
gdbserver
stdout goes to the Eclipse "Console" window, which further reduces window switching.In Eclipse set:
for C/C++ Application" to
/root/path/to/project/path/to/executable
Automatic with public key
Very similar to the password authentication, except that you must go to: "Connection", "New", and choose "Public key based authentication"
Pros:
Cons:
so I would prefer this method for servers.
SSH can connect without a password if you:
~/.ssh/authorized_keys
on the target to contain the~/.ssh/id_rsa.pub
from the hostBefore using this method, make sure that your authorized keys work from the command line, i.e. you should now be able to do:
without typing any password.
gdbserver
需要更多参数。例如,输入gdbserver localhost:1337 yourprogram yourprogramarguments
并保持其运行。然后,在 Eclipse 中,为“C/C++ 应用程序”创建新的调试配置。在主选项卡的底部,选择
GDB (GSF) Remote System Process Launcher
作为启动器。在调试器选项卡上,选择gdbserver Debugger
作为调试器。在连接下,指定TCP
作为连接类型,并指定localhost:1337
作为地址。当您启动配置时,您可以通过在控制台中输入命令来控制远程gdb
。gdbserver
needs more arguments. For example, saygdbserver localhost:1337 yourprogram yourprogramarguments
and keep it running.Then, in Eclipse, create a new debug configuration for a "C/C++ Application". On the main tab, on the bottom, choose
GDB (GSF) Remote System Process Launcher
as launcher. On the debugger tab, choosegdbserver Debugger
as the debugger. Under connection, sayTCP
as connection type and givelocalhost:1337
as address. When you launch the configuration, you may control the remotegdb
by entering commands into the console.Eclipse 2019-03更新
在 Eclipse 2019 中,上述步骤不起作用,因为 Eclipse 更改了“C/C++ Remote Application”中的配置布局。
@Ciro 帖子的更新:
以下步骤对我有用:
在“调试配置”下
在“C/C++ 远程应用程序”下
在“Main”选项卡下:
在“调试器”选项卡下:
这些是我所做的唯一更改,以便之前的答案适用于我。
Update for Eclipse 2019-03
In eclipse 2019, the above steps didn't work, because Eclipse has changed the layout of the configuration in "C/C++ Remote Application".
Updates of @Ciro post:
The following steps worked with me:
Under "Debug Configurations"
Under "C / C++ Remote Application"
Under the tab "Main":
Under the tab "Debugger":
These are the only changes I made so that the previous answer works with me.