Pass -fcrash-diagnostics-dir along to LLVM
authorPaul Robinson <paul.robinson@sony.com>
Tue, 23 Mar 2021 17:45:37 +0000 (10:45 -0700)
committerPaul Robinson <paul.robinson@sony.com>
Tue, 6 Apr 2021 16:30:52 +0000 (09:30 -0700)
This allows frontend and backend diagnostic files to all go into the
same place.  Have it control the Windows (mini-)dump location.

Differential Revision: https://reviews.llvm.org/D99199

clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/crash-diagnostics-dir-2.c [new file with mode: 0644]
llvm/lib/Support/Signals.cpp
llvm/lib/Support/Windows/Signals.inc

index aaf6f83..22f4ad1 100644 (file)
@@ -5156,6 +5156,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   if (D.CCGenDiagnostics)
     CmdArgs.push_back("-disable-pragma-debug-crash");
 
+  // Allow backend to put its diagnostic files in the same place as frontend
+  // 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));
+  }
+
   bool UseSeparateSections = isUseSeparateSections(Triple);
 
   if (Args.hasFlag(options::OPT_ffunction_sections,
diff --git a/clang/test/Driver/crash-diagnostics-dir-2.c b/clang/test/Driver/crash-diagnostics-dir-2.c
new file mode 100644 (file)
index 0000000..432a889
--- /dev/null
@@ -0,0 +1,5 @@
+// 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 29be4df..5aa1a9e 100644 (file)
@@ -43,6 +43,11 @@ static cl::opt<bool, true>
     DisableSymbolication("disable-symbolication",
                          cl::desc("Disable symbolizing crash backtraces."),
                          cl::location(DisableSymbolicationFlag), cl::Hidden);
+static std::string CrashDiagnosticsDirectory;
+static cl::opt<std::string, true>
+    CrashDiagnosticsDir("crash-diagnostics-dir", cl::value_desc("directory"),
+                        cl::desc("Directory for crash diagnostic files."),
+                        cl::location(CrashDiagnosticsDirectory), cl::Hidden);
 
 constexpr char DisableSymbolizationEnv[] = "LLVM_DISABLE_SYMBOLIZATION";
 constexpr char LLVMSymbolizerPathEnv[] = "LLVM_SYMBOLIZER_PATH";
index 3758582..df5fcb1 100644 (file)
@@ -766,16 +766,18 @@ WriteWindowsDumpFile(PMINIDUMP_EXCEPTION_INFORMATION ExceptionInfo) {
     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;