pineapple/src/core/arm/arm_interface.cpp

93 lines
3.1 KiB
C++
Raw Normal View History

2020-12-28 16:15:37 +01:00
// Copyright 2018 yuzu emulator team
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <map>
#include <optional>
#include "common/bit_field.h"
#include "common/common_types.h"
#include "common/logging/log.h"
#include "core/arm/arm_interface.h"
2022-04-11 19:42:37 +02:00
#include "core/arm/symbols.h"
2020-12-28 16:15:37 +01:00
#include "core/core.h"
2022-04-11 19:42:37 +02:00
#include "core/hle/kernel/k_process.h"
2020-12-28 16:15:37 +01:00
#include "core/loader/loader.h"
#include "core/memory.h"
2022-04-21 09:44:37 +02:00
#include "core/arm/dynarmic/arm_dynarmic_32.h"
#include "core/arm/dynarmic/arm_dynarmic_64.h"
2020-12-28 16:15:37 +01:00
namespace Core {
constexpr u64 SEGMENT_BASE = 0x7100000000ull;
std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktraceFromContext(
2022-04-21 09:44:37 +02:00
Core::System& system, const ARM_Interface::ThreadContext32& ctx) {
return ARM_Dynarmic_32::GetBacktraceFromContext(system, ctx);
2020-12-28 16:15:37 +01:00
}
2022-04-21 09:44:37 +02:00
std::vector<ARM_Interface::BacktraceEntry> ARM_Interface::GetBacktraceFromContext(
Core::System& system, const ARM_Interface::ThreadContext64& ctx) {
return ARM_Dynarmic_64::GetBacktraceFromContext(system, ctx);
}
2020-12-28 16:15:37 +01:00
2022-04-21 09:44:37 +02:00
void ARM_Interface::SymbolicateBacktrace(Core::System& system, std::vector<BacktraceEntry>& out) {
2020-12-28 16:15:37 +01:00
std::map<VAddr, std::string> modules;
auto& loader{system.GetAppLoader()};
if (loader.ReadNSOModules(modules) != Loader::ResultStatus::Success) {
2022-04-21 09:44:37 +02:00
return;
2020-12-28 16:15:37 +01:00
}
2022-04-11 19:42:37 +02:00
std::map<std::string, Symbols::Symbols> symbols;
2020-12-28 16:15:37 +01:00
for (const auto& module : modules) {
2022-04-11 19:42:37 +02:00
symbols.insert_or_assign(module.second,
Symbols::GetSymbols(module.first, system.Memory(),
system.CurrentProcess()->Is64BitProcess()));
2020-12-28 16:15:37 +01:00
}
for (auto& entry : out) {
VAddr base = 0;
for (auto iter = modules.rbegin(); iter != modules.rend(); ++iter) {
const auto& module{*iter};
if (entry.original_address >= module.first) {
entry.module = module.second;
base = module.first;
break;
}
}
entry.offset = entry.original_address - base;
entry.address = SEGMENT_BASE + entry.offset;
2022-04-21 09:44:37 +02:00
if (entry.module.empty()) {
2020-12-28 16:15:37 +01:00
entry.module = "unknown";
2022-04-21 09:44:37 +02:00
}
2020-12-28 16:15:37 +01:00
const auto symbol_set = symbols.find(entry.module);
if (symbol_set != symbols.end()) {
2022-04-11 19:42:37 +02:00
const auto symbol = Symbols::GetSymbolName(symbol_set->second, entry.offset);
2020-12-28 16:15:37 +01:00
if (symbol.has_value()) {
// TODO(DarkLordZach): Add demangling of symbol names.
entry.name = *symbol;
}
}
}
}
void ARM_Interface::LogBacktrace() const {
2022-04-21 09:44:37 +02:00
const VAddr sp = GetSP();
2020-12-28 16:15:37 +01:00
const VAddr pc = GetPC();
LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc);
LOG_ERROR(Core_ARM, "{:20}{:20}{:20}{:20}{}", "Module Name", "Address", "Original Address",
"Offset", "Symbol");
LOG_ERROR(Core_ARM, "");
const auto backtrace = GetBacktrace();
for (const auto& entry : backtrace) {
LOG_ERROR(Core_ARM, "{:20}{:016X} {:016X} {:016X} {}", entry.module, entry.address,
entry.original_address, entry.offset, entry.name);
}
}
} // namespace Core