Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the left-most number mean in DWARF dump from readelf?

Tags:

gdb

dwarf

readelf

For example:

 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <c>   DW_AT_producer    : (indirect string, offset: 0xe): GNU C1
1 5.4.0 20160609 -masm=intel -m32 -mtune=generic -march=i686 -g -fst
ack-protector-strong
    <10>   DW_AT_language    : 12       (ANSI C99)
    <11>   DW_AT_name        : (indirect string, offset: 0xbe): hell
o.c
    <15>   DW_AT_comp_dir    : (indirect string, offset: 0x97): /tmp
    <19>   DW_AT_low_pc      : 0x804840b
    <1d>   DW_AT_high_pc     : 0x2e
    <21>   DW_AT_stmt_list   : 0x0
 <1><25>: Abbrev Number: 2 (DW_TAG_base_type)
    <26>   DW_AT_byte_size   : 4
    <27>   DW_AT_encoding    : 7        (unsigned)
    <28>   DW_AT_name        : (indirect string, offset: 0x77): unsi
gned int
 <1><2c>: Abbrev Number: 2 (DW_TAG_base_type)
    <2d>   DW_AT_byte_size   : 1
    <2e>   DW_AT_encoding    : 8        (unsigned char)
    <2f>   DW_AT_name        : (indirect string, offset: 0x84): unsi
gned char
 <1><33>: Abbrev Number: 2 (DW_TAG_base_type)
    <34>   DW_AT_byte_size   : 2
    <35>   DW_AT_encoding    : 7        (unsigned)
    <36>   DW_AT_name        : (indirect string, offset: 0xa1): shor
t unsigned int

At the beginning of each DIE entry, there is a number such as <0>, <1>... what do these number means? It seems the same number indicates the same DWARF type, I guess e.g. entries with <1> mean they are all (DW_TAG_base_type).

like image 974
Amumu Avatar asked Jan 12 '17 10:01

Amumu


1 Answers

DWARF DIEs are arranged in a tree. The left-most number tells you the depth of the DIE. In your example:

 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)

The <0> means that this DIE appears at the outermost level. This will only happen for compile or type unit DIEs.

Then:

 <1><25>: Abbrev Number: 2 (DW_TAG_base_type)

This DIE is a child of the compilation unit DIE.

You can get deeper nesting; for example the local variables of a function might be quite deeply nested, depending on the block structure of the function. Items in a namespace might also be nested.

like image 148
Tom Tromey Avatar answered Oct 19 '22 07:10

Tom Tromey