LLDB  mainline
UnwindAssemblyInstEmulation.h
Go to the documentation of this file.
1 //===-- UnwindAssemblyInstEmulation.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_SOURCE_PLUGINS_UNWINDASSEMBLY_INSTEMULATION_UNWINDASSEMBLYINSTEMULATION_H
10 #define LLDB_SOURCE_PLUGINS_UNWINDASSEMBLY_INSTEMULATION_UNWINDASSEMBLYINSTEMULATION_H
11 
13 #include "lldb/Symbol/UnwindPlan.h"
16 #include "lldb/lldb-private.h"
17 
19 public:
20  ~UnwindAssemblyInstEmulation() override = default;
21 
24  lldb_private::UnwindPlan &unwind_plan) override;
25 
26  bool
28  uint8_t *opcode_data, size_t opcode_size,
29  lldb_private::UnwindPlan &unwind_plan);
30 
31  bool
33  lldb_private::Thread &thread,
34  lldb_private::UnwindPlan &unwind_plan) override;
35 
37  lldb_private::Thread &thread,
38  lldb_private::UnwindPlan &unwind_plan) override;
39 
40  // thread may be NULL in which case we only use the Target (e.g. if this is
41  // called pre-process-launch).
42  bool
44  const lldb_private::ExecutionContext &exe_ctx,
45  lldb_private::Address &first_non_prologue_insn) override;
46 
49 
50  // PluginInterface protocol
51  static void Initialize();
52 
53  static void Terminate();
54 
56 
57  static const char *GetPluginDescriptionStatic();
58 
60 
61  uint32_t GetPluginVersion() override;
62 
63 private:
64  // Call CreateInstance to get an instance of this class
66  lldb_private::EmulateInstruction *inst_emulator)
67  : UnwindAssembly(arch), m_inst_emulator_up(inst_emulator),
68  m_range_ptr(nullptr), m_unwind_plan_ptr(nullptr), m_curr_row(),
72  if (m_inst_emulator_up.get()) {
73  m_inst_emulator_up->SetBaton(this);
76  }
77  }
78 
79  static size_t
80  ReadMemory(lldb_private::EmulateInstruction *instruction, void *baton,
82  lldb::addr_t addr, void *dst, size_t length);
83 
84  static size_t
85  WriteMemory(lldb_private::EmulateInstruction *instruction, void *baton,
87  lldb::addr_t addr, const void *dst, size_t length);
88 
89  static bool ReadRegister(lldb_private::EmulateInstruction *instruction,
90  void *baton,
91  const lldb_private::RegisterInfo *reg_info,
92  lldb_private::RegisterValue &reg_value);
93 
94  static bool
95  WriteRegister(lldb_private::EmulateInstruction *instruction, void *baton,
97  const lldb_private::RegisterInfo *reg_info,
98  const lldb_private::RegisterValue &reg_value);
99 
100  // size_t
101  // ReadMemory (lldb_private::EmulateInstruction *instruction,
102  // const lldb_private::EmulateInstruction::Context &context,
103  // lldb::addr_t addr,
104  // void *dst,
105  // size_t length);
106 
107  size_t WriteMemory(lldb_private::EmulateInstruction *instruction,
109  lldb::addr_t addr, const void *dst, size_t length);
110 
112  const lldb_private::RegisterInfo *reg_info,
113  lldb_private::RegisterValue &reg_value);
114 
117  const lldb_private::RegisterInfo *reg_info,
118  const lldb_private::RegisterValue &reg_value);
119 
120  static uint64_t
121  MakeRegisterKindValuePair(const lldb_private::RegisterInfo &reg_info);
122 
123  void SetRegisterValue(const lldb_private::RegisterInfo &reg_info,
124  const lldb_private::RegisterValue &reg_value);
125 
126  bool GetRegisterValue(const lldb_private::RegisterInfo &reg_info,
127  lldb_private::RegisterValue &reg_value);
128 
129  std::unique_ptr<lldb_private::EmulateInstruction> m_inst_emulator_up;
133  typedef std::map<uint64_t, uint64_t> PushedRegisterToAddrMap;
134  uint64_t m_initial_sp;
135  lldb_private::RegisterInfo m_cfa_reg_info;
137  typedef std::map<uint64_t, lldb_private::RegisterValue> RegisterValueMap;
140 
141  // While processing the instruction stream, we need to communicate some state
142  // change
143  // information up to the higher level loop that makes decisions about how to
144  // push
145  // the unwind instructions for the UnwindPlan we're constructing.
146 
147  // The instruction we're processing updated the UnwindPlan::Row contents
149  // The instruction is branching forward with the given offset. 0 value means
150  // no branching.
152 };
153 
154 #endif // LLDB_SOURCE_PLUGINS_UNWINDASSEMBLY_INSTEMULATION_UNWINDASSEMBLYINSTEMULATION_H
lldb_private::ExecutionContext
Definition: ExecutionContext.h:291
lldb_private::ArchSpec
Definition: ArchSpec.h:33
lldb_private::RegisterValue
Definition: RegisterValue.h:28
UnwindAssemblyInstEmulation::MakeRegisterKindValuePair
static uint64_t MakeRegisterKindValuePair(const lldb_private::RegisterInfo &reg_info)
Definition: UnwindAssemblyInstEmulation.cpp:361
UnwindAssemblyInstEmulation::m_range_ptr
lldb_private::AddressRange * m_range_ptr
Definition: UnwindAssemblyInstEmulation.h:130
UnwindAssemblyInstEmulation::Terminate
static void Terminate()
Definition: UnwindAssemblyInstEmulation.cpp:348
lldb_private::EmulateInstruction::Context
Definition: EmulateInstruction.h:184
UnwindAssemblyInstEmulation::m_curr_row
lldb_private::UnwindPlan::RowSP m_curr_row
Definition: UnwindAssemblyInstEmulation.h:132
UnwindAssemblyInstEmulation::m_register_values
RegisterValueMap m_register_values
Definition: UnwindAssemblyInstEmulation.h:138
UnwindAssemblyInstEmulation::GetRegisterValue
bool GetRegisterValue(const lldb_private::RegisterInfo &reg_info, lldb_private::RegisterValue &reg_value)
Definition: UnwindAssemblyInstEmulation.cpp:376
RegisterValue.h
UnwindAssemblyInstEmulation::m_forward_branch_offset
uint32_t m_forward_branch_offset
Definition: UnwindAssemblyInstEmulation.h:151
lldb_private::UnwindAssembly
Definition: UnwindAssembly.h:18
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
UnwindAssemblyInstEmulation::FirstNonPrologueInsn
bool FirstNonPrologueInsn(lldb_private::AddressRange &func, const lldb_private::ExecutionContext &exe_ctx, lldb_private::Address &first_non_prologue_insn) override
Definition: UnwindAssemblyInstEmulation.cpp:319
UnwindAssemblyInstEmulation::UnwindAssemblyInstEmulation
UnwindAssemblyInstEmulation(const lldb_private::ArchSpec &arch, lldb_private::EmulateInstruction *inst_emulator)
Definition: UnwindAssemblyInstEmulation.h:65
UnwindAssemblyInstEmulation::m_curr_row_modified
bool m_curr_row_modified
Definition: UnwindAssemblyInstEmulation.h:148
UnwindAssemblyInstEmulation::m_inst_emulator_up
std::unique_ptr< lldb_private::EmulateInstruction > m_inst_emulator_up
Definition: UnwindAssemblyInstEmulation.h:129
EmulateInstruction.h
UnwindAssemblyInstEmulation::WriteMemory
static size_t WriteMemory(lldb_private::EmulateInstruction *instruction, void *baton, const lldb_private::EmulateInstruction::Context &context, lldb::addr_t addr, const void *dst, size_t length)
Definition: UnwindAssemblyInstEmulation.cpp:409
UnwindAssemblyInstEmulation::PushedRegisterToAddrMap
std::map< uint64_t, uint64_t > PushedRegisterToAddrMap
Definition: UnwindAssemblyInstEmulation.h:133
lldb_private::Thread
Definition: Thread.h:62
UnwindAssemblyInstEmulation::WriteRegister
static bool WriteRegister(lldb_private::EmulateInstruction *instruction, void *baton, const lldb_private::EmulateInstruction::Context &context, const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &reg_value)
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::AddressRange
Definition: AddressRange.h:25
UnwindAssemblyInstEmulation::m_fp_is_cfa
bool m_fp_is_cfa
Definition: UnwindAssemblyInstEmulation.h:136
UnwindAssemblyInstEmulation::GetPluginName
lldb_private::ConstString GetPluginName() override
Definition: UnwindAssemblyInstEmulation.cpp:337
UnwindAssemblyInstEmulation::GetPluginDescriptionStatic
static const char * GetPluginDescriptionStatic()
Definition: UnwindAssemblyInstEmulation.cpp:357
UnwindAssemblyInstEmulation::Initialize
static void Initialize()
Definition: UnwindAssemblyInstEmulation.cpp:343
UnwindAssemblyInstEmulation::m_initial_sp
uint64_t m_initial_sp
Definition: UnwindAssemblyInstEmulation.h:134
UnwindAssemblyInstEmulation::GetPluginVersion
uint32_t GetPluginVersion() override
Definition: UnwindAssemblyInstEmulation.cpp:341
UnwindAssemblyInstEmulation
Definition: UnwindAssemblyInstEmulation.h:18
UnwindPlan.h
UnwindAssemblyInstEmulation::GetFastUnwindPlan
bool GetFastUnwindPlan(lldb_private::AddressRange &func, lldb_private::Thread &thread, lldb_private::UnwindPlan &unwind_plan) override
Definition: UnwindAssemblyInstEmulation.cpp:313
lldb-private.h
UnwindAssemblyInstEmulation::RegisterValueMap
std::map< uint64_t, lldb_private::RegisterValue > RegisterValueMap
Definition: UnwindAssemblyInstEmulation.h:137
lldb_private::UnwindPlan::RowSP
std::shared_ptr< Row > RowSP
Definition: UnwindPlan.h:395
UnwindAssemblyInstEmulation::ReadRegister
static bool ReadRegister(lldb_private::EmulateInstruction *instruction, void *baton, const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &reg_value)
uint32_t
lldb_private::EmulateInstruction
Definition: EmulateInstruction.h:93
UnwindAssemblyInstEmulation::m_pushed_regs
PushedRegisterToAddrMap m_pushed_regs
Definition: UnwindAssemblyInstEmulation.h:139
UnwindAssemblyInstEmulation::GetPluginNameStatic
static lldb_private::ConstString GetPluginNameStatic()
Definition: UnwindAssemblyInstEmulation.cpp:352
lldb_private::Address
Definition: Address.h:59
UnwindAssemblyInstEmulation::AugmentUnwindPlanFromCallSite
bool AugmentUnwindPlanFromCallSite(lldb_private::AddressRange &func, lldb_private::Thread &thread, lldb_private::UnwindPlan &unwind_plan) override
Definition: UnwindAssemblyInstEmulation.cpp:308
UnwindAssemblyInstEmulation::~UnwindAssemblyInstEmulation
~UnwindAssemblyInstEmulation() override=default
UnwindAssemblyInstEmulation::CreateInstance
static lldb_private::UnwindAssembly * CreateInstance(const lldb_private::ArchSpec &arch)
Definition: UnwindAssemblyInstEmulation.cpp:326
UnwindAssemblyInstEmulation::SetRegisterValue
void SetRegisterValue(const lldb_private::RegisterInfo &reg_info, const lldb_private::RegisterValue &reg_value)
Definition: UnwindAssemblyInstEmulation.cpp:371
UnwindAssemblyInstEmulation::GetNonCallSiteUnwindPlanFromAssembly
bool GetNonCallSiteUnwindPlanFromAssembly(lldb_private::AddressRange &func, lldb_private::Thread &thread, lldb_private::UnwindPlan &unwind_plan) override
Definition: UnwindAssemblyInstEmulation.cpp:35
UnwindAssemblyInstEmulation::m_cfa_reg_info
lldb_private::RegisterInfo m_cfa_reg_info
Definition: UnwindAssemblyInstEmulation.h:135
lldb_private::UnwindAssembly::UnwindAssembly
UnwindAssembly(const ArchSpec &arch)
Definition: UnwindAssembly.cpp:31
UnwindAssembly.h
UnwindAssemblyInstEmulation::m_unwind_plan_ptr
lldb_private::UnwindPlan * m_unwind_plan_ptr
Definition: UnwindAssemblyInstEmulation.h:131
lldb_private::UnwindPlan
Definition: UnwindPlan.h:53
UnwindAssemblyInstEmulation::ReadMemory
static size_t ReadMemory(lldb_private::EmulateInstruction *instruction, void *baton, const lldb_private::EmulateInstruction::Context &context, lldb::addr_t addr, void *dst, size_t length)
Definition: UnwindAssemblyInstEmulation.cpp:390