Commit 79804db4 authored by Raphael Junqueira's avatar Raphael Junqueira Committed by Alexandre Julliard

- better traces

- handle inclusion "levels" - better parsing of subprogram, typedef, pointer, ... entries - arrays, enums, const_type, reference_type parsing - checks parsing cursors errors (when sibling value available) - more utilities functions (dwarf2_parse_attr_as_data)
parent 2964d8bc
......@@ -293,17 +293,187 @@ typedef enum dwarf_type_e {
DW_ATE_unsigned_char = 0x8
} dwarf_type_t;
typedef enum dwarf_operation_e {
DW_OP_addr = 0x03,
DW_OP_deref = 0x06,
DW_OP_const1u = 0x08,
DW_OP_const1s = 0x09,
DW_OP_const2u = 0x0a,
DW_OP_const2s = 0x0b,
DW_OP_const4u = 0x0c,
DW_OP_const4s = 0x0d,
DW_OP_const8u = 0x0e,
DW_OP_const8s = 0x0f,
DW_OP_constu = 0x10,
DW_OP_consts = 0x11,
DW_OP_dup = 0x12,
DW_OP_drop = 0x13,
DW_OP_over = 0x14,
DW_OP_pick = 0x15,
DW_OP_swap = 0x16,
DW_OP_rot = 0x17,
DW_OP_xderef = 0x18,
DW_OP_abs = 0x19,
DW_OP_and = 0x1a,
DW_OP_div = 0x1b,
DW_OP_minus = 0x1c,
DW_OP_mod = 0x1d,
DW_OP_mul = 0x1e,
DW_OP_neg = 0x1f,
DW_OP_not = 0x20,
DW_OP_or = 0x21,
DW_OP_plus = 0x22,
DW_OP_plus_uconst = 0x23,
DW_OP_shl = 0x24,
DW_OP_shr = 0x25,
DW_OP_shra = 0x26,
DW_OP_xor = 0x27,
DW_OP_bra = 0x28,
DW_OP_eq = 0x29,
DW_OP_ge = 0x2a,
DW_OP_gt = 0x2b,
DW_OP_le = 0x2c,
DW_OP_lt = 0x2d,
DW_OP_ne = 0x2e,
DW_OP_skip = 0x2f,
DW_OP_lit0 = 0x30,
DW_OP_lit1 = 0x31,
DW_OP_lit2 = 0x32,
DW_OP_lit3 = 0x33,
DW_OP_lit4 = 0x34,
DW_OP_lit5 = 0x35,
DW_OP_lit6 = 0x36,
DW_OP_lit7 = 0x37,
DW_OP_lit8 = 0x38,
DW_OP_lit9 = 0x39,
DW_OP_lit10 = 0x3a,
DW_OP_lit11 = 0x3b,
DW_OP_lit12 = 0x3c,
DW_OP_lit13 = 0x3d,
DW_OP_lit14 = 0x3e,
DW_OP_lit15 = 0x3f,
DW_OP_lit16 = 0x40,
DW_OP_lit17 = 0x41,
DW_OP_lit18 = 0x42,
DW_OP_lit19 = 0x43,
DW_OP_lit20 = 0x44,
DW_OP_lit21 = 0x45,
DW_OP_lit22 = 0x46,
DW_OP_lit23 = 0x47,
DW_OP_lit24 = 0x48,
DW_OP_lit25 = 0x49,
DW_OP_lit26 = 0x4a,
DW_OP_lit27 = 0x4b,
DW_OP_lit28 = 0x4c,
DW_OP_lit29 = 0x4d,
DW_OP_lit30 = 0x4e,
DW_OP_lit31 = 0x4f,
DW_OP_reg0 = 0x50,
DW_OP_reg1 = 0x51,
DW_OP_reg2 = 0x52,
DW_OP_reg3 = 0x53,
DW_OP_reg4 = 0x54,
DW_OP_reg5 = 0x55,
DW_OP_reg6 = 0x56,
DW_OP_reg7 = 0x57,
DW_OP_reg8 = 0x58,
DW_OP_reg9 = 0x59,
DW_OP_reg10 = 0x5a,
DW_OP_reg11 = 0x5b,
DW_OP_reg12 = 0x5c,
DW_OP_reg13 = 0x5d,
DW_OP_reg14 = 0x5e,
DW_OP_reg15 = 0x5f,
DW_OP_reg16 = 0x60,
DW_OP_reg17 = 0x61,
DW_OP_reg18 = 0x62,
DW_OP_reg19 = 0x63,
DW_OP_reg20 = 0x64,
DW_OP_reg21 = 0x65,
DW_OP_reg22 = 0x66,
DW_OP_reg23 = 0x67,
DW_OP_reg24 = 0x68,
DW_OP_reg25 = 0x69,
DW_OP_reg26 = 0x6a,
DW_OP_reg27 = 0x6b,
DW_OP_reg28 = 0x6c,
DW_OP_reg29 = 0x6d,
DW_OP_reg30 = 0x6e,
DW_OP_reg31 = 0x6f,
DW_OP_breg0 = 0x70,
DW_OP_breg1 = 0x71,
DW_OP_breg2 = 0x72,
DW_OP_breg3 = 0x73,
DW_OP_breg4 = 0x74,
DW_OP_breg5 = 0x75,
DW_OP_breg6 = 0x76,
DW_OP_breg7 = 0x77,
DW_OP_breg8 = 0x78,
DW_OP_breg9 = 0x79,
DW_OP_breg10 = 0x7a,
DW_OP_breg11 = 0x7b,
DW_OP_breg12 = 0x7c,
DW_OP_breg13 = 0x7d,
DW_OP_breg14 = 0x7e,
DW_OP_breg15 = 0x7f,
DW_OP_breg16 = 0x80,
DW_OP_breg17 = 0x81,
DW_OP_breg18 = 0x82,
DW_OP_breg19 = 0x83,
DW_OP_breg20 = 0x84,
DW_OP_breg21 = 0x85,
DW_OP_breg22 = 0x86,
DW_OP_breg23 = 0x87,
DW_OP_breg24 = 0x88,
DW_OP_breg25 = 0x89,
DW_OP_breg26 = 0x8a,
DW_OP_breg27 = 0x8b,
DW_OP_breg28 = 0x8c,
DW_OP_breg29 = 0x8d,
DW_OP_breg30 = 0x8e,
DW_OP_breg31 = 0x8f,
DW_OP_regx = 0x90,
DW_OP_fbreg = 0x91,
DW_OP_bregx = 0x92,
DW_OP_piece = 0x93,
DW_OP_deref_size = 0x94,
DW_OP_xderef_size = 0x95,
DW_OP_nop = 0x96
} dwarf_operation_t;
/**
* Parsers
*/
typedef struct dwarf2_abbrev_entry_attr_s {
unsigned long attribute;
unsigned long form;
struct dwarf2_abbrev_entry_attr_s* next;
} dwarf2_abbrev_entry_attr_t;
typedef struct dwarf2_abbrev_entry_s {
unsigned long entry_code;
unsigned long tag;
unsigned char have_child;
dwarf2_abbrev_entry_attr_t* attrs;
struct dwarf2_abbrev_entry_s* next;
} dwarf2_abbrev_entry_t;
typedef struct dwarf2_abbrev_table_s {
dwarf2_abbrev_entry_t* first;
unsigned n_entries;
} dwarf2_abbrev_table_t;
typedef struct dwarf2_parse_context_s {
dwarf2_abbrev_table_t* abbrev_table;
const unsigned char* data_stream;
const unsigned char* data;
const unsigned char* start_data;
const unsigned char* end_data;
const unsigned char* str_section;
unsigned long offset;
unsigned char word_size;
unsigned char level;
} dwarf2_parse_context_t;
static unsigned char dwarf2_parse_byte(dwarf2_parse_context_t* ctx)
......@@ -369,24 +539,23 @@ static long dwarf2_leb128_as_signed(dwarf2_parse_context_t* ctx)
return ret;
}
typedef struct dwarf2_abbrev_entry_attr_s {
unsigned long attribute;
unsigned long form;
struct dwarf2_abbrev_entry_attr_s* next;
} dwarf2_abbrev_entry_attr_t;
const char* dwarf2_debug_ctx(dwarf2_parse_context_t* ctx)
{
return wine_dbg_sprintf("ctx(0x%x,%u)", ctx->data - ctx->start_data, ctx->level);
}
const char* dwarf2_debug_attr(dwarf2_abbrev_entry_attr_t* attr)
{
return wine_dbg_sprintf("attr(attr:0x%lx,form:0x%lx)", attr->attribute, attr->form);
}
typedef struct dwarf2_abbrev_entry_s {
unsigned long entry_code;
unsigned long tag;
unsigned char have_child;
dwarf2_abbrev_entry_attr_t* attrs;
struct dwarf2_abbrev_entry_s* next;
} dwarf2_abbrev_entry_t;
static void dwarf2_check_sibling(dwarf2_parse_context_t* ctx, unsigned long next_sibling)
{
if (0 < next_sibling && ctx->data != ctx->data_stream + next_sibling) {
WARN("cursor error for %s should be sibling<0x%lx>\n", dwarf2_debug_ctx(ctx), next_sibling);
ctx->data = ctx->data_stream + next_sibling;
}
}
typedef struct dwarf2_abbrev_table_s {
dwarf2_abbrev_entry_t* first;
unsigned n_entries;
} dwarf2_abbrev_table_t;
dwarf2_abbrev_entry_attr_t* dwarf2_abbrev_entry_add_attr(dwarf2_abbrev_entry_t* abbrev_entry, unsigned long attribute, unsigned long form)
{
......@@ -418,7 +587,7 @@ dwarf2_abbrev_entry_t* dwarf2_abbrev_table_add_entry(dwarf2_abbrev_table_t* abbr
ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dwarf2_abbrev_entry_t));
assert( NULL != ret );
TRACE("(%p,%u) entry_code(%lu) tag(0x%lx) have_child(%u) -> %p\n", abbrev_table, abbrev_table->n_entries, entry_code, tag, have_child, ret);
TRACE("(table:%p,n_entries:%u) entry_code(%lu) tag(0x%lx) have_child(%u) -> %p\n", abbrev_table, abbrev_table->n_entries, entry_code, tag, have_child, ret);
ret->entry_code = entry_code;
ret->tag = tag;
......@@ -465,7 +634,7 @@ dwarf2_abbrev_table_t* dwarf2_parse_abbrev_set(dwarf2_parse_context_t* abbrev_ct
{
dwarf2_abbrev_table_t* abbrev_table = NULL;
TRACE("beginning at 0x%x, end at %p\n", abbrev_ctx->data - abbrev_ctx->start_data, abbrev_ctx->end_data);
TRACE("%s, end at %p\n", dwarf2_debug_ctx(abbrev_ctx), abbrev_ctx->end_data);
assert( NULL != abbrev_ctx );
abbrev_table = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(dwarf2_abbrev_table_t));
......@@ -477,11 +646,11 @@ dwarf2_abbrev_table_t* dwarf2_parse_abbrev_set(dwarf2_parse_context_t* abbrev_ct
unsigned char have_child;
dwarf2_abbrev_entry_t* abbrev_entry;
TRACE("now at %p\n", abbrev_ctx->data);
TRACE("now at %s\n", dwarf2_debug_ctx(abbrev_ctx));
entry_code = dwarf2_leb128_as_unsigned(abbrev_ctx);
TRACE("found entry_code %lu\n", entry_code);
if (0 == entry_code) {
TRACE("NULL entry code at %p\n", abbrev_ctx->data);
TRACE("NULL entry code at %s\n", dwarf2_debug_ctx(abbrev_ctx));
break ;
}
tag = dwarf2_leb128_as_unsigned(abbrev_ctx);
......@@ -573,6 +742,35 @@ static unsigned long dwarf2_parse_attr_as_ref(dwarf2_abbrev_entry_attr_t* attr,
return uvalue;
}
static unsigned long dwarf2_parse_attr_as_data(dwarf2_abbrev_entry_attr_t* attr,
dwarf2_parse_context_t* ctx)
{
unsigned long uvalue = 0;
switch (attr->form) {
case DW_FORM_data1:
uvalue = dwarf2_parse_byte(ctx);
TRACE("data1<%lu>\n", uvalue);
break;
case DW_FORM_data2:
uvalue = dwarf2_parse_u2(ctx);
TRACE("data2<%lu>\n", uvalue);
break;
case DW_FORM_data4:
uvalue = dwarf2_parse_u4(ctx);
TRACE("data4<%lu>\n", uvalue);
break;
case DW_FORM_data8:
FIXME("Unsupported 64bits support\n");
ctx->data += 8;
break;
}
return uvalue;
}
static void dwarf2_parse_attr(dwarf2_abbrev_entry_attr_t* attr,
dwarf2_parse_context_t* ctx)
{
......@@ -663,31 +861,6 @@ static void dwarf2_parse_attr(dwarf2_abbrev_entry_attr_t* attr,
}
}
static struct symt_compiland* dwarf2_parse_compiland(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_compiland* compiland = NULL;
const char* name = NULL;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
default:
dwarf2_parse_attr(attr, ctx);
}
}
if (NULL != name) {
compiland = symt_new_compiland(module, name);
}
return compiland;
}
struct symt* dwarf2_find_symt_by_ref(struct module* module, unsigned long ref)
{
TRACE("want ref<0x%lx>\n", ref);
......@@ -709,7 +882,7 @@ static struct symt_basic* dwarf2_parse_base_type(struct module* module, dwarf2_a
enum BasicType bt;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
......@@ -724,6 +897,7 @@ static struct symt_basic* dwarf2_parse_base_type(struct module* module, dwarf2_a
encoding = dwarf2_parse_byte(ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
......@@ -741,9 +915,7 @@ static struct symt_basic* dwarf2_parse_base_type(struct module* module, dwarf2_a
bt = btNoType;
}
/*TRACE("symt_new_basic(%p, %u, %s, %u)", module, bt, name, size);*/
if (NULL != name) {
symt = symt_new_basic(module, bt, name, size);
}
return symt;
}
......@@ -754,7 +926,7 @@ static struct symt_typedef* dwarf2_parse_typedef(struct module* module, dwarf2_a
const char* name = NULL;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("beginning at 0x%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
......@@ -768,7 +940,12 @@ static struct symt_typedef* dwarf2_parse_typedef(struct module* module, dwarf2_a
ref_type = dwarf2_find_symt_by_ref(module, ref);
}
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
dwarf2_parse_attr(attr, ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
......@@ -785,7 +962,7 @@ static struct symt_pointer* dwarf2_parse_pointer_type(struct module* module, dwa
unsigned size = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
......@@ -799,6 +976,7 @@ static struct symt_pointer* dwarf2_parse_pointer_type(struct module* module, dwa
}
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
......@@ -806,117 +984,199 @@ static struct symt_pointer* dwarf2_parse_pointer_type(struct module* module, dwa
return symt;
}
static struct symt_udt* dwarf2_parse_class_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
static void dwarf2_parse_array_subrange_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_array* parent)
{
struct symt_udt* symt = NULL;
const char* name = NULL;
unsigned size = 0;
unsigned min = 0;
unsigned max = 0;
struct symt* idx_type = NULL;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
case DW_AT_type:
{
unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
idx_type = dwarf2_find_symt_by_ref(module, ref);
/** check if idx_type is a basic_type integer */
}
break;
case DW_AT_byte_size:
size = dwarf2_parse_byte(ctx);
case DW_AT_lower_bound:
TRACE("%s %s, lower_bound\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
min = dwarf2_parse_attr_as_data(attr, ctx);
break;
case DW_AT_upper_bound:
TRACE("%s %s, upper_bound\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
max = dwarf2_parse_attr_as_data(attr, ctx);
break;
case DW_AT_count:
TRACE("%s %s, count min:%u\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr), min);
max = min + dwarf2_parse_attr_as_data(attr, ctx);
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt = symt_new_udt(module, name, size, UdtClass);
return symt;
parent->start = min;
parent->end = max;
TRACE("found min:%u max:%u\n", min, max);
}
static struct symt_udt* dwarf2_parse_struct_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
static struct symt_array* dwarf2_parse_array_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_udt* symt = NULL;
const char* name = NULL;
unsigned size = 0;
struct symt_array* symt = NULL;
struct symt* ref_type = NULL;
unsigned min = 0;
unsigned max = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_byte_size:
size = dwarf2_parse_byte(ctx);
case DW_AT_type:
{
unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
ref_type = dwarf2_find_symt_by_ref(module, ref);
}
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt = symt_new_udt(module, name, size, UdtStruct);
symt = symt_new_array(module, min, max, ref_type);
if (entry->have_child) { /** any interest to not have child ? */
++ctx->level;
while (ctx->data < ctx->end_data) {
dwarf2_abbrev_entry_t* entry = NULL;
unsigned long entry_code;
unsigned long entry_ref = 0;
entry_ref = ctx->data - ctx->data_stream;
entry_code = dwarf2_leb128_as_unsigned(ctx);
TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
if (0 == entry_code) {
break ;
}
entry = dwarf2_abbrev_table_find_entry(ctx->abbrev_table, entry_code);
assert( NULL != entry );
switch (entry->tag) {
case DW_TAG_subrange_type:
dwarf2_parse_array_subrange_type(module, entry, ctx, symt);
break;
default:
{
dwarf2_abbrev_entry_attr_t* attr;
TRACE("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
dwarf2_parse_attr(attr, ctx);
}
}
break;
}
}
--ctx->level;
}
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
return symt;
}
static struct symt_udt* dwarf2_parse_union_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
static struct symt_typedef* dwarf2_parse_const_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_udt* symt = NULL;
const char* name = NULL;
unsigned size = 0;
struct symt_typedef* symt = NULL;
struct symt* ref_type = NULL;
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
case DW_AT_type:
{
unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
ref_type = dwarf2_find_symt_by_ref(module, ref);
}
break;
case DW_AT_byte_size:
size = dwarf2_parse_byte(ctx);
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
FIXME("need to generate a name\n");
symt = symt_new_typedef(module, ref_type, "");
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
return symt;
}
static struct symt_typedef* dwarf2_parse_reference_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_typedef* symt = NULL;
struct symt* ref_type = NULL;
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_type:
{
unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
ref_type = dwarf2_find_symt_by_ref(module, ref);
}
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt = symt_new_udt(module, name, size, UdtUnion);
FIXME("need to generate a name\n");
symt = symt_new_typedef(module, ref_type, "");
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
return symt;
}
static struct symt_function* dwarf2_parse_subprogram(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_compiland* compiland)
static void dwarf2_parse_udt_member(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_udt* parent)
{
struct symt_function* symt_f = NULL;
struct symt* elt_type = NULL;
const char* name = NULL;
struct symt* sig_type = NULL;
unsigned long addr = 0;
unsigned long low_pc = 0;
unsigned long high_pc = 0;
unsigned long offset = 0;
unsigned size = 0;
unsigned char is_decl = 0;
unsigned char inl_flags = 0;
unsigned char decl_file = 0;
unsigned char decl_line = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
assert( NULL != parent );
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_low_pc:
low_pc = dwarf2_parse_attr_as_addr(attr, ctx);
addr = module->module.BaseOfImage + low_pc;
break;
case DW_AT_high_pc:
high_pc = dwarf2_parse_attr_as_addr(attr, ctx);
size = high_pc - low_pc;
break;
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
......@@ -924,40 +1184,655 @@ static struct symt_function* dwarf2_parse_subprogram(struct module* module, dwar
case DW_AT_type:
{
unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
sig_type = dwarf2_find_symt_by_ref(module, ref);
elt_type = dwarf2_find_symt_by_ref(module, ref);
}
break;
case DW_AT_declaration:
is_decl = dwarf2_parse_byte(ctx);
case DW_AT_data_member_location:
{
unsigned long uvalue = 0;
TRACE("found member_location at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
/*offset = dwarf2_parse_attr_as_data(attr, ctx);*/
switch (attr->form) {
case DW_FORM_block:
uvalue = dwarf2_leb128_as_unsigned(ctx);
break;
case DW_AT_inline:
inl_flags = dwarf2_parse_byte(ctx);
case DW_FORM_block1:
uvalue = dwarf2_parse_byte(ctx);
break;
/* not work yet, need parsing .debug_line and using Compil Unit stmt_list
case DW_AT_decl_file:
decl_file = dwarf2_parse_byte(ctx);
case DW_FORM_block2:
uvalue = dwarf2_parse_u2(ctx);
break;
case DW_AT_decl_line:
decl_line = dwarf2_parse_byte(ctx);
case DW_FORM_block4:
uvalue = dwarf2_parse_u4(ctx);
break;
default:
TRACE("Unhandled attr form at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
if (uvalue) {
unsigned char op = dwarf2_parse_byte(ctx);
--uvalue;
switch (op) {
case DW_OP_plus_uconst:
offset = dwarf2_leb128_as_unsigned(ctx);
break;
default:
TRACE("Unhandled attr op at %s, for %s, op:%u\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr), op);
ctx->data += uvalue;
}
TRACE("found offset:%lu\n", offset);
}
}
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
dwarf2_parse_attr(attr, ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt_add_udt_element(module, parent, name, elt_type, offset, size);
}
static void dwarf2_parse_udt_members(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_udt* symt)
{
if (entry->have_child) { /** any interest to not have child ? */
++ctx->level;
while (ctx->data < ctx->end_data) {
dwarf2_abbrev_entry_t* entry = NULL;
unsigned long entry_code;
unsigned long entry_ref = 0;
entry_ref = ctx->data - ctx->data_stream;
entry_code = dwarf2_leb128_as_unsigned(ctx);
TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
if (0 == entry_code) {
break ;
}
entry = dwarf2_abbrev_table_find_entry(ctx->abbrev_table, entry_code);
assert( NULL != entry );
switch (entry->tag) {
case DW_TAG_member:
dwarf2_parse_udt_member(module, entry, ctx, symt);
break;
default:
{
dwarf2_abbrev_entry_attr_t* attr;
TRACE("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
dwarf2_parse_attr(attr, ctx);
}
}
break;
}
}
--ctx->level;
}
}
static struct symt_udt* dwarf2_parse_class_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_udt* symt = NULL;
const char* name = NULL;
unsigned size = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
case DW_AT_byte_size:
size = dwarf2_parse_byte(ctx);
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
dwarf2_parse_attr(attr, ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt = symt_new_udt(module, name, size, UdtClass);
dwarf2_parse_udt_members(module, entry, ctx, symt);
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
return symt;
}
static struct symt_udt* dwarf2_parse_struct_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_udt* symt = NULL;
const char* name = NULL;
unsigned size = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
case DW_AT_byte_size:
size = dwarf2_parse_byte(ctx);
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
dwarf2_parse_attr(attr, ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt = symt_new_udt(module, name, size, UdtStruct);
dwarf2_parse_udt_members(module, entry, ctx, symt);
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
return symt;
}
static struct symt_udt* dwarf2_parse_union_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_udt* symt = NULL;
const char* name = NULL;
unsigned size = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
case DW_AT_byte_size:
size = dwarf2_parse_byte(ctx);
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
dwarf2_parse_attr(attr, ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt = symt_new_udt(module, name, size, UdtUnion);
dwarf2_parse_udt_members(module, entry, ctx, symt);
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
return symt;
}
static void dwarf2_parse_enumerator(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_enum* parent)
{
const char* name = NULL;
long value = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
case DW_AT_const_value:
switch (attr->form) {
case DW_FORM_sdata:
value = dwarf2_leb128_as_signed(ctx);
TRACE("found value %ld\n", value);
break;
case DW_FORM_udata:
value = dwarf2_leb128_as_unsigned(ctx);
TRACE("found value %ld\n", value);
break;
default:
TRACE("Unhandled attr form at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt_add_enum_element(module, parent, name, value);
}
static struct symt_enum* dwarf2_parse_enumeration_type(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_enum* symt = NULL;
const char* name = NULL;
unsigned long size = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
case DW_AT_byte_size:
size = dwarf2_parse_attr_as_data(attr, ctx);
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
dwarf2_parse_attr(attr, ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt = symt_new_enum(module, name);
if (entry->have_child) { /** any interest to not have child ? */
++ctx->level;
while (ctx->data < ctx->end_data) {
dwarf2_abbrev_entry_t* entry = NULL;
unsigned long entry_code;
unsigned long entry_ref = 0;
entry_ref = ctx->data - ctx->data_stream;
entry_code = dwarf2_leb128_as_unsigned(ctx);
TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
if (0 == entry_code) {
break ;
}
entry = dwarf2_abbrev_table_find_entry(ctx->abbrev_table, entry_code);
assert( NULL != entry );
switch (entry->tag) {
case DW_TAG_enumerator:
dwarf2_parse_enumerator(module, entry, ctx, symt);
break;
default:
{
dwarf2_abbrev_entry_attr_t* attr;
TRACE("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
dwarf2_parse_attr(attr, ctx);
}
}
break;
}
}
--ctx->level;
}
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
return symt;
}
static void dwarf2_parse_subprogram_parameter(struct module* module,
dwarf2_abbrev_entry_t* entry,
dwarf2_parse_context_t* ctx,
struct symt_function_signature* sig_type,
struct symt_function* func_type)
{
struct symt* param_type = NULL;
const char* name = NULL;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_type:
{
unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
param_type = dwarf2_find_symt_by_ref(module, ref);
}
break;
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
dwarf2_parse_attr(attr, ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
symt_add_function_signature_parameter(module, sig_type, param_type);
}
static void dwarf2_parse_subprogram_block(struct module* module,
dwarf2_abbrev_entry_t* entry,
dwarf2_parse_context_t* ctx,
struct symt_function_signature* sig_type,
struct symt_function* func_type)
{
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_decl_file:
case DW_AT_decl_line:
dwarf2_parse_attr(attr, ctx);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
}
static void dwarf2_parse_subprogram_content(struct module* module,
dwarf2_abbrev_entry_t* entry,
dwarf2_parse_context_t* ctx,
struct symt_function_signature* sig_type,
struct symt_function* func_type)
{
if (entry->have_child) { /** any interest to not have child ? */
++ctx->level;
while (ctx->data < ctx->end_data) {
dwarf2_abbrev_entry_t* entry = NULL;
unsigned long entry_code;
unsigned long entry_ref = 0;
entry_ref = ctx->data - ctx->data_stream;
entry_code = dwarf2_leb128_as_unsigned(ctx);
TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
if (0 == entry_code) {
break ;
}
entry = dwarf2_abbrev_table_find_entry(ctx->abbrev_table, entry_code);
assert( NULL != entry );
switch (entry->tag) {
case DW_TAG_formal_parameter:
dwarf2_parse_subprogram_parameter(module, entry, ctx, sig_type, func_type);
break;
case DW_TAG_lexical_block:
dwarf2_parse_subprogram_block(module, entry, ctx, sig_type, func_type);
break;
default:
{
dwarf2_abbrev_entry_attr_t* attr;
TRACE("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
dwarf2_parse_attr(attr, ctx);
}
}
break;
}
}
--ctx->level;
}
}
static struct symt_function* dwarf2_parse_subprogram(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_compiland* compiland)
{
struct symt_function* func_type = NULL;
const char* name = NULL;
struct symt* ret_type = NULL;
struct symt_function_signature* sig_type = NULL;
unsigned long addr = 0;
unsigned long low_pc = 0;
unsigned long high_pc = 0;
unsigned size = 0;
unsigned char is_decl = 0;
unsigned char inl_flags = 0;
unsigned char decl_file = 0;
unsigned char decl_line = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
unsigned long next_sibling = 0;
TRACE("%s, for %lu\n", dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_low_pc:
low_pc = dwarf2_parse_attr_as_addr(attr, ctx);
addr = module->module.BaseOfImage + low_pc;
break;
case DW_AT_high_pc:
high_pc = dwarf2_parse_attr_as_addr(attr, ctx);
size = high_pc - low_pc;
break;
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
case DW_AT_type:
{
unsigned long ref = dwarf2_parse_attr_as_ref(attr, ctx);
ret_type = dwarf2_find_symt_by_ref(module, ref);
}
break;
case DW_AT_declaration:
is_decl = dwarf2_parse_byte(ctx);
break;
case DW_AT_inline:
inl_flags = dwarf2_parse_byte(ctx);
break;
/* not work yet, need parsing .debug_line and using Compil Unit stmt_list
case DW_AT_decl_file:
decl_file = dwarf2_parse_byte(ctx);
break;
case DW_AT_decl_line:
decl_line = dwarf2_parse_byte(ctx);
break;
*/
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
/*symt_function_signature* symt_new_function_signature(module, ret_type)*/
sig_type = symt_new_function_signature(module, ret_type);
if (!is_decl) {
symt_f = symt_new_function(module, compiland, name, addr, size, sig_type);
func_type = symt_new_function(module, compiland, name, addr, size, &sig_type->symt);
if (low_pc && high_pc) {
symt_add_function_point(module, symt_f, SymTagFuncDebugStart, low_pc, NULL);
symt_add_function_point(module, symt_f, SymTagFuncDebugEnd, high_pc, NULL);
symt_add_function_point(module, func_type, SymTagFuncDebugStart, low_pc, NULL);
symt_add_function_point(module, func_type, SymTagFuncDebugEnd, high_pc, NULL);
}
if (decl_file && decl_line) {
symt_add_func_line(module, symt_f, decl_file, decl_line, low_pc);
symt_add_func_line(module, func_type, decl_file, decl_line, low_pc);
}
return symt_f;
}
return NULL;
dwarf2_parse_subprogram_content(module, entry, ctx, sig_type, func_type);
symt_normalize_function(module, func_type);
/** set correct data cursor */
dwarf2_check_sibling(ctx, next_sibling);
return func_type;
}
static void dwarf2_parse_compiland_content(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx, struct symt_compiland* compiland)
{
if (entry->have_child) { /** any interest to not have child ? */
++ctx->level;
while (ctx->data < ctx->end_data) {
dwarf2_abbrev_entry_t* entry = NULL;
unsigned long entry_code;
unsigned long entry_ref = 0;
entry_ref = ctx->data - ctx->data_stream;
entry_code = dwarf2_leb128_as_unsigned(ctx);
TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
if (0 == entry_code) {
break ;
}
entry = dwarf2_abbrev_table_find_entry(ctx->abbrev_table, entry_code);
assert( NULL != entry );
switch (entry->tag) {
case DW_TAG_typedef:
{
struct symt_typedef* symt = dwarf2_parse_typedef(module, entry, ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_base_type:
{
struct symt_basic* symt = dwarf2_parse_base_type(module, entry, ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_pointer_type:
{
struct symt_pointer* symt = dwarf2_parse_pointer_type(module, entry, ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_class_type:
{
struct symt_udt* symt = dwarf2_parse_class_type(module, entry, ctx);
if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_structure_type:
{
struct symt_udt* symt = dwarf2_parse_struct_type(module, entry, ctx);
if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_union_type:
{
struct symt_udt* symt = dwarf2_parse_union_type(module, entry, ctx);
if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_array_type:
{
struct symt_array* symt = dwarf2_parse_array_type(module, entry, ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_const_type:
{
struct symt_typedef* symt = dwarf2_parse_const_type(module, entry, ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_reference_type:
{
struct symt_typedef* symt = dwarf2_parse_reference_type(module, entry, ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_enumeration_type:
{
struct symt_enum* symt = dwarf2_parse_enumeration_type(module, entry, ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_subprogram:
{
struct symt_function* symt = dwarf2_parse_subprogram(module, entry, ctx, compiland);
if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
default:
{
dwarf2_abbrev_entry_attr_t* attr;
TRACE("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
dwarf2_parse_attr(attr, ctx);
}
}
break;
}
}
--ctx->level;
}
}
static struct symt_compiland* dwarf2_parse_compiland(struct module* module, dwarf2_abbrev_entry_t* entry, dwarf2_parse_context_t* ctx)
{
struct symt_compiland* compiland = NULL;
const char* name = NULL;
unsigned long next_sibling = 0;
dwarf2_abbrev_entry_attr_t* attr = NULL;
TRACE("beginning at Ox%x, for %lu\n", ctx->data - ctx->start_data, entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
switch (attr->attribute) {
case DW_AT_sibling:
next_sibling = dwarf2_parse_attr_as_ref(attr, ctx);
break;
case DW_AT_name:
name = dwarf2_parse_attr_as_string(attr, ctx);
TRACE("found name %s\n", name);
break;
default:
TRACE("Unhandled attr at %s, for %s\n", dwarf2_debug_ctx(ctx), dwarf2_debug_attr(attr));
dwarf2_parse_attr(attr, ctx);
}
}
compiland = symt_new_compiland(module, name);
dwarf2_parse_compiland_content(module, entry, ctx, compiland);
dwarf2_check_sibling(ctx, next_sibling);
return compiland;
}
BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
......@@ -975,10 +1850,7 @@ BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
dwarf2_comp_unit_t comp_unit;
dwarf2_parse_context_t ctx;
dwarf2_parse_context_t abbrev_ctx;
unsigned level = 0;
struct symt_compiland* compiland = NULL;
struct symt_function* curr_func = NULL;
struct symt_udt* curr_udt = NULL;
comp_unit_stream = (dwarf2_comp_unit_stream_t*) comp_unit_cursor;
......@@ -993,10 +1865,12 @@ BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
TRACE("- abbrev_offset: %lu\n", comp_unit.abbrev_offset);
TRACE("- word_size: %u\n", comp_unit.word_size);
ctx.data_stream = debug;
ctx.data = ctx.start_data = comp_unit_cursor + sizeof(dwarf2_comp_unit_stream_t);
ctx.offset = comp_unit_cursor - debug;
ctx.word_size = comp_unit.word_size;
ctx.str_section = str;
ctx.level = 0;
comp_unit_cursor += comp_unit.length + sizeof(unsigned);
ctx.end_data = comp_unit_cursor;
......@@ -1006,29 +1880,26 @@ BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
continue ;
}
abbrev_ctx.abbrev_table = NULL;
abbrev_ctx.data_stream = abbrev;
abbrev_ctx.data = abbrev_ctx.start_data = abbrev + comp_unit.abbrev_offset;
abbrev_ctx.end_data = abbrev + abbrev_size;
abbrev_ctx.offset = comp_unit.abbrev_offset;
abbrev_ctx.str_section = str;
abbrev_table = dwarf2_parse_abbrev_set(&abbrev_ctx);
ctx.abbrev_table = abbrev_table;
while (ctx.data < ctx.end_data) {
unsigned long entry_code;
dwarf2_abbrev_entry_t* entry = NULL;
unsigned long entry_code;
unsigned long entry_ref = 0;
entry_ref = ctx.data - debug;
entry_ref = ctx.data - ctx.data_stream;
entry_code = dwarf2_leb128_as_unsigned(&ctx);
TRACE("found entry_code %lu at 0x%lx\n", entry_code, entry_ref);
if (0 == entry_code) {
--level;
if (2 > level) { /** returns to compunit level */
if (curr_func) {
symt_normalize_function(module, curr_func);
curr_func = NULL;
}
}
continue ;
}
entry = dwarf2_abbrev_table_find_entry(abbrev_table, entry_code);
......@@ -1039,7 +1910,6 @@ BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
}
switch (entry->tag) {
case DW_TAG_compile_unit:
{
struct symt_compiland* symt = dwarf2_parse_compiland(module, entry, &ctx);
......@@ -1047,78 +1917,16 @@ BOOL dwarf2_parse(struct module* module, unsigned long load_offset,
compiland = symt;
}
break;
case DW_TAG_typedef:
{
struct symt_typedef* symt = dwarf2_parse_typedef(module, entry, &ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_base_type:
{
struct symt_basic* symt = dwarf2_parse_base_type(module, entry, &ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_pointer_type:
{
struct symt_pointer* symt = dwarf2_parse_pointer_type(module, entry, &ctx);
dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
}
break;
case DW_TAG_class_type:
{
struct symt_udt* symt = dwarf2_parse_class_type(module, entry, &ctx);
if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
curr_udt = symt;
}
break;
case DW_TAG_structure_type:
{
struct symt_udt* symt = dwarf2_parse_struct_type(module, entry, &ctx);
if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
curr_udt = symt;
}
break;
case DW_TAG_union_type:
{
struct symt_udt* symt = dwarf2_parse_union_type(module, entry, &ctx);
if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
curr_udt = symt;
}
break;
case DW_TAG_subprogram:
{
struct symt_function* symt = dwarf2_parse_subprogram(module, entry, &ctx, compiland);
if (NULL != symt) dwarf2_add_symt_ref(module, entry_ref, &symt->symt);
curr_func = symt;
}
break;
case DW_TAG_array_type:
case DW_TAG_formal_parameter:
case DW_TAG_reference_type:
case DW_TAG_inheritance:
case DW_TAG_member:
case DW_TAG_enumeration_type:
case DW_TAG_enumerator:
default:
{
dwarf2_abbrev_entry_attr_t* attr;
TRACE("Unhandled Tag type 0x%lx beginning at %p, for %lu\n", entry->tag, ctx.data, entry->entry_code);
TRACE("Unhandled Tag type 0x%lx at %s, for %lu\n", entry->tag, dwarf2_debug_ctx(&ctx), entry->entry_code);
for (attr = entry->attrs; NULL != attr; attr = attr->next) {
dwarf2_parse_attr(attr, &ctx);
}
}
break;
}
if (entry->have_child) {
++level;
}
}
dwarf2_abbrev_table_free(abbrev_table);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment