mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-03 20:38: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:
@@ -34,14 +34,14 @@ rdi_parse(RDI_U8 *data, RDI_U64 size, RDI_Parsed *out)
|
||||
//////////////////////////////
|
||||
//- rjf: extract data sections
|
||||
//
|
||||
RDI_DataSection *dsecs = 0;
|
||||
RDI_Section *dsecs = 0;
|
||||
RDI_U32 dsec_count = 0;
|
||||
if(result == RDI_ParseStatus_Good)
|
||||
{
|
||||
RDI_U64 opl = (RDI_U64)hdr->data_section_off + (RDI_U64)hdr->data_section_count*sizeof(*dsecs);
|
||||
if(opl <= size)
|
||||
{
|
||||
dsecs = (RDI_DataSection*)(data + hdr->data_section_off);
|
||||
dsecs = (RDI_Section*)(data + hdr->data_section_off);
|
||||
dsec_count = hdr->data_section_count;
|
||||
}
|
||||
if(dsecs == 0)
|
||||
@@ -51,211 +51,146 @@ rdi_parse(RDI_U8 *data, RDI_U64 size, RDI_Parsed *out)
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: extract primary data section indexes
|
||||
//
|
||||
RDI_U32 dsec_idx[RDI_DataSectionTag_PRIMARY_COUNT] = {0};
|
||||
if(result == RDI_ParseStatus_Good)
|
||||
{
|
||||
RDI_DataSection *sec_ptr = dsecs;
|
||||
for(RDI_U32 i = 0; i < dsec_count; i += 1, sec_ptr += 1)
|
||||
{
|
||||
if(sec_ptr->tag < RDI_DataSectionTag_PRIMARY_COUNT)
|
||||
{
|
||||
dsec_idx[sec_ptr->tag] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: fill out raw data info
|
||||
//- rjf: fill result
|
||||
//
|
||||
if(result == RDI_ParseStatus_Good)
|
||||
{
|
||||
out->raw_data = data;
|
||||
out->raw_data_size = size;
|
||||
out->dsecs = dsecs;
|
||||
out->dsec_count = dsec_count;
|
||||
for(RDI_U32 i = 0; i < RDI_DataSectionTag_PRIMARY_COUNT; i += 1)
|
||||
{
|
||||
out->dsec_idx[i] = dsec_idx[i];
|
||||
}
|
||||
out->sections = dsecs;
|
||||
out->sections_count = dsec_count;
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: extract string table info
|
||||
//
|
||||
RDI_U8 *string_data = 0;
|
||||
RDI_U64 string_opl = 0;
|
||||
RDI_U32 *string_offs = 0;
|
||||
RDI_U64 string_count = 0;
|
||||
if(result == RDI_ParseStatus_Good)
|
||||
{
|
||||
RDI_U64 table_entry_count = 0;
|
||||
rdi_parse__extract_primary(out, string_offs, &table_entry_count, RDI_DataSectionTag_StringTable);
|
||||
rdi_parse__extract_primary(out, string_data, &string_opl, RDI_DataSectionTag_StringData);
|
||||
if(table_entry_count > 0)
|
||||
{
|
||||
string_count = table_entry_count - 1;
|
||||
}
|
||||
if(string_data == 0)
|
||||
{
|
||||
result = RDI_ParseStatus_MissingStringDataSection;
|
||||
}
|
||||
else if (string_offs == 0)
|
||||
{
|
||||
result = RDI_ParseStatus_MissingStringTableSection;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: extract index run table info
|
||||
//
|
||||
RDI_U32 *idx_run_data = 0;
|
||||
RDI_U64 idx_run_count = 0;
|
||||
if(result == RDI_ParseStatus_Good)
|
||||
{
|
||||
rdi_parse__extract_primary(out, idx_run_data, &idx_run_count, RDI_DataSectionTag_IndexRuns);
|
||||
if(idx_run_data == 0)
|
||||
{
|
||||
result = RDI_ParseStatus_MissingIndexRunSection;
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: extract info tables
|
||||
//- rjf: validate results
|
||||
//
|
||||
if(result == RDI_ParseStatus_Good)
|
||||
{
|
||||
out->string_data = string_data;
|
||||
out->string_offs = string_offs;
|
||||
out->string_data_size = string_opl;
|
||||
out->string_count = string_count;
|
||||
out->idx_run_data = idx_run_data;
|
||||
out->idx_run_count = idx_run_count;
|
||||
for(RDI_SectionKind k = (RDI_SectionKind)(RDI_SectionKind_NULL+1); k < RDI_SectionKind_COUNT; k = (RDI_SectionKind)(k+1))
|
||||
{
|
||||
RDI_TopLevelInfo *tli = 0;
|
||||
RDI_U64 dummy = 0;
|
||||
rdi_parse__extract_primary(out, tli, &dummy, RDI_DataSectionTag_TopLevelInfo);
|
||||
if (dummy != 1){
|
||||
tli = 0;
|
||||
}
|
||||
out->top_level_info = tli;
|
||||
}
|
||||
rdi_parse__extract_primary(out, out->binary_sections, &out->binary_sections_count, RDI_DataSectionTag_BinarySections);
|
||||
rdi_parse__extract_primary(out, out->file_paths, &out->file_paths_count, RDI_DataSectionTag_FilePathNodes);
|
||||
rdi_parse__extract_primary(out, out->source_files, &out->source_files_count, RDI_DataSectionTag_SourceFiles);
|
||||
rdi_parse__extract_primary(out, out->line_tables, &out->line_tables_count, RDI_DataSectionTag_LineTables);
|
||||
rdi_parse__extract_primary(out, out->source_line_maps, &out->source_line_maps_count, RDI_DataSectionTag_SourceLineMaps);
|
||||
rdi_parse__extract_primary(out, out->line_info_voffs, &out->line_info_voffs_count, RDI_DataSectionTag_LineInfoVoffs);
|
||||
rdi_parse__extract_primary(out, out->line_info_lines, &out->line_info_lines_count, RDI_DataSectionTag_LineInfoLines);
|
||||
rdi_parse__extract_primary(out, out->line_info_columns, &out->line_info_columns_count, RDI_DataSectionTag_LineInfoColumns);
|
||||
rdi_parse__extract_primary(out, out->units, &out->units_count, RDI_DataSectionTag_Units);
|
||||
rdi_parse__extract_primary(out, out->unit_vmap, &out->unit_vmap_count, RDI_DataSectionTag_UnitVmap);
|
||||
rdi_parse__extract_primary(out, out->unit_vmap, &out->unit_vmap_count, RDI_DataSectionTag_UnitVmap);
|
||||
rdi_parse__extract_primary(out, out->type_nodes, &out->type_nodes_count, RDI_DataSectionTag_TypeNodes);
|
||||
rdi_parse__extract_primary(out, out->udts, &out->udts_count, RDI_DataSectionTag_UDTs);
|
||||
rdi_parse__extract_primary(out, out->members, &out->members_count, RDI_DataSectionTag_Members);
|
||||
rdi_parse__extract_primary(out, out->enum_members, &out->enum_members_count, RDI_DataSectionTag_EnumMembers);
|
||||
rdi_parse__extract_primary(out, out->global_variables, &out->global_variables_count, RDI_DataSectionTag_GlobalVariables);
|
||||
rdi_parse__extract_primary(out, out->global_vmap, &out->global_vmap_count, RDI_DataSectionTag_GlobalVmap);
|
||||
rdi_parse__extract_primary(out, out->thread_variables, &out->thread_variables_count, RDI_DataSectionTag_ThreadVariables);
|
||||
rdi_parse__extract_primary(out, out->procedures, &out->procedures_count, RDI_DataSectionTag_Procedures);
|
||||
rdi_parse__extract_primary(out, out->scopes, &out->scopes_count, RDI_DataSectionTag_Scopes);
|
||||
rdi_parse__extract_primary(out, out->scope_voffs, &out->scope_voffs_count, RDI_DataSectionTag_ScopeVoffData);
|
||||
rdi_parse__extract_primary(out, out->scope_vmap, &out->scope_vmap_count, RDI_DataSectionTag_ScopeVmap);
|
||||
rdi_parse__extract_primary(out, out->locals, &out->locals_count, RDI_DataSectionTag_Locals);
|
||||
rdi_parse__extract_primary(out, out->location_blocks, &out->location_blocks_count, RDI_DataSectionTag_LocationBlocks);
|
||||
rdi_parse__extract_primary(out, out->location_data, &out->location_data_size, RDI_DataSectionTag_LocationData);
|
||||
rdi_parse__extract_primary(out, out->name_maps, &out->name_maps_count, RDI_DataSectionTag_NameMaps);
|
||||
{
|
||||
RDI_NameMap *name_map_ptr = out->name_maps;
|
||||
RDI_NameMap *name_map_opl = out->name_maps + out->name_maps_count;
|
||||
for (; name_map_ptr < name_map_opl; name_map_ptr += 1){
|
||||
if (out->name_maps_by_kind[name_map_ptr->kind] == 0){
|
||||
out->name_maps_by_kind[name_map_ptr->kind] = name_map_ptr;
|
||||
if(rdi_section_is_required_table[k])
|
||||
{
|
||||
RDI_U64 data_size = 0;
|
||||
RDI_SectionEncoding encoding = 0;
|
||||
void *data = rdi_section_raw_data_from_kind(out, k, &encoding, &data_size);
|
||||
if(data == 0 || data == &rdi_nil_element_union || data_size == 0)
|
||||
{
|
||||
result = RDI_ParseStatus_MissingRequiredSection;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
//- rjf: fill any missing tables with nil elements
|
||||
//
|
||||
#if !defined(RDI_DISABLE_NILS)
|
||||
if(out->top_level_info == 0) { out->top_level_info = &rdi_top_level_info_nil; }
|
||||
if(out->binary_sections == 0) { out->binary_sections = &rdi_binary_section_nil; out->binary_sections_count = 1; }
|
||||
if(out->file_paths == 0) { out->file_paths = &rdi_file_path_node_nil; out->file_paths_count = 1; }
|
||||
if(out->source_files == 0) { out->source_files = &rdi_source_file_nil; out->source_files_count = 1; }
|
||||
if(out->line_tables == 0) { out->line_tables = &rdi_line_table_nil; out->line_tables_count = 1; }
|
||||
if(out->source_line_maps == 0) { out->source_line_maps = &rdi_source_line_map_nil; out->source_line_maps_count = 1; }
|
||||
if(out->units == 0) { out->units = &rdi_unit_nil; out->units_count = 1; }
|
||||
if(out->unit_vmap == 0) { out->unit_vmap = &rdi_vmap_entry_nil; out->unit_vmap_count = 1; }
|
||||
if(out->type_nodes == 0) { out->type_nodes = &rdi_type_node_nil; out->type_nodes_count = 1; }
|
||||
if(out->udts == 0) { out->udts = &rdi_udt_nil; out->udts_count = 1; }
|
||||
if(out->members == 0) { out->members = &rdi_member_nil; out->members_count = 1; }
|
||||
if(out->enum_members == 0) { out->enum_members = &rdi_enum_member_nil; out->enum_members_count = 1; }
|
||||
if(out->global_variables == 0) { out->global_variables = &rdi_global_variable_nil; out->global_variables_count = 1; }
|
||||
if(out->global_vmap == 0) { out->global_vmap = &rdi_vmap_entry_nil; out->global_vmap_count = 1; }
|
||||
if(out->thread_variables == 0) { out->thread_variables = &rdi_thread_variable_nil; out->thread_variables_count = 1; }
|
||||
if(out->procedures == 0) { out->procedures = &rdi_procedure_nil; out->procedures_count = 1; }
|
||||
if(out->scopes == 0) { out->scopes = &rdi_scope_nil; out->scopes_count = 1; }
|
||||
if(out->scope_voffs == 0) { out->scope_voffs = &rdi_voff_nil; out->scope_voffs_count = 1; }
|
||||
if(out->scope_vmap == 0) { out->scope_vmap = &rdi_vmap_entry_nil; out->scope_vmap_count = 1; }
|
||||
if(out->locals == 0) { out->locals = &rdi_local_nil; out->locals_count = 1; }
|
||||
if(out->location_blocks == 0) { out->location_blocks = &rdi_location_block_nil; out->location_blocks_count = 1; }
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ Parsed Info Extraction Helpers
|
||||
//~ Base Parsed Info Extraction Helpers
|
||||
|
||||
//- top-level info
|
||||
//- 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)
|
||||
{
|
||||
void *result = 0;
|
||||
#if !defined(RDI_DISABLE_NILS)
|
||||
result = &rdi_nil_element_union;
|
||||
*size_out = rdi_section_element_size_table[kind];
|
||||
#endif
|
||||
if(0 <= kind && kind < rdi->sections_count)
|
||||
{
|
||||
result = rdi->raw_data+rdi->sections[kind].off;
|
||||
*size_out = rdi->sections[kind].encoded_size;
|
||||
*encoding_out = rdi->sections[kind].encoding;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
RDI_PROC void *
|
||||
rdi_section_raw_table_from_kind(RDI_Parsed *rdi, RDI_SectionKind kind, RDI_U64 *count_out)
|
||||
{
|
||||
void *result = 0;
|
||||
RDI_U64 all_elements_size = 0;
|
||||
RDI_SectionEncoding all_elements_encoding = 0;
|
||||
void *all_elements = rdi_section_raw_data_from_kind(rdi, kind, &all_elements_encoding, &all_elements_size);
|
||||
if(all_elements_encoding == RDI_SectionEncoding_Unpacked)
|
||||
{
|
||||
RDI_U64 element_size = (RDI_U64)rdi_section_element_size_table[kind];
|
||||
RDI_U64 all_elements_count = all_elements_size/element_size;
|
||||
result = all_elements;
|
||||
*count_out = all_elements_count;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
RDI_PROC void *
|
||||
rdi_section_raw_element_from_kind_idx(RDI_Parsed *rdi, RDI_SectionKind kind, RDI_U64 idx)
|
||||
{
|
||||
RDI_U64 count = 0;
|
||||
void *table = rdi_section_raw_table_from_kind(rdi, kind, &count);
|
||||
void *result = table;
|
||||
if(idx < count)
|
||||
{
|
||||
RDI_U64 element_size = (RDI_U64)rdi_section_element_size_table[kind];
|
||||
result = (RDI_U8 *)table + element_size*idx;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//- info about whole parse
|
||||
|
||||
RDI_PROC RDI_U64
|
||||
rdi_decompressed_size_from_parsed(RDI_Parsed *rdi)
|
||||
{
|
||||
RDI_U64 decompressed_size = rdi->raw_data_size;
|
||||
for(RDI_U64 dsec_idx = 0; dsec_idx < rdi->dsec_count; dsec_idx += 1)
|
||||
for(RDI_U64 section_idx = 0; section_idx < rdi->sections_count; section_idx += 1)
|
||||
{
|
||||
decompressed_size += (rdi->dsecs[dsec_idx].unpacked_size - rdi->dsecs[dsec_idx].encoded_size);
|
||||
decompressed_size += (rdi->sections[section_idx].unpacked_size - rdi->sections[section_idx].encoded_size);
|
||||
}
|
||||
return decompressed_size;
|
||||
}
|
||||
|
||||
//- 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)
|
||||
{
|
||||
RDI_U8 *result = 0;
|
||||
RDI_U64 len_result = 0;
|
||||
if(idx < parsed->string_count)
|
||||
RDI_U8 *result_base = 0;
|
||||
RDI_U64 result_size = 0;
|
||||
{
|
||||
RDI_U32 off_raw = parsed->string_offs[idx];
|
||||
RDI_U32 opl_raw = parsed->string_offs[idx + 1];
|
||||
RDI_U32 opl = rdi_parse__min(opl_raw, parsed->string_data_size);
|
||||
RDI_U32 off = rdi_parse__min(off_raw, opl);
|
||||
result = parsed->string_data + off;
|
||||
len_result = opl - off;
|
||||
RDI_U64 string_offs_count = 0;
|
||||
RDI_U32 *string_offs = rdi_table_from_name(rdi, StringTable, &string_offs_count);
|
||||
if(idx < string_offs_count)
|
||||
{
|
||||
RDI_U64 string_data_size = 0;
|
||||
RDI_U8 *string_data = rdi_table_from_name(rdi, StringData, &string_data_size);
|
||||
RDI_U32 off_raw = string_offs[idx];
|
||||
RDI_U32 opl_raw = string_offs[idx + 1];
|
||||
RDI_U32 opl = rdi_parse__min(opl_raw, string_data_size);
|
||||
RDI_U32 off = rdi_parse__min(off_raw, opl);
|
||||
result_base = string_data + off;
|
||||
result_size = opl - off;
|
||||
}
|
||||
}
|
||||
*len_out = len_result;
|
||||
return result;
|
||||
*len_out = result_size;
|
||||
return result_base;
|
||||
}
|
||||
|
||||
//- index runs
|
||||
|
||||
RDI_PROC RDI_U32*
|
||||
rdi_idx_run_from_first_count(RDI_Parsed *parsed, RDI_U32 raw_first, RDI_U32 raw_count, RDI_U32 *n_out)
|
||||
rdi_idx_run_from_first_count(RDI_Parsed *rdi, RDI_U32 raw_first, RDI_U32 raw_count, RDI_U32 *n_out)
|
||||
{
|
||||
RDI_U64 idx_run_count = 0;
|
||||
RDI_U32 *idx_run_data = rdi_table_from_name(rdi, IndexRuns, &idx_run_count);
|
||||
RDI_U32 raw_opl = raw_first + raw_count;
|
||||
RDI_U32 opl = rdi_parse__min(raw_opl, parsed->idx_run_count);
|
||||
RDI_U32 opl = rdi_parse__min(raw_opl, idx_run_count);
|
||||
RDI_U32 first = rdi_parse__min(raw_first, opl);
|
||||
RDI_U32 *result = 0;
|
||||
if(first < parsed->idx_run_count)
|
||||
if(first < idx_run_count)
|
||||
{
|
||||
result = parsed->idx_run_data + first;
|
||||
result = idx_run_data + first;
|
||||
}
|
||||
*n_out = opl - first;
|
||||
return result;
|
||||
@@ -264,17 +199,17 @@ rdi_idx_run_from_first_count(RDI_Parsed *parsed, RDI_U32 raw_first, RDI_U32 raw_
|
||||
//- line info
|
||||
|
||||
RDI_PROC void
|
||||
rdi_parsed_from_line_table(RDI_Parsed *p, RDI_LineTable *line_table, RDI_ParsedLineTable *out)
|
||||
rdi_parsed_from_line_table(RDI_Parsed *rdi, RDI_LineTable *line_table, RDI_ParsedLineTable *out)
|
||||
{
|
||||
//- rjf: extract top-level line info tables
|
||||
RDI_U64 all_voffs_count = 0;
|
||||
RDI_U64 *all_voffs = (RDI_U64 *)rdi_data_from_dsec(p, p->dsec_idx[RDI_DataSectionTag_LineInfoVoffs], sizeof(RDI_U64), RDI_DataSectionTag_LineInfoVoffs, &all_voffs_count);
|
||||
RDI_U64 *all_voffs = rdi_table_from_name(rdi, LineInfoVOffs, &all_voffs_count);
|
||||
RDI_U64 *all_voffs_opl = all_voffs + all_voffs_count;
|
||||
RDI_U64 all_lines_count = 0;
|
||||
RDI_Line *all_lines = (RDI_Line *)rdi_data_from_dsec(p, p->dsec_idx[RDI_DataSectionTag_LineInfoLines], sizeof(RDI_Line), RDI_DataSectionTag_LineInfoLines, &all_lines_count);
|
||||
RDI_Line *all_lines = rdi_table_from_name(rdi, LineInfoLines, &all_lines_count);
|
||||
RDI_Line *all_lines_opl = all_lines + all_lines_count;
|
||||
RDI_U64 all_cols_count = 0;
|
||||
RDI_Column *all_cols = (RDI_Column *)rdi_data_from_dsec(p, p->dsec_idx[RDI_DataSectionTag_LineInfoColumns], sizeof(RDI_Column), RDI_DataSectionTag_LineInfoColumns, &all_cols_count);
|
||||
RDI_Column *all_cols = rdi_table_from_name(rdi, LineInfoColumns, &all_cols_count);
|
||||
RDI_Column *all_cols_opl = all_cols + all_cols_count;
|
||||
|
||||
//- rjf: extract ranges of top-level tables belonging to this line table
|
||||
@@ -332,17 +267,17 @@ 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_parsed_from_source_line_map(RDI_Parsed *rdi, RDI_SourceLineMap *map, RDI_ParsedSourceLineMap *out)
|
||||
{
|
||||
//- rjf: extract top-level line info tables
|
||||
RDI_U64 all_nums_count = 0;
|
||||
RDI_U32 *all_nums = (RDI_U32 *)rdi_data_from_dsec(p, p->dsec_idx[RDI_DataSectionTag_SourceLineMapNumbers], sizeof(RDI_U32), RDI_DataSectionTag_SourceLineMapNumbers, &all_nums_count);
|
||||
RDI_U32 *all_nums = rdi_table_from_name(rdi, SourceLineMapNumbers, &all_nums_count);
|
||||
RDI_U32 *all_nums_opl = all_nums + all_nums_count;
|
||||
RDI_U64 all_rngs_count = 0;
|
||||
RDI_U32 *all_rngs = (RDI_U32 *)rdi_data_from_dsec(p, p->dsec_idx[RDI_DataSectionTag_SourceLineMapRanges], sizeof(RDI_U32), RDI_DataSectionTag_SourceLineMapRanges, &all_rngs_count);
|
||||
RDI_U32 *all_rngs = rdi_table_from_name(rdi, SourceLineMapRanges, &all_rngs_count);
|
||||
RDI_U32 *all_rngs_opl = all_rngs + all_rngs_count;
|
||||
RDI_U64 all_voffs_count = 0;
|
||||
RDI_U64 *all_voffs = (RDI_U64 *)rdi_data_from_dsec(p, p->dsec_idx[RDI_DataSectionTag_SourceLineMapVOffs], sizeof(RDI_U64), RDI_DataSectionTag_SourceLineMapVOffs, &all_voffs_count);
|
||||
RDI_U64 *all_voffs = rdi_table_from_name(rdi, SourceLineMapVOffs, &all_voffs_count);
|
||||
RDI_U64 *all_voffs_opl = all_voffs + all_voffs_count;
|
||||
|
||||
//- rjf: extract ranges of top-level tables belonging to this line map
|
||||
@@ -363,7 +298,7 @@ rdi_parsed_from_source_line_map(RDI_Parsed *p, RDI_SourceLineMap *map, RDI_Parse
|
||||
out->voff_count = voffs_count;
|
||||
}
|
||||
|
||||
RDI_PROC RDI_U64*
|
||||
RDI_PROC RDI_U64 *
|
||||
rdi_line_voffs_from_num(RDI_ParsedSourceLineMap *map, RDI_U32 linenum, RDI_U32 *n_out)
|
||||
{
|
||||
RDI_U64 *result = 0;
|
||||
@@ -424,7 +359,7 @@ rdi_line_voffs_from_num(RDI_ParsedSourceLineMap *map, RDI_U32 linenum, RDI_U32 *
|
||||
//- vmap lookups
|
||||
|
||||
RDI_PROC RDI_U64
|
||||
rdi_vmap_idx_from_voff(RDI_VMapEntry *vmap, RDI_U32 vmap_count, RDI_U64 voff)
|
||||
rdi_vmap_idx_from_voff(RDI_VMapEntry *vmap, RDI_U64 vmap_count, RDI_U64 voff)
|
||||
{
|
||||
RDI_U64 result = 0;
|
||||
if(vmap_count > 0 && vmap[0].voff <= voff && voff < vmap[vmap_count - 1].voff)
|
||||
@@ -459,27 +394,42 @@ rdi_vmap_idx_from_voff(RDI_VMapEntry *vmap, RDI_U32 vmap_count, RDI_U64 voff)
|
||||
return result;
|
||||
}
|
||||
|
||||
//- name maps
|
||||
|
||||
RDI_PROC RDI_NameMap*
|
||||
rdi_name_map_from_kind(RDI_Parsed *p, RDI_NameMapKind kind){
|
||||
RDI_NameMap *result = 0;
|
||||
if(0 < kind && kind < RDI_NameMapKind_COUNT)
|
||||
{
|
||||
result = p->name_maps_by_kind[kind];
|
||||
}
|
||||
RDI_PROC RDI_U64
|
||||
rdi_vmap_idx_from_section_kind_voff(RDI_Parsed *rdi, RDI_SectionKind kind, RDI_U64 voff)
|
||||
{
|
||||
RDI_U64 vmaps_count = 0;
|
||||
RDI_VMapEntry *vmaps = rdi_section_raw_table_from_kind(rdi, kind, &vmaps_count);
|
||||
RDI_U64 result = rdi_vmap_idx_from_voff(vmaps, vmaps_count, voff);
|
||||
return result;
|
||||
}
|
||||
|
||||
//- name maps
|
||||
|
||||
RDI_PROC void
|
||||
rdi_name_map_parse(RDI_Parsed *p, RDI_NameMap *mapptr, RDI_ParsedNameMap *out)
|
||||
rdi_parsed_from_name_map(RDI_Parsed *rdi, RDI_NameMap *mapptr, RDI_ParsedNameMap *out)
|
||||
{
|
||||
out->buckets = 0;
|
||||
out->bucket_count = 0;
|
||||
if(mapptr != 0)
|
||||
{
|
||||
out->buckets = (RDI_NameMapBucket*)rdi_data_from_dsec(p, mapptr->bucket_data_idx, sizeof(RDI_NameMapBucket), RDI_DataSectionTag_NameMapBuckets, &out->bucket_count);
|
||||
out->nodes = (RDI_NameMapNode*)rdi_data_from_dsec(p, mapptr->node_data_idx, sizeof(RDI_NameMapNode), RDI_DataSectionTag_NameMapNodes, &out->node_count);
|
||||
RDI_U64 all_buckets_count = 0;
|
||||
RDI_NameMapBucket *all_buckets = rdi_table_from_name(rdi, NameMapBuckets, &all_buckets_count);
|
||||
RDI_U64 all_nodes_count = 0;
|
||||
RDI_NameMapNode *all_nodes = rdi_table_from_name(rdi, NameMapNodes, &all_nodes_count);
|
||||
out->buckets = all_buckets+mapptr->bucket_base_idx;
|
||||
out->nodes = all_nodes+mapptr->node_base_idx;
|
||||
out->bucket_count = mapptr->bucket_count;
|
||||
out->node_count = mapptr->node_count;
|
||||
if(mapptr->bucket_base_idx > all_buckets_count)
|
||||
{
|
||||
out->buckets = 0;
|
||||
out->bucket_count = 0;
|
||||
}
|
||||
if(mapptr->node_base_idx > all_nodes_count)
|
||||
{
|
||||
out->nodes = 0;
|
||||
out->node_count = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,49 +495,20 @@ rdi_matches_from_map_node(RDI_Parsed *p, RDI_NameMapNode *node, RDI_U32 *n_out)
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ High-Level Composite Lookup Functions
|
||||
|
||||
//- procedures
|
||||
|
||||
RDI_PROC RDI_U64
|
||||
rdi_first_voff_from_proc(RDI_Parsed *p, RDI_U32 proc_id)
|
||||
rdi_first_voff_from_proc_idx(RDI_Parsed *rdi, RDI_U32 proc_idx)
|
||||
{
|
||||
RDI_U64 result = 0;
|
||||
if(0 < proc_id && proc_id < p->procedures_count)
|
||||
{
|
||||
RDI_Procedure *proc = p->procedures + proc_id;
|
||||
RDI_U32 scope_id = proc->root_scope_idx;
|
||||
if(0 < scope_id && scope_id < p->scopes_count)
|
||||
{
|
||||
RDI_Scope *scope = p->scopes + scope_id;
|
||||
if(scope->voff_range_first < scope->voff_range_opl && scope->voff_range_first < p->scope_voffs_count)
|
||||
{
|
||||
result = p->scope_voffs[scope->voff_range_first];
|
||||
}
|
||||
}
|
||||
RDI_Procedure *procedure = rdi_element_from_name_idx(rdi, Procedures, proc_idx);
|
||||
RDI_Scope *scope = rdi_element_from_name_idx(rdi, Scopes, procedure->root_scope_idx);
|
||||
RDI_U64 *voffs = rdi_element_from_name_idx(rdi, ScopeVOffData, scope->voff_range_first);
|
||||
result = *voffs;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ Parser Helpers
|
||||
|
||||
RDI_PROC void*
|
||||
rdi_data_from_dsec(RDI_Parsed *parsed, RDI_U32 idx, RDI_U32 item_size, RDI_DataSectionTag expected_tag, RDI_U64 *count_out)
|
||||
{
|
||||
void *result = 0;
|
||||
RDI_U32 count_result = 0;
|
||||
if(0 < idx && idx < parsed->dsec_count)
|
||||
{
|
||||
RDI_DataSection *ds = parsed->dsecs + idx;
|
||||
if(ds->tag == expected_tag)
|
||||
{
|
||||
RDI_U64 encoded_opl = ds->off + ds->encoded_size;
|
||||
if(encoded_opl <= parsed->raw_data_size)
|
||||
{
|
||||
count_result = ds->unpacked_size/item_size;
|
||||
result = (parsed->raw_data + ds->off);
|
||||
}
|
||||
}
|
||||
}
|
||||
*count_out = count_result;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user