[cfe-commits] r91661 - in /cfe/trunk: include/clang/CodeGen/CodeGenOptions.h include/clang/Driver/CC1Options.td include/clang/Driver/ToolChain.h lib/CodeGen/CGDebugInfo.cpp lib/Driver/ToolChains.cpp lib/Driver/ToolChains.h lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/Driver/darwin-debug-flags.c

Daniel Dunbar daniel at zuster.org
Thu Dec 17 18:43:18 PST 2009


Author: ddunbar
Date: Thu Dec 17 20:43:17 2009
New Revision: 91661

URL: http://llvm.org/viewvc/llvm-project?rev=91661&view=rev
Log:
Add -dwarf-debug-flags, which provides a way to embed the cc1 level options used
to compile a translation unit into the debug info for that file.
 - Used by parts of Darwin build process to check compiler flags, etc.
 - <rdar://problem/7256886> clang does not emit AT_APPLE_flags

Added:
    cfe/trunk/test/Driver/darwin-debug-flags.c
Modified:
    cfe/trunk/include/clang/CodeGen/CodeGenOptions.h
    cfe/trunk/include/clang/Driver/CC1Options.td
    cfe/trunk/include/clang/Driver/ToolChain.h
    cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
    cfe/trunk/lib/Driver/ToolChains.cpp
    cfe/trunk/lib/Driver/ToolChains.h
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/CodeGen/CodeGenOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/CodeGen/CodeGenOptions.h?rev=91661&r1=91660&r2=91661&view=diff

==============================================================================
--- cfe/trunk/include/clang/CodeGen/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/CodeGen/CodeGenOptions.h Thu Dec 17 20:43:17 2009
@@ -58,6 +58,10 @@
   /// Enable additional debugging information.
   std::string DebugPass;
 
+  /// The string to embed in the debug information for the compile unit, if
+  /// non-empty.
+  std::string DwarfDebugFlags;
+
   /// The ABI to use for passing floating point arguments.
   std::string FloatABI;
 

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=91661&r1=91660&r2=91661&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Dec 17 20:43:17 2009
@@ -104,6 +104,8 @@
   HelpText<"Don't run LLVM optimization passes">;
 def disable_red_zone : Flag<"-disable-red-zone">,
   HelpText<"Do not emit code that uses the red zone.">;
+def dwarf_debug_flags : Separate<"-dwarf-debug-flags">,
+  HelpText<"The string to embed in the Dwarf debug flags record.">;
 def g : Flag<"-g">, HelpText<"Generate source level debug information">;
 def fcatch_undefined_behavior : Flag<"-fcatch-undefined-behavior">,
     HelpText<"Generate runtime checks for undefined behavior.">;

Modified: cfe/trunk/include/clang/Driver/ToolChain.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/ToolChain.h?rev=91661&r1=91660&r2=91661&view=diff

==============================================================================
--- cfe/trunk/include/clang/Driver/ToolChain.h (original)
+++ cfe/trunk/include/clang/Driver/ToolChain.h Thu Dec 17 20:43:17 2009
@@ -113,6 +113,10 @@
   /// for this tool chain, or 0 if this tool chain does not force a
   /// particular PIC mode.
   virtual const char *GetForcedPicModel() const = 0;
+
+  /// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
+  /// compile unit information.
+  virtual bool UseDwarfDebugFlags() const { return false; }
 };
 
 } // end namespace driver

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

==============================================================================
--- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Dec 17 20:43:17 2009
@@ -123,8 +123,6 @@
     CLANG_VENDOR
 #endif
     "clang " CLANG_VERSION_STRING;
-  bool isOptimized = LO.Optimize;
-  const char *Flags = "";   // FIXME: Encode command line options.
 
   // Figure out which version of the ObjC runtime we have.
   unsigned RuntimeVers = 0;
@@ -132,11 +130,9 @@
     RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1;
 
   // Create new compile unit.
