next checkpoint on dwarf cleanup

This commit is contained in:
Ryan Fleury
2025-11-10 16:37:23 -08:00
parent f396b2eaa3
commit 08642d2745
9 changed files with 387 additions and 403 deletions
+72 -70
View File
@@ -73,10 +73,10 @@ internal U64
dw_reg_count_from_arch(Arch arch)
{
switch (arch) {
default: { NotImplemented; } // fall-through
case Arch_Null: return 0;
case Arch_x86: return DW_RegX86_Last;
case Arch_x64: return DW_RegX64_Last;
default: { NotImplemented; } // fall-through
case Arch_Null: return 0;
case Arch_x86: return DW_RegX86_Last;
case Arch_x64: return DW_RegX64_Last;
}
}
@@ -98,10 +98,10 @@ internal U64
dw_sp_from_arch(Arch arch)
{
switch (arch) {
default: NotImplemented;
case Arch_Null: return 0;
case Arch_x86: return DW_RegX86_Esp;
case Arch_x64: return DW_RegX64_Rsp;
default: NotImplemented;
case Arch_Null: return 0;
case Arch_x86: return DW_RegX86_Esp;
case Arch_x64: return DW_RegX64_Rsp;
}
}
@@ -278,58 +278,64 @@ internal B32
dw_are_attrib_class_and_form_kind_compatible(DW_Version ver, DW_AttribClass attrib_class, DW_FormKind form_kind)
{
DW_AttribClass compat_flags = dw_attrib_class_from_form_kind(ver, form_kind);
B32 are_compat = (attrib_class & compat_flags) != 0;
B32 are_compat = (attrib_class & compat_flags) != 0;
return are_compat;
}
internal String8
dw_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_L);
String8 result = {0};
switch(k)
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_L);}break;
DW_SectionKind_XList(X)
#undef X
}
return str8_zero();
return result;
}
internal String8
dw_mach_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_M);
String8 result = {0};
switch(k)
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_M);}break;
DW_SectionKind_XList(X)
#undef X
}
return str8_zero();
return result;
}
internal String8
dw_dwo_name_string_from_section_kind(DW_SectionKind k)
{
switch (k) {
#define X(_N,_L,_M,_D) case DW_Section_##_N: return str8_lit(_D);
String8 result = {0};
switch(k)
{
#define X(_N,_L,_M,_D) case DW_Section_##_N:{result = str8_lit(_D);}break;
DW_SectionKind_XList(X)
#undef X
}
return str8_zero();
return result;
}
internal U64
dw_size_from_format(DW_Format format)
{
U64 result = 0;
switch (format) {
case DW_Format_Null: break;
switch(format)
{
default:{}break;
case DW_Format_32Bit: result = 4; break;
case DW_Format_64Bit: result = 8; break;
default: InvalidPath; break;
}
return result;
}
internal DW_AttribClass
dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKind attrib_kind, DW_FormKind form_kind)
dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, DW_AttribKind attrib_kind, DW_FormKind form_kind)
{
// NOTE(rjf): DWARF's spec specifies two mappings:
// (DW_AttribKind) => List(DW_AttribClass)
@@ -340,14 +346,10 @@ dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKin
DW_AttribClass attrib_class = dw_attrib_class_from_attrib(ver, ext, attrib_kind);
DW_AttribClass form_class = dw_attrib_class_from_form_kind(ver, form_kind);
if(relaxed)
if(attrib_class == DW_AttribClass_Null || form_class == DW_AttribClass_Null)
{
if(attrib_class == DW_AttribClass_Null || form_class == DW_AttribClass_Null)
{
attrib_class = dw_attrib_class_from_attrib(DW_Version_Last, ext, attrib_kind);
form_class = dw_attrib_class_from_form_kind(DW_Version_Last, form_kind);
}
attrib_class = dw_attrib_class_from_attrib(DW_Version_Last, ext, attrib_kind);
form_class = dw_attrib_class_from_form_kind(DW_Version_Last, form_kind);
}
DW_AttribClass result = DW_AttribClass_Null;
@@ -428,11 +430,11 @@ dw_operand_count_from_expr_op(DW_ExprOp op)
switch (op) {
#define X(_N, _ID, _OPER_COUNT, _POP_COUNT, _PUSH_COUNT) case _ID: return _OPER_COUNT;
DW_Expr_V3_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -443,11 +445,11 @@ dw_pop_count_from_expr_op(DW_ExprOp op)
switch (op) {
#define X(_N, _ID, _OPER_COUNT, _POP_COUNT, _PUSH_COUNT) case _ID: return _POP_COUNT;
DW_Expr_V3_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -458,11 +460,11 @@ dw_push_count_from_expr_op(DW_ExprOp op)
switch (op) {
#define X(_N, _ID, _OPER_COUNT, _POP_COUNT, _PUSH_COUNT) case _ID: return _PUSH_COUNT;
DW_Expr_V3_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
DW_Expr_V4_XList(X)
DW_Expr_V5_XList(X)
DW_Expr_GNU_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -474,7 +476,7 @@ dw_operand_count_from_cfa_opcode(DW_CFA_Opcode opcode)
#define X(_N, _ID, ...) case _ID: { local_persist DW_CFA_OperandType t[] = { DW_CFA_OperandType_Null, __VA_ARGS__ }; return ArrayCount(t)-1; }
DW_CFA_Kind_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -484,21 +486,21 @@ dw_is_cfa_expr_opcode_invalid(DW_ExprOp opcode)
{
B32 is_invalid = 0;
switch (opcode) {
case DW_ExprOp_Addrx:
case DW_ExprOp_Call2:
case DW_ExprOp_Call4:
case DW_ExprOp_CallRef:
case DW_ExprOp_ConstType:
case DW_ExprOp_Constx:
case DW_ExprOp_Convert:
case DW_ExprOp_DerefType:
case DW_ExprOp_RegvalType:
case DW_ExprOp_Reinterpret:
case DW_ExprOp_PushObjectAddress:
case DW_ExprOp_CallFrameCfa: {
is_invalid = 1;
} break;
default: break;
case DW_ExprOp_Addrx:
case DW_ExprOp_Call2:
case DW_ExprOp_Call4:
case DW_ExprOp_CallRef:
case DW_ExprOp_ConstType:
case DW_ExprOp_Constx:
case DW_ExprOp_Convert:
case DW_ExprOp_DerefType:
case DW_ExprOp_RegvalType:
case DW_ExprOp_Reinterpret:
case DW_ExprOp_PushObjectAddress:
case DW_ExprOp_CallFrameCfa: {
is_invalid = 1;
} break;
default: break;
}
return is_invalid;
}
@@ -508,14 +510,14 @@ dw_is_new_row_cfa_opcode(DW_CFA_Opcode opcode)
{
B32 is_new_row_op = 0;
switch (opcode) {
case DW_CFA_SetLoc:
case DW_CFA_AdvanceLoc:
case DW_CFA_AdvanceLoc1:
case DW_CFA_AdvanceLoc2:
case DW_CFA_AdvanceLoc4: {
is_new_row_op = 1;
} break;
default: break;
case DW_CFA_SetLoc:
case DW_CFA_AdvanceLoc:
case DW_CFA_AdvanceLoc1:
case DW_CFA_AdvanceLoc2:
case DW_CFA_AdvanceLoc4: {
is_new_row_op = 1;
} break;
default: break;
}
return is_new_row_op;
}
@@ -527,7 +529,7 @@ dw_operand_types_from_cfa_op(DW_CFA_Opcode opcode)
#define X(_N, _ID, ...) case _ID: { local_persist DW_CFA_OperandType t[] = { DW_CFA_OperandType_Null, __VA_ARGS__ }; return &t[0] + 1; }
DW_CFA_Kind_XList(X)
#undef X
default: { NotImplemented; } break;
default: { NotImplemented; } break;
}
return 0;
}
@@ -539,9 +541,9 @@ internal String8
dw_string_from_format(DW_Format format)
{
switch (format) {
case DW_Format_Null: return str8_zero();
case DW_Format_32Bit: return str8_lit("DWARF32");
case DW_Format_64Bit: return str8_lit("DWARF64");
case DW_Format_Null: return str8_zero();
case DW_Format_32Bit: return str8_lit("DWARF32");
case DW_Format_64Bit: return str8_lit("DWARF64");
}
return str8_zero();
}
@@ -824,7 +826,7 @@ dw_string_from_cfa_opcode(DW_CFA_Opcode opcode)
#define X(_NAME, _ID, ...) case _ID: return str8_lit(Stringify(_NAME));
DW_CFA_Kind_XList(X)
#undef X
default: InvalidPath; break;
default: InvalidPath; break;
}
return str8_zero();
}
+1 -1
View File
@@ -1782,7 +1782,7 @@ internal U64 dw_size_from_format(DW_Format format);
////////////////////////////////
internal DW_AttribClass dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, B32 relaxed, DW_AttribKind attrib, DW_FormKind form_kind);
internal DW_AttribClass dw_pick_attrib_value_class(DW_Version ver, DW_Ext ext, DW_AttribKind attrib, DW_FormKind form_kind);
internal U64 dw_pick_default_lower_bound(DW_Language lang);
+4 -20
View File
@@ -1,13 +1,6 @@
// Copyright (c) Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U64
dw_hash_from_string(String8 string)
{
XXH64_hash_t hash64 = XXH3_64bits(string.str, string.size);
return hash64;
}
internal U64
str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out)
{
@@ -58,20 +51,16 @@ str8_deserial_read_uleb128(String8 string, U64 off, U64 *value_out)
U64 cursor = off;
for(;;)
{
U8 byte = 0;
U8 byte = 0;
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
if(bytes_read != sizeof(byte))
{
break;
}
U8 val = byte & 0x7fu;
value |= ((U64)val) << shift;
cursor += bytes_read;
shift += 7u;
if((byte & 0x80u) == 0)
{
break;
@@ -93,19 +82,16 @@ str8_deserial_read_sleb128(String8 string, U64 off, S64 *value_out)
U64 cursor = off;
for(;;)
{
U8 byte;
U8 byte = 0;
U64 bytes_read = str8_deserial_read_struct(string, cursor, &byte);
if(bytes_read != sizeof(byte))
{
break;
}
U8 val = byte & 0x7fu;
value |= ((U64)val) << shift;
cursor += bytes_read;
shift += 7u;
if((byte & 0x80u) == 0)
{
if(shift < sizeof(value) * 8 && (byte & 0x40u) != 0)
@@ -1678,7 +1664,7 @@ dw_interp_loclists_ptr(DW_Input *input, DW_FormKind form_kind, DW_Form form)
internal DW_AttribClass
dw_value_class_from_attrib(DW_CompUnit *cu, DW_Attrib *attrib)
{
return dw_pick_attrib_value_class(cu->version, cu->ext, cu->relaxed, attrib->attrib_kind, attrib->form_kind);
return dw_pick_attrib_value_class(cu->version, cu->ext, attrib->attrib_kind, attrib->form_kind);
}
internal String8
@@ -2163,7 +2149,6 @@ dw_cu_from_info_off(Arena *arena, DW_Input *input, DW_ListUnitInput lu_input, U6
U64 low_pc = dw_interp_address(address_size, max_U64, addr_lu, low_pc_attrib->form_kind, low_pc_attrib->form);
// fill out compile unit
cu.relaxed = relaxed;
cu.ext = DW_Ext_All;
cu.kind = unit_kind;
cu.version = version;
@@ -3027,7 +3012,6 @@ dw_parsed_line_table_from_data(Arena *arena, String8 unit_data, DW_Input *input,
//
// See the DWARF V4 spec (June 10, 2010), page 122.
error = 1;
// AssertAlways(!"UNHANDLED DEFINE FILE!!!");
}break;
case DW_ExtOpcode_SetDiscriminator:
@@ -3103,7 +3087,7 @@ dw_v4_pub_strings_table_from_section_kind(Arena *arena, DW_Input *input, DW_Sect
String8 string = {0};
cursor += str8_deserial_read_cstr(section_data, cursor, &string);
U64 hash = dw_hash_from_string(string);
U64 hash = u64_hash_from_str8(string);
U64 bucket_idx = hash % names_table.size;
DW_PubStringsBucket *bucket = push_array(arena, DW_PubStringsBucket, 1);
+94 -82
View File
@@ -4,54 +4,59 @@
#ifndef DWARF_PARSE_H
#define DWARF_PARSE_H
typedef struct DW_Section
typedef struct DW_Section DW_Section;
struct DW_Section
{
String8 name;
String8 data;
B32 is_dwo;
} DW_Section;
};
typedef struct DW_Input
typedef struct DW_Input DW_Input;
struct DW_Input
{
DW_Section sec[DW_Section_Count];
DW_Section sup[DW_Section_Count];
} DW_Input;
};
typedef struct DW_ListUnit
typedef struct DW_ListUnit DW_ListUnit;
struct DW_ListUnit
{
DW_Version version;
U64 address_size;
U64 segment_selector_size;
U64 entry_size;
String8 entries;
} DW_ListUnit;
U64 address_size;
U64 segment_selector_size;
U64 entry_size;
String8 entries;
};
typedef struct DW_ListUnitInput
typedef struct DW_ListUnitInput DW_ListUnitInput;
struct DW_ListUnitInput
{
U64 addr_count;
U64 str_offset_count;
U64 rnglist_count;
U64 loclist_count;
Rng1U64Array addr_ranges;
Rng1U64Array str_offset_ranges;
Rng1U64Array rnglist_ranges;
Rng1U64Array loclist_ranges;
DW_ListUnit *addrs;
DW_ListUnit *str_offsets;
DW_ListUnit *rnglists;
DW_ListUnit *loclists;
} DW_ListUnitInput;
U64 addr_count;
U64 str_offset_count;
U64 rnglist_count;
U64 loclist_count;
Rng1U64Array addr_ranges;
Rng1U64Array str_offset_ranges;
Rng1U64Array rnglist_ranges;
Rng1U64Array loclist_ranges;
DW_ListUnit *addrs;
DW_ListUnit *str_offsets;
DW_ListUnit *rnglists;
DW_ListUnit *loclists;
};
typedef struct DW_AbbrevTableEntry
typedef struct DW_AbbrevTableEntry DW_AbbrevTableEntry;
struct DW_AbbrevTableEntry
{
U64 id;
U64 off;
} DW_AbbrevTableEntry;
};
typedef struct DW_AbbrevTable DW_AbbrevTable;
struct DW_AbbrevTable
{
U64 count;
U64 count;
DW_AbbrevTableEntry *entries;
};
@@ -63,7 +68,8 @@ typedef enum DW_AbbrevKind
DW_Abbrev_AttribSequenceEnd,
DW_Abbrev_DIEBegin,
DW_Abbrev_DIEEnd,
} DW_AbbrevKind;
}
DW_AbbrevKind;
typedef U32 DW_AbbrevFlags;
enum
@@ -72,14 +78,15 @@ enum
DW_AbbrevFlag_HasChildren = (1 << 1),
};
typedef struct DW_Abbrev
typedef struct DW_Abbrev DW_Abbrev;
struct DW_Abbrev
{
DW_AbbrevKind kind;
U64 sub_kind;
U64 id;
U64 const_value;
DW_AbbrevKind kind;
U64 sub_kind;
U64 id;
U64 const_value;
DW_AbbrevFlags flags;
} DW_Abbrev;
};
typedef union DW_Form
{
@@ -100,71 +107,80 @@ typedef union DW_Form
U64 rnglistx;
U64 ptr;
U64 implicit_const;
} DW_Form;
}
DW_Form;
typedef struct DW_Attrib
typedef struct DW_Attrib DW_Attrib;
struct DW_Attrib
{
U64 info_off;
U64 abbrev_off;
U64 abbrev_id;
DW_AttribKind attrib_kind;
DW_FormKind form_kind;
DW_Form form;
} DW_Attrib;
U64 info_off;
U64 abbrev_off;
U64 abbrev_id;
DW_AttribKind attrib_kind;
DW_FormKind form_kind;
DW_Form form;
};
typedef struct DW_AttribNode
typedef struct DW_AttribNode DW_AttribNode;
struct DW_AttribNode
{
struct DW_AttribNode *next;
DW_Attrib v;
} DW_AttribNode;
DW_AttribNode *next;
DW_Attrib v;
};
typedef struct DW_AttribList
typedef struct DW_AttribList DW_AttribList;
struct DW_AttribList
{
DW_AttribNode *first;
DW_AttribNode *last;
U64 count;
} DW_AttribList;
U64 count;
};
typedef struct DW_Tag
typedef struct DW_Tag DW_Tag;
struct DW_Tag
{
B32 has_children;
U64 abbrev_id;
DW_TagKind kind;
DW_AttribList attribs;
U64 info_off;
U8 v[1];
} DW_Tag;
B32 has_children;
U64 abbrev_id;
DW_TagKind kind;
DW_AttribList attribs;
U64 info_off;
U8 v[1];
};
typedef struct DW_TagNode
typedef struct DW_TagNode DW_TagNode;
struct DW_TagNode
{
DW_Tag tag;
struct DW_TagNode *sibling;
struct DW_TagNode *first_child;
struct DW_TagNode *last_child;
} DW_TagNode;
DW_Tag tag;
DW_TagNode *sibling;
DW_TagNode *first_child;
DW_TagNode *last_child;
};
typedef struct DW_Loc
typedef struct DW_Loc DW_Loc;
struct DW_Loc
{
Rng1U64 range;
String8 expr;
} DW_Loc;
};
typedef struct DW_LocNode
typedef struct DW_LocNode DW_LocNode;
struct DW_LocNode
{
DW_Loc v;
struct DW_LocNode *next;
} DW_LocNode;
DW_LocNode *next;
DW_Loc v;
};
typedef struct DW_LocList
typedef struct DW_LocList DW_LocList;
struct DW_LocList
{
U64 count;
DW_LocNode *first;
DW_LocNode *last;
} DW_LocList;
U64 count;
};
typedef struct DW_CompUnit
typedef struct DW_CompUnit DW_CompUnit;
struct DW_CompUnit
{
B32 relaxed;
DW_Ext ext;
DW_CompUnitKind kind;
DW_Version version;
@@ -183,7 +199,7 @@ typedef struct DW_CompUnit
U64 dwo_id;
DW_Tag tag;
HashTable *tag_ht;
} DW_CompUnit;
};
typedef struct DW_TagTree
{
@@ -328,12 +344,12 @@ typedef union DW_ExprOperand
U16 u16;
U32 u32;
U64 u64;
S8 s8;
S16 s16;
S32 s32;
S64 s64;
String8 block;
} DW_ExprOperand;
@@ -431,10 +447,6 @@ typedef struct DW_CFA_InstList
#define DW_DECODE_PTR(name) U64 name(String8 data, void *ud, U64 *ptr_out)
typedef DW_DECODE_PTR(DW_DecodePtr);
// hasher
internal U64 dw_hash_from_string(String8 string);
// deserial helpers
internal U64 str8_deserial_read_dwarf_packed_size(String8 string, U64 off, U64 *size_out);