Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 1 | //===-- 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 Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 15 | #include "lldb/lldb-public.h" |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 16 | #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 Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 21 | namespace lldb_private { |
| 22 | |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 23 | class RegisterContextLLDB; |
| 24 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 25 | class UnwindLLDB : public lldb_private::Unwind |
| 26 | { |
| 27 | public: |
| 28 | UnwindLLDB (lldb_private::Thread &thread); |
| 29 | |
| 30 | virtual |
| 31 | ~UnwindLLDB() { } |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 32 | |
Jason Molenda | aff2a26 | 2012-11-16 01:03:31 +0000 | [diff] [blame^] | 33 | enum RegisterSearchResult |
| 34 | { |
| 35 | eRegisterFound = 0, |
| 36 | eRegisterNotFound, |
| 37 | eRegisterIsVolatile |
| 38 | }; |
| 39 | |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 40 | protected: |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 41 | 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 Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 62 | void |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 63 | DoClear() |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 64 | { |
| 65 | m_frames.clear(); |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 66 | m_unwind_complete = false; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | virtual uint32_t |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 70 | DoGetFrameCount(); |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 71 | |
| 72 | bool |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 73 | DoGetFrameInfoAtIndex (uint32_t frame_idx, |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 74 | lldb::addr_t& cfa, |
| 75 | lldb::addr_t& start_pc); |
| 76 | |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 77 | lldb::RegisterContextSP |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 78 | DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame); |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 79 | |
Greg Clayton | d64afba | 2012-03-14 03:07:05 +0000 | [diff] [blame] | 80 | typedef STD_SHARED_PTR(RegisterContextLLDB) RegisterContextLLDBSP; |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 81 | |
| 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 Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 84 | RegisterContextLLDBSP |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 85 | 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 Molenda | 60f0bd4 | 2012-10-26 06:08:58 +0000 | [diff] [blame] | 90 | SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc, uint32_t starting_frame_num, bool pc_or_return_address_reg); |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 91 | |
| 92 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 93 | private: |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 94 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 95 | 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 Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 100 | RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 101 | |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 102 | Cursor () : start_pc (LLDB_INVALID_ADDRESS), cfa (LLDB_INVALID_ADDRESS), sctx(), reg_ctx_lldb_sp() { } |
Jason Molenda | 45b4924 | 2010-11-09 01:21:22 +0000 | [diff] [blame] | 103 | private: |
Jason Molenda | fa19c3e7 | 2010-11-04 09:40:56 +0000 | [diff] [blame] | 104 | DISALLOW_COPY_AND_ASSIGN (Cursor); |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 105 | }; |
| 106 | |
Greg Clayton | d64afba | 2012-03-14 03:07:05 +0000 | [diff] [blame] | 107 | typedef STD_SHARED_PTR(Cursor) CursorSP; |
Jason Molenda | 5976200 | 2010-11-04 00:53:20 +0000 | [diff] [blame] | 108 | std::vector<CursorSP> m_frames; |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 109 | 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 Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 113 | |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 114 | bool AddOneMoreFrame (ABI *abi); |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 115 | bool AddFirstFrame (); |
| 116 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 117 | //------------------------------------------------------------------ |
| 118 | // For UnwindLLDB only |
| 119 | //------------------------------------------------------------------ |
| 120 | DISALLOW_COPY_AND_ASSIGN (UnwindLLDB); |
| 121 | }; |
| 122 | |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 123 | } // namespace lldb_private |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 124 | |
| 125 | #endif // lldb_UnwindLLDB_h_ |