1 //===-- DWARFDebugInfo.h ----------------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef SymbolFileDWARF_DWARFDebugInfo_h_ 10 #define SymbolFileDWARF_DWARFDebugInfo_h_ 11 12 #include <map> 13 #include <vector> 14 15 #include "DWARFDIE.h" 16 #include "DWARFTypeUnit.h" 17 #include "DWARFUnit.h" 18 #include "SymbolFileDWARF.h" 19 #include "lldb/Core/STLUtils.h" 20 #include "lldb/lldb-private.h" 21 #include "llvm/Support/Error.h" 22 23 namespace lldb_private { 24 class DWARFContext; 25 } 26 27 typedef std::multimap<const char *, dw_offset_t, CStringCompareFunctionObject> 28 CStringToDIEMap; 29 typedef CStringToDIEMap::iterator CStringToDIEMapIter; 30 typedef CStringToDIEMap::const_iterator CStringToDIEMapConstIter; 31 32 class DWARFDebugInfo { 33 public: 34 typedef dw_offset_t (*Callback)(SymbolFileDWARF *dwarf2Data, 35 DWARFUnit *cu, 36 DWARFDebugInfoEntry *die, 37 const dw_offset_t next_offset, 38 const uint32_t depth, void *userData); 39 40 explicit DWARFDebugInfo(SymbolFileDWARF &dwarf, 41 lldb_private::DWARFContext &context); 42 43 size_t GetNumUnits(); 44 DWARFUnit *GetUnitAtIndex(lldb::user_id_t idx); 45 DWARFUnit *GetUnitAtOffset(DIERef::Section section, dw_offset_t cu_offset, 46 uint32_t *idx_ptr = nullptr); 47 DWARFUnit *GetUnitContainingDIEOffset(DIERef::Section section, 48 dw_offset_t die_offset); 49 DWARFUnit *GetUnit(const DIERef &die_ref); 50 DWARFTypeUnit *GetTypeUnitForHash(uint64_t hash); 51 bool ContainsTypeUnits(); 52 DWARFDIE GetDIEForDIEOffset(DIERef::Section section, 53 dw_offset_t die_offset); 54 DWARFDIE GetDIE(const DIERef &die_ref); 55 56 enum { 57 eDumpFlag_Verbose = (1 << 0), // Verbose dumping 58 eDumpFlag_ShowForm = (1 << 1), // Show the DW_form type 59 eDumpFlag_ShowAncestors = 60 (1 << 2) // Show all parent DIEs when dumping single DIEs 61 }; 62 63 llvm::Expected<DWARFDebugAranges &> GetCompileUnitAranges(); 64 65 protected: 66 typedef std::vector<DWARFUnitSP> UnitColl; 67 68 SymbolFileDWARF &m_dwarf; 69 lldb_private::DWARFContext &m_context; 70 UnitColl m_units; 71 std::unique_ptr<DWARFDebugAranges> 72 m_cu_aranges_up; // A quick address to compile unit table 73 74 std::vector<std::pair<uint64_t, uint32_t>> m_type_hash_to_unit_index; 75 76 private: 77 // All parsing needs to be done partially any managed by this class as 78 // accessors are called. 79 void ParseUnitHeadersIfNeeded(); 80 81 void ParseUnitsFor(DIERef::Section section); 82 83 uint32_t FindUnitIndex(DIERef::Section section, dw_offset_t offset); 84 85 DISALLOW_COPY_AND_ASSIGN(DWARFDebugInfo); 86 }; 87 88 #endif // SymbolFileDWARF_DWARFDebugInfo_h_ 89