zturner created this revision.
zturner added a reviewer: clayborg.
zturner added a subscriber: lldb-commits.

ClangASTContext was assuming the presence of DWARF debug info, so it was baked 
into the class that DWARFASTParserClang would be used.  This won't be the case 
with PDB, which will need a PDBASTParserClang.  This will be used for PDB's 
generated by MSVC (since it is ABI compatible with clang-cl) as well as (in the 
future) PDBs generated directly by clang.

For now PDBASTParserClang is not implemented, this only breaks up the 
DWARFASTParser class into an abstraction that is not dwarf dependent, and has 
ClangASTContext deal only with this abstraction, while SymbolFileDWARF can deal 
directly with the DWARFASTParser.

http://reviews.llvm.org/D18194

Files:
  include/lldb/Symbol/ClangASTContext.h
  include/lldb/Symbol/DebugInfoASTParser.h
  include/lldb/Symbol/GoASTContext.h
  include/lldb/Symbol/JavaASTContext.h
  include/lldb/Symbol/SymbolFile.h
  include/lldb/Symbol/TypeSystem.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
  source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
  source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
  source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
  source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
  source/Symbol/ClangASTContext.cpp
  source/Symbol/GoASTContext.cpp
  source/Symbol/JavaASTContext.cpp

Index: source/Symbol/JavaASTContext.cpp
===================================================================
--- source/Symbol/JavaASTContext.cpp
+++ source/Symbol/JavaASTContext.cpp
@@ -496,8 +496,8 @@
     return m_pointer_byte_size;
 }
 
-DWARFASTParser *
-JavaASTContext::GetDWARFParser()
+DebugInfoASTParser *
+JavaASTContext::GetDebugInfoASTParser()
 {
     if (!m_dwarf_ast_parser_ap)
         m_dwarf_ast_parser_ap.reset(new DWARFASTParserJava(*this));
Index: source/Symbol/GoASTContext.cpp
===================================================================
--- source/Symbol/GoASTContext.cpp
+++ source/Symbol/GoASTContext.cpp
@@ -1639,8 +1639,8 @@
     return (kind & GoType::KIND_DIRECT_IFACE) == GoType::KIND_DIRECT_IFACE;
 }
 
-DWARFASTParser *
-GoASTContext::GetDWARFParser()
+DebugInfoASTParser *
+GoASTContext::GetDebugInfoASTParser()
 {
     if (!m_dwarf_ast_parser_ap)
         m_dwarf_ast_parser_ap.reset(new DWARFASTParserGo(*this));
Index: source/Symbol/ClangASTContext.cpp
===================================================================
--- source/Symbol/ClangASTContext.cpp
+++ source/Symbol/ClangASTContext.cpp
@@ -9653,16 +9653,17 @@
     }
 }
 
-
-DWARFASTParser *
-ClangASTContext::GetDWARFParser ()
+DebugInfoASTParser *
+ClangASTContext::GetDebugInfoASTParser()
 {
-    if (!m_dwarf_ast_parser_ap)
-        m_dwarf_ast_parser_ap.reset(new DWARFASTParserClang(*this));
-    return m_dwarf_ast_parser_ap.get();
+    if (!m_di_ast_parser_ap)
+    {
+        if (m_sym_file->GetSymbolFileFormat() == SymbolFileFormat::DWARF)
+            m_di_ast_parser_ap.reset(new DWARFASTParserClang(*this));
+    }
+    return m_di_ast_parser_ap.get();
 }
 
-
 bool
 ClangASTContext::LayoutRecordType(void *baton,
                                   const clang::RecordDecl *record_decl,
@@ -9673,8 +9674,9 @@
                                   llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
 {
     ClangASTContext *ast = (ClangASTContext *)baton;
-    DWARFASTParserClang *dwarf_ast_parser = (DWARFASTParserClang *)ast->GetDWARFParser();
-    return dwarf_ast_parser->LayoutRecordType(record_decl, bit_size, alignment, field_offsets, base_offsets, vbase_offsets);
+    DebugInfoASTParser *di_ast_parser = ast->GetDebugInfoASTParser();
+    return di_ast_parser->LayoutRecordType(record_decl, bit_size, alignment, field_offsets, base_offsets,
+                                           vbase_offsets);
 }
 
 //----------------------------------------------------------------------
Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
===================================================================
--- source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
+++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.h
@@ -55,6 +55,9 @@
     void
     InitializeObject() override;
 
+    lldb_private::SymbolFileFormat
+    GetSymbolFileFormat() const override;
+
     //------------------------------------------------------------------
     // Compile Unit function calls
     //------------------------------------------------------------------
Index: source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
===================================================================
--- source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
+++ source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp
@@ -118,6 +118,12 @@
     m_session_up->setLoadAddress(obj_load_address);
 }
 
+lldb_private::SymbolFileFormat
+SymbolFilePDB::GetSymbolFileFormat() const
+{
+    return SymbolFileFormat::PDB;
+}
+
 uint32_t
 SymbolFilePDB::GetNumCompileUnits()
 {
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -107,6 +107,9 @@
     void
     InitializeObject() override;
 
+    lldb_private::SymbolFileFormat
+    GetSymbolFileFormat() const override;
+
     //------------------------------------------------------------------
     // Compile Unit function calls
     //------------------------------------------------------------------
@@ -243,7 +246,6 @@
                    const lldb_private::ConstString &name,
                    const lldb_private::CompilerDeclContext *parent_decl_ctx) override;
 
-
     //------------------------------------------------------------------
     // PluginInterface protocol
     //------------------------------------------------------------------
Index: source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -569,6 +569,12 @@
     }
 }
 
+SymbolFileFormat
+SymbolFileDWARF::GetSymbolFileFormat() const
+{
+    return SymbolFileFormat::DWARF;
+}
+
 bool
 SymbolFileDWARF::SupportedVersion(uint16_t version)
 {
@@ -996,7 +1002,7 @@
 
         if (type_system)
         {
-            DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+            DWARFASTParser *dwarf_ast = llvm::dyn_cast_or_null<DWARFASTParser>(type_system->GetDebugInfoASTParser());
             if (dwarf_ast)
                 return dwarf_ast->ParseFunctionFromDWARF(sc, die);
         }
@@ -1461,7 +1467,7 @@
 SymbolFileDWARF::ParseDeclsForContext (CompilerDeclContext decl_ctx)
 {
     TypeSystem *type_system = decl_ctx.GetTypeSystem();
-    DWARFASTParser *ast_parser = type_system->GetDWARFParser();
+    DWARFASTParser *ast_parser = llvm::dyn_cast_or_null<DWARFASTParser>(type_system->GetDebugInfoASTParser());
     std::vector<DWARFDIE> decl_ctx_die_list = ast_parser->GetDIEForDeclContext(decl_ctx);
 
     for (DWARFDIE decl_ctx_die : decl_ctx_die_list)
@@ -1611,9 +1617,9 @@
     TypeSystem *type_system = compiler_type.GetTypeSystem();
     if (type_system)
     {
-        DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
-        if (dwarf_ast)
-            return dwarf_ast->CanCompleteType(compiler_type);
+        DebugInfoASTParser *ast_parser = type_system->GetDebugInfoASTParser();
+        if (ast_parser)
+            return ast_parser->CanCompleteType(compiler_type);
     }
     return false;
 }
@@ -1627,7 +1633,7 @@
     TypeSystem *type_system = compiler_type.GetTypeSystem();
     if (type_system)
     {
-        DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+        DebugInfoASTParser *dwarf_ast = type_system->GetDebugInfoASTParser();
         if (dwarf_ast && dwarf_ast->CanCompleteType(compiler_type))
             return dwarf_ast->CompleteType(compiler_type);
     }
@@ -3823,7 +3829,7 @@
 
         if (type_system)
         {
-            DWARFASTParser *dwarf_ast = type_system->GetDWARFParser();
+            DWARFASTParser *dwarf_ast = llvm::dyn_cast_or_null<DWARFASTParser>(type_system->GetDebugInfoASTParser());
             if (dwarf_ast)
             {
                 Log *log = LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO);
Index: source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
+++ source/Plugins/SymbolFile/DWARF/DWARFDIE.cpp
@@ -9,18 +9,20 @@
 
 #include "DWARFDIE.h"
 
+#include "DWARFASTParser.h"
 #include "DWARFCompileUnit.h"
+#include "DWARFDIECollection.h"
 #include "DWARFDebugAbbrev.h"
 #include "DWARFDebugAranges.h"
 #include "DWARFDebugInfo.h"
 #include "DWARFDebugInfoEntry.h"
 #include "DWARFDebugRanges.h"
 #include "DWARFDeclContext.h"
-#include "DWARFDIECollection.h"
 #include "DWARFFormValue.h"
 #include "SymbolFileDWARF.h"
 
 #include "lldb/Core/Module.h"
+#include "lldb/Symbol/DebugInfoASTParser.h"
 #include "lldb/Symbol/ObjectFile.h"
 #include "lldb/Symbol/Type.h"
 #include "lldb/Symbol/TypeSystem.h"
@@ -406,7 +408,7 @@
 {
     lldb_private::TypeSystem *type_system = GetTypeSystem ();
     if (type_system)
-        return type_system->GetDWARFParser();
+        return llvm::dyn_cast<DWARFASTParser>(type_system->GetDebugInfoASTParser());
     else
         return nullptr;
 }
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.h
@@ -70,12 +70,10 @@
     GetDeclContextContainingUIDFromDWARF (const DWARFDIE &die) override;
 
     bool
-    LayoutRecordType(const clang::RecordDecl *record_decl,
-                     uint64_t &bit_size,
-                     uint64_t &alignment,
+    LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
                      llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
                      llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
-                     llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets);
+                     llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) override;
 
 protected:
     class DelayedAddObjCClassProperty;
Index: source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
===================================================================
--- source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
+++ source/Plugins/SymbolFile/DWARF/DWARFASTParser.h
@@ -14,14 +14,17 @@
 #include "lldb/Core/PluginInterface.h"
 #include "lldb/Symbol/CompilerDecl.h"
 #include "lldb/Symbol/CompilerDeclContext.h"
+#include "lldb/Symbol/DebugInfoASTParser.h"
 
 class DWARFDIE;
 
-class DWARFASTParser
+class DWARFASTParser : public DebugInfoASTParser
 {
 public:
     virtual ~DWARFASTParser() {}
 
+    DECLARE_DEBUG_INFO_PARSER_TYPE(lldb_private::SymbolFileFormat::DWARF)
+
     virtual lldb::TypeSP
     ParseTypeFromDWARF (const lldb_private::SymbolContext& sc,
                         const DWARFDIE &die,
@@ -33,18 +36,6 @@
                             const DWARFDIE &die) = 0;
 
     virtual bool
-    CanCompleteType (const lldb_private::CompilerType &compiler_type)
-    {
-        return false;
-    }
-
-    virtual bool
-    CompleteType (const lldb_private::CompilerType &compiler_type)
-    {
-        return false;
-    }
-
-    virtual bool
     CompleteTypeFromDWARF (const DWARFDIE &die,
                            lldb_private::Type *type,
                            lldb_private::CompilerType &compiler_type) = 0;
Index: include/lldb/Symbol/TypeSystem.h
===================================================================
--- include/lldb/Symbol/TypeSystem.h
+++ include/lldb/Symbol/TypeSystem.h
@@ -28,8 +28,7 @@
 #include "lldb/Symbol/CompilerDecl.h"
 #include "lldb/Symbol/CompilerDeclContext.h"
 
-class DWARFDIE;
-class DWARFASTParser;
+class DebugInfoASTParser;
 
 namespace lldb_private {
     
@@ -99,8 +98,8 @@
     virtual void
     Finalize() {}
 
-    virtual DWARFASTParser *
-    GetDWARFParser ()
+    virtual DebugInfoASTParser *
+    GetDebugInfoASTParser()
     {
         return nullptr;
     }
Index: include/lldb/Symbol/SymbolFile.h
===================================================================
--- include/lldb/Symbol/SymbolFile.h
+++ include/lldb/Symbol/SymbolFile.h
@@ -21,6 +21,13 @@
 
 namespace lldb_private {
 
+enum class SymbolFileFormat
+{
+    DWARF,
+    PDB,
+    Other
+};
+
 class SymbolFile :
     public PluginInterface
 {
@@ -115,6 +122,12 @@
     //------------------------------------------------------------------    
     virtual void            InitializeObject() {}
 
+    virtual SymbolFileFormat
+    GetSymbolFileFormat() const
+    {
+        return SymbolFileFormat::Other;
+    }
+
     //------------------------------------------------------------------
     // Compile Unit function calls
     //------------------------------------------------------------------
@@ -154,12 +167,10 @@
                                       lldb_private::TypeList &type_list) = 0;
 
     virtual lldb_private::TypeSystem *
-                            GetTypeSystemForLanguage (lldb::LanguageType language);
+    GetTypeSystemForLanguage(lldb::LanguageType language);
 
     virtual CompilerDeclContext
-                            FindNamespace (const SymbolContext& sc, 
-                                           const ConstString &name,
-                                           const CompilerDeclContext *parent_decl_ctx)
+    FindNamespace(const SymbolContext &sc, const ConstString &name, const CompilerDeclContext *parent_decl_ctx)
     {
         return CompilerDeclContext();
     }
Index: include/lldb/Symbol/JavaASTContext.h
===================================================================
--- include/lldb/Symbol/JavaASTContext.h
+++ include/lldb/Symbol/JavaASTContext.h
@@ -21,6 +21,8 @@
 #include "lldb/Core/ConstString.h"
 #include "lldb/Symbol/TypeSystem.h"
 
+class DWARFASTParser;
+
 namespace lldb_private
 {
 
@@ -58,8 +60,8 @@
     static void
     Terminate();
 
-    DWARFASTParser *
-    GetDWARFParser() override;
+    DebugInfoASTParser *
+    GetDebugInfoASTParser() override;
 
     uint32_t
     GetPointerByteSize() override;
Index: include/lldb/Symbol/GoASTContext.h
===================================================================
--- include/lldb/Symbol/GoASTContext.h
+++ include/lldb/Symbol/GoASTContext.h
@@ -23,6 +23,7 @@
 #include "lldb/Core/ConstString.h"
 #include "lldb/Symbol/TypeSystem.h"
 #include "lldb/Symbol/CompilerType.h"
+class DWARFASTParser;
 
 namespace lldb_private
 {
@@ -59,8 +60,9 @@
 
     static void
     Terminate ();
-    
-    DWARFASTParser *GetDWARFParser() override;
+
+    DebugInfoASTParser *
+    GetDebugInfoASTParser() override;
 
     void
     SetAddressByteSize(int byte_size)
Index: include/lldb/Symbol/DebugInfoASTParser.h
===================================================================
--- /dev/null
+++ include/lldb/Symbol/DebugInfoASTParser.h
@@ -0,0 +1,56 @@
+//===-- DebugInfoASTParser.h ------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_INCLUDE_SYMBOL_DEBUGINFO_AST_PARSER_H
+#define LLDB_INCLUDE_SYMBOL_DEBUGINFO_AST_PARSER_H
+
+#include "lldb/Symbol/CompilerType.h"
+#include "lldb/Symbol/SymbolFile.h"
+
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/Casting.h"
+
+#include "clang/AST/CharUnits.h"
+
+#define DECLARE_DEBUG_INFO_PARSER_TYPE(TypeValue)                                                                      \
+    static const lldb_private::SymbolFileFormat type = TypeValue;                                                      \
+    lldb_private::SymbolFileFormat GetDebugInfoFormat() const override { return TypeValue; }                           \
+    static bool classof(const DebugInfoASTParser *parser) { return parser->GetDebugInfoFormat() == type; }
+
+class DebugInfoASTParser
+{
+public:
+    virtual ~DebugInfoASTParser() {}
+
+    virtual lldb_private::SymbolFileFormat
+    GetDebugInfoFormat() const = 0;
+
+    virtual bool
+    CanCompleteType(const lldb_private::CompilerType &compiler_type)
+    {
+        return false;
+    }
+
+    virtual bool
+    CompleteType(const lldb_private::CompilerType &compiler_type)
+    {
+        return false;
+    }
+
+    virtual bool
+    LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment,
+                     llvm::DenseMap<const clang::FieldDecl *, uint64_t> &field_offsets,
+                     llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets,
+                     llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets)
+    {
+        return false;
+    }
+};
+
+#endif // LLDB_INCLUDE_SYMBOL_DEBUGINFO_AST_PARSER_H
Index: include/lldb/Symbol/ClangASTContext.h
===================================================================
--- include/lldb/Symbol/ClangASTContext.h
+++ include/lldb/Symbol/ClangASTContext.h
@@ -30,11 +30,12 @@
 
 // Project includes
 #include "Plugins/ExpressionParser/Clang/ClangPersistentVariables.h"
-#include "lldb/lldb-enumerations.h"
 #include "lldb/Core/ClangForward.h"
 #include "lldb/Core/ConstString.h"
 #include "lldb/Symbol/CompilerType.h"
+#include "lldb/Symbol/DebugInfoASTParser.h"
 #include "lldb/Symbol/TypeSystem.h"
+#include "lldb/lldb-enumerations.h"
 
 namespace lldb_private {
 
@@ -520,8 +521,8 @@
     //------------------------------------------------------------------
     // TypeSystem methods
     //------------------------------------------------------------------
-    DWARFASTParser *
-    GetDWARFParser () override;
+    DebugInfoASTParser *
+    GetDebugInfoASTParser() override;
 
     //------------------------------------------------------------------
     // ClangASTContext callbacks for external source lookups.
@@ -1212,6 +1213,7 @@
     //------------------------------------------------------------------
     // Classes that inherit from ClangASTContext can see and modify these
     //------------------------------------------------------------------
+    // clang-format off
     std::string                                     m_target_triple;
     std::unique_ptr<clang::ASTContext>              m_ast_ap;
     std::unique_ptr<clang::LangOptions>             m_language_options_ap;
@@ -1225,7 +1227,7 @@
     std::unique_ptr<clang::IdentifierTable>         m_identifier_table_ap;
     std::unique_ptr<clang::SelectorTable>           m_selector_table_ap;
     std::unique_ptr<clang::Builtin::Context>        m_builtins_ap;
-    std::unique_ptr<DWARFASTParser>                 m_dwarf_ast_parser_ap;
+    std::unique_ptr<DebugInfoASTParser>             m_di_ast_parser_ap;
     std::unique_ptr<ClangASTSource>                 m_scratch_ast_source_ap;
     std::unique_ptr<clang::MangleContext>           m_mangle_ctx_ap;
     CompleteTagDeclCallback                         m_callback_tag_decl;
@@ -1235,7 +1237,7 @@
     bool                                            m_ast_owned;
     bool                                            m_can_evaluate_expressions;
     std::map<void *, std::shared_ptr<void>>         m_decl_objects;
-
+    // clang-format on
 private:
     //------------------------------------------------------------------
     // For ClangASTContext only
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to