From: Kevin Enderby Date: Thu, 22 Dec 2011 19:31:58 +0000 (+0000) Subject: Last part of support for generating dwarf for assembly source files. This gets X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=567003e572eed69cf1e8a04601076c8803355c7a;p=clang Last part of support for generating dwarf for assembly source files. This gets 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 --- diff --git a/include/clang/Driver/CC1AsOptions.td b/include/clang/Driver/CC1AsOptions.td index b1067b7889..ac4d65c662 100644 --- a/include/clang/Driver/CC1AsOptions.td +++ b/include/clang/Driver/CC1AsOptions.td @@ -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.">; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index d99b4f2fce..7ee4b4c126 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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. diff --git a/test/Driver/darwin-debug-flags.c b/test/Driver/darwin-debug-flags.c index 326ca47411..9ef4f6d696 100644 --- a/test/Driver/darwin-debug-flags.c +++ b/test/Driver/darwin-debug-flags.c @@ -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 // +// 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" diff --git a/test/Driver/debug-options.c b/test/Driver/debug-options.c index 867251971d..0d42ee92d3 100644 --- a/test/Driver/debug-options.c +++ b/test/Driver/debug-options.c @@ -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" diff --git a/tools/driver/cc1as_main.cpp b/tools/driver/cc1as_main.cpp index 5a175126df..9959b0d296 100644 --- a/tools/driver/cc1as_main.cpp +++ b/tools/driver/cc1as_main.cpp @@ -72,6 +72,8 @@ struct AssemblerInvocation { std::vector 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 Str;