thanks!
On Thu, Jan 4, 2018 at 5:42 PM, Adrian Prantl via lldb-commits <lldb-commits@lists.llvm.org> wrote: > Author: adrian > Date: Thu Jan 4 08:42:05 2018 > New Revision: 321802 > > URL: http://llvm.org/viewvc/llvm-project?rev=321802&view=rev > Log: > Look for external types in all clang modules imported by the current symbol > file. > > This fixes a bug in -gmodules DWARF handling when debugging without a .dSYM > bundle > that was particularly noticable when debugging LLVM itself. > > Debugging without clang modules and DWO handling should be unaffected by this > patch. > > <rdar://problem/32436209> > > Added: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/ > > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/Makefile > > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/TestGModules.py > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/a.h > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/b.h > > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/main.cpp > > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/memory.h > > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/module.modulemap > Modified: > lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp > lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp > lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h > > Added: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/Makefile > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/Makefile?rev=321802&view=auto > ============================================================================== > --- > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/Makefile > (added) > +++ > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/Makefile > Thu Jan 4 08:42:05 2018 > @@ -0,0 +1,6 @@ > +LEVEL = ../../../make > + > +CXX_SOURCES = main.cpp > +# CFLAGS_EXTRAS += $(MODULE_DEBUG_INFO_FLAGS) > + > +include $(LEVEL)/Makefile.rules > > Added: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/TestGModules.py > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/TestGModules.py?rev=321802&view=auto > ============================================================================== > --- > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/TestGModules.py > (added) > +++ > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/TestGModules.py > Thu Jan 4 08:42:05 2018 > @@ -0,0 +1,4 @@ > +import lldbsuite.test.lldbinline as lldbinline > +import lldbsuite.test.decorators > + > +lldbinline.MakeInlineTest(__file__, globals()) > > Added: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/a.h > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/a.h?rev=321802&view=auto > ============================================================================== > --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/a.h > (added) > +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/a.h > Thu Jan 4 08:42:05 2018 > @@ -0,0 +1,7 @@ > +#include "memory.h" > + > +class MemoryBuffer { int buffer = 42; }; > + > +struct SrcBuffer { > + my_std::unique_ptr<MemoryBuffer> Buffer; > +}; > > Added: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/b.h > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/b.h?rev=321802&view=auto > ============================================================================== > --- lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/b.h > (added) > +++ lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/b.h > Thu Jan 4 08:42:05 2018 > @@ -0,0 +1,6 @@ > +#include "a.h" > +#include "memory.h" > + > +class Module { > + my_std::unique_ptr<MemoryBuffer> MBptr; > +}; > > Added: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/main.cpp > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/main.cpp?rev=321802&view=auto > ============================================================================== > --- > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/main.cpp > (added) > +++ > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/main.cpp > Thu Jan 4 08:42:05 2018 > @@ -0,0 +1,9 @@ > +#include "b.h" > + > +int main(int argc, const char * argv[]) > +{ > + Module m; > + // Test that the type Module which contains a field that is a > + // template instantiation can be fully resolved. > + return 0; //% > self.assertTrue(self.frame().FindVariable('m').GetChildAtIndex(0).GetChildAtIndex(0).GetChildAtIndex(0).GetName() > == 'buffer', 'find template specializations in imported modules') > +} > > Added: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/memory.h > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/memory.h?rev=321802&view=auto > ============================================================================== > --- > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/memory.h > (added) > +++ > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/memory.h > Thu Jan 4 08:42:05 2018 > @@ -0,0 +1,8 @@ > +#ifndef MEMORY_H > +#define MEMORY_H > +namespace my_std { > + template<class T> class unique_ptr { > + T t; > + }; > +} > +#endif > > Added: > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/module.modulemap > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/module.modulemap?rev=321802&view=auto > ============================================================================== > --- > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/module.modulemap > (added) > +++ > lldb/trunk/packages/Python/lldbsuite/test/lang/cpp/gmodules-templates/module.modulemap > Thu Jan 4 08:42:05 2018 > @@ -0,0 +1,11 @@ > +module A { > + header "a.h" > +} > + > +module B { > + header "b.h" > +} > + > +module std { > + header "memory.h" > +} > > Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp?rev=321802&r1=321801&r2=321802&view=diff > ============================================================================== > --- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp > (original) > +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp Thu > Jan 4 08:42:05 2018 > @@ -17,6 +17,7 @@ > #include "DWARFDeclContext.h" > #include "DWARFDefines.h" > #include "SymbolFileDWARF.h" > +#include "SymbolFileDWARFDwo.h" > #include "SymbolFileDWARFDebugMap.h" > #include "UniqueDWARFASTType.h" > > @@ -123,57 +124,86 @@ ClangASTImporter &DWARFASTParserClang::G > return *m_clang_ast_importer_ap; > } > > +/// Detect a forward declaration that is nested in a DW_TAG_module. > +static bool isClangModuleFwdDecl(const DWARFDIE &Die) { > + if (!Die.GetAttributeValueAsUnsigned(DW_AT_declaration, 0)) > + return false; > + auto Parent = Die.GetParent(); > + while (Parent.IsValid()) { > + if (Parent.Tag() == DW_TAG_module) > + return true; > + Parent = Parent.GetParent(); > + } > + return false; > +} > + > TypeSP DWARFASTParserClang::ParseTypeFromDWO(const DWARFDIE &die, Log *log) { > ModuleSP dwo_module_sp = die.GetContainingDWOModule(); > - if (dwo_module_sp) { > - // This type comes from an external DWO module > - std::vector<CompilerContext> dwo_context; > - die.GetDWOContext(dwo_context); > - TypeMap dwo_types; > - if (dwo_module_sp->GetSymbolVendor()->FindTypes(dwo_context, true, > - dwo_types)) { > - const size_t num_dwo_types = dwo_types.GetSize(); > - if (num_dwo_types == 1) { > - // We found a real definition for this type elsewhere > - // so lets use it and cache the fact that we found > - // a complete type for this die > - TypeSP dwo_type_sp = dwo_types.GetTypeAtIndex(0); > - if (dwo_type_sp) { > - lldb_private::CompilerType dwo_type = > - dwo_type_sp->GetForwardCompilerType(); > - > - lldb_private::CompilerType type = > - GetClangASTImporter().CopyType(m_ast, dwo_type); > - > - // printf ("copied_qual_type: ast = %p, clang_type = %p, name = > - // '%s'\n", m_ast, copied_qual_type.getAsOpaquePtr(), > - // external_type->GetName().GetCString()); > - if (type) { > - SymbolFileDWARF *dwarf = die.GetDWARF(); > - TypeSP type_sp(new Type(die.GetID(), dwarf, > dwo_type_sp->GetName(), > - dwo_type_sp->GetByteSize(), NULL, > - LLDB_INVALID_UID, Type::eEncodingInvalid, > - &dwo_type_sp->GetDeclaration(), type, > - Type::eResolveStateForward)); > - > - dwarf->GetTypeList()->Insert(type_sp); > - dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); > - clang::TagDecl *tag_decl = ClangASTContext::GetAsTagDecl(type); > - if (tag_decl) > - LinkDeclContextToDIE(tag_decl, die); > - else { > - clang::DeclContext *defn_decl_ctx = > - GetCachedClangDeclContextForDIE(die); > - if (defn_decl_ctx) > - LinkDeclContextToDIE(defn_decl_ctx, die); > - } > - return type_sp; > - } > - } > - } > + if (!dwo_module_sp) > + return TypeSP(); > + > + // This type comes from an external DWO module. > + std::vector<CompilerContext> dwo_context; > + die.GetDWOContext(dwo_context); > + TypeMap dwo_types; > + > + if (!dwo_module_sp->GetSymbolVendor()->FindTypes(dwo_context, true, > + dwo_types)) { > + if (!isClangModuleFwdDecl(die)) > + return TypeSP(); > + > + // Since this this type is defined in one of the Clang modules > + // imported by this symbol file, search all of them. > + auto *SymFile = die.GetCU()->GetSymbolFileDWARF(); > + for (const auto &NameModule : SymFile->getExternalTypeModules()) { > + if (!NameModule.second) > + continue; > + SymbolVendor *SymVendor = NameModule.second->GetSymbolVendor(); > + if (SymVendor->FindTypes(dwo_context, true, dwo_types)) > + break; > } > } > - return TypeSP(); > + > + const size_t num_dwo_types = dwo_types.GetSize(); > + if (num_dwo_types != 1) > + return TypeSP(); > + > + // We found a real definition for this type in the Clang module, so > + // lets use it and cache the fact that we found a complete type for > + // this die. > + TypeSP dwo_type_sp = dwo_types.GetTypeAtIndex(0); > + if (!dwo_type_sp) > + return TypeSP(); > + > + lldb_private::CompilerType dwo_type = > dwo_type_sp->GetForwardCompilerType(); > + > + lldb_private::CompilerType type = > + GetClangASTImporter().CopyType(m_ast, dwo_type); > + > + // printf ("copied_qual_type: ast = %p, clang_type = %p, name = > + // '%s'\n", m_ast, copied_qual_type.getAsOpaquePtr(), > + // external_type->GetName().GetCString()); > + if (!type) > + return TypeSP(); > + > + SymbolFileDWARF *dwarf = die.GetDWARF(); > + TypeSP type_sp(new Type( > + die.GetID(), dwarf, dwo_type_sp->GetName(), dwo_type_sp->GetByteSize(), > + NULL, LLDB_INVALID_UID, Type::eEncodingInvalid, > + &dwo_type_sp->GetDeclaration(), type, Type::eResolveStateForward)); > + > + dwarf->GetTypeList()->Insert(type_sp); > + dwarf->GetDIEToType()[die.GetDIE()] = type_sp.get(); > + clang::TagDecl *tag_decl = ClangASTContext::GetAsTagDecl(type); > + if (tag_decl) > + LinkDeclContextToDIE(tag_decl, die); > + else { > + clang::DeclContext *defn_decl_ctx = GetCachedClangDeclContextForDIE(die); > + if (defn_decl_ctx) > + LinkDeclContextToDIE(defn_decl_ctx, die); > + } > + > + return type_sp; > } > > TypeSP DWARFASTParserClang::ParseTypeFromDWARF(const SymbolContext &sc, > > Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp?rev=321802&r1=321801&r2=321802&view=diff > ============================================================================== > --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (original) > +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp Thu Jan 4 > 08:42:05 2018 > @@ -1562,7 +1562,7 @@ std::unique_ptr<SymbolFileDWARFDwo> > SymbolFileDWARF::GetDwoSymbolFileForCompileUnit( > DWARFCompileUnit &dwarf_cu, const DWARFDebugInfoEntry &cu_die) { > // If we are using a dSYM file, we never want the standard DWO files since > - // the -gmodule support uses the same DWO machanism to specify full debug > + // the -gmodules support uses the same DWO machanism to specify full debug > // info files for modules. > if (GetDebugMapSymfile()) > return nullptr; > > Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h > URL: > http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h?rev=321802&r1=321801&r2=321802&view=diff > ============================================================================== > --- lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h (original) > +++ lldb/trunk/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Thu Jan 4 > 08:42:05 2018 > @@ -293,6 +293,14 @@ public: > > lldb::ModuleSP GetDWOModule(lldb_private::ConstString name); > > + typedef std::map<lldb_private::ConstString, lldb::ModuleSP> > + ExternalTypeModuleMap; > + > + /// Return the list of Clang modules imported by this SymbolFile. > + const ExternalTypeModuleMap& getExternalTypeModules() const { > + return m_external_type_modules; > + } > + > virtual DWARFDIE GetDIE(const DIERef &die_ref); > > virtual std::unique_ptr<SymbolFileDWARFDwo> > @@ -439,9 +447,6 @@ protected: > > typedef std::set<lldb_private::Type *> TypeSet; > > - typedef std::map<lldb_private::ConstString, lldb::ModuleSP> > - ExternalTypeModuleMap; > - > void GetTypes(const DWARFDIE &die, dw_offset_t min_die_offset, > dw_offset_t max_die_offset, uint32_t type_mask, > TypeSet &type_set); > > > _______________________________________________ > lldb-commits mailing list > lldb-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits