Index: clang/include/clang/Basic/DebugInfoOptions.h =================================================================== --- clang/include/clang/Basic/DebugInfoOptions.h +++ clang/include/clang/Basic/DebugInfoOptions.h @@ -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 Index: clang/include/clang/Driver/ToolChain.h =================================================================== --- clang/include/clang/Driver/ToolChain.h +++ clang/include/clang/Driver/ToolChain.h @@ -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 @@ /// 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; } Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -3075,21 +3075,24 @@ 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) @@ -3164,6 +3167,9 @@ CmdArgs.push_back("-gembed-source"); } + if (EmitCodeView) + CmdArgs.push_back("-gcodeview"); + RenderDebugEnablingArgs(Args, CmdArgs, DebugInfoKind, DWARFVersion, DebuggerTuning); @@ -3884,8 +3890,6 @@ types::ID InputType = Input.getType(); if (D.IsCLMode()) AddClangCLArgs(Args, InputType, CmdArgs, &DebugInfoKind, &EmitCodeView); - else - EmitCodeView = Args.hasArg(options::OPT_gcodeview); const Arg *SplitDWARFArg = nullptr; RenderDebugOptions(TC, D, RawTriple, Args, EmitCodeView, IsWindowsMSVC, @@ -5471,7 +5475,6 @@ *DebugInfoKind = codegenoptions::LimitedDebugInfo; else *DebugInfoKind = codegenoptions::DebugLineTablesOnly; - CmdArgs.push_back("-gcodeview"); } else { *EmitCodeView = false; } Index: clang/lib/Driver/ToolChains/MSVC.h =================================================================== --- clang/lib/Driver/ToolChains/MSVC.h +++ clang/lib/Driver/ToolChains/MSVC.h @@ -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 @@ 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, Index: clang/test/CodeGen/dwarf-version.c =================================================================== --- clang/test/CodeGen/dwarf-version.c +++ clang/test/CodeGen/dwarf-version.c @@ -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 @@ // NODWARF-NOT: !"Dwarf Version" // CODEVIEW: !{i32 2, !"CodeView", i32 1} +// NOCODEVIEW-NOT: !"CodeView" // NODWARF-NOT: !"Dwarf Version" Index: clang/test/CodeGenCXX/debug-info-byval.cpp =================================================================== --- clang/test/CodeGenCXX/debug-info-byval.cpp +++ clang/test/CodeGenCXX/debug-info-byval.cpp @@ -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 { Index: clang/test/CodeGenCXX/debug-info-ctor2.cpp =================================================================== --- clang/test/CodeGenCXX/debug-info-ctor2.cpp +++ clang/test/CodeGenCXX/debug-info-ctor2.cpp @@ -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 Index: clang/test/CodeGenCXX/debug-info-member.cpp =================================================================== --- clang/test/CodeGenCXX/debug-info-member.cpp +++ clang/test/CodeGenCXX/debug-info-member.cpp @@ -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; Index: clang/test/CodeGenCXX/debug-info-method-spec.cpp =================================================================== --- clang/test/CodeGenCXX/debug-info-method-spec.cpp +++ clang/test/CodeGenCXX/debug-info-method-spec.cpp @@ -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: Index: clang/test/Driver/debug-options.c =================================================================== --- clang/test/Driver/debug-options.c +++ clang/test/Driver/debug-options.c @@ -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'