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.