debugger: Add symbol support to PPC stack traces

Also moved the declaration to precompiled.h instead of redefining it wherever it is used
This commit is contained in:
Exzap 2024-07-26 05:08:38 +02:00
parent 252429933f
commit 47f1dcf996
6 changed files with 16 additions and 13 deletions

View File

@ -501,8 +501,6 @@ void debugger_createPPCStateSnapshot(PPCInterpreter_t* hCPU)
debuggerState.debugSession.ppcSnapshot.cr[i] = hCPU->cr[i];
}
void DebugLogStackTrace(OSThread_t* thread, MPTR sp);
void debugger_enterTW(PPCInterpreter_t* hCPU)
{
// handle logging points

View File

@ -1,6 +1,6 @@
#include "Cafe/OS/common/OSCommon.h"
#include "Common/SysAllocator.h"
#include "Cafe/OS/RPL/rpl.h"
#include "Cafe/OS/RPL/rpl_symbol_storage.h"
#include "Cafe/OS/libs/coreinit/coreinit_Misc.h"
@ -69,7 +69,7 @@ sint32 ScoreStackTrace(OSThread_t* thread, MPTR sp)
return score;
}
void DebugLogStackTrace(OSThread_t* thread, MPTR sp)
void DebugLogStackTrace(OSThread_t* thread, MPTR sp, bool printSymbols)
{
// sp might not point to a valid stackframe
// 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)
uint32 returnAddress = 0;
returnAddress = memory_readU32(nextStackPtr + 4);
cemuLog_log(LogType::Force, fmt::format("SP {0:08x} ReturnAddr {1:08x}", nextStackPtr, returnAddress));
RPLStoredSymbol* symbol = nullptr;
if(printSymbols)
symbol = rplSymbolStorage_getByClosestAddress(returnAddress);
if(symbol)
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));
else
cemuLog_log(LogType::Force, fmt::format("SP {:08x} ReturnAddr {:08x}", nextStackPtr, returnAddress));
currentStackPtr = nextStackPtr;
}

View File

@ -2,8 +2,6 @@
#include "Cafe/HW/Espresso/PPCCallback.h"
#include "Cafe/OS/libs/coreinit/coreinit_MEM_ExpHeap.h"
void DebugLogStackTrace(OSThread_t* thread, MPTR sp);
#define EXP_HEAP_GET_FROM_FREE_BLOCKCHAIN(__blockchain__) (MEMExpHeapHead2*)((uintptr_t)__blockchain__ - offsetof(MEMExpHeapHead2, expHeapHead) - offsetof(MEMExpHeapHead40_t, chainFreeBlocks))
namespace coreinit

View File

@ -6,8 +6,6 @@
#include "Cafe/HW/Espresso/Debugger/GDBStub.h"
#include "ExceptionHandler.h"
void DebugLogStackTrace(OSThread_t* thread, MPTR sp);
bool crashLogCreated = false;
bool CrashLog_Create()
@ -97,7 +95,7 @@ void ExceptionHandler_LogGeneralInfo()
MPTR currentStackVAddr = hCPU->gpr[1];
CrashLog_WriteLine("");
CrashLog_WriteHeader("PPC stack trace");
DebugLogStackTrace(currentThread, currentStackVAddr);
DebugLogStackTrace(currentThread, currentStackVAddr, true);
// stack dump
CrashLog_WriteLine("");

View File

@ -552,6 +552,9 @@ inline uint32 GetTitleIdLow(uint64 titleId)
#include "Cafe/HW/Espresso/PPCState.h"
#include "Cafe/HW/Espresso/PPCCallback.h"
// PPC stack trace printer
void DebugLogStackTrace(struct OSThread_t* thread, MPTR sp, bool printSymbols = false);
// generic formatter for enums (to underlying)
template <typename Enum>
requires std::is_enum_v<Enum>

View File

@ -277,12 +277,10 @@ void DebugPPCThreadsWindow::RefreshThreadList()
m_thread_list->SetScrollPos(0, scrollPos, true);
}
void DebugLogStackTrace(OSThread_t* thread, MPTR sp);
void DebugPPCThreadsWindow::DumpStackTrace(OSThread_t* thread)
{
cemuLog_log(LogType::Force, "Dumping stack trace for thread {0:08x} LR: {1:08x}", memory_getVirtualOffsetFromPointer(thread), _swapEndianU32(thread->context.lr));
DebugLogStackTrace(thread, _swapEndianU32(thread->context.gpr[1]));
DebugLogStackTrace(thread, _swapEndianU32(thread->context.gpr[1]), true);
}
void DebugPPCThreadsWindow::PresentProfileResults(OSThread_t* thread, const std::unordered_map<VAddr, uint32>& samples)