Question

Consider the following sample of dwarf code -

<0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <c>   DW_AT_producer    : (indirect string, offset: 0xd): GNU C++ 4.3.0 20080428 (Red Hat 4.3.0-8)  
    <10>   DW_AT_language    : 4    (C++)
    <11>   DW_AT_name        : (indirect string, offset: 0x75): test.cpp    
    <15>   DW_AT_comp_dir    : (indirect string, offset: 0x4d): /home/dwarf 
    <19>   DW_AT_low_pc      : 0x0  
    <21>   DW_AT_high_pc     : 0xb  
    <29>   DW_AT_stmt_list   : 0x0  
 <1><2d>: Abbrev Number: 2 (DW_TAG_class_type)
    <2e>   DW_AT_name        : C    
    <30>   DW_AT_byte_size   : 8    
    <31>   DW_AT_decl_file   : 1    
    <32>   DW_AT_decl_line   : 1    
    <33>   DW_AT_sibling     : <0x86>   
 <2><37>: Abbrev Number: 3 (DW_TAG_member)
    <38>   DW_AT_name        : x    
    <3a>   DW_AT_decl_file   : 1    
    <3b>   DW_AT_decl_line   : 7    
    <3c>   DW_AT_type        : <0x86>   
    <40>   DW_AT_data_member_location: 2 byte block: 23 0   (DW_OP_plus_uconst: 0)
    <43>   DW_AT_accessibility: 3   (private)
 <2><44>: Abbrev Number: 3 (DW_TAG_member)
    <45>   DW_AT_name        : y    
    <47>   DW_AT_decl_file   : 1    
    <48>   DW_AT_decl_line   : 8    
    <49>   DW_AT_type        : <0x86>   
    <4d>   DW_AT_data_member_location: 2 byte block: 23 4   (DW_OP_plus_uconst: 4)
    <50>   DW_AT_accessibility: 3   (private)

I have been working on a program that parses through dwarf files, and I am unsure of one part of it. If you notice, each tag has an extra number to the left of it (in this sample there is <0>, <1> and <2>). Im not really sure what it is. I think it is some sort of stack level or something, since <0> is given to the program as a whole, <1> is given to a top level class, and <2> is given to its member variables. However, I have not been able to find anything on it in the documentation. For reference, here is the original program -

class C {
public:
    C();
    C(int x, int y);
    int getX();
private:
    int x;
    int y;
};

class SubC : public C {
    int z;
};

int f() {return 0;}

C c;
SubC subC;

int i;
double d;
Was it helpful?

Solution

DWARF DIEs are organized as a tree - the top level DW_TAG_compile_unit for a single file will contain all of the type definitions (DW_TAG_class_type for instance), all of the functions (DW_TAG_subprogram), and global/static variables (DW_TAG_variable). A class definition (DW_TAG_class_type) will be a parent DIE and contain children like DW_TAG_member for member variables or DW_TAG_subprogram for methods.

The output you've appended is the way your particular DWARF dumper operates - it looks like it is using that number to show parent/child relationships. Is this readelf? Other dwarf dumper programs may choose to show this in a different way. On Mac OS X, dwarfdump shows this relationship with indentation - children DIEs are indented a little more than parent DIEs.

If you're looking at the DWARF spec on http://dwarfstd.org/ you won't find anything about this number in the standard -- but if you write a genuine DWARF parser (as opposed to a parser which is interpreting the output of readelf or whatever), you'll see this topic covered in section 2.3 ("Relationship of Debugging Information Entries") and section 7.5.3 "Abbreviations Tables" (DW_CHILDREN_yes or DW_CHILDREN_no) in the DWARF4 spec.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top