blob: 35d85e2e3d26e941d4e381d94015c4f11ca4b6d1 [file] [log] [blame]
Jason Molendaab4f1922010-10-25 11:12:07 +00001//===-- UnwindLLDB.h --------------------------------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef lldb_UnwindLLDB_h_
11#define lldb_UnwindLLDB_h_
12
Jason Molendaab4f1922010-10-25 11:12:07 +000013#include <vector>
14
Greg Claytone0d378b2011-03-24 21:19:54 +000015#include "lldb/lldb-public.h"
Jason Molendaa4bea722014-02-14 05:06:49 +000016#include "lldb/Core/ConstString.h"
Greg Claytone576ab22011-02-15 00:19:15 +000017#include "lldb/Symbol/FuncUnwinders.h"
18#include "lldb/Symbol/UnwindPlan.h"
19#include "lldb/Target/RegisterContext.h"
20#include "lldb/Target/Unwind.h"
21
Jason Molendaab4f1922010-10-25 11:12:07 +000022namespace lldb_private {
23
Jason Molenda707fec42011-11-01 03:21:25 +000024class RegisterContextLLDB;
25
Jason Molendaab4f1922010-10-25 11:12:07 +000026class UnwindLLDB : public lldb_private::Unwind
27{
28public:
29 UnwindLLDB (lldb_private::Thread &thread);
30
31 virtual
32 ~UnwindLLDB() { }
Jason Molenda707fec42011-11-01 03:21:25 +000033
Jason Molendaaff2a262012-11-16 01:03:31 +000034 enum RegisterSearchResult
35 {
36 eRegisterFound = 0,
37 eRegisterNotFound,
38 eRegisterIsVolatile
39 };
40
Jim Ingham8f077162011-10-21 01:49:48 +000041protected:
Jason Molenda707fec42011-11-01 03:21:25 +000042 friend class lldb_private::RegisterContextLLDB;
43
44 struct RegisterLocation {
45 enum RegisterLocationTypes
46 {
47 eRegisterNotSaved = 0, // register was not preserved by callee. If volatile reg, is unavailable
48 eRegisterSavedAtMemoryLocation, // register is saved at a specific word of target mem (target_memory_location)
49 eRegisterInRegister, // register is available in a (possible other) register (register_number)
50 eRegisterSavedAtHostMemoryLocation, // register is saved at a word in lldb's address space
Jason Molendace19fe32014-12-09 22:28:10 +000051 eRegisterValueInferred, // register val was computed (and is in inferred_value)
52 eRegisterInLiveRegisterContext // register value is in a live (stack frame #0) register
Jason Molenda707fec42011-11-01 03:21:25 +000053 };
54 int type;
55 union
56 {
57 lldb::addr_t target_memory_location;
58 uint32_t register_number; // in eRegisterKindLLDB register numbering system
59 void* host_memory_location;
60 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset
61 } location;
62 };
63
Jason Molendaab4f1922010-10-25 11:12:07 +000064 void
Jim Ingham8f077162011-10-21 01:49:48 +000065 DoClear()
Jason Molendaab4f1922010-10-25 11:12:07 +000066 {
67 m_frames.clear();
Jim Inghamb0c72a52012-02-29 03:40:22 +000068 m_unwind_complete = false;
Jason Molendaab4f1922010-10-25 11:12:07 +000069 }
70
71 virtual uint32_t
Jim Ingham8f077162011-10-21 01:49:48 +000072 DoGetFrameCount();
Jason Molendaab4f1922010-10-25 11:12:07 +000073
74 bool
Jim Ingham8f077162011-10-21 01:49:48 +000075 DoGetFrameInfoAtIndex (uint32_t frame_idx,
Jason Molendaab4f1922010-10-25 11:12:07 +000076 lldb::addr_t& cfa,
77 lldb::addr_t& start_pc);
78
Greg Clayton5ccbd292011-01-06 22:15:06 +000079 lldb::RegisterContextSP
Jason Molendab57e4a12013-11-04 09:33:30 +000080 DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
Jason Molendaab4f1922010-10-25 11:12:07 +000081
Greg Clayton7b0992d2013-04-18 22:45:39 +000082 typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP;
Jason Molenda707fec42011-11-01 03:21:25 +000083
84 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
85 // The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
Greg Claytone1cd1be2012-01-29 20:56:30 +000086 RegisterContextLLDBSP
Jason Molenda707fec42011-11-01 03:21:25 +000087 GetRegisterContextForFrameNum (uint32_t frame_num);
88
89 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
90 // has a saved location for this reg.
91 bool
Jason Molenda23399d72013-06-05 00:12:50 +000092 SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num, bool pc_register);
Jason Molenda707fec42011-11-01 03:21:25 +000093
94
Jason Molendaa4bea722014-02-14 05:06:49 +000095 //------------------------------------------------------------------
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 //------------------------------------------------------------------
107 const std::vector<ConstString> &
108 GetUserSpecifiedTrapHandlerFunctionNames ()
109 {
110 return m_user_supplied_trap_handler_functions;
111 }
112
Jason Molendaab4f1922010-10-25 11:12:07 +0000113private:
Jason Molenda707fec42011-11-01 03:21:25 +0000114
Jason Molendaab4f1922010-10-25 11:12:07 +0000115 struct Cursor
116 {
117 lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown
118 lldb::addr_t cfa; // The canonical frame address for this stack frame
119 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to & provide to the StackFrame creation
Greg Claytone1cd1be2012-01-29 20:56:30 +0000120 RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
Jason Molendaab4f1922010-10-25 11:12:07 +0000121
Greg Claytone1cd1be2012-01-29 20:56:30 +0000122 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
Jason Molenda45b49242010-11-09 01:21:22 +0000123 private:
Jason Molendafa19c3e72010-11-04 09:40:56 +0000124 DISALLOW_COPY_AND_ASSIGN (Cursor);
Jason Molendaab4f1922010-10-25 11:12:07 +0000125 };
126
Greg Clayton7b0992d2013-04-18 22:45:39 +0000127 typedef std::shared_ptr<Cursor> CursorSP;
Jason Molenda59762002010-11-04 00:53:20 +0000128 std::vector<CursorSP> m_frames;
Jim Inghamb0c72a52012-02-29 03:40:22 +0000129 bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the
130 // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size()
131 // is how far we've currently gone.
132
Jason Molendaa4bea722014-02-14 05:06:49 +0000133 std::vector<ConstString> m_user_supplied_trap_handler_functions;
Jason Molendaab4f1922010-10-25 11:12:07 +0000134
Greg Clayton9b72eb72011-05-24 23:06:02 +0000135 bool AddOneMoreFrame (ABI *abi);
Jason Molenda8fed2952010-11-09 02:31:21 +0000136 bool AddFirstFrame ();
137
Jason Molendaab4f1922010-10-25 11:12:07 +0000138 //------------------------------------------------------------------
139 // For UnwindLLDB only
140 //------------------------------------------------------------------
141 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
142};
143
Greg Clayton58be07b2011-01-07 06:08:19 +0000144} // namespace lldb_private
Jason Molendaab4f1922010-10-25 11:12:07 +0000145
146#endif // lldb_UnwindLLDB_h_