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" |
Jason Molenda | a4bea72 | 2014-02-14 05:06:49 +0000 | [diff] [blame] | 16 | #include "lldb/Core/ConstString.h" |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 17 | #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 Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 22 | namespace lldb_private { |
| 23 | |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 24 | class RegisterContextLLDB; |
| 25 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 26 | class UnwindLLDB : public lldb_private::Unwind |
| 27 | { |
| 28 | public: |
| 29 | UnwindLLDB (lldb_private::Thread &thread); |
| 30 | |
| 31 | virtual |
| 32 | ~UnwindLLDB() { } |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 33 | |
Jason Molenda | aff2a26 | 2012-11-16 01:03:31 +0000 | [diff] [blame] | 34 | enum RegisterSearchResult |
| 35 | { |
| 36 | eRegisterFound = 0, |
| 37 | eRegisterNotFound, |
| 38 | eRegisterIsVolatile |
| 39 | }; |
| 40 | |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 41 | protected: |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 42 | 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 |
Jason Molenda | ce19fe3 | 2014-12-09 22:28:10 +0000 | [diff] [blame^] | 51 | eRegisterValueInferred, // register val was computed (and is in inferred_value) |
| 52 | eRegisterInLiveRegisterContext // register value is in a live (stack frame #0) register |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 53 | }; |
| 54 | int type; |
| 55 | union |
| 56 | { |
| 57 | lldb::addr_t target_memory_location; |
| 58 | uint32_t register_number; // in eRegisterKindLLDB register numbering system |
| 59 | void* host_memory_location; |
| 60 | uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset |
| 61 | } location; |
| 62 | }; |
| 63 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 64 | void |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 65 | DoClear() |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 66 | { |
| 67 | m_frames.clear(); |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 68 | m_unwind_complete = false; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | virtual uint32_t |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 72 | DoGetFrameCount(); |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 73 | |
| 74 | bool |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 75 | DoGetFrameInfoAtIndex (uint32_t frame_idx, |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 76 | lldb::addr_t& cfa, |
| 77 | lldb::addr_t& start_pc); |
| 78 | |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 79 | lldb::RegisterContextSP |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 80 | DoCreateRegisterContextForFrame (lldb_private::StackFrame *frame); |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 81 | |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 82 | typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP; |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 83 | |
| 84 | // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB) |
| 85 | // 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] | 86 | RegisterContextLLDBSP |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 87 | GetRegisterContextForFrameNum (uint32_t frame_num); |
| 88 | |
| 89 | // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that |
| 90 | // has a saved location for this reg. |
| 91 | bool |
Jason Molenda | 23399d7 | 2013-06-05 00:12:50 +0000 | [diff] [blame] | 92 | SearchForSavedLocationForRegister (uint32_t lldb_regnum, lldb_private::UnwindLLDB::RegisterLocation ®loc, uint32_t starting_frame_num, bool pc_register); |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 93 | |
| 94 | |
Jason Molenda | a4bea72 | 2014-02-14 05:06:49 +0000 | [diff] [blame] | 95 | //------------------------------------------------------------------ |
| 96 | /// Provide the list of user-specified trap handler functions |
| 97 | /// |
| 98 | /// The Platform is one source of trap handler function names; that |
| 99 | /// may be augmented via a setting. The setting needs to be converted |
| 100 | /// into an array of ConstStrings before it can be used - we only want |
| 101 | /// to do that once per thread so it's here in the UnwindLLDB object. |
| 102 | /// |
| 103 | /// @return |
| 104 | /// Vector of ConstStrings of trap handler function names. May be |
| 105 | /// empty. |
| 106 | //------------------------------------------------------------------ |
| 107 | const std::vector<ConstString> & |
| 108 | GetUserSpecifiedTrapHandlerFunctionNames () |
| 109 | { |
| 110 | return m_user_supplied_trap_handler_functions; |
| 111 | } |
| 112 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 113 | private: |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 114 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 115 | struct Cursor |
| 116 | { |
| 117 | lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown |
| 118 | lldb::addr_t cfa; // The canonical frame address for this stack frame |
| 119 | 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] | 120 | RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 121 | |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 122 | 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] | 123 | private: |
Jason Molenda | fa19c3e7 | 2010-11-04 09:40:56 +0000 | [diff] [blame] | 124 | DISALLOW_COPY_AND_ASSIGN (Cursor); |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 125 | }; |
| 126 | |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 127 | typedef std::shared_ptr<Cursor> CursorSP; |
Jason Molenda | 5976200 | 2010-11-04 00:53:20 +0000 | [diff] [blame] | 128 | std::vector<CursorSP> m_frames; |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 129 | bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the |
| 130 | // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size() |
| 131 | // is how far we've currently gone. |
| 132 | |
Jason Molenda | a4bea72 | 2014-02-14 05:06:49 +0000 | [diff] [blame] | 133 | std::vector<ConstString> m_user_supplied_trap_handler_functions; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 134 | |
Greg Clayton | 9b72eb7 | 2011-05-24 23:06:02 +0000 | [diff] [blame] | 135 | bool AddOneMoreFrame (ABI *abi); |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 136 | bool AddFirstFrame (); |
| 137 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 138 | //------------------------------------------------------------------ |
| 139 | // For UnwindLLDB only |
| 140 | //------------------------------------------------------------------ |
| 141 | DISALLOW_COPY_AND_ASSIGN (UnwindLLDB); |
| 142 | }; |
| 143 | |
Greg Clayton | 58be07b | 2011-01-07 06:08:19 +0000 | [diff] [blame] | 144 | } // namespace lldb_private |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 145 | |
| 146 | #endif // lldb_UnwindLLDB_h_ |