1 //===-- RegisterContextLLDB.h --------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef lldb_RegisterContextLLDB_h_
11 #define lldb_RegisterContextLLDB_h_
15 #include "lldb/lldb-private.h"
16 #include "lldb/Target/RegisterContext.h"
17 #include "lldb/Symbol/UnwindPlan.h"
18 #include "lldb/Symbol/SymbolContext.h"
19 #include "UnwindLLDB.h"
21 namespace lldb_private {
25 class RegisterContextLLDB : public lldb_private::RegisterContext
28 typedef std::shared_ptr<RegisterContextLLDB> SharedPtr;
30 RegisterContextLLDB (lldb_private::Thread &thread,
31 const SharedPtr& next_frame,
32 lldb_private::SymbolContext& sym_ctx,
33 uint32_t frame_number, lldb_private::UnwindLLDB& unwind_lldb);
36 // pure virtual functions from the base class that we must implement
40 ~RegisterContextLLDB () { }
43 InvalidateAllRegisters ();
48 virtual const lldb_private::RegisterInfo *
49 GetRegisterInfoAtIndex (size_t reg);
52 GetRegisterSetCount ();
54 virtual const lldb_private::RegisterSet *
55 GetRegisterSet (size_t reg_set);
58 ReadRegister (const lldb_private::RegisterInfo *reg_info, lldb_private::RegisterValue &value);
61 WriteRegister (const lldb_private::RegisterInfo *reg_info, const lldb_private::RegisterValue &value);
64 ReadAllRegisterValues (lldb::DataBufferSP &data_sp);
67 WriteAllRegisterValues (const lldb::DataBufferSP &data_sp);
70 ConvertRegisterKindToRegisterNumber (uint32_t kind, uint32_t num);
76 GetCFA (lldb::addr_t& cfa);
79 GetStartPC (lldb::addr_t& start_pc);
82 ReadPC (lldb::addr_t& start_pc);
90 eDebuggerFrame, // a debugger inferior function call frame; we get caller's registers from debugger
91 eSkipFrame, // The unwind resulted in a bogus frame but may get back on track so we don't want to give up yet
92 eNotAValidFrame // this frame is invalid for some reason - most likely it is past the top (end) of the stack
95 // UnwindLLDB needs to pass around references to RegisterLocations
96 friend class UnwindLLDB;
98 // Indicates whether this frame is frame zero -- the currently
99 // executing frame -- or not.
101 IsFrameZero () const;
104 InitializeZerothFrame ();
107 InitializeNonZerothFrame();
110 GetNextFrame () const;
113 GetPrevFrame () const;
115 // A SkipFrame occurs when the unwind out of frame 0 didn't go right -- we've got one bogus frame at frame #1.
116 // There is a good chance we'll get back on track if we follow the frame pointer chain (or whatever is appropriate
117 // on this ABI) so we allow one invalid frame to be in the stack. Ideally we'll mark this frame specially at some
118 // point and indicate to the user that the unwinder had a hiccup. Often when this happens we will miss a frame of
119 // the program's actual stack in the unwind and we want to flag that for the user somehow.
121 IsSkipFrame () const;
123 // Provide a location for where THIS function saved the CALLER's register value
124 // Or a frame "below" this one saved it, i.e. a function called by this one, preserved a register that this
125 // function didn't modify/use.
127 // The RegisterLocation type may be set to eRegisterNotAvailable -- this will happen for a volatile register
128 // being queried mid-stack. Instead of floating frame 0's contents of that register up the stack (which may
129 // or may not be the value of that reg when the function was executing), we won't return any value.
131 // If a non-volatile register (a "preserved" register) is requested mid-stack and no frames "below" the requested
132 // stack have saved the register anywhere, it is safe to assume that frame 0's register values are still the same
133 // as the requesting frame's.
134 lldb_private::UnwindLLDB::RegisterSearchResult
135 SavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc);
138 ReadRegisterValueFromRegisterLocation (lldb_private::UnwindLLDB::RegisterLocation regloc,
139 const lldb_private::RegisterInfo *reg_info,
140 lldb_private::RegisterValue &value);
143 WriteRegisterValueToRegisterLocation (lldb_private::UnwindLLDB::RegisterLocation regloc,
144 const lldb_private::RegisterInfo *reg_info,
145 const lldb_private::RegisterValue &value);
148 InvalidateFullUnwindPlan ();
150 // Get the contents of a general purpose (address-size) register for this frame
151 // (usually retrieved from the next frame)
153 ReadGPRValue (int register_kind, uint32_t regnum, lldb::addr_t &value);
156 GetFastUnwindPlanForFrame ();
159 GetFullUnwindPlanForFrame ();
162 UnwindLogMsg (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
165 UnwindLogMsgVerbose (const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
167 lldb_private::Thread& m_thread;
170 // The following tell us how to retrieve the CALLER's register values (ie the "previous" frame, aka the frame above)
171 // i.e. where THIS frame saved them
174 lldb::UnwindPlanSP m_fast_unwind_plan_sp; // may be NULL
175 lldb::UnwindPlanSP m_full_unwind_plan_sp;
176 bool m_all_registers_available; // Can we retrieve all regs or just nonvolatile regs?
177 int m_frame_type; // enum FrameType
180 lldb_private::Address m_start_pc;
181 lldb_private::Address m_current_pc;
183 int m_current_offset; // how far into the function we've executed; -1 if unknown
184 // 0 if no instructions have been executed yet.
186 int m_current_offset_backed_up_one; // how far into the function we've executed; -1 if unknown
187 // 0 if no instructions have been executed yet.
188 // On architectures where the return address on the stack points
189 // to the instruction after the CALL, this value will have 1
190 // subtracted from it. Else a function that ends in a CALL will
191 // have an offset pointing into the next function's address range.
192 // m_current_pc has the actual address of the "current" pc.
194 lldb_private::SymbolContext& m_sym_ctx;
195 bool m_sym_ctx_valid; // if ResolveSymbolContextForAddress fails, don't try to use m_sym_ctx
197 uint32_t m_frame_number; // What stack frame this RegisterContext is
199 std::map<uint32_t, lldb_private::UnwindLLDB::RegisterLocation> m_registers; // where to find reg values for this frame
201 lldb_private::UnwindLLDB& m_parent_unwind; // The UnwindLLDB that is creating this RegisterContextLLDB
203 //------------------------------------------------------------------
204 // For RegisterContextLLDB only
205 //------------------------------------------------------------------
207 DISALLOW_COPY_AND_ASSIGN (RegisterContextLLDB);
210 } // namespace lldb_private
212 #endif // lldb_RegisterContextLLDB_h_