dwarf cleanup checkpoint

This commit is contained in:
Ryan Fleury
2025-11-10 17:41:01 -08:00
parent 08642d2745
commit 17ec73d752
20 changed files with 524 additions and 592 deletions
+66
View File
@@ -2838,6 +2838,72 @@ 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,6 +444,8 @@ 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
@@ -648,7 +648,7 @@ coff_print_obj(Arena *arena, String8List *out, String8 indent, String8 raw_data,
} }
if (opts & RD_Option_Dwarf) { if (opts & RD_Option_Dwarf) {
DW_Input dwarf_input = dw_input_from_coff_section_table(scratch.arena, raw_data, raw_string_table, header->section_count, section_table); DW_Raw dwarf_input = dw_raw_from_coff_section_table(scratch.arena, raw_data, raw_string_table, header->section_count, section_table);
dw_format(arena, out, indent, opts, &dwarf_input, arch, ExecutableImageKind_CoffPe); dw_format(arena, out, indent, opts, &dwarf_input, arch, ExecutableImageKind_CoffPe);
} }
+97 -97
View File
@@ -1568,7 +1568,7 @@ ctrl_reg_block_from_thread(Arena *arena, CTRL_EntityCtx *ctx, CTRL_Handle handle
U64 current_reg_gen = ctrl_reg_gen(); U64 current_reg_gen = ctrl_reg_gen();
B32 need_stale = 1; B32 need_stale = 1;
if(node->reg_gen != current_reg_gen && if(node->reg_gen != current_reg_gen &&
dmn_thread_read_reg_block(handle.dmn_handle, result)) dmn_thread_read_reg_block(handle.dmn_handle, result))
{ {
if(node != 0) if(node != 0)
{ {
@@ -1830,10 +1830,10 @@ internal
DW_MEM_READ(ctrl_unwind_mem_read_dwarf_x64) DW_MEM_READ(ctrl_unwind_mem_read_dwarf_x64)
{ {
CTRL_MemoryReadContextDwarfX64 *ctx = ud; CTRL_MemoryReadContextDwarfX64 *ctx = ud;
B32 is_stale = 0; B32 is_stale = 0;
B32 is_read = ctrl_process_memory_read(ctx->process_handle, r1u64(addr, addr + size), &is_stale, buffer, ctx->endt_us); B32 is_read = ctrl_process_memory_read(ctx->process_handle, r1u64(addr, addr + size), &is_stale, buffer, ctx->endt_us);
DW_UnwindStatus status = DW_UnwindStatus_Fail; DW_UnwindStatus status = DW_UnwindStatus_Fail;
if(is_stale && is_read) if(is_stale && is_read)
{ {
@@ -1843,7 +1843,7 @@ DW_MEM_READ(ctrl_unwind_mem_read_dwarf_x64)
{ {
status = DW_UnwindStatus_Ok; status = DW_UnwindStatus_Ok;
} }
return status; return status;
} }
@@ -1858,9 +1858,9 @@ DW_REG_READ(ctrl_unwind_reg_read_dwarf_x64)
#define X(_N, _ID, _MAP_N, ...) case _ID: { reg_size = sizeof(regs->_MAP_N); reg_bytes = &regs->_MAP_N; } break; #define X(_N, _ID, _MAP_N, ...) case _ID: { reg_size = sizeof(regs->_MAP_N); reg_bytes = &regs->_MAP_N; } break;
DW_Regs_X64_XList(X) DW_Regs_X64_XList(X)
#undef X #undef X
default: { InvalidPath; } break; default: { InvalidPath; } break;
} }
// copy out register value // copy out register value
DW_UnwindStatus status = DW_UnwindStatus_Fail; DW_UnwindStatus status = DW_UnwindStatus_Fail;
if(reg_size > 0) if(reg_size > 0)
@@ -1869,7 +1869,7 @@ DW_REG_READ(ctrl_unwind_reg_read_dwarf_x64)
MemoryCopy(buffer, reg_bytes, reg_size); MemoryCopy(buffer, reg_bytes, reg_size);
status = DW_UnwindStatus_Ok; status = DW_UnwindStatus_Ok;
} }
return status; return status;
} }
@@ -1884,9 +1884,9 @@ DW_REG_WRITE(ctrl_unwind_reg_write_dwarf_x64)
#define X(_N, _ID, _MAP_N, ...) case _ID: { reg_size = sizeof(regs->_MAP_N); reg_bytes = &regs->_MAP_N; } break; #define X(_N, _ID, _MAP_N, ...) case _ID: { reg_size = sizeof(regs->_MAP_N); reg_bytes = &regs->_MAP_N; } break;
DW_Regs_X64_XList(X) DW_Regs_X64_XList(X)
#undef X #undef X
default: { InvalidPath; } break; default: { InvalidPath; } break;
} }
// write value to the register // write value to the register
DW_UnwindStatus status = DW_UnwindStatus_Fail; DW_UnwindStatus status = DW_UnwindStatus_Fail;
if(reg_size > 0) if(reg_size > 0)
@@ -1895,7 +1895,7 @@ DW_REG_WRITE(ctrl_unwind_reg_write_dwarf_x64)
MemoryCopy(reg_bytes, value, value_size); MemoryCopy(reg_bytes, value, value_size);
status = DW_UnwindStatus_Ok; status = DW_UnwindStatus_Ok;
} }
return status; return status;
} }
@@ -1903,9 +1903,9 @@ internal CTRL_UnwindStepResult
ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, Arch arch, void *regs, U64 endt_us) ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, Arch arch, void *regs, U64 endt_us)
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
CTRL_UnwindStepResult result = { .flags = CTRL_UnwindFlag_Error }; CTRL_UnwindStepResult result = { .flags = CTRL_UnwindFlag_Error };
// gather context for virtual stack unwinder // gather context for virtual stack unwinder
U64 cfi_rebase = 0; U64 cfi_rebase = 0;
B32 is_unwind_eh = 0; B32 is_unwind_eh = 0;
@@ -1931,13 +1931,13 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
} }
} }
} }
// grab IP // grab IP
U64 ip = regs_rip_from_arch_block(arch, regs); U64 ip = regs_rip_from_arch_block(arch, regs);
// use .eh_frame_hdr to quickly locate nearest FDE // use .eh_frame_hdr to quickly locate nearest FDE
U64 fde_addr = eh_find_nearest_fde(eh_frame_hdr, &eh_ptr_ctx, ip); U64 fde_addr = eh_find_nearest_fde(eh_frame_hdr, &eh_ptr_ctx, ip);
if(fde_addr != max_U64) if(fde_addr != max_U64)
{ {
// parse call frame info // parse call frame info
@@ -1947,7 +1947,7 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
if(is_unwind_eh) if(is_unwind_eh)
{ {
B32 is_stale = 0; B32 is_stale = 0;
// extract FDE info // extract FDE info
Rng1U64 fde_vrange = {0}; Rng1U64 fde_vrange = {0};
DW_Format fde_format = DW_Format_Null; DW_Format fde_format = DW_Format_Null;
@@ -1969,16 +1969,16 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
fde_vrange = r1u64(fde_addr, fde_addr + sizeof(first_four_bytes) + first_four_bytes); fde_vrange = r1u64(fde_addr, fde_addr + sizeof(first_four_bytes) + first_four_bytes);
fde_format = DW_Format_32Bit; fde_format = DW_Format_32Bit;
} }
// read out whole FDE // read out whole FDE
void *fde_raw = push_array(scratch.arena, U8, dim_1u64(fde_vrange)); void *fde_raw = push_array(scratch.arena, U8, dim_1u64(fde_vrange));
if(!ctrl_process_memory_read(process_handle, fde_vrange, &is_stale, fde_raw, endt_us)) { goto eh_parse_exit; } if(!ctrl_process_memory_read(process_handle, fde_vrange, &is_stale, fde_raw, endt_us)) { goto eh_parse_exit; }
fde_data = str8(fde_raw, dim_1u64(fde_vrange)); fde_data = str8(fde_raw, dim_1u64(fde_vrange));
// 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 = str8_deserial_read_dwarf_uint(fde_data, cie_delta_off, fde_format, &cie_delta); U64 cie_delta_size = dw_str8_deserial_read_fmt_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;
} }
@@ -2003,19 +2003,19 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
cie_vrange = r1u64(cie_addr, cie_addr + sizeof(first_four_bytes) + first_four_bytes); cie_vrange = r1u64(cie_addr, cie_addr + sizeof(first_four_bytes) + first_four_bytes);
cie_format = DW_Format_32Bit; cie_format = DW_Format_32Bit;
} }
// read out whole CIE // read out whole CIE
void *cie_raw = push_array(scratch.arena, U8, dim_1u64(cie_vrange)); void *cie_raw = push_array(scratch.arena, U8, dim_1u64(cie_vrange));
if(!ctrl_process_memory_read(process_handle, cie_vrange, &is_stale, cie_raw, endt_us)) { goto eh_parse_exit; } if(!ctrl_process_memory_read(process_handle, cie_vrange, &is_stale, cie_raw, endt_us)) { goto eh_parse_exit; }
cie_data = str8(cie_raw, dim_1u64(cie_vrange)); cie_data = str8(cie_raw, dim_1u64(cie_vrange));
} }
// parse CIE and FDE // parse CIE and FDE
if(eh_parse_cie(cie_data, cie_format, arch, cie_vrange.min, &eh_ptr_ctx, &cie)) if(eh_parse_cie(cie_data, cie_format, arch, cie_vrange.min, &eh_ptr_ctx, &cie))
{ {
is_cfi_parsed = eh_parse_fde(fde_data, fde_format, fde_vrange.min, &cie, &eh_ptr_ctx, &fde); is_cfi_parsed = eh_parse_fde(fde_data, fde_format, fde_vrange.min, &cie, &eh_ptr_ctx, &fde);
} }
eh_parse_exit:; eh_parse_exit:;
if(is_stale) if(is_stale)
{ {
@@ -2026,7 +2026,7 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
{ {
is_cfi_parsed = dw_parse_cfi(unwind_data, fde_addr, arch, &cie, &fde); is_cfi_parsed = dw_parse_cfi(unwind_data, fde_addr, arch, &cie, &fde);
} }
if(is_cfi_parsed && contains_1u64(fde.pc_range, ip)) if(is_cfi_parsed && contains_1u64(fde.pc_range, ip))
{ {
// setup pointer decoder ops // setup pointer decoder ops
@@ -2037,7 +2037,7 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
EH_DecodePtrCtx *decode_ptr_ctx_eh = push_array(scratch.arena, EH_DecodePtrCtx, 1); EH_DecodePtrCtx *decode_ptr_ctx_eh = push_array(scratch.arena, EH_DecodePtrCtx, 1);
decode_ptr_ctx_eh->ptr_ctx = &eh_ptr_ctx; decode_ptr_ctx_eh->ptr_ctx = &eh_ptr_ctx;
decode_ptr_ctx_eh->addr_enc = cie.ext[EH_CIE_Ext_AddrEnc]; decode_ptr_ctx_eh->addr_enc = cie.ext[EH_CIE_Ext_AddrEnc];
decode_ptr_func = eh_decode_ptr; decode_ptr_func = eh_decode_ptr;
decode_ptr_ctx = decode_ptr_ctx_eh; decode_ptr_ctx = decode_ptr_ctx_eh;
} }
@@ -2046,7 +2046,7 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
decode_ptr_func = dw_decode_ptr_debug_frame; decode_ptr_func = dw_decode_ptr_debug_frame;
decode_ptr_ctx = &cie; decode_ptr_ctx = &cie;
} }
// find register rules for IP // find register rules for IP
DW_CFI_Row *cfi_row = dw_cfi_row_from_pc(scratch.arena, arch, &cie, &fde, decode_ptr_func, decode_ptr_ctx, ip); DW_CFI_Row *cfi_row = dw_cfi_row_from_pc(scratch.arena, arch, &cie, &fde, decode_ptr_func, decode_ptr_ctx, ip);
if(cfi_row) if(cfi_row)
@@ -2060,28 +2060,28 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
DW_RegWrite *reg_write_func = 0; DW_RegWrite *reg_write_func = 0;
switch(arch) switch(arch)
{ {
case Arch_Null: break; case Arch_Null: break;
case Arch_x64: case Arch_x64:
{ {
CTRL_MemoryReadContextDwarfX64 *mem_read_ctx_x64 = push_array(scratch.arena, CTRL_MemoryReadContextDwarfX64, 1); CTRL_MemoryReadContextDwarfX64 *mem_read_ctx_x64 = push_array(scratch.arena, CTRL_MemoryReadContextDwarfX64, 1);
mem_read_ctx_x64->process_handle = process_handle; mem_read_ctx_x64->process_handle = process_handle;
mem_read_ctx_x64->endt_us = endt_us; mem_read_ctx_x64->endt_us = endt_us;
mem_read_ctx = mem_read_ctx_x64; mem_read_ctx = mem_read_ctx_x64;
reg_read_ctx = regs; reg_read_ctx = regs;
reg_write_ctx = regs; reg_write_ctx = regs;
mem_read_func = ctrl_unwind_mem_read_dwarf_x64; mem_read_func = ctrl_unwind_mem_read_dwarf_x64;
reg_read_func = ctrl_unwind_reg_read_dwarf_x64; reg_read_func = ctrl_unwind_reg_read_dwarf_x64;
reg_write_func = ctrl_unwind_reg_write_dwarf_x64; reg_write_func = ctrl_unwind_reg_write_dwarf_x64;
}break; }break;
case Arch_x86: case Arch_x86:
case Arch_arm64: case Arch_arm64:
case Arch_arm32: case Arch_arm32:
{ {
NotImplemented; NotImplemented;
}break; }break;
default: { InvalidPath; } break; default: { InvalidPath; } break;
} }
// apply register rules to the context // apply register rules to the context
@@ -2094,30 +2094,30 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
reg_read_ctx, reg_read_ctx,
reg_write_func, reg_write_func,
reg_write_ctx); reg_write_ctx);
// last frame typically has undefined rule for IP // last frame typically has undefined rule for IP
if(cfi_row->regs[cie.ret_addr_reg].rule == DW_CFI_RegisterRule_Undefined) if(cfi_row->regs[cie.ret_addr_reg].rule == DW_CFI_RegisterRule_Undefined)
{ {
regs_arch_block_write_rip(arch, regs, 0); regs_arch_block_write_rip(arch, regs, 0);
} }
// translate unwind status code to control layer's result flags // translate unwind status code to control layer's result flags
switch(cfi_uw_status) switch(cfi_uw_status)
{ {
case DW_UnwindStatus_Ok: case DW_UnwindStatus_Ok:
{ {
result.flags &= ~(CTRL_UnwindFlag_Error|CTRL_UnwindFlag_Stale); result.flags &= ~(CTRL_UnwindFlag_Error|CTRL_UnwindFlag_Stale);
}break; }break;
case DW_UnwindStatus_Fail: case DW_UnwindStatus_Fail:
{ {
result.flags |= CTRL_UnwindFlag_Error; result.flags |= CTRL_UnwindFlag_Error;
}break; }break;
case DW_UnwindStatus_Maybe: case DW_UnwindStatus_Maybe:
{ {
result.flags &= ~CTRL_UnwindFlag_Error; result.flags &= ~CTRL_UnwindFlag_Error;
result.flags |= CTRL_UnwindFlag_Stale; result.flags |= CTRL_UnwindFlag_Stale;
}break; }break;
default: { InvalidPath; } break; default: { InvalidPath; } break;
} }
} }
} }
@@ -2126,7 +2126,7 @@ ctrl_unwind_step__dwarf(CTRL_Handle process_handle, CTRL_Handle module_handle, A
{ {
// TODO: if IP does not have FDE, does this mean function is a leaf? // TODO: if IP does not have FDE, does this mean function is a leaf?
} }
scratch_end(scratch); scratch_end(scratch);
return result; return result;
} }
@@ -2977,9 +2977,9 @@ internal CTRL_UnwindStepResult
ctrl_unwind_step(CTRL_Handle process, CTRL_Handle module, U64 module_base_vaddr, Arch arch, void *reg_block, U64 endt_us) ctrl_unwind_step(CTRL_Handle process, CTRL_Handle module, U64 module_base_vaddr, Arch arch, void *reg_block, U64 endt_us)
{ {
CTRL_UnwindStepResult result = {0}; CTRL_UnwindStepResult result = {0};
result = ctrl_unwind_step__dwarf(process, module, arch, reg_block, endt_us); result = ctrl_unwind_step__dwarf(process, module, arch, reg_block, endt_us);
if(result.flags == CTRL_UnwindFlag_Error && ~result.flags & CTRL_UnwindFlag_Stale) if(result.flags == CTRL_UnwindFlag_Error && ~result.flags & CTRL_UnwindFlag_Stale)
{ {
switch(arch) switch(arch)
@@ -2987,7 +2987,7 @@ ctrl_unwind_step(CTRL_Handle process, CTRL_Handle module, U64 module_base_vaddr,
default:{}break; default:{}break;
case Arch_x64: case Arch_x64:
{ {
result = ctrl_unwind_step__pe_x64(process, module, module_base_vaddr, (REGS_RegBlockX64 *)reg_block, endt_us); result = ctrl_unwind_step__pe_x64(process, module, module_base_vaddr, (REGS_RegBlockX64 *)reg_block, endt_us);
}break; }break;
} }
} }
@@ -3478,11 +3478,11 @@ ctrl_thread__entry_point(void *p)
scratch_end(scratch); scratch_end(scratch);
} }
//- rjf: gather all touched files by user breakpoints //- rjf: gather all touched files by user breakpoints
for(CTRL_UserBreakpointNode *n = msg->user_bps.first; n != 0; n = n->next) for(CTRL_UserBreakpointNode *n = msg->user_bps.first; n != 0; n = n->next)
{ {
if(n->v.kind != CTRL_UserBreakpointKind_FileNameAndLineColNumber) if(n->v.kind != CTRL_UserBreakpointKind_FileNameAndLineColNumber)
@@ -3731,7 +3731,7 @@ internal void
ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_range, String8 path, Rng1U64 elf_phdr_vrange, U64 elf_phdr_entsize) ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_range, String8 path, Rng1U64 elf_phdr_vrange, U64 elf_phdr_entsize)
{ {
Temp scratch = scratch_begin(0,0); Temp scratch = scratch_begin(0,0);
Arena *arena = arena_alloc(); Arena *arena = arena_alloc();
U64 entry_point_voff = 0; U64 entry_point_voff = 0;
Rng1U64 tls_vaddr_range = {0}; Rng1U64 tls_vaddr_range = {0};
@@ -3742,24 +3742,24 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
String8 raddbg_data = {0}; String8 raddbg_data = {0};
Rng1U64 raddbg_section_voff_range = r1u64(0, 0); Rng1U64 raddbg_section_voff_range = r1u64(0, 0);
Rng1U64 raddbg_is_attached_section_voff_range = r1u64(0, 0); Rng1U64 raddbg_is_attached_section_voff_range = r1u64(0, 0);
PE_IntelPdata *pdatas = 0; PE_IntelPdata *pdatas = 0;
U64 pdatas_count = 0; U64 pdatas_count = 0;
U32 pdb_dbg_time = 0; U32 pdb_dbg_time = 0;
U32 pdb_dbg_age = 0; U32 pdb_dbg_age = 0;
Guid pdb_dbg_guid = {0}; Guid pdb_dbg_guid = {0};
String8 pdb_dbg_path = {0}; String8 pdb_dbg_path = {0};
U64 cfi_rebase = 0; U64 cfi_rebase = 0;
B32 is_unwind_eh = 0; B32 is_unwind_eh = 0;
EH_FrameHdr eh_frame_hdr = {0}; EH_FrameHdr eh_frame_hdr = {0};
EH_PtrCtx eh_ptr_ctx = { .pc_vaddr = max_U64, .text_vaddr = max_U64, .data_vaddr = max_U64, .func_vaddr = max_U64, .ptr_align = 0 }; EH_PtrCtx eh_ptr_ctx = { .pc_vaddr = max_U64, .text_vaddr = max_U64, .data_vaddr = max_U64, .func_vaddr = max_U64, .ptr_align = 0 };
// read module's signature bytes // read module's signature bytes
U64 module_sig_size = Max(elf_magic_string.size, sizeof(PE_DosMagic)); U64 module_sig_size = Max(elf_magic_string.size, sizeof(PE_DosMagic));
U8 *module_sig_bytes = push_array(scratch.arena, U8, module_sig_size); U8 *module_sig_bytes = push_array(scratch.arena, U8, module_sig_size);
dmn_process_read(process.dmn_handle, rng_1u64(vaddr_range.min, vaddr_range.min + module_sig_size), module_sig_bytes); dmn_process_read(process.dmn_handle, rng_1u64(vaddr_range.min, vaddr_range.min + module_sig_size), module_sig_bytes);
////////////////////////////// //////////////////////////////
//- parse PE module //- parse PE module
// //
@@ -4008,34 +4008,34 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
if(elf_sig == 0) { goto elf_exit; } if(elf_sig == 0) { goto elf_exit; }
switch(elf_sig[ELF_Identifier_Class]) switch(elf_sig[ELF_Identifier_Class])
{ {
default: default:
case ELF_Class_None:{}break; case ELF_Class_None:{}break;
case ELF_Class_32: case ELF_Class_32:
{ {
NotImplemented; NotImplemented;
}break; }break;
case ELF_Class_64: case ELF_Class_64:
{ {
ELF_Hdr64 *ehdr = dmn_process_read_raw(scratch.arena, process.dmn_handle, rng_1u64(vaddr_range.min, vaddr_range.min + sizeof(*ehdr))); ELF_Hdr64 *ehdr = dmn_process_read_raw(scratch.arena, process.dmn_handle, rng_1u64(vaddr_range.min, vaddr_range.min + sizeof(*ehdr)));
if(ehdr == 0) { goto elf_exit; } if(ehdr == 0) { goto elf_exit; }
e_entry = ehdr->e_entry; e_entry = ehdr->e_entry;
e_type = ehdr->e_type; e_type = ehdr->e_type;
}break; }break;
} }
} }
if(e_type == ELF_Type_Dyn) if(e_type == ELF_Type_Dyn)
{ {
cfi_rebase = vaddr_range.min; cfi_rebase = vaddr_range.min;
} }
// find and parse .eh_frame_hdr // find and parse .eh_frame_hdr
Rng1U64 eh_frame_hdr_vrange = {0}; Rng1U64 eh_frame_hdr_vrange = {0};
String8 eh_frame_hdr_data = {0}; String8 eh_frame_hdr_data = {0};
{ {
void *phdrs_raw = dmn_process_read_raw(scratch.arena, process.dmn_handle, elf_phdr_vrange); void *phdrs_raw = dmn_process_read_raw(scratch.arena, process.dmn_handle, elf_phdr_vrange);
if(phdrs_raw == 0) { goto elf_exit; } if(phdrs_raw == 0) { goto elf_exit; }
if(elf_phdr_entsize == sizeof(ELF_Phdr32)) if(elf_phdr_entsize == sizeof(ELF_Phdr32))
{ {
NotImplemented; NotImplemented;
@@ -4057,19 +4057,19 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
} }
} }
} }
// parse .eh_frame_hdr // parse .eh_frame_hdr
Arch arch = ctrl_arch_from_process_handle(process); Arch arch = ctrl_arch_from_process_handle(process);
eh_ptr_ctx.pc_vaddr = eh_frame_hdr_vrange.min; eh_ptr_ctx.pc_vaddr = eh_frame_hdr_vrange.min;
eh_ptr_ctx.data_vaddr = eh_frame_hdr_vrange.min; eh_ptr_ctx.data_vaddr = eh_frame_hdr_vrange.min;
eh_frame_hdr = eh_parse_frame_hdr(eh_frame_hdr_data, byte_size_from_arch(arch), &eh_ptr_ctx); eh_frame_hdr = eh_parse_frame_hdr(eh_frame_hdr_data, byte_size_from_arch(arch), &eh_ptr_ctx);
// set entry point // set entry point
if (e_entry != 0) if (e_entry != 0)
{ {
entry_point_voff = e_entry - vaddr_range.min; entry_point_voff = e_entry - vaddr_range.min;
} }
// TODO: is there a way to detect DWARF in runtime ELF? // TODO: is there a way to detect DWARF in runtime ELF?
if(1) if(1)
{ {
@@ -4162,7 +4162,7 @@ ctrl_thread__module_open(CTRL_Handle process, CTRL_Handle module, Rng1U64 vaddr_
} }
} }
} }
scratch_end(scratch); scratch_end(scratch);
} }
+7 -8
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_Input internal DW_Raw
dw_input_from_coff_section_table(Arena *arena, dw_raw_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_Input input = {0}; DW_Raw 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,7 +51,6 @@ dw_input_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;
} }
+1 -2
View File
@@ -5,7 +5,6 @@
#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_Input dw_input_from_coff_section_table(Arena *arena, String8 raw_image, 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);
#endif // DWARF_COFF_H #endif // DWARF_COFF_H
+18 -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 += str8_deserial_read_dwarf_uint(raw_data, cursor, format, &x); cursor += dw_str8_deserial_read_fmt_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 += str8_deserial_read_dwarf_uint(raw_data, cursor, format, &info_off); cursor += dw_str8_deserial_read_fmt_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);
@@ -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_Input *input, Arch arch, ExecutableImageKind image_type, B32 relaxed) dw_print_debug_loc(Arena *arena, String8List *out, String8 indent, DW_Raw *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_Input *inp
} }
internal void internal void
dw_print_debug_ranges(Arena *arena, String8List *out, String8 indent, DW_Input *input, Arch arch, ExecutableImageKind image_type, B32 relaxed) dw_print_debug_ranges(Arena *arena, String8List *out, String8 indent, DW_Raw *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_Input *
} }
internal void internal void
dw_print_debug_aranges(Arena *arena, String8List *out, String8 indent, DW_Input *input) dw_print_debug_aranges(Arena *arena, String8List *out, String8 indent, DW_Raw *input)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1022,7 +1022,7 @@ dw_print_debug_aranges(Arena *arena, String8List *out, String8 indent, DW_Input
} }
internal void internal void
dw_print_debug_addr(Arena *arena, String8List *out, String8 indent, DW_Input *input) dw_print_debug_addr(Arena *arena, String8List *out, String8 indent, DW_Raw *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_Input *input, Rng1U64Array segment_virtual_ranges, Arch arch) dw_print_debug_loclists(Arena *arena, String8List *out, String8 indent, DW_Raw *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_Input
} }
internal void internal void
dw_print_debug_rnglists(Arena *arena, String8List *out, String8 indent, DW_Input *input, Rng1U64Array segment_ranges) dw_print_debug_rnglists(Arena *arena, String8List *out, String8 indent, DW_Raw *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_Input
} }
internal void internal void
dw_format_string_table(Arena *arena, String8List *out, String8 indent, DW_Input *input, DW_SectionKind sec) dw_format_string_table(Arena *arena, String8List *out, String8 indent, DW_Raw *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_Input
} }
internal void internal void
dw_print_debug_pubnames(Arena *arena, String8List *out, String8 indent, DW_Input *input) dw_print_debug_pubnames(Arena *arena, String8List *out, String8 indent, DW_Raw *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_Input *input) dw_print_debug_pubtypes(Arena *arena, String8List *out, String8 indent, DW_Raw *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_Input *input) dw_print_debug_line_str(Arena *arena, String8List *out, String8 indent, DW_Raw *input)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1527,7 +1527,7 @@ dw_print_debug_line_str(Arena *arena, String8List *out, String8 indent, DW_Input
} }
internal void internal void
dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_Input *input) dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_Raw *input)
{ {
NotImplemented; NotImplemented;
#if 0 #if 0
@@ -1598,7 +1598,7 @@ dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_In
//~ rjf: Dump Entry Point //~ rjf: Dump Entry Point
internal String8 internal String8
dw_string_from_attrib_value(Arena *arena, DW_Input *input, Arch arch, DW_CompUnit *unit, DW_LineVMHeader *line_vm, DW_Attrib *attrib) dw_string_from_attrib_value(Arena *arena, DW_Raw *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_Input *input, Arch arch, DW_CompUni
internal String8List internal String8List
dw_dump_list_from_sections(Arena *arena, dw_dump_list_from_sections(Arena *arena,
DW_Input *input, DW_Raw *input,
Arch arch, Arch arch,
DW_DumpSubsetFlags subset_flags) DW_DumpSubsetFlags subset_flags)
{ {
@@ -1748,18 +1748,17 @@ 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_input(scratch.arena, input); DW_ListUnitInput lu_input = dw_list_unit_input_from_raw(scratch.arena, input);
B32 relaxed = 1;
DW_CompUnit *cu_arr; DW_CompUnit *cu_arr;
{ {
DW_ListUnitInput lu_input = dw_list_unit_input_from_input(scratch.arena, input); DW_ListUnitInput lu_input = dw_list_unit_input_from_raw(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, relaxed); cu_arr[cu_idx] = dw_cu_from_info_off(scratch.arena, input, lu_input, cu_ranges.v[cu_idx].min);
} }
} }
+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_Input *input, Arch arch, ExecutableImageKind image_type, B32 relaxed); 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_ranges (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_aranges (Arena *arena, String8List *out, String8 indent, DW_Input *input); internal void dw_print_debug_aranges (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_addr (Arena *arena, String8List *out, String8 indent, DW_Raw *input);
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_loclists (Arena *arena, String8List *out, String8 indent, DW_Raw *input, Rng1U64Array segment_vranges, Arch arch);
internal void dw_print_debug_rnglists (Arena *arena, String8List *out, String8 indent, DW_Input *input, Rng1U64Array segment_vranges); internal void dw_print_debug_rnglists (Arena *arena, String8List *out, String8 indent, DW_Raw *input, Rng1U64Array segment_vranges);
internal void dw_print_debug_pubnames (Arena *arena, String8List *out, String8 indent, DW_Input *input); internal void dw_print_debug_pubnames (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_pubtypes (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_line_str (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); internal void dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_Raw *input);
#endif #endif
//////////////////////////////// ////////////////////////////////
//~ rjf: Dump Entry Point //~ rjf: Dump Entry Point
internal String8List dw_dump_list_from_sections(Arena *arena, DW_Input *input, Arch arch, DW_DumpSubsetFlags subset_flags); internal String8List dw_dump_list_from_sections(Arena *arena, DW_Raw *input, Arch arch, DW_DumpSubsetFlags subset_flags);
#endif // DWARF_DUMP_H #endif // DWARF_DUMP_H
+3 -4
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_Input internal DW_Raw
dw_input_from_elf_bin(Arena *arena, String8 data, ELF_Bin *bin) dw_raw_from_elf_bin(Arena *arena, String8 data, ELF_Bin *bin)
{ {
DW_Input result = {0}; DW_Raw 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,7 +106,6 @@ dw_input_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_Input dw_input_from_elf_bin(Arena *arena, String8 raw_image, ELF_Bin *bin); internal DW_Raw dw_raw_from_elf_bin(Arena *arena, String8 raw_image, ELF_Bin *bin);
#endif // DWARF_ELF_H #endif // DWARF_ELF_H
-1
View File
@@ -15,4 +15,3 @@ 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
+87 -209
View File
@@ -2,7 +2,7 @@
// Licensed under the MIT license (https://opensource.org/license/mit/) // Licensed under the MIT license (https://opensource.org/license/mit/)
internal U64 internal U64
str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out) dw_str8_deserial_read_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)))
@@ -24,7 +24,7 @@ str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out)
} }
internal U64 internal U64
str8_deserial_read_dwarf_uint(String8 string, U64 off, DW_Format format, U64 *uint_out) dw_str8_deserial_read_fmt_uint(String8 string, U64 off, DW_Format format, U64 *uint_out)
{ {
U64 bytes_read = 0; U64 bytes_read = 0;
switch(format) switch(format)
@@ -43,126 +43,6 @@ str8_deserial_read_dwarf_uint(String8 string, U64 off, DW_Format format, U64 *ui
return bytes_read; return bytes_read;
} }
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 U64
str8_deserial_read_uleb128_array(Arena *arena, String8 string, U64 off, U64 count, U64 **arr_out)
{
Temp temp = temp_begin(arena);
U64 *arr = push_array(arena, U64, count);
U64 i, cursor;
for (i = 0, cursor = off; i < count; ++i) {
U64 read_size = str8_deserial_read_uleb128(string, cursor, &arr[i]);
if (read_size == 0) {
break;
}
cursor += read_size;
}
U64 bytes_read = 0;
if (i == count) {
*arr_out = arr;
bytes_read = cursor - off;
} else {
temp_end(temp);
*arr_out = 0;
}
return bytes_read;
}
internal U64
str8_deserial_read_sleb128_array(Arena *arena, String8 string, U64 off, U64 count, S64 **arr_out)
{
Temp temp = temp_begin(arena);
S64 *arr = push_array(arena, S64, count);
U64 i, cursor;
for (i = 0, cursor = off; i < count; ++i) {
U64 read_size = str8_deserial_read_sleb128(string, cursor, &arr[i]);
if (read_size == 0) {
break;
}
cursor += read_size;
}
U64 bytes_read = 0;
if (i == count) {
*arr_out = arr;
bytes_read = cursor - off;
} else {
temp_end(temp);
*arr_out = 0;
}
return bytes_read;
}
internal DW_SectionKind internal DW_SectionKind
dw_section_kind_from_string(String8 string) dw_section_kind_from_string(String8 string)
{ {
@@ -194,7 +74,7 @@ dw_unit_ranges_from_data(Arena *arena, String8 data)
{ {
// rjf: read CU size; bad read -> terminate // 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 = dw_str8_deserial_read_packed_size(data, cursor, &cu_size);
if(cu_size_size == 0) if(cu_size_size == 0)
{ {
break; break;
@@ -219,7 +99,7 @@ dw_read_list_unit_header_addr(String8 unit_data, DW_ListUnit *lu_out)
U64 header_size = 0; U64 header_size = 0;
U64 unit_length = 0; U64 unit_length = 0;
U64 unit_length_size = str8_deserial_read_dwarf_packed_size(unit_data, 0, &unit_length); U64 unit_length_size = dw_str8_deserial_read_packed_size(unit_data, 0, &unit_length);
if (unit_length_size) { if (unit_length_size) {
DW_Version version = DW_Version_Null; DW_Version version = DW_Version_Null;
@@ -260,7 +140,7 @@ dw_read_list_unit_header_str_offsets(String8 unit_data, DW_ListUnit *lu_out)
U64 header_size = 0; U64 header_size = 0;
U64 unit_length = 0; U64 unit_length = 0;
U64 unit_length_size = str8_deserial_read_dwarf_packed_size(unit_data, 0, &unit_length); U64 unit_length_size = dw_str8_deserial_read_packed_size(unit_data, 0, &unit_length);
if (unit_length_size) { if (unit_length_size) {
DW_Version version = DW_Version_Null; DW_Version version = DW_Version_Null;
@@ -291,7 +171,7 @@ dw_read_list_unit_header_list(String8 unit_data, DW_ListUnit *lu_out)
U64 header_size = 0; U64 header_size = 0;
U64 unit_length = 0; U64 unit_length = 0;
U64 unit_length_size = str8_deserial_read_dwarf_packed_size(unit_data, 0, &unit_length); U64 unit_length_size = dw_str8_deserial_read_packed_size(unit_data, 0, &unit_length);
if (unit_length_size) { if (unit_length_size) {
DW_Version version = DW_Version_Null; DW_Version version = DW_Version_Null;
@@ -327,7 +207,7 @@ dw_read_list_unit_header_list(String8 unit_data, DW_ListUnit *lu_out)
} }
internal DW_ListUnitInput internal DW_ListUnitInput
dw_list_unit_input_from_input(Arena *arena, DW_Input *input) dw_list_unit_input_from_raw(Arena *arena, DW_Raw *input)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -709,11 +589,11 @@ dw_read_form(String8 data,
if (version < DW_Version_3) { if (version < DW_Version_3) {
bytes_read = str8_deserial_read(data, off, &form.ref, address_size, address_size); bytes_read = str8_deserial_read(data, off, &form.ref, address_size, address_size);
} else { } else {
bytes_read = str8_deserial_read_dwarf_uint(data, off, unit_format, &form.ref); bytes_read = dw_str8_deserial_read_fmt_uint(data, off, unit_format, &form.ref);
} }
} break; } break;
case DW_Form_GNU_RefAlt: { case DW_Form_GNU_RefAlt: {
bytes_read = str8_deserial_read_dwarf_uint(data, off, unit_format, &form.ref); bytes_read = dw_str8_deserial_read_fmt_uint(data, off, unit_format, &form.ref);
} break; } break;
case DW_Form_Ref1: { case DW_Form_Ref1: {
bytes_read = str8_deserial_read(data, off, &form.ref, 1, 1); bytes_read = str8_deserial_read(data, off, &form.ref, 1, 1);
@@ -734,7 +614,7 @@ dw_read_form(String8 data,
case DW_Form_LineStrp: case DW_Form_LineStrp:
case DW_Form_GNU_StrpAlt: case DW_Form_GNU_StrpAlt:
case DW_Form_Strp: { case DW_Form_Strp: {
bytes_read = str8_deserial_read_dwarf_uint(data, off, unit_format, &form.sec_offset); bytes_read = dw_str8_deserial_read_fmt_uint(data, off, unit_format, &form.sec_offset);
} break; } break;
case DW_Form_ExprLoc: { case DW_Form_ExprLoc: {
U64 expr_size = 0; U64 expr_size = 0;
@@ -764,7 +644,7 @@ dw_read_form(String8 data,
NotImplemented; NotImplemented;
} break; } break;
case DW_Form_StrpSup: { case DW_Form_StrpSup: {
bytes_read = str8_deserial_read_dwarf_uint(data, off, unit_format, &form.strp_sup); bytes_read = dw_str8_deserial_read_fmt_uint(data, off, unit_format, &form.strp_sup);
} break; } break;
case DW_Form_Data16: { case DW_Form_Data16: {
bytes_read = str8_deserial_read_block(data, off, 16, &form.data); bytes_read = str8_deserial_read_block(data, off, 16, &form.data);
@@ -902,7 +782,7 @@ dw_read_tag(Arena *arena,
} }
internal U64 internal U64
dw_read_tag_cu(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 info_off, DW_Tag *tag_out) dw_read_tag_cu(Arena *arena, DW_Raw *input, DW_CompUnit *cu, U64 info_off, DW_Tag *tag_out)
{ {
String8 tag_data = str8_substr(input->sec[DW_Section_Info].data, cu->info_range); String8 tag_data = str8_substr(input->sec[DW_Section_Info].data, cu->info_range);
U64 tag_off = info_off - cu->info_range.min; U64 tag_off = info_off - cu->info_range.min;
@@ -1054,14 +934,14 @@ dw_interp_address(U64 address_size, U64 base_addr, DW_ListUnit *addr_lu, DW_Form
} }
internal String8 internal String8
dw_interp_block(DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form) dw_interp_block(DW_Raw *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form)
{ {
NotImplemented; NotImplemented;
return str8_zero(); return str8_zero();
} }
internal String8 internal String8
dw_interp_string(DW_Input *input, dw_interp_string(DW_Raw *input,
DW_Format unit_format, DW_Format unit_format,
DW_ListUnit *str_offsets, DW_ListUnit *str_offsets,
DW_FormKind form_kind, DW_FormKind form_kind,
@@ -1100,7 +980,7 @@ dw_interp_string(DW_Input *input,
} }
internal String8 internal String8
dw_interp_line_ptr(DW_Input *input, DW_FormKind form_kind, DW_Form form) dw_interp_line_ptr(DW_Raw *input, DW_FormKind form_kind, DW_Form form)
{ {
String8 result = {0}; String8 result = {0};
if (form_kind == DW_Form_SecOffset) { if (form_kind == DW_Form_SecOffset) {
@@ -1125,7 +1005,7 @@ dw_interp_file(DW_LineVMHeader *line_vm, DW_FormKind form_kind, DW_Form form)
} }
internal DW_Reference internal DW_Reference
dw_interp_ref(DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form) dw_interp_ref(DW_Raw *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form)
{ {
DW_Reference ref = {0}; DW_Reference ref = {0};
if (form_kind == DW_Form_Ref1 || form_kind == DW_Form_Ref2 || if (form_kind == DW_Form_Ref1 || form_kind == DW_Form_Ref2 ||
@@ -1146,7 +1026,7 @@ dw_interp_ref(DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form f
} }
internal DW_LocList internal DW_LocList
dw_interp_loclist(Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form) dw_interp_loclist(Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form)
{ {
DW_LocList loclist = {0}; DW_LocList loclist = {0};
@@ -1433,7 +1313,7 @@ dw_interp_flag(DW_FormKind form_kind, DW_Form form)
} }
internal Rng1U64List internal Rng1U64List
dw_interp_rnglist(Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form) dw_interp_rnglist(Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_FormKind form_kind, DW_Form form)
{ {
Rng1U64List rnglist = {0}; Rng1U64List rnglist = {0};
@@ -1624,7 +1504,7 @@ dw_interp_rnglist(Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_FormKind fo
} }
internal String8 internal String8
dw_interp_secptr(DW_Input *input, DW_SectionKind section, DW_FormKind form_kind, DW_Form form) dw_interp_secptr(DW_Raw *input, DW_SectionKind section, DW_FormKind form_kind, DW_Form form)
{ {
String8 secptr = {0}; String8 secptr = {0};
if (form_kind == DW_Form_SecOffset) { if (form_kind == DW_Form_SecOffset) {
@@ -1638,25 +1518,25 @@ dw_interp_secptr(DW_Input *input, DW_SectionKind section, DW_FormKind form_kind,
} }
internal String8 internal String8
dw_interp_addrptr(DW_Input *input, DW_FormKind form_kind, DW_Form form) dw_interp_addrptr(DW_Raw *input, DW_FormKind form_kind, DW_Form form)
{ {
return dw_interp_secptr(input, DW_Section_Addr, form_kind, form); return dw_interp_secptr(input, DW_Section_Addr, form_kind, form);
} }
internal String8 internal String8
dw_interp_str_offsets_ptr(DW_Input *input, DW_FormKind form_kind, DW_Form form) dw_interp_str_offsets_ptr(DW_Raw *input, DW_FormKind form_kind, DW_Form form)
{ {
return dw_interp_secptr(input, DW_Section_StrOffsets, form_kind, form); return dw_interp_secptr(input, DW_Section_StrOffsets, form_kind, form);
} }
internal String8 internal String8
dw_interp_rnglists_ptr(DW_Input *input, DW_FormKind form_kind, DW_Form form) dw_interp_rnglists_ptr(DW_Raw *input, DW_FormKind form_kind, DW_Form form)
{ {
return dw_interp_secptr(input, DW_Section_RngLists, form_kind, form); return dw_interp_secptr(input, DW_Section_RngLists, form_kind, form);
} }
internal String8 internal String8
dw_interp_loclists_ptr(DW_Input *input, DW_FormKind form_kind, DW_Form form) dw_interp_loclists_ptr(DW_Raw *input, DW_FormKind form_kind, DW_Form form)
{ {
return dw_interp_secptr(input, DW_Section_LocLists, form_kind, form); return dw_interp_secptr(input, DW_Section_LocLists, form_kind, form);
} }
@@ -1668,7 +1548,7 @@ dw_value_class_from_attrib(DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal String8 internal String8
dw_exprloc_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_exprloc_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_ExprLoc || value_class == DW_AttribClass_Block); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_ExprLoc || value_class == DW_AttribClass_Block);
@@ -1676,7 +1556,7 @@ dw_exprloc_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal U128 internal U128
dw_const_u128_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_const_u128_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const);
@@ -1684,7 +1564,7 @@ dw_const_u128_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal U64 internal U64
dw_const_u64_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_const_u64_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const);
@@ -1692,7 +1572,7 @@ dw_const_u64_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal U32 internal U32
dw_const_u32_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_const_u32_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const);
@@ -1700,7 +1580,7 @@ dw_const_u32_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal S64 internal S64
dw_const_s64_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_const_s64_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const);
@@ -1708,7 +1588,7 @@ dw_const_s64_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal S32 internal S32
dw_const_s32_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_const_s32_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Const);
@@ -1716,7 +1596,7 @@ dw_const_s32_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal B32 internal B32
dw_flag_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_flag_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Flag); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Flag);
@@ -1724,7 +1604,7 @@ dw_flag_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal U64 internal U64
dw_address_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_address_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || AssertAlways(value_class == DW_AttribClass_Null ||
@@ -1749,7 +1629,7 @@ dw_address_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal String8 internal String8
dw_block_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_block_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Block); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Block);
@@ -1757,7 +1637,7 @@ dw_block_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal String8 internal String8
dw_string_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_string_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_String || value_class == DW_AttribClass_StrOffsetsPtr); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_String || value_class == DW_AttribClass_StrOffsetsPtr);
@@ -1765,7 +1645,7 @@ dw_string_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal String8 internal String8
dw_line_ptr_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_line_ptr_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_LinePtr); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_LinePtr);
@@ -1781,7 +1661,7 @@ dw_file_from_attrib(DW_CompUnit *cu, DW_LineVMHeader *line_vm, DW_Attrib *attrib
} }
internal DW_Reference internal DW_Reference
dw_ref_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_ref_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Reference); AssertAlways(value_class == DW_AttribClass_Null || value_class == DW_AttribClass_Reference);
@@ -1789,7 +1669,7 @@ dw_ref_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib)
} }
internal DW_LocList internal DW_LocList
dw_loclist_from_attrib(Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_loclist_from_attrib(Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
AssertAlways(value_class == DW_AttribClass_Null || AssertAlways(value_class == DW_AttribClass_Null ||
@@ -1799,7 +1679,7 @@ dw_loclist_from_attrib(Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Attrib
} }
internal Rng1U64List internal Rng1U64List
dw_rnglist_from_attrib(Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib) dw_rnglist_from_attrib(Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib)
{ {
Rng1U64List rnglist = {0}; Rng1U64List rnglist = {0};
DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib); DW_AttribClass value_class = dw_value_class_from_attrib(cu, attrib);
@@ -1826,7 +1706,7 @@ dw_attrib_from_tag_(DW_Tag tag, DW_AttribKind kind)
} }
internal DW_Attrib * internal DW_Attrib *
dw_attrib_from_tag(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_attrib_from_tag(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
DW_Attrib *attrib = dw_attrib_from_tag_(tag, kind); DW_Attrib *attrib = dw_attrib_from_tag_(tag, kind);
@@ -1845,7 +1725,7 @@ dw_attrib_from_tag(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind k
} }
internal B32 internal B32
dw_tag_has_attrib(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_tag_has_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
DW_Attrib *attrib = dw_attrib_from_tag(input, cu, tag, kind); DW_Attrib *attrib = dw_attrib_from_tag(input, cu, tag, kind);
B32 has_attrib = attrib->attrib_kind != DW_AttribKind_Null; B32 has_attrib = attrib->attrib_kind != DW_AttribKind_Null;
@@ -1853,85 +1733,85 @@ dw_tag_has_attrib(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind ki
} }
internal String8 internal String8
dw_exprloc_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_exprloc_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_exprloc_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_exprloc_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal String8 internal String8
dw_block_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_block_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_block_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_block_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal U128 internal U128
dw_const_u128_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_const_u128_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_const_u128_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_const_u128_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal U64 internal U64
dw_const_u64_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_const_u64_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_const_u64_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_const_u64_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal U32 internal U32
dw_const_u32_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_const_u32_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_const_u32_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_const_u32_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal U64 internal U64
dw_address_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_address_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_address_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_address_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal String8 internal String8
dw_string_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_string_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_string_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_string_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal String8 internal String8
dw_line_ptr_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_line_ptr_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_line_ptr_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_line_ptr_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal DW_Reference internal DW_Reference
dw_ref_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_ref_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_ref_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_ref_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal DW_LocList internal DW_LocList
dw_loclist_from_tag_attrib_kind(Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_loclist_from_tag_attrib_kind(Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_loclist_from_attrib(arena, input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_loclist_from_attrib(arena, input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal Rng1U64List internal Rng1U64List
dw_rnglist_from_tag_attrib_kind(Arena *arena, DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_rnglist_from_tag_attrib_kind(Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_rnglist_from_attrib(arena, input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_rnglist_from_attrib(arena, input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal B32 internal B32
dw_flag_from_tag_attrib_kind(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_flag_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_flag_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind)); return dw_flag_from_attrib(input, cu, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal DW_LineFile * 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) dw_file_from_tag_attrib_kind(DW_Raw *input, DW_CompUnit *cu, DW_LineVMHeader *line_vm, DW_Tag tag, DW_AttribKind kind)
{ {
return dw_file_from_attrib(cu, line_vm, dw_attrib_from_tag(input, cu, tag, kind)); return dw_file_from_attrib(cu, line_vm, dw_attrib_from_tag(input, cu, tag, kind));
} }
internal B32 internal B32
dw_try_byte_size_from_tag(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, U64 *byte_size_out) dw_try_byte_size_from_tag(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, U64 *byte_size_out)
{ {
B32 has_byte_size = dw_tag_has_attrib(input, cu, tag, DW_AttribKind_ByteSize); B32 has_byte_size = dw_tag_has_attrib(input, cu, tag, DW_AttribKind_ByteSize);
B32 has_bit_size = dw_tag_has_attrib(input, cu, tag, DW_AttribKind_BitSize ); B32 has_bit_size = dw_tag_has_attrib(input, cu, tag, DW_AttribKind_BitSize );
@@ -1953,7 +1833,7 @@ dw_try_byte_size_from_tag(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, U64 *byt
} }
internal U64 internal U64
dw_byte_size_from_tag(DW_Input *input, DW_CompUnit *cu, DW_Tag tag) dw_byte_size_from_tag(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag)
{ {
U64 byte_size = max_U64; U64 byte_size = max_U64;
dw_try_byte_size_from_tag(input, cu, tag, &byte_size); dw_try_byte_size_from_tag(input, cu, tag, &byte_size);
@@ -1961,7 +1841,7 @@ dw_byte_size_from_tag(DW_Input *input, DW_CompUnit *cu, DW_Tag tag)
} }
internal U32 internal U32
dw_byte_size_32_from_tag(DW_Input *input, DW_CompUnit *cu, DW_Tag tag) dw_byte_size_32_from_tag(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag)
{ {
U32 byte_size32 = 0; U32 byte_size32 = 0;
U64 byte_size64; U64 byte_size64;
@@ -1972,7 +1852,7 @@ dw_byte_size_32_from_tag(DW_Input *input, DW_CompUnit *cu, DW_Tag tag)
} }
internal U64 internal U64
dw_u64_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) dw_u64_from_attrib(DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
U64 result = 0; U64 result = 0;
DW_Attrib *attrib = dw_attrib_from_tag(input, cu, tag, kind); DW_Attrib *attrib = dw_attrib_from_tag(input, cu, tag, kind);
@@ -2003,7 +1883,7 @@ dw_u64_from_attrib(DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind k
} }
internal DW_CompUnit internal DW_CompUnit
dw_cu_from_info_off(Arena *arena, DW_Input *input, DW_ListUnitInput lu_input, U64 offset, B32 relaxed) dw_cu_from_info_off(Arena *arena, DW_Raw *input, DW_ListUnitInput lu_input, U64 offset)
{ {
DW_CompUnit cu = {0}; DW_CompUnit cu = {0};
@@ -2011,7 +1891,7 @@ dw_cu_from_info_off(Arena *arena, DW_Input *input, DW_ListUnitInput lu_input, U6
// read unit size in bytes // read unit size in bytes
U64 length = 0; U64 length = 0;
U64 length_size = str8_deserial_read_dwarf_packed_size(info_data, offset, &length); U64 length_size = dw_str8_deserial_read_packed_size(info_data, offset, &length);
if (length_size) { if (length_size) {
// compute unit range // compute unit range
@@ -2058,7 +1938,7 @@ dw_cu_from_info_off(Arena *arena, DW_Input *input, DW_ListUnitInput lu_input, U6
case DW_Version_3: case DW_Version_3:
case DW_Version_4: { case DW_Version_4: {
U64 abbrev_base_off = cursor; U64 abbrev_base_off = cursor;
U64 abbrev_base_size = str8_deserial_read_dwarf_uint(data, abbrev_base_off, format, &abbrev_base); U64 abbrev_base_size = dw_str8_deserial_read_fmt_uint(data, abbrev_base_off, format, &abbrev_base);
if (!abbrev_base_size) { if (!abbrev_base_size) {
break; break;
} }
@@ -2086,7 +1966,7 @@ dw_cu_from_info_off(Arena *arena, DW_Input *input, DW_ListUnitInput lu_input, U6
} }
U64 abbrev_base_off = address_size_off + address_size_size; U64 abbrev_base_off = address_size_off + address_size_size;
U64 abbrev_base_size = str8_deserial_read_dwarf_uint(data, abbrev_base_off, format, &abbrev_base); U64 abbrev_base_size = dw_str8_deserial_read_fmt_uint(data, abbrev_base_off, format, &abbrev_base);
if (!abbrev_base_size) { if (!abbrev_base_size) {
break; break;
} }
@@ -2209,7 +2089,7 @@ dw_tag_tree_from_data(Arena *arena, String8 info_data, String8 abbrev_data, DW_C
} }
internal DW_TagTree internal DW_TagTree
dw_tag_tree_from_cu(Arena *arena, DW_Input *input, DW_CompUnit *cu) dw_tag_tree_from_cu(Arena *arena, DW_Raw *input, DW_CompUnit *cu)
{ {
String8 abbrev_data = input->sec[DW_Section_Abbrev].data; String8 abbrev_data = input->sec[DW_Section_Abbrev].data;
String8 info_data = str8_substr(input->sec[DW_Section_Info].data, cu->info_range); String8 info_data = str8_substr(input->sec[DW_Section_Info].data, cu->info_range);
@@ -2302,7 +2182,7 @@ dw_line_vm_file_array_from_list(Arena *arena, DW_LineVMFileList list)
internal U64 internal U64
dw_read_line_file(String8 data, dw_read_line_file(String8 data,
U64 off, U64 off,
DW_Input *input, DW_Raw *input,
DW_Version version, DW_Version version,
DW_Format format, DW_Format format,
DW_Ext ext, DW_Ext ext,
@@ -2364,7 +2244,7 @@ internal U64
dw_read_line_file_array(Arena *arena, dw_read_line_file_array(Arena *arena,
String8 data, String8 data,
U64 off, U64 off,
DW_Input *input, DW_Raw *input,
DW_Version version, DW_Version version,
DW_Format format, DW_Format format,
DW_Ext ext, DW_Ext ext,
@@ -2412,7 +2292,7 @@ dw_read_line_file_array(Arena *arena,
} }
internal U64 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) 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)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -2420,7 +2300,7 @@ dw_read_line_vm_header(Arena *arena, String8 line_data, U64 line_off, DW_Input *
// read unit length // read unit length
U64 unit_length = 0; U64 unit_length = 0;
U64 unit_length_size = str8_deserial_read_dwarf_packed_size(line_data, line_off, &unit_length); U64 unit_length_size = dw_str8_deserial_read_packed_size(line_data, line_off, &unit_length);
U64 unit_opl = line_off + unit_length_size + unit_length; U64 unit_opl = line_off + unit_length_size + unit_length;
Rng1U64 unit_range = rng_1u64(line_off, unit_opl); Rng1U64 unit_range = rng_1u64(line_off, unit_opl);
@@ -2457,7 +2337,7 @@ dw_read_line_vm_header(Arena *arena, String8 line_data, U64 line_off, DW_Input *
// read header length // read header length
U64 header_length = 0; U64 header_length = 0;
U64 header_length_size = str8_deserial_read_dwarf_uint(unit_data, unit_cursor, format, &header_length); U64 header_length_size = dw_str8_deserial_read_fmt_uint(unit_data, unit_cursor, format, &header_length);
if (header_length_size == 0) { if (header_length_size == 0) {
goto exit; goto exit;
} }
@@ -2611,12 +2491,11 @@ dw_read_line_vm_header(Arena *arena, String8 line_data, U64 line_off, DW_Input *
unit_cursor += enc_count_size; unit_cursor += enc_count_size;
// read table entry encodings // read table entry encodings
U64 *enc_arr = 0; U64 *enc_arr = push_array(scratch.arena, U64, enc_count*2);
U64 enc_arr_size = str8_deserial_read_uleb128_array(scratch.arena, unit_data, unit_cursor, enc_count*2, &enc_arr); for EachIndex(idx, enc_count)
if (enc_arr_size == 0) { {
goto exit; unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &enc_arr[idx]);
} }
unit_cursor += enc_arr_size;
// read table count // read table count
U64 table_count = 0; U64 table_count = 0;
@@ -2657,12 +2536,11 @@ dw_read_line_vm_header(Arena *arena, String8 line_data, U64 line_off, DW_Input *
unit_cursor += enc_count_size; unit_cursor += enc_count_size;
// read table entry encodings // read table entry encodings
U64 *enc_arr = 0; U64 *enc_arr = push_array(scratch.arena, U64, enc_count*2);
U64 enc_arr_size = str8_deserial_read_uleb128_array(scratch.arena, unit_data, unit_cursor, enc_count*2, &enc_arr); for EachIndex(idx, enc_count)
if (enc_arr_size == 0) { {
goto exit; unit_cursor += str8_deserial_read_uleb128(unit_data, unit_cursor, &enc_arr[idx]);
} }
unit_cursor += enc_arr_size;
// read table count // read table count
U64 table_count = 0; U64 table_count = 0;
@@ -2808,7 +2686,7 @@ 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, String8 unit_data, DW_Input *input, String8 cu_dir, String8 cu_name, U8 cu_address_size, DW_ListUnit *cu_str_offsets) 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)
{ {
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);
@@ -3031,7 +2909,7 @@ dw_parsed_line_table_from_data(Arena *arena, String8 unit_data, DW_Input *input,
} }
internal DW_PubStringsTable internal DW_PubStringsTable
dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Input *input, DW_SectionKind section_kind) dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Raw *input, DW_SectionKind section_kind)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -3043,7 +2921,7 @@ dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Input *input, DW_Sect
for(U64 cursor = 0; cursor < section_data.size; ) { for(U64 cursor = 0; cursor < section_data.size; ) {
U64 unit_length = 0; U64 unit_length = 0;
U64 unit_length_size = str8_deserial_read_dwarf_packed_size(section_data, cursor, &unit_length); U64 unit_length_size = dw_str8_deserial_read_packed_size(section_data, cursor, &unit_length);
if (unit_length_size == 0) { if (unit_length_size == 0) {
break; break;
} }
@@ -3063,13 +2941,13 @@ dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Input *input, DW_Sect
DW_Format format = DW_FormatFromSize(unit_length); DW_Format format = DW_FormatFromSize(unit_length);
U64 debug_info_off = 0; U64 debug_info_off = 0;
cursor += str8_deserial_read_dwarf_uint(section_data, cursor, format, &debug_info_off); cursor += dw_str8_deserial_read_fmt_uint(section_data, cursor, format, &debug_info_off);
if (cursor >= cursor_opl) { if (cursor >= cursor_opl) {
break; break;
} }
U64 debug_info_length = 0; U64 debug_info_length = 0;
cursor += str8_deserial_read_dwarf_packed_size(section_data, cursor, &debug_info_length); cursor += dw_str8_deserial_read_packed_size(section_data, cursor, &debug_info_length);
if (cursor >= cursor_opl) { if (cursor >= cursor_opl) {
break; break;
} }
@@ -3077,7 +2955,7 @@ dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Input *input, DW_Sect
U64 off_size = dw_size_from_format(format); U64 off_size = dw_size_from_format(format);
for (; (cursor + off_size) <= cursor_opl;) { for (; (cursor + off_size) <= cursor_opl;) {
U64 info_off = 0; U64 info_off = 0;
U64 info_off_size = str8_deserial_read_dwarf_uint(section_data, cursor, format, &info_off); U64 info_off_size = dw_str8_deserial_read_fmt_uint(section_data, cursor, format, &info_off);
cursor += info_off_size; cursor += info_off_size;
if (info_off_size == 0 || info_off == 0) { if (info_off_size == 0 || info_off == 0) {
@@ -3213,11 +3091,11 @@ dw_expr_from_data(Arena *arena, DW_Format format, U64 addr_size, String8 data)
cursor += str8_deserial_read_struct(data, cursor, &operands[0].u32); cursor += str8_deserial_read_struct(data, cursor, &operands[0].u32);
} break; } break;
case DW_ExprOp_CallRef: { case DW_ExprOp_CallRef: {
cursor += str8_deserial_read_dwarf_uint(data, cursor, format, &operands[0].u64); cursor += dw_str8_deserial_read_fmt_uint(data, cursor, format, &operands[0].u64);
} break; } break;
case DW_ExprOp_ImplicitPointer: case DW_ExprOp_ImplicitPointer:
case DW_ExprOp_GNU_ImplicitPointer: { case DW_ExprOp_GNU_ImplicitPointer: {
cursor += str8_deserial_read_dwarf_uint(data, cursor, format, &operands[0].u64); cursor += dw_str8_deserial_read_fmt_uint(data, cursor, format, &operands[0].u64);
cursor += str8_deserial_read_sleb128(data, cursor, &operands[1].s64); cursor += str8_deserial_read_sleb128(data, cursor, &operands[1].s64);
} break; } break;
case DW_ExprOp_Convert: case DW_ExprOp_Convert:
@@ -3350,13 +3228,13 @@ dw_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 = str8_deserial_read_dwarf_packed_size(data, off, &length); U64 length_size = dw_str8_deserial_read_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 = str8_deserial_read_dwarf_uint(entry_data, length_size, format, &id); U64 id_size = dw_str8_deserial_read_fmt_uint(entry_data, length_size, format, &id);
if (id_size == 0) { goto exit; } if (id_size == 0) { goto exit; }
U64 id_type = format == DW_Format_32Bit ? max_U32 : max_U64; U64 id_type = format == DW_Format_32Bit ? max_U32 : max_U64;
@@ -3377,7 +3255,7 @@ dw_parse_cie(String8 data, DW_Format format, Arch arch, DW_CIE *cie_out)
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 = str8_deserial_read_dwarf_uint(data, cursor, format, &cie_id); U64 cie_id_size = dw_str8_deserial_read_fmt_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;
@@ -3447,7 +3325,7 @@ dw_parse_fde(String8 data, DW_Format format, DW_CIE *cie, DW_FDE *fde_out)
// extract CIE pointer // extract CIE pointer
U64 cie_pointer = 0; U64 cie_pointer = 0;
U64 cie_pointer_size = str8_deserial_read_dwarf_uint(data, cursor, format, &cie_pointer); U64 cie_pointer_size = dw_str8_deserial_read_fmt_uint(data, cursor, format, &cie_pointer);
if (cie_pointer_size == 0) { goto exit; } if (cie_pointer_size == 0) { goto exit; }
cursor += cie_pointer_size; cursor += cie_pointer_size;
@@ -3487,7 +3365,7 @@ dw_parse_cfi(String8 data, U64 fde_offset, Arch arch, DW_CIE *cie_out, DW_FDE *f
if (fde_desc.type == DW_DescriptorEntryType_FDE) { if (fde_desc.type == DW_DescriptorEntryType_FDE) {
U64 cie_pointer_off = fde_desc.format == DW_Format_32Bit ? 4 : 12; U64 cie_pointer_off = fde_desc.format == DW_Format_32Bit ? 4 : 12;
U64 cie_pointer = 0; U64 cie_pointer = 0;
U64 cie_pointer_size = str8_deserial_read_dwarf_uint(data, fde_offset + cie_pointer_off, fde_desc.format, &cie_pointer); U64 cie_pointer_size = dw_str8_deserial_read_fmt_uint(data, fde_offset + cie_pointer_off, fde_desc.format, &cie_pointer);
if (cie_pointer_size) { if (cie_pointer_size) {
DW_DescriptorEntry cie_desc = {0}; DW_DescriptorEntry cie_desc = {0};
dw_parse_descriptor_entry_header(data, cie_pointer, &cie_desc); dw_parse_descriptor_entry_header(data, cie_pointer, &cie_desc);
+50 -53
View File
@@ -4,19 +4,20 @@
#ifndef DWARF_PARSE_H #ifndef DWARF_PARSE_H
#define DWARF_PARSE_H #define DWARF_PARSE_H
////////////////////////////////
//~ rjf: Raw DWARF Info Bundle
typedef struct DW_Section DW_Section; typedef struct DW_Section DW_Section;
struct DW_Section struct DW_Section
{ {
String8 name;
String8 data; String8 data;
B32 is_dwo; B32 is_dwo;
}; };
typedef struct DW_Input DW_Input; typedef struct DW_Raw DW_Raw;
struct DW_Input struct DW_Raw
{ {
DW_Section sec[DW_Section_Count]; DW_Section sec[DW_Section_Count];
DW_Section sup[DW_Section_Count];
}; };
typedef struct DW_ListUnit DW_ListUnit; typedef struct DW_ListUnit DW_ListUnit;
@@ -449,12 +450,8 @@ typedef DW_DECODE_PTR(DW_DecodePtr);
// deserial helpers // deserial helpers
internal U64 str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out); internal U64 dw_str8_deserial_read_packed_size(String8 string, U64 off, U64 *size_out);
internal U64 str8_deserial_read_dwarf_uint (String8 string, U64 off, DW_Format format, U64 *uint_out); internal U64 dw_str8_deserial_read_fmt_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);
@@ -464,7 +461,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_input(Arena *arena, DW_Input *input); internal DW_ListUnitInput dw_list_unit_input_from_raw(Arena *arena, DW_Raw *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);
@@ -480,7 +477,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_Input *input, DW_CompUnit *cu, U64 info_off, 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);
// attrib interp // attrib interp
@@ -493,56 +490,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_Input *input, DW_CompUnit *cu, 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_string (DW_Input *input, DW_Format unit_format, DW_ListUnit *str_offsets, 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_line_ptr (DW_Input *input, DW_FormKind form_kind, DW_Form form); internal String8 dw_interp_line_ptr (DW_Raw *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_Input *input, DW_CompUnit *cu, 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_LocList dw_interp_loclist (Arena *arena, 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 Rng1U64List dw_interp_rnglist (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 String8 dw_exprloc_from_attrib (DW_Input *input, DW_CompUnit *cu, DW_Attrib *attrib); internal String8 dw_exprloc_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 U128 dw_const_u128_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 U64 dw_const_u64_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 U32 dw_const_u32_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 S64 dw_const_s64_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 S32 dw_const_s32_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 B32 dw_flag_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 U64 dw_address_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_block_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_string_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 String8 dw_line_ptr_from_attrib (DW_Raw *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_Input *input, DW_CompUnit *cu, DW_Attrib *attrib); internal DW_Reference dw_ref_from_attrib (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 DW_LocList dw_loclist_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 Rng1U64List dw_rnglist_from_attrib (Arena *arena, DW_Raw *input, DW_CompUnit *cu, DW_Attrib *attrib);
internal String8 dw_exprloc_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal String8 dw_exprloc_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 U128 dw_const_u128_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 U64 dw_const_u64_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 U32 dw_const_u32_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 B32 dw_flag_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 U64 dw_address_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_block_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_string_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 String8 dw_line_ptr_from_tag_attrib_kind (DW_Raw *input, DW_CompUnit *cu, 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_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_Reference dw_ref_from_tag_attrib_kind (DW_Input *input, DW_CompUnit *cu, 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_LocList dw_loclist_from_tag_attrib_kind (Arena *arena, 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 Rng1U64List dw_rnglist_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);
// compile unit // compile unit
internal DW_CompUnit dw_cu_from_info_off(Arena *arena, DW_Input *input, DW_ListUnitInput lu_input, U64 offset, B32 relaxed); internal DW_CompUnit dw_cu_from_info_off(Arena *arena, DW_Raw *input, DW_ListUnitInput lu_input, U64 offset);
internal DW_TagTree dw_tag_tree_from_cu(Arena *arena, DW_Input *input, DW_CompUnit *cu); internal DW_TagTree dw_tag_tree_from_cu(Arena *arena, DW_Raw *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_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_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_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 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 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);
@@ -550,11 +547,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_Input *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_Raw *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_Input *input, DW_SectionKind section_kind); internal DW_PubStringsTable dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Raw *input, DW_SectionKind section_kind);
// expression // expression
+2 -3
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,4 +45,3 @@ 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
+136 -136
View File
@@ -5,69 +5,69 @@ internal U64
eh_parse_ptr(String8 frame_base, U64 off, U64 pc, EH_PtrCtx *ptr_ctx, EH_PtrEnc encoding, U64 *ptr_out) eh_parse_ptr(String8 frame_base, U64 off, U64 pc, EH_PtrCtx *ptr_ctx, EH_PtrEnc encoding, U64 *ptr_out)
{ {
U64 ptr_off = off; U64 ptr_off = off;
if (encoding == EH_PtrEnc_Omit) { if (encoding == EH_PtrEnc_Omit) {
return 0; return 0;
} }
// align read offset as needed // align read offset as needed
if (encoding == EH_PtrEnc_Aligned) { if (encoding == EH_PtrEnc_Aligned) {
ptr_off = AlignPow2(ptr_off, ptr_ctx->ptr_align); ptr_off = AlignPow2(ptr_off, ptr_ctx->ptr_align);
encoding = EH_PtrEnc_Ptr; encoding = EH_PtrEnc_Ptr;
} }
// decode pointer value // decode pointer value
U64 decode_size = 0; U64 decode_size = 0;
U64 raw_ptr_size = 0; U64 raw_ptr_size = 0;
U64 raw_ptr = 0; U64 raw_ptr = 0;
switch (encoding & EH_PtrEnc_TypeMask) { switch (encoding & EH_PtrEnc_TypeMask) {
default: { InvalidPath; } break; default: { InvalidPath; } break;
case EH_PtrEnc_Ptr : { raw_ptr_size = 8; } goto ufixed; case EH_PtrEnc_Ptr : { raw_ptr_size = 8; } goto ufixed;
case EH_PtrEnc_UData2: { raw_ptr_size = 2; } goto ufixed; case EH_PtrEnc_UData2: { raw_ptr_size = 2; } goto ufixed;
case EH_PtrEnc_UData4: { raw_ptr_size = 4; } goto ufixed; case EH_PtrEnc_UData4: { raw_ptr_size = 4; } goto ufixed;
case EH_PtrEnc_UData8: { raw_ptr_size = 8; } goto ufixed; case EH_PtrEnc_UData8: { raw_ptr_size = 8; } goto ufixed;
ufixed: { ufixed: {
decode_size += str8_deserial_read(frame_base, ptr_off, &raw_ptr, raw_ptr_size, raw_ptr_size); decode_size += str8_deserial_read(frame_base, ptr_off, &raw_ptr, raw_ptr_size, raw_ptr_size);
} break; } break;
// TODO: Signed is actually just a flag that indicates this int is negavite. // TODO: Signed is actually just a flag that indicates this int is negavite.
// There shouldn't be a read for Signed. // There shouldn't be a read for Signed.
// For instance, (EH_PtrEnc_UData2 | EH_PtrEnc_Signed) == EH_PtrEnc_SData etc. // For instance, (EH_PtrEnc_UData2 | EH_PtrEnc_Signed) == EH_PtrEnc_SData etc.
case EH_PtrEnc_Signed: { raw_ptr_size = 8; } goto sfixed; case EH_PtrEnc_Signed: { raw_ptr_size = 8; } goto sfixed;
case EH_PtrEnc_SData2: { raw_ptr_size = 2; } goto sfixed; case EH_PtrEnc_SData2: { raw_ptr_size = 2; } goto sfixed;
case EH_PtrEnc_SData4: { raw_ptr_size = 4; } goto sfixed; case EH_PtrEnc_SData4: { raw_ptr_size = 4; } goto sfixed;
case EH_PtrEnc_SData8: { raw_ptr_size = 8; } goto sfixed; case EH_PtrEnc_SData8: { raw_ptr_size = 8; } goto sfixed;
sfixed: { sfixed: {
decode_size += str8_deserial_read(frame_base, ptr_off, &raw_ptr, raw_ptr_size, raw_ptr_size); decode_size += str8_deserial_read(frame_base, ptr_off, &raw_ptr, raw_ptr_size, raw_ptr_size);
raw_ptr = extend_sign64(raw_ptr, raw_ptr_size); raw_ptr = extend_sign64(raw_ptr, raw_ptr_size);
} break; } break;
case EH_PtrEnc_ULEB128: { decode_size += str8_deserial_read_uleb128(frame_base, ptr_off, &raw_ptr); } break; case EH_PtrEnc_ULEB128: { decode_size += str8_deserial_read_uleb128(frame_base, ptr_off, &raw_ptr); } break;
case EH_PtrEnc_SLEB128: { decode_size += str8_deserial_read_sleb128(frame_base, ptr_off, (S64*)&raw_ptr); } break; case EH_PtrEnc_SLEB128: { decode_size += str8_deserial_read_sleb128(frame_base, ptr_off, (S64*)&raw_ptr); } break;
} }
// apply relative bases // apply relative bases
if (decode_size > 0) { if (decode_size > 0) {
U64 ptr = raw_ptr; U64 ptr = raw_ptr;
switch (encoding & EH_PtrEnc_ModifierMask) { switch (encoding & EH_PtrEnc_ModifierMask) {
case 0: break; case 0: break;
case EH_PtrEnc_PcRel: { ptr = pc + raw_ptr; } break; case EH_PtrEnc_PcRel: { ptr = pc + raw_ptr; } break;
case EH_PtrEnc_TextRel: { ptr = ptr_ctx->text_vaddr + raw_ptr; } break; case EH_PtrEnc_TextRel: { ptr = ptr_ctx->text_vaddr + raw_ptr; } break;
case EH_PtrEnc_DataRel: { ptr = ptr_ctx->data_vaddr + raw_ptr; } break; case EH_PtrEnc_DataRel: { ptr = ptr_ctx->data_vaddr + raw_ptr; } break;
case EH_PtrEnc_FuncRel: { case EH_PtrEnc_FuncRel: {
Assert(!"TODO: need a sample to verify implementation"); Assert(!"TODO: need a sample to verify implementation");
ptr = ptr_ctx->func_vaddr + raw_ptr; ptr = ptr_ctx->func_vaddr + raw_ptr;
} break; } break;
default: { InvalidPath; } break; default: { InvalidPath; } break;
} }
if (ptr_out) { if (ptr_out) {
*ptr_out = ptr; *ptr_out = ptr;
} }
} }
return decode_size; return decode_size;
} }
@@ -76,49 +76,49 @@ eh_parse_frame_hdr(String8 data, U64 address_size, EH_PtrCtx *ptr_ctx)
{ {
EH_FrameHdr header = {0}; EH_FrameHdr header = {0};
U64 cursor = 0; U64 cursor = 0;
U64 version_size = str8_deserial_read_struct(data, cursor, &header.version); U64 version_size = str8_deserial_read_struct(data, cursor, &header.version);
if (version_size == 0) { goto exit; } if (version_size == 0) { goto exit; }
cursor += version_size; cursor += version_size;
if (header.version == 1) { if (header.version == 1) {
U64 eh_frame_ptr_enc_size = str8_deserial_read_struct(data, cursor, &header.eh_frame_ptr_enc); U64 eh_frame_ptr_enc_size = str8_deserial_read_struct(data, cursor, &header.eh_frame_ptr_enc);
if (eh_frame_ptr_enc_size == 0) { goto exit; } if (eh_frame_ptr_enc_size == 0) { goto exit; }
cursor += eh_frame_ptr_enc_size; cursor += eh_frame_ptr_enc_size;
U64 fde_count_enc_size = str8_deserial_read_struct(data, cursor, &header.fde_count_enc); U64 fde_count_enc_size = str8_deserial_read_struct(data, cursor, &header.fde_count_enc);
if (fde_count_enc_size == 0) { goto exit; } if (fde_count_enc_size == 0) { goto exit; }
cursor += fde_count_enc_size; cursor += fde_count_enc_size;
U64 table_enc_size = str8_deserial_read_struct(data, cursor, &header.table_enc); U64 table_enc_size = str8_deserial_read_struct(data, cursor, &header.table_enc);
if (table_enc_size == 0) { goto exit; } if (table_enc_size == 0) { goto exit; }
cursor += table_enc_size; cursor += table_enc_size;
cursor += eh_parse_ptr(data, cursor, cursor, ptr_ctx, header.eh_frame_ptr_enc, &header.eh_frame_ptr); cursor += eh_parse_ptr(data, cursor, cursor, ptr_ctx, header.eh_frame_ptr_enc, &header.eh_frame_ptr);
cursor += eh_parse_ptr(data, cursor, cursor, ptr_ctx, header.fde_count_enc, &header.fde_count); cursor += eh_parse_ptr(data, cursor, cursor, ptr_ctx, header.fde_count_enc, &header.fde_count);
switch (header.table_enc & EH_PtrEnc_TypeMask) { switch (header.table_enc & EH_PtrEnc_TypeMask) {
case EH_PtrEnc_Ptr: { header.field_byte_size = address_size; } break; case EH_PtrEnc_Ptr: { header.field_byte_size = address_size; } break;
case EH_PtrEnc_ULEB128: { InvalidPath; } break; // TODO: when loading module convert these to UData8 case EH_PtrEnc_ULEB128: { InvalidPath; } break; // TODO: when loading module convert these to UData8
case EH_PtrEnc_UData2: { header.field_byte_size = 2; } break; case EH_PtrEnc_UData2: { header.field_byte_size = 2; } break;
case EH_PtrEnc_UData4: { header.field_byte_size = 4; } break; case EH_PtrEnc_UData4: { header.field_byte_size = 4; } break;
case EH_PtrEnc_UData8: { header.field_byte_size = 8; } break; case EH_PtrEnc_UData8: { header.field_byte_size = 8; } break;
case EH_PtrEnc_Signed: { header.field_byte_size = address_size; } break; case EH_PtrEnc_Signed: { header.field_byte_size = address_size; } break;
case EH_PtrEnc_SLEB128: { InvalidPath; } break; // TODO: when loading module convert these to UData8 case EH_PtrEnc_SLEB128: { InvalidPath; } break; // TODO: when loading module convert these to UData8
case EH_PtrEnc_SData2: { header.field_byte_size = 2; } break; case EH_PtrEnc_SData2: { header.field_byte_size = 2; } break;
case EH_PtrEnc_SData4: { header.field_byte_size = 4; } break; case EH_PtrEnc_SData4: { header.field_byte_size = 4; } break;
case EH_PtrEnc_SData8: { header.field_byte_size = 8; } break; case EH_PtrEnc_SData8: { header.field_byte_size = 8; } break;
default: { InvalidPath; } break; default: { InvalidPath; } break;
} }
header.entry_byte_size = header.field_byte_size * 2; header.entry_byte_size = header.field_byte_size * 2;
header.table = str8_skip(data, cursor); header.table = str8_skip(data, cursor);
AssertAlways(header.table.size == header.entry_byte_size * header.fde_count); AssertAlways(header.table.size == header.entry_byte_size * header.fde_count);
} else { } else {
Assert(0 && "unknown version"); Assert(0 && "unknown version");
} }
exit:; exit:;
return header; return header;
} }
@@ -130,9 +130,9 @@ eh_parse_aug_data(String8 aug_string, String8 aug_data, U64 pc, EH_PtrCtx *ptr_c
// On 32bit arch it is a 4-byte and on 64-bit 8-byte value. // On 32bit arch it is a 4-byte and on 64-bit 8-byte value.
// Reference: https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/ehframechpt.html // Reference: https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/ehframechpt.html
// Reference doc doesn't clarify structure for EH Data though // Reference doc doesn't clarify structure for EH Data though
U64 cursor = 0; U64 cursor = 0;
U64 aug_data_size = 0; U64 aug_data_size = 0;
EH_AugFlags aug_flags = 0; EH_AugFlags aug_flags = 0;
EH_PtrEnc lsda_encoding = EH_PtrEnc_Omit; EH_PtrEnc lsda_encoding = EH_PtrEnc_Omit;
@@ -141,30 +141,30 @@ eh_parse_aug_data(String8 aug_string, String8 aug_data, U64 pc, EH_PtrCtx *ptr_c
U64 handler_ip = 0; U64 handler_ip = 0;
if (str8_match(str8_prefix(aug_string, 1), str8_lit("z"), 0)) { if (str8_match(str8_prefix(aug_string, 1), str8_lit("z"), 0)) {
cursor = str8_deserial_read_uleb128(aug_data, cursor, &aug_data_size); cursor = str8_deserial_read_uleb128(aug_data, cursor, &aug_data_size);
for (U8 *ptr = aug_string.str+1; ptr < (aug_string.str+aug_string.size); ptr += 1) { for (U8 *ptr = aug_string.str+1; ptr < (aug_string.str+aug_string.size); ptr += 1) {
switch (*ptr) { switch (*ptr) {
case 'L': { case 'L': {
cursor += str8_deserial_read_struct(aug_data, cursor, &lsda_encoding); cursor += str8_deserial_read_struct(aug_data, cursor, &lsda_encoding);
aug_flags |= EH_AugFlag_HasLSDA; aug_flags |= EH_AugFlag_HasLSDA;
} break; } break;
case 'P': { case 'P': {
cursor += str8_deserial_read_struct(aug_data, cursor, &handler_encoding); cursor += str8_deserial_read_struct(aug_data, cursor, &handler_encoding);
cursor += eh_parse_ptr(aug_data, cursor, pc + cursor, ptr_ctx, handler_encoding, &handler_ip); cursor += eh_parse_ptr(aug_data, cursor, pc + cursor, ptr_ctx, handler_encoding, &handler_ip);
aug_flags |= EH_AugFlag_HasHandler; aug_flags |= EH_AugFlag_HasHandler;
} break; } break;
case 'R': { case 'R': {
cursor += str8_deserial_read_struct(aug_data, cursor, &addr_encoding); cursor += str8_deserial_read_struct(aug_data, cursor, &addr_encoding);
aug_flags |= EH_AugFlag_HasAddrEnc; aug_flags |= EH_AugFlag_HasAddrEnc;
} break; } break;
case 'S': { case 'S': {
aug_flags |= EH_AugFlag_SignalFrame; aug_flags |= EH_AugFlag_SignalFrame;
} break; } break;
default: { Assert(!"failed to parse augmentation string"); goto exit; } break; default: { Assert(!"failed to parse augmentation string"); goto exit; } break;
} }
} }
} }
if (aug_out) { if (aug_out) {
aug_out->handler_ip = handler_ip; aug_out->handler_ip = handler_ip;
aug_out->handler_encoding = handler_encoding; aug_out->handler_encoding = handler_encoding;
@@ -173,8 +173,8 @@ eh_parse_aug_data(String8 aug_string, String8 aug_data, U64 pc, EH_PtrCtx *ptr_c
aug_out->flags = aug_flags; aug_out->flags = aug_flags;
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;
} }
@@ -185,24 +185,24 @@ eh_parse_descriptor_entry_header(String8 data, U64 off, DW_DescriptorEntry *desc
U32 first_four_bytes = 0; U32 first_four_bytes = 0;
str8_deserial_read_struct(data, off, &first_four_bytes); str8_deserial_read_struct(data, off, &first_four_bytes);
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 = str8_deserial_read_dwarf_packed_size(data, off, &length); U64 length_size = dw_str8_deserial_read_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 = str8_deserial_read_dwarf_uint(entry_data, length_size, format, &id); U64 id_size = dw_str8_deserial_read_fmt_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;
desc_out->type = (id == 0) ? DW_DescriptorEntryType_CIE : DW_DescriptorEntryType_FDE; desc_out->type = (id == 0) ? DW_DescriptorEntryType_CIE : DW_DescriptorEntryType_FDE;
desc_out->entry_range = entry_range; desc_out->entry_range = entry_range;
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;
} }
@@ -211,17 +211,17 @@ eh_parse_cie(String8 data, DW_Format format, Arch arch, U64 pc, EH_PtrCtx *ptr_c
{ {
B32 is_parsed = 0; B32 is_parsed = 0;
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 = str8_deserial_read_dwarf_uint(data, cursor, format, &cie_id); U64 cie_id_size = dw_str8_deserial_read_fmt_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;
U8 version = 0; U8 version = 0;
U64 version_size = str8_deserial_read_struct(data, cursor, &version); U64 version_size = str8_deserial_read_struct(data, cursor, &version);
if (version_size == 0) { goto exit; } if (version_size == 0) { goto exit; }
cursor += version_size; cursor += version_size;
String8 aug_string = {0}; String8 aug_string = {0};
String8 aug_data = {0}; String8 aug_data = {0};
EH_Augmentation aug = {0}; EH_Augmentation aug = {0};
@@ -232,33 +232,33 @@ eh_parse_cie(String8 data, DW_Format format, Arch arch, U64 pc, EH_PtrCtx *ptr_c
U64 aug_string_size = str8_deserial_read_cstr(data, cursor, &aug_string); U64 aug_string_size = str8_deserial_read_cstr(data, cursor, &aug_string);
if (aug_string_size == 0) { goto exit; } if (aug_string_size == 0) { goto exit; }
cursor += aug_string_size; cursor += aug_string_size;
U64 eh_data = 0; U64 eh_data = 0;
if (str8_match(aug_string, str8_lit("eh"), 0)) { if (str8_match(aug_string, str8_lit("eh"), 0)) {
U64 arch_byte_size = byte_size_from_arch(arch); U64 arch_byte_size = byte_size_from_arch(arch);
cursor += str8_deserial_read(data, cursor, &eh_data, arch_byte_size, arch_byte_size); cursor += str8_deserial_read(data, cursor, &eh_data, arch_byte_size, arch_byte_size);
} }
U64 code_align_factor_size = str8_deserial_read_uleb128(data, cursor, &code_align_factor); U64 code_align_factor_size = str8_deserial_read_uleb128(data, cursor, &code_align_factor);
if (code_align_factor_size == 0) { goto exit; } if (code_align_factor_size == 0) { goto exit; }
cursor += code_align_factor_size; cursor += code_align_factor_size;
U64 data_align_factor_size = str8_deserial_read_sleb128(data, cursor, &data_align_factor); U64 data_align_factor_size = str8_deserial_read_sleb128(data, cursor, &data_align_factor);
if (data_align_factor_size == 0) { goto exit; } if (data_align_factor_size == 0) { goto exit; }
cursor += data_align_factor_size; cursor += data_align_factor_size;
ret_addr_reg = 0; ret_addr_reg = 0;
U64 ret_addr_reg_size = str8_deserial_read(data, cursor, &ret_addr_reg, sizeof(U8), sizeof(U8)); U64 ret_addr_reg_size = str8_deserial_read(data, cursor, &ret_addr_reg, sizeof(U8), sizeof(U8));
if (ret_addr_reg_size == 0) { goto exit; } if (ret_addr_reg_size == 0) { goto exit; }
cursor += ret_addr_reg_size; cursor += ret_addr_reg_size;
U64 aug_data_size = eh_parse_aug_data(aug_string, str8_skip(data, cursor), pc + cursor, ptr_ctx, &aug); U64 aug_data_size = eh_parse_aug_data(aug_string, str8_skip(data, cursor), pc + cursor, ptr_ctx, &aug);
aug_data = str8_substr(data, r1u64(cursor, cursor + aug.size)); aug_data = str8_substr(data, r1u64(cursor, cursor + aug.size));
cursor += aug_data_size; cursor += aug_data_size;
} else { } else {
Assert(0 && "unexpected version"); Assert(0 && "unexpected version");
} }
cie_out->insts = str8_skip(data, cursor); cie_out->insts = str8_skip(data, cursor);
cie_out->aug_string = aug_string; cie_out->aug_string = aug_string;
cie_out->aug_data = aug_data; cie_out->aug_data = aug_data;
@@ -269,11 +269,11 @@ eh_parse_cie(String8 data, DW_Format format, Arch arch, U64 pc, EH_PtrCtx *ptr_c
cie_out->version = version; cie_out->version = version;
cie_out->address_size = byte_size_from_arch(arch); cie_out->address_size = byte_size_from_arch(arch);
cie_out->segment_selector_size = 0; cie_out->segment_selector_size = 0;
cie_out->ext[EH_CIE_Ext_LSDAEnc] = EH_PtrEnc_Omit; cie_out->ext[EH_CIE_Ext_LSDAEnc] = EH_PtrEnc_Omit;
cie_out->ext[EH_CIE_Ext_AddrEnc] = EH_PtrEnc_Omit; cie_out->ext[EH_CIE_Ext_AddrEnc] = EH_PtrEnc_Omit;
cie_out->ext[EH_CIE_Ext_HandlerEnc] = EH_PtrEnc_Omit; cie_out->ext[EH_CIE_Ext_HandlerEnc] = EH_PtrEnc_Omit;
if (aug.flags & EH_AugFlag_HasLSDA) { if (aug.flags & EH_AugFlag_HasLSDA) {
cie_out->ext[EH_CIE_Ext_LSDAEnc] = aug.lsda_encoding; cie_out->ext[EH_CIE_Ext_LSDAEnc] = aug.lsda_encoding;
} }
@@ -284,9 +284,9 @@ eh_parse_cie(String8 data, DW_Format format, Arch arch, U64 pc, EH_PtrCtx *ptr_c
cie_out->ext[EH_CIE_Ext_HandlerEnc] = aug.handler_encoding; cie_out->ext[EH_CIE_Ext_HandlerEnc] = aug.handler_encoding;
cie_out->ext[EH_CIE_Ext_HandlerIp ] = aug.handler_ip; cie_out->ext[EH_CIE_Ext_HandlerIp ] = aug.handler_ip;
} }
is_parsed = 1; is_parsed = 1;
exit:; exit:;
return is_parsed; return is_parsed;
} }
@@ -295,7 +295,7 @@ eh_parse_fde(String8 data, DW_Format format, U64 pc, DW_CIE *cie, EH_PtrCtx *ptr
{ {
B32 is_parsed = 0; B32 is_parsed = 0;
U64 cursor = format == DW_Format_32Bit ? 8 : 20; U64 cursor = format == DW_Format_32Bit ? 8 : 20;
U64 pc_begin = 0; U64 pc_begin = 0;
U64 pc_delta = 0; U64 pc_delta = 0;
EH_PtrEnc addr_enc = cie->ext[EH_CIE_Ext_AddrEnc]; EH_PtrEnc addr_enc = cie->ext[EH_CIE_Ext_AddrEnc];
@@ -303,21 +303,21 @@ eh_parse_fde(String8 data, DW_Format format, U64 pc, DW_CIE *cie, EH_PtrCtx *ptr
U64 pc_begin_size = eh_parse_ptr(data, cursor, pc + cursor, ptr_ctx, addr_enc, &pc_begin); U64 pc_begin_size = eh_parse_ptr(data, cursor, pc + cursor, ptr_ctx, addr_enc, &pc_begin);
if (pc_begin_size == 0) { goto exit; } if (pc_begin_size == 0) { goto exit; }
cursor += pc_begin_size; cursor += pc_begin_size;
U64 pc_delta_size = eh_parse_ptr(data, cursor, pc + cursor, ptr_ctx, addr_enc & EH_PtrEnc_TypeMask, &pc_delta); U64 pc_delta_size = eh_parse_ptr(data, cursor, pc + cursor, ptr_ctx, addr_enc & EH_PtrEnc_TypeMask, &pc_delta);
if (pc_delta_size == 0) { goto exit; } if (pc_delta_size == 0) { goto exit; }
cursor += pc_delta_size; cursor += pc_delta_size;
} }
if (cursor + cie->aug_data.size > data.size) { goto exit; } if (cursor + cie->aug_data.size > data.size) { goto exit; }
cursor += cie->aug_data.size; cursor += cie->aug_data.size;
fde_out->format = format; fde_out->format = format;
fde_out->pc_range = rng_1u64(pc_begin, pc_begin + pc_delta); fde_out->pc_range = rng_1u64(pc_begin, pc_begin + pc_delta);
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;
} }
@@ -326,7 +326,7 @@ eh_find_nearest_fde(EH_FrameHdr header, EH_PtrCtx *ptr_ctx, U64 pc)
{ {
U64 fde_addr = max_U64; U64 fde_addr = max_U64;
U64 fde_idx = max_U64; U64 fde_idx = max_U64;
if (header.version == 1) { if (header.version == 1) {
if (header.fde_count > 0) { if (header.fde_count > 0) {
U64 first = 0; U64 first = 0;
@@ -339,7 +339,7 @@ eh_find_nearest_fde(EH_FrameHdr header, EH_PtrCtx *ptr_ctx, U64 pc)
if (first > pc) { if (first > pc) {
goto exit; goto exit;
} }
U64 last_off = header.table.size - header.entry_byte_size; U64 last_off = header.table.size - header.entry_byte_size;
U64 last = 0; U64 last = 0;
U64 last_size = eh_parse_ptr(header.table, last_off, ptr_ctx->pc_vaddr + last_off, ptr_ctx, header.table_enc, &last); U64 last_size = eh_parse_ptr(header.table, last_off, ptr_ctx->pc_vaddr + last_off, ptr_ctx, header.table_enc, &last);
@@ -348,7 +348,7 @@ eh_find_nearest_fde(EH_FrameHdr header, EH_PtrCtx *ptr_ctx, U64 pc)
fde_idx = header.fde_count - 1; fde_idx = header.fde_count - 1;
goto exit; goto exit;
} }
U64 l = 0; U64 l = 0;
U64 r = header.fde_count - 1; U64 r = header.fde_count - 1;
while (l <= r) { while (l <= r) {
@@ -366,12 +366,12 @@ eh_find_nearest_fde(EH_FrameHdr header, EH_PtrCtx *ptr_ctx, U64 pc)
goto exit; goto exit;
} }
} }
fde_idx = l > 0 ? l-1 : 0; fde_idx = l > 0 ? l-1 : 0;
} }
} }
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);
@@ -390,7 +390,7 @@ internal String8
eh_frame_hdr_from_call_frame_info(Arena *arena, U64 fde_count, U64 *fde_offsets, DW_FDE *fde) eh_frame_hdr_from_call_frame_info(Arena *arena, U64 fde_count, U64 *fde_offsets, DW_FDE *fde)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
// make .eh_frame_hdr // make .eh_frame_hdr
String8List srl = {0}; String8List srl = {0};
str8_serial_begin(scratch.arena, &srl); str8_serial_begin(scratch.arena, &srl);
@@ -400,14 +400,14 @@ eh_frame_hdr_from_call_frame_info(Arena *arena, U64 fde_count, U64 *fde_offsets,
str8_serial_push_u8(scratch.arena, &srl, EH_PtrEnc_UData8); // table encoding str8_serial_push_u8(scratch.arena, &srl, EH_PtrEnc_UData8); // table encoding
str8_serial_push_u64(scratch.arena, &srl, fde_count); // fde_count str8_serial_push_u64(scratch.arena, &srl, fde_count); // fde_count
String8 header = str8_serial_end(scratch.arena, &srl); String8 header = str8_serial_end(scratch.arena, &srl);
// alloc buffer for output // alloc buffer for output
U64 buffer_size = header.size + sizeof(EH_FrameHdrEntry) * fde_count; U64 buffer_size = header.size + sizeof(EH_FrameHdrEntry) * fde_count;
U8 *buffer = push_array(arena, U8, buffer_size); U8 *buffer = push_array(arena, U8, buffer_size);
// copy header // copy header
MemoryCopyStr8(buffer, header); MemoryCopyStr8(buffer, header);
// write the table // write the table
EH_FrameHdrEntry *table = (EH_FrameHdrEntry *)(buffer + header.size); EH_FrameHdrEntry *table = (EH_FrameHdrEntry *)(buffer + header.size);
for EachIndex(fde_idx, fde_count) { for EachIndex(fde_idx, fde_count) {
@@ -415,7 +415,7 @@ eh_frame_hdr_from_call_frame_info(Arena *arena, U64 fde_count, U64 *fde_offsets,
table[fde_idx].fde_offset = fde_offsets[fde_idx]; table[fde_idx].fde_offset = fde_offsets[fde_idx];
} }
radsort(table, fde_count, eh_frame_hdr_entry_sort); radsort(table, fde_count, eh_frame_hdr_entry_sort);
String8 eh_frame_hdr = str8(buffer, buffer_size); String8 eh_frame_hdr = str8(buffer, buffer_size);
scratch_end(scratch); scratch_end(scratch);
return eh_frame_hdr; return eh_frame_hdr;
@@ -432,16 +432,16 @@ internal String8
eh_string_from_ptr_enc_type(EH_PtrEnc type) eh_string_from_ptr_enc_type(EH_PtrEnc type)
{ {
switch (type) { switch (type) {
case EH_PtrEnc_Ptr: return str8_lit("Ptr"); case EH_PtrEnc_Ptr: return str8_lit("Ptr");
case EH_PtrEnc_ULEB128: return str8_lit("ULEB128"); case EH_PtrEnc_ULEB128: return str8_lit("ULEB128");
case EH_PtrEnc_UData2: return str8_lit("UData2"); case EH_PtrEnc_UData2: return str8_lit("UData2");
case EH_PtrEnc_UData4: return str8_lit("UData4"); case EH_PtrEnc_UData4: return str8_lit("UData4");
case EH_PtrEnc_UData8: return str8_lit("UData8"); case EH_PtrEnc_UData8: return str8_lit("UData8");
case EH_PtrEnc_Signed: return str8_lit("Signed"); case EH_PtrEnc_Signed: return str8_lit("Signed");
case EH_PtrEnc_SLEB128: return str8_lit("SLEB128"); case EH_PtrEnc_SLEB128: return str8_lit("SLEB128");
case EH_PtrEnc_SData2: return str8_lit("SData2"); case EH_PtrEnc_SData2: return str8_lit("SData2");
case EH_PtrEnc_SData4: return str8_lit("SData4"); case EH_PtrEnc_SData4: return str8_lit("SData4");
case EH_PtrEnc_SData8: return str8_lit("SData8"); case EH_PtrEnc_SData8: return str8_lit("SData8");
} }
return str8_zero(); return str8_zero();
} }
@@ -450,11 +450,11 @@ internal String8
eh_string_from_ptr_enc_modifier(EH_PtrEnc modifier) eh_string_from_ptr_enc_modifier(EH_PtrEnc modifier)
{ {
switch (modifier) { switch (modifier) {
case EH_PtrEnc_PcRel: return str8_lit("PcRel"); case EH_PtrEnc_PcRel: return str8_lit("PcRel");
case EH_PtrEnc_TextRel: return str8_lit("TextRel"); case EH_PtrEnc_TextRel: return str8_lit("TextRel");
case EH_PtrEnc_DataRel: return str8_lit("DataRel"); case EH_PtrEnc_DataRel: return str8_lit("DataRel");
case EH_PtrEnc_FuncRel: return str8_lit("FuncRel"); case EH_PtrEnc_FuncRel: return str8_lit("FuncRel");
case EH_PtrEnc_Aligned: return str8_lit("Aligned"); case EH_PtrEnc_Aligned: return str8_lit("Aligned");
} }
return str8_zero(); return str8_zero();
} }
+3 -4
View File
@@ -20,7 +20,7 @@ enum
EH_PtrEnc_SData2 = 0x0A, // Signed 16-bit value EH_PtrEnc_SData2 = 0x0A, // Signed 16-bit value
EH_PtrEnc_SData4 = 0x0B, // Signed 32-bit value EH_PtrEnc_SData4 = 0x0B, // Signed 32-bit value
EH_PtrEnc_SData8 = 0x0C, // Signed 64-bit value EH_PtrEnc_SData8 = 0x0C, // Signed 64-bit value
EH_PtrEnc_TypeMask = 0x0F, EH_PtrEnc_TypeMask = 0x0F,
}; };
@@ -31,7 +31,7 @@ enum
EH_PtrEnc_DataRel = 0x30, // Value is relative to the .got or .eh_frame_hdr section. EH_PtrEnc_DataRel = 0x30, // Value is relative to the .got or .eh_frame_hdr section.
EH_PtrEnc_FuncRel = 0x40, // Value is relative to the function. EH_PtrEnc_FuncRel = 0x40, // Value is relative to the function.
EH_PtrEnc_Aligned = 0x50, // Value is aligned to an address unit sized boundary. EH_PtrEnc_Aligned = 0x50, // Value is aligned to an address unit sized boundary.
EH_PtrEnc_ModifierMask = 0x70, EH_PtrEnc_ModifierMask = 0x70,
}; };
@@ -104,7 +104,7 @@ typedef struct EH_DecodePtrCtx
EH_PtrEnc addr_enc; EH_PtrEnc addr_enc;
EH_PtrCtx *ptr_ctx; EH_PtrCtx *ptr_ctx;
} EH_DecodePtrCtx; } EH_DecodePtrCtx;
//////////////////////////////// ////////////////////////////////
internal U64 eh_parse_ptr(String8 frame_base, U64 off, U64 pc, EH_PtrCtx *ptr_ctx, EH_PtrEnc encoding, U64 *ptr_out); internal U64 eh_parse_ptr(String8 frame_base, U64 off, U64 pc, EH_PtrCtx *ptr_ctx, EH_PtrEnc encoding, U64 *ptr_out);
@@ -123,4 +123,3 @@ 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
+6 -6
View File
@@ -1099,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_Input dw = {0}; DW_Raw 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};
@@ -1115,7 +1115,7 @@ rb_thread_entry_point(void *p)
{ {
elf = elf_bin_from_data(arena, f->data); elf = elf_bin_from_data(arena, f->data);
arch = arch_from_elf_machine(elf.hdr.e_machine); arch = arch_from_elf_machine(elf.hdr.e_machine);
for EachIndex(sect_idx, elf.hdr.e_shnum) for EachIndex(sect_idx, elf.hdr.e_shnum)
{ {
ELF_Shdr64 *shdr = &elf.shdrs.v[sect_idx]; ELF_Shdr64 *shdr = &elf.shdrs.v[sect_idx];
@@ -1124,7 +1124,7 @@ rb_thread_entry_point(void *p)
{ {
eh_frame_hdr = str8_substr(f->data, r1u64(shdr->sh_offset, shdr->sh_offset + shdr->sh_size)); eh_frame_hdr = str8_substr(f->data, r1u64(shdr->sh_offset, shdr->sh_offset + shdr->sh_size));
eh_frame_hdr_vaddr = shdr->sh_addr; eh_frame_hdr_vaddr = shdr->sh_addr;
} }
else if(str8_match(name, str8_lit(".eh_frame"), 0)) else if(str8_match(name, str8_lit(".eh_frame"), 0))
{ {
@@ -1141,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_input_from_coff_section_table(arena, f->data, string_table, section_count, section_table); dw = dw_raw_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_input_from_elf_bin(arena, f->data, &elf); dw = dw_raw_from_elf_bin(arena, f->data, &elf);
} }
} }
} }
@@ -1241,7 +1241,7 @@ rb_thread_entry_point(void *p)
} }
} }
} }
if(eh_dump_subset_flags) if(eh_dump_subset_flags)
{ {
if(lane_idx() == 0) if(lane_idx() == 0)
+3 -3
View File
@@ -4064,7 +4064,7 @@ pe_print(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Op
} }
if (opts & RD_Option_Dwarf) { if (opts & RD_Option_Dwarf) {
DW_Input dwarf_input = dw_input_from_coff_section_table(scratch.arena, raw_data, raw_string_table, file_header->section_count, sections); DW_Raw dwarf_input = dw_raw_from_coff_section_table(scratch.arena, raw_data, raw_string_table, file_header->section_count, sections);
dw_format(arena, out, indent, opts, &dwarf_input, arch, ExecutableImageKind_CoffPe); dw_format(arena, out, indent, opts, &dwarf_input, arch, ExecutableImageKind_CoffPe);
} }
@@ -4080,12 +4080,12 @@ elf_print_dwarf_expressions(Arena *arena, String8List *out, String8 indent, Stri
ELF_Bin bin = elf_bin_from_data(raw_data); ELF_Bin bin = elf_bin_from_data(raw_data);
Arch arch = arch_from_elf_machine(bin.hdr.e_machine); Arch arch = arch_from_elf_machine(bin.hdr.e_machine);
DW_Input dwarf_input = dw_input_from_elf_bin(scratch.arena, raw_data, &bin); DW_Raw dwarf_input = dw_raw_from_elf_bin(scratch.arena, raw_data, &bin);
ELF_Class elf_class = bin.hdr.e_ident[ELF_Identifier_Class]; ELF_Class elf_class = bin.hdr.e_ident[ELF_Identifier_Class];
ExecutableImageKind image_type = elf_class == ELF_Class_32 ? ExecutableImageKind_Elf32 : elf_class == ELF_Class_64 ? ExecutableImageKind_Elf64 : ELF_Class_None; ExecutableImageKind image_type = elf_class == ELF_Class_32 ? ExecutableImageKind_Elf32 : elf_class == ELF_Class_64 ? ExecutableImageKind_Elf64 : ELF_Class_None;
B32 relaxed = 1; B32 relaxed = 1;
Rng1U64List cu_ranges = dw_unit_ranges_from_data(scratch.arena, dwarf_input.sec[DW_Section_Info].data); Rng1U64List cu_ranges = dw_unit_ranges_from_data(scratch.arena, dwarf_input.sec[DW_Section_Info].data);
DW_ListUnitInput lu_input = dw_list_unit_input_from_input(scratch.arena, &dwarf_input); DW_ListUnitInput lu_input = dw_list_unit_input_from_raw(scratch.arena, &dwarf_input);
if (bin.hdr.e_type == ELF_Type_Exec || bin.hdr.e_type == ELF_Type_Dyn) { if (bin.hdr.e_type == ELF_Type_Exec || bin.hdr.e_type == ELF_Type_Dyn) {
U64 cu_idx = 0; U64 cu_idx = 0;
+19 -23
View File
@@ -136,7 +136,7 @@ d2r_type_from_offset(D2R_TypeTable *type_table, U64 info_off)
} }
internal RDIM_Type * internal RDIM_Type *
d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind) d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind)
{ {
RDIM_Type *type = type_table->builtin_types[RDI_TypeKind_Void]; RDIM_Type *type = type_table->builtin_types[RDI_TypeKind_Void];
@@ -165,7 +165,7 @@ d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu
} }
internal Rng1U64List internal Rng1U64List
d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag) d2r_range_list_from_tag(Arena *arena, DW_Raw *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag)
{ {
// collect non-contiguous range // collect non-contiguous range
Rng1U64List raw_ranges = dw_rnglist_from_tag_attrib_kind(arena, input, cu, tag, DW_AttribKind_Ranges); Rng1U64List raw_ranges = dw_rnglist_from_tag_attrib_kind(arena, input, cu, tag, DW_AttribKind_Ranges);
@@ -223,7 +223,7 @@ d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 imag
} }
internal RDIM_Type ** 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) d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Raw *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
@@ -892,7 +892,7 @@ d2r_push_relational_op(Arena *arena, D2R_ValueTypeStack *stack, RDIM_EvalBytecod
internal RDIM_EvalBytecode internal RDIM_EvalBytecode
d2r_bytecode_from_expression(Arena *arena, d2r_bytecode_from_expression(Arena *arena,
DW_Input *input, DW_Raw *input,
U64 image_base, U64 image_base,
U64 address_size, U64 address_size,
Arch arch, Arch arch,
@@ -1438,7 +1438,7 @@ d2r_bytecode_from_expression(Arena *arena,
} }
internal RDIM_Location * 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) 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)
{ {
RDIM_Location *loc = 0; RDIM_Location *loc = 0;
if (expr.size) { if (expr.size) {
@@ -1459,7 +1459,7 @@ d2r_locset_from_attrib(Arena *arena,
RDIM_ScopeChunkList *scopes, RDIM_ScopeChunkList *scopes,
RDIM_Scope *curr_scope, RDIM_Scope *curr_scope,
RDIM_LocationChunkList *locations, RDIM_LocationChunkList *locations,
DW_Input *input, DW_Raw *input,
DW_CompUnit *cu, DW_CompUnit *cu,
U64 image_base, U64 image_base,
Arch arch, Arch arch,
@@ -1507,7 +1507,7 @@ d2r_var_locset_from_tag(Arena *arena,
RDIM_ScopeChunkList *scopes, RDIM_ScopeChunkList *scopes,
RDIM_Scope *curr_scope, RDIM_Scope *curr_scope,
RDIM_LocationChunkList *locations, RDIM_LocationChunkList *locations,
DW_Input *input, DW_Raw *input,
DW_CompUnit *cu, DW_CompUnit *cu,
U64 image_base, U64 image_base,
Arch arch, Arch arch,
@@ -1687,7 +1687,7 @@ d2r_is_tag_converted(DW_TagNode *tag_node)
} }
internal RDIM_Type * 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) 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)
{ {
RDIM_Type *type = type_table->builtin_types[RDI_TypeKind_Void]; RDIM_Type *type = type_table->builtin_types[RDI_TypeKind_Void];
@@ -1730,7 +1730,7 @@ d2r_find_or_convert_type(Arena *arena, D2R_TypeTable *type_table, DW_Input *inpu
} }
internal void 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) 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)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
for(D2R_TagIter *it = d2r_tag_iter_init(scratch.arena, root); for(D2R_TagIter *it = d2r_tag_iter_init(scratch.arena, root);
@@ -2146,7 +2146,7 @@ d2r_convert_types(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_C
internal void internal void
d2r_convert_udts(Arena *arena, d2r_convert_udts(Arena *arena,
D2R_TypeTable *type_table, D2R_TypeTable *type_table,
DW_Input *input, DW_Raw *input,
DW_CompUnit *cu, DW_CompUnit *cu,
DW_Language cu_lang, DW_Language cu_lang,
U64 arch_addr_size, U64 arch_addr_size,
@@ -2245,7 +2245,7 @@ d2r_convert_udts(Arena *arena,
} }
internal void internal void
d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, U64 image_base, Arch arch, DW_TagNode *root) 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)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
for(D2R_TagIter *it = d2r_tag_iter_init(scratch.arena, root); for(D2R_TagIter *it = d2r_tag_iter_init(scratch.arena, root);
@@ -2543,7 +2543,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
// //
Arch arch = Arch_Null; Arch arch = Arch_Null;
U64 image_base = 0; U64 image_base = 0;
DW_Input input = {0}; DW_Raw input = {0};
PathStyle path_style = PathStyle_Null; PathStyle path_style = PathStyle_Null;
switch(params->exe_kind) switch(params->exe_kind)
{ {
@@ -2557,7 +2557,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
arch = pe.arch; arch = pe.arch;
image_base = pe.image_base; image_base = pe.image_base;
binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, params->exe_data, string_table, pe.section_count, section_table); binary_sections = c2r_rdi_binary_sections_from_coff_sections(arena, params->exe_data, string_table, pe.section_count, section_table);
input = dw_input_from_coff_section_table(scratch.arena, params->exe_data, string_table, pe.section_count, section_table); input = dw_raw_from_coff_section_table(scratch.arena, params->exe_data, string_table, pe.section_count, section_table);
path_style = PathStyle_WindowsAbsolute; path_style = PathStyle_WindowsAbsolute;
}break; }break;
case ExecutableImageKind_Elf32: case ExecutableImageKind_Elf32:
@@ -2567,7 +2567,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
arch = arch_from_elf_machine(bin.hdr.e_machine); arch = arch_from_elf_machine(bin.hdr.e_machine);
image_base = (bin.hdr.e_type == ELF_Type_Dyn ? 0 : elf_base_addr_from_bin(&bin)); image_base = (bin.hdr.e_type == ELF_Type_Dyn ? 0 : elf_base_addr_from_bin(&bin));
binary_sections = e2r_rdi_binary_sections_from_elf_section_table(arena, params->dbg_data, &bin, bin.shdrs); binary_sections = e2r_rdi_binary_sections_from_elf_section_table(arena, params->dbg_data, &bin, bin.shdrs);
input = dw_input_from_elf_bin(scratch.arena, params->dbg_data, &bin); input = dw_raw_from_elf_bin(scratch.arena, params->dbg_data, &bin);
path_style = PathStyle_UnixAbsolute; path_style = PathStyle_UnixAbsolute;
}break; }break;
} }
@@ -2593,7 +2593,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
} }
//////////////////////////// ////////////////////////////
//- rjf: unpack input image info //- rjf: convert top-level-info
// //
{ {
// rjf: base arch -> rdi // rjf: base arch -> rdi
@@ -2655,7 +2655,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
//- rjf: read unit data length //- rjf: read unit data length
U64 unit_length = 0; U64 unit_length = 0;
U64 unit_length_size = str8_deserial_read_dwarf_packed_size(unit_data, unit_cursor, &unit_length); U64 unit_length_size = dw_str8_deserial_read_packed_size(unit_data, unit_cursor, &unit_length);
B32 unit_length_good = (unit_length_size != 0); B32 unit_length_good = (unit_length_size != 0);
unit_cursor += unit_length_size; unit_cursor += unit_length_size;
DW_Format unit_format = DW_FormatFromSize(unit_length); DW_Format unit_format = DW_FormatFromSize(unit_length);
@@ -2684,7 +2684,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
U8 unit_segment_selector_size = 0; U8 unit_segment_selector_size = 0;
B32 unit_good = 0; B32 unit_good = 0;
{ {
U64 unit_info_off_size = str8_deserial_read_dwarf_uint(unit_data, unit_cursor, unit_format, &unit_info_off); U64 unit_info_off_size = dw_str8_deserial_read_fmt_uint(unit_data, unit_cursor, unit_format, &unit_info_off);
unit_cursor += unit_info_off_size; unit_cursor += unit_info_off_size;
U64 unit_address_size_size = str8_deserial_read_struct(unit_data, unit_cursor, &unit_address_size); U64 unit_address_size_size = str8_deserial_read_struct(unit_data, unit_cursor, &unit_address_size);
unit_cursor += unit_address_size_size; unit_cursor += unit_address_size_size;
@@ -2756,7 +2756,7 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
DW_ListUnitInput lu_input = {0}; DW_ListUnitInput lu_input = {0};
ProfScope("parse list of comp units") ProfScope("parse list of comp units")
{ {
lu_input = dw_list_unit_input_from_input(scratch.arena, &input); lu_input = dw_list_unit_input_from_raw(scratch.arena, &input);
} }
//////////////////////////// ////////////////////////////
@@ -2775,14 +2775,10 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
DW_CompUnit *cu_arr = 0; DW_CompUnit *cu_arr = 0;
ProfScope("parse comp unit headers") ProfScope("parse comp unit headers")
{ {
// TODO(rjf): parse should always be relaxed. any verification checks we do
// should just be logged via log_info(...), and then the caller of this
// converter can collect those & display as necessary.
B32 is_parse_relaxed = 1;
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, is_parse_relaxed); cu_arr[cu_idx] = dw_cu_from_info_off(scratch.arena, &input, lu_input, cu_ranges.v[cu_idx].min);
} }
} }
+11 -11
View File
@@ -113,9 +113,9 @@ 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_Input *input, DW_CompUnit *cu, DW_Tag tag, DW_AttribKind kind); internal RDIM_Type * d2r_type_from_attrib(D2R_TypeTable *type_table, DW_Raw *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_Raw *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_Raw *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out);
//////////////////////////////// ////////////////////////////////
//~ RDIM Bytecode Helpers //~ RDIM Bytecode Helpers
@@ -141,10 +141,10 @@ 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_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_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_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_Raw *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_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_Raw *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_Raw *input, DW_CompUnit *cu, U64 image_base, Arch arch, DW_Tag tag);
//////////////////////////////// ////////////////////////////////
//~ rjf: Compilation Unit / Scope Conversion Helpers //~ rjf: Compilation Unit / Scope Conversion Helpers
@@ -167,11 +167,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_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 arch_addr_size, DW_Tag tag, DW_AttribKind kind); 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_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_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_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_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, 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