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 | |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 13 | // C Includes |
| 14 | // C++ Includes |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 15 | #include <vector> |
| 16 | |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 17 | // Other libraries and framework includes |
| 18 | // Project includes |
Greg Clayton | e0d378b | 2011-03-24 21:19:54 +0000 | [diff] [blame] | 19 | #include "lldb/lldb-public.h" |
Jason Molenda | a4bea72 | 2014-02-14 05:06:49 +0000 | [diff] [blame] | 20 | #include "lldb/Core/ConstString.h" |
Greg Clayton | e576ab2 | 2011-02-15 00:19:15 +0000 | [diff] [blame] | 21 | #include "lldb/Symbol/FuncUnwinders.h" |
| 22 | #include "lldb/Symbol/UnwindPlan.h" |
| 23 | #include "lldb/Target/RegisterContext.h" |
| 24 | #include "lldb/Target/Unwind.h" |
| 25 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 26 | namespace lldb_private { |
| 27 | |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 28 | class RegisterContextLLDB; |
| 29 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 30 | class UnwindLLDB : public lldb_private::Unwind |
| 31 | { |
| 32 | public: |
| 33 | UnwindLLDB (lldb_private::Thread &thread); |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 34 | |
| 35 | ~UnwindLLDB() override = default; |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 36 | |
Jason Molenda | aff2a26 | 2012-11-16 01:03:31 +0000 | [diff] [blame] | 37 | enum RegisterSearchResult |
| 38 | { |
| 39 | eRegisterFound = 0, |
| 40 | eRegisterNotFound, |
| 41 | eRegisterIsVolatile |
| 42 | }; |
| 43 | |
Jim Ingham | 8f07716 | 2011-10-21 01:49:48 +0000 | [diff] [blame] | 44 | protected: |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 45 | friend class lldb_private::RegisterContextLLDB; |
| 46 | |
| 47 | struct RegisterLocation { |
| 48 | enum RegisterLocationTypes |
| 49 | { |
| 50 | eRegisterNotSaved = 0, // register was not preserved by callee. If volatile reg, is unavailable |
| 51 | eRegisterSavedAtMemoryLocation, // register is saved at a specific word of target mem (target_memory_location) |
| 52 | eRegisterInRegister, // register is available in a (possible other) register (register_number) |
| 53 | eRegisterSavedAtHostMemoryLocation, // register is saved at a word in lldb's address space |
Jason Molenda | ce19fe3 | 2014-12-09 22:28:10 +0000 | [diff] [blame] | 54 | eRegisterValueInferred, // register val was computed (and is in inferred_value) |
| 55 | eRegisterInLiveRegisterContext // register value is in a live (stack frame #0) register |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 56 | }; |
| 57 | int type; |
| 58 | union |
| 59 | { |
| 60 | lldb::addr_t target_memory_location; |
| 61 | uint32_t register_number; // in eRegisterKindLLDB register numbering system |
| 62 | void* host_memory_location; |
| 63 | uint64_t inferred_value; // eRegisterValueInferred - e.g. stack pointer == cfa + offset |
| 64 | } location; |
| 65 | }; |
| 66 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 67 | void |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 68 | DoClear() override |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 69 | { |
| 70 | m_frames.clear(); |
Tamas Berghammer | 8d53464 | 2015-07-06 09:24:20 +0000 | [diff] [blame] | 71 | m_candidate_frame.reset(); |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 72 | m_unwind_complete = false; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 75 | uint32_t |
| 76 | DoGetFrameCount() override; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 77 | |
| 78 | bool |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 79 | DoGetFrameInfoAtIndex(uint32_t frame_idx, |
| 80 | lldb::addr_t& cfa, |
| 81 | lldb::addr_t& start_pc) override; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 82 | |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 83 | lldb::RegisterContextSP |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 84 | DoCreateRegisterContextForFrame(lldb_private::StackFrame *frame) override; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 85 | |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 86 | typedef std::shared_ptr<RegisterContextLLDB> RegisterContextLLDBSP; |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 87 | |
| 88 | // Needed to retrieve the "next" frame (e.g. frame 2 needs to retrieve frame 1's RegisterContextLLDB) |
| 89 | // 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] | 90 | RegisterContextLLDBSP |
Jason Molenda | 707fec4 | 2011-11-01 03:21:25 +0000 | [diff] [blame] | 91 | GetRegisterContextForFrameNum (uint32_t frame_num); |
| 92 | |
| 93 | // Iterate over the RegisterContextLLDB's in our m_frames vector, look for the first one that |
| 94 | // has a saved location for this reg. |
| 95 | bool |
Jason Molenda | 23399d7 | 2013-06-05 00:12:50 +0000 | [diff] [blame] | 96 | 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] | 97 | |
| 98 | |
Jason Molenda | a4bea72 | 2014-02-14 05:06:49 +0000 | [diff] [blame] | 99 | //------------------------------------------------------------------ |
| 100 | /// Provide the list of user-specified trap handler functions |
| 101 | /// |
| 102 | /// The Platform is one source of trap handler function names; that |
| 103 | /// may be augmented via a setting. The setting needs to be converted |
| 104 | /// into an array of ConstStrings before it can be used - we only want |
| 105 | /// to do that once per thread so it's here in the UnwindLLDB object. |
| 106 | /// |
| 107 | /// @return |
| 108 | /// Vector of ConstStrings of trap handler function names. May be |
| 109 | /// empty. |
| 110 | //------------------------------------------------------------------ |
| 111 | const std::vector<ConstString> & |
| 112 | GetUserSpecifiedTrapHandlerFunctionNames () |
| 113 | { |
| 114 | return m_user_supplied_trap_handler_functions; |
| 115 | } |
| 116 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 117 | private: |
| 118 | struct Cursor |
| 119 | { |
| 120 | lldb::addr_t start_pc; // The start address of the function/symbol for this frame - current pc if unknown |
| 121 | lldb::addr_t cfa; // The canonical frame address for this stack frame |
| 122 | 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] | 123 | RegisterContextLLDBSP reg_ctx_lldb_sp; // These are all RegisterContextLLDB's |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 124 | |
Greg Clayton | e1cd1be | 2012-01-29 20:56:30 +0000 | [diff] [blame] | 125 | 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] | 126 | private: |
Jason Molenda | fa19c3e7 | 2010-11-04 09:40:56 +0000 | [diff] [blame] | 127 | DISALLOW_COPY_AND_ASSIGN (Cursor); |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Greg Clayton | 7b0992d | 2013-04-18 22:45:39 +0000 | [diff] [blame] | 130 | typedef std::shared_ptr<Cursor> CursorSP; |
Jason Molenda | 5976200 | 2010-11-04 00:53:20 +0000 | [diff] [blame] | 131 | std::vector<CursorSP> m_frames; |
Tamas Berghammer | 8d53464 | 2015-07-06 09:24:20 +0000 | [diff] [blame] | 132 | CursorSP m_candidate_frame; |
Jim Ingham | b0c72a5 | 2012-02-29 03:40:22 +0000 | [diff] [blame] | 133 | bool m_unwind_complete; // If this is true, we've enumerated all the frames in the stack, and m_frames.size() is the |
| 134 | // number of frames, etc. Otherwise we've only gone as far as directly asked, and m_frames.size() |
| 135 | // is how far we've currently gone. |
| 136 | |
Jason Molenda | a4bea72 | 2014-02-14 05:06:49 +0000 | [diff] [blame] | 137 | std::vector<ConstString> m_user_supplied_trap_handler_functions; |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 138 | |
Abhishek Aggarwal | be99464 | 2015-11-13 10:47:49 +0000 | [diff] [blame] | 139 | //----------------------------------------------------------------- |
| 140 | // Check if Full UnwindPlan of First frame is valid or not. |
| 141 | // If not then try Fallback UnwindPlan of the frame. If Fallback |
| 142 | // UnwindPlan succeeds then update the Full UnwindPlan with the |
| 143 | // Fallback UnwindPlan. |
| 144 | //----------------------------------------------------------------- |
| 145 | void |
| 146 | UpdateUnwindPlanForFirstFrameIfInvalid (ABI* abi); |
| 147 | |
Tamas Berghammer | 8d53464 | 2015-07-06 09:24:20 +0000 | [diff] [blame] | 148 | CursorSP |
| 149 | GetOneMoreFrame (ABI* abi); |
| 150 | |
| 151 | bool |
| 152 | AddOneMoreFrame (ABI *abi); |
| 153 | |
| 154 | bool |
| 155 | AddFirstFrame (); |
Jason Molenda | 8fed295 | 2010-11-09 02:31:21 +0000 | [diff] [blame] | 156 | |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 157 | //------------------------------------------------------------------ |
| 158 | // For UnwindLLDB only |
| 159 | //------------------------------------------------------------------ |
| 160 | DISALLOW_COPY_AND_ASSIGN (UnwindLLDB); |
| 161 | }; |
| 162 | |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 163 | } // namespace lldb_private |
Jason Molenda | ab4f192 | 2010-10-25 11:12:07 +0000 | [diff] [blame] | 164 | |
Eugene Zelenko | ab7f6d0 | 2015-10-21 18:46:17 +0000 | [diff] [blame] | 165 | #endif // lldb_UnwindLLDB_h_ |