initial pass for compression in converter; decompression in debuggerdbgi layer

This commit is contained in:
Ryan Fleury
2024-04-10 09:33:55 -07:00
parent d560f8c734
commit 56bc399fd5
12 changed files with 1824 additions and 67 deletions
+1
View File
@@ -168,6 +168,7 @@
# define ins_atomic_u64_dec_eval(x) InterlockedDecrement64((volatile __int64 *)(x))
# define ins_atomic_u64_eval_assign(x,c) InterlockedExchange64((volatile __int64 *)(x),(c))
# define ins_atomic_u64_add_eval(x,c) InterlockedAdd64((volatile __int64 *)(x), c)
# define ins_atomic_u64_eval_cond_assign(x,k,c) InterlockedCompareExchange64((volatile __int64 *)(x),(k),(c))
# define ins_atomic_u32_eval(x,c) InterlockedAdd((volatile LONG *)(x), 0)
# define ins_atomic_u32_eval_assign(x,c) InterlockedExchange((volatile LONG *)(x),(c))
# define ins_atomic_u32_eval_cond_assign(x,k,c) InterlockedCompareExchange((volatile LONG *)(x),(k),(c))
+74 -6
View File
@@ -859,6 +859,13 @@ dbgi_parse_thread_entry_point(void *p)
os_file_close(file);
}
//- rjf: heuristically choose compression settings
B32 should_compress = 0;
if(og_dbg_props.size > MB(64))
{
should_compress = 1;
}
//- rjf: raddbg file not up-to-date? we need to generate it
if(do_task)
{
@@ -883,6 +890,10 @@ dbgi_parse_thread_entry_point(void *p)
str8_list_pushf(scratch.arena, &opts.cmd_line, "raddbg");
str8_list_pushf(scratch.arena, &opts.cmd_line, "--convert");
str8_list_pushf(scratch.arena, &opts.cmd_line, "--quiet");
if(should_compress)
{
str8_list_pushf(scratch.arena, &opts.cmd_line, "--compress");
}
//str8_list_pushf(scratch.arena, &opts.cmd_line, "--capture");
str8_list_pushf(scratch.arena, &opts.cmd_line, "--exe:%S", exe_path);
str8_list_pushf(scratch.arena, &opts.cmd_line, "--pdb:%S", og_dbg_path);
@@ -1020,15 +1031,72 @@ dbgi_parse_thread_entry_point(void *p)
do_task = 0;
}
//- rjf: parse raddbg info
RDI_Parsed rdi_parsed = dbgi_parse_nil.rdi;
U64 arch_addr_size = 8;
//- rjf: initial parse of raddbg info
RDI_Parsed rdi_parsed_maybe_compressed = dbgi_parse_nil.rdi;
if(do_task)
{
RDI_ParseStatus parse_status = rdi_parse((U8 *)raddbgi_file_base, raddbgi_file_props.size, &rdi_parsed);
if(rdi_parsed.top_level_info != 0)
RDI_ParseStatus parse_status = rdi_parse((U8 *)raddbgi_file_base, raddbgi_file_props.size, &rdi_parsed_maybe_compressed);
(void)parse_status;
}
//- rjf: decompress, if necessary
RDI_Parsed rdi_parsed = rdi_parsed_maybe_compressed;
if(do_task)
{
U64 decompressed_size = raddbgi_file_props.size;
for(U64 dsec_idx = 0; dsec_idx < rdi_parsed_maybe_compressed.dsec_count; dsec_idx += 1)
{
arch_addr_size = rdi_addr_size_from_arch(rdi_parsed.top_level_info->architecture);
decompressed_size += (rdi_parsed_maybe_compressed.dsecs[dsec_idx].unpacked_size - rdi_parsed_maybe_compressed.dsecs[dsec_idx].encoded_size);
}
if(decompressed_size > raddbgi_file_props.size)
{
U8 *decompressed_data = push_array_no_zero(parse_arena, U8, decompressed_size);
// rjf: copy header
RDI_Header *src_header = (RDI_Header *)raddbgi_file_base;
RDI_Header *dst_header = (RDI_Header *)decompressed_data;
{
MemoryCopy(dst_header, src_header, sizeof(RDI_Header));
}
// rjf: copy & adjust sections for decompressed version
if(rdi_parsed_maybe_compressed.dsec_count != 0)
{
RDI_DataSection *dsec_base = (RDI_DataSection *)(decompressed_data + dst_header->data_section_off);
MemoryCopy(dsec_base, (U8 *)raddbgi_file_base + src_header->data_section_off, sizeof(RDI_DataSection) * rdi_parsed_maybe_compressed.dsec_count);
U64 off = dst_header->data_section_off + sizeof(RDI_DataSection) * rdi_parsed_maybe_compressed.dsec_count;
off += 7;
off -= off%8;
for(U64 idx = 0; idx < rdi_parsed_maybe_compressed.dsec_count; idx += 1)
{
dsec_base[idx].encoding = RDI_DataSectionEncoding_Unpacked;
dsec_base[idx].off = off;
dsec_base[idx].encoded_size = dsec_base[idx].unpacked_size;
off += dsec_base[idx].unpacked_size;
off += 7;
off -= off%8;
}
}
// rjf: decompress sections into new decompressed file buffer
if(rdi_parsed_maybe_compressed.dsec_count != 0)
{
RDI_DataSection *src_first = rdi_parsed_maybe_compressed.dsecs;
RDI_DataSection *dst_first = (RDI_DataSection *)(decompressed_data + dst_header->data_section_off);
RDI_DataSection *src_opl = src_first + rdi_parsed_maybe_compressed.dsec_count;
RDI_DataSection *dst_opl = dst_first + rdi_parsed_maybe_compressed.dsec_count;
for(RDI_DataSection *src = src_first, *dst = dst_first;
src < src_opl && dst < dst_opl;
src += 1, dst += 1)
{
rr_lzb_simple_decode((U8*)raddbgi_file_base + src->off, src->encoded_size,
decompressed_data + dst->off, dst->unpacked_size);
}
}
// rjf: re-parse
RDI_ParseStatus parse_status = rdi_parse(decompressed_data, decompressed_size, &rdi_parsed);
(void)parse_status;
}
}
+2 -1
View File
@@ -300,7 +300,8 @@ typedef enum RDI_DataSectionTagEnum{
#define RDI_DataSectionEncodingXList(X) \
X(Unpacked, 0)
X(Unpacked, 0)\
X(LZB, 1)
typedef RDI_U32 RDI_DataSectionEncoding;
typedef enum RDI_DataSectionEncodingEnum{
+10 -10
View File
@@ -537,23 +537,23 @@ rdi_first_voff_from_proc(RDI_Parsed *p, RDI_U32 proc_id){
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){
RDI_U64 *count_out)
{
void *result = 0;
RDI_U32 count_result = 0;
// TODO(allen): need a version of this that works with encodings other than "Unpacked"
if (0 < idx && idx < parsed->dsec_count){
if(0 < idx && idx < parsed->dsec_count)
{
RDI_DataSection *ds = parsed->dsecs + idx;
if (ds->tag == expected_tag){
RDI_U64 opl = ds->off + ds->encoded_size;
if (opl <= parsed->raw_data_size){
count_result = ds->encoded_size/item_size;
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);
}
+44 -42
View File
@@ -1744,11 +1744,13 @@ rdim_bake_section_list_push(RDIM_Arena *arena, RDIM_BakeSectionList *list)
}
RDI_PROC RDIM_BakeSection *
rdim_bake_section_list_push_new(RDIM_Arena *arena, RDIM_BakeSectionList *list, void *data, RDI_U64 size, RDI_DataSectionTag tag, RDI_U64 tag_idx)
rdim_bake_section_list_push_new_unpacked(RDIM_Arena *arena, RDIM_BakeSectionList *list, void *data, RDI_U64 size, RDI_DataSectionTag tag, RDI_U64 tag_idx)
{
RDIM_BakeSection *section = rdim_bake_section_list_push(arena, list);
section->data = data;
section->size = size;
section->encoding = RDI_DataSectionEncoding_Unpacked;
section->encoded_size = size;
section->unpacked_size = size;
section->tag = tag;
section->tag_idx = tag_idx;
return section;
@@ -2142,7 +2144,7 @@ rdim_bake_top_level_info_section_list_from_params(RDIM_Arena *arena, RDIM_BakeSt
dst_tli->exe_name_string_idx = rdim_bake_idx_from_string(strings, src_tli->exe_name);
dst_tli->exe_hash = src_tli->exe_hash;
dst_tli->voff_max = src_tli->voff_max;
rdim_bake_section_list_push_new(arena, &sections, dst_tli, sizeof(*dst_tli), RDI_DataSectionTag_TopLevelInfo, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, dst_tli, sizeof(*dst_tli), RDI_DataSectionTag_TopLevelInfo, 0);
return sections;
}
@@ -2166,7 +2168,7 @@ rdim_bake_binary_section_section_list_from_params(RDIM_Arena *arena, RDIM_BakeSt
dst->foff_first = src->foff_first;
dst->foff_opl = src->foff_opl;
}
rdim_bake_section_list_push_new(arena, &sections, dst_base, sizeof(*dst_base)*dst_idx, RDI_DataSectionTag_BinarySections, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, dst_base, sizeof(*dst_base)*dst_idx, RDI_DataSectionTag_BinarySections, 0);
return sections;
}
@@ -2286,11 +2288,11 @@ rdim_bake_section_list_from_unit(RDIM_Arena *arena, RDIM_Unit *unit)
//- rjf: build line info sections
//
U64 unit_idx = rdim_idx_from_unit(unit);
rdim_bake_section_list_push_new(arena, &sections, unit_voffs, sizeof(RDI_U64)*(unit_line_count+1), RDI_DataSectionTag_LineInfoVoffs, unit_idx);
rdim_bake_section_list_push_new(arena, &sections, unit_lines, sizeof(RDI_Line)*unit_line_count, RDI_DataSectionTag_LineInfoData, unit_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, unit_voffs, sizeof(RDI_U64)*(unit_line_count+1), RDI_DataSectionTag_LineInfoVoffs, unit_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, unit_lines, sizeof(RDI_Line)*unit_line_count, RDI_DataSectionTag_LineInfoData, unit_idx);
if(unit_cols != 0)
{
rdim_bake_section_list_push_new(arena, &sections, unit_cols, sizeof(RDI_Column)*unit_line_count, RDI_DataSectionTag_LineInfoColumns, unit_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, unit_cols, sizeof(RDI_Column)*unit_line_count, RDI_DataSectionTag_LineInfoColumns, unit_idx);
}
return sections;
@@ -2417,11 +2419,11 @@ rdim_bake_unit_top_level_section_list_from_params(RDIM_Arena *arena, RDIM_BakeSt
////////////////////////
//- rjf: build line info sections
//
rdim_bake_section_list_push_new(arena, &sections, unit_voffs, sizeof(RDI_U64)*(unit_line_count+1), RDI_DataSectionTag_LineInfoVoffs, dst_idx);
rdim_bake_section_list_push_new(arena, &sections, unit_lines, sizeof(RDI_Line)*unit_line_count, RDI_DataSectionTag_LineInfoData, dst_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, unit_voffs, sizeof(RDI_U64)*(unit_line_count+1), RDI_DataSectionTag_LineInfoVoffs, dst_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, unit_lines, sizeof(RDI_Line)*unit_line_count, RDI_DataSectionTag_LineInfoData, dst_idx);
if(unit_cols != 0)
{
rdim_bake_section_list_push_new(arena, &sections, unit_cols, sizeof(RDI_Column)*unit_line_count, RDI_DataSectionTag_LineInfoColumns, dst_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, unit_cols, sizeof(RDI_Column)*unit_line_count, RDI_DataSectionTag_LineInfoColumns, dst_idx);
}
////////////////////////
@@ -2439,7 +2441,7 @@ rdim_bake_unit_top_level_section_list_from_params(RDIM_Arena *arena, RDIM_BakeSt
dst->line_info_col_data_idx = (RDI_U32)rdim_bake_section_idx_from_params_tag_idx(params, RDI_DataSectionTag_LineInfoColumns, dst_idx); // TODO(rjf): @u64_to_u32
}
}
rdim_bake_section_list_push_new(arena, &sections, dst_base, sizeof(*dst_base)*dst_idx, RDI_DataSectionTag_Units, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, dst_base, sizeof(*dst_base)*dst_idx, RDI_DataSectionTag_Units, 0);
return sections;
}
@@ -2514,7 +2516,7 @@ rdim_bake_unit_vmap_section_list_from_params(RDIM_Arena *arena, RDIM_BakeParams
//- rjf: build section
RDIM_BakeSectionList sections = {0};
RDI_U64 unit_vmap_size = sizeof(unit_vmap.vmap[0])*(unit_vmap.count+1);
rdim_bake_section_list_push_new(arena, &sections, unit_vmap.vmap, unit_vmap_size, RDI_DataSectionTag_UnitVmap, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, unit_vmap.vmap, unit_vmap_size, RDI_DataSectionTag_UnitVmap, 0);
return sections;
}
@@ -2689,9 +2691,9 @@ rdim_bake_src_file_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringMa
dst_file->line_map_nums_data_idx = (RDI_U32)rdim_bake_section_idx_from_params_tag_idx(params, RDI_DataSectionTag_LineMapNumbers, dst_file_idx); // TODO(rjf): @u64_to_u32
dst_file->line_map_range_data_idx = (RDI_U32)rdim_bake_section_idx_from_params_tag_idx(params, RDI_DataSectionTag_LineMapRanges, dst_file_idx); // TODO(rjf): @u64_to_u32
dst_file->line_map_voff_data_idx = (RDI_U32)rdim_bake_section_idx_from_params_tag_idx(params, RDI_DataSectionTag_LineMapVoffs, dst_file_idx); // TODO(rjf): @u64_to_u32
rdim_bake_section_list_push_new(arena, &sections, src_file_line_nums, sizeof(*src_file_line_nums)*src_file_line_count, RDI_DataSectionTag_LineMapNumbers, dst_file_idx);
rdim_bake_section_list_push_new(arena, &sections, src_file_line_ranges, sizeof(*src_file_line_ranges)*(src_file_line_count + 1), RDI_DataSectionTag_LineMapRanges, dst_file_idx);
rdim_bake_section_list_push_new(arena, &sections, src_file_voffs, sizeof(*src_file_voffs)*src_file_voff_count, RDI_DataSectionTag_LineMapVoffs, dst_file_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, src_file_line_nums, sizeof(*src_file_line_nums)*src_file_line_count, RDI_DataSectionTag_LineMapNumbers, dst_file_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, src_file_line_ranges, sizeof(*src_file_line_ranges)*(src_file_line_count + 1), RDI_DataSectionTag_LineMapRanges, dst_file_idx);
rdim_bake_section_list_push_new_unpacked(arena, &sections, src_file_voffs, sizeof(*src_file_voffs)*src_file_voff_count, RDI_DataSectionTag_LineMapVoffs, dst_file_idx);
}
}
}
@@ -2699,7 +2701,7 @@ rdim_bake_src_file_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringMa
////////////////////////////
//- rjf: build section for all source files
//
rdim_bake_section_list_push_new(arena, &sections, dst_files, sizeof(RDI_SourceFile)*dst_files_count, RDI_DataSectionTag_SourceFiles, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, dst_files, sizeof(RDI_SourceFile)*dst_files_count, RDI_DataSectionTag_SourceFiles, 0);
return sections;
}
@@ -2775,7 +2777,7 @@ rdim_bake_type_node_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringM
//- rjf: build sections
RDIM_BakeSectionList sections = {0};
rdim_bake_section_list_push_new(arena, &sections, type_nodes, sizeof(RDI_TypeNode)*(params->types.total_count+1), RDI_DataSectionTag_TypeNodes, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, type_nodes, sizeof(RDI_TypeNode)*(params->types.total_count+1), RDI_DataSectionTag_TypeNodes, 0);
return sections;
}
@@ -2843,9 +2845,9 @@ rdim_bake_udt_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringMapTigh
//- rjf: build sections
RDIM_BakeSectionList sections = {0};
rdim_bake_section_list_push_new(arena, &sections, udts, sizeof(RDI_UDT) * (params->udts.total_count+1), RDI_DataSectionTag_UDTs, 0);
rdim_bake_section_list_push_new(arena, &sections, members , sizeof(RDI_Member) * (params->udts.total_member_count+1), RDI_DataSectionTag_Members, 0);
rdim_bake_section_list_push_new(arena, &sections, enum_members, sizeof(RDI_EnumMember) * (params->udts.total_enum_val_count+1), RDI_DataSectionTag_EnumMembers, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, udts, sizeof(RDI_UDT) * (params->udts.total_count+1), RDI_DataSectionTag_UDTs, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, members , sizeof(RDI_Member) * (params->udts.total_member_count+1), RDI_DataSectionTag_Members, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, enum_members, sizeof(RDI_EnumMember) * (params->udts.total_enum_val_count+1), RDI_DataSectionTag_EnumMembers, 0);
return sections;
}
@@ -2887,7 +2889,7 @@ rdim_bake_global_variable_section_list_from_params(RDIM_Arena *arena, RDIM_BakeS
//- rjf: build sections
RDIM_BakeSectionList sections = {0};
rdim_bake_section_list_push_new(arena, &sections, global_variables, sizeof(RDI_GlobalVariable)*(params->global_variables.total_count+1), RDI_DataSectionTag_GlobalVariables, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, global_variables, sizeof(RDI_GlobalVariable)*(params->global_variables.total_count+1), RDI_DataSectionTag_GlobalVariables, 0);
return sections;
}
@@ -2966,7 +2968,7 @@ rdim_bake_global_vmap_section_list_from_params(RDIM_Arena *arena, RDIM_BakeParam
//- rjf: build sections
RDIM_BakeSectionList sections = {0};
rdim_bake_section_list_push_new(arena, &sections, global_vmap.vmap, sizeof(RDI_VMapEntry)*(global_vmap.count+1), RDI_DataSectionTag_GlobalVmap, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, global_vmap.vmap, sizeof(RDI_VMapEntry)*(global_vmap.count+1), RDI_DataSectionTag_GlobalVmap, 0);
return sections;
}
@@ -3008,7 +3010,7 @@ rdim_bake_thread_variable_section_list_from_params(RDIM_Arena *arena, RDIM_BakeS
//- rjf: build sections
RDIM_BakeSectionList sections = {0};
rdim_bake_section_list_push_new(arena, &sections, thread_variables, sizeof(RDI_ThreadVariable)*(params->thread_variables.total_count+1), RDI_DataSectionTag_ThreadVariables, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, thread_variables, sizeof(RDI_ThreadVariable)*(params->thread_variables.total_count+1), RDI_DataSectionTag_ThreadVariables, 0);
return sections;
}
@@ -3051,7 +3053,7 @@ rdim_bake_procedure_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringM
//- rjf: build sections
RDIM_BakeSectionList sections = {0};
rdim_bake_section_list_push_new(arena, &sections, procedures, sizeof(RDI_Procedure)*(params->procedures.total_count+1), RDI_DataSectionTag_Procedures, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, procedures, sizeof(RDI_Procedure)*(params->procedures.total_count+1), RDI_DataSectionTag_Procedures, 0);
return sections;
}
@@ -3218,11 +3220,11 @@ rdim_bake_scope_section_list_from_params(RDIM_Arena *arena, RDIM_BakeStringMapTi
RDIM_BakeSectionList sections = {0};
RDIM_ProfScope("push all symbol info sections")
{
rdim_bake_section_list_push_new(arena, &sections, scopes, sizeof(RDI_Scope) * (params->scopes.total_count+1), RDI_DataSectionTag_Scopes, 0);
rdim_bake_section_list_push_new(arena, &sections, scope_voffs, sizeof(RDI_U64) * (params->scopes.scope_voff_count+1), RDI_DataSectionTag_ScopeVoffData, 0);
rdim_bake_section_list_push_new(arena, &sections, locals, sizeof(RDI_Local) * (params->scopes.local_count+1), RDI_DataSectionTag_Locals, 0);
rdim_bake_section_list_push_new(arena, &sections, location_blocks, sizeof(RDI_LocationBlock) * (params->scopes.location_count+1), RDI_DataSectionTag_LocationBlocks, 0);
rdim_bake_section_list_push_new(arena, &sections, location_data_blob.str, location_data_blob.size, RDI_DataSectionTag_LocationData, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, scopes, sizeof(RDI_Scope) * (params->scopes.total_count+1), RDI_DataSectionTag_Scopes, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, scope_voffs, sizeof(RDI_U64) * (params->scopes.scope_voff_count+1), RDI_DataSectionTag_ScopeVoffData, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, locals, sizeof(RDI_Local) * (params->scopes.local_count+1), RDI_DataSectionTag_Locals, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, location_blocks, sizeof(RDI_LocationBlock) * (params->scopes.location_count+1), RDI_DataSectionTag_LocationBlocks, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, location_data_blob.str, location_data_blob.size, RDI_DataSectionTag_LocationData, 0);
}
rdim_scratch_end(scratch);
return sections;
@@ -3280,7 +3282,7 @@ rdim_bake_scope_vmap_section_list_from_params(RDIM_Arena *arena, RDIM_BakeParams
//- rjf: build sections
RDIM_BakeSectionList sections = {0};
rdim_bake_section_list_push_new(arena, &sections, scope_vmap.vmap, sizeof(RDI_VMapEntry)*(scope_vmap.count+1), RDI_DataSectionTag_ScopeVmap, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, scope_vmap.vmap, sizeof(RDI_VMapEntry)*(scope_vmap.count+1), RDI_DataSectionTag_ScopeVmap, 0);
return sections;
}
@@ -3322,7 +3324,7 @@ rdim_bake_top_level_name_map_section_list_from_params_maps(RDIM_Arena *arena, RD
}
// rjf: push section for all name maps
rdim_bake_section_list_push_new(arena, &sections, dst_maps, sizeof(RDI_NameMap)*name_map_count, RDI_DataSectionTag_NameMaps, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, dst_maps, sizeof(RDI_NameMap)*name_map_count, RDI_DataSectionTag_NameMaps, 0);
return sections;
}
@@ -3424,8 +3426,8 @@ rdim_bake_name_map_section_list_from_params_kind_map(RDIM_Arena *arena, RDIM_Bak
}
// rjf: sections for buckets/nodes
rdim_bake_section_list_push_new(arena, &sections, baked_buckets, sizeof(RDI_NameMapBucket)* baked_buckets_count, RDI_DataSectionTag_NameMapBuckets, (RDI_U64)k);
rdim_bake_section_list_push_new(arena, &sections, baked_nodes, sizeof(RDI_NameMapNode) * baked_nodes_count, RDI_DataSectionTag_NameMapNodes, (RDI_U64)k);
rdim_bake_section_list_push_new_unpacked(arena, &sections, baked_buckets, sizeof(RDI_NameMapBucket)* baked_buckets_count, RDI_DataSectionTag_NameMapBuckets, (RDI_U64)k);
rdim_bake_section_list_push_new_unpacked(arena, &sections, baked_nodes, sizeof(RDI_NameMapNode) * baked_nodes_count, RDI_DataSectionTag_NameMapNodes, (RDI_U64)k);
}
return sections;
}
@@ -3461,7 +3463,7 @@ rdim_bake_file_path_section_list_from_path_tree(RDIM_Arena *arena, RDIM_BakeStri
}
}
RDIM_BakeSectionList sections = {0};
rdim_bake_section_list_push_new(arena, &sections, dst_nodes, sizeof(RDI_FilePathNode)*dst_nodes_count, RDI_DataSectionTag_FilePathNodes, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, dst_nodes, sizeof(RDI_FilePathNode)*dst_nodes_count, RDI_DataSectionTag_FilePathNodes, 0);
return sections;
}
@@ -3507,8 +3509,8 @@ rdim_bake_string_section_list_from_string_map(RDIM_Arena *arena, RDIM_BakeString
}
}
}
rdim_bake_section_list_push_new(arena, &sections, str_offs, sizeof(RDI_U32)*(strings->total_count+1), RDI_DataSectionTag_StringTable, 0);
rdim_bake_section_list_push_new(arena, &sections, buf, off_cursor, RDI_DataSectionTag_StringData, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, str_offs, sizeof(RDI_U32)*(strings->total_count+1), RDI_DataSectionTag_StringTable, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, buf, off_cursor, RDI_DataSectionTag_StringData, 0);
return sections;
}
@@ -3530,7 +3532,7 @@ rdim_bake_idx_run_section_list_from_idx_run_map(RDIM_Arena *arena, RDIM_BakeIdxR
out_ptr += node->count;
}
}
rdim_bake_section_list_push_new(arena, &sections, idx_data, sizeof(RDI_U32)*idx_runs->idx_count, RDI_DataSectionTag_IndexRuns, 0);
rdim_bake_section_list_push_new_unpacked(arena, &sections, idx_data, sizeof(RDI_U32)*idx_runs->idx_count, RDI_DataSectionTag_IndexRuns, 0);
return sections;
}
@@ -3591,17 +3593,17 @@ rdim_serialized_strings_from_params_bake_section_list(RDIM_Arena *arena, RDIM_Ba
if(src == 0) { continue; }
RDI_DataSection *dst = rdi_sections+dst_idx;
U64 data_section_off = 0;
if(src->size != 0)
if(src->encoded_size != 0)
{
rdim_str8_list_push_align(arena, &strings, 8);
data_section_off = strings.total_size;
rdim_str8_list_push(arena, &strings, rdim_str8((RDI_U8 *)src->data, src->size));
rdim_str8_list_push(arena, &strings, rdim_str8((RDI_U8 *)src->data, src->encoded_size));
}
dst->tag = src->tag;
dst->encoding = RDI_DataSectionEncoding_Unpacked;
dst->encoding = src->encoding;
dst->off = data_section_off;
dst->encoded_size = src->size;
dst->unpacked_size = src->size;
dst->encoded_size = src->encoded_size;
dst->unpacked_size = src->unpacked_size;
}
rdim_scratch_end(scratch);
+4 -2
View File
@@ -811,7 +811,9 @@ typedef struct RDIM_BakeSection RDIM_BakeSection;
struct RDIM_BakeSection
{
void *data;
RDI_U64 size;
RDI_DataSectionEncoding encoding;
RDI_U64 encoded_size;
RDI_U64 unpacked_size;
RDI_DataSectionTag tag;
RDI_U64 tag_idx;
};
@@ -1153,7 +1155,7 @@ RDI_PROC void rdim_bake_name_map_push(RDIM_Arena *arena, RDIM_BakeNameMap *map,
//~ rjf: [Baking Helpers] Data Section List Building Helpers
RDI_PROC RDIM_BakeSection *rdim_bake_section_list_push(RDIM_Arena *arena, RDIM_BakeSectionList *list);
RDI_PROC RDIM_BakeSection *rdim_bake_section_list_push_new(RDIM_Arena *arena, RDIM_BakeSectionList *list, void *data, RDI_U64 size, RDI_DataSectionTag tag, RDI_U64 tag_idx);
RDI_PROC RDIM_BakeSection *rdim_bake_section_list_push_new_unpacked(RDIM_Arena *arena, RDIM_BakeSectionList *list, void *data, RDI_U64 size, RDI_DataSectionTag tag, RDI_U64 tag_idx);
RDI_PROC void rdim_bake_section_list_concat_in_place(RDIM_BakeSectionList *dst, RDIM_BakeSectionList *to_push);
////////////////////////////////
+11 -2
View File
@@ -16,9 +16,11 @@
//- rjf: [lib]
#include "lib_raddbgi_format/raddbgi_format.h"
#include "lib_raddbgi_format/raddbgi_format_parse.h"
#include "lib_raddbgi_format/raddbgi_format.c"
#include "lib_raddbgi_format/raddbgi_format_parse.h"
#include "lib_raddbgi_format/raddbgi_format_parse.c"
#include "third_party/rad_lzb_simple/rad_lzb_simple.h"
#include "third_party/rad_lzb_simple/rad_lzb_simple.c"
//- rjf: [h]
#include "base/base_inc.h"
@@ -389,8 +391,15 @@ entry_point(CmdLine *cmd_line)
bake2srlz = p2r_bake(scratch.arena, convert2bake);
}
//- rjf: compress
P2R_Bake2Serialize *bake2srlz_compressed = bake2srlz;
if(cmd_line_has_flag(cmd_line, str8_lit("compress"))) ProfScope("compress")
{
bake2srlz_compressed = p2r_compress(scratch.arena, bake2srlz);
}
//- rjf: serialize
String8List serialize_out = rdim_serialized_strings_from_params_bake_section_list(scratch.arena, &convert2bake->bake_params, &bake2srlz->sections);
String8List serialize_out = rdim_serialized_strings_from_params_bake_section_list(scratch.arena, &convert2bake->bake_params, &bake2srlz_compressed->sections);
//- rjf: write
if(out_file_is_good)
+98
View File
@@ -95,11 +95,54 @@ p2r_user2convert_from_cmdln(Arena *arena, CmdLine *cmdline)
}
}
//- rjf: define string -> flag bits
#define FlagNameMapXList \
Case("sections", BinarySections)\
Case("units", Units)\
Case("procedures", Procedures)\
Case("globals", GlobalVariables)\
Case("threadvars", ThreadVariables)\
Case("scopes", Scopes)\
Case("locals", Locals)\
Case("types", Types)\
Case("udts", UDTs)\
Case("lines", LineInfo)\
Case("globals_name_map", GlobalVariableNameMap)\
Case("threadvars_name_map", ThreadVariableNameMap)\
Case("procedure_name_map", ProcedureNameMap)\
Case("type_name_map", TypeNameMap)\
Case("link_name_map", LinkNameProcedureNameMap)\
Case("source_path_name_map",NormalSourcePathNameMap)\
//- rjf: get flags
{
result->flags = P2R_ConvertFlag_All;
String8List only_names = cmd_line_strings(cmdline, str8_lit("only"));
String8List omit_names = cmd_line_strings(cmdline, str8_lit("only"));
if(only_names.node_count != 0)
{
result->flags = 0;
for(String8Node *n = only_names.first; n != 0; n = n->next)
{
String8 string = n->string;
#define Case(str, flag) if(str8_match(string, str8_lit(str), StringMatchFlag_CaseInsensitive)) {result->flags |= P2R_ConvertFlag_##flag;}
FlagNameMapXList;
#undef Case
}
}
if(omit_names.node_count != 0)
{
for(String8Node *n = omit_names.first; n != 0; n = n->next)
{
String8 string = n->string;
#define Case(str, flag) if(str8_match(string, str8_lit(str), StringMatchFlag_CaseInsensitive)) {result->flags &= ~P2R_ConvertFlag_##flag;}
FlagNameMapXList;
#undef Case
}
}
}
#undef FlagNameMapXList
return result;
}
@@ -4238,3 +4281,58 @@ p2r_bake(Arena *arena, P2R_Convert2Bake *in)
scratch_end(scratch);
return out;
}
////////////////////////////////
//~ rjf: Top-Level Compression Entry Point
internal P2R_Bake2Serialize *
p2r_compress(Arena *arena, P2R_Bake2Serialize *in)
{
RDIM_BakeSectionList prepack_sections = in->sections;
RDIM_BakeSectionList postpack_sections = {0};
{
//- rjf: set up compression context
rr_lzb_simple_context ctx = {0};
ctx.m_tableSizeBits = 14;
ctx.m_hashTable = push_array(arena, U16, 1<<ctx.m_tableSizeBits);
//- rjf: compress, or just copy, all sections
for(RDIM_BakeSectionNode *src_n = prepack_sections.first; src_n != 0; src_n = src_n->next)
{
RDIM_BakeSection *src = &src_n->v;
// rjf: push new section
RDIM_BakeSection *dst = rdim_bake_section_list_push(arena, &postpack_sections);
// rjf: unpack uncompressed section info
void *data = src->data;
RDI_DataSectionEncoding encoding = src->encoding;
RDI_U64 encoded_size = src->encoded_size;
RDI_U64 unpacked_size = src->unpacked_size;
// rjf: determine if this section should be compressed
B32 should_compress = 1;
// rjf: compress if needed
if(should_compress)
{
MemoryZero(ctx.m_hashTable, sizeof(U16)*(1<<ctx.m_tableSizeBits));
void *raw_data = data;
data = push_array_no_zero(arena, U8, unpacked_size);
encoded_size = rr_lzb_simple_encode_veryfast(&ctx, raw_data, unpacked_size, data);
encoding = RDI_DataSectionEncoding_LZB;
}
// rjf: fill
dst->data = data;
dst->encoding = encoding;
dst->encoded_size = encoded_size;
dst->unpacked_size = unpacked_size;
dst->tag = src->tag;
dst->tag_idx = src->tag_idx;
}
}
P2R_Bake2Serialize *out = push_array(arena, P2R_Bake2Serialize, 1);
out->sections = postpack_sections;
return out;
}
+27 -3
View File
@@ -5,16 +5,35 @@
#define RADDBGI_FROM_PDB_H
////////////////////////////////
//~ rjf: Conversion Stage Inputs/Outputs
//~ rjf: Export Artifact Flags
typedef U32 P2R_ConvertFlags;
enum
{
P2R_ConvertFlag_Types = (1<<0),
P2R_ConvertFlag_UDTs = (1<<1),
P2R_ConvertFlag_Strings = (1<<0),
P2R_ConvertFlag_IndexRuns = (1<<1),
P2R_ConvertFlag_BinarySections = (1<<2),
P2R_ConvertFlag_Units = (1<<3),
P2R_ConvertFlag_Procedures = (1<<4),
P2R_ConvertFlag_GlobalVariables = (1<<5),
P2R_ConvertFlag_ThreadVariables = (1<<6),
P2R_ConvertFlag_Scopes = (1<<7),
P2R_ConvertFlag_Locals = (1<<8),
P2R_ConvertFlag_Types = (1<<9),
P2R_ConvertFlag_UDTs = (1<<10),
P2R_ConvertFlag_LineInfo = (1<<11),
P2R_ConvertFlag_GlobalVariableNameMap = (1<<12),
P2R_ConvertFlag_ThreadVariableNameMap = (1<<13),
P2R_ConvertFlag_ProcedureNameMap = (1<<14),
P2R_ConvertFlag_TypeNameMap = (1<<15),
P2R_ConvertFlag_LinkNameProcedureNameMap= (1<<16),
P2R_ConvertFlag_NormalSourcePathNameMap = (1<<17),
P2R_ConvertFlag_All = 0xffffffff,
};
////////////////////////////////
//~ rjf: Conversion Stage Inputs/Outputs
typedef struct P2R_User2Convert P2R_User2Convert;
struct P2R_User2Convert
{
@@ -602,4 +621,9 @@ internal TS_TASK_FUNCTION_DEF(p2r_bake_idx_runs_task__entry_point);
internal P2R_Bake2Serialize *p2r_bake(Arena *arena, P2R_Convert2Bake *in);
////////////////////////////////
//~ rjf: Top-Level Compression Entry Point
internal P2R_Bake2Serialize *p2r_compress(Arena *arena, P2R_Bake2Serialize *in);
#endif // RADDBGI_FROM_PDB_H
+10 -1
View File
@@ -17,6 +17,8 @@
//- rjf: [lib]
#include "lib_raddbgi_format/raddbgi_format.h"
#include "lib_raddbgi_format/raddbgi_format.c"
#include "third_party/rad_lzb_simple/rad_lzb_simple.h"
#include "third_party/rad_lzb_simple/rad_lzb_simple.c"
//- rjf: [h]
#include "base/base_inc.h"
@@ -96,8 +98,15 @@ entry_point(CmdLine *cmdline)
bake2srlz = p2r_bake(arena, convert2bake);
}
//- rjf: compress
P2R_Bake2Serialize *bake2srlz_compressed = bake2srlz;
if(cmd_line_has_flag(cmdline, str8_lit("compress"))) ProfScope("compress")
{
bake2srlz_compressed = p2r_compress(arena, bake2srlz);
}
//- rjf: serialize
String8List serialize_out = rdim_serialized_strings_from_params_bake_section_list(arena, &convert2bake->bake_params, &bake2srlz->sections);
String8List serialize_out = rdim_serialized_strings_from_params_bake_section_list(arena, &convert2bake->bake_params, &bake2srlz_compressed->sections);
//- rjf: write
ProfScope("write")
File diff suppressed because it is too large Load Diff
+141
View File
@@ -0,0 +1,141 @@
#ifndef _RAD_LZB_SIMPLE_H_
#define _RAD_LZB_SIMPLE_H_
/*======================================================
To encode :
Set up an rr_lzb_simple_context
fill out m_tableSizeBits (14-16 is typical)
allocate m_hashTable
rr_lzb_simple_context c;
c.m_tableSizeBits = 14;
c.m_hashTable = OODLE_MALLOC_ARRAY(U16,RR_ONE_SA<<c.m_tableSizeBits);
then call _encode
NOTE :
compressed & raw size are not included in the encoded bytes. You must send
them separately.
NOTE :
lzb will never expand. comp_len is <= raw_len strictly.
if comp_len = raw_len it indicates that the compressed bytes are just a memcpy
of the raw bytes. In that case you do not need to decode.
To decode :
if comp_len is == raw_len, then the compressed bytes are just a copy of the
raw bytes and you could use them directly without calling decode.
if you call rr_lzb_simple_decode in that case, then the compressed buffer will
be memcpy'd to the raw buffer
===============================================================*/
//~ TODO(rjf): temporary glue for building this without the shared rad code:
#define __RAD64REGS__
#include <stdint.h>
typedef uint8_t U8;
typedef uint16_t U16;
typedef uint32_t U32;
typedef uint64_t U64;
typedef int8_t S8;
typedef int16_t S16;
typedef int32_t S32;
typedef int64_t S64;
typedef S64 SINTa;
typedef U64 RAD_U64;
typedef S64 RAD_S64;
typedef U32 RAD_U32;
typedef S32 RAD_S32;
#define RADINLINE __inline
#if defined(_MSC_VER)
# define RADFORCEINLINE __forceinline
#elif defined(__clang__)
# define RADFORCEINLINE __attribute__((always_inline))
#else
# error need force inline for this compiler
#endif
#define RR_STRING_JOIN(arg1, arg2) RR_STRING_JOIN_DELAY(arg1, arg2)
#define RR_STRING_JOIN_DELAY(arg1, arg2) RR_STRING_JOIN_IMMEDIATE(arg1, arg2)
#define RR_STRING_JOIN_IMMEDIATE(arg1, arg2) arg1 ## arg2
#ifdef _MSC_VER
#define RR_NUMBERNAME(name) RR_STRING_JOIN(name,__COUNTER__)
#else
#define RR_NUMBERNAME(name) RR_STRING_JOIN(name,__LINE__)
#endif
#define RR_COMPILER_ASSERT(exp) typedef char RR_NUMBERNAME(_dummy_array) [ (exp) ? 1 : -1 ]
#if defined(__clang__)
# define Expect(expr, val) __builtin_expect((expr), (val))
#else
# define Expect(expr, val) (expr)
#endif
#define RAD_LIKELY(expr) Expect(expr,1)
#define RAD_UNLIKELY(expr) Expect(expr,0)
#define __RADLITTLEENDIAN__ 1
#define RAD_PTRBYTES 8
#define RR_MIN(a,b) ( (a) < (b) ? (a) : (b) )
#define RR_MAX(a,b) ( (a) > (b) ? (a) : (b) )
#define RR_ASSERT_ALWAYS(c) do{if(!(c)) {__debugbreak();}}while(0)
#define RR_ASSERT(c) RR_ASSERT_ALWAYS(c)
#define RR_PUT16_LE(ptr,val) *((U16 *)(ptr)) = (U16)(val)
#define RR_GET16_LE_UNALIGNED(ptr) *((const U16 *)(ptr))
static RADINLINE U32
rrCtzBytes32(U32 val)
{
// Don't get fancy here. Assumes val != 0.
if (val & 0x000000ffu) return 0;
if (val & 0x0000ff00u) return 1;
if (val & 0x00ff0000u) return 2;
return 3;
}
static RADINLINE U32
rrCtzBytes64(U64 val)
{
U32 lo = (U32) val;
return lo ? rrCtzBytes32(lo) : 4 + rrCtzBytes32((U32) (val >> 32));
}
//~
//---------------------
typedef struct rr_lzb_simple_context rr_lzb_simple_context;
struct rr_lzb_simple_context
{
U16 * m_hashTable; // must be allocated to sizeof(U16)*(1<<m_tableSizeBits)
S32 m_tableSizeBits;
};
SINTa rr_lzb_simple_encode_fast(rr_lzb_simple_context * ctx,
const void * raw, SINTa rawLen, void * comp);
SINTa rr_lzb_simple_encode_veryfast(rr_lzb_simple_context * ctx,
const void * raw, SINTa rawLen, void * comp);
//---------------------
// rr_lzb_simple_decode returns the number of compressed bytes consumed ( == compLen)
SINTa rr_lzb_simple_decode(const void * comp, SINTa compLen, void * raw, SINTa rawLen);
//---------------------
#endif // _RAD_LZB_SIMPLE_H_