From cc00fe7825657c2c7ecddb146e2ecb8a92a1e24d Mon Sep 17 00:00:00 2001 From: Nikita Smith Date: Sun, 22 Feb 2026 20:18:26 -0800 Subject: [PATCH] minor fixes and improvements for DWARF dumper --- src/dwarf/dwarf.h | 2 +- src/dwarf/dwarf_dump.c | 48 +++++++++++++++++++++--------------------- src/radbin/radbin.c | 45 +++++++++++++++++++++++++++++---------- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/src/dwarf/dwarf.h b/src/dwarf/dwarf.h index 272f269c..09b87e27 100644 --- a/src/dwarf/dwarf.h +++ b/src/dwarf/dwarf.h @@ -158,7 +158,7 @@ typedef enum DW_InlKindEnum X(FixedAdvancePc, 0x09) \ X(SetPrologueEnd, 0x0A) \ X(SetEpilogueBegin, 0x0B) \ - X(SetIsa, 0x0C) \ + X(SetIsa, 0x0C) typedef U8 DW_StdOpcode; typedef enum DW_StdOpcodeEnum diff --git a/src/dwarf/dwarf_dump.c b/src/dwarf/dwarf_dump.c index de095b6a..b228f6df 100644 --- a/src/dwarf/dwarf_dump.c +++ b/src/dwarf/dwarf_dump.c @@ -960,18 +960,18 @@ DW_PRINTER(dw_print_line) { String8List opcode_length_strings = numeric_str8_list_from_data(unit_temp.arena, 16, str8(vm->header.opcode_lens, vm->header.num_opcode_lens), 1); String8 opcode_lengths_string = str8_list_join(arena, &opcode_length_strings, &(StringJoin){.sep = str8_lit(", ")}); - dw_printf("version: %u\n", vm->header.version ); - dw_printf("line_table_size: %I64u\n", vm->header.unit_length ); - dw_printf("address_size: %u\n", vm->header.address_size ); - dw_printf("segment_selector_size: %u\n", vm->header.segment_selector_size); - dw_printf("header_length: %I64u\n", vm->header.header_length ); - dw_printf("min_instruction_length: %u\n", vm->header.min_inst_len ); - dw_printf("max_ops_for_instruction: %u\n", vm->header.max_ops_for_inst ); - dw_printf("default_is_stmt: %u\n", vm->header.default_is_stmt ); - dw_printf("line_base: %d\n", vm->header.line_base ); - dw_printf("line_range: %u\n", vm->header.line_range ); - dw_printf("opcode_base: %u\n", vm->header.opcode_base ); - dw_printf("opcode_lengths: { %S }\n", opcode_lengths_string ); + dw_printf("version: %u\n", vm->header.version ); + dw_printf("line_table_size: %I64u\n", vm->header.unit_length ); + dw_printf("address_size: %u\n", vm->header.address_size ); + dw_printf("segment_selector_size: %u\n", vm->header.segment_selector_size); + dw_printf("header_length: %I64u\n", vm->header.header_length ); + dw_printf("min_instruction_length: %u\n", vm->header.min_inst_len ); + dw_printf("max_ops_for_instruction: %u\n", vm->header.max_ops_for_inst ); + dw_printf("default_is_stmt: %u\n", vm->header.default_is_stmt ); + dw_printf("line_base: %d\n", vm->header.line_base ); + dw_printf("line_range: %u\n", vm->header.line_range ); + dw_printf("opcode_base: %u\n", vm->header.opcode_base ); + dw_printf("opcode_lengths: { %S }\n", opcode_lengths_string ); } dw_unindent(); dw_printf("}\n"); @@ -983,11 +983,9 @@ DW_PRINTER(dw_print_line) { dw_printf("// %-4s %-30s\n", "No.", "Name"); dw_printf("// ---- ------------------------------\n"); - String8 cu_comp_dir = dw_string_from_tag_attrib_kind(input, cu, cu->tag, DW_AttribKind_CompDir); - dw_printf("{ %-4I64u %-30S }\n", 0, cu_comp_dir); for EachIndex(dir_idx, vm->header.dir_table.count) { - dw_printf("{ %-4I64u %-30S }\n", dir_idx+1, vm->header.dir_table.v[dir_idx]); + dw_printf("{ %-4I64u %-30S }\n", dir_idx, vm->header.dir_table.v[dir_idx]); } } dw_unindent(); @@ -998,7 +996,7 @@ DW_PRINTER(dw_print_line) dw_printf("{\n"); dw_indent(); { - dw_printf("// %-4s %-8s %-8s %-33s %-8s %-20s\n", "No.", "Dir No.", "Time", "MD5", "Size", "Name"); + dw_printf("// %-4s %-8s %-8s %-33s %-8s %-20s\n", "No.", "Dir No.", "Time", "MD5", "Size", "Path"); dw_printf("// ---- -------- -------- --------------------------------- -------- --------------------\n"); for EachIndex(file_idx, vm->header.file_table.count) { @@ -1006,11 +1004,11 @@ DW_PRINTER(dw_print_line) dw_printf("{ %-4I64u %-8I64u %-8I64u %016I64x-%016I64x %-8I64u %-20S }\n", file_idx, file->dir_idx, - file->modify_time, - file->md5_digest.u64[1], - file->md5_digest.u64[0], - file->file_size, - file->file_name); + file->time_stamp, + file->md5.u64[1], + file->md5.u64[0], + file->size, + file->path); } } dw_unindent(); @@ -1038,8 +1036,10 @@ DW_PRINTER(dw_print_line) str8_list_pushf(opcode_temp.arena, &opcode_fmt, "%08I64x:", global_opcode_off); // push opcode id - String8 opcode_str = dw_string_from_std_opcode(opcode_temp.arena, vm->opcode); - str8_list_push(arena, &opcode_fmt, opcode_str); + if (vm->opcode != 0) { + String8 opcode_str = dw_string_from_std_opcode(opcode_temp.arena, vm->opcode); + str8_list_pushf(arena, &opcode_fmt, "%-11S:", opcode_str); + } // print operands switch(vm->opcode) @@ -1103,7 +1103,7 @@ DW_PRINTER(dw_print_line) }break; case DW_StdOpcode_ExtendedOpcode: { - str8_list_push(opcode_temp.arena, &opcode_fmt, dw_string_from_ext_opcode(opcode_temp.arena, vm->ext_opcode)); + str8_list_pushf(opcode_temp.arena, &opcode_fmt, "%S*", dw_string_from_ext_opcode(opcode_temp.arena, vm->ext_opcode)); //str8_list_pushf(opcode_temp.arena, &opcode_fmt, "length: %u", length); switch(vm->ext_opcode) { diff --git a/src/radbin/radbin.c b/src/radbin/radbin.c index 372834f8..99bcd7be 100644 --- a/src/radbin/radbin.c +++ b/src/radbin/radbin.c @@ -341,6 +341,21 @@ rb_thread_entry_point(void *p) } scratch_end(scratch); } + + if(file_format == RB_FileFormat_COFF_OBJ || file_format == RB_FileFormat_COFF_BigOBJ) + { + Temp scratch = scratch_begin(&arena, 1); + COFF_FileHeaderInfo coff_obj = coff_file_header_info_from_data(file_data); + String8 string_table = str8_substr(file_data, coff_obj.string_table_range); + U64 section_count = coff_obj.section_count_no_null; + COFF_SectionHeader *section_table = (COFF_SectionHeader *)str8_substr(file_data, coff_obj.section_table_range).str; + if(dw_is_dwarf_present_coff_section_table(string_table, section_count, section_table)) + { + log_infof("DWARF data detected in %S (%S)\n", n->string, rb_file_format_display_name_table[file_format]); + file_format_flags |= RB_FileFormatFlag_HasDWARF; + } + scratch_end(scratch); + } ////////////////////////// //- rjf: ELF => check if contains DWARF @@ -1101,22 +1116,30 @@ rb_thread_entry_point(void *p) lane_sync(); //- rjf: unpack file parses - Arch arch = Arch_Null; - PE_BinInfo pe = {0}; - ELF_Bin elf = {0}; - DW_Input dw = {0}; - U64 eh_frame_hdr_vaddr = 0; - U64 eh_frame_vaddr = 0; - String8 eh_frame_hdr = {0}; - String8 eh_frame = {0}; + Arch arch = Arch_Null; + PE_BinInfo pe = {0}; + ELF_Bin elf = {0}; + COFF_FileHeaderInfo coff_obj = {0}; + DW_Input dw = {0}; + U64 eh_frame_hdr_vaddr = 0; + U64 eh_frame_vaddr = 0; + String8 eh_frame_hdr = {0}; + String8 eh_frame = {0}; { if(f->format == RB_FileFormat_PE) { - pe = pe_bin_info_from_data(arena, f->data); + pe = pe_bin_info_from_data(arena, f->data); arch = pe.arch; } - if(f->format == RB_FileFormat_ELF32 || - f->format == RB_FileFormat_ELF64) + else if(f->format == RB_FileFormat_COFF_OBJ || f->format == RB_FileFormat_COFF_BigOBJ) + { + coff_obj = coff_file_header_info_from_data(f->data); + String8 string_table = str8_substr(f->data, coff_obj.string_table_range); + U64 section_count = coff_obj.section_count_no_null; + COFF_SectionHeader *section_table = (COFF_SectionHeader *)str8_substr(f->data, coff_obj.section_table_range).str; + dw = dw_input_from_coff_section_table(arena, f->data, string_table, section_count, section_table); + } + else if(f->format == RB_FileFormat_ELF32 || f->format == RB_FileFormat_ELF64) { elf = elf_bin_from_data(arena, f->data); arch = arch_from_elf_machine(elf.hdr.e_machine);