[clang] 8d8f9c2 - [clang] Add -fdebug-default-version for specifying the default DWARF version
David Blaikie via cfe-commits
cfe-commits at lists.llvm.org
Thu Nov 7 12:06:18 PST 2019
Author: David Blaikie
Date: 2019-11-07T12:05:58-08:00
New Revision: 8d8f9c24407461fadf1730e80ebcf7c767254715
URL: https://github.com/llvm/llvm-project/commit/8d8f9c24407461fadf1730e80ebcf7c767254715
DIFF: https://github.com/llvm/llvm-project/commit/8d8f9c24407461fadf1730e80ebcf7c767254715.diff
LOG: [clang] Add -fdebug-default-version for specifying the default DWARF version
This flag decouples specifying the DWARF version from enabling/disabling
DWARF in general (or the gN level - gmlt/limited/standalone, etc) while
still allowing existing -gdwarf-N flags to override this default.
Patch by Caroline Tice!
Differential Revision: https://reviews.llvm.org/D69822
Added:
clang/test/Driver/debug-default-version.c
Modified:
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/CommonArgs.h
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 8995f3d198e4..dcd2976a97f2 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1958,6 +1958,8 @@ def fsplit_dwarf_inlining: Flag <["-"], "fsplit-dwarf-inlining">, Group<f_Group>
Flags<[CC1Option]>, HelpText<"Provide minimal debug info in the object/executable to facilitate online symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF">;
def fno_split_dwarf_inlining: Flag<["-"], "fno-split-dwarf-inlining">, Group<f_Group>,
Flags<[CC1Option]>;
+def fdebug_default_version: Joined<["-"], "fdebug-default-version=">, Group<f_Group>,
+ HelpText<"Default DWARF version to use, if a -g option caused DWARF debug info to be produced">;
def fdebug_prefix_map_EQ
: Joined<["-"], "fdebug-prefix-map=">, Group<f_Group>,
Flags<[CC1Option,CC1AsOption]>,
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 17cb4816e61f..008742aca57f 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3335,7 +3335,6 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
// This avoids having to monkey around further in cc1 other than to disable
// codeview if not running in a Windows environment. Perhaps even that
// decision should be made in the driver as well though.
- unsigned DWARFVersion = 0;
llvm::DebuggerKind DebuggerTuning = TC.getDefaultDebuggerTuning();
bool SplitDWARFInlining =
@@ -3418,11 +3417,18 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
}
}
+ unsigned DWARFVersion = 0;
+ unsigned DefaultDWARFVersion = ParseDebugDefaultVersion(TC, Args);
if (EmitDwarf) {
// Start with the platform default DWARF version
DWARFVersion = TC.GetDefaultDwarfVersion();
assert(DWARFVersion && "toolchain default DWARF version must be nonzero");
+ // If the user specified a default DWARF version, that takes precedence
+ // over the platform default.
+ if (DefaultDWARFVersion)
+ DWARFVersion = DefaultDWARFVersion;
+
// Override with a user-specified DWARF version
if (GDwarfN)
if (auto ExplicitVersion = DwarfVersionNum(GDwarfN->getSpelling()))
@@ -6354,6 +6360,11 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
if (WantDebug)
DwarfVersion = DwarfVersionNum(A->getSpelling());
}
+
+ unsigned DefaultDwarfVersion = ParseDebugDefaultVersion(getToolChain(), Args);
+ if (DwarfVersion == 0)
+ DwarfVersion = DefaultDwarfVersion;
+
if (DwarfVersion == 0)
DwarfVersion = getToolChain().GetDefaultDwarfVersion();
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 10743559e048..709ddaae4ab0 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1138,6 +1138,21 @@ unsigned tools::ParseFunctionAlignment(const ToolChain &TC,
return Value ? llvm::Log2_32_Ceil(std::min(Value, 65536u)) : Value;
}
+unsigned tools::ParseDebugDefaultVersion(const ToolChain &TC,
+ const ArgList &Args) {
+ const Arg *A = Args.getLastArg(options::OPT_fdebug_default_version);
+
+ if (!A)
+ return 0;
+
+ unsigned Value = 0;
+ if (StringRef(A->getValue()).getAsInteger(10, Value) || Value > 5 ||
+ Value < 2)
+ TC.getDriver().Diag(diag::err_drv_invalid_int_value)
+ << A->getAsString(Args) << A->getValue();
+ return Value;
+}
+
void tools::AddAssemblerKPIC(const ToolChain &ToolChain, const ArgList &Args,
ArgStringList &CmdArgs) {
llvm::Reloc::Model RelocationModel;
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.h b/clang/lib/Driver/ToolChains/CommonArgs.h
index 79468e6b8926..cf1ce14249ea 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.h
+++ b/clang/lib/Driver/ToolChains/CommonArgs.h
@@ -68,6 +68,9 @@ ParsePICArgs(const ToolChain &ToolChain, const llvm::opt::ArgList &Args);
unsigned ParseFunctionAlignment(const ToolChain &TC,
const llvm::opt::ArgList &Args);
+unsigned ParseDebugDefaultVersion(const ToolChain &TC,
+ const llvm::opt::ArgList &Args);
+
void AddAssemblerKPIC(const ToolChain &ToolChain,
const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs);
diff --git a/clang/test/Driver/debug-default-version.c b/clang/test/Driver/debug-default-version.c
new file mode 100644
index 000000000000..f244c88a8cd0
--- /dev/null
+++ b/clang/test/Driver/debug-default-version.c
@@ -0,0 +1,44 @@
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -fdebug-default-version=4 -gdwarf-2 -S -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF2
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -gdwarf-3 -fdebug-default-version=4 -S -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF3
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -gdwarf-4 -fdebug-default-version=2 -S -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF4
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -gdwarf-5 -S -fdebug-default-version=2 -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF5
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -fdebug-default-version=5 -g -S -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF5
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -gdwarf -fdebug-default-version=2 -S -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF2
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -fdebug-default-version=4 -S -o - %s 2>&1 | FileCheck %s --check-prefixes=NODEBUGINFO,NODWARF4
+
+// Check which debug info formats we use on Windows. By default, in an MSVC
+// environment, we should use codeview. You can enable dwarf, which implicitly
+// disables codeview, or you can explicitly ask for both if you don't know how
+// the app will be debugged.
+// RUN: %clang -### -Werror -target i686-pc-windows-msvc -fdebug-default-version=2 -gdwarf -S -o - %s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=DWARF2,NOCODEVIEW
+// Explicitly request both.
+// RUN: %clang -### -Werror -target i686-pc-windows-msvc -fdebug-default-version=4 -gdwarf -gcodeview -S -o - %s 2>&1 \
+// RUN: | FileCheck %s --check-prefixes=DWARF4,CODEVIEW
+
+// Do Assembler testing most of the same test cases as those above.
+
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -fdebug-default-version=5 -g -x assembler -c -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF5
+
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -fdebug-default-version=4 -gdwarf-2 -x assembler -c -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF2
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -gdwarf-3 -fdebug-default-version=4 -x assembler -c -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF3
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -gdwarf-4 -fdebug-default-version=2 -x assembler -c -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF4
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -gdwarf-5 -x assembler -c -fdebug-default-version=2 -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF5
+// RUN: %clang -### -Werror -target x86_64-linux-gnu -fdebug-default-version=5 -g -x assembler -c -o - %s 2>&1 | FileCheck %s --check-prefix=DWARF5
+
+int main(void) {
+ return 0;
+}
+
+// NOCODEVIEW-NOT: -gcodeview
+// CODEVIEW: "-gcodeview"
+
+// NODEBUGINFO-NOT: -debug-info-kind=
+
+// DWARF2: "-dwarf-version=2"
+// DWARF3: "-dwarf-version=3"
+// DWARF4: "-dwarf-version=4"
+// DWARF5: "-dwarf-version=5"
+
+// NOCODEVIEW-NOT: -gcodeview
+// NODWARF4-NOT: -dwarf-version=4
More information about the cfe-commits
mailing list