如何获取BIT_FIELD_REF引用的位域的名称?

发布于 2025-01-06 23:36:18 字数 230 浏览 1 评论 0原文

我想获取从 GENERIC 表示中声明它的字段的名称。我有一个 BIT_FIELD_REF 树,它的 DECL_NAME 为零。例如,

struct {
    int a;
    unsigned b:1;
} s;

...
if (s.b)
    ...

对于 sb,我将得到一个 BIT_FIELD_REF,但没有明显的方法来获取“b”,即字段的原始名称。怎么做呢?

I want to get the name of the field with which it was declared from GENERIC representation. I have a BIT_FIELD_REF tree and it's DECL_NAME is zero. For example,

struct {
    int a;
    unsigned b:1;
} s;

...
if (s.b)
    ...

For s.b I'll get a BIT_FIELD_REF and there's no obvious way to get the “b”, which is the original name of the field. How to do it?

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

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

发布评论

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

评论(2

埋葬我深情 2025-01-13 23:36:18

尝试从 GDB 调用 debug_c_tree (tree_var) 或调用 debug_tree (tree_var) ,看看是否知道名称。如果是这样,对漂亮的打印机进行逆向工程。

Try call debug_c_tree (tree_var) or call debug_tree (tree_var) from GDB, and see if that knows the name. If it does, reverse engineer the pretty-printer.

半岛未凉 2025-01-13 23:36:18

我到底做了什么:调查 tree-dump.c 中的内容,我最终了解到已知的位字段的名称来自结构体的 DIE,并且很难跟踪。

然后我决定从 BIT_FIELD_REF 参数 0(对结构的引用)类型获取名称,即 RECORD_TYPE ,它存储所有字段的大小和偏移量。

问题是要理解 BIT_FIELD_REF 并不引用位本身:它的使用方式类似于 BIT_FIELD_REF & INTEGER_CST,其中常量的作用类似于掩码。了解这一点后,我快速计算了偏移量并从类型中获取了名称。

What exactly did I do: investigating stuff in tree-dump.c I ended up understanding that names of the bit fields where they're known were coming from struct's DIEs and were hard to track.

Then I decided to get the name from the BIT_FIELD_REF argument 0 (reference to structure) type, which is RECORD_TYPE and it stores all the fields' sizes and offsets.

Problem was to understand that BIT_FIELD_REF doesn't reference the bits itself: it is used like BIT_FIELD_REF & INTEGER_CST, where constant acts like mask. After understanding this, I quickly computed the offsets and got the name from the type.

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