From e9bc28f62954061e2d544810f8e578bed3213a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 7 Nov 2024 19:41:10 +0100 Subject: [PATCH 1/3] Fix bug where the 'o' char input got eaten because the char matches the keycode for Esc.. --- UI/EmuScreen.cpp | 2 +- ext/imgui/imgui_impl_platform.cpp | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index da44e949c0..72dacb1d35 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -955,7 +955,7 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) { if (UI::IsFocusMovementEnabled() || (imguiVisible_ && 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 (imguiVisible_ && imguiInited_) { + if (imguiVisible_ && imguiInited_ && (key.flags & (KEY_UP | KEY_DOWN))) { InputMapping mapping(key.deviceId, key.keyCode); std::vector pspButtons; bool mappingFound = KeyMap::InputMappingToPspButton(mapping, &pspButtons); diff --git a/ext/imgui/imgui_impl_platform.cpp b/ext/imgui/imgui_impl_platform.cpp index 5fa614497e..a9b9b8f170 100644 --- a/ext/imgui/imgui_impl_platform.cpp +++ b/ext/imgui/imgui_impl_platform.cpp @@ -22,10 +22,10 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) { default: { ImGuiKey keyCode = KeyCodeToImGui(key.keyCode); - if (keyCode == ImGuiKey_None) { - WARN_LOG(Log::System, "Unmapped ImGui keycode conversion from %d", key.keyCode); - } else { + if (keyCode != ImGuiKey_None) { io.AddKeyEvent(keyCode, true); + } else { + WARN_LOG(Log::System, "KeyDown: Unmapped ImGui keycode conversion from %d", key.keyCode); } break; } @@ -33,10 +33,15 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) { } if (key.flags & KEY_UP) { ImGuiKey keyCode = KeyCodeToImGui(key.keyCode); - io.AddKeyEvent(keyCode, false); + if (keyCode != ImGuiKey_None) { + io.AddKeyEvent(keyCode, false); + } else { + WARN_LOG(Log::System, "KeyUp: Unmapped ImGui keycode conversion from %d", key.keyCode); + } } if (key.flags & KEY_CHAR) { const int unichar = key.unicodeChar; + if (unichar >= 0x20) { // Insert it! (todo: do it with a string insert) char buf[16]; From 8081ebc265a618adb8408dba35b0df54b46372f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 7 Nov 2024 19:47:45 +0100 Subject: [PATCH 2/3] Crashfixes --- Core/MIPS/MIPSStackWalk.cpp | 5 +++++ UI/EmuScreen.cpp | 2 +- UI/ImDebugger/ImDebugger.cpp | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Core/MIPS/MIPSStackWalk.cpp b/Core/MIPS/MIPSStackWalk.cpp index eb816a6ad0..60e38a0658 100644 --- a/Core/MIPS/MIPSStackWalk.cpp +++ b/Core/MIPS/MIPSStackWalk.cpp @@ -163,6 +163,11 @@ namespace MIPSStackWalk { std::vector Walk(u32 pc, u32 ra, u32 sp, u32 threadEntry, u32 threadStackTop) { std::vector frames; + + if (!Memory::IsValidAddress(pc) || !Memory::IsValidAddress(sp) || !Memory::IsValidAddress(ra)) { + return frames; + } + StackFrame current; current.pc = pc; current.sp = sp; diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index 72dacb1d35..39e0fc23e3 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -1643,7 +1643,7 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) { ImGui_ImplThin3d_Init(draw); } - if (imguiVisible_ && imguiInited_) { + if (imguiVisible_ && imguiInited_ && PSP_IsInited()) { _dbg_assert_(imDebugger_); ImGui_ImplPlatform_NewFrame(); diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 9adde3ad2e..1e6d20fb6c 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -198,7 +198,7 @@ void DrawCallStacks(MIPSDebugInterface *debug, bool *open) { } void DrawModules(MIPSDebugInterface *debug, bool *open) { - if (!ImGui::Begin("Modules", open)) { + if (!ImGui::Begin("Modules", open) || !g_symbolMap) { ImGui::End(); return; } From 80474fd0f0c07235c408530845839b2dcb14c82f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 7 Nov 2024 20:11:23 +0100 Subject: [PATCH 3/3] Some cosmetic fixes to the ImGui debugger --- Core/MIPS/MIPSDebugInterface.cpp | 4 ++-- UI/ImDebugger/ImDebugger.cpp | 11 +++++------ UI/ImDebugger/ImDisasmView.cpp | 23 +++++++++++++---------- UI/ImDebugger/ImDisasmView.h | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Core/MIPS/MIPSDebugInterface.cpp b/Core/MIPS/MIPSDebugInterface.cpp index d31983741a..ab0798409b 100644 --- a/Core/MIPS/MIPSDebugInterface.cpp +++ b/Core/MIPS/MIPSDebugInterface.cpp @@ -244,8 +244,8 @@ void MIPSDebugInterface::toggleBreakpoint(unsigned int address) int MIPSDebugInterface::getColor(unsigned int address, bool darkMode) const { - int colors[6] = { 0xe0FFFF, 0xFFe0e0, 0xe8e8FF, 0xFFe0FF, 0xe0FFe0, 0xFFFFe0 }; - int colorsDark[6] = { ~0xe0FFFF, ~0xFFe0e0, ~0xe8e8FF, ~0xFFe0FF, ~0xe0FFe0, ~0xFFFFe0 }; + uint32_t colors[6] = { 0xFFe0FFFF, 0xFFFFe0e0, 0xFFe8e8FF, 0xFFFFe0FF, 0xFFe0FFe0, 0xFFFFFFe0 }; + uint32_t colorsDark[6] = { 0xFF301010, 0xFF103030, 0xFF403010, 0xFF103000, 0xFF301030, 0xFF101030 }; int n = g_symbolMap->GetFunctionNum(address); if (n == -1) { diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 1e6d20fb6c..c0d1be38e0 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -57,7 +57,7 @@ void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) { ImGui::EndTabItem(); } - if (ImGui::BeginTabItem("FPR")) { + if (ImGui::BeginTabItem("FPU")) { if (ImGui::BeginTable("fpr", 3, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersH)) { ImGui::TableSetupColumn("regname", ImGuiTableColumnFlags_WidthFixed); ImGui::TableSetupColumn("value", ImGuiTableColumnFlags_WidthFixed); @@ -79,7 +79,7 @@ void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) { } ImGui::EndTabItem(); } - if (ImGui::BeginTabItem("VPR")) { + if (ImGui::BeginTabItem("VFPU")) { ImGui::Text("TODO"); ImGui::EndTabItem(); } @@ -93,10 +93,10 @@ static const char *ThreadStatusToString(u32 status) { case THREADSTATUS_RUNNING: return "Running"; case THREADSTATUS_READY: return "Ready"; case THREADSTATUS_WAIT: return "Wait"; - case THREADSTATUS_SUSPEND: return "Suspend"; + case THREADSTATUS_SUSPEND: return "Suspended"; case THREADSTATUS_DORMANT: return "Dormant"; case THREADSTATUS_DEAD: return "Dead"; - case THREADSTATUS_WAITSUSPEND: return "WaitSuspend"; + case THREADSTATUS_WAITSUSPEND: return "WaitSuspended"; default: break; } @@ -379,12 +379,11 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState c while (clipper.Step()) { for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { if (ImGui::Selectable(symCache_[i].name.c_str(), false)) { - disasmView_.setCurAddress(symCache_[i].address); + disasmView_.gotoAddr(symCache_[i].address); disasmView_.scrollAddressIntoView(); } } } - clipper.End(); ImGui::EndListBox(); } diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index a573c1e5e0..6975b19e5d 100644 --- a/UI/ImDebugger/ImDisasmView.cpp +++ b/UI/ImDebugger/ImDisasmView.cpp @@ -375,7 +375,7 @@ void ImDisasmView::Draw(ImDrawList *drawList) { ImColor textColor = 0xFFFFFFFF; if (isInInterval(address, line.totalSize, debugger->getPC())) { - backgroundColor = scaleColor(backgroundColor, 1.15f); + backgroundColor = scaleColor(backgroundColor, 1.3f); } if (address >= selectRangeStart_ && address < selectRangeEnd_ && searching_ == false) { @@ -383,7 +383,7 @@ void ImDisasmView::Draw(ImDrawList *drawList) { backgroundColor = ImColor(address == curAddress_ ? 0xFFFF8822 : 0xFFFF9933); textColor = ImColor(0xFF000000); } else { - backgroundColor = ImColor(0xFFC0C0C0); + backgroundColor = ImColor(0xFF606060); } } @@ -404,10 +404,12 @@ void ImDisasmView::Draw(ImDrawList *drawList) { drawList->AddText(ImVec2(rect.left + pixelPositions_.addressStart, rect.top + rowY1 + 2), textColor, addressText); if (isInInterval(address, line.totalSize, debugger->getPC())) { - // Show the current PC with a little square. - drawList->AddRectFilled( - ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - rowHeight_, canvas_p0.y + rowY1 + 2), - ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - 4, canvas_p0.y + rowY1 + rowHeight_ - 2), 0xFFFFFFFF); + // Show the current PC with a little triangle. + drawList->AddTriangleFilled( + ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - rowHeight_ * 0.7f, canvas_p0.y + rowY1 + 2), + ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - rowHeight_ * 0.7f, canvas_p0.y + rowY1 + rowHeight_ - 2), + ImVec2(canvas_p0.x + pixelPositions_.opcodeStart - 4, canvas_p0.y + rowY1 + rowHeight_ * 0.5f), + 0xFFFFFFFF); } // display whether the condition of a branch is met @@ -498,7 +500,8 @@ void ImDisasmView::ScrollRelative(int amount) { ScanVisibleFunctions(); } -void ImDisasmView::followBranch() { +// Follows branches and jumps. +void ImDisasmView::FollowBranch() { DisassemblyLineInfo line; manager.getLine(curAddress_, true, line); @@ -507,7 +510,7 @@ void ImDisasmView::followBranch() { jumpStack_.push_back(curAddress_); gotoAddr(line.info.branchTarget); } else if (line.info.hasRelevantAddress) { - // well, not exactly a branch, but we can do something anyway + // well, not exactly a branch, but we can do something anyway // SendMessage(GetParent(wnd), WM_DEB_GOTOHEXEDIT, line.info.relevantAddress, 0); // SetFocus(wnd); } @@ -644,7 +647,7 @@ void ImDisasmView::onKeyDown(ImGuiKey key) { } return; case VK_RIGHT: - followBranch(); + FollowBranch(); return; case VK_TAB: displaySymbols_ = !displaySymbols_; @@ -797,7 +800,7 @@ void ImDisasmView::PopupMenu() { debugger->setPC(curAddress_); } if (ImGui::MenuItem("Follow branch")) { - followBranch(); + FollowBranch(); } if (ImGui::MenuItem("Run to here")) { // CBreakPoints::AddBreakPoint(pos, true); diff --git a/UI/ImDebugger/ImDisasmView.h b/UI/ImDebugger/ImDisasmView.h index 7cbc232129..055e30bb97 100644 --- a/UI/ImDebugger/ImDisasmView.h +++ b/UI/ImDebugger/ImDisasmView.h @@ -125,7 +125,7 @@ private: std::string disassembleRange(u32 start, u32 size); void disassembleToFile(); void search(bool continueSearch); - void followBranch(); + void FollowBranch(); void calculatePixelPositions(); bool getDisasmAddressText(u32 address, char* dest, bool abbreviateLabels, bool showData); void updateStatusBarText();