如何获取BIT_FIELD_REF引用的位域的名称?
我想获取从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试从 GDB 调用 debug_c_tree (tree_var) 或调用 debug_tree (tree_var) ,看看是否知道名称。如果是这样,对漂亮的打印机进行逆向工程。
Try
call debug_c_tree (tree_var)
orcall debug_tree (tree_var)
from GDB, and see if that knows the name. If it does, reverse engineer the pretty-printer.我到底做了什么:调查
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 isRECORD_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 likeBIT_FIELD_REF & INTEGER_CST
, where constant acts like mask. After understanding this, I quickly computed the offsets and got the name from the type.