From d3e9e1296ca852abad04936a6eff33037b367cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandro=20S=C3=A1nchez=20Bach?= Date: Sat, 26 Jul 2014 07:51:45 +0200 Subject: [PATCH] Kernel Explorer implemented --- rpcs3/Emu/IdManager.h | 13 +-- rpcs3/Gui/KernelExplorer.cpp | 167 +++++++++++++++++++++++++++++++++++ rpcs3/Gui/KernelExplorer.h | 15 ++++ rpcs3/Gui/MainFrame.cpp | 24 +++-- rpcs3/Gui/MainFrame.h | 1 + rpcs3/rpcs3.vcxproj | 2 + rpcs3/rpcs3.vcxproj.filters | 6 ++ 7 files changed, 216 insertions(+), 12 deletions(-) create mode 100644 rpcs3/Gui/KernelExplorer.cpp create mode 100644 rpcs3/Gui/KernelExplorer.h diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index da9174f4b8..b1170cce04 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -26,7 +26,7 @@ enum IDType TYPE_LWCOND, TYPE_EVENT_FLAG, - // Generic + // Any other objects TYPE_OTHER, }; @@ -104,7 +104,7 @@ class IdManager static const u32 s_max_id = -1; std::unordered_map m_id_map; - std::set m_types[TYPE_OTHER]; + std::set m_types[TYPE_OTHER]; std::mutex m_mtx_main; u32 m_cur_id; @@ -179,12 +179,13 @@ public: bool HasID(const s64 id) { - std::lock_guard lock(m_mtx_main); + { + std::lock_guard lock(m_mtx_main); - if(id == rID_ANY) { - return m_id_map.begin() != m_id_map.end(); + if(id == rID_ANY) { + return m_id_map.begin() != m_id_map.end(); + } } - return CheckID(id); } diff --git a/rpcs3/Gui/KernelExplorer.cpp b/rpcs3/Gui/KernelExplorer.cpp new file mode 100644 index 0000000000..711e3f4df5 --- /dev/null +++ b/rpcs3/Gui/KernelExplorer.cpp @@ -0,0 +1,167 @@ +#include "stdafx.h" +#include "Utilities/Log.h" +#include "Emu/Memory/Memory.h" +#include "Emu/System.h" + +#include "KernelExplorer.h" + +KernelExplorer::KernelExplorer(wxWindow* parent) + : wxFrame(parent, wxID_ANY, "Kernel Explorer", wxDefaultPosition, wxSize(700, 450)) +{ + this->SetBackgroundColour(wxColour(240,240,240)); //This fix the ugly background color under Windows + wxBoxSizer* s_panel = new wxBoxSizer(wxVERTICAL); + + // Buttons + wxBoxSizer* box_buttons = new wxBoxSizer(wxHORIZONTAL); + wxButton* b_refresh = new wxButton(this, wxID_ANY, "Refresh"); + box_buttons->AddSpacer(10); + box_buttons->Add(b_refresh); + box_buttons->AddSpacer(10); + + wxStaticBoxSizer* box_tree = new wxStaticBoxSizer(wxHORIZONTAL, this, "Kernel"); + m_tree = new wxTreeCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(600,300)); + box_tree->Add(m_tree); + + // Merge and display everything + s_panel->AddSpacer(10); + s_panel->Add(box_buttons); + s_panel->AddSpacer(10); + s_panel->Add(box_tree, 0, 0, 100); + s_panel->AddSpacer(10); + SetSizerAndFit(s_panel); + + // Events + b_refresh->Bind(wxEVT_BUTTON, &KernelExplorer::OnRefresh, this); + + // Fill the wxTreeCtrl + Update(); +}; + +void KernelExplorer::Update() +{ + int count; + char name[4096]; + + m_tree->DeleteAllItems(); + auto& root = m_tree->AddRoot("Process, ID = 0x00000001, Total Memory Usage = 0x0C8A9000 (200.7 MB)"); + + // TODO: PPU Threads + // TODO: SPU/RawSPU Threads + // TODO: FileSystem + + // Semaphores + count = Emu.GetIdManager().GetTypeCount(TYPE_SEMAPHORE); + if (count) { + sprintf(name, "Semaphores (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_SEMAPHORE); + for (const auto& id : objects) { + sprintf(name, "Semaphore: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Mutexes + count = Emu.GetIdManager().GetTypeCount(TYPE_MUTEX); + if (count) { + sprintf(name, "Mutexes (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_MUTEX); + for (const auto& id : objects) { + sprintf(name, "Mutex: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Light Weight Mutexes + count = Emu.GetIdManager().GetTypeCount(TYPE_LWMUTEX); + if (count) { + sprintf(name, "Light Weight Mutexes (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_LWMUTEX); + for (const auto& id : objects) { + sprintf(name, "LW Mutex: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Condition Variables + count = Emu.GetIdManager().GetTypeCount(TYPE_COND); + if (count) { + sprintf(name, "Condition Variables (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_COND); + for (const auto& id : objects) { + sprintf(name, "Condition Variable: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Light Weight Condition Variables + count = Emu.GetIdManager().GetTypeCount(TYPE_LWCOND); + if (count) { + sprintf(name, "Light Weight Condition Variables (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_LWCOND); + for (const auto& id : objects) { + sprintf(name, "LW Condition Variable: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Event Queues + count = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_QUEUE); + if (count) { + sprintf(name, "Event Queues (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_EVENT_QUEUE); + for (const auto& id : objects) { + sprintf(name, "Event Queue: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Modules + count = Emu.GetIdManager().GetTypeCount(TYPE_PRX); + if (count) { + sprintf(name, "Modules (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_PRX); + sprintf(name, "Segment List (%d)", 2 * objects.size()); // TODO: Assuming 2 segments per PRX file is not good + m_tree->AppendItem(node, name); + for (const auto& id : objects) { + sprintf(name, "PRX: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + // Memory Containers + count = Emu.GetIdManager().GetTypeCount(TYPE_MEM); + if (count) { + sprintf(name, "Memory Containers (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_MEM); + for (const auto& id : objects) { + sprintf(name, "Memory Container: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + // Event Flags + count = Emu.GetIdManager().GetTypeCount(TYPE_EVENT_FLAG); + if (count) { + sprintf(name, "Event Flags (%d)", count); + auto& node = m_tree->AppendItem(root, name); + auto& objects = Emu.GetIdManager().GetTypeIDs(TYPE_EVENT_FLAG); + for (const auto& id : objects) { + sprintf(name, "Event Flag: ID = 0x%08x", id); + m_tree->AppendItem(node, name); + } + } + + m_tree->Expand(root); +} + +void KernelExplorer::OnRefresh(wxCommandEvent& WXUNUSED(event)) +{ + Update(); +} diff --git a/rpcs3/Gui/KernelExplorer.h b/rpcs3/Gui/KernelExplorer.h new file mode 100644 index 0000000000..06b65eeeed --- /dev/null +++ b/rpcs3/Gui/KernelExplorer.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +class KernelExplorer : public wxFrame +{ + wxTreeCtrl* m_tree; + +public: + KernelExplorer(wxWindow* parent); + void Update(); + + void OnRefresh(wxCommandEvent& WXUNUSED(event)); +}; diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index 69249a2fd8..fc79993072 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -4,20 +4,22 @@ #include "Emu/System.h" #include "rpcs3.h" #include "MainFrame.h" -#include "CompilerELF.h" -#include "MemoryViewer.h" -#include "RSXDebugger.h" -#include "PADManager.h" #include "git-version.h" #include "Ini.h" #include "Emu/RSX/sysutil_video.h" +#include "Gui/PADManager.h" #include "Gui/VHDDManager.h" #include "Gui/VFSManager.h" #include "Gui/AboutDialog.h" #include "Gui/GameViewer.h" +#include "Gui/CompilerELF.h" #include "Gui/AutoPauseManager.h" #include "Gui/SaveDataUtility.h" +#include "Gui/KernelExplorer.h" +#include "Gui/MemoryViewer.h" +#include "Gui/RSXDebugger.h" + #include #include "Loader/PKG.h" @@ -42,6 +44,7 @@ enum IDs id_config_autopause_manager, id_config_savedata_manager, id_tools_compiler, + id_tools_kernel_explorer, id_tools_memory_viewer, id_tools_rsx_debugger, id_help_about, @@ -98,6 +101,7 @@ MainFrame::MainFrame() wxMenu* menu_tools = new wxMenu(); menubar->Append(menu_tools, "Tools"); menu_tools->Append(id_tools_compiler, "ELF Compiler"); + menu_tools->Append(id_tools_kernel_explorer, "Kernel Explorer")->Enable(false); menu_tools->Append(id_tools_memory_viewer, "Memory Viewer")->Enable(false); menu_tools->Append(id_tools_rsx_debugger, "RSX Debugger")->Enable(false); @@ -134,6 +138,7 @@ MainFrame::MainFrame() Bind(wxEVT_MENU, &MainFrame::ConfigSaveData, this, id_config_savedata_manager); Bind(wxEVT_MENU, &MainFrame::OpenELFCompiler, this, id_tools_compiler); + Bind(wxEVT_MENU, &MainFrame::OpenKernelExplorer, this, id_tools_kernel_explorer); Bind(wxEVT_MENU, &MainFrame::OpenMemoryViewer, this, id_tools_memory_viewer); Bind(wxEVT_MENU, &MainFrame::OpenRSXDebugger, this, id_tools_rsx_debugger); @@ -635,6 +640,11 @@ void MainFrame::OpenELFCompiler(wxCommandEvent& WXUNUSED(event)) (new CompilerELF(this)) -> Show(); } +void MainFrame::OpenKernelExplorer(wxCommandEvent& WXUNUSED(event)) +{ + (new KernelExplorer(this)) -> Show(); +} + void MainFrame::OpenMemoryViewer(wxCommandEvent& WXUNUSED(event)) { (new MemoryViewerPanel(this)) -> Show(); @@ -732,8 +742,10 @@ void MainFrame::UpdateUI(wxCommandEvent& event) send_exit.Enable(enable_commands); // Tools - wxMenuItem& memory_viewer = *menubar.FindItem( id_tools_memory_viewer ); - wxMenuItem& rsx_debugger = *menubar.FindItem( id_tools_rsx_debugger); + wxMenuItem& kernel_explorer = *menubar.FindItem(id_tools_kernel_explorer); + wxMenuItem& memory_viewer = *menubar.FindItem(id_tools_memory_viewer); + wxMenuItem& rsx_debugger = *menubar.FindItem(id_tools_rsx_debugger); + kernel_explorer.Enable(!is_stopped); memory_viewer.Enable(!is_stopped); rsx_debugger.Enable(!is_stopped); diff --git a/rpcs3/Gui/MainFrame.h b/rpcs3/Gui/MainFrame.h index 604e68e97c..3e1b625048 100644 --- a/rpcs3/Gui/MainFrame.h +++ b/rpcs3/Gui/MainFrame.h @@ -41,6 +41,7 @@ private: void ConfigAutoPause(wxCommandEvent& event); void ConfigSaveData(wxCommandEvent& event); void OpenELFCompiler(wxCommandEvent& evt); + void OpenKernelExplorer(wxCommandEvent& evt); void OpenMemoryViewer(wxCommandEvent& evt); void OpenRSXDebugger(wxCommandEvent& evt); void OpenFnIdGenerator(wxCommandEvent& evt); diff --git a/rpcs3/rpcs3.vcxproj b/rpcs3/rpcs3.vcxproj index 9b4424a1db..bdd38e73eb 100644 --- a/rpcs3/rpcs3.vcxproj +++ b/rpcs3/rpcs3.vcxproj @@ -173,6 +173,7 @@ + @@ -218,6 +219,7 @@ + diff --git a/rpcs3/rpcs3.vcxproj.filters b/rpcs3/rpcs3.vcxproj.filters index 7043c6c0f1..d01670ad84 100644 --- a/rpcs3/rpcs3.vcxproj.filters +++ b/rpcs3/rpcs3.vcxproj.filters @@ -101,6 +101,9 @@ Gui + + + Gui @@ -214,6 +217,9 @@ Gui + + + Gui \ No newline at end of file