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" |
Zachary Turner | 2f3df61 | 2017-04-06 21:28:29 +0000 | [diff] [blame] | 20 | #include "lldb/Core/RegisterValue.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | #include "lldb/Core/Value.h" |
Greg Clayton | 54979cd | 2010-12-15 05:08:08 +0000 | [diff] [blame] | 22 | #include "lldb/Core/ValueObjectConstResult.h" |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 23 | #include "lldb/Core/ValueObjectMemory.h" |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 24 | #include "lldb/Core/ValueObjectVariable.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 25 | #include "lldb/Symbol/CompileUnit.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 26 | #include "lldb/Symbol/Function.h" |
Greg Clayton | 1f74607 | 2012-08-29 21:13:06 +0000 | [diff] [blame] | 27 | #include "lldb/Symbol/Symbol.h" |
| 28 | #include "lldb/Symbol/SymbolContextScope.h" |
Enrico Granata | 4625239 | 2015-11-19 22:28:58 +0000 | [diff] [blame] | 29 | #include "lldb/Symbol/Type.h" |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 30 | #include "lldb/Symbol/VariableList.h" |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 31 | #include "lldb/Target/ABI.h" |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 32 | #include "lldb/Target/ExecutionContext.h" |
| 33 | #include "lldb/Target/Process.h" |
| 34 | #include "lldb/Target/RegisterContext.h" |
| 35 | #include "lldb/Target/Target.h" |
| 36 | #include "lldb/Target/Thread.h" |
| 37 | |
| 38 | using namespace lldb; |
| 39 | using namespace lldb_private; |
| 40 | |
| 41 | // The first bits in the flags are reserved for the SymbolContext::Scope bits |
| 42 | // so we know if we have tried to look up information in our internal symbol |
| 43 | // context (m_sc) already. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 44 | #define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1)) |
| 45 | #define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1) |
| 46 | #define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1) |
| 47 | #define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1) |
| 48 | #define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1) |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 49 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 50 | StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx, |
| 51 | user_id_t unwind_frame_index, addr_t cfa, |
| 52 | bool cfa_is_valid, addr_t pc, uint32_t stop_id, |
| 53 | bool stop_id_is_valid, bool is_history_frame, |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 54 | const SymbolContext *sc_ptr) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 55 | : m_thread_wp(thread_sp), m_frame_index(frame_idx), |
| 56 | m_concrete_frame_index(unwind_frame_index), m_reg_context_sp(), |
| 57 | m_id(pc, cfa, nullptr), m_frame_code_addr(pc), m_sc(), m_flags(), |
| 58 | m_frame_base(), m_frame_base_error(), m_cfa_is_valid(cfa_is_valid), |
| 59 | m_stop_id(stop_id), m_stop_id_is_valid(stop_id_is_valid), |
| 60 | m_is_history_frame(is_history_frame), m_variable_list_sp(), |
| 61 | m_variable_list_value_objects(), m_disassembly(), m_mutex() { |
| 62 | // If we don't have a CFA value, use the frame index for our StackID so that |
| 63 | // recursive |
| 64 | // functions properly aren't confused with one another on a history stack. |
| 65 | if (m_is_history_frame && !m_cfa_is_valid) { |
| 66 | m_id.SetCFA(m_frame_index); |
| 67 | } |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 68 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 69 | if (sc_ptr != nullptr) { |
| 70 | m_sc = *sc_ptr; |
| 71 | m_flags.Set(m_sc.GetResolvedMask()); |
| 72 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 73 | } |
| 74 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 75 | StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx, |
| 76 | user_id_t unwind_frame_index, |
| 77 | const RegisterContextSP ®_context_sp, addr_t cfa, |
| 78 | addr_t pc, const SymbolContext *sc_ptr) |
| 79 | : m_thread_wp(thread_sp), m_frame_index(frame_idx), |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 80 | m_concrete_frame_index(unwind_frame_index), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 81 | m_reg_context_sp(reg_context_sp), m_id(pc, cfa, nullptr), |
| 82 | m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(), |
| 83 | m_frame_base_error(), m_cfa_is_valid(true), m_stop_id(0), |
| 84 | m_stop_id_is_valid(false), m_is_history_frame(false), |
| 85 | m_variable_list_sp(), m_variable_list_value_objects(), m_disassembly(), |
| 86 | m_mutex() { |
| 87 | if (sc_ptr != nullptr) { |
| 88 | m_sc = *sc_ptr; |
| 89 | m_flags.Set(m_sc.GetResolvedMask()); |
| 90 | } |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 91 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 92 | if (reg_context_sp && !m_sc.target_sp) { |
| 93 | m_sc.target_sp = reg_context_sp->CalculateTarget(); |
| 94 | if (m_sc.target_sp) |
| 95 | m_flags.Set(eSymbolContextTarget); |
| 96 | } |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 99 | StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx, |
| 100 | user_id_t unwind_frame_index, |
| 101 | const RegisterContextSP ®_context_sp, addr_t cfa, |
| 102 | const Address &pc_addr, const SymbolContext *sc_ptr) |
| 103 | : m_thread_wp(thread_sp), m_frame_index(frame_idx), |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 104 | m_concrete_frame_index(unwind_frame_index), |
| 105 | m_reg_context_sp(reg_context_sp), |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 106 | m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa, |
| 107 | nullptr), |
| 108 | m_frame_code_addr(pc_addr), m_sc(), m_flags(), m_frame_base(), |
| 109 | m_frame_base_error(), m_cfa_is_valid(true), m_stop_id(0), |
| 110 | m_stop_id_is_valid(false), m_is_history_frame(false), |
| 111 | m_variable_list_sp(), m_variable_list_value_objects(), m_disassembly(), |
| 112 | m_mutex() { |
| 113 | if (sc_ptr != nullptr) { |
| 114 | m_sc = *sc_ptr; |
| 115 | m_flags.Set(m_sc.GetResolvedMask()); |
| 116 | } |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 117 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 118 | if (!m_sc.target_sp && reg_context_sp) { |
| 119 | m_sc.target_sp = reg_context_sp->CalculateTarget(); |
| 120 | if (m_sc.target_sp) |
| 121 | m_flags.Set(eSymbolContextTarget); |
| 122 | } |
Saleem Abdulrasool | bb19a13 | 2016-05-19 05:13:57 +0000 | [diff] [blame] | 123 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 124 | ModuleSP pc_module_sp(pc_addr.GetModule()); |
| 125 | if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) { |
| 126 | if (pc_module_sp) { |
| 127 | m_sc.module_sp = pc_module_sp; |
| 128 | m_flags.Set(eSymbolContextModule); |
| 129 | } else { |
| 130 | m_sc.module_sp.reset(); |
Greg Clayton | 1b72fcb | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 131 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 132 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Eugene Zelenko | d70a6e7 | 2016-02-18 18:52:47 +0000 | [diff] [blame] | 135 | StackFrame::~StackFrame() = default; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 136 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 137 | StackID &StackFrame::GetStackID() { |
| 138 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 139 | // Make sure we have resolved the StackID object's symbol context scope if |
| 140 | // we already haven't looked it up. |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 141 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 142 | if (m_flags.IsClear(RESOLVED_FRAME_ID_SYMBOL_SCOPE)) { |
| 143 | if (m_id.GetSymbolContextScope()) { |
| 144 | // We already have a symbol context scope, we just don't have our |
| 145 | // flag bit set. |
| 146 | m_flags.Set(RESOLVED_FRAME_ID_SYMBOL_SCOPE); |
| 147 | } else { |
| 148 | // Calculate the frame block and use this for the stack ID symbol |
| 149 | // context scope if we have one. |
| 150 | SymbolContextScope *scope = GetFrameBlock(); |
| 151 | if (scope == nullptr) { |
| 152 | // We don't have a block, so use the symbol |
| 153 | if (m_flags.IsClear(eSymbolContextSymbol)) |
| 154 | GetSymbolContext(eSymbolContextSymbol); |
| 155 | |
| 156 | // It is ok if m_sc.symbol is nullptr here |
| 157 | scope = m_sc.symbol; |
| 158 | } |
| 159 | // Set the symbol context scope (the accessor will set the |
| 160 | // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags). |
| 161 | SetSymbolContextScope(scope); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 162 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 163 | } |
| 164 | return m_id; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | } |
| 166 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 167 | uint32_t StackFrame::GetFrameIndex() const { |
| 168 | ThreadSP thread_sp = GetThread(); |
| 169 | if (thread_sp) |
| 170 | return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex( |
| 171 | m_frame_index); |
| 172 | else |
| 173 | return m_frame_index; |
Jim Ingham | 513c6bb | 2012-09-01 01:02:41 +0000 | [diff] [blame] | 174 | } |
| 175 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 176 | void StackFrame::SetSymbolContextScope(SymbolContextScope *symbol_scope) { |
| 177 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 178 | m_flags.Set(RESOLVED_FRAME_ID_SYMBOL_SCOPE); |
| 179 | m_id.SetSymbolContextScope(symbol_scope); |
Greg Clayton | 59e8fc1c | 2010-08-30 18:11:35 +0000 | [diff] [blame] | 180 | } |
| 181 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 182 | const Address &StackFrame::GetFrameCodeAddress() { |
| 183 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 184 | if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) && |
| 185 | !m_frame_code_addr.IsSectionOffset()) { |
| 186 | m_flags.Set(RESOLVED_FRAME_CODE_ADDR); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 187 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 188 | // Resolve the PC into a temporary address because if ResolveLoadAddress |
| 189 | // fails to resolve the address, it will clear the address object... |
| 190 | ThreadSP thread_sp(GetThread()); |
| 191 | if (thread_sp) { |
| 192 | TargetSP target_sp(thread_sp->CalculateTarget()); |
| 193 | if (target_sp) { |
Pavel Labath | c3c7212 | 2017-06-08 13:26:35 +0000 | [diff] [blame^] | 194 | const bool allow_section_end = true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 195 | if (m_frame_code_addr.SetOpcodeLoadAddress( |
| 196 | m_frame_code_addr.GetOffset(), target_sp.get(), |
Pavel Labath | c3c7212 | 2017-06-08 13:26:35 +0000 | [diff] [blame^] | 197 | eAddressClassCode, allow_section_end)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 198 | ModuleSP module_sp(m_frame_code_addr.GetModule()); |
| 199 | if (module_sp) { |
| 200 | m_sc.module_sp = module_sp; |
| 201 | m_flags.Set(eSymbolContextModule); |
| 202 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 203 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 204 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 205 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 206 | } |
| 207 | return m_frame_code_addr; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 210 | bool StackFrame::ChangePC(addr_t pc) { |
| 211 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 212 | // We can't change the pc value of a history stack frame - it is immutable. |
| 213 | if (m_is_history_frame) |
| 214 | return false; |
| 215 | m_frame_code_addr.SetRawAddress(pc); |
| 216 | m_sc.Clear(false); |
| 217 | m_flags.Reset(0); |
| 218 | ThreadSP thread_sp(GetThread()); |
| 219 | if (thread_sp) |
| 220 | thread_sp->ClearStackFrames(); |
| 221 | return true; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 224 | const char *StackFrame::Disassemble() { |
| 225 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
Zachary Turner | 8b3f216 | 2017-02-28 17:59:59 +0000 | [diff] [blame] | 226 | if (m_disassembly.Empty()) { |
| 227 | ExecutionContext exe_ctx(shared_from_this()); |
| 228 | Target *target = exe_ctx.GetTargetPtr(); |
| 229 | if (target) { |
| 230 | const char *plugin_name = nullptr; |
| 231 | const char *flavor = nullptr; |
| 232 | Disassembler::Disassemble(target->GetDebugger(), |
| 233 | target->GetArchitecture(), plugin_name, flavor, |
| 234 | exe_ctx, 0, false, 0, 0, m_disassembly); |
| 235 | } |
| 236 | if (m_disassembly.Empty()) |
| 237 | return nullptr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 238 | } |
Zachary Turner | 8b3f216 | 2017-02-28 17:59:59 +0000 | [diff] [blame] | 239 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 240 | return m_disassembly.GetData(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 241 | } |
| 242 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 243 | Block *StackFrame::GetFrameBlock() { |
| 244 | if (m_sc.block == nullptr && m_flags.IsClear(eSymbolContextBlock)) |
| 245 | GetSymbolContext(eSymbolContextBlock); |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 246 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 247 | if (m_sc.block) { |
| 248 | Block *inline_block = m_sc.block->GetContainingInlinedBlock(); |
| 249 | if (inline_block) { |
| 250 | // Use the block with the inlined function info |
| 251 | // as the frame block we want this frame to have only the variables |
| 252 | // for the inlined function and its non-inlined block child blocks. |
| 253 | return inline_block; |
| 254 | } else { |
| 255 | // This block is not contained within any inlined function blocks |
| 256 | // with so we want to use the top most function block. |
| 257 | return &m_sc.function->GetBlock(false); |
| 258 | } |
| 259 | } |
| 260 | return nullptr; |
Greg Clayton | 95897c6 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 263 | //---------------------------------------------------------------------- |
| 264 | // Get the symbol context if we already haven't done so by resolving the |
| 265 | // PC address as much as possible. This way when we pass around a |
| 266 | // StackFrame object, everyone will have as much information as |
| 267 | // possible and no one will ever have to look things up manually. |
| 268 | //---------------------------------------------------------------------- |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 269 | const SymbolContext &StackFrame::GetSymbolContext(uint32_t resolve_scope) { |
| 270 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 271 | // Copy our internal symbol context into "sc". |
| 272 | if ((m_flags.Get() & resolve_scope) != resolve_scope) { |
| 273 | uint32_t resolved = 0; |
Greg Clayton | 75a0333 | 2012-11-29 00:53:06 +0000 | [diff] [blame] | 274 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 275 | // If the target was requested add that: |
| 276 | if (!m_sc.target_sp) { |
| 277 | m_sc.target_sp = CalculateTarget(); |
| 278 | if (m_sc.target_sp) |
| 279 | resolved |= eSymbolContextTarget; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 282 | // Resolve our PC to section offset if we haven't already done so |
| 283 | // and if we don't have a module. The resolved address section will |
| 284 | // contain the module to which it belongs |
| 285 | if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR)) |
| 286 | GetFrameCodeAddress(); |
| 287 | |
| 288 | // If this is not frame zero, then we need to subtract 1 from the PC |
| 289 | // value when doing address lookups since the PC will be on the |
| 290 | // instruction following the function call instruction... |
| 291 | |
| 292 | Address lookup_addr(GetFrameCodeAddress()); |
| 293 | if (m_frame_index > 0 && lookup_addr.IsValid()) { |
| 294 | addr_t offset = lookup_addr.GetOffset(); |
| 295 | if (offset > 0) { |
| 296 | lookup_addr.SetOffset(offset - 1); |
| 297 | |
| 298 | } else { |
| 299 | // lookup_addr is the start of a section. We need |
| 300 | // do the math on the actual load address and re-compute |
| 301 | // the section. We're working with a 'noreturn' function |
| 302 | // at the end of a section. |
| 303 | ThreadSP thread_sp(GetThread()); |
| 304 | if (thread_sp) { |
| 305 | TargetSP target_sp(thread_sp->CalculateTarget()); |
| 306 | if (target_sp) { |
| 307 | addr_t addr_minus_one = |
| 308 | lookup_addr.GetLoadAddress(target_sp.get()) - 1; |
| 309 | lookup_addr.SetLoadAddress(addr_minus_one, target_sp.get()); |
| 310 | } else { |
| 311 | lookup_addr.SetOffset(offset - 1); |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | if (m_sc.module_sp) { |
| 318 | // We have something in our stack frame symbol context, lets check |
| 319 | // if we haven't already tried to lookup one of those things. If we |
| 320 | // haven't then we will do the query. |
| 321 | |
| 322 | uint32_t actual_resolve_scope = 0; |
| 323 | |
| 324 | if (resolve_scope & eSymbolContextCompUnit) { |
| 325 | if (m_flags.IsClear(eSymbolContextCompUnit)) { |
| 326 | if (m_sc.comp_unit) |
| 327 | resolved |= eSymbolContextCompUnit; |
| 328 | else |
| 329 | actual_resolve_scope |= eSymbolContextCompUnit; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | if (resolve_scope & eSymbolContextFunction) { |
| 334 | if (m_flags.IsClear(eSymbolContextFunction)) { |
| 335 | if (m_sc.function) |
| 336 | resolved |= eSymbolContextFunction; |
| 337 | else |
| 338 | actual_resolve_scope |= eSymbolContextFunction; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if (resolve_scope & eSymbolContextBlock) { |
| 343 | if (m_flags.IsClear(eSymbolContextBlock)) { |
| 344 | if (m_sc.block) |
| 345 | resolved |= eSymbolContextBlock; |
| 346 | else |
| 347 | actual_resolve_scope |= eSymbolContextBlock; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if (resolve_scope & eSymbolContextSymbol) { |
| 352 | if (m_flags.IsClear(eSymbolContextSymbol)) { |
| 353 | if (m_sc.symbol) |
| 354 | resolved |= eSymbolContextSymbol; |
| 355 | else |
| 356 | actual_resolve_scope |= eSymbolContextSymbol; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | if (resolve_scope & eSymbolContextLineEntry) { |
| 361 | if (m_flags.IsClear(eSymbolContextLineEntry)) { |
| 362 | if (m_sc.line_entry.IsValid()) |
| 363 | resolved |= eSymbolContextLineEntry; |
| 364 | else |
| 365 | actual_resolve_scope |= eSymbolContextLineEntry; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | if (actual_resolve_scope) { |
| 370 | // We might be resolving less information than what is already |
| 371 | // in our current symbol context so resolve into a temporary |
| 372 | // symbol context "sc" so we don't clear out data we have |
| 373 | // already found in "m_sc" |
| 374 | SymbolContext sc; |
| 375 | // Set flags that indicate what we have tried to resolve |
| 376 | resolved |= m_sc.module_sp->ResolveSymbolContextForAddress( |
| 377 | lookup_addr, actual_resolve_scope, sc); |
| 378 | // Only replace what we didn't already have as we may have |
| 379 | // information for an inlined function scope that won't match |
| 380 | // what a standard lookup by address would match |
| 381 | if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == nullptr) |
| 382 | m_sc.comp_unit = sc.comp_unit; |
| 383 | if ((resolved & eSymbolContextFunction) && m_sc.function == nullptr) |
| 384 | m_sc.function = sc.function; |
| 385 | if ((resolved & eSymbolContextBlock) && m_sc.block == nullptr) |
| 386 | m_sc.block = sc.block; |
| 387 | if ((resolved & eSymbolContextSymbol) && m_sc.symbol == nullptr) |
| 388 | m_sc.symbol = sc.symbol; |
| 389 | if ((resolved & eSymbolContextLineEntry) && |
| 390 | !m_sc.line_entry.IsValid()) { |
| 391 | m_sc.line_entry = sc.line_entry; |
| 392 | m_sc.line_entry.ApplyFileMappings(m_sc.target_sp); |
| 393 | } |
| 394 | } |
| 395 | } else { |
| 396 | // If we don't have a module, then we can't have the compile unit, |
| 397 | // function, block, line entry or symbol, so we can safely call |
| 398 | // ResolveSymbolContextForAddress with our symbol context member m_sc. |
| 399 | if (m_sc.target_sp) { |
| 400 | resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress( |
| 401 | lookup_addr, resolve_scope, m_sc); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | // Update our internal flags so we remember what we have tried to locate so |
| 406 | // we don't have to keep trying when more calls to this function are made. |
| 407 | // We might have dug up more information that was requested (for example |
| 408 | // if we were asked to only get the block, we will have gotten the |
| 409 | // compile unit, and function) so set any additional bits that we resolved |
| 410 | m_flags.Set(resolve_scope | resolved); |
| 411 | } |
| 412 | |
| 413 | // Return the symbol context with everything that was possible to resolve |
| 414 | // resolved. |
| 415 | return m_sc; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 416 | } |
| 417 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 418 | VariableList *StackFrame::GetVariableList(bool get_file_globals) { |
| 419 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 420 | if (m_flags.IsClear(RESOLVED_VARIABLES)) { |
| 421 | m_flags.Set(RESOLVED_VARIABLES); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 422 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 423 | Block *frame_block = GetFrameBlock(); |
| 424 | |
| 425 | if (frame_block) { |
| 426 | const bool get_child_variables = true; |
| 427 | const bool can_create = true; |
| 428 | const bool stop_if_child_block_is_inlined_function = true; |
| 429 | m_variable_list_sp.reset(new VariableList()); |
| 430 | frame_block->AppendBlockVariables(can_create, get_child_variables, |
| 431 | stop_if_child_block_is_inlined_function, |
Zachary Turner | 3bc714b | 2017-03-02 00:05:25 +0000 | [diff] [blame] | 432 | [](Variable *v) { return true; }, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 433 | m_variable_list_sp.get()); |
Sean Callanan | 7c0962d | 2010-11-01 04:38:59 +0000 | [diff] [blame] | 434 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && get_file_globals) { |
| 438 | m_flags.Set(RESOLVED_GLOBAL_VARIABLES); |
| 439 | |
| 440 | if (m_flags.IsClear(eSymbolContextCompUnit)) |
| 441 | GetSymbolContext(eSymbolContextCompUnit); |
| 442 | |
| 443 | if (m_sc.comp_unit) { |
| 444 | VariableListSP global_variable_list_sp( |
| 445 | m_sc.comp_unit->GetVariableList(true)); |
| 446 | if (m_variable_list_sp) |
| 447 | m_variable_list_sp->AddVariables(global_variable_list_sp.get()); |
| 448 | else |
| 449 | m_variable_list_sp = global_variable_list_sp; |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 450 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | return m_variable_list_sp.get(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Greg Clayton | d41f032 | 2011-08-02 23:35:43 +0000 | [diff] [blame] | 456 | VariableListSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 457 | StackFrame::GetInScopeVariableList(bool get_file_globals, |
| 458 | bool must_have_valid_location) { |
| 459 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 460 | // We can't fetch variable information for a history stack frame. |
| 461 | if (m_is_history_frame) |
| 462 | return VariableListSP(); |
Jason Molenda | 9961847 | 2013-11-04 11:02:52 +0000 | [diff] [blame] | 463 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 464 | VariableListSP var_list_sp(new VariableList); |
| 465 | GetSymbolContext(eSymbolContextCompUnit | eSymbolContextBlock); |
Greg Clayton | d41f032 | 2011-08-02 23:35:43 +0000 | [diff] [blame] | 466 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 467 | if (m_sc.block) { |
| 468 | const bool can_create = true; |
| 469 | const bool get_parent_variables = true; |
| 470 | const bool stop_if_block_is_inlined_function = true; |
| 471 | m_sc.block->AppendVariables( |
| 472 | can_create, get_parent_variables, stop_if_block_is_inlined_function, |
| 473 | [this, must_have_valid_location](Variable *v) { |
| 474 | return v->IsInScope(this) && (!must_have_valid_location || |
| 475 | v->LocationIsValidForFrame(this)); |
| 476 | }, |
| 477 | var_list_sp.get()); |
| 478 | } |
| 479 | |
| 480 | if (m_sc.comp_unit && get_file_globals) { |
| 481 | VariableListSP global_variable_list_sp( |
| 482 | m_sc.comp_unit->GetVariableList(true)); |
| 483 | if (global_variable_list_sp) |
| 484 | var_list_sp->AddVariables(global_variable_list_sp.get()); |
| 485 | } |
| 486 | |
| 487 | return var_list_sp; |
Greg Clayton | d41f032 | 2011-08-02 23:35:43 +0000 | [diff] [blame] | 488 | } |
| 489 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 490 | ValueObjectSP StackFrame::GetValueForVariableExpressionPath( |
Zachary Turner | 0eb31a1 | 2016-11-17 05:14:32 +0000 | [diff] [blame] | 491 | llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options, |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 492 | VariableSP &var_sp, Status &error) { |
Zachary Turner | 0eb31a1 | 2016-11-17 05:14:32 +0000 | [diff] [blame] | 493 | llvm::StringRef original_var_expr = var_expr; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 494 | // We can't fetch variable information for a history stack frame. |
| 495 | if (m_is_history_frame) |
Greg Clayton | 8b2fe6d | 2010-12-14 02:59:59 +0000 | [diff] [blame] | 496 | return ValueObjectSP(); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 497 | |
Zachary Turner | 0eb31a1 | 2016-11-17 05:14:32 +0000 | [diff] [blame] | 498 | if (var_expr.empty()) { |
| 499 | error.SetErrorStringWithFormat("invalid variable path '%s'", |
| 500 | var_expr.str().c_str()); |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 501 | return ValueObjectSP(); |
| 502 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 503 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 504 | const bool check_ptr_vs_member = |
| 505 | (options & eExpressionPathOptionCheckPtrVsMember) != 0; |
| 506 | const bool no_fragile_ivar = |
| 507 | (options & eExpressionPathOptionsNoFragileObjcIvar) != 0; |
| 508 | const bool no_synth_child = |
| 509 | (options & eExpressionPathOptionsNoSyntheticChildren) != 0; |
| 510 | // const bool no_synth_array = (options & |
| 511 | // eExpressionPathOptionsNoSyntheticArrayRange) != 0; |
| 512 | error.Clear(); |
| 513 | bool deref = false; |
| 514 | bool address_of = false; |
| 515 | ValueObjectSP valobj_sp; |
| 516 | const bool get_file_globals = true; |
| 517 | // When looking up a variable for an expression, we need only consider the |
| 518 | // variables that are in scope. |
| 519 | VariableListSP var_list_sp(GetInScopeVariableList(get_file_globals)); |
| 520 | VariableList *variable_list = var_list_sp.get(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 521 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 522 | if (!variable_list) |
| 523 | return ValueObjectSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 524 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 525 | // If first character is a '*', then show pointer contents |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 526 | std::string var_expr_storage; |
| 527 | if (var_expr[0] == '*') { |
| 528 | deref = true; |
| 529 | var_expr = var_expr.drop_front(); // Skip the '*' |
| 530 | } else if (var_expr[0] == '&') { |
| 531 | address_of = true; |
| 532 | var_expr = var_expr.drop_front(); // Skip the '&' |
| 533 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 534 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 535 | size_t separator_idx = var_expr.find_first_of(".-[=+~|&^%#@!/?,<>{}"); |
| 536 | StreamString var_expr_path_strm; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 537 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 538 | ConstString name_const_string(var_expr.substr(0, separator_idx)); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 539 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 540 | var_sp = variable_list->FindVariable(name_const_string, false); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 541 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 542 | bool synthetically_added_instance_object = false; |
| 543 | |
| 544 | if (var_sp) { |
| 545 | var_expr = var_expr.drop_front(name_const_string.GetLength()); |
| 546 | } |
| 547 | |
| 548 | if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) { |
| 549 | // Check for direct ivars access which helps us with implicit |
| 550 | // access to ivars with the "this->" or "self->" |
| 551 | GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock); |
| 552 | lldb::LanguageType method_language = eLanguageTypeUnknown; |
| 553 | bool is_instance_method = false; |
| 554 | ConstString method_object_name; |
| 555 | if (m_sc.GetFunctionMethodInfo(method_language, is_instance_method, |
| 556 | method_object_name)) { |
| 557 | if (is_instance_method && method_object_name) { |
| 558 | var_sp = variable_list->FindVariable(method_object_name); |
| 559 | if (var_sp) { |
| 560 | separator_idx = 0; |
| 561 | var_expr_storage = "->"; |
| 562 | var_expr_storage += var_expr; |
| 563 | var_expr = var_expr_storage; |
| 564 | synthetically_added_instance_object = true; |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 565 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 566 | } |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 567 | } |
| 568 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 569 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 570 | if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) { |
| 571 | // Check if any anonymous unions are there which contain a variable with |
| 572 | // the name we need |
| 573 | for (size_t i = 0; i < variable_list->GetSize(); i++) { |
| 574 | VariableSP variable_sp = variable_list->GetVariableAtIndex(i); |
| 575 | if (!variable_sp) |
| 576 | continue; |
| 577 | if (!variable_sp->GetName().IsEmpty()) |
| 578 | continue; |
| 579 | |
| 580 | Type *var_type = variable_sp->GetType(); |
| 581 | if (!var_type) |
| 582 | continue; |
| 583 | |
| 584 | if (!var_type->GetForwardCompilerType().IsAnonymousType()) |
| 585 | continue; |
| 586 | valobj_sp = GetValueObjectForFrameVariable(variable_sp, use_dynamic); |
| 587 | if (!valobj_sp) |
| 588 | return valobj_sp; |
| 589 | valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true); |
| 590 | if (valobj_sp) |
| 591 | break; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | if (var_sp && !valobj_sp) { |
| 596 | valobj_sp = GetValueObjectForFrameVariable(var_sp, use_dynamic); |
| 597 | if (!valobj_sp) |
| 598 | return valobj_sp; |
| 599 | } |
| 600 | if (!valobj_sp) { |
| 601 | error.SetErrorStringWithFormat("no variable named '%s' found in this frame", |
| 602 | name_const_string.GetCString()); |
| 603 | return ValueObjectSP(); |
| 604 | } |
| 605 | |
| 606 | // We are dumping at least one child |
| 607 | while (separator_idx != std::string::npos) { |
| 608 | // Calculate the next separator index ahead of time |
| 609 | ValueObjectSP child_valobj_sp; |
| 610 | const char separator_type = var_expr[0]; |
Tamas Berghammer | 4c08fe2 | 2017-03-31 20:23:22 +0000 | [diff] [blame] | 611 | bool expr_is_ptr = false; |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 612 | switch (separator_type) { |
| 613 | case '-': |
Tamas Berghammer | 4c08fe2 | 2017-03-31 20:23:22 +0000 | [diff] [blame] | 614 | expr_is_ptr = true; |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 615 | if (var_expr.size() >= 2 && var_expr[1] != '>') |
| 616 | return ValueObjectSP(); |
| 617 | |
| 618 | if (no_fragile_ivar) { |
| 619 | // Make sure we aren't trying to deref an objective |
| 620 | // C ivar if this is not allowed |
| 621 | const uint32_t pointer_type_flags = |
| 622 | valobj_sp->GetCompilerType().GetTypeInfo(nullptr); |
| 623 | if ((pointer_type_flags & eTypeIsObjC) && |
| 624 | (pointer_type_flags & eTypeIsPointer)) { |
| 625 | // This was an objective C object pointer and |
| 626 | // it was requested we skip any fragile ivars |
| 627 | // so return nothing here |
| 628 | return ValueObjectSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 629 | } |
| 630 | } |
Tamas Berghammer | 4c08fe2 | 2017-03-31 20:23:22 +0000 | [diff] [blame] | 631 | |
| 632 | // If we have a non pointer type with a sythetic value then lets check if |
| 633 | // we have an sythetic dereference specified. |
| 634 | if (!valobj_sp->IsPointerType() && valobj_sp->HasSyntheticValue()) { |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 635 | Status deref_error; |
Tamas Berghammer | 4c08fe2 | 2017-03-31 20:23:22 +0000 | [diff] [blame] | 636 | if (valobj_sp->GetCompilerType().IsReferenceType()) { |
| 637 | valobj_sp = valobj_sp->GetSyntheticValue()->Dereference(deref_error); |
| 638 | if (error.Fail()) { |
| 639 | error.SetErrorStringWithFormatv( |
| 640 | "Failed to dereference reference type: %s", deref_error); |
| 641 | return ValueObjectSP(); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | valobj_sp = valobj_sp->Dereference(deref_error); |
| 646 | if (error.Fail()) { |
| 647 | error.SetErrorStringWithFormatv( |
| 648 | "Failed to dereference sythetic value: %s", deref_error); |
| 649 | return ValueObjectSP(); |
| 650 | } |
| 651 | expr_is_ptr = false; |
| 652 | } |
| 653 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 654 | var_expr = var_expr.drop_front(); // Remove the '-' |
| 655 | LLVM_FALLTHROUGH; |
| 656 | case '.': { |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 657 | var_expr = var_expr.drop_front(); // Remove the '.' or '>' |
| 658 | separator_idx = var_expr.find_first_of(".-["); |
| 659 | ConstString child_name(var_expr.substr(0, var_expr.find_first_of(".-["))); |
| 660 | |
| 661 | if (check_ptr_vs_member) { |
| 662 | // We either have a pointer type and need to verify |
| 663 | // valobj_sp is a pointer, or we have a member of a |
| 664 | // class/union/struct being accessed with the . syntax |
| 665 | // and need to verify we don't have a pointer. |
| 666 | const bool actual_is_ptr = valobj_sp->IsPointerType(); |
| 667 | |
| 668 | if (actual_is_ptr != expr_is_ptr) { |
| 669 | // Incorrect use of "." with a pointer, or "->" with |
| 670 | // a class/union/struct instance or reference. |
| 671 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 672 | if (actual_is_ptr) |
| 673 | error.SetErrorStringWithFormat( |
| 674 | "\"%s\" is a pointer and . was used to attempt to access " |
| 675 | "\"%s\". Did you mean \"%s->%s\"?", |
| 676 | var_expr_path_strm.GetData(), child_name.GetCString(), |
| 677 | var_expr_path_strm.GetData(), var_expr.str().c_str()); |
| 678 | else |
| 679 | error.SetErrorStringWithFormat( |
| 680 | "\"%s\" is not a pointer and -> was used to attempt to " |
| 681 | "access \"%s\". Did you mean \"%s.%s\"?", |
| 682 | var_expr_path_strm.GetData(), child_name.GetCString(), |
| 683 | var_expr_path_strm.GetData(), var_expr.str().c_str()); |
| 684 | return ValueObjectSP(); |
| 685 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 686 | } |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 687 | child_valobj_sp = valobj_sp->GetChildMemberWithName(child_name, true); |
| 688 | if (!child_valobj_sp) { |
| 689 | if (!no_synth_child) { |
| 690 | child_valobj_sp = valobj_sp->GetSyntheticValue(); |
| 691 | if (child_valobj_sp) |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 692 | child_valobj_sp = |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 693 | child_valobj_sp->GetChildMemberWithName(child_name, true); |
| 694 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 695 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 696 | if (no_synth_child || !child_valobj_sp) { |
| 697 | // No child member with name "child_name" |
| 698 | if (synthetically_added_instance_object) { |
| 699 | // We added a "this->" or "self->" to the beginning of the |
| 700 | // expression |
| 701 | // and this is the first pointer ivar access, so just return |
| 702 | // the normal |
| 703 | // error |
| 704 | error.SetErrorStringWithFormat( |
| 705 | "no variable or instance variable named '%s' found in " |
| 706 | "this frame", |
| 707 | name_const_string.GetCString()); |
| 708 | } else { |
| 709 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 710 | if (child_name) { |
| 711 | error.SetErrorStringWithFormat( |
| 712 | "\"%s\" is not a member of \"(%s) %s\"", |
| 713 | child_name.GetCString(), |
| 714 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 715 | var_expr_path_strm.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 716 | } else { |
| 717 | error.SetErrorStringWithFormat( |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 718 | "incomplete expression path after \"%s\" in \"%s\"", |
Zachary Turner | 0eb31a1 | 2016-11-17 05:14:32 +0000 | [diff] [blame] | 719 | var_expr_path_strm.GetData(), |
| 720 | original_var_expr.str().c_str()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 721 | } |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 722 | } |
| 723 | return ValueObjectSP(); |
| 724 | } |
| 725 | } |
| 726 | synthetically_added_instance_object = false; |
| 727 | // Remove the child name from the path |
| 728 | var_expr = var_expr.drop_front(child_name.GetLength()); |
| 729 | if (use_dynamic != eNoDynamicValues) { |
| 730 | ValueObjectSP dynamic_value_sp( |
| 731 | child_valobj_sp->GetDynamicValue(use_dynamic)); |
| 732 | if (dynamic_value_sp) |
| 733 | child_valobj_sp = dynamic_value_sp; |
| 734 | } |
| 735 | } break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 736 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 737 | case '[': { |
| 738 | // Array member access, or treating pointer as an array |
| 739 | // Need at least two brackets and a number |
| 740 | if (var_expr.size() <= 2) { |
| 741 | error.SetErrorStringWithFormat( |
| 742 | "invalid square bracket encountered after \"%s\" in \"%s\"", |
| 743 | var_expr_path_strm.GetData(), var_expr.str().c_str()); |
| 744 | return ValueObjectSP(); |
| 745 | } |
| 746 | |
| 747 | // Drop the open brace. |
| 748 | var_expr = var_expr.drop_front(); |
| 749 | long child_index = 0; |
| 750 | |
| 751 | // If there's no closing brace, this is an invalid expression. |
| 752 | size_t end_pos = var_expr.find_first_of(']'); |
| 753 | if (end_pos == llvm::StringRef::npos) { |
| 754 | error.SetErrorStringWithFormat( |
| 755 | "missing closing square bracket in expression \"%s\"", |
| 756 | var_expr_path_strm.GetData()); |
| 757 | return ValueObjectSP(); |
| 758 | } |
| 759 | llvm::StringRef index_expr = var_expr.take_front(end_pos); |
| 760 | llvm::StringRef original_index_expr = index_expr; |
| 761 | // Drop all of "[index_expr]" |
| 762 | var_expr = var_expr.drop_front(end_pos + 1); |
| 763 | |
| 764 | if (index_expr.consumeInteger(0, child_index)) { |
| 765 | // If there was no integer anywhere in the index expression, this is |
| 766 | // erroneous expression. |
| 767 | error.SetErrorStringWithFormat("invalid index expression \"%s\"", |
| 768 | index_expr.str().c_str()); |
| 769 | return ValueObjectSP(); |
| 770 | } |
| 771 | |
| 772 | if (index_expr.empty()) { |
| 773 | // The entire index expression was a single integer. |
| 774 | |
| 775 | if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) { |
| 776 | // what we have is *ptr[low]. the most similar C++ syntax is to deref |
| 777 | // ptr and extract bit low out of it. reading array item low would be |
| 778 | // done by saying ptr[low], without a deref * sign |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 779 | Status error; |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 780 | ValueObjectSP temp(valobj_sp->Dereference(error)); |
| 781 | if (error.Fail()) { |
| 782 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 783 | error.SetErrorStringWithFormat( |
| 784 | "could not dereference \"(%s) %s\"", |
| 785 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 786 | var_expr_path_strm.GetData()); |
| 787 | return ValueObjectSP(); |
| 788 | } |
| 789 | valobj_sp = temp; |
| 790 | deref = false; |
| 791 | } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && |
| 792 | deref) { |
| 793 | // what we have is *arr[low]. the most similar C++ syntax is |
| 794 | // to get arr[0] |
| 795 | // (an operation that is equivalent to deref-ing arr) |
| 796 | // and extract bit low out of it. reading array item low |
| 797 | // would be done by saying arr[low], without a deref * sign |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 798 | Status error; |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 799 | ValueObjectSP temp(valobj_sp->GetChildAtIndex(0, true)); |
| 800 | if (error.Fail()) { |
| 801 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 802 | error.SetErrorStringWithFormat( |
| 803 | "could not get item 0 for \"(%s) %s\"", |
| 804 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 805 | var_expr_path_strm.GetData()); |
| 806 | return ValueObjectSP(); |
| 807 | } |
| 808 | valobj_sp = temp; |
| 809 | deref = false; |
| 810 | } |
| 811 | |
| 812 | bool is_incomplete_array = false; |
| 813 | if (valobj_sp->IsPointerType()) { |
| 814 | bool is_objc_pointer = true; |
| 815 | |
| 816 | if (valobj_sp->GetCompilerType().GetMinimumLanguage() != |
| 817 | eLanguageTypeObjC) |
| 818 | is_objc_pointer = false; |
| 819 | else if (!valobj_sp->GetCompilerType().IsPointerType()) |
| 820 | is_objc_pointer = false; |
| 821 | |
| 822 | if (no_synth_child && is_objc_pointer) { |
| 823 | error.SetErrorStringWithFormat( |
| 824 | "\"(%s) %s\" is an Objective-C pointer, and cannot be " |
| 825 | "subscripted", |
| 826 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 827 | var_expr_path_strm.GetData()); |
| 828 | |
| 829 | return ValueObjectSP(); |
| 830 | } else if (is_objc_pointer) { |
| 831 | // dereferencing ObjC variables is not valid.. so let's try |
| 832 | // and recur to synthetic children |
| 833 | ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); |
| 834 | if (!synthetic /* no synthetic */ |
| 835 | || synthetic == valobj_sp) /* synthetic is the same as |
| 836 | the original object */ |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 837 | { |
| 838 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 839 | error.SetErrorStringWithFormat( |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 840 | "\"(%s) %s\" is not an array type", |
| 841 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 842 | var_expr_path_strm.GetData()); |
| 843 | } else if ( |
| 844 | static_cast<uint32_t>(child_index) >= |
| 845 | synthetic |
| 846 | ->GetNumChildren() /* synthetic does not have that many values */) { |
| 847 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 848 | error.SetErrorStringWithFormat( |
| 849 | "array index %ld is not valid for \"(%s) %s\"", child_index, |
| 850 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 851 | var_expr_path_strm.GetData()); |
| 852 | } else { |
| 853 | child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); |
| 854 | if (!child_valobj_sp) { |
| 855 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 856 | error.SetErrorStringWithFormat( |
| 857 | "array index %ld is not valid for \"(%s) %s\"", child_index, |
| 858 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 859 | var_expr_path_strm.GetData()); |
| 860 | } |
| 861 | } |
| 862 | } else { |
| 863 | child_valobj_sp = |
| 864 | valobj_sp->GetSyntheticArrayMember(child_index, true); |
| 865 | if (!child_valobj_sp) { |
| 866 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 867 | error.SetErrorStringWithFormat( |
| 868 | "failed to use pointer as array for index %ld for " |
| 869 | "\"(%s) %s\"", |
| 870 | child_index, |
| 871 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 872 | var_expr_path_strm.GetData()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 873 | } |
| 874 | } |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 875 | } else if (valobj_sp->GetCompilerType().IsArrayType( |
| 876 | nullptr, nullptr, &is_incomplete_array)) { |
| 877 | // Pass false to dynamic_value here so we can tell the |
| 878 | // difference between |
| 879 | // no dynamic value and no member of this type... |
| 880 | child_valobj_sp = valobj_sp->GetChildAtIndex(child_index, true); |
| 881 | if (!child_valobj_sp && (is_incomplete_array || !no_synth_child)) |
| 882 | child_valobj_sp = |
| 883 | valobj_sp->GetSyntheticArrayMember(child_index, true); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 884 | |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 885 | if (!child_valobj_sp) { |
| 886 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 887 | error.SetErrorStringWithFormat( |
| 888 | "array index %ld is not valid for \"(%s) %s\"", child_index, |
| 889 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 890 | var_expr_path_strm.GetData()); |
| 891 | } |
| 892 | } else if (valobj_sp->GetCompilerType().IsScalarType()) { |
| 893 | // this is a bitfield asking to display just one bit |
| 894 | child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild( |
| 895 | child_index, child_index, true); |
| 896 | if (!child_valobj_sp) { |
| 897 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 898 | error.SetErrorStringWithFormat( |
| 899 | "bitfield range %ld-%ld is not valid for \"(%s) %s\"", |
| 900 | child_index, child_index, |
| 901 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 902 | var_expr_path_strm.GetData()); |
| 903 | } |
| 904 | } else { |
| 905 | ValueObjectSP synthetic = valobj_sp->GetSyntheticValue(); |
| 906 | if (no_synth_child /* synthetic is forbidden */ || |
| 907 | !synthetic /* no synthetic */ |
| 908 | || synthetic == valobj_sp) /* synthetic is the same as the |
| 909 | original object */ |
| 910 | { |
| 911 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 912 | error.SetErrorStringWithFormat( |
| 913 | "\"(%s) %s\" is not an array type", |
| 914 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 915 | var_expr_path_strm.GetData()); |
| 916 | } else if ( |
| 917 | static_cast<uint32_t>(child_index) >= |
| 918 | synthetic |
| 919 | ->GetNumChildren() /* synthetic does not have that many values */) { |
| 920 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 921 | error.SetErrorStringWithFormat( |
| 922 | "array index %ld is not valid for \"(%s) %s\"", child_index, |
| 923 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 924 | var_expr_path_strm.GetData()); |
| 925 | } else { |
| 926 | child_valobj_sp = synthetic->GetChildAtIndex(child_index, true); |
| 927 | if (!child_valobj_sp) { |
| 928 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 929 | error.SetErrorStringWithFormat( |
| 930 | "array index %ld is not valid for \"(%s) %s\"", child_index, |
| 931 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 932 | var_expr_path_strm.GetData()); |
| 933 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 934 | } |
| 935 | } |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 936 | |
| 937 | if (!child_valobj_sp) { |
| 938 | // Invalid array index... |
| 939 | return ValueObjectSP(); |
| 940 | } |
| 941 | |
| 942 | separator_idx = var_expr.find_first_of(".-["); |
| 943 | if (use_dynamic != eNoDynamicValues) { |
| 944 | ValueObjectSP dynamic_value_sp( |
| 945 | child_valobj_sp->GetDynamicValue(use_dynamic)); |
| 946 | if (dynamic_value_sp) |
| 947 | child_valobj_sp = dynamic_value_sp; |
| 948 | } |
| 949 | // Break out early from the switch since we were able to find the child |
| 950 | // member |
| 951 | break; |
| 952 | } |
| 953 | |
| 954 | // this is most probably a BitField, let's take a look |
| 955 | if (index_expr.front() != '-') { |
| 956 | error.SetErrorStringWithFormat("invalid range expression \"'%s'\"", |
| 957 | original_index_expr.str().c_str()); |
| 958 | return ValueObjectSP(); |
| 959 | } |
| 960 | |
Zachary Turner | 7edc3a6 | 2016-11-21 23:18:13 +0000 | [diff] [blame] | 961 | index_expr = index_expr.drop_front(); |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 962 | long final_index = 0; |
| 963 | if (index_expr.getAsInteger(0, final_index)) { |
| 964 | error.SetErrorStringWithFormat("invalid range expression \"'%s'\"", |
| 965 | original_index_expr.str().c_str()); |
| 966 | return ValueObjectSP(); |
| 967 | } |
| 968 | |
| 969 | // if the format given is [high-low], swap range |
| 970 | if (child_index > final_index) { |
| 971 | long temp = child_index; |
| 972 | child_index = final_index; |
| 973 | final_index = temp; |
| 974 | } |
| 975 | |
| 976 | if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) { |
| 977 | // what we have is *ptr[low-high]. the most similar C++ syntax is to |
| 978 | // deref ptr and extract bits low thru high out of it. reading array |
| 979 | // items low thru high would be done by saying ptr[low-high], without |
| 980 | // a deref * sign |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 981 | Status error; |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 982 | ValueObjectSP temp(valobj_sp->Dereference(error)); |
| 983 | if (error.Fail()) { |
| 984 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 985 | error.SetErrorStringWithFormat( |
| 986 | "could not dereference \"(%s) %s\"", |
| 987 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 988 | var_expr_path_strm.GetData()); |
| 989 | return ValueObjectSP(); |
| 990 | } |
| 991 | valobj_sp = temp; |
| 992 | deref = false; |
| 993 | } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) { |
| 994 | // what we have is *arr[low-high]. the most similar C++ syntax is to get |
| 995 | // arr[0] (an operation that is equivalent to deref-ing arr) and extract |
| 996 | // bits low thru high out of it. reading array items low thru high would |
| 997 | // be done by saying arr[low-high], without a deref * sign |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 998 | Status error; |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 999 | ValueObjectSP temp(valobj_sp->GetChildAtIndex(0, true)); |
| 1000 | if (error.Fail()) { |
| 1001 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 1002 | error.SetErrorStringWithFormat( |
| 1003 | "could not get item 0 for \"(%s) %s\"", |
| 1004 | valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1005 | var_expr_path_strm.GetData()); |
| 1006 | return ValueObjectSP(); |
| 1007 | } |
| 1008 | valobj_sp = temp; |
| 1009 | deref = false; |
| 1010 | } |
| 1011 | |
| 1012 | child_valobj_sp = |
| 1013 | valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true); |
| 1014 | if (!child_valobj_sp) { |
| 1015 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1016 | error.SetErrorStringWithFormat( |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 1017 | "bitfield range %ld-%ld is not valid for \"(%s) %s\"", child_index, |
| 1018 | final_index, valobj_sp->GetTypeName().AsCString("<invalid type>"), |
| 1019 | var_expr_path_strm.GetData()); |
| 1020 | } |
| 1021 | |
| 1022 | if (!child_valobj_sp) { |
| 1023 | // Invalid bitfield range... |
| 1024 | return ValueObjectSP(); |
| 1025 | } |
| 1026 | |
| 1027 | separator_idx = var_expr.find_first_of(".-["); |
| 1028 | if (use_dynamic != eNoDynamicValues) { |
| 1029 | ValueObjectSP dynamic_value_sp( |
| 1030 | child_valobj_sp->GetDynamicValue(use_dynamic)); |
| 1031 | if (dynamic_value_sp) |
| 1032 | child_valobj_sp = dynamic_value_sp; |
| 1033 | } |
| 1034 | // Break out early from the switch since we were able to find the child |
| 1035 | // member |
| 1036 | break; |
| 1037 | } |
| 1038 | default: |
| 1039 | // Failure... |
| 1040 | { |
| 1041 | valobj_sp->GetExpressionPath(var_expr_path_strm, false); |
| 1042 | error.SetErrorStringWithFormat( |
| 1043 | "unexpected char '%c' encountered after \"%s\" in \"%s\"", |
| 1044 | separator_type, var_expr_path_strm.GetData(), |
| 1045 | var_expr.str().c_str()); |
| 1046 | |
| 1047 | return ValueObjectSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1048 | } |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1049 | } |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 1050 | |
| 1051 | if (child_valobj_sp) |
| 1052 | valobj_sp = child_valobj_sp; |
| 1053 | |
| 1054 | if (var_expr.empty()) |
| 1055 | break; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1056 | } |
Zachary Turner | 24bd317 | 2016-11-17 01:37:52 +0000 | [diff] [blame] | 1057 | if (valobj_sp) { |
| 1058 | if (deref) { |
| 1059 | ValueObjectSP deref_valobj_sp(valobj_sp->Dereference(error)); |
| 1060 | valobj_sp = deref_valobj_sp; |
| 1061 | } else if (address_of) { |
| 1062 | ValueObjectSP address_of_valobj_sp(valobj_sp->AddressOf(error)); |
| 1063 | valobj_sp = address_of_valobj_sp; |
| 1064 | } |
| 1065 | } |
| 1066 | return valobj_sp; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1069 | bool StackFrame::GetFrameBaseValue(Scalar &frame_base, Status *error_ptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1070 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 1071 | if (!m_cfa_is_valid) { |
| 1072 | m_frame_base_error.SetErrorString( |
| 1073 | "No frame base available for this historical stack frame."); |
| 1074 | return false; |
| 1075 | } |
| 1076 | |
| 1077 | if (m_flags.IsClear(GOT_FRAME_BASE)) { |
| 1078 | if (m_sc.function) { |
| 1079 | m_frame_base.Clear(); |
| 1080 | m_frame_base_error.Clear(); |
| 1081 | |
| 1082 | m_flags.Set(GOT_FRAME_BASE); |
| 1083 | ExecutionContext exe_ctx(shared_from_this()); |
| 1084 | Value expr_value; |
| 1085 | addr_t loclist_base_addr = LLDB_INVALID_ADDRESS; |
| 1086 | if (m_sc.function->GetFrameBaseExpression().IsLocationList()) |
| 1087 | loclist_base_addr = |
| 1088 | m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress( |
| 1089 | exe_ctx.GetTargetPtr()); |
| 1090 | |
| 1091 | if (m_sc.function->GetFrameBaseExpression().Evaluate( |
| 1092 | &exe_ctx, nullptr, nullptr, nullptr, loclist_base_addr, nullptr, |
| 1093 | nullptr, expr_value, &m_frame_base_error) == false) { |
| 1094 | // We should really have an error if evaluate returns, but in case |
| 1095 | // we don't, lets set the error to something at least. |
| 1096 | if (m_frame_base_error.Success()) |
| 1097 | m_frame_base_error.SetErrorString( |
| 1098 | "Evaluation of the frame base expression failed."); |
| 1099 | } else { |
| 1100 | m_frame_base = expr_value.ResolveValue(&exe_ctx); |
| 1101 | } |
| 1102 | } else { |
| 1103 | m_frame_base_error.SetErrorString("No function in symbol context."); |
Jim Ingham | 78a685a | 2011-04-16 00:01:13 +0000 | [diff] [blame] | 1104 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | if (m_frame_base_error.Success()) |
| 1108 | frame_base = m_frame_base; |
| 1109 | |
| 1110 | if (error_ptr) |
| 1111 | *error_ptr = m_frame_base_error; |
| 1112 | return m_frame_base_error.Success(); |
| 1113 | } |
| 1114 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1115 | DWARFExpression *StackFrame::GetFrameBaseExpression(Status *error_ptr) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1116 | if (!m_sc.function) { |
| 1117 | if (error_ptr) { |
| 1118 | error_ptr->SetErrorString("No function in symbol context."); |
| 1119 | } |
| 1120 | return nullptr; |
| 1121 | } |
| 1122 | |
| 1123 | return &m_sc.function->GetFrameBaseExpression(); |
| 1124 | } |
| 1125 | |
| 1126 | RegisterContextSP StackFrame::GetRegisterContext() { |
| 1127 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 1128 | if (!m_reg_context_sp) { |
| 1129 | ThreadSP thread_sp(GetThread()); |
| 1130 | if (thread_sp) |
| 1131 | m_reg_context_sp = thread_sp->CreateRegisterContextForFrame(this); |
| 1132 | } |
| 1133 | return m_reg_context_sp; |
| 1134 | } |
| 1135 | |
| 1136 | bool StackFrame::HasDebugInformation() { |
| 1137 | GetSymbolContext(eSymbolContextLineEntry); |
| 1138 | return m_sc.line_entry.IsValid(); |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | ValueObjectSP |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1142 | StackFrame::GetValueObjectForFrameVariable(const VariableSP &variable_sp, |
| 1143 | DynamicValueType use_dynamic) { |
| 1144 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 1145 | ValueObjectSP valobj_sp; |
| 1146 | if (m_is_history_frame) { |
Greg Clayton | 288bdf9 | 2010-09-02 02:59:18 +0000 | [diff] [blame] | 1147 | return valobj_sp; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1148 | } |
| 1149 | VariableList *var_list = GetVariableList(true); |
| 1150 | if (var_list) { |
| 1151 | // Make sure the variable is a frame variable |
| 1152 | const uint32_t var_idx = var_list->FindIndexForVariable(variable_sp.get()); |
| 1153 | const uint32_t num_variables = var_list->GetSize(); |
| 1154 | if (var_idx < num_variables) { |
| 1155 | valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex(var_idx); |
| 1156 | if (!valobj_sp) { |
| 1157 | if (m_variable_list_value_objects.GetSize() < num_variables) |
| 1158 | m_variable_list_value_objects.Resize(num_variables); |
| 1159 | valobj_sp = ValueObjectVariable::Create(this, variable_sp); |
| 1160 | m_variable_list_value_objects.SetValueObjectAtIndex(var_idx, valobj_sp); |
| 1161 | } |
Enrico Granata | 592afe7 | 2016-03-15 21:50:51 +0000 | [diff] [blame] | 1162 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1163 | } |
| 1164 | if (use_dynamic != eNoDynamicValues && valobj_sp) { |
| 1165 | ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue(use_dynamic); |
| 1166 | if (dynamic_sp) |
| 1167 | return dynamic_sp; |
| 1168 | } |
| 1169 | return valobj_sp; |
Enrico Granata | 592afe7 | 2016-03-15 21:50:51 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1172 | ValueObjectSP StackFrame::TrackGlobalVariable(const VariableSP &variable_sp, |
| 1173 | DynamicValueType use_dynamic) { |
| 1174 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 1175 | if (m_is_history_frame) |
| 1176 | return ValueObjectSP(); |
| 1177 | |
| 1178 | // Check to make sure we aren't already tracking this variable? |
| 1179 | ValueObjectSP valobj_sp( |
| 1180 | GetValueObjectForFrameVariable(variable_sp, use_dynamic)); |
| 1181 | if (!valobj_sp) { |
| 1182 | // We aren't already tracking this global |
| 1183 | VariableList *var_list = GetVariableList(true); |
| 1184 | // If this frame has no variables, create a new list |
| 1185 | if (var_list == nullptr) |
| 1186 | m_variable_list_sp.reset(new VariableList()); |
| 1187 | |
| 1188 | // Add the global/static variable to this frame |
| 1189 | m_variable_list_sp->AddVariable(variable_sp); |
| 1190 | |
| 1191 | // Now make a value object for it so we can track its changes |
| 1192 | valobj_sp = GetValueObjectForFrameVariable(variable_sp, use_dynamic); |
| 1193 | } |
| 1194 | return valobj_sp; |
| 1195 | } |
| 1196 | |
| 1197 | bool StackFrame::IsInlined() { |
| 1198 | if (m_sc.block == nullptr) |
| 1199 | GetSymbolContext(eSymbolContextBlock); |
| 1200 | if (m_sc.block) |
| 1201 | return m_sc.block->GetContainingInlinedBlock() != nullptr; |
| 1202 | return false; |
| 1203 | } |
| 1204 | |
| 1205 | lldb::LanguageType StackFrame::GetLanguage() { |
| 1206 | CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit; |
| 1207 | if (cu) |
| 1208 | return cu->GetLanguage(); |
| 1209 | return lldb::eLanguageTypeUnknown; |
| 1210 | } |
| 1211 | |
| 1212 | lldb::LanguageType StackFrame::GuessLanguage() { |
| 1213 | LanguageType lang_type = GetLanguage(); |
| 1214 | |
| 1215 | if (lang_type == eLanguageTypeUnknown) { |
Jim Ingham | bdbdd22 | 2017-04-12 00:19:54 +0000 | [diff] [blame] | 1216 | SymbolContext sc = GetSymbolContext(eSymbolContextFunction |
| 1217 | | eSymbolContextSymbol); |
| 1218 | if (sc.function) { |
| 1219 | lang_type = sc.function->GetMangled().GuessLanguage(); |
| 1220 | } |
| 1221 | else if (sc.symbol) |
| 1222 | { |
| 1223 | lang_type = sc.symbol->GetMangled().GuessLanguage(); |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1224 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | return lang_type; |
| 1228 | } |
| 1229 | |
| 1230 | namespace { |
| 1231 | std::pair<const Instruction::Operand *, int64_t> |
| 1232 | GetBaseExplainingValue(const Instruction::Operand &operand, |
| 1233 | RegisterContext ®ister_context, lldb::addr_t value) { |
| 1234 | switch (operand.m_type) { |
| 1235 | case Instruction::Operand::Type::Dereference: |
| 1236 | case Instruction::Operand::Type::Immediate: |
| 1237 | case Instruction::Operand::Type::Invalid: |
| 1238 | case Instruction::Operand::Type::Product: |
| 1239 | // These are not currently interesting |
| 1240 | return std::make_pair(nullptr, 0); |
| 1241 | case Instruction::Operand::Type::Sum: { |
| 1242 | const Instruction::Operand *immediate_child = nullptr; |
| 1243 | const Instruction::Operand *variable_child = nullptr; |
| 1244 | if (operand.m_children[0].m_type == Instruction::Operand::Type::Immediate) { |
| 1245 | immediate_child = &operand.m_children[0]; |
| 1246 | variable_child = &operand.m_children[1]; |
| 1247 | } else if (operand.m_children[1].m_type == |
| 1248 | Instruction::Operand::Type::Immediate) { |
| 1249 | immediate_child = &operand.m_children[1]; |
| 1250 | variable_child = &operand.m_children[0]; |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1251 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1252 | if (!immediate_child) { |
| 1253 | return std::make_pair(nullptr, 0); |
| 1254 | } |
| 1255 | lldb::addr_t adjusted_value = value; |
| 1256 | if (immediate_child->m_negative) { |
| 1257 | adjusted_value += immediate_child->m_immediate; |
| 1258 | } else { |
| 1259 | adjusted_value -= immediate_child->m_immediate; |
| 1260 | } |
| 1261 | std::pair<const Instruction::Operand *, int64_t> base_and_offset = |
| 1262 | GetBaseExplainingValue(*variable_child, register_context, |
| 1263 | adjusted_value); |
| 1264 | if (!base_and_offset.first) { |
| 1265 | return std::make_pair(nullptr, 0); |
| 1266 | } |
| 1267 | if (immediate_child->m_negative) { |
| 1268 | base_and_offset.second -= immediate_child->m_immediate; |
| 1269 | } else { |
| 1270 | base_and_offset.second += immediate_child->m_immediate; |
| 1271 | } |
| 1272 | return base_and_offset; |
| 1273 | } |
| 1274 | case Instruction::Operand::Type::Register: { |
| 1275 | const RegisterInfo *info = |
| 1276 | register_context.GetRegisterInfoByName(operand.m_register.AsCString()); |
| 1277 | if (!info) { |
| 1278 | return std::make_pair(nullptr, 0); |
| 1279 | } |
| 1280 | RegisterValue reg_value; |
| 1281 | if (!register_context.ReadRegister(info, reg_value)) { |
| 1282 | return std::make_pair(nullptr, 0); |
| 1283 | } |
| 1284 | if (reg_value.GetAsUInt64() == value) { |
| 1285 | return std::make_pair(&operand, 0); |
| 1286 | } else { |
| 1287 | return std::make_pair(nullptr, 0); |
| 1288 | } |
| 1289 | } |
| 1290 | } |
Zachary Turner | 5a8ad459 | 2016-10-05 17:07:34 +0000 | [diff] [blame] | 1291 | return std::make_pair(nullptr, 0); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | std::pair<const Instruction::Operand *, int64_t> |
| 1295 | GetBaseExplainingDereference(const Instruction::Operand &operand, |
| 1296 | RegisterContext ®ister_context, |
| 1297 | lldb::addr_t addr) { |
| 1298 | if (operand.m_type == Instruction::Operand::Type::Dereference) { |
| 1299 | return GetBaseExplainingValue(operand.m_children[0], register_context, |
| 1300 | addr); |
| 1301 | } |
| 1302 | return std::make_pair(nullptr, 0); |
| 1303 | } |
Ilia K | 4f730dc | 2016-09-12 05:25:33 +0000 | [diff] [blame] | 1304 | } |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1305 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1306 | lldb::ValueObjectSP StackFrame::GuessValueForAddress(lldb::addr_t addr) { |
| 1307 | TargetSP target_sp = CalculateTarget(); |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1308 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1309 | const ArchSpec &target_arch = target_sp->GetArchitecture(); |
| 1310 | |
| 1311 | AddressRange pc_range; |
| 1312 | pc_range.GetBaseAddress() = GetFrameCodeAddress(); |
| 1313 | pc_range.SetByteSize(target_arch.GetMaximumOpcodeByteSize()); |
| 1314 | |
| 1315 | ExecutionContext exe_ctx(shared_from_this()); |
| 1316 | |
| 1317 | const char *plugin_name = nullptr; |
| 1318 | const char *flavor = nullptr; |
| 1319 | const bool prefer_file_cache = false; |
| 1320 | |
| 1321 | DisassemblerSP disassembler_sp = Disassembler::DisassembleRange( |
| 1322 | target_arch, plugin_name, flavor, exe_ctx, pc_range, prefer_file_cache); |
| 1323 | |
Jim Ingham | 99d1e28 | 2017-03-31 22:39:55 +0000 | [diff] [blame] | 1324 | if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) { |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1325 | return ValueObjectSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1326 | } |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1327 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1328 | InstructionSP instruction_sp = |
| 1329 | disassembler_sp->GetInstructionList().GetInstructionAtIndex(0); |
| 1330 | |
| 1331 | llvm::SmallVector<Instruction::Operand, 3> operands; |
| 1332 | |
| 1333 | if (!instruction_sp->ParseOperands(operands)) { |
| 1334 | return ValueObjectSP(); |
| 1335 | } |
| 1336 | |
| 1337 | RegisterContextSP register_context_sp = GetRegisterContext(); |
| 1338 | |
| 1339 | if (!register_context_sp) { |
| 1340 | return ValueObjectSP(); |
| 1341 | } |
| 1342 | |
| 1343 | for (const Instruction::Operand &operand : operands) { |
| 1344 | std::pair<const Instruction::Operand *, int64_t> base_and_offset = |
| 1345 | GetBaseExplainingDereference(operand, *register_context_sp, addr); |
| 1346 | |
| 1347 | if (!base_and_offset.first) { |
| 1348 | continue; |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1349 | } |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1350 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1351 | switch (base_and_offset.first->m_type) { |
| 1352 | case Instruction::Operand::Type::Immediate: { |
| 1353 | lldb_private::Address addr; |
| 1354 | if (target_sp->ResolveLoadAddress(base_and_offset.first->m_immediate + |
| 1355 | base_and_offset.second, |
| 1356 | addr)) { |
| 1357 | TypeSystem *c_type_system = |
| 1358 | target_sp->GetScratchTypeSystemForLanguage(nullptr, eLanguageTypeC); |
| 1359 | if (!c_type_system) { |
| 1360 | return ValueObjectSP(); |
| 1361 | } else { |
| 1362 | CompilerType void_ptr_type = |
| 1363 | c_type_system |
| 1364 | ->GetBasicTypeFromAST(lldb::BasicType::eBasicTypeChar) |
| 1365 | .GetPointerType(); |
| 1366 | return ValueObjectMemory::Create(this, "", addr, void_ptr_type); |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1367 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1368 | } else { |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1369 | return ValueObjectSP(); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1370 | } |
| 1371 | break; |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1372 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1373 | case Instruction::Operand::Type::Register: { |
| 1374 | return GuessValueForRegisterAndOffset(base_and_offset.first->m_register, |
| 1375 | base_and_offset.second); |
| 1376 | } |
| 1377 | default: |
| 1378 | return ValueObjectSP(); |
| 1379 | } |
| 1380 | } |
| 1381 | |
| 1382 | return ValueObjectSP(); |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1385 | namespace { |
| 1386 | ValueObjectSP GetValueForOffset(StackFrame &frame, ValueObjectSP &parent, |
| 1387 | int64_t offset) { |
| 1388 | if (offset < 0 || uint64_t(offset) >= parent->GetByteSize()) { |
| 1389 | return ValueObjectSP(); |
| 1390 | } |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1391 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1392 | if (parent->IsPointerOrReferenceType()) { |
| 1393 | return parent; |
| 1394 | } |
| 1395 | |
| 1396 | for (int ci = 0, ce = parent->GetNumChildren(); ci != ce; ++ci) { |
| 1397 | const bool can_create = true; |
| 1398 | ValueObjectSP child_sp = parent->GetChildAtIndex(ci, can_create); |
| 1399 | |
| 1400 | if (!child_sp) { |
| 1401 | return ValueObjectSP(); |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1404 | int64_t child_offset = child_sp->GetByteOffset(); |
| 1405 | int64_t child_size = child_sp->GetByteSize(); |
| 1406 | |
| 1407 | if (offset >= child_offset && offset < (child_offset + child_size)) { |
| 1408 | return GetValueForOffset(frame, child_sp, offset - child_offset); |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1409 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1410 | } |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1411 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1412 | if (offset == 0) { |
| 1413 | return parent; |
| 1414 | } else { |
| 1415 | return ValueObjectSP(); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | ValueObjectSP GetValueForDereferincingOffset(StackFrame &frame, |
| 1420 | ValueObjectSP &base, |
| 1421 | int64_t offset) { |
| 1422 | // base is a pointer to something |
| 1423 | // offset is the thing to add to the pointer |
| 1424 | // We return the most sensible ValueObject for the result of *(base+offset) |
| 1425 | |
| 1426 | if (!base->IsPointerOrReferenceType()) { |
| 1427 | return ValueObjectSP(); |
| 1428 | } |
| 1429 | |
Zachary Turner | 97206d5 | 2017-05-12 04:51:55 +0000 | [diff] [blame] | 1430 | Status error; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1431 | ValueObjectSP pointee = base->Dereference(error); |
Sean Callanan | a0a1d2d | 2016-09-29 00:16:37 +0000 | [diff] [blame] | 1432 | |
| 1433 | if (!pointee) { |
| 1434 | return ValueObjectSP(); |
| 1435 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1436 | |
Ilia K | 4f730dc | 2016-09-12 05:25:33 +0000 | [diff] [blame] | 1437 | if (offset >= 0 && uint64_t(offset) >= pointee->GetByteSize()) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1438 | int64_t index = offset / pointee->GetByteSize(); |
| 1439 | offset = offset % pointee->GetByteSize(); |
| 1440 | const bool can_create = true; |
| 1441 | pointee = base->GetSyntheticArrayMember(index, can_create); |
| 1442 | } |
| 1443 | |
| 1444 | if (!pointee || error.Fail()) { |
| 1445 | return ValueObjectSP(); |
| 1446 | } |
| 1447 | |
| 1448 | return GetValueForOffset(frame, pointee, offset); |
| 1449 | } |
| 1450 | |
| 1451 | //------------------------------------------------------------------ |
| 1452 | /// Attempt to reconstruct the ValueObject for the address contained in a |
| 1453 | /// given register plus an offset. |
| 1454 | /// |
| 1455 | /// @params [in] frame |
| 1456 | /// The current stack frame. |
| 1457 | /// |
| 1458 | /// @params [in] reg |
| 1459 | /// The register. |
| 1460 | /// |
| 1461 | /// @params [in] offset |
| 1462 | /// The offset from the register. |
| 1463 | /// |
| 1464 | /// @param [in] disassembler |
| 1465 | /// A disassembler containing instructions valid up to the current PC. |
| 1466 | /// |
| 1467 | /// @param [in] variables |
| 1468 | /// The variable list from the current frame, |
| 1469 | /// |
| 1470 | /// @param [in] pc |
| 1471 | /// The program counter for the instruction considered the 'user'. |
| 1472 | /// |
| 1473 | /// @return |
| 1474 | /// A string describing the base for the ExpressionPath. This could be a |
| 1475 | /// variable, a register value, an argument, or a function return value. |
| 1476 | /// The ValueObject if found. If valid, it has a valid ExpressionPath. |
| 1477 | //------------------------------------------------------------------ |
| 1478 | lldb::ValueObjectSP DoGuessValueAt(StackFrame &frame, ConstString reg, |
| 1479 | int64_t offset, Disassembler &disassembler, |
| 1480 | VariableList &variables, const Address &pc) { |
| 1481 | // Example of operation for Intel: |
| 1482 | // |
| 1483 | // +14: movq -0x8(%rbp), %rdi |
| 1484 | // +18: movq 0x8(%rdi), %rdi |
| 1485 | // +22: addl 0x4(%rdi), %eax |
| 1486 | // |
| 1487 | // f, a pointer to a struct, is known to be at -0x8(%rbp). |
| 1488 | // |
| 1489 | // DoGuessValueAt(frame, rdi, 4, dis, vars, 0x22) finds the instruction at +18 |
| 1490 | // that assigns to rdi, and calls itself recursively for that dereference |
| 1491 | // DoGuessValueAt(frame, rdi, 8, dis, vars, 0x18) finds the instruction at |
| 1492 | // +14 that assigns to rdi, and calls itself recursively for that |
| 1493 | // derefernece |
| 1494 | // DoGuessValueAt(frame, rbp, -8, dis, vars, 0x14) finds "f" in the |
| 1495 | // variable list. |
| 1496 | // Returns a ValueObject for f. (That's what was stored at rbp-8 at +14) |
| 1497 | // Returns a ValueObject for *(f+8) or f->b (That's what was stored at rdi+8 |
| 1498 | // at +18) |
| 1499 | // Returns a ValueObject for *(f->b+4) or f->b->a (That's what was stored at |
| 1500 | // rdi+4 at +22) |
| 1501 | |
| 1502 | // First, check the variable list to see if anything is at the specified |
| 1503 | // location. |
Sean Callanan | 807ee2f | 2016-09-13 21:18:27 +0000 | [diff] [blame] | 1504 | |
Sean Callanan | 5085710 | 2016-09-14 00:48:19 +0000 | [diff] [blame] | 1505 | using namespace OperandMatchers; |
| 1506 | |
Sean Callanan | 0ac172d | 2016-09-14 20:29:57 +0000 | [diff] [blame] | 1507 | const RegisterInfo *reg_info = |
| 1508 | frame.GetRegisterContext()->GetRegisterInfoByName(reg.AsCString()); |
| 1509 | if (!reg_info) { |
| 1510 | return ValueObjectSP(); |
| 1511 | } |
| 1512 | |
Sean Callanan | 807ee2f | 2016-09-13 21:18:27 +0000 | [diff] [blame] | 1513 | Instruction::Operand op = |
| 1514 | offset ? Instruction::Operand::BuildDereference( |
| 1515 | Instruction::Operand::BuildSum( |
| 1516 | Instruction::Operand::BuildRegister(reg), |
| 1517 | Instruction::Operand::BuildImmediate(offset))) |
| 1518 | : Instruction::Operand::BuildDereference( |
| 1519 | Instruction::Operand::BuildRegister(reg)); |
| 1520 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1521 | for (size_t vi = 0, ve = variables.GetSize(); vi != ve; ++vi) { |
| 1522 | VariableSP var_sp = variables.GetVariableAtIndex(vi); |
Sean Callanan | 807ee2f | 2016-09-13 21:18:27 +0000 | [diff] [blame] | 1523 | if (var_sp->LocationExpression().MatchesOperand(frame, op)) { |
| 1524 | return frame.GetValueObjectForFrameVariable(var_sp, eNoDynamicValues); |
Sean Callanan | 4740a73 | 2016-09-06 04:48:36 +0000 | [diff] [blame] | 1525 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1528 | const uint32_t current_inst = |
| 1529 | disassembler.GetInstructionList().GetIndexOfInstructionAtAddress(pc); |
| 1530 | if (current_inst == UINT32_MAX) { |
| 1531 | return ValueObjectSP(); |
| 1532 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1533 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1534 | for (uint32_t ii = current_inst - 1; ii != (uint32_t)-1; --ii) { |
| 1535 | // This is not an exact algorithm, and it sacrifices accuracy for |
Sean Callanan | 0ac172d | 2016-09-14 20:29:57 +0000 | [diff] [blame] | 1536 | // generality. Recognizing "mov" and "ld" instructions –– and which are |
| 1537 | // their source and destination operands -- is something the disassembler |
| 1538 | // should do for us. |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1539 | InstructionSP instruction_sp = |
| 1540 | disassembler.GetInstructionList().GetInstructionAtIndex(ii); |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1541 | |
Sean Callanan | 5085710 | 2016-09-14 00:48:19 +0000 | [diff] [blame] | 1542 | if (instruction_sp->IsCall()) { |
| 1543 | ABISP abi_sp = frame.CalculateProcess()->GetABI(); |
| 1544 | if (!abi_sp) { |
| 1545 | continue; |
| 1546 | } |
| 1547 | |
| 1548 | const char *return_register_name; |
| 1549 | if (!abi_sp->GetPointerReturnRegister(return_register_name)) { |
| 1550 | continue; |
| 1551 | } |
| 1552 | |
| 1553 | const RegisterInfo *return_register_info = |
| 1554 | frame.GetRegisterContext()->GetRegisterInfoByName( |
| 1555 | return_register_name); |
| 1556 | if (!return_register_info) { |
| 1557 | continue; |
| 1558 | } |
| 1559 | |
| 1560 | int64_t offset = 0; |
| 1561 | |
| 1562 | if (!MatchUnaryOp(MatchOpType(Instruction::Operand::Type::Dereference), |
| 1563 | MatchRegOp(*return_register_info))(op) && |
| 1564 | !MatchUnaryOp( |
| 1565 | MatchOpType(Instruction::Operand::Type::Dereference), |
| 1566 | MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum), |
| 1567 | MatchRegOp(*return_register_info), |
| 1568 | FetchImmOp(offset)))(op)) { |
| 1569 | continue; |
| 1570 | } |
| 1571 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1572 | llvm::SmallVector<Instruction::Operand, 1> operands; |
| 1573 | if (!instruction_sp->ParseOperands(operands) || operands.size() != 1) { |
| 1574 | continue; |
| 1575 | } |
Chris Lattner | 30fdc8d | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1576 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1577 | switch (operands[0].m_type) { |
| 1578 | default: |
| 1579 | break; |
| 1580 | case Instruction::Operand::Type::Immediate: { |
| 1581 | SymbolContext sc; |
| 1582 | Address load_address; |
| 1583 | if (!frame.CalculateTarget()->ResolveLoadAddress( |
| 1584 | operands[0].m_immediate, load_address)) { |
| 1585 | break; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1586 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1587 | frame.CalculateTarget()->GetImages().ResolveSymbolContextForAddress( |
| 1588 | load_address, eSymbolContextFunction, sc); |
| 1589 | if (!sc.function) { |
| 1590 | break; |
| 1591 | } |
| 1592 | CompilerType function_type = sc.function->GetCompilerType(); |
| 1593 | if (!function_type.IsFunctionType()) { |
| 1594 | break; |
| 1595 | } |
| 1596 | CompilerType return_type = function_type.GetFunctionReturnType(); |
| 1597 | RegisterValue return_value; |
Sean Callanan | 5085710 | 2016-09-14 00:48:19 +0000 | [diff] [blame] | 1598 | if (!frame.GetRegisterContext()->ReadRegister(return_register_info, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1599 | return_value)) { |
| 1600 | break; |
| 1601 | } |
| 1602 | std::string name_str( |
| 1603 | sc.function->GetName().AsCString("<unknown function>")); |
| 1604 | name_str.append("()"); |
| 1605 | Address return_value_address(return_value.GetAsUInt64()); |
| 1606 | ValueObjectSP return_value_sp = ValueObjectMemory::Create( |
Zachary Turner | 22a2628 | 2016-11-12 18:17:36 +0000 | [diff] [blame] | 1607 | &frame, name_str, return_value_address, return_type); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1608 | return GetValueForDereferincingOffset(frame, return_value_sp, offset); |
| 1609 | } |
| 1610 | } |
| 1611 | |
| 1612 | continue; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1613 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1614 | |
| 1615 | llvm::SmallVector<Instruction::Operand, 2> operands; |
| 1616 | if (!instruction_sp->ParseOperands(operands) || operands.size() != 2) { |
| 1617 | continue; |
| 1618 | } |
| 1619 | |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1620 | Instruction::Operand *origin_operand = nullptr; |
Sean Callanan | aa4b44c | 2016-09-14 20:58:31 +0000 | [diff] [blame] | 1621 | auto clobbered_reg_matcher = [reg_info](const Instruction::Operand &op) { |
| 1622 | return MatchRegOp(*reg_info)(op) && op.m_clobbered; |
| 1623 | }; |
Sean Callanan | 0ac172d | 2016-09-14 20:29:57 +0000 | [diff] [blame] | 1624 | |
| 1625 | if (clobbered_reg_matcher(operands[0])) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1626 | origin_operand = &operands[1]; |
Sean Callanan | 0ac172d | 2016-09-14 20:29:57 +0000 | [diff] [blame] | 1627 | } |
| 1628 | else if (clobbered_reg_matcher(operands[1])) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1629 | origin_operand = &operands[0]; |
Sean Callanan | 0ac172d | 2016-09-14 20:29:57 +0000 | [diff] [blame] | 1630 | } |
| 1631 | else { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1632 | continue; |
| 1633 | } |
| 1634 | |
| 1635 | // We have an origin operand. Can we track its value down? |
Sean Callanan | 561a9bb | 2016-09-14 21:54:28 +0000 | [diff] [blame] | 1636 | ValueObjectSP source_path; |
| 1637 | ConstString origin_register; |
| 1638 | int64_t origin_offset = 0; |
| 1639 | |
| 1640 | if (FetchRegOp(origin_register)(*origin_operand)) { |
| 1641 | source_path = DoGuessValueAt(frame, origin_register, 0, disassembler, |
| 1642 | variables, instruction_sp->GetAddress()); |
| 1643 | } else if (MatchUnaryOp( |
| 1644 | MatchOpType(Instruction::Operand::Type::Dereference), |
| 1645 | FetchRegOp(origin_register))(*origin_operand) || |
| 1646 | MatchUnaryOp( |
| 1647 | MatchOpType(Instruction::Operand::Type::Dereference), |
| 1648 | MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum), |
| 1649 | FetchRegOp(origin_register), |
| 1650 | FetchImmOp(origin_offset)))(*origin_operand)) { |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1651 | source_path = |
Sean Callanan | 561a9bb | 2016-09-14 21:54:28 +0000 | [diff] [blame] | 1652 | DoGuessValueAt(frame, origin_register, origin_offset, disassembler, |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1653 | variables, instruction_sp->GetAddress()); |
Sean Callanan | 561a9bb | 2016-09-14 21:54:28 +0000 | [diff] [blame] | 1654 | if (!source_path) { |
| 1655 | continue; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1656 | } |
Sean Callanan | 561a9bb | 2016-09-14 21:54:28 +0000 | [diff] [blame] | 1657 | source_path = |
| 1658 | GetValueForDereferincingOffset(frame, source_path, offset); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | if (source_path) { |
| 1662 | return source_path; |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | return ValueObjectSP(); |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | lldb::ValueObjectSP StackFrame::GuessValueForRegisterAndOffset(ConstString reg, |
| 1671 | int64_t offset) { |
| 1672 | TargetSP target_sp = CalculateTarget(); |
| 1673 | |
| 1674 | const ArchSpec &target_arch = target_sp->GetArchitecture(); |
| 1675 | |
| 1676 | Block *frame_block = GetFrameBlock(); |
| 1677 | |
| 1678 | if (!frame_block) { |
| 1679 | return ValueObjectSP(); |
| 1680 | } |
| 1681 | |
| 1682 | Function *function = frame_block->CalculateSymbolContextFunction(); |
| 1683 | if (!function) { |
| 1684 | return ValueObjectSP(); |
| 1685 | } |
| 1686 | |
| 1687 | AddressRange pc_range = function->GetAddressRange(); |
| 1688 | |
| 1689 | if (GetFrameCodeAddress().GetFileAddress() < |
| 1690 | pc_range.GetBaseAddress().GetFileAddress() || |
| 1691 | GetFrameCodeAddress().GetFileAddress() - |
| 1692 | pc_range.GetBaseAddress().GetFileAddress() >= |
| 1693 | pc_range.GetByteSize()) { |
| 1694 | return ValueObjectSP(); |
| 1695 | } |
| 1696 | |
| 1697 | ExecutionContext exe_ctx(shared_from_this()); |
| 1698 | |
| 1699 | const char *plugin_name = nullptr; |
| 1700 | const char *flavor = nullptr; |
| 1701 | const bool prefer_file_cache = false; |
| 1702 | DisassemblerSP disassembler_sp = Disassembler::DisassembleRange( |
| 1703 | target_arch, plugin_name, flavor, exe_ctx, pc_range, prefer_file_cache); |
| 1704 | |
| 1705 | if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) { |
| 1706 | return ValueObjectSP(); |
| 1707 | } |
| 1708 | |
| 1709 | const bool get_file_globals = false; |
| 1710 | VariableList *variables = GetVariableList(get_file_globals); |
| 1711 | |
| 1712 | if (!variables) { |
| 1713 | return ValueObjectSP(); |
| 1714 | } |
| 1715 | |
| 1716 | return DoGuessValueAt(*this, reg, offset, *disassembler_sp, *variables, |
| 1717 | GetFrameCodeAddress()); |
| 1718 | } |
| 1719 | |
| 1720 | TargetSP StackFrame::CalculateTarget() { |
| 1721 | TargetSP target_sp; |
| 1722 | ThreadSP thread_sp(GetThread()); |
| 1723 | if (thread_sp) { |
| 1724 | ProcessSP process_sp(thread_sp->CalculateProcess()); |
| 1725 | if (process_sp) |
| 1726 | target_sp = process_sp->CalculateTarget(); |
| 1727 | } |
| 1728 | return target_sp; |
| 1729 | } |
| 1730 | |
| 1731 | ProcessSP StackFrame::CalculateProcess() { |
| 1732 | ProcessSP process_sp; |
| 1733 | ThreadSP thread_sp(GetThread()); |
| 1734 | if (thread_sp) |
| 1735 | process_sp = thread_sp->CalculateProcess(); |
| 1736 | return process_sp; |
| 1737 | } |
| 1738 | |
| 1739 | ThreadSP StackFrame::CalculateThread() { return GetThread(); } |
| 1740 | |
| 1741 | StackFrameSP StackFrame::CalculateStackFrame() { return shared_from_this(); } |
| 1742 | |
| 1743 | void StackFrame::CalculateExecutionContext(ExecutionContext &exe_ctx) { |
| 1744 | exe_ctx.SetContext(shared_from_this()); |
| 1745 | } |
| 1746 | |
| 1747 | void StackFrame::DumpUsingSettingsFormat(Stream *strm, |
| 1748 | const char *frame_marker) { |
| 1749 | if (strm == nullptr) |
| 1750 | return; |
| 1751 | |
| 1752 | GetSymbolContext(eSymbolContextEverything); |
| 1753 | ExecutionContext exe_ctx(shared_from_this()); |
| 1754 | StreamString s; |
| 1755 | |
| 1756 | if (frame_marker) |
| 1757 | s.PutCString(frame_marker); |
| 1758 | |
| 1759 | const FormatEntity::Entry *frame_format = nullptr; |
| 1760 | Target *target = exe_ctx.GetTargetPtr(); |
| 1761 | if (target) |
| 1762 | frame_format = target->GetDebugger().GetFrameFormat(); |
| 1763 | if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx, |
| 1764 | nullptr, nullptr, false, false)) { |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1765 | strm->PutCString(s.GetString()); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1766 | } else { |
| 1767 | Dump(strm, true, false); |
| 1768 | strm->EOL(); |
| 1769 | } |
| 1770 | } |
| 1771 | |
| 1772 | void StackFrame::Dump(Stream *strm, bool show_frame_index, |
| 1773 | bool show_fullpaths) { |
| 1774 | if (strm == nullptr) |
| 1775 | return; |
| 1776 | |
| 1777 | if (show_frame_index) |
| 1778 | strm->Printf("frame #%u: ", m_frame_index); |
| 1779 | ExecutionContext exe_ctx(shared_from_this()); |
| 1780 | Target *target = exe_ctx.GetTargetPtr(); |
| 1781 | strm->Printf("0x%0*" PRIx64 " ", |
| 1782 | target ? (target->GetArchitecture().GetAddressByteSize() * 2) |
| 1783 | : 16, |
| 1784 | GetFrameCodeAddress().GetLoadAddress(target)); |
| 1785 | GetSymbolContext(eSymbolContextEverything); |
| 1786 | const bool show_module = true; |
| 1787 | const bool show_inline = true; |
| 1788 | const bool show_function_arguments = true; |
| 1789 | const bool show_function_name = true; |
| 1790 | m_sc.DumpStopContext(strm, exe_ctx.GetBestExecutionContextScope(), |
| 1791 | GetFrameCodeAddress(), show_fullpaths, show_module, |
| 1792 | show_inline, show_function_arguments, |
| 1793 | show_function_name); |
| 1794 | } |
| 1795 | |
| 1796 | void StackFrame::UpdateCurrentFrameFromPreviousFrame(StackFrame &prev_frame) { |
| 1797 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 1798 | assert(GetStackID() == |
| 1799 | prev_frame.GetStackID()); // TODO: remove this after some testing |
| 1800 | m_variable_list_sp = prev_frame.m_variable_list_sp; |
| 1801 | m_variable_list_value_objects.Swap(prev_frame.m_variable_list_value_objects); |
Zachary Turner | c156427 | 2016-11-16 21:15:24 +0000 | [diff] [blame] | 1802 | if (!m_disassembly.GetString().empty()) { |
| 1803 | m_disassembly.Clear(); |
| 1804 | m_disassembly.PutCString(prev_frame.m_disassembly.GetString()); |
| 1805 | } |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | void StackFrame::UpdatePreviousFrameFromCurrentFrame(StackFrame &curr_frame) { |
| 1809 | std::lock_guard<std::recursive_mutex> guard(m_mutex); |
| 1810 | assert(GetStackID() == |
| 1811 | curr_frame.GetStackID()); // TODO: remove this after some testing |
| 1812 | m_id.SetPC(curr_frame.m_id.GetPC()); // Update the Stack ID PC value |
| 1813 | assert(GetThread() == curr_frame.GetThread()); |
| 1814 | m_frame_index = curr_frame.m_frame_index; |
| 1815 | m_concrete_frame_index = curr_frame.m_concrete_frame_index; |
| 1816 | m_reg_context_sp = curr_frame.m_reg_context_sp; |
| 1817 | m_frame_code_addr = curr_frame.m_frame_code_addr; |
| 1818 | assert(!m_sc.target_sp || !curr_frame.m_sc.target_sp || |
| 1819 | m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get()); |
| 1820 | assert(!m_sc.module_sp || !curr_frame.m_sc.module_sp || |
| 1821 | m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get()); |
| 1822 | assert(m_sc.comp_unit == nullptr || curr_frame.m_sc.comp_unit == nullptr || |
| 1823 | m_sc.comp_unit == curr_frame.m_sc.comp_unit); |
| 1824 | assert(m_sc.function == nullptr || curr_frame.m_sc.function == nullptr || |
| 1825 | m_sc.function == curr_frame.m_sc.function); |
| 1826 | m_sc = curr_frame.m_sc; |
| 1827 | m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything); |
| 1828 | m_flags.Set(m_sc.GetResolvedMask()); |
| 1829 | m_frame_base.Clear(); |
| 1830 | m_frame_base_error.Clear(); |
| 1831 | } |
| 1832 | |
| 1833 | bool StackFrame::HasCachedData() const { |
| 1834 | if (m_variable_list_sp) |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1835 | return true; |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1836 | if (m_variable_list_value_objects.GetSize() > 0) |
| 1837 | return true; |
| 1838 | if (!m_disassembly.GetString().empty()) |
| 1839 | return true; |
| 1840 | return false; |
| 1841 | } |
| 1842 | |
| 1843 | bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source, |
| 1844 | const char *frame_marker) { |
| 1845 | |
| 1846 | if (show_frame_info) { |
| 1847 | strm.Indent(); |
| 1848 | DumpUsingSettingsFormat(&strm, frame_marker); |
| 1849 | } |
| 1850 | |
| 1851 | if (show_source) { |
| 1852 | ExecutionContext exe_ctx(shared_from_this()); |
| 1853 | bool have_source = false, have_debuginfo = false; |
| 1854 | Debugger::StopDisassemblyType disasm_display = |
| 1855 | Debugger::eStopDisassemblyTypeNever; |
| 1856 | Target *target = exe_ctx.GetTargetPtr(); |
| 1857 | if (target) { |
| 1858 | Debugger &debugger = target->GetDebugger(); |
| 1859 | const uint32_t source_lines_before = |
| 1860 | debugger.GetStopSourceLineCount(true); |
| 1861 | const uint32_t source_lines_after = |
| 1862 | debugger.GetStopSourceLineCount(false); |
| 1863 | disasm_display = debugger.GetStopDisassemblyDisplay(); |
| 1864 | |
| 1865 | GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry); |
| 1866 | if (m_sc.comp_unit && m_sc.line_entry.IsValid()) { |
| 1867 | have_debuginfo = true; |
| 1868 | if (source_lines_before > 0 || source_lines_after > 0) { |
| 1869 | size_t num_lines = |
| 1870 | target->GetSourceManager().DisplaySourceLinesWithLineNumbers( |
| 1871 | m_sc.line_entry.file, m_sc.line_entry.line, |
Todd Fiala | 9666ba7 | 2016-09-21 20:13:14 +0000 | [diff] [blame] | 1872 | m_sc.line_entry.column, source_lines_before, |
| 1873 | source_lines_after, "->", &strm); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1874 | if (num_lines != 0) |
| 1875 | have_source = true; |
| 1876 | // TODO: Give here a one time warning if source file is missing. |
| 1877 | } |
| 1878 | } |
| 1879 | switch (disasm_display) { |
| 1880 | case Debugger::eStopDisassemblyTypeNever: |
| 1881 | break; |
| 1882 | |
| 1883 | case Debugger::eStopDisassemblyTypeNoDebugInfo: |
| 1884 | if (have_debuginfo) |
| 1885 | break; |
| 1886 | LLVM_FALLTHROUGH; |
| 1887 | |
| 1888 | case Debugger::eStopDisassemblyTypeNoSource: |
| 1889 | if (have_source) |
| 1890 | break; |
| 1891 | LLVM_FALLTHROUGH; |
| 1892 | |
| 1893 | case Debugger::eStopDisassemblyTypeAlways: |
| 1894 | if (target) { |
| 1895 | const uint32_t disasm_lines = debugger.GetDisassemblyLineCount(); |
| 1896 | if (disasm_lines > 0) { |
| 1897 | const ArchSpec &target_arch = target->GetArchitecture(); |
| 1898 | AddressRange pc_range; |
| 1899 | pc_range.GetBaseAddress() = GetFrameCodeAddress(); |
| 1900 | pc_range.SetByteSize(disasm_lines * |
| 1901 | target_arch.GetMaximumOpcodeByteSize()); |
| 1902 | const char *plugin_name = nullptr; |
| 1903 | const char *flavor = nullptr; |
Jason Molenda | 0b4c26b | 2016-09-08 05:12:41 +0000 | [diff] [blame] | 1904 | const bool mixed_source_and_assembly = false; |
| 1905 | Disassembler::Disassemble( |
| 1906 | target->GetDebugger(), target_arch, plugin_name, flavor, |
| 1907 | exe_ctx, pc_range, disasm_lines, mixed_source_and_assembly, 0, |
| 1908 | Disassembler::eOptionMarkPCAddress, strm); |
Kate Stone | b9c1b51 | 2016-09-06 20:57:50 +0000 | [diff] [blame] | 1909 | } |
| 1910 | } |
| 1911 | break; |
| 1912 | } |
| 1913 | } |
| 1914 | } |
| 1915 | return true; |
Greg Clayton | 7260f62 | 2011-04-18 08:33:37 +0000 | [diff] [blame] | 1916 | } |