Index: include/llvm/CodeGen/CommandFlags.h =================================================================== --- include/llvm/CodeGen/CommandFlags.h +++ include/llvm/CodeGen/CommandFlags.h @@ -226,6 +226,17 @@ "Create one table per unique function type."), clEnumValEnd)); +cl::opt +DebuggerTuning("debugger-tune", + cl::desc("Tune debug info for a particular debugger"), + cl::init(DebuggerKind::Default), + cl::values( + clEnumValN(DebuggerKind::GDB, "gdb", "gdb"), + clEnumValN(DebuggerKind::LLDB, "lldb", "lldb"), + clEnumValN(DebuggerKind::SCE, "sce", + "SCE targets (e.g. PS4)"), + clEnumValEnd)); + // Common utility function tightly tied to the options listed here. Initializes // a TargetOptions object with CodeGen flags and returns it. static inline TargetOptions InitTargetOptionsFromCodeGenFlags() { @@ -254,6 +265,7 @@ Options.MCOptions = InitMCTargetOptionsFromFlags(); Options.JTType = JTableType; + Options.DebuggerTuning = DebuggerTuning; Options.ThreadModel = TMModel; Index: include/llvm/Target/TargetOptions.h =================================================================== --- include/llvm/Target/TargetOptions.h +++ include/llvm/Target/TargetOptions.h @@ -57,6 +57,13 @@ }; } + enum class DebuggerKind { + Default, // No specific tuning. + GDB, // Tune debug info for gdb. + LLDB, // Tune debug info for lldb. + SCE // Tune debug info for SCE targets (e.g. PS4). + }; + class TargetOptions { public: TargetOptions() @@ -73,7 +80,8 @@ DataSections(false), UniqueSectionNames(true), TrapUnreachable(false), TrapFuncName(), FloatABIType(FloatABI::Default), AllowFPOpFusion(FPOpFusion::Standard), JTType(JumpTable::Single), - ThreadModel(ThreadModel::POSIX) {} + ThreadModel(ThreadModel::POSIX), + DebuggerTuning(DebuggerKind::Default) {} /// PrintMachineCode - This flag is enabled when the -print-machineinstrs /// option is specified on the command line, and should enable debugging @@ -225,6 +233,9 @@ /// for things like atomics ThreadModel::Model ThreadModel; + /// Which debugger are we expecting to consume the debug info? + DebuggerKind DebuggerTuning; + /// Machine level options. MCTargetOptions MCOptions; }; Index: lib/CodeGen/AsmPrinter/DwarfDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.h +++ lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -33,6 +33,8 @@ #include "llvm/MC/MCDwarf.h" #include "llvm/MC/MachineLocation.h" #include "llvm/Support/Allocator.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetOptions.h" #include namespace llvm { @@ -315,7 +317,6 @@ // True iff there are multiple CUs in this module. bool SingleCU; bool IsDarwin; - bool IsPS4; AddressPool AddrPool; @@ -537,6 +538,19 @@ /// standard DW_OP_form_tls_address opcode bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; } + /// \defgroup DebuggerTuning Predicates to tune DWARF for a given debugger. + /// @{ + bool tuneDebugForGDB() const { + return Asm->TM.Options.DebuggerTuning == DebuggerKind::GDB; + } + bool tuneDebugForLLDB() const { + return Asm->TM.Options.DebuggerTuning == DebuggerKind::LLDB; + } + bool tuneDebugForSCE() const { + return Asm->TM.Options.DebuggerTuning == DebuggerKind::SCE; + } + /// @} + // Experimental DWARF5 features. /// \brief Returns whether or not to emit tables that dwarf consumers can Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -197,7 +197,6 @@ UsedNonDefaultText(false), SkeletonHolder(A, "skel_string", DIEValueAllocator), IsDarwin(Triple(A->getTargetTriple()).isOSDarwin()), - IsPS4(Triple(A->getTargetTriple()).isPS4()), AccelNames(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, dwarf::DW_FORM_data4)), AccelObjC(DwarfAccelTable::Atom(dwarf::DW_ATOM_die_offset, @@ -209,8 +208,18 @@ CurFn = nullptr; CurMI = nullptr; + // Make sure we know our "debugger tuning." + if (Asm->TM.Options.DebuggerTuning == DebuggerKind::Default) { + if (IsDarwin) + Asm->TM.Options.DebuggerTuning = DebuggerKind::LLDB; + else if (Triple(A->getTargetTriple()).isPS4CPU()) + Asm->TM.Options.DebuggerTuning = DebuggerKind::SCE; + else + Asm->TM.Options.DebuggerTuning = DebuggerKind::GDB; + } + // Turn on accelerator tables for Darwin by default, pubnames by - // default for non-Darwin/PS4, and handle split dwarf. + // default for non-Darwin/SCE, and handle split dwarf. if (DwarfAccelTables == Default) HasDwarfAccelTables = IsDarwin; else @@ -222,7 +231,7 @@ HasSplitDwarf = SplitDwarf == Enable; if (DwarfPubSections == Default) - HasDwarfPubSections = !IsDarwin && !IsPS4; + HasDwarfPubSections = !IsDarwin && !tuneDebugForSCE(); else HasDwarfPubSections = DwarfPubSections == Enable; @@ -230,9 +239,9 @@ DwarfVersion = DwarfVersionNumber ? DwarfVersionNumber : MMI->getModule()->getDwarfVersion(); - // Darwin and PS4 use the standard TLS opcode (defined in DWARF 3). - // Everybody else uses GNU's. - UseGNUTLSOpcode = !(IsDarwin || IsPS4) || DwarfVersion < 3; + // DWARF 2 didn't define a standard TLS opcode, so use the GNU opcode; + // and GDB always wants the GNU opcode. + UseGNUTLSOpcode = DwarfVersion < 3 || tuneDebugForGDB(); Asm->OutStreamer->getContext().setDwarfVersion(DwarfVersion); Index: test/DebugInfo/X86/dwarf-public-names.ll =================================================================== --- test/DebugInfo/X86/dwarf-public-names.ll +++ test/DebugInfo/X86/dwarf-public-names.ll @@ -4,6 +4,11 @@ ; RUN: llvm-dwarfdump -debug-dump=pubnames %t.o | FileCheck --check-prefix=NOPUB %s ; RUN: llc -mtriple=x86_64-scei-ps4 -filetype=obj -o %t.o < %s ; RUN: llvm-dwarfdump -debug-dump=pubnames %t.o | FileCheck --check-prefix=NOPUB %s +; RUN: llc -mtriple=x86_64-pc-linux-gnu -debugger-tune=sce -filetype=obj -o %t.o < %s +; RUN: llvm-dwarfdump -debug-dump=pubnames %t.o | FileCheck --check-prefix=NOPUB %s +; RUN: llc -mtriple=x86_64-scei-ps4 -debugger-tune=gdb -filetype=obj -o %t.o < %s +; RUN: llvm-dwarfdump -debug-dump=pubnames %t.o | FileCheck --check-prefix=LINUX %s + ; ModuleID = 'dwarf-public-names.cpp' ; ; Generated from: