aboutsummaryrefslogtreecommitdiff
path: root/bdep/bdep.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'bdep/bdep.cxx')
-rw-r--r--bdep/bdep.cxx21
1 files changed, 20 insertions, 1 deletions
diff --git a/bdep/bdep.cxx b/bdep/bdep.cxx
index e4146e5..e02687d 100644
--- a/bdep/bdep.cxx
+++ b/bdep/bdep.cxx
@@ -6,8 +6,11 @@
# include <signal.h> // signal()
#endif
-#include <cstring> // strcmp()
+#include <cstring> // strcmp()
#include <iostream>
+#include <exception> // set_terminate(), terminate_handler
+
+#include <libbutl/backtrace.mxx> // backtrace()
#include <bdep/types.hxx>
#include <bdep/utility.hxx>
@@ -152,12 +155,28 @@ init (const common_options& co,
return o;
}
+// Print backtrace if terminating due to an unhandled exception. Note that
+// custom_terminate is non-static and not a lambda to reduce the noise.
+//
+static terminate_handler default_terminate;
+
+void
+custom_terminate ()
+{
+ *diag_stream << backtrace ();
+
+ if (default_terminate != nullptr)
+ default_terminate ();
+}
+
int bdep::
main (int argc, char* argv[])
try
{
using namespace cli;
+ default_terminate = set_terminate (custom_terminate);
+
stderr_term = fdterm (stderr_fd ());
argv0 = argv[0];