]> granicus.if.org Git - clang/commitdiff
Last part of support for generating dwarf for assembly source files. This gets
authorKevin Enderby <enderby@apple.com>
Thu, 22 Dec 2011 19:31:58 +0000 (19:31 +0000)
committerKevin Enderby <enderby@apple.com>
Thu, 22 Dec 2011 19:31:58 +0000 (19:31 +0000)
the clang driver to enable this when assembling a .s file.  rdar://9275556

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147167 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/CC1AsOptions.td
lib/Driver/Tools.cpp
test/Driver/darwin-debug-flags.c
test/Driver/debug-options.c
tools/driver/cc1as_main.cpp

index b1067b788983f716fe57320c2829d525c1e3ef37..ac4d65c6625fd1fedf4209dfc97be975df323370 100644 (file)
@@ -80,3 +80,8 @@ def no_exec_stack : Flag<"--noexecstack">,
 
 def fatal_warnings : Flag<"--fatal-warnings">,
     HelpText<"Consider warnings as errors">;
+
+def g : Flag<"-g">, HelpText<"Generate source level debug information">;
+
+def dwarf_debug_flags : Separate<"-dwarf-debug-flags">,
+  HelpText<"The string to embed in the Dwarf debug flags record.">;
index d99b4f2fced6be7bdbf7a27a84727aa746f2fe15..7ee4b4c126bddafa37e01df60d78c93579f1c513 100644 (file)
@@ -2501,7 +2501,32 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
   // Ignore explicit -force_cpusubtype_ALL option.
   (void) Args.hasArg(options::OPT_force__cpusubtype__ALL);
 
-  // FIXME: Add -g support, once we have it.
+  // Same as Clang::ConstructJob() we special case debug options to only pass
+  // -g to clang. I guess if it is wrong there then it is wrong here too :) .
+  Args.ClaimAllArgs(options::OPT_g_Group);
+  if (Arg *A = Args.getLastArg(options::OPT_g_Group))
+    if (!A->getOption().matches(options::OPT_g0)) {
+      CmdArgs.push_back("-g");
+    }
+
+  // Optionally embed the -cc1as level arguments into the debug info, for build
+  // analysis.
+  if (getToolChain().UseDwarfDebugFlags()) {
+    ArgStringList OriginalArgs;
+    for (ArgList::const_iterator it = Args.begin(),
+           ie = Args.end(); it != ie; ++it)
+      (*it)->render(Args, OriginalArgs);
+
+    llvm::SmallString<256> Flags;
+    const char *Exec = getToolChain().getDriver().getClangProgramPath();
+    Flags += Exec;
+    for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) {
+      Flags += " ";
+      Flags += OriginalArgs[i];
+    }
+    CmdArgs.push_back("-dwarf-debug-flags");
+    CmdArgs.push_back(Args.MakeArgString(Flags.str()));
+  }
 
   // FIXME: Add -static support, once we have it.
 
index 326ca47411a3360252b2eec12cd5c572a79ff9c7..9ef4f6d69615a8decd397759dfb1cb40ece6f039 100644 (file)
@@ -1,5 +1,7 @@
 // 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>
+// RUN: touch %t.s
+// RUN: env RC_DEBUG_OPTIONS=1 %clang -### -c -g %t.s 2>&1 | FileCheck -check-prefix=S %s
 
 // CHECK: !0 = metadata !{
 // CHECK: -g -Os
@@ -7,3 +9,5 @@
 // CHECK: [ DW_TAG_compile_unit ]
 
 int x;
+
+// S: "-dwarf-debug-flags"
index 867251971d26646c76a9f8bb93cc9ddc4471413f..0d42ee92d3a8f146673b0abba5175cea2d4ff10b 100644 (file)
@@ -5,6 +5,10 @@
 // RUN: %clang -### -c -g3 %s 2>&1 | FileCheck -check-prefix=G3 %s
 // RUN: %clang -### -c -ganything %s 2>&1 | FileCheck -check-prefix=GANY %s
 // RUN: %clang -### -c -gfoo %s 2>&1 | FileCheck -check-prefix=GFOO %s
+// Check to make sure clang with -g on a .s file gets passed.
+// rdar://9275556
+// RUN: touch %t.s
+// RUN: %clang -### -c -g %t.s 2>&1 | FileCheck -check-prefix=S %s
 //
 // G: "-cc1"
 // G: "-g"
@@ -17,3 +21,6 @@
 //
 // GFOO: "-cc1"
 // GFOO-NOT: "-g"
+//
+// S: "-cc1as"
+// S: "-g"
index 5a175126dff95b4c2fd66ff847d80864ae6de27e..9959b0d2965d57db60ca7b5d5d4a10f200369f33 100644 (file)
@@ -72,6 +72,8 @@ struct AssemblerInvocation {
   std::vector<std::string> IncludePaths;
   unsigned NoInitialTextSection : 1;
   unsigned SaveTemporaryLabels : 1;
+  unsigned GenDwarfForAssembly : 1;
+  std::string DwarfDebugFlags;
 
   /// @}
   /// @name Frontend Options
@@ -158,6 +160,8 @@ void AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
   Opts.IncludePaths = Args->getAllArgValues(OPT_I);
   Opts.NoInitialTextSection = Args->hasArg(OPT_n);
   Opts.SaveTemporaryLabels = Args->hasArg(OPT_L);
+  Opts.GenDwarfForAssembly = Args->hasArg(OPT_g);
+  Opts.DwarfDebugFlags = Args->getLastArgValue(OPT_dwarf_debug_flags);
 
   // Frontend Options
   if (Args->hasArg(OPT_INPUT)) {
@@ -273,6 +277,10 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
                              Reloc::Default, CodeModel::Default, Ctx);
   if (Opts.SaveTemporaryLabels)
     Ctx.setAllowTemporaryLabels(false);
+  if (Opts.GenDwarfForAssembly)
+    Ctx.setGenDwarfForAssembly(true);
+  if (!Opts.DwarfDebugFlags.empty())
+    Ctx.setDwarfDebugFlags(StringRef(Opts.DwarfDebugFlags));
 
   OwningPtr<MCStreamer> Str;