gdb\bfd:获取子变量地址或大小或偏移量

发布于 2024-09-15 17:35:17 字数 466 浏览 2 评论 0原文

我正在使用 gdb 和 libbfd 从 elf 文件中检索全局变量信息并显示它。 我可以从 libbfd 获取以下数据:全局变量名称、地址和大小。 我使用 gdb 和 gdb\MI 检索变量及其子变量的类型(ptype、whatis、-var-create 和 -var-list-children)。

如何从所有孩子的父母那里获取地址\大小\偏移量?

例如,

   type = struct {\n"
   unsigned char count;\n"
   unsigned char time;\n
   }\n

如果这种类型的变量 A 位于地址 0x000100 中,我想显示 A.count 位于 0x000100 中,大小为 0x1,A.time 位于 0x000101 中,大小为 0x1。

编辑: 我读到 gdb 可以读取 DWARF 信息,但我不知道如何从 gdb 获取此信息。

I'm using gdb and libbfd to retrieve global variables information from an elf file and show it.
I can get the following data from libbfd: Global Variable name, address and size.
I retrieve the type of the variables and its children using gdb and gdb\MI (ptype, whatis, -var-create & -var-list-children).

How can I get the address\size\offset from parent of all the children?

e.g

   type = struct {\n"
   unsigned char count;\n"
   unsigned char time;\n
   }\n

If a variable A of this type is in address 0x000100, I want to show that A.count is in 0x000100 with size 0x1 and A.time is in 0x000101 with size 0x1.

EDIT:
I've read that gdb can read the DWARF info, but I can't figure out how can I get this information from gdb.

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

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

发布评论

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

评论(1

梅窗月明清似水 2024-09-22 17:35:17

这就是我最终所做的。
为了获取大小,我使用了:

p sizeof(A.time)

为了获取地址,我使用了:

p /a &A.time

注意:这仅适用于大小大于 1 字节的变量。
为了能够获取位域大小和位偏移量,我必须根据 nabble 中提供的建议重新编译 GDB: 位域元素错误的地址?

Here's what I did eventually.
To get the size, I used:

p sizeof(A.time)

and to get the address I used:

p /a &A.time

NOTE: This only applies for variable of a size bigger then 1 byte.
To be able to get bitfields size and offset in bits, I had to recompile GDB according to the suggestion offered in nabble: Address of bitfield element bug?

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