From 385014adcbcf55541702f65f74a8cfe09eb33edd Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Wed, 31 Jan 2024 08:43:33 -0800 Subject: [PATCH] raddbg nil tables, autofill empty tables with 1-sized nils; use element-from-idx wrapper to bounds-check and nilify all out-of-bounds raddbg table accesses --- src/ctrl/ctrl_core.c | 7 ++- src/dbgi/dbgi.c | 4 +- src/dbgi/dbgi.h | 46 ++++++++++++++++++- src/df/core/df_core.c | 31 +++++-------- src/df/core/df_core.mdesk | 4 +- src/df/core/generated/df_core.meta.c | 4 +- src/df/gfx/df_views.c | 22 ++++----- src/eval/eval_parser.c | 38 ++++++--------- src/raddbg/raddbg.h | 1 + src/raddbg_format/raddbg_format_parse.c | 61 +++++++++++++++++-------- src/raddbg_format/raddbg_format_parse.h | 55 +++++++++++++++------- src/render/render_core.h | 55 ---------------------- src/type_graph/type_graph.c | 12 ++--- 13 files changed, 174 insertions(+), 166 deletions(-) diff --git a/src/ctrl/ctrl_core.c b/src/ctrl/ctrl_core.c index f3eb6e0f..32d113b2 100644 --- a/src/ctrl/ctrl_core.c +++ b/src/ctrl/ctrl_core.c @@ -242,9 +242,8 @@ ctrl_append_resolved_module_user_bp_traps(Arena *arena, DEMON_Handle process, DE } // rjf: src_id * pt -> push - if(0 < src_id && src_id < rdbg->source_file_count) { - RADDBG_SourceFile *src = rdbg->source_files + src_id; + RADDBG_SourceFile *src = raddbg_element_from_idx(rdbg, source_files, src_id); RADDBG_ParsedLineMap line_map = {0}; raddbg_line_map_from_source_file(rdbg, src, &line_map); U32 voff_count = 0; @@ -1553,9 +1552,9 @@ ctrl_thread__next_demon_event(Arena *arena, CTRL_Msg *msg, DEMON_RunCtrls *run_c { U32 id_count = 0; U32 *ids = raddbg_matches_from_map_node(rdbg, node, &id_count); - if(id_count > 0 && 0 < ids[0] && ids[0] < rdbg->global_variable_count) + if(id_count > 0) { - RADDBG_GlobalVariable *global_var = &rdbg->global_variables[ids[0]]; + RADDBG_GlobalVariable *global_var = raddbg_element_from_idx(rdbg, global_variables, ids[0]); U64 global_var_voff = global_var->voff; U64 global_var_vaddr = global_var->voff + demon_base_vaddr_from_module(ctrl_demon_handle_from_ctrl(module)); Architecture arch = demon_arch_from_object(ev->thread); diff --git a/src/dbgi/dbgi.c b/src/dbgi/dbgi.c index b939fb05..8314e246 100644 --- a/src/dbgi/dbgi.c +++ b/src/dbgi/dbgi.c @@ -958,7 +958,7 @@ dbgi_parse_thread_entry_point(void *p) } //- rjf: parse raddbg info - RADDBG_Parsed raddbg_parsed = {0}; + RADDBG_Parsed raddbg_parsed = dbgi_parse_nil.rdbg; U64 arch_addr_size = 8; if(do_task) { @@ -1146,7 +1146,7 @@ dbgi_fuzzy_thread__entry_point(void *p) DBGI_FuzzySearchItemChunkList items_list = {0}; if(task_is_good) { - for(U64 procedure_idx = 1; task_is_good && procedure_idx < rdbg->procedure_count; procedure_idx += 1) + for(U64 procedure_idx = 1; task_is_good && procedure_idx < rdbg->procedures_count; procedure_idx += 1) { RADDBG_Procedure *procedure = &rdbg->procedures[procedure_idx]; U64 name_size = 0; diff --git a/src/dbgi/dbgi.h b/src/dbgi/dbgi.h index a5deda88..0a2339f5 100644 --- a/src/dbgi/dbgi.h +++ b/src/dbgi/dbgi.h @@ -307,7 +307,51 @@ struct DBGI_Shared global DBGI_Shared *dbgi_shared = 0; thread_static DBGI_ThreadCtx *dbgi_tctx = 0; -global DBGI_Parse dbgi_parse_nil = {0}; +global DBGI_Parse dbgi_parse_nil = +{ + 0, + 0, + 0, + {0}, + {0}, + 0, + {0}, + {0}, + { + 0, + 0, + 0, + 0, + {0}, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + &raddbg_binary_section_nil, 1, + &raddbg_file_path_node_nil, 1, + &raddbg_source_file_nil, 1, + &raddbg_unit_nil, 1, + &raddbg_vmap_entry_nil, 1, + &raddbg_type_node_nil, 1, + &raddbg_udt_nil, 1, + &raddbg_member_nil, 1, + &raddbg_enum_member_nil, 1, + &raddbg_global_variable_nil, 1, + &raddbg_vmap_entry_nil, 1, + &raddbg_thread_variable_nil, 1, + &raddbg_procedure_nil, 1, + &raddbg_scope_nil, 1, + &raddbg_voff_nil, 1, + &raddbg_vmap_entry_nil, 1, + &raddbg_local_nil, 1, + &raddbg_location_block_nil, 1, + 0, 0, + 0, 0, + }, +}; //////////////////////////////// //~ rjf: Main Layer Initialization diff --git a/src/df/core/df_core.c b/src/df/core/df_core.c index 797e7768..8b83ef00 100644 --- a/src/df/core/df_core.c +++ b/src/df/core/df_core.c @@ -3376,15 +3376,15 @@ df_voff_from_binary_symbol_name(DF_Entity *binary, String8 symbol_name) if(entity_num != 0) switch(name_map_kind) { default:{}break; - case RADDBG_NameMapKind_GlobalVariables: if(entity_num <= rdbg->global_variable_count) + case RADDBG_NameMapKind_GlobalVariables: { - RADDBG_GlobalVariable *global_var = &rdbg->global_variables[entity_num-1]; + RADDBG_GlobalVariable *global_var = raddbg_element_from_idx(rdbg, global_variables, entity_num-1); voff = global_var->voff; }break; - case RADDBG_NameMapKind_Procedures: if(entity_num <= rdbg->procedure_count) + case RADDBG_NameMapKind_Procedures: { - RADDBG_Procedure *procedure = &rdbg->procedures[entity_num-1]; - RADDBG_Scope *scope = &rdbg->scopes[procedure->root_scope_idx]; + RADDBG_Procedure *procedure = raddbg_element_from_idx(rdbg, procedures, entity_num-1); + RADDBG_Scope *scope = raddbg_element_from_idx(rdbg, scopes, procedure->root_scope_idx); voff = rdbg->scope_voffs[scope->voff_range_first]; }break; } @@ -4374,21 +4374,14 @@ df_dynamically_typed_eval_from_eval(TG_Graph *graph, RADDBG_Parsed *rdbg, DF_Ctr MemoryCopy(&vtable_vaddr, vtable_base_ptr_memory.str, addr_size); U64 vtable_voff = df_voff_from_vaddr(module, vtable_vaddr); U64 global_idx = raddbg_vmap_idx_from_voff(rdbg->global_vmap, rdbg->global_vmap_count, vtable_voff); - if(0 < global_idx && global_idx < rdbg->global_variable_count) + RADDBG_GlobalVariable *global_var = raddbg_element_from_idx(rdbg, global_variables, global_idx); + if(global_var->link_flags & RADDBG_LinkFlag_TypeScoped) { - RADDBG_GlobalVariable *global_var = &rdbg->global_variables[global_idx]; - if(global_var->link_flags & RADDBG_LinkFlag_TypeScoped && - 0 < global_var->container_idx && global_var->container_idx < rdbg->udt_count) - { - RADDBG_UDT *udt = &rdbg->udts[global_var->container_idx]; - if(0 < udt->self_type_idx && udt->self_type_idx < rdbg->type_node_count) - { - RADDBG_TypeNode *type = &rdbg->type_nodes[udt->self_type_idx]; - TG_Key derived_type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type->kind), (U64)udt->self_type_idx); - TG_Key ptr_to_derived_type_key = tg_cons_type_make(graph, TG_Kind_Ptr, derived_type_key, 0); - eval.type_key = ptr_to_derived_type_key; - } - } + RADDBG_UDT *udt = raddbg_element_from_idx(rdbg, udts, global_var->container_idx); + RADDBG_TypeNode *type = raddbg_element_from_idx(rdbg, type_nodes, udt->self_type_idx); + TG_Key derived_type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type->kind), (U64)udt->self_type_idx); + TG_Key ptr_to_derived_type_key = tg_cons_type_make(graph, TG_Kind_Ptr, derived_type_key, 0); + eval.type_key = ptr_to_derived_type_key; } } } diff --git a/src/df/core/df_core.mdesk b/src/df/core/df_core.mdesk index c373b467..6950a4a8 100644 --- a/src/df/core/df_core.mdesk +++ b/src/df/core/df_core.mdesk @@ -355,11 +355,11 @@ DF_CoreCmdTable:// | | | {FindCodeLocation 1 FilePath Nil 0 0 0 0 0 1 FileOutline "find_code_location" "Find Code Location" "Finds a specific source code location given file, line, and column coordinates. Opens the file if necessary." "" } //- rjf: view drivers - {Commands 0 Null Nil 0 0 0 0 0 0 List "commands" "Commands" "Opens the list of all commands." "" } + {Commands 1 Null Nil 0 0 0 0 0 0 List "commands" "Commands" "Opens the list of all commands." "" } {Target 1 Null Nil 0 0 0 0 0 0 Target "target" "Target" "Opens the editor for a target." "" } {Targets 0 Null Nil 0 0 0 0 0 0 Target "targets" "Targets" "Opens the list of all targets." "" } {FilePathMap 0 Null Nil 0 0 0 0 0 0 FileOutline "file_path_map" "File Path Map" "Opens the file path mapping editor." "" } - {Scheduler 0 Null Nil 0 0 0 0 0 0 Scheduler "scheduler" "Scheduler" "Opens the scheduler view, for process and thread controls." "" } + {Scheduler 0 Null Nil 0 0 0 0 0 0 Scheduler "scheduler" "Scheduler" "Opens the scheduler view, for process and thread controls." "threads,processes,targets" } {CallStack 0 Null Nil 0 0 0 0 0 0 Thread "call_stack" "Call Stack" "Opens the call stack view." "callstack,thread" } {Modules 0 Null Nil 0 0 0 0 0 0 Module "modules" "Modules" "Opens the modules view." "" } {PendingEntity 1 Null Nil 0 0 0 0 0 0 FileOutline "pending_entity" "Pending Entity" "Opens a view which waits for the passed entity to be completely loaded, then replaces itself with a new view." "" } diff --git a/src/df/core/generated/df_core.meta.c b/src/df/core/generated/df_core.meta.c index beac7ff1..a5e96dc3 100644 --- a/src/df/core/generated/df_core.meta.c +++ b/src/df/core/generated/df_core.meta.c @@ -179,11 +179,11 @@ DF_CmdSpecInfo df_g_core_cmd_kind_spec_info_table[] = { str8_lit_comp("entity_ref_fast_path"), str8_lit_comp("Activates the default behavior when clicking an entity reference."), str8_lit_comp(""), str8_lit_comp("Entity Reference Fast Path"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("spawn_entity_view"), str8_lit_comp("Spawns a new view, given an entity and other parameterizations."), str8_lit_comp(""), str8_lit_comp("Spawn Entity View"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Null}, { str8_lit_comp("find_code_location"), str8_lit_comp("Finds a specific source code location given file, line, and column coordinates. Opens the file if necessary."), str8_lit_comp(""), str8_lit_comp("Find Code Location"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_FilePath, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*1)}, DF_IconKind_FileOutline}, -{ str8_lit_comp("commands"), str8_lit_comp("Opens the list of all commands."), str8_lit_comp(""), str8_lit_comp("Commands"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_List}, +{ str8_lit_comp("commands"), str8_lit_comp("Opens the list of all commands."), str8_lit_comp(""), str8_lit_comp("Commands"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_List}, { str8_lit_comp("target"), str8_lit_comp("Opens the editor for a target."), str8_lit_comp(""), str8_lit_comp("Target"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Target}, { str8_lit_comp("targets"), str8_lit_comp("Opens the list of all targets."), str8_lit_comp(""), str8_lit_comp("Targets"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Target}, { str8_lit_comp("file_path_map"), str8_lit_comp("Opens the file path mapping editor."), str8_lit_comp(""), str8_lit_comp("File Path Map"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_FileOutline}, -{ str8_lit_comp("scheduler"), str8_lit_comp("Opens the scheduler view, for process and thread controls."), str8_lit_comp(""), str8_lit_comp("Scheduler"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Scheduler}, +{ str8_lit_comp("scheduler"), str8_lit_comp("Opens the scheduler view, for process and thread controls."), str8_lit_comp("threads,processes,targets"), str8_lit_comp("Scheduler"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Scheduler}, { str8_lit_comp("call_stack"), str8_lit_comp("Opens the call stack view."), str8_lit_comp("callstack,thread"), str8_lit_comp("Call Stack"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Thread}, { str8_lit_comp("modules"), str8_lit_comp("Opens the modules view."), str8_lit_comp(""), str8_lit_comp("Modules"), (DF_CmdSpecFlag_OmitFromLists*0), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_Module}, { str8_lit_comp("pending_entity"), str8_lit_comp("Opens a view which waits for the passed entity to be completely loaded, then replaces itself with a new view."), str8_lit_comp(""), str8_lit_comp("Pending Entity"), (DF_CmdSpecFlag_OmitFromLists*1), {DF_CmdParamSlot_Null, DF_EntityKind_Nil, (DF_CmdQueryFlag_AllowFiles*0)|(DF_CmdQueryFlag_AllowFolders*0)|(DF_CmdQueryFlag_CodeInput*0)|(DF_CmdQueryFlag_KeepOldInput*0)|(DF_CmdQueryFlag_SelectOldInput*0)|(DF_CmdQueryFlag_Required*0)}, DF_IconKind_FileOutline}, diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index 1b24df7d..fadfc503 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -2839,13 +2839,12 @@ DF_VIEW_UI_FUNCTION_DEF(SymbolLister) //- rjf: submit best match when hitting enter w/ no selection if(slv->cursor.y == 0 && items.count != 0 && os_key_press(ui_events(), ui_window(), 0, OS_Key_Return)) { - U64 procedure_idx = items.v[0].procedure_idx; - if(0 < procedure_idx && procedure_idx < rdbg->procedure_count) + RADDBG_Procedure *procedure = raddbg_element_from_idx(rdbg, procedures, items.v[0].procedure_idx); + U64 name_size = 0; + U8 *name_base = raddbg_string_from_idx(rdbg, procedure->name_string_idx, &name_size); + String8 name = str8(name_base, name_size); + if(name.size != 0) { - RADDBG_Procedure *procedure = &rdbg->procedures[procedure_idx]; - U64 name_size = 0; - U8 *name_base = raddbg_string_from_idx(rdbg, procedure->name_string_idx, &name_size); - String8 name = str8(name_base, name_size); DF_CmdParams p = df_cmd_params_from_view(ws, panel, view); p.string = name; df_cmd_params_mark_slot(&p, DF_CmdParamSlot_String); @@ -2878,17 +2877,12 @@ DF_VIEW_UI_FUNCTION_DEF(SymbolLister) UI_Focus((slv->cursor.y == idx+1) ? UI_FocusKind_On : UI_FocusKind_Off) { DBGI_FuzzySearchItem *item = &items.v[idx]; - if(item->procedure_idx >= rdbg->procedure_count) { continue; } - RADDBG_Procedure *procedure = &rdbg->procedures[item->procedure_idx]; + RADDBG_Procedure *procedure = raddbg_element_from_idx(rdbg, procedures, item->procedure_idx); U64 name_size = 0; U8 *name_base = raddbg_string_from_idx(rdbg, procedure->name_string_idx, &name_size); String8 name = str8(name_base, name_size); - TG_Key type_key = tg_key_zero(); - if(procedure->type_idx < rdbg->type_node_count) - { - RADDBG_TypeNode *type_node = &rdbg->type_nodes[procedure->type_idx]; - type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), procedure->type_idx); - } + RADDBG_TypeNode *type_node = raddbg_element_from_idx(rdbg, type_nodes, procedure->type_idx); + TG_Key type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), procedure->type_idx); ui_set_next_hover_cursor(OS_Cursor_HandPoint); UI_Box *box = ui_build_box_from_stringf(UI_BoxFlag_Clickable| UI_BoxFlag_DrawBackground| diff --git a/src/eval/eval_parser.c b/src/eval/eval_parser.c index 70c376bb..85d863d8 100644 --- a/src/eval/eval_parser.c +++ b/src/eval/eval_parser.c @@ -224,7 +224,7 @@ eval_push_member_map_from_raddbg_voff(Arena *arena, RADDBG_Parsed *rdbg, U64 vof if(tightest_scope != 0 && rdbg->procedures != 0) { U32 proc_idx = tightest_scope->proc_idx; - if(0 < proc_idx && proc_idx < rdbg->procedure_count) + if(0 < proc_idx && proc_idx < rdbg->procedures_count) { procedure = &rdbg->procedures[proc_idx]; } @@ -235,7 +235,7 @@ eval_push_member_map_from_raddbg_voff(Arena *arena, RADDBG_Parsed *rdbg, U64 vof if(procedure != 0 && rdbg->udts != 0 && procedure->link_flags & RADDBG_LinkFlag_TypeScoped) { U32 udt_idx = procedure->container_idx; - if(0 < udt_idx && udt_idx < rdbg->udt_count) + if(0 < udt_idx && udt_idx < rdbg->udts_count) { udt = &rdbg->udts[udt_idx]; } @@ -253,7 +253,7 @@ eval_push_member_map_from_raddbg_voff(Arena *arena, RADDBG_Parsed *rdbg, U64 vof member_idx < udt->member_first+udt->member_count; member_idx += 1) { - if(member_idx < 1 || rdbg->member_count <= member_idx) + if(member_idx < 1 || rdbg->members_count <= member_idx) { break; } @@ -515,13 +515,9 @@ eval_leaf_type_from_name(RADDBG_Parsed *rdbg, String8 name) U32 *matches = raddbg_matches_from_map_node(rdbg, node, &match_count); if(match_count != 0) { - U32 type_node_idx = matches[0]; - if(type_node_idx < rdbg->type_node_count) - { - RADDBG_TypeNode *type_node = &rdbg->type_nodes[type_node_idx]; - key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), (U64)type_node_idx); - found = 1; - } + RADDBG_TypeNode *type_node = raddbg_element_from_idx(rdbg, type_nodes, matches[0]); + found = type_node->kind != RADDBG_TypeKind_NULL; + key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), (U64)matches[0]); } } } @@ -877,13 +873,13 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 if(mapped_identifier == 0) { U64 local_num = eval_num_from_string(ctx->locals_map, local_lookup_string); - if(local_num != 0 && - ctx->rdbg->locals != 0 && (1 <= local_num && local_num <= ctx->rdbg->local_count) && - ctx->rdbg->type_nodes != 0) + if(local_num != 0) { mapped_identifier = 1; identifier_type_is_possibly_dynamically_overridden = 1; - RADDBG_Local *local_var = &ctx->rdbg->locals[local_num-1]; + RADDBG_Local *local_var = raddbg_element_from_idx(ctx->rdbg, locals, local_num-1); + RADDBG_TypeNode *type_node = raddbg_element_from_idx(ctx->rdbg, type_nodes, local_var->type_idx); + type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), (U64)local_var->type_idx); // rjf: grab location info for(U32 loc_block_idx = local_var->location_first; @@ -927,14 +923,6 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 } } } - - // rjf: get type - if(0 <= local_var->type_idx && local_var->type_idx < ctx->rdbg->type_node_count) - { - U32 type_idx = local_var->type_idx; - RADDBG_TypeNode *type_node = &ctx->rdbg->type_nodes[type_idx]; - type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), (U64)type_idx); - } } } @@ -994,7 +982,7 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 loc_kind = RADDBG_LocationKind_AddrBytecodeStream; loc_bytecode = eval_bytecode_from_oplist(arena, &oplist); U32 type_idx = global_var->type_idx; - if(type_idx < ctx->rdbg->type_node_count) + if(type_idx < ctx->rdbg->type_nodes_count) { RADDBG_TypeNode *type_node = &ctx->rdbg->type_nodes[type_idx]; type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), (U64)type_idx); @@ -1032,7 +1020,7 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 loc_kind = RADDBG_LocationKind_AddrBytecodeStream; loc_bytecode = eval_bytecode_from_oplist(arena, &oplist); U32 type_idx = thread_var->type_idx; - if(type_idx < ctx->rdbg->type_node_count) + if(type_idx < ctx->rdbg->type_nodes_count) { RADDBG_TypeNode *type_node = &ctx->rdbg->type_nodes[type_idx]; type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), (U64)type_idx); @@ -1072,7 +1060,7 @@ eval_parse_expr_from_text_tokens__prec(Arena *arena, EVAL_ParseCtx *ctx, String8 loc_kind = RADDBG_LocationKind_ValBytecodeStream; loc_bytecode = eval_bytecode_from_oplist(arena, &oplist); U32 type_idx = procedure->type_idx; - if(type_idx < ctx->rdbg->type_node_count) + if(type_idx < ctx->rdbg->type_nodes_count) { RADDBG_TypeNode *type_node = &ctx->rdbg->type_nodes[type_idx]; type_key = tg_key_ext(tg_kind_from_raddbg_type_kind(type_node->kind), (U64)type_idx); diff --git a/src/raddbg/raddbg.h b/src/raddbg/raddbg.h index 11bcab99..4b352cd0 100644 --- a/src/raddbg/raddbg.h +++ b/src/raddbg/raddbg.h @@ -40,6 +40,7 @@ // always have the same color ordering? // // [ ] middle mouse button on tab should close it +// [ ] pipe failure-to-launch errors back to frontend //////////////////////////////// //~ rjf: Hot, High Priority Tasks (Complete Unusability, Crashes, Fire-Worthy) diff --git a/src/raddbg_format/raddbg_format_parse.c b/src/raddbg_format/raddbg_format_parse.c index 015f3cba..b29e9776 100644 --- a/src/raddbg_format/raddbg_format_parse.c +++ b/src/raddbg_format/raddbg_format_parse.c @@ -121,16 +121,16 @@ raddbg_parse(RADDBG_U8 *data, RADDBG_U64 size, RADDBG_Parsed *out){ out->top_level_info = tli; } - raddbg_parse__extract_primary(out, out->binary_sections, &out->binary_section_count, + raddbg_parse__extract_primary(out, out->binary_sections, &out->binary_sections_count, RADDBG_DataSectionTag_BinarySections); - raddbg_parse__extract_primary(out, out->file_paths, &out->file_path_count, + raddbg_parse__extract_primary(out, out->file_paths, &out->file_paths_count, RADDBG_DataSectionTag_FilePathNodes); - raddbg_parse__extract_primary(out, out->source_files, &out->source_file_count, + raddbg_parse__extract_primary(out, out->source_files, &out->source_files_count, RADDBG_DataSectionTag_SourceFiles); - raddbg_parse__extract_primary(out, out->units, &out->unit_count, + raddbg_parse__extract_primary(out, out->units, &out->units_count, RADDBG_DataSectionTag_Units); raddbg_parse__extract_primary(out, out->unit_vmap, &out->unit_vmap_count, @@ -139,54 +139,54 @@ raddbg_parse(RADDBG_U8 *data, RADDBG_U64 size, RADDBG_Parsed *out){ raddbg_parse__extract_primary(out, out->unit_vmap, &out->unit_vmap_count, RADDBG_DataSectionTag_UnitVmap); - raddbg_parse__extract_primary(out, out->type_nodes, &out->type_node_count, + raddbg_parse__extract_primary(out, out->type_nodes, &out->type_nodes_count, RADDBG_DataSectionTag_TypeNodes); - raddbg_parse__extract_primary(out, out->udts, &out->udt_count, + raddbg_parse__extract_primary(out, out->udts, &out->udts_count, RADDBG_DataSectionTag_UDTs); - raddbg_parse__extract_primary(out, out->members, &out->member_count, + raddbg_parse__extract_primary(out, out->members, &out->members_count, RADDBG_DataSectionTag_Members); - raddbg_parse__extract_primary(out, out->enum_members, &out->enum_member_count, + raddbg_parse__extract_primary(out, out->enum_members, &out->enum_members_count, RADDBG_DataSectionTag_EnumMembers); - raddbg_parse__extract_primary(out, out->global_variables, &out->global_variable_count, + raddbg_parse__extract_primary(out, out->global_variables, &out->global_variables_count, RADDBG_DataSectionTag_GlobalVariables); raddbg_parse__extract_primary(out, out->global_vmap, &out->global_vmap_count, RADDBG_DataSectionTag_GlobalVmap); - raddbg_parse__extract_primary(out, out->thread_variables, &out->thread_variable_count, + raddbg_parse__extract_primary(out, out->thread_variables, &out->thread_variables_count, RADDBG_DataSectionTag_ThreadVariables); - raddbg_parse__extract_primary(out, out->procedures, &out->procedure_count, + raddbg_parse__extract_primary(out, out->procedures, &out->procedures_count, RADDBG_DataSectionTag_Procedures); - raddbg_parse__extract_primary(out, out->scopes, &out->scope_count, + raddbg_parse__extract_primary(out, out->scopes, &out->scopes_count, RADDBG_DataSectionTag_Scopes); - raddbg_parse__extract_primary(out, out->scope_voffs, &out->scope_voff_count, + raddbg_parse__extract_primary(out, out->scope_voffs, &out->scope_voffs_count, RADDBG_DataSectionTag_ScopeVoffData); raddbg_parse__extract_primary(out, out->scope_vmap, &out->scope_vmap_count, RADDBG_DataSectionTag_ScopeVmap); - raddbg_parse__extract_primary(out, out->locals, &out->local_count, + raddbg_parse__extract_primary(out, out->locals, &out->locals_count, RADDBG_DataSectionTag_Locals); - raddbg_parse__extract_primary(out, out->location_blocks, &out->location_block_count, + raddbg_parse__extract_primary(out, out->location_blocks, &out->location_blocks_count, RADDBG_DataSectionTag_LocationBlocks); raddbg_parse__extract_primary(out, out->location_data, &out->location_data_size, RADDBG_DataSectionTag_LocationData); { - raddbg_parse__extract_primary(out, out->name_maps, &out->name_map_count, + raddbg_parse__extract_primary(out, out->name_maps, &out->name_maps_count, RADDBG_DataSectionTag_NameMaps); RADDBG_NameMap *name_map_ptr = out->name_maps; - RADDBG_NameMap *name_map_opl = out->name_maps + out->name_map_count; + RADDBG_NameMap *name_map_opl = out->name_maps + out->name_maps_count; for (; name_map_ptr < name_map_opl; name_map_ptr += 1){ if (out->name_maps_by_kind[name_map_ptr->kind] == 0){ out->name_maps_by_kind[name_map_ptr->kind] = name_map_ptr; @@ -194,6 +194,27 @@ raddbg_parse(RADDBG_U8 *data, RADDBG_U64 size, RADDBG_Parsed *out){ } } +#if !defined(RADDBG_DISABLE_NILS) + if(out->binary_sections == 0) { out->binary_sections = &raddbg_binary_section_nil; out->binary_sections_count = 1; } + if(out->file_paths == 0) { out->file_paths = &raddbg_file_path_node_nil; out->file_paths_count = 1; } + if(out->source_files == 0) { out->source_files = &raddbg_source_file_nil; out->source_files_count = 1; } + if(out->units == 0) { out->units = &raddbg_unit_nil; out->units_count = 1; } + if(out->unit_vmap == 0) { out->unit_vmap = &raddbg_vmap_entry_nil; out->unit_vmap_count = 1; } + if(out->type_nodes == 0) { out->type_nodes = &raddbg_type_node_nil; out->type_nodes_count = 1; } + if(out->udts == 0) { out->udts = &raddbg_udt_nil; out->udts_count = 1; } + if(out->members == 0) { out->members = &raddbg_member_nil; out->members_count = 1; } + if(out->enum_members == 0) { out->enum_members = &raddbg_enum_member_nil; out->enum_members_count = 1; } + if(out->global_variables == 0) { out->global_variables = &raddbg_global_variable_nil; out->global_variables_count = 1; } + if(out->global_vmap == 0) { out->global_vmap = &raddbg_vmap_entry_nil; out->global_vmap_count = 1; } + if(out->thread_variables == 0) { out->thread_variables = &raddbg_thread_variable_nil; out->thread_variables_count = 1; } + if(out->procedures == 0) { out->procedures = &raddbg_procedure_nil; out->procedures_count = 1; } + if(out->scopes == 0) { out->scopes = &raddbg_scope_nil; out->scopes_count = 1; } + if(out->scope_voffs == 0) { out->scope_voffs = &raddbg_voff_nil; out->scope_voffs_count = 1; } + if(out->scope_vmap == 0) { out->scope_vmap = &raddbg_vmap_entry_nil; out->scope_vmap_count = 1; } + if(out->locals == 0) { out->locals = &raddbg_local_nil; out->locals_count = 1; } + if(out->location_blocks == 0) { out->location_blocks = &raddbg_location_block_nil; out->location_blocks_count = 1; } +#endif + } return(result); @@ -495,13 +516,13 @@ raddbg_matches_from_map_node(RADDBG_Parsed *p, RADDBG_NameMapNode *node, RADDBG_PROC RADDBG_U64 raddbg_first_voff_from_proc(RADDBG_Parsed *p, RADDBG_U32 proc_id){ RADDBG_U64 result = 0; - if (0 < proc_id && proc_id < p->procedure_count){ + if (0 < proc_id && proc_id < p->procedures_count){ RADDBG_Procedure *proc = p->procedures + proc_id; RADDBG_U32 scope_id = proc->root_scope_idx; - if (0 < scope_id && scope_id < p->scope_count){ + if (0 < scope_id && scope_id < p->scopes_count){ RADDBG_Scope *scope = p->scopes + scope_id; if (scope->voff_range_first < scope->voff_range_opl && - scope->voff_range_first < p->scope_voff_count){ + scope->voff_range_first < p->scope_voffs_count){ result = p->scope_voffs[scope->voff_range_first]; } } diff --git a/src/raddbg_format/raddbg_format_parse.h b/src/raddbg_format/raddbg_format_parse.h index f2cf3074..5f8e0d14 100644 --- a/src/raddbg_format/raddbg_format_parse.h +++ b/src/raddbg_format/raddbg_format_parse.h @@ -30,45 +30,45 @@ typedef struct RADDBG_Parsed{ RADDBG_TopLevelInfo* top_level_info; RADDBG_BinarySection* binary_sections; - RADDBG_U64 binary_section_count; + RADDBG_U64 binary_sections_count; RADDBG_FilePathNode* file_paths; - RADDBG_U64 file_path_count; + RADDBG_U64 file_paths_count; RADDBG_SourceFile* source_files; - RADDBG_U64 source_file_count; + RADDBG_U64 source_files_count; RADDBG_Unit* units; - RADDBG_U64 unit_count; + RADDBG_U64 units_count; RADDBG_VMapEntry* unit_vmap; RADDBG_U64 unit_vmap_count; RADDBG_TypeNode* type_nodes; - RADDBG_U64 type_node_count; + RADDBG_U64 type_nodes_count; RADDBG_UDT* udts; - RADDBG_U64 udt_count; + RADDBG_U64 udts_count; RADDBG_Member* members; - RADDBG_U64 member_count; + RADDBG_U64 members_count; RADDBG_EnumMember* enum_members; - RADDBG_U64 enum_member_count; + RADDBG_U64 enum_members_count; RADDBG_GlobalVariable* global_variables; - RADDBG_U64 global_variable_count; + RADDBG_U64 global_variables_count; RADDBG_VMapEntry* global_vmap; RADDBG_U64 global_vmap_count; RADDBG_ThreadVariable* thread_variables; - RADDBG_U64 thread_variable_count; + RADDBG_U64 thread_variables_count; RADDBG_Procedure* procedures; - RADDBG_U64 procedure_count; + RADDBG_U64 procedures_count; RADDBG_Scope* scopes; - RADDBG_U64 scope_count; + RADDBG_U64 scopes_count; RADDBG_U64* scope_voffs; - RADDBG_U64 scope_voff_count; + RADDBG_U64 scope_voffs_count; RADDBG_VMapEntry* scope_vmap; RADDBG_U64 scope_vmap_count; RADDBG_Local* locals; - RADDBG_U64 local_count; + RADDBG_U64 locals_count; RADDBG_LocationBlock* location_blocks; - RADDBG_U64 location_block_count; + RADDBG_U64 location_blocks_count; RADDBG_U8* location_data; RADDBG_U64 location_data_size; RADDBG_NameMap* name_maps; - RADDBG_U64 name_map_count; + RADDBG_U64 name_maps_count; // other helpers @@ -124,6 +124,27 @@ typedef struct RADDBG_ParsedNameMap{ RADDBG_U64 node_count; } RADDBG_ParsedNameMap; +//////////////////////////////// +//~ Global Nils + +#if !defined(RADDBG_DISABLE_NILS) +static RADDBG_BinarySection raddbg_binary_section_nil = {0}; +static RADDBG_FilePathNode raddbg_file_path_node_nil = {0}; +static RADDBG_SourceFile raddbg_source_file_nil = {0}; +static RADDBG_Unit raddbg_unit_nil = {0}; +static RADDBG_VMapEntry raddbg_vmap_entry_nil = {0}; +static RADDBG_TypeNode raddbg_type_node_nil = {0}; +static RADDBG_UDT raddbg_udt_nil = {0}; +static RADDBG_Member raddbg_member_nil = {0}; +static RADDBG_EnumMember raddbg_enum_member_nil = {0}; +static RADDBG_GlobalVariable raddbg_global_variable_nil = {0}; +static RADDBG_ThreadVariable raddbg_thread_variable_nil = {0}; +static RADDBG_Procedure raddbg_procedure_nil = {0}; +static RADDBG_Scope raddbg_scope_nil = {0}; +static U64 raddbg_voff_nil = 0; +static RADDBG_LocationBlock raddbg_location_block_nil = {0}; +static RADDBG_Local raddbg_local_nil = {0}; +#endif //////////////////////////////// //~ RADDBG Parse API @@ -138,6 +159,8 @@ RADDBG_PROC RADDBG_U32* raddbg_idx_run_from_first_count(RADDBG_Parsed *parsed, RADDBG_U32 first, RADDBG_U32 raw_count, RADDBG_U32 *n_out); +//- table lookups +#define raddbg_element_from_idx(parsed, name, idx) ((0 <= (idx) && (idx) < (parsed)->name##_count) ? &(parsed)->name[idx] : (parsed)->name ? &(parsed)->name[0] : 0) //- line info RADDBG_PROC void diff --git a/src/render/render_core.h b/src/render/render_core.h index fbd9e04e..e4db1699 100644 --- a/src/render/render_core.h +++ b/src/render/render_core.h @@ -193,61 +193,6 @@ struct R_PassList U64 count; }; -//////////////////////////////// -//~ rjf: 2D Rendering Types - -typedef enum R2_CmdKind -{ - R2_CmdKind_Null, - R2_CmdKind_Rects, - R2_CmdKind_COUNT -} -R2_CmdKind; - -typedef struct R2_CmdInst_Rect R2_CmdInst_Rect; -struct R2_CmdInst_Rect -{ - Rng2F32 dst; - Rng2F32 src; - Vec4F32 colors[Corner_COUNT]; - F32 corner_radii[Corner_COUNT]; - F32 border_thickness; - F32 edge_softness; - F32 white_texture_override; - F32 _unused_[1]; -}; - -typedef struct R2_Cmd R2_Cmd; -struct R2_Cmd -{ - R2_CmdKind kind; - R_Handle texture; - Rng2F32 clip; - Vec2F32 translate; - F32 transparency; - U64 count; - union - { - void *data; - R2_CmdInst_Rect *data__rect; - }; -}; - -typedef struct R2_CmdNode R2_CmdNode; -struct R2_CmdNode -{ - R2_CmdNode *next; - R2_Cmd cmd; -}; - -typedef struct R2_CmdList R2_CmdList; -struct R2_CmdList -{ - R2_CmdNode *first; - R2_CmdNode *last; - U64 count; -}; - //////////////////////////////// //~ rjf: Handle Type Functions diff --git a/src/type_graph/type_graph.c b/src/type_graph/type_graph.c index 73c3da57..feb1f797 100644 --- a/src/type_graph/type_graph.c +++ b/src/type_graph/type_graph.c @@ -331,7 +331,7 @@ tg_type_from_graph_raddbg_key(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg case TG_KeyKind_Ext: { U64 type_node_idx = key.u64[0]; - if(0 <= type_node_idx && type_node_idx < rdbg->type_node_count) + if(0 <= type_node_idx && type_node_idx < rdbg->type_nodes_count) { RADDBG_TypeNode *rdbg_type = &rdbg->type_nodes[type_node_idx]; TG_Kind kind = tg_kind_from_raddbg_type_kind(rdbg_type->kind); @@ -348,12 +348,12 @@ tg_type_from_graph_raddbg_key(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg U32 members_count = 0; { U32 udt_idx = rdbg_type->user_defined.udt_idx; - if(0 <= udt_idx && udt_idx < rdbg->udt_count) + if(0 <= udt_idx && udt_idx < rdbg->udts_count) { RADDBG_UDT *udt = &rdbg->udts[udt_idx]; members_count = udt->member_count; members = push_array(arena, TG_Member, members_count); - if(members_count != 0 && 0 <= udt->member_first && udt->member_first+udt->member_count <= rdbg->member_count) + if(members_count != 0 && 0 <= udt->member_first && udt->member_first+udt->member_count <= rdbg->members_count) { for(U32 member_idx = udt->member_first; member_idx < udt->member_first+udt->member_count; @@ -361,7 +361,7 @@ tg_type_from_graph_raddbg_key(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg { RADDBG_Member *src = &rdbg->members[member_idx]; TG_Kind member_type_kind = TG_Kind_Null; - if(src->type_idx < rdbg->type_node_count) + if(src->type_idx < rdbg->type_nodes_count) { RADDBG_TypeNode *member_type = &rdbg->type_nodes[src->type_idx]; member_type_kind = tg_kind_from_raddbg_type_kind(member_type->kind); @@ -406,12 +406,12 @@ tg_type_from_graph_raddbg_key(Arena *arena, TG_Graph *graph, RADDBG_Parsed *rdbg U32 enum_vals_count = 0; { U32 udt_idx = rdbg_type->user_defined.udt_idx; - if(0 <= udt_idx && udt_idx < rdbg->udt_count) + if(0 <= udt_idx && udt_idx < rdbg->udts_count) { RADDBG_UDT *udt = &rdbg->udts[udt_idx]; enum_vals_count = udt->member_count; enum_vals = push_array(arena, TG_EnumVal, enum_vals_count); - if(0 <= udt->member_first && udt->member_first+udt->member_count < rdbg->enum_member_count) + if(0 <= udt->member_first && udt->member_first+udt->member_count < rdbg->enum_members_count) { for(U32 member_idx = udt->member_first; member_idx < udt->member_first+udt->member_count;