1

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. Is there any easy way to retrieve the information that x was an array and of what type?

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. I just need to check if it was an array and of what type ?

Regards,

pankaj

pankaj
  • 335
  • 4
  • 15
  • 1
    try this link: http://stackoverflow.com/questions/11003376/extract-global-variables-from-a-out-file – Tono Nam Jun 28 '12 at 15:09

1 Answers1

0

You can use the DWARF-reading libraries in elfutils to parse the DWARF, find the variable, and then decode its type. This is non-trivial but the libraries do help a bit.

Tom Tromey
  • 21,507
  • 2
  • 45
  • 63