在 Java 中:以编程方式确定 C/C++ 的地址 给定 COFF/ELF/DWARF 可执行文件的变量

发布于 2024-07-16 11:52:45 字数 884 浏览 14 评论 0原文

这是我时不时遇到的情况:

对于不使用虚拟寻址的嵌入式系统,我有一个从 C 或 C++ 代码编译而成的可执行文件,其中包含调试信息。 它通常采用 COFF 或 ELF/DWARF(我把这两种搞混了)格式。

在运行时,在 PC 上,我想确定给定名称的变量的地址。 (例如“foo.bar[7].baz”)这允许我在嵌入式系统上读取/写入变量的值(给出超出本问题范围的调试协议)。 显然,任何基于堆栈或基于堆的变量都被淘汰,因为它们没有静态地址。

我之前曾用 C++ 为 TI 的 2800 系列 DSP 解析来自 TI 编译器的 COFF 文件,这有点痛苦。 我想知道是否有一个 Java 库已经可以完成这类事情,因为我在使用一两个其他处理器的可执行文件时也面临着同样的问题。


更新: (11/18/2009) 一个有希望的线索!

有人使用过 Eclipse CDT ELF 解析器吗?

(参见http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.cdt.doc.isv/reference/api/org/eclipse/cdt/ core/model/IBinary.html 对于 javadoc pgs 之一)

TI 的 Code Composer 4(基于 Eclipse)似乎使用了这个,所以看起来如果我能找出文档在哪里也许我可以使用它解决我的问题。

This is a situation I run into now and then:

For an embedded system which does not use virtual addressing, I have an executable file that was compiled from C or C++ code with debugging information included. It's usually in COFF or ELF/DWARF (I get those two mixed up) format.

At runtime, on a PC, I would like to determine the address of a variable given its name. (e.g. "foo.bar[7].baz") This allows me to read/write the variable's value on the embedded system (given a debugging protocol that is beyond the scope of this question). Obviously, any variables that are stack-based or heap-based are out since they don't have static addresses.

I've done this before myself in C++ to parse COFF files from TI's compiler for their 2800 series DSPs, and it was kind of a pain. I was wondering if there was a Java library out there that does this sort of thing already, since I'm facing the same thing with one or two other processors' executable files.


Update: (11/18/2009) A promising clue!

Has anyone out there used the Eclipse CDT ELF parser?

(See http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.cdt.doc.isv/reference/api/org/eclipse/cdt/core/model/IBinary.html for one of the javadoc pgs)

TI's Code Composer 4 (based on Eclipse) seems to use this, so it seems like if I can figure out where the documentation is maybe I can use that to solve my problem.

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

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

发布评论

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

评论(2

沫离伤花 2024-07-23 11:52:45

gdb 支持您的目标 CPU 吗?

如果是,那么实现调试协议并与目标对话的程序也可以实现 GDB远程串行协议并提供一个TCP套接字供gdb与之通信。

这种安排类似于

gdb <--gdb protocol--> java-prog <--你的调试协议--> target

要运行整个程序,假设您的目标已经在运行您的程序

  1. 运行 java-prog
  2. 运行 gdb your-executable 并连接到 java-prog

    (gdb) 目标远程 127.0.0.1:port

  3. 询问 gdb读取一个值

    (gdb) p foo.bar[7].baz

这被转换为发送到 java-prog 的 gdb 数据包通过 TCP。
java-prog 应该在 gdb 协议和您的自定义调试协议之间进行转换。

Does gdb support your target CPU?

If yes, your program that implements the debugging protocol and talks to the target could also implement the GDB Remote Serial Protocol and provide a TCP socket for gdb to communicate with.

The arrangement would be something like this

gdb <--gdb protocol--> java-prog <--your debug protocol--> target

To run the whole thing, assuming your target is already running your program

  1. Run java-prog
  2. Run gdb your-executable and connect to java-prog

    (gdb) target remote 127.0.0.1:port

  3. Ask gdb to read a value

    (gdb) p foo.bar[7].baz

This is translated to gdb packets which are sent to java-prog over TCP.
java-prog should do the translation between the gdb protocol and your custom debug protocol.

别念他 2024-07-23 11:52:45

您可以构建一个 JNI 接口,连接到为您的平台编译的 GNU binutils。 但是,如果 GPL 与您的软件许可证冲突,那么这将不是一个可行的解决方案。

You could build a JNI interface to GNU binutils compiled for your platform. However, if the GPL conflicts with your software's license, then this will not be a viable solution.

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