Skip to content

Commit

Permalink
Merge pull request #19609 from hrydgard/imgui-debugger
Browse files Browse the repository at this point in the history
ImGui debugger
  • Loading branch information
hrydgard authored Nov 7, 2024
2 parents ff6a10a + 0535f5e commit ace7cae
Show file tree
Hide file tree
Showing 25 changed files with 1,787 additions and 53 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ option(USE_LIBNX "Set to ON to build for Switch(libnx)" OFF)
option(USE_FFMPEG "Build with FFMPEG support" ON)
option(USE_DISCORD "Build with Discord support" ON)
option(USE_MINIUPNPC "Build with miniUPnPc support" ON)
option(USE_ARMIPS "Build with armips support in API/debugger" ON)
option(USE_ARMIPS "Build with armips support in API/debuggerdebugger" ON)
option(USE_SYSTEM_SNAPPY "Dynamically link against system snappy" ${USE_SYSTEM_SNAPPY})
option(USE_SYSTEM_FFMPEG "Dynamically link against system FFMPEG" ${USE_SYSTEM_FFMPEG})
option(USE_SYSTEM_LIBZIP "Dynamically link against system libzip" ${USE_SYSTEM_LIBZIP})
Expand Down Expand Up @@ -1519,6 +1519,10 @@ endif()

list(APPEND NativeAppSource
android/jni/TestRunner.cpp
UI/ImDebugger/ImDebugger.cpp
UI/ImDebugger/ImDebugger.h
UI/ImDebugger/ImDisasmView.cpp
UI/ImDebugger/ImDisasmView.h
UI/DiscordIntegration.cpp
UI/NativeApp.cpp
UI/BackgroundAudio.h
Expand Down
49 changes: 27 additions & 22 deletions Core/Debugger/DebugInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,48 @@ class DebugInterface {
public:
virtual int getInstructionSize(int instruction) {return 1;}

virtual bool isAlive() {return true;}
virtual bool isBreakpoint(unsigned int address) {return false;}
virtual void setBreakpoint(unsigned int address){}
virtual void clearBreakpoint(unsigned int address){}
virtual void clearAllBreakpoints() {}
virtual void toggleBreakpoint(unsigned int address){}
virtual unsigned int readMemory(unsigned int address){return 0;}
virtual unsigned int getPC() {return 0;}
virtual bool isAlive() = 0;
virtual bool isBreakpoint(unsigned int address) = 0;
virtual void setBreakpoint(unsigned int address) = 0;
virtual void clearBreakpoint(unsigned int address) = 0;
virtual void clearAllBreakpoints() = 0;
virtual void toggleBreakpoint(unsigned int address) = 0;
virtual unsigned int readMemory(unsigned int address) {return 0;}
virtual unsigned int getPC() = 0;
virtual void setPC(unsigned int address) {}
virtual void step() {}
virtual void runToBreakpoint() {}
virtual int getColor(unsigned int address){return 0xFFFFFFFF;}
virtual int getColor(unsigned int address, bool darkMode) const {return darkMode ? 0xFF101010 : 0xFFFFFFFF;}
virtual std::string getDescription(unsigned int address) {return "";}
virtual bool initExpression(const char* exp, PostfixExpression& dest) { return false; };
virtual bool parseExpression(PostfixExpression& exp, u32& dest) { return false; };

virtual u32 GetHi() { return 0; };
virtual u32 GetLo() { return 0; };
virtual u32 GetHi() = 0;
virtual u32 GetLo() = 0;
virtual u32 GetLLBit() = 0;

virtual void SetHi(u32 val) { };
virtual void SetLo(u32 val) { };
virtual const char *GetName() = 0;
virtual u32 GetGPR32Value(int reg) {return 0;}
virtual void SetGPR32Value(int reg) {}
virtual u32 GetGPR32Value(int reg) = 0;
virtual void SetGPR32Value(int reg, u32 value) = 0;
virtual float GetFPR32Value(int reg) { return -1.0f; }
virtual float GetVPR32Value(int reg) { return -1.0f; }

virtual u32 GetPC() = 0;
virtual void SetPC(u32 _pc) = 0;
virtual u32 GetLR() {return GetPC();}
virtual void DisAsm(u32 pc, char *out, size_t outSize) {
snprintf(out, outSize, "[%08x] UNKNOWN", pc);
}
virtual u32 GetLR() = 0;

virtual void DisAsm(u32 pc, char *out, size_t outSize) = 0;

// More stuff for debugger
virtual int GetNumCategories() {return 0;}
virtual int GetNumRegsInCategory(int cat) {return 0;}
virtual const char *GetCategoryName(int cat) {return 0;}
virtual std::string GetRegName(int cat, int index) { return ""; }
virtual int GetNumCategories() = 0;
virtual int GetNumRegsInCategory(int cat) = 0;
virtual const char *GetCategoryName(int cat) = 0;
virtual std::string GetRegName(int cat, int index) = 0;
virtual void PrintRegValue(int cat, int index, char *out, size_t outSize) {
snprintf(out, outSize, "%08X", GetGPR32Value(index));
}
virtual u32 GetRegValue(int cat, int index) {return 0;}
virtual u32 GetRegValue(int cat, int index) = 0;
virtual void SetRegValue(int cat, int index, u32 value) {}
};
1 change: 1 addition & 0 deletions Core/Debugger/SymbolMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ class SymbolMap {
// This is indexed by the end address of the module.
std::map<u32, const ModuleEntry> activeModuleEnds;

// Module ID, index
typedef std::pair<int, u32> SymbolKey;

// These are indexed by the module id and relative address in the module.
Expand Down
2 changes: 1 addition & 1 deletion Core/Debugger/WebSocket/DisasmSubscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void WebSocketDisasmState::WriteDisasmLine(JsonWriter &json, const DisassemblyLi
} else {
json.writeNull("macroEncoding");
}
int c = currentDebugMIPS->getColor(addr) & 0x00FFFFFF;
int c = currentDebugMIPS->getColor(addr, false) & 0x00FFFFFF;
json.writeString("backgroundColor", StringFromFormat("#%02x%02x%02x", c & 0xFF, (c >> 8) & 0xFF, c >> 16));
json.writeString("name", l.name);
json.writeString("params", l.params);
Expand Down
2 changes: 2 additions & 0 deletions Core/HLE/sceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ void __DisplayFlip(int cyclesLate) {
if (fbReallyDirty) {
DisplayFireActualFlip();
}
} else {
WARN_LOG(Log::sceDisplay, "Core_NextFrame returned false");
}
}

Expand Down
22 changes: 14 additions & 8 deletions Core/MIPS/MIPSDebugInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,21 @@ void MIPSDebugInterface::toggleBreakpoint(unsigned int address)
}


int MIPSDebugInterface::getColor(unsigned int address)
{
int colors[6] = {0xe0FFFF,0xFFe0e0,0xe8e8FF,0xFFe0FF,0xe0FFe0,0xFFFFe0};
int n=g_symbolMap->GetFunctionNum(address);
if (n==-1) return 0xFFFFFF;
return colors[n%6];
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 };

int n = g_symbolMap->GetFunctionNum(address);
if (n == -1) {
return DebugInterface::getColor(address, darkMode);
} else if (darkMode) {
return colorsDark[n % ARRAY_SIZE(colorsDark)];
} else {
return colors[n % ARRAY_SIZE(colors)];
}
}
std::string MIPSDebugInterface::getDescription(unsigned int address)
{

std::string MIPSDebugInterface::getDescription(unsigned int address) {
return g_symbolMap->GetDescription(address);
}

Expand Down
9 changes: 8 additions & 1 deletion Core/MIPS/MIPSDebugInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ class MIPSDebugInterface : public DebugInterface
void setPC(unsigned int address) override { cpu->pc = address; }
void step() override {}
void runToBreakpoint() override;
int getColor(unsigned int address) override;
int getColor(unsigned int address, bool darkMode) const override;
std::string getDescription(unsigned int address) override;
bool initExpression(const char* exp, PostfixExpression& dest) override;
bool parseExpression(PostfixExpression& exp, u32& dest) override;

//overridden functions
const char *GetName() override;
u32 GetGPR32Value(int reg) override { return cpu->r[reg]; }
float GetFPR32Value(int reg) override { return cpu->f[reg]; }
void SetGPR32Value(int reg, u32 value) override { cpu->r[reg] = value; }

u32 GetPC() override { return cpu->pc; }
u32 GetLR() override { return cpu->r[MIPS_REG_RA]; }
void DisAsm(u32 pc, char *out, size_t outSize) override;
Expand Down Expand Up @@ -76,6 +79,10 @@ class MIPSDebugInterface : public DebugInterface
return cpu->hi;
}

u32 GetLLBit() override {
return cpu->llBit;
}

u32 GetLo() override {
return cpu->lo;
}
Expand Down
14 changes: 10 additions & 4 deletions UI/EmuScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ using namespace std::placeholders;
#include "Core/Debugger/SymbolMap.h"
#include "Core/RetroAchievements.h"
#include "Core/SaveState.h"
#include "UI/ImDebugger/ImDebugger.h"
#include "Core/HLE/__sceAudio.h"
#include "Core/HLE/proAdhoc.h"
// #include "Core/HLE/proAdhoc.h"
#include "Core/HW/Display.h"

#include "UI/BackgroundAudio.h"
Expand Down Expand Up @@ -1240,6 +1241,9 @@ UI::EventReturn EmuScreen::OnResume(UI::EventParams &params) {
return UI::EVENT_DONE;
}

// To avoid including proAdhoc.h, which includes a lot of stuff.
int GetChatMessageCount();

void EmuScreen::update() {
using namespace UI;

Expand Down Expand Up @@ -1635,18 +1639,20 @@ ScreenRenderFlags EmuScreen::render(ScreenRenderMode mode) {

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

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

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

// Draw imgui on top. For now, all we have is the demo window.
ImGui::NewFrame();
ImGui::ShowDemoWindow(nullptr);
ImGui::Render();
imDebugger_->Frame(currentDebugMIPS);

ImGui::Render();
ImGui_ImplThin3d_RenderDrawData(ImGui::GetDrawData(), draw);
}
return flags;
Expand Down
4 changes: 4 additions & 0 deletions UI/EmuScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "Core/KeyMap.h"
#include "Core/ControlMapper.h"

#include "UI/ImDebugger/ImDebugger.h"

struct AxisInput;

class AsyncImageFileView;
Expand Down Expand Up @@ -129,6 +131,8 @@ class EmuScreen : public UIScreen {

ControlMapper controlMapper_;

std::unique_ptr<ImDebugger> imDebugger_ = nullptr;

bool imguiInited_ = false;
bool imguiVisible_ = false;
};
Loading

0 comments on commit ace7cae

Please sign in to comment.