|
|
|
@ -768,30 +768,16 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
@@ -768,30 +768,16 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
|
|
|
|
|
u32 depth = 0; |
|
|
|
|
u64 base_data_offset = data_offset - header_size; |
|
|
|
|
|
|
|
|
|
int found_sr = 0; |
|
|
|
|
|
|
|
|
|
struct mi_function *func = dest->functions + dest->func_count; |
|
|
|
|
struct mi_compunit *comp_unit = dest->compilation_units + dest->cu_count; |
|
|
|
|
struct mi_block *block = comp_unit->blocks; |
|
|
|
|
struct mi_variable *variable = block->variables; |
|
|
|
|
|
|
|
|
|
enum dwarf_die_tag parent = 0; |
|
|
|
|
struct mi_function *func = dest->functions + dest->func_count; |
|
|
|
|
struct mi_variable *variable = dest->variables + dest->var_count; |
|
|
|
|
|
|
|
|
|
// TODO: make this not bad
|
|
|
|
|
comp_unit->functions_from = dest->func_count; |
|
|
|
|
|
|
|
|
|
for (;;) { |
|
|
|
|
data_offset += decode_leb128(file + data_offset, &code); |
|
|
|
|
|
|
|
|
|
if (code == 0) { |
|
|
|
|
// NOTE: finalize parent
|
|
|
|
|
if (parent == DW_TAG_lexical_block) { |
|
|
|
|
block->high_pc = block->low_pc + block->high_pc; |
|
|
|
|
++block; |
|
|
|
|
++comp_unit->block_count; |
|
|
|
|
variable = block->variables; |
|
|
|
|
__builtin_trap(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (depth > 1) { |
|
|
|
|
--depth; |
|
|
|
|
continue; |
|
|
|
@ -808,7 +794,6 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
@@ -808,7 +794,6 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
|
|
|
|
|
|
|
|
|
|
u32 has_children = file[schema_offset++]; |
|
|
|
|
if (has_children) { |
|
|
|
|
parent = tag; |
|
|
|
|
++depth; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -828,7 +813,7 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
@@ -828,7 +813,7 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
|
|
|
|
|
} else if (attribute == DW_AT_high_pc) { |
|
|
|
|
comp_unit->high_pc = value; |
|
|
|
|
} else if (attribute == DW_AT_comp_dir) { |
|
|
|
|
comp_unit->comp_dir = (char *) value; |
|
|
|
|
comp_unit->source.comp_dir = (char *) value; |
|
|
|
|
} |
|
|
|
|
} else if (tag == DW_TAG_subprogram) { |
|
|
|
|
if (attribute == DW_AT_name) { |
|
|
|
@ -838,12 +823,6 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
@@ -838,12 +823,6 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
|
|
|
|
|
} else if (attribute == DW_AT_high_pc) { |
|
|
|
|
func->high_pc = value; |
|
|
|
|
} |
|
|
|
|
} else if (tag == DW_TAG_lexical_block) { |
|
|
|
|
if (attribute == DW_AT_low_pc) { |
|
|
|
|
block->low_pc = value; |
|
|
|
|
} else if (attribute == DW_AT_high_pc) { |
|
|
|
|
block->high_pc = value; |
|
|
|
|
} |
|
|
|
|
} else if (tag == DW_TAG_variable) { |
|
|
|
|
if (attribute == DW_AT_name) { |
|
|
|
|
variable->name = (char *) value; |
|
|
|
@ -853,16 +832,18 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
@@ -853,16 +832,18 @@ read_debug_info_for_compilation_unit(u8 *file, struct mi_debuginfo *dest,
|
|
|
|
|
} |
|
|
|
|
} while (attribute != 0 || form != 0); |
|
|
|
|
|
|
|
|
|
if (parent == DW_TAG_variable) { |
|
|
|
|
++variable; |
|
|
|
|
++block->var_count; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (parent == DW_TAG_subprogram) { |
|
|
|
|
// NOTE(aolo2): DIE completely processed, finish it up
|
|
|
|
|
if (tag == DW_TAG_subprogram) { |
|
|
|
|
func->high_pc = func->low_pc + func->high_pc; |
|
|
|
|
func->comp_unit = dest->cu_count; |
|
|
|
|
++func; |
|
|
|
|
func->variables_from = dest->var_count; |
|
|
|
|
++comp_unit->functions_count; |
|
|
|
|
++dest->func_count; |
|
|
|
|
++func; |
|
|
|
|
} else if (tag == DW_TAG_variable) { |
|
|
|
|
struct mi_function *parent = func - 1; |
|
|
|
|
++parent->variables_count; |
|
|
|
|
++dest->var_count; |
|
|
|
|
++variable; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -900,14 +881,14 @@ parse_debug_info(u8 *file, struct mi_debuginfo *dest)
@@ -900,14 +881,14 @@ parse_debug_info(u8 *file, struct mi_debuginfo *dest)
|
|
|
|
|
static u64 |
|
|
|
|
read_debug_line_for_compilation_unit(u8 *file, u64 dl_offset, struct mi_compunit *unit) |
|
|
|
|
{ |
|
|
|
|
struct mi_sourcepoint *dest = unit->sp_table; |
|
|
|
|
int *dest_size = &unit->sp_count; |
|
|
|
|
struct mi_sourcepoint *dest = unit->source.sp_table; |
|
|
|
|
int *dest_size = &unit->source.sp_count; |
|
|
|
|
|
|
|
|
|
struct mi_sourcefile *dest_files = unit->source_files; |
|
|
|
|
int *dest_files_size = &unit->source_file_count; |
|
|
|
|
struct mi_sourcefile *dest_files = unit->source.source_files; |
|
|
|
|
int *dest_files_size = &unit->source.source_file_count; |
|
|
|
|
|
|
|
|
|
char **dest_directories = unit->source_directories; |
|
|
|
|
int *dest_directories_size = &unit->source_dirs_count; |
|
|
|
|
char **dest_directories = unit->source.source_directories; |
|
|
|
|
int *dest_directories_size = &unit->source.source_dirs_count; |
|
|
|
|
|
|
|
|
|
struct dwarf_debug_line_header_v3_x32 header = { 0 }; |
|
|
|
|
memcpy(&header, file + dl_offset, 15); /* all fixed-size info */ |
|
|
|
@ -1246,9 +1227,9 @@ parse_debug_line(u8 *file, struct mi_debuginfo *debug)
@@ -1246,9 +1227,9 @@ parse_debug_line(u8 *file, struct mi_debuginfo *debug)
|
|
|
|
|
// count
|
|
|
|
|
for (;;) { |
|
|
|
|
u64 size = read_debug_line_for_compilation_unit(file, at, unit); |
|
|
|
|
unit->sp_table = calloc(1, unit->sp_count * sizeof(struct mi_sourcepoint)); |
|
|
|
|
unit->source_directories = calloc(1, unit->source_dirs_count * sizeof(char *)); |
|
|
|
|
unit->source_files = calloc(1, unit->source_file_count * sizeof(struct mi_sourcefile)); |
|
|
|
|
unit->source.sp_table = calloc(1, unit->source.sp_count * sizeof(struct mi_sourcepoint)); |
|
|
|
|
unit->source.source_directories = calloc(1, unit->source.source_dirs_count * sizeof(char *)); |
|
|
|
|
unit->source.source_files = calloc(1, unit->source.source_file_count * sizeof(struct mi_sourcefile)); |
|
|
|
|
read += size; |
|
|
|
|
at += size; |
|
|
|
|
++unit; |
|
|
|
|