0

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;
4

1 回答 1

2

DW_TAG_compile_unitDWARF DIE 以树的形式组织 -单个文件的顶层将包含所有类型定义(DW_TAG_class_type例如)、所有函数 ( DW_TAG_subprogram) 和全局/静态变量 ( DW_TAG_variable)。一个类定义 ( DW_TAG_class_type) 将是一个父 DIE 并包含像DW_TAG_member成员变量或DW_TAG_subprogram方法这样的子级。

您附加的输出是您的特定 DWARF 转储器的操作方式 - 看起来它正在使用该数字来显示父/子关系。这是readelf吗?其他 dwarf dumper 程序可能会选择以不同的方式显示这一点。在 Mac OS X 上,dwarfdump显示了这种与缩进的关系——子 DIE 的缩进比父 DIE 多一点。

如果您正在查看http://dwarfstd.org/上的 DWARF 规范,您将不会在标准中找到有关此数字的任何信息 - 但如果您编写真正的 DWARF 解析器(而不是解释输出readelf或其他内容),您将在 DWARF4 规范的第 2.3 节(“调试信息条目的关系”)和第 7.5.3 节“缩写表”(DW_CHILDREN_yes或)中看到该主题。DW_CHILDREN_no

于 2013-06-06T07:14:09.143 回答