mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-04 21:08:40 +00:00
dumper for Dwarf
This commit is contained in:
+2831
-413
File diff suppressed because it is too large
Load Diff
+153
-74
@@ -9,31 +9,63 @@
|
||||
|
||||
#define rd_printf(f, ...) str8_list_pushf(arena, out, "%S" f, indent, __VA_ARGS__)
|
||||
#define rd_newline() str8_list_pushf(arena, out, "");
|
||||
#define rd_errorf(f, ...) rd_printf("ERROR: "f, __VA_ARGS__)
|
||||
#define rd_errorf(f, ...) rd_stderr("ERROR: "f, __VA_ARGS__)
|
||||
#define rd_warningf(f, ...) rd_stderr("WARNING: "f, __VA_ARGS__)
|
||||
#define rd_indent() do { if (indent.size + RD_INDENT_WIDTH <= RD_INDENT_MAX) { indent.size += RD_INDENT_WIDTH; } else { Assert(!"indent overflow"); } } while (0)
|
||||
#define rd_unindent() do { if (indent.size >= RD_INDENT_WIDTH) { indent.size -= RD_INDENT_WIDTH; } else { Assert(!"unbalanced indent"); } } while (0)
|
||||
#define rd_unindent() do { if (indent.size >= RD_INDENT_WIDTH) { indent.size -= RD_INDENT_WIDTH; } else { Assert(!"unbalanced indent"); } } while (0)
|
||||
|
||||
typedef U64 RD_Option;
|
||||
enum RD_OptionEnum
|
||||
{
|
||||
RD_Option_Help = (1 << 0),
|
||||
RD_Option_Version = (1 << 1),
|
||||
RD_Option_Headers = (1 << 2),
|
||||
RD_Option_Sections = (1 << 3),
|
||||
RD_Option_Debug = (1 << 4),
|
||||
RD_Option_Imports = (1 << 5),
|
||||
RD_Option_Exports = (1 << 6),
|
||||
RD_Option_Disasm = (1 << 7),
|
||||
RD_Option_Rawdata = (1 << 8),
|
||||
RD_Option_Tls = (1 << 9),
|
||||
RD_Option_Codeview = (1 << 10),
|
||||
RD_Option_Symbols = (1 << 11),
|
||||
RD_Option_Relocs = (1 << 12),
|
||||
RD_Option_Exceptions = (1 << 13),
|
||||
RD_Option_LoadConfig = (1 << 14),
|
||||
RD_Option_Resources = (1 << 15),
|
||||
RD_Option_LongNames = (1 << 16),
|
||||
};
|
||||
|
||||
#define RD_Option_Help (1ull << 0)
|
||||
#define RD_Option_Version (1ull << 1)
|
||||
#define RD_Option_Headers (1ull << 2)
|
||||
#define RD_Option_Sections (1ull << 3)
|
||||
#define RD_Option_Debug (1ull << 4)
|
||||
#define RD_Option_Imports (1ull << 5)
|
||||
#define RD_Option_Exports (1ull << 6)
|
||||
#define RD_Option_Disasm (1ull << 7)
|
||||
#define RD_Option_Rawdata (1ull << 8)
|
||||
#define RD_Option_Tls (1ull << 9)
|
||||
#define RD_Option_Codeview (1ull << 10)
|
||||
#define RD_Option_Symbols (1ull << 11)
|
||||
#define RD_Option_Relocs (1ull << 12)
|
||||
#define RD_Option_Exceptions (1ull << 13)
|
||||
#define RD_Option_LoadConfig (1ull << 14)
|
||||
#define RD_Option_Resources (1ull << 15)
|
||||
#define RD_Option_LongNames (1ull << 16)
|
||||
// DWARF
|
||||
#define RD_Option_DebugInfo (1ull << 17)
|
||||
#define RD_Option_DebugAbbrev (1ull << 18)
|
||||
#define RD_Option_DebugLine (1ull << 19)
|
||||
#define RD_Option_DebugStr (1ull << 20)
|
||||
#define RD_Option_DebugLoc (1ull << 21)
|
||||
#define RD_Option_DebugRanges (1ull << 22)
|
||||
#define RD_Option_DebugARanges (1ull << 23)
|
||||
#define RD_Option_DebugAddr (1ull << 24)
|
||||
#define RD_Option_DebugLocLists (1ull << 25)
|
||||
#define RD_Option_DebugRngLists (1ull << 26)
|
||||
#define RD_Option_DebugPubNames (1ull << 27)
|
||||
#define RD_Option_DebugPubTypes (1ull << 28)
|
||||
#define RD_Option_DebugLineStr (1ull << 29)
|
||||
#define RD_Option_DebugStrOffsets (1ull << 30)
|
||||
#define RD_Option_Dwarf \
|
||||
(RD_Option_DebugInfo | \
|
||||
RD_Option_DebugAbbrev | \
|
||||
RD_Option_DebugLine | \
|
||||
RD_Option_DebugStr | \
|
||||
RD_Option_DebugLoc | \
|
||||
RD_Option_DebugRanges | \
|
||||
RD_Option_DebugARanges | \
|
||||
RD_Option_DebugAddr | \
|
||||
RD_Option_DebugLocLists | \
|
||||
RD_Option_DebugRngLists | \
|
||||
RD_Option_DebugPubNames | \
|
||||
RD_Option_DebugPubTypes | \
|
||||
RD_Option_DebugLineStr | \
|
||||
RD_Option_DebugStrOffsets)
|
||||
#define RD_Option_RelaxDwarfParser (1ull << 31ull)
|
||||
// RDI
|
||||
#define RD_Option_NoRdi (1ull << 32ull)
|
||||
|
||||
typedef struct RD_Marker
|
||||
{
|
||||
@@ -66,77 +98,124 @@ typedef struct RD_DisasmResult
|
||||
U64 size;
|
||||
} RD_DisasmResult;
|
||||
|
||||
typedef struct RD_Section
|
||||
{
|
||||
String8 name;
|
||||
String8 raw_data;
|
||||
} RD_Section;
|
||||
|
||||
typedef struct RD_SectionArray
|
||||
{
|
||||
U64 count;
|
||||
RD_Section *v;
|
||||
} RD_SectionArray;
|
||||
|
||||
typedef struct RD_Line
|
||||
{
|
||||
String8 file_path;
|
||||
U32 line_num;
|
||||
} RD_Line;
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
//- Markers
|
||||
// raddump
|
||||
|
||||
internal B32 rd_is_pe(String8 raw_data);
|
||||
internal void rd_format_preamble(Arena *arena, String8List *out, String8 indent, String8 input_path, String8 raw_data);
|
||||
|
||||
// Markers
|
||||
|
||||
internal RD_MarkerArray * rd_section_markers_from_coff_symbol_table(Arena *arena, String8 raw_data, U64 string_table_off, U64 section_count, COFF_Symbol32Array symbols);
|
||||
|
||||
//- Disasm
|
||||
// Sections
|
||||
|
||||
internal RD_SectionArray rd_sections_from_coff_section_table(Arena *arnea, String8 raw_image, U64 string_table_off, U64 section_count, COFF_SectionHeader *sections);
|
||||
|
||||
// Disasm
|
||||
|
||||
internal RD_DisasmResult rd_disasm_next_instruction(Arena *arena, Arch arch, U64 addr, String8 raw_code);
|
||||
internal void rd_format_disasm(Arena *arena, String8List *out, String8 indent, Arch arch, U64 image_base, U64 sect_off, U64 marker_count, RD_Marker *markers, String8 raw_code);
|
||||
internal void rd_print_disasm (Arena *arena, String8List *out, String8 indent, Arch arch, U64 image_base, U64 sect_off, U64 marker_count, RD_Marker *markers, String8 raw_code);
|
||||
|
||||
//- Raw Data
|
||||
// Raw Data
|
||||
|
||||
internal String8 rd_format_hex_array(Arena *arena, U8 *ptr, U64 size);
|
||||
internal void rd_format_raw_data(Arena *arena, String8List *out, String8 indent, U64 bytes_per_row, U64 marker_count, RD_Marker *markers, String8 raw_data);
|
||||
internal void rd_print_raw_data (Arena *arena, String8List *out, String8 indent, U64 bytes_per_row, U64 marker_count, RD_Marker *markers, String8 raw_data);
|
||||
|
||||
//- CodeView
|
||||
// DWARF
|
||||
|
||||
internal void cv_format_binary_annots(Arena *arena, String8List *out, String8 indent, CV_Arch arch, String8 raw_data);
|
||||
internal void cv_format_lvar_addr_range(Arena *arena, String8List *out, String8 indent, CV_LvarAddrRange range);
|
||||
internal void cv_format_lvar_addr_gap(Arena *arena, String8List *out, String8 indent, String8 raw_data);
|
||||
internal void cv_format_lvar_attr(Arena *arena, String8List *out, String8 indent, CV_LocalVarAttr attr);
|
||||
internal void cv_format_symbol(Arena *arena, String8List *out, String8 indent, CV_Arch arch, U32 type, String8 raw_symbol);
|
||||
internal U64 cv_format_leaf(Arena *arena, String8List *out, String8 indent, CV_LeafKind kind, String8 raw_leaf);
|
||||
internal void cv_format_debug_t(Arena *arena, String8List *out, String8 indent, CV_DebugT debug_t);
|
||||
internal void cv_format_symbols_c13(Arena *arena, String8List *out, String8 indent, String8 raw_data);
|
||||
internal void cv_format_lines_c13(Arena *arena, String8List *out, String8 indent, String8 raw_lines);
|
||||
internal void cv_format_file_checksums(Arena *arena, String8List *out, String8 indent, String8 raw_chksums);
|
||||
internal void cv_format_string_table(Arena *arena, String8List *out, String8 indent, String8 raw_strtab);
|
||||
internal void cv_format_inlinee_lines(Arena *arena, String8List *out, String8 indent, String8 raw_data);
|
||||
internal void cv_format_symbols_section(Arena *arena, String8List *out, String8 indent, String8 raw_ss);
|
||||
internal String8List dw_string_list_from_expression (Arena *arena, String8 raw_data, U64 address_size, Arch arch, DW_Version ver, DW_Ext ext, B32 is_dwarf64);
|
||||
internal String8 dw_format_expression_single_line(Arena *arena, String8 raw_data, U64 address_size, Arch arch, DW_Version ver, DW_Ext ext, B32 is_dwarf64);
|
||||
internal String8 dw_format_eh_ptr_enc (Arena *arena, DW_EhPtrEnc enc);
|
||||
internal void dw_print_cfi_program (Arena *arena, String8List *out, String8 indent, String8 raw_data, DW_CIEUnpacked *cie, DW_EhPtrCtx *ptr_ctx, Arch arch, DW_Version ver, DW_Ext ext, B32 is_dwarf64);
|
||||
|
||||
//- COFF
|
||||
internal void dw_print_eh_frame (Arena *arena, String8List *out, String8 indent, String8 raw_eh_frame, Arch arch, DW_Version ver, DW_Ext ext, DW_EhPtrCtx *ptr_ctx);
|
||||
internal void dw_print_debug_info (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections, Arch arch, ImageType image_type, B32 relaxed);
|
||||
internal void dw_print_debug_abbrev (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections);
|
||||
internal void dw_print_debug_line (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections, B32 relaxed);
|
||||
internal void dw_print_debug_str (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections);
|
||||
internal void dw_print_debug_loc (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections, Arch arch, ImageType image_type, B32 relaxed);
|
||||
internal void dw_print_debug_ranges (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections, Arch arch, ImageType image_type, B32 relaxed);
|
||||
internal void dw_print_debug_aranges (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections);
|
||||
internal void dw_print_debug_addr (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections);
|
||||
internal void dw_print_debug_loclists (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections, Rng1U64Array segment_vranges, Arch arch);
|
||||
internal void dw_print_debug_rnglists (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections, Rng1U64Array segment_vranges);
|
||||
internal void dw_print_debug_pubnames (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections);
|
||||
internal void dw_print_debug_pubtypes (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections);
|
||||
internal void dw_print_debug_line_str (Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections);
|
||||
internal void dw_print_debug_str_offsets(Arena *arena, String8List *out, String8 indent, DW_SectionArray *sections);
|
||||
|
||||
internal void coff_format_archive_member_header(Arena *arena, String8List *out, String8 indent, COFF_ArchiveMemberHeader header, String8 long_names);
|
||||
internal void coff_format_section_table(Arena *arena, String8List *out, String8 indent, String8 raw_data, U64 string_table_off, COFF_Symbol32Array symbols, U64 sect_count, COFF_SectionHeader *sect_headers);
|
||||
internal void coff_disasm_sections(Arena *arena, String8List *out, String8 indent, String8 raw_data, COFF_MachineType machine, U64 image_base, B32 is_obj, RD_MarkerArray *section_markers, U64 section_count, COFF_SectionHeader *sections);
|
||||
internal void coff_raw_data_sections(Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_obj, RD_MarkerArray *section_markers, U64 section_count, COFF_SectionHeader *sections);
|
||||
internal void coff_format_relocs(Arena *arena, String8List *out, String8 indent, String8 raw_data, U64 string_table_off, COFF_MachineType machine, U64 sect_count, COFF_SectionHeader *sect_headers, COFF_Symbol32Array symbols);
|
||||
internal void coff_format_symbol_table(Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_big_obj, U64 string_table_off, COFF_Symbol32Array symbols);
|
||||
internal void coff_format_big_obj_header(Arena *arena, String8List *out, String8 indent, COFF_HeaderBigObj *header);
|
||||
internal void coff_format_header(Arena *arena, String8List *out, String8 indent, COFF_Header *header);
|
||||
internal void coff_format_import(Arena *arena, String8List *out, String8 indent, COFF_ImportHeader *header);
|
||||
internal void coff_format_big_obj(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts);
|
||||
internal void coff_format_obj(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts);
|
||||
internal void coff_format_archive(Arena *arena, String8List *out, String8 indent, String8 raw_archive, RD_Option opts);
|
||||
// CodeView
|
||||
|
||||
//- MSVC CRT
|
||||
internal void cv_print_binary_annots (Arena *arena, String8List *out, String8 indent, CV_Arch arch, String8 raw_data);
|
||||
internal void cv_print_lvar_addr_range(Arena *arena, String8List *out, String8 indent, CV_LvarAddrRange range);
|
||||
internal void cv_print_lvar_addr_gap (Arena *arena, String8List *out, String8 indent, String8 raw_data);
|
||||
internal void cv_print_lvar_attr (Arena *arena, String8List *out, String8 indent, CV_LocalVarAttr attr);
|
||||
internal void cv_print_symbol (Arena *arena, String8List *out, String8 indent, CV_Arch arch, CV_TypeIndex min_itype, CV_SymKind type, String8 raw_symbol);
|
||||
internal U64 cv_print_leaf (Arena *arena, String8List *out, String8 indent, CV_TypeIndex min_itype, CV_LeafKind kind, String8 raw_leaf);
|
||||
internal void cv_print_debug_t (Arena *arena, String8List *out, String8 indent, CV_DebugT debug_t);
|
||||
internal void cv_print_symbols_c13 (Arena *arena, String8List *out, String8 indent, CV_Arch arch, String8 raw_data);
|
||||
internal void cv_print_lines_c13 (Arena *arena, String8List *out, String8 indent, String8 raw_lines);
|
||||
internal void cv_print_file_checksums (Arena *arena, String8List *out, String8 indent, String8 raw_chksums);
|
||||
internal void cv_print_string_table (Arena *arena, String8List *out, String8 indent, String8 raw_strtab);
|
||||
internal void cv_print_inlinee_lines (Arena *arena, String8List *out, String8 indent, String8 raw_data);
|
||||
internal void cv_print_symbols_section(Arena *arena, String8List *out, String8 indent, CV_Arch arch, String8 raw_ss);
|
||||
|
||||
internal void mscrt_format_eh_handler_type32(Arena *arena, String8List *out, String8 indent, MSCRT_EhHandlerType32 *handler);
|
||||
// COFF
|
||||
|
||||
//- PE
|
||||
internal void coff_print_archive_member_header(Arena *arena, String8List *out, String8 indent, COFF_ArchiveMemberHeader header, String8 long_names);
|
||||
internal void coff_print_seciton_table (Arena *arena, String8List *out, String8 indent, String8 raw_data, U64 string_table_off, COFF_Symbol32Array symbols, U64 sect_count, COFF_SectionHeader *sect_headers);
|
||||
internal void coff_disasm_sections (Arena *arena, String8List *out, String8 indent, String8 raw_data, COFF_MachineType machine, U64 image_base, B32 is_obj, RD_MarkerArray *section_markers, U64 section_count, COFF_SectionHeader *sections);
|
||||
internal void coff_raw_data_sections (Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_obj, RD_MarkerArray *section_markers, U64 section_count, COFF_SectionHeader *sections);
|
||||
internal void coff_print_relocs (Arena *arena, String8List *out, String8 indent, String8 raw_data, U64 string_table_off, COFF_MachineType machine, U64 sect_count, COFF_SectionHeader *sect_headers, COFF_Symbol32Array symbols);
|
||||
internal void coff_print_symbol_table (Arena *arena, String8List *out, String8 indent, String8 raw_data, B32 is_big_obj, U64 string_table_off, COFF_Symbol32Array symbols);
|
||||
internal void coff_print_big_obj_header (Arena *arena, String8List *out, String8 indent, COFF_HeaderBigObj *header);
|
||||
internal void coff_print_header (Arena *arena, String8List *out, String8 indent, COFF_Header *header);
|
||||
internal void coff_print_import (Arena *arena, String8List *out, String8 indent, COFF_ImportHeader *header);
|
||||
internal void coff_print_big_obj (Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts);
|
||||
internal void coff_print_obj (Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts);
|
||||
internal void coff_print_archive (Arena *arena, String8List *out, String8 indent, String8 raw_archive, RD_Option opts);
|
||||
|
||||
internal void pe_format_data_directory_ranges(Arena *arena, String8List *out, String8 indent, U64 count, PE_DataDirectory *dirs);
|
||||
internal void pe_format_optional_header32(Arena *arena, String8List *out, String8 indent, PE_OptionalHeader32 *opt_header, PE_DataDirectory *dirs);
|
||||
internal void pe_format_optional_header32plus(Arena *arena, String8List *out, String8 indent, PE_OptionalHeader32Plus *opt_header, PE_DataDirectory *dirs);
|
||||
internal void pe_format_load_config32(Arena *arena, String8List *out, String8 indent, PE_LoadConfig32 *lc);
|
||||
internal void pe_format_load_config64(Arena *arena, String8List *out, String8 indent, PE_LoadConfig64 *lc);
|
||||
internal void pe_format_tls(Arena *arena, String8List *out, String8 indent, PE_ParsedTLS tls);
|
||||
internal void pe_format_debug_directory(Arena *arena, String8List *out, String8 indent, String8 raw_data, String8 raw_dir);
|
||||
internal void pe_format_export_table(Arena *arena, String8List *out, String8 indent, PE_ParsedExportTable exptab);
|
||||
internal void pe_format_static_import_table(Arena *arena, String8List *out, String8 indent, U64 image_base, PE_ParsedStaticImportTable imptab);
|
||||
internal void pe_format_delay_import_table(Arena *arena, String8List *out, String8 indent, U64 image_base, PE_ParsedDelayImportTable imptab);
|
||||
internal void pe_format_resources(Arena *arena, String8List *out, String8 indent, PE_ResourceDir *root);
|
||||
internal void pe_format_exceptions_x8664(Arena *arena, String8List *out, String8 indent, U64 section_count, COFF_SectionHeader *sections, String8 raw_data, Rng1U64 except_frange);
|
||||
internal void pe_format_exceptions(Arena *arena, String8List *out, String8 indent, COFF_MachineType machine, U64 section_count, COFF_SectionHeader *sections, String8 raw_data, Rng1U64 except_frange);
|
||||
internal void pe_format_base_relocs(Arena *arena, String8List *out, String8 indent, COFF_MachineType machine, U64 image_base, U64 section_count, COFF_SectionHeader *sections, String8 raw_data, Rng1U64 base_reloc_franges);
|
||||
internal void pe_format(Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts);
|
||||
// MSVC CRT
|
||||
|
||||
////////////////////////////////
|
||||
internal void mscrt_print_eh_handler_type32(Arena *arena, String8List *out, String8 indent, RDI_Parsed *rdi, MSCRT_EhHandlerType32 *handler);
|
||||
|
||||
internal void format_preamble(Arena *arena, String8List *out, String8 indent, String8 input_path, String8 raw_data);
|
||||
// PE
|
||||
|
||||
internal void pe_print_data_directory_ranges(Arena *arena, String8List *out, String8 indent, U64 count, PE_DataDirectory *dirs);
|
||||
internal void pe_print_optional_header32 (Arena *arena, String8List *out, String8 indent, PE_OptionalHeader32 *opt_header, PE_DataDirectory *dirs);
|
||||
internal void pe_print_optional_header32plus(Arena *arena, String8List *out, String8 indent, PE_OptionalHeader32Plus *opt_header, PE_DataDirectory *dirs);
|
||||
internal void pe_print_load_config32 (Arena *arena, String8List *out, String8 indent, PE_LoadConfig32 *lc);
|
||||
internal void pe_print_load_config64 (Arena *arena, String8List *out, String8 indent, PE_LoadConfig64 *lc);
|
||||
internal void pe_print_tls (Arena *arena, String8List *out, String8 indent, PE_ParsedTLS tls);
|
||||
internal void pe_print_debug_diretory (Arena *arena, String8List *out, String8 indent, String8 raw_data, String8 raw_dir);
|
||||
internal void pe_print_export_table (Arena *arena, String8List *out, String8 indent, PE_ParsedExportTable exptab);
|
||||
internal void pe_print_static_import_table (Arena *arena, String8List *out, String8 indent, U64 image_base, PE_ParsedStaticImportTable imptab);
|
||||
internal void pe_print_delay_import_table (Arena *arena, String8List *out, String8 indent, U64 image_base, PE_ParsedDelayImportTable imptab);
|
||||
internal void pe_print_resources (Arena *arena, String8List *out, String8 indent, PE_ResourceDir *root);
|
||||
internal void pe_print_exceptions_x8664 (Arena *arena, String8List *out, String8 indent, U64 section_count, COFF_SectionHeader *sections, String8 raw_data, Rng1U64 except_frange, RDI_Parsed *rdi);
|
||||
internal void pe_print_exceptions (Arena *arena, String8List *out, String8 indent, COFF_MachineType machine, U64 section_count, COFF_SectionHeader *sections, String8 raw_data, Rng1U64 except_frange, RDI_Parsed *rdi);
|
||||
internal void pe_print_base_relocs (Arena *arena, String8List *out, String8 indent, COFF_MachineType machine, U64 image_base, U64 section_count, COFF_SectionHeader *sections, String8 raw_data, Rng1U64 base_reloc_franges, RDI_Parsed *rdi);
|
||||
internal void pe_print (Arena *arena, String8List *out, String8 indent, String8 raw_data, RD_Option opts, RDI_Parsed *rdi);
|
||||
|
||||
#endif // RADDUMP_H
|
||||
|
||||
|
||||
+122
-52
@@ -6,16 +6,25 @@
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#include "linker/base_ext/base_blake3.h"
|
||||
#include "linker/base_ext/base_blake3.c"
|
||||
#include "third_party/xxHash/xxhash.c"
|
||||
#include "third_party/xxHash/xxhash.h"
|
||||
#include "third_party/radsort/radsort.h"
|
||||
#include "third_party/md5/md5.c"
|
||||
#include "third_party/md5/md5.h"
|
||||
#include "third_party/zydis/zydis.h"
|
||||
#include "third_party/zydis/zydis.c"
|
||||
#include "third_party/rad_lzb_simple/rad_lzb_simple.h"
|
||||
#include "third_party/rad_lzb_simple/rad_lzb_simple.c"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#include "base/base_inc.h"
|
||||
#include "os/os_inc.h"
|
||||
#include "async/async.h"
|
||||
#include "rdi_format/rdi_format_local.h"
|
||||
#include "rdi_make/rdi_make_local.h"
|
||||
#include "path/path.h"
|
||||
#include "coff/coff.h"
|
||||
#include "coff/coff_enum.h"
|
||||
@@ -28,9 +37,19 @@
|
||||
#include "msf/msf.h"
|
||||
#include "msf/msf_parse.h"
|
||||
#include "pdb/pdb.h"
|
||||
#include "pdb/pdb_parse.h"
|
||||
#include "rdi_from_pdb/rdi_from_pdb.h"
|
||||
#include "dwarf/dwarf.h"
|
||||
#include "dwarf/dwarf_parse.h"
|
||||
#include "dwarf/dwarf_expr.h"
|
||||
#include "dwarf/dwarf_unwind.h"
|
||||
#include "dwarf/dwarf_enum.h"
|
||||
|
||||
#include "base/base_inc.c"
|
||||
#include "os/os_inc.c"
|
||||
#include "async/async.c"
|
||||
#include "rdi_format/rdi_format_local.c"
|
||||
#include "rdi_make/rdi_make_local.c"
|
||||
#include "path/path.c"
|
||||
#include "coff/coff.c"
|
||||
#include "coff/coff_enum.c"
|
||||
@@ -43,9 +62,16 @@
|
||||
#include "msf/msf.c"
|
||||
#include "msf/msf_parse.c"
|
||||
#include "pdb/pdb.c"
|
||||
#include "pdb/pdb_parse.c"
|
||||
#include "rdi_from_pdb/rdi_from_pdb.c"
|
||||
#include "dwarf/dwarf.c"
|
||||
#include "dwarf/dwarf_parse.c"
|
||||
#include "dwarf/dwarf_expr.c"
|
||||
#include "dwarf/dwarf_unwind.c"
|
||||
#include "dwarf/dwarf_enum.c"
|
||||
|
||||
#include "linker/base_ext/base_core.h"
|
||||
#include "linker/base_ext/base_core.c"
|
||||
#include "linker/base_ext/base_inc.h"
|
||||
#include "linker/base_ext/base_inc.c"
|
||||
#include "linker/path_ext/path.h"
|
||||
#include "linker/path_ext/path.c"
|
||||
#include "linker/thread_pool/thread_pool.h"
|
||||
@@ -66,29 +92,66 @@ global read_only struct
|
||||
char *name;
|
||||
char *help;
|
||||
} g_rd_dump_option_map[] = {
|
||||
{ RD_Option_Help, "help", "Print help and exit" },
|
||||
{ RD_Option_Version, "v", "Print version and exit" },
|
||||
{ RD_Option_Headers, "headers", "Dump DOS header, file header, optional header, and/or archive header" },
|
||||
{ RD_Option_Sections, "sections", "Dump section headers as table" },
|
||||
{ RD_Option_Rawdata, "rawdata", "Dump raw section data" },
|
||||
{ RD_Option_Codeview, "cv", "Dump CodeView" },
|
||||
{ RD_Option_Disasm, "disasm", "Disassemble code sections" },
|
||||
{ RD_Option_Symbols, "symbols", "Dump COFF symbol table" },
|
||||
{ RD_Option_Relocs, "relocs", "Dump relocations" },
|
||||
{ RD_Option_Exceptions, "exceptions", "Dump exceptions" },
|
||||
{ RD_Option_Tls, "tls", "Dump Thread Local Storage directory" },
|
||||
{ RD_Option_Debug, "debug", "Dump debug directory" },
|
||||
{ RD_Option_Imports, "imports", "Dump import table" },
|
||||
{ RD_Option_Exports, "exports", "Dump export table" },
|
||||
{ RD_Option_LoadConfig, "loadconfig", "Dump load config" },
|
||||
{ RD_Option_Resources, "resources", "Dump resource directory" },
|
||||
{ RD_Option_LongNames, "longnames", "Dump archive long names" },
|
||||
{ RD_Option_Help, "help", "Print help and exit" },
|
||||
{ RD_Option_Version, "version", "Print version and exit" },
|
||||
{ RD_Option_Headers, "headers", "Dump DOS header, file header, optional header, and/or archive header" },
|
||||
{ RD_Option_Sections, "sections", "Dump section headers as table" },
|
||||
{ RD_Option_Rawdata, "rawdata", "Dump raw section data" },
|
||||
{ RD_Option_Codeview, "cv", "Dump CodeView" },
|
||||
{ RD_Option_Disasm, "disasm", "Disassemble code sections" },
|
||||
{ RD_Option_Symbols, "symtab", "Dump COFF symbol table" },
|
||||
{ RD_Option_Relocs, "relocs", "Dump relocations" },
|
||||
{ RD_Option_Exceptions, "exceptions", "Dump exceptions" },
|
||||
{ RD_Option_Tls, "tls", "Dump Thread Local Storage directory" },
|
||||
{ RD_Option_Debug, "debug", "Dump debug directory" },
|
||||
{ RD_Option_Imports, "imports", "Dump import table" },
|
||||
{ RD_Option_Exports, "exports", "Dump export table" },
|
||||
{ RD_Option_LoadConfig, "loadconfig", "Dump load config" },
|
||||
{ RD_Option_Resources, "resources", "Dump resource directory" },
|
||||
{ RD_Option_LongNames, "longnames", "Dump archive long names" },
|
||||
{ RD_Option_DebugInfo, "debug_info", "Dump .debug_info" },
|
||||
{ RD_Option_DebugAbbrev, "debug_abbrev", "Dump .debug_abbrev" },
|
||||
{ RD_Option_DebugLine, "debug_line", "Dump .debug_line" },
|
||||
{ RD_Option_DebugStr, "debug_str", "Dump .debug_str" },
|
||||
{ RD_Option_DebugLoc, "debug_loc", "Dump .debug_loc" },
|
||||
{ RD_Option_DebugRanges, "debug_ranges", "Dump .debug_ranges" },
|
||||
{ RD_Option_DebugARanges, "debug_aranges", "Dump .debug_aranges" },
|
||||
{ RD_Option_DebugAddr, "debug_addr", "Dump .debug_addr" },
|
||||
{ RD_Option_DebugLocLists, "debug_loclists", "Dump .debug_loclists" },
|
||||
{ RD_Option_DebugRngLists, "debug_rnglists", "Dump .debug_rnglists" },
|
||||
{ RD_Option_DebugPubNames, "debug_pubnames", "Dump .debug_pubnames" },
|
||||
{ RD_Option_DebugPubTypes, "debug_pubtypes", "Dump .debug_putypes" },
|
||||
{ RD_Option_DebugLineStr, "debug_linestr", "Dump .debug_linestr" },
|
||||
{ RD_Option_DebugStrOffsets, "debug_stroffsets", "Dump .debug_stroffsets" },
|
||||
{ RD_Option_Dwarf, "dwarf", "Dump all DWARF sections" },
|
||||
{ RD_Option_RelaxDwarfParser, "relax_dwarf_parser", "Relaxes version requirement on attribute and form encodings" },
|
||||
{ RD_Option_NoRdi, "nordi", "Don't load RAD Debug Info" },
|
||||
|
||||
{ RD_Option_Help, "h", "Alias for -help" },
|
||||
{ RD_Option_Version, "v", "Alias for -version" },
|
||||
{ RD_Option_Sections, "s", "Alias for -sections" },
|
||||
{ RD_Option_Exceptions, "e", "Alias for -exceptions" },
|
||||
{ RD_Option_Imports, "i", "Alias for -imports" },
|
||||
{ RD_Option_Exports, "x", "Alias for -exports" },
|
||||
{ RD_Option_LoadConfig, "l", "Alias for -loadconifg" },
|
||||
{ RD_Option_Resources, "c", "Alias for -resources" },
|
||||
{ RD_Option_Relocs, "r", "Alias for -relocs" },
|
||||
};
|
||||
|
||||
internal void
|
||||
entry_point(CmdLine *cmdline)
|
||||
{
|
||||
Temp scratch = scratch_begin(0,0);
|
||||
Arena *arena = arena_alloc();
|
||||
|
||||
// make indent
|
||||
String8List *out = push_array(arena, String8List, 1);
|
||||
String8 indent;
|
||||
{
|
||||
U64 indent_buffer_size = RD_INDENT_WIDTH * RD_INDENT_MAX;
|
||||
U8 *indent_buffer = push_array(arena, U8, indent_buffer_size);
|
||||
MemorySet(indent_buffer, ' ', indent_buffer_size);
|
||||
indent = str8(indent_buffer, 0);
|
||||
}
|
||||
|
||||
// parse options
|
||||
RD_Option opts = 0;
|
||||
@@ -107,8 +170,8 @@ entry_point(CmdLine *cmdline)
|
||||
}
|
||||
|
||||
if (opt == 0) {
|
||||
fprintf(stderr, "Unknown argument: \"%.*s\"\n", str8_varg(cmd->string));
|
||||
os_abort(1);
|
||||
rd_errorf("Unknown argument: \"%S\"", cmd->string);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
opts |= opt;
|
||||
@@ -117,66 +180,73 @@ entry_point(CmdLine *cmdline)
|
||||
|
||||
// print help
|
||||
if (opts & RD_Option_Help) {
|
||||
int longest_cmd_switch = 0;
|
||||
for (U64 opt_idx = 0; opt_idx < ArrayCount(g_rd_dump_option_map); ++opt_idx) {
|
||||
fprintf(stdout, "-%s %s\n", g_rd_dump_option_map[opt_idx].name, g_rd_dump_option_map[opt_idx].help);
|
||||
longest_cmd_switch = Max(longest_cmd_switch, strlen(g_rd_dump_option_map[opt_idx].name));
|
||||
}
|
||||
os_abort(0);
|
||||
rd_printf(BUILD_TITLE_STRING_LITERAL);
|
||||
rd_newline();
|
||||
rd_printf("# Help");
|
||||
rd_indent();
|
||||
for (U64 opt_idx = 0; opt_idx < ArrayCount(g_rd_dump_option_map); ++opt_idx) {
|
||||
char *name = g_rd_dump_option_map[opt_idx].name;
|
||||
char *help = g_rd_dump_option_map[opt_idx].help;
|
||||
int indent_size = longest_cmd_switch - strlen(name) + 1;
|
||||
rd_printf("-%s%.*s%s", g_rd_dump_option_map[opt_idx].name, indent_size, indent.str, g_rd_dump_option_map[opt_idx].help);
|
||||
}
|
||||
rd_unindent();
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// print version
|
||||
if (opts & RD_Option_Version) {
|
||||
fprintf(stdout, BUILD_TITLE_STRING_LITERAL "\n");
|
||||
fprintf(stdout, "\traddump <options> <inputs>\n");
|
||||
os_abort(0);
|
||||
rd_printf(BUILD_TITLE_STRING_LITERAL);
|
||||
rd_printf("\traddump <options> <inputs>");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// input check
|
||||
if (cmdline->inputs.node_count == 0) {
|
||||
fprintf(stderr, "No input file specified\n");
|
||||
os_abort(1);
|
||||
rd_errorf("No input file specified");
|
||||
goto exit;
|
||||
} else if (cmdline->inputs.node_count > 1) {
|
||||
fprintf(stderr, "Too many inputs specified, expected one\n");
|
||||
os_abort(1);
|
||||
rd_errorf("Too many inputs specified, expected one");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// read input
|
||||
String8 file_path = str8_list_first(&cmdline->inputs);
|
||||
String8 raw_data = os_data_from_file_path(scratch.arena, file_path);
|
||||
String8 raw_data = os_data_from_file_path(arena, file_path);
|
||||
|
||||
// is read ok?
|
||||
if (raw_data.size == 0) {
|
||||
fprintf(stderr, "Unable to read input file \"%.*s\"\n", str8_varg(file_path));
|
||||
os_abort(1);
|
||||
}
|
||||
|
||||
// make indent
|
||||
String8 indent;
|
||||
{
|
||||
U64 indent_buffer_size = RD_INDENT_WIDTH * RD_INDENT_MAX;
|
||||
U8 *indent_buffer = push_array(scratch.arena, U8, indent_buffer_size);
|
||||
MemorySet(indent_buffer, ' ', indent_buffer_size);
|
||||
indent = str8(indent_buffer, 0);
|
||||
rd_errorf("Unable to read input file \"%S\"", file_path);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// format input
|
||||
String8List out = {0};
|
||||
format_preamble(scratch.arena, &out, indent, file_path, raw_data);
|
||||
rd_format_preamble(arena, out, indent, file_path, raw_data);
|
||||
if (coff_is_archive(raw_data) || coff_is_thin_archive(raw_data)) {
|
||||
coff_format_archive(scratch.arena, &out, indent, raw_data, opts);
|
||||
coff_print_archive(arena, out, indent, raw_data, opts);
|
||||
} else if (coff_is_big_obj(raw_data)) {
|
||||
coff_format_big_obj(scratch.arena, &out, indent, raw_data, opts);
|
||||
coff_print_big_obj(arena, out, indent, raw_data, opts);
|
||||
} else if (coff_is_obj(raw_data)) {
|
||||
coff_format_obj(scratch.arena, &out, indent, raw_data, opts);
|
||||
} else if (is_pe(raw_data)) {
|
||||
pe_format(scratch.arena, &out, indent, raw_data, opts);
|
||||
coff_print_obj(arena, out, indent, raw_data, opts);
|
||||
} else if (rd_is_pe(raw_data)) {
|
||||
RDI_Parsed *rdi = 0;
|
||||
if (!(opts & RD_Option_NoRdi)) {
|
||||
rdi = rd_rdi_from_pe(arena, file_path, raw_data);
|
||||
}
|
||||
pe_print(arena, out, indent, raw_data, opts, rdi);
|
||||
} else if (pe_is_res(raw_data)) {
|
||||
//tool_out_coff_res(stdout, file_data);
|
||||
}
|
||||
|
||||
exit:;
|
||||
// print formatted string
|
||||
String8 out_string = str8_list_join(scratch.arena, &out, &(StringJoin){ .sep = str8_lit("\n"),});
|
||||
String8 out_string = str8_list_join(arena, out, &(StringJoin){ .sep = str8_lit("\n"),});
|
||||
fprintf(stdout, "%.*s", str8_varg(out_string));
|
||||
|
||||
scratch_end(scratch);
|
||||
arena_release(arena);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user