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,
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,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits