From 5b14f7de64321000d01c1c92dfd06abe8628d9f1 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Fri, 22 Aug 2014 16:11:10 +0200 Subject: [PATCH 1/3] Add a list with bios version specific information --- pcsx2/ps2/BiosTools.cpp | 16 ++++++++++++++++ pcsx2/ps2/BiosTools.h | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/pcsx2/ps2/BiosTools.cpp b/pcsx2/ps2/BiosTools.cpp index 31309ba0e2..5f95d2dd1f 100644 --- a/pcsx2/ps2/BiosTools.cpp +++ b/pcsx2/ps2/BiosTools.cpp @@ -52,7 +52,13 @@ static_assert( sizeof(romdir) == DIRENTRY_SIZE, "romdir struct not packed to 16 u32 BiosVersion; u32 BiosChecksum; wxString BiosDescription; +const BiosDebugInformation* CurrentBiosInformation; +const BiosDebugInformation biosVersions[] = { + // USA v02.00(14/06/2004) Console + { 0x00000200, 0xD778DB8D, 0x8001a640 }, + +}; // -------------------------------------------------------------------------------------- // Exception::BiosLoadFailed (implementations) @@ -271,6 +277,16 @@ void LoadBIOS() LoadExtraRom( L"rom1", eeMem->ROM1 ); LoadExtraRom( L"rom2", eeMem->ROM2 ); LoadExtraRom( L"erom", eeMem->EROM ); + + CurrentBiosInformation = NULL; + for (int i = 0; i < sizeof(biosVersions)/sizeof(biosVersions[0]); i++) + { + if (biosVersions[i].biosChecksum == BiosChecksum && biosVersions[i].biosVersion == BiosVersion) + { + CurrentBiosInformation = &biosVersions[i]; + break; + } + } } catch (Exception::BadStream& ex) { diff --git a/pcsx2/ps2/BiosTools.h b/pcsx2/ps2/BiosTools.h index 66d0656524..aa4b26f2cf 100644 --- a/pcsx2/ps2/BiosTools.h +++ b/pcsx2/ps2/BiosTools.h @@ -28,9 +28,17 @@ namespace Exception }; } +struct BiosDebugInformation +{ + u32 biosVersion; + u32 biosChecksum; + u32 threadListAddr; +}; + extern u32 BiosVersion; // Used by CDVD extern u32 BiosChecksum; extern wxString BiosDescription; +extern const BiosDebugInformation* CurrentBiosInformation; extern void LoadBIOS(); extern bool IsBIOS(const wxString& filename, wxString& description); From 5f7a3a8ca920f4337833ee91d7937febc1d01140 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Fri, 22 Aug 2014 16:11:13 +0200 Subject: [PATCH 2/3] Read EE threads from bios (thanks @gregory38) --- pcsx2/CMakeLists.txt | 6 ++- pcsx2/DebugTools/BiosDebugData.cpp | 28 +++++++++++ pcsx2/DebugTools/BiosDebugData.h | 50 +++++++++++++++++++ pcsx2/windows/VCprojects/pcsx2.vcxproj | 2 + .../windows/VCprojects/pcsx2.vcxproj.filters | 6 +++ pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj | 2 + .../VCprojects/pcsx2_vs2012.vcxproj.filters | 6 +++ pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj | 4 +- .../VCprojects/pcsx2_vs2013.vcxproj.filters | 8 ++- 9 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 pcsx2/DebugTools/BiosDebugData.cpp create mode 100644 pcsx2/DebugTools/BiosDebugData.h diff --git a/pcsx2/CMakeLists.txt b/pcsx2/CMakeLists.txt index fcbbaccf5b..88b197efbd 100644 --- a/pcsx2/CMakeLists.txt +++ b/pcsx2/CMakeLists.txt @@ -267,7 +267,8 @@ set(pcsx2DebugToolsSources DebugTools/DisR3000A.cpp DebugTools/DisR5900asm.cpp DebugTools/DisVU0Micro.cpp - DebugTools/DisVU1Micro.cpp) + DebugTools/DisVU1Micro.cpp + DebugTools/BiosDebugData.cpp) # DebugTools headers set(pcsx2DebugToolsHeaders @@ -282,7 +283,8 @@ set(pcsx2DebugToolsHeaders DebugTools/Debug.h DebugTools/DisASm.h DebugTools/DisVUmicro.h - DebugTools/DisVUops.h) + DebugTools/DisVUops.h + DebugTools/BiosDebugData.h) # gui sources set(pcsx2GuiSources diff --git a/pcsx2/DebugTools/BiosDebugData.cpp b/pcsx2/DebugTools/BiosDebugData.cpp new file mode 100644 index 0000000000..85964d814f --- /dev/null +++ b/pcsx2/DebugTools/BiosDebugData.cpp @@ -0,0 +1,28 @@ +#include "PrecompiledHeader.h" +#include "BiosDebugData.h" +#include "../Memory.h" + +std::vector getEEThreads() +{ + std::vector threads; + + if (CurrentBiosInformation == NULL) + return threads; + + u32 start = CurrentBiosInformation->threadListAddr & 0x3fffff; + for (int tid = 0; tid < 256; tid++) + { + EEThread thread; + + EEInternalThread* internal = (EEInternalThread*) PSM(start+tid*sizeof(EEInternalThread)); + if (internal->status != THS_BAD) + { + thread.tid = tid; + thread.data = *internal; + threads.push_back(thread); + } + } + + return threads; +} + diff --git a/pcsx2/DebugTools/BiosDebugData.h b/pcsx2/DebugTools/BiosDebugData.h new file mode 100644 index 0000000000..e0daca58c2 --- /dev/null +++ b/pcsx2/DebugTools/BiosDebugData.h @@ -0,0 +1,50 @@ +#pragma once +#include "Pcsx2Types.h" +#include "../ps2/BiosTools.h" + +struct EEInternalThread { // internal struct + u32 prev; + u32 next; + int status; + u32 entry; + u32 stack; + u32 gpReg; + short currentPriority; + short initPriority; + int waitType; + int semaId; + int wakeupCount; + int attr; + int option; + u32 entry_init; + int argc; + u32 argstring; + u32 stack_bottom; //FIXME + int stackSize; + u32 root; + u32 heap_base; +}; + +enum { + THS_BAD = 0x00, + THS_RUN = 0x01, + THS_READY = 0x02, + THS_WAIT = 0x04, + THS_SUSPEND = 0x08, + THS_WAIT_SUSPEND = 0x0C, + THS_DORMANT = 0x10, +}; + +enum { + WAIT_NONE = 0, + WAIT_WAKEUP_REQ = 1, + WAIT_SEMA = 2, +}; + +struct EEThread +{ + u32 tid; + EEInternalThread data; +}; + +std::vector getEEThreads(); \ No newline at end of file diff --git a/pcsx2/windows/VCprojects/pcsx2.vcxproj b/pcsx2/windows/VCprojects/pcsx2.vcxproj index ae8f19fca2..18f6823584 100644 --- a/pcsx2/windows/VCprojects/pcsx2.vcxproj +++ b/pcsx2/windows/VCprojects/pcsx2.vcxproj @@ -426,6 +426,7 @@ + @@ -712,6 +713,7 @@ + diff --git a/pcsx2/windows/VCprojects/pcsx2.vcxproj.filters b/pcsx2/windows/VCprojects/pcsx2.vcxproj.filters index 32a0e46274..8ebc4642ab 100644 --- a/pcsx2/windows/VCprojects/pcsx2.vcxproj.filters +++ b/pcsx2/windows/VCprojects/pcsx2.vcxproj.filters @@ -820,6 +820,9 @@ System\Ps2\Debug + + System\Ps2\Debug + System\Ps2\Debug @@ -1236,6 +1239,9 @@ System\Ps2\Debug + + System\Ps2\Debug + System\Ps2\Debug diff --git a/pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj b/pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj index 002ebdab4c..26b283f10f 100644 --- a/pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj +++ b/pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj @@ -411,6 +411,7 @@ + @@ -698,6 +699,7 @@ + diff --git a/pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj.filters b/pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj.filters index cfbae94ea9..1153d41a4f 100644 --- a/pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj.filters +++ b/pcsx2/windows/VCprojects/pcsx2_vs2012.vcxproj.filters @@ -835,6 +835,9 @@ System\Ps2\Debug + + System\Ps2\Debug + System\Ps2\Debug @@ -1251,6 +1254,9 @@ System\Ps2\Debug + + System\Ps2\Debug + System\Ps2\Debug diff --git a/pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj b/pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj index fde2077b2a..5f345811a1 100644 --- a/pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj +++ b/pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj @@ -411,6 +411,7 @@ + @@ -698,6 +699,7 @@ + @@ -938,4 +940,4 @@ - + \ No newline at end of file diff --git a/pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj.filters b/pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj.filters index 3eef87385e..ec441c1b3e 100644 --- a/pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj.filters +++ b/pcsx2/windows/VCprojects/pcsx2_vs2013.vcxproj.filters @@ -850,6 +850,9 @@ System\Ps2\Debug + + System\Ps2\Debug + @@ -1263,6 +1266,9 @@ System\Ps2\Debug + + System\Ps2\Debug + @@ -1345,4 +1351,4 @@ AppHost\Resources - + \ No newline at end of file From 1e3e5c92a886b1813be59a9c67ab7df9305d74c8 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Fri, 22 Aug 2014 16:11:16 +0200 Subject: [PATCH 3/3] Add thread list to debugger --- pcsx2/gui/Debugger/DebuggerLists.cpp | 140 +++++++++++++++++++++-- pcsx2/gui/Debugger/DebuggerLists.h | 18 ++- pcsx2/gui/Debugger/DisassemblyDialog.cpp | 11 ++ pcsx2/gui/Debugger/DisassemblyDialog.h | 1 + 4 files changed, 161 insertions(+), 9 deletions(-) diff --git a/pcsx2/gui/Debugger/DebuggerLists.cpp b/pcsx2/gui/Debugger/DebuggerLists.cpp index 29ca5637d0..d9f4651ce8 100644 --- a/pcsx2/gui/Debugger/DebuggerLists.cpp +++ b/pcsx2/gui/Debugger/DebuggerLists.cpp @@ -410,14 +410,6 @@ void BreakpointList::removeBreakpoint(int itemIndex) } } -void BreakpointList::postEvent(wxEventType type, int value) -{ - wxCommandEvent event( type, GetId() ); - event.SetEventObject(this); - event.SetInt(value); - wxPostEvent(this,event); -} - void BreakpointList::onPopupClick(wxCommandEvent& evt) { int index = GetFirstSelected(); @@ -475,3 +467,135 @@ void BreakpointList::onDoubleClick(int itemIndex, const wxPoint& point) { gotoBreakpointAddress(itemIndex); } + + +// +// ThreadList +// + +enum { TL_TID, TL_PROGRAMCOUNTER, TL_ENTRYPOINT, TL_PRIORITY, TL_STATE, TL_WAITTYPE, TL_COLUMNCOUNT }; + +GenericListViewColumn threadColumns[TL_COLUMNCOUNT] = { + { L"TID", 0.08f }, + { L"PC", 0.21f }, + { L"Entry Point", 0.21f }, + { L"Priority", 0.08f }, + { L"State", 0.21f }, + { L"Wait type", 0.21f }, +}; + +ThreadList::ThreadList(wxWindow* parent, DebugInterface* _cpu) + : GenericListView(parent,threadColumns,TL_COLUMNCOUNT), cpu(_cpu) +{ +#ifdef __linux__ + // On linux wx failed to resize properly the page. I don't know why so for the moment I just create a static size page + // Far from ideal but at least I can use the memory window! + this->SetSize(wxSize(1000, 200)); +#endif +} + +void ThreadList::reloadThreads() +{ + threads = getEEThreads(); + update(); +} + + +int ThreadList::getRowCount() +{ + return threads.size(); +} + +wxString ThreadList::getColumnText(int item, int col) const +{ + if (item < 0 || item >= (int)threads.size()) + return L""; + + FastFormatUnicode dest; + const EEThread& thread = threads[item]; + + switch (col) + { + case TL_TID: + dest.Write("%d",thread.tid); + break; + case TL_PROGRAMCOUNTER: + if (thread.data.status == THS_RUN) + dest.Write("0x%08X", cpu->getPC()); + else + dest.Write("0x%08X", thread.data.entry); + break; + case TL_ENTRYPOINT: + dest.Write("0x%08X", thread.data.entry_init); + break; + case TL_PRIORITY: + dest.Write("0x%02X", thread.data.currentPriority); + break; + case TL_STATE: + switch (thread.data.status) + { + case THS_BAD: + dest.Write("Bad"); + break; + case THS_RUN: + dest.Write("Running"); + break; + case THS_READY: + dest.Write("Ready"); + break; + case THS_WAIT: + dest.Write("Waiting"); + break; + case THS_SUSPEND: + dest.Write("Suspended"); + break; + case THS_WAIT_SUSPEND: + dest.Write("Waiting/Suspended"); + break; + case THS_DORMANT: + dest.Write("Dormant"); + break; + } + break; + case TL_WAITTYPE: + switch (thread.data.waitType) + { + case WAIT_NONE: + dest.Write("None"); + break; + case WAIT_WAKEUP_REQ: + dest.Write("Wakeup request"); + break; + case WAIT_SEMA: + dest.Write("Semaphore"); + break; + } + break; + default: + return L"Invalid"; + } + + return dest; +} + +void ThreadList::onDoubleClick(int itemIndex, const wxPoint& point) +{ + if (itemIndex < 0 || itemIndex >= (int)threads.size()) + return; + + const EEThread& thread = threads[itemIndex]; + + switch (thread.data.status) + { + case THS_DORMANT: + case THS_BAD: + postEvent(debEVT_GOTOINDISASM,thread.data.entry_init); + break; + case THS_RUN: + postEvent(debEVT_GOTOINDISASM,cpu->getPC()); + break; + default: + postEvent(debEVT_GOTOINDISASM,thread.data.entry); + break; + } +} \ No newline at end of file diff --git a/pcsx2/gui/Debugger/DebuggerLists.h b/pcsx2/gui/Debugger/DebuggerLists.h index 1ac1bac1f4..f48320df9e 100644 --- a/pcsx2/gui/Debugger/DebuggerLists.h +++ b/pcsx2/gui/Debugger/DebuggerLists.h @@ -17,6 +17,7 @@ #include #include "DebugTools/DebugInterface.h" #include "DebugTools/Breakpoints.h" +#include "DebugTools/BiosDebugData.h" #include "CtrlDisassemblyView.h" struct GenericListViewColumn @@ -74,7 +75,6 @@ private: void toggleEnabled(int itemIndex); void gotoBreakpointAddress(int itemIndex); void removeBreakpoint(int itemIndex); - void postEvent(wxEventType type, int value); void showMenu(const wxPoint& pos); std::vector displayedBreakPoints_; @@ -82,3 +82,19 @@ private: DebugInterface* cpu; CtrlDisassemblyView* disasm; }; + +class ThreadList: public GenericListView +{ +public: + ThreadList(wxWindow* parent, DebugInterface* _cpu); + void reloadThreads(); +protected: + void onPopupClick(wxCommandEvent& evt); + + virtual wxString getColumnText(int row, int col) const; + virtual int getRowCount(); + virtual void onDoubleClick(int itemIndex, const wxPoint& point); +private: + DebugInterface* cpu; + std::vector threads; +}; diff --git a/pcsx2/gui/Debugger/DisassemblyDialog.cpp b/pcsx2/gui/Debugger/DisassemblyDialog.cpp index 768886d6cb..f5ec5ddc87 100644 --- a/pcsx2/gui/Debugger/DisassemblyDialog.cpp +++ b/pcsx2/gui/Debugger/DisassemblyDialog.cpp @@ -107,6 +107,13 @@ CpuTabPage::CpuTabPage(wxWindow* parent, DebugInterface* _cpu) breakpointList = new BreakpointList(bottomTabs,cpu,disassembly); bottomTabs->AddPage(breakpointList,L"Breakpoints"); + + threadList = NULL; + if (cpu == &r5900Debug) + { + threadList = new ThreadList(bottomTabs,cpu); + bottomTabs->AddPage(threadList,L"Threads"); + } mainSizer->Add(bottomTabs,1,wxEXPAND); @@ -162,6 +169,10 @@ void CpuTabPage::setBottomTabPage(wxWindow* win) void CpuTabPage::update() { breakpointList->reloadBreakpoints(); + + if (threadList != NULL) + threadList->reloadThreads(); + Refresh(); } diff --git a/pcsx2/gui/Debugger/DisassemblyDialog.h b/pcsx2/gui/Debugger/DisassemblyDialog.h index aab77a9e2f..4484daa209 100644 --- a/pcsx2/gui/Debugger/DisassemblyDialog.h +++ b/pcsx2/gui/Debugger/DisassemblyDialog.h @@ -59,6 +59,7 @@ private: wxNotebook* leftTabs; BreakpointList* breakpointList; wxStaticText* cyclesText; + ThreadList* threadList; u32 lastCycles; };