[codeview] Make "clang -g" emit codeview by default when targetting MSVC

Summary:
If you're using the Microsoft ABI, chances are that you want PDBs and
codeview debug info. Currently, everyone has to remember to specific
-gcodeview by default, when it would be nice if the standard -g option
did the right thing by default.

Also, do some related cleanup of -cc1 options. When targetting the MS
C++ ABI, we probably shouldn't pass -debugger-tuning=gdb. We were also
passing -gcodeview twice, which is silly.

Reviewers: smeenai, zturner

Subscribers: aprantl, JDevlieghere, llvm-commits

Differential Revision: https://reviews.llvm.org/D54499

llvm-svn: 346907
This commit is contained in:
Reid Kleckner 2018-11-14 22:59:27 +00:00
parent dced6ee923
commit 7b7b1140e3
10 changed files with 80 additions and 25 deletions

View File

@ -13,6 +13,11 @@
namespace clang {
namespace codegenoptions {
enum DebugInfoFormat {
DIF_DWARF,
DIF_CodeView,
};
enum DebugInfoKind {
NoDebugInfo, /// Don't generate debug info.
LocTrackingOnly, /// Emit location information but do not generate

View File

@ -12,6 +12,7 @@
#include "clang/Basic/LLVM.h"
#include "clang/Basic/Sanitizers.h"
#include "clang/Basic/DebugInfoOptions.h"
#include "clang/Driver/Action.h"
#include "clang/Driver/Multilib.h"
#include "clang/Driver/Types.h"
@ -402,6 +403,11 @@ public:
/// Complain if this tool chain doesn't support Objective-C ARC.
virtual void CheckObjCARC() const {}
/// Get the default debug info format. Typically, this is DWARF.
virtual codegenoptions::DebugInfoFormat getDefaultDebugFormat() const {
return codegenoptions::DIF_DWARF;
}
/// UseDwarfDebugFlags - Embed the compile options to clang into the Dwarf
/// compile unit information.
virtual bool UseDwarfDebugFlags() const { return false; }

View File

@ -3102,21 +3102,24 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
if (checkDebugInfoOption(A, Args, D, TC))
DWARFVersion = DwarfVersionNum(A->getSpelling());
// Forward -gcodeview. EmitCodeView might have been set by CL-compatibility
// argument parsing.
if (EmitCodeView) {
if (const Arg *A = Args.getLastArg(options::OPT_gcodeview)) {
EmitCodeView = checkDebugInfoOption(A, Args, D, TC);
if (EmitCodeView) {
// DWARFVersion remains at 0 if no explicit choice was made.
CmdArgs.push_back("-gcodeview");
}
}
if (const Arg *A = Args.getLastArg(options::OPT_gcodeview)) {
if (checkDebugInfoOption(A, Args, D, TC))
EmitCodeView = true;
}
// If the user asked for debug info but did not explicitly specify -gcodeview
// or -gdwarf, ask the toolchain for the default format.
if (!EmitCodeView && DWARFVersion == 0 &&
DebugInfoKind != codegenoptions::NoDebugInfo)
DWARFVersion = TC.GetDefaultDwarfVersion();
DebugInfoKind != codegenoptions::NoDebugInfo) {
switch (TC.getDefaultDebugFormat()) {
case codegenoptions::DIF_CodeView:
EmitCodeView = true;
break;
case codegenoptions::DIF_DWARF:
DWARFVersion = TC.GetDefaultDwarfVersion();
break;
}
}
// -gline-directives-only supported only for the DWARF debug info.
if (DWARFVersion == 0 && DebugInfoKind == codegenoptions::DebugDirectivesOnly)
@ -3195,6 +3198,9 @@ static void RenderDebugOptions(const ToolChain &TC, const Driver &D,
CmdArgs.push_back("-gembed-source");
}
if (EmitCodeView)
CmdArgs.push_back("-gcodeview");
RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DWARFVersion,
DebuggerTuning);
@ -3916,8 +3922,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
types::ID InputType = Input.getType();
if (D.IsCLMode())
AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView);
else
EmitCodeView = Args.hasArg(options::OPT_gcodeview);
DwarfFissionKind DwarfFission;
RenderDebugOptions(TC, D, RawTriple, Args, EmitCodeView, IsWindowsMSVC,
@ -5503,7 +5507,6 @@ void Clang::AddClangCLArgs(const ArgList &Args, types::ID InputType,
*DebugInfoKind = codegenoptions::LimitedDebugInfo;
else
*DebugInfoKind = codegenoptions::DebugLineTablesOnly;
CmdArgs.push_back("-gcodeview");
} else {
*EmitCodeView = false;
}

View File

@ -11,6 +11,7 @@
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_MSVC_H
#include "Cuda.h"
#include "clang/Basic/DebugInfoOptions.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Tool.h"
#include "clang/Driver/ToolChain.h"
@ -78,6 +79,18 @@ public:
bool isPIEDefault() const override;
bool isPICDefaultForced() const override;
/// Set CodeView as the default debug info format. Users can use -gcodeview
/// and -gdwarf to override the default.
codegenoptions::DebugInfoFormat getDefaultDebugFormat() const override {
return codegenoptions::DIF_CodeView;
}
/// Set the debugger tuning to "default", since we're definitely not tuning
/// for GDB.
llvm::DebuggerKind getDefaultDebuggerTuning() const override {
return llvm::DebuggerKind::Default;
}
enum class SubDirectoryType {
Bin,
Include,

View File

@ -14,14 +14,29 @@
// RUN: %clang -target powerpc-unknown-openbsd -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER2
// RUN: %clang -target powerpc-unknown-freebsd -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER2
// RUN: %clang -target i386-pc-solaris -g -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER2
//
// Test what -gcodeview and -gdwarf do on Windows.
// RUN: %clang -target i686-pc-windows-msvc -gcodeview -S -emit-llvm -o - %s | FileCheck %s --check-prefix=NODWARF --check-prefix=CODEVIEW
// RUN: %clang -target i686-pc-windows-msvc -gdwarf -gcodeview -S -emit-llvm -o - %s | FileCheck %s --check-prefix=VER4 --check-prefix=CODEVIEW
// 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, of you can explicitly ask for both if you don't know how
// the app will be debugged.
// Default is codeview.
// RUN: %clang -target i686-pc-windows-msvc -g -S -emit-llvm -o - %s \
// RUN: | FileCheck %s --check-prefixes=NODWARF,CODEVIEW
// Explicitly request codeview.
// RUN: %clang -target i686-pc-windows-msvc -gcodeview -S -emit-llvm -o - %s \
// RUN: | FileCheck %s --check-prefixes=NODWARF,CODEVIEW
// Explicitly request DWARF.
// RUN: %clang -target i686-pc-windows-msvc -gdwarf -S -emit-llvm -o - %s \
// RUN: | FileCheck %s --check-prefixes=VER4,NOCODEVIEW
// Explicitly request both.
// RUN: %clang -target i686-pc-windows-msvc -gdwarf -gcodeview -S -emit-llvm -o - %s \
// RUN: | FileCheck %s --check-prefixes=VER4,CODEVIEW
int main (void) {
return 0;
}
// NOCODEVIEW-NOT: !"CodeView"
// VER2: !{i32 2, !"Dwarf Version", i32 2}
// VER3: !{i32 2, !"Dwarf Version", i32 3}
// VER4: !{i32 2, !"Dwarf Version", i32 4}
@ -29,4 +44,5 @@ int main (void) {
// NODWARF-NOT: !"Dwarf Version"
// CODEVIEW: !{i32 2, !"CodeView", i32 1}
// NOCODEVIEW-NOT: !"CodeView"
// NODWARF-NOT: !"Dwarf Version"

View File

@ -1,5 +1,5 @@
// FIXME: Check IR rather than asm, then triple is not needed.
// RUN: %clang -Xclang -triple=%itanium_abi_triple -g -S %s -o - | FileCheck %s
// RUN: %clang --target=%itanium_abi_triple -g -S %s -o - | FileCheck %s
// Test to check presence of debug info for byval parameter.
// Radar 8350436.
class DAG {

View File

@ -1,5 +1,5 @@
// FIXME: Check IR rather than asm, then triple is not needed.
// RUN: %clang -Xclang -triple=%itanium_abi_triple -fverbose-asm -g -S %s -o - | grep AT_explicit
// RUN: %clang --target=%itanium_abi_triple -fverbose-asm -g -S %s -o - | grep AT_explicit
class MyClass

View File

@ -1,5 +1,5 @@
// FIXME: Check IR rather than asm, then triple is not needed.
// RUN: %clang -Xclang -triple=%itanium_abi_triple -fverbose-asm -g -S %s -o - | grep DW_ACCESS_public
// RUN: %clang --target=%itanium_abi_triple -fverbose-asm -g -S %s -o - | grep DW_ACCESS_public
class A {
public:
int x;

View File

@ -1,5 +1,5 @@
// FIXME: Check IR rather than asm, then triple is not needed.
// RUN: %clang -Xclang -triple=%itanium_abi_triple -fverbose-asm -g -S %s -o - | grep DW_AT_specification
// RUN: %clang --target=%itanium_abi_triple -fverbose-asm -g -S %s -o - | grep DW_AT_specification
// Radar 9254491
class A {
public:

View File

@ -64,6 +64,14 @@
// RUN: %clang -### -c -g %s -target x86_64-pc-freebsd10.0 2>&1 \
// RUN: | FileCheck -check-prefix=G_GDB %s
// Windows.
// RUN: %clang -### -c -g %s -target x86_64-w64-windows-gnu 2>&1 \
// RUN: | FileCheck -check-prefix=G_GDB %s
// RUN: %clang -### -c -g %s -target x86_64-windows-msvc 2>&1 \
// RUN: | FileCheck -check-prefix=G_NOTUNING %s
// RUN: %clang_cl -### -c -Z7 -target x86_64-windows-msvc -- %s 2>&1 \
// RUN: | FileCheck -check-prefix=G_NOTUNING %s
// On the PS4, -g defaults to -gno-column-info, and we always generate the
// arange section.
// RUN: %clang -### -c %s -target x86_64-scei-ps4 2>&1 \
@ -204,7 +212,7 @@
// RUN: %clang -### -gmodules -gline-tables-only %s 2>&1 \
// RUN: | FileCheck -check-prefix=GLTO_ONLY %s
//
// RUN: %clang -### -gmodules -gline-directives-only %s 2>&1 \
// RUN: %clang -### -target %itanium_abi_triple -gmodules -gline-directives-only %s 2>&1 \
// RUN: | FileCheck -check-prefix=GLIO_ONLY %s
//
// G: "-cc1"
@ -259,6 +267,9 @@
// G_LLDB: "-debugger-tuning=lldb"
// G_SCE: "-debugger-tuning=sce"
//
// G_NOTUNING: "-cc1"
// G_NOTUNING-NOT: "-debugger-tuning="
//
// This tests asserts that "-gline-tables-only" "-g0" disables debug info.
// GLTO_NO: "-cc1"
// GLTO_NO-NOT: -debug-info-kind=
@ -301,7 +312,8 @@
//
// NOCI-NOT: "-dwarf-column-info"
//
// GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj" "-debug-info-kind={{standalone|limited}}"
// GEXTREFS: "-dwarf-ext-refs" "-fmodule-format=obj"
// GEXTREFS: "-debug-info-kind={{standalone|limited}}"
// RUN: not %clang -cc1 -debug-info-kind=watkind 2>&1 | FileCheck -check-prefix=BADSTRING1 %s
// BADSTRING1: error: invalid value 'watkind' in '-debug-info-kind=watkind'