From c910e29168bae831531c812878e7494adb80d742 Mon Sep 17 00:00:00 2001 From: PixelyIon Date: Sat, 7 May 2022 18:34:56 +0530 Subject: [PATCH] Extend `HostSignalHandler`'s `SIGSEGV` debugger path The function now returns from a segmentation fault when a debugger is present, this allows the entire context to be intact which can allow the debugger to correctly pick up variables from all stack frames while it could not extrapolate most variables when trapped inside the signal handler without the values of all registers. --- app/src/main/cpp/skyline/nce.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/skyline/nce.cpp b/app/src/main/cpp/skyline/nce.cpp index af41004a..954f3e9e 100644 --- a/app/src/main/cpp/skyline/nce.cpp +++ b/app/src/main/cpp/skyline/nce.cpp @@ -162,8 +162,16 @@ namespace skyline::nce { return false; }()}; - if (runningUnderDebugger) + if (runningUnderDebugger) { + /* Variables for debugger, these are meant to be read and utilized by the debugger to break in user code with all registers intact */ + void *pc{reinterpret_cast(ctx->uc_mcontext.pc)}; // Use 'p pc' to get the value of this and 'breakpoint set -t current -a ${value of pc}' to break in user code + bool shouldReturn{true}; // Set this to false to throw an exception instead of returning + raise(SIGTRAP); // Notify the debugger if we've got a SIGSEGV as the debugger doesn't catch them by default as they might be hooked + + if (shouldReturn) + return; + } } signal::ExceptionalSignalHandler(signal, info, ctx); // Delegate throwing a host exception to the exceptional signal handler