From e95d9b15b4c78a6c3cf78aaac393f287dfd34c17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 26 Nov 2024 00:13:28 +0100 Subject: [PATCH] Add kernel object viewer, reimpl "Run to here" --- Core/HLE/sceKernel.cpp | 8 ---- Core/HLE/sceKernel.h | 10 ++++- UI/ImDebugger/ImDebugger.cpp | 76 +++++++++++++++++++++++++++++----- UI/ImDebugger/ImDebugger.h | 1 + UI/ImDebugger/ImDisasmView.cpp | 17 +++----- 5 files changed, 79 insertions(+), 33 deletions(-) diff --git a/Core/HLE/sceKernel.cpp b/Core/HLE/sceKernel.cpp index 4f90bc94ba..e494b1746a 100644 --- a/Core/HLE/sceKernel.cpp +++ b/Core/HLE/sceKernel.cpp @@ -510,14 +510,6 @@ SceUID KernelObjectPool::Create(KernelObject *obj, int rangeBottom, int rangeTop return 0; } -bool KernelObjectPool::IsValid(SceUID handle) const { - int index = handle - handleOffset; - if (index < 0 || index >= maxCount) - return false; - else - return occupied[index]; -} - void KernelObjectPool::Clear() { for (int i = 0; i < maxCount; i++) { // brutally clear everything, no validation diff --git a/Core/HLE/sceKernel.h b/Core/HLE/sceKernel.h index 6094781909..609f569014 100644 --- a/Core/HLE/sceKernel.h +++ b/Core/HLE/sceKernel.h @@ -452,7 +452,13 @@ public: return error; }; - bool IsValid(SceUID handle) const; + bool IsValid(SceUID handle) const { + int index = handle - handleOffset; + if (index < 0 || index >= maxCount) + return false; + else + return occupied[index]; + } template T* Get(SceUID handle, u32 &outError) { @@ -530,12 +536,12 @@ public: void Clear(); int GetCount() const; -private: enum { maxCount = 4096, handleOffset = 0x100, initialNextID = 0x10 }; +private: KernelObject *pool[maxCount]; bool occupied[maxCount]; int nextID; diff --git a/UI/ImDebugger/ImDebugger.cpp b/UI/ImDebugger/ImDebugger.cpp index 46622b9471..6cf0c4745f 100644 --- a/UI/ImDebugger/ImDebugger.cpp +++ b/UI/ImDebugger/ImDebugger.cpp @@ -52,7 +52,7 @@ void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) { auto gprLine = [&](const char *regname, int value) { ImGui::TableSetColumnIndex(0); - ImGui::Text("%s", regname); + ImGui::TextUnformatted(regname); ImGui::TableSetColumnIndex(1); ImGui::Text("%08x", value); if (value >= -1000000 && value <= 1000000) { @@ -84,7 +84,7 @@ void DrawRegisterView(MIPSDebugInterface *mipsDebug, bool *open) { u32 fivalue; memcpy(&fivalue, &fvalue, sizeof(fivalue)); ImGui::TableSetColumnIndex(0); - ImGui::Text("%s", mipsDebug->GetRegName(1, i).c_str()); + ImGui::TextUnformatted(mipsDebug->GetRegName(1, i).c_str()); ImGui::TableSetColumnIndex(1); ImGui::Text("%0.7f", fvalue); ImGui::TableSetColumnIndex(2); @@ -154,7 +154,7 @@ void DrawThreadView(ImConfig &cfg) { ImGui::TableNextColumn(); ImGui::Text("%d", thread.priority); ImGui::TableNextColumn(); - ImGui::Text("%s", ThreadStatusToString(thread.status)); + ImGui::TextUnformatted(ThreadStatusToString(thread.status)); if (ImGui::BeginPopup("threadPopup")) { DebugThreadInfo &thread = info[i]; ImGui::Text("Thread: %s", thread.name); @@ -218,6 +218,55 @@ static void DrawFilesystemBrowser(ImConfig &cfg) { ImGui::End(); } +static void DrawKernelObjects(ImConfig &cfg) { + if (!ImGui::Begin("Kernel Objects", &cfg.filesystemBrowserOpen)) { + ImGui::End(); + return; + } + if (ImGui::BeginTable("kos", 5, ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersH)) { + ImGui::TableSetupColumn("ID", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed); + ImGui::TableSetupColumn("Summary", ImGuiTableColumnFlags_WidthStretch); + + ImGui::TableHeadersRow(); + + for (int i = 0; i < (int)KernelObjectPool::maxCount; i++) { + int id = i + KernelObjectPool::handleOffset; + if (!kernelObjects.IsValid(id)) { + continue; + } + KernelObject *obj = kernelObjects.GetFast(id); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::PushID(i); + if (ImGui::Selectable("", cfg.selectedThread == i, ImGuiSelectableFlags_AllowDoubleClick | ImGuiSelectableFlags_SpanAllColumns)) { + cfg.selectedThread = i; + } + ImGui::SameLine(); + /* + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) { + cfg.selectedThread = i; + ImGui::OpenPopup("kernelObjectPopup"); + } + */ + ImGui::Text("%04x", id); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(obj->GetTypeName()); + ImGui::TableNextColumn(); + ImGui::TextUnformatted(obj->GetName()); + ImGui::TableNextColumn(); + char qi[128]; + obj->GetQuickInfo(qi, sizeof(qi)); + ImGui::TextUnformatted(qi); + ImGui::PopID(); + } + + ImGui::EndTable(); + } + ImGui::End(); +} + static const char *MemCheckConditionToString(MemCheckCondition cond) { switch (cond) { case MEMCHECK_READ: return "Read"; @@ -303,7 +352,7 @@ static void DrawBreakpointsView(MIPSDebugInterface *mipsDebug, ImConfig &cfg) { ImGui::TextUnformatted("-"); // opcode ImGui::TableNextColumn(); if (bp.hasCond) { - ImGui::Text("%s", bp.cond.expressionString.c_str()); + ImGui::TextUnformatted(bp.cond.expressionString.c_str()); } else { ImGui::TextUnformatted("-"); // condition } @@ -325,7 +374,7 @@ static void DrawBreakpointsView(MIPSDebugInterface *mipsDebug, ImConfig &cfg) { ImGui::SameLine(); ImGui::CheckboxFlags("", (int *)&mc.result, BREAK_ACTION_PAUSE); ImGui::TableNextColumn(); - ImGui::Text("%s", MemCheckConditionToString(mc.cond)); + ImGui::TextUnformatted(MemCheckConditionToString(mc.cond)); ImGui::TableNextColumn(); ImGui::Text("%08x", mc.start); ImGui::TableNextColumn(); @@ -453,13 +502,13 @@ void DrawCallStacks(MIPSDebugInterface *debug, bool *open) { const std::string entrySym = g_symbolMap->GetLabelString(frame.entry); ImGui::TableSetColumnIndex(0); - ImGui::Text("%s", entrySym.c_str()); + ImGui::TextUnformatted(entrySym.c_str()); ImGui::TableSetColumnIndex(1); ImGui::Text("%08x", frame.entry); ImGui::TableSetColumnIndex(2); ImGui::Text("%08x", frame.pc); ImGui::TableSetColumnIndex(3); - ImGui::Text("%s", "N/A"); // opcode, see the old debugger + ImGui::TextUnformatted("N/A"); // opcode, see the old debugger ImGui::TableSetColumnIndex(4); ImGui::Text("%08x", frame.sp); ImGui::TableSetColumnIndex(5); @@ -501,7 +550,7 @@ void DrawModules(MIPSDebugInterface *debug, ImConfig &cfg) { ImGui::TableNextColumn(); ImGui::Text("%08x", module.size); ImGui::TableNextColumn(); - ImGui::Text("%s", module.active ? "yes" : "no"); + ImGui::TextUnformatted(module.active ? "yes" : "no"); } ImGui::EndTable(); @@ -624,8 +673,9 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu } if (ImGui::BeginMenu("OS HLE")) { ImGui::MenuItem("File System Browser", nullptr, &cfg_.filesystemBrowserOpen); - ImGui::MenuItem("HLE Threads", nullptr, &cfg_.threadsOpen); - ImGui::MenuItem("HLE Modules",nullptr, &cfg_.modulesOpen); + ImGui::MenuItem("Kernel Objects", nullptr, &cfg_.kernelObjectsOpen); + ImGui::MenuItem("Threads", nullptr, &cfg_.threadsOpen); + ImGui::MenuItem("Modules",nullptr, &cfg_.modulesOpen); ImGui::MenuItem("sceAtrac", nullptr, &cfg_.atracOpen); ImGui::EndMenu(); } @@ -673,6 +723,10 @@ void ImDebugger::Frame(MIPSDebugInterface *mipsDebug, GPUDebugInterface *gpuDebu DrawFilesystemBrowser(cfg_); } + if (cfg_.kernelObjectsOpen) { + DrawKernelObjects(cfg_); + } + if (cfg_.threadsOpen) { DrawThreadView(cfg_); } @@ -845,7 +899,7 @@ void ImDisasmWindow::Draw(MIPSDebugInterface *mipsDebug, bool *open, CoreState c disasmView_.Draw(ImGui::GetWindowDrawList()); ImGui::EndTable(); - ImGui::Text("%s", disasmView_.StatusBarText().c_str()); + ImGui::TextUnformatted(disasmView_.StatusBarText().c_str()); } ImGui::End(); } diff --git a/UI/ImDebugger/ImDebugger.h b/UI/ImDebugger/ImDebugger.h index 45bf6dfd33..a1ba864dd9 100644 --- a/UI/ImDebugger/ImDebugger.h +++ b/UI/ImDebugger/ImDebugger.h @@ -75,6 +75,7 @@ struct ImConfig { bool framebuffersOpen = false; bool styleEditorOpen = false; bool filesystemBrowserOpen = false; + bool kernelObjectsOpen = false; // HLE explorer settings // bool filterByUsed = true; diff --git a/UI/ImDebugger/ImDisasmView.cpp b/UI/ImDebugger/ImDisasmView.cpp index f534237e57..d11ce7d8f6 100644 --- a/UI/ImDebugger/ImDisasmView.cpp +++ b/UI/ImDebugger/ImDisasmView.cpp @@ -811,16 +811,6 @@ void ImDisasmView::PopupMenu() { } ImGui::Separator(); - /* - if (ImGui::MenuItem("Edit symbol")) { - EditSymbolsWindow esw(wnd, debugger); - if (esw.exec()) { - esw.eval(); - SendMessage(GetParent(wnd), WM_DEB_MAPLOADED, 0, 0); - redraw(); - } - } - */ if (ImGui::MenuItem("Set PC to here")) { debugger->setPC(curAddress_); } @@ -828,8 +818,11 @@ void ImDisasmView::PopupMenu() { FollowBranch(); } if (ImGui::MenuItem("Run to here")) { - // g_breakpoints.AddBreakPoint(pos, true); - // Core_Resume(); + g_breakpoints.AddBreakPoint(curAddress_, true); + g_breakpoints.SetSkipFirst(curAddress_); + if (Core_IsStepping()) { + Core_Resume(); + } } ImGui::Separator(); if (ImGui::MenuItem("Assemble")) {