]> granicus.if.org Git - clang/commitdiff
Debug Info: support for gdwarf-2 gdwarf-3 gdwarf-4
authorManman Ren <mren@apple.com>
Wed, 19 Jun 2013 01:46:49 +0000 (01:46 +0000)
committerManman Ren <mren@apple.com>
Wed, 19 Jun 2013 01:46:49 +0000 (01:46 +0000)
These options will add a module flag with name "Dwarf Version".
The behavior flag is currently set to Warning, so when two values disagree,
a warning will be emitted.

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

include/clang/Driver/Options.td
include/clang/Frontend/CodeGenOptions.def
lib/CodeGen/CodeGenModule.cpp
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
test/CodeGen/dwarf-version.c [new file with mode: 0644]
test/Driver/debug-options.c

index 5eb4286cc8944871df13f3b1f1eff5b970f100b9..c8e22d2fd2163702fc0296052ff5eb89ee66e8a8 100644 (file)
@@ -810,9 +810,12 @@ def ggdb0 : Flag<["-"], "ggdb0">, Group<g_Group>;
 def ggdb1 : Flag<["-"], "ggdb1">, Group<g_Group>;
 def ggdb2 : Flag<["-"], "ggdb2">, Group<g_Group>;
 def ggdb3 : Flag<["-"], "ggdb3">, Group<g_Group>;
-def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group<g_Group>;
-def gdwarf_3 : Flag<["-"], "gdwarf-3">, Group<g_Group>;
-def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group<g_Group>;
+def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group<g_Group>,
+  HelpText<"Generate source level debug information with dwarf version 2">, Flags<[CC1Option]>;
+def gdwarf_3 : Flag<["-"], "gdwarf-3">, Group<g_Group>,
+  HelpText<"Generate source level debug information with dwarf version 3">, Flags<[CC1Option]>;
+def gdwarf_4 : Flag<["-"], "gdwarf-4">, Group<g_Group>,
+  HelpText<"Generate source level debug information with dwarf version 4">, Flags<[CC1Option]>;
 def gfull : Flag<["-"], "gfull">, Group<g_Group>;
 def gused : Flag<["-"], "gused">, Group<g_Group>;
 def gstabs : Joined<["-"], "gstabs">, Group<g_Group>, Flags<[Unsupported]>;
index b414d7554f267fcbbb33780834bd40c9b7e00333..4dbf4d00615e107867efd1c7e72dc4054d6a9364 100644 (file)
@@ -135,6 +135,9 @@ VALUE_CODEGENOPT(SSPBufferSize, 32, 0)
 /// The kind of generated debug info.
 ENUM_CODEGENOPT(DebugInfo, DebugInfoKind, 2, NoDebugInfo)
 
+/// Dwarf version.
+VALUE_CODEGENOPT(DwarfVersion, 3, 0)
+
 /// The kind of inlining to perform.
 ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NoInlining)
 
index d76fee5c844318aea2284cf73228c76c3017fe14..18c56b0dae29a25a6e7855786df9552535872f3c 100644 (file)
@@ -190,6 +190,11 @@ void CodeGenModule::Release() {
       (Context.getLangOpts().Modules || !LinkerOptionsMetadata.empty())) {
     EmitModuleLinkOptions();
   }
+  if (CodeGenOpts.DwarfVersion)
+    // We actually want the latest version when there are conflicts.
+    // We can change from Warning to Latest if such mode is supported.
+    getModule().addModuleFlag(llvm::Module::Warning, "Dwarf Version",
+                              CodeGenOpts.DwarfVersion);
 
   SimplifyPersonality();
 
