Skip to content

Commit

Permalink
Merge pull request #19628 from hrydgard/assorted-debugger-fixes
Browse files Browse the repository at this point in the history
Assorted debugger fixes
  • Loading branch information
hrydgard authored Nov 12, 2024
2 parents c720991 + 18240b3 commit 2d96304
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 41 deletions.
1 change: 1 addition & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ static const ConfigSetting generalSettings[] = {
ConfigSetting("IgnoreBadMemAccess", &g_Config.bIgnoreBadMemAccess, true, CfgFlag::DEFAULT),
ConfigSetting("CurrentDirectory", &g_Config.currentDirectory, "", CfgFlag::DEFAULT),
ConfigSetting("ShowDebuggerOnLoad", &g_Config.bShowDebuggerOnLoad, false, CfgFlag::DEFAULT),
ConfigSetting("ShowImDebugger", &g_Config.bShowImDebugger, false, CfgFlag::DONT_SAVE),
ConfigSetting("CheckForNewVersion", &g_Config.bCheckForNewVersion, true, CfgFlag::DEFAULT),
ConfigSetting("Language", &g_Config.sLanguageIni, &DefaultLangRegion, CfgFlag::DEFAULT),
ConfigSetting("ForceLagSync2", &g_Config.bForceLagSync, false, CfgFlag::PER_GAME),
Expand Down
2 changes: 2 additions & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ struct Config {
bool bIgnoreScreenInsets; // Android: Center screen disregarding insets if this is enabled.
bool bVSync;

bool bShowImDebugger;

int iFrameSkip;
int iFrameSkipType;
int iFastForwardMode; // See FastForwardMode in ConfigValues.h.
Expand Down
11 changes: 8 additions & 3 deletions Core/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,18 @@ bool Core_Run(GraphicsContext *ctx) {
// Free-threaded (hm, possibly except tracing).
void Core_Break(const char *reason, u32 relatedAddress) {
// Stop the tracer
mipsTracer.stop_tracing();

{
std::lock_guard<std::mutex> 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);
return;
}
mipsTracer.stop_tracing();
g_stepCommand.reason = reason;
g_stepCommand.relatedAddr = relatedAddress;
steppingCounter++;
_assert_msg_(reason != nullptr, "No reason specified for break");

Core_UpdateState(CORE_STEPPING);
}
System_Notify(SystemNotification::DEBUG_MODE_CHANGE);
Expand Down
6 changes: 4 additions & 2 deletions Core/Debugger/WebSocket/SteppingBroadcaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ struct CPUSteppingEvent {
j.writeUint("pc", currentMIPS->pc);
// A double ought to be good enough for a 156 day debug session.
j.writeFloat("ticks", CoreTiming::GetTicks());
j.writeString("reason", reason_.reason);
j.writeUint("relatedAddress", reason_.relatedAddress);
if (reason_.reason) {
j.writeString("reason", reason_.reason);
j.writeUint("relatedAddress", reason_.relatedAddress);
}
j.end();
return j.str();
}
Expand Down
19 changes: 16 additions & 3 deletions Core/PSPLoaders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <thread>

#include "Core/Core.h"
#include "Common/Data/Encoding/Utf8.h"
#include "Common/Thread/ThreadUtil.h"
#include "Common/System/Request.h"
Expand Down Expand Up @@ -324,7 +325,11 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) {
// TODO: We can't use the initial error_string pointer.
bool success = __KernelLoadExec(bootpath.c_str(), 0, &PSP_CoreParameter().errorString);
if (success && coreState == CORE_POWERUP) {
coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING;
if (PSP_CoreParameter().startBreak) {
Core_Break("start-break");
} else {
coreState = CORE_RUNNING;
}
} else {
coreState = CORE_BOOT_ERROR;
// TODO: This is a crummy way to communicate the error...
Expand Down Expand Up @@ -483,7 +488,11 @@ bool Load_PSP_ELF_PBP(FileLoader *fileLoader, std::string *error_string) {

bool success = __KernelLoadExec(finalName.c_str(), 0, &PSP_CoreParameter().errorString);
if (success && coreState == CORE_POWERUP) {
coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING;
if (PSP_CoreParameter().startBreak) {
Core_Break("start-break");
} else {
coreState = CORE_RUNNING;
}
} else {
coreState = CORE_BOOT_ERROR;
// TODO: This is a crummy way to communicate the error...
Expand All @@ -509,7 +518,11 @@ bool Load_PSP_GE_Dump(FileLoader *fileLoader, std::string *error_string) {

bool success = __KernelLoadGEDump("disc0:/data.ppdmp", &PSP_CoreParameter().errorString);
if (success && coreState == CORE_POWERUP) {
coreState = PSP_CoreParameter().startBreak ? CORE_STEPPING : CORE_RUNNING;
if (PSP_CoreParameter().startBreak) {
Core_Break("start-break");
} else {
coreState = CORE_RUNNING;
}
} else {
coreState = CORE_BOOT_ERROR;
// TODO: This is a crummy way to communicate the error...
Expand Down
40 changes: 21 additions & 19 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ bool EmuScreen::UnsyncTouch(const TouchInput &touch) {
}
}

if (!(imguiVisible_ && imguiInited_)) {
if (!(g_Config.bShowImDebugger && imguiInited_)) {
GamepadTouch();
}

Expand All @@ -673,7 +673,7 @@ void EmuScreen::onVKey(int virtualKeyCode, bool down) {
switch (virtualKeyCode) {
case VIRTKEY_TOGGLE_DEBUGGER:
if (down) {
imguiVisible_ = !imguiVisible_;
g_Config.bShowImDebugger = !g_Config.bShowImDebugger;
}
break;
case VIRTKEY_FASTFORWARD:
Expand Down Expand Up @@ -952,10 +952,10 @@ void EmuScreen::onVKeyAnalog(int virtualKeyCode, float value) {

bool EmuScreen::UnsyncKey(const KeyInput &key) {
System_Notify(SystemNotification::ACTIVITY);
if (UI::IsFocusMovementEnabled() || (imguiVisible_ && imguiInited_)) {
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 (imguiVisible_ && imguiInited_ && (key.flags & (KEY_UP | KEY_DOWN))) {
if (g_Config.bShowImDebugger && imguiInited_ && (key.flags & (KEY_UP | KEY_DOWN))) {
InputMapping mapping(key.deviceId, key.keyCode);
std::vector<int> pspButtons;
bool mappingFound = KeyMap::InputMappingToPspButton(mapping, &pspButtons);
Expand All @@ -976,7 +976,7 @@ bool EmuScreen::UnsyncKey(const KeyInput &key) {
bool EmuScreen::key(const KeyInput &key) {
bool retval = UIScreen::key(key);

if (!retval && imguiVisible_ && imguiInited_) {
if (!retval && g_Config.bShowImDebugger && imguiInited_) {
ImGui_ImplPlatform_KeyEvent(key);
}

Expand All @@ -993,7 +993,7 @@ bool EmuScreen::key(const KeyInput &key) {
}

void EmuScreen::touch(const TouchInput &touch) {
if (imguiVisible_ && imguiInited_) {
if (g_Config.bShowImDebugger && imguiInited_) {
ImGui_ImplPlatform_TouchEvent(touch);
} else {
UIScreen::touch(touch);
Expand Down Expand Up @@ -1637,23 +1637,25 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {
darken();
}

if (imguiVisible_ && !imguiInited_) {
imguiInited_ = true;
imDebugger_ = std::make_unique<ImDebugger>();
ImGui_ImplThin3d_Init(draw);
}
if (g_Config.bShowImDebugger) {
if (!imguiInited_) {
imguiInited_ = true;
imDebugger_ = std::make_unique<ImDebugger>();
ImGui_ImplThin3d_Init(draw);
}

if (imguiVisible_ && imguiInited_ && PSP_IsInited()) {
_dbg_assert_(imDebugger_);
if (PSP_IsInited()) {
_dbg_assert_(imDebugger_);

ImGui_ImplPlatform_NewFrame();
ImGui_ImplThin3d_NewFrame(draw, ui_draw2d.GetDrawMatrix());
ImGui_ImplPlatform_NewFrame();
ImGui_ImplThin3d_NewFrame(draw, ui_draw2d.GetDrawMatrix());

ImGui::NewFrame();
imDebugger_->Frame(currentDebugMIPS);
ImGui::NewFrame();
imDebugger_->Frame(currentDebugMIPS);

ImGui::Render();
ImGui_ImplThin3d_RenderDrawData(ImGui::GetDrawData(), draw);
ImGui::Render();
ImGui_ImplThin3d_RenderDrawData(ImGui::GetDrawData(), draw);
}
}
return flags;
}
Expand Down
1 change: 0 additions & 1 deletion UI/EmuScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,4 @@ class EmuScreen : public UIScreen {
std::unique_ptr<ImDebugger> imDebugger_ = nullptr;

bool imguiInited_ = false;
bool imguiVisible_ = false;
};
18 changes: 9 additions & 9 deletions Windows/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,20 +641,20 @@ namespace MainWindow
SetCapture(hWnd);

// Simulate doubleclick, doesn't work with RawInput enabled
static double lastMouseDown;
static double lastMouseDownTime;
static float lastMouseDownX = -1.0f;
static float lastMouseDownY = -1.0f;
double now = time_now_d();
if ((now - lastMouseDown) < 0.001 * GetDoubleClickTime()) {
float dx = lastMouseDownX - x;
float dy = lastMouseDownY - y;
float distSq = dx * dx + dy * dy;
if (distSq < 3.0f*3.0f && !g_Config.bShowTouchControls && !g_Config.bMouseControl && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) {
const double now = time_now_d();
if ((now - lastMouseDownTime) < 0.001 * GetDoubleClickTime()) {
const float dx = lastMouseDownX - x;
const float dy = lastMouseDownY - y;
const float distSq = dx * dx + dy * dy;
if (distSq < 3.0f*3.0f && !g_Config.bShowTouchControls && !g_Config.bShowImDebugger && !g_Config.bMouseControl && GetUIState() == UISTATE_INGAME && g_Config.bFullscreenOnDoubleclick) {
SendToggleFullscreen(!g_Config.UseFullScreen());
}
lastMouseDown = 0.0;
lastMouseDownTime = 0.0;
} else {
lastMouseDown = now;
lastMouseDownTime = now;
}
lastMouseDownX = x;
lastMouseDownY = y;
Expand Down
4 changes: 0 additions & 4 deletions ext/imgui/imgui_impl_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) {
ImGuiKey keyCode = KeyCodeToImGui(key.keyCode);
if (keyCode != ImGuiKey_None) {
io.AddKeyEvent(keyCode, true);
} else {
WARN_LOG(Log::System, "KeyDown: Unmapped ImGui keycode conversion from %d", key.keyCode);
}
break;
}
Expand All @@ -35,8 +33,6 @@ void ImGui_ImplPlatform_KeyEvent(const KeyInput &key) {
ImGuiKey keyCode = KeyCodeToImGui(key.keyCode);
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) {
Expand Down

0 comments on commit 2d96304

Please sign in to comment.