[PATCH] D100809: [Debug-Info] implement -gstrict-dwarf
ChenZheng via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 19 20:19:39 PDT 2021
shchenz created this revision.
shchenz added reviewers: dblaikie, probinson, aprantl, jsji, Esme, echristo, PowerPC.
shchenz added a project: debug-info.
Herald added subscribers: jansvoboda11, dexonsmith, dang.
shchenz requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This patch implements `-gstrict-dwarf` option.
We had this option in clang code base just not used it.
We plan to verify the DWARF info based on DWARF 3.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D100809
Files:
clang/docs/ClangCommandLineReference.rst
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/debug-options.c
Index: clang/test/Driver/debug-options.c
===================================================================
--- clang/test/Driver/debug-options.c
+++ clang/test/Driver/debug-options.c
@@ -110,6 +110,18 @@
// RUN: %clang -### -c -g %s -target powerpc64-ibm-aix-xcoff 2>&1 \
// RUN: | FileCheck -check-prefix=G_LIMITED -check-prefix=G_DBX %s
+// For DBX, -g defaults to -gstrict-dwarf.
+// RUN: %clang -### -c -g %s -target powerpc-ibm-aix-xcoff 2>&1 \
+// RUN: | FileCheck -check-prefix=G_STRICT %s
+// RUN: %clang -### -c -g %s -target powerpc64-ibm-aix-xcoff 2>&1 \
+// RUN: | FileCheck -check-prefix=G_STRICT %s
+// RUN: %clang -### -c -g -gno-strict-dwarf %s -target powerpc-ibm-aix-xcoff \
+// RUN: 2>&1 | FileCheck -check-prefix=STRICT %s
+// RUN: %clang -### -c -g %s -target x86_64-linux-gnu 2>&1 \
+// RUN: | FileCheck -check-prefix=STRICT %s
+// RUN: %clang -### -c -g -ggdb %s -target powerpc-ibm-aix-xcoff 2>&1 \
+// RUN: | FileCheck -check-prefix=STRICT %s
+
// On the AIX, -g defaults to -gno-column-info.
// RUN: %clang -### -c -g %s -target powerpc-ibm-aix-xcoff 2>&1 \
// RUN: | FileCheck -check-prefix=NOCI %s
@@ -314,6 +326,9 @@
// G_SCE: "-debugger-tuning=sce"
// G_DBX: "-debugger-tuning=dbx"
//
+// G_STRICT: "-gstrict-dwarf"
+// STRICT-NOT: "-gstrict-dwarf"
+//
// G_NOTUNING: "-cc1"
// G_NOTUNING-NOT: "-debugger-tuning="
//
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -3968,7 +3968,14 @@
DebugInfoKind == codegenoptions::DebugDirectivesOnly)
DebugInfoKind = codegenoptions::NoDebugInfo;
- // We ignore flag -gstrict-dwarf for now.
+ // strict DWARF is set to false by default. But for DBX, we need it to be set
+ // as true by default.
+ if (const Arg *A = Args.getLastArg(options::OPT_gstrict_dwarf))
+ (void)checkDebugInfoOption(A, Args, D, TC);
+ if (Args.hasFlag(options::OPT_gstrict_dwarf, options::OPT_gno_strict_dwarf,
+ DebuggerTuning == llvm::DebuggerKind::DBX))
+ CmdArgs.push_back("-gstrict-dwarf");
+
// And we handle flag -grecord-gcc-switches later with DWARFDebugFlags.
Args.ClaimAllArgs(options::OPT_g_flags_Group);
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -2779,8 +2779,10 @@
Group<g_flags_Group>;
def : Flag<["-"], "grecord-gcc-switches">, Alias<grecord_command_line>;
def : Flag<["-"], "gno-record-gcc-switches">, Alias<gno_record_command_line>;
-def gstrict_dwarf : Flag<["-"], "gstrict-dwarf">, Group<g_flags_Group>;
-def gno_strict_dwarf : Flag<["-"], "gno-strict-dwarf">, Group<g_flags_Group>;
+defm strict_dwarf : BoolOption<"g", "strict-dwarf",
+ CodeGenOpts<"DebugStrictDwarf">, DefaultFalse,
+ PosFlag<SetTrue, [CC1Option]>, NegFlag<SetFalse>, BothFlags<[CoreOption]>>,
+ Group<g_flags_Group>;
defm column_info : BoolOption<"g", "column-info",
CodeGenOpts<"DebugColumnInfo">, DefaultTrue,
NegFlag<SetFalse, [CC1Option]>, PosFlag<SetTrue>, BothFlags<[CoreOption]>>,
Index: clang/include/clang/Basic/CodeGenOptions.def
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -293,6 +293,7 @@
VALUE_CODEGENOPT(StackProbeSize , 32, 4096) ///< Overrides default stack
///< probe size, even if 0.
CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
+CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.
CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
///< in debug info.
Index: clang/docs/ClangCommandLineReference.rst
===================================================================
--- clang/docs/ClangCommandLineReference.rst
+++ clang/docs/ClangCommandLineReference.rst
@@ -3546,6 +3546,8 @@
.. option:: -gstrict-dwarf, -gno-strict-dwarf
+Use DWARF extensions in later DWARF versions.
+
.. option:: -gz=<arg>, -gz (equivalent to -gz=zlib)
DWARF debug sections compression type
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100809.338694.patch
Type: text/x-patch
Size: 4410 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210420/fcae2a99/attachment-0001.bin>
More information about the cfe-commits
mailing list