summaryrefslogtreecommitdiff
path: root/indra/llcommon/llexception.cpp
diff options
context:
space:
mode:
authorAndrey Kleshchev <andreykproductengine@lindenlab.com>2020-07-21 17:00:15 +0300
committerAndrey Kleshchev <andreykproductengine@lindenlab.com>2020-07-21 17:01:29 +0300
commit4fabf8446c00f7e9094196d73fad13bdb2d571ec (patch)
treed31b82fcdd167e1c0a0939696a77ec874fc7a14a /indra/llcommon/llexception.cpp
parent94eea485edf06c48fcbbbf195ee2f8eb9b8616b1 (diff)
parent72423372d6cd7f763a5567ad75752fa4e7131d60 (diff)
Merge branch 'master' into DRTVWR-486
Diffstat (limited to 'indra/llcommon/llexception.cpp')
-rw-r--r--indra/llcommon/llexception.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/indra/llcommon/llexception.cpp b/indra/llcommon/llexception.cpp
index b32ec2c9c9..5ce8958687 100644
--- a/indra/llcommon/llexception.cpp
+++ b/indra/llcommon/llexception.cpp
@@ -18,10 +18,28 @@
#include <typeinfo>
// external library headers
#include <boost/exception/diagnostic_information.hpp>
+#include <boost/exception/error_info.hpp>
+// On Mac, got:
+// #error "Boost.Stacktrace requires `_Unwind_Backtrace` function. Define
+// `_GNU_SOURCE` macro or `BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED` if
+// _Unwind_Backtrace is available without `_GNU_SOURCE`."
+#define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED
+#if LL_WINDOWS
+// On Windows, header-only implementation causes macro collisions -- use
+// prebuilt library
+#define BOOST_STACKTRACE_LINK
+#endif // LL_WINDOWS
+#include <boost/stacktrace.hpp>
// other Linden headers
#include "llerror.h"
#include "llerrorcontrol.h"
+// used to attach and extract stacktrace information to/from boost::exception,
+// see https://www.boost.org/doc/libs/release/doc/html/stacktrace/getting_started.html#stacktrace.getting_started.exceptions_with_stacktrace
+// apparently the struct passed as the first template param needs no definition?
+typedef boost::error_info<struct errinfo_stacktrace_, boost::stacktrace::stacktrace>
+ errinfo_stacktrace;
+
namespace {
// used by crash_on_unhandled_exception_() and log_unhandled_exception_()
void log_unhandled_exception_(LLError::ELevel level,
@@ -53,3 +71,17 @@ void log_unhandled_exception_(const char* file, int line, const char* pretty_fun
// routinely, but we DO expect to return from this function.
log_unhandled_exception_(LLError::LEVEL_WARN, file, line, pretty_function, context);
}
+
+void annotate_exception_(boost::exception& exc)
+{
+ // https://www.boost.org/doc/libs/release/libs/exception/doc/tutorial_transporting_data.html
+ // "Adding of Arbitrary Data to Active Exception Objects"
+ // Given a boost::exception&, we can add boost::error_info items to it
+ // without knowing its leaf type.
+ // The stacktrace constructor that lets us skip a level -- and why would
+ // we always include annotate_exception_()? -- also requires a max depth.
+ // For the nullary constructor, the stacktrace class declaration itself
+ // passes static_cast<std::size_t>(-1), but that's kind of dubious.
+ // Anyway, which of us is really going to examine more than 100 frames?
+ exc << errinfo_stacktrace(boost::stacktrace::stacktrace(1, 100));
+}