简体   繁体   English

从调试信息中获取变量类型

[英]retrieving variable type from debug info

Consider : 考虑:

int x[] = {1, 2, 3};

int main(){
    return 0;
}

If we do an objdump of the data section, we will get the variable x with the starting address and the size as (4*3) bytes. 如果对数据段进行objdump,则将获得变量x,其起始地址为(4 * 3)字节。 Is there any easy way to retrieve the information that x was an array and of what type? 有什么简单的方法可以检索x是数组以及什么类型的信息?

I know we can do this using dwarfdump -i a.out and then parse the result to achieve the same, but is there anything easier which can be done. 我知道我们可以使用dwarfdump -i a.out进行此操作,然后解析结果以实现相同效果,但是有什么容易做的。 I just need to check if it was an array and of what type ? 我只需要检查它是否是数组以及什么类型?

Regards, 问候,

pankaj 潘卡

You can use the DWARF-reading libraries in elfutils to parse the DWARF, find the variable, and then decode its type. 您可以使用elfutils中的DWARF读取库来解析DWARF,找到变量,然后解码其类型。 This is non-trivial but the libraries do help a bit. 这是不平凡的,但是库确实有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM