From 83e3ea5aa7cc87b17653838b8da04528d3763bf6 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 25 Feb 2024 19:23:58 -0600 Subject: [PATCH] Use a common function to abort for debugging purposes --- src/entry_handler.cpp | 12 ++++++++++++ src/entry_handler.h | 2 ++ src/main.cpp | 4 ++-- src/platform/windows/misc.cpp | 2 +- src/stream.cpp | 2 +- 5 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/entry_handler.cpp b/src/entry_handler.cpp index c7719eb0..146a4dfb 100644 --- a/src/entry_handler.cpp +++ b/src/entry_handler.cpp @@ -166,6 +166,18 @@ namespace lifetime { } } + /** + * @brief Breaks into the debugger or terminates Sunshine if no debugger is attached. + */ + void + debug_trap() { +#ifdef _WIN32 + DebugBreak(); +#else + std::raise(SIGTRAP); +#endif + } + /** * @brief Gets the argv array passed to main(). */ diff --git a/src/entry_handler.h b/src/entry_handler.h index c58d0325..bdab361c 100644 --- a/src/entry_handler.h +++ b/src/entry_handler.h @@ -42,6 +42,8 @@ namespace lifetime { extern std::atomic_int desired_exit_code; void exit_sunshine(int exit_code, bool async); + void + debug_trap(); char ** get_argv(); } // namespace lifetime diff --git a/src/main.cpp b/src/main.cpp index b8983e3d..5cc28f9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -318,7 +318,7 @@ main(int argc, char *argv[]) { auto task = []() { BOOST_LOG(fatal) << "10 seconds passed, yet Sunshine's still running: Forcing shutdown"sv; log_flush(); - std::abort(); + lifetime::debug_trap(); }; force_shutdown = task_pool.pushDelayed(task, 10s).task_id; @@ -331,7 +331,7 @@ main(int argc, char *argv[]) { auto task = []() { BOOST_LOG(fatal) << "10 seconds passed, yet Sunshine's still running: Forcing shutdown"sv; log_flush(); - std::abort(); + lifetime::debug_trap(); }; force_shutdown = task_pool.pushDelayed(task, 10s).task_id; diff --git a/src/platform/windows/misc.cpp b/src/platform/windows/misc.cpp index b53bfea5..77de69f4 100644 --- a/src/platform/windows/misc.cpp +++ b/src/platform/windows/misc.cpp @@ -489,7 +489,7 @@ namespace platf { auto winerror = GetLastError(); // Log the failure of reverting to self and its error code BOOST_LOG(fatal) << "Failed to revert to self after impersonation: "sv << winerror; - std::abort(); + DebugBreak(); } return ec; diff --git a/src/stream.cpp b/src/stream.cpp index b9238057..9c146804 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -1815,7 +1815,7 @@ namespace stream { auto task = []() { BOOST_LOG(fatal) << "Hang detected! Session failed to terminate in 10 seconds."sv; log_flush(); - std::abort(); + lifetime::debug_trap(); }; auto force_kill = task_pool.pushDelayed(task, 10s).task_id; auto fg = util::fail_guard([&force_kill]() {