From: Daniel Dunbar Date: Thu, 7 Apr 2011 18:51:54 +0000 (+0000) Subject: Fronted/CC_LOG_DIAGNOSTICS: Output main file name, and add support for X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=28f14933edc863821e4f2ffa3663835c62440dcb;p=clang Fronted/CC_LOG_DIAGNOSTICS: Output main file name, and add support for outputting dwarf-debug-flags. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129094 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/LogDiagnosticPrinter.h b/include/clang/Frontend/LogDiagnosticPrinter.h index 8ac6093318..b6fc23ca1f 100644 --- a/include/clang/Frontend/LogDiagnosticPrinter.h +++ b/include/clang/Frontend/LogDiagnosticPrinter.h @@ -12,6 +12,7 @@ #include "clang/Basic/Diagnostic.h" #include "clang/Basic/SourceLocation.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/SmallVector.h" namespace clang { @@ -49,11 +50,18 @@ class LogDiagnosticPrinter : public DiagnosticClient { llvm::SmallVector Entries; + std::string MainFilename; + std::string DwarfDebugFlags; + public: LogDiagnosticPrinter(llvm::raw_ostream &OS, const DiagnosticOptions &Diags, bool OwnsOutputStream = false); virtual ~LogDiagnosticPrinter(); + void setDwarfDebugFlags(llvm::StringRef Value) { + DwarfDebugFlags = Value; + } + void BeginSourceFile(const LangOptions &LO, const Preprocessor *PP) { LangOpts = &LO; } diff --git a/lib/Frontend/LogDiagnosticPrinter.cpp b/lib/Frontend/LogDiagnosticPrinter.cpp index 9eee843dbe..954bad4e7c 100644 --- a/lib/Frontend/LogDiagnosticPrinter.cpp +++ b/lib/Frontend/LogDiagnosticPrinter.cpp @@ -53,8 +53,14 @@ void LogDiagnosticPrinter::EndSourceFile() { llvm::raw_svector_ostream OS(Msg); OS << "\n"; - // FIXME: Output main translation unit file name. - // FIXME: Include the invocation, if dwarf-debug-flags is available. + if (!MainFilename.empty()) { + OS << " main-file\n" + << " " << MainFilename << "\n"; + } + if (!DwarfDebugFlags.empty()) { + OS << " dwarf-debug-flags\n" + << " " << DwarfDebugFlags << "\n"; + } OS << " diagnostics\n"; OS << " \n"; for (unsigned i = 0, e = Entries.size(); i != e; ++i) { @@ -92,6 +98,17 @@ void LogDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level, // Default implementation (Warnings/errors count). DiagnosticClient::HandleDiagnostic(Level, Info); + // Initialize the main file name, if we haven't already fetched it. + if (MainFilename.empty()) { + const SourceManager &SM = Info.getSourceManager(); + FileID FID = SM.getMainFileID(); + if (!FID.isInvalid()) { + const FileEntry *FE = SM.getFileEntryForID(FID); + if (FE && FE->getName()) + MainFilename = FE->getName(); + } + } + // Create the diag entry. DiagEntry DE; DE.DiagnosticID = Info.getID();