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 @@ -3252,6 +3252,7 @@ // are preserved, all other debug options are substituted with "-g". Args.ClaimAllArgs(options::OPT_g_Group); if (Arg *A = Args.getLastArg(options::OPT_g_Group)) { + const llvm::Triple &Triple = getToolChain().getTriple(); if (A->getOption().matches(options::OPT_gline_tables_only) || A->getOption().matches(options::OPT_g1)) { // FIXME: we should support specifying dwarf version with @@ -3272,7 +3273,6 @@ else if (!A->getOption().matches(options::OPT_g0) && !A->getOption().matches(options::OPT_ggdb0)) { // Default is dwarf-2 for Darwin, OpenBSD, FreeBSD and Solaris. - const llvm::Triple &Triple = getToolChain().getTriple(); if (Triple.isOSDarwin() || Triple.getOS() == llvm::Triple::OpenBSD || Triple.getOS() == llvm::Triple::FreeBSD || Triple.getOS() == llvm::Triple::Solaris) @@ -3280,6 +3280,17 @@ else CmdArgs.push_back("-g"); } + // Pass along the debugger target, or a target-specific default. + if (Arg *A = Args.getLastArg(options::OPT_ggdb, options::OPT_glldb, + options::OPT_gsce)) + CmdArgs.push_back(Args.MakeArgString(A->getSpelling())); + else if (Args.hasArg(options::OPT_ggdb1, options::OPT_ggdb2, + options::OPT_ggdb3)) + CmdArgs.push_back("-ggdb"); + else if (Triple.isOSDarwin()) + CmdArgs.push_back("-glldb"); + else if (Triple.isPS4CPU()) + CmdArgs.push_back("-gsce"); } // We ignore flags -gstrict-dwarf and -grecord-gcc-switches for now. Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -405,6 +405,13 @@ // 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); + Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns); Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone); Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables); Index: test/Driver/debug-options.c =================================================================== --- test/Driver/debug-options.c +++ test/Driver/debug-options.c @@ -2,30 +2,51 @@ // rdar://10383444 // RUN: %clang -### -c -g %s -target x86_64-linux-gnu 2>&1 \ - | FileCheck -check-prefix=G %s + | FileCheck -check-prefix=G -check-prefix=G_NOTARGET %s // RUN: %clang -### -c -g2 %s -target x86_64-linux-gnu 2>&1 \ - | FileCheck -check-prefix=G %s + | FileCheck -check-prefix=G -check-prefix=G_NOTARGET %s // RUN: %clang -### -c -g3 %s -target x86_64-linux-gnu 2>&1 \ - | FileCheck -check-prefix=G %s + | FileCheck -check-prefix=G -check-prefix=G_NOTARGET %s // RUN: %clang -### -c -ggdb %s -target x86_64-linux-gnu 2>&1 \ - | FileCheck -check-prefix=G %s + | FileCheck -check-prefix=G -check-prefix=G_GDB %s // RUN: %clang -### -c -ggdb1 %s -target x86_64-linux-gnu 2>&1 \ - | FileCheck -check-prefix=G %s + | FileCheck -check-prefix=G -check-prefix=G_GDB %s // RUN: %clang -### -c -ggdb3 %s -target x86_64-linux-gnu 2>&1 \ - | FileCheck -check-prefix=G %s + | FileCheck -check-prefix=G -check-prefix=G_GDB %s +// RUN: %clang -### -c -glldb %s -target x86_64-linux-gnu 2>&1 \ + | FileCheck -check-prefix=G -check-prefix=G_LLDB %s // RUN: %clang -### -c -g %s -target x86_64-apple-darwin 2>&1 \ - | FileCheck -check-prefix=G_DARWIN %s + | FileCheck -check-prefix=G_DARWIN -check-prefix=G_LLDB %s // RUN: %clang -### -c -g2 %s -target x86_64-apple-darwin 2>&1 \ - | FileCheck -check-prefix=G_DARWIN %s + | FileCheck -check-prefix=G_DARWIN -check-prefix=G_LLDB %s // RUN: %clang -### -c -g3 %s -target x86_64-apple-darwin 2>&1 \ - | FileCheck -check-prefix=G_DARWIN %s + | FileCheck -check-prefix=G_DARWIN -check-prefix=G_LLDB %s // RUN: %clang -### -c -ggdb %s -target x86_64-apple-darwin 2>&1 \ - | FileCheck -check-prefix=G_DARWIN %s + | FileCheck -check-prefix=G_DARWIN -check-prefix=G_GDB %s // RUN: %clang -### -c -ggdb1 %s -target x86_64-apple-darwin 2>&1 \ - | FileCheck -check-prefix=G_DARWIN %s + | FileCheck -check-prefix=G_DARWIN -check-prefix=G_GDB %s // RUN: %clang -### -c -ggdb3 %s -target x86_64-apple-darwin 2>&1 \ - | FileCheck -check-prefix=G_DARWIN %s + | FileCheck -check-prefix=G_DARWIN -check-prefix=G_GDB %s + +// RUN: %clang -### -c -g %s -target x86_64-scei-ps4 2>&1 \ + | FileCheck -check-prefix=G -check-prefix=G_SCE %s +// RUN: %clang -### -c -g2 %s -target x86_64-scei-ps4 2>&1 \ + | FileCheck -check-prefix=G -check-prefix=G_SCE %s +// RUN: %clang -### -c -g3 %s -target x86_64-scei-ps4 2>&1 \ + | FileCheck -check-prefix=G -check-prefix=G_SCE %s +// RUN: %clang -### -c -ggdb %s -target x86_64-scei-ps4 2>&1 \ + | FileCheck -check-prefix=G -check-prefix=G_GDB %s +// RUN: %clang -### -c -ggdb1 %s -target x86_64-scei-ps4 2>&1 \ + | FileCheck -check-prefix=G -check-prefix=G_GDB %s +// RUN: %clang -### -c -ggdb3 %s -target x86_64-scei-ps4 2>&1 \ + | FileCheck -check-prefix=G -check-prefix=G_GDB %s +// RUN: %clang -### -c -glldb %s -target x86_64-scei-ps4 2>&1 \ + | FileCheck -check-prefix=G -check-prefix=G_LLDB %s + +// RUN: %clang -### -c -ggdb -glldb -gsce %s 2>&1 | FileCheck -check-prefix=G_SCE %s +// RUN: %clang -### -c -glldb -gsce -ggdb %s 2>&1 | FileCheck -check-prefix=G_GDB %s +// RUN: %clang -### -c -gsce -ggdb -glldb %s 2>&1 | FileCheck -check-prefix=G_LLDB %s // RUN: %clang -### -c -gdwarf-2 %s 2>&1 | FileCheck -check-prefix=G_D2 %s // @@ -87,7 +108,7 @@ // G_D2: "-gdwarf-2" // // G_NO: "-cc1" -// G_NO-NOT: "-g" +// G_NO-NOT: "-g{{.*}}" // // GLTO_ONLY: "-cc1" // GLTO_ONLY-NOT: "-g" @@ -126,3 +147,11 @@ // CI: "-dwarf-column-info" // // NOCI-NOT: "-dwarf-column-info" +// +// G_NOTARGET-NOT: "-ggdb" +// G_NOTARGET-NOT: "-glldb" +// G_NOTARGET-NOT: "-gsce" +// +// G_GDB: "-ggdb" +// G_LLDB: "-glldb" +// G_SCE: "-gsce"