Просмотр исходного кода

Print backtrace on svcBreak

When we get an svcBreak we get a backtrace now
David Marcec 7 лет назад
Родитель
Сommit
7149332712
3 измененных файлов с 24 добавлено и 0 удалено
  1. 2 0
      src/core/hle/kernel/svc.cpp
  2. 17 0
      src/core/hle/kernel/thread.cpp
  3. 5 0
      src/core/hle/kernel/thread.h

+ 2 - 0
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();

+ 17 - 0
src/core/hle/kernel/thread.cpp

@@ -388,6 +388,23 @@ bool Thread::InvokeWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> 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);
+    }
+}
+
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 
 /**

+ 5 - 0
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;
     }