start dwarf -> rdi cleanup; eliminate some assertions-as-validation, remove incorrect assumption that line info addresses are vaddrs (they seem to be voffs)

This commit is contained in:
Ryan Fleury
2025-11-10 15:06:52 -08:00
parent efb4731ace
commit f396b2eaa3
11 changed files with 1433 additions and 1250 deletions
+2 -2
View File
@@ -46,8 +46,8 @@ load_paths =
commands = commands =
{ {
//- rjf: [raddbg] //- rjf: [raddbg]
.f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg meta telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, // .f1 = { .win = "raddbg_stable --ipc kill_all && build raddbg meta telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
// .f1 = { .win = "raddbg_stable --ipc kill_all && build radbin debug telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, .f1 = { .win = "raddbg_stable --ipc kill_all && build radbin debug telemetry", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
//- rjf: [raddbg wsl] //- rjf: [raddbg wsl]
// .f1 = { .win = "wsl ./build.sh raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, }, // .f1 = { .win = "wsl ./build.sh raddbg", .linux = "", .out = "*compilation*", .footer_panel = true, .save_dirty_files = true, .cursor_at_end = false, },
+87 -80
View File
@@ -12,12 +12,17 @@ internal U64
str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out) str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out)
{ {
U64 bytes_read = 0; U64 bytes_read = 0;
if (str8_deserial_read(string, off, size_out, sizeof(U32), sizeof(U32))) { if(str8_deserial_read(string, off, size_out, sizeof(U32), sizeof(U32)))
if (*size_out == max_U32) { {
if (str8_deserial_read_struct(string, off+sizeof(U32), size_out)) { if(*size_out == max_U32)
{
if(str8_deserial_read_struct(string, off+sizeof(U32), size_out))
{
bytes_read = sizeof(U32) + sizeof(U64); bytes_read = sizeof(U32) + sizeof(U64);
} }
} else { }
else
{
*size_out &= (U64)max_U32; *size_out &= (U64)max_U32;
bytes_read = sizeof(U32); bytes_read = sizeof(U32);
} }
@@ -29,13 +34,16 @@ internal U64
str8_deserial_read_dwarf_uint(String8 string, U64 off, DW_Format format, U64 *uint_out) str8_deserial_read_dwarf_uint(String8 string, U64 off, DW_Format format, U64 *uint_out)
{ {
U64 bytes_read = 0; U64 bytes_read = 0;
switch (format) { switch(format)
{
case DW_Format_Null: break; case DW_Format_Null: break;
case DW_Format_32Bit: { case DW_Format_32Bit:
{
*uint_out &= (U64)max_U32; *uint_out &= (U64)max_U32;
bytes_read = str8_deserial_read(string, off, uint_out, sizeof(U32), sizeof(U32)); bytes_read = str8_deserial_read(string, off, uint_out, sizeof(U32), sizeof(U32));
}break; }break;
case DW_Format_64Bit: { case DW_Format_64Bit:
{
bytes_read = str8_deserial_read_struct(string, off, uint_out); bytes_read = str8_deserial_read_struct(string, off, uint_out);
}break; }break;
} }
@@ -196,27 +204,26 @@ internal Rng1U64List
dw_unit_ranges_from_data(Arena *arena, String8 data) dw_unit_ranges_from_data(Arena *arena, String8 data)
{ {
Rng1U64List result = {0}; Rng1U64List result = {0};
for(U64 cursor = 0; cursor < data.size;)
for (U64 cursor = 0; cursor < data.size; ) { {
// read CU size // rjf: read CU size; bad read -> terminate
U64 cu_size = 0; U64 cu_size = 0;
U64 cu_size_size = str8_deserial_read_dwarf_packed_size(data, cursor, &cu_size); U64 cu_size_size = str8_deserial_read_dwarf_packed_size(data, cursor, &cu_size);
if(cu_size_size == 0)
// was read ok? {
if (cu_size_size == 0) {
break; break;
} }
if (cu_size > 0) { // rjf: push
// push unit range if(cu_size > 0)
{
rng1u64_list_push(arena, &result, rng_1u64(cursor, cursor+cu_size+cu_size_size)); rng1u64_list_push(arena, &result, rng_1u64(cursor, cursor+cu_size+cu_size_size));
} }
// advance // rjf: advance
cursor += cu_size_size; cursor += cu_size_size;
cursor += cu_size; cursor += cu_size;
} }
return result; return result;
} }
@@ -2420,15 +2427,7 @@ dw_read_line_file_array(Arena *arena,
} }
internal U64 internal U64
dw_read_line_vm_header(Arena *arena, 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)
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)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -2824,18 +2823,12 @@ dw_path_from_file_idx(Arena *arena, DW_LineVMHeader *vm, U64 file_idx)
} }
internal DW_LineTableParseResult internal DW_LineTableParseResult
dw_parsed_line_table_from_data(Arena *arena, 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)
String8 unit_data,
DW_Input *input,
String8 cu_dir,
String8 cu_name,
U8 cu_address_size,
DW_ListUnit *cu_str_offsets)
{ {
DW_LineVMHeader vm_header = {0}; DW_LineVMHeader vm_header = {0};
U64 vm_header_size = dw_read_line_vm_header(arena, unit_data, 0, input, cu_dir, cu_name, cu_address_size, cu_str_offsets, &vm_header); U64 vm_header_size = dw_read_line_vm_header(arena, unit_data, 0, input, cu_dir, cu_name, cu_address_size, cu_str_offsets, &vm_header);
U64 unit_cursor = vm_header_size; U64 unit_cursor = vm_header_size;
U64 unit_cursor_opl = Min(unit_data.size, vm_header.unit_range.max);
//- rjf: prep state for VM //- rjf: prep state for VM
DW_LineVMState vm_state = {0}; DW_LineVMState vm_state = {0};
@@ -2845,16 +2838,20 @@ dw_parsed_line_table_from_data(Arena *arena,
DW_LineTableParseResult result = {.vm_header = vm_header}; DW_LineTableParseResult result = {.vm_header = vm_header};
B32 end_of_seq = 0; B32 end_of_seq = 0;
B32 error = 0; B32 error = 0;
for (; !error && unit_cursor < unit_data.size; ) { for(;!error && unit_cursor < unit_cursor_opl;)
{
//- rjf: parse opcode //- rjf: parse opcode
U8 opcode = 0; U8 opcode = 0;
unit_cursor += str8_deserial_read_struct(unit_data, unit_cursor, &opcode); unit_cursor += str8_deserial_read_struct(unit_data, unit_cursor, &opcode);
//- rjf: do opcode action //- rjf: do opcode action
switch (opcode) { switch(opcode)
default: { {
//- rjf: special opcode case //- rjf: special opcode cases
if (opcode >= vm_header.opcode_base) { default:
{
if(opcode >= vm_header.opcode_base)
{
U32 adjusted_opcode = (U32)(opcode - vm_header.opcode_base); U32 adjusted_opcode = (U32)(opcode - vm_header.opcode_base);
U32 op_advance = adjusted_opcode / vm_header.line_range; U32 op_advance = adjusted_opcode / vm_header.line_range;
S32 line_inc = (S32)vm_header.line_base + ((S32)adjusted_opcode) % (S32)vm_header.line_range; S32 line_inc = (S32)vm_header.line_base + ((S32)adjusted_opcode) % (S32)vm_header.line_range;
@@ -2884,25 +2881,31 @@ dw_parsed_line_table_from_data(Arena *arena,
} }
#endif #endif
} }
// Skipping unknown opcode. This is a valid case and // Skipping unknown opcode. This is a valid case and
// it works because compiler stores operand lengths. // it works because compiler stores operand lengths.
else { else
if (0 < opcode && opcode <= vm_header.num_opcode_lens) { {
if(0 < opcode && opcode <= vm_header.num_opcode_lens)
{
U8 num_operands = vm_header.opcode_lens[opcode - 1]; U8 num_operands = vm_header.opcode_lens[opcode - 1];
for (U8 i = 0; i < num_operands; ++i) { for(U8 i = 0; i < num_operands; i += 1)
{
U64 operand = 0; U64 operand = 0;
unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &operand); unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &operand);
} }
} else { }
else
{
error = 1; error = 1;
goto exit; goto exit;
} }
} }
}break; }break;
//- Standard opcodes //- standard opcodes
case DW_StdOpcode_Copy:
case DW_StdOpcode_Copy: { {
if(vm_state.is_stmt) if(vm_state.is_stmt)
{ {
dw_push_line(arena, &result, &vm_state, end_of_seq); dw_push_line(arena, &result, &vm_state, end_of_seq);
@@ -2913,67 +2916,68 @@ dw_parsed_line_table_from_data(Arena *arena,
vm_state.prologue_end = 0; vm_state.prologue_end = 0;
vm_state.epilogue_begin = 0; vm_state.epilogue_begin = 0;
}break; }break;
case DW_StdOpcode_AdvancePc:
case DW_StdOpcode_AdvancePc: { {
U64 advance = 0; U64 advance = 0;
unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &advance); unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &advance);
dw_line_vm_advance(&vm_state, advance, vm_header.min_inst_len, vm_header.max_ops_for_inst); dw_line_vm_advance(&vm_state, advance, vm_header.min_inst_len, vm_header.max_ops_for_inst);
}break; }break;
case DW_StdOpcode_AdvanceLine:
case DW_StdOpcode_AdvanceLine: { {
S64 s = 0; S64 s = 0;
unit_cursor += str8_deserial_read_sleb128(unit_data, unit_cursor, &s); unit_cursor += str8_deserial_read_sleb128(unit_data, unit_cursor, &s);
vm_state.line += s; vm_state.line += s;
}break; }break;
case DW_StdOpcode_SetFile:
case DW_StdOpcode_SetFile: { {
U64 file_index = 0; U64 file_index = 0;
unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &file_index); unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &file_index);
vm_state.file_index = file_index; vm_state.file_index = file_index;
}break; }break;
case DW_StdOpcode_SetColumn:
case DW_StdOpcode_SetColumn: { {
U64 column = 0; U64 column = 0;
unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &column); unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &column);
vm_state.column = column; vm_state.column = column;
}break; }break;
case DW_StdOpcode_NegateStmt:
case DW_StdOpcode_NegateStmt: { {
vm_state.is_stmt = !vm_state.is_stmt; vm_state.is_stmt = !vm_state.is_stmt;
}break; }break;
case DW_StdOpcode_SetBasicBlock:
case DW_StdOpcode_SetBasicBlock: { {
vm_state.basic_block = 1; vm_state.basic_block = 1;
}break; }break;
case DW_StdOpcode_ConstAddPc:
case DW_StdOpcode_ConstAddPc: { {
U64 advance = (0xffu - vm_header.opcode_base) / vm_header.line_range; U64 advance = (0xffu - vm_header.opcode_base) / vm_header.line_range;
dw_line_vm_advance(&vm_state, advance, vm_header.min_inst_len, vm_header.max_ops_for_inst); dw_line_vm_advance(&vm_state, advance, vm_header.min_inst_len, vm_header.max_ops_for_inst);
}break; }break;
case DW_StdOpcode_FixedAdvancePc:
case DW_StdOpcode_FixedAdvancePc: { {
U16 operand = 0; U16 operand = 0;
unit_cursor += str8_deserial_read_struct(unit_data, unit_cursor, &operand); unit_cursor += str8_deserial_read_struct(unit_data, unit_cursor, &operand);
vm_state.address += operand; vm_state.address += operand;
vm_state.op_index = 0; vm_state.op_index = 0;
}break; }break;
case DW_StdOpcode_SetPrologueEnd:
case DW_StdOpcode_SetPrologueEnd: { {
vm_state.prologue_end = 1; vm_state.prologue_end = 1;
}break; }break;
case DW_StdOpcode_SetEpilogueBegin:
case DW_StdOpcode_SetEpilogueBegin: { {
vm_state.epilogue_begin = 1; vm_state.epilogue_begin = 1;
}break; }break;
case DW_StdOpcode_SetIsa:
case DW_StdOpcode_SetIsa: { {
U64 v = 0; U64 v = 0;
unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &v); unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &v);
vm_state.isa = v; vm_state.isa = v;
}break; }break;
//- Extended opcodes //- extended opcodes
case DW_StdOpcode_ExtendedOpcode: { case DW_StdOpcode_ExtendedOpcode:
{
U64 length = 0; U64 length = 0;
unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &length); unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &length);
@@ -2981,8 +2985,12 @@ dw_parsed_line_table_from_data(Arena *arena,
U8 extended_opcode = 0; U8 extended_opcode = 0;
unit_cursor += str8_deserial_read_struct(unit_data, unit_cursor, &extended_opcode); unit_cursor += str8_deserial_read_struct(unit_data, unit_cursor, &extended_opcode);
switch (extended_opcode) { switch(extended_opcode)
case DW_ExtOpcode_EndSequence: { {
default:{}break;
case DW_ExtOpcode_EndSequence:
{
vm_state.end_sequence = 1; vm_state.end_sequence = 1;
if(vm_state.is_stmt) if(vm_state.is_stmt)
{ {
@@ -2992,14 +3000,16 @@ dw_parsed_line_table_from_data(Arena *arena,
end_of_seq = 1; end_of_seq = 1;
}break; }break;
case DW_ExtOpcode_SetAddress: { case DW_ExtOpcode_SetAddress:
{
U64 address = 0; U64 address = 0;
unit_cursor += str8_deserial_read(unit_data, unit_cursor, &address, vm_header.address_size, vm_header.address_size); unit_cursor += str8_deserial_read(unit_data, unit_cursor, &address, vm_header.address_size, vm_header.address_size);
vm_state.address = address; vm_state.address = address;
vm_state.op_index = 0; vm_state.op_index = 0;
}break; }break;
case DW_ExtOpcode_DefineFile: { case DW_ExtOpcode_DefineFile:
{
String8 file_name = {0}; String8 file_name = {0};
U64 dir_index = 0; U64 dir_index = 0;
U64 modify_time = 0; U64 modify_time = 0;
@@ -3017,25 +3027,22 @@ dw_parsed_line_table_from_data(Arena *arena,
// //
// See the DWARF V4 spec (June 10, 2010), page 122. // See the DWARF V4 spec (June 10, 2010), page 122.
error = 1; error = 1;
AssertAlways(!"UNHANDLED DEFINE FILE!!!"); // AssertAlways(!"UNHANDLED DEFINE FILE!!!");
}break; }break;
case DW_ExtOpcode_SetDiscriminator: { case DW_ExtOpcode_SetDiscriminator:
{
U64 v = 0; U64 v = 0;
unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &v); unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &v);
vm_state.discriminator = v; vm_state.discriminator = v;
}break; }break;
default: break;
} }
unit_cursor = extended_opl; unit_cursor = extended_opl;
}break; }break;
} }
} }
exit:; exit:;
return result; return result;
} }
+1 -1
View File
@@ -216,7 +216,7 @@ enum
ELF_SectionIndex_MIPS_SUndefined = 0xff04, ELF_SectionIndex_MIPS_SUndefined = 0xff04,
}; };
typedef U32 ELF_SectionFlag; typedef U32 ELF_SectionFlags;
enum enum
{ {
ELF_Shf_Write = (1 << 0), ELF_Shf_Write = (1 << 0),
+3 -8
View File
@@ -58,14 +58,11 @@ c2r_rdi_binary_section_flags_from_coff_section_flags(COFF_SectionFlags flags)
internal RDIM_BinarySectionList internal RDIM_BinarySectionList
c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, String8 string_table, U64 sectab_count, COFF_SectionHeader *sectab) c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, String8 string_table, U64 sectab_count, COFF_SectionHeader *sectab)
{ {
ProfBeginFunction();
RDIM_BinarySectionList binary_sections = {0}; RDIM_BinarySectionList binary_sections = {0};
for EachIndex(idx, sectab_count)
for (U64 isec = 0; isec < sectab_count; ++isec) { {
COFF_SectionHeader *coff_sec = &sectab[isec]; COFF_SectionHeader *coff_sec = &sectab[idx];
RDIM_BinarySection *sec = rdim_binary_section_list_push(arena, &binary_sections); RDIM_BinarySection *sec = rdim_binary_section_list_push(arena, &binary_sections);
sec->name = coff_name_from_section_header(string_table, coff_sec); sec->name = coff_name_from_section_header(string_table, coff_sec);
sec->flags = c2r_rdi_binary_section_flags_from_coff_section_flags(coff_sec->flags); sec->flags = c2r_rdi_binary_section_flags_from_coff_section_flags(coff_sec->flags);
sec->voff_first = coff_sec->voff; sec->voff_first = coff_sec->voff;
@@ -73,7 +70,5 @@ c2r_rdi_binary_sections_from_coff_sections(Arena *arena, String8 image_data, Str
sec->foff_first = coff_sec->foff; sec->foff_first = coff_sec->foff;
sec->foff_opl = coff_sec->foff + coff_sec->fsize; sec->foff_opl = coff_sec->foff + coff_sec->fsize;
} }
ProfEnd();
return binary_sections; return binary_sections;
} }
File diff suppressed because it is too large Load Diff
+13 -6
View File
@@ -1,7 +1,11 @@
// 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/)
#pragma once #ifndef RDI_FROM_DWARF_H
#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
@@ -15,6 +19,9 @@ struct D2R_ConvertParams
B32 deterministic; B32 deterministic;
}; };
////////////////////////////////
//~ rjf: Conversion Helper Types
typedef struct D2R_TypeTable typedef struct D2R_TypeTable
{ {
HashTable *ht; HashTable *ht;
@@ -104,9 +111,6 @@ internal RDIM_Type * d2r_type_from_offset(D2R_TypeTable *type_table, U64 i
internal RDIM_Type * d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Input *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_Input *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_Input *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
@@ -134,15 +138,14 @@ internal void d2r_push_relational_op(Arena *arena, D2R_ValueTypeStack *
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_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_Input *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_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_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_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); 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
@@ -159,6 +162,8 @@ internal DW_Tag d2r_tag_iterator_parent_tag(D2R_TagIterator *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_Input *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_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_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_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_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);
@@ -167,3 +172,5 @@ internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_
//~ 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
+29 -2
View File
@@ -1,9 +1,36 @@
// 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 RDIM_BinarySectionList internal RDI_BinarySectionFlags
e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, ELF_Shdr64Array shdrs) 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
e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, String8 data, ELF_Bin *bin, 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;
} }
+2 -1
View File
@@ -4,6 +4,7 @@
#ifndef RDI_FROM_ELF_H #ifndef RDI_FROM_ELF_H
#define RDI_FROM_ELF_H #define RDI_FROM_ELF_H
internal RDIM_BinarySectionList e2r_rdi_binary_sections_from_elf_section_table(Arena *arena, ELF_Shdr64Array shdrs); 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, String8 data, ELF_Bin *bin, ELF_Shdr64Array shdrs);
#endif // RDI_FROM_ELF_H #endif // RDI_FROM_ELF_H
+2 -2
View File
@@ -5,7 +5,7 @@
#define RDI_FROM_PDB_H #define RDI_FROM_PDB_H
//////////////////////////////// ////////////////////////////////
//~ rjf: Conversion Stage Inputs/Outputs //~ rjf: Conversion Stage Inputs
typedef struct P2R_ConvertParams P2R_ConvertParams; typedef struct P2R_ConvertParams P2R_ConvertParams;
struct P2R_ConvertParams struct P2R_ConvertParams
@@ -19,7 +19,7 @@ struct P2R_ConvertParams
}; };
//////////////////////////////// ////////////////////////////////
//~ rjf: Shared Conversion State //~ rjf: Conversion Helper Types
//- rjf: link name map (voff -> string) //- rjf: link name map (voff -> string)