-  return Unit = DebugFactory.CreateCompileUnit(LangTag, 
-                                               AbsFileName.getLast(),
-                                               AbsFileName.getDirname(),
-                                               Producer, isMain,
-                                               isOptimized, Flags, RuntimeVers);
+  return Unit = DebugFactory.CreateCompileUnit(
+    LangTag, AbsFileName.getLast(), AbsFileName.getDirname(), Producer, isMain,
+    LO.Optimize, CGM.getCodeGenOpts().DwarfDebugFlags, RuntimeVers);
 }
 
 /// CreateType - Get the Basic type from the cache or create a new

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

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Thu Dec 17 20:43:17 2009
@@ -526,6 +526,12 @@
   return getArchName() == "x86_64";
 }
 
+bool Darwin::UseDwarfDebugFlags() const {
+  if (const char *S = ::getenv("RC_DEBUG_OPTIONS"))
+    return S[0] != '\0';
+  return false;
+}
+
 const char *Darwin::GetDefaultRelocationModel() const {
   return "pic";
 }

Modified: cfe/trunk/lib/Driver/ToolChains.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=91661&r1=91660&r2=91661&view=diff

==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.h (original)
+++ cfe/trunk/lib/Driver/ToolChains.h Thu Dec 17 20:43:17 2009
@@ -154,6 +154,8 @@
   virtual const char *GetDefaultRelocationModel() const;
   virtual const char *GetForcedPicModel() const;
 
+  virtual bool UseDwarfDebugFlags() const;
+
   /// }
 };
 

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

==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Dec 17 20:43:17 2009
@@ -1109,6 +1109,20 @@
 
   const char *Exec =
     Args.MakeArgString(getToolChain().GetProgramPath(C, "clang"));
+
+  // Optionally embed the -cc1 level arguments into the debug info, for build
+  // analysis.
+  if (getToolChain().UseDwarfDebugFlags()) {
+    llvm::SmallString<256> Flags;
+    Flags += Exec;
+    for (unsigned i = 0, e = CmdArgs.size(); i != e; ++i) {
+      Flags += " ";
+      Flags += CmdArgs[i];
+    }
+    CmdArgs.push_back("-dwarf-debug-flags");
+    CmdArgs.push_back(Args.MakeArgString(Flags.str()));
+  }
+
   Dest.addCommand(new Command(JA, *this, Exec, CmdArgs));
 
   // Explicitly warn that these options are unsupported, even though

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=91661&r1=91660&r2=91661&view=diff

==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Dec 17 20:43:17 2009
@@ -122,6 +122,10 @@
     Res.push_back("-disable-llvm-optzns");
   if (Opts.DisableRedZone)
     Res.push_back("-disable-red-zone");
+  if (!Opts.DwarfDebugFlags.empty()) {
+    Res.push_back("-dwarf-debug-flags");
+    Res.push_back(Opts.DwarfDebugFlags);
+  }
   if (!Opts.MergeAllConstants)
     Res.push_back("-fno-merge-all-constants");
   if (Opts.NoCommon)
@@ -749,6 +753,7 @@
   Opts.DebugInfo = Args.hasArg(OPT_g);
   Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
+  Opts.DwarfDebugFlags = getLastArgValue(Args, OPT_dwarf_debug_flags);
   Opts.MergeAllConstants = !Args.hasArg(OPT_fno_merge_all_constants);
   Opts.NoCommon = Args.hasArg(OPT_fno_common);
   Opts.NoImplicitFloat = Args.hasArg(OPT_no_implicit_float);

Added: cfe/trunk/test/Driver/darwin-debug-flags.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/darwin-debug-flags.c?rev=91661&view=auto

==============================================================================
--- cfe/trunk/test/Driver/darwin-debug-flags.c (added)
+++ cfe/trunk/test/Driver/darwin-debug-flags.c Thu Dec 17 20:43:17 2009
@@ -0,0 +1,11 @@
+// RUN: env RC_DEBUG_OPTIONS=1 %clang -ccc-host-triple i386-apple-darwin9 -g -Os %s  -emit-llvm -S -o - | FileCheck %s
+// <rdar://problem/7256886>
+
+// CHECK: !1 = metadata !{
+// CHECK: -cc1
+// CHECK: -triple i386-apple-darwin9
+// CHECK: -g
+// CHECK: -Os
+// CHECK: [DW_TAG_compile_unit ]
+
+int x;





More information about the cfe-commits mailing list