[cfe-commits] r68595 - in /cfe/trunk: include/clang/Basic/LangOptions.h lib/CodeGen/CGDebugInfo.cpp lib/Driver/Tools.cpp tools/clang-cc/clang-cc.cpp

Daniel Dunbar daniel at zuster.org
Tue Apr 7 22:11:16 PDT 2009


Author: ddunbar
Date: Wed Apr  8 00:11:16 2009
New Revision: 68595

URL: http://llvm.org/viewvc/llvm-project?rev=68595&view=rev
Log:
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.

 - <rdar://problem/6753383> building with clang using --save-temps
   gets the compile unit name from the .i file...

Modified:
    cfe/trunk/include/clang/Basic/LangOptions.h
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Modified: cfe/trunk/include/clang/Basic/LangOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=68595&r1=68594&r2=68595&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.h (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.h Wed Apr  8 00:11:16 2009
@@ -76,6 +76,11 @@
                    // 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 @@
     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; }
   

Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=68595&r1=68594&r2=68595&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Wed Apr  8 00:11:16 2009
@@ -74,6 +74,12 @@
   const char *DirName = FE ? FE->getDir()->getName() : "<unknown>";
   
   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)

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=68595&r1=68594&r2=68595&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Apr  8 00:11:16 2009
@@ -74,6 +74,11 @@
   // 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<AnalyzeJobAction>(JA)) {
     // Add default argument set.
     //

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68595&r1=68594&r2=68595&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Wed Apr  8 00:11:16 2009
@@ -603,6 +603,9 @@
          llvm::cl::desc("Compile common globals like normal definitions"),
          llvm::cl::ValueDisallowed);
 
+static llvm::cl::opt<std::string>
+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<unsigned> {
@@ -777,6 +780,9 @@
 
   assert(PICLevel <= 2 && "Invalid value for -pic-level");
   Options.PICLevel = PICLevel;
+
+  if (MainFileName.getPosition())
+    Options.setMainFileName(MainFileName.c_str());
 }
 
 static llvm::cl::opt<bool>





More information about the cfe-commits mailing list