Index: include/clang/Driver/CC1AsOptions.td =================================================================== --- include/clang/Driver/CC1AsOptions.td +++ include/clang/Driver/CC1AsOptions.td @@ -85,6 +85,13 @@ def g : Flag<["-"], "g">, HelpText<"Generate source level debug information">; +def gdwarf_2 : Flag<["-"], "gdwarf-2">, + HelpText<"Generate source level debug information with dwarf version 2">; +def gdwarf_3 : Flag<["-"], "gdwarf-3">, + HelpText<"Generate source level debug information with dwarf version 3">; +def gdwarf_4 : Flag<["-"], "gdwarf-4">, + HelpText<"Generate source level debug information with dwarf version 4">; + def fdebug_compilation_dir : Separate<["-"], "fdebug-compilation-dir">, HelpText<"The compilation directory to embed in the debug info.">; Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -4068,6 +4068,13 @@ if (!A->getOption().matches(options::OPT_g0)) CmdArgs.push_back("-g"); + if (Args.hasArg(options::OPT_gdwarf_2)) + CmdArgs.push_back("-gdwarf-2"); + if (Args.hasArg(options::OPT_gdwarf_3)) + CmdArgs.push_back("-gdwarf-3"); + if (Args.hasArg(options::OPT_gdwarf_4)) + CmdArgs.push_back("-gdwarf-4"); + // Add the -fdebug-compilation-dir flag if needed. addDebugCompDirArg(Args, CmdArgs); Index: test/Driver/integrated-as.s =================================================================== --- test/Driver/integrated-as.s +++ test/Driver/integrated-as.s @@ -38,3 +38,12 @@ // COMPRESS_DEBUG_QUIET-NOT: warning: DWARF compression is not implemented // COMPRESS_DEBUG_QUIET-NOT: warning: argument unused during compilation // COMPRESS_DEBUG_QUIET: -cc1as + +// RUN: %clang -### -c -integrated-as %s -gdwarf-2 2>&1 | FileCheck --check-prefix=DWARF2 %s +// DWARF2: "-g" "-gdwarf-2" + +// RUN: %clang -### -c -integrated-as %s -gdwarf-3 2>&1 | FileCheck --check-prefix=DWARF3 %s +// DWARF3: "-g" "-gdwarf-3" + +// RUN: %clang -### -c -integrated-as %s -gdwarf-4 2>&1 | FileCheck --check-prefix=DWARF4 %s +// DWARF4: "-g" "-gdwarf-4" Index: tools/driver/cc1as_main.cpp =================================================================== --- tools/driver/cc1as_main.cpp +++ tools/driver/cc1as_main.cpp @@ -85,6 +85,7 @@ unsigned NoInitialTextSection : 1; unsigned SaveTemporaryLabels : 1; unsigned GenDwarfForAssembly : 1; + unsigned DwarfVersion; std::string DwarfDebugFlags; std::string DwarfDebugProducer; std::string DebugCompilationDir; @@ -135,6 +136,7 @@ ShowEncoding = 0; RelaxAll = 0; NoExecStack = 0; + DwarfVersion = 3; } static bool CreateFromArgs(AssemblerInvocation &Res, const char **ArgBegin, @@ -186,6 +188,13 @@ Opts.NoInitialTextSection = Args->hasArg(OPT_n); Opts.SaveTemporaryLabels = Args->hasArg(OPT_msave_temp_labels); Opts.GenDwarfForAssembly = Args->hasArg(OPT_g); + if (Args->hasArg(OPT_gdwarf_2)) + Opts.DwarfVersion = 2; + if (Args->hasArg(OPT_gdwarf_3)) + Opts.DwarfVersion = 3; + if (Args->hasArg(OPT_gdwarf_4)) + Opts.DwarfVersion = 4; + Opts.DwarfDebugFlags = Args->getLastArgValue(OPT_dwarf_debug_flags); Opts.DwarfDebugProducer = Args->getLastArgValue(OPT_dwarf_debug_producer); Opts.DebugCompilationDir = Args->getLastArgValue(OPT_fdebug_compilation_dir); @@ -318,6 +327,7 @@ Ctx.setCompilationDir(Opts.DebugCompilationDir); if (!Opts.MainFileName.empty()) Ctx.setMainFileName(StringRef(Opts.MainFileName)); + Ctx.setDwarfVersion(Opts.DwarfVersion); // Build up the feature string from the target feature list. std::string FS;