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 "lldb/Core/RangeMap.h" 18 #include "lldb/Symbol/SymbolFile.h" 19 20 #include "UniqueDWARFASTType.h" 21 22 class SymbolFileDWARF; 23 class DWARFDebugAranges; 24 class DWARFDeclContext; 25 26 class SymbolFileDWARFDebugMap : public lldb_private::SymbolFile 27 { 28 public: 29 30 //------------------------------------------------------------------ 31 // Static Functions 32 //------------------------------------------------------------------ 33 static void 34 Initialize(); 35 36 static void 37 Terminate(); 38 39 static lldb_private::ConstString 40 GetPluginNameStatic(); 41 42 static const char * 43 GetPluginDescriptionStatic(); 44 45 static lldb_private::SymbolFile * 46 CreateInstance (lldb_private::ObjectFile* obj_file); 47 48 //------------------------------------------------------------------ 49 // Constructors and Destructors 50 //------------------------------------------------------------------ 51 SymbolFileDWARFDebugMap (lldb_private::ObjectFile* ofile); 52 ~SymbolFileDWARFDebugMap () override; 53 54 uint32_t CalculateAbilities () override; 55 void InitializeObject() override; 56 57 //------------------------------------------------------------------ 58 // Compile Unit function calls 59 //------------------------------------------------------------------ 60 uint32_t GetNumCompileUnits () override; 61 lldb::CompUnitSP ParseCompileUnitAtIndex (uint32_t index) override; 62 63 lldb::LanguageType ParseCompileUnitLanguage (const lldb_private::SymbolContext& sc) override; 64 size_t ParseCompileUnitFunctions (const lldb_private::SymbolContext& sc) override; 65 bool ParseCompileUnitLineTable (const lldb_private::SymbolContext& sc) override; 66 bool ParseCompileUnitDebugMacros (const lldb_private::SymbolContext& sc) override; 67 bool ParseCompileUnitSupportFiles (const lldb_private::SymbolContext& sc, lldb_private::FileSpecList &support_files) override; 68 bool ParseImportedModules (const lldb_private::SymbolContext &sc, std::vector<lldb_private::ConstString> &imported_modules) override; 69 size_t ParseFunctionBlocks (const lldb_private::SymbolContext& sc) override; 70 size_t ParseTypes (const lldb_private::SymbolContext& sc) override; 71 size_t ParseVariablesForContext (const lldb_private::SymbolContext& sc) override; 72 73 lldb_private::Type* ResolveTypeUID (lldb::user_id_t type_uid) override; 74 lldb_private::CompilerDeclContext GetDeclContextForUID (lldb::user_id_t uid) override; 75 lldb_private::CompilerDeclContext GetDeclContextContainingUID (lldb::user_id_t uid) override; 76 void ParseDeclsForContext (lldb_private::CompilerDeclContext decl_ctx) override; 77 78 bool CompleteType (lldb_private::CompilerType& compiler_type) override; 79 uint32_t ResolveSymbolContext (const lldb_private::Address& so_addr, uint32_t resolve_scope, lldb_private::SymbolContext& sc) override; 80 uint32_t ResolveSymbolContext (const lldb_private::FileSpec& file_spec, uint32_t line, bool check_inlines, uint32_t resolve_scope, lldb_private::SymbolContextList& sc_list) override; 81 uint32_t FindGlobalVariables (const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override; 82 uint32_t FindGlobalVariables (const lldb_private::RegularExpression& regex, bool append, uint32_t max_matches, lldb_private::VariableList& variables) override; 83 uint32_t FindFunctions (const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, uint32_t name_type_mask, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override; 84 uint32_t FindFunctions (const lldb_private::RegularExpression& regex, bool include_inlines, bool append, lldb_private::SymbolContextList& sc_list) override; 85 uint32_t FindTypes (const lldb_private::SymbolContext& sc, const lldb_private::ConstString &name, const lldb_private::CompilerDeclContext *parent_decl_ctx, bool append, uint32_t max_matches, llvm::DenseSet<lldb_private::SymbolFile *> &searched_symbol_files, lldb_private::TypeMap& types) override; 86 lldb_private::CompilerDeclContext 87 FindNamespace (const lldb_private::SymbolContext& sc, 88 const lldb_private::ConstString &name, 89 const lldb_private::CompilerDeclContext *parent_decl_ctx) override; 90 size_t GetTypes (lldb_private::SymbolContextScope *sc_scope, 91 uint32_t type_mask, 92 lldb_private::TypeList &type_list) override; 93 94 //------------------------------------------------------------------ 95 // PluginInterface protocol 96 //------------------------------------------------------------------ 97 lldb_private::ConstString 98 GetPluginName() override; 99 100 uint32_t 101 GetPluginVersion() override; 102 103 protected: 104 enum 105 { 106 kHaveInitializedOSOs = (1 << 0), 107 kNumFlags 108 }; 109 110 friend class DWARFCompileUnit; 111 friend class SymbolFileDWARF; 112 friend class DebugMapModule; 113 friend class DWARFASTParserClang; 114 struct OSOInfo 115 { 116 lldb::ModuleSP module_sp; 117 118 OSOInfo() : 119 module_sp () 120 { 121 } 122 }; 123 124 typedef std::shared_ptr<OSOInfo> OSOInfoSP; 125 126 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, lldb::addr_t> FileRangeMap; 127 128 //------------------------------------------------------------------ 129 // Class specific types 130 //------------------------------------------------------------------ 131 struct CompileUnitInfo 132 { 133 lldb_private::FileSpec so_file; 134 lldb_private::ConstString oso_path; 135 lldb_private::TimeValue oso_mod_time; 136 OSOInfoSP oso_sp; 137 lldb::CompUnitSP compile_unit_sp; 138 uint32_t first_symbol_index; 139 uint32_t last_symbol_index; 140 uint32_t first_symbol_id; 141 uint32_t last_symbol_id; 142 FileRangeMap file_range_map; 143 bool file_range_map_valid; 144 145 146 CompileUnitInfo() : 147 so_file (), 148 oso_path (), 149 oso_mod_time (), 150 oso_sp (), 151 compile_unit_sp (), 152 first_symbol_index (UINT32_MAX), 153 last_symbol_index (UINT32_MAX), 154 first_symbol_id (UINT32_MAX), 155 last_symbol_id (UINT32_MAX), 156 file_range_map (), 157 file_range_map_valid (false) 158 { 159 } 160 161 const FileRangeMap & 162 GetFileRangeMap(SymbolFileDWARFDebugMap *exe_symfile); 163 }; 164 165 //------------------------------------------------------------------ 166 // Protected Member Functions 167 //------------------------------------------------------------------ 168 void 169 InitOSO (); 170 171 static uint32_t 172 GetOSOIndexFromUserID (lldb::user_id_t uid) 173 { 174 return (uint32_t)((uid >> 32ull) - 1ull); 175 } 176 177 static SymbolFileDWARF * 178 GetSymbolFileAsSymbolFileDWARF (SymbolFile *sym_file); 179 180 bool 181 GetFileSpecForSO (uint32_t oso_idx, lldb_private::FileSpec &file_spec); 182 183 CompileUnitInfo * 184 GetCompUnitInfo (const lldb_private::SymbolContext& sc); 185 186 size_t 187 GetCompUnitInfosForModule (const lldb_private::Module *oso_module, 188 std::vector<CompileUnitInfo *>& cu_infos); 189 190 lldb_private::Module * 191 GetModuleByCompUnitInfo (CompileUnitInfo *comp_unit_info); 192 193 lldb_private::Module * 194 GetModuleByOSOIndex (uint32_t oso_idx); 195 196 lldb_private::ObjectFile * 197 GetObjectFileByCompUnitInfo (CompileUnitInfo *comp_unit_info); 198 199 lldb_private::ObjectFile * 200 GetObjectFileByOSOIndex (uint32_t oso_idx); 201 202 uint32_t 203 GetCompUnitInfoIndex (const CompileUnitInfo *comp_unit_info); 204 205 SymbolFileDWARF * 206 GetSymbolFile (const lldb_private::SymbolContext& sc); 207 208 SymbolFileDWARF * 209 GetSymbolFileByCompUnitInfo (CompileUnitInfo *comp_unit_info); 210 211 SymbolFileDWARF * 212 GetSymbolFileByOSOIndex (uint32_t oso_idx); 213 214 // If closure returns "false", iteration continues. If it returns 215 // "true", iteration terminates. 216 void 217 ForEachSymbolFile (std::function<bool (SymbolFileDWARF *)> closure) 218 { 219 for (uint32_t oso_idx = 0, num_oso_idxs = m_compile_unit_infos.size(); 220 oso_idx < num_oso_idxs; 221 ++oso_idx) 222 { 223 if (SymbolFileDWARF *oso_dwarf = GetSymbolFileByOSOIndex (oso_idx)) 224 { 225 if (closure(oso_dwarf)) 226 return; 227 } 228 } 229 } 230 231 CompileUnitInfo * 232 GetCompileUnitInfoForSymbolWithIndex (uint32_t symbol_idx, uint32_t *oso_idx_ptr); 233 234 CompileUnitInfo * 235 GetCompileUnitInfoForSymbolWithID (lldb::user_id_t symbol_id, uint32_t *oso_idx_ptr); 236 237 static int 238 SymbolContainsSymbolWithIndex (uint32_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info); 239 240 static int 241 SymbolContainsSymbolWithID (lldb::user_id_t *symbol_idx_ptr, const CompileUnitInfo *comp_unit_info); 242 243 uint32_t 244 PrivateFindGlobalVariables (const lldb_private::ConstString &name, 245 const lldb_private::CompilerDeclContext *parent_decl_ctx, 246 const std::vector<uint32_t> &name_symbol_indexes, 247 uint32_t max_matches, 248 lldb_private::VariableList& variables); 249 250 251 void 252 SetCompileUnit (SymbolFileDWARF *oso_dwarf, const lldb::CompUnitSP &cu_sp); 253 254 lldb::CompUnitSP 255 GetCompileUnit (SymbolFileDWARF *oso_dwarf); 256 257 CompileUnitInfo * 258 GetCompileUnitInfo (SymbolFileDWARF *oso_dwarf); 259 260 lldb::TypeSP 261 FindDefinitionTypeForDWARFDeclContext (const DWARFDeclContext &die_decl_ctx); 262 263 bool 264 Supports_DW_AT_APPLE_objc_complete_type (SymbolFileDWARF *skip_dwarf_oso); 265 266 lldb::TypeSP 267 FindCompleteObjCDefinitionTypeForDIE (const DWARFDIE &die, 268 const lldb_private::ConstString &type_name, 269 bool must_be_implementation); 270 271 272 UniqueDWARFASTTypeMap & 273 GetUniqueDWARFASTTypeMap () 274 { 275 return m_unique_ast_type_map; 276 } 277 278 279 //------------------------------------------------------------------ 280 // OSOEntry 281 //------------------------------------------------------------------ 282 class OSOEntry 283 { 284 public: 285 286 OSOEntry () : 287 m_exe_sym_idx (UINT32_MAX), 288 m_oso_file_addr (LLDB_INVALID_ADDRESS) 289 { 290 } 291 292 OSOEntry (uint32_t exe_sym_idx, 293 lldb::addr_t oso_file_addr) : 294 m_exe_sym_idx (exe_sym_idx), 295 m_oso_file_addr (oso_file_addr) 296 { 297 } 298 299 uint32_t 300 GetExeSymbolIndex () const 301 { 302 return m_exe_sym_idx; 303 } 304 305 bool 306 operator < (const OSOEntry &rhs) const 307 { 308 return m_exe_sym_idx < rhs.m_exe_sym_idx; 309 } 310 311 lldb::addr_t 312 GetOSOFileAddress () const 313 { 314 return m_oso_file_addr; 315 } 316 317 void 318 SetOSOFileAddress (lldb::addr_t oso_file_addr) 319 { 320 m_oso_file_addr = oso_file_addr; 321 } 322 protected: 323 uint32_t m_exe_sym_idx; 324 lldb::addr_t m_oso_file_addr; 325 }; 326 327 typedef lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, OSOEntry> DebugMap; 328 329 //------------------------------------------------------------------ 330 // Member Variables 331 //------------------------------------------------------------------ 332 std::bitset<kNumFlags> m_flags; 333 std::vector<CompileUnitInfo> m_compile_unit_infos; 334 std::vector<uint32_t> m_func_indexes; // Sorted by address 335 std::vector<uint32_t> m_glob_indexes; 336 std::map<lldb_private::ConstString, OSOInfoSP> m_oso_map; 337 UniqueDWARFASTTypeMap m_unique_ast_type_map; 338 lldb_private::LazyBool m_supports_DW_AT_APPLE_objc_complete_type; 339 DebugMap m_debug_map; 340 341 //------------------------------------------------------------------ 342 // When an object file from the debug map gets parsed in 343 // SymbolFileDWARF, it needs to tell the debug map about the object 344 // files addresses by calling this function once for each N_FUN, 345 // N_GSYM and N_STSYM and after all entries in the debug map have 346 // been matched up, FinalizeOSOFileRanges() should be called. 347 //------------------------------------------------------------------ 348 bool 349 AddOSOFileRange (CompileUnitInfo *cu_info, 350 lldb::addr_t exe_file_addr, 351 lldb::addr_t oso_file_addr, 352 lldb::addr_t oso_byte_size); 353 354 //------------------------------------------------------------------ 355 // Called after calling AddOSOFileRange() for each object file debug 356 // map entry to finalize the info for the unlinked compile unit. 357 //------------------------------------------------------------------ 358 void 359 FinalizeOSOFileRanges (CompileUnitInfo *cu_info); 360 361 //------------------------------------------------------------------ 362 /// Convert \a addr from a .o file address, to an executable address. 363 /// 364 /// @param[in] addr 365 /// A section offset address from a .o file 366 /// 367 /// @return 368 /// Returns true if \a addr was converted to be an executable 369 /// section/offset address, false otherwise. 370 //------------------------------------------------------------------ 371 bool 372 LinkOSOAddress (lldb_private::Address &addr); 373 374 //------------------------------------------------------------------ 375 /// Convert a .o file "file address" to an executable "file address". 376 /// 377 /// @param[in] oso_symfile 378 /// The DWARF symbol file that contains \a oso_file_addr 379 /// 380 /// @param[in] oso_file_addr 381 /// A .o file "file address" to convert. 382 /// 383 /// @return 384 /// LLDB_INVALID_ADDRESS if \a oso_file_addr is not in the 385 /// linked executable, otherwise a valid "file address" from the 386 /// linked executable that contains the debug map. 387 //------------------------------------------------------------------ 388 lldb::addr_t 389 LinkOSOFileAddress (SymbolFileDWARF *oso_symfile, lldb::addr_t oso_file_addr); 390 391 //------------------------------------------------------------------ 392 /// Given a line table full of lines with "file addresses" that are 393 /// for a .o file represented by \a oso_symfile, link a new line table 394 /// and return it. 395 /// 396 /// @param[in] oso_symfile 397 /// The DWARF symbol file that produced the \a line_table 398 /// 399 /// @param[in] addr 400 /// A section offset address from a .o file 401 /// 402 /// @return 403 /// Returns a valid line table full of linked addresses, or NULL 404 /// if none of the line table addresses exist in the main 405 /// executable. 406 //------------------------------------------------------------------ 407 lldb_private::LineTable * 408 LinkOSOLineTable (SymbolFileDWARF *oso_symfile, 409 lldb_private::LineTable *line_table); 410 411 size_t 412 AddOSOARanges (SymbolFileDWARF* dwarf2Data, 413 DWARFDebugAranges* debug_aranges); 414 }; 415 416 #endif // #ifndef SymbolFileDWARF_SymbolFileDWARFDebugMap_h_ 417