test param flag

This commit is contained in:
Nikita Smith
2026-04-20 13:55:23 -07:00
committed by Ryan Fleury
parent 52875a2d93
commit 43c3d5e348
3 changed files with 80 additions and 56 deletions
+26 -31
View File
@@ -2296,13 +2296,13 @@ d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 imag
internal void internal void
d2r_convert_symbols(Arena *arena, d2r_convert_symbols(Arena *arena,
D2R_TypeTable *type_table, D2R_TypeTable *type_table,
RDIM_Scope *global_scope,
DW_Input *input, DW_Input *input,
DW_CompUnit *cu, DW_CompUnit *cu,
DW_Language cu_lang, DW_Language cu_lang,
U64 image_base, U64 image_base,
Arch arch, Arch arch,
DW_TagNode *root) DW_TagNode *root,
RDIM_Unit *unit_rdi)
{ {
Temp scratch = scratch_begin(&arena, 1); Temp scratch = scratch_begin(&arena, 1);
for (D2R_TagIterator *it = d2r_tag_iterator_init(scratch.arena, root); it->tag_node != 0; d2r_tag_iterator_next(scratch.arena, it)) { for (D2R_TagIterator *it = d2r_tag_iterator_init(scratch.arena, root); it->tag_node != 0; d2r_tag_iterator_next(scratch.arena, it)) {
@@ -2373,11 +2373,11 @@ d2r_convert_symbols(Arena *arena,
String8 frame_base_expr = dw_exprloc_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_FrameBase); String8 frame_base_expr = dw_exprloc_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_FrameBase);
// get proc container symbol // get proc container symbol
RDIM_Symbol *proc = rdim_symbol_chunk_list_push(arena, &g_d2r_shared.procs, D2R_PROC_CHUNK_CAP); RDIM_Symbol *proc = rdim_symbol_chunk_list_push(arena, &unit_rdi->procedures, D2R_PROC_CHUNK_CAP);
// make scope // make scope
Rng1U64List ranges = d2r_range_list_from_tag(scratch.arena, input, cu, image_base, tag); Rng1U64List ranges = d2r_range_list_from_tag(scratch.arena, input, cu, image_base, tag);
RDIM_Scope *root_scope = d2r_push_scope(arena, &g_d2r_shared.scopes, D2R_SCOPE_CHUNK_CAP, it->stack, ranges); RDIM_Scope *root_scope = d2r_push_scope(arena, &unit_rdi->scopes, D2R_SCOPE_CHUNK_CAP, it->stack, ranges);
root_scope->symbol = proc; root_scope->symbol = proc;
// fill out proc // fill out proc
@@ -2388,7 +2388,7 @@ d2r_convert_symbols(Arena *arena,
proc->container_scope = 0; proc->container_scope = 0;
proc->container_type = container_type; proc->container_type = container_type;
proc->root_scope = root_scope; proc->root_scope = root_scope;
proc->location_cases = d2r_locset_from_attrib(arena, &g_d2r_shared.scopes, root_scope, input, cu, image_base, arch, tag, DW_AttribKind_FrameBase); proc->location_cases = d2r_locset_from_attrib(arena, &unit_rdi->scopes, root_scope, input, cu, image_base, arch, tag, DW_AttribKind_FrameBase);
// sub program with user-defined parent tag is a method // sub program with user-defined parent tag is a method
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it); DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
@@ -2456,7 +2456,7 @@ d2r_convert_symbols(Arena *arena,
// make scope // make scope
Rng1U64List ranges = d2r_range_list_from_tag(scratch.arena, input, cu, image_base, tag); Rng1U64List ranges = d2r_range_list_from_tag(scratch.arena, input, cu, image_base, tag);
RDIM_Scope *root_scope = d2r_push_scope(arena, &g_d2r_shared.scopes, D2R_SCOPE_CHUNK_CAP, it->stack, ranges); RDIM_Scope *root_scope = d2r_push_scope(arena, &unit_rdi->scopes, D2R_SCOPE_CHUNK_CAP, it->stack, ranges);
root_scope->inline_site = inline_site; root_scope->inline_site = inline_site;
} break; } break;
case DW_TagKind_Variable: { case DW_TagKind_Variable: {
@@ -2471,7 +2471,7 @@ d2r_convert_symbols(Arena *arena,
RDIM_Symbol *local = rdim_symbol_chunk_list_push(arena, &scope->locals, 8); RDIM_Symbol *local = rdim_symbol_chunk_list_push(arena, &scope->locals, 8);
local->name = name; local->name = name;
local->type = type; local->type = type;
local->location_cases = d2r_var_locset_from_tag(arena, &g_d2r_shared.scopes, scope, input, cu, image_base, arch, tag); local->location_cases = d2r_var_locset_from_tag(arena, &unit_rdi->scopes, scope, input, cu, image_base, arch, tag);
} else { } else {
// NOTE: due to a bug in clang in stb_sprintf.h local variables // NOTE: due to a bug in clang in stb_sprintf.h local variables
@@ -2534,7 +2534,7 @@ d2r_convert_symbols(Arena *arena,
param->is_param = 1; param->is_param = 1;
param->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name); param->name = dw_string_from_tag_attrib_kind(input, cu, tag, DW_AttribKind_Name);
param->type = d2r_type_from_attrib(type_table, input, cu, tag, DW_AttribKind_Type); param->type = d2r_type_from_attrib(type_table, input, cu, tag, DW_AttribKind_Type);
param->location_cases = d2r_var_locset_from_tag(arena, &g_d2r_shared.scopes, scope, input, cu, image_base, arch, tag); param->location_cases = d2r_var_locset_from_tag(arena, &unit_rdi->scopes, scope, input, cu, image_base, arch, tag);
} else { } else {
Assert(!"this is a local variable"); Assert(!"this is a local variable");
log_user_errorf(".debug_info+%llx out of scope formal parameter", tag.info_off); log_user_errorf(".debug_info+%llx out of scope formal parameter", tag.info_off);
@@ -2546,7 +2546,7 @@ d2r_convert_symbols(Arena *arena,
parent_tag.kind == DW_TagKind_InlinedSubroutine || parent_tag.kind == DW_TagKind_InlinedSubroutine ||
parent_tag.kind == DW_TagKind_LexicalBlock) { parent_tag.kind == DW_TagKind_LexicalBlock) {
Rng1U64List ranges = d2r_range_list_from_tag(scratch.arena, input, cu, image_base, tag); Rng1U64List ranges = d2r_range_list_from_tag(scratch.arena, input, cu, image_base, tag);
d2r_push_scope(arena, &g_d2r_shared.scopes, D2R_SCOPE_CHUNK_CAP, it->stack, ranges); d2r_push_scope(arena, &unit_rdi->scopes, D2R_SCOPE_CHUNK_CAP, it->stack, ranges);
} }
} break; } break;
case DW_TagKind_CallSite: { case DW_TagKind_CallSite: {
@@ -3002,10 +3002,6 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
} }
ProfEnd(); ProfEnd();
////////////////////////////////
RDIM_Scope *global_scope = rdim_scope_chunk_list_push(arena, &g_d2r_shared.scopes, D2R_SCOPE_CHUNK_CAP);
//////////////////////////////// ////////////////////////////////
RDIM_Type *builtin_types[RDI_TypeKind_Count] = {0}; RDIM_Type *builtin_types[RDI_TypeKind_Count] = {0};
@@ -3058,32 +3054,26 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
String8 cu_dir = dw_string_from_tag_attrib_kind(&input, cu, cu->tag, DW_AttribKind_CompDir); String8 cu_dir = dw_string_from_tag_attrib_kind(&input, cu, cu->tag, DW_AttribKind_CompDir);
String8 cu_prod = dw_string_from_tag_attrib_kind(&input, cu, cu->tag, DW_AttribKind_Producer); String8 cu_prod = dw_string_from_tag_attrib_kind(&input, cu, cu->tag, DW_AttribKind_Producer);
DW_Language cu_lang = dw_const_u64_from_tag_attrib_kind(&input, cu, cu->tag, DW_AttribKind_Language); DW_Language cu_lang = dw_const_u64_from_tag_attrib_kind(&input, cu, cu->tag, DW_AttribKind_Language);
// init type table // init type table
D2R_TypeTable *type_table = push_array(comp_temp.arena, D2R_TypeTable, 1); D2R_TypeTable *type_table = push_array(comp_temp.arena, D2R_TypeTable, 1);
type_table->ht = hash_table_init(comp_temp.arena, 0x4000); type_table->ht = hash_table_init(comp_temp.arena, 0x4000);
type_table->types = &g_d2r_shared.types; type_table->types = &g_d2r_shared.types;
type_table->type_chunk_cap = D2R_TYPE_CHUNK_CAP; type_table->type_chunk_cap = D2R_TYPE_CHUNK_CAP;
type_table->builtin_types = builtin_types; type_table->builtin_types = builtin_types;
// convert debug info
d2r_convert_types(arena, type_table, &input, cu, cu_lang, arch, tag_tree.root);
d2r_convert_udts(arena, type_table, &input, cu, cu_lang, tag_tree.root);
d2r_convert_symbols(arena, type_table, global_scope, &input, cu, cu_lang, image_base, arch, tag_tree.root);
RDIM_Rng1U64ChunkList cu_voff_ranges = {0};
if (cu_idx < cu_contrib_map.count) {
cu_voff_ranges = d2r_voff_ranges_from_cu_info_off(cu_contrib_map, cu_ranges.v[cu_idx].min);
} else {
Rng1U64List range_list = d2r_range_list_from_tag(scratch.arena, &input, cu, image_base, cu->tag);
for EachNode(n, Rng1U64Node, range_list.first) {
rdim_rng1u64_chunk_list_push(arena, &cu_voff_ranges, 512, (RDIM_Rng1U64){ .min = n->v.min, .max = n->v.max });
}
}
// convert compile unit // convert compile unit
RDIM_Unit *unit = rdim_unit_chunk_list_push(arena, &g_d2r_shared.units, D2R_UNIT_CHUNK_CAP);
{ {
RDIM_Unit *unit = rdim_unit_chunk_list_push(arena, &g_d2r_shared.units, D2R_UNIT_CHUNK_CAP); RDIM_Rng1U64ChunkList cu_voff_ranges = {0};
if (cu_idx < cu_contrib_map.count) {
cu_voff_ranges = d2r_voff_ranges_from_cu_info_off(cu_contrib_map, cu_ranges.v[cu_idx].min);
} else {
Rng1U64List range_list = d2r_range_list_from_tag(scratch.arena, &input, cu, image_base, cu->tag);
for EachNode(n, Rng1U64Node, range_list.first) {
rdim_rng1u64_chunk_list_push(arena, &cu_voff_ranges, 512, (RDIM_Rng1U64){ .min = n->v.min, .max = n->v.max });
}
}
unit->unit_name = cu_name; unit->unit_name = cu_name;
unit->compiler_name = cu_prod; unit->compiler_name = cu_prod;
unit->source_file = str8_zero(); // TODO unit->source_file = str8_zero(); // TODO
@@ -3094,6 +3084,11 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
unit->line_table = cu_line_tables_rdi[cu_idx]; unit->line_table = cu_line_tables_rdi[cu_idx];
unit->voff_ranges = cu_voff_ranges; unit->voff_ranges = cu_voff_ranges;
} }
// convert debug info
d2r_convert_types(arena, type_table, &input, cu, cu_lang, arch, tag_tree.root);
d2r_convert_udts(arena, type_table, &input, cu, cu_lang, tag_tree.root);
d2r_convert_symbols(arena, type_table, &input, cu, cu_lang, image_base, arch, tag_tree.root, unit);
next_cu:; next_cu:;
temp_end(comp_temp); temp_end(comp_temp);
+1 -3
View File
@@ -42,8 +42,6 @@ typedef struct D2R_Shared
RDIM_LineTableChunkList line_tables; RDIM_LineTableChunkList line_tables;
RDIM_SymbolChunkList gvars; RDIM_SymbolChunkList gvars;
RDIM_SymbolChunkList tvars; RDIM_SymbolChunkList tvars;
RDIM_SymbolChunkList procs;
RDIM_ScopeChunkList scopes;
RDIM_InlineSiteChunkList inline_sites; RDIM_InlineSiteChunkList inline_sites;
} D2R_Shared; } D2R_Shared;
@@ -257,7 +255,7 @@ internal void d2r_convert_udts(Arena *arena, D2R_TypeTable *type_table, DW_Input
internal RDIM_Scope * d2r_push_scope (Arena *arena, RDIM_ScopeChunkList *scopes, U64 scope_chunk_cap, D2R_TagFrame *tag_stack, Rng1U64List ranges); internal RDIM_Scope * d2r_push_scope (Arena *arena, RDIM_ScopeChunkList *scopes, U64 scope_chunk_cap, D2R_TagFrame *tag_stack, Rng1U64List ranges);
internal RDIM_Type ** d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out); internal RDIM_Type ** d2r_collect_proc_params(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_TagNode *cur_node, U64 *param_count_out);
internal Rng1U64List d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag); internal Rng1U64List d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 image_base, DW_Tag tag);
internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, RDIM_Scope *global_scope, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 image_base, Arch arch, DW_TagNode *root); internal void d2r_convert_symbols(Arena *arena, D2R_TypeTable *type_table, DW_Input *input, DW_CompUnit *cu, DW_Language cu_lang, U64 image_base, Arch arch, DW_TagNode *root, RDIM_Unit *unit_rdi);
//////////////////////////////// ////////////////////////////////
//~ Line Table Conversion //~ Line Table Conversion
+53 -22
View File
@@ -457,12 +457,18 @@ TEST(d2r_general)
dw_writer_push_attrib_flag(writer, DW_AttribKind_External, 1); dw_writer_push_attrib_flag(writer, DW_AttribKind_External, 1);
dw_writer_push_attrib_flag(writer, DW_AttribKind_Prototyped, 1); dw_writer_push_attrib_flag(writer, DW_AttribKind_Prototyped, 1);
dw_writer_push_attrib_stringf(writer, DW_AttribKind_Name, "FooBar"); dw_writer_push_attrib_stringf(writer, DW_AttribKind_Name, "FooBar");
// declare variable // declare local
dw_writer_tag_begin(writer, DW_TagKind_Variable); dw_writer_tag_begin(writer, DW_TagKind_Variable);
dw_writer_push_attrib_exprv(writer, DW_AttribKind_Location, DW_ExprEnc_Op(Reg7)); dw_writer_push_attrib_exprv(writer, DW_AttribKind_Location, DW_ExprEnc_Op(Reg7));
dw_writer_push_attrib_stringf(writer, DW_AttribKind_Name, "TestLocal"); dw_writer_push_attrib_stringf(writer, DW_AttribKind_Name, "TestLocal");
dw_writer_push_attrib_ref(writer, DW_AttribKind_Type, char_type); dw_writer_push_attrib_ref(writer, DW_AttribKind_Type, char_type);
dw_writer_tag_end(writer); dw_writer_tag_end(writer);
// declare param
dw_writer_tag_begin(writer, DW_TagKind_FormalParameter);
dw_writer_push_attrib_exprv(writer, DW_AttribKind_Location, DW_ExprEnc_Op(Reg7));
dw_writer_push_attrib_stringf(writer, DW_AttribKind_Name, "TestParam");
dw_writer_push_attrib_ref(writer, DW_AttribKind_Type, char_type);
dw_writer_tag_end(writer);
dw_writer_tag_end(writer); dw_writer_tag_end(writer);
} }
@@ -475,28 +481,53 @@ TEST(d2r_general)
RDI_Scope *root_scope = rdi_root_scope_from_procedure(rdi, proc); RDI_Scope *root_scope = rdi_root_scope_from_procedure(rdi, proc);
T_Ok(root_scope); T_Ok(root_scope);
T_Ok(root_scope->local_count == 1); T_Ok(root_scope->local_count == 2);
RDI_Symbol *test_local = rdi_element_from_name_idx(rdi, LocalVariables, root_scope->local_first + 0); {
T_Ok(test_local); RDI_Symbol *test_local = rdi_element_from_name_idx(rdi, LocalVariables, root_scope->local_first + 0);
T_Ok(test_local->symbol_flags & RDI_SymbolFlag_IsParam); T_Ok(test_local);
String8 test_local_name = str8_from_rdi_string_idx(rdi, test_local->name_string_idx); T_Ok((test_local->symbol_flags & RDI_SymbolFlag_IsParam) == 0);
T_Ok(str8_match(test_local_name, str8_lit("TestLocal"), 0)); String8 test_local_name = str8_from_rdi_string_idx(rdi, test_local->name_string_idx);
T_Ok(str8_match(test_local_name, str8_lit("TestLocal"), 0));
RDI_TypeNode *test_local_type = rdi_element_from_name_idx(rdi, TypeNodes, test_local->type_idx);
T_Ok(test_local_type); RDI_TypeNode *test_local_type = rdi_element_from_name_idx(rdi, TypeNodes, test_local->type_idx);
T_Ok(test_local_type->kind == RDI_TypeKind_Alias); T_Ok(test_local_type);
T_Ok(test_local_type->flags == 0); T_Ok(test_local_type->kind == RDI_TypeKind_Alias);
String8 alias_name = str8_from_rdi_string_idx(rdi, test_local_type->user_defined.name_string_idx); T_Ok(test_local_type->flags == 0);
T_Ok(str8_match(alias_name, str8_lit("char"), 0)); String8 alias_name = str8_from_rdi_string_idx(rdi, test_local_type->user_defined.name_string_idx);
T_Ok(str8_match(alias_name, str8_lit("char"), 0));
RDI_TypeNode *char_type = rdi_element_from_name_idx(rdi, TypeNodes, test_local_type->user_defined.direct_type_idx);
T_Ok(char_type); RDI_TypeNode *char_type = rdi_element_from_name_idx(rdi, TypeNodes, test_local_type->user_defined.direct_type_idx);
T_Ok(char_type->kind == RDI_TypeKind_Char8); T_Ok(char_type);
T_Ok(char_type->flags == 0); T_Ok(char_type->kind == RDI_TypeKind_Char8);
T_Ok(char_type->byte_size == 1); T_Ok(char_type->flags == 0);
String8 char_type_name = str8_from_rdi_string_idx(rdi, char_type->built_in.name_string_idx); T_Ok(char_type->byte_size == 1);
T_Ok(str8_match(char_type_name, str8_lit("Char8"), 0)); String8 char_type_name = str8_from_rdi_string_idx(rdi, char_type->built_in.name_string_idx);
T_Ok(str8_match(char_type_name, str8_lit("Char8"), 0));
}
{
RDI_Symbol *test_local = rdi_element_from_name_idx(rdi, LocalVariables, root_scope->local_first + 1);
T_Ok(test_local);
T_Ok((test_local->symbol_flags & RDI_SymbolFlag_IsParam) != 0);
String8 test_local_name = str8_from_rdi_string_idx(rdi, test_local->name_string_idx);
T_Ok(str8_match(test_local_name, str8_lit("TestParam"), 0));
RDI_TypeNode *test_local_type = rdi_element_from_name_idx(rdi, TypeNodes, test_local->type_idx);
T_Ok(test_local_type);
T_Ok(test_local_type->kind == RDI_TypeKind_Alias);
T_Ok(test_local_type->flags == 0);
String8 alias_name = str8_from_rdi_string_idx(rdi, test_local_type->user_defined.name_string_idx);
T_Ok(str8_match(alias_name, str8_lit("char"), 0));
RDI_TypeNode *char_type = rdi_element_from_name_idx(rdi, TypeNodes, test_local_type->user_defined.direct_type_idx);
T_Ok(char_type);
T_Ok(char_type->kind == RDI_TypeKind_Char8);
T_Ok(char_type->flags == 0);
T_Ok(char_type->byte_size == 1);
String8 char_type_name = str8_from_rdi_string_idx(rdi, char_type->built_in.name_string_idx);
T_Ok(str8_match(char_type_name, str8_lit("Char8"), 0));
}
dw_writer_end(&writer); dw_writer_end(&writer);
} }