From 4b382777e9a875f456da12d176d2f5247f427eba Mon Sep 17 00:00:00 2001 From: Ryan Fleury Date: Mon, 16 Sep 2024 17:09:41 -0700 Subject: [PATCH] fix debug engine incorrectly using visual run state to soft halt, when ctrl thread did not necessarily report it was running; was leading to 'phantom halts'; other small fixes, dead code elimination, and begin sketching out proper cross-window drag/drop --- src/dbg_engine/dbg_engine_core.c | 7 ++-- src/dbg_engine/dbg_engine_core.h | 1 + src/os/gfx/linux/os_gfx_linux.c | 6 +++ src/os/gfx/os_gfx.h | 3 +- src/os/gfx/stub/os_gfx_stub.c | 6 +++ src/os/gfx/win32/os_gfx_win32.c | 65 ++++++++++++++++++++------------ src/raddbg/raddbg_core.c | 24 +----------- src/ui/ui_core.c | 15 ++++++++ src/ui/ui_core.h | 3 ++ 9 files changed, 78 insertions(+), 52 deletions(-) diff --git a/src/dbg_engine/dbg_engine_core.c b/src/dbg_engine/dbg_engine_core.c index 0a91d9e1..ac53e0a3 100644 --- a/src/dbg_engine/dbg_engine_core.c +++ b/src/dbg_engine/dbg_engine_core.c @@ -1577,7 +1577,6 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P D_EventList result = {0}; d_state->frame_index += 1; d_state->frame_eval_memread_endt_us = os_now_microseconds() + 5000; - B32 ctrl_running_pre_tick = d_state->ctrl_is_running; ////////////////////////////// //- rjf: sync with ctrl thread @@ -1615,12 +1614,14 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P case CTRL_EventKind_Started: { d_state->ctrl_is_running = 1; + d_state->ctrl_thread_run_state = 1; }break; case CTRL_EventKind_Stopped: { B32 should_snap = !(d_state->ctrl_soft_halt_issued); d_state->ctrl_is_running = 0; + d_state->ctrl_thread_run_state = 0; d_state->ctrl_soft_halt_issued = 0; // rjf: exception or unexpected trap -> push error @@ -1680,7 +1681,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P { // rjf: the first process? -> clear session output & reset all bp hit counts CTRL_EntityList existing_processes = ctrl_entity_list_from_kind(d_state->ctrl_entity_store, CTRL_EntityKind_Process); - if(existing_processes.count == 0) + if(existing_processes.count == 1) { MTX_Op op = {r1u64(0, 0xffffffffffffffffull), str8_lit("[new session]\n")}; mtx_push_op(d_state->output_log_key, op); @@ -2563,7 +2564,7 @@ d_tick(Arena *arena, D_TargetArray *targets, D_BreakpointArray *breakpoints, D_P ctrl_msg_list_concat_in_place(&d_state->ctrl_msgs, &msgs_copy); if(d_state->ctrl_msgs.count != 0) { - if(!d_state->ctrl_soft_halt_issued && ctrl_running_pre_tick) + if(!d_state->ctrl_soft_halt_issued && d_state->ctrl_thread_run_state) { d_state->ctrl_soft_halt_issued = 1; ctrl_halt(); diff --git a/src/dbg_engine/dbg_engine_core.h b/src/dbg_engine/dbg_engine_core.h index 28e1c677..ba470191 100644 --- a/src/dbg_engine/dbg_engine_core.h +++ b/src/dbg_engine/dbg_engine_core.h @@ -394,6 +394,7 @@ struct D_State D_BreakpointArray ctrl_last_run_extra_bps; U128 ctrl_last_run_param_state_hash; B32 ctrl_is_running; + B32 ctrl_thread_run_state; B32 ctrl_soft_halt_issued; Arena *ctrl_msg_arena; CTRL_MsgList ctrl_msgs; diff --git a/src/os/gfx/linux/os_gfx_linux.c b/src/os/gfx/linux/os_gfx_linux.c index b3c0339c..c8a588c0 100644 --- a/src/os/gfx/linux/os_gfx_linux.c +++ b/src/os/gfx/linux/os_gfx_linux.c @@ -448,6 +448,12 @@ os_get_modifiers(void) return 0; } +internal B32 +os_key_is_down(OS_Key key) +{ + return 0; +} + internal Vec2F32 os_mouse_from_window(OS_Handle handle) { diff --git a/src/os/gfx/os_gfx.h b/src/os/gfx/os_gfx.h index 838d0735..cd56a6ba 100644 --- a/src/os/gfx/os_gfx.h +++ b/src/os/gfx/os_gfx.h @@ -173,7 +173,8 @@ internal Vec2F32 os_dim_from_monitor(OS_Handle monitor); internal void os_send_wakeup_event(void); internal OS_EventList os_get_events(Arena *arena, B32 wait); -internal OS_Modifiers os_get_modifiers(void); +internal OS_Modifiers os_get_modifiers(void); +internal B32 os_key_is_down(OS_Key key); internal Vec2F32 os_mouse_from_window(OS_Handle window); //////////////////////////////// diff --git a/src/os/gfx/stub/os_gfx_stub.c b/src/os/gfx/stub/os_gfx_stub.c index e9fb9066..356e7d47 100644 --- a/src/os/gfx/stub/os_gfx_stub.c +++ b/src/os/gfx/stub/os_gfx_stub.c @@ -197,6 +197,12 @@ os_get_modifiers(void) return f; } +internal B32 +os_key_is_down(OS_Key key) +{ + return 0; +} + internal Vec2F32 os_mouse_from_window(OS_Handle window) { diff --git a/src/os/gfx/win32/os_gfx_win32.c b/src/os/gfx/win32/os_gfx_win32.c index 907fdab0..17620cb3 100644 --- a/src/os/gfx/win32/os_gfx_win32.c +++ b/src/os/gfx/win32/os_gfx_win32.c @@ -314,6 +314,9 @@ os_w32_vkey_from_os_key(OS_Key key) vkey_table[OS_Key_Num7] = VK_NUMPAD7; vkey_table[OS_Key_Num8] = VK_NUMPAD8; vkey_table[OS_Key_Num9] = VK_NUMPAD9; + vkey_table[OS_Key_LeftMouseButton] = VK_LBUTTON; + vkey_table[OS_Key_MiddleMouseButton] = VK_MBUTTON; + vkey_table[OS_Key_RightMouseButton] = VK_RBUTTON; } result = vkey_table[key]; } @@ -356,10 +359,10 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_SIZE: case WM_PAINT: - { + { PAINTSTRUCT ps = {0}; BeginPaint(hwnd, &ps); - update(); + update(); EndPaint(hwnd, &ps); }break; @@ -533,27 +536,27 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) F32 new_dpi = (F32)(wParam & 0xffff); window->dpi = new_dpi; }break; - - //- rjf: [file drop] - case WM_DROPFILES: - { - HDROP drop = (HDROP)wParam; - POINT drop_pt = {0}; - DragQueryPoint(drop, &drop_pt); - ScreenToClient(window->hwnd, &drop_pt); - U64 num_files_dropped = DragQueryFile(drop, 0xffffffff, 0, 0); - OS_Event *event = os_w32_push_event(OS_EventKind_FileDrop, window); - event->pos = v2f32((F32)drop_pt.x, (F32)drop_pt.y); - for(U64 idx = 0; idx < num_files_dropped; idx += 1) - { - U64 name_size = DragQueryFile(drop, idx, 0, 0) + 1; - U8 *name_ptr = push_array(os_w32_event_arena, U8, name_size); - DragQueryFile(drop, idx, (char *)name_ptr, name_size); - str8_list_push(os_w32_event_arena, &event->strings, str8(name_ptr, name_size)); - } - DragFinish(drop); - }break; - + + //- rjf: [file drop] + case WM_DROPFILES: + { + HDROP drop = (HDROP)wParam; + POINT drop_pt = {0}; + DragQueryPoint(drop, &drop_pt); + ScreenToClient(window->hwnd, &drop_pt); + U64 num_files_dropped = DragQueryFile(drop, 0xffffffff, 0, 0); + OS_Event *event = os_w32_push_event(OS_EventKind_FileDrop, window); + event->pos = v2f32((F32)drop_pt.x, (F32)drop_pt.y); + for(U64 idx = 0; idx < num_files_dropped; idx += 1) + { + U64 name_size = DragQueryFile(drop, idx, 0, 0) + 1; + U8 *name_ptr = push_array(os_w32_event_arena, U8, name_size); + DragQueryFile(drop, idx, (char *)name_ptr, name_size); + str8_list_push(os_w32_event_arena, &event->strings, str8(name_ptr, name_size)); + } + DragFinish(drop); + }break; + //- rjf: [custom border] case WM_NCPAINT: { @@ -1027,8 +1030,8 @@ os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) (int)resolution.y, 0, 0, os_w32_gfx_state->hInstance, - 0); - DragAcceptFiles(hwnd, 1); + 0); + DragAcceptFiles(hwnd, 1); scratch_end(scratch); } @@ -1412,6 +1415,18 @@ os_get_modifiers(void) return modifiers; } +internal B32 +os_key_is_down(OS_Key key) +{ + B32 down = 0; + WPARAM vkey = os_w32_vkey_from_os_key(key); + if(GetKeyState(vkey) & 0x8000) + { + down = 1; + } + return down; +} + internal Vec2F32 os_mouse_from_window(OS_Handle handle) { diff --git a/src/raddbg/raddbg_core.c b/src/raddbg/raddbg_core.c index 188d9349..dd62a77c 100644 --- a/src/raddbg/raddbg_core.c +++ b/src/raddbg/raddbg_core.c @@ -9421,12 +9421,6 @@ rd_init(CmdLine *cmdln) rd_state->entities_root = rd_entity_alloc(&d_nil_entity, RD_EntityKind_Root); rd_state->key_map_arena = arena_alloc(); rd_state->popup_arena = arena_alloc(); -#if 0 // TODO(rjf): @msgs - rd_state->view_spec_table_size = 256; - rd_state->view_spec_table = push_array(arena, RD_ViewSpec *, rd_state->view_spec_table_size); - rd_state->view_rule_spec_table_size = 1024; - rd_state->view_rule_spec_table = push_array(arena, RD_ViewRuleSpec *, d_state->view_rule_spec_table_size); -#endif rd_state->code_ctx_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_code_ctx_menu_")); rd_state->entity_ctx_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_entity_ctx_menu_")); rd_state->tab_ctx_menu_key = ui_key_from_string(ui_key_zero(), str8_lit("_tab_ctx_menu_")); @@ -9446,22 +9440,6 @@ rd_init(CmdLine *cmdln) rd_entity_equip_name(local_machine, str8_lit("This PC")); } - // rjf: register gfx layer views -#if 0 // TODO(rjf): @msgs - { - RD_ViewSpecInfoArray array = {rd_gfx_view_kind_spec_info_table, ArrayCount(rd_gfx_view_kind_spec_info_table)}; - rd_register_view_specs(array); - } -#endif - - // rjf: register gfx layer view rules -#if 0 // TODO(rjf): @msgs - { - RD_ViewRuleSpecInfoArray array = {rd_gfx_view_rule_spec_info_table, ArrayCount(rd_gfx_view_rule_spec_info_table)}; - rd_register_view_rule_specs(array); - } -#endif - // rjf: set up user / project paths { Temp scratch = scratch_begin(0, 0); @@ -14144,7 +14122,7 @@ rd_frame(void) } // rjf: no stop-causing thread, but have selected thread? -> snap to selected - CTRL_Entity *selected_thread = &ctrl_entity_nil; // TODO(rjf): ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_base_regs()->thread); + CTRL_Entity *selected_thread = ctrl_entity_from_handle(d_state->ctrl_entity_store, rd_base_regs()->thread); if(thread == &ctrl_entity_nil && selected_thread != &ctrl_entity_nil) { rd_cmd(RD_CmdKind_FindThread); diff --git a/src/ui/ui_core.c b/src/ui/ui_core.c index 94997a8a..caa854ca 100644 --- a/src/ui/ui_core.c +++ b/src/ui/ui_core.c @@ -424,6 +424,7 @@ ui_state_alloc(void) Arena *arena = arena_alloc(); UI_State *ui = push_array(arena, UI_State, 1); ui->arena = arena; + ui->external_key = ui_key_from_string(ui_key_zero(), str8_lit("###external_interaction_key###")); ui->build_arenas[0] = arena_alloc(); ui->build_arenas[1] = arena_alloc(); ui->drag_state_arena = arena_alloc(); @@ -832,6 +833,19 @@ ui_begin_build(OS_Handle window, UI_EventList *events, UI_IconInfo *icon_info, U } } + //- rjf: detect external press & holds + for(EachEnumVal(UI_MouseButtonKind, k)) + { + if(ui_key_match(ui_state->active_box_key[k], ui_key_zero()) && os_key_is_down(OS_Key_LeftMouseButton+k)) + { + ui_state->active_box_key[k] = ui_state->external_key; + } + else if(ui_key_match(ui_state->active_box_key[k], ui_state->external_key) && !os_key_is_down(OS_Key_LeftMouseButton+k)) + { + ui_state->active_box_key[k] = ui_key_zero(); + } + } + //- rjf: fill build phase parameters { ui_state->events = events; @@ -1435,6 +1449,7 @@ ui_end_build(void) } //- rjf: hover cursor + if(!ui_key_match(ui_state->active_box_key[UI_MouseButtonKind_Left], ui_state->external_key)) { UI_Box *hot = ui_box_from_key(ui_state->hot_box_key); UI_Box *active = ui_box_from_key(ui_state->active_box_key[UI_MouseButtonKind_Left]); diff --git a/src/ui/ui_core.h b/src/ui/ui_core.h index 76432d51..45c9c8b2 100644 --- a/src/ui/ui_core.h +++ b/src/ui/ui_core.h @@ -625,6 +625,9 @@ struct UI_State //- rjf: main arena Arena *arena; + //- rjf: fixed keys + UI_Key external_key; + //- rjf: build arenas Arena *build_arenas[2]; U64 build_index;