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
+17 -22
View File
@@ -2296,13 +2296,13 @@ d2r_range_list_from_tag(Arena *arena, DW_Input *input, DW_CompUnit *cu, U64 imag
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)
DW_TagNode *root,
RDIM_Unit *unit_rdi)
{
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)) {
@@ -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);
// 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
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;
// fill out proc
@@ -2388,7 +2388,7 @@ d2r_convert_symbols(Arena *arena,
proc->container_scope = 0;
proc->container_type = container_type;
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
DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it);
@@ -2456,7 +2456,7 @@ d2r_convert_symbols(Arena *arena,
// make scope
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;
} break;
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);
local->name = name;
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 {
// 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->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->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 {
Assert(!"this is a local variable");
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_LexicalBlock) {
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;
case DW_TagKind_CallSite: {
@@ -3004,10 +3004,6 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
////////////////////////////////
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};
for (RDI_TypeKind type_kind = RDI_TypeKind_FirstBuiltIn; type_kind <= RDI_TypeKind_LastBuiltIn; type_kind += 1) {
RDIM_Type *type = rdim_type_chunk_list_push(arena, &g_d2r_shared.types, D2R_TYPE_CHUNK_CAP);
@@ -3066,11 +3062,9 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
type_table->type_chunk_cap = D2R_TYPE_CHUNK_CAP;
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);
// convert compile unit
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);
@@ -3080,10 +3074,6 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
rdim_rng1u64_chunk_list_push(arena, &cu_voff_ranges, 512, (RDIM_Rng1U64){ .min = n->v.min, .max = n->v.max });
}
}
// convert compile unit
{
RDIM_Unit *unit = rdim_unit_chunk_list_push(arena, &g_d2r_shared.units, D2R_UNIT_CHUNK_CAP);
unit->unit_name = cu_name;
unit->compiler_name = cu_prod;
unit->source_file = str8_zero(); // TODO
@@ -3095,6 +3085,11 @@ d2r_convert(Arena *arena, D2R_ConvertParams *params)
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:;
temp_end(comp_temp);
}
+1 -3
View File
@@ -42,8 +42,6 @@ typedef struct D2R_Shared
RDIM_LineTableChunkList line_tables;
RDIM_SymbolChunkList gvars;
RDIM_SymbolChunkList tvars;
RDIM_SymbolChunkList procs;
RDIM_ScopeChunkList scopes;
RDIM_InlineSiteChunkList inline_sites;
} 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_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 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
+34 -3
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_Prototyped, 1);
dw_writer_push_attrib_stringf(writer, DW_AttribKind_Name, "FooBar");
// declare variable
// declare local
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_stringf(writer, DW_AttribKind_Name, "TestLocal");
dw_writer_push_attrib_ref(writer, DW_AttribKind_Type, char_type);
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);
}
@@ -475,11 +481,12 @@ TEST(d2r_general)
RDI_Scope *root_scope = rdi_root_scope_from_procedure(rdi, proc);
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);
T_Ok(test_local->symbol_flags & RDI_SymbolFlag_IsParam);
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("TestLocal"), 0));
@@ -497,6 +504,30 @@ TEST(d2r_general)
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));
}
{
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);
}