Index: include/llvm/CodeGen/CommandFlags.h =================================================================== --- include/llvm/CodeGen/CommandFlags.h +++ include/llvm/CodeGen/CommandFlags.h @@ -264,6 +264,17 @@ CFIFuncName("cfi-func-name", cl::desc("The name of the CFI function to call"), cl::init("")); +cl::opt +DebuggerTarget("debugger-target", + cl::desc("Tune debug info for a particular debugger"), + cl::init(DebuggerKind::Any), + 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() { @@ -296,6 +307,7 @@ Options.CFIType = CFIType; Options.CFIEnforcing = CFIEnforcing; Options.CFIFuncName = CFIFuncName; + Options.Debugger = DebuggerTarget; Options.ThreadModel = TMModel; Index: include/llvm/Target/TargetOptions.h =================================================================== --- include/llvm/Target/TargetOptions.h +++ include/llvm/Target/TargetOptions.h @@ -65,6 +65,13 @@ // feasible. }; + enum class DebuggerKind { + Any, // 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() @@ -82,7 +89,8 @@ TrapFuncName(), FloatABIType(FloatABI::Default), AllowFPOpFusion(FPOpFusion::Standard), JTType(JumpTable::Single), FCFI(false), ThreadModel(ThreadModel::POSIX), - CFIType(CFIntegrity::Sub), CFIEnforcing(false), CFIFuncName() {} + CFIType(CFIntegrity::Sub), CFIEnforcing(false), CFIFuncName(), + Debugger(DebuggerKind::Any) {} /// PrintMachineCode - This flag is enabled when the -print-machineinstrs /// option is specified on the command line, and should enable debugging @@ -261,6 +269,9 @@ std::string CFIFuncName; StringRef getCFIFuncName() const; + /// Which debugger are we expecting to consume the debug info? + DebuggerKind Debugger; + /// 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 { @@ -307,7 +309,6 @@ // True iff there are multiple CUs in this module. bool SingleCU; bool IsDarwin; - bool IsPS4; AddressPool AddrPool; @@ -527,6 +528,19 @@ /// standard DW_OP_form_tls_address opcode bool useGNUTLSOpcode() const { return UseGNUTLSOpcode; } + /// \defgroup DebuggerTarget Predicates for targeting a given debugger + /// @{ + bool isDebuggerGDB() const { + return Asm->TM.Options.Debugger == DebuggerKind::GDB; + } + bool isDebuggerLLDB() const { + return Asm->TM.Options.Debugger == DebuggerKind::LLDB; + } + bool isDebuggerSCE() const { + return Asm->TM.Options.Debugger == 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 @@ -194,7 +194,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, @@ -206,8 +205,18 @@ CurFn = nullptr; CurMI = nullptr; + // Make sure we have a "debugger target." + if (Asm->TM.Options.Debugger == DebuggerKind::Any) { + if (IsDarwin) + Asm->TM.Options.Debugger = DebuggerKind::LLDB; + else if (Triple(A->getTargetTriple()).isPS4CPU()) + Asm->TM.Options.Debugger = DebuggerKind::SCE; + else + Asm->TM.Options.Debugger = 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 @@ -219,7 +228,7 @@ HasSplitDwarf = SplitDwarf == Enable; if (DwarfPubSections == Default) - HasDwarfPubSections = !IsDarwin && !IsPS4; + HasDwarfPubSections = !IsDarwin && !isDebuggerSCE(); else HasDwarfPubSections = DwarfPubSections == Enable; @@ -227,9 +236,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 || isDebuggerGDB(); 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-target=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-target=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: