Author: adrian Date: Thu Aug 27 14:46:20 2015 New Revision: 246192 URL: http://llvm.org/viewvc/llvm-project?rev=246192&view=rev Log: Add a -gmodules option to the driver and a -dwarf-ext-refs to cc1 to enable the use of external type references in the debug info (a.k.a. module debugging).
The driver expands -gmodules to "-g -fmodule-format=obj -dwarf-ext-refs" and passes that to cc1. All this does at the moment is set a flag codegenopts. http://reviews.llvm.org/D11958 Modified: cfe/trunk/docs/CommandGuide/clang.rst cfe/trunk/include/clang/Driver/CC1Options.td cfe/trunk/include/clang/Driver/Options.td cfe/trunk/include/clang/Frontend/ASTUnit.h cfe/trunk/include/clang/Frontend/CodeGenOptions.def cfe/trunk/include/clang/Lex/HeaderSearchOptions.h cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp cfe/trunk/lib/Driver/Tools.cpp cfe/trunk/lib/Frontend/ASTUnit.cpp cfe/trunk/lib/Frontend/CompilerInvocation.cpp cfe/trunk/lib/Frontend/FrontendAction.cpp cfe/trunk/lib/Lex/HeaderSearch.cpp cfe/trunk/test/Driver/debug-options.c cfe/trunk/tools/libclang/CIndex.cpp Modified: cfe/trunk/docs/CommandGuide/clang.rst URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/CommandGuide/clang.rst?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/docs/CommandGuide/clang.rst (original) +++ cfe/trunk/docs/CommandGuide/clang.rst Thu Aug 27 14:46:20 2015 @@ -257,6 +257,13 @@ Code Generation Options Generate debug information. Note that Clang debug information works best at -O0. +.. option:: -gmodules + + Generate debug information that contains external references to + types defined in clang modules or precompiled headers instead of + emitting redundant debug type information into every object file. + This option implies `-fmodule-format=obj`. + .. option:: -fstandalone-debug -fno-standalone-debug Clang supports a number of optimizations to reduce the size of debug Modified: cfe/trunk/include/clang/Driver/CC1Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/CC1Options.td (original) +++ cfe/trunk/include/clang/Driver/CC1Options.td Thu Aug 27 14:46:20 2015 @@ -167,6 +167,9 @@ def gnu_pubnames : Flag<["-"], "gnu-pubn HelpText<"Emit newer GNU style pubnames">; def arange_sections : Flag<["-"], "arange_sections">, HelpText<"Emit DWARF .debug_arange sections">; +def dwarf_ext_refs : Flag<["-"], "dwarf-ext-refs">, + HelpText<"Generate debug info with external references to clang modules" + " or precompiled headers">; def fforbid_guard_variables : Flag<["-"], "fforbid-guard-variables">, HelpText<"Emit an error if a C++ static local initializer would need a guard variable">; def no_implicit_float : Flag<["-"], "no-implicit-float">, Modified: cfe/trunk/include/clang/Driver/Options.td URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/include/clang/Driver/Options.td (original) +++ cfe/trunk/include/clang/Driver/Options.td Thu Aug 27 14:46:20 2015 @@ -1133,6 +1133,9 @@ def gno_column_info : Flag<["-"], "gno-c def gsplit_dwarf : Flag<["-"], "gsplit-dwarf">, Group<g_flags_Group>; def ggnu_pubnames : Flag<["-"], "ggnu-pubnames">, Group<g_flags_Group>; def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group<g_flags_Group>; +def gmodules : Flag <["-"], "gmodules">, Group<f_Group>, + HelpText<"Generate debug info with external references to clang modules" + " or precompiled headers">; def headerpad__max__install__names : Joined<["-"], "headerpad_max_install_names">; def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption]>, HelpText<"Display available options">; Modified: cfe/trunk/include/clang/Frontend/ASTUnit.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/ASTUnit.h?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/ASTUnit.h (original) +++ cfe/trunk/include/clang/Frontend/ASTUnit.h Thu Aug 27 14:46:20 2015 @@ -728,8 +728,8 @@ public: static std::unique_ptr<ASTUnit> LoadFromASTFile( const std::string &Filename, const PCHContainerReader &PCHContainerRdr, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls = false, - ArrayRef<RemappedFile> RemappedFiles = None, + const FileSystemOptions &FileSystemOpts, bool UseDebugInfo = false, + bool OnlyLocalDecls = false, ArrayRef<RemappedFile> RemappedFiles = None, bool CaptureDiagnostics = false, bool AllowPCHWithCompilerErrors = false, bool UserFilesAreVolatile = false); Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original) +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Thu Aug 27 14:46:20 2015 @@ -161,6 +161,9 @@ VALUE_CODEGENOPT(StackProbeSize , 32, CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information ///< in debug info. +CODEGENOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should contain + ///< external references to a PCH or module. + CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists. /// The user specified number of registers to be used for integral arguments, Modified: cfe/trunk/include/clang/Lex/HeaderSearchOptions.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearchOptions.h?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/include/clang/Lex/HeaderSearchOptions.h (original) +++ cfe/trunk/include/clang/Lex/HeaderSearchOptions.h Thu Aug 27 14:46:20 2015 @@ -169,7 +169,9 @@ public: /// \brief Whether to validate system input files when a module is loaded. unsigned ModulesValidateSystemHeaders : 1; -public: + /// Whether the module includes debug information (-gmodules). + unsigned UseDebugInfo : 1; + HeaderSearchOptions(StringRef _Sysroot = "/") : Sysroot(_Sysroot), ModuleFormat("raw"), DisableModuleHash(0), ImplicitModuleMaps(0), ModuleMapFileHomeIsCwd(0), @@ -178,7 +180,8 @@ public: UseBuiltinIncludes(true), UseStandardSystemIncludes(true), UseStandardCXXIncludes(true), UseLibcxx(false), Verbose(false), ModulesValidateOncePerBuildSession(false), - ModulesValidateSystemHeaders(false) {} + ModulesValidateSystemHeaders(false), + UseDebugInfo(false) {} /// AddPath - Add the \p Path path to the specified \p Group list. void AddPath(StringRef Path, frontend::IncludeDirGroup Group, Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Thu Aug 27 14:46:20 2015 @@ -45,6 +45,7 @@ using namespace clang::CodeGen; CGDebugInfo::CGDebugInfo(CodeGenModule &CGM) : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()), + DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs), DBuilder(CGM.getModule()) { CreateCompileUnit(); } Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original) +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Thu Aug 27 14:46:20 2015 @@ -52,6 +52,7 @@ class CGDebugInfo { friend class SaveAndRestoreLocation; CodeGenModule &CGM; const CodeGenOptions::DebugInfoKind DebugKind; + bool DebugTypeExtRefs; llvm::DIBuilder DBuilder; llvm::DICompileUnit *TheCU = nullptr; SourceLocation CurLoc; Modified: cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp (original) +++ cfe/trunk/lib/CodeGen/ObjectFilePCHContainerOperations.cpp Thu Aug 27 14:46:20 2015 @@ -64,6 +64,7 @@ public: // ThreadModel, but the backend expects them to be nonempty. CodeGenOpts.CodeModel = "default"; CodeGenOpts.ThreadModel = "single"; + CodeGenOpts.DebugTypeExtRefs = true; CodeGenOpts.setDebugInfo(CodeGenOptions::FullDebugInfo); CodeGenOpts.SplitDwarfFile = OutputFileName; } Modified: cfe/trunk/lib/Driver/Tools.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/lib/Driver/Tools.cpp (original) +++ cfe/trunk/lib/Driver/Tools.cpp Thu Aug 27 14:46:20 2015 @@ -3739,6 +3739,12 @@ void Clang::ConstructJob(Compilation &C, CmdArgs.push_back("-dwarf-column-info"); // FIXME: Move backend command line options to the module. + if (Args.hasArg(options::OPT_gmodules)) { + CmdArgs.push_back("-g"); + CmdArgs.push_back("-dwarf-ext-refs"); + CmdArgs.push_back("-fmodule-format=obj"); + } + // -gsplit-dwarf should turn on -g and enable the backend dwarf // splitting and extraction. // FIXME: Currently only works on Linux. Modified: cfe/trunk/lib/Frontend/ASTUnit.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/ASTUnit.cpp?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/ASTUnit.cpp (original) +++ cfe/trunk/lib/Frontend/ASTUnit.cpp Thu Aug 27 14:46:20 2015 @@ -649,12 +649,12 @@ void ASTUnit::ConfigureDiags(IntrusiveRe } std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile( - const std::string &Filename, - const PCHContainerReader &PCHContainerRdr, + const std::string &Filename, const PCHContainerReader &PCHContainerRdr, IntrusiveRefCntPtr<DiagnosticsEngine> Diags, - const FileSystemOptions &FileSystemOpts, bool OnlyLocalDecls, - ArrayRef<RemappedFile> RemappedFiles, bool CaptureDiagnostics, - bool AllowPCHWithCompilerErrors, bool UserFilesAreVolatile) { + const FileSystemOptions &FileSystemOpts, bool UseDebugInfo, + bool OnlyLocalDecls, ArrayRef<RemappedFile> RemappedFiles, + bool CaptureDiagnostics, bool AllowPCHWithCompilerErrors, + bool UserFilesAreVolatile) { std::unique_ptr<ASTUnit> AST(new ASTUnit(true)); // Recover resources if we crash before exiting this method. Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original) +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Thu Aug 27 14:46:20 2015 @@ -424,6 +424,7 @@ static bool ParseCodeGenArgs(CodeGenOpti Opts.DwarfVersion = 3; else if (Args.hasArg(OPT_gdwarf_4)) Opts.DwarfVersion = 4; + Opts.DebugTypeExtRefs = Args.hasArg(OPT_dwarf_ext_refs); if (const Arg *A = Args.getLastArg(OPT_emit_llvm_uselists, OPT_no_emit_llvm_uselists)) Modified: cfe/trunk/lib/Frontend/FrontendAction.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/FrontendAction.cpp?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/lib/Frontend/FrontendAction.cpp (original) +++ cfe/trunk/lib/Frontend/FrontendAction.cpp Thu Aug 27 14:46:20 2015 @@ -190,9 +190,9 @@ bool FrontendAction::BeginSourceFile(Com IntrusiveRefCntPtr<DiagnosticsEngine> Diags(&CI.getDiagnostics()); - std::unique_ptr<ASTUnit> AST = - ASTUnit::LoadFromASTFile(InputFile, CI.getPCHContainerReader(), - Diags, CI.getFileSystemOpts()); + std::unique_ptr<ASTUnit> AST = ASTUnit::LoadFromASTFile( + InputFile, CI.getPCHContainerReader(), Diags, CI.getFileSystemOpts(), + CI.getCodeGenOpts().DebugTypeExtRefs); if (!AST) goto failure; Modified: cfe/trunk/lib/Lex/HeaderSearch.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/HeaderSearch.cpp?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/lib/Lex/HeaderSearch.cpp (original) +++ cfe/trunk/lib/Lex/HeaderSearch.cpp Thu Aug 27 14:46:20 2015 @@ -154,7 +154,7 @@ std::string HeaderSearch::getModuleFileN llvm::hash_code Hash = llvm::hash_combine(DirName.lower(), FileName.lower(), - HSOpts->ModuleFormat); + HSOpts->ModuleFormat, HSOpts->UseDebugInfo); SmallString<128> HashStr; llvm::APInt(64, size_t(Hash)).toStringUnsigned(HashStr, /*Radix*/36); Modified: cfe/trunk/test/Driver/debug-options.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/debug-options.c?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/test/Driver/debug-options.c (original) +++ cfe/trunk/test/Driver/debug-options.c Thu Aug 27 14:46:20 2015 @@ -77,6 +77,9 @@ // // RUN: %clang -### -g %s 2>&1 | FileCheck -check-prefix=CI %s // +// RUN: %clang -### -gmodules %s 2>&1 \ +// RUN: | FileCheck -check-prefix=GEXTREFS %s +// // G: "-cc1" // G: "-g" // @@ -126,3 +129,5 @@ // CI: "-dwarf-column-info" // // NOCI-NOT: "-dwarf-column-info" +// +// GEXTREFS: "-g" "-dwarf-ext-refs" "-fmodule-format=obj" Modified: cfe/trunk/tools/libclang/CIndex.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=246192&r1=246191&r2=246192&view=diff ============================================================================== --- cfe/trunk/tools/libclang/CIndex.cpp (original) +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 27 14:46:20 2015 @@ -2971,7 +2971,8 @@ enum CXErrorCode clang_createTranslation CompilerInstance::createDiagnostics(new DiagnosticOptions()); std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile( ast_filename, CXXIdx->getPCHContainerOperations()->getRawReader(), Diags, - FileSystemOpts, CXXIdx->getOnlyLocalDecls(), None, + FileSystemOpts, /*UseDebugInfo=*/false, + CXXIdx->getOnlyLocalDecls(), None, /*CaptureDiagnostics=*/true, /*AllowPCHWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/true); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits