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
+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;
}
}