index 373939cd933ab9936788edecefa3e01bfd4c1b8f..7f22d6ff091cebd10db3f339c6b59580d396305a 100644 (file)
@@ -2489,6 +2489,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   if (Arg *A = Args.getLastArg(options::OPT_g_Group)) {
     if (A->getOption().matches(options::OPT_gline_tables_only))
       CmdArgs.push_back("-gline-tables-only");
+    else if (A->getOption().matches(options::OPT_gdwarf_2))
+      CmdArgs.push_back("-gdwarf-2");
+    else if (A->getOption().matches(options::OPT_gdwarf_3))
+      CmdArgs.push_back("-gdwarf-3");
+    else if (A->getOption().matches(options::OPT_gdwarf_4))
+      CmdArgs.push_back("-gdwarf-4");
     else if (!A->getOption().matches(options::OPT_g0) &&
              !A->getOption().matches(options::OPT_ggdb0))
       CmdArgs.push_back("-g");
index 1407e105f24cbb7a1c2c03be8154791e3a3587c8..d9316ec4f0f135ced85215ad9537a0947429cbb2 100644 (file)
@@ -318,7 +318,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
 
   if (Args.hasArg(OPT_gline_tables_only)) {
     Opts.setDebugInfo(CodeGenOptions::DebugLineTablesOnly);
-  } else if (Args.hasArg(OPT_g_Flag)) {
+  } else if (Args.hasArg(OPT_g_Flag) || Args.hasArg(OPT_gdwarf_2) ||
+             Args.hasArg(OPT_gdwarf_3) || Args.hasArg(OPT_gdwarf_4)) {
     if (Args.hasFlag(OPT_flimit_debug_info, OPT_fno_limit_debug_info, true))
       Opts.setDebugInfo(CodeGenOptions::LimitedDebugInfo);
     else
@@ -326,6 +327,15 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
   }
   Opts.DebugColumnInfo = Args.hasArg(OPT_dwarf_column_info);
   Opts.SplitDwarfFile = Args.getLastArgValue(OPT_split_dwarf_file);
+  if (Args.hasArg(OPT_gdwarf_2))
+    Opts.DwarfVersion = 2;
+  else if (Args.hasArg(OPT_gdwarf_3))
+    Opts.DwarfVersion = 3;
+  else if (Args.hasArg(OPT_gdwarf_4))
+    Opts.DwarfVersion = 4;
+  else if (Opts.getDebugInfo() != CodeGenOptions::NoDebugInfo)
+    // Default Dwarf version is 3 if we are generating debug information.
+    Opts.DwarfVersion = 3;
 
   Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
diff --git a/test/CodeGen/dwarf-version.c b/test/CodeGen/dwarf-version.c
new file mode 100644 (file)
index 0000000..739f18d
--- /dev/null
@@ -0,0 +1,10 @@
+// RUN: %clang -target x86_64-linux-gnu -gdwarf-2 -S -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu -gdwarf-3 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER3
+// RUN: %clang -target x86_64-linux-gnu -gdwarf-4 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER4
+int main (void) {
+  return 0;
+}
+
+// CHECK: metadata !{i32 2, metadata !"Dwarf Version", i32 2}
+// VER3: metadata !{i32 2, metadata !"Dwarf Version", i32 3}
+// VER4: metadata !{i32 2, metadata !"Dwarf Version", i32 4}
index fec3f17c48da2b0cd411c89fa40f8be288255f92..981fa908801629dcc6e69933758ec394e8a08065 100644 (file)
@@ -7,7 +7,7 @@
 // RUN: %clang -### -c -ggdb %s 2>&1 | FileCheck -check-prefix=G %s
 // RUN: %clang -### -c -ggdb1 %s 2>&1 | FileCheck -check-prefix=G %s
 // RUN: %clang -### -c -ggdb3 %s 2>&1 | FileCheck -check-prefix=G %s
-// RUN: %clang -### -c -gdwarf-2 %s 2>&1 | FileCheck -check-prefix=G %s
+// RUN: %clang -### -c -gdwarf-2 %s 2>&1 | FileCheck -check-prefix=G_D2 %s
 //
 // RUN: %clang -### -c -gfoo %s 2>&1 | FileCheck -check-prefix=G_NO %s
 // RUN: %clang -### -c -g -g0 %s 2>&1 | FileCheck -check-prefix=G_NO %s
@@ -27,6 +27,9 @@
 //
 // G: "-cc1"
 // G: "-g"
+// 
+// G_D2: "-cc1"
+// G_D2: "-gdwarf-2"
 //
 // G_NO: "-cc1"
 // G_NO-NOT: "-g"