Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -1039,11 +1039,16 @@ def g1 : Flag<["-"], "g1">, Group; def g2 : Flag<["-"], "g2">, Group; def g3 : Flag<["-"], "g3">, Group; -def ggdb : Flag<["-"], "ggdb">, Group; +def ggdb : Flag<["-"], "ggdb">, Group, + HelpText<"Tune debug info for gdb">, Flags<[CC1Option]>; def ggdb0 : Flag<["-"], "ggdb0">, Group; def ggdb1 : Flag<["-"], "ggdb1">, Group; def ggdb2 : Flag<["-"], "ggdb2">, Group; def ggdb3 : Flag<["-"], "ggdb3">, Group; +def glldb : Flag<["-"], "glldb">, Group, + HelpText<"Tune debug info for lldb">, Flags<[CC1Option]>; +def gsce : Flag<["-"], "gsce">, Group, + HelpText<"Tune debug info for an SCE target (e.g. PS4)">, Flags<[CC1Option]>; def gdwarf_2 : Flag<["-"], "gdwarf-2">, Group, HelpText<"Generate source-level debug information with dwarf version 2">, Flags<[CC1Option,CC1AsOption]>; def gdwarf_3 : Flag<["-"], "gdwarf-3">, Group, Index: include/clang/Frontend/CodeGenOptions.h =================================================================== --- include/clang/Frontend/CodeGenOptions.h +++ include/clang/Frontend/CodeGenOptions.h @@ -16,6 +16,7 @@ #include "clang/Basic/Sanitizers.h" #include "llvm/Support/Regex.h" +#include "llvm/Target/TargetOptions.h" #include #include #include Index: include/clang/Frontend/CodeGenOptions.def =================================================================== --- include/clang/Frontend/CodeGenOptions.def +++ include/clang/Frontend/CodeGenOptions.def @@ -155,6 +155,9 @@ /// The kind of generated debug info. ENUM_CODEGENOPT(DebugInfo, DebugInfoKind, 3, NoDebugInfo) +/// Which debugger we are targeting. +ENUM_CODEGENOPT(Debugger, llvm::DebuggerKind, 2, llvm::DebuggerKind::GDB) + /// Dwarf version. VALUE_CODEGENOPT(DwarfVersion, 3, 0) Index: lib/CodeGen/BackendUtil.cpp =================================================================== --- lib/CodeGen/BackendUtil.cpp +++ lib/CodeGen/BackendUtil.cpp @@ -532,6 +532,7 @@ Options.FunctionSections = CodeGenOpts.FunctionSections; Options.DataSections = CodeGenOpts.DataSections; Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames; + Options.Debugger = CodeGenOpts.getDebugger(); Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll; Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels; Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -3281,6 +3281,11 @@ CmdArgs.push_back("-g"); } } + // Pass along the debugger target, if specified. + // FIXME: Write a 3-arg version of AddLastArg instead? + if (Arg *A = Args.getLastArg(options::OPT_ggdb, options::OPT_glldb, + options::OPT_gsce)) + CmdArgs.push_back(Args.MakeArgString(A->getSpelling())); // We ignore flags -gstrict-dwarf and -grecord-gcc-switches for now. Args.ClaimAllArgs(options::OPT_g_flags_Group); Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -405,6 +405,19 @@ // Default Dwarf version is 4 if we are generating debug information. Opts.DwarfVersion = 4; + if (Args.hasArg(OPT_ggdb)) + Opts.setDebugger(llvm::DebuggerKind::GDB); + else if (Args.hasArg(OPT_glldb)) + Opts.setDebugger(llvm::DebuggerKind::LLDB); + else if (Args.hasArg(OPT_gsce)) + Opts.setDebugger(llvm::DebuggerKind::SCE); + else if (llvm::Triple(TargetOpts.Triple).isOSDarwin()) + Opts.setDebugger(llvm::DebuggerKind::LLDB); + else if (llvm::Triple(TargetOpts.Triple).isPS4CPU()) + Opts.setDebugger(llvm::DebuggerKind::SCE); + else + Opts.setDebugger(llvm::DebuggerKind::GDB); + Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);