[PATCH] D99199: Make -fcrash-diagnostics-dir control the Windows (mini-)dump location

Paul Robinson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 23 10:53:41 PDT 2021


probinson created this revision.
probinson added a reviewer: rnk.
Herald added subscribers: dexonsmith, hiraditya.
probinson requested review of this revision.
Herald added projects: clang, LLVM.

There's no automated test for this, as I don't see any existing tests for creating minidumps.  I have tried it locally, and it works fine even when the directory name has a space in it.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D99199

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/crash-diagnostics-dir-2.c
  llvm/lib/Support/Signals.cpp
  llvm/lib/Support/Windows/Signals.inc


Index: llvm/lib/Support/Windows/Signals.inc
===================================================================
--- llvm/lib/Support/Windows/Signals.inc
+++ llvm/lib/Support/Windows/Signals.inc
@@ -766,16 +766,18 @@
     if (!GetDumpType(DefaultLocalDumpsKey, DumpType))
       DumpType = MiniDumpNormal;
 
-  // Look to see if a dump location is specified in the registry; first with the
+  // Look to see if a dump location is specified on the command line.  If not,
+  // look to see if a dump location is specified in the registry; first with the
   // app-specific key and failing that with the global key.  If none are found
   // we'll just create the dump file in the default temporary file location
   // (GetDumpFolder will return false either if the key is NULL or if there is
   // no valid DumpFolder value at its location).
   bool ExplicitDumpDirectorySet = true;
-  SmallString<MAX_PATH> DumpDirectory;
-  if (!GetDumpFolder(AppSpecificKey, DumpDirectory))
-    if (!GetDumpFolder(DefaultLocalDumpsKey, DumpDirectory))
-      ExplicitDumpDirectorySet = false;
+  SmallString<MAX_PATH> DumpDirectory(CrashDiagnosticsDirectory);
+  if (DumpDirectory.empty())
+    if (!GetDumpFolder(AppSpecificKey, DumpDirectory))
+      if (!GetDumpFolder(DefaultLocalDumpsKey, DumpDirectory))
+        ExplicitDumpDirectorySet = false;
 
   int FD;
   SmallString<MAX_PATH> DumpPath;
Index: llvm/lib/Support/Signals.cpp
===================================================================
--- llvm/lib/Support/Signals.cpp
+++ llvm/lib/Support/Signals.cpp
@@ -43,6 +43,13 @@
     DisableSymbolication("disable-symbolication",
                          cl::desc("Disable symbolizing crash backtraces."),
                          cl::location(DisableSymbolicationFlag), cl::Hidden);
+#ifdef _WIN32
+static std::string CrashDiagnosticsDirectory;
+static cl::opt<std::string, true>
+    CrashDiagnosticsDir("crash-diagnostics-dir", cl::value_desc("directory"),
+                        cl::desc("Directory to use for any crash dump file."),
+                        cl::location(CrashDiagnosticsDirectory), cl::Hidden);
+#endif
 
 constexpr char DisableSymbolizationEnv[] = "LLVM_DISABLE_SYMBOLIZATION";
 constexpr char LLVMSymbolizerPathEnv[] = "LLVM_SYMBOLIZER_PATH";
Index: clang/test/Driver/crash-diagnostics-dir-2.c
===================================================================
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir-2.c
@@ -0,0 +1,6 @@
+// REQUIRES: system-windows
+// RUN: %clang -### -fcrash-diagnostics-dir=mydumps -c %s 2>&1 \
+// RUN:     | FileCheck %s --check-prefix=OPTION
+// OPTION: "-crash-diagnostics-dir=mydumps"
+// RUN: %clang -### -c %s 2>&1 | FileCheck %s --check-prefix=NOOPTION
+// NOOPTION-NOT: "-crash-diagnostics-dir
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5124,6 +5124,15 @@
   if (D.CCGenDiagnostics)
     CmdArgs.push_back("-disable-pragma-debug-crash");
 
+#ifdef _WIN32
+  // Put (mini-)dumps in the same place as other crash diagnostics files.
+  if (Args.hasArg(options::OPT_fcrash_diagnostics_dir)) {
+    StringRef Dir = Args.getLastArgValue(options::OPT_fcrash_diagnostics_dir);
+    CmdArgs.push_back("-mllvm");
+    CmdArgs.push_back(Args.MakeArgString("-crash-diagnostics-dir=" + Dir));
+  }
+#endif
+
   bool UseSeparateSections = isUseSeparateSections(Triple);
 
   if (Args.hasFlag(options::OPT_ffunction_sections,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99199.332726.patch
Type: text/x-patch
Size: 3540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210323/22b8aba7/attachment-0001.bin>


More information about the llvm-commits mailing list