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