[PATCH] D48601: Added -fcrash-diagnostics-dir flag
Chijioke Kamanu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 26 11:50:03 PDT 2018
j10kay created this revision.
j10kay added reviewers: hans, inglorion, rnk.
Herald added subscribers: llvm-commits, hiraditya.
New flag causes crash reports to be written in the specified directory
rather than the temp directory.
Repository:
rL LLVM
https://reviews.llvm.org/D48601
Files:
clang/include/clang/Driver/Options.td
clang/lib/Driver/Driver.cpp
clang/test/Driver/crash-diagnostics-dir.c
llvm/include/llvm/Support/FileSystem.h
llvm/lib/Support/Path.cpp
Index: llvm/lib/Support/Path.cpp
===================================================================
--- llvm/lib/Support/Path.cpp
+++ llvm/lib/Support/Path.cpp
@@ -756,13 +756,7 @@
std::error_code createUniqueFile(const Twine &Model, int &ResultFd,
SmallVectorImpl<char> &ResultPath,
- unsigned Mode) {
- return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File);
-}
-
-static std::error_code createUniqueFile(const Twine &Model, int &ResultFd,
- SmallVectorImpl<char> &ResultPath,
- unsigned Mode, OpenFlags Flags) {
+ unsigned Mode, sys::fs::OpenFlags Flags) {
return createUniqueEntity(Model, ResultFd, ResultPath, false, Mode, FS_File,
Flags);
}
@@ -779,6 +773,12 @@
return EC;
}
+std::error_code createUniqueFile(const Twine &Prefix, StringRef Suffix,
+ llvm::SmallVectorImpl<char> &ResultPath) {
+ const char *Middle = Suffix.empty() ? "-%%%%%%" : "-%%%%%%.";
+ return createUniqueFile(Prefix + Middle + Suffix, ResultPath);
+}
+
static std::error_code
createTemporaryFile(const Twine &Model, int &ResultFD,
llvm::SmallVectorImpl<char> &ResultPath, FSEntity Type) {
Index: llvm/include/llvm/Support/FileSystem.h
===================================================================
--- llvm/include/llvm/Support/FileSystem.h
+++ llvm/include/llvm/Support/FileSystem.h
@@ -755,6 +755,8 @@
SmallVectorImpl<char> &ResultPath,
unsigned Mode = all_read | all_write);
+std::error_code createUniqueFile(const Twine &Prefix, StringRef Suffix,
+ SmallVectorImpl<char> &ResultPath);
/// Represents a temporary file.
///
/// The temporary file must be eventually discarded or given a final name and
Index: clang/test/Driver/crash-diagnostics-dir.c
===================================================================
--- /dev/null
+++ clang/test/Driver/crash-diagnostics-dir.c
@@ -0,0 +1,5 @@
+// RUN: mkdir -p %t
+// RUN: not %clang -fcrash-diagnostics-dir=%t -c %s 2>&1 | FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: {{.*}}/Output/crash-diagnostics-dir.c.tmp/{{.*}}.c
Index: clang/lib/Driver/Driver.cpp
===================================================================
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -4036,8 +4036,22 @@
CCGenDiagnostics) {
StringRef Name = llvm::sys::path::filename(BaseInput);
std::pair<StringRef, StringRef> Split = Name.split('.');
- std::string TmpName = GetTemporaryPath(
- Split.first, types::getTypeTempSuffix(JA.getType(), IsCLMode()));
+ SmallString<128> TmpName;
+ auto Suffix = types::getTypeTempSuffix(JA.getType(), IsCLMode());
+ Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
+ if (CCGenDiagnostics && A) {
+ SmallString<128> CrashDirectory;
+ CrashDirectory = A->getValue();
+ llvm::sys::path::append(CrashDirectory, Split.first);
+ std::error_code EC =
+ llvm::sys::fs::createUniqueFile(CrashDirectory, Suffix, TmpName);
+ if (EC) {
+ Diag(clang::diag::err_unable_to_make_temp) << EC.message();
+ return "";
+ }
+ } else {
+ TmpName = GetTemporaryPath(Split.first, Suffix);
+ }
return C.addTempFile(C.getArgs().MakeArgString(TmpName));
}
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -798,6 +798,7 @@
Group<f_Group>;
def fno_crash_diagnostics : Flag<["-"], "fno-crash-diagnostics">, Group<f_clang_Group>, Flags<[NoArgumentUnused]>,
HelpText<"Disable auto-generation of preprocessed source files and a script for reproduction during a clang crash">;
+def fcrash_diagnostics_dir : Joined<["-"], "fcrash-diagnostics-dir=">, Group<f_clang_Group>, Flags<[NoArgumentUnused]>;
def fcreate_profile : Flag<["-"], "fcreate-profile">, Group<f_Group>;
def fcxx_exceptions: Flag<["-"], "fcxx-exceptions">, Group<f_Group>,
HelpText<"Enable C++ exceptions">, Flags<[CC1Option]>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48601.152933.patch
Type: text/x-patch
Size: 4476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180626/089fba2b/attachment.bin>
More information about the cfe-commits
mailing list