blob: eb5400389df3e6d52e8728e98fbf9596ba36fef9 [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
51 eRegisterValueInferred // register val was computed (and is in inferred_value)
52 };
53 int type;
54 union
55 {
56 lldb::addr_t target_memory_location;
57 uint32_t register_number; // in eRegisterKindLLDB register numbering system
58 void* host_memory_location;
59 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset
60 } location;
61 };
62
Jason Molendaab4f1922010-10-25 11:12:07 +000063 void
Jim Ingham8f077162011-10-21 01:49:48 +000064 DoClear()
Jason Molendaab4f1922010-10-25 11:12:07 +000065 {
66 m_frames.clear();
Jim Inghamb0c72a52012-02-29 03:40:22 +000067 m_unwind_complete = false;
Jason Molendaab4f1922010-10-25 11:12:07 +000068 }
69
70 virtual uint32_t
Jim Ingham8f077162011-10-21 01:49:48 +000071 DoGetFrameCount();
Jason Molendaab4f1922010-10-25 11:12:07 +000072
73 bool
Jim Ingham8f077162011-10-21 01:49:48 +000074 DoGetFrameInfoAtIndex (uint32_t frame_idx,
Jason Molendaab4f1922010-10-25 11:12:07 +000075 lldb::addr_t& cfa,
76 lldb::addr_t& start_pc);
77
Greg Clayton5ccbd292011-01-06 22:15:06 +000078 lldb::RegisterContextSP
Jason Molendab57e4a12013-11-04 09:33:30 +000079 DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
Jason Molendaab4f1922010-10-25 11:12:07 +000080
Greg Clayton7b0992d2013-04-18 22:45:39 +000081 typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP;
Jason Molenda707fec42011-11-01 03:21:25 +000082
83 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
84 // The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
Greg Claytone1cd1be2012-01-29 20:56:30 +000085 RegisterContextLLDBSP
Jason Molenda707fec42011-11-01 03:21:25 +000086 GetRegisterContextForFrameNum (uint32_t frame_num);
87
88 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
89 // has a saved location for this reg.
90 bool
Jason Molenda23399d72013-06-05 00:12:50 +000091 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 +000092
93
Jason Molendaa4bea722014-02-14 05:06:49 +000094 //------------------------------------------------------------------
95 /// Provide the list of user-specified trap handler functions
96 ///
97 /// The Platform is one source of trap handler function names; that
98 /// may be augmented via a setting. The setting needs to be converted
99 /// into an array of ConstStrings before it can be used - we only want
100 /// to do that once per thread so it's here in the UnwindLLDB object.
101 ///
102 /// @return
103 /// Vector of ConstStrings of trap handler function names. May be
104 /// empty.
105 //------------------------------------------------------------------
106 const std::vector<ConstString> &
107 GetUserSpecifiedTrapHandlerFunctionNames ()
108 {
109 return m_user_supplied_trap_handler_functions;
110 }
111
Jason Molendaab4f1922010-10-25 11:12:07 +0000112private:
Jason Molenda707fec42011-11-01 03:21:25 +0000113
Jason Molendaab4f1922010-10-25 11:12:07 +0000114 struct Cursor
115 {
116 lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown
117 lldb::addr_t cfa; // The canonical frame address for this stack frame
118 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to & provide to the StackFrame creation
Greg Claytone1cd1be2012-01-29 20:56:30 +0000119 RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
Jason Molendaab4f1922010-10-25 11:12:07 +0000120
Greg Claytone1cd1be2012-01-29 20:56:30 +0000121 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
Jason Molenda45b49242010-11-09 01:21:22 +0000122 private:
Jason Molendafa19c3e72010-11-04 09:40:56 +0000123 DISALLOW_COPY_AND_ASSIGN (Cursor);
Jason Molendaab4f1922010-10-25 11:12:07 +0000124 };
125
Greg Clayton7b0992d2013-04-18 22:45:39 +0000126 typedef std::shared_ptr<Cursor> CursorSP;
Jason Molenda59762002010-11-04 00:53:20 +0000127 std::vector<CursorSP> m_frames;
Jim Inghamb0c72a52012-02-29 03:40:22 +0000128 bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the
129 // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size()
130 // is how far we've currently gone.
131
Jason Molendaa4bea722014-02-14 05:06:49 +0000132 std::vector<ConstString> m_user_supplied_trap_handler_functions;
Jason Molendaab4f1922010-10-25 11:12:07 +0000133
Greg Clayton9b72eb72011-05-24 23:06:02 +0000134 bool AddOneMoreFrame (ABI *abi);
Jason Molenda8fed2952010-11-09 02:31:21 +0000135 bool AddFirstFrame ();
136
Jason Molendaab4f1922010-10-25 11:12:07 +0000137 //------------------------------------------------------------------
138 // For UnwindLLDB only
139 //------------------------------------------------------------------
140 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
141};
142
Greg Clayton58be07b2011-01-07 06:08:19 +0000143} // namespace lldb_private
Jason Molendaab4f1922010-10-25 11:12:07 +0000144
145#endif // lldb_UnwindLLDB_h_