1 //===-- SymbolFileDWARFDebugMap.h ------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_ 11 #define SymbolFileDWARF_SymbolFileDWARFDebugMap_h_ 12 13 14 #include <vector> 15 #include <bitset> 16 17 #include "clang/AST/CharUnits.h" 18 19 #include "lldb/Symbol/SymbolFile.h" 20 21 #include "UniqueDWARFASTType.h" 22 23 class SymbolFileDWARF; 24 class DWARFCompileUnit; 25 class DWARFDebugInfoEntry; 26 class DWARFDeclContext; 27 class DebugMapModule; 28 29 class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile 30 { 31 public: 32 33 //------------------------------------------------------------------ 34 // Static Functions 35 //------------------------------------------------------------------ 36 static void 37 Initialize(); 38 39 static void 40 Terminate(); 41 42 static const char * 43 GetPluginNameStatic(); 44 45 static const char * 46 GetPluginDescriptionStatic(); 47 48 static lldb_private::SymbolFile * 49 CreateInstance (lldb_private::ObjectFile* obj_file); 50 51 //------------------------------------------------------------------ 52 // Constructors and Destructors 53 //------------------------------------------------------------------ 54 SymbolFileDWARFDebugMap (lldb_private::ObjectFile* ofile); 55 virtual ~ SymbolFileDWARFDebugMap (); 56 57 virtual uint32_t CalculateAbilities (); 58 59 virtual void InitializeObject(); 60 61 //------------------------------------------------------------------ 62 // Compile Unit function calls 63 //------------------------------------------------------------------ 64 virtual uint32_t GetNumCompileUnits (); 65 virtual lldb::CompUnitSP ParseCompileUnitAtIndex (uint32_t index); 66 67 virtual lldb::LanguageType ParseCompileUnitLanguage (const lldb_private::SymbolContext& sc); 68 virtual size_t ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc); 69 virtual bool ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc); 70 virtual bool ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, lldb_private::FileSpecList &support_files); 71 virtual size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc); 72 virtual size_t ParseTypes (const lldb_private::SymbolContext& sc); 73 virtual size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc); 74 75 virtual lldb_private::Type* ResolveTypeUID (lldb::user_id_t type_uid); 76 virtual clang::DeclContext* GetClangDeclContextContainingTypeUID (lldb::user_id_t type_uid); 77 virtual clang::DeclContext* GetClangDeclContextForTypeUID (const lldb_private::SymbolContext &sc, lldb::user_id_t type_uid); 78 virtual lldb::clang_type_t ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_Type); 79 virtual uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc); 80 virtual uint32_t ResolveSymbolContext (const lldb_private::FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, lldb_private::SymbolContextList& sc_list); 81 virtual uint32_t FindGlobalVariables (const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::VariableList& variables); 82 virtual uint32_t FindGlobalVariables (const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables); 83 virtual uint32_t FindFunctions (const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, uint32_t name_type_mask, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list); 84 virtual uint32_t FindFunctions (const lldb_private::RegularExpression& regex, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list); 85 virtual uint32_t FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::ClangNamespaceDecl *namespace_decl, bool append, uint32_t max_matches, lldb_private::TypeList& types); 86 virtual lldb_private::ClangNamespaceDecl 87 FindNamespace (const lldb_private::SymbolContext& sc, 88 const lldb_private::ConstString &name, 89 const lldb_private::ClangNamespaceDecl *parent_namespace_decl); 90 91 92 //------------------------------------------------------------------ 93 // ClangASTContext callbacks for external source lookups. 94 //------------------------------------------------------------------ 95 static void 96 CompleteTagDecl (void *baton, clang::TagDecl *); 97 98 static void 99 CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *); 100 101 static bool 102 LayoutRecordType (void *baton, 103 const clang::RecordDecl *record_decl, 104 uint64_t &size, 105 uint64_t &alignment, 106 llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, 107 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, 108 llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets); 109 110 111 //------------------------------------------------------------------ 112 // PluginInterface protocol 113 //------------------------------------------------------------------ 114 virtual const char * 115 GetPluginName(); 116 117 virtual const char * 118 GetShortPluginName(); 119 120 virtual uint32_t 121 GetPluginVersion(); 122 123 protected: 124 enum 125 { 126 kHaveInitializedOSOs = (1 << 0), 127 kNumFlags 128 }; 129 130 friend class SymbolFileDWARF; 131 friend class DebugMapModule; 132 //------------------------------------------------------------------ 133 // Class specific types 134 //------------------------------------------------------------------ 135 struct CompileUnitInfo 136 { 137 lldb_private::FileSpec so_file; 138 lldb_private::FileSpec oso_file; 139 lldb_private::ConstString oso_object; // for archives this will be the .o file in the "oso_file" 140 // lldb_private::Symbol *so_symbol; 141 // lldb_private::Symbol *oso_symbol; 142 // lldb_private::Symbol *last_symbol; 143 uint32_t first_symbol_index; 144 uint32_t last_symbol_index; 145 uint32_t first_symbol_id; 146 uint32_t last_symbol_id; 147 lldb::ModuleSP oso_module_sp; 148 lldb::CompUnitSP oso_compile_unit_sp; 149 // SymbolFileDWARF *oso_symfile; 150 bool symbol_file_supported; 151 152 CompileUnitInfo() : 153 so_file (), 154 oso_file (), 155 oso_object (), 156 // so_symbol (NULL), 157 // oso_symbol (NULL), 158 // last_symbol (NULL), 159 first_symbol_index (UINT32_MAX), 160 last_symbol_index (UINT32_MAX), 161 first_symbol_id (UINT32_MAX), 162 last_symbol_id (UINT32_MAX), 163 oso_module_sp (), 164 oso_compile_unit_sp (), 165 // oso_symfile (NULL), 166 symbol_file_supported (true) 167 { 168 } 169 }; 170 171 //------------------------------------------------------------------ 172 // Protected Member Functions 173 //------------------------------------------------------------------ 174 void 175 InitOSO (); 176 177 static uint32_t 178 GetOSOIndexFromUserID (lldb::user_id_t uid) 179 { 180 return (uint32_t)((uid >> 32ull) - 1ull); 181 } 182 bool 183 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec); 184 185 CompileUnitInfo * 186 GetCompUnitInfo (const lldb_private::SymbolContext& sc); 187 188 CompileUnitInfo * 189 GetCompUnitInfo (const lldb_private::Module *oso_module); 190 191 lldb_private::Module * 192 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info); 193 194 lldb_private::Module * 195 GetModuleByOSOIndex (uint32_t oso_idx); 196 197 lldb_private::ObjectFile * 198 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info); 199 200 lldb_private::ObjectFile * 201 GetObjectFileByOSOIndex (uint32_t oso_idx); 202 203 uint32_t 204 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info); 205 206 SymbolFileDWARF * 207 GetSymbolFile (const lldb_private::SymbolContext& sc); 208 209 SymbolFileDWARF * 210 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info); 211 212 SymbolFileDWARF * 213 GetSymbolFileByOSOIndex (uint32_t oso_idx); 214 215 CompileUnitInfo * 216 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr); 217 218 CompileUnitInfo * 219 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr); 220 221 static int 222 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info); 223 224 static int 225 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info); 226 227 uint32_t 228 PrivateFindGlobalVariables (const lldb_private::ConstString &name, 229 const lldb_private::ClangNamespaceDecl *namespace_decl, 230 const std::vector<uint32_t> &name_symbol_indexes, 231 uint32_t max_matches, 232 lldb_private::VariableList& variables); 233 234 235 void 236 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp); 237 238 lldb::CompUnitSP 239 GetCompileUnit (SymbolFileDWARF *oso_dwarf); 240 241 lldb::TypeSP 242 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx); 243 244 bool 245 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso); 246 247 lldb::TypeSP 248 FindCompleteObjCDefinitionTypeForDIE (const DWARFDebugInfoEntry *die, 249 const lldb_private::ConstString &type_name, 250 bool must_be_implementation); 251 252 253 UniqueDWARFASTTypeMap & 254 GetUniqueDWARFASTTypeMap () 255 { 256 return m_unique_ast_type_map; 257 } 258 //------------------------------------------------------------------ 259 // Member Variables 260 //------------------------------------------------------------------ 261 std::bitset<kNumFlags> m_flags; 262 std::vector<CompileUnitInfo> m_compile_unit_infos; 263 std::vector<uint32_t> m_func_indexes; // Sorted by address 264 std::vector<uint32_t> m_glob_indexes; 265 UniqueDWARFASTTypeMap m_unique_ast_type_map; 266 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type; 267 }; 268 269 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_ 270