objdump/readelf get variables information
Asked Answered
S

1

0

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:

enter image description here

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.

Superintend answered 14/6, 2012 at 19:15 Comment(1)
Have you solved this? Are you just trying to make your parsing/extracting information from readelf faster?Valletta
P
0

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

Pourboire answered 26/6, 2012 at 22:1 Comment(1)
I need to parse it on windows... I might be able to compile that on windows I will give it a try.Superintend

© 2022 - 2024 — McMap. All rights reserved.