From 71493327121038696c887158cb34f94e2f225e0f Mon Sep 17 00:00:00 2001 From: David Marcec Date: Mon, 3 Dec 2018 19:12:09 +1100 Subject: Print backtrace on svcBreak When we get an svcBreak we get a backtrace now --- src/core/hle/kernel/svc.cpp | 2 ++ src/core/hle/kernel/thread.cpp | 17 +++++++++++++++++ src/core/hle/kernel/thread.h | 5 +++++ 3 files changed, 24 insertions(+) (limited to 'src') diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 3339777c1..2273f0bcf 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -625,6 +625,8 @@ static void Break(u32 reason, u64 info1, u64 info2) { "Emulated program broke execution! reason=0x{:016X}, info1=0x{:016X}, info2=0x{:016X}", reason, info1, info2); handle_debug_buffer(info1, info2); + GetCurrentThread()->LogBacktrace(); + ASSERT(false); Core::CurrentProcess()->PrepareForTermination(); diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 4ffb76818..a044db6e7 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -388,6 +388,23 @@ bool Thread::InvokeWakeupCallback(ThreadWakeupReason reason, SharedPtr t return wakeup_callback(reason, std::move(thread), std::move(object), index); } +void Thread::LogBacktrace() { + auto& system = Core::System::GetInstance(); + VAddr fp = system.ArmInterface(processor_id).GetReg(29); + VAddr lr = system.ArmInterface(processor_id).GetReg(30); + VAddr sp = system.ArmInterface(processor_id).GetReg(13); + VAddr pc = system.ArmInterface(processor_id).GetPC(); + LOG_ERROR(Debug, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); + for (std::size_t i = 0; i < 256; i++) { + LOG_ERROR(Debug, "{:016X}", lr - 4); + if (!fp) { + break; + } + lr = Memory::Read64(fp + 8); + fp = Memory::Read64(fp); + } +} + //////////////////////////////////////////////////////////////////////////////////////////////////// /** diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index d384d50db..469f8a56d 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -240,6 +240,11 @@ public: return status == ThreadStatus::WaitSynchAll; } + /** + * Logs the backtrace for the current thread + */ + void LogBacktrace(); + ThreadContext& GetContext() { return context; } -- cgit v1.2.3 From 5102c912569a29259ec26aa254d4598e81205a17 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Mon, 3 Dec 2018 20:13:48 +1100 Subject: Moved backtrace to ArmInterface Added to both dynarmic and unicorn --- src/core/arm/arm_interface.h | 2 ++ src/core/arm/dynarmic/arm_dynarmic.cpp | 16 ++++++++++++++++ src/core/arm/dynarmic/arm_dynarmic.h | 2 ++ src/core/arm/unicorn/arm_unicorn.cpp | 17 +++++++++++++++++ src/core/arm/unicorn/arm_unicorn.h | 1 + src/core/hle/kernel/thread.cpp | 15 +-------------- 6 files changed, 39 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index 59da33f30..26fe68a2e 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -141,6 +141,8 @@ public: /// Prepare core for thread reschedule (if needed to correctly handle state) virtual void PrepareReschedule() = 0; + + virtual void LogBacktrace() = 0; }; } // namespace Core diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 4d2491870..47dadba91 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -278,6 +278,22 @@ void ARM_Dynarmic::PageTableChanged() { current_page_table = Memory::GetCurrentPageTable(); } +void ARM_Dynarmic::LogBacktrace() { + VAddr fp = GetReg(29); + VAddr lr = GetReg(30); + VAddr sp = GetReg(13); + VAddr pc = GetPC(); + LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); + for (;;) { + LOG_ERROR(Core_ARM, "{:016X}", lr); + if (!fp) { + break; + } + lr = Memory::Read64(fp + 8) - 4; + fp = Memory::Read64(fp); + } +} + DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(std::size_t core_count) : monitor(core_count) {} DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default; diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index 512bf8ce9..791653233 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -53,6 +53,8 @@ public: void ClearInstructionCache() override; void PageTableChanged() override; + void LogBacktrace() override; + private: std::unique_ptr MakeJit() const; diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index ded4dd359..c9495124e 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp @@ -10,6 +10,7 @@ #include "core/core.h" #include "core/core_timing.h" #include "core/hle/kernel/svc.h" +#include "core/memory.h" namespace Core { @@ -266,6 +267,22 @@ void ARM_Unicorn::ClearExclusiveState() {} void ARM_Unicorn::ClearInstructionCache() {} +void ARM_Unicorn::LogBacktrace() { + VAddr fp = GetReg(29); + VAddr lr = GetReg(30); + VAddr sp = GetReg(13); + VAddr pc = GetPC(); + LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); + for (;;) { + LOG_ERROR(Core_ARM, "{:016X}", lr); + if (!fp) { + break; + } + lr = Memory::Read64(fp + 8) - 4; + fp = Memory::Read64(fp); + } +} + void ARM_Unicorn::RecordBreak(GDBStub::BreakpointAddress bkpt) { last_bkpt = bkpt; last_bkpt_hit = true; diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h index 75761950b..41da6a73c 100644 --- a/src/core/arm/unicorn/arm_unicorn.h +++ b/src/core/arm/unicorn/arm_unicorn.h @@ -40,6 +40,7 @@ public: void ClearInstructionCache() override; void PageTableChanged() override{}; void RecordBreak(GDBStub::BreakpointAddress bkpt); + void LogBacktrace() override; private: uc_engine* uc{}; diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index a044db6e7..a276812f0 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -389,20 +389,7 @@ bool Thread::InvokeWakeupCallback(ThreadWakeupReason reason, SharedPtr t } void Thread::LogBacktrace() { - auto& system = Core::System::GetInstance(); - VAddr fp = system.ArmInterface(processor_id).GetReg(29); - VAddr lr = system.ArmInterface(processor_id).GetReg(30); - VAddr sp = system.ArmInterface(processor_id).GetReg(13); - VAddr pc = system.ArmInterface(processor_id).GetPC(); - LOG_ERROR(Debug, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); - for (std::size_t i = 0; i < 256; i++) { - LOG_ERROR(Debug, "{:016X}", lr - 4); - if (!fp) { - break; - } - lr = Memory::Read64(fp + 8); - fp = Memory::Read64(fp); - } + Core::System::GetInstance().ArmInterface(processor_id).LogBacktrace(); } //////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 08d5663cb8989f6e57cc28e02c572367685d69fd Mon Sep 17 00:00:00 2001 From: David Marcec Date: Wed, 19 Dec 2018 14:10:51 +1100 Subject: Moved backtrace to ArmInterface --- src/core/arm/arm_interface.h | 18 +++++++++++++++++- src/core/arm/dynarmic/arm_dynarmic.cpp | 16 ---------------- src/core/arm/dynarmic/arm_dynarmic.h | 2 -- src/core/arm/unicorn/arm_unicorn.cpp | 16 ---------------- src/core/arm/unicorn/arm_unicorn.h | 1 - src/core/hle/kernel/svc.cpp | 5 +++-- src/core/hle/kernel/thread.cpp | 4 ---- src/core/hle/kernel/thread.h | 5 ----- 8 files changed, 20 insertions(+), 47 deletions(-) (limited to 'src') diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index 26fe68a2e..b0472d55d 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -6,6 +6,8 @@ #include #include "common/common_types.h" +#include "common/logging/log.h" +#include "core/memory.h" namespace Kernel { enum class VMAPermission : u8; @@ -142,7 +144,21 @@ public: /// Prepare core for thread reschedule (if needed to correctly handle state) virtual void PrepareReschedule() = 0; - virtual void LogBacktrace() = 0; + void LogBacktrace() { + VAddr fp = GetReg(29); + VAddr lr = GetReg(30); + VAddr sp = GetReg(13); + VAddr pc = GetPC(); + LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); + for (;;) { + LOG_ERROR(Core_ARM, "{:016X}", lr); + if (!fp) { + break; + } + lr = Memory::Read64(fp + 8) - 4; + fp = Memory::Read64(fp); + } + } }; } // namespace Core diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 47dadba91..4d2491870 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp @@ -278,22 +278,6 @@ void ARM_Dynarmic::PageTableChanged() { current_page_table = Memory::GetCurrentPageTable(); } -void ARM_Dynarmic::LogBacktrace() { - VAddr fp = GetReg(29); - VAddr lr = GetReg(30); - VAddr sp = GetReg(13); - VAddr pc = GetPC(); - LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); - for (;;) { - LOG_ERROR(Core_ARM, "{:016X}", lr); - if (!fp) { - break; - } - lr = Memory::Read64(fp + 8) - 4; - fp = Memory::Read64(fp); - } -} - DynarmicExclusiveMonitor::DynarmicExclusiveMonitor(std::size_t core_count) : monitor(core_count) {} DynarmicExclusiveMonitor::~DynarmicExclusiveMonitor() = default; diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index 791653233..512bf8ce9 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h @@ -53,8 +53,6 @@ public: void ClearInstructionCache() override; void PageTableChanged() override; - void LogBacktrace() override; - private: std::unique_ptr MakeJit() const; diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index c9495124e..c455c81fb 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp @@ -267,22 +267,6 @@ void ARM_Unicorn::ClearExclusiveState() {} void ARM_Unicorn::ClearInstructionCache() {} -void ARM_Unicorn::LogBacktrace() { - VAddr fp = GetReg(29); - VAddr lr = GetReg(30); - VAddr sp = GetReg(13); - VAddr pc = GetPC(); - LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); - for (;;) { - LOG_ERROR(Core_ARM, "{:016X}", lr); - if (!fp) { - break; - } - lr = Memory::Read64(fp + 8) - 4; - fp = Memory::Read64(fp); - } -} - void ARM_Unicorn::RecordBreak(GDBStub::BreakpointAddress bkpt) { last_bkpt = bkpt; last_bkpt_hit = true; diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h index 41da6a73c..75761950b 100644 --- a/src/core/arm/unicorn/arm_unicorn.h +++ b/src/core/arm/unicorn/arm_unicorn.h @@ -40,7 +40,6 @@ public: void ClearInstructionCache() override; void PageTableChanged() override{}; void RecordBreak(GDBStub::BreakpointAddress bkpt); - void LogBacktrace() override; private: uc_engine* uc{}; diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp index 2273f0bcf..290670e78 100644 --- a/src/core/hle/kernel/svc.cpp +++ b/src/core/hle/kernel/svc.cpp @@ -625,8 +625,9 @@ static void Break(u32 reason, u64 info1, u64 info2) { "Emulated program broke execution! reason=0x{:016X}, info1=0x{:016X}, info2=0x{:016X}", reason, info1, info2); handle_debug_buffer(info1, info2); - GetCurrentThread()->LogBacktrace(); - + Core::System::GetInstance() + .ArmInterface(static_cast(GetCurrentThread()->GetProcessorID())) + .LogBacktrace(); ASSERT(false); Core::CurrentProcess()->PrepareForTermination(); diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index a276812f0..4ffb76818 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp @@ -388,10 +388,6 @@ bool Thread::InvokeWakeupCallback(ThreadWakeupReason reason, SharedPtr t return wakeup_callback(reason, std::move(thread), std::move(object), index); } -void Thread::LogBacktrace() { - Core::System::GetInstance().ArmInterface(processor_id).LogBacktrace(); -} - //////////////////////////////////////////////////////////////////////////////////////////////////// /** diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 469f8a56d..d384d50db 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h @@ -240,11 +240,6 @@ public: return status == ThreadStatus::WaitSynchAll; } - /** - * Logs the backtrace for the current thread - */ - void LogBacktrace(); - ThreadContext& GetContext() { return context; } -- cgit v1.2.3 From 22d4e106642ac9d6a0dabc700c4dcd47be08ff41 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Sat, 29 Dec 2018 12:55:19 +1100 Subject: Moved log backtrace to arm_interface.cpp. Added printing of error code to fatal --- src/core/CMakeLists.txt | 1 + src/core/arm/arm_interface.cpp | 26 ++++++++++++++++++++++++++ src/core/arm/arm_interface.h | 24 +++++++----------------- src/core/hle/service/fatal/fatal.cpp | 3 ++- 4 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 src/core/arm/arm_interface.cpp (limited to 'src') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index e1f21a764..0a8f018a1 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,5 +1,6 @@ add_library(core STATIC arm/arm_interface.h + arm/arm_interface.cpp arm/exclusive_monitor.cpp arm/exclusive_monitor.h arm/unicorn/arm_unicorn.cpp diff --git a/src/core/arm/arm_interface.cpp b/src/core/arm/arm_interface.cpp new file mode 100644 index 000000000..bcc812da4 --- /dev/null +++ b/src/core/arm/arm_interface.cpp @@ -0,0 +1,26 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include "arm_interface.h" +#include "common/common_types.h" +#include "common/logging/log.h" +#include "core/memory.h" + +namespace Core { +void ARM_Interface::LogBacktrace() { + VAddr fp = GetReg(29); + VAddr lr = GetReg(30); + VAddr sp = GetReg(13); + VAddr pc = GetPC(); + LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); + for (;;) { + LOG_ERROR(Core_ARM, "{:016X}", lr); + if (!fp) { + break; + } + lr = Memory::Read64(fp + 8) - 4; + fp = Memory::Read64(fp); + } +} +}; // namespace Core diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index b0472d55d..91d2b0f81 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h @@ -6,8 +6,6 @@ #include #include "common/common_types.h" -#include "common/logging/log.h" -#include "core/memory.h" namespace Kernel { enum class VMAPermission : u8; @@ -144,21 +142,13 @@ public: /// Prepare core for thread reschedule (if needed to correctly handle state) virtual void PrepareReschedule() = 0; - void LogBacktrace() { - VAddr fp = GetReg(29); - VAddr lr = GetReg(30); - VAddr sp = GetReg(13); - VAddr pc = GetPC(); - LOG_ERROR(Core_ARM, "Backtrace, sp={:016X}, pc={:016X}", sp, pc); - for (;;) { - LOG_ERROR(Core_ARM, "{:016X}", lr); - if (!fp) { - break; - } - lr = Memory::Read64(fp + 8) - 4; - fp = Memory::Read64(fp); - } - } + /// fp (= r29) points to the last frame record. + /// Note that this is the frame record for the *previous* frame, not the current one. + /// Note we need to subtract 4 from our last read to get the proper address + /// Frame records are two words long: + /// fp+0 : pointer to previous frame record + /// fp+8 : value of lr for frame + void LogBacktrace(); }; } // namespace Core diff --git a/src/core/hle/service/fatal/fatal.cpp b/src/core/hle/service/fatal/fatal.cpp index 2f15ac2a6..770590d0b 100644 --- a/src/core/hle/service/fatal/fatal.cpp +++ b/src/core/hle/service/fatal/fatal.cpp @@ -111,7 +111,8 @@ static void GenerateErrorReport(ResultCode error_code, const FatalInfo& info) { } static void ThrowFatalError(ResultCode error_code, FatalType fatal_type, const FatalInfo& info) { - LOG_ERROR(Service_Fatal, "Threw fatal error type {}", static_cast(fatal_type)); + LOG_ERROR(Service_Fatal, "Threw fatal error type {} with error code 0x{:X}", + static_cast(fatal_type), error_code.raw); switch (fatal_type) { case FatalType::ErrorReportAndScreen: GenerateErrorReport(error_code, info); -- cgit v1.2.3