blob: ed3be5bf5d5881d8f6a090ebe1a8a9c749e7dd9f [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
Jason Molendaaff2a262012-11-16 01:03:31 +000033 enum RegisterSearchResult
34 {
35 eRegisterFound = 0,
36 eRegisterNotFound,
37 eRegisterIsVolatile
38 };
39
Jim Ingham8f077162011-10-21 01:49:48 +000040protected:
Jason Molenda707fec42011-11-01 03:21:25 +000041 friend class lldb_private::RegisterContextLLDB;
42
43 struct RegisterLocation {
44 enum RegisterLocationTypes
45 {
46 eRegisterNotSaved = 0, // register was not preserved by callee. If volatile reg, is unavailable
47 eRegisterSavedAtMemoryLocation, // register is saved at a specific word of target mem (target_memory_location)
48 eRegisterInRegister, // register is available in a (possible other) register (register_number)
49 eRegisterSavedAtHostMemoryLocation, // register is saved at a word in lldb's address space
50 eRegisterValueInferred // register val was computed (and is in inferred_value)
51 };
52 int type;
53 union
54 {
55 lldb::addr_t target_memory_location;
56 uint32_t register_number; // in eRegisterKindLLDB register numbering system
57 void* host_memory_location;
58 uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset
59 } location;
60 };
61
Jason Molendaab4f1922010-10-25 11:12:07 +000062 void
Jim Ingham8f077162011-10-21 01:49:48 +000063 DoClear()
Jason Molendaab4f1922010-10-25 11:12:07 +000064 {
65 m_frames.clear();
Jim Inghamb0c72a52012-02-29 03:40:22 +000066 m_unwind_complete = false;
Jason Molendaab4f1922010-10-25 11:12:07 +000067 }
68
69 virtual uint32_t
Jim Ingham8f077162011-10-21 01:49:48 +000070 DoGetFrameCount();
Jason Molendaab4f1922010-10-25 11:12:07 +000071
72 bool
Jim Ingham8f077162011-10-21 01:49:48 +000073 DoGetFrameInfoAtIndex (uint32_t frame_idx,
Jason Molendaab4f1922010-10-25 11:12:07 +000074 lldb::addr_t& cfa,
75 lldb::addr_t& start_pc);
76
Greg Clayton5ccbd292011-01-06 22:15:06 +000077 lldb::RegisterContextSP
Jim Ingham8f077162011-10-21 01:49:48 +000078 DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame);
Jason Molendaab4f1922010-10-25 11:12:07 +000079
Greg Claytond64afba2012-03-14 03:07:05 +000080 typedef STD_SHARED_PTR(RegisterContextLLDB) RegisterContextLLDBSP;
Jason Molenda707fec42011-11-01 03:21:25 +000081
82 // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB)
83 // The RegisterContext for frame_num must already exist or this returns an empty shared pointer.
Greg Claytone1cd1be2012-01-29 20:56:30 +000084 RegisterContextLLDBSP
Jason Molenda707fec42011-11-01 03:21:25 +000085 GetRegisterContextForFrameNum (uint32_t frame_num);
86
87 // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that
88 // has a saved location for this reg.
89 bool
Jason Molenda60f0bd42012-10-26 06:08:58 +000090 SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation &regloc, uint32_t starting_frame_num, bool pc_or_return_address_reg);
Jason Molenda707fec42011-11-01 03:21:25 +000091
92
Jason Molendaab4f1922010-10-25 11:12:07 +000093private:
Jason Molenda707fec42011-11-01 03:21:25 +000094
Jason Molendaab4f1922010-10-25 11:12:07 +000095 struct Cursor
96 {
97 lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown
98 lldb::addr_t cfa; // The canonical frame address for this stack frame
99 lldb_private::SymbolContext sctx; // A symbol context we'll contribute to & provide to the StackFrame creation
Greg Claytone1cd1be2012-01-29 20:56:30 +0000100 RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's
Jason Molendaab4f1922010-10-25 11:12:07 +0000101
Greg Claytone1cd1be2012-01-29 20:56:30 +0000102 Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { }
Jason Molenda45b49242010-11-09 01:21:22 +0000103 private:
Jason Molendafa19c3e72010-11-04 09:40:56 +0000104 DISALLOW_COPY_AND_ASSIGN (Cursor);
Jason Molendaab4f1922010-10-25 11:12:07 +0000105 };
106
Greg Claytond64afba2012-03-14 03:07:05 +0000107 typedef STD_SHARED_PTR(Cursor) CursorSP;
Jason Molenda59762002010-11-04 00:53:20 +0000108 std::vector<CursorSP> m_frames;
Jim Inghamb0c72a52012-02-29 03:40:22 +0000109 bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the
110 // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size()
111 // is how far we've currently gone.
112
Jason Molendaab4f1922010-10-25 11:12:07 +0000113
Greg Clayton9b72eb72011-05-24 23:06:02 +0000114 bool AddOneMoreFrame (ABI *abi);
Jason Molenda8fed2952010-11-09 02:31:21 +0000115 bool AddFirstFrame ();
116
Jason Molendaab4f1922010-10-25 11:12:07 +0000117 //------------------------------------------------------------------
118 // For UnwindLLDB only
119 //------------------------------------------------------------------
120 DISALLOW_COPY_AND_ASSIGN (UnwindLLDB);
121};
122
Greg Clayton58be07b2011-01-07 06:08:19 +0000123} // namespace lldb_private
Jason Molendaab4f1922010-10-25 11:12:07 +0000124
125#endif // lldb_UnwindLLDB_h_