From 2a7177861b60e9a7be60399988f97b3cb76237f3 Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Mon, 6 Oct 2025 17:06:00 -0700 Subject: [PATCH] remove extra watch row column cases - simplify most cases down to expr / eval. use extra 'note' for watch window cells to annotate type info - this sacrifices the full type evaluation cell, and instead uses a small extra bit of text to denote the type for quick reading. but this full type cell is not needed in most cases, and it can always be reobtained with an explicit `typeof` evaluation. --- src/eval/eval_ir.c | 8 ++ src/raddbg/raddbg_core.c | 39 ++++++++- src/raddbg/raddbg_eval.c | 10 --- src/raddbg/raddbg_views.c | 163 ++++++++++-------------------------- src/raddbg/raddbg_views.h | 2 +- src/raddbg/raddbg_widgets.c | 13 ++- src/raddbg/raddbg_widgets.h | 2 + 7 files changed, 102 insertions(+), 135 deletions(-) diff --git a/src/eval/eval_ir.c b/src/eval/eval_ir.c index 42fca2f9..f38c2557 100644 --- a/src/eval/eval_ir.c +++ b/src/eval/eval_ir.c @@ -1815,6 +1815,7 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I mapped_type_key = e_type_key_ext(e_type_kind_from_rdi(type_node->kind), local->type_idx, module_idx); // rjf: extract local's location block + B32 got_location_block = 0; U64 ip_voff = e_base_ctx->thread_ip_voff; for(U32 loc_block_idx = local->location_first; loc_block_idx < local->location_opl; @@ -1825,8 +1826,15 @@ e_push_irtree_and_type_from_expr(Arena *arena, E_IRTreeAndType *root_parent, E_I { mapped_location_block_module = module; mapped_location_block = block; + got_location_block = 1; } } + + // rjf: no location block -> error + if(!got_location_block) + { + e_msgf(arena, &result.msgs, E_MsgKind_MissingInfo, expr->range, "Could not find location info for `%S`.", string__redirected); + } } }break; diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 973cfeb4..2c907bda 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -5041,6 +5041,39 @@ rd_view_ui(Rng2F32 rect) { cell_params.flags &= ~RD_CellFlag_NoBackground; } + + // rjf: apply type note + if(!(cell_info.flags & RD_WatchCellFlag_NoEval) && + cell->eval.space.kind == RD_EvalSpaceKind_CtrlEntity && + row_info->callstack_thread == &ctrl_entity_nil && + e_type_kind_from_key(cell->eval.irtree.type_key) != E_TypeKind_Function) + UI_FontSize(ui_top_font_size()*0.8f) + { + if(cell_width_px >= ui_top_font_size()*8.f) + { + E_TypeKey type_key = cell->eval.irtree.type_key; + String8 note_string = {0}; + if(cell->eval.irtree.mode == E_Mode_Null && (row->block->eval.irtree.mode != E_Mode_Null || row->block->parent == &ev_nil_block)) + { + note_string = str8f(scratch.arena, "type (size: %I64u)", e_type_byte_size_from_key(type_key)); + } + else if(cell->eval.irtree.mode == E_Mode_Null) + { + note_string = str8f(scratch.arena, "type (size: %I64u, offset: %I64u)", + e_type_byte_size_from_key(type_key), + cell->eval.value.u64); + } + else + { + note_string = e_type_string_from_key(scratch.arena, type_key); + } + DR_FStrList note_fstrs = rd_fstrs_from_code_string(scratch.arena, 1, 0, ui_color_from_name(str8_lit("text")), note_string); + F32 note_fstrs_width_px = dr_dim_from_fstrs(0, ¬e_fstrs).x + 10; + note_fstrs_width_px = Min(note_fstrs_width_px, cell_width_px*0.5f); + cell_params.note_fstrs = note_fstrs; + cell_params.note_width = ui_px(note_fstrs_width_px, 1); + } + } } // rjf: build @@ -6448,15 +6481,15 @@ rd_window_frame(void) RDI_Parsed *rdi = di_rdi_from_key(access, dbgi_key, 0, 0); if(rdi->raw_data_size != 0) { - ui_labelf("Symbols successfully loaded from %S", dbg_info_entity->string); + ui_labelf("Debug information successfully loaded from %S", dbg_info_entity->string); } else if(dbg_info_entity->string.size != 0) { - ui_labelf("Symbols not found at %S", dbg_info_entity->string); + ui_labelf("Debug information not found at %S", dbg_info_entity->string); } else if(dbg_info_entity->string.size == 0) { - ui_labelf("Symbol information not found in module file"); + ui_labelf("Debug information location not found in module file"); } access_close(access); } diff --git a/src/raddbg/raddbg_eval.c b/src/raddbg/raddbg_eval.c index 4de6e60d..82c501ce 100644 --- a/src/raddbg/raddbg_eval.c +++ b/src/raddbg/raddbg_eval.c @@ -208,9 +208,7 @@ E_TYPE_EXPAND_INFO_FUNCTION_DEF(registers) CTRL_Entity *thread = ctrl_entity_from_handle(&d_state->ctrl_entity_store->ctx, rd_regs()->thread); Arch arch = thread->arch; U64 reg_count = regs_reg_code_count_from_arch(arch); - U64 alias_count = regs_alias_code_count_from_arch(arch); String8 *reg_strings = regs_reg_code_string_table_from_arch(arch); - String8 *alias_strings = regs_alias_code_string_table_from_arch(arch); String8List exprs_list = {0}; for(U64 idx = 1; idx < reg_count; idx += 1) { @@ -220,14 +218,6 @@ E_TYPE_EXPAND_INFO_FUNCTION_DEF(registers) str8_list_push(scratch.arena, &exprs_list, reg_strings[idx]); } } - for(U64 idx = 1; idx < alias_count; idx += 1) - { - FuzzyMatchRangeList matches = fuzzy_match_find(scratch.arena, filter, alias_strings[idx]); - if(matches.count == matches.needle_part_count) - { - str8_list_push(scratch.arena, &exprs_list, alias_strings[idx]); - } - } String8Array *accel = push_array(arena, String8Array, 1); *accel = str8_array_from_list(arena, &exprs_list); E_TypeExpandInfo info = {accel, accel->count}; diff --git a/src/raddbg/raddbg_views.c b/src/raddbg/raddbg_views.c index beb48052..db9294a7 100644 --- a/src/raddbg/raddbg_views.c +++ b/src/raddbg/raddbg_views.c @@ -848,20 +848,15 @@ rd_id_from_watch_cell(RD_WatchCell *cell) return result; } -internal RD_WatchCell * -rd_watch_cell_list_push(Arena *arena, RD_WatchCellList *list) -{ - RD_WatchCell *cell = push_array(arena, RD_WatchCell, 1); - cell->index = list->count; - SLLQueuePush(list->first, list->last, cell); - list->count += 1; - return cell; -} - internal RD_WatchCell * rd_watch_cell_list_push_new_(Arena *arena, RD_WatchCellList *list, RD_WatchCell *params) { - RD_WatchCell *cell = rd_watch_cell_list_push(arena, list); + RD_WatchCell *cell = push_array(arena, RD_WatchCell, 1); + { + cell->index = list->count; + SLLQueuePush(list->first, list->last, cell); + list->count += 1; + } U64 index = cell->index; MemoryCopyStruct(cell, params); cell->index = index; @@ -869,6 +864,7 @@ rd_watch_cell_list_push_new_(Arena *arena, RD_WatchCellList *list, RD_WatchCell { cell->pct = cell->default_pct; } + list->pct_sum += cell->pct; cell->next = 0; return cell; } @@ -1153,29 +1149,15 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row) //////////////////////////// //- rjf: @watch_row_build_cells files / folders // - else if(row->eval.space.kind == E_SpaceKind_FileSystem) + else if(row->eval.space.kind == E_SpaceKind_FileSystem && + e_type_kind_from_key(row->eval.irtree.type_key) == E_TypeKind_Set) { E_Type *type = e_type_from_key(row->eval.irtree.type_key); - if(type->kind == E_TypeKind_Set) + String8 file_path = e_string_from_id(row->eval.value.u64); + rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_NoEval|RD_WatchCellFlag_Indented|RD_WatchCellFlag_Button|RD_WatchCellFlag_IsNonCode, .pct = 1.f); + if(str8_match(type->name, str8_lit("file"), 0)) { - String8 file_path = e_string_from_id(row->eval.value.u64); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_NoEval|RD_WatchCellFlag_Indented|RD_WatchCellFlag_Button|RD_WatchCellFlag_IsNonCode, .pct = 1.f); - if(str8_match(type->name, str8_lit("file"), 0)) - { - info.can_expand = 0; - } - } - else - { - info.cell_style_key = str8_lit("expr_and_eval"); - RD_Cfg *view = rd_cfg_from_id(rd_regs()->view); - RD_Cfg *style = rd_cfg_child_from_string(view, info.cell_style_key); - RD_Cfg *w_cfg = style->first; - F32 next_pct = 0; -#define take_pct() (next_pct = (F32)f64_from_str8(w_cfg->string), w_cfg = w_cfg->next, next_pct) - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_NoEval|RD_WatchCellFlag_Indented, .default_pct = 0.35f, .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .default_pct = 0.65f, .pct = take_pct()); -#undef take_pct + info.can_expand = 0; } } @@ -1399,33 +1381,6 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row) .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_Indented, .pct = 1.f); } - //////////////////////////// - //- rjf: @watch_row_build_cells meta-evaluation catch-all: expression / value - // - else if(row->eval.space.kind == RD_EvalSpaceKind_MetaCfg || - row->eval.space.kind == RD_EvalSpaceKind_MetaCmd || - row->eval.space.kind == RD_EvalSpaceKind_MetaCtrlEntity || - row->eval.space.kind == E_SpaceKind_File) - { - E_TypeKey substantive_row_eval_type = e_type_key_unwrap(row->eval.irtree.type_key, E_TypeUnwrapFlag_Meta); - if(e_type_kind_from_key(substantive_row_eval_type) == E_TypeKind_Array && - e_type_kind_from_key(e_type_key_direct(substantive_row_eval_type)) == E_TypeKind_U8) - { - info.can_expand = 0; - } - info.cell_style_key = str8_lit("expr_and_eval"); - RD_Cfg *view = rd_cfg_from_id(rd_regs()->view); - RD_Cfg *style = rd_cfg_child_from_string(view, info.cell_style_key); - RD_Cfg *w_cfg = style->first; - F32 next_pct = 0; -#define take_pct() (next_pct = (F32)f64_from_str8(w_cfg->string), w_cfg = w_cfg->next, next_pct) - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, - .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_NoEval|RD_WatchCellFlag_Indented, .default_pct = 0.35f, .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, - .default_pct = 0.65f, .pct = take_pct()); -#undef take_pct - } - //////////////////////////// //- rjf: @watch_row_build_cells procedures (expr & eval, mostly expr) // @@ -1466,71 +1421,24 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row) #undef take_pct } - //////////////////////////// - //- rjf: @watch_row_build_cells error rows - // - else if(row->eval.irtree.mode == E_Mode_Null && row->eval.msgs.max_kind > E_MsgKind_Null) - { - info.cell_style_key = str8_lit("expr_and_error"); - RD_Cfg *view = rd_cfg_from_id(rd_regs()->view); - RD_Cfg *style = rd_cfg_child_from_string(view, info.cell_style_key); - RD_Cfg *w_cfg = style->first; - F32 next_pct = 0; -#define take_pct() (next_pct = (F32)f64_from_str8(w_cfg->string), w_cfg = w_cfg->next, next_pct) - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, - .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_NoEval|RD_WatchCellFlag_Indented, - .default_pct = 0.60f, - .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .default_pct = 0.40f, .pct = take_pct()); -#undef take_pct - } - - //////////////////////////// - //- rjf: @watch_row_build_cells root-level type rows - // - else if(row->eval.irtree.mode == E_Mode_Null && (row->block->eval.irtree.mode != E_Mode_Null || row->block->parent == &ev_nil_block)) - { - info.cell_style_key = str8_lit("root_type"); - RD_Cfg *view = rd_cfg_from_id(rd_regs()->view); - RD_Cfg *style = rd_cfg_child_from_string(view, info.cell_style_key); - RD_Cfg *w_cfg = style->first; - F32 next_pct = 0; -#define take_pct() (next_pct = (F32)f64_from_str8(w_cfg->string), w_cfg = w_cfg->next, next_pct) - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, - .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_NoEval|RD_WatchCellFlag_Indented, - .default_pct = 0.50f, - .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, e_eval_wrapf(row->eval, "typeof($)"), .default_pct = 0.35f, .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, e_eval_wrapf(row->eval, "sizeof($)"), .default_pct = 0.15f, .pct = take_pct()); -#undef take_pct - } - - //////////////////////////// - //- rjf: @watch_row_build_cells sub-type rows - // - else if(row->eval.irtree.mode == E_Mode_Null) - { - info.cell_style_key = str8_lit("sub_type"); - RD_Cfg *view = rd_cfg_from_id(rd_regs()->view); - RD_Cfg *style = rd_cfg_child_from_string(view, info.cell_style_key); - RD_Cfg *w_cfg = style->first; - F32 next_pct = 0; -#define take_pct() (next_pct = (F32)f64_from_str8(w_cfg->string), w_cfg = w_cfg->next, next_pct) - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, - .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_NoEval|RD_WatchCellFlag_Indented, - .default_pct = 0.35f, - .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, e_eval_wrapf(row->eval, "typeof($)"), .default_pct = 0.35f, .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, e_eval_wrapf(row->eval, "sizeof($)"), .default_pct = 0.15f, .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, e_eval_wrapf(row->eval, "(uint64)(&$)"), .default_pct = 0.15f, .pct = take_pct()); -#undef take_pct - } - //////////////////////////// //- rjf: @watch_row_build_cells catchall (normal rows) // else { + // rjf: disable expansion on meta string evaluations + if(row->eval.space.kind == RD_EvalSpaceKind_MetaCfg || + row->eval.space.kind == RD_EvalSpaceKind_MetaCmd || + row->eval.space.kind == RD_EvalSpaceKind_MetaCtrlEntity || + row->eval.space.kind == E_SpaceKind_File) + { + E_TypeKey substantive_row_eval_type = e_type_key_unwrap(row->eval.irtree.type_key, E_TypeUnwrapFlag_Meta); + if(e_type_kind_from_key(substantive_row_eval_type) == E_TypeKind_Array && + e_type_kind_from_key(e_type_key_direct(substantive_row_eval_type)) == E_TypeKind_U8) + { + info.can_expand = 0; + } + } info.cell_style_key = str8_lit("normal"); RD_Cfg *view = rd_cfg_from_id(rd_regs()->view); RD_Cfg *style = rd_cfg_child_from_string(view, info.cell_style_key); @@ -1541,11 +1449,26 @@ rd_watch_row_info_from_row(Arena *arena, EV_Row *row) .flags = RD_WatchCellFlag_Expr|RD_WatchCellFlag_NoEval|RD_WatchCellFlag_Indented, .default_pct = 0.35f, .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .default_pct = 0.40f, .pct = take_pct()); - rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, e_eval_wrapf(row->eval, "typeof($)"), .default_pct = 0.25f, .pct = take_pct()); + rd_watch_cell_list_push_new(arena, &info.cells, RD_WatchCellKind_Eval, row->eval, .default_pct = 0.65f, .pct = take_pct()); #undef take_pct } + //////////////////////////// + //- rjf: normalize all cell widths + // + if(abs_f32(info.cells.pct_sum - 1.f) > 0.01f) + { + F32 sum = info.cells.pct_sum; + if(sum <= 0) + { + sum = 1.f; + } + for(RD_WatchCell *c = info.cells.first; c != 0; c = c->next) + { + c->pct /= sum; + } + } + scratch_end(scratch); } return info; diff --git a/src/raddbg/raddbg_views.h b/src/raddbg/raddbg_views.h index f13b2ecc..b4f40702 100644 --- a/src/raddbg/raddbg_views.h +++ b/src/raddbg/raddbg_views.h @@ -114,6 +114,7 @@ struct RD_WatchCellList RD_WatchCell *first; RD_WatchCell *last; U64 count; + F32 pct_sum; }; typedef struct RD_WatchRowInfo RD_WatchRowInfo; @@ -206,7 +207,6 @@ internal RD_CodeViewBuildResult rd_code_view_build(Arena *arena, RD_CodeViewStat //- rjf: cell list building internal U64 rd_id_from_watch_cell(RD_WatchCell *cell); -internal RD_WatchCell *rd_watch_cell_list_push(Arena *arena, RD_WatchCellList *list); internal RD_WatchCell *rd_watch_cell_list_push_new_(Arena *arena, RD_WatchCellList *list, RD_WatchCell *params); #define rd_watch_cell_list_push_new(arena, list, kind_, eval_, ...) rd_watch_cell_list_push_new_((arena), (list), &(RD_WatchCell){.kind = (kind_), .eval = (eval_), __VA_ARGS__}) diff --git a/src/raddbg/raddbg_widgets.c b/src/raddbg/raddbg_widgets.c index e61c9d4c..36cbe7f6 100644 --- a/src/raddbg/raddbg_widgets.c +++ b/src/raddbg/raddbg_widgets.c @@ -602,7 +602,7 @@ rd_title_fstrs_from_ctrl_entity(Arena *arena, CTRL_Entity *entity, B32 include_e if(rdi->raw_data_size == 0) { dr_fstrs_push_new(arena, &result, ¶ms, str8_lit(" ")); - dr_fstrs_push_new(arena, &result, ¶ms, str8_lit("(Symbols not found)"), .font = rd_font_from_slot(RD_FontSlot_Main), .raster_flags = rd_raster_flags_from_slot(RD_FontSlot_Main), .size = extras_size, .color = secondary_color); + dr_fstrs_push_new(arena, &result, ¶ms, str8_lit("(Debug information not loaded)"), .font = rd_font_from_slot(RD_FontSlot_Main), .raster_flags = rd_raster_flags_from_slot(RD_FontSlot_Main), .size = extras_size, .color = secondary_color); } access_close(access); } @@ -3372,8 +3372,10 @@ rd_cell(RD_CellParams *params, String8 string) B32 build_bindings = !!(params->flags & RD_CellFlag_Bindings) && !is_focus_active; B32 build_lhs_name_desc = (params->meta_fstrs.node_count != 0 || params->description.size != 0); B32 build_line_edit = (params->pre_edit_value.size != 0 || params->value_fstrs.node_count != 0); + B32 build_note = (params->note_fstrs.node_count != 0 && !is_focus_active); DR_FStrList lhs_name_fstrs = params->meta_fstrs; DR_FStrList value_name_fstrs = params->value_fstrs; + DR_FStrList note_fstrs = params->note_fstrs; ////////////////////////////// //- rjf: determine autocompletion string @@ -3801,6 +3803,15 @@ rd_cell(RD_CellParams *params, String8 string) } } + ////////////////////////////// + //- rjf: build notes + // + if(build_note) UI_Parent(box) UI_PrefWidth(params->note_width) + { + UI_Box *note_box = ui_build_box_from_key(UI_BoxFlag_DrawText, ui_key_zero()); + ui_box_equip_display_fstrs(note_box, ¬e_fstrs); + } + ////////////////////////////// //- rjf: do non-textual edits (delete, copy, cut) // diff --git a/src/raddbg/raddbg_widgets.h b/src/raddbg/raddbg_widgets.h index 88678f99..5d5a509e 100644 --- a/src/raddbg/raddbg_widgets.h +++ b/src/raddbg/raddbg_widgets.h @@ -51,6 +51,8 @@ struct RD_CellParams String8 pre_edit_value; DR_FStrList meta_fstrs; DR_FStrList value_fstrs; + DR_FStrList note_fstrs; + UI_Size note_width; String8 search_needle; String8 description;