使用 Eclipse CDT/RSE/RDT 远程调试 C++ 应用程序
我正在与 Eclipse(在 Windows 中)进行斗争,以使其连接到我的 Linux 机器并在那里远程编译和调试 C++ 代码.
I am fighting with Eclipse (in Windows) to make it connect to my Linux box and compile and debug C++ code there remotely.
我的工作:
- 已安装 CDT/RSE/RDT(Eclipse Juno、CDT 8.1.2、PTP(RDT) 6.0.4、RSE 3.4)
- rdt-server 在 Linux 机器上运行 (
perl ./daemon.pl 4075
) - 创建本地 C++ 项目(基于 Makefile)
- 编译和调试本地 C++ 项目
- 创建远程项目(使用Linux"连接到 rdt-server)
- 编译远程项目(基于 Makefile)
我可以做的一些手动操作(没有 Eclipse):
Some manual things I can do (without Eclipse):
- 远程"调试我编译的项目:
ssh mybox 'cd/path/to/project;gdb main'
- 启动一个gdbserver:
ssh mybox 'cd/path/to/project;gdbserver fqdn:10000 main'
什么不工作:在 Eclipse 中调试
- 通过C++ 应用程序"调试错误:未指定程序(因为我没有本地代码)
- 通过C++ 远程"调试错误:未指定程序(我需要本地代码吗?)
- 通过C++ attach"调试(调试器:gdbserver")
- 在 linuxbox 上运行的 gdbserver
- gdb 无法与 gdbserver 通信(cygwin gdb 7.5,linux gdb/gdbserver 7.3);警告:架构拒绝了目标提供的描述.
- debug via "C++ application" Error: Program not specified (because I have a no local code)
- debug via "C++ remote" Error: Program not specified (do I need local code for that?)
- debug via "C++ attach" (Debugger: "gdbserver")
- gdbserver running on linuxbox
- gdb can not talk to the gdbserver (cygwin gdb 7.5, linux gdb/gdbserver 7.3); warning: Architecture rejected target-supplied description.
其他可能导致问题的事情:
Other things that might cause problems:
- 我正在使用 MSYS/Git 提供的
ssh
二进制文件(不在PATH
上) - Cygwin 不在
PATH
- I am using the
ssh
binary provided with MSYS/Git (not onPATH
) - Cygwin is not on
PATH
我真的很想在 Eclipse 中为我的 C++ 项目进行远程调试.您对如何从这里开始有什么建议吗?
I really would like to do remote debugging in Eclipse for my C++ projects. Do you have any suggestions how to proceed from here?
推荐答案
使用 CLI 进行健全性检查
在您做任何事情之前,请确保您:
Before you do anything, make sure you:
- 正确交叉编译应用程序并使其运行.您不一定需要使用 Eclipse 来执行此操作.
- 从命令行让 GDB 远程调试正常工作
这个答案假设你可以在开发板上做:
This answer supposes that you can do on the development board:
sudo apt-get install gdbserver gdbserver :1234 path/to/executable
在主机上:
aarch64-linux-gnu-gdb -ex "target remote board-hostname:1234" -ex "file path/to/cross/compiled/executable" -ex 'tb main' -ex c
然后正确调试一切.
Eclipse 设置
在 Ubuntu 16.04 主机、Eclipse Oxygen 4.7.0(从网站下载)、
gdbserver
7.12、aarch64-linux-gnu-gdb
7.6 中测试.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:
- 手动
- 自动
- 密码验证
- 公钥认证
手动
使用此方法,我们必须在目标上启动
gdbserver
,然后再在 Eclipse 上运行调试.With this method, we have to launch
gdbserver
on the target before running debug on Eclipse.Pro:无需通过 Eclipse 配置 SSH 连接,让 Eclipse 能够
Pro: dispenses configuring SSH connections through Eclipse to allow Eclipse to
Con:每次调试开始时,您都必须重新启动
gdbserver
.如果 Eclipse 理解gdbserver --multi
,这可能会被克服,但我认为它不会?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.
打开调试配置,然后新建一个C/C++远程应用".
Open the debug configurations, then create a new "C / C++ Remote Application".
在主要"标签下:
像往常一样选择名称"、项目"和C/C++ 应用程序"进行本地调试
select the "Name", "Project" and "C/C++ Application" as usual for a local debug
在底部启动器中,单击选择其他",选中使用配置特定设置"并选择GDB (DSF) 手动远程调试启动器"
at the bottom launcher, click "Select other", check "Use configuration specific settings" and pick "GDB (DSF) Manual Remote Debugging Launcher"
我们这样做的原因:自动启动器首先通过 SSH 连接到开发板并为您启动
gdbserver
.Why we do this: the automatic launcher first connects to the board with SSH and launches the
gdbserver
for you.在调试器"选项卡下:
GDB 调试器":与主机 CLI 中使用的相同,
aarch64-linux-gnu-gdb
用于此示例
子选项卡连接":将主机名和端口设置为在 CLI 上传递给主机(
board-hostname
和1234
)Sub-tab "Connection": set hostname and port as passed to the host on CLI (
board-hostname
and1234
)最后,就像我们在 CLI 中所做的那样,在目标上手动启动
gdbserver
:Finally, manually launch
gdbserver
on the target just as we did from the CLI:gdbserver :1234 path/to/executable
并从 Eclipse 正常启动调试器.
and start the debugger from Eclipse normally.
每次终止程序时都必须重新启动
gdbserver
.You have to restart
gdbserver
every time you terminate the program.密码验证自动
这是固定公开密码的开发板的最佳方法.
This is the best method for development boards, which have fixed publicly known passwords.
它通过SSH和密码连接到目标,每次都自动在目标上启动
gdbserver
,超级方便!It connects to the target with SSH and a password, and launches
gdbserver
on the target automatically every time, which is super convenient!目标
gdbserver
标准输出到EclipseConsole"窗口,进一步减少窗口切换.Target
gdbserver
stdout goes to the Eclipse "Console" window, which further reduces window switching.在 Eclipse 集合中:
In Eclipse set:
- 解决安全存储无法保存主密码"错误,如下所述:如何解决安全存储无法保存主密码"在带有 SSH 密码调试连接的 Eclipse CDT 远程应用程序中?
- 将启动器设置为:自动远程调试启动器"
- 设置远程绝对文件路径用于 C/C++ 应用程序"到
/root/path/to/project/path/to/executable
- 连接"、新建",然后选择基于密码的身份验证"
使用公钥自动
与密码认证非常相似,不同之处在于你必须去:连接",新建",并选择基于公钥的认证"
Very similar to the password authentication, except that you must go to: "Connection", "New", and choose "Public key based authentication"
优点:
- 如果您有加密的私钥,则克服安全存储无法保存主密码"(不安全,但对
- 对于服务器,您可能已经设置了公钥
缺点:
- 第一次设置按键可能会造成伤害
- 无论何时开发板都必须重做密钥设置
如果您满足以下条件,SSH 无需密码即可连接:
SSH can connect without a password if you:
- 在目标上设置
~/.ssh/authorized_keys
以包含来自主机的~/.ssh/id_rsa.pub
- 在主机上有一个未加密的私钥,可以绕过我们的密码问题
- 正确设置讨厌的文件夹权限:https://unix.stackexchange.com/questions/36540/why-am-i-still-getting-a-password-prompt-with-ssh-with-public-key-authentication一个>
- set
~/.ssh/authorized_keys
on the target to contain the~/.ssh/id_rsa.pub
from the host - have a non encrypted private key on host, which bypasses our password woes
- set pesky folder permissions correctly: https://unix.stackexchange.com/questions/36540/why-am-i-still-getting-a-password-prompt-with-ssh-with-public-key-authentication
在使用此方法之前,请确保您的授权密钥可以在命令行中使用,即您现在应该能够:
Before using this method, make sure that your authorized keys work from the command line, i.e. you should now be able to do:
ssh user@host
无需输入任何密码.
更改进程的当前工作目录
如何使用Eclipse CDT中的gdbserver自动启动器远程调试时设置程序的当前工作目录?
相关文章