lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Suppressing exception stack dumps


From: Vadim Zeitlin
Subject: [lmi] Suppressing exception stack dumps
Date: Mon, 15 Mar 2021 00:27:02 +0100

 Hello,

 The commit message of 12273527f (Add C++ exception unwinder for
pc-linux-gnu, 2021-02-07) mentions that "practical experience will guide
future use" and I'd like to provide some practical experience: IMHO, always
getting dumps of all exceptions and the corresponding stack trace is not
very useful, as it results in a huge amount of noise when running many
tests. I realize it can be useful to see this information (although, to be
honest, I'm not really sure if it's more useful than just running the
program under gdb, putting a breakpoint on __cxa_throw and looking at the
stack backtrace when it's triggered), but this should be done on demand and
not on by default. Or, at the very least, there should be a way to turn
this off.

 IOW I'd like to propose the following patch:
---------------------------------- >8 --------------------------------------
diff --git a/unwind.cpp b/unwind.cpp
index 8260cc94a..0cc7db572 100644
--- a/unwind.cpp
+++ b/unwind.cpp
@@ -28,7 +28,8 @@
 #define UNW_LOCAL_ONLY

 #include <cstdio>                       // fprintf()
-#include <cstdlib>                      // free()
+#include <cstdlib>                      // free(), getenv()
+#include <cstring>                      // strcmp()
 #include <cxxabi.h>
 #include <dlfcn.h>
 #include <elfutils/libdwfl.h>
@@ -186,8 +187,11 @@ void print_backtrace()
 extern "C"
 void __cxa_throw(void* thrown_exception, std::type_info* tinfo, void 
(*dest)(void*))
 {
-    identify_exception(thrown_exception, tinfo);
-    print_backtrace();
+    if (std::strcmp(std::getenv("LMI_VERBOSE_EXCEPTIONS"), "1") == 0)
+        {
+        identify_exception(thrown_exception, tinfo);
+        print_backtrace();
+        }
     original_cxa_throw(thrown_exception, tinfo, dest);
 }

---------------------------------- >8 --------------------------------------
that would require doing

        $ LMI_VERBOSE_EXCEPTIONS=1 ./lmi_cli ...

to see it. Of course, alternatively, we could have LMI_SILENT_EXCEPTIONS
that could be set to 1 to disable the display that would be enabled by
default. But I think it would be better to not show them by default.

 Would you agree to apply either of those patches and, if so, should I make
a pull-request for them?

 Thanks in advance,
VZ

Attachment: pgpMGyW3cs1Mw.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]