[cfe-commits] PATCH: Add diagnostic output for crash reports

Chad Rosier mcrosier at apple.com
Wed Jul 13 14:55:39 PDT 2011


On Jul 13, 2011, at 2:38 PM, Douglas Gregor wrote:

> Hi Chad,
> 
> On Jul 13, 2011, at 2:07 PM, Chad Rosier wrote:
> 
>> This patch adds support for producing additional diagnostic information upon a clang crash.  Specifically, the compile is rerun to generate preprocessed source and a message is emitted showing all the command-line options needed to reproduce the problem.  The user is asked to submit a radar/bug report and attach this additional information.  Also, I tested things by hard coding the verifier pass to fail, but I was hoping someone could suggest a more robust means of testing prior to committing.
> 
> Making Clang crash for testing purposes is *easy* :)
> 
> #pragma clang __debug crash 
> 

Very cool.

>> This is for <rdar://problem/9575623>.
> 
> 
> Thanks for working on this! Some comments:

Thanks for the quick response.

> Index: include/clang/Driver/Compilation.h
> ===================================================================
> --- include/clang/Driver/Compilation.h	(revision 135078)
> +++ include/clang/Driver/Compilation.h	(working copy)
> @@ -14,6 +14,7 @@
> #include "clang/Driver/Util.h"
> 
> #include "llvm/ADT/DenseMap.h"
> +#include "llvm/Support/Path.h"
> 
> namespace llvm {
>   class raw_ostream;
> @@ -60,6 +61,9 @@
>   /// Result files which should be removed on failure.
>   ArgStringList ResultFiles;
> 
> +  /// Redirection for stdout, stderr, etc.
> +  const llvm::sys::Path **Redirects;
> +
> public:
>   Compilation(const Driver &D, const ToolChain &DefaultToolChain,
>               InputArgList *Args, DerivedArgList *TranslatedArgs);
> @@ -84,7 +88,7 @@
>   const ArgStringList &getTempFiles() const { return TempFiles; }
> 
>   const ArgStringList &getResultFiles() const { return ResultFiles; }
> -
> +  

White space removed.

>   /// getArgsForToolChain - Return the derived argument list for the
>   /// tool chain \arg TC (or the default tool chain, if TC is not
>   /// specified).
> @@ -136,6 +140,11 @@
>   /// Command which failed.
>   /// \return The accumulated result code of the job.
>   int ExecuteJob(const Job &J, const Command *&FailingCommand) const;
> +
> +  /// initCompilationForDiagnostics - Remove stale state and supress output
> +  /// so compilation can be reexecuted to generate additional diagnostic
> +  /// information (e.g., preprocessed source).
> 
> Typo "suppress"

Fixed.

> 
> -int Driver::ExecuteCompilation(const Compilation &C) const {
> +// When clang crashes, produce diagnostic information including the fully 
> +// preprocessed source file and relevant command line arguments.  Request  
> +// that the developer attach the diagnostic information to a radar.
> +void Driver::generateCompilationDiagnostics(Compilation &C,
> +                                            const Command *FailingCommand) {
> +  llvm::errs() << "\nCompilation error detected, generating diagnostic "
> +               << "information including preprocessed source code and "
> +               << "relevant command line arguments.  Please submit a "
> +               << "radar/bugzilla and include all diagnostic information.\n";
> 
> A few comments here.:
> 
>  - This should use the driver's diagnostics engine, rather than printing directly via llvm::errs()

Will do.

>  - The diagnostic emitted should be customized via something passed to "configure" so vendors of different Clang-based compilers can send people to different URLs to file bugs. The default llvm.org Clang should people to file a bug report at http://llvm.org/, but Apple/Google/whoever will want to customize that URL for the compilers they use.

Will do.

> Did you check how well this works when the crash occurs in a translation unit that uses a precompiled header? We'd like to make sure that we're actually going to get useful data in that case.

I have not tested with PCH, but I will do so once I've made the above changes.

  Chad

> 	- Doug




More information about the cfe-commits mailing list