LLDB  mainline
UnwindLLDB.h
Go to the documentation of this file.
1 //===-- UnwindLLDB.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_TARGET_UNWINDLLDB_H
10 #define LLDB_TARGET_UNWINDLLDB_H
11 
12 #include <vector>
13 
16 #include "lldb/Symbol/UnwindPlan.h"
18 #include "lldb/Target/Unwind.h"
20 #include "lldb/lldb-public.h"
21 
22 namespace lldb_private {
23 
24 class RegisterContextUnwind;
25 
27 public:
29 
30  ~UnwindLLDB() override = default;
31 
36  };
37 
38 protected:
40 
43  eRegisterNotSaved = 0, // register was not preserved by callee. If
44  // volatile reg, is unavailable
45  eRegisterSavedAtMemoryLocation, // register is saved at a specific word of
46  // target mem (target_memory_location)
47  eRegisterInRegister, // register is available in a (possible other)
48  // register (register_number)
49  eRegisterSavedAtHostMemoryLocation, // register is saved at a word in
50  // lldb's address space
51  eRegisterValueInferred, // register val was computed (and is in
52  // inferred_value)
53  eRegisterInLiveRegisterContext // register value is in a live (stack frame
54  // #0) register
55  };
56  int type;
57  union {
59  uint32_t
60  register_number; // in eRegisterKindLLDB register numbering system
62  uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer ==
63  // cfa + offset
64  } location;
65  };
66 
67  void DoClear() override {
68  m_frames.clear();
69  m_candidate_frame.reset();
70  m_unwind_complete = false;
71  }
72 
73  uint32_t DoGetFrameCount() override;
74 
75  bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
76  lldb::addr_t &start_pc,
77  bool &behaves_like_zeroth_frame) override;
78 
79  lldb::RegisterContextSP
81 
82  typedef std::shared_ptr<RegisterContextUnwind> RegisterContextLLDBSP;
83 
84  // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame
85  // 1's RegisterContextUnwind)
86  // The RegisterContext for frame_num must already exist or this returns an
87  // empty shared pointer.
89 
90  // Iterate over the RegisterContextUnwind's in our m_frames vector, look for
91  // the first one that has a saved location for this reg.
94  uint32_t starting_frame_num, bool pc_register);
95 
96  /// Provide the list of user-specified trap handler functions
97  ///
98  /// The Platform is one source of trap handler function names; that
99  /// may be augmented via a setting. The setting needs to be converted
100  /// into an array of ConstStrings before it can be used - we only want
101  /// to do that once per thread so it's here in the UnwindLLDB object.
102  ///
103  /// \return
104  /// Vector of ConstStrings of trap handler function names. May be
105  /// empty.
106  const std::vector<ConstString> &GetUserSpecifiedTrapHandlerFunctionNames() {
108  }
109 
110 private:
111  struct Cursor {
113  LLDB_INVALID_ADDRESS; // The start address of the function/symbol for
114  // this frame - current pc if unknown
115  lldb::addr_t cfa = LLDB_INVALID_ADDRESS; // The canonical frame address for
116  // this stack frame
117  lldb_private::SymbolContext sctx; // A symbol context we'll contribute to &
118  // provide to the StackFrame creation
120  reg_ctx_lldb_sp; // These are all RegisterContextUnwind's
121 
122  Cursor() {}
123 
124  private:
125  Cursor(const Cursor &) = delete;
126  const Cursor &operator=(const Cursor &) = delete;
127  };
128 
129  typedef std::shared_ptr<Cursor> CursorSP;
130  std::vector<CursorSP> m_frames;
132  bool m_unwind_complete; // If this is true, we've enumerated all the frames in
133  // the stack, and m_frames.size() is the
134  // number of frames, etc. Otherwise we've only gone as far as directly asked,
135  // and m_frames.size()
136  // is how far we've currently gone.
137 
138  std::vector<ConstString> m_user_supplied_trap_handler_functions;
139 
140  // Check if Full UnwindPlan of First frame is valid or not.
141  // If not then try Fallback UnwindPlan of the frame. If Fallback
142  // UnwindPlan succeeds then update the Full UnwindPlan with the
143  // Fallback UnwindPlan.
145 
147 
148  bool AddOneMoreFrame(ABI *abi);
149 
150  bool AddFirstFrame();
151 
152  // For UnwindLLDB only
153  UnwindLLDB(const UnwindLLDB &) = delete;
154  const UnwindLLDB &operator=(const UnwindLLDB &) = delete;
155 };
156 
157 } // namespace lldb_private
158 
159 #endif // LLDB_TARGET_UNWINDLLDB_H
lldb_private::UnwindLLDB::GetUserSpecifiedTrapHandlerFunctionNames
const std::vector< ConstString > & GetUserSpecifiedTrapHandlerFunctionNames()
Provide the list of user-specified trap handler functions.
Definition: UnwindLLDB.h:106
lldb-public.h
lldb_private::UnwindLLDB::CursorSP
std::shared_ptr< Cursor > CursorSP
Definition: UnwindLLDB.h:129
lldb_private::UnwindLLDB::RegisterLocation::type
int type
Definition: UnwindLLDB.h:56
lldb_private::UnwindLLDB::Cursor::reg_ctx_lldb_sp
RegisterContextLLDBSP reg_ctx_lldb_sp
Definition: UnwindLLDB.h:120
lldb_private::UnwindLLDB::Cursor::operator=
const Cursor & operator=(const Cursor &)=delete
lldb_private::ABI
Definition: ABI.h:27
lldb_private::UnwindLLDB::DoClear
void DoClear() override
Definition: UnwindLLDB.h:67
lldb_private::UnwindLLDB::RegisterLocation::inferred_value
uint64_t inferred_value
Definition: UnwindLLDB.h:62
lldb_private::UnwindLLDB::~UnwindLLDB
~UnwindLLDB() override=default
lldb_private::UnwindLLDB::m_candidate_frame
CursorSP m_candidate_frame
Definition: UnwindLLDB.h:131
Unwind.h
lldb_private::UnwindLLDB::GetOneMoreFrame
CursorSP GetOneMoreFrame(ABI *abi)
Definition: UnwindLLDB.cpp:114
lldb_private::UnwindLLDB::m_user_supplied_trap_handler_functions
std::vector< ConstString > m_user_supplied_trap_handler_functions
Definition: UnwindLLDB.h:138
lldb_private::UnwindLLDB::UpdateUnwindPlanForFirstFrameIfInvalid
void UpdateUnwindPlanForFirstFrameIfInvalid(ABI *abi)
Definition: UnwindLLDB.cpp:296
lldb_private::UnwindLLDB::RegisterLocation::register_number
uint32_t register_number
Definition: UnwindLLDB.h:60
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb_private::UnwindLLDB::UnwindLLDB
UnwindLLDB(lldb_private::Thread &thread)
Definition: UnwindLLDB.cpp:26
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::UnwindLLDB::RegisterLocation::eRegisterSavedAtHostMemoryLocation
@ eRegisterSavedAtHostMemoryLocation
Definition: UnwindLLDB.h:49
lldb_private::UnwindLLDB::Cursor::Cursor
Cursor()
Definition: UnwindLLDB.h:122
lldb_private::UnwindLLDB::RegisterContextLLDBSP
std::shared_ptr< RegisterContextUnwind > RegisterContextLLDBSP
Definition: UnwindLLDB.h:82
lldb_private::UnwindLLDB::Cursor::cfa
lldb::addr_t cfa
Definition: UnwindLLDB.h:115
lldb_private::UnwindLLDB::m_unwind_complete
bool m_unwind_complete
Definition: UnwindLLDB.h:132
lldb_private::UnwindLLDB::Cursor::sctx
lldb_private::SymbolContext sctx
Definition: UnwindLLDB.h:117
lldb_private::UnwindLLDB::RegisterSearchResult
RegisterSearchResult
Definition: UnwindLLDB.h:32
lldb_private::Thread
Definition: Thread.h:61
lldb_private::UnwindLLDB::DoGetFrameInfoAtIndex
bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &start_pc, bool &behaves_like_zeroth_frame) override
Definition: UnwindLLDB.cpp:392
lldb_private::UnwindLLDB
Definition: UnwindLLDB.h:26
lldb_private::UnwindLLDB::RegisterLocation
Definition: UnwindLLDB.h:41
lldb_private::UnwindLLDB::DoGetFrameCount
uint32_t DoGetFrameCount() override
Definition: UnwindLLDB.cpp:41
lldb_private::UnwindLLDB::Cursor
Definition: UnwindLLDB.h:111
lldb_private::UnwindLLDB::RegisterLocation::eRegisterNotSaved
@ eRegisterNotSaved
Definition: UnwindLLDB.h:43
lldb_private::UnwindLLDB::SearchForSavedLocationForRegister
bool SearchForSavedLocationForRegister(uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num, bool pc_register)
Definition: UnwindLLDB.cpp:471
lldb_private::UnwindLLDB::RegisterLocation::eRegisterInRegister
@ eRegisterInRegister
Definition: UnwindLLDB.h:47
UnwindPlan.h
lldb_private::UnwindLLDB::DoCreateRegisterContextForFrame
lldb::RegisterContextSP DoCreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
Definition: UnwindLLDB.cpp:434
lldb_private::UnwindLLDB::RegisterLocation::RegisterLocationTypes
RegisterLocationTypes
Definition: UnwindLLDB.h:42
FuncUnwinders.h
lldb_private::UnwindLLDB::RegisterLocation::location
union lldb_private::UnwindLLDB::RegisterLocation::@40 location
uint32_t
lldb_private::UnwindLLDB::RegisterLocation::eRegisterValueInferred
@ eRegisterValueInferred
Definition: UnwindLLDB.h:51
lldb_private::UnwindLLDB::Cursor::start_pc
lldb::addr_t start_pc
Definition: UnwindLLDB.h:112
lldb_private::UnwindLLDB::eRegisterNotFound
@ eRegisterNotFound
Definition: UnwindLLDB.h:34
lldb_private::UnwindLLDB::GetRegisterContextForFrameNum
RegisterContextLLDBSP GetRegisterContextForFrameNum(uint32_t frame_num)
Definition: UnwindLLDB.cpp:464
LLDB_INVALID_ADDRESS
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:74
lldb_private::UnwindLLDB::eRegisterFound
@ eRegisterFound
Definition: UnwindLLDB.h:33
lldb_private::UnwindLLDB::AddOneMoreFrame
bool AddOneMoreFrame(ABI *abi)
Definition: UnwindLLDB.cpp:318
SymbolContext.h
lldb_private::UnwindLLDB::operator=
const UnwindLLDB & operator=(const UnwindLLDB &)=delete
lldb_private::RegisterContextUnwind
Definition: RegisterContextUnwind.h:25
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::UnwindLLDB::RegisterLocation::eRegisterInLiveRegisterContext
@ eRegisterInLiveRegisterContext
Definition: UnwindLLDB.h:53
lldb_private::UnwindLLDB::RegisterLocation::target_memory_location
lldb::addr_t target_memory_location
Definition: UnwindLLDB.h:58
lldb_private::UnwindLLDB::RegisterLocation::eRegisterSavedAtMemoryLocation
@ eRegisterSavedAtMemoryLocation
Definition: UnwindLLDB.h:45
ConstString.h
lldb_private::UnwindLLDB::m_frames
std::vector< CursorSP > m_frames
Definition: UnwindLLDB.h:130
lldb_private::UnwindLLDB::eRegisterIsVolatile
@ eRegisterIsVolatile
Definition: UnwindLLDB.h:35
lldb_private::UnwindLLDB::RegisterLocation::host_memory_location
void * host_memory_location
Definition: UnwindLLDB.h:61
lldb_private::StackFrame
Definition: StackFrame.h:40
lldb_private::Unwind
Definition: Unwind.h:18
RegisterContext.h
lldb_private::UnwindLLDB::AddFirstFrame
bool AddFirstFrame()
Definition: UnwindLLDB.cpp:71