Skip to content

Commit 17ec73d

Browse files
committed
dwarf cleanup checkpoint
1 parent 08642d2 commit 17ec73d

File tree

20 files changed

+526
-594
lines changed

20 files changed

+526
-594
lines changed

src/base/base_strings.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,72 @@ str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out)
28382838
return block_out->size;
28392839
}
28402840

2841+
internal U64
2842+
str8_deserial_read_uleb128(String8 string, U64 off, U64 *value_out)
2843+
{
2844+
U64 value = 0;
2845+
U64 shift = 0;
2846+
U64 cursor = off;
2847+
for(;;)
2848+
{
2849+
U8 byte = 0;
2850+
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
2851+
if(bytes_read != sizeof(byte))
2852+
{
2853+
break;
2854+
}
2855+
U8 val = byte & 0x7fu;
2856+
value |= ((U64)val) << shift;
2857+
cursor += bytes_read;
2858+
shift += 7u;
2859+
if((byte & 0x80u) == 0)
2860+
{
2861+
break;
2862+
}
2863+
}
2864+
if(value_out != 0)
2865+
{
2866+
*value_out = value;
2867+
}
2868+
U64 bytes_read = cursor - off;
2869+
return bytes_read;
2870+
}
2871+
2872+
internal U64
2873+
str8_deserial_read_sleb128(String8 string, U64 off, S64 *value_out)
2874+
{
2875+
U64 value = 0;
2876+
U64 shift = 0;
2877+
U64 cursor = off;
2878+
for(;;)
2879+
{
2880+
U8 byte = 0;
2881+
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
2882+
if(bytes_read != sizeof(byte))
2883+
{
2884+
break;
2885+
}
2886+
U8 val = byte & 0x7fu;
2887+
value |= ((U64)val) << shift;
2888+
cursor += bytes_read;
2889+
shift += 7u;
2890+
if((byte & 0x80u) == 0)
2891+
{
2892+
if(shift < sizeof(value) * 8 && (byte & 0x40u) != 0)
2893+
{
2894+
value |= -(S64)(1ull << shift);
2895+
}
2896+
break;
2897+
}
2898+
}
2899+
if(value_out != 0)
2900+
{
2901+
*value_out = value;
2902+
}
2903+
U64 bytes_read = cursor - off;
2904+
return bytes_read;
2905+
}
2906+
28412907
////////////////////////////////
28422908

28432909
internal int

src/base/base_strings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ internal U64 str8_deserial_read_windows_utf16_string16(String8 string, U64 of
444444
internal U64 str8_deserial_read_block(String8 string, U64 off, U64 size, String8 *block_out);
445445
#define str8_deserial_read_array(string, off, ptr, count) str8_deserial_read((string), (off), (ptr), sizeof(*(ptr))*(count), sizeof(*(ptr)))
446446
#define str8_deserial_read_struct(string, off, ptr) str8_deserial_read_array(string, off, ptr, 1)
447+
internal U64 str8_deserial_read_uleb128(String8 string, U64 off, U64 *value_out);
448+
internal U64 str8_deserial_read_sleb128(String8 string, U64 off, S64 *value_out);
447449

448450
////////////////////////////////
449451
//~ rjf: Basic String Hashes

src/coff/coff_dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ coff_print_obj(Arena *arena, String8List *out, String8 indent, String8 raw_data,
648648
}
649649

650650
if (opts & RD_Option_Dwarf) {
651-
DW_Input dwarf_input = dw_input_from_coff_section_table(scratch.arena, raw_data, raw_string_table, header->section_count, section_table);
651+
DW_Raw dwarf_input = dw_raw_from_coff_section_table(scratch.arena, raw_data, raw_string_table, header->section_count, section_table);
652652
dw_format(arena, out, indent, opts, &dwarf_input, arch, ExecutableImageKind_CoffPe);
653653
}
654654

0 commit comments

Comments
 (0)