mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-07-14 13:31:25 -07:00
moved DWARF parser to use str8_deserial-style API, added to the parser
layer functionality for interpreting different types of attributes, added support for location lists, and API to enable parsing tags with abstract origin.
This commit is contained in:
+1882
-859
File diff suppressed because it is too large
Load Diff
@@ -1,50 +1,69 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#ifndef RDI_FROM_DWARF_H
|
||||
#define RDI_FROM_DWARF_H
|
||||
#pragma once
|
||||
|
||||
typedef U64 D2R_ConvertFlags;
|
||||
enum
|
||||
{
|
||||
#define X(t,n,k) D2R_ConvertFlag_##t = (1ull << RDI_SectionKind_##t),
|
||||
RDI_SectionKind_XList
|
||||
#undef X
|
||||
D2R_ConvertFlag_StrictParse,
|
||||
};
|
||||
|
||||
typedef struct D2R_User2Convert
|
||||
{
|
||||
String8 input_exe_name;
|
||||
String8 input_exe_data;
|
||||
String8 input_debug_name;
|
||||
String8 input_debug_data;
|
||||
String8 output_name;
|
||||
D2R_ConvertFlags flags;
|
||||
String8List errors;
|
||||
} D2R_User2Convert;
|
||||
|
||||
typedef struct D2R_TypeTable
|
||||
{
|
||||
HashTable *ht;
|
||||
RDIM_TypeChunkList *types;
|
||||
U64 type_chunk_cap;
|
||||
RDIM_Type *void_type;
|
||||
RDIM_Type *varg_type;
|
||||
} D2R_TypeTable;
|
||||
|
||||
typedef struct D2R_TagNode
|
||||
{
|
||||
struct D2R_TagNode *next;
|
||||
DW_TagNode *cur_node;
|
||||
RDIM_Type *type;
|
||||
RDIM_Scope *scope;
|
||||
} D2R_TagNode;
|
||||
|
||||
typedef struct D2R_CompUnitContribMap
|
||||
{
|
||||
U64 count;
|
||||
U64 *info_off_arr;
|
||||
RDIM_Rng1U64List *voff_range_arr;
|
||||
} D2R_CompUnitContribMap;
|
||||
|
||||
////////////////////////////////
|
||||
//~ Program Parameters Type
|
||||
// Command Line -> Conversion Inputs
|
||||
|
||||
typedef struct DWARFCONV_Params{
|
||||
String8 input_elf_name;
|
||||
String8 input_elf_data;
|
||||
|
||||
String8 output_name;
|
||||
|
||||
U64 unit_idx_min;
|
||||
U64 unit_idx_max;
|
||||
|
||||
struct{
|
||||
B8 input;
|
||||
} hide_errors;
|
||||
|
||||
B8 dump;
|
||||
B8 dump__first;
|
||||
B8 dump_header;
|
||||
B8 dump_sections;
|
||||
B8 dump_segments;
|
||||
B8 dump_symtab;
|
||||
B8 dump_dynsym;
|
||||
B8 dump_debug_sections;
|
||||
B8 dump_debug_info;
|
||||
B8 dump_debug_abbrev;
|
||||
B8 dump_debug_pubnames;
|
||||
B8 dump_debug_pubtypes;
|
||||
B8 dump_debug_names;
|
||||
B8 dump_debug_aranges;
|
||||
B8 dump_debug_addr;
|
||||
B8 dump__last;
|
||||
|
||||
String8List errors;
|
||||
} DWARFCONV_Params;
|
||||
internal D2R_User2Convert * d2r_user2convert_from_cmdln(Arena *arena, CmdLine *cmdline);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Program Parameters Parser
|
||||
// Top-Level Conversion Entry Point
|
||||
|
||||
static DWARFCONV_Params *dwarf_convert_params_from_cmd_line(Arena *arena, CmdLine *cmdline);
|
||||
internal RDIM_BakeParams * d2r_convert (Arena *arena, D2R_User2Convert *in);
|
||||
internal RDIM_BakeResults d2r_bake (RDIM_HelpState *state, RDIM_BakeParams *in);
|
||||
internal RDIM_SerializedSectionBundle d2r_compress(Arena *arena, RDIM_SerializedSectionBundle in);
|
||||
|
||||
////////////////////////////////
|
||||
// Enum Conversion
|
||||
|
||||
internal RDI_Language rdi_language_from_dw_language(DW_Language v);
|
||||
internal RDI_RegCodeX86 rdi_reg_from_dw_reg_x86(DW_RegX86 v);
|
||||
internal B32 rdi_reg_from_dw_reg_x64(DW_RegX64 v, RDI_RegCodeX64 *code_out, U64 *off_out, U64 *size_out);
|
||||
internal B32 rdi_reg_from_dw_reg(Arch arch, DW_Reg v, RDI_RegCode *code_out, U64 *off_out, U64 *size_out);
|
||||
|
||||
#endif //RDI_FROM_DWARF_H
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
// Copyright (c) 2024 Epic Games Tools
|
||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||
|
||||
#define BUILD_TITLE "Epic Games Tools (R) DWARF Converter"
|
||||
#define BUILD_CONSOLE_INTERFACE 1
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#include "third_party/rad_lzb_simple/rad_lzb_simple.h"
|
||||
#include "third_party/rad_lzb_simple/rad_lzb_simple.c"
|
||||
#include "third_party/xxHash/xxhash.c"
|
||||
#include "third_party/xxHash/xxhash.h"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#include "lib_rdi_format/rdi_format.h"
|
||||
#include "lib_rdi_format/rdi_format.c"
|
||||
#include "lib_rdi_format/rdi_format_parse.h"
|
||||
#include "lib_rdi_format/rdi_format_parse.c"
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
#include "base/base_inc.h"
|
||||
#include "os/os_inc.h"
|
||||
#include "async/async.h"
|
||||
#include "rdi_make/rdi_make_local.h"
|
||||
#include "rdi_make/rdi_make_help.h"
|
||||
#include "linker/path_ext/path.h"
|
||||
#include "linker/hash_table.h"
|
||||
#include "coff/coff.h"
|
||||
#include "coff/coff_parse.h"
|
||||
#include "dwarf/dwarf.h"
|
||||
#include "dwarf/dwarf_parse.h"
|
||||
#include "dwarf/dwarf_coff.h"
|
||||
#include "pe/pe.h"
|
||||
#include "linker/rdi/rdi_coff.h"
|
||||
#include "rdi_from_dwarf/rdi_from_dwarf.h"
|
||||
|
||||
#include "base/base_inc.c"
|
||||
#include "os/os_inc.c"
|
||||
#include "async/async.c"
|
||||
#include "coff/coff.c"
|
||||
#include "coff/coff_parse.c"
|
||||
#include "pe/pe.c"
|
||||
#include "rdi_make/rdi_make_local.c"
|
||||
#include "rdi_make/rdi_make_help.c"
|
||||
#include "linker/rdi/rdi_coff.c"
|
||||
#include "linker/path_ext/path.c"
|
||||
#include "linker/hash_table.c"
|
||||
#include "dwarf/dwarf.c"
|
||||
#include "dwarf/dwarf_parse.c"
|
||||
#include "dwarf/dwarf_coff.c"
|
||||
#include "rdi_from_dwarf/rdi_from_dwarf.c"
|
||||
|
||||
////////////////////////////////
|
||||
// Entry Point
|
||||
|
||||
internal void
|
||||
entry_point(CmdLine *cmdline)
|
||||
{
|
||||
// initialize state and unpack command line
|
||||
Arena *arena = arena_alloc();
|
||||
B32 do_help = (cmd_line_has_flag(cmdline, str8_lit("help")) ||
|
||||
cmd_line_has_flag(cmdline, str8_lit("h")) ||
|
||||
cmd_line_has_flag(cmdline, str8_lit("?")));
|
||||
|
||||
D2R_User2Convert *user2convert = d2r_user2convert_from_cmdln(arena, cmdline);
|
||||
|
||||
// display help
|
||||
if (do_help) {
|
||||
fprintf(stderr, "--- rdi_from_dwarf ------------------------------------------------------------\n\n");
|
||||
|
||||
fprintf(stderr, "This utility converts debug information from DWARF into the RAD Debug Info\n");
|
||||
fprintf(stderr, "format. The following arguments are accepted:\n\n");
|
||||
|
||||
fprintf(stderr, "--exe:<path> [optional] Specifies the path of the executable filefor which the\n");
|
||||
fprintf(stderr, " debug info was generated.\n");
|
||||
fprintf(stderr, "--debug:<path> Specifies the path of the .DEBUG debug info file to\n");
|
||||
fprintf(stderr, " convert.\n");
|
||||
fprintf(stderr, "--out:<path> Specifies the path at which the output will be written.\n\n");
|
||||
|
||||
if (!do_help) {
|
||||
for (String8Node *n = user2convert->errors.first; n != 0; n = n->next) {
|
||||
fprintf(stderr, "error(input): %.*s\n", str8_varg(n->string));
|
||||
}
|
||||
}
|
||||
|
||||
os_abort(0);
|
||||
}
|
||||
|
||||
RDIM_HelpState *rdim_help_state = rdim_help_init();
|
||||
|
||||
ProfBegin("convert");
|
||||
RDIM_BakeParams *convert2bake = d2r_convert(arena, user2convert);
|
||||
ProfEnd();
|
||||
|
||||
ProfBegin("bake");
|
||||
RDIM_BakeResults bake2srlz = d2r_bake(rdim_help_state, convert2bake);
|
||||
ProfEnd();
|
||||
|
||||
ProfBegin("serialize bake");
|
||||
RDIM_SerializedSectionBundle srlz2file = rdim_serialized_section_bundle_from_bake_results(&bake2srlz);
|
||||
ProfEnd();
|
||||
|
||||
RDIM_SerializedSectionBundle srlz2file_compressed = srlz2file;
|
||||
if (cmd_line_has_flag(cmdline, str8_lit("compress"))) {
|
||||
ProfBegin("compress");
|
||||
srlz2file_compressed = d2r_compress(arena, srlz2file);
|
||||
ProfEnd();
|
||||
}
|
||||
|
||||
ProfBegin("serialize blobs");
|
||||
String8List blobs = rdim_file_blobs_from_section_bundle(arena, &srlz2file_compressed);
|
||||
ProfEnd();
|
||||
|
||||
ProfBegin("write");
|
||||
if (!os_write_data_list_to_file_path(user2convert->output_name, blobs)) {
|
||||
fprintf(stderr, "error(ouptut): unable to write to %.*s\n", str8_varg(user2convert->output_name));
|
||||
}
|
||||
ProfEnd();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user