r241084 - Debug Info: Emit debug info for @import declarations.

David Blaikie dblaikie at gmail.com
Tue Jun 30 10:46:59 PDT 2015


On Tue, Jun 30, 2015 at 10:39 AM, Adrian Prantl <aprantl at apple.com> wrote:

> Author: adrian
> Date: Tue Jun 30 12:39:51 2015
> New Revision: 241084
>
> URL: http://llvm.org/viewvc/llvm-project?rev=241084&view=rev
> Log:
> Debug Info: Emit debug info for @import declarations.
>
> This allows a module-aware debugger such as LLDB to import the currently
> visible modules before dropping into the expression evaluator.
>
> rdar://problem/20965932
>
> Added:
>     cfe/trunk/test/Modules/Inputs/DebugModule.h
>     cfe/trunk/test/Modules/debug-info-moduleimport.m
> Modified:
>     cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>     cfe/trunk/lib/CodeGen/CGDebugInfo.h
>     cfe/trunk/lib/CodeGen/CodeGenModule.cpp
>     cfe/trunk/test/Modules/Inputs/module.map
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=241084&r1=241083&r2=241084&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Jun 30 12:39:51 2015
> @@ -27,6 +27,8 @@
>  #include "clang/Basic/SourceManager.h"
>  #include "clang/Basic/Version.h"
>  #include "clang/Frontend/CodeGenOptions.h"
> +#include "clang/Lex/HeaderSearchOptions.h"
> +#include "clang/Lex/PreprocessorOptions.h"
>  #include "llvm/ADT/SmallVector.h"
>  #include "llvm/ADT/StringExtras.h"
>  #include "llvm/IR/Constants.h"
> @@ -1661,6 +1663,49 @@ llvm::DIType *CGDebugInfo::CreateType(co
>    return CreateTypeDefinition(Ty, Unit);
>  }
>
> +llvm::DIModule *
> +CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor
> Mod) {
> +  llvm::DIModule *ModuleRef = nullptr;
> +  auto it = ModuleRefCache.find(Mod.Signature);
> +  if (it != ModuleRefCache.end())
> +    ModuleRef = it->second;
>

Early return to reduce indentation?


> +  else {
> +    // Macro definitions that were defined with "-D" on the command line.
> +    SmallString<128> ConfigMacros;
> +    {
> +      llvm::raw_svector_ostream OS(ConfigMacros);
> +      const auto &PPOpts = CGM.getPreprocessorOpts();
> +      unsigned I = 0;
> +      // Translate the macro definitions back into a commmand line.
> +      for (auto &M : PPOpts.Macros) {
> +        if (++I > 1)
> +          OS << " ";
> +        const std::string &Macro = M.first;
> +        bool Undef = M.second;
> +        OS << "\"-" << (Undef ? 'U' : 'D');
> +        for (char c : Macro)
> +          switch (c) {
> +          case '\\' : OS << "\\\\"; break;
> +          case '"'  : OS << "\\\""; break;
> +          default: OS << c;
> +          }
> +        OS << '\"';
> +      }
> +    }
> +    llvm::DIBuilder DIB(CGM.getModule());
> +    auto *CU = DIB.createCompileUnit(
> +        TheCU->getSourceLanguage(), internString(Mod.ModuleName),
> +        internString(Mod.Path), TheCU->getProducer(), true, StringRef(),
> 0,
> +        internString(Mod.ASTFile), llvm::DIBuilder::FullDebug,
> Mod.Signature);
> +    ModuleRef = DIB.createModule(
> +        CU, Mod.ModuleName, ConfigMacros, internString(Mod.Path),
> +        internString(CGM.getHeaderSearchOpts().Sysroot));
> +    DIB.finalize();
> +    ModuleRefCache.insert(std::make_pair(Mod.Signature, ModuleRef));
> +  }
> +  return ModuleRef;
> +}
> +
>  llvm::DIType *CGDebugInfo::CreateTypeDefinition(const ObjCInterfaceType
> *Ty,
>                                                  llvm::DIFile *Unit) {
>    ObjCInterfaceDecl *ID = Ty->getDecl();
> @@ -3304,6 +3349,15 @@ void CGDebugInfo::EmitUsingDecl(const Us
>          getLineNumber(USD.getLocation()));
>  }
>
> +void CGDebugInfo::EmitImportDecl(const ImportDecl &ID) {
> +  auto *Reader = CGM.getContext().getExternalSource();
> +  auto Info = Reader->getSourceDescriptor(*ID.getImportedModule());
> +  DBuilder.createImportedDeclaration(
> +    getCurrentContextDescriptor(cast<Decl>(ID.getDeclContext())),
> +                                getOrCreateModuleRef(Info),
> +                                getLineNumber(ID.getLocation()));
> +}
> +
>  llvm::DIImportedEntity *
>  CGDebugInfo::EmitNamespaceAlias(const NamespaceAliasDecl &NA) {
>    if (CGM.getCodeGenOpts().getDebugInfo() <
> CodeGenOptions::LimitedDebugInfo)
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.h?rev=241084&r1=241083&r2=241084&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.h (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.h Tue Jun 30 12:39:51 2015
> @@ -83,6 +83,9 @@ class CGDebugInfo {
>    /// which may change.
>    llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
>
> +  /// \brief Cache of references to AST files such as PCHs or modules.
> +  llvm::DenseMap<uint64_t, llvm::DIModule *> ModuleRefCache;
> +
>    /// \brief list of interfaces we want to keep even if orphaned.
>    std::vector<void *> RetainedTypes;
>
> @@ -289,6 +292,9 @@ public:
>    /// \brief Emit C++ using declaration.
>    void EmitUsingDecl(const UsingDecl &UD);
>
> +  /// \brief Emit an @import declaration.
> +  void EmitImportDecl(const ImportDecl &ID);
> +
>    /// \brief Emit C++ namespace alias.
>    llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl
> &NA);
>
> @@ -344,6 +350,10 @@ private:
>    /// necessary.
>    llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
>
> +  /// \brief Get a reference to a clang module.
> +  llvm::DIModule *
> +  getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod);
> +
>    /// \brief Get the type from the cache or create a new
>    /// partial type if necessary.
>    llvm::DIType *getOrCreateLimitedType(const RecordType *Ty, llvm::DIFile
> *F);
>
> Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=241084&r1=241083&r2=241084&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue Jun 30 12:39:51 2015
> @@ -3362,6 +3362,8 @@ void CodeGenModule::EmitTopLevelDecl(Dec
>            Owner->getTopLevelModule()->Name == getLangOpts().CurrentModule)
>          break;
>      }
> +    if (CGDebugInfo *DI = getModuleDebugInfo())
> +      DI->EmitImportDecl(*Import);
>
>      ImportedModules.insert(Import->getImportedModule());
>      break;
>
> Added: cfe/trunk/test/Modules/Inputs/DebugModule.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/DebugModule.h?rev=241084&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Modules/Inputs/DebugModule.h (added)
> +++ cfe/trunk/test/Modules/Inputs/DebugModule.h Tue Jun 30 12:39:51 2015
> @@ -0,0 +1 @@
> + at class F;
>
> Modified: cfe/trunk/test/Modules/Inputs/module.map
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/module.map?rev=241084&r1=241083&r2=241084&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/Modules/Inputs/module.map (original)
> +++ cfe/trunk/test/Modules/Inputs/module.map Tue Jun 30 12:39:51 2015
> @@ -327,3 +327,8 @@ module recursive2 {
>  module crash {
>    header "crash.h"
>  }
> +
> +module DebugModule {
> +  header "DebugModule.h"
> +}
> +
>
> Added: cfe/trunk/test/Modules/debug-info-moduleimport.m
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/debug-info-moduleimport.m?rev=241084&view=auto
>
> ==============================================================================
> --- cfe/trunk/test/Modules/debug-info-moduleimport.m (added)
> +++ cfe/trunk/test/Modules/debug-info-moduleimport.m Tue Jun 30 12:39:51
> 2015
> @@ -0,0 +1,7 @@
> +// RUN: rm -rf %t
> +// RUN: %clang_cc1 -g -fmodules -DGREETING="Hello World" -UNDEBUG
> -fimplicit-module-maps -fmodules-cache-path=%t %s -I %S/Inputs -isysroot
> /tmp/.. -I %t -emit-llvm -o - | FileCheck %s
> +
> +// CHECK: ![[CU:.*]] = !DICompileUnit
> + at import DebugModule;
> +// CHECK: !DIImportedEntity(tag: DW_TAG_imported_declaration, scope:
> ![[CU]], entity: ![[MODULE:.*]], line: 5)
> +// CHECK: ![[MODULE]] = !DIModule(scope: null, name: "DebugModule",
> configMacros: "\22-DGREETING=Hello World\22 \22-UNDEBUG\22", includePath:
> "{{.*}}/test/Modules/Inputs", isysroot: "/tmp/..")
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150630/422284cf/attachment.html>


More information about the cfe-commits mailing list