blob: b9352b61b8bf27b43dd9885dd00794392fec9d52 [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();
59 }
60
61 virtual uint32_t
Jim Ingham8f077162011-10-21 01:49:48 +000062 DoGetFrameCount();
Jason Molendaab4f1922010-10-25 11:12:07 +000063
64 bool
Jim Ingham8f077162011-10-21 01:49:48 +000065 DoGetFrameInfoAtIndex (uint32_t frame_idx,
Jason Molendaab4f1922010-10-25 11:12:07 +000066 lldb::addr_t& cfa,
67 lldb::addr_t& start_pc);
68
Greg Clayton5ccbd292011-01-06 22:15:06 +000069 lldb::RegisterContextSP
Jim Ingham8f077162011-10-21 01:49:48 +000070 DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
Jason Molendaab4f1922010-10-25 11:12:07 +000071
Greg Claytone1cd1be2012-01-29 20:56:30 +000072 typedef SHARED_PTR(RegisterContextLLDB) RegisterContextLLDBSP;
Jason Molenda707fec42011-11-01 03:21:25 +000073
74 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
75 // The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
Greg Claytone1cd1be2012-01-29 20:56:30 +000076 RegisterContextLLDBSP
Jason Molenda707fec42011-11-01 03:21:25 +000077 GetRegisterContextForFrameNum (uint32_t frame_num);
78
79 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
80 // has a saved location for this reg.
81 bool
82 SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num);
83
84
Jason Molendaab4f1922010-10-25 11:12:07 +000085private:
Jason Molenda707fec42011-11-01 03:21:25 +000086
Jason Molendaab4f1922010-10-25 11:12:07 +000087 struct Cursor
88 {
89 lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown
90 lldb::addr_t cfa; // The canonical frame address for this stack frame
91 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to & provide to the StackFrame creation
Greg Claytone1cd1be2012-01-29 20:56:30 +000092 RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
Jason Molendaab4f1922010-10-25 11:12:07 +000093
Greg Claytone1cd1be2012-01-29 20:56:30 +000094 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
Jason Molenda45b49242010-11-09 01:21:22 +000095 private:
Jason Molendafa19c3e72010-11-04 09:40:56 +000096 DISALLOW_COPY_AND_ASSIGN (Cursor);
Jason Molendaab4f1922010-10-25 11:12:07 +000097 };
98
Greg Claytone1cd1be2012-01-29 20:56:30 +000099 typedef SHARED_PTR(Cursor) CursorSP;
Jason Molenda59762002010-11-04 00:53:20 +0000100 std::vector<CursorSP> m_frames;
Jason Molendaab4f1922010-10-25 11:12:07 +0000101
Greg Clayton9b72eb72011-05-24 23:06:02 +0000102 bool AddOneMoreFrame (ABI *abi);
Jason Molenda8fed2952010-11-09 02:31:21 +0000103 bool AddFirstFrame ();
104
Jason Molendaab4f1922010-10-25 11:12:07 +0000105 //------------------------------------------------------------------
106 // For UnwindLLDB only
107 //------------------------------------------------------------------
108 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
109};
110
Greg Clayton58be07b2011-01-07 06:08:19 +0000111} // namespace lldb_private
Jason Molendaab4f1922010-10-25 11:12:07 +0000112
113#endif // lldb_UnwindLLDB_h_