使用 gdb 和 gdbserver 从 Windows 远程调试 Linux 进程:Windows 端到底需要什么?

发布于 2024-09-14 20:37:05 字数 1336 浏览 3 评论 0原文

我正在 Windows 上运行 Eclipse CDT 来开发构建并运行的 C 代码。在远程 Linux 系统上进行了测试。目前,该代码从未在 Windows 上编译。

我可以使用 CDT 在 gdbserver 下的 Linux 目标上启动远程进程,然后从 Windows 主机附加 gdb。但是,gdb 立即失败,并出现以下错误:

warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default i386 settings.
[...]
Remote 'g' packet reply is too long: 74afe9bff0aee9bf02000000f4af4a00a0aee9bf[...]

两个 Linux 系统之间的调试工作正常,因此很明显我在 Windows 主机端做错了什么。我的具体问题是:

  • Cygwin 版本的 gdb 是否足以调试远程 Linux 进程,或者我是否需要特殊的跨 gdb 才能在 Windows 上运行它并与 Linux 进程一起使用?如果是这样,我在哪里可以得到这样的 gdb?

  • 使用 gdb 进行远程调试需要主机系统上有可用的符号。实现这一目标的最简单方法是什么?我是否可以将 Linux 目标上的构建生成的符号复制到 Windows 主机,还是必须在 Windows 上进行完整的构建?有没有办法避免此要求,以便我只能在目标上提供符号?

谢谢,

-R


更多信息RSE 常见问题提供了一些指针,但不幸的是我仍然被阻止。常见问题解答描述了两种方法:

  • 通过 ssh 在远程系统上启动 gdb 客户端。这里的问题是 CDT 调试启动器中的某些字段与本地系统相关(项目路径、可执行路径等)。
  • 构建/获取 gdb 的交叉调试版本,支持从 Windows 调试 Linux 进程。这里的问题是,关于如何实现这一目标的信息很少。

我还提出了 此问题CDT论坛

I am running Eclipse CDT on Windows to develop C code that is built & tested on remote Linux systems. Currently, the code is never compiled on Windows.

I am able to use CDT to begin the remote process on the Linux target under gdbserver, and then attach gdb from the Windows host. However, gdb immediately fails with errors like:

warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB.  Attempting to continue with the default i386 settings.
[...]
Remote 'g' packet reply is too long: 74afe9bff0aee9bf02000000f4af4a00a0aee9bf[...]

Debugging between two Linux systems works fine, so it's clear that I'm doing something wrong on the Windows host side. My specific questions are:

  • Is the Cygwin version of gdb sufficient to debug remote Linux processes, or do I need a special cross-gdb in order to run it on Windows and work with Linux processes? If so, is there anywhere can I get hold of such a gdb?

  • Remote debugging with gdb requires that symbols are available on the host system. What is the easiest way to achieve this? Can I just copy the symbols produced by the build on the Linux target to the Windows host, or do have to get a full build going on Windows? Is there a way to avoid this requirement, such that I can supply symbols only on the target?

Thanks,

-R


More info: The RSE FAQ provides some pointers, but unfortunately I'm still blocked. The FAQ describes two approaches:

  • Launch the gdb client on the remote system over ssh. Problem here is that certain fields in the CDT debug launcher are tied to the local system (project path, executable path etc...).
  • Build/obtain a cross-debugging version of gdb that supports debugging Linux processes from Windows. Problem here is that there's little info on how to achieve this.

I have also raised this issue on the CDT forum.

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

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

发布评论

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

评论(6

黎歌 2024-09-21 20:37:05

只需重建 gdb 并支持目标平台即可。您可以使用 Cygwin 来实现此目的。
RHEL 目标平台示例:

> wget http://ftp.gnu.org/gnu/gdb/gdb-<ver>.tar.xz
> tar -xJvf gdb-<ver>.tar.xz
> mkdir -p gdb-<ver>/build/x86_64-redhat-linux-gnu
> cd gdb-<ver>/build/x86_64-redhat-linux-gnu
> ../../configure --target=x86_64-redhat-linux-gnu
> make && make install
> x86_64-redhat-linux-gnu-gdb.exe --version

此后不要忘记重新配置您的工具链。
要获取目标配置名称,可以使用:

> echo ${BASH_VERSINFO[5]}

Just rebuild gdb with target platform supporting. You can use Cygwin for this.
Example for RHEL target platform:

> wget http://ftp.gnu.org/gnu/gdb/gdb-<ver>.tar.xz
> tar -xJvf gdb-<ver>.tar.xz
> mkdir -p gdb-<ver>/build/x86_64-redhat-linux-gnu
> cd gdb-<ver>/build/x86_64-redhat-linux-gnu
> ../../configure --target=x86_64-redhat-linux-gnu
> make && make install
> x86_64-redhat-linux-gnu-gdb.exe --version

Don't forget to reconfigure your toolchain after this.
To obtain the target configuration name, you can use:

> echo ${BASH_VERSINFO[5]}
恬淡成诗 2024-09-21 20:37:05

现在有一个插件
http://marketplace.eclipse.org/content/direct-remote-c-debugging

它允许您通过 ssh 在服务器上远程启动 gdb。它关心路径映射和其他事情。

您不需要远程运行 gdb 服务器

Now there is a plugin
http://marketplace.eclipse.org/content/direct-remote-c-debugging

Which allows you to launch gdb on the server remotely over ssh. It takes care about path mapping and others things.

You don't need gdb server to be running remotely

ペ泪落弦音 2024-09-21 20:37:05

我在 Windows 上构建失败,但发现在 Linux 下构建它非常容易。总结并完成@Eugene 的回复:
首先,准备源代码:

wget http://ftp.gnu.org/gnu/gdb/gdb-<ver>.tar.xz
tar -xJvf gdb-<ver>.tar.xz
mkdir -p gdb-<ver>/build/x86_64-redhat-linux-gnu
cd gdb-<ver>/build/x86_64-redhat-linux-gnu

下载 Windows 编译器:

sudo apt-get install mingw-w64

查看要调试二进制文件的目标配置平台(在 --target 参数中放入什么内容):

echo ${BASH_VERSINFO[5]}

准备针对所需平台但在不同主机上运行的 makefile。我们将其编译为静态,以便它不依赖于任何 DLL 或其他库。此外,我们还禁用构建其他二进制文件,如 gdb wiki 建议:

../../configure --host=x86_64-w64-mingw32 --target=x86_64-pc-linux-gnu --enable-static=yes --disable-interprocess-agent --disable-binutils --disable-ld --disable-gold --disable-gas --disable-sim --disable-gprof

最后,构建(大约需要 30-60 分钟) ):

make LDFLAGS=-static

您可以在 gdb 文件夹中找到您的调试器。删除它的调试符号也很好,因为构建可执行文件后会很大:

strip -s gdb/gdb.exe

瞧! gdb.exe 准备在 Windows 中运行并远程调试 Linux 可执行文件!

I failed to build on Windows, but found quite easy building it under Linux. To summarize and complete @Eugene response:
First, prepare sources:

wget http://ftp.gnu.org/gnu/gdb/gdb-<ver>.tar.xz
tar -xJvf gdb-<ver>.tar.xz
mkdir -p gdb-<ver>/build/x86_64-redhat-linux-gnu
cd gdb-<ver>/build/x86_64-redhat-linux-gnu

Download Windows compiler:

sudo apt-get install mingw-w64

Check out the target configuration platform you want to debug your binaries (what to put in --target parameter):

echo ${BASH_VERSINFO[5]}

Prepare makefiles targeted for your desired platform but running on different host. We compiling it static so that it doesn't depend on any DLLs or other libraries. Also we disabling building other binaries as gdb wiki suggests:

../../configure --host=x86_64-w64-mingw32 --target=x86_64-pc-linux-gnu --enable-static=yes --disable-interprocess-agent --disable-binutils --disable-ld --disable-gold --disable-gas --disable-sim --disable-gprof

finally, build (takes like 30-60 min):

make LDFLAGS=-static

You can find your debugger in gdb folder. It is also good to strip it of debugging symbols as after building executable is huge:

strip -s gdb/gdb.exe

Voila! gdb.exe ready to run in Windows and remotely debug Linux executables!

一梦浮鱼 2024-09-21 20:37:05

使用 gcc/gdb 设置交叉编译或交叉调试环境是一个非常困难的问题,而且它几乎从来都不是最有效的解决方案。在你的 Windows 机器上放置一个 Linux 虚拟机并在那里进行调试,工作量会少得多。如果您确实需要在“那边”进行调试,我建议您只使用 ssh 并使用命令行 gdb。如果您那里没有源代码,那么从您控制下的 Linux VM 进行远程调试将是实用的。

Setting up a cross-compile or cross-debug environment with gcc/gdb is a very difficult problem, and it's almost never the most efficient solution. Putting a linux VM on your windows box, and debugging there, will be much less work. If you need, really, to debug 'over there', I'd suggest just ssh-ing and using command-line gdb. If you can't have source over there, remote-debugging from a linux VM under your control would be practical.

何以心动 2024-09-21 20:37:05

Visual Studio Community Edition 2017 具有 GDB 交叉编译和调试工具。将此与 Linux 服务器或 Windows Linux 子系统结合起来,您可以可靠地为 Linux 系统开发 C 代码。查看 本指南。

Visual Studio Community Edition 2017 features GDB cross-compiling and debugging tools. Couple this with a Linux server or the Windows Linux sub-system and you can reliably develop C code for Linux systems. check out this guide.

爱她像谁 2024-09-21 20:37:05

一般来说,Linux 上的软件开发比 Windows 上的软件开发要容易得多。但这不是主题。

调试交叉编译的二进制文件时,重要的是使用交叉编译器中的 gdb,而不是主机 gdb。例如,您不能使用为 Windows 构建的 gdb 来调试 Linux 进程(当然可以,但不建议这样做)。您需要使用交叉编译器 gdb 来调试远程进程(它是用于构建二进制文件的同一工具链的一部分)。正如你所说,你从不在 Windows 上编译,我很确定这可能是你的问题。让它工作的最简单方法是在远程计算机上的命令行中使用 gdb,在其中进行编译,并通过 ssh 进行调试。

Software development is generally much easier on linux than it is on windows. But that's off topic.

What is important when you debug cross compiled binaries is that you use gdb from cross compiler - not host gdb. You can not for example use gdb built for windows to debug a linux process (well you can but it is not recommended). You need to use the cross compiler gdb to debug the remote process (which is part of the same toolchain that was used to build the binary). As you are saying that you never compile on windows, I'm pretty certain this could be your problem. The easiest way for you to get it working is to just use the gdb from command line on the remote machine, where you compile, and do your debugging over ssh.

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