Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More ImDebugger fixes #20024

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions UI/ImDebugger/ImDebugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "UI/ImDebugger/ImGe.h"

extern bool g_TakeScreenshot;
static ImVec4 g_normalTextColor;

void ShowInMemoryViewerMenuItem(uint32_t addr, ImControl &control) {
if (ImGui::BeginMenu("Show in memory viewer")) {
Expand Down Expand Up @@ -96,22 +97,31 @@ void StatusBar(std::string_view status) {

// TODO: Style it.
// Left click performs the preferred action, if any. Right click opens a menu for more.
void ImClickableAddress(uint32_t addr, ImControl &control, ImCmd cmd) {
void ImClickableValue(const char *id, uint32_t addr, ImControl &control, ImCmd cmd) {
ImGui::PushID(id);

bool validAddr = Memory::IsValidAddress(addr);

char temp[32];
snprintf(temp, sizeof(temp), "%08x", addr);
if (ImGui::SmallButton(temp)) {
if (ImGui::Selectable(temp) && validAddr) {
control.command = { cmd, addr };
}

// Create a right-click popup menu
// Create a right-click popup menu. Restore the color while it's up. NOTE: can't query the theme, pushcolor modifies it!
ImGui::PushStyleColor(ImGuiCol_Text, g_normalTextColor);
if (ImGui::BeginPopupContextItem(temp)) {
if (ImGui::MenuItem("Copy address to clipboard")) {
if (ImGui::MenuItem(validAddr ? "Copy address to clipboard" : "Copy value to clipboard")) {
System_CopyStringToClipboard(temp);
}
ImGui::Separator();
ShowInWindowMenuItems(addr, control);
if (validAddr) {
ImGui::Separator();
ShowInWindowMenuItems(addr, control);
}
ImGui::EndPopup();
}
ImGui::PopStyleColor();
ImGui::PopID();
}

void DrawSchedulerView(ImConfig &cfg) {
Expand Down Expand Up @@ -170,13 +180,8 @@ static void DrawGPRs(ImConfig &config, ImControl &control, const MIPSDebugInterf
} else if (disabled) {
ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(255, 255, 255, 128));
}
if (Memory::IsValid4AlignedAddress(value)) {
ImGui::PushID(index);
ImClickableAddress(value, control, index == MIPS_REG_RA ? ImCmd::SHOW_IN_CPU_DISASM : ImCmd::SHOW_IN_MEMORY_VIEWER);
ImGui::PopID();
} else {
ImGui::Text("%08x", value);
}
// TODO: Check if the address is in the code segment to decide default action.
ImClickableValue(regname, value, control, index == MIPS_REG_RA ? ImCmd::SHOW_IN_CPU_DISASM : ImCmd::SHOW_IN_MEMORY_VIEWER);
ImGui::TableNextColumn();
if (value >= -1000000 && value <= 1000000) {
ImGui::Text("%d", value);
Expand Down Expand Up @@ -349,10 +354,10 @@ void DrawThreadView(ImConfig &cfg, ImControl &control) {
for (int i = 0; i < (int)info.size(); i++) {
const DebugThreadInfo &thread = info[i];
ImGui::TableNextRow();
ImGui::PushID(i);
ImGui::TableNextColumn();
ImGui::Text("%d", thread.id);
ImGui::TableNextColumn();
ImGui::PushID(i);
if (ImGui::Selectable(thread.name, cfg.selectedThread == i, ImGuiSelectableFlags_AllowDoubleClick | ImGuiSelectableFlags_SpanAllColumns)) {
cfg.selectedThread = i;
}
Expand All @@ -361,9 +366,9 @@ void DrawThreadView(ImConfig &cfg, ImControl &control) {
ImGui::OpenPopup("threadPopup");
}
ImGui::TableNextColumn();
ImClickableAddress(thread.curPC, control, ImCmd::SHOW_IN_CPU_DISASM);
ImClickableValue("curpc", thread.curPC, control, ImCmd::SHOW_IN_CPU_DISASM);
ImGui::TableNextColumn();
ImClickableAddress(thread.entrypoint, control, ImCmd::SHOW_IN_CPU_DISASM);
ImClickableValue("entry", thread.entrypoint, control, ImCmd::SHOW_IN_CPU_DISASM);
ImGui::TableNextColumn();
ImGui::Text("%d", thread.priority);
ImGui::TableNextColumn();
Expand Down Expand Up @@ -897,7 +902,7 @@ static void DrawBreakpointsView(MIPSDebugInterface *mipsDebug, ImConfig &cfg) {
ImGui::End();
}

void DrawAudioDecodersView(ImConfig &cfg) {
void DrawAudioDecodersView(ImConfig &cfg, ImControl &control) {
if (!ImGui::Begin("Audio decoding contexts", &cfg.audioDecodersOpen)) {
ImGui::End();
return;
Expand Down Expand Up @@ -1156,8 +1161,8 @@ void DrawSasAudio(ImConfig &cfg) {
ImGui::End();
}

static void DrawCallStacks(const MIPSDebugInterface *debug, bool *open) {
if (!ImGui::Begin("Callstacks", open)) {
static void DrawCallStacks(const MIPSDebugInterface *debug, ImConfig &config, ImControl &control) {
if (!ImGui::Begin("Callstacks", &config.callstackOpen)) {
ImGui::End();
return;
}
Expand Down Expand Up @@ -1194,25 +1199,24 @@ static void DrawCallStacks(const MIPSDebugInterface *debug, bool *open) {
ImGui::TableSetColumnIndex(0);
ImGui::TextUnformatted(entrySym.c_str());
ImGui::TableSetColumnIndex(1);
ImGui::Text("%08x", frame.entry);
ImClickableValue("frameentry", frame.entry, control, ImCmd::SHOW_IN_CPU_DISASM);
ImGui::TableSetColumnIndex(2);
ImGui::Text("%08x", frame.pc);
ImClickableValue("framepc", frame.pc, control, ImCmd::SHOW_IN_CPU_DISASM);
ImGui::TableSetColumnIndex(3);
ImGui::TextUnformatted("N/A"); // opcode, see the old debugger
ImGui::TableSetColumnIndex(4);
ImGui::Text("%08x", frame.sp);
ImClickableValue("framepc", frame.sp, control, ImCmd::SHOW_IN_MEMORY_VIEWER);
ImGui::TableSetColumnIndex(5);
ImGui::Text("%d", frame.stackSize);
ImGui::TableNextRow();
// TODO: More fields?
}

ImGui::EndTable();
}
ImGui::End();
}

static void DrawModules(const MIPSDebugInterface *debug, ImConfig &cfg) {
static void DrawModules(const MIPSDebugInterface *debug, ImConfig &cfg, ImControl &control) {
if (!ImGui::Begin("Modules", &cfg.modulesOpen) || !g_symbolMap) {
ImGui::End();
return;
Expand All @@ -1236,7 +1240,7 @@ static void DrawModules(const MIPSDebugInterface *debug, ImConfig &cfg) {
cfg.selectedModule = i;
}
ImGui::TableNextColumn();
ImGui::Text("%08x", module.address);
ImClickableValue("addr", module.address, control, ImCmd::SHOW_IN_MEMORY_VIEWER);
ImGui::TableNextColumn();
ImGui::Text("%08x", module.size);
ImGui::TableNextColumn();
Expand Down Expand Up @@ -1287,6 +1291,7 @@ void DrawHLEModules(ImConfig &config) {
ImDebugger::ImDebugger() {
reqToken_ = g_requestManager.GenerateRequesterToken();
cfg_.LoadConfig(ConfigPath());
g_normalTextColor = ImGui::GetStyleColorVec4(ImGuiCol_Text);
}

ImDebugger::~ImDebugger() {
Expand Down Expand Up @@ -1508,15 +1513,15 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu
}

if (cfg_.callstackOpen) {
DrawCallStacks(mipsDebug, &cfg_.callstackOpen);
DrawCallStacks(mipsDebug, cfg_, control);
}

if (cfg_.modulesOpen) {
DrawModules(mipsDebug, cfg_);
DrawModules(mipsDebug, cfg_, control);
}

if (cfg_.audioDecodersOpen) {
DrawAudioDecodersView(cfg_);
DrawAudioDecodersView(cfg_, control);
}

if (cfg_.hleModulesOpen) {
Expand Down
2 changes: 1 addition & 1 deletion UI/ImDebugger/ImDebugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class ImDebugger {
};

// Simple custom controls and utilities.
void ImClickableAddress(uint32_t addr, ImControl &control, ImCmd cmd);
void ImClickableValue(const char *id, uint32_t addr, ImControl &control, ImCmd cmd);
void ShowInWindowMenuItems(uint32_t addr, ImControl &control);
void ShowInMemoryViewerMenuItem(uint32_t addr, ImControl &control);
void ShowInMemoryDumperMenuItem(uint32_t addr, uint32_t size, MemDumpMode mode, ImControl &control);
Expand Down
8 changes: 4 additions & 4 deletions UI/ImDebugger/ImGe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -926,17 +926,17 @@ void ImGeDebuggerWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterfa
ImGui::Text("State: %s", DLStateToString(list.state));
ImGui::TextUnformatted("PC:");
ImGui::SameLine();
ImClickableAddress(list.pc, control, ImCmd::SHOW_IN_GE_DISASM);
ImClickableValue("pc", list.pc, control, ImCmd::SHOW_IN_GE_DISASM);
ImGui::Text("StartPC:");
ImGui::SameLine();
ImClickableAddress(list.startpc, control, ImCmd::SHOW_IN_GE_DISASM);
ImClickableValue("startpc", list.startpc, control, ImCmd::SHOW_IN_GE_DISASM);
if (list.pendingInterrupt) {
ImGui::TextUnformatted("(Pending interrupt)");
}
if (list.stall) {
ImGui::TextUnformatted("Stall addr:");
ImGui::SameLine();
ImClickableAddress(list.pc, control, ImCmd::SHOW_IN_GE_DISASM);
ImClickableValue("stall", list.pc, control, ImCmd::SHOW_IN_GE_DISASM);
}
ImGui::Text("Stack depth: %d", (int)list.stackptr);
ImGui::Text("BBOX result: %d", (int)list.bboxResult);
Expand Down Expand Up @@ -1363,7 +1363,7 @@ void ImGeStateWindow::Draw(ImConfig &cfg, ImControl &control, GPUDebugInterface
// Special handling for pointer and pointer/width entries - create an address control
if (info.fmt == CMD_FMT_PTRWIDTH) {
const u32 val = (value & 0xFFFFFF) | (otherValue & 0x00FF0000) << 8;
ImClickableAddress(val, control, ImCmd::NONE);
ImClickableValue(info.uiName, val, control, ImCmd::NONE);
ImGui::SameLine();
ImGui::Text("w=%d", otherValue & 0xFFFF);
} else {
Expand Down
Loading