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