[Dwarf-Discuss] Array Information

Daniel Berlin dberlin@dberlin.org
Wed Mar 12 12:18:37 GMT 2008


On Wed, Mar 12, 2008 at 6:53 AM, ashim saikia <ar.saikia at yahoo.com> wrote:
>
> Hi,
> I am unable to get the array info using dwarf2. Should I migrate to dwarf3.
> I have written a simple c program containing array.
> #include <stdio.h>
>
> main()
> {
>         int a[20];
>         int b[30];
>         int i=0;
>         int *p=NULL;
>
>         for(i=0;i<20;i++) {
>           a[i]=2;
>           b[i]=2;
>         }
>
>         *p=30;
>         for(i=0;i<20;i++)
>           printf("\n a[%d]=%d",i,a[i]);
> }
>
> The following steps I have followed to get the dwarf info:
>
> $ gcc -g -c testarray.c
> $ objdump -h testarray.o
>
> $readelf -wi testarray.o
> The result is:-
>
> he section .debug_info contains:
>
>   Compilation Unit @ offset 0x0:
>    Length:        383
>    Version:       2
>    Abbrev Offset: 0
>    Pointer Size:  4
>  <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
>   < c>     DW_AT_stmt_list   : 0
>   <10>     DW_AT_high_pc     : 0x8048458
>   <14>     DW_AT_low_pc      : 0x80483c4
>   <18>     DW_AT_producer    : GNU C 4.1.2 20070925 (Red Hat 4.1.2-33)
>   <40>     DW_AT_language    : 1    (ANSI C)
>   <41>     DW_AT_name        : testarray.c
>   <4d>     DW_AT_comp_dir    : /usr1/ashim/cprogs
>  <2><129>: Abbrev Number: 5 (DW_TAG_variable)
>   <12a>     DW_AT_name        : a
>   <12c>     DW_AT_decl_file   : 1
>   <12d>     DW_AT_decl_line   : 5
>   <12e>     DW_AT_type        : <15c>
>   <132>     DW_AT_location    : 3 byte block: 91 9c 7f     (DW_OP_fbreg:
> -100)
>  <1><15c>: Abbrev Number: 6 (DW_TAG_array_type)
>   <15d>     DW_AT_sibling     : <16c>
>   <161>     DW_AT_type        : <bf>
>
> Here at DW_TAG_array type I am not getting the DW_AT_name (i.e. the name of
> the array) without which I cannot establish the relation between the array,
> its type and the number of elements.
????


1.  You are getting the name, because the variable has the name, not the type.
2. The type of the array is clearly marked.
3. The number of elements is clearly marked by the subrange type child
of the array type, as allowed by the standard ("Subrange
type entries may also be used to represent the bounds of array dimensions.")

I'm not sure what you think you are missing.
You seem to be confused about the difference between the name of a
type and a name of the variable.




More information about the Dwarf-discuss mailing list