1353358Sdim//===-- UnwindTable.h -------------------------------------------*- C++ -*-===//
2254721Semaste//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6254721Semaste//
7254721Semaste//===----------------------------------------------------------------------===//
8254721Semaste
9254721Semaste#ifndef liblldb_UnwindTable_h
10254721Semaste#define liblldb_UnwindTable_h
11254721Semaste
12254721Semaste#include <map>
13309124Sdim#include <mutex>
14254721Semaste
15314564Sdim#include "lldb/lldb-private.h"
16254721Semaste
17254721Semastenamespace lldb_private {
18254721Semaste
19254721Semaste// A class which holds all the FuncUnwinders objects for a given ObjectFile.
20341825Sdim// The UnwindTable is populated with FuncUnwinders objects lazily during the
21341825Sdim// debug session.
22254721Semaste
23314564Sdimclass UnwindTable {
24254721Semastepublic:
25353358Sdim  /// Create an Unwind table using the data in the given module.
26353358Sdim  explicit UnwindTable(Module &module);
27353358Sdim
28314564Sdim  ~UnwindTable();
29254721Semaste
30360784Sdim  lldb_private::CallFrameInfo *GetObjectFileUnwindInfo();
31360784Sdim
32314564Sdim  lldb_private::DWARFCallFrameInfo *GetEHFrameInfo();
33321369Sdim  lldb_private::DWARFCallFrameInfo *GetDebugFrameInfo();
34254721Semaste
35314564Sdim  lldb_private::CompactUnwindInfo *GetCompactUnwindInfo();
36280031Sdim
37314564Sdim  ArmUnwindInfo *GetArmUnwindInfo();
38353358Sdim  SymbolFile *GetSymbolFile();
39296417Sdim
40314564Sdim  lldb::FuncUnwindersSP GetFuncUnwindersContainingAddress(const Address &addr,
41314564Sdim                                                          SymbolContext &sc);
42254721Semaste
43314564Sdim  bool GetAllowAssemblyEmulationUnwindPlans();
44309124Sdim
45314564Sdim  // Normally when we create a new FuncUnwinders object we track it in this
46341825Sdim  // UnwindTable so it can be reused later.  But for the target modules show-
47341825Sdim  // unwind we want to create brand new UnwindPlans for the function of
48341825Sdim  // interest - so ignore any existing FuncUnwinders for that function and
49341825Sdim  // don't add this new one to our UnwindTable. This FuncUnwinders object does
50341825Sdim  // have a reference to the UnwindTable but the lifetime of this uncached
51341825Sdim  // FuncUnwinders is expected to be short so in practice this will not be a
52341825Sdim  // problem.
53314564Sdim  lldb::FuncUnwindersSP
54314564Sdim  GetUncachedFuncUnwindersContainingAddress(const Address &addr,
55314564Sdim                                            SymbolContext &sc);
56254721Semaste
57344779Sdim  ArchSpec GetArchitecture();
58276479Sdim
59254721Semasteprivate:
60314564Sdim  void Dump(Stream &s);
61254721Semaste
62314564Sdim  void Initialize();
63321369Sdim  llvm::Optional<AddressRange> GetAddressRange(const Address &addr,
64321369Sdim                                               SymbolContext &sc);
65254721Semaste
66314564Sdim  typedef std::map<lldb::addr_t, lldb::FuncUnwindersSP> collection;
67314564Sdim  typedef collection::iterator iterator;
68314564Sdim  typedef collection::const_iterator const_iterator;
69254721Semaste
70353358Sdim  Module &m_module;
71314564Sdim  collection m_unwinds;
72254721Semaste
73314564Sdim  bool m_initialized; // delay some initialization until ObjectFile is set up
74314564Sdim  std::mutex m_mutex;
75296417Sdim
76360784Sdim  std::unique_ptr<CallFrameInfo> m_object_file_unwind_up;
77314564Sdim  std::unique_ptr<DWARFCallFrameInfo> m_eh_frame_up;
78321369Sdim  std::unique_ptr<DWARFCallFrameInfo> m_debug_frame_up;
79314564Sdim  std::unique_ptr<CompactUnwindInfo> m_compact_unwind_up;
80314564Sdim  std::unique_ptr<ArmUnwindInfo> m_arm_unwind_up;
81314564Sdim
82314564Sdim  DISALLOW_COPY_AND_ASSIGN(UnwindTable);
83254721Semaste};
84254721Semaste
85254721Semaste} // namespace lldb_private
86254721Semaste
87314564Sdim#endif // liblldb_UnwindTable_h
88