mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-04 04:48:40 +00:00
rdi: first pass of eliminating remainder of non-top-level sections; simplification/cleanup of rdi parsing layer
This commit is contained in:
@@ -19,83 +19,17 @@ typedef enum RDI_ParseStatus
|
||||
RDI_ParseStatus_HeaderDoesNotMatch = 1,
|
||||
RDI_ParseStatus_UnsupportedVersionNumber = 2,
|
||||
RDI_ParseStatus_InvalidDataSecionLayout = 3,
|
||||
RDI_ParseStatus_MissingStringDataSection = 4,
|
||||
RDI_ParseStatus_MissingStringTableSection = 5,
|
||||
RDI_ParseStatus_MissingIndexRunSection = 6,
|
||||
RDI_ParseStatus_MissingRequiredSection = 4,
|
||||
}
|
||||
RDI_ParseStatus;
|
||||
|
||||
typedef struct RDI_Parsed RDI_Parsed;
|
||||
struct RDI_Parsed
|
||||
{
|
||||
// raw data & primary data sections
|
||||
RDI_U8 *raw_data;
|
||||
RDI_U64 raw_data_size;
|
||||
RDI_DataSection *dsecs;
|
||||
RDI_U64 dsec_count;
|
||||
RDI_U32 dsec_idx[RDI_DataSectionTag_PRIMARY_COUNT];
|
||||
|
||||
// parsed universal data structures (strings, index runs)
|
||||
RDI_U8* string_data;
|
||||
RDI_U64 string_data_size;
|
||||
RDI_U32* string_offs;
|
||||
RDI_U64 string_count;
|
||||
RDI_U32* idx_run_data;
|
||||
RDI_U32 idx_run_count;
|
||||
|
||||
// extracted info & tables (any of these may be empty or null, even with a successful parse)
|
||||
RDI_TopLevelInfo* top_level_info;
|
||||
RDI_BinarySection* binary_sections;
|
||||
RDI_U64 binary_sections_count;
|
||||
RDI_FilePathNode* file_paths;
|
||||
RDI_U64 file_paths_count;
|
||||
RDI_SourceFile* source_files;
|
||||
RDI_U64 source_files_count;
|
||||
RDI_LineTable* line_tables;
|
||||
RDI_U64 line_tables_count;
|
||||
RDI_SourceLineMap* source_line_maps;
|
||||
RDI_U64 source_line_maps_count;
|
||||
RDI_U64* line_info_voffs;
|
||||
RDI_U64 line_info_voffs_count;
|
||||
RDI_Line* line_info_lines;
|
||||
RDI_U64 line_info_lines_count;
|
||||
RDI_Column* line_info_columns;
|
||||
RDI_U64 line_info_columns_count;
|
||||
RDI_Unit* units;
|
||||
RDI_U64 units_count;
|
||||
RDI_VMapEntry* unit_vmap;
|
||||
RDI_U64 unit_vmap_count;
|
||||
RDI_TypeNode* type_nodes;
|
||||
RDI_U64 type_nodes_count;
|
||||
RDI_UDT* udts;
|
||||
RDI_U64 udts_count;
|
||||
RDI_Member* members;
|
||||
RDI_U64 members_count;
|
||||
RDI_EnumMember* enum_members;
|
||||
RDI_U64 enum_members_count;
|
||||
RDI_GlobalVariable* global_variables;
|
||||
RDI_U64 global_variables_count;
|
||||
RDI_VMapEntry* global_vmap;
|
||||
RDI_U64 global_vmap_count;
|
||||
RDI_ThreadVariable* thread_variables;
|
||||
RDI_U64 thread_variables_count;
|
||||
RDI_Procedure* procedures;
|
||||
RDI_U64 procedures_count;
|
||||
RDI_Scope* scopes;
|
||||
RDI_U64 scopes_count;
|
||||
RDI_U64* scope_voffs;
|
||||
RDI_U64 scope_voffs_count;
|
||||
RDI_VMapEntry* scope_vmap;
|
||||
RDI_U64 scope_vmap_count;
|
||||
RDI_Local* locals;
|
||||
RDI_U64 locals_count;
|
||||
RDI_LocationBlock* location_blocks;
|
||||
RDI_U64 location_blocks_count;
|
||||
RDI_U8* location_data;
|
||||
RDI_U64 location_data_size;
|
||||
RDI_NameMap* name_maps;
|
||||
RDI_U64 name_maps_count;
|
||||
RDI_NameMap* name_maps_by_kind[RDI_NameMapKind_COUNT];
|
||||
RDI_Section *sections;
|
||||
RDI_U64 sections_count;
|
||||
};
|
||||
|
||||
typedef struct RDI_ParsedLineTable RDI_ParsedLineTable;
|
||||
@@ -142,29 +76,31 @@ struct RDI_ParsedNameMap
|
||||
////////////////////////////////
|
||||
//~ Global Nils
|
||||
|
||||
#if !defined(RDI_DISABLE_NILS)
|
||||
static RDI_TopLevelInfo rdi_top_level_info_nil = {0};
|
||||
static RDI_BinarySection rdi_binary_section_nil = {0};
|
||||
static RDI_FilePathNode rdi_file_path_node_nil = {0};
|
||||
static RDI_SourceFile rdi_source_file_nil = {0};
|
||||
static RDI_LineTable rdi_line_table_nil = {0};
|
||||
static RDI_SourceLineMap rdi_source_line_map_nil = {0};
|
||||
static RDI_Line rdi_line_nil = {0};
|
||||
static RDI_Column rdi_column_nil = {0};
|
||||
static RDI_Unit rdi_unit_nil = {0};
|
||||
static RDI_VMapEntry rdi_vmap_entry_nil = {0};
|
||||
static RDI_TypeNode rdi_type_node_nil = {0};
|
||||
static RDI_UDT rdi_udt_nil = {0};
|
||||
static RDI_Member rdi_member_nil = {0};
|
||||
static RDI_EnumMember rdi_enum_member_nil = {0};
|
||||
static RDI_GlobalVariable rdi_global_variable_nil = {0};
|
||||
static RDI_ThreadVariable rdi_thread_variable_nil = {0};
|
||||
static RDI_Procedure rdi_procedure_nil = {0};
|
||||
static RDI_Scope rdi_scope_nil = {0};
|
||||
static RDI_U64 rdi_voff_nil = 0;
|
||||
static RDI_LocationBlock rdi_location_block_nil = {0};
|
||||
static RDI_Local rdi_local_nil = {0};
|
||||
#endif
|
||||
static union
|
||||
{
|
||||
RDI_TopLevelInfo top_level_info;
|
||||
RDI_BinarySection binary_section;
|
||||
RDI_FilePathNode file_path_node;
|
||||
RDI_SourceFile source_file;
|
||||
RDI_LineTable line_table;
|
||||
RDI_SourceLineMap source_line_map;
|
||||
RDI_Line line;
|
||||
RDI_Column column;
|
||||
RDI_Unit unit;
|
||||
RDI_VMapEntry vmap_entry;
|
||||
RDI_TypeNode type_node;
|
||||
RDI_UDT udt;
|
||||
RDI_Member member;
|
||||
RDI_EnumMember enum_member;
|
||||
RDI_GlobalVariable global_variable;
|
||||
RDI_ThreadVariable thread_variable;
|
||||
RDI_Procedure procedure;
|
||||
RDI_Scope scope;
|
||||
RDI_U64 voff;
|
||||
RDI_LocationBlock location_block;
|
||||
RDI_Local local;
|
||||
}
|
||||
rdi_nil_element_union = {0};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Top-Level Parsing API
|
||||
@@ -172,28 +108,32 @@ static RDI_Local rdi_local_nil = {0};
|
||||
RDI_PROC RDI_ParseStatus rdi_parse(RDI_U8 *data, RDI_U64 size, RDI_Parsed *out);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Parsed Info Extraction Helpers
|
||||
//~ Base Parsed Info Extraction Helpers
|
||||
|
||||
//- element extractor
|
||||
#define rdi_element_from_idx(parsed, name, idx) ((0 <= (idx) && (idx) < (parsed)->name##_count) ? &(parsed)->name[idx] : (parsed)->name ? &(parsed)->name[0] : 0)
|
||||
//- section table/element raw data extraction
|
||||
RDI_PROC void *rdi_section_raw_data_from_kind(RDI_Parsed *rdi, RDI_SectionKind kind, RDI_SectionEncoding *encoding_out, RDI_U64 *size_out);
|
||||
RDI_PROC void *rdi_section_raw_table_from_kind(RDI_Parsed *rdi, RDI_SectionKind kind, RDI_U64 *count_out);
|
||||
RDI_PROC void *rdi_section_raw_element_from_kind_idx(RDI_Parsed *rdi, RDI_SectionKind kind, RDI_U64 idx);
|
||||
#define rdi_table_from_name(rdi, name, count_out) (RDI_SectionElementType_##name *)rdi_section_raw_table_from_kind((rdi), RDI_SectionKind_##name, (count_out))
|
||||
#define rdi_element_from_name_idx(rdi, name, idx) (RDI_SectionElementType_##name *)rdi_section_raw_element_from_kind_idx((rdi), RDI_SectionKind_##name, (idx))
|
||||
|
||||
//- top-level info
|
||||
//- info about whole parse
|
||||
RDI_PROC RDI_U64 rdi_decompressed_size_from_parsed(RDI_Parsed *rdi);
|
||||
|
||||
//- strings
|
||||
RDI_PROC RDI_U8 *rdi_string_from_idx(RDI_Parsed *parsed, RDI_U32 idx, RDI_U64 *len_out);
|
||||
RDI_PROC RDI_U8 *rdi_string_from_idx(RDI_Parsed *rdi, RDI_U32 idx, RDI_U64 *len_out);
|
||||
|
||||
//- index runs
|
||||
RDI_PROC RDI_U32 *rdi_idx_run_from_first_count(RDI_Parsed *parsed, RDI_U32 first, RDI_U32 raw_count, RDI_U32 *n_out);
|
||||
RDI_PROC RDI_U32 *rdi_idx_run_from_first_count(RDI_Parsed *rdi, RDI_U32 raw_first, RDI_U32 raw_count, RDI_U32 *n_out);
|
||||
|
||||
//- line info
|
||||
RDI_PROC void rdi_parsed_from_line_table(RDI_Parsed *p, RDI_LineTable *line_table, RDI_ParsedLineTable *out);
|
||||
RDI_PROC void rdi_parsed_from_line_table(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_ParsedLineTable *out);
|
||||
RDI_PROC RDI_U64 rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff);
|
||||
RDI_PROC void rdi_parsed_from_source_line_map(RDI_Parsed *p, RDI_SourceLineMap *map, RDI_ParsedSourceLineMap *out);
|
||||
RDI_PROC void rdi_parsed_from_source_line_map(RDI_Parsed *rdi, RDI_SourceLineMap *map, RDI_ParsedSourceLineMap *out);
|
||||
RDI_PROC RDI_U64 *rdi_line_voffs_from_num(RDI_ParsedSourceLineMap *map, RDI_U32 linenum, RDI_U32 *n_out);
|
||||
|
||||
//- vmap lookups
|
||||
RDI_PROC RDI_U64 rdi_vmap_idx_from_voff(RDI_VMapEntry *vmap, RDI_U32 vmap_count, RDI_U64 voff);
|
||||
RDI_PROC RDI_U64 rdi_vmap_idx_from_voff(RDI_VMapEntry *vmap, RDI_U64 vmap_count, RDI_U64 voff);
|
||||
|
||||
//- name maps
|
||||
RDI_PROC RDI_NameMap *rdi_name_map_from_kind(RDI_Parsed *p, RDI_NameMapKind kind);
|
||||
@@ -201,16 +141,15 @@ RDI_PROC void rdi_name_map_parse(RDI_Parsed* p, RDI_NameMap *mapptr, RDI_ParsedN
|
||||
RDI_PROC RDI_NameMapNode *rdi_name_map_lookup(RDI_Parsed *p, RDI_ParsedNameMap *map, RDI_U8 *str, RDI_U64 len);
|
||||
RDI_PROC RDI_U32 *rdi_matches_from_map_node(RDI_Parsed *p, RDI_NameMapNode *node, RDI_U32 *n_out);
|
||||
|
||||
////////////////////////////////
|
||||
//~ High-Level Composite Lookup Functions
|
||||
|
||||
//- procedures
|
||||
RDI_PROC RDI_U64 rdi_first_voff_from_proc(RDI_Parsed *p, RDI_U32 proc_id);
|
||||
RDI_PROC RDI_U64 rdi_first_voff_from_proc_idx(RDI_Parsed *rdi, RDI_U32 proc_idx);
|
||||
|
||||
////////////////////////////////
|
||||
//~ Parser Helpers
|
||||
|
||||
#define rdi_parse__min(a,b) (((a)<(b))?(a):(b))
|
||||
#define rdi_parse__extract_primary(p,outptr,outn,pritag) \
|
||||
( (*(void**)&(outptr)) = \
|
||||
rdi_data_from_dsec((p),(p)->dsec_idx[pritag],sizeof(*(outptr)),(pritag),(outn)) )
|
||||
RDI_PROC void *rdi_data_from_dsec(RDI_Parsed *p, RDI_U32 idx, RDI_U32 item_size, RDI_DataSectionTag expected_tag, RDI_U64 *n_out);
|
||||
|
||||
#endif // RDI_FORMAT_PARSE_H
|
||||
|
||||
Reference in New Issue
Block a user