diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-12-18 02:43:17 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-12-18 02:43:17 +0000 |
commit | f2d8b9f967a1ab53ee9fdbcc3ac0a4ee0a83a26e (patch) | |
tree | a895667ec91441fddff4eba4440bd06b6195c9fc | |
parent | dd5614b18cbe4c528b0589b4ba722346bdb9fcce (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91661 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/CodeGen/CodeGenOptions.h | 4 | ||||
-rw-r--r-- | include/clang/Driver/CC1Options.td | 2 | ||||
-rw-r--r-- | include/clang/Driver/ToolChain.h | 4 | ||||
-rw-r--r-- | lib/CodeGen/CGDebugInfo.cpp | 10 | ||||
-rw-r--r-- | lib/Driver/ToolChains.cpp | 6 | ||||
-rw-r--r-- | lib/Driver/ToolChains.h | 2 | ||||
-rw-r--r-- | lib/Driver/Tools.cpp | 14 | ||||
-rw-r--r-- | lib/Frontend/CompilerInvocation.cpp | 5 | ||||
-rw-r--r-- | test/Driver/darwin-debug-flags.c | 11 |
9 files changed, 51 insertions, 7 deletions
diff --git a/include/clang/CodeGen/CodeGenOptions.h b/include/clang/CodeGen/CodeGenOptions.h index c8fb37b9dd..8682715ce5 100644 --- a/include/clang/CodeGen/CodeGenOptions.h +++ b/include/clang/CodeGen/CodeGenOptions.h @@ -58,6 +58,10 @@ public: /// 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; diff --git a/include/clang/Driver/CC1Options.td b/include/clang/Driver/CC1Options.td index f6160e9764..a7db9a8557 100644 --- a/include/clang/Driver/CC1Options.td +++ b/include/clang/Driver/CC1Options.td @@ -104,6 +104,8 @@ def disable_llvm_optzns : Flag<"-disable-llvm-optzns">, 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.">; diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index df651a6c3d..a570ec26ed 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -113,6 +113,10 @@ public: /// 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 diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 2238c89f83..0a92710ff4 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -123,8 +123,6 @@ llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { 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 @@ llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) { 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 diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 420573dea2..0c2db8a87c 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -526,6 +526,12 @@ bool Darwin::IsUnwindTablesDefault() const { 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"; } diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index fcd96f1e5c..be36344f0c 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -154,6 +154,8 @@ public: virtual const char *GetDefaultRelocationModel() const; virtual const char *GetForcedPicModel() const; + virtual bool UseDwarfDebugFlags() const; + /// } }; diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 55008e3bbb..d3c1b310ed 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1109,6 +1109,20 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, 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 diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 0a592b2e5a..414705716b 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -122,6 +122,10 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts, 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 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, 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); diff --git a/test/Driver/darwin-debug-flags.c b/test/Driver/darwin-debug-flags.c new file mode 100644 index 0000000000..86cd5b9a83 --- /dev/null +++ b/test/Driver/darwin-debug-flags.c @@ -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; |