Skip to content

Commit 47f1dcf

Browse files
committed
debugger: Add symbol support to PPC stack traces
Also moved the declaration to precompiled.h instead of redefining it wherever it is used
1 parent 2524299 commit 47f1dcf

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

src/Cafe/HW/Espresso/Debugger/Debugger.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,6 @@ void debugger_createPPCStateSnapshot(PPCInterpreter_t* hCPU)
501501
debuggerState.debugSession.ppcSnapshot.cr[i] = hCPU->cr[i];
502502
}
503503

504-
void DebugLogStackTrace(OSThread_t* thread, MPTR sp);
505-
506504
void debugger_enterTW(PPCInterpreter_t* hCPU)
507505
{
508506
// handle logging points

src/Cafe/OS/libs/coreinit/coreinit.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Cafe/OS/common/OSCommon.h"
22
#include "Common/SysAllocator.h"
3-
#include "Cafe/OS/RPL/rpl.h"
3+
#include "Cafe/OS/RPL/rpl_symbol_storage.h"
44

55
#include "Cafe/OS/libs/coreinit/coreinit_Misc.h"
66

@@ -69,7 +69,7 @@ sint32 ScoreStackTrace(OSThread_t* thread, MPTR sp)
6969
return score;
7070
}
7171

72-
void DebugLogStackTrace(OSThread_t* thread, MPTR sp)
72+
void DebugLogStackTrace(OSThread_t* thread, MPTR sp, bool printSymbols)
7373
{
7474
// sp might not point to a valid stackframe
7575
// scan stack and evaluate which sp is most likely the beginning of the stackframe
@@ -107,7 +107,15 @@ void DebugLogStackTrace(OSThread_t* thread, MPTR sp)
107107

108108
uint32 returnAddress = 0;
109109
returnAddress = memory_readU32(nextStackPtr + 4);
110-
cemuLog_log(LogType::Force, fmt::format("SP {0:08x} ReturnAddr {1:08x}", nextStackPtr, returnAddress));
110+
111+
RPLStoredSymbol* symbol = nullptr;
112+
if(printSymbols)
113+
symbol = rplSymbolStorage_getByClosestAddress(returnAddress);
114+
115+
if(symbol)
116+
cemuLog_log(LogType::Force, fmt::format("SP {:08x} ReturnAddr {:08x} ({}.{}+0x{:x})", nextStackPtr, returnAddress, (const char*)symbol->libName, (const char*)symbol->symbolName, returnAddress - symbol->address));
117+
else
118+
cemuLog_log(LogType::Force, fmt::format("SP {:08x} ReturnAddr {:08x}", nextStackPtr, returnAddress));
111119

112120
currentStackPtr = nextStackPtr;
113121
}

src/Cafe/OS/libs/coreinit/coreinit_MEM_ExpHeap.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#include "Cafe/HW/Espresso/PPCCallback.h"
33
#include "Cafe/OS/libs/coreinit/coreinit_MEM_ExpHeap.h"
44

5-
void DebugLogStackTrace(OSThread_t* thread, MPTR sp);
6-
75
#define EXP_HEAP_GET_FROM_FREE_BLOCKCHAIN(__blockchain__) (MEMExpHeapHead2*)((uintptr_t)__blockchain__ - offsetof(MEMExpHeapHead2, expHeapHead) - offsetof(MEMExpHeapHead40_t, chainFreeBlocks))
86

97
namespace coreinit

src/Common/ExceptionHandler/ExceptionHandler.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#include "Cafe/HW/Espresso/Debugger/GDBStub.h"
77
#include "ExceptionHandler.h"
88

9-
void DebugLogStackTrace(OSThread_t* thread, MPTR sp);
10-
119
bool crashLogCreated = false;
1210

1311
bool CrashLog_Create()
@@ -97,7 +95,7 @@ void ExceptionHandler_LogGeneralInfo()
9795
MPTR currentStackVAddr = hCPU->gpr[1];
9896
CrashLog_WriteLine("");
9997
CrashLog_WriteHeader("PPC stack trace");
100-
DebugLogStackTrace(currentThread, currentStackVAddr);
98+
DebugLogStackTrace(currentThread, currentStackVAddr, true);
10199

102100
// stack dump
103101
CrashLog_WriteLine("");

src/Common/precompiled.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ inline uint32 GetTitleIdLow(uint64 titleId)
552552
#include "Cafe/HW/Espresso/PPCState.h"
553553
#include "Cafe/HW/Espresso/PPCCallback.h"
554554

555+
// PPC stack trace printer
556+
void DebugLogStackTrace(struct OSThread_t* thread, MPTR sp, bool printSymbols = false);
557+
555558
// generic formatter for enums (to underlying)
556559
template <typename Enum>
557560
requires std::is_enum_v<Enum>

src/gui/windows/PPCThreadsViewer/DebugPPCThreadsWindow.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,10 @@ void DebugPPCThreadsWindow::RefreshThreadList()
277277
m_thread_list->SetScrollPos(0, scrollPos, true);
278278
}
279279

280-
void DebugLogStackTrace(OSThread_t* thread, MPTR sp);
281-
282280
void DebugPPCThreadsWindow::DumpStackTrace(OSThread_t* thread)
283281
{
284282
cemuLog_log(LogType::Force, "Dumping stack trace for thread {0:08x} LR: {1:08x}", memory_getVirtualOffsetFromPointer(thread), _swapEndianU32(thread->context.lr));
285-
DebugLogStackTrace(thread, _swapEndianU32(thread->context.gpr[1]));
283+
DebugLogStackTrace(thread, _swapEndianU32(thread->context.gpr[1]), true);
286284
}
287285

288286
void DebugPPCThreadsWindow::PresentProfileResults(OSThread_t* thread, const std::unordered_map<VAddr, uint32>& samples)

0 commit comments

Comments
 (0)