diff --git a/src/df/core/df_core.c b/src/df/core/df_core.c index 38445b33..4b3feae2 100644 --- a/src/df/core/df_core.c +++ b/src/df/core/df_core.c @@ -8957,24 +8957,6 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) } } }break; - case DF_CoreCmdKind_ToggleBreakpointAtCursor: - { - DF_InteractRegs *regs = df_interact_regs(); - DF_Entity *file = df_entity_from_handle(regs->file); - if(file->kind == DF_EntityKind_File && regs->cursor.line != 0) - { - DF_CmdParams p = df_cmd_params_zero(); - p.entity = df_handle_from_entity(file); - p.text_point = regs->cursor; - df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_TextBreakpoint)); - } - else if(regs->vaddr_range.min != 0) - { - DF_CmdParams p = df_cmd_params_zero(); - p.vaddr = regs->vaddr_range.min; - df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_AddressBreakpoint)); - } - }break; //- rjf: watches case DF_CoreCmdKind_ToggleWatchPin: @@ -9028,6 +9010,117 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) } }break; + //- rjf: cursor operations + case DF_CoreCmdKind_ToggleBreakpointAtCursor: + { + DF_InteractRegs *regs = df_interact_regs(); + DF_Entity *file = df_entity_from_handle(regs->file); + if(file->kind == DF_EntityKind_File && regs->cursor.line != 0) + { + DF_CmdParams p = df_cmd_params_zero(); + p.entity = df_handle_from_entity(file); + p.text_point = regs->cursor; + df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_TextBreakpoint)); + } + else if(regs->vaddr_range.min != 0) + { + DF_CmdParams p = df_cmd_params_zero(); + p.vaddr = regs->vaddr_range.min; + df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_AddressBreakpoint)); + } + }break; + case DF_CoreCmdKind_ToggleWatchPinAtCursor: + { + DF_InteractRegs *regs = df_interact_regs(); + DF_Entity *file = df_entity_from_handle(regs->file); + if(file->kind == DF_EntityKind_File && regs->cursor.line != 0) + { + DF_CmdParams p = df_cmd_params_zero(); + p.entity = df_handle_from_entity(file); + p.text_point = regs->cursor; + p.string = params.string; + df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ToggleWatchPin)); + } + else if(regs->vaddr_range.min != 0) + { + DF_CmdParams p = df_cmd_params_zero(); + p.vaddr = regs->vaddr_range.min; + p.string = params.string; + df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ToggleWatchPin)); + } + }break; + case DF_CoreCmdKind_GoToNameAtCursor: + case DF_CoreCmdKind_ToggleWatchExpressionAtCursor: + { + HS_Scope *hs_scope = hs_scope_open(); + TXT_Scope *txt_scope = txt_scope_open(); + DF_InteractRegs *regs = df_interact_regs(); + U128 text_key = regs->text_key; + TXT_LangKind lang_kind = regs->lang_kind; + TxtRng range = txt_rng(regs->cursor, regs->mark); + U128 hash = {0}; + TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, text_key, lang_kind, &hash); + String8 data = hs_data_from_hash(hs_scope, hash); + Rng1U64 expr_off_range = {0}; + if(range.min.column != range.max.column) + { + expr_off_range = r1u64(txt_off_from_info_pt(&info, range.min), txt_off_from_info_pt(&info, range.max)); + } + else + { + expr_off_range = txt_expr_off_range_from_info_data_pt(&info, data, range.min); + } + String8 expr = str8_substr(data, expr_off_range); + DF_CmdParams p = df_cmd_params_zero(); + p.string = expr; + df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(core_cmd_kind == DF_CoreCmdKind_GoToNameAtCursor ? DF_CoreCmdKind_GoToName : + core_cmd_kind == DF_CoreCmdKind_ToggleWatchExpressionAtCursor ? DF_CoreCmdKind_ToggleWatchExpression : + DF_CoreCmdKind_GoToName)); + txt_scope_close(txt_scope); + hs_scope_close(hs_scope); + }break; + case DF_CoreCmdKind_RunToCursor: + { + DF_Entity *file = df_entity_from_handle(df_interact_regs()->file); + if(!df_entity_is_nil(file)) + { + DF_CmdParams p = df_cmd_params_zero(); + p.entity = df_handle_from_entity(file); + p.text_point = df_interact_regs()->cursor; + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunToLine)); + } + else + { + DF_CmdParams p = df_cmd_params_zero(); + p.vaddr = df_interact_regs()->vaddr_range.min; + df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_RunToAddress)); + } + }break; + case DF_CoreCmdKind_SetNextStatement: + { + DF_Entity *file = df_entity_from_handle(df_interact_regs()->file); + DF_Entity *thread = df_entity_from_handle(df_interact_regs()->thread); + U64 new_rip_vaddr = df_interact_regs()->vaddr_range.min; + if(!df_entity_is_nil(file)) + { + DF_LineList *lines = &df_interact_regs()->lines; + for(DF_LineNode *n = lines->first; n != 0; n = n->next) + { + DF_EntityList modules = df_modules_from_dbgi_key(scratch.arena, &n->v.dbgi_key); + DF_Entity *module = df_module_from_thread_candidates(thread, &modules); + if(!df_entity_is_nil(module)) + { + new_rip_vaddr = df_vaddr_from_voff(module, n->v.voff_range.min); + break; + } + } + } + DF_CmdParams p = df_cmd_params_zero(); + p.entity = df_handle_from_entity(thread); + p.vaddr = new_rip_vaddr; + df_cmd_list_push(arena, cmds, &p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_SetThreadIP)); + }break; + //- rjf: targets case DF_CoreCmdKind_AddTarget: { @@ -9157,6 +9250,19 @@ df_core_begin_frame(Arena *arena, DF_CmdList *cmds, F32 dt) } scratch_end(scratch); } + + //- rjf: fill core interaction register info + { + DF_Entity *thread = df_entity_from_handle(df_state->ctrl_ctx.thread); + DF_Entity *module = df_module_from_thread(thread); + DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); + df_interact_regs()->thread = df_handle_from_entity(thread); + df_interact_regs()->module = df_handle_from_entity(module); + df_interact_regs()->process = df_handle_from_entity(process); + df_interact_regs()->unwind_count = df_state->ctrl_ctx.unwind_count; + df_interact_regs()->inline_unwind_count = df_state->ctrl_ctx.inline_unwind_count; + } + ProfEnd(); } diff --git a/src/df/core/df_core.h b/src/df/core/df_core.h index e10c1f38..ead3bd9f 100644 --- a/src/df/core/df_core.h +++ b/src/df/core/df_core.h @@ -659,17 +659,17 @@ struct DF_TextLineDasm2SrcInfoList typedef struct DF_InteractRegs DF_InteractRegs; struct DF_InteractRegs { - DF_Handle window; - DF_Handle panel; - DF_Handle view; DF_Handle module; DF_Handle process; DF_Handle thread; + U64 unwind_count; + U64 inline_unwind_count; + DF_Handle window; + DF_Handle panel; + DF_Handle view; DF_Handle file; TxtPt cursor; TxtPt mark; - U64 unwind_count; - U64 inline_unwind_count; U128 text_key; TXT_LangKind lang_kind; Rng1U64 vaddr_range; diff --git a/src/df/gfx/df_gfx.c b/src/df/gfx/df_gfx.c index 01b634e3..0d3a1f04 100644 --- a/src/df/gfx/df_gfx.c +++ b/src/df/gfx/df_gfx.c @@ -7166,6 +7166,7 @@ df_window_update_and_render(Arena *arena, DF_Window *ws, DF_CmdList *cmds) DF_Entity *entity = df_entity_from_handle(view->entity); df_interact_regs()->cursor = view->cursor; df_interact_regs()->mark = view->mark; + df_interact_regs()->file = df_handle_zero(); switch(entity->kind) { default:{}break; @@ -10838,7 +10839,7 @@ internal UI_BOX_CUSTOM_DRAW(df_bp_box_draw_extensions) } internal DF_CodeSliceSignal -df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeCtx *code_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, String8 string) +df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, String8 string) { DF_CodeSliceSignal result = {0}; ProfBeginFunction(); @@ -11161,7 +11162,7 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ // rjf: fill out progress t (progress into range of current line's // voff range) - if(code_ctx->file != &df_g_nil_entity && params->line_infos[line_idx].first != 0) + if(!df_entity_is_nil(df_entity_from_handle(df_interact_regs()->file)) && params->line_infos[line_idx].first != 0) { DF_LineList *lines = ¶ms->line_infos[line_idx]; DF_Line *line = 0; @@ -11238,7 +11239,7 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ { bp_draw->color = bp_color; bp_draw->alive_t = bp->alive_t; - if(code_ctx->file != &df_g_nil_entity) + if(!df_entity_is_nil(df_entity_from_handle(df_interact_regs()->file))) { DF_LineList *lines = ¶ms->line_infos[line_idx]; for(DF_LineNode *n = lines->first; n != 0; n = n->next) @@ -11369,11 +11370,11 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ UI_Signal line_margin_sig = ui_signal_from_box(line_margin_box); if(ui_clicked(line_margin_sig)) { - if(!df_entity_is_nil(code_ctx->file)) + if(!df_entity_is_nil(df_entity_from_handle(df_interact_regs()->file))) { TxtPt pt = txt_pt(line_num, 1); DF_CmdParams p = df_cmd_params_from_window(ws); - p.entity = df_handle_from_entity(code_ctx->file); + p.entity = df_interact_regs()->file; p.text_point = pt; df_push_cmd__root(&p, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_TextBreakpoint)); } @@ -11425,7 +11426,7 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ { if(n->v.dbgi_key.min_timestamp >= best_stamp) { - has_line_info = (n->v.pt.line == line_num || code_ctx->file == &df_g_nil_entity); + has_line_info = (n->v.pt.line == line_num || df_entity_is_nil(df_entity_from_handle(df_interact_regs()->file))); line_info_line_num = n->v.pt.line; best_stamp = n->v.dbgi_key.min_timestamp; } @@ -11737,10 +11738,10 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ } ui_ctx_menu_open(ws->code_ctx_menu_key, ui_key_zero(), sub_2f32(ui_mouse(), v2f32(2, 2))); arena_clear(ws->code_ctx_menu_arena); - ws->code_ctx_menu_file = df_handle_from_entity(code_ctx->file); - ws->code_ctx_menu_text_key = code_ctx->text_key; - ws->code_ctx_menu_lang_kind = code_ctx->lang_kind; - ws->code_ctx_menu_range = txt_rng(*cursor, *mark); + ws->code_ctx_menu_file = df_interact_regs()->file; + ws->code_ctx_menu_text_key = df_interact_regs()->text_key; + ws->code_ctx_menu_lang_kind = df_interact_regs()->lang_kind; + ws->code_ctx_menu_range = txt_rng(*cursor, *mark); if(params->line_num_range.min <= cursor->line && cursor->line < params->line_num_range.max) { ws->code_ctx_menu_vaddr = params->line_vaddrs[cursor->line - params->line_num_range.min]; @@ -11780,9 +11781,9 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ case DF_EntityKind_Breakpoint: case DF_EntityKind_WatchPin: { - if(!df_entity_is_nil(code_ctx->file)) + if(!df_entity_is_nil(df_entity_from_handle(df_interact_regs()->file))) { - df_entity_change_parent(0, dropped_entity, dropped_entity->parent, code_ctx->file); + df_entity_change_parent(0, dropped_entity, dropped_entity->parent, df_entity_from_handle(df_interact_regs()->file)); df_entity_equip_txt_pt(dropped_entity, txt_pt(line_num, 1)); if(dropped_entity->flags & DF_EntityFlag_HasVAddr) { @@ -11798,7 +11799,7 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ case DF_EntityKind_Thread: { U64 new_rip_vaddr = line_vaddr; - if(!df_entity_is_nil(code_ctx->file)) + if(!df_entity_is_nil(df_entity_from_handle(df_interact_regs()->file))) { DF_LineList *lines = ¶ms->line_infos[line_idx]; for(DF_LineNode *n = lines->first; n != 0; n = n->next) @@ -11872,7 +11873,7 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ { U64 line_slice_idx = mouse_pt.line-params->line_num_range.min; DF_LineList *lines = ¶ms->line_infos[line_slice_idx]; - if(lines->first != 0 && (code_ctx->file == &df_g_nil_entity || lines->first->v.pt.line == mouse_pt.line)) + if(lines->first != 0 && (df_entity_is_nil(df_entity_from_handle(df_interact_regs()->file)) || lines->first->v.pt.line == mouse_pt.line)) { DF_RichHoverInfo info = {0}; info.process = df_handle_from_entity(selected_thread_process); @@ -11893,7 +11894,7 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ DF_Eval eval = df_eval_from_string(scratch.arena, di_scope, ctrl_ctx, parse_ctx, &eval_string2expr_map_nil, mouse_expr); if(eval.mode != EVAL_EvalMode_NULL) { - df_set_hover_eval(ws, mouse_expr_baseline_pos, *ctrl_ctx, code_ctx->file, mouse_pt, 0, mouse_expr); + df_set_hover_eval(ws, mouse_expr_baseline_pos, *ctrl_ctx, df_entity_from_handle(df_interact_regs()->file), mouse_pt, 0, mouse_expr); } di_scope_close(di_scope); } @@ -12243,7 +12244,7 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ DF_LineList *lines = ¶ms->line_infos[line_idx]; for(DF_LineNode *n = lines->first; n != 0; n = n->next) { - if((n->v.pt.line == line_num || code_ctx->file == &df_g_nil_entity) && + if((n->v.pt.line == line_num || df_entity_is_nil(df_entity_from_handle(df_interact_regs()->file))) && di_key_match(&n->v.dbgi_key, &hovered_line_dbgi_key) && n->v.voff_range.min <= hovered_line_voff && hovered_line_voff < n->v.voff_range.max) { @@ -12279,13 +12280,13 @@ df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_ } internal DF_CodeSliceSignal -df_code_slicef(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeCtx *code_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, char *fmt, ...) +df_code_slicef(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, char *fmt, ...) { Temp scratch = scratch_begin(0, 0); va_list args; va_start(args, fmt); String8 string = push_str8fv(scratch.arena, fmt, args); - DF_CodeSliceSignal sig = df_code_slice(ws, ctrl_ctx, parse_ctx, code_ctx, params, cursor, mark, preferred_column, string); + DF_CodeSliceSignal sig = df_code_slice(ws, ctrl_ctx, parse_ctx, params, cursor, mark, preferred_column, string); va_end(args); scratch_end(scratch); return sig; diff --git a/src/df/gfx/df_gfx.h b/src/df/gfx/df_gfx.h index 5eb09b77..9e8244c9 100644 --- a/src/df/gfx/df_gfx.h +++ b/src/df/gfx/df_gfx.h @@ -434,14 +434,6 @@ enum DF_CodeSliceFlag_LineNums = (1<<3), }; -typedef struct DF_CodeCtx DF_CodeCtx; -struct DF_CodeCtx -{ - DF_Entity *file; // the source file, if any, from which the code was derived - U128 text_key; // the text info cache key for the backing textual data - TXT_LangKind lang_kind; // the language for which the text is parsed/analyzed -}; - typedef struct DF_CodeSliceParams DF_CodeSliceParams; struct DF_CodeSliceParams { @@ -1088,8 +1080,8 @@ internal void df_entity_src_loc_button(DF_Window *ws, DF_Entity *entity, TxtPt p internal UI_BOX_CUSTOM_DRAW(df_thread_box_draw_extensions); internal UI_BOX_CUSTOM_DRAW(df_bp_box_draw_extensions); -internal DF_CodeSliceSignal df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeCtx *code_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, String8 string); -internal DF_CodeSliceSignal df_code_slicef(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeCtx *code_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, char *fmt, ...); +internal DF_CodeSliceSignal df_code_slice(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, String8 string); +internal DF_CodeSliceSignal df_code_slicef(DF_Window *ws, DF_CtrlCtx *ctrl_ctx, EVAL_ParseCtx *parse_ctx, DF_CodeSliceParams *params, TxtPt *cursor, TxtPt *mark, S64 *preferred_column, char *fmt, ...); internal B32 df_do_txt_controls(TXT_TextInfo *info, String8 data, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column); internal B32 df_do_txti_controls(TXTI_Handle handle, U64 line_count_per_page, TxtPt *cursor, TxtPt *mark, S64 *preferred_column); diff --git a/src/df/gfx/df_view_rules.c b/src/df/gfx/df_view_rules.c index 15a34f0c..e76f2035 100644 --- a/src/df/gfx/df_view_rules.c +++ b/src/df/gfx/df_view_rules.c @@ -592,8 +592,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(text) //- rjf: build code slice UI_WidthFill UI_HeightFill UI_Parent(container) { - DF_CodeCtx code_ctx = {&df_g_nil_entity, text_key, top.lang}; - DF_CodeSliceSignal slice_sig = df_code_slice(ws, ctrl_ctx, parse_ctx, &code_ctx, &code_slice_params, &state->cursor, &state->mark, &state->preferred_column, str8_lit("###slice")); + DF_CodeSliceSignal slice_sig = df_code_slice(ws, ctrl_ctx, parse_ctx, &code_slice_params, &state->cursor, &state->mark, &state->preferred_column, str8_lit("###slice")); } } @@ -745,8 +744,7 @@ DF_GFX_VIEW_RULE_BLOCK_UI_FUNCTION_DEF(disasm) if(dasm_info.insts.count != 0 && dasm_text_info.lines_count != 0) UI_Padding(ui_pct(1, 0)) UI_PrefWidth(ui_px(dasm_text_info.lines_max_size*ui_top_font_size()*1.2f, 1.f)) UI_Column UI_Padding(ui_pct(1, 0)) { - DF_CodeCtx code_ctx = {&df_g_nil_entity, dasm_info.text_key, lang_kind}; - DF_CodeSliceSignal sig = df_code_slice(ws, ctrl_ctx, parse_ctx, &code_ctx, &code_slice_params, &state->cursor, &state->mark, &state->preferred_column, str8_lit("###code_slice")); + DF_CodeSliceSignal sig = df_code_slice(ws, ctrl_ctx, parse_ctx, &code_slice_params, &state->cursor, &state->mark, &state->preferred_column, str8_lit("###code_slice")); } } dasm_scope_close(dasm_scope); diff --git a/src/df/gfx/df_views.c b/src/df/gfx/df_views.c index 3bc78c32..4ac962cd 100644 --- a/src/df/gfx/df_views.c +++ b/src/df/gfx/df_views.c @@ -387,7 +387,7 @@ df_code_view_init(DF_CodeViewState *cv, DF_View *view) } internal void -df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, DF_CmdList *cmds, String8 data, TXT_TextInfo *info, DF_CodeCtx *code_ctx) +df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, DF_CmdList *cmds, String8 data, TXT_TextInfo *info) { for(DF_CmdNode *n = cmds->first; n != 0; n = n->next) { @@ -427,79 +427,12 @@ df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewStat arena_clear(cv->find_text_arena); cv->find_text_bwd = push_str8_copy(cv->find_text_arena, cmd->params.string); }break; - case DF_CoreCmdKind_GoToNameAtCursor: - { - Temp scratch = scratch_begin(0, 0); - TXT_Scope *txt_scope = txt_scope_open(); - HS_Scope *hs_scope = hs_scope_open(); - { - // rjf: determine expression range - Rng1U64 expr_range = {0}; - { - TxtRng selection_range = txt_rng(view->cursor, view->mark); - if(txt_pt_match(selection_range.min, selection_range.max)) - { - expr_range = txt_expr_off_range_from_info_data_pt(info, data, view->cursor); - } - else - { - expr_range = r1u64(txt_off_from_info_pt(info, selection_range.min), txt_off_from_info_pt(info, selection_range.max)); - } - } - - // rjf: expression range -> text - String8 expr_text = str8_substr(data, expr_range); - - // rjf: go to name - DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); - params.string = expr_text; - df_cmd_params_mark_slot(¶ms, DF_CmdParamSlot_String); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_GoToName)); - } - hs_scope_close(hs_scope); - txt_scope_close(txt_scope); - scratch_end(scratch); - }break; - case DF_CoreCmdKind_ToggleWatchExpressionAtCursor: - { - Temp scratch = scratch_begin(0, 0); - TXT_Scope *txt_scope = txt_scope_open(); - HS_Scope *hs_scope = hs_scope_open(); - { - // rjf: determine expression range - Rng1U64 expr_range = {0}; - { - TxtRng selection_range = txt_rng(view->cursor, view->mark); - if(txt_pt_match(selection_range.min, selection_range.max)) - { - expr_range = txt_expr_off_range_from_info_data_pt(info, data, view->cursor); - } - else - { - expr_range = r1u64(txt_off_from_info_pt(info, selection_range.min), txt_off_from_info_pt(info, selection_range.max)); - } - } - - // rjf: expression range -> text - String8 expr_text = str8_substr(data, expr_range); - - // rjf: toggle watch expr - DF_CmdParams params = df_cmd_params_from_view(ws, panel, view); - params.string = expr_text; - df_cmd_params_mark_slot(¶ms, DF_CmdParamSlot_String); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_ToggleWatchExpression)); - scratch_end(scratch); - } - hs_scope_close(hs_scope); - txt_scope_close(txt_scope); - scratch_end(scratch); - }break; } } } internal void -df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, Rng2F32 rect, String8 data, TXT_TextInfo *info, DF_CodeCtx *code_ctx) +df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, Rng2F32 rect, String8 data, TXT_TextInfo *info) { ProfBeginFunction(); Temp scratch = scratch_begin(0, 0); @@ -631,7 +564,8 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta // rjf: find visible breakpoints ProfScope("find visible breakpoints") { - for(DF_Entity *bp = code_ctx->file->first; !df_entity_is_nil(bp); bp = bp->next) + DF_Entity *file = df_entity_from_handle(df_interact_regs()->file); + for(DF_Entity *bp = file->first; !df_entity_is_nil(bp); bp = bp->next) { if(bp->deleted || bp->kind != DF_EntityKind_Breakpoint) { continue; } if(visible_line_num_range.min <= bp->text_point.line && bp->text_point.line <= visible_line_num_range.max) @@ -645,6 +579,7 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta // rjf: find live threads mapping to this file ProfScope("find live threads mapping to this file") { + DF_Entity *file = df_entity_from_handle(df_interact_regs()->file); DF_Entity *selected_thread = df_entity_from_handle(ctrl_ctx.thread); DF_EntityList threads = df_query_cached_entity_list_with_kind(DF_EntityKind_Thread); for(DF_EntityNode *thread_n = threads.first; thread_n != 0; thread_n = thread_n->next) @@ -661,7 +596,7 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta DF_LineList lines = df_lines_from_dbgi_key_voff(scratch.arena, &dbgi_key, rip_voff); for(DF_LineNode *n = lines.first; n != 0; n = n->next) { - if(df_entity_from_handle(n->v.file) == code_ctx->file && visible_line_num_range.min <= n->v.pt.line && n->v.pt.line <= visible_line_num_range.max) + if(df_entity_from_handle(n->v.file) == file && visible_line_num_range.min <= n->v.pt.line && n->v.pt.line <= visible_line_num_range.max) { U64 slice_line_idx = lines.first->v.pt.line-visible_line_num_range.min; df_entity_list_push(scratch.arena, &code_slice_params.line_ips[slice_line_idx], thread); @@ -673,7 +608,8 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta // rjf: find visible watch pins ProfScope("find visible watch pins") { - for(DF_Entity *wp = code_ctx->file->first; !df_entity_is_nil(wp); wp = wp->next) + DF_Entity *file = df_entity_from_handle(df_interact_regs()->file); + for(DF_Entity *wp = file->first; !df_entity_is_nil(wp); wp = wp->next) { if(wp->deleted || wp->kind != DF_EntityKind_WatchPin) { continue; } if(visible_line_num_range.min <= wp->text_point.line && wp->text_point.line <= visible_line_num_range.max) @@ -687,7 +623,8 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta // rjf: find all src -> dasm info ProfScope("find all src -> dasm info") { - DF_LineListArray lines_array = df_lines_array_from_file_line_range(scratch.arena, code_ctx->file, visible_line_num_range); + DF_Entity *file = df_entity_from_handle(df_interact_regs()->file); + DF_LineListArray lines_array = df_lines_array_from_file_line_range(scratch.arena, file, visible_line_num_range); if(lines_array.count != 0) { MemoryCopy(code_slice_params.line_infos, lines_array.v, sizeof(DF_LineList)*lines_array.count); @@ -886,7 +823,7 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta DF_CodeSliceSignal sig = {0}; UI_Focus(UI_FocusKind_On) { - sig = df_code_slicef(ws, &ctrl_ctx, &parse_ctx, code_ctx, &code_slice_params, &view->cursor, &view->mark, &cv->preferred_column, "txt_view_%p", view); + sig = df_code_slicef(ws, &ctrl_ctx, &parse_ctx, &code_slice_params, &view->cursor, &view->mark, &cv->preferred_column, "txt_view_%p", view); } //- rjf: press code slice? -> focus panel @@ -925,40 +862,6 @@ df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewSta String8 text = txt_string_from_info_data_txt_rng(info, data, txt_rng(view->cursor, view->mark)); df_set_search_string(text); } - - //- rjf: go to disasm - // TODO(rjf): @src_collapse -#if 0 - if(sig.goto_disasm_line_num != 0 && contains_1s64(visible_line_num_range, sig.goto_disasm_line_num)) - { - U64 line_idx = (sig.goto_disasm_line_num-visible_line_num_range.min); - DF_TextLineSrc2DasmInfoList *src2dasm_list = &code_slice_params.line_src2dasm[line_idx]; - if(src2dasm_list->first != 0) - { - Rng1U64 voff_rng = src2dasm_list->first->v.voff_range; - DI_Key dbgi_key = src2dasm_list->first->v.dbgi_key; - DF_EntityList possible_modules = df_modules_from_dbgi_key(scratch.arena, &dbgi_key); - DF_Entity *thread = df_entity_from_handle(ctrl_ctx.thread); - DF_Entity *thread_dst_module = df_module_from_thread_candidates(thread, &possible_modules); - DF_Entity *process = df_entity_ancestor_from_kind(thread, DF_EntityKind_Process); - DF_Entity *module = thread_dst_module; - if(df_entity_is_nil(module)) - { - module = df_first_entity_from_list(&possible_modules); - } - U64 voff = voff_rng.min; - if(!df_entity_is_nil(module) && voff != 0) - { - DF_CmdParams params = df_cmd_params_from_window(ws); - params.entity = df_handle_from_entity(process); - params.vaddr = df_vaddr_from_voff(module, voff); - df_cmd_params_mark_slot(¶ms, DF_CmdParamSlot_Entity); - df_cmd_params_mark_slot(¶ms, DF_CmdParamSlot_VirtualAddr); - df_push_cmd__root(¶ms, df_cmd_spec_from_core_cmd_kind(DF_CoreCmdKind_FindCodeLocation)); - } - } - } -#endif } ////////////////////////////// @@ -6303,15 +6206,14 @@ DF_VIEW_CMD_FUNCTION_DEF(Code) Temp scratch = scratch_begin(0, 0); HS_Scope *hs_scope = hs_scope_open(); TXT_Scope *txt_scope = txt_scope_open(); - DF_Entity *entity = df_entity_from_handle(view->entity); + DF_Entity *entity = df_entity_from_handle(df_interact_regs()->file); String8 path = df_full_path_from_entity(scratch.arena, entity); - TXT_LangKind lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(path)); - U128 key = fs_key_from_path(path); + df_interact_regs()->text_key = fs_key_from_path(path); + df_interact_regs()->lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(path)); U128 hash = {0}; - TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash); + TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, df_interact_regs()->text_key, df_interact_regs()->lang_kind, &hash); String8 data = hs_data_from_hash(hs_scope, hash); - DF_CodeCtx code_ctx = {entity, key, lang_kind}; - df_code_view_cmds(ws, panel, view, cv, cmds, data, &info, &code_ctx); + df_code_view_cmds(ws, panel, view, cv, cmds, data, &info); txt_scope_close(txt_scope); hs_scope_close(hs_scope); scratch_end(scratch); @@ -6334,12 +6236,12 @@ DF_VIEW_UI_FUNCTION_DEF(Code) ////////////////////////////// //- rjf: unpack entity info // - DF_Entity *entity = df_entity_from_handle(view->entity); + DF_Entity *entity = df_entity_from_handle(df_interact_regs()->file); String8 path = df_full_path_from_entity(scratch.arena, entity); - TXT_LangKind lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(path)); - U128 key = fs_key_from_path(path); + df_interact_regs()->text_key = fs_key_from_path(path); + df_interact_regs()->lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(path)); U128 hash = {0}; - TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash); + TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, df_interact_regs()->text_key, df_interact_regs()->lang_kind, &hash); String8 data = hs_data_from_hash(hs_scope, hash); B32 entity_is_missing = !!(entity->flags & DF_EntityFlag_IsMissing); B32 key_has_data = !u128_match(hash, u128_zero()) && info.lines_count; @@ -6397,8 +6299,14 @@ DF_VIEW_UI_FUNCTION_DEF(Code) // if(!entity_is_missing && key_has_data) { - DF_CodeCtx code_ctx = {entity, key, lang_kind}; - df_code_view_build(ws, panel, view, cv, code_area_rect, data, &info, &code_ctx); + df_code_view_build(ws, panel, view, cv, code_area_rect, data, &info); + } + + ////////////////////////////// + //- rjf: unpack cursor info + // + { + df_interact_regs()->lines = df_lines_from_file_line_num(df_frame_arena(), entity, df_interact_regs()->cursor.line); } ////////////////////////////// @@ -6733,10 +6641,10 @@ DF_VIEW_UI_FUNCTION_DEF(Code) // B32 entity_is_missing = !!(entity->flags & DF_EntityFlag_IsMissing && !(entity->flags & DF_EntityFlag_Output)); String8 path = df_full_path_from_entity(scratch.arena, entity); - U128 key = fs_key_from_path(path); - TXT_LangKind lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(path)); + df_interact_regs()->text_key = fs_key_from_path(path); + df_interact_regs()->lang_kind = txt_lang_kind_from_extension(str8_skip_last_dot(path)); U128 hash = {0}; - TXT_TextInfo text_info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash); + TXT_TextInfo text_info = txt_text_info_from_key_lang(txt_scope, df_interact_regs()->text_key, df_interact_regs()->lang_kind, &hash); String8 data = hs_data_from_hash(hs_scope, hash); B32 text_info_is_ready = (text_info.lines_count != 0); @@ -8086,8 +7994,7 @@ DF_VIEW_UI_FUNCTION_DEF(Disassembly) DF_CodeSliceSignal sig = {0}; UI_Focus(UI_FocusKind_On) { - DF_CodeCtx code_ctx = {&df_g_nil_entity, dasm_info.text_key, lang_kind}; - sig = df_code_slicef(ws, &ctrl_ctx, &parse_ctx, &code_ctx, &code_slice_params, &dv->cursor, &dv->mark, &dv->preferred_column, "dasm_slice_%p", view); + sig = df_code_slicef(ws, &ctrl_ctx, &parse_ctx, &code_slice_params, &dv->cursor, &dv->mark, &dv->preferred_column, "dasm_slice_%p", view); } //- rjf: hover eval @@ -8583,13 +8490,12 @@ DF_VIEW_CMD_FUNCTION_DEF(Output) Temp scratch = scratch_begin(0, 0); HS_Scope *hs_scope = hs_scope_open(); TXT_Scope *txt_scope = txt_scope_open(); - U128 key = df_state->output_log_key; - TXT_LangKind lang_kind = TXT_LangKind_Null; + df_interact_regs()->text_key = df_state->output_log_key; + df_interact_regs()->lang_kind = TXT_LangKind_Null; U128 hash = {0}; - TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, key, lang_kind, &hash); + TXT_TextInfo info = txt_text_info_from_key_lang(txt_scope, df_interact_regs()->text_key, df_interact_regs()->lang_kind, &hash); String8 data = hs_data_from_hash(hs_scope, hash); - DF_CodeCtx code_ctx = {&df_g_nil_entity, key, lang_kind}; - df_code_view_cmds(ws, panel, view, cv, cmds, data, &info, &code_ctx); + df_code_view_cmds(ws, panel, view, cv, cmds, data, &info); txt_scope_close(txt_scope); hs_scope_close(hs_scope); scratch_end(scratch); @@ -8628,8 +8534,7 @@ DF_VIEW_UI_FUNCTION_DEF(Output) //- rjf: build code contents // { - DF_CodeCtx code_ctx = {&df_g_nil_entity, key, lang_kind}; - df_code_view_build(ws, panel, view, cv, code_area_rect, data, &info, &code_ctx); + df_code_view_build(ws, panel, view, cv, code_area_rect, data, &info); } ////////////////////////////// diff --git a/src/df/gfx/df_views.h b/src/df/gfx/df_views.h index 65768bad..a3ad66ee 100644 --- a/src/df/gfx/df_views.h +++ b/src/df/gfx/df_views.h @@ -469,8 +469,8 @@ internal void df_entity_lister_item_array_sort_by_strength__in_place(DF_EntityLi //~ rjf: Code Views internal void df_code_view_init(DF_CodeViewState *cv, DF_View *view); -internal void df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, DF_CmdList *cmds, String8 data, TXT_TextInfo *info, DF_CodeCtx *code_ctx); -internal void df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, Rng2F32 rect, String8 data, TXT_TextInfo *info, DF_CodeCtx *code_ctx); +internal void df_code_view_cmds(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, DF_CmdList *cmds, String8 data, TXT_TextInfo *info); +internal void df_code_view_build(DF_Window *ws, DF_Panel *panel, DF_View *view, DF_CodeViewState *cv, Rng2F32 rect, String8 data, TXT_TextInfo *info); //////////////////////////////// //~ rjf: Watch Views