revert DWARF changes to commit bda3a71379

This commit is contained in:
Nikita Smith
2025-11-13 10:53:29 -08:00
parent 2a76093e17
commit 7cafde3376
27 changed files with 2103 additions and 2304 deletions
+2 -68
View File
@@ -2769,14 +2769,14 @@ str8_serial_push_string(Arena *arena, String8List *srl, String8 str){
internal U64 internal U64
str8_deserial_read(String8 string, U64 off, void *read_dst, U64 read_size, U64 granularity) str8_deserial_read(String8 string, U64 off, void *read_dst, U64 read_size, U64 granularity)
{ {
U64 bytes_left = string.size - Min(off, string.size); U64 bytes_left = string.size-Min(off, string.size);
U64 actually_readable_size = Min(bytes_left, read_size); U64 actually_readable_size = Min(bytes_left, read_size);
U64 legally_readable_size = actually_readable_size - actually_readable_size%granularity; U64 legally_readable_size = actually_readable_size - actually_readable_size%granularity;
if(legally_readable_size > 0) if(legally_readable_size > 0)
{ {
MemoryCopy(read_dst, string.str+off, legally_readable_size); MemoryCopy(read_dst, string.str+off, legally_readable_size);
} }
return actually_readable_size; return legally_readable_size;
} }
internal U64 internal U64
@@ -2838,72 +2838,6 @@ str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out)
return block_out->size; return block_out->size;
} }
internal U64
str8_deserial_read_uleb128(String8 string, U64 off, U64 *value_out)
{
U64 value = 0;
U64 shift = 0;
U64 cursor = off;
for(;;)
{
U8 byte = 0;
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
if(bytes_read != sizeof(byte))
{
break;
}
U8 val = byte & 0x7fu;
value |= ((U64)val) << shift;
cursor += bytes_read;
shift += 7u;
if((byte & 0x80u) == 0)
{
break;
}
}
if(value_out != 0)
{
*value_out = value;
}
U64 bytes_read = cursor - off;
return bytes_read;
}
internal U64
str8_deserial_read_sleb128(String8 string, U64 off, S64 *value_out)
{
U64 value = 0;
U64 shift = 0;
U64 cursor = off;
for(;;)
{
U8 byte = 0;
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
if(bytes_read != sizeof(byte))
{
break;
}
U8 val = byte & 0x7fu;
value |= ((U64)val) << shift;
cursor += bytes_read;
shift += 7u;
if((byte & 0x80u) == 0)
{
if(shift < sizeof(value) * 8 && (byte & 0x40u) != 0)
{
value |= -(S64)(1ull << shift);
}
break;
}
}
if(value_out != 0)
{
*value_out = value;
}
U64 bytes_read = cursor - off;
return bytes_read;
}
//////////////////////////////// ////////////////////////////////
internal int internal int
-2
View File
@@ -444,8 +444,6 @@ internal U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 of
internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out); internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out);
#define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr))*(count), sizeof(*(ptr))) #define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr))*(count), sizeof(*(ptr)))
#define str8_deserial_read_struct(string, off, ptr) str8_deserial_read_array(string, off, ptr, 1) #define str8_deserial_read_struct(string, off, ptr) str8_deserial_read_array(string, off, ptr, 1)
internal U64 str8_deserial_read_uleb128(String8 string, U64 off, U64 *value_out);
internal U64 str8_deserial_read_sleb128(String8 string, U64 off, S64 *value_out);
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic String Hashes //~ rjf: Basic String Hashes
+1 -1
View File
@@ -1978,7 +1978,7 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
// compute CIE address // compute CIE address
U64 cie_delta_off = fde_format == DW_Format_32Bit ? 4 : 12; U64 cie_delta_off = fde_format == DW_Format_32Bit ? 4 : 12;
U64 cie_delta = 0; U64 cie_delta = 0;
U64 cie_delta_size = dw_str8_deserial_read_fmt_uint(fde_data, cie_delta_off, fde_format, &cie_delta); U64 cie_delta_size = str8_deserial_read_dwarf_uint(fde_data, cie_delta_off, fde_format, &cie_delta);
if (cie_delta_size == 0) { goto eh_parse_exit; } if (cie_delta_size == 0) { goto eh_parse_exit; }
cie_addr = (fde_addr + cie_delta_off) - cie_delta; cie_addr = (fde_addr + cie_delta_off) - cie_delta;
} }
+20 -22
View File
@@ -194,7 +194,7 @@ dw_attrib_class_from_attrib_mips(DW_AttribKind k)
} }
internal DW_AttribClass internal DW_AttribClass
dw_attrib_class_from_kind(DW_Version ver, DW_Ext ext, DW_AttribKind k) dw_attrib_class_from_attrib(DW_Version ver, DW_Ext ext, DW_AttribKind k)
{ {
DW_AttribClass result = DW_AttribClass_Null; DW_AttribClass result = DW_AttribClass_Null;
@@ -285,57 +285,51 @@ dw_are_attrib_class_and_form_kind_compatible(DW_Version ver, DW_AttribClass attr
internal String8 internal String8
dw_name_string_from_section_kind(DW_SectionKind k) dw_name_string_from_section_kind(DW_SectionKind k)
{ {
String8 result = {0}; switch (k) {
switch(k) #define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_L);
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_L);}break;
DW_SectionKind_XList(X) DW_SectionKind_XList(X)
#undef X #undef X
} }
return result; return str8_zero();
} }
internal String8 internal String8
dw_mach_name_string_from_section_kind(DW_SectionKind k) dw_mach_name_string_from_section_kind(DW_SectionKind k)
{ {
String8 result = {0}; switch (k) {
switch(k) #define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_M);
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_M);}break;
DW_SectionKind_XList(X) DW_SectionKind_XList(X)
#undef X #undef X
} }
return result; return str8_zero();
} }
internal String8 internal String8
dw_dwo_name_string_from_section_kind(DW_SectionKind k) dw_dwo_name_string_from_section_kind(DW_SectionKind k)
{ {
String8 result = {0}; switch (k) {
switch(k) #define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_D);
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_D);}break;
DW_SectionKind_XList(X) DW_SectionKind_XList(X)
#undef X #undef X
} }
return result; return str8_zero();
} }
internal U64 internal U64
dw_size_from_format(DW_Format format) dw_size_from_format(DW_Format format)
{ {
U64 result = 0; U64 result = 0;
switch(format) switch (format) {
{ case DW_Format_Null: break;
default:{}break;
case DW_Format_32Bit: result = 4; break; case DW_Format_32Bit: result = 4; break;
case DW_Format_64Bit: result = 8; break; case DW_Format_64Bit: result = 8; break;
default: InvalidPath; break;
} }
return result; return result;
} }
internal DW_AttribClass internal DW_AttribClass
dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, DW_AttribKind attrib_kind, DW_FormKind form_kind) dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKind attrib_kind, DW_FormKind form_kind)
{ {
// NOTE(rjf): DWARF's spec specifies two mappings: // NOTE(rjf): DWARF's spec specifies two mappings:
// (DW_AttribKind) => List(DW_AttribClass) // (DW_AttribKind) => List(DW_AttribClass)
@@ -344,13 +338,17 @@ dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, DW_AttribKind attrib_kind
// This function's purpose is to find the overlapping class between an // This function's purpose is to find the overlapping class between an
// DW_AttribKind and DW_FormKind. // DW_AttribKind and DW_FormKind.
DW_AttribClass attrib_class = dw_attrib_class_from_kind(ver, ext, attrib_kind); DW_AttribClass attrib_class = dw_attrib_class_from_attrib(ver, ext, attrib_kind);
DW_AttribClass form_class = dw_attrib_class_from_form_kind(ver, form_kind); DW_AttribClass form_class = dw_attrib_class_from_form_kind(ver, form_kind);
if(relaxed)
{
if(attrib_class == DW_AttribClass_Null || form_class == DW_AttribClass_Null) if(attrib_class == DW_AttribClass_Null || form_class == DW_AttribClass_Null)
{ {
attrib_class = dw_attrib_class_from_kind(DW_Version_Last, ext, attrib_kind); attrib_class = dw_attrib_class_from_attrib(DW_Version_Last, ext, attrib_kind);
form_class = dw_attrib_class_from_form_kind(DW_Version_Last, form_kind); form_class = dw_attrib_class_from_form_kind(DW_Version_Last, form_kind);
} }
}
DW_AttribClass result = DW_AttribClass_Null; DW_AttribClass result = DW_AttribClass_Null;
if(attrib_class != DW_AttribClass_Null && form_class != DW_AttribClass_Null) if(attrib_class != DW_AttribClass_Null && form_class != DW_AttribClass_Null)
+4 -4
View File
@@ -478,7 +478,7 @@ X(GNU_RefAlt, DW_AttribClass_Undefined) \
X(GNU_StrpAlt, DW_AttribClass_String) X(GNU_StrpAlt, DW_AttribClass_String)
typedef U64 DW_FormKind; typedef U64 DW_FormKind;
typedef enum DW_FormKindEnum typedef enum DW_FormEnum
{ {
DW_Form_Null, DW_Form_Null,
#define X(_N, _ID) DW_Form_##_N = _ID, #define X(_N, _ID) DW_Form_##_N = _ID,
@@ -487,7 +487,7 @@ typedef enum DW_FormKindEnum
DW_Form_V5_XList(X) DW_Form_V5_XList(X)
DW_Form_GNU_XList(X) DW_Form_GNU_XList(X)
#undef X #undef X
} DW_FormKindEnum; } DW_FormEnum;
//- Attributes DWARF2 //- Attributes DWARF2
@@ -1762,7 +1762,7 @@ internal DW_AttribClass dw_attrib_class_from_attrib_llvm (DW_AttribKind k);
internal DW_AttribClass dw_attrib_class_from_attrib_apple(DW_AttribKind k); internal DW_AttribClass dw_attrib_class_from_attrib_apple(DW_AttribKind k);
internal DW_AttribClass dw_attrib_class_from_attrib_mips (DW_AttribKind k); internal DW_AttribClass dw_attrib_class_from_attrib_mips (DW_AttribKind k);
internal DW_AttribClass dw_attrib_class_from_kind(DW_Version ver, DW_Ext ext, DW_AttribKind v); internal DW_AttribClass dw_attrib_class_from_attrib(DW_Version ver, DW_Ext ext, DW_AttribKind v);
//- Form Class Encodings //- Form Class Encodings
@@ -1782,7 +1782,7 @@ internal U64 dw_size_from_format(DW_Format format);
//////////////////////////////// ////////////////////////////////
internal DW_AttribClass dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, DW_AttribKind attrib, DW_FormKind form_kind); internal DW_AttribClass dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKind attrib, DW_FormKind form_kind);
internal U64 dw_pick_default_lower_bound(DW_Language lang); internal U64 dw_pick_default_lower_bound(DW_Language lang);
+4 -3
View File
@@ -23,14 +23,14 @@ dw_is_dwarf_present_coff_section_table(String8 string_table, U64 section_count,
return is_dwarf_present; return is_dwarf_present;
} }
internal DW_Raw internal DW_Input
dw_raw_from_coff_section_table(Arena *arena, dw_input_from_coff_section_table(Arena *arena,
String8 raw_image, String8 raw_image,
String8 string_table, String8 string_table,
U64 section_count, U64 section_count,
COFF_SectionHeader *section_table) COFF_SectionHeader *section_table)
{ {
DW_Raw input = {0}; DW_Input input = {0};
B32 sect_status[ArrayCount(input.sec)] = {0}; B32 sect_status[ArrayCount(input.sec)] = {0};
for (U64 i = 0; i < section_count; ++i) { for (U64 i = 0; i < section_count; ++i) {
@@ -51,6 +51,7 @@ dw_raw_from_coff_section_table(Arena *arena,
} else { } else {
sect_status[s] = 1; sect_status[s] = 1;
DW_Section *d = &input.sec[s]; DW_Section *d = &input.sec[s];
d->name = push_str8_copy(arena, name);
d->data = str8_substr(raw_image, raw_data_range); d->data = str8_substr(raw_image, raw_data_range);
d->is_dwo = is_dwo; d->is_dwo = is_dwo;
} }
+2 -1
View File
@@ -5,6 +5,7 @@
#define DWARF_COFF_H #define DWARF_COFF_H
internal B32 dw_is_dwarf_present_coff_section_table(String8 string_table, U64 section_count, COFF_SectionHeader *section_table); internal B32 dw_is_dwarf_present_coff_section_table(String8 string_table, U64 section_count, COFF_SectionHeader *section_table);
internal DW_Raw dw_raw_from_coff_section_table(Arena *arena, String8 raw_image, String8 string_table, U64 section_count, COFF_SectionHeader *section_table); internal DW_Input dw_input_from_coff_section_table(Arena *arena, String8 raw_image, String8 string_table, U64 section_count, COFF_SectionHeader *section_table);
#endif // DWARF_COFF_H #endif // DWARF_COFF_H
+20 -19
View File
@@ -211,13 +211,13 @@ dw_string_list_from_expression(Arena *arena, String8 raw_data, U64 cu_base, U64
} break; } break;
case DW_ExprOp_CallRef: { case DW_ExprOp_CallRef: {
U64 x = 0; U64 x = 0;
cursor += dw_str8_deserial_read_fmt_uint(raw_data, cursor, format, &x); cursor += str8_deserial_read_dwarf_uint(raw_data, cursor, format, &x);
op_value = push_str8f(scratch.arena, "%llu", x); op_value = push_str8f(scratch.arena, "%llu", x);
} break; } break;
case DW_ExprOp_ImplicitPointer: case DW_ExprOp_ImplicitPointer:
case DW_ExprOp_GNU_ImplicitPointer: { case DW_ExprOp_GNU_ImplicitPointer: {
U64 info_off = 0; U64 info_off = 0;
cursor += dw_str8_deserial_read_fmt_uint(raw_data, cursor, format, &info_off); cursor += str8_deserial_read_dwarf_uint(raw_data, cursor, format, &info_off);
S64 ptr = 0; S64 ptr = 0;
cursor += str8_deserial_read_sleb128(raw_data, cursor, &ptr); cursor += str8_deserial_read_sleb128(raw_data, cursor, &ptr);
@@ -489,7 +489,7 @@ dw_string_list_from_cfi_program(Arena *arena,
} }
} }
exit:; exit:;
scratch_end(scratch); scratch_end(scratch);
return list; return list;
} }
@@ -680,7 +680,7 @@ dw_print_eh_frame(Arena *arena, String8List *out, String8 indent, String8 raw_eh
} }
internal void internal void
dw_print_debug_loc(Arena *arena, String8List *out, String8 indent, DW_Raw *input, Arch arch, ExecutableImageKind image_type, B32 relaxed) dw_print_debug_loc(Arena *arena, String8List *out, String8 indent, DW_Input *input, Arch arch, ExecutableImageKind image_type, B32 relaxed)
{ {
#if 0 #if 0
DW_Section info = input->sec[DW_Section_Info]; DW_Section info = input->sec[DW_Section_Info];
@@ -827,7 +827,7 @@ dw_print_debug_loc(Arena *arena, String8List *out, String8 indent, DW_Raw *input
} }
internal void internal void
dw_print_debug_ranges(Arena *arena, String8List *out, String8 indent, DW_Raw *input, Arch arch, ExecutableImageKind image_type, B32 relaxed) dw_print_debug_ranges(Arena *arena, String8List *out, String8 indent, DW_Input *input, Arch arch, ExecutableImageKind image_type, B32 relaxed)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -933,7 +933,7 @@ dw_print_debug_ranges(Arena *arena, String8List *out, String8 indent, DW_Raw *in
} }
internal void internal void
dw_print_debug_aranges(Arena *arena, String8List *out, String8 indent, DW_Raw *input) dw_print_debug_aranges(Arena *arena, String8List *out, String8 indent, DW_Input *input)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1022,7 +1022,7 @@ dw_print_debug_aranges(Arena *arena, String8List *out, String8 indent, DW_Raw *i
} }
internal void internal void
dw_print_debug_addr(Arena *arena, String8List *out, String8 indent, DW_Raw *input) dw_print_debug_addr(Arena *arena, String8List *out, String8 indent, DW_Input *input)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1131,7 +1131,7 @@ dw_based_range_read_address(void *base, Rng1U64 range, U64 offset, Rng1U64Array
} }
internal void internal void
dw_print_debug_loclists(Arena *arena, String8List *out, String8 indent, DW_Raw *input, Rng1U64Array segment_virtual_ranges, Arch arch) dw_print_debug_loclists(Arena *arena, String8List *out, String8 indent, DW_Input *input, Rng1U64Array segment_virtual_ranges, Arch arch)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1284,7 +1284,7 @@ dw_print_debug_loclists(Arena *arena, String8List *out, String8 indent, DW_Raw *
} }
internal void internal void
dw_print_debug_rnglists(Arena *arena, String8List *out, String8 indent, DW_Raw *input, Rng1U64Array segment_ranges) dw_print_debug_rnglists(Arena *arena, String8List *out, String8 indent, DW_Input *input, Rng1U64Array segment_ranges)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1423,7 +1423,7 @@ dw_print_debug_rnglists(Arena *arena, String8List *out, String8 indent, DW_Raw *
} }
internal void internal void
dw_format_string_table(Arena *arena, String8List *out, String8 indent, DW_Raw *input, DW_SectionKind sec) dw_format_string_table(Arena *arena, String8List *out, String8 indent, DW_Input *input, DW_SectionKind sec)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1485,19 +1485,19 @@ dw_format_string_table(Arena *arena, String8List *out, String8 indent, DW_Raw *i
} }
internal void internal void
dw_print_debug_pubnames(Arena *arena, String8List *out, String8 indent, DW_Raw *input) dw_print_debug_pubnames(Arena *arena, String8List *out, String8 indent, DW_Input *input)
{ {
dw_format_string_table(arena, out, indent, input, DW_Section_PubNames); dw_format_string_table(arena, out, indent, input, DW_Section_PubNames);
} }
internal void internal void
dw_print_debug_pubtypes(Arena *arena, String8List *out, String8 indent, DW_Raw *input) dw_print_debug_pubtypes(Arena *arena, String8List *out, String8 indent, DW_Input *input)
{ {
dw_format_string_table(arena, out, indent, input, DW_Section_PubTypes); dw_format_string_table(arena, out, indent, input, DW_Section_PubTypes);
} }
internal void internal void
dw_print_debug_line_str(Arena *arena, String8List *out, String8 indent, DW_Raw *input) dw_print_debug_line_str(Arena *arena, String8List *out, String8 indent, DW_Input *input)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1527,7 +1527,7 @@ dw_print_debug_line_str(Arena *arena, String8List *out, String8 indent, DW_Raw *
} }
internal void internal void
dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_Raw *input) dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_Input *input)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1598,7 +1598,7 @@ dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_Ra
//~ rjf: Dump Entry Point //~ rjf: Dump Entry Point
internal String8 internal String8
dw_string_from_attrib_value(Arena *arena, DW_Raw *input, Arch arch, DW_CompUnit *unit, DW_LineVMHeader *line_vm, DW_Attrib *attrib) dw_string_from_attrib_value(Arena *arena, DW_Input *input, Arch arch, DW_CompUnit *unit, DW_LineVMHeader *line_vm, DW_Attrib *attrib)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -1737,7 +1737,7 @@ dw_string_from_attrib_value(Arena *arena, DW_Raw *input, Arch arch, DW_CompUnit
internal String8List internal String8List
dw_dump_list_from_sections(Arena *arena, dw_dump_list_from_sections(Arena *arena,
DW_Raw *input, DW_Input *input,
Arch arch, Arch arch,
DW_DumpSubsetFlags subset_flags) DW_DumpSubsetFlags subset_flags)
{ {
@@ -1748,17 +1748,18 @@ dw_dump_list_from_sections(Arena *arena,
#define DumpSubset(name) if(subset_flags & DW_DumpSubsetFlag_##name) DeferLoop(dumpf("// %S\n\n", dw_name_title_from_dump_subset_table[DW_DumpSubset_##name]), dump(str8_lit("\n"))) #define DumpSubset(name) if(subset_flags & DW_DumpSubsetFlag_##name) DeferLoop(dumpf("// %S\n\n", dw_name_title_from_dump_subset_table[DW_DumpSubset_##name]), dump(str8_lit("\n")))
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
Rng1U64Array segment_vranges = {0}; Rng1U64Array segment_vranges = {0};
DW_ListUnitInput lu_input = dw_list_unit_input_from_raw(scratch.arena, input); DW_ListUnitInput lu_input = dw_list_unit_input_from_input(scratch.arena, input);
B32 relaxed = 1;
DW_CompUnit *cu_arr; DW_CompUnit *cu_arr;
{ {
DW_ListUnitInput lu_input = dw_list_unit_input_from_raw(scratch.arena, input); DW_ListUnitInput lu_input = dw_list_unit_input_from_input(scratch.arena, input);
Rng1U64List cu_range_list = dw_unit_ranges_from_data(scratch.arena, input->sec[DW_Section_Info].data); Rng1U64List cu_range_list = dw_unit_ranges_from_data(scratch.arena, input->sec[DW_Section_Info].data);
Rng1U64Array cu_ranges = rng1u64_array_from_list(scratch.arena, &cu_range_list); Rng1U64Array cu_ranges = rng1u64_array_from_list(scratch.arena, &cu_range_list);
cu_arr = push_array(scratch.arena, DW_CompUnit, cu_ranges.count); cu_arr = push_array(scratch.arena, DW_CompUnit, cu_ranges.count);
for EachIndex(cu_idx, cu_ranges.count) for EachIndex(cu_idx, cu_ranges.count)
{ {
cu_arr[cu_idx] = dw_cu_from_info_off(scratch.arena, input, lu_input, cu_ranges.v[cu_idx].min); cu_arr[cu_idx] = dw_cu_from_info_off(scratch.arena, input, lu_input, cu_ranges.v[cu_idx].min, relaxed);
} }
} }
+11 -11
View File
@@ -70,21 +70,21 @@ internal String8 dw_string_from_cfi_row(Arena *arena, Arch arch, U64 address_siz
#if 0 #if 0
internal void dw_print_eh_frame (Arena *arena, String8List *out, String8 indent, String8 raw_eh_frame, Arch arch, DW_Version ver, DW_Ext ext, EH_PtrCtx *ptr_ctx); internal void dw_print_eh_frame (Arena *arena, String8List *out, String8 indent, String8 raw_eh_frame, Arch arch, DW_Version ver, DW_Ext ext, EH_PtrCtx *ptr_ctx);
internal void dw_print_debug_loc (Arena *arena, String8List *out, String8 indent, DW_Raw *input, Arch arch, ExecutableImageKind image_type, B32 relaxed); internal void dw_print_debug_loc (Arena *arena, String8List *out, String8 indent, DW_Input *input, Arch arch, ExecutableImageKind image_type, B32 relaxed);
internal void dw_print_debug_ranges (Arena *arena, String8List *out, String8 indent, DW_Raw *input, Arch arch, ExecutableImageKind image_type, B32 relaxed); internal void dw_print_debug_ranges (Arena *arena, String8List *out, String8 indent, DW_Input *input, Arch arch, ExecutableImageKind image_type, B32 relaxed);
internal void dw_print_debug_aranges (Arena *arena, String8List *out, String8 indent, DW_Raw *input); internal void dw_print_debug_aranges (Arena *arena, String8List *out, String8 indent, DW_Input *input);
internal void dw_print_debug_addr (Arena *arena, String8List *out, String8 indent, DW_Raw *input); internal void dw_print_debug_addr (Arena *arena, String8List *out, String8 indent, DW_Input *input);
internal void dw_print_debug_loclists (Arena *arena, String8List *out, String8 indent, DW_Raw *input, Rng1U64Array segment_vranges, Arch arch); internal void dw_print_debug_loclists (Arena *arena, String8List *out, String8 indent, DW_Input *input, Rng1U64Array segment_vranges, Arch arch);
internal void dw_print_debug_rnglists (Arena *arena, String8List *out, String8 indent, DW_Raw *input, Rng1U64Array segment_vranges); internal void dw_print_debug_rnglists (Arena *arena, String8List *out, String8 indent, DW_Input *input, Rng1U64Array segment_vranges);
internal void dw_print_debug_pubnames (Arena *arena, String8List *out, String8 indent, DW_Raw *input); internal void dw_print_debug_pubnames (Arena *arena, String8List *out, String8 indent, DW_Input *input);
internal void dw_print_debug_pubtypes (Arena *arena, String8List *out, String8 indent, DW_Raw *input); internal void dw_print_debug_pubtypes (Arena *arena, String8List *out, String8 indent, DW_Input *input);
internal void dw_print_debug_line_str (Arena *arena, String8List *out, String8 indent, DW_Raw *input); internal void dw_print_debug_line_str (Arena *arena, String8List *out, String8 indent, DW_Input *input);
internal void dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_Raw *input); internal void dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_Input *input);
#endif #endif
//////////////////////////////// ////////////////////////////////
//~ rjf: Dump Entry Point //~ rjf: Dump Entry Point
internal String8List dw_dump_list_from_sections(Arena *arena, DW_Raw *input, Arch arch, DW_DumpSubsetFlags subset_flags); internal String8List dw_dump_list_from_sections(Arena *arena, DW_Input *input, Arch arch, DW_DumpSubsetFlags subset_flags);
#endif // DWARF_DUMP_H #endif // DWARF_DUMP_H
+4 -3
View File
@@ -27,10 +27,10 @@ dw_is_dwarf_present_from_elf_bin(String8 data, ELF_Bin *bin)
#define SINFL_IMPLEMENTATION #define SINFL_IMPLEMENTATION
#include "third_party/sinfl/sinfl.h" #include "third_party/sinfl/sinfl.h"
internal DW_Raw internal DW_Input
dw_raw_from_elf_bin(Arena *arena, String8 data, ELF_Bin *bin) dw_input_from_elf_bin(Arena *arena, String8 data, ELF_Bin *bin)
{ {
DW_Raw result = {0}; DW_Input result = {0};
B32 is_section_present[ArrayCount(result.sec)] = {0}; B32 is_section_present[ArrayCount(result.sec)] = {0};
for(U64 section_idx = 1; section_idx < bin->shdrs.count; section_idx += 1) for(U64 section_idx = 1; section_idx < bin->shdrs.count; section_idx += 1)
{ {
@@ -106,6 +106,7 @@ dw_raw_from_elf_bin(Arena *arena, String8 data, ELF_Bin *bin)
//- rjf: store //- rjf: store
is_section_present[section_kind] = 1; is_section_present[section_kind] = 1;
DW_Section *d = &result.sec[section_kind]; DW_Section *d = &result.sec[section_kind];
d->name = push_str8_copy(arena, section_name);
d->data = section_data__uncompressed; d->data = section_data__uncompressed;
d->is_dwo = is_dwo; d->is_dwo = is_dwo;
} }
+1 -1
View File
@@ -5,6 +5,6 @@
#define DWARF_ELF_H #define DWARF_ELF_H
internal B32 dw_is_dwarf_present_from_elf_bin(String8 raw_image, ELF_Bin *bin); internal B32 dw_is_dwarf_present_from_elf_bin(String8 raw_image, ELF_Bin *bin);
internal DW_Raw dw_raw_from_elf_bin(Arena *arena, String8 raw_image, ELF_Bin *bin); internal DW_Input dw_input_from_elf_bin(Arena *arena, String8 raw_image, ELF_Bin *bin);
#endif // DWARF_ELF_H #endif // DWARF_ELF_H
+1
View File
@@ -15,3 +15,4 @@ typedef struct DW_CallFrameInfo
internal DW_CallFrameInfo dw_call_frame_info_from_data(Arena *arena, Arch arch, U64 rebase, String8 debug_frame); internal DW_CallFrameInfo dw_call_frame_info_from_data(Arena *arena, Arch arch, U64 rebase, String8 debug_frame);
#endif // DWARF_HELP_H #endif // DWARF_HELP_H
-1
View File
@@ -4,7 +4,6 @@
#include "dwarf/dwarf.c" #include "dwarf/dwarf.c"
#include "dwarf/dwarf_expr.c" #include "dwarf/dwarf_expr.c"
#include "dwarf/dwarf_parse.c" #include "dwarf/dwarf_parse.c"
#include "dwarf/dwarf_parse_2.c"
#include "dwarf/dwarf_coff.c" #include "dwarf/dwarf_coff.c"
#include "dwarf/dwarf_elf.c" #include "dwarf/dwarf_elf.c"
#include "dwarf/dwarf_unwind.c" #include "dwarf/dwarf_unwind.c"
-1
View File
@@ -7,7 +7,6 @@
#include "dwarf/dwarf.h" #include "dwarf/dwarf.h"
#include "dwarf/dwarf_expr.h" #include "dwarf/dwarf_expr.h"
#include "dwarf/dwarf_parse.h" #include "dwarf/dwarf_parse.h"
#include "dwarf/dwarf_parse_2.h"
#include "dwarf/dwarf_coff.h" #include "dwarf/dwarf_coff.h"
#include "dwarf/dwarf_elf.h" #include "dwarf/dwarf_elf.h"
#include "dwarf/dwarf_unwind.h" #include "dwarf/dwarf_unwind.h"
+331 -198
View File
File diff suppressed because it is too large Load Diff
+95 -102
View File
@@ -4,34 +4,29 @@
#ifndef DWARF_PARSE_H #ifndef DWARF_PARSE_H
#define DWARF_PARSE_H #define DWARF_PARSE_H
//////////////////////////////// typedef struct DW_Section
//~ rjf: Raw DWARF Info Bundle
typedef struct DW_Section DW_Section;
struct DW_Section
{ {
String8 name;
String8 data; String8 data;
B32 is_dwo; B32 is_dwo;
}; } DW_Section;
typedef struct DW_Raw DW_Raw; typedef struct DW_Input
struct DW_Raw
{ {
DW_Section sec[DW_Section_Count]; DW_Section sec[DW_Section_Count];
}; DW_Section sup[DW_Section_Count];
} DW_Input;
typedef struct DW_ListUnit DW_ListUnit; typedef struct DW_ListUnit
struct DW_ListUnit
{ {
DW_Version version; DW_Version version;
U64 address_size; U64 address_size;
U64 segment_selector_size; U64 segment_selector_size;
U64 entry_size; U64 entry_size;
String8 entries; String8 entries;
}; } DW_ListUnit;
typedef struct DW_ListUnitInput DW_ListUnitInput; typedef struct DW_ListUnitInput
struct DW_ListUnitInput
{ {
U64 addr_count; U64 addr_count;
U64 str_offset_count; U64 str_offset_count;
@@ -45,14 +40,13 @@ struct DW_ListUnitInput
DW_ListUnit *str_offsets; DW_ListUnit *str_offsets;
DW_ListUnit *rnglists; DW_ListUnit *rnglists;
DW_ListUnit *loclists; DW_ListUnit *loclists;
}; } DW_ListUnitInput;
typedef struct DW_AbbrevTableEntry DW_AbbrevTableEntry; typedef struct DW_AbbrevTableEntry
struct DW_AbbrevTableEntry
{ {
U64 id; U64 id;
U64 off; U64 off;
}; } DW_AbbrevTableEntry;
typedef struct DW_AbbrevTable DW_AbbrevTable; typedef struct DW_AbbrevTable DW_AbbrevTable;
struct DW_AbbrevTable struct DW_AbbrevTable
@@ -69,8 +63,7 @@ typedef enum DW_AbbrevKind
DW_Abbrev_AttribSequenceEnd, DW_Abbrev_AttribSequenceEnd,
DW_Abbrev_DIEBegin, DW_Abbrev_DIEBegin,
DW_Abbrev_DIEEnd, DW_Abbrev_DIEEnd,
} } DW_AbbrevKind;
DW_AbbrevKind;
typedef U32 DW_AbbrevFlags; typedef U32 DW_AbbrevFlags;
enum enum
@@ -79,15 +72,14 @@ enum
DW_AbbrevFlag_HasChildren = (1 << 1), DW_AbbrevFlag_HasChildren = (1 << 1),
}; };
typedef struct DW_Abbrev DW_Abbrev; typedef struct DW_Abbrev
struct DW_Abbrev
{ {
DW_AbbrevKind kind; DW_AbbrevKind kind;
U64 sub_kind; U64 sub_kind;
U64 id; U64 id;
U64 const_value; U64 const_value;
DW_AbbrevFlags flags; DW_AbbrevFlags flags;
}; } DW_Abbrev;
typedef union DW_Form typedef union DW_Form
{ {
@@ -108,35 +100,32 @@ typedef union DW_Form
U64 rnglistx; U64 rnglistx;
U64 ptr; U64 ptr;
U64 implicit_const; U64 implicit_const;
} } DW_Form;
DW_Form;
typedef struct DW_Attrib DW_Attrib; typedef struct DW_Attrib
struct DW_Attrib
{ {
U64 info_off; U64 info_off;
U64 abbrev_off;
U64 abbrev_id;
DW_AttribKind attrib_kind; DW_AttribKind attrib_kind;
DW_FormKind form_kind; DW_FormKind form_kind;
DW_Form form; DW_Form form;
}; } DW_Attrib;
typedef struct DW_AttribNode DW_AttribNode; typedef struct DW_AttribNode
struct DW_AttribNode
{ {
DW_AttribNode *next; struct DW_AttribNode *next;
DW_Attrib v; DW_Attrib v;
}; } DW_AttribNode;
typedef struct DW_AttribList DW_AttribList; typedef struct DW_AttribList
struct DW_AttribList
{ {
DW_AttribNode *first; DW_AttribNode *first;
DW_AttribNode *last; DW_AttribNode *last;
U64 count; U64 count;
}; } DW_AttribList;
typedef struct DW_Tag DW_Tag; typedef struct DW_Tag
struct DW_Tag
{ {
B32 has_children; B32 has_children;
U64 abbrev_id; U64 abbrev_id;
@@ -144,42 +133,38 @@ struct DW_Tag
DW_AttribList attribs; DW_AttribList attribs;
U64 info_off; U64 info_off;
U8 v[1]; U8 v[1];
}; } DW_Tag;
typedef struct DW_TagNode DW_TagNode; typedef struct DW_TagNode
struct DW_TagNode
{ {
DW_Tag tag; DW_Tag tag;
DW_TagNode *sibling; struct DW_TagNode *sibling;
DW_TagNode *first_child; struct DW_TagNode *first_child;
DW_TagNode *last_child; struct DW_TagNode *last_child;
}; } DW_TagNode;
typedef struct DW_Loc DW_Loc; typedef struct DW_Loc
struct DW_Loc
{ {
Rng1U64 range; Rng1U64 range;
String8 expr; String8 expr;
}; } DW_Loc;
typedef struct DW_LocNode DW_LocNode; typedef struct DW_LocNode
struct DW_LocNode
{ {
DW_LocNode *next;
DW_Loc v; DW_Loc v;
}; struct DW_LocNode *next;
} DW_LocNode;
typedef struct DW_LocList DW_LocList; typedef struct DW_LocList
struct DW_LocList
{ {
U64 count;
DW_LocNode *first; DW_LocNode *first;
DW_LocNode *last; DW_LocNode *last;
U64 count; } DW_LocList;
};
typedef struct DW_CompUnit DW_CompUnit; typedef struct DW_CompUnit
struct DW_CompUnit
{ {
B32 relaxed;
DW_Ext ext; DW_Ext ext;
DW_CompUnitKind kind; DW_CompUnitKind kind;
DW_Version version; DW_Version version;
@@ -198,7 +183,7 @@ struct DW_CompUnit
U64 dwo_id; U64 dwo_id;
DW_Tag tag; DW_Tag tag;
HashTable *tag_ht; HashTable *tag_ht;
}; } DW_CompUnit;
typedef struct DW_TagTree typedef struct DW_TagTree
{ {
@@ -446,10 +431,18 @@ typedef struct DW_CFA_InstList
#define DW_DECODE_PTR(name) U64 name(String8 data, void *ud, U64 *ptr_out) #define DW_DECODE_PTR(name) U64 name(String8 data, void *ud, U64 *ptr_out)
typedef DW_DECODE_PTR(DW_DecodePtr); typedef DW_DECODE_PTR(DW_DecodePtr);
// hasher
internal U64 dw_hash_from_string(String8 string);
// deserial helpers // deserial helpers
internal U64 dw_str8_deserial_read_packed_size(String8 string, U64 off, U64 *size_out); internal U64 str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out);
internal U64 dw_str8_deserial_read_fmt_uint(String8 string, U64 off, DW_Format format, U64 *uint_out); internal U64 str8_deserial_read_dwarf_uint (String8 string, U64 off, DW_Format format, U64 *uint_out);
internal U64 str8_deserial_read_uleb128 (String8 string, U64 off, U64 *value_out);
internal U64 str8_deserial_read_sleb128 (String8 string, U64 off, S64 *value_out);
internal U64 str8_deserial_read_uleb128_array(Arena *arena, String8 string, U64 off, U64 count, U64 **arr_out);
internal U64 str8_deserial_read_sleb128_array(Arena *arena, String8 string, U64 off, U64 count, S64 **arr_out);
internal Rng1U64List dw_unit_ranges_from_data(Arena *arena, String8 data); internal Rng1U64List dw_unit_ranges_from_data(Arena *arena, String8 data);
@@ -459,7 +452,7 @@ internal U64 dw_read_list_unit_header_addr (String8 unit_data, DW_ListUnit
internal U64 dw_read_list_unit_header_str_offsets(String8 unit_data, DW_ListUnit *lu_out); internal U64 dw_read_list_unit_header_str_offsets(String8 unit_data, DW_ListUnit *lu_out);
internal U64 dw_read_list_unit_header_list (String8 unit_data, DW_ListUnit *lu_out); internal U64 dw_read_list_unit_header_list (String8 unit_data, DW_ListUnit *lu_out);
internal DW_ListUnitInput dw_list_unit_input_from_raw(Arena *arena, DW_Raw *input); internal DW_ListUnitInput dw_list_unit_input_from_input(Arena *arena, DW_Input *input);
internal U64 dw_offset_from_list_unit(DW_ListUnit *lu, U64 index); internal U64 dw_offset_from_list_unit(DW_ListUnit *lu, U64 index);
internal U64 dw_addr_from_list_unit (DW_ListUnit *lu, U64 index); internal U64 dw_addr_from_list_unit (DW_ListUnit *lu, U64 index);
@@ -475,7 +468,7 @@ internal U64 dw_abbrev_offset_from_abbrev_id(DW_AbbrevTable table, U6
internal U64 dw_read_form(String8 data, U64 off, DW_Version version, DW_Format unit_format, U64 address_size, DW_FormKind form_kind, U64 implicit_const, DW_Form *form_out); internal U64 dw_read_form(String8 data, U64 off, DW_Version version, DW_Format unit_format, U64 address_size, DW_FormKind form_kind, U64 implicit_const, DW_Form *form_out);
internal U64 dw_read_tag (Arena *arena, String8 tag_data, U64 tag_off, U64 tag_base, DW_AbbrevTable abbrev_table, String8 abbrev_data, DW_Version version, DW_Format unit_format, U64 address_size, DW_Tag *tag_out); internal U64 dw_read_tag (Arena *arena, String8 tag_data, U64 tag_off, U64 tag_base, DW_AbbrevTable abbrev_table, String8 abbrev_data, DW_Version version, DW_Format unit_format, U64 address_size, DW_Tag *tag_out);
internal U64 dw_read_tag_cu(Arena *arena, DW_Raw *input, DW_CompUnit *cu, U64 info_off, DW_Tag *tag_out); internal U64 dw_read_tag_cu(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 info_off, DW_Tag *tag_out);
// attrib interp // attrib interp
@@ -488,56 +481,56 @@ internal S64 dw_interp_const_s64 (DW_FormKind form_kind, DW_Form form)
internal S32 dw_interp_const_s32 (DW_FormKind form_kind, DW_Form form); internal S32 dw_interp_const_s32 (DW_FormKind form_kind, DW_Form form);
internal B32 dw_interp_flag (DW_FormKind form_kind, DW_Form form); internal B32 dw_interp_flag (DW_FormKind form_kind, DW_Form form);
internal U64 dw_interp_address (U64 address_size, U64 base_addr, DW_ListUnit *addr_xlist, DW_FormKind form_kind, DW_Form form); internal U64 dw_interp_address (U64 address_size, U64 base_addr, DW_ListUnit *addr_xlist, DW_FormKind form_kind, DW_Form form);
internal String8 dw_interp_block (DW_Raw *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form); internal String8 dw_interp_block (DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form);
internal String8 dw_interp_string (DW_Raw *input, DW_Format unit_format, DW_ListUnit *str_offsets, DW_FormKind form_kind, DW_Form form); internal String8 dw_interp_string (DW_Input *input, DW_Format unit_format, DW_ListUnit *str_offsets, DW_FormKind form_kind, DW_Form form);
internal String8 dw_interp_line_ptr (DW_Raw *input, DW_FormKind form_kind, DW_Form form); internal String8 dw_interp_line_ptr (DW_Input *input, DW_FormKind form_kind, DW_Form form);
internal DW_LineFile * dw_interp_file (DW_LineVMHeader *line_vm, DW_FormKind form_kind, DW_Form form); internal DW_LineFile * dw_interp_file (DW_LineVMHeader *line_vm, DW_FormKind form_kind, DW_Form form);
internal DW_Reference dw_interp_ref (DW_Raw *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form); internal DW_Reference dw_interp_ref (DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form);
internal DW_LocList dw_interp_loclist (Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form); internal DW_LocList dw_interp_loclist (Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form);
internal Rng1U64List dw_interp_rnglist (Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form); internal Rng1U64List dw_interp_rnglist (Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form);
internal String8 dw_exprloc_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal String8 dw_exprloc_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal U128 dw_const_u128_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal U128 dw_const_u128_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal U64 dw_const_u64_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal U64 dw_const_u64_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal U32 dw_const_u32_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal U32 dw_const_u32_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal S64 dw_const_s64_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal S64 dw_const_s64_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal S32 dw_const_s32_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal S32 dw_const_s32_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal B32 dw_flag_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal B32 dw_flag_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal U64 dw_address_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal U64 dw_address_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal String8 dw_block_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal String8 dw_block_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal String8 dw_string_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal String8 dw_string_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal String8 dw_line_ptr_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal String8 dw_line_ptr_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal DW_LineFile * dw_file_from_attrib (DW_CompUnit *cu, DW_LineVMHeader *line_vm, DW_Attrib *attrib); internal DW_LineFile * dw_file_from_attrib (DW_CompUnit *cu, DW_LineVMHeader *line_vm, DW_Attrib *attrib);
internal DW_Reference dw_ref_from_attrib (DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal DW_Reference dw_ref_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal DW_LocList dw_loclist_from_attrib (Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal DW_LocList dw_loclist_from_attrib (Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal Rng1U64List dw_rnglist_from_attrib (Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib); internal Rng1U64List dw_rnglist_from_attrib (Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal String8 dw_exprloc_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal String8 dw_exprloc_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal U128 dw_const_u128_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal U128 dw_const_u128_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal U64 dw_const_u64_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal U64 dw_const_u64_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal U32 dw_const_u32_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal U32 dw_const_u32_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal B32 dw_flag_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal B32 dw_flag_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal U64 dw_address_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal U64 dw_address_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal String8 dw_block_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal String8 dw_block_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal String8 dw_string_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal String8 dw_string_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal String8 dw_line_ptr_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal String8 dw_line_ptr_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal String8 dw_line_ptr_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal String8 dw_line_ptr_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal DW_LineFile * dw_file_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_LineVMHeader *line_vm, DW_Tag tag, DW_AttribKind kind); internal DW_LineFile * dw_file_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_LineVMHeader *line_vm, DW_Tag tag, DW_AttribKind kind);
internal DW_Reference dw_ref_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal DW_Reference dw_ref_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal DW_LocList dw_loclist_from_tag_attrib_kind (Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal DW_LocList dw_loclist_from_tag_attrib_kind (Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal Rng1U64List dw_rnglist_from_tag_attrib_kind (Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal Rng1U64List dw_rnglist_from_tag_attrib_kind (Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
// compile unit // compile unit
internal DW_CompUnit dw_cu_from_info_off(Arena *arena, DW_Raw *input, DW_ListUnitInput lu_input, U64 offset); internal DW_CompUnit dw_cu_from_info_off(Arena *arena, DW_Input *input, DW_ListUnitInput lu_input, U64 offset, B32 relaxed);
internal DW_TagTree dw_tag_tree_from_cu(Arena *arena, DW_Raw *input, DW_CompUnit *cu); internal DW_TagTree dw_tag_tree_from_cu(Arena *arena, DW_Input *input, DW_CompUnit *cu);
internal HashTable * dw_make_tag_hash_table(Arena *arena, DW_TagTree tag_tree); internal HashTable * dw_make_tag_hash_table(Arena *arena, DW_TagTree tag_tree);
internal DW_TagNode * dw_tag_node_from_info_off(DW_CompUnit *cu, U64 info_off); internal DW_TagNode * dw_tag_node_from_info_off(DW_CompUnit *cu, U64 info_off);
// line info // line info
internal U64 dw_read_line_file(String8 line_data, U64 line_off, DW_Raw *input, DW_Version unit_version, DW_Format unit_format, DW_Ext ext, U64 address_size, DW_ListUnit *str_offsets, U64 enc_count, U64 *enc_arr, DW_LineFile *line_file_out); internal U64 dw_read_line_file(String8 line_data, U64 line_off, DW_Input *input, DW_Version unit_version, DW_Format unit_format, DW_Ext ext, U64 address_size, DW_ListUnit *str_offsets, U64 enc_count, U64 *enc_arr, DW_LineFile *line_file_out);
internal U64 dw_read_line_vm_header(Arena *arena, String8 line_data, U64 line_off, DW_Raw *input, String8 cu_dir, String8 cu_name, U8 cu_address_size, DW_ListUnit *cu_str_offsets, DW_LineVMHeader *header_out); internal U64 dw_read_line_vm_header(Arena *arena, String8 line_data, U64 line_off, DW_Input *input, String8 cu_dir, String8 cu_name, U8 cu_address_size, DW_ListUnit *cu_str_offsets, DW_LineVMHeader *header_out);
internal void dw_line_vm_reset(DW_LineVMState *state, B32 default_is_stmt); internal void dw_line_vm_reset(DW_LineVMState *state, B32 default_is_stmt);
internal void dw_line_vm_advance(DW_LineVMState *state, U64 advance, U64 min_inst_len, U64 max_ops_for_inst); internal void dw_line_vm_advance(DW_LineVMState *state, U64 advance, U64 min_inst_len, U64 max_ops_for_inst);
internal DW_LineSeqNode * dw_push_line_seq(Arena* arena, DW_LineTableParseResult *parsed_tbl); internal DW_LineSeqNode * dw_push_line_seq(Arena* arena, DW_LineTableParseResult *parsed_tbl);
@@ -545,11 +538,11 @@ internal DW_LineNode * dw_push_line(Arena *arena, DW_LineTableParseResult *tb
internal String8 dw_path_from_file(Arena *arena, DW_LineVMHeader *vm, DW_LineFile *file); internal String8 dw_path_from_file(Arena *arena, DW_LineVMHeader *vm, DW_LineFile *file);
internal String8 dw_path_from_file_idx(Arena *arena, DW_LineVMHeader *vm, U64 file_idx); internal String8 dw_path_from_file_idx(Arena *arena, DW_LineVMHeader *vm, U64 file_idx);
internal DW_LineTableParseResult dw_parsed_line_table_from_data(Arena *arena, String8 unit_data, DW_Raw *input, String8 cu_dir, String8 cu_name, U8 cu_address_size, DW_ListUnit *cu_str_offsets); internal DW_LineTableParseResult dw_parsed_line_table_from_data(Arena *arena, String8 unit_data, DW_Input *input, String8 cu_dir, String8 cu_name, U8 cu_address_size, DW_ListUnit *cu_str_offsets);
// helper for .debug_pubtypes and .debug_pubnames // helper for .debug_pubtypes and .debug_pubnames
internal DW_PubStringsTable dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Raw *input, DW_SectionKind section_kind); internal DW_PubStringsTable dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Input *input, DW_SectionKind section_kind);
// expression // expression
+3 -2
View File
@@ -8,8 +8,8 @@
//~ Dump Subset Types //~ Dump Subset Types
#define EH_DumpSubset_XList \ #define EH_DumpSubset_XList \
X(EhFrameHdr, eh_frame_hdr, ".eh_frame_hdr") \ X(EhFrameHdr, eh_frame_hdr, ".eh_frame_hdr") \
X(EhFrame, eh_frame, ".eh_frame") X(EhFrame, eh_frame, ".eh_frame")
typedef enum EH_DumpSubset { typedef enum EH_DumpSubset {
#define X(name, name_lower, title) EH_DumpSubset_##name, #define X(name, name_lower, title) EH_DumpSubset_##name,
@@ -45,3 +45,4 @@ read_only global String8 eh_name_title_from_dump_subset_table[] =
internal String8List eh_dump_list_from_data(Arena *arena, Arch arch, U64 eh_frame_hdr_vaddr, U64 eh_frame_vaddr, String8 eh_frame_hdr, String8 eh_frame, EH_DumpSubsetFlags subset_flags); internal String8List eh_dump_list_from_data(Arena *arena, Arch arch, U64 eh_frame_hdr_vaddr, U64 eh_frame_vaddr, String8 eh_frame_hdr, String8 eh_frame, EH_DumpSubsetFlags subset_flags);
#endif // EH_FRAME_DUMP_H #endif // EH_FRAME_DUMP_H
+9 -9
View File
@@ -118,7 +118,7 @@ eh_parse_frame_hdr(String8 data, U64 address_size, EH_PtrCtx *ptr_ctx)
Assert(0 && "unknown version"); Assert(0 && "unknown version");
} }
exit:; exit:;
return header; return header;
} }
@@ -174,7 +174,7 @@ eh_parse_aug_data(String8 aug_string, String8 aug_data, U64 pc, EH_PtrCtx *ptr_c
aug_out->size = aug_data_size; aug_out->size = aug_data_size;
} }
exit:; exit:;
U64 parse_size = cursor; U64 parse_size = cursor;
return parse_size; return parse_size;
} }
@@ -187,13 +187,13 @@ eh_parse_descriptor_entry_header(String8 data, U64 off, DW_DescriptorEntry *desc
DW_Format format = first_four_bytes == max_U32 ? DW_Format_64Bit : DW_Format_32Bit; DW_Format format = first_four_bytes == max_U32 ? DW_Format_64Bit : DW_Format_32Bit;
U64 length = 0; U64 length = 0;
U64 length_size = dw_str8_deserial_read_packed_size(data, off, &length); U64 length_size = str8_deserial_read_dwarf_packed_size(data, off, &length);
if (length_size == 0) { goto exit; } if (length_size == 0) { goto exit; }
Rng1U64 entry_range = rng_1u64(off, off + length_size + length); Rng1U64 entry_range = rng_1u64(off, off + length_size + length);
String8 entry_data = str8_substr(data, entry_range); String8 entry_data = str8_substr(data, entry_range);
U64 id = 0; U64 id = 0;
U64 id_size = dw_str8_deserial_read_fmt_uint(entry_data, length_size, format, &id); U64 id_size = str8_deserial_read_dwarf_uint(entry_data, length_size, format, &id);
if (id_size == 0) { goto exit; } if (id_size == 0) { goto exit; }
desc_out->format = format; desc_out->format = format;
@@ -202,7 +202,7 @@ eh_parse_descriptor_entry_header(String8 data, U64 off, DW_DescriptorEntry *desc
desc_out->cie_pointer = id; desc_out->cie_pointer = id;
desc_out->cie_pointer_off = off + length_size; desc_out->cie_pointer_off = off + length_size;
exit:; exit:;
return length + length_size; return length + length_size;
} }
@@ -213,7 +213,7 @@ eh_parse_cie(String8 data, DW_Format format, Arch arch, U64 pc, EH_PtrCtx *ptr_c
U64 cursor = format == DW_Format_32Bit ? 4 : 12; U64 cursor = format == DW_Format_32Bit ? 4 : 12;
U64 cie_id = 0; U64 cie_id = 0;
U64 cie_id_size = dw_str8_deserial_read_fmt_uint(data, cursor, format, &cie_id); U64 cie_id_size = str8_deserial_read_dwarf_uint(data, cursor, format, &cie_id);
if (cie_id_size == 0) { goto exit; } if (cie_id_size == 0) { goto exit; }
cursor += cie_id_size; cursor += cie_id_size;
@@ -286,7 +286,7 @@ eh_parse_cie(String8 data, DW_Format format, Arch arch, U64 pc, EH_PtrCtx *ptr_c
} }
is_parsed = 1; is_parsed = 1;
exit:; exit:;
return is_parsed; return is_parsed;
} }
@@ -317,7 +317,7 @@ eh_parse_fde(String8 data, DW_Format format, U64 pc, DW_CIE *cie, EH_PtrCtx *ptr
fde_out->insts = str8_skip(data, cursor); fde_out->insts = str8_skip(data, cursor);
is_parsed = 1; is_parsed = 1;
exit:; exit:;
return is_parsed; return is_parsed;
} }
@@ -371,7 +371,7 @@ eh_find_nearest_fde(EH_FrameHdr header, EH_PtrCtx *ptr_ctx, U64 pc)
} }
} }
exit:; exit:;
if (fde_idx < header.fde_count) { if (fde_idx < header.fde_count) {
U64 fde_addr_off = (fde_idx * header.entry_byte_size) + header.field_byte_size; U64 fde_addr_off = (fde_idx * header.entry_byte_size) + header.field_byte_size;
U64 fde_addr_size = eh_parse_ptr(header.table, fde_addr_off, ptr_ctx->pc_vaddr + fde_addr_off, ptr_ctx, header.table_enc, &fde_addr); U64 fde_addr_size = eh_parse_ptr(header.table, fde_addr_off, ptr_ctx->pc_vaddr + fde_addr_off, ptr_ctx, header.table_enc, &fde_addr);
+1
View File
@@ -123,3 +123,4 @@ internal String8 eh_string_from_ptr_enc_modifier(EH_PtrEnc modifier);
internal String8 eh_string_from_ptr_enc(Arena *arena, EH_PtrEnc enc); internal String8 eh_string_from_ptr_enc(Arena *arena, EH_PtrEnc enc);
#endif // EH_FRAME_H #endif // EH_FRAME_H
+8 -105
View File
@@ -613,10 +613,12 @@ rb_thread_entry_point(void *p)
}break; }break;
} }
//- rjf: convert DWARF in inputs to RDI info //- rjf: convert inputs to RDI info
B32 convert_done = 0; B32 convert_done = 0;
RDIM_BakeParams pdb_bake_params = {0};
RDIM_BakeParams dwarf_bake_params = {0}; RDIM_BakeParams dwarf_bake_params = {0};
{ {
//- rjf: PE inputs w/ DWARF, or ELF inputs => DWARF -> RDI conversion
B32 pe_w_dwarf = (input_files_from_format_table[RB_FileFormat_PE].count != 0 && B32 pe_w_dwarf = (input_files_from_format_table[RB_FileFormat_PE].count != 0 &&
input_files_from_format_table[RB_FileFormat_PE].first->v->format_flags & RB_FileFormatFlag_HasDWARF); input_files_from_format_table[RB_FileFormat_PE].first->v->format_flags & RB_FileFormatFlag_HasDWARF);
B32 elf_w_dwarf = (input_files_from_format_table[RB_FileFormat_ELF32].count != 0 || B32 elf_w_dwarf = (input_files_from_format_table[RB_FileFormat_ELF32].count != 0 ||
@@ -628,103 +630,7 @@ rb_thread_entry_point(void *p)
else if(pe_w_dwarf) { log_infof("PEs w/ DWARF specified; converting DWARF data to RDI\n"); } else if(pe_w_dwarf) { log_infof("PEs w/ DWARF specified; converting DWARF data to RDI\n"); }
else if(elf_w_dwarf) { log_infof("ELFs specified; converting DWARF data to RDI\n"); } else if(elf_w_dwarf) { log_infof("ELFs specified; converting DWARF data to RDI\n"); }
// rjf: input files -> exe, exe metadata, & raw dwarf
RB_File *exe_file = &rb_file_nil;
Arch arch = Arch_Null;
U64 base_vaddr = 0;
RDIM_BinarySectionList binary_sections = {0};
DW_Raw raw = {0};
B32 got_dwarf = 0;
{
for(RB_FileNode *n = input_files.first; n != 0; n = n->next)
{
// rjf: the first PE w/ DWARF, *or* the first ELF => pick as our exectable
if(exe_file == &rb_file_nil &&
((n->v->format == RB_FileFormat_PE && n->v->format_flags & RB_FileFormatFlag_HasDWARF) ||
n->v->format == RB_FileFormat_ELF64 ||
n->v->format == RB_FileFormat_ELF32))
{
exe_file = n->v;
}
// rjf: PE => get PE info
PE_BinInfo pe = {0};
if(n->v->format == RB_FileFormat_PE)
{
pe = pe_bin_info_from_data(arena, n->v->data);
if(arch == Arch_Null)
{
arch = pe.arch;
}
if(base_vaddr == 0)
{
base_vaddr = pe.image_base;
}
if(binary_sections.count == 0)
{
String8 raw_sections = str8_substr(n->v->data, pe.section_table_range);
COFF_SectionHeader *section_table = str8_deserial_get_raw_ptr(raw_sections, 0, sizeof(COFF_SectionHeader)*pe.section_count);
String8 string_table = str8_substr(n->v->data, pe.string_table_range);
binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, n->v->data, string_table, pe.section_count, section_table);
}
}
// rjf: ELF => get ELF info
ELF_Bin elf = {0};
if(n->v->format == RB_FileFormat_ELF32 ||
n->v->format == RB_FileFormat_ELF64)
{
elf = elf_bin_from_data(arena, n->v->data);
if(arch == Arch_Null)
{
arch = arch_from_elf_machine(elf.hdr.e_machine);
}
if(base_vaddr == 0)
{
base_vaddr = elf_base_addr_from_bin(&elf);
}
if(binary_sections.count == 0)
{
binary_sections = e2r_rdi_binary_sections_from_elf_section_table(arena, n->v->data, &elf, elf.shdrs);
}
}
// rjf: PE w/ DWARF => gather DWARF sections
if(!got_dwarf && n->v->format == RB_FileFormat_PE && n->v->format_flags & RB_FileFormatFlag_HasDWARF)
{
String8 raw_sections = str8_substr(n->v->data, pe.section_table_range);
COFF_SectionHeader *section_table = str8_deserial_get_raw_ptr(raw_sections, 0, sizeof(COFF_SectionHeader)*pe.section_count);
String8 string_table = str8_substr(n->v->data, pe.string_table_range);
raw = dw_raw_from_coff_section_table(arena, n->v->data, string_table, pe.section_count, section_table);
got_dwarf = 1;
}
// rjf: ELF w/ DWARF => gather DWARF sections
if(!got_dwarf && (n->v->format == RB_FileFormat_ELF32 || n->v->format == RB_FileFormat_ELF64) && n->v->format_flags & RB_FileFormatFlag_HasDWARF)
{
raw = dw_raw_from_elf_bin(arena, n->v->data, &elf);
got_dwarf = 1;
}
}
}
// rjf: convert (NEW)
#if 0
D2R2_ConvertParams convert_params = {0};
{
convert_params.exe_name = exe_file->path;
convert_params.exe_data = exe_file->data;
convert_params.arch = arch;
convert_params.base_vaddr = base_vaddr;
convert_params.binary_sections = binary_sections;
convert_params.raw = raw;
convert_params.subset_flags = subset_flags;
convert_params.deterministic = cmd_line_has_flag(cmdline, str8_lit("deterministic"));
}
ProfScope("convert") dwarf_bake_params = d2r2_convert(arena, &convert_params);
// rjf: convert // rjf: convert
#else
D2R_ConvertParams convert_params = {0}; D2R_ConvertParams convert_params = {0};
{ {
B32 got_exe = 0; B32 got_exe = 0;
@@ -804,13 +710,9 @@ rb_thread_entry_point(void *p)
convert_params.deterministic = cmd_line_has_flag(cmdline, str8_lit("deterministic")); convert_params.deterministic = cmd_line_has_flag(cmdline, str8_lit("deterministic"));
} }
ProfScope("convert") dwarf_bake_params = d2r_convert(arena, &convert_params); ProfScope("convert") dwarf_bake_params = d2r_convert(arena, &convert_params);
#endif
} }
}
lane_sync();
//- rjf: convert PDB in inputs to RDI info //- rjf: PDB inputs => PDB -> RDI conversion
RDIM_BakeParams pdb_bake_params = {0};
if(input_files_from_format_table[RB_FileFormat_PDB].count != 0) if(input_files_from_format_table[RB_FileFormat_PDB].count != 0)
{ {
convert_done = 1; convert_done = 1;
@@ -836,6 +738,7 @@ rb_thread_entry_point(void *p)
} }
ProfScope("convert") pdb_bake_params = p2r_convert(arena, &convert_params); ProfScope("convert") pdb_bake_params = p2r_convert(arena, &convert_params);
} }
}
lane_sync(); lane_sync();
//- rjf: join conversion artifacts //- rjf: join conversion artifacts
@@ -1196,7 +1099,7 @@ rb_thread_entry_point(void *p)
Arch arch = Arch_Null; Arch arch = Arch_Null;
PE_BinInfo pe = {0}; PE_BinInfo pe = {0};
ELF_Bin elf = {0}; ELF_Bin elf = {0};
DW_Raw dw = {0}; DW_Input dw = {0};
U64 eh_frame_hdr_vaddr = 0; U64 eh_frame_hdr_vaddr = 0;
U64 eh_frame_vaddr = 0; U64 eh_frame_vaddr = 0;
String8 eh_frame_hdr = {0}; String8 eh_frame_hdr = {0};
@@ -1238,12 +1141,12 @@ rb_thread_entry_point(void *p)
U64 section_count = raw_sections.size / sizeof(COFF_SectionHeader); U64 section_count = raw_sections.size / sizeof(COFF_SectionHeader);
COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_sections.str; COFF_SectionHeader *section_table = (COFF_SectionHeader *)raw_sections.str;
String8 string_table = str8_substr(f->data, pe.string_table_range); String8 string_table = str8_substr(f->data, pe.string_table_range);
dw = dw_raw_from_coff_section_table(arena, f->data, string_table, section_count, section_table); dw = dw_input_from_coff_section_table(arena, f->data, string_table, section_count, section_table);
} }
else if(f->format == RB_FileFormat_ELF32 || else if(f->format == RB_FileFormat_ELF32 ||
f->format == RB_FileFormat_ELF64) f->format == RB_FileFormat_ELF64)
{ {
dw = dw_raw_from_elf_bin(arena, f->data, &elf); dw = dw_input_from_elf_bin(arena, f->data, &elf);
} }
} }
} }
-2
View File
@@ -34,7 +34,6 @@
#include "rdi_from_elf/rdi_from_elf.h" #include "rdi_from_elf/rdi_from_elf.h"
#include "rdi_from_pdb/rdi_from_pdb.h" #include "rdi_from_pdb/rdi_from_pdb.h"
#include "rdi_from_dwarf/rdi_from_dwarf.h" #include "rdi_from_dwarf/rdi_from_dwarf.h"
#include "rdi_from_dwarf/rdi_from_dwarf_2.h"
#include "radbin/radbin.h" #include "radbin/radbin.h"
//- rjf: [c] //- rjf: [c]
@@ -61,7 +60,6 @@
#include "rdi_from_elf/rdi_from_elf.c" #include "rdi_from_elf/rdi_from_elf.c"
#include "rdi_from_pdb/rdi_from_pdb.c" #include "rdi_from_pdb/rdi_from_pdb.c"
#include "rdi_from_dwarf/rdi_from_dwarf.c" #include "rdi_from_dwarf/rdi_from_dwarf.c"
#include "rdi_from_dwarf/rdi_from_dwarf_2.c"
#include "radbin/radbin.c" #include "radbin/radbin.c"
//////////////////////////////// ////////////////////////////////
File diff suppressed because it is too large Load Diff
+29 -41
View File
@@ -1,11 +1,7 @@
// Copyright (c) Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
#ifndef RDI_FROM_DWARF_H #pragma once
#define RDI_FROM_DWARF_H
////////////////////////////////
//~ rjf: Conversion Stage Inputs
typedef struct D2R_ConvertParams D2R_ConvertParams; typedef struct D2R_ConvertParams D2R_ConvertParams;
struct D2R_ConvertParams struct D2R_ConvertParams
@@ -19,43 +15,35 @@ struct D2R_ConvertParams
B32 deterministic; B32 deterministic;
}; };
//////////////////////////////// typedef struct D2R_TypeTable
//~ rjf: Conversion Helper Types
typedef struct D2R_TypeTable D2R_TypeTable;
struct D2R_TypeTable
{ {
HashTable *ht; HashTable *ht;
RDIM_TypeChunkList *types; RDIM_TypeChunkList *types;
U64 type_chunk_cap; U64 type_chunk_cap;
RDIM_Type **builtin_types; RDIM_Type **builtin_types;
}; } D2R_TypeTable;
typedef struct D2R_TagFrame D2R_TagFrame; typedef struct D2R_TagFrame
struct D2R_TagFrame
{ {
DW_TagNode *node; DW_TagNode *node;
RDIM_Scope *scope; RDIM_Scope *scope;
struct D2R_TagFrame *next; struct D2R_TagFrame *next;
}; } D2R_TagFrame;
typedef struct D2R_TagIter D2R_TagIter; typedef struct D2R_TagIterator
struct D2R_TagIter
{ {
D2R_TagFrame *free_list; D2R_TagFrame *free_list;
D2R_TagFrame *stack; D2R_TagFrame *stack;
DW_TagNode *tag_node; DW_TagNode *tag_node;
DW_TagNode *root;
B32 visit_children; B32 visit_children;
}; } D2R_TagIterator;
typedef struct D2R_CompUnitContribMap D2R_CompUnitContribMap; typedef struct D2R_CompUnitContribMap
struct D2R_CompUnitContribMap
{ {
U64 count; U64 count;
U64 *info_off_arr; U64 *info_off_arr;
RDIM_Rng1U64ChunkList *voff_range_arr; RDIM_Rng1U64ChunkList *voff_range_arr;
}; } D2R_CompUnitContribMap;
#define D2R_ValueType_IsSigned(x) ((x) == D2R_ValueType_S8 || (x) == D2R_ValueType_S16 || (x) == D2R_ValueType_S32 || (x) == D2R_ValueType_S64 || (x) == D2R_ValueType_S128 || (x) == D2R_ValueType_S256 || (x) == D2R_ValueType_S512) #define D2R_ValueType_IsSigned(x) ((x) == D2R_ValueType_S8 || (x) == D2R_ValueType_S16 || (x) == D2R_ValueType_S32 || (x) == D2R_ValueType_S64 || (x) == D2R_ValueType_S128 || (x) == D2R_ValueType_S256 || (x) == D2R_ValueType_S512)
#define D2R_ValueType_IsUnsigned(x) ((x) == D2R_ValueType_U8 || (x) == D2R_ValueType_U16 || (x) == D2R_ValueType_U32 || (x) == D2R_ValueType_U64 || (x) == D2R_ValueType_U128 || (x) == D2R_ValueType_U256 || (x) == D2R_ValueType_U512) #define D2R_ValueType_IsUnsigned(x) ((x) == D2R_ValueType_U8 || (x) == D2R_ValueType_U16 || (x) == D2R_ValueType_U32 || (x) == D2R_ValueType_U64 || (x) == D2R_ValueType_U128 || (x) == D2R_ValueType_U256 || (x) == D2R_ValueType_U512)
@@ -113,9 +101,12 @@ internal RDI_RegCode d2r_rdi_reg_code_from_dw_reg(Arch arch, DW_Reg v);
internal RDIM_Type * d2r_create_type(Arena *arena, D2R_TypeTable *type_table); internal RDIM_Type * d2r_create_type(Arena *arena, D2R_TypeTable *type_table);
internal RDIM_Type * d2r_create_type_from_offset(Arena *arena, D2R_TypeTable *type_table, U64 info_off); internal RDIM_Type * d2r_create_type_from_offset(Arena *arena, D2R_TypeTable *type_table, U64 info_off);
internal RDIM_Type * d2r_type_from_offset(D2R_TypeTable *type_table, U64 info_off); internal RDIM_Type * d2r_type_from_offset(D2R_TypeTable *type_table, U64 info_off);
internal RDIM_Type * d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal RDIM_Type * d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind);
internal Rng1U64List d2r_range_list_from_tag(Arena *arena, DW_Raw *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag); internal Rng1U64List d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag);
internal RDIM_Type ** d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out); internal RDIM_Type ** d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out);
internal RDI_TypeKind d2r_unsigned_type_kind_from_size(U64 byte_size);
internal RDI_TypeKind d2r_signed_type_kind_from_size(U64 byte_size);
internal RDI_EvalTypeGroup d2r_type_group_from_type_kind(RDI_TypeKind x);
//////////////////////////////// ////////////////////////////////
//~ RDIM Bytecode Helpers //~ RDIM Bytecode Helpers
@@ -141,25 +132,26 @@ internal D2R_ValueType d2r_apply_usual_arithmetic_conversions(Arena *arena, D2R_
internal void d2r_push_arithmetic_op(Arena *arena, D2R_ValueTypeStack *stack, RDIM_EvalBytecode *bc, RDI_EvalOp op); internal void d2r_push_arithmetic_op(Arena *arena, D2R_ValueTypeStack *stack, RDIM_EvalBytecode *bc, RDI_EvalOp op);
internal void d2r_push_relational_op(Arena *arena, D2R_ValueTypeStack *stack, RDIM_EvalBytecode *bc, RDI_EvalOp op); internal void d2r_push_relational_op(Arena *arena, D2R_ValueTypeStack *stack, RDIM_EvalBytecode *bc, RDI_EvalOp op);
internal RDIM_EvalBytecode d2r_bytecode_from_expression(Arena *arena, DW_Raw *input, U64 image_base, U64 address_size, Arch arch, DW_ListUnit *addr_lu, String8 expr, DW_CompUnit *cu, D2R_ValueType *result_type_out); internal RDIM_EvalBytecode d2r_bytecode_from_expression(Arena *arena, DW_Input *input, U64 image_base, U64 address_size, Arch arch, DW_ListUnit *addr_lu, String8 expr, DW_CompUnit *cu, D2R_ValueType *result_type_out);
internal RDIM_Location * d2r_transpile_expression(Arena *arena, RDIM_LocationChunkList *locations, DW_Raw *input, U64 image_base, U64 address_size, Arch arch, DW_ListUnit *addr_lu, DW_CompUnit *cu, String8 expr); internal RDIM_Location * d2r_transpile_expression(Arena *arena, RDIM_LocationChunkList *locations, DW_Input *input, U64 image_base, U64 address_size, Arch arch, DW_ListUnit *addr_lu, DW_CompUnit *cu, String8 expr);
internal RDIM_LocationCaseList d2r_locset_from_attrib(Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope *curr_scope, RDIM_LocationChunkList *locations, DW_Raw *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind); internal RDIM_Location * d2r_location_from_attrib(Arena *arena, RDIM_LocationChunkList *locations, DW_Input *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind);
internal RDIM_LocationCaseList d2r_var_locset_from_tag(Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope *curr_scope, RDIM_LocationChunkList *locations, DW_Raw *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag); internal RDIM_LocationCaseList d2r_locset_from_attrib(Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope *curr_scope, RDIM_LocationChunkList *locations, DW_Input *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag, DW_AttribKind kind);
internal RDIM_LocationCaseList d2r_var_locset_from_tag(Arena *arena, RDIM_ScopeChunkList *scopes, RDIM_Scope *curr_scope, RDIM_LocationChunkList *locations, DW_Input *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag);
//////////////////////////////// ////////////////////////////////
//~ rjf: Compilation Unit / Scope Conversion Helpers //~ rjf: Compilation Unit / Scope Conversion Helpers
internal D2R_CompUnitContribMap d2r_cu_contrib_map_from_aranges(Arena *arena, DW_Input *input, U64 image_base);
internal RDIM_Rng1U64ChunkList d2r_voff_ranges_from_cu_info_off(D2R_CompUnitContribMap map, U64 info_off); internal RDIM_Rng1U64ChunkList d2r_voff_ranges_from_cu_info_off(D2R_CompUnitContribMap map, U64 info_off);
internal RDIM_Scope *d2r_push_scope(Arena *arena, RDIM_ScopeChunkList *scopes, U64 scope_chunk_cap, D2R_TagFrame *tag_stack, Rng1U64List ranges);
//////////////////////////////// ////////////////////////////////
//~ Tag Iterator //~ Tag Iterator
internal D2R_TagIter *d2r_tag_iter_init(Arena *arena, DW_TagNode *root); internal D2R_TagIterator * d2r_tag_iterator_init(Arena *arena, DW_TagNode *root);
internal void d2r_tag_iter_next(Arena *arena, D2R_TagIter *iter); internal void d2r_tag_iterator_next(Arena *arena, D2R_TagIterator *iter);
internal void d2r_tag_iter_skip_children(D2R_TagIter *iter); internal void d2r_tag_iterator_skip_children(D2R_TagIterator *iter);
internal DW_TagNode * d2r_tag_iter_parent_tag_node(D2R_TagIter *iter); internal DW_TagNode * d2r_tag_iterator_parent_tag_node(D2R_TagIterator *iter);
internal DW_Tag d2r_tag_iter_parent_tag(D2R_TagIter *iter); internal DW_Tag d2r_tag_iterator_parent_tag(D2R_TagIterator *iter);
//////////////////////////////// ////////////////////////////////
//~ Type/UDT/Symbol Conversion //~ Type/UDT/Symbol Conversion
@@ -167,15 +159,11 @@ internal DW_Tag d2r_tag_iter_parent_tag(D2R_TagIter *iter);
internal void d2r_flag_converted_tag(DW_TagNode *tag_node); internal void d2r_flag_converted_tag(DW_TagNode *tag_node);
internal B8 d2r_is_tag_converted(DW_TagNode *tag_node); internal B8 d2r_is_tag_converted(DW_TagNode *tag_node);
internal RDIM_Type *d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_Tag tag, DW_AttribKind kind); internal void d2r_convert_types(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_TagNode *root);
internal void d2r_convert_udts(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_TagNode *root);
internal void d2r_convert_types(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_TagNode *root); internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_scope, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, U64 image_base, Arch arch, DW_TagNode *root);
internal void d2r_convert_udts(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_TagNode *root);
internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, U64 image_base, Arch arch, DW_TagNode *root);
//////////////////////////////// ////////////////////////////////
//~ rjf: Main Conversion Entry Point //~ rjf: Main Conversion Entry Point
internal RDIM_BakeParams d2r_convert(Arena *arena, D2R_ConvertParams *params); internal RDIM_BakeParams d2r_convert(Arena *arena, D2R_ConvertParams *params);
#endif // RDI_FROM_DWARF_H
+1 -28
View File
@@ -1,36 +1,9 @@
// Copyright (c) Epic Games Tools // Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
internal RDI_BinarySectionFlags
e2r_rdi_binary_section_flags_from_elf(ELF_SectionFlags f)
{
RDI_BinarySectionFlags result = RDI_BinarySectionFlag_Read;
if(f & ELF_Shf_Write)
{
result |= RDI_BinarySectionFlag_Write;
}
if(f & ELF_Shf_ExecInstr)
{
result |= RDI_BinarySectionFlag_Execute;
}
return result;
}
internal RDIM_BinarySectionList internal RDIM_BinarySectionList
e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, String8 data, ELF_Bin *bin, ELF_Shdr64Array shdrs) e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, ELF_Shdr64Array shdrs)
{ {
RDIM_BinarySectionList result = {0}; RDIM_BinarySectionList result = {0};
U64 base_vaddr = elf_base_addr_from_bin(bin);
for EachIndex(idx, shdrs.count)
{
ELF_Shdr64 *src = &shdrs.v[idx];
RDIM_BinarySection *dst = rdim_binary_section_list_push(arena, &result);
dst->name = elf_name_from_shdr64(data, bin, src);
dst->flags = e2r_rdi_binary_section_flags_from_elf(src->sh_flags);
dst->voff_first = src->sh_addr - base_vaddr;
dst->voff_opl = dst->voff_first + src->sh_size;
dst->foff_first = src->sh_offset;
dst->foff_opl = dst->foff_first + src->sh_size;
}
return result; return result;
} }
+1 -2
View File
@@ -4,7 +4,6 @@
#ifndef RDI_FROM_ELF_H #ifndef RDI_FROM_ELF_H
#define RDI_FROM_ELF_H #define RDI_FROM_ELF_H
internal RDI_BinarySectionFlags e2r_rdi_binary_section_flags_from_elf(ELF_SectionFlags f); internal RDIM_BinarySectionList e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, ELF_Shdr64Array shdrs);
internal RDIM_BinarySectionList e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, String8 data, ELF_Bin *bin, ELF_Shdr64Array shdrs);
#endif // RDI_FROM_ELF_H #endif // RDI_FROM_ELF_H
+29
View File
@@ -17,6 +17,35 @@ rdim_data_model_from_os_arch(OperatingSystem os, RDI_Arch arch)
return data_model; return data_model;
} }
internal RDIM_TopLevelInfo
rdim_make_top_level_info(String8 image_name, Arch arch, U64 exe_hash, RDIM_BinarySectionList sections)
{
// convert arch
RDI_Arch arch_rdi = RDI_Arch_NULL;
switch(arch)
{
default:{}break;
case Arch_x64:{arch_rdi = RDI_Arch_X64;}break;
case Arch_x86:{arch_rdi = RDI_Arch_X86;}break;
}
// find max VOFF
U64 exe_voff_max = 0;
for EachNode(sect_n, RDIM_BinarySectionNode, sections.first)
{
exe_voff_max = Max(exe_voff_max, sect_n->v.voff_opl);
}
// fill out top level info
RDIM_TopLevelInfo top_level_info = {0};
top_level_info.arch = arch_rdi;
top_level_info.exe_hash = exe_hash;
top_level_info.voff_max = exe_voff_max;
top_level_info.producer_name = str8_lit(BUILD_TITLE_STRING_LITERAL);
return top_level_info;
}
internal RDIM_BakeResults internal RDIM_BakeResults
rdim_bake(Arena *arena, RDIM_BakeParams *params) rdim_bake(Arena *arena, RDIM_BakeParams *params)
{ {
+1
View File
@@ -161,6 +161,7 @@ struct RDIM_Shared
global RDIM_Shared *rdim_shared = 0; global RDIM_Shared *rdim_shared = 0;
internal RDIM_DataModel rdim_data_model_from_os_arch(OperatingSystem os, RDI_Arch arch); internal RDIM_DataModel rdim_data_model_from_os_arch(OperatingSystem os, RDI_Arch arch);
internal RDIM_TopLevelInfo rdim_make_top_level_info(String8 image_name, Arch arch, U64 exe_hash, RDIM_BinarySectionList sections);
internal RDIM_BakeResults rdim_bake(Arena *arena, RDIM_BakeParams *params); internal RDIM_BakeResults rdim_bake(Arena *arena, RDIM_BakeParams *params);
internal RDIM_SerializedSectionBundle rdim_compress(Arena *arena, RDIM_SerializedSectionBundle *in); internal RDIM_SerializedSectionBundle rdim_compress(Arena *arena, RDIM_SerializedSectionBundle *in);