blob: ff4030f63647945e78c206f2ecb7aac909efd671 [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"
Greg Claytone576ab22011-02-15 00:19:15 +000016#include "lldb/Symbol/FuncUnwinders.h"
17#include "lldb/Symbol/UnwindPlan.h"
18#include "lldb/Target/RegisterContext.h"
19#include "lldb/Target/Unwind.h"
20
Jason Molendaab4f1922010-10-25 11:12:07 +000021namespace lldb_private {
22
Jason Molenda707fec42011-11-01 03:21:25 +000023class RegisterContextLLDB;
24
Jason Molendaab4f1922010-10-25 11:12:07 +000025class UnwindLLDB : public lldb_private::Unwind
26{
27public:
28 UnwindLLDB (lldb_private::Thread &thread);
29
30 virtual
31 ~UnwindLLDB() { }
Jason Molenda707fec42011-11-01 03:21:25 +000032
Jim Ingham8f077162011-10-21 01:49:48 +000033protected:
Jason Molenda707fec42011-11-01 03:21:25 +000034 friend class lldb_private::RegisterContextLLDB;
35
36 struct RegisterLocation {
37 enum RegisterLocationTypes
38 {
39 eRegisterNotSaved = 0, // register was not preserved by callee. If volatile reg, is unavailable
40 eRegisterSavedAtMemoryLocation, // register is saved at a specific word of target mem (target_memory_location)
41 eRegisterInRegister, // register is available in a (possible other) register (register_number)
42 eRegisterSavedAtHostMemoryLocation, // register is saved at a word in lldb's address space
43 eRegisterValueInferred // register val was computed (and is in inferred_value)
44 };
45 int type;
46 union
47 {
48 lldb::addr_t target_memory_location;
49 uint32_t register_number; // in eRegisterKindLLDB register numbering system
50 void* host_memory_location;
51 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset
52 } location;
53 };
54
Jason Molendaab4f1922010-10-25 11:12:07 +000055 void
Jim Ingham8f077162011-10-21 01:49:48 +000056 DoClear()
Jason Molendaab4f1922010-10-25 11:12:07 +000057 {
58 m_frames.clear();
Jim Inghamb0c72a52012-02-29 03:40:22 +000059 m_unwind_complete = false;
Jason Molendaab4f1922010-10-25 11:12:07 +000060 }
61
62 virtual uint32_t
Jim Ingham8f077162011-10-21 01:49:48 +000063 DoGetFrameCount();
Jason Molendaab4f1922010-10-25 11:12:07 +000064
65 bool
Jim Ingham8f077162011-10-21 01:49:48 +000066 DoGetFrameInfoAtIndex (uint32_t frame_idx,
Jason Molendaab4f1922010-10-25 11:12:07 +000067 lldb::addr_t& cfa,
68 lldb::addr_t& start_pc);
69
Greg Clayton5ccbd292011-01-06 22:15:06 +000070 lldb::RegisterContextSP
Jim Ingham8f077162011-10-21 01:49:48 +000071 DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
Jason Molendaab4f1922010-10-25 11:12:07 +000072
Greg Claytone1cd1be2012-01-29 20:56:30 +000073 typedef SHARED_PTR(RegisterContextLLDB) RegisterContextLLDBSP;
Jason Molenda707fec42011-11-01 03:21:25 +000074
75 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
76 // The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
Greg Claytone1cd1be2012-01-29 20:56:30 +000077 RegisterContextLLDBSP
Jason Molenda707fec42011-11-01 03:21:25 +000078 GetRegisterContextForFrameNum (uint32_t frame_num);
79
80 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
81 // has a saved location for this reg.
82 bool
83 SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num);
84
85
Jason Molendaab4f1922010-10-25 11:12:07 +000086private:
Jason Molenda707fec42011-11-01 03:21:25 +000087
Jason Molendaab4f1922010-10-25 11:12:07 +000088 struct Cursor
89 {
90 lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown
91 lldb::addr_t cfa; // The canonical frame address for this stack frame
92 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to & provide to the StackFrame creation
Greg Claytone1cd1be2012-01-29 20:56:30 +000093 RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
Jason Molendaab4f1922010-10-25 11:12:07 +000094
Greg Claytone1cd1be2012-01-29 20:56:30 +000095 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
Jason Molenda45b49242010-11-09 01:21:22 +000096 private:
Jason Molendafa19c3e72010-11-04 09:40:56 +000097 DISALLOW_COPY_AND_ASSIGN (Cursor);
Jason Molendaab4f1922010-10-25 11:12:07 +000098 };
99
Greg Claytone1cd1be2012-01-29 20:56:30 +0000100 typedef SHARED_PTR(Cursor) CursorSP;
Jason Molenda59762002010-11-04 00:53:20 +0000101 std::vector<CursorSP> m_frames;
Jim Inghamb0c72a52012-02-29 03:40:22 +0000102 bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the
103 // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size()
104 // is how far we've currently gone.
105
Jason Molendaab4f1922010-10-25 11:12:07 +0000106
Greg Clayton9b72eb72011-05-24 23:06:02 +0000107 bool AddOneMoreFrame (ABI *abi);
Jason Molenda8fed2952010-11-09 02:31:21 +0000108 bool AddFirstFrame ();
109
Jason Molendaab4f1922010-10-25 11:12:07 +0000110 //------------------------------------------------------------------
111 // For UnwindLLDB only
112 //------------------------------------------------------------------
113 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
114};
115
Greg Clayton58be07b2011-01-07 06:08:19 +0000116} // namespace lldb_private
Jason Molendaab4f1922010-10-25 11:12:07 +0000117
118#endif // lldb_UnwindLLDB_h_