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