1 //===-- UnwindTable.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 LLDB_SYMBOL_UNWINDTABLE_H 10 #define LLDB_SYMBOL_UNWINDTABLE_H 11 12 #include <map> 13 #include <mutex> 14 #include <optional> 15 16 #include "lldb/lldb-private.h" 17 18 namespace lldb_private { 19 20 // A class which holds all the FuncUnwinders objects for a given ObjectFile. 21 // The UnwindTable is populated with FuncUnwinders objects lazily during the 22 // debug session. 23 24 class UnwindTable { 25 public: 26 /// Create an Unwind table using the data in the given module. 27 explicit UnwindTable(Module &module); 28 29 ~UnwindTable(); 30 31 lldb_private::CallFrameInfo *GetObjectFileUnwindInfo(); 32 33 lldb_private::DWARFCallFrameInfo *GetEHFrameInfo(); 34 lldb_private::DWARFCallFrameInfo *GetDebugFrameInfo(); 35 36 lldb_private::CompactUnwindInfo *GetCompactUnwindInfo(); 37 38 ArmUnwindInfo *GetArmUnwindInfo(); 39 SymbolFile *GetSymbolFile(); 40 41 lldb::FuncUnwindersSP 42 GetFuncUnwindersContainingAddress(const Address &addr, 43 const SymbolContext &sc); 44 45 bool GetAllowAssemblyEmulationUnwindPlans(); 46 47 // Normally when we create a new FuncUnwinders object we track it in this 48 // UnwindTable so it can be reused later. But for the target modules show- 49 // unwind we want to create brand new UnwindPlans for the function of 50 // interest - so ignore any existing FuncUnwinders for that function and 51 // don't add this new one to our UnwindTable. This FuncUnwinders object does 52 // have a reference to the UnwindTable but the lifetime of this uncached 53 // FuncUnwinders is expected to be short so in practice this will not be a 54 // problem. 55 lldb::FuncUnwindersSP 56 GetUncachedFuncUnwindersContainingAddress(const Address &addr, 57 const SymbolContext &sc); 58 59 ArchSpec GetArchitecture(); 60 61 /// Called after an ObjectFile/SymbolFile has been added to a Module to add 62 /// any new unwind sections that may now be available. 63 void ModuleWasUpdated(); 64 65 private: 66 void Dump(Stream &s); 67 68 void Initialize(); 69 AddressRanges GetAddressRanges(const Address &addr, const SymbolContext &sc); 70 71 typedef std::map<lldb::addr_t, lldb::FuncUnwindersSP> collection; 72 typedef collection::iterator iterator; 73 typedef collection::const_iterator const_iterator; 74 75 Module &m_module; 76 collection m_unwinds; 77 78 bool m_scanned_all_unwind_sources; // true when we have looked at the 79 // ObjectFile and SymbolFile for all 80 // sources of unwind information; false if 81 // we haven't done that yet, or one of the 82 // files has been updated in the Module. 83 std::mutex m_mutex; 84 85 std::unique_ptr<CallFrameInfo> m_object_file_unwind_up; 86 std::unique_ptr<DWARFCallFrameInfo> m_eh_frame_up; 87 std::unique_ptr<DWARFCallFrameInfo> m_debug_frame_up; 88 std::unique_ptr<CompactUnwindInfo> m_compact_unwind_up; 89 std::unique_ptr<ArmUnwindInfo> m_arm_unwind_up; 90 91 UnwindTable(const UnwindTable &) = delete; 92 const UnwindTable &operator=(const UnwindTable &) = delete; 93 }; 94 95 } // namespace lldb_private 96 97 #endif // LLDB_SYMBOL_UNWINDTABLE_H 98