objdump/readelf get variables information

99封情书 提交于 2019-12-25 05:07:13

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/11039843/objdump-readelf-get-variables-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!