[clang] 04b3c8c - Pass -fcrash-diagnostics-dir along to LLVM

Paul Robinson via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 6 09:35:25 PDT 2021


Author: Paul Robinson
Date: 2021-04-06T09:30:52-07:00
New Revision: 04b3c8c52c549ee57e69a1b23484b8c4109f83b8

URL: https://github.com/llvm/llvm-project/commit/04b3c8c52c549ee57e69a1b23484b8c4109f83b8
DIFF: https://github.com/llvm/llvm-project/commit/04b3c8c52c549ee57e69a1b23484b8c4109f83b8.diff

LOG: Pass -fcrash-diagnostics-dir along to LLVM

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

Added: 
    clang/test/Driver/crash-diagnostics-dir-2.c

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp
    llvm/lib/Support/Signals.cpp
    llvm/lib/Support/Windows/Signals.inc

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index aaf6f83a0cfa5..22f4ad15ac370 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -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
index 0000000000000..432a8893f8786
--- /dev/null
+++ b/clang/test/Driver/crash-diagnostics-dir-2.c
@@ -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

diff  --git a/llvm/lib/Support/Signals.cpp b/llvm/lib/Support/Signals.cpp
index 29be4df959543..5aa1a9efcf595 100644
--- a/llvm/lib/Support/Signals.cpp
+++ b/llvm/lib/Support/Signals.cpp
@@ -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";

diff  --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc
index 3758582b35f76..df5fcb1b151bc 100644
--- a/llvm/lib/Support/Windows/Signals.inc
+++ b/llvm/lib/Support/Windows/Signals.inc
@@ -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;


        


More information about the cfe-commits mailing list