如何设置 Eclipse 使用 gdbserver 进行远程 C 调试?

发布于 2024-09-29 15:21:30 字数 639 浏览 4 评论 0原文

我对 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 技术交流群。

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

发布评论

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

评论(3

娇俏 2024-10-06 15:21:30

CLI 健全性检查

在执行任何操作之前,请确保:

这个答案假设您可以在开发板上执行:

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。

我已成功使用以下所有方法:

  • 手动
  • 自动
    • 密码验证
    • 公钥验证

手动

使用这种方法,我们必须在 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-hostname1234

    在此输入图像描述

    在此处输入图像描述

最后,像我们在 CLI 中所做的那样在目标上手动启动 gdbserver

gdbserver :1234 path/to/executable

并正常从 Eclipse 启动调试器。

每次终止程序时都必须重新启动gdbserver

自动密码验证

对于具有固定公开密码的开发板来说,这是最好的方法。

它通过 SSH 和密码连接到目标,并且每次都会自动在目标上启动 gdbserver,这非常方便!

目标gdbserver stdout转到Eclipse“控制台”窗口,这进一步减少了窗口切换。

在 Eclipse 集中:

使用公钥自动

与密码身份验证非常相似,不同之处在于您必须转到:“连接”、“新建”,然后选择“基于公钥的身份验证”

优点:

  • 克服了“安全存储无法保存主密码”的问题你有一个未加密的服务器私钥(不安全,但对开发板来说很好)
  • ,你可能已经设置了公钥

缺点:

  • 密钥设置可能会伤害第一次,
  • 每当开发板被核攻击时都必须重做密钥设置

,所以我更喜欢这种服务器方法 ,则

SSH 无需密码即可连接:

在使用此方法之前,请确保您的授权密钥可以在命令行中使用,即您现在应该能够执行以下操作:

ssh user@host

无需输入任何密码。

CLI sanity check

Before you do anything, make sure you:

This answer supposes that you can do on the development board:

sudo apt-get install gdbserver
gdbserver :1234 path/to/executable

And on host:

aarch64-linux-gnu-gdb \
  -ex "target remote board-hostname:1234" \
  -ex "file path/to/cross/compiled/executable" \
  -ex 'tb main' \
  -ex c

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
  • automatic
    • password auth
    • public key auth

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 understood gdbserver --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.

    enter image description here

Under the tab "Debugger":

  • "GDB debugger": same as used from CLI on host, aarch64-linux-gnu-gdb for this example

  • Sub-tab "Connection": set hostname and port as passed to the host on CLI (board-hostname and 1234)

    enter image description here

    enter image description here

Finally, manually launch gdbserver on the target just as we did from the CLI:

gdbserver :1234 path/to/executable

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:

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:

  • overcomes the "Secure storage was unable to save the master password" if you have an unencrypted private key (unsafe, but fine for devboards)
  • for servers, you likely have already setup the public key

Cons:

  • key setup may hurt the first time
  • must redo key setup whenever devboard is nuked

so I would prefer this method for servers.

SSH can connect without a password if you:

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

without typing any password.

伪心 2024-10-06 15:21:30

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, say gdbserver 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, choose gdbserver Debugger as the debugger. Under connection, say TCP as connection type and give localhost:1337 as address. When you launch the configuration, you may control the remote gdb by entering commands into the console.

小糖芽 2024-10-06 15:21:30

Eclipse 2019-03更新

在 Eclipse 2019 中,上述步骤不起作用,因为 Eclipse 更改了“C/C++ Remote Application”中的配置布局。

@Ciro 帖子的更新:

以下步骤对我有用:
在“调试配置”下
在“C/C++ 远程应用程序”下
在“Main”选项卡下:

  • 选择“Connection”==> “远程主机”。
  • 选择“新建”、“SSH”(在我的例子中),然后输入远程目标计算机的配置。
  • 在“C/C++ 应用程序的远程绝对文件路径:”中设置应用程序在目标/远程设备中的路径。

在“调试器”选项卡下:

  • 子选项卡“连接”已被删除。
  • 添加了新的子选项卡“Gdbserver 设置”。
  • 配置“Gdbserver path:”指向gdbserver的路径。就我而言,它是“/usr/bin/gdbserver”
  • 配置端口号

这些是我所做的唯一更改,以便之前的答案适用于我。

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":

  • select the "Connection" ==> "Remote Host".
  • select "New" , "SSH" (In my case) , then enter the configuration for your remote target machine.
  • in "Remote Absolute File Path for C/C++ Application:" set the path of the application in the target/remote device.

Under the tab "Debugger":

  • Sub-tab "Connection" has been removed.
  • New sub-tab "Gdbserver Settings" has been added.
  • Configure "Gdbserver path:" to point to the path of gdbserver. In my case it was "/usr/bin/gdbserver"
  • Configure port number

These are the only changes I made so that the previous answer works with me.

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