SymbolFileDWARF.h revision b01000fd063629facd45044f137446fb748ee179
1//===-- SymbolFileDWARF.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 liblldb_SymbolFileDWARF_h_ 11#define liblldb_SymbolFileDWARF_h_ 12 13// C Includes 14// C++ Includes 15#include <list> 16#include <memory> 17#include <map> 18#include <vector> 19 20// Other libraries and framework includes 21#include "llvm/ADT/DenseMap.h" 22 23#include "lldb/Core/ClangForward.h" 24#include "lldb/Core/ConstString.h" 25#include "lldb/Core/dwarf.h" 26#include "lldb/Core/DataExtractor.h" 27#include "lldb/Core/Flags.h" 28#include "lldb/Core/UniqueCStringMap.h" 29#include "lldb/Symbol/SymbolFile.h" 30#include "lldb/Symbol/SymbolContext.h" 31 32// Project includes 33#include "DWARFDefines.h" 34#include "NameToDIE.h" 35 36 37//---------------------------------------------------------------------- 38// Forward Declarations for this DWARF plugin 39//---------------------------------------------------------------------- 40class DWARFAbbreviationDeclaration; 41class DWARFAbbreviationDeclarationSet; 42class DWARFCompileUnit; 43class DWARFDebugAbbrev; 44class DWARFDebugAranges; 45class DWARFDebugInfo; 46class DWARFDebugInfoEntry; 47class DWARFDebugLine; 48class DWARFDebugPubnames; 49class DWARFDebugRanges; 50class DWARFDIECollection; 51class DWARFFormValue; 52class SymbolFileDWARFDebugMap; 53 54class SymbolFileDWARF : public lldb_private::SymbolFile 55{ 56public: 57 friend class SymbolFileDWARFDebugMap; 58 59 //------------------------------------------------------------------ 60 // Static Functions 61 //------------------------------------------------------------------ 62 static void 63 Initialize(); 64 65 static void 66 Terminate(); 67 68 static const char * 69 GetPluginNameStatic(); 70 71 static const char * 72 GetPluginDescriptionStatic(); 73 74 static lldb_private::SymbolFile* 75 CreateInstance (lldb_private::ObjectFile* obj_file); 76 //------------------------------------------------------------------ 77 // Constructors and Destructors 78 //------------------------------------------------------------------ 79 SymbolFileDWARF(lldb_private::ObjectFile* ofile); 80 virtual ~SymbolFileDWARF(); 81 82 virtual uint32_t GetAbilities (); 83 virtual void InitializeObject(); 84 85 //------------------------------------------------------------------ 86 // Compile Unit function calls 87 //------------------------------------------------------------------ 88 virtual uint32_t GetNumCompileUnits(); 89 virtual lldb::CompUnitSP ParseCompileUnitAtIndex(uint32_t index); 90 91 virtual size_t ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc); 92 virtual bool ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc); 93 virtual bool ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, lldb_private::FileSpecList& support_files); 94 virtual size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc); 95 virtual size_t ParseTypes (const lldb_private::SymbolContext& sc); 96 virtual size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc); 97 98 virtual lldb_private::Type* ResolveTypeUID(lldb::user_id_t type_uid); 99 virtual lldb::clang_type_t ResolveClangOpaqueTypeDefinition (lldb::clang_type_t clang_opaque_type); 100 101 virtual lldb_private::Type* ResolveType (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* type_die, bool assert_not_being_parsed = true); 102 virtual clang::DeclContext* GetClangDeclContextForTypeUID (lldb::user_id_t type_uid); 103 104 virtual uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc); 105 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); 106 virtual uint32_t FindGlobalVariables(const lldb_private::ConstString &name, bool append, uint32_t max_matches, lldb_private::VariableList& variables); 107 virtual uint32_t FindGlobalVariables(const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables); 108 virtual uint32_t FindFunctions(const lldb_private::ConstString &name, uint32_t name_type_mask, bool append, lldb_private::SymbolContextList& sc_list); 109 virtual uint32_t FindFunctions(const lldb_private::RegularExpression& regex, bool append, lldb_private::SymbolContextList& sc_list); 110 virtual uint32_t FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, bool append, uint32_t max_matches, lldb_private::TypeList& types); 111 virtual lldb_private::TypeList * 112 GetTypeList (); 113 virtual lldb_private::ClangASTContext & 114 GetClangASTContext (); 115 116 virtual lldb_private::ClangNamespaceDecl 117 FindNamespace (const lldb_private::SymbolContext& sc, 118 const lldb_private::ConstString &name); 119 120 121 //------------------------------------------------------------------ 122 // ClangASTContext callbacks for external source lookups. 123 //------------------------------------------------------------------ 124 static void 125 CompleteTagDecl (void *baton, clang::TagDecl *); 126 127 static void 128 CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *); 129 130 //------------------------------------------------------------------ 131 // PluginInterface protocol 132 //------------------------------------------------------------------ 133 virtual const char * 134 GetPluginName(); 135 136 virtual const char * 137 GetShortPluginName(); 138 139 virtual uint32_t 140 GetPluginVersion(); 141 142 virtual void 143 GetPluginCommandHelp (const char *command, lldb_private::Stream *strm); 144 145 virtual lldb_private::Error 146 ExecutePluginCommand (lldb_private::Args &command, lldb_private::Stream *strm); 147 148 virtual lldb_private::Log * 149 EnablePluginLogging (lldb_private::Stream *strm, lldb_private::Args &command); 150 151 // Approach 2 - count + accessor 152 // Index compile units would scan the initial compile units and register 153 // them with the module. This would only be done on demand if and only if 154 // the compile units were needed. 155 //virtual size_t GetCompUnitCount() = 0; 156 //virtual CompUnitSP GetCompUnitAtIndex(size_t cu_idx) = 0; 157 158 const lldb_private::DataExtractor& get_debug_abbrev_data(); 159 const lldb_private::DataExtractor& get_debug_frame_data(); 160 const lldb_private::DataExtractor& get_debug_info_data(); 161 const lldb_private::DataExtractor& get_debug_line_data(); 162 const lldb_private::DataExtractor& get_debug_loc_data(); 163 const lldb_private::DataExtractor& get_debug_ranges_data(); 164 const lldb_private::DataExtractor& get_debug_str_data(); 165 166 DWARFDebugAbbrev* DebugAbbrev(); 167 const DWARFDebugAbbrev* DebugAbbrev() const; 168 169 DWARFDebugAranges* DebugAranges(); 170 const DWARFDebugAranges*DebugAranges() const; 171 172 DWARFDebugInfo* DebugInfo(); 173 const DWARFDebugInfo* DebugInfo() const; 174 175 DWARFDebugRanges* DebugRanges(); 176 const DWARFDebugRanges* DebugRanges() const; 177 178 const lldb_private::DataExtractor& 179 GetCachedSectionData (uint32_t got_flag, lldb::SectionType sect_type, lldb_private::DataExtractor &data); 180 181 static bool 182 SupportedVersion(uint16_t version); 183 184 clang::DeclContext * 185 GetClangDeclContextForDIE (DWARFCompileUnit *cu, const DWARFDebugInfoEntry *die); 186 187 clang::DeclContext * 188 GetClangDeclContextForDIEOffset (dw_offset_t die_offset); 189 190 lldb_private::Flags& 191 GetFlags () 192 { 193 return m_flags; 194 } 195 196 const lldb_private::Flags& 197 GetFlags () const 198 { 199 return m_flags; 200 } 201 202 bool 203 HasForwardDeclForClangType (lldb::clang_type_t clang_type); 204 205protected: 206 207 enum 208 { 209 flagsGotDebugAbbrevData = (1 << 0), 210 flagsGotDebugArangesData = (1 << 1), 211 flagsGotDebugFrameData = (1 << 2), 212 flagsGotDebugInfoData = (1 << 3), 213 flagsGotDebugLineData = (1 << 4), 214 flagsGotDebugLocData = (1 << 5), 215 flagsGotDebugMacInfoData = (1 << 6), 216 flagsGotDebugPubNamesData = (1 << 7), 217 flagsGotDebugPubTypesData = (1 << 8), 218 flagsGotDebugRangesData = (1 << 9), 219 flagsGotDebugStrData = (1 << 10), 220 }; 221 222 DISALLOW_COPY_AND_ASSIGN (SymbolFileDWARF); 223 bool ParseCompileUnit (DWARFCompileUnit* cu, lldb::CompUnitSP& compile_unit_sp); 224 DWARFCompileUnit* GetDWARFCompileUnitForUID(lldb::user_id_t cu_uid); 225 DWARFCompileUnit* GetNextUnparsedDWARFCompileUnit(DWARFCompileUnit* prev_cu); 226 lldb_private::CompileUnit* GetCompUnitForDWARFCompUnit(DWARFCompileUnit* cu, uint32_t cu_idx = UINT32_MAX); 227 bool GetFunction (DWARFCompileUnit* cu, const DWARFDebugInfoEntry* func_die, lldb_private::SymbolContext& sc); 228 lldb_private::Function * ParseCompileUnitFunction (const lldb_private::SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die); 229 size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc, 230 lldb_private::Block *parent_block, 231 DWARFCompileUnit* dwarf_cu, 232 const DWARFDebugInfoEntry *die, 233 lldb::addr_t subprogram_low_pc, 234 bool parse_siblings, 235 bool parse_children); 236 size_t ParseTypes (const lldb_private::SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool parse_siblings, bool parse_children); 237 lldb::TypeSP ParseType (const lldb_private::SymbolContext& sc, DWARFCompileUnit* dwarf_cu, const DWARFDebugInfoEntry *die, bool *type_is_new); 238 239 lldb::VariableSP ParseVariableDIE( 240 const lldb_private::SymbolContext& sc, 241 DWARFCompileUnit* dwarf_cu, 242 const DWARFDebugInfoEntry *die, 243 const lldb::addr_t func_low_pc); 244 245 size_t ParseVariables( 246 const lldb_private::SymbolContext& sc, 247 DWARFCompileUnit* dwarf_cu, 248 const lldb::addr_t func_low_pc, 249 const DWARFDebugInfoEntry *die, 250 bool parse_siblings, 251 bool parse_children, 252 lldb_private::VariableList* cc_variable_list = NULL); 253 254 size_t ParseChildMembers( 255 const lldb_private::SymbolContext& sc, 256 DWARFCompileUnit* dwarf_cu, 257 const DWARFDebugInfoEntry *die, 258 lldb::clang_type_t class_clang_type, 259 const lldb::LanguageType class_language, 260 std::vector<clang::CXXBaseSpecifier *>& base_classes, 261 std::vector<int>& member_accessibilities, 262 DWARFDIECollection& member_function_dies, 263 lldb::AccessType &default_accessibility, 264 bool &is_a_class); 265 266 size_t ParseChildParameters( 267 const lldb_private::SymbolContext& sc, 268 lldb::TypeSP& type_sp, 269 DWARFCompileUnit* dwarf_cu, 270 const DWARFDebugInfoEntry *parent_die, 271 bool skip_artificial, 272 lldb_private::TypeList* type_list, 273 std::vector<lldb::clang_type_t>& function_args, 274 std::vector<clang::ParmVarDecl*>& function_param_decls, 275 unsigned &type_quals); 276 277 size_t ParseChildEnumerators( 278 const lldb_private::SymbolContext& sc, 279 lldb::clang_type_t enumerator_qual_type, 280 uint32_t enumerator_byte_size, 281 DWARFCompileUnit* dwarf_cu, 282 const DWARFDebugInfoEntry *enum_die); 283 284 void ParseChildArrayInfo( 285 const lldb_private::SymbolContext& sc, 286 DWARFCompileUnit* dwarf_cu, 287 const DWARFDebugInfoEntry *parent_die, 288 int64_t& first_index, 289 std::vector<uint64_t>& element_orders, 290 uint32_t& byte_stride, 291 uint32_t& bit_stride); 292 293 void FindFunctions( 294 const lldb_private::ConstString &name, 295 const NameToDIE &name_to_die, 296 lldb_private::SymbolContextList& sc_list); 297 298 void FindFunctions ( 299 const lldb_private::RegularExpression ®ex, 300 const NameToDIE &name_to_die, 301 lldb_private::SymbolContextList& sc_list); 302 303 lldb::TypeSP FindDefinitionTypeForDIE ( 304 DWARFCompileUnit* cu, 305 const DWARFDebugInfoEntry *die, 306 const lldb_private::ConstString &type_name); 307 308 lldb::TypeSP GetTypeForDIE (DWARFCompileUnit *cu, 309 const DWARFDebugInfoEntry* die); 310 311 uint32_t FindTypes(std::vector<dw_offset_t> die_offsets, uint32_t max_matches, lldb_private::TypeList& types); 312 313 void Index(); 314 315 void SetDebugMapSymfile (SymbolFileDWARFDebugMap *debug_map_symfile) 316 { 317 m_debug_map_symfile = debug_map_symfile; 318 } 319 320 clang::NamespaceDecl * 321 ResolveNamespaceDIE (DWARFCompileUnit *curr_cu, const DWARFDebugInfoEntry *die); 322 323 SymbolFileDWARFDebugMap * m_debug_map_symfile; 324 clang::TranslationUnitDecl * m_clang_tu_decl; 325 lldb_private::Flags m_flags; 326 lldb_private::DataExtractor m_dwarf_data; 327 lldb_private::DataExtractor m_data_debug_abbrev; 328 lldb_private::DataExtractor m_data_debug_frame; 329 lldb_private::DataExtractor m_data_debug_info; 330 lldb_private::DataExtractor m_data_debug_line; 331 lldb_private::DataExtractor m_data_debug_loc; 332 lldb_private::DataExtractor m_data_debug_ranges; 333 lldb_private::DataExtractor m_data_debug_str; 334 335 // The auto_ptr items below are generated on demand if and when someone accesses 336 // them through a non const version of this class. 337 std::auto_ptr<DWARFDebugAbbrev> m_abbr; 338 std::auto_ptr<DWARFDebugAranges> m_aranges; 339 std::auto_ptr<DWARFDebugInfo> m_info; 340 std::auto_ptr<DWARFDebugLine> m_line; 341 NameToDIE m_function_basename_index; // All concrete functions 342 NameToDIE m_function_fullname_index; // All concrete functions 343 NameToDIE m_function_method_index; // All inlined functions 344 NameToDIE m_function_selector_index; // All method names for functions of classes 345 NameToDIE m_objc_class_selectors_index; // Given a class name, find all selectors for the class 346 NameToDIE m_global_index; // Global and static variables 347 NameToDIE m_type_index; // All type DIE offsets 348 NameToDIE m_namespace_index; // All type DIE offsets 349 bool m_indexed:1, 350 m_is_external_ast_source:1; 351 352 std::auto_ptr<DWARFDebugRanges> m_ranges; 353 354 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::DeclContext *> DIEToDeclContextMap; 355 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb_private::Type *> DIEToTypePtr; 356 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::VariableSP> DIEToVariableSP; 357 typedef llvm::DenseMap<const DWARFDebugInfoEntry *, lldb::clang_type_t> DIEToClangType; 358 typedef llvm::DenseMap<lldb::clang_type_t, const DWARFDebugInfoEntry *> ClangTypeToDIE; 359 DIEToDeclContextMap m_die_to_decl_ctx; 360 DIEToTypePtr m_die_to_type; 361 DIEToVariableSP m_die_to_variable_sp; 362 DIEToClangType m_forward_decl_die_to_clang_type; 363 ClangTypeToDIE m_forward_decl_clang_type_to_die; 364}; 365 366#endif // liblldb_SymbolFileDWARF_h_ 367