move per-source-file line maps to top-level sections, and move source line -> voff maps to separate top-level info table

This commit is contained in:
Ryan Fleury
2024-06-04 13:33:38 -07:00
parent f7e67a80c9
commit ebd5cf9e47
12 changed files with 338 additions and 232 deletions
+49 -36
View File
@@ -45,7 +45,7 @@ typedef int64_t RDI_S64;
// \"raddbg\0\0\"
#define RDI_MAGIC_CONSTANT 0x0000676264646172
#define RDI_ENCODING_VERSION 2
#define RDI_ENCODING_VERSION 3
////////////////////////////////////////////////////////////////
//~ Format Types & Functions
@@ -65,31 +65,32 @@ RDI_DataSectionTag_LineTables = 0x0008,
RDI_DataSectionTag_LineInfoVoffs = 0x0009,
RDI_DataSectionTag_LineInfoLines = 0x000A,
RDI_DataSectionTag_LineInfoColumns = 0x000B,
RDI_DataSectionTag_Units = 0x000C,
RDI_DataSectionTag_UnitVmap = 0x000D,
RDI_DataSectionTag_TypeNodes = 0x000E,
RDI_DataSectionTag_UDTs = 0x000F,
RDI_DataSectionTag_Members = 0x0010,
RDI_DataSectionTag_EnumMembers = 0x0011,
RDI_DataSectionTag_GlobalVariables = 0x0012,
RDI_DataSectionTag_GlobalVmap = 0x0013,
RDI_DataSectionTag_ThreadVariables = 0x0014,
RDI_DataSectionTag_Procedures = 0x0015,
RDI_DataSectionTag_Scopes = 0x0016,
RDI_DataSectionTag_ScopeVoffData = 0x0017,
RDI_DataSectionTag_ScopeVmap = 0x0018,
RDI_DataSectionTag_InlineSites = 0x0019,
RDI_DataSectionTag_Locals = 0x001A,
RDI_DataSectionTag_LocationBlocks = 0x001B,
RDI_DataSectionTag_LocationData = 0x001C,
RDI_DataSectionTag_NameMaps = 0x001D,
RDI_DataSectionTag_PRIMARY_COUNT = 0x001E,
RDI_DataSectionTag_SourceLineMaps = 0x000C,
RDI_DataSectionTag_SourceLineMapNumbers = 0x000D,
RDI_DataSectionTag_SourceLineMapRanges = 0x000E,
RDI_DataSectionTag_SourceLineMapVOffs = 0x000F,
RDI_DataSectionTag_Units = 0x0010,
RDI_DataSectionTag_UnitVmap = 0x0011,
RDI_DataSectionTag_TypeNodes = 0x0012,
RDI_DataSectionTag_UDTs = 0x0013,
RDI_DataSectionTag_Members = 0x0014,
RDI_DataSectionTag_EnumMembers = 0x0015,
RDI_DataSectionTag_GlobalVariables = 0x0016,
RDI_DataSectionTag_GlobalVmap = 0x0017,
RDI_DataSectionTag_ThreadVariables = 0x0018,
RDI_DataSectionTag_Procedures = 0x0019,
RDI_DataSectionTag_Scopes = 0x001A,
RDI_DataSectionTag_ScopeVoffData = 0x001B,
RDI_DataSectionTag_ScopeVmap = 0x001C,
RDI_DataSectionTag_InlineSites = 0x001D,
RDI_DataSectionTag_Locals = 0x001E,
RDI_DataSectionTag_LocationBlocks = 0x001F,
RDI_DataSectionTag_LocationData = 0x0020,
RDI_DataSectionTag_NameMaps = 0x0021,
RDI_DataSectionTag_PRIMARY_COUNT = 0x0022,
RDI_DataSectionTag_SECONDARY = 0x80000000,
RDI_DataSectionTag_LineMapNumbers = RDI_DataSectionTag_SECONDARY|0x0001,
RDI_DataSectionTag_LineMapRanges = RDI_DataSectionTag_SECONDARY|0x0002,
RDI_DataSectionTag_LineMapVoffs = RDI_DataSectionTag_SECONDARY|0x0003,
RDI_DataSectionTag_NameMapBuckets = RDI_DataSectionTag_SECONDARY|0x0004,
RDI_DataSectionTag_NameMapNodes = RDI_DataSectionTag_SECONDARY|0x0005,
RDI_DataSectionTag_NameMapBuckets = RDI_DataSectionTag_SECONDARY|0x0001,
RDI_DataSectionTag_NameMapNodes = RDI_DataSectionTag_SECONDARY|0x0002,
} RDI_DataSectionTagEnum;
typedef RDI_U32 RDI_DataSectionEncoding;
@@ -506,6 +507,10 @@ X(LineTables)\
X(LineInfoVoffs)\
X(LineInfoLines)\
X(LineInfoColumns)\
X(SourceLineMaps)\
X(SourceLineMapNumbers)\
X(SourceLineMapRanges)\
X(SourceLineMapVOffs)\
X(Units)\
X(UnitVmap)\
X(TypeNodes)\
@@ -526,9 +531,6 @@ X(LocationData)\
X(NameMaps)\
X(PRIMARY_COUNT)\
X(SECONDARY)\
X(LineMapNumbers)\
X(LineMapRanges)\
X(LineMapVoffs)\
X(NameMapBuckets)\
X(NameMapNodes)\
@@ -581,10 +583,7 @@ X(RDI_U32, source_file_idx)\
#define RDI_SourceFile_XList \
X(RDI_U32, file_path_node_idx)\
X(RDI_U32, normal_full_path_string_idx)\
X(RDI_U32, line_map_count)\
X(RDI_U32, line_map_nums_data_idx)\
X(RDI_U32, line_map_range_data_idx)\
X(RDI_U32, line_map_voff_data_idx)\
X(RDI_U32, source_line_map_idx)\
#define RDI_Unit_XList \
X(RDI_U32, unit_name_string_idx)\
@@ -611,6 +610,13 @@ X(RDI_U32, line_num)\
X(RDI_U16, col_first)\
X(RDI_U16, col_opl)\
#define RDI_SourceLineMapMemberTable \
X(RDI_U32, line_count)\
X(RDI_U32, voff_count)\
X(RDI_U32, line_map_nums_base_idx)\
X(RDI_U32, line_map_range_base_idx)\
X(RDI_U32, line_map_voff_base_idx)\
#define RDI_Language_XList \
X(NULL)\
X(C)\
@@ -958,10 +964,7 @@ struct RDI_SourceFile
{
RDI_U32 file_path_node_idx;
RDI_U32 normal_full_path_string_idx;
RDI_U32 line_map_count;
RDI_U32 line_map_nums_data_idx;
RDI_U32 line_map_range_data_idx;
RDI_U32 line_map_voff_data_idx;
RDI_U32 source_line_map_idx;
};
typedef struct RDI_Unit RDI_Unit;
@@ -1001,6 +1004,16 @@ RDI_U16 col_first;
RDI_U16 col_opl;
};
typedef struct RDI_SourceLineMap RDI_SourceLineMap;
struct RDI_SourceLineMap
{
RDI_U32 line_count;
RDI_U32 voff_count;
RDI_U32 line_map_nums_base_idx;
RDI_U32 line_map_range_base_idx;
RDI_U32 line_map_voff_base_idx;
};
typedef struct RDI_TypeNode RDI_TypeNode;
struct RDI_TypeNode
{
+30 -24
View File
@@ -145,6 +145,7 @@ rdi_parse(RDI_U8 *data, RDI_U64 size, RDI_Parsed *out)
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);
@@ -185,6 +186,8 @@ rdi_parse(RDI_U8 *data, RDI_U64 size, RDI_Parsed *out)
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; }
@@ -329,36 +332,39 @@ rdi_line_info_idx_from_voff(RDI_ParsedLineTable *line_info, RDI_U64 voff)
}
RDI_PROC void
rdi_line_map_from_source_file(RDI_Parsed *p, RDI_SourceFile *srcfile, RDI_ParsedLineMap *out)
rdi_parsed_from_source_line_map(RDI_Parsed *p, RDI_SourceLineMap *map, RDI_ParsedSourceLineMap *out)
{
RDI_U64 num_count = 0;
RDI_U32 *nums = (RDI_U32*)rdi_data_from_dsec(p, srcfile->line_map_nums_data_idx, sizeof(RDI_U32),
RDI_DataSectionTag_LineMapNumbers,
&num_count);
//- 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_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_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_opl = all_voffs + all_voffs_count;
RDI_U64 range_count = 0;
RDI_U32 *ranges = (RDI_U32*)rdi_data_from_dsec(p, srcfile->line_map_range_data_idx, sizeof(RDI_U32),
RDI_DataSectionTag_LineMapRanges,
&range_count);
//- rjf: extract ranges of top-level tables belonging to this line map
RDI_U32 *map_nums = all_nums + map->line_map_nums_base_idx;
RDI_U32 *map_rngs = all_rngs + map->line_map_range_base_idx;
RDI_U64 *map_voffs= all_voffs+ map->line_map_voff_base_idx;
RDI_U64 lines_count = (RDI_U64)map->line_count;
RDI_U64 voffs_count = (RDI_U64)map->voff_count;
if(map_nums >= all_nums_opl) {map_nums = all_nums; lines_count = 0;}
if(map_rngs >= all_rngs_opl) {map_rngs = all_rngs; lines_count = 0;}
if(map_voffs>= all_voffs_opl){map_voffs= all_voffs;voffs_count = 0;}
RDI_U64 voff_count = 0;
RDI_U64 *voffs = (RDI_U64*)rdi_data_from_dsec(p, srcfile->line_map_voff_data_idx, sizeof(RDI_U64),
RDI_DataSectionTag_LineMapVoffs,
&voff_count);
RDI_U32 count_a = (range_count > 0)?(range_count - 1):0;
RDI_U32 count_b = rdi_parse__min(count_a, num_count);
RDI_U32 count = rdi_parse__min(count_b, srcfile->line_map_count);
out->nums = nums;
out->ranges = ranges;
out->voffs = voffs;
out->count = count;
out->voff_count = voff_count;
//- rjf: fill result
out->nums = map_nums;
out->ranges = map_rngs;
out->voffs = map_voffs;
out->count = lines_count;
out->voff_count = voffs_count;
}
RDI_PROC RDI_U64*
rdi_line_voffs_from_num(RDI_ParsedLineMap *map, RDI_U32 linenum, RDI_U32 *n_out)
rdi_line_voffs_from_num(RDI_ParsedSourceLineMap *map, RDI_U32 linenum, RDI_U32 *n_out)
{
RDI_U64 *result = 0;
*n_out = 0;
+7 -4
View File
@@ -53,6 +53,8 @@ struct RDI_Parsed
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;
@@ -110,8 +112,8 @@ struct RDI_ParsedLineTable
RDI_U64 col_count;
};
typedef struct RDI_ParsedLineMap RDI_ParsedLineMap;
struct RDI_ParsedLineMap
typedef struct RDI_ParsedSourceLineMap RDI_ParsedSourceLineMap;
struct RDI_ParsedSourceLineMap
{
// NOTE: Mapping LINE_NUMBER -> VOFFs
//
@@ -146,6 +148,7 @@ 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};
@@ -186,8 +189,8 @@ RDI_PROC RDI_U32 *rdi_idx_run_from_first_count(RDI_Parsed *parsed, RDI_U32 first
//- line info
RDI_PROC void rdi_parsed_from_line_table(RDI_Parsed *p, 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_line_map_from_source_file(RDI_Parsed *p, RDI_SourceFile *srcfile, RDI_ParsedLineMap *out);
RDI_PROC RDI_U64 *rdi_line_voffs_from_num(RDI_ParsedLineMap *map, RDI_U32 linenum, RDI_U32 *n_out);
RDI_PROC void rdi_parsed_from_source_line_map(RDI_Parsed *p, 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);