diff options
author | Chad Rosier <mcrosier@apple.com> | 2011-08-02 17:58:04 +0000 |
---|---|---|
committer | Chad Rosier <mcrosier@apple.com> | 2011-08-02 17:58:04 +0000 |
commit | 2b81910618f63e4ce2373c926a26e76b4b91373f (patch) | |
tree | 48cef925cb1f3b951d23d5e7edea779d5505c6c1 /lib/Driver/Compilation.cpp | |
parent | c24a1eef40207457692a1ad597cefdd0dc8fa149 (diff) |
When the compiler crashes, the compiler driver now produces diagnostic
information including the fully preprocessed source file(s) and command line
arguments. The developer is asked to attach this diagnostic information to a
bug report.
rdar://9575623
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136702 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Driver/Compilation.cpp')
-rw-r--r-- | lib/Driver/Compilation.cpp | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 47ac1756c8..85a5fc9330 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -16,6 +16,7 @@ #include "clang/Driver/Options.h" #include "clang/Driver/ToolChain.h" +#include "llvm/ADT/STLExtras.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Program.h" #include <sys/stat.h> @@ -27,7 +28,7 @@ using namespace clang; Compilation::Compilation(const Driver &D, const ToolChain &_DefaultToolChain, InputArgList *_Args, DerivedArgList *_TranslatedArgs) : TheDriver(D), DefaultToolChain(_DefaultToolChain), Args(_Args), - TranslatedArgs(_TranslatedArgs) { + TranslatedArgs(_TranslatedArgs), Redirects(0) { } Compilation::~Compilation() { @@ -45,6 +46,13 @@ Compilation::~Compilation() { for (ActionList::iterator it = Actions.begin(), ie = Actions.end(); it != ie; ++it) delete *it; + + // Free redirections of stdout/stderr. + if (Redirects) { + delete Redirects[1]; + delete Redirects[2]; + delete [] Redirects; + } } const DerivedArgList &Compilation::getArgsForToolChain(const ToolChain *TC, @@ -137,8 +145,8 @@ int Compilation::ExecuteCommand(const Command &C, std::copy(C.getArguments().begin(), C.getArguments().end(), Argv+1); Argv[C.getArguments().size() + 1] = 0; - if (getDriver().CCCEcho || getDriver().CCPrintOptions || - getArgs().hasArg(options::OPT_v)) { + if ((getDriver().CCCEcho || getDriver().CCPrintOptions || + getArgs().hasArg(options::OPT_v)) && !getDriver().CCGenDiagnostics) { raw_ostream *OS = &llvm::errs(); // Follow gcc implementation of CC_PRINT_OPTIONS; we could also cache the @@ -169,7 +177,7 @@ int Compilation::ExecuteCommand(const Command &C, std::string Error; int Res = llvm::sys::Program::ExecuteAndWait(Prog, Argv, - /*env*/0, /*redirects*/0, + /*env*/0, Redirects, /*secondsToWait*/0, /*memoryLimit*/0, &Error); if (!Error.empty()) { @@ -197,3 +205,24 @@ int Compilation::ExecuteJob(const Job &J, return 0; } } + +void Compilation::initCompilationForDiagnostics(void) { + // Free actions and jobs. + DeleteContainerPointers(Actions); + Jobs.clear(); + + // Clear temporary/results file lists. + TempFiles.clear(); + ResultFiles.clear(); + + // Remove any user specified output. Claim any unclaimed arguments, so as + // to avoid emitting warnings about unused args. + if (TranslatedArgs->hasArg(options::OPT_o)) + TranslatedArgs->eraseArg(options::OPT_o); + TranslatedArgs->ClaimAllArgs(); + + // Redirect stdout/stderr to /dev/null. + Redirects = new const llvm::sys::Path*[3](); + Redirects[1] = new const llvm::sys::Path(); + Redirects[2] = new const llvm::sys::Path(); +} |