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
18#include "lldb/Target/Unwind.h"
20#include "lldb/lldb-public.h"
21
22namespace lldb_private {
23
25class ArchitectureArm;
26
28public:
30
31 ~UnwindLLDB() override = default;
32
38
39protected:
42
43 /// An UnwindPlan::Row::AbstractRegisterLocation, combined with the register
44 /// context and memory for a specific stop point, is used to create a
45 /// ConcreteRegisterLocation.
48 eRegisterNotSaved = 0, // register was not preserved by callee. If
49 // volatile reg, is unavailable
50 eRegisterSavedAtMemoryLocation, // register is saved at a specific word of
51 // target mem (target_memory_location)
52 eRegisterInRegister, // register is available in a (possible other)
53 // register (register_number)
54 eRegisterIsRegisterPlusOffset, // register is available in a (possible
55 // other) register (register_number) with
56 // an offset applied
57 eRegisterSavedAtHostMemoryLocation, // register is saved at a word in
58 // lldb's address space
59 eRegisterValueInferred, // register val was computed (and is in
60 // inferred_value)
61 eRegisterInLiveRegisterContext // register value is in a live (stack frame
62 // #0) register
63 };
64 int type;
65 union {
67 uint32_t
68 register_number; // in eRegisterKindLLDB register numbering system
70 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer ==
71 // cfa + offset
72 struct {
73 uint32_t
74 register_number; // in eRegisterKindLLDB register numbering system
75 uint64_t offset;
78 };
79
80 void DoClear() override {
81 m_frames.clear();
82 m_candidate_frame.reset();
83 m_unwind_complete = false;
84 }
85
86 uint32_t DoGetFrameCount() override;
87
88 bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa,
89 lldb::addr_t &start_pc,
90 bool &behaves_like_zeroth_frame) override;
91
94
95 typedef std::shared_ptr<RegisterContextUnwind> RegisterContextLLDBSP;
96
97 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame
98 // 1's RegisterContextUnwind)
99 // The RegisterContext for frame_num must already exist or this returns an
100 // empty shared pointer.
102
103 // Iterate over the RegisterContextUnwind's in our m_frames vector, look for
104 // the first one that has a saved location for this reg.
106 uint32_t lldb_regnum,
108 uint32_t starting_frame_num, bool pc_register);
109
110 /// Provide the list of user-specified trap handler functions
111 ///
112 /// The Platform is one source of trap handler function names; that
113 /// may be augmented via a setting. The setting needs to be converted
114 /// into an array of ConstStrings before it can be used - we only want
115 /// to do that once per thread so it's here in the UnwindLLDB object.
116 ///
117 /// \return
118 /// Vector of ConstStrings of trap handler function names. May be
119 /// empty.
120 const std::vector<ConstString> &GetUserSpecifiedTrapHandlerFunctionNames() {
122 }
123
124private:
125 struct Cursor {
127 LLDB_INVALID_ADDRESS; // The start address of the function/symbol for
128 // this frame - current pc if unknown
129 lldb::addr_t cfa = LLDB_INVALID_ADDRESS; // The canonical frame address for
130 // this stack frame
131 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to &
132 // provide to the StackFrame creation
134 reg_ctx_lldb_sp; // These are all RegisterContextUnwind's
135
136 Cursor() = default;
137
138 private:
139 Cursor(const Cursor &) = delete;
140 const Cursor &operator=(const Cursor &) = delete;
141 };
142
143 typedef std::shared_ptr<Cursor> CursorSP;
144 std::vector<CursorSP> m_frames;
146 bool m_unwind_complete; // If this is true, we've enumerated all the frames in
147 // the stack, and m_frames.size() is the
148 // number of frames, etc. Otherwise we've only gone as far as directly asked,
149 // and m_frames.size()
150 // is how far we've currently gone.
151
153
154 // Check if Full UnwindPlan of First frame is valid or not.
155 // If not then try Fallback UnwindPlan of the frame. If Fallback
156 // UnwindPlan succeeds then update the Full UnwindPlan with the
157 // Fallback UnwindPlan.
159
161
162 bool AddOneMoreFrame(ABI *abi);
163
164 bool AddFirstFrame();
165
166 // For UnwindLLDB only
167 UnwindLLDB(const UnwindLLDB &) = delete;
168 const UnwindLLDB &operator=(const UnwindLLDB &) = delete;
169};
170
171} // namespace lldb_private
172
173#endif // LLDB_TARGET_UNWINDLLDB_H
This base class provides an interface to stack frames.
Definition StackFrame.h:44
Defines a symbol context baton that can be handed other debug core functions.
void UpdateUnwindPlanForFirstFrameIfInvalid(ABI *abi)
std::vector< ConstString > m_user_supplied_trap_handler_functions
Definition UnwindLLDB.h:152
std::vector< CursorSP > m_frames
Definition UnwindLLDB.h:144
const std::vector< ConstString > & GetUserSpecifiedTrapHandlerFunctionNames()
Provide the list of user-specified trap handler functions.
Definition UnwindLLDB.h:120
RegisterContextLLDBSP GetRegisterContextForFrameNum(uint32_t frame_num)
lldb::RegisterContextSP DoCreateRegisterContextForFrame(lldb_private::StackFrame *frame) override
UnwindLLDB(lldb_private::Thread &thread)
std::shared_ptr< Cursor > CursorSP
Definition UnwindLLDB.h:143
bool AddOneMoreFrame(ABI *abi)
CursorSP GetOneMoreFrame(ABI *abi)
UnwindLLDB(const UnwindLLDB &)=delete
std::shared_ptr< RegisterContextUnwind > RegisterContextLLDBSP
Definition UnwindLLDB.h:95
const UnwindLLDB & operator=(const UnwindLLDB &)=delete
bool DoGetFrameInfoAtIndex(uint32_t frame_idx, lldb::addr_t &cfa, lldb::addr_t &start_pc, bool &behaves_like_zeroth_frame) override
bool SearchForSavedLocationForRegister(uint32_t lldb_regnum, lldb_private::UnwindLLDB::ConcreteRegisterLocation &regloc, uint32_t starting_frame_num, bool pc_register)
void DoClear() override
Definition UnwindLLDB.h:80
~UnwindLLDB() override=default
uint32_t DoGetFrameCount() override
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
An UnwindPlan::Row::AbstractRegisterLocation, combined with the register context and memory for a spe...
Definition UnwindLLDB.h:46
struct lldb_private::UnwindLLDB::ConcreteRegisterLocation::@250272047141350077067164323227154322243030206067::@235335143127077156324316317012344113206032105310 reg_plus_offset
union lldb_private::UnwindLLDB::ConcreteRegisterLocation::@250272047141350077067164323227154322243030206067 location
RegisterContextLLDBSP reg_ctx_lldb_sp
Definition UnwindLLDB.h:134
Cursor(const Cursor &)=delete
const Cursor & operator=(const Cursor &)=delete
lldb_private::SymbolContext sctx
Definition UnwindLLDB.h:131