Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- StackFrame.cpp ------------------------------------------*- 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 | #include "lldb/Target/StackFrame.h" |
| 11 | |
| 12 | // C Includes |
| 13 | // C++ Includes |
| 14 | // Other libraries and framework includes |
| 15 | // Project includes |
| 16 | #include "lldb/Core/Module.h" |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 17 | #include "lldb/Core/Debugger.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Core/Disassembler.h" |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 19 | #include "lldb/Core/FormatEntity.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | #include "lldb/Core/Value.h" |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 21 | #include "lldb/Core/ValueObjectVariable.h" |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 22 | #include "lldb/Core/ValueObjectConstResult.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 23 | #include "lldb/Symbol/CompileUnit.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 24 | #include "lldb/Symbol/Function.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 25 | #include "lldb/Symbol/Symbol.h" |
| 26 | #include "lldb/Symbol/SymbolContextScope.h" |
Enrico Granata | 4625239 | 2015-11-19 22:28:58 +0000 | [diff] [blame] | 27 | #include "lldb/Symbol/Type.h" |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 28 | #include "lldb/Symbol/VariableList.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 29 | #include "lldb/Target/ExecutionContext.h" |
| 30 | #include "lldb/Target/Process.h" |
| 31 | #include "lldb/Target/RegisterContext.h" |
| 32 | #include "lldb/Target/Target.h" |
| 33 | #include "lldb/Target/Thread.h" |
| 34 | |
| 35 | using namespace lldb; |
| 36 | using namespace lldb_private; |
| 37 | |
| 38 | // The first bits in the flags are reserved for the SymbolContext::Scope bits |
| 39 | // so we know if we have tried to look up information in our internal symbol |
| 40 | // context (m_sc) already. |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 41 | #define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1)) |
Greg Clayton | 6dadd50 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 42 | #define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1) |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 43 | #define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1) |
| 44 | #define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1) |
Sean Callanan | 7c0962d | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 45 | #define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 46 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 47 | StackFrame::StackFrame (const ThreadSP &thread_sp, |
| 48 | user_id_t frame_idx, |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 49 | user_id_t unwind_frame_index, |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 50 | addr_t cfa, |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 51 | bool cfa_is_valid, |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 52 | addr_t pc, |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 53 | uint32_t stop_id, |
| 54 | bool stop_id_is_valid, |
| 55 | bool is_history_frame, |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 56 | const SymbolContext *sc_ptr) : |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 57 | m_thread_wp (thread_sp), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 58 | m_frame_index (frame_idx), |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 59 | m_concrete_frame_index (unwind_frame_index), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 60 | m_reg_context_sp (), |
Greg Clayton | 6dadd50 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 61 | m_id (pc, cfa, NULL), |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 62 | m_frame_code_addr (pc), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 63 | m_sc (), |
| 64 | m_flags (), |
| 65 | m_frame_base (), |
| 66 | m_frame_base_error (), |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 67 | m_cfa_is_valid (cfa_is_valid), |
| 68 | m_stop_id (stop_id), |
| 69 | m_stop_id_is_valid (stop_id_is_valid), |
| 70 | m_is_history_frame (is_history_frame), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 71 | m_variable_list_sp (), |
Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 72 | m_variable_list_value_objects (), |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 73 | m_disassembly (), |
| 74 | m_mutex (Mutex::eMutexTypeRecursive) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | { |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 76 | // If we don't have a CFA value, use the frame index for our StackID so that recursive |
| 77 | // functions properly aren't confused with one another on a history stack. |
| 78 | if (m_is_history_frame && m_cfa_is_valid == false) |
| 79 | { |
| 80 | m_id.SetCFA (m_frame_index); |
| 81 | } |
| 82 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 83 | if (sc_ptr != NULL) |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 84 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | m_sc = *sc_ptr; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 86 | m_flags.Set(m_sc.GetResolvedMask ()); |
| 87 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 90 | StackFrame::StackFrame (const ThreadSP &thread_sp, |
| 91 | user_id_t frame_idx, |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 92 | user_id_t unwind_frame_index, |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 93 | const RegisterContextSP ®_context_sp, |
| 94 | addr_t cfa, |
| 95 | addr_t pc, |
| 96 | const SymbolContext *sc_ptr) : |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 97 | m_thread_wp (thread_sp), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 98 | m_frame_index (frame_idx), |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 99 | m_concrete_frame_index (unwind_frame_index), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 100 | m_reg_context_sp (reg_context_sp), |
Greg Clayton | 6dadd50 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 101 | m_id (pc, cfa, NULL), |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 102 | m_frame_code_addr (pc), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 103 | m_sc (), |
| 104 | m_flags (), |
| 105 | m_frame_base (), |
| 106 | m_frame_base_error (), |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 107 | m_cfa_is_valid (true), |
| 108 | m_stop_id (0), |
| 109 | m_stop_id_is_valid (false), |
| 110 | m_is_history_frame (false), |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | m_variable_list_sp (), |
Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 112 | m_variable_list_value_objects (), |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 113 | m_disassembly (), |
| 114 | m_mutex (Mutex::eMutexTypeRecursive) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | { |
| 116 | if (sc_ptr != NULL) |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 117 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | m_sc = *sc_ptr; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 119 | m_flags.Set(m_sc.GetResolvedMask ()); |
| 120 | } |
| 121 | |
| 122 | if (reg_context_sp && !m_sc.target_sp) |
| 123 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 124 | m_sc.target_sp = reg_context_sp->CalculateTarget(); |
| 125 | if (m_sc.target_sp) |
| 126 | m_flags.Set (eSymbolContextTarget); |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 130 | StackFrame::StackFrame (const ThreadSP &thread_sp, |
| 131 | user_id_t frame_idx, |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 132 | user_id_t unwind_frame_index, |
Greg Clayton | 8f7180b | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 133 | const RegisterContextSP ®_context_sp, |
| 134 | addr_t cfa, |
| 135 | const Address& pc_addr, |
| 136 | const SymbolContext *sc_ptr) : |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 137 | m_thread_wp (thread_sp), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 138 | m_frame_index (frame_idx), |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 139 | m_concrete_frame_index (unwind_frame_index), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 140 | m_reg_context_sp (reg_context_sp), |
Greg Clayton | 1ac04c3 | 2012-02-21 00:09:25 +0000 | [diff] [blame] | 141 | m_id (pc_addr.GetLoadAddress (thread_sp->CalculateTarget().get()), cfa, NULL), |
Greg Clayton | 12fc3e0 | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 142 | m_frame_code_addr (pc_addr), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 143 | m_sc (), |
| 144 | m_flags (), |
| 145 | m_frame_base (), |
| 146 | m_frame_base_error (), |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 147 | m_cfa_is_valid (true), |
| 148 | m_stop_id (0), |
| 149 | m_stop_id_is_valid (false), |
| 150 | m_is_history_frame (false), |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 151 | m_variable_list_sp (), |
Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 152 | m_variable_list_value_objects (), |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 153 | m_disassembly (), |
| 154 | m_mutex (Mutex::eMutexTypeRecursive) |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 155 | { |
| 156 | if (sc_ptr != NULL) |
| 157 | { |
| 158 | m_sc = *sc_ptr; |
| 159 | m_flags.Set(m_sc.GetResolvedMask ()); |
| 160 | } |
| 161 | |
| 162 | if (m_sc.target_sp.get() == NULL && reg_context_sp) |
| 163 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 164 | m_sc.target_sp = reg_context_sp->CalculateTarget(); |
| 165 | if (m_sc.target_sp) |
| 166 | m_flags.Set (eSymbolContextTarget); |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 169 | ModuleSP pc_module_sp (pc_addr.GetModule()); |
| 170 | if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 171 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 172 | if (pc_module_sp) |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 173 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 174 | m_sc.module_sp = pc_module_sp; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 175 | m_flags.Set (eSymbolContextModule); |
| 176 | } |
Greg Clayton | ffc1d66 | 2010-09-13 04:34:30 +0000 | [diff] [blame] | 177 | else |
| 178 | { |
| 179 | m_sc.module_sp.reset(); |
| 180 | } |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 181 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
| 185 | //---------------------------------------------------------------------- |
| 186 | // Destructor |
| 187 | //---------------------------------------------------------------------- |
| 188 | StackFrame::~StackFrame() |
| 189 | { |
| 190 | } |
| 191 | |
| 192 | StackID& |
| 193 | StackFrame::GetStackID() |
| 194 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 195 | Mutex::Locker locker(m_mutex); |
Greg Clayton | 6dadd50 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 196 | // Make sure we have resolved the StackID object's symbol context scope if |
| 197 | // we already haven't looked it up. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 198 | |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 199 | if (m_flags.IsClear (RESOLVED_FRAME_ID_SYMBOL_SCOPE)) |
| 200 | { |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 201 | if (m_id.GetSymbolContextScope ()) |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 202 | { |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 203 | // We already have a symbol context scope, we just don't have our |
| 204 | // flag bit set. |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 205 | m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); |
| 206 | } |
| 207 | else |
| 208 | { |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 209 | // Calculate the frame block and use this for the stack ID symbol |
| 210 | // context scope if we have one. |
| 211 | SymbolContextScope *scope = GetFrameBlock (); |
| 212 | if (scope == NULL) |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 213 | { |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 214 | // We don't have a block, so use the symbol |
| 215 | if (m_flags.IsClear (eSymbolContextSymbol)) |
| 216 | GetSymbolContext (eSymbolContextSymbol); |
| 217 | |
| 218 | // It is ok if m_sc.symbol is NULL here |
| 219 | scope = m_sc.symbol; |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 220 | } |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 221 | // Set the symbol context scope (the accessor will set the |
| 222 | // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags). |
| 223 | SetSymbolContextScope (scope); |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 224 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | } |
| 226 | return m_id; |
| 227 | } |
| 228 | |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 229 | uint32_t |
| 230 | StackFrame::GetFrameIndex () const |
| 231 | { |
| 232 | ThreadSP thread_sp = GetThread(); |
| 233 | if (thread_sp) |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 234 | return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(m_frame_index); |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 235 | else |
| 236 | return m_frame_index; |
| 237 | } |
| 238 | |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 239 | void |
| 240 | StackFrame::SetSymbolContextScope (SymbolContextScope *symbol_scope) |
| 241 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 242 | Mutex::Locker locker(m_mutex); |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 243 | m_flags.Set (RESOLVED_FRAME_ID_SYMBOL_SCOPE); |
| 244 | m_id.SetSymbolContextScope (symbol_scope); |
| 245 | } |
| 246 | |
Greg Clayton | 3413275 | 2011-07-06 04:07:21 +0000 | [diff] [blame] | 247 | const Address& |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 248 | StackFrame::GetFrameCodeAddress() |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 249 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 250 | Mutex::Locker locker(m_mutex); |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 251 | if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && !m_frame_code_addr.IsSectionOffset()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 252 | { |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 253 | m_flags.Set (RESOLVED_FRAME_CODE_ADDR); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 254 | |
| 255 | // Resolve the PC into a temporary address because if ResolveLoadAddress |
| 256 | // fails to resolve the address, it will clear the address object... |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 257 | ThreadSP thread_sp (GetThread()); |
| 258 | if (thread_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 259 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 260 | TargetSP target_sp (thread_sp->CalculateTarget()); |
| 261 | if (target_sp) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 262 | { |
Tamas Berghammer | 25b9f7e | 2015-09-07 09:58:09 +0000 | [diff] [blame] | 263 | if (m_frame_code_addr.SetOpcodeLoadAddress (m_frame_code_addr.GetOffset(), target_sp.get(), eAddressClassCode)) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 264 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 265 | ModuleSP module_sp (m_frame_code_addr.GetModule()); |
| 266 | if (module_sp) |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 267 | { |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 268 | m_sc.module_sp = module_sp; |
| 269 | m_flags.Set(eSymbolContextModule); |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 270 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | } |
| 274 | } |
Greg Clayton | 12fc3e0 | 2010-08-26 22:05:43 +0000 | [diff] [blame] | 275 | return m_frame_code_addr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 278 | bool |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 279 | StackFrame::ChangePC (addr_t pc) |
| 280 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 281 | Mutex::Locker locker(m_mutex); |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 282 | // We can't change the pc value of a history stack frame - it is immutable. |
| 283 | if (m_is_history_frame) |
| 284 | return false; |
Greg Clayton | e72dfb3 | 2012-02-24 01:59:29 +0000 | [diff] [blame] | 285 | m_frame_code_addr.SetRawAddress(pc); |
Greg Clayton | 7231035 | 2013-02-23 04:12:47 +0000 | [diff] [blame] | 286 | m_sc.Clear(false); |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 287 | m_flags.Reset(0); |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 288 | ThreadSP thread_sp (GetThread()); |
| 289 | if (thread_sp) |
| 290 | thread_sp->ClearStackFrames (); |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 291 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | const char * |
| 295 | StackFrame::Disassemble () |
| 296 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 297 | Mutex::Locker locker(m_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 298 | if (m_disassembly.GetSize() == 0) |
| 299 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 300 | ExecutionContext exe_ctx (shared_from_this()); |
| 301 | Target *target = exe_ctx.GetTargetPtr(); |
| 302 | if (target) |
| 303 | { |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 304 | const char *plugin_name = NULL; |
| 305 | const char *flavor = NULL; |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 306 | Disassembler::Disassemble (target->GetDebugger(), |
| 307 | target->GetArchitecture(), |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 308 | plugin_name, |
| 309 | flavor, |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 310 | exe_ctx, |
| 311 | 0, |
| 312 | 0, |
| 313 | 0, |
| 314 | m_disassembly); |
| 315 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 316 | if (m_disassembly.GetSize() == 0) |
| 317 | return NULL; |
| 318 | } |
| 319 | return m_disassembly.GetData(); |
| 320 | } |
| 321 | |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 322 | Block * |
| 323 | StackFrame::GetFrameBlock () |
| 324 | { |
| 325 | if (m_sc.block == NULL && m_flags.IsClear (eSymbolContextBlock)) |
| 326 | GetSymbolContext (eSymbolContextBlock); |
| 327 | |
| 328 | if (m_sc.block) |
| 329 | { |
| 330 | Block *inline_block = m_sc.block->GetContainingInlinedBlock(); |
| 331 | if (inline_block) |
| 332 | { |
| 333 | // Use the block with the inlined function info |
| 334 | // as the frame block we want this frame to have only the variables |
| 335 | // for the inlined function and its non-inlined block child blocks. |
| 336 | return inline_block; |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | // This block is not contained withing any inlined function blocks |
| 341 | // with so we want to use the top most function block. |
| 342 | return &m_sc.function->GetBlock (false); |
| 343 | } |
| 344 | } |
| 345 | return NULL; |
| 346 | } |
| 347 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 348 | //---------------------------------------------------------------------- |
| 349 | // Get the symbol context if we already haven't done so by resolving the |
| 350 | // PC address as much as possible. This way when we pass around a |
| 351 | // StackFrame object, everyone will have as much information as |
| 352 | // possible and no one will ever have to look things up manually. |
| 353 | //---------------------------------------------------------------------- |
| 354 | const SymbolContext& |
| 355 | StackFrame::GetSymbolContext (uint32_t resolve_scope) |
| 356 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 357 | Mutex::Locker locker(m_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 358 | // Copy our internal symbol context into "sc". |
Greg Clayton | 73b472d | 2010-10-27 03:32:59 +0000 | [diff] [blame] | 359 | if ((m_flags.Get() & resolve_scope) != resolve_scope) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | { |
Greg Clayton | 75a0333 | 2012-11-29 00:53:06 +0000 | [diff] [blame] | 361 | uint32_t resolved = 0; |
| 362 | |
| 363 | // If the target was requested add that: |
| 364 | if (!m_sc.target_sp) |
| 365 | { |
| 366 | m_sc.target_sp = CalculateTarget(); |
| 367 | if (m_sc.target_sp) |
| 368 | resolved |= eSymbolContextTarget; |
| 369 | } |
| 370 | |
| 371 | |
Bruce Mitchener | aaa0ba3 | 2014-07-08 18:05:41 +0000 | [diff] [blame] | 372 | // Resolve our PC to section offset if we haven't already done so |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | // and if we don't have a module. The resolved address section will |
| 374 | // contain the module to which it belongs |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 375 | if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR)) |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 376 | GetFrameCodeAddress(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 377 | |
| 378 | // If this is not frame zero, then we need to subtract 1 from the PC |
| 379 | // value when doing address lookups since the PC will be on the |
| 380 | // instruction following the function call instruction... |
| 381 | |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 382 | Address lookup_addr(GetFrameCodeAddress()); |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 383 | if (m_frame_index > 0 && lookup_addr.IsValid()) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | { |
| 385 | addr_t offset = lookup_addr.GetOffset(); |
| 386 | if (offset > 0) |
Jason Molenda | cf29675 | 2014-11-08 05:38:17 +0000 | [diff] [blame] | 387 | { |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 388 | lookup_addr.SetOffset(offset - 1); |
Jason Molenda | cf29675 | 2014-11-08 05:38:17 +0000 | [diff] [blame] | 389 | |
| 390 | } |
| 391 | else |
| 392 | { |
| 393 | // lookup_addr is the start of a section. We need |
| 394 | // do the math on the actual load address and re-compute |
| 395 | // the section. We're working with a 'noreturn' function |
| 396 | // at the end of a section. |
| 397 | ThreadSP thread_sp (GetThread()); |
| 398 | if (thread_sp) |
| 399 | { |
| 400 | TargetSP target_sp (thread_sp->CalculateTarget()); |
| 401 | if (target_sp) |
| 402 | { |
| 403 | addr_t addr_minus_one = lookup_addr.GetLoadAddress(target_sp.get()) - 1; |
| 404 | lookup_addr.SetLoadAddress (addr_minus_one, target_sp.get()); |
| 405 | } |
| 406 | else |
| 407 | { |
| 408 | lookup_addr.SetOffset(offset - 1); |
| 409 | } |
| 410 | } |
| 411 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 412 | } |
| 413 | |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 414 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 415 | if (m_sc.module_sp) |
| 416 | { |
| 417 | // We have something in our stack frame symbol context, lets check |
| 418 | // if we haven't already tried to lookup one of those things. If we |
| 419 | // haven't then we will do the query. |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 420 | |
| 421 | uint32_t actual_resolve_scope = 0; |
| 422 | |
| 423 | if (resolve_scope & eSymbolContextCompUnit) |
| 424 | { |
| 425 | if (m_flags.IsClear (eSymbolContextCompUnit)) |
| 426 | { |
| 427 | if (m_sc.comp_unit) |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 428 | resolved |= eSymbolContextCompUnit; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 429 | else |
| 430 | actual_resolve_scope |= eSymbolContextCompUnit; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | if (resolve_scope & eSymbolContextFunction) |
| 435 | { |
| 436 | if (m_flags.IsClear (eSymbolContextFunction)) |
| 437 | { |
| 438 | if (m_sc.function) |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 439 | resolved |= eSymbolContextFunction; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 440 | else |
| 441 | actual_resolve_scope |= eSymbolContextFunction; |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | if (resolve_scope & eSymbolContextBlock) |
| 446 | { |
| 447 | if (m_flags.IsClear (eSymbolContextBlock)) |
| 448 | { |
| 449 | if (m_sc.block) |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 450 | resolved |= eSymbolContextBlock; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 451 | else |
| 452 | actual_resolve_scope |= eSymbolContextBlock; |
| 453 | } |
| 454 | } |
| 455 | |
| 456 | if (resolve_scope & eSymbolContextSymbol) |
| 457 | { |
| 458 | if (m_flags.IsClear (eSymbolContextSymbol)) |
| 459 | { |
| 460 | if (m_sc.symbol) |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 461 | resolved |= eSymbolContextSymbol; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 462 | else |
| 463 | actual_resolve_scope |= eSymbolContextSymbol; |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | if (resolve_scope & eSymbolContextLineEntry) |
| 468 | { |
| 469 | if (m_flags.IsClear (eSymbolContextLineEntry)) |
| 470 | { |
| 471 | if (m_sc.line_entry.IsValid()) |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 472 | resolved |= eSymbolContextLineEntry; |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 473 | else |
| 474 | actual_resolve_scope |= eSymbolContextLineEntry; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | if (actual_resolve_scope) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 479 | { |
| 480 | // We might be resolving less information than what is already |
| 481 | // in our current symbol context so resolve into a temporary |
| 482 | // symbol context "sc" so we don't clear out data we have |
| 483 | // already found in "m_sc" |
| 484 | SymbolContext sc; |
| 485 | // Set flags that indicate what we have tried to resolve |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 486 | resolved |= m_sc.module_sp->ResolveSymbolContextForAddress (lookup_addr, actual_resolve_scope, sc); |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 487 | // Only replace what we didn't already have as we may have |
| 488 | // information for an inlined function scope that won't match |
| 489 | // what a standard lookup by address would match |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 490 | if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == NULL) |
| 491 | m_sc.comp_unit = sc.comp_unit; |
| 492 | if ((resolved & eSymbolContextFunction) && m_sc.function == NULL) |
| 493 | m_sc.function = sc.function; |
| 494 | if ((resolved & eSymbolContextBlock) && m_sc.block == NULL) |
| 495 | m_sc.block = sc.block; |
| 496 | if ((resolved & eSymbolContextSymbol) && m_sc.symbol == NULL) |
| 497 | m_sc.symbol = sc.symbol; |
Greg Clayton | 75a0333 | 2012-11-29 00:53:06 +0000 | [diff] [blame] | 498 | if ((resolved & eSymbolContextLineEntry) && !m_sc.line_entry.IsValid()) |
| 499 | { |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 500 | m_sc.line_entry = sc.line_entry; |
Greg Clayton | 75a0333 | 2012-11-29 00:53:06 +0000 | [diff] [blame] | 501 | if (m_sc.target_sp) |
| 502 | { |
| 503 | // Be sure to apply and file remappings to our file and line |
| 504 | // entries when handing out a line entry |
| 505 | FileSpec new_file_spec; |
| 506 | if (m_sc.target_sp->GetSourcePathMap().FindFile (m_sc.line_entry.file, new_file_spec)) |
| 507 | m_sc.line_entry.file = new_file_spec; |
| 508 | } |
| 509 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | else |
| 513 | { |
| 514 | // If we don't have a module, then we can't have the compile unit, |
| 515 | // function, block, line entry or symbol, so we can safely call |
| 516 | // ResolveSymbolContextForAddress with our symbol context member m_sc. |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 517 | if (m_sc.target_sp) |
Sean Callanan | f4be227 | 2013-02-21 20:54:33 +0000 | [diff] [blame] | 518 | { |
Greg Clayton | 75a0333 | 2012-11-29 00:53:06 +0000 | [diff] [blame] | 519 | resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress (lookup_addr, resolve_scope, m_sc); |
Sean Callanan | f4be227 | 2013-02-21 20:54:33 +0000 | [diff] [blame] | 520 | } |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 521 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 522 | |
| 523 | // Update our internal flags so we remember what we have tried to locate so |
| 524 | // we don't have to keep trying when more calls to this function are made. |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 525 | // We might have dug up more information that was requested (for example |
| 526 | // if we were asked to only get the block, we will have gotten the |
| 527 | // compile unit, and function) so set any additional bits that we resolved |
| 528 | m_flags.Set (resolve_scope | resolved); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | // Return the symbol context with everything that was possible to resolve |
| 532 | // resolved. |
| 533 | return m_sc; |
| 534 | } |
| 535 | |
| 536 | |
| 537 | VariableList * |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 538 | StackFrame::GetVariableList (bool get_file_globals) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 539 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 540 | Mutex::Locker locker(m_mutex); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 541 | if (m_flags.IsClear(RESOLVED_VARIABLES)) |
| 542 | { |
| 543 | m_flags.Set(RESOLVED_VARIABLES); |
| 544 | |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 545 | Block *frame_block = GetFrameBlock(); |
| 546 | |
| 547 | if (frame_block) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 548 | { |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 549 | const bool get_child_variables = true; |
| 550 | const bool can_create = true; |
Greg Clayton | c662ec8 | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 551 | const bool stop_if_child_block_is_inlined_function = true; |
| 552 | m_variable_list_sp.reset(new VariableList()); |
| 553 | frame_block->AppendBlockVariables(can_create, get_child_variables, stop_if_child_block_is_inlined_function, m_variable_list_sp.get()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 554 | } |
Sean Callanan | 7c0962d | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && |
| 558 | get_file_globals) |
| 559 | { |
| 560 | m_flags.Set(RESOLVED_GLOBAL_VARIABLES); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 561 | |
Sean Callanan | 7c0962d | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 562 | if (m_flags.IsClear (eSymbolContextCompUnit)) |
| 563 | GetSymbolContext (eSymbolContextCompUnit); |
| 564 | |
| 565 | if (m_sc.comp_unit) |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 566 | { |
Sean Callanan | 7c0962d | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 567 | VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); |
| 568 | if (m_variable_list_sp) |
| 569 | m_variable_list_sp->AddVariables (global_variable_list_sp.get()); |
| 570 | else |
| 571 | m_variable_list_sp = global_variable_list_sp; |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 572 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 573 | } |
Sean Callanan | 7c0962d | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 574 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 575 | return m_variable_list_sp.get(); |
| 576 | } |
| 577 | |
Greg Clayton | d41f032 | 2011-08-02 23:35:43 +0000 | [diff] [blame] | 578 | VariableListSP |
| 579 | StackFrame::GetInScopeVariableList (bool get_file_globals) |
| 580 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 581 | Mutex::Locker locker(m_mutex); |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 582 | // We can't fetch variable information for a history stack frame. |
| 583 | if (m_is_history_frame) |
| 584 | return VariableListSP(); |
| 585 | |
Greg Clayton | d41f032 | 2011-08-02 23:35:43 +0000 | [diff] [blame] | 586 | VariableListSP var_list_sp(new VariableList); |
| 587 | GetSymbolContext (eSymbolContextCompUnit | eSymbolContextBlock); |
| 588 | |
| 589 | if (m_sc.block) |
| 590 | { |
| 591 | const bool can_create = true; |
| 592 | const bool get_parent_variables = true; |
| 593 | const bool stop_if_block_is_inlined_function = true; |
| 594 | m_sc.block->AppendVariables (can_create, |
| 595 | get_parent_variables, |
| 596 | stop_if_block_is_inlined_function, |
| 597 | var_list_sp.get()); |
| 598 | } |
| 599 | |
Siva Chandra | b90168f | 2016-02-02 23:49:41 +0000 | [diff] [blame] | 600 | if (m_sc.comp_unit && get_file_globals) |
Greg Clayton | d41f032 | 2011-08-02 23:35:43 +0000 | [diff] [blame] | 601 | { |
| 602 | VariableListSP global_variable_list_sp (m_sc.comp_unit->GetVariableList(true)); |
| 603 | if (global_variable_list_sp) |
| 604 | var_list_sp->AddVariables (global_variable_list_sp.get()); |
| 605 | } |
| 606 | |
| 607 | return var_list_sp; |
| 608 | } |
| 609 | |
| 610 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 611 | ValueObjectSP |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 612 | StackFrame::GetValueForVariableExpressionPath (const char *var_expr_cstr, |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 613 | DynamicValueType use_dynamic, |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 614 | uint32_t options, |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 615 | VariableSP &var_sp, |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 616 | Error &error) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 617 | { |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 618 | // We can't fetch variable information for a history stack frame. |
| 619 | if (m_is_history_frame) |
| 620 | return ValueObjectSP(); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 621 | |
| 622 | if (var_expr_cstr && var_expr_cstr[0]) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 623 | { |
Greg Clayton | 6d5e68e | 2011-01-20 19:27:18 +0000 | [diff] [blame] | 624 | const bool check_ptr_vs_member = (options & eExpressionPathOptionCheckPtrVsMember) != 0; |
| 625 | const bool no_fragile_ivar = (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 626 | const bool no_synth_child = (options & eExpressionPathOptionsNoSyntheticChildren) != 0; |
Enrico Granata | 58ad334 | 2011-08-19 21:56:10 +0000 | [diff] [blame] | 627 | //const bool no_synth_array = (options & eExpressionPathOptionsNoSyntheticArrayRange) != 0; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 628 | error.Clear(); |
| 629 | bool deref = false; |
| 630 | bool address_of = false; |
| 631 | ValueObjectSP valobj_sp; |
| 632 | const bool get_file_globals = true; |
Greg Clayton | d41f032 | 2011-08-02 23:35:43 +0000 | [diff] [blame] | 633 | // When looking up a variable for an expression, we need only consider the |
| 634 | // variables that are in scope. |
| 635 | VariableListSP var_list_sp (GetInScopeVariableList (get_file_globals)); |
| 636 | VariableList *variable_list = var_list_sp.get(); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 637 | |
| 638 | if (variable_list) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 639 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 640 | // If first character is a '*', then show pointer contents |
| 641 | const char *var_expr = var_expr_cstr; |
| 642 | if (var_expr[0] == '*') |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 643 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 644 | deref = true; |
| 645 | var_expr++; // Skip the '*' |
| 646 | } |
| 647 | else if (var_expr[0] == '&') |
| 648 | { |
| 649 | address_of = true; |
| 650 | var_expr++; // Skip the '&' |
| 651 | } |
| 652 | |
| 653 | std::string var_path (var_expr); |
| 654 | size_t separator_idx = var_path.find_first_of(".-[=+~|&^%#@!/?,<>{}"); |
| 655 | StreamString var_expr_path_strm; |
| 656 | |
| 657 | ConstString name_const_string; |
| 658 | if (separator_idx == std::string::npos) |
| 659 | name_const_string.SetCString (var_path.c_str()); |
| 660 | else |
| 661 | name_const_string.SetCStringWithLength (var_path.c_str(), separator_idx); |
| 662 | |
Paul Herman | 10bc1a4 | 2015-08-18 22:46:57 +0000 | [diff] [blame] | 663 | var_sp = variable_list->FindVariable(name_const_string, false); |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 664 | |
| 665 | bool synthetically_added_instance_object = false; |
| 666 | |
| 667 | if (var_sp) |
| 668 | { |
| 669 | var_path.erase (0, name_const_string.GetLength ()); |
| 670 | } |
Enrico Granata | 4625239 | 2015-11-19 22:28:58 +0000 | [diff] [blame] | 671 | |
| 672 | if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 673 | { |
| 674 | // Check for direct ivars access which helps us with implicit |
| 675 | // access to ivars with the "this->" or "self->" |
| 676 | GetSymbolContext(eSymbolContextFunction|eSymbolContextBlock); |
| 677 | lldb::LanguageType method_language = eLanguageTypeUnknown; |
| 678 | bool is_instance_method = false; |
| 679 | ConstString method_object_name; |
| 680 | if (m_sc.GetFunctionMethodInfo (method_language, is_instance_method, method_object_name)) |
| 681 | { |
| 682 | if (is_instance_method && method_object_name) |
| 683 | { |
| 684 | var_sp = variable_list->FindVariable(method_object_name); |
| 685 | if (var_sp) |
| 686 | { |
| 687 | separator_idx = 0; |
| 688 | var_path.insert(0, "->"); |
| 689 | synthetically_added_instance_object = true; |
| 690 | } |
| 691 | } |
| 692 | } |
| 693 | } |
Enrico Granata | 4625239 | 2015-11-19 22:28:58 +0000 | [diff] [blame] | 694 | |
| 695 | if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) |
| 696 | { |
| 697 | // Check if any anonymous unions are there which contain a variable with the name we need |
| 698 | for (size_t i = 0; |
| 699 | i < variable_list->GetSize(); |
| 700 | i++) |
| 701 | { |
| 702 | if (VariableSP variable_sp = variable_list->GetVariableAtIndex(i)) |
| 703 | { |
| 704 | if (variable_sp->GetName().IsEmpty()) |
| 705 | { |
| 706 | if (Type *var_type = variable_sp->GetType()) |
| 707 | { |
| 708 | if (var_type->GetForwardCompilerType().IsAnonymousType()) |
| 709 | { |
| 710 | valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); |
| 711 | if (!valobj_sp) |
| 712 | return valobj_sp; |
| 713 | valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true); |
| 714 | if (valobj_sp) |
| 715 | break; |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | } |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 722 | |
Enrico Granata | 4625239 | 2015-11-19 22:28:58 +0000 | [diff] [blame] | 723 | if (var_sp && !valobj_sp) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 724 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 725 | valobj_sp = GetValueObjectForFrameVariable (var_sp, use_dynamic); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 726 | if (!valobj_sp) |
| 727 | return valobj_sp; |
Enrico Granata | 4625239 | 2015-11-19 22:28:58 +0000 | [diff] [blame] | 728 | } |
| 729 | if (valobj_sp) |
| 730 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 731 | // We are dumping at least one child |
| 732 | while (separator_idx != std::string::npos) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 733 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 734 | // Calculate the next separator index ahead of time |
| 735 | ValueObjectSP child_valobj_sp; |
| 736 | const char separator_type = var_path[0]; |
| 737 | switch (separator_type) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 738 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 739 | |
| 740 | case '-': |
| 741 | if (var_path.size() >= 2 && var_path[1] != '>') |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 742 | return ValueObjectSP(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 743 | |
Greg Clayton | 6d5e68e | 2011-01-20 19:27:18 +0000 | [diff] [blame] | 744 | if (no_fragile_ivar) |
| 745 | { |
| 746 | // Make sure we aren't trying to deref an objective |
| 747 | // C ivar if this is not allowed |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 748 | const uint32_t pointer_type_flags = valobj_sp->GetCompilerType().GetTypeInfo (NULL); |
Enrico Granata | 622be23 | 2014-10-21 20:52:14 +0000 | [diff] [blame] | 749 | if ((pointer_type_flags & eTypeIsObjC) && |
| 750 | (pointer_type_flags & eTypeIsPointer)) |
Greg Clayton | 6d5e68e | 2011-01-20 19:27:18 +0000 | [diff] [blame] | 751 | { |
| 752 | // This was an objective C object pointer and |
| 753 | // it was requested we skip any fragile ivars |
| 754 | // so return nothing here |
| 755 | return ValueObjectSP(); |
| 756 | } |
| 757 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 758 | var_path.erase (0, 1); // Remove the '-' |
Jason Molenda | 62e0681 | 2016-02-16 04:14:33 +0000 | [diff] [blame^] | 759 | LLVM_FALLTHROUGH; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 760 | case '.': |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 761 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 762 | const bool expr_is_ptr = var_path[0] == '>'; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 763 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 764 | var_path.erase (0, 1); // Remove the '.' or '>' |
| 765 | separator_idx = var_path.find_first_of(".-["); |
| 766 | ConstString child_name; |
| 767 | if (separator_idx == std::string::npos) |
| 768 | child_name.SetCString (var_path.c_str()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 769 | else |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 770 | child_name.SetCStringWithLength(var_path.c_str(), separator_idx); |
| 771 | |
| 772 | if (check_ptr_vs_member) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 773 | { |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 774 | // We either have a pointer type and need to verify |
| 775 | // valobj_sp is a pointer, or we have a member of a |
| 776 | // class/union/struct being accessed with the . syntax |
| 777 | // and need to verify we don't have a pointer. |
| 778 | const bool actual_is_ptr = valobj_sp->IsPointerType (); |
| 779 | |
| 780 | if (actual_is_ptr != expr_is_ptr) |
| 781 | { |
| 782 | // Incorrect use of "." with a pointer, or "->" with |
| 783 | // a class/union/struct instance or reference. |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 784 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 785 | if (actual_is_ptr) |
| 786 | error.SetErrorStringWithFormat ("\"%s\" is a pointer and . was used to attempt to access \"%s\". Did you mean \"%s->%s\"?", |
| 787 | var_expr_path_strm.GetString().c_str(), |
| 788 | child_name.GetCString(), |
| 789 | var_expr_path_strm.GetString().c_str(), |
| 790 | var_path.c_str()); |
| 791 | else |
| 792 | error.SetErrorStringWithFormat ("\"%s\" is not a pointer and -> was used to attempt to access \"%s\". Did you mean \"%s.%s\"?", |
| 793 | var_expr_path_strm.GetString().c_str(), |
| 794 | child_name.GetCString(), |
| 795 | var_expr_path_strm.GetString().c_str(), |
| 796 | var_path.c_str()); |
| 797 | return ValueObjectSP(); |
| 798 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 799 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 800 | child_valobj_sp = valobj_sp->GetChildMemberWithName (child_name, true); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 801 | if (!child_valobj_sp) |
| 802 | { |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 803 | if (no_synth_child == false) |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 804 | { |
| 805 | child_valobj_sp = valobj_sp->GetSyntheticValue(); |
| 806 | if (child_valobj_sp) |
| 807 | child_valobj_sp = child_valobj_sp->GetChildMemberWithName (child_name, true); |
| 808 | } |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 809 | |
| 810 | if (no_synth_child || !child_valobj_sp) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 811 | { |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 812 | // No child member with name "child_name" |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 813 | if (synthetically_added_instance_object) |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 814 | { |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 815 | // We added a "this->" or "self->" to the beginning of the expression |
| 816 | // and this is the first pointer ivar access, so just return the normal |
| 817 | // error |
| 818 | error.SetErrorStringWithFormat("no variable or instance variable named '%s' found in this frame", |
| 819 | name_const_string.GetCString()); |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 820 | } |
| 821 | else |
| 822 | { |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 823 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 824 | if (child_name) |
| 825 | { |
| 826 | error.SetErrorStringWithFormat ("\"%s\" is not a member of \"(%s) %s\"", |
| 827 | child_name.GetCString(), |
| 828 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 829 | var_expr_path_strm.GetString().c_str()); |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | error.SetErrorStringWithFormat ("incomplete expression path after \"%s\" in \"%s\"", |
| 834 | var_expr_path_strm.GetString().c_str(), |
| 835 | var_expr_cstr); |
| 836 | } |
Enrico Granata | 8c9d356 | 2011-08-11 17:08:01 +0000 | [diff] [blame] | 837 | } |
| 838 | return ValueObjectSP(); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 839 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 840 | } |
Greg Clayton | 685c88c | 2012-07-14 00:53:55 +0000 | [diff] [blame] | 841 | synthetically_added_instance_object = false; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 842 | // Remove the child name from the path |
| 843 | var_path.erase(0, child_name.GetLength()); |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 844 | if (use_dynamic != eNoDynamicValues) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 845 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 846 | ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 847 | if (dynamic_value_sp) |
| 848 | child_valobj_sp = dynamic_value_sp; |
| 849 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 850 | } |
| 851 | break; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 852 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 853 | case '[': |
| 854 | // Array member access, or treating pointer as an array |
| 855 | if (var_path.size() > 2) // Need at least two brackets and a number |
| 856 | { |
| 857 | char *end = NULL; |
Greg Clayton | 1a65ae1 | 2011-01-25 23:55:37 +0000 | [diff] [blame] | 858 | long child_index = ::strtol (&var_path[1], &end, 0); |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 859 | if (end && *end == ']' |
| 860 | && *(end-1) != '[') // this code forces an error in the case of arr[]. as bitfield[] is not a good syntax we're good to go |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 861 | { |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 862 | if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 863 | { |
| 864 | // what we have is *ptr[low]. the most similar C++ syntax is to deref ptr |
| 865 | // and extract bit low out of it. reading array item low |
| 866 | // would be done by saying ptr[low], without a deref * sign |
| 867 | Error error; |
| 868 | ValueObjectSP temp(valobj_sp->Dereference(error)); |
| 869 | if (error.Fail()) |
| 870 | { |
| 871 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 872 | error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", |
| 873 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 874 | var_expr_path_strm.GetString().c_str()); |
| 875 | return ValueObjectSP(); |
| 876 | } |
| 877 | valobj_sp = temp; |
| 878 | deref = false; |
| 879 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 880 | else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 881 | { |
| 882 | // what we have is *arr[low]. the most similar C++ syntax is to get arr[0] |
| 883 | // (an operation that is equivalent to deref-ing arr) |
| 884 | // and extract bit low out of it. reading array item low |
| 885 | // would be done by saying arr[low], without a deref * sign |
| 886 | Error error; |
| 887 | ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); |
| 888 | if (error.Fail()) |
| 889 | { |
| 890 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 891 | error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", |
| 892 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 893 | var_expr_path_strm.GetString().c_str()); |
| 894 | return ValueObjectSP(); |
| 895 | } |
| 896 | valobj_sp = temp; |
| 897 | deref = false; |
| 898 | } |
| 899 | |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 900 | bool is_incomplete_array = false; |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 901 | if (valobj_sp->IsPointerType ()) |
| 902 | { |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 903 | bool is_objc_pointer = true; |
| 904 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 905 | if (valobj_sp->GetCompilerType().GetMinimumLanguage() != eLanguageTypeObjC) |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 906 | is_objc_pointer = false; |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 907 | else if (!valobj_sp->GetCompilerType().IsPointerType()) |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 908 | is_objc_pointer = false; |
| 909 | |
| 910 | if (no_synth_child && is_objc_pointer) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 911 | { |
Sean Callanan | 226b70c | 2012-03-08 02:39:03 +0000 | [diff] [blame] | 912 | error.SetErrorStringWithFormat("\"(%s) %s\" is an Objective-C pointer, and cannot be subscripted", |
| 913 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 914 | var_expr_path_strm.GetString().c_str()); |
| 915 | |
| 916 | return ValueObjectSP(); |
| 917 | } |
| 918 | else if (is_objc_pointer) |
| 919 | { |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 920 | // dereferencing ObjC variables is not valid.. so let's try and recur to synthetic children |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 921 | ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 922 | if (synthetic.get() == NULL /* no synthetic */ |
| 923 | || synthetic == valobj_sp) /* synthetic is the same as the original object */ |
| 924 | { |
| 925 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 926 | error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", |
| 927 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 928 | var_expr_path_strm.GetString().c_str()); |
| 929 | } |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 930 | else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */) |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 931 | { |
| 932 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 933 | error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 934 | child_index, |
| 935 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 936 | var_expr_path_strm.GetString().c_str()); |
| 937 | } |
| 938 | else |
| 939 | { |
| 940 | child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); |
| 941 | if (!child_valobj_sp) |
| 942 | { |
| 943 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 944 | error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 945 | child_index, |
| 946 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 947 | var_expr_path_strm.GetString().c_str()); |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | else |
| 952 | { |
Bruce Mitchener | 11d8636 | 2015-02-26 23:55:39 +0000 | [diff] [blame] | 953 | child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true); |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 954 | if (!child_valobj_sp) |
| 955 | { |
| 956 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 957 | error.SetErrorStringWithFormat ("failed to use pointer as array for index %ld for \"(%s) %s\"", |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 958 | child_index, |
| 959 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 960 | var_expr_path_strm.GetString().c_str()); |
| 961 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 962 | } |
| 963 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 964 | else if (valobj_sp->GetCompilerType().IsArrayType (NULL, NULL, &is_incomplete_array)) |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 965 | { |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 966 | // Pass false to dynamic_value here so we can tell the difference between |
| 967 | // no dynamic value and no member of this type... |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 968 | child_valobj_sp = valobj_sp->GetChildAtIndex (child_index, true); |
Greg Clayton | 4ef877f | 2012-12-06 02:33:54 +0000 | [diff] [blame] | 969 | if (!child_valobj_sp && (is_incomplete_array || no_synth_child == false)) |
| 970 | child_valobj_sp = valobj_sp->GetSyntheticArrayMember (child_index, true); |
| 971 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 972 | if (!child_valobj_sp) |
| 973 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 974 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 975 | error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 976 | child_index, |
| 977 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 978 | var_expr_path_strm.GetString().c_str()); |
| 979 | } |
| 980 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 981 | else if (valobj_sp->GetCompilerType().IsScalarType()) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 982 | { |
| 983 | // this is a bitfield asking to display just one bit |
| 984 | child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, child_index, true); |
| 985 | if (!child_valobj_sp) |
| 986 | { |
| 987 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 988 | error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"", |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 989 | child_index, child_index, |
| 990 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 991 | var_expr_path_strm.GetString().c_str()); |
| 992 | } |
| 993 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 994 | else |
| 995 | { |
Enrico Granata | 86cc982 | 2012-03-19 22:58:49 +0000 | [diff] [blame] | 996 | ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 997 | if (no_synth_child /* synthetic is forbidden */ || |
| 998 | synthetic.get() == NULL /* no synthetic */ |
| 999 | || synthetic == valobj_sp) /* synthetic is the same as the original object */ |
| 1000 | { |
| 1001 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 1002 | error.SetErrorStringWithFormat ("\"(%s) %s\" is not an array type", |
| 1003 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1004 | var_expr_path_strm.GetString().c_str()); |
| 1005 | } |
Saleem Abdulrasool | 3985c8c | 2014-04-02 03:51:35 +0000 | [diff] [blame] | 1006 | else if (static_cast<uint32_t>(child_index) >= synthetic->GetNumChildren() /* synthetic does not have that many values */) |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 1007 | { |
| 1008 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 1009 | error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 1010 | child_index, |
| 1011 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1012 | var_expr_path_strm.GetString().c_str()); |
| 1013 | } |
| 1014 | else |
| 1015 | { |
| 1016 | child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); |
| 1017 | if (!child_valobj_sp) |
| 1018 | { |
| 1019 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 1020 | error.SetErrorStringWithFormat ("array index %ld is not valid for \"(%s) %s\"", |
Enrico Granata | 27b625e | 2011-08-09 01:04:56 +0000 | [diff] [blame] | 1021 | child_index, |
| 1022 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1023 | var_expr_path_strm.GetString().c_str()); |
| 1024 | } |
| 1025 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | if (!child_valobj_sp) |
| 1029 | { |
| 1030 | // Invalid array index... |
| 1031 | return ValueObjectSP(); |
| 1032 | } |
| 1033 | |
| 1034 | // Erase the array member specification '[%i]' where |
| 1035 | // %i is the array index |
| 1036 | var_path.erase(0, (end - var_path.c_str()) + 1); |
| 1037 | separator_idx = var_path.find_first_of(".-["); |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1038 | if (use_dynamic != eNoDynamicValues) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1039 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1040 | ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1041 | if (dynamic_value_sp) |
| 1042 | child_valobj_sp = dynamic_value_sp; |
| 1043 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1044 | // Break out early from the switch since we were |
| 1045 | // able to find the child member |
| 1046 | break; |
| 1047 | } |
Enrico Granata | 20edcdb | 2011-07-19 18:03:25 +0000 | [diff] [blame] | 1048 | else if (end && *end == '-') |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1049 | { |
| 1050 | // this is most probably a BitField, let's take a look |
| 1051 | char *real_end = NULL; |
| 1052 | long final_index = ::strtol (end+1, &real_end, 0); |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1053 | bool expand_bitfield = true; |
Enrico Granata | 20edcdb | 2011-07-19 18:03:25 +0000 | [diff] [blame] | 1054 | if (real_end && *real_end == ']') |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1055 | { |
| 1056 | // if the format given is [high-low], swap range |
Enrico Granata | 20edcdb | 2011-07-19 18:03:25 +0000 | [diff] [blame] | 1057 | if (child_index > final_index) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1058 | { |
| 1059 | long temp = child_index; |
| 1060 | child_index = final_index; |
| 1061 | final_index = temp; |
| 1062 | } |
| 1063 | |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1064 | if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1065 | { |
| 1066 | // what we have is *ptr[low-high]. the most similar C++ syntax is to deref ptr |
| 1067 | // and extract bits low thru high out of it. reading array items low thru high |
| 1068 | // would be done by saying ptr[low-high], without a deref * sign |
| 1069 | Error error; |
| 1070 | ValueObjectSP temp(valobj_sp->Dereference(error)); |
| 1071 | if (error.Fail()) |
| 1072 | { |
| 1073 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 1074 | error.SetErrorStringWithFormat ("could not dereference \"(%s) %s\"", |
| 1075 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1076 | var_expr_path_strm.GetString().c_str()); |
| 1077 | return ValueObjectSP(); |
| 1078 | } |
| 1079 | valobj_sp = temp; |
| 1080 | deref = false; |
| 1081 | } |
Greg Clayton | 99558cc4 | 2015-08-24 23:46:31 +0000 | [diff] [blame] | 1082 | else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1083 | { |
| 1084 | // what we have is *arr[low-high]. the most similar C++ syntax is to get arr[0] |
| 1085 | // (an operation that is equivalent to deref-ing arr) |
| 1086 | // and extract bits low thru high out of it. reading array items low thru high |
| 1087 | // would be done by saying arr[low-high], without a deref * sign |
| 1088 | Error error; |
| 1089 | ValueObjectSP temp(valobj_sp->GetChildAtIndex (0, true)); |
| 1090 | if (error.Fail()) |
| 1091 | { |
| 1092 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 1093 | error.SetErrorStringWithFormat ("could not get item 0 for \"(%s) %s\"", |
| 1094 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1095 | var_expr_path_strm.GetString().c_str()); |
| 1096 | return ValueObjectSP(); |
| 1097 | } |
| 1098 | valobj_sp = temp; |
| 1099 | deref = false; |
| 1100 | } |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1101 | /*else if (valobj_sp->IsArrayType() || valobj_sp->IsPointerType()) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1102 | { |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1103 | child_valobj_sp = valobj_sp->GetSyntheticArrayRangeChild(child_index, final_index, true); |
| 1104 | expand_bitfield = false; |
| 1105 | if (!child_valobj_sp) |
| 1106 | { |
| 1107 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
| 1108 | error.SetErrorStringWithFormat ("array range %i-%i is not valid for \"(%s) %s\"", |
| 1109 | child_index, final_index, |
| 1110 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1111 | var_expr_path_strm.GetString().c_str()); |
| 1112 | } |
| 1113 | }*/ |
| 1114 | |
| 1115 | if (expand_bitfield) |
| 1116 | { |
| 1117 | child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true); |
| 1118 | if (!child_valobj_sp) |
| 1119 | { |
| 1120 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Jason Molenda | 7e589a6 | 2011-09-20 00:26:08 +0000 | [diff] [blame] | 1121 | error.SetErrorStringWithFormat ("bitfield range %ld-%ld is not valid for \"(%s) %s\"", |
Enrico Granata | d64d0bc | 2011-08-19 21:13:46 +0000 | [diff] [blame] | 1122 | child_index, final_index, |
| 1123 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1124 | var_expr_path_strm.GetString().c_str()); |
| 1125 | } |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1126 | } |
| 1127 | } |
| 1128 | |
| 1129 | if (!child_valobj_sp) |
| 1130 | { |
| 1131 | // Invalid bitfield range... |
| 1132 | return ValueObjectSP(); |
| 1133 | } |
| 1134 | |
| 1135 | // Erase the bitfield member specification '[%i-%i]' where |
| 1136 | // %i is the index |
| 1137 | var_path.erase(0, (real_end - var_path.c_str()) + 1); |
| 1138 | separator_idx = var_path.find_first_of(".-["); |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1139 | if (use_dynamic != eNoDynamicValues) |
Enrico Granata | 9fc1944 | 2011-07-06 02:13:41 +0000 | [diff] [blame] | 1140 | { |
| 1141 | ValueObjectSP dynamic_value_sp(child_valobj_sp->GetDynamicValue(use_dynamic)); |
| 1142 | if (dynamic_value_sp) |
| 1143 | child_valobj_sp = dynamic_value_sp; |
| 1144 | } |
| 1145 | // Break out early from the switch since we were |
| 1146 | // able to find the child member |
| 1147 | break; |
| 1148 | |
| 1149 | } |
| 1150 | } |
| 1151 | else |
| 1152 | { |
| 1153 | error.SetErrorStringWithFormat("invalid square bracket encountered after \"%s\" in \"%s\"", |
| 1154 | var_expr_path_strm.GetString().c_str(), |
| 1155 | var_path.c_str()); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1156 | } |
| 1157 | return ValueObjectSP(); |
| 1158 | |
| 1159 | default: |
| 1160 | // Failure... |
| 1161 | { |
Greg Clayton | 6beaaa6 | 2011-01-17 03:46:26 +0000 | [diff] [blame] | 1162 | valobj_sp->GetExpressionPath (var_expr_path_strm, false); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1163 | error.SetErrorStringWithFormat ("unexpected char '%c' encountered after \"%s\" in \"%s\"", |
| 1164 | separator_type, |
| 1165 | var_expr_path_strm.GetString().c_str(), |
| 1166 | var_path.c_str()); |
| 1167 | |
| 1168 | return ValueObjectSP(); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1169 | } |
| 1170 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1171 | |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1172 | if (child_valobj_sp) |
| 1173 | valobj_sp = child_valobj_sp; |
| 1174 | |
| 1175 | if (var_path.empty()) |
| 1176 | break; |
| 1177 | |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1178 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1179 | if (valobj_sp) |
| 1180 | { |
| 1181 | if (deref) |
| 1182 | { |
Greg Clayton | af67cec | 2010-12-20 20:49:23 +0000 | [diff] [blame] | 1183 | ValueObjectSP deref_valobj_sp (valobj_sp->Dereference(error)); |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1184 | valobj_sp = deref_valobj_sp; |
| 1185 | } |
| 1186 | else if (address_of) |
| 1187 | { |
| 1188 | ValueObjectSP address_of_valobj_sp (valobj_sp->AddressOf(error)); |
| 1189 | valobj_sp = address_of_valobj_sp; |
| 1190 | } |
| 1191 | } |
| 1192 | return valobj_sp; |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1193 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1194 | else |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1195 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1196 | error.SetErrorStringWithFormat("no variable named '%s' found in this frame", |
| 1197 | name_const_string.GetCString()); |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1198 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1199 | } |
| 1200 | } |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 1201 | else |
| 1202 | { |
| 1203 | error.SetErrorStringWithFormat("invalid variable path '%s'", var_expr_cstr); |
| 1204 | } |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 1205 | return ValueObjectSP(); |
| 1206 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1207 | |
| 1208 | bool |
| 1209 | StackFrame::GetFrameBaseValue (Scalar &frame_base, Error *error_ptr) |
| 1210 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 1211 | Mutex::Locker locker(m_mutex); |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 1212 | if (m_cfa_is_valid == false) |
| 1213 | { |
| 1214 | m_frame_base_error.SetErrorString("No frame base available for this historical stack frame."); |
| 1215 | return false; |
| 1216 | } |
| 1217 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1218 | if (m_flags.IsClear(GOT_FRAME_BASE)) |
| 1219 | { |
| 1220 | if (m_sc.function) |
| 1221 | { |
| 1222 | m_frame_base.Clear(); |
| 1223 | m_frame_base_error.Clear(); |
| 1224 | |
| 1225 | m_flags.Set(GOT_FRAME_BASE); |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1226 | ExecutionContext exe_ctx (shared_from_this()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1227 | Value expr_value; |
Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1228 | addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; |
| 1229 | if (m_sc.function->GetFrameBaseExpression().IsLocationList()) |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1230 | loclist_base_addr = m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress (exe_ctx.GetTargetPtr()); |
Greg Clayton | 016a95e | 2010-09-14 02:20:48 +0000 | [diff] [blame] | 1231 | |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1232 | if (m_sc.function->GetFrameBaseExpression().Evaluate(&exe_ctx, NULL, NULL, NULL, loclist_base_addr, NULL, expr_value, &m_frame_base_error) == false) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1233 | { |
| 1234 | // We should really have an error if evaluate returns, but in case |
| 1235 | // we don't, lets set the error to something at least. |
| 1236 | if (m_frame_base_error.Success()) |
| 1237 | m_frame_base_error.SetErrorString("Evaluation of the frame base expression failed."); |
| 1238 | } |
| 1239 | else |
| 1240 | { |
Greg Clayton | 57ee306 | 2013-07-11 22:46:58 +0000 | [diff] [blame] | 1241 | m_frame_base = expr_value.ResolveValue(&exe_ctx); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1242 | } |
| 1243 | } |
| 1244 | else |
| 1245 | { |
| 1246 | m_frame_base_error.SetErrorString ("No function in symbol context."); |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | if (m_frame_base_error.Success()) |
| 1251 | frame_base = m_frame_base; |
| 1252 | |
| 1253 | if (error_ptr) |
| 1254 | *error_ptr = m_frame_base_error; |
| 1255 | return m_frame_base_error.Success(); |
| 1256 | } |
| 1257 | |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1258 | RegisterContextSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1259 | StackFrame::GetRegisterContext () |
| 1260 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 1261 | Mutex::Locker locker(m_mutex); |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1262 | if (!m_reg_context_sp) |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1263 | { |
| 1264 | ThreadSP thread_sp (GetThread()); |
| 1265 | if (thread_sp) |
| 1266 | m_reg_context_sp = thread_sp->CreateRegisterContextForFrame (this); |
| 1267 | } |
Greg Clayton | 5ccbd29 | 2011-01-06 22:15:06 +0000 | [diff] [blame] | 1268 | return m_reg_context_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | bool |
| 1272 | StackFrame::HasDebugInformation () |
| 1273 | { |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 1274 | GetSymbolContext (eSymbolContextLineEntry); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1275 | return m_sc.line_entry.IsValid(); |
| 1276 | } |
| 1277 | |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1278 | |
| 1279 | ValueObjectSP |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1280 | StackFrame::GetValueObjectForFrameVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1281 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 1282 | Mutex::Locker locker(m_mutex); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1283 | ValueObjectSP valobj_sp; |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 1284 | if (m_is_history_frame) |
| 1285 | { |
| 1286 | return valobj_sp; |
| 1287 | } |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1288 | VariableList *var_list = GetVariableList (true); |
| 1289 | if (var_list) |
| 1290 | { |
| 1291 | // Make sure the variable is a frame variable |
| 1292 | const uint32_t var_idx = var_list->FindIndexForVariable (variable_sp.get()); |
| 1293 | const uint32_t num_variables = var_list->GetSize(); |
| 1294 | if (var_idx < num_variables) |
| 1295 | { |
| 1296 | valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex (var_idx); |
| 1297 | if (valobj_sp.get() == NULL) |
| 1298 | { |
| 1299 | if (m_variable_list_value_objects.GetSize() < num_variables) |
| 1300 | m_variable_list_value_objects.Resize(num_variables); |
Jim Ingham | 58b59f9 | 2011-04-22 23:53:53 +0000 | [diff] [blame] | 1301 | valobj_sp = ValueObjectVariable::Create (this, variable_sp); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1302 | m_variable_list_value_objects.SetValueObjectAtIndex (var_idx, valobj_sp); |
| 1303 | } |
| 1304 | } |
| 1305 | } |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1306 | if (use_dynamic != eNoDynamicValues && valobj_sp) |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1307 | { |
Jim Ingham | 2837b76 | 2011-05-04 03:43:18 +0000 | [diff] [blame] | 1308 | ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue (use_dynamic); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1309 | if (dynamic_sp) |
| 1310 | return dynamic_sp; |
| 1311 | } |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1312 | return valobj_sp; |
| 1313 | } |
| 1314 | |
| 1315 | ValueObjectSP |
Greg Clayton | 4d122c4 | 2011-09-17 08:33:22 +0000 | [diff] [blame] | 1316 | StackFrame::TrackGlobalVariable (const VariableSP &variable_sp, DynamicValueType use_dynamic) |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1317 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 1318 | Mutex::Locker locker(m_mutex); |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 1319 | if (m_is_history_frame) |
| 1320 | return ValueObjectSP(); |
| 1321 | |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1322 | // Check to make sure we aren't already tracking this variable? |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1323 | ValueObjectSP valobj_sp (GetValueObjectForFrameVariable (variable_sp, use_dynamic)); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1324 | if (!valobj_sp) |
| 1325 | { |
| 1326 | // We aren't already tracking this global |
| 1327 | VariableList *var_list = GetVariableList (true); |
| 1328 | // If this frame has no variables, create a new list |
| 1329 | if (var_list == NULL) |
| 1330 | m_variable_list_sp.reset (new VariableList()); |
| 1331 | |
| 1332 | // Add the global/static variable to this frame |
| 1333 | m_variable_list_sp->AddVariable (variable_sp); |
| 1334 | |
| 1335 | // Now make a value object for it so we can track its changes |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1336 | valobj_sp = GetValueObjectForFrameVariable (variable_sp, use_dynamic); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1337 | } |
| 1338 | return valobj_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Jim Ingham | 6b8379c | 2010-08-26 20:44:45 +0000 | [diff] [blame] | 1341 | bool |
| 1342 | StackFrame::IsInlined () |
| 1343 | { |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1344 | if (m_sc.block == NULL) |
| 1345 | GetSymbolContext (eSymbolContextBlock); |
| 1346 | if (m_sc.block) |
| 1347 | return m_sc.block->GetContainingInlinedBlock() != NULL; |
| 1348 | return false; |
Jim Ingham | 6b8379c | 2010-08-26 20:44:45 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
Dawn Perchik | 009d110 | 2015-09-04 01:02:30 +0000 | [diff] [blame] | 1351 | lldb::LanguageType |
| 1352 | StackFrame::GetLanguage () |
| 1353 | { |
| 1354 | CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit; |
| 1355 | if (cu) |
| 1356 | return cu->GetLanguage(); |
| 1357 | return lldb::eLanguageTypeUnknown; |
| 1358 | } |
| 1359 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1360 | TargetSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1361 | StackFrame::CalculateTarget () |
| 1362 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1363 | TargetSP target_sp; |
| 1364 | ThreadSP thread_sp(GetThread()); |
| 1365 | if (thread_sp) |
| 1366 | { |
| 1367 | ProcessSP process_sp (thread_sp->CalculateProcess()); |
| 1368 | if (process_sp) |
| 1369 | target_sp = process_sp->CalculateTarget(); |
| 1370 | } |
| 1371 | return target_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1374 | ProcessSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1375 | StackFrame::CalculateProcess () |
| 1376 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1377 | ProcessSP process_sp; |
| 1378 | ThreadSP thread_sp(GetThread()); |
| 1379 | if (thread_sp) |
| 1380 | process_sp = thread_sp->CalculateProcess(); |
| 1381 | return process_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1382 | } |
| 1383 | |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1384 | ThreadSP |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1385 | StackFrame::CalculateThread () |
| 1386 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1387 | return GetThread(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1388 | } |
| 1389 | |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1390 | StackFrameSP |
| 1391 | StackFrame::CalculateStackFrame () |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1392 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1393 | return shared_from_this(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | |
| 1397 | void |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1398 | StackFrame::CalculateExecutionContext (ExecutionContext &exe_ctx) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1399 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1400 | exe_ctx.SetContext (shared_from_this()); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | void |
Jim Ingham | 8ec10ef | 2013-10-18 17:38:31 +0000 | [diff] [blame] | 1404 | StackFrame::DumpUsingSettingsFormat (Stream *strm, const char *frame_marker) |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1405 | { |
| 1406 | if (strm == NULL) |
| 1407 | return; |
| 1408 | |
| 1409 | GetSymbolContext(eSymbolContextEverything); |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1410 | ExecutionContext exe_ctx (shared_from_this()); |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1411 | StreamString s; |
Jim Ingham | 8ec10ef | 2013-10-18 17:38:31 +0000 | [diff] [blame] | 1412 | |
| 1413 | if (frame_marker) |
| 1414 | s.PutCString(frame_marker); |
| 1415 | |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 1416 | const FormatEntity::Entry *frame_format = NULL; |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1417 | Target *target = exe_ctx.GetTargetPtr(); |
| 1418 | if (target) |
| 1419 | frame_format = target->GetDebugger().GetFrameFormat(); |
Greg Clayton | 554f68d | 2015-02-04 22:00:53 +0000 | [diff] [blame] | 1420 | if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, NULL, NULL, false, false)) |
Greg Clayton | 0603aa9 | 2010-10-04 01:05:56 +0000 | [diff] [blame] | 1421 | { |
| 1422 | strm->Write(s.GetData(), s.GetSize()); |
| 1423 | } |
| 1424 | else |
| 1425 | { |
| 1426 | Dump (strm, true, false); |
| 1427 | strm->EOL(); |
| 1428 | } |
| 1429 | } |
| 1430 | |
| 1431 | void |
Greg Clayton | 6dadd50 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 1432 | StackFrame::Dump (Stream *strm, bool show_frame_index, bool show_fullpaths) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1433 | { |
| 1434 | if (strm == NULL) |
| 1435 | return; |
| 1436 | |
| 1437 | if (show_frame_index) |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 1438 | strm->Printf("frame #%u: ", m_frame_index); |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1439 | ExecutionContext exe_ctx (shared_from_this()); |
| 1440 | Target *target = exe_ctx.GetTargetPtr(); |
Daniel Malea | d01b295 | 2012-11-29 21:49:15 +0000 | [diff] [blame] | 1441 | strm->Printf("0x%0*" PRIx64 " ", |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1442 | target ? (target->GetArchitecture().GetAddressByteSize() * 2) : 16, |
| 1443 | GetFrameCodeAddress().GetLoadAddress(target)); |
Greg Clayton | 9da7bd0 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 1444 | GetSymbolContext(eSymbolContextEverything); |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 1445 | const bool show_module = true; |
| 1446 | const bool show_inline = true; |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1447 | const bool show_function_arguments = true; |
Jason Molenda | c980fa9 | 2015-02-13 23:24:21 +0000 | [diff] [blame] | 1448 | const bool show_function_name = true; |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1449 | m_sc.DumpStopContext (strm, |
| 1450 | exe_ctx.GetBestExecutionContextScope(), |
| 1451 | GetFrameCodeAddress(), |
| 1452 | show_fullpaths, |
| 1453 | show_module, |
Jason Molenda | aff1b35 | 2014-10-10 23:07:36 +0000 | [diff] [blame] | 1454 | show_inline, |
Jason Molenda | c980fa9 | 2015-02-13 23:24:21 +0000 | [diff] [blame] | 1455 | show_function_arguments, |
| 1456 | show_function_name); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
Greg Clayton | 5082c5f | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 1459 | void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1460 | StackFrame::UpdateCurrentFrameFromPreviousFrame (StackFrame &prev_frame) |
Greg Clayton | 5082c5f | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 1461 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 1462 | Mutex::Locker locker(m_mutex); |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1463 | assert (GetStackID() == prev_frame.GetStackID()); // TODO: remove this after some testing |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1464 | m_variable_list_sp = prev_frame.m_variable_list_sp; |
| 1465 | m_variable_list_value_objects.Swap (prev_frame.m_variable_list_value_objects); |
| 1466 | if (!m_disassembly.GetString().empty()) |
| 1467 | m_disassembly.GetString().swap (m_disassembly.GetString()); |
Greg Clayton | 5082c5f | 2010-08-27 18:24:16 +0000 | [diff] [blame] | 1468 | } |
Greg Clayton | 68275d5 | 2010-08-27 21:47:54 +0000 | [diff] [blame] | 1469 | |
| 1470 | |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1471 | void |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1472 | StackFrame::UpdatePreviousFrameFromCurrentFrame (StackFrame &curr_frame) |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1473 | { |
Jason Molenda | 6a35470 | 2014-10-02 01:08:16 +0000 | [diff] [blame] | 1474 | Mutex::Locker locker(m_mutex); |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 1475 | assert (GetStackID() == curr_frame.GetStackID()); // TODO: remove this after some testing |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1476 | m_id.SetPC (curr_frame.m_id.GetPC()); // Update the Stack ID PC value |
| 1477 | assert (GetThread() == curr_frame.GetThread()); |
| 1478 | m_frame_index = curr_frame.m_frame_index; |
| 1479 | m_concrete_frame_index = curr_frame.m_concrete_frame_index; |
| 1480 | m_reg_context_sp = curr_frame.m_reg_context_sp; |
| 1481 | m_frame_code_addr = curr_frame.m_frame_code_addr; |
| 1482 | assert (m_sc.target_sp.get() == NULL || curr_frame.m_sc.target_sp.get() == NULL || m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get()); |
| 1483 | assert (m_sc.module_sp.get() == NULL || curr_frame.m_sc.module_sp.get() == NULL || m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get()); |
| 1484 | assert (m_sc.comp_unit == NULL || curr_frame.m_sc.comp_unit == NULL || m_sc.comp_unit == curr_frame.m_sc.comp_unit); |
| 1485 | assert (m_sc.function == NULL || curr_frame.m_sc.function == NULL || m_sc.function == curr_frame.m_sc.function); |
| 1486 | m_sc = curr_frame.m_sc; |
| 1487 | m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); |
| 1488 | m_flags.Set (m_sc.GetResolvedMask()); |
| 1489 | m_frame_base.Clear(); |
| 1490 | m_frame_base_error.Clear(); |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | |
Greg Clayton | 2cad65a | 2010-09-03 17:10:42 +0000 | [diff] [blame] | 1494 | bool |
Jason Molenda | b57e4a1 | 2013-11-04 09:33:30 +0000 | [diff] [blame] | 1495 | StackFrame::HasCachedData () const |
| 1496 | { |
| 1497 | if (m_variable_list_sp.get()) |
| 1498 | return true; |
| 1499 | if (m_variable_list_value_objects.GetSize() > 0) |
| 1500 | return true; |
| 1501 | if (!m_disassembly.GetString().empty()) |
| 1502 | return true; |
| 1503 | return false; |
| 1504 | } |
| 1505 | |
| 1506 | bool |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1507 | StackFrame::GetStatus (Stream& strm, |
| 1508 | bool show_frame_info, |
Jim Ingham | 8ec10ef | 2013-10-18 17:38:31 +0000 | [diff] [blame] | 1509 | bool show_source, |
| 1510 | const char *frame_marker) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1511 | { |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1512 | |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1513 | if (show_frame_info) |
| 1514 | { |
| 1515 | strm.Indent(); |
Jim Ingham | 8ec10ef | 2013-10-18 17:38:31 +0000 | [diff] [blame] | 1516 | DumpUsingSettingsFormat (&strm, frame_marker); |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | if (show_source) |
| 1520 | { |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1521 | ExecutionContext exe_ctx (shared_from_this()); |
Mohit K. Bhakkad | 8be7499 | 2015-12-03 04:56:16 +0000 | [diff] [blame] | 1522 | bool have_source = false, have_debuginfo = false; |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1523 | Debugger::StopDisassemblyType disasm_display = Debugger::eStopDisassemblyTypeNever; |
Greg Clayton | d9e416c | 2012-02-18 05:35:26 +0000 | [diff] [blame] | 1524 | Target *target = exe_ctx.GetTargetPtr(); |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1525 | if (target) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1526 | { |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1527 | Debugger &debugger = target->GetDebugger(); |
| 1528 | const uint32_t source_lines_before = debugger.GetStopSourceLineCount(true); |
| 1529 | const uint32_t source_lines_after = debugger.GetStopSourceLineCount(false); |
| 1530 | disasm_display = debugger.GetStopDisassemblyDisplay (); |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 1531 | |
Todd Fiala | 6d1fbc9 | 2014-07-07 20:47:24 +0000 | [diff] [blame] | 1532 | GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); |
| 1533 | if (m_sc.comp_unit && m_sc.line_entry.IsValid()) |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 1534 | { |
Mohit K. Bhakkad | 8be7499 | 2015-12-03 04:56:16 +0000 | [diff] [blame] | 1535 | have_debuginfo = true; |
Todd Fiala | 6d1fbc9 | 2014-07-07 20:47:24 +0000 | [diff] [blame] | 1536 | if (source_lines_before > 0 || source_lines_after > 0) |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 1537 | { |
Mohit K. Bhakkad | 8be7499 | 2015-12-03 04:56:16 +0000 | [diff] [blame] | 1538 | size_t num_lines = target->GetSourceManager().DisplaySourceLinesWithLineNumbers (m_sc.line_entry.file, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1539 | m_sc.line_entry.line, |
| 1540 | source_lines_before, |
| 1541 | source_lines_after, |
| 1542 | "->", |
Jason Molenda | 7cd81c5 | 2013-04-29 09:59:31 +0000 | [diff] [blame] | 1543 | &strm); |
Mohit K. Bhakkad | 8be7499 | 2015-12-03 04:56:16 +0000 | [diff] [blame] | 1544 | if (num_lines != 0) |
| 1545 | have_source = true; |
| 1546 | // TODO: Give here a one time warning if source file is missing. |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 1547 | } |
| 1548 | } |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1549 | switch (disasm_display) |
| 1550 | { |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1551 | case Debugger::eStopDisassemblyTypeNever: |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 1552 | break; |
Mohit K. Bhakkad | 8be7499 | 2015-12-03 04:56:16 +0000 | [diff] [blame] | 1553 | |
| 1554 | case Debugger::eStopDisassemblyTypeNoDebugInfo: |
| 1555 | if (have_debuginfo) |
| 1556 | break; |
Jason Molenda | 62e0681 | 2016-02-16 04:14:33 +0000 | [diff] [blame^] | 1557 | LLVM_FALLTHROUGH; |
Mohit K. Bhakkad | 8be7499 | 2015-12-03 04:56:16 +0000 | [diff] [blame] | 1558 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1559 | case Debugger::eStopDisassemblyTypeNoSource: |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1560 | if (have_source) |
| 1561 | break; |
Jason Molenda | 62e0681 | 2016-02-16 04:14:33 +0000 | [diff] [blame^] | 1562 | LLVM_FALLTHROUGH; |
Mohit K. Bhakkad | 8be7499 | 2015-12-03 04:56:16 +0000 | [diff] [blame] | 1563 | |
Greg Clayton | 67cc063 | 2012-08-22 17:17:09 +0000 | [diff] [blame] | 1564 | case Debugger::eStopDisassemblyTypeAlways: |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1565 | if (target) |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 1566 | { |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1567 | const uint32_t disasm_lines = debugger.GetDisassemblyLineCount(); |
| 1568 | if (disasm_lines > 0) |
| 1569 | { |
| 1570 | const ArchSpec &target_arch = target->GetArchitecture(); |
| 1571 | AddressRange pc_range; |
| 1572 | pc_range.GetBaseAddress() = GetFrameCodeAddress(); |
| 1573 | pc_range.SetByteSize(disasm_lines * target_arch.GetMaximumOpcodeByteSize()); |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 1574 | const char *plugin_name = NULL; |
| 1575 | const char *flavor = NULL; |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1576 | Disassembler::Disassemble (target->GetDebugger(), |
| 1577 | target_arch, |
Jim Ingham | 0f063ba | 2013-03-02 00:26:47 +0000 | [diff] [blame] | 1578 | plugin_name, |
| 1579 | flavor, |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1580 | exe_ctx, |
| 1581 | pc_range, |
| 1582 | disasm_lines, |
| 1583 | 0, |
| 1584 | Disassembler::eOptionMarkPCAddress, |
| 1585 | strm); |
| 1586 | } |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 1587 | } |
Greg Clayton | 53eb7ad | 2012-07-11 20:33:48 +0000 | [diff] [blame] | 1588 | break; |
Greg Clayton | e372b98 | 2011-11-21 21:44:34 +0000 | [diff] [blame] | 1589 | } |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1590 | } |
| 1591 | } |
| 1592 | return true; |
| 1593 | } |
| 1594 | |