objdump / readelf获取变量信息 [英] objdump/readelf get variables information

查看:524
本文介绍了objdump / readelf获取变量信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从编译后的c程序中获取关于全局变量的信息。我在实用程序,它可以为您解析DWARF信息。


I need to get the information about global variables from a compiled c program. I asked a similar question in here.

The problem that I have now is that the program where I am trying to extract the variables info is very big and it takes 4 seconds just to get the tree in text (readelf -w[i] file.out). Then I have to parse the tree jumping back and forth in order to get to the place that I need. For example if a variable is of type const unsigned char * volatile MyVariable then I will have to navigate to 5 different nodes of the tree and if the program contains 1000 variables then it takes a while to get what I need.

So my question is how can I make better use of the readelf command to achieve what I need. The readelf -w[i] file.out command gives me way more information that I need (every function, subrutine, local variable, etc). For example instead of going over the output of that command to get the global variables I use the readelf -s --wide file.out command to get just the variables. that command will just give me the name of the variables so I will still have to look in the tree to see if a variable is an integer for example.

On page 237 of this link I belive there is an example of how to get info about a type for example. Here is a pic:

I am taking about 15 seconds to parse what I need and still have several bugs. It will be nice if I don't have to reinvent the wheel and make better use of the readelf command.

解决方案

You could try Andy Wingo's new dltool utility, which does all the parsing the DWARF info for you.

这篇关于objdump / readelf获取变量信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