From c9abc043af88f90d177a5bd147f627b78ca49fde Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Wed, 8 Apr 2009 05:11:16 +0000 Subject: [PATCH] Make debug info work when using -save-temps. - This is pretty ugly, but the most obvious solution. Chime in if you have a nicer one. - The problem is that with -save-temps, clang-cc has no idea what the name of the original input file is. However, the user expects to be able to set breakpoints based on the input file name. - We support this by providing a new option -main-file-name (similar to -dumpbase used by gcc) which allows the driver to pass in the original file name. - building with clang using --save-temps gets the compile unit name from the .i file... git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68595 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/LangOptions.h | 10 ++++++++++ lib/CodeGen/CGDebugInfo.cpp | 6 ++++++ lib/Driver/Tools.cpp | 5 +++++ tools/clang-cc/clang-cc.cpp | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/include/clang/Basic/LangOptions.h b/include/clang/Basic/LangOptions.h index f746edb65f..f95024dd88 100644 --- a/include/clang/Basic/LangOptions.h +++ b/include/clang/Basic/LangOptions.h @@ -76,6 +76,11 @@ private: // signed. Set/Query this value using accessors. unsigned SymbolVisibility : 3; // Symbol's visibility. + /// The user provided name for the "main file", if non-null. This is + /// useful in situations where the input file name does not match + /// the original input file, for example with -save-temps. + const char *MainFileName; + public: unsigned InstantiationDepth; // Maximum template instantiation depth. @@ -110,11 +115,16 @@ public: OptimizeSize = 0; PICLevel = 0; + + MainFileName = 0; } GCMode getGCMode() const { return (GCMode) GC; } void setGCMode(GCMode m) { GC = (unsigned) m; } + const char *getMainFileName() const { return MainFileName; } + void setMainFileName(const char *Name) { MainFileName = Name; } + VisibilityMode getVisibilityMode() const { return (VisibilityMode) SymbolVisibility; } void setVisibilityMode(VisibilityMode v) { SymbolVisibility = (unsigned) v; } diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index c0819369b1..45ceb2b8e6 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -74,6 +74,12 @@ llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { const char *DirName = FE ? FE->getDir()->getName() : ""; const LangOptions &LO = M->getLangOptions(); + + // If this is the main file, use the user provided main file name if + // specified. + if (isMain && LO.getMainFileName()) + FileName = LO.getMainFileName(); + unsigned LangTag; if (LO.CPlusPlus) { if (LO.ObjC1) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index eb9bbf2b7b..4ae96c2e64 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -74,6 +74,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // The make clang go fast button. CmdArgs.push_back("-disable-free"); + // Set the main file name, so that debug info works even with + // -save-temps. + CmdArgs.push_back("-main-file-name"); + CmdArgs.push_back(darwin::CC1::getBaseInputName(Args, Inputs)); + if (isa(JA)) { // Add default argument set. // diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp index 8e396cd0c7..f2ccb80de3 100644 --- a/tools/clang-cc/clang-cc.cpp +++ b/tools/clang-cc/clang-cc.cpp @@ -603,6 +603,9 @@ NoCommon("fno-common", llvm::cl::desc("Compile common globals like normal definitions"), llvm::cl::ValueDisallowed); +static llvm::cl::opt +MainFileName("main-file-name", + llvm::cl::desc("Main file name to use for debug info")); // It might be nice to add bounds to the CommandLine library directly. struct OptLevelParser : public llvm::cl::parser { @@ -777,6 +780,9 @@ static void InitializeLanguageStandard(LangOptions &Options, LangKind LK, assert(PICLevel <= 2 && "Invalid value for -pic-level"); Options.PICLevel = PICLevel; + + if (MainFileName.getPosition()) + Options.setMainFileName(MainFileName.c_str()); } static llvm::cl::opt -- 2.40.0