From 9801f4c8108f8296972f19d3d0c456b1a209e68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 25 Nov 2024 10:09:21 +0100 Subject: [PATCH] Add "Rename function" functionality. Fix some input and stepping bugs. --- Core/Core.cpp | 11 +++++-- UI/EmuScreen.cpp | 27 ++++++++++----- UI/ImDebugger/ImDisasmView.cpp | 60 ++++++++++++++++++++++------------ UI/ImDebugger/ImDisasmView.h | 4 ++- 4 files changed, 70 insertions(+), 32 deletions(-) diff --git a/Core/Core.cpp b/Core/Core.cpp index 0e5be48aea..10f9742308 100644 --- a/Core/Core.cpp +++ b/Core/Core.cpp @@ -418,11 +418,18 @@ void Core_Break(const char *reason, u32 relatedAddress) { { std::lock_guard lock(g_stepMutex); if (!g_stepCommand.empty()) { - // Already broke. - ERROR_LOG(Log::CPU, "Core_Break called with a break already in progress: %s", g_stepCommand.reason); + // If we're in a failed step that uses a temp breakpoint, we need to be able to override it here. + switch (g_stepCommand.type) { + case CPUStepType::Over: + case CPUStepType::Out: + // Allow overwriting the command. + break; + } + ERROR_LOG(Log::CPU, "Core_Break called with a step-command already in progress: %s", g_stepCommand.reason); return; } mipsTracer.stop_tracing(); + g_stepCommand.type = CPUStepType::None; g_stepCommand.reason = reason; g_stepCommand.relatedAddr = relatedAddress; steppingCounter++; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 4926814567..963cc53df3 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -969,17 +969,28 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { if (UI::IsFocusMovementEnabled() || (g_Config.bShowImDebugger && imguiInited_)) { // Note: Allow some Vkeys through, so we can toggle the imgui for example (since we actually block the control mapper otherwise in imgui mode). // We need to manually implement it here :/ - if (g_Config.bShowImDebugger && imguiInited_ && (key.flags & (KEY_UP | KEY_DOWN))) { - InputMapping mapping(key.deviceId, key.keyCode); - std::vector pspButtons; - bool mappingFound = KeyMap::InputMappingToPspButton(mapping, &pspButtons); - if (mappingFound) { - for (auto b : pspButtons) { - if (b == VIRTKEY_TOGGLE_DEBUGGER || b == VIRTKEY_PAUSE) { - return controlMapper_.Key(key, &pauseTrigger_); + if (g_Config.bShowImDebugger && imguiInited_) { + if (key.flags & (KEY_UP | KEY_DOWN)) { + InputMapping mapping(key.deviceId, key.keyCode); + std::vector pspButtons; + bool mappingFound = KeyMap::InputMappingToPspButton(mapping, &pspButtons); + if (mappingFound) { + for (auto b : pspButtons) { + if (b == VIRTKEY_TOGGLE_DEBUGGER || b == VIRTKEY_PAUSE) { + return controlMapper_.Key(key, &pauseTrigger_); + } } } } + UI::EnableFocusMovement(false); + // Enable gamepad controls while running imgui (but ignore mouse/keyboard). + switch (key.deviceId) { + case DEVICE_ID_KEYBOARD: + case DEVICE_ID_MOUSE: + break; + default: + controlMapper_.Key(key, &pauseTrigger_); + } } return UIScreen::UnsyncKey(key); diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index 38a8768c8c..238ad7d48a 100644 --- a/UI/ImDebugger/ImDisasmView.cpp +++ b/UI/ImDebugger/ImDisasmView.cpp @@ -461,7 +461,7 @@ void ImDisasmView::Draw(ImDrawList *drawList) { } } - ProcessKeyboardShortcuts(); + ProcessKeyboardShortcuts(ImGui::IsItemFocused()); int coreStep = Core_GetSteppingCounter(); if (coreStep != lastSteppingCount_) { @@ -561,7 +561,11 @@ void ImDisasmView::editBreakpoint(ImConfig &cfg) { */ } -void ImDisasmView::ProcessKeyboardShortcuts() { +void ImDisasmView::ProcessKeyboardShortcuts(bool focused) { + if (!focused) { + return; + } + u32 windowEnd = manager.getNthNextAddress(windowStart_, visibleRows_); keyTaken = true; @@ -638,6 +642,9 @@ void ImDisasmView::ProcessKeyboardShortcuts() { } return; } + if (ImGui::IsKeyPressed(ImGuiKey_F9)) { + toggleBreakpoint(); + } } /* @@ -665,9 +672,6 @@ void ImDisasmView::ProcessKeyboardShortcuts() { case VK_TAB: displaySymbols_ = !displaySymbols_; break; - case VK_SPACE: - debugger->toggleBreakpoint(curAddress); - break; default: keyTaken = false; return; @@ -783,6 +787,7 @@ void ImDisasmView::NopInstructions(u32 selectRangeStart, u32 selectRangeEnd) { } void ImDisasmView::PopupMenu() { + bool renameFunctionPopup = false; if (ImGui::BeginPopup("context")) { ImGui::Text("Address: %08x", curAddress_); if (ImGui::MenuItem("Toggle breakpoint", "F9")) { @@ -831,24 +836,14 @@ void ImDisasmView::PopupMenu() { } ImGui::Separator(); if (ImGui::MenuItem("Rename function")) { - u32 funcBegin = g_symbolMap->GetFunctionStart(curAddress_); - /* - if (funcBegin != -1) { - char name[256]; - std::string newname; - truncate_cpy(name, g_symbolMap->GetLabelString(funcBegin).c_str()); - if (InputBox_GetString(MainWindow::GetHInstance(), MainWindow::GetHWND(), L"New function name", name, newname)) { - g_symbolMap->SetLabelName(newname.c_str(), funcBegin); - u32 funcSize = g_symbolMap->GetFunctionSize(funcBegin); - MIPSAnalyst::RegisterFunction(funcBegin, funcSize, newname.c_str()); - MIPSAnalyst::UpdateHashMap(); - MIPSAnalyst::ApplyHashMap(); - mapReloaded_ = true; - } + funcBegin_ = g_symbolMap->GetFunctionStart(curAddress_); + if (funcBegin_ != -1) { + truncate_cpy(funcNameTemp_, g_symbolMap->GetLabelString(funcBegin_).c_str()); + renameFunctionPopup = true; + statusBarText_ = funcNameTemp_; } else { - MessageBox(MainWindow::GetHWND(), L"No symbol selected", 0, 0); + statusBarText_ = "No function here"; } - */ } if (ImGui::MenuItem("Remove function")) { u32 funcBegin = g_symbolMap->GetFunctionStart(curAddress_); @@ -905,6 +900,29 @@ void ImDisasmView::PopupMenu() { } ImGui::EndPopup(); } + + // Sub popups here + if (renameFunctionPopup) { + ImGui::OpenPopup("renameFunction"); + } + // ImGui::SetNextWindowPos(pos, ImGuiCond_Appearing()) + if (ImGui::BeginPopup("renameFunction")) { + std::string symName = g_symbolMap->GetDescription(funcBegin_); + ImGui::Text("Rename function %s", symName.c_str()); + if (ImGui::IsWindowAppearing()) { + ImGui::SetKeyboardFocusHere(); + } + if (ImGui::InputText("Name", funcNameTemp_, sizeof(funcNameTemp_), ImGuiInputTextFlags_EnterReturnsTrue) && strlen(funcNameTemp_)) { + g_symbolMap->SetLabelName(funcNameTemp_, funcBegin_); + u32 funcSize = g_symbolMap->GetFunctionSize(funcBegin_); + MIPSAnalyst::RegisterFunction(funcBegin_, funcSize, funcNameTemp_); + MIPSAnalyst::UpdateHashMap(); + MIPSAnalyst::ApplyHashMap(); + mapReloaded_ = true; + ImGui::CloseCurrentPopup(); + } + ImGui::EndPopup(); + } } void ImDisasmView::updateStatusBarText() { diff --git a/UI/ImDebugger/ImDisasmView.h b/UI/ImDebugger/ImDisasmView.h index 7ff9ad7932..ceed40fba4 100644 --- a/UI/ImDebugger/ImDisasmView.h +++ b/UI/ImDebugger/ImDisasmView.h @@ -124,7 +124,7 @@ private: float bottom; }; - void ProcessKeyboardShortcuts(); + void ProcessKeyboardShortcuts(bool focused); void assembleOpcode(u32 address, const std::string &defaultText); std::string disassembleRange(u32 start, u32 size); void disassembleToFile(); @@ -174,4 +174,6 @@ private: int lastSteppingCount_ = 0; std::string statusBarText_; + u32 funcBegin_; + char funcNameTemp_[128]; };