1

Assume a C module containing the following function definition:

void foo(int (*a)[6]){...}


Is it possible to extract the actual array size information '6' of parameter 'a' from the dwarf information (embedded in the resulting .o-file) obtained when compiling the source file with gcc -g?

I have applied 'readelf -wi' on the object file to obtain the dwarf information, but I cannot find any information to derive the fixed array size.

Blue Demon
  • 293
  • 3
  • 12

1 Answers1

1

It works ok for me using the Fedora 20 system gcc. Whether it works on other versions of gcc, I don't know... I don't recall specific changes in this area, but then gcc does change quite a bit.

Anyway, I compiled a snippet like the above using gcc -g. Then I examined it with "readelf -wi". This dumps the DWARF information. I see:

 <1><57>: Abbrev Number: 4 (DW_TAG_array_type)
    <58>   DW_AT_type        : <0x6e>   
    <5c>   DW_AT_sibling     : <0x67>   
 <2><60>: Abbrev Number: 5 (DW_TAG_subrange_type)
    <61>   DW_AT_type        : <0x67>   
    <65>   DW_AT_upper_bound : 5        

... as the type of the parameter "a". The subrange type there shows the bounds.

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