diff --git a/src/lib_rdi/rdi.h b/src/lib_rdi/rdi.h index e41014ee..63dc2a67 100644 --- a/src/lib_rdi/rdi.h +++ b/src/lib_rdi/rdi.h @@ -387,9 +387,10 @@ RDI_MemberKind_NestedType = 0x0300, typedef RDI_U8 RDI_ContainerKind; typedef enum RDI_ContainerKindEnum { -RDI_ContainerKind_Type = 0x0, -RDI_ContainerKind_Scope = 0x1, -RDI_ContainerKind_Namespace = 0x2, +RDI_ContainerKind_Unit = 0x0, +RDI_ContainerKind_Type = 0x1, +RDI_ContainerKind_Scope = 0x2, +RDI_ContainerKind_Namespace = 0x3, } RDI_ContainerKindEnum; typedef RDI_U8 RDI_ContainerFlags; diff --git a/src/raddbg/raddbg_main.c b/src/raddbg/raddbg_main.c index 5e2daede..8da853c1 100644 --- a/src/raddbg/raddbg_main.c +++ b/src/raddbg/raddbg_main.c @@ -25,15 +25,19 @@ // [ ] single-line viz for pointers w/ bad (unmapped) addresses // //- namespace/locations/variables RDI pass -// [ ] RDI_Local, RDI_GlobalVariable, RDI_ThreadVariable -> RDI_Variable -// [ ] RDI_Variable gets RDI_ContainerFlags, and a container_idx -// [ ] RDI_Namespace can be a container, same as types/procedures -// [ ] If procedure-contained, then index goes to scope now, not procedure -// [ ] Location sections -> split by location kind, fixed tables for simple locations, one catch-all table for bytecode. -// [ ] Location kind -> can be thread-local offset, or module virtual offset, to enclose globals/tlocals cases -// [ ] Referring to one location -> kind * index -// [ ] Referring to many locations, based on scope offsets -> kind = BlockList; BlockList encodes a first/opl pair into Block table, each Block has scope_off_first/opl, location_kind, location_idx - but a block's location kind CANNOT BE BlockList -// [ ] RDI_Variable has location_kind, location_idx +// [x] RDI_Local, RDI_GlobalVariable, RDI_ThreadVariable -> RDI_Variable +// [x] RDI_Variable gets RDI_ContainerFlags, and a container_idx +// [x] RDI_Namespace can be a container, same as types/procedures +// [x] If procedure-contained, then index goes to scope now, not procedure +// [x] Location sections -> split by location kind, fixed tables for simple locations, one catch-all table for bytecode. +// [x] Location kind -> can be thread-local offset, or module virtual offset, to enclose globals/tlocals cases +// [x] Referring to one location -> kind * index +// [x] Referring to many locations, based on scope offsets -> kind = BlockList; BlockList encodes a first/opl pair into Block table, each Block has scope_off_first/opl, location_kind, location_idx - but a block's location kind CANNOT BE BlockList +// [x] RDI_Variable has location_kind, location_idx +// +// [ ] we keep flat tables of symbols, *but*, "sort" by containing unit. unit -> [f, opl) of procedures, globals, threadvars, constants, etc. +// [ ] container can also be a unit, so you can also go from procedure/global/tvar -> unit +// // [ ] symbols only store their *partly-qualified name*, e.g. `x` for A::B::C::x // [ ] default name maps look up *partly-qualified names* // [ ] to match a *fully qualified name*, there needs to be a second kind of different lookup - instead of string-matching, we need to match against the *fully qualified names*. the maps must be built by hashing the *fully qualified name*, but redirecting to the symbol with the *partially qualified name*. this is to allow fully-qualified lookups, but avoid storing fully-qualified names. diff --git a/src/rdi/rdi.mdesk b/src/rdi/rdi.mdesk index 20f0ce80..907fec25 100644 --- a/src/rdi/rdi.mdesk +++ b/src/rdi/rdi.mdesk @@ -992,9 +992,10 @@ RDI_EnumMemberTable: @table(name value) RDI_ContainerKindTable: { - {Type 0x0} - {Scope 0x1} - {Namespace 0x2} + {Unit 0x0} + {Type 0x1} + {Scope 0x2} + {Namespace 0x3} } @table(name value) diff --git a/src/rdi_from_dwarf/rdi_from_dwarf.c b/src/rdi_from_dwarf/rdi_from_dwarf.c index 027a76ce..043ae534 100644 --- a/src/rdi_from_dwarf/rdi_from_dwarf.c +++ b/src/rdi_from_dwarf/rdi_from_dwarf.c @@ -1359,7 +1359,7 @@ d2r_locset_from_attrib(Arena *arena, for EachNode(loc_n, DW_LocNode, loclist.first) { RDIM_Location location = d2r_transpile_expression(arena, input, image_base, arch, cu->addr_lu, cu, loc_n->v.expr); RDIM_Rng1U64 voff_range = { .min = loc_n->v.range.min - image_base, .max = loc_n->v.range.max - image_base }; - rdim_push_location_case(arena, scopes, &locset, &location, voff_range); + rdim_location_case_list_push(arena, &locset, location, voff_range); } scratch_end(scratch); @@ -1370,7 +1370,7 @@ d2r_locset_from_attrib(Arena *arena, // convert expression and inherit life-time ranges from enclosed scope RDIM_Location location = d2r_transpile_expression(arena, input, image_base, arch, cu->addr_lu, cu, expr); for EachNode(range_n, RDIM_Rng1U64Node, curr_scope->voff_ranges.first) { - rdim_push_location_case(arena, scopes, &locset, &location, range_n->v); + rdim_location_case_list_push(arena, &locset, location, range_n->v); } } else if (attrib_class != DW_AttribClass_Null) { log_user_errorf("unexpected attrib class @ .debug_info+%llx", tag.info_off); @@ -1414,7 +1414,7 @@ d2r_var_locset_from_tag(Arena *arena, // push location cases for EachNode(range_n, RDIM_Rng1U64Node, curr_scope->voff_ranges.first) { - rdim_push_location_case(arena, scopes, &locset, &loc, range_n->v); + rdim_location_case_list_push(arena, &locset, loc, range_n->v); } } else if (has_location) { locset = d2r_locset_from_attrib(arena, scopes, curr_scope, input, cu, image_base, arch, tag, DW_AttribKind_Location); @@ -2468,10 +2468,9 @@ d2r_convert_symbols(Arena *arena, parent_tag.kind == DW_TagKind_InlinedSubroutine || parent_tag.kind == DW_TagKind_LexicalBlock) { RDIM_Scope *scope = it->stack->next->scope; - RDIM_Local *local = rdim_scope_push_local(arena, &g_d2r_shared.scopes, scope); - local->kind = RDI_LocalKind_Variable; - local->name = name; - local->type = type; + 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); } else { @@ -2531,10 +2530,10 @@ d2r_convert_symbols(Arena *arena, DW_Tag parent_tag = d2r_tag_iterator_parent_tag(it); if (parent_tag.kind == DW_TagKind_SubProgram || parent_tag.kind == DW_TagKind_InlinedSubroutine) { RDIM_Scope *scope = it->stack->next->scope; - RDIM_Local *param = rdim_scope_push_local(arena, &g_d2r_shared.scopes, scope); - param->kind = RDI_LocalKind_Parameter; - 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); + RDIM_Symbol *param = rdim_symbol_chunk_list_push(arena, &scope->locals, 4); + 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); } else { Assert(!"this is a local variable"); diff --git a/src/rdi_make/rdi_make_local.c b/src/rdi_make/rdi_make_local.c index 035a5b5b..eb955b23 100644 --- a/src/rdi_make/rdi_make_local.c +++ b/src/rdi_make/rdi_make_local.c @@ -2980,7 +2980,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) lane_sync(); ////////////////////////////////////////////////////////////// - //- rjf: @rdim_bake_stage bake scopes + //- rjf: @rdim_bake_stage bake scopes, gather locals // typedef struct BakedScopes BakedScopes; struct BakedScopes @@ -2989,8 +2989,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) RDI_U64 scopes_count; RDI_U64 *scope_voffs; RDI_U64 scope_voffs_count; - RDI_Symbol *locals; - RDI_U64 locals_count; + RDIM_SymbolChunkList arranged_locals; }; BakedScopes *baked_scopes = 0; ProfScope("bake scopes") @@ -3011,11 +3010,6 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) baked_scopes->scope_voffs_count = params->scopes.scope_voff_count+1; baked_scopes->scope_voffs = push_array(arena, RDI_U64, baked_scopes->scope_voffs_count); } - if(lane_idx() == lane_from_task_idx(2)) - { - baked_scopes->locals_count = params->scopes.local_count+1; - baked_scopes->locals = push_array(arena, RDI_Symbol, baked_scopes->locals_count); - } lane_sync(); //- rjf: wide fill @@ -3050,8 +3044,8 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) for EachIndex(src_local_idx, src_local_n->count) { RDIM_Symbol *src_local = &src_local_n->v[src_local_idx]; - RDI_Symbol *dst_local = &baked_scopes->locals[chunk_local_off]; #if 0 + RDI_Symbol *dst_local = &baked_scopes->locals[chunk_local_off]; dst_local->kind = src_local->kind; dst_local->name_string_idx = rdim_bake_idx_from_string(bake_strings, src_local->name); dst_local->type_idx = (RDI_U32)rdim_idx_from_type(src_local->type); // TODO(rjf): @u64_to_u32 @@ -3481,6 +3475,8 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) U64 baked_procedures_count = 0; RDI_Symbol *baked_constants = 0; U64 baked_constants_count = 0; + RDI_Symbol *baked_locals = 0; + U64 baked_locals_count = 0; struct { RDIM_SymbolChunkList *symbols; @@ -3489,10 +3485,11 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) } symbol_table_lists[] = { - {¶ms->global_variables, &baked_global_variables, &baked_global_variables_count}, - {¶ms->thread_variables, &baked_thread_variables, &baked_thread_variables_count}, - {¶ms->procedures, &baked_procedures, &baked_procedures_count}, - {¶ms->constants, &baked_constants, &baked_constants_count}, + {¶ms->global_variables, &baked_global_variables, &baked_global_variables_count}, + {¶ms->thread_variables, &baked_thread_variables, &baked_thread_variables_count}, + {¶ms->procedures, &baked_procedures, &baked_procedures_count}, + {¶ms->constants, &baked_constants, &baked_constants_count}, + {&baked_scopes->arranged_locals, &baked_locals, &baked_locals_count}, }; ////////////////////////////////////////////////////////////// @@ -3908,7 +3905,7 @@ rdim_bake(Arena *arena, RDIM_BakeParams *params) Map(ThreadVariableSymbols, baked_thread_variables, baked_thread_variables_count); Map(ConstantSymbols, baked_constants, baked_constants_count); Map(ProcedureSymbols, baked_procedures, baked_procedures_count); - // Map(LocalVariableSymbols, ); + Map(LocalVariableSymbols, baked_locals, baked_locals_count); Map(LocationsBytecodeData, baked_location_bytecode_data, baked_location_bytecode_data_size); Map(LocationsConstantData, baked_location_constant_data, baked_location_constant_data_size); Map(LocationsSetElements, baked_location_set_elements, baked_location_set_elements_count);