From 891eb7f1c4787238ae0cd3e1bfd9c710dfa9bd2a Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Thu, 4 Apr 2019 17:57:12 -0500 Subject: [PATCH] st/oxr: Add a debug option to break/trap on error. Might be useful for debugging, since once the consuming call has returned, you've lost most of the context of what led to the error. --- src/xrt/state_trackers/oxr/oxr_logger.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/xrt/state_trackers/oxr/oxr_logger.cpp b/src/xrt/state_trackers/oxr/oxr_logger.cpp index bf30dc24f..eee1f1c32 100644 --- a/src/xrt/state_trackers/oxr/oxr_logger.cpp +++ b/src/xrt/state_trackers/oxr/oxr_logger.cpp @@ -16,8 +16,13 @@ #include "oxr_objects.h" #include "oxr_logger.h" +#ifdef _MSC_VER +// needed for __debugbreak() +#include +#endif // _MSC_VER DEBUG_GET_ONCE_BOOL_OPTION(entrypoints, "OXR_DEBUG_ENTRYPOINTS", false) +DEBUG_GET_ONCE_BOOL_OPTION(break_on_error, "OXR_BREAK_ON_ERROR", false) static const char * oxr_result_to_string(XrResult result); @@ -85,12 +90,22 @@ oxr_error(struct oxr_logger *logger, XrResult result, const char *fmt, ...) fprintf(stderr, " in %s", logger->api_func_name); } + fprintf(stderr, ": "); va_list args; va_start(args, fmt); vfprintf(stderr, fmt, args); va_end(args); fprintf(stderr, "\n"); + if (debug_get_bool_option_break_on_error()) { +/// Trigger a debugger breakpoint. +#ifdef _MSC_VER + __debugbreak(); +#else + __builtin_trap(); +#endif + } + return result; }