Skip to content

Commit

Permalink
Merge pull request #12444 from lioncash/map
Browse files Browse the repository at this point in the history
Core/Debugger_SymbolMap: Minor interface cleanup
  • Loading branch information
Tilka committed Dec 18, 2023
2 parents c188dc2 + 472c65e commit 0cab658
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 53 deletions.
63 changes: 23 additions & 40 deletions Source/Core/Core/Debugger/Debugger_SymbolMap.cpp
Expand Up @@ -20,34 +20,16 @@

namespace Dolphin_Debugger
{
void AddAutoBreakpoints()
{
#if defined(_DEBUG) || defined(DEBUGFAST)
#if 1
const char* bps[] = {
"PPCHalt",
};

for (const char* bp : bps)
{
Common::Symbol* symbol = g_symbolDB.GetSymbolFromName(bp);
if (symbol)
Core::System::GetInstance().GetPowerPC().GetBreakPoints().Add(symbol->address, false);
}
#endif
#endif
}

// Returns true if the address is not a valid RAM address or NULL.
static bool IsStackBottom(const Core::CPUThreadGuard& guard, u32 addr)
{
return !addr || !PowerPC::MMU::HostIsRAMAddress(guard, addr);
}

static void WalkTheStack(Core::System& system, const Core::CPUThreadGuard& guard,
static void WalkTheStack(const Core::CPUThreadGuard& guard,
const std::function<void(u32)>& stack_step)
{
auto& ppc_state = system.GetPPCState();
const auto& ppc_state = guard.GetSystem().GetPPCState();

if (!IsStackBottom(guard, ppc_state.gpr[1]))
{
Expand All @@ -70,45 +52,46 @@ static void WalkTheStack(Core::System& system, const Core::CPUThreadGuard& guard
// Returns callstack "formatted for debugging" - meaning that it
// includes LR as the last item, and all items are the last step,
// instead of "pointing ahead"
bool GetCallstack(Core::System& system, const Core::CPUThreadGuard& guard,
std::vector<CallstackEntry>& output)
bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector<CallstackEntry>& output)
{
auto& ppc_state = system.GetPPCState();
const auto& ppc_state = guard.GetSystem().GetPPCState();

if (!Core::IsRunning() || !PowerPC::MMU::HostIsRAMAddress(guard, ppc_state.gpr[1]))
return false;

if (LR(ppc_state) == 0)
{
CallstackEntry entry;
entry.Name = "(error: LR=0)";
entry.vAddress = 0x0;
output.push_back(entry);
output.push_back({
.Name = "(error: LR=0)",
.vAddress = 0,
});
return false;
}

CallstackEntry entry;
entry.Name = fmt::format(" * {} [ LR = {:08x} ]\n", g_symbolDB.GetDescription(LR(ppc_state)),
LR(ppc_state) - 4);
entry.vAddress = LR(ppc_state) - 4;
output.push_back(entry);
output.push_back({
.Name = fmt::format(" * {} [ LR = {:08x} ]\n", g_symbolDB.GetDescription(LR(ppc_state)),
LR(ppc_state) - 4),
.vAddress = LR(ppc_state) - 4,
});

WalkTheStack(system, guard, [&entry, &output](u32 func_addr) {
WalkTheStack(guard, [&output](u32 func_addr) {
std::string func_desc = g_symbolDB.GetDescription(func_addr);
if (func_desc.empty() || func_desc == "Invalid")
func_desc = "(unknown)";
entry.Name = fmt::format(" * {} [ addr = {:08x} ]\n", func_desc, func_addr - 4);
entry.vAddress = func_addr - 4;
output.push_back(entry);

output.push_back({
.Name = fmt::format(" * {} [ addr = {:08x} ]\n", func_desc, func_addr - 4),
.vAddress = func_addr - 4,
});
});

return true;
}

void PrintCallstack(Core::System& system, const Core::CPUThreadGuard& guard,
Common::Log::LogType type, Common::Log::LogLevel level)
void PrintCallstack(const Core::CPUThreadGuard& guard, Common::Log::LogType type,
Common::Log::LogLevel level)
{
auto& ppc_state = system.GetPPCState();
const auto& ppc_state = guard.GetSystem().GetPPCState();

GENERIC_LOG_FMT(type, level, "== STACK TRACE - SP = {:08x} ==", ppc_state.gpr[1]);

Expand All @@ -123,7 +106,7 @@ void PrintCallstack(Core::System& system, const Core::CPUThreadGuard& guard,
LR(ppc_state));
}

WalkTheStack(system, guard, [type, level](u32 func_addr) {
WalkTheStack(guard, [type, level](u32 func_addr) {
std::string func_desc = g_symbolDB.GetDescription(func_addr);
if (func_desc.empty() || func_desc == "Invalid")
func_desc = "(unknown)";
Expand Down
12 changes: 4 additions & 8 deletions Source/Core/Core/Debugger/Debugger_SymbolMap.h
Expand Up @@ -13,8 +13,7 @@
namespace Core
{
class CPUThreadGuard;
class System;
} // namespace Core
}

namespace Dolphin_Debugger
{
Expand All @@ -24,12 +23,9 @@ struct CallstackEntry
u32 vAddress = 0;
};

bool GetCallstack(Core::System& system, const Core::CPUThreadGuard& guard,
std::vector<CallstackEntry>& output);
void PrintCallstack(Core::System& system, const Core::CPUThreadGuard& guard,
Common::Log::LogType type, Common::Log::LogLevel level);
bool GetCallstack(const Core::CPUThreadGuard& guard, std::vector<CallstackEntry>& output);
void PrintCallstack(const Core::CPUThreadGuard& guard, Common::Log::LogType type,
Common::Log::LogLevel level);
void PrintDataBuffer(Common::Log::LogType type, const u8* data, size_t size,
std::string_view title);
void AddAutoBreakpoints();

} // namespace Dolphin_Debugger
5 changes: 2 additions & 3 deletions Source/Core/Core/PowerPC/Expression.cpp
Expand Up @@ -115,9 +115,8 @@ static double CallstackFunc(expr_func* f, vec_expr_t* args, void* c)

std::vector<Dolphin_Debugger::CallstackEntry> stack;
{
auto& system = Core::System::GetInstance();
Core::CPUThreadGuard guard(system);
bool success = Dolphin_Debugger::GetCallstack(system, guard, stack);
Core::CPUThreadGuard guard(Core::System::GetInstance());
const bool success = Dolphin_Debugger::GetCallstack(guard, stack);
if (!success)
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/PowerPC/Interpreter/Interpreter.cpp
Expand Up @@ -323,7 +323,7 @@ void Interpreter::unknown_instruction(Interpreter& interpreter, UGeckoInstructio
const u32 opcode = PowerPC::MMU::HostRead_U32(guard, last_pc);
const std::string disasm = Common::GekkoDisassembler::Disassemble(opcode, last_pc);
NOTICE_LOG_FMT(POWERPC, "Last PC = {:08x} : {}", last_pc, disasm);
Dolphin_Debugger::PrintCallstack(system, guard, Common::Log::LogType::POWERPC,
Dolphin_Debugger::PrintCallstack(guard, Common::Log::LogType::POWERPC,
Common::Log::LogLevel::LNOTICE);

const auto& ppc_state = interpreter.m_ppc_state;
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/DolphinQt/Debugger/CodeWidget.cpp
Expand Up @@ -344,7 +344,7 @@ void CodeWidget::UpdateCallstack()

const bool success = [this, &stack] {
Core::CPUThreadGuard guard(m_system);
return Dolphin_Debugger::GetCallstack(m_system, guard, stack);
return Dolphin_Debugger::GetCallstack(guard, stack);
}();

if (!success)
Expand Down

0 comments on commit 0cab658

Please sign in to comment.