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