xref: /freebsd/contrib/llvm-project/lldb/include/lldb/Symbol/UnwindTable.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
10b57cec5SDimitry Andric //===-- UnwindTable.h -------------------------------------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
95ffd83dbSDimitry Andric #ifndef LLDB_SYMBOL_UNWINDTABLE_H
105ffd83dbSDimitry Andric #define LLDB_SYMBOL_UNWINDTABLE_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include <map>
130b57cec5SDimitry Andric #include <mutex>
14bdd1243dSDimitry Andric #include <optional>
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "lldb/lldb-private.h"
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric namespace lldb_private {
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric // A class which holds all the FuncUnwinders objects for a given ObjectFile.
210b57cec5SDimitry Andric // The UnwindTable is populated with FuncUnwinders objects lazily during the
220b57cec5SDimitry Andric // debug session.
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric class UnwindTable {
250b57cec5SDimitry Andric public:
260b57cec5SDimitry Andric   /// Create an Unwind table using the data in the given module.
270b57cec5SDimitry Andric   explicit UnwindTable(Module &module);
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric   ~UnwindTable();
300b57cec5SDimitry Andric 
319dba64beSDimitry Andric   lldb_private::CallFrameInfo *GetObjectFileUnwindInfo();
329dba64beSDimitry Andric 
330b57cec5SDimitry Andric   lldb_private::DWARFCallFrameInfo *GetEHFrameInfo();
340b57cec5SDimitry Andric   lldb_private::DWARFCallFrameInfo *GetDebugFrameInfo();
350b57cec5SDimitry Andric 
360b57cec5SDimitry Andric   lldb_private::CompactUnwindInfo *GetCompactUnwindInfo();
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   ArmUnwindInfo *GetArmUnwindInfo();
390b57cec5SDimitry Andric   SymbolFile *GetSymbolFile();
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   lldb::FuncUnwindersSP GetFuncUnwindersContainingAddress(const Address &addr,
420b57cec5SDimitry Andric                                                           SymbolContext &sc);
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric   bool GetAllowAssemblyEmulationUnwindPlans();
450b57cec5SDimitry Andric 
460b57cec5SDimitry Andric   // Normally when we create a new FuncUnwinders object we track it in this
470b57cec5SDimitry Andric   // UnwindTable so it can be reused later.  But for the target modules show-
480b57cec5SDimitry Andric   // unwind we want to create brand new UnwindPlans for the function of
490b57cec5SDimitry Andric   // interest - so ignore any existing FuncUnwinders for that function and
500b57cec5SDimitry Andric   // don't add this new one to our UnwindTable. This FuncUnwinders object does
510b57cec5SDimitry Andric   // have a reference to the UnwindTable but the lifetime of this uncached
520b57cec5SDimitry Andric   // FuncUnwinders is expected to be short so in practice this will not be a
530b57cec5SDimitry Andric   // problem.
540b57cec5SDimitry Andric   lldb::FuncUnwindersSP
550b57cec5SDimitry Andric   GetUncachedFuncUnwindersContainingAddress(const Address &addr,
5606c3fb27SDimitry Andric                                             const SymbolContext &sc);
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   ArchSpec GetArchitecture();
590b57cec5SDimitry Andric 
60*0fca6ea1SDimitry Andric   /// Called after a SymbolFile has been added to a Module to add any new
61*0fca6ea1SDimitry Andric   /// unwind sections that may now be available.
62*0fca6ea1SDimitry Andric   void Update();
63*0fca6ea1SDimitry Andric 
640b57cec5SDimitry Andric private:
650b57cec5SDimitry Andric   void Dump(Stream &s);
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric   void Initialize();
68bdd1243dSDimitry Andric   std::optional<AddressRange> GetAddressRange(const Address &addr,
6906c3fb27SDimitry Andric                                               const SymbolContext &sc);
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric   typedef std::map<lldb::addr_t, lldb::FuncUnwindersSP> collection;
720b57cec5SDimitry Andric   typedef collection::iterator iterator;
730b57cec5SDimitry Andric   typedef collection::const_iterator const_iterator;
740b57cec5SDimitry Andric 
750b57cec5SDimitry Andric   Module &m_module;
760b57cec5SDimitry Andric   collection m_unwinds;
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   bool m_initialized; // delay some initialization until ObjectFile is set up
790b57cec5SDimitry Andric   std::mutex m_mutex;
800b57cec5SDimitry Andric 
819dba64beSDimitry Andric   std::unique_ptr<CallFrameInfo> m_object_file_unwind_up;
820b57cec5SDimitry Andric   std::unique_ptr<DWARFCallFrameInfo> m_eh_frame_up;
830b57cec5SDimitry Andric   std::unique_ptr<DWARFCallFrameInfo> m_debug_frame_up;
840b57cec5SDimitry Andric   std::unique_ptr<CompactUnwindInfo> m_compact_unwind_up;
850b57cec5SDimitry Andric   std::unique_ptr<ArmUnwindInfo> m_arm_unwind_up;
860b57cec5SDimitry Andric 
875ffd83dbSDimitry Andric   UnwindTable(const UnwindTable &) = delete;
885ffd83dbSDimitry Andric   const UnwindTable &operator=(const UnwindTable &) = delete;
890b57cec5SDimitry Andric };
900b57cec5SDimitry Andric 
910b57cec5SDimitry Andric } // namespace lldb_private
920b57cec5SDimitry Andric 
935ffd83dbSDimitry Andric #endif // LLDB_SYMBOL_UNWINDTABLE_H
94