[PATCH] D86170: PrintStackTrace: don't symbolize if LLVM_DISABLE_SYMBOLIZATION is set

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 08:15:50 PDT 2020


MaskRay updated this revision to Diff 286824.
MaskRay added a comment.

env -> printenv
Use SetEnvironmentVariableA on Windows


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86170/new/

https://reviews.llvm.org/D86170

Files:
  llvm/lib/Support/Signals.cpp
  llvm/test/tools/not/disable-symbolization.test
  llvm/utils/not/not.cpp


Index: llvm/utils/not/not.cpp
===================================================================
--- llvm/utils/not/not.cpp
+++ llvm/utils/not/not.cpp
@@ -15,6 +15,10 @@
 #include "llvm/Support/WithColor.h"
 #include "llvm/Support/raw_ostream.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
 using namespace llvm;
 
 int main(int argc, const char **argv) {
@@ -27,6 +31,16 @@
     ++argv;
     --argc;
     ExpectCrash = true;
+
+    // Crash is expected, so disable crash report and symbolization to reduce
+    // output and avoid potentially slow symbolization.
+#ifdef _WIN32
+    SetEnvironmentVariableA("LLVM_DISABLE_CRASH_REPORT", "1");
+    SetEnvironmentVariableA("LLVM_DISABLE_SYMBOLIZATION", "1");
+#else
+    setenv("LLVM_DISABLE_CRASH_REPORT", "1", 0);
+    setenv("LLVM_DISABLE_SYMBOLIZATION", "1", 0);
+#endif
   }
 
   if (argc == 0)
Index: llvm/test/tools/not/disable-symbolization.test
===================================================================
--- /dev/null
+++ llvm/test/tools/not/disable-symbolization.test
@@ -0,0 +1,5 @@
+# RUN: not --crash printenv > %t || true
+# RUN: FileCheck %s < %t
+
+# CHECK-DAG: LLVM_DISABLE_CRASH_REPORT=1
+# CHECK-DAG: LLVM_DISABLE_SYMBOLIZATION=1
Index: llvm/lib/Support/Signals.cpp
===================================================================
--- llvm/lib/Support/Signals.cpp
+++ llvm/lib/Support/Signals.cpp
@@ -44,6 +44,8 @@
                          cl::desc("Disable symbolizing crash backtraces."),
                          cl::location(DisableSymbolicationFlag), cl::Hidden);
 
+constexpr char DisableSymbolizationEnv[] = "LLVM_DISABLE_SYMBOLIZATION";
+
 // Callbacks to run in signal handler must be lock-free because a signal handler
 // could be running as we add new callbacks. We don't add unbounded numbers of
 // callbacks, an array is therefore sufficient.
@@ -105,7 +107,7 @@
 LLVM_ATTRIBUTE_USED
 static bool printSymbolizedStackTrace(StringRef Argv0, void **StackTrace,
                                       int Depth, llvm::raw_ostream &OS) {
-  if (DisableSymbolicationFlag)
+  if (DisableSymbolicationFlag || getenv(DisableSymbolizationEnv))
     return false;
 
   // Don't recursively invoke the llvm-symbolizer binary.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D86170.286824.patch
Type: text/x-patch
Size: 2218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200820/fe6fdca4/attachment.bin>


More information about the llvm-commits mailing list