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