blob: 3cea6444596c791f0e8d3bfb946a5ef4c4ad9f4e [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:241//===-- 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
Eugene Zelenkod70a6e72016-02-18 18:52:4710#include "lldb/Target/StackFrame.h"
Greg Clayton0603aa92010-10-04 01:05:5611#include "lldb/Core/Debugger.h"
Chris Lattner30fdc8d2010-06-08 16:52:2412#include "lldb/Core/Disassembler.h"
Greg Clayton554f68d2015-02-04 22:00:5313#include "lldb/Core/FormatEntity.h"
Enrico Granata592afe72016-03-15 21:50:5114#include "lldb/Core/Mangled.h"
15#include "lldb/Core/Module.h"
Chris Lattner30fdc8d2010-06-08 16:52:2416#include "lldb/Core/Value.h"
Greg Clayton54979cd2010-12-15 05:08:0817#include "lldb/Core/ValueObjectConstResult.h"
Sean Callanan4740a732016-09-06 04:48:3618#include "lldb/Core/ValueObjectMemory.h"
Kate Stoneb9c1b512016-09-06 20:57:5019#include "lldb/Core/ValueObjectVariable.h"
Greg Clayton1f746072012-08-29 21:13:0620#include "lldb/Symbol/CompileUnit.h"
Chris Lattner30fdc8d2010-06-08 16:52:2421#include "lldb/Symbol/Function.h"
Greg Clayton1f746072012-08-29 21:13:0622#include "lldb/Symbol/Symbol.h"
23#include "lldb/Symbol/SymbolContextScope.h"
Enrico Granata46252392015-11-19 22:28:5824#include "lldb/Symbol/Type.h"
Greg Clayton288bdf92010-09-02 02:59:1825#include "lldb/Symbol/VariableList.h"
Sean Callanan4740a732016-09-06 04:48:3626#include "lldb/Target/ABI.h"
Chris Lattner30fdc8d2010-06-08 16:52:2427#include "lldb/Target/ExecutionContext.h"
28#include "lldb/Target/Process.h"
29#include "lldb/Target/RegisterContext.h"
Kuba Mracek41ae8e72018-10-31 04:00:2230#include "lldb/Target/StackFrameRecognizer.h"
Chris Lattner30fdc8d2010-06-08 16:52:2431#include "lldb/Target/Target.h"
32#include "lldb/Target/Thread.h"
Pavel Labathd821c992018-08-07 11:07:2133#include "lldb/Utility/RegisterValue.h"
Chris Lattner30fdc8d2010-06-08 16:52:2434
Zachary Turner991e4452018-10-25 20:45:1935#include "lldb/lldb-enumerations.h"
36
Chris Lattner30fdc8d2010-06-08 16:52:2437using namespace lldb;
38using namespace lldb_private;
39
40// The first bits in the flags are reserved for the SymbolContext::Scope bits
41// so we know if we have tried to look up information in our internal symbol
42// context (m_sc) already.
Kate Stoneb9c1b512016-09-06 20:57:5043#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextEverything + 1))
44#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
45#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
46#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
47#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
Chris Lattner30fdc8d2010-06-08 16:52:2448
Kate Stoneb9c1b512016-09-06 20:57:5049StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
50 user_id_t unwind_frame_index, addr_t cfa,
Vedant Kumar4b36f792018-10-05 23:23:1551 bool cfa_is_valid, addr_t pc, StackFrame::Kind kind,
Saleem Abdulrasoolbb19a132016-05-19 05:13:5752 const SymbolContext *sc_ptr)
Kate Stoneb9c1b512016-09-06 20:57:5053 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
54 m_concrete_frame_index(unwind_frame_index), m_reg_context_sp(),
55 m_id(pc, cfa, nullptr), m_frame_code_addr(pc), m_sc(), m_flags(),
56 m_frame_base(), m_frame_base_error(), m_cfa_is_valid(cfa_is_valid),
Vedant Kumar4b36f792018-10-05 23:23:1557 m_stack_frame_kind(kind), m_variable_list_sp(),
Kuba Mracek41ae8e72018-10-31 04:00:2258 m_variable_list_value_objects(), m_recognized_frame_sp(), m_disassembly(),
59 m_mutex() {
Kate Stoneb9c1b512016-09-06 20:57:5060 // If we don't have a CFA value, use the frame index for our StackID so that
Adrian Prantl05097242018-04-30 16:49:0461 // recursive functions properly aren't confused with one another on a history
62 // stack.
Vedant Kumar4b36f792018-10-05 23:23:1563 if (IsHistorical() && !m_cfa_is_valid) {
Kate Stoneb9c1b512016-09-06 20:57:5064 m_id.SetCFA(m_frame_index);
65 }
Jason Molenda99618472013-11-04 11:02:5266
Kate Stoneb9c1b512016-09-06 20:57:5067 if (sc_ptr != nullptr) {
68 m_sc = *sc_ptr;
69 m_flags.Set(m_sc.GetResolvedMask());
70 }
Chris Lattner30fdc8d2010-06-08 16:52:2471}
72
Kate Stoneb9c1b512016-09-06 20:57:5073StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
74 user_id_t unwind_frame_index,
75 const RegisterContextSP &reg_context_sp, addr_t cfa,
76 addr_t pc, const SymbolContext *sc_ptr)
77 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
Saleem Abdulrasoolbb19a132016-05-19 05:13:5778 m_concrete_frame_index(unwind_frame_index),
Kate Stoneb9c1b512016-09-06 20:57:5079 m_reg_context_sp(reg_context_sp), m_id(pc, cfa, nullptr),
80 m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(),
Vedant Kumar4b36f792018-10-05 23:23:1581 m_frame_base_error(), m_cfa_is_valid(true),
82 m_stack_frame_kind(StackFrame::Kind::Regular), m_variable_list_sp(),
Kuba Mracek41ae8e72018-10-31 04:00:2283 m_variable_list_value_objects(), m_recognized_frame_sp(), m_disassembly(),
84 m_mutex() {
Kate Stoneb9c1b512016-09-06 20:57:5085 if (sc_ptr != nullptr) {
86 m_sc = *sc_ptr;
87 m_flags.Set(m_sc.GetResolvedMask());
88 }
Saleem Abdulrasoolbb19a132016-05-19 05:13:5789
Kate Stoneb9c1b512016-09-06 20:57:5090 if (reg_context_sp && !m_sc.target_sp) {
91 m_sc.target_sp = reg_context_sp->CalculateTarget();
92 if (m_sc.target_sp)
93 m_flags.Set(eSymbolContextTarget);
94 }
Greg Clayton1b72fcb2010-08-24 00:45:4195}
96
Kate Stoneb9c1b512016-09-06 20:57:5097StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
98 user_id_t unwind_frame_index,
99 const RegisterContextSP &reg_context_sp, addr_t cfa,
100 const Address &pc_addr, const SymbolContext *sc_ptr)
101 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
Saleem Abdulrasoolbb19a132016-05-19 05:13:57102 m_concrete_frame_index(unwind_frame_index),
103 m_reg_context_sp(reg_context_sp),
Kate Stoneb9c1b512016-09-06 20:57:50104 m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa,
105 nullptr),
106 m_frame_code_addr(pc_addr), m_sc(), m_flags(), m_frame_base(),
Vedant Kumar4b36f792018-10-05 23:23:15107 m_frame_base_error(), m_cfa_is_valid(true),
108 m_stack_frame_kind(StackFrame::Kind::Regular), m_variable_list_sp(),
Kuba Mracek41ae8e72018-10-31 04:00:22109 m_variable_list_value_objects(), m_recognized_frame_sp(), m_disassembly(),
110 m_mutex() {
Kate Stoneb9c1b512016-09-06 20:57:50111 if (sc_ptr != nullptr) {
112 m_sc = *sc_ptr;
113 m_flags.Set(m_sc.GetResolvedMask());
114 }
Saleem Abdulrasoolbb19a132016-05-19 05:13:57115
Kate Stoneb9c1b512016-09-06 20:57:50116 if (!m_sc.target_sp && reg_context_sp) {
117 m_sc.target_sp = reg_context_sp->CalculateTarget();
118 if (m_sc.target_sp)
119 m_flags.Set(eSymbolContextTarget);
120 }
Saleem Abdulrasoolbb19a132016-05-19 05:13:57121
Kate Stoneb9c1b512016-09-06 20:57:50122 ModuleSP pc_module_sp(pc_addr.GetModule());
123 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) {
124 if (pc_module_sp) {
125 m_sc.module_sp = pc_module_sp;
126 m_flags.Set(eSymbolContextModule);
127 } else {
128 m_sc.module_sp.reset();
Greg Clayton1b72fcb2010-08-24 00:45:41129 }
Kate Stoneb9c1b512016-09-06 20:57:50130 }
Chris Lattner30fdc8d2010-06-08 16:52:24131}
132
Eugene Zelenkod70a6e72016-02-18 18:52:47133StackFrame::~StackFrame() = default;
Chris Lattner30fdc8d2010-06-08 16:52:24134
Kate Stoneb9c1b512016-09-06 20:57:50135StackID &StackFrame::GetStackID() {
136 std::lock_guard<std::recursive_mutex> guard(m_mutex);
Adrian Prantl05097242018-04-30 16:49:04137 // Make sure we have resolved the StackID object's symbol context scope if we
138 // already haven't looked it up.
Chris Lattner30fdc8d2010-06-08 16:52:24139
Kate Stoneb9c1b512016-09-06 20:57:50140 if (m_flags.IsClear(RESOLVED_FRAME_ID_SYMBOL_SCOPE)) {
141 if (m_id.GetSymbolContextScope()) {
Adrian Prantl05097242018-04-30 16:49:04142 // We already have a symbol context scope, we just don't have our flag
143 // bit set.
Kate Stoneb9c1b512016-09-06 20:57:50144 m_flags.Set(RESOLVED_FRAME_ID_SYMBOL_SCOPE);
145 } else {
Adrian Prantl05097242018-04-30 16:49:04146 // Calculate the frame block and use this for the stack ID symbol context
147 // scope if we have one.
Kate Stoneb9c1b512016-09-06 20:57:50148 SymbolContextScope *scope = GetFrameBlock();
149 if (scope == nullptr) {
150 // We don't have a block, so use the symbol
151 if (m_flags.IsClear(eSymbolContextSymbol))
152 GetSymbolContext(eSymbolContextSymbol);
153
154 // It is ok if m_sc.symbol is nullptr here
155 scope = m_sc.symbol;
156 }
157 // Set the symbol context scope (the accessor will set the
158 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
159 SetSymbolContextScope(scope);
Chris Lattner30fdc8d2010-06-08 16:52:24160 }
Kate Stoneb9c1b512016-09-06 20:57:50161 }
162 return m_id;
Chris Lattner30fdc8d2010-06-08 16:52:24163}
164
Kate Stoneb9c1b512016-09-06 20:57:50165uint32_t StackFrame::GetFrameIndex() const {
166 ThreadSP thread_sp = GetThread();
167 if (thread_sp)
168 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(
169 m_frame_index);
170 else
171 return m_frame_index;
Jim Ingham513c6bb2012-09-01 01:02:41172}
173
Kate Stoneb9c1b512016-09-06 20:57:50174void StackFrame::SetSymbolContextScope(SymbolContextScope *symbol_scope) {
175 std::lock_guard<std::recursive_mutex> guard(m_mutex);
176 m_flags.Set(RESOLVED_FRAME_ID_SYMBOL_SCOPE);
177 m_id.SetSymbolContextScope(symbol_scope);
Greg Clayton59e8fc1c2010-08-30 18:11:35178}
179
Kate Stoneb9c1b512016-09-06 20:57:50180const Address &StackFrame::GetFrameCodeAddress() {
181 std::lock_guard<std::recursive_mutex> guard(m_mutex);
182 if (m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR) &&
183 !m_frame_code_addr.IsSectionOffset()) {
184 m_flags.Set(RESOLVED_FRAME_CODE_ADDR);
Chris Lattner30fdc8d2010-06-08 16:52:24185
Kate Stoneb9c1b512016-09-06 20:57:50186 // Resolve the PC into a temporary address because if ResolveLoadAddress
187 // fails to resolve the address, it will clear the address object...
188 ThreadSP thread_sp(GetThread());
189 if (thread_sp) {
190 TargetSP target_sp(thread_sp->CalculateTarget());
191 if (target_sp) {
Pavel Labathc3c72122017-06-08 13:26:35192 const bool allow_section_end = true;
Kate Stoneb9c1b512016-09-06 20:57:50193 if (m_frame_code_addr.SetOpcodeLoadAddress(
194 m_frame_code_addr.GetOffset(), target_sp.get(),
Tatyana Krasnukha04803b32018-06-26 13:06:54195 AddressClass::eCode, allow_section_end)) {
Kate Stoneb9c1b512016-09-06 20:57:50196 ModuleSP module_sp(m_frame_code_addr.GetModule());
197 if (module_sp) {
198 m_sc.module_sp = module_sp;
199 m_flags.Set(eSymbolContextModule);
200 }
Chris Lattner30fdc8d2010-06-08 16:52:24201 }
Kate Stoneb9c1b512016-09-06 20:57:50202 }
Chris Lattner30fdc8d2010-06-08 16:52:24203 }
Kate Stoneb9c1b512016-09-06 20:57:50204 }
205 return m_frame_code_addr;
Chris Lattner30fdc8d2010-06-08 16:52:24206}
207
Kate Stoneb9c1b512016-09-06 20:57:50208bool StackFrame::ChangePC(addr_t pc) {
209 std::lock_guard<std::recursive_mutex> guard(m_mutex);
210 // We can't change the pc value of a history stack frame - it is immutable.
Vedant Kumar4b36f792018-10-05 23:23:15211 if (IsHistorical())
Kate Stoneb9c1b512016-09-06 20:57:50212 return false;
213 m_frame_code_addr.SetRawAddress(pc);
214 m_sc.Clear(false);
215 m_flags.Reset(0);
216 ThreadSP thread_sp(GetThread());
217 if (thread_sp)
218 thread_sp->ClearStackFrames();
219 return true;
Chris Lattner30fdc8d2010-06-08 16:52:24220}
221
Kate Stoneb9c1b512016-09-06 20:57:50222const char *StackFrame::Disassemble() {
223 std::lock_guard<std::recursive_mutex> guard(m_mutex);
Zachary Turner8b3f21602017-02-28 17:59:59224 if (m_disassembly.Empty()) {
225 ExecutionContext exe_ctx(shared_from_this());
226 Target *target = exe_ctx.GetTargetPtr();
227 if (target) {
228 const char *plugin_name = nullptr;
229 const char *flavor = nullptr;
230 Disassembler::Disassemble(target->GetDebugger(),
231 target->GetArchitecture(), plugin_name, flavor,
232 exe_ctx, 0, false, 0, 0, m_disassembly);
233 }
234 if (m_disassembly.Empty())
235 return nullptr;
Kate Stoneb9c1b512016-09-06 20:57:50236 }
Zachary Turner8b3f21602017-02-28 17:59:59237
Kate Stoneb9c1b512016-09-06 20:57:50238 return m_disassembly.GetData();
Chris Lattner30fdc8d2010-06-08 16:52:24239}
240
Kate Stoneb9c1b512016-09-06 20:57:50241Block *StackFrame::GetFrameBlock() {
242 if (m_sc.block == nullptr && m_flags.IsClear(eSymbolContextBlock))
243 GetSymbolContext(eSymbolContextBlock);
Greg Clayton95897c62010-09-07 04:20:48244
Kate Stoneb9c1b512016-09-06 20:57:50245 if (m_sc.block) {
246 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
247 if (inline_block) {
Adrian Prantl05097242018-04-30 16:49:04248 // Use the block with the inlined function info as the frame block we
249 // want this frame to have only the variables for the inlined function
250 // and its non-inlined block child blocks.
Kate Stoneb9c1b512016-09-06 20:57:50251 return inline_block;
252 } else {
Adrian Prantl05097242018-04-30 16:49:04253 // This block is not contained within any inlined function blocks with so
254 // we want to use the top most function block.
Kate Stoneb9c1b512016-09-06 20:57:50255 return &m_sc.function->GetBlock(false);
256 }
257 }
258 return nullptr;
Greg Clayton95897c62010-09-07 04:20:48259}
260
Chris Lattner30fdc8d2010-06-08 16:52:24261//----------------------------------------------------------------------
262// Get the symbol context if we already haven't done so by resolving the
263// PC address as much as possible. This way when we pass around a
Adrian Prantl05097242018-04-30 16:49:04264// StackFrame object, everyone will have as much information as possible and no
265// one will ever have to look things up manually.
Chris Lattner30fdc8d2010-06-08 16:52:24266//----------------------------------------------------------------------
Zachary Turner991e4452018-10-25 20:45:19267const SymbolContext &
268StackFrame::GetSymbolContext(SymbolContextItem resolve_scope) {
Kate Stoneb9c1b512016-09-06 20:57:50269 std::lock_guard<std::recursive_mutex> guard(m_mutex);
270 // Copy our internal symbol context into "sc".
271 if ((m_flags.Get() & resolve_scope) != resolve_scope) {
272 uint32_t resolved = 0;
Greg Clayton75a03332012-11-29 00:53:06273
Kate Stoneb9c1b512016-09-06 20:57:50274 // If the target was requested add that:
275 if (!m_sc.target_sp) {
276 m_sc.target_sp = CalculateTarget();
277 if (m_sc.target_sp)
278 resolved |= eSymbolContextTarget;
Chris Lattner30fdc8d2010-06-08 16:52:24279 }
280
Adrian Prantl05097242018-04-30 16:49:04281 // Resolve our PC to section offset if we haven't already done so and if we
282 // don't have a module. The resolved address section will contain the
283 // module to which it belongs
Kate Stoneb9c1b512016-09-06 20:57:50284 if (!m_sc.module_sp && m_flags.IsClear(RESOLVED_FRAME_CODE_ADDR))
285 GetFrameCodeAddress();
286
Adrian Prantl05097242018-04-30 16:49:04287 // If this is not frame zero, then we need to subtract 1 from the PC value
288 // when doing address lookups since the PC will be on the instruction
289 // following the function call instruction...
Kate Stoneb9c1b512016-09-06 20:57:50290
291 Address lookup_addr(GetFrameCodeAddress());
292 if (m_frame_index > 0 && lookup_addr.IsValid()) {
293 addr_t offset = lookup_addr.GetOffset();
294 if (offset > 0) {
295 lookup_addr.SetOffset(offset - 1);
296
297 } else {
Adrian Prantl05097242018-04-30 16:49:04298 // lookup_addr is the start of a section. We need do the math on the
299 // actual load address and re-compute the section. We're working with
300 // a 'noreturn' function at the end of a section.
Kate Stoneb9c1b512016-09-06 20:57:50301 ThreadSP thread_sp(GetThread());
302 if (thread_sp) {
303 TargetSP target_sp(thread_sp->CalculateTarget());
304 if (target_sp) {
305 addr_t addr_minus_one =
306 lookup_addr.GetLoadAddress(target_sp.get()) - 1;
307 lookup_addr.SetLoadAddress(addr_minus_one, target_sp.get());
308 } else {
309 lookup_addr.SetOffset(offset - 1);
310 }
311 }
312 }
313 }
314
315 if (m_sc.module_sp) {
Adrian Prantl05097242018-04-30 16:49:04316 // We have something in our stack frame symbol context, lets check if we
317 // haven't already tried to lookup one of those things. If we haven't
318 // then we will do the query.
Kate Stoneb9c1b512016-09-06 20:57:50319
Zachary Turner991e4452018-10-25 20:45:19320 SymbolContextItem actual_resolve_scope = SymbolContextItem(0);
Kate Stoneb9c1b512016-09-06 20:57:50321
322 if (resolve_scope & eSymbolContextCompUnit) {
323 if (m_flags.IsClear(eSymbolContextCompUnit)) {
324 if (m_sc.comp_unit)
325 resolved |= eSymbolContextCompUnit;
326 else
327 actual_resolve_scope |= eSymbolContextCompUnit;
328 }
329 }
330
331 if (resolve_scope & eSymbolContextFunction) {
332 if (m_flags.IsClear(eSymbolContextFunction)) {
333 if (m_sc.function)
334 resolved |= eSymbolContextFunction;
335 else
336 actual_resolve_scope |= eSymbolContextFunction;
337 }
338 }
339
340 if (resolve_scope & eSymbolContextBlock) {
341 if (m_flags.IsClear(eSymbolContextBlock)) {
342 if (m_sc.block)
343 resolved |= eSymbolContextBlock;
344 else
345 actual_resolve_scope |= eSymbolContextBlock;
346 }
347 }
348
349 if (resolve_scope & eSymbolContextSymbol) {
350 if (m_flags.IsClear(eSymbolContextSymbol)) {
351 if (m_sc.symbol)
352 resolved |= eSymbolContextSymbol;
353 else
354 actual_resolve_scope |= eSymbolContextSymbol;
355 }
356 }
357
358 if (resolve_scope & eSymbolContextLineEntry) {
359 if (m_flags.IsClear(eSymbolContextLineEntry)) {
360 if (m_sc.line_entry.IsValid())
361 resolved |= eSymbolContextLineEntry;
362 else
363 actual_resolve_scope |= eSymbolContextLineEntry;
364 }
365 }
366
367 if (actual_resolve_scope) {
Adrian Prantl05097242018-04-30 16:49:04368 // We might be resolving less information than what is already in our
369 // current symbol context so resolve into a temporary symbol context
370 // "sc" so we don't clear out data we have already found in "m_sc"
Kate Stoneb9c1b512016-09-06 20:57:50371 SymbolContext sc;
372 // Set flags that indicate what we have tried to resolve
373 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress(
374 lookup_addr, actual_resolve_scope, sc);
Adrian Prantl05097242018-04-30 16:49:04375 // Only replace what we didn't already have as we may have information
376 // for an inlined function scope that won't match what a standard
377 // lookup by address would match
Kate Stoneb9c1b512016-09-06 20:57:50378 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == nullptr)
379 m_sc.comp_unit = sc.comp_unit;
380 if ((resolved & eSymbolContextFunction) && m_sc.function == nullptr)
381 m_sc.function = sc.function;
382 if ((resolved & eSymbolContextBlock) && m_sc.block == nullptr)
383 m_sc.block = sc.block;
384 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == nullptr)
385 m_sc.symbol = sc.symbol;
386 if ((resolved & eSymbolContextLineEntry) &&
387 !m_sc.line_entry.IsValid()) {
388 m_sc.line_entry = sc.line_entry;
389 m_sc.line_entry.ApplyFileMappings(m_sc.target_sp);
390 }
391 }
392 } else {
393 // If we don't have a module, then we can't have the compile unit,
394 // function, block, line entry or symbol, so we can safely call
395 // ResolveSymbolContextForAddress with our symbol context member m_sc.
396 if (m_sc.target_sp) {
397 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress(
398 lookup_addr, resolve_scope, m_sc);
399 }
400 }
401
402 // Update our internal flags so we remember what we have tried to locate so
403 // we don't have to keep trying when more calls to this function are made.
Adrian Prantl05097242018-04-30 16:49:04404 // We might have dug up more information that was requested (for example if
405 // we were asked to only get the block, we will have gotten the compile
406 // unit, and function) so set any additional bits that we resolved
Kate Stoneb9c1b512016-09-06 20:57:50407 m_flags.Set(resolve_scope | resolved);
408 }
409
410 // Return the symbol context with everything that was possible to resolve
411 // resolved.
412 return m_sc;
Chris Lattner30fdc8d2010-06-08 16:52:24413}
414
Kate Stoneb9c1b512016-09-06 20:57:50415VariableList *StackFrame::GetVariableList(bool get_file_globals) {
416 std::lock_guard<std::recursive_mutex> guard(m_mutex);
417 if (m_flags.IsClear(RESOLVED_VARIABLES)) {
418 m_flags.Set(RESOLVED_VARIABLES);
Chris Lattner30fdc8d2010-06-08 16:52:24419
Kate Stoneb9c1b512016-09-06 20:57:50420 Block *frame_block = GetFrameBlock();
421
422 if (frame_block) {
423 const bool get_child_variables = true;
424 const bool can_create = true;
425 const bool stop_if_child_block_is_inlined_function = true;
426 m_variable_list_sp.reset(new VariableList());
427 frame_block->AppendBlockVariables(can_create, get_child_variables,
428 stop_if_child_block_is_inlined_function,
Zachary Turner3bc714b2017-03-02 00:05:25429 [](Variable *v) { return true; },
Kate Stoneb9c1b512016-09-06 20:57:50430 m_variable_list_sp.get());
Sean Callanan7c0962d2010-11-01 04:38:59431 }
Kate Stoneb9c1b512016-09-06 20:57:50432 }
433
434 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && get_file_globals) {
435 m_flags.Set(RESOLVED_GLOBAL_VARIABLES);
436
437 if (m_flags.IsClear(eSymbolContextCompUnit))
438 GetSymbolContext(eSymbolContextCompUnit);
439
440 if (m_sc.comp_unit) {
441 VariableListSP global_variable_list_sp(
442 m_sc.comp_unit->GetVariableList(true));
443 if (m_variable_list_sp)
444 m_variable_list_sp->AddVariables(global_variable_list_sp.get());
445 else
446 m_variable_list_sp = global_variable_list_sp;
Chris Lattner30fdc8d2010-06-08 16:52:24447 }
Kate Stoneb9c1b512016-09-06 20:57:50448 }
449
450 return m_variable_list_sp.get();
Chris Lattner30fdc8d2010-06-08 16:52:24451}
452
Greg Claytond41f0322011-08-02 23:35:43453VariableListSP
Kate Stoneb9c1b512016-09-06 20:57:50454StackFrame::GetInScopeVariableList(bool get_file_globals,
455 bool must_have_valid_location) {
456 std::lock_guard<std::recursive_mutex> guard(m_mutex);
457 // We can't fetch variable information for a history stack frame.
Vedant Kumar4b36f792018-10-05 23:23:15458 if (IsHistorical())
Kate Stoneb9c1b512016-09-06 20:57:50459 return VariableListSP();
Jason Molenda99618472013-11-04 11:02:52460
Kate Stoneb9c1b512016-09-06 20:57:50461 VariableListSP var_list_sp(new VariableList);
462 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextBlock);
Greg Claytond41f0322011-08-02 23:35:43463
Kate Stoneb9c1b512016-09-06 20:57:50464 if (m_sc.block) {
465 const bool can_create = true;
466 const bool get_parent_variables = true;
467 const bool stop_if_block_is_inlined_function = true;
468 m_sc.block->AppendVariables(
469 can_create, get_parent_variables, stop_if_block_is_inlined_function,
470 [this, must_have_valid_location](Variable *v) {
471 return v->IsInScope(this) && (!must_have_valid_location ||
472 v->LocationIsValidForFrame(this));
473 },
474 var_list_sp.get());
475 }
476
477 if (m_sc.comp_unit && get_file_globals) {
478 VariableListSP global_variable_list_sp(
479 m_sc.comp_unit->GetVariableList(true));
480 if (global_variable_list_sp)
481 var_list_sp->AddVariables(global_variable_list_sp.get());
482 }
483
484 return var_list_sp;
Greg Claytond41f0322011-08-02 23:35:43485}
486
Kate Stoneb9c1b512016-09-06 20:57:50487ValueObjectSP StackFrame::GetValueForVariableExpressionPath(
Zachary Turner0eb31a12016-11-17 05:14:32488 llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options,
Zachary Turner97206d52017-05-12 04:51:55489 VariableSP &var_sp, Status &error) {
Zachary Turner0eb31a12016-11-17 05:14:32490 llvm::StringRef original_var_expr = var_expr;
Kate Stoneb9c1b512016-09-06 20:57:50491 // We can't fetch variable information for a history stack frame.
Vedant Kumar4b36f792018-10-05 23:23:15492 if (IsHistorical())
Greg Clayton8b2fe6d2010-12-14 02:59:59493 return ValueObjectSP();
Chris Lattner30fdc8d2010-06-08 16:52:24494
Zachary Turner0eb31a12016-11-17 05:14:32495 if (var_expr.empty()) {
496 error.SetErrorStringWithFormat("invalid variable path '%s'",
497 var_expr.str().c_str());
Zachary Turner24bd3172016-11-17 01:37:52498 return ValueObjectSP();
499 }
Kate Stoneb9c1b512016-09-06 20:57:50500
Zachary Turner24bd3172016-11-17 01:37:52501 const bool check_ptr_vs_member =
502 (options & eExpressionPathOptionCheckPtrVsMember) != 0;
503 const bool no_fragile_ivar =
504 (options & eExpressionPathOptionsNoFragileObjcIvar) != 0;
505 const bool no_synth_child =
506 (options & eExpressionPathOptionsNoSyntheticChildren) != 0;
507 // const bool no_synth_array = (options &
508 // eExpressionPathOptionsNoSyntheticArrayRange) != 0;
509 error.Clear();
510 bool deref = false;
511 bool address_of = false;
512 ValueObjectSP valobj_sp;
513 const bool get_file_globals = true;
514 // When looking up a variable for an expression, we need only consider the
515 // variables that are in scope.
516 VariableListSP var_list_sp(GetInScopeVariableList(get_file_globals));
517 VariableList *variable_list = var_list_sp.get();
Kate Stoneb9c1b512016-09-06 20:57:50518
Zachary Turner24bd3172016-11-17 01:37:52519 if (!variable_list)
520 return ValueObjectSP();
Kate Stoneb9c1b512016-09-06 20:57:50521
Zachary Turner24bd3172016-11-17 01:37:52522 // If first character is a '*', then show pointer contents
Zachary Turner24bd3172016-11-17 01:37:52523 std::string var_expr_storage;
524 if (var_expr[0] == '*') {
525 deref = true;
526 var_expr = var_expr.drop_front(); // Skip the '*'
527 } else if (var_expr[0] == '&') {
528 address_of = true;
529 var_expr = var_expr.drop_front(); // Skip the '&'
530 }
Kate Stoneb9c1b512016-09-06 20:57:50531
Zachary Turner24bd3172016-11-17 01:37:52532 size_t separator_idx = var_expr.find_first_of(".-[=+~|&^%#@!/?,<>{}");
533 StreamString var_expr_path_strm;
Kate Stoneb9c1b512016-09-06 20:57:50534
Zachary Turner24bd3172016-11-17 01:37:52535 ConstString name_const_string(var_expr.substr(0, separator_idx));
Kate Stoneb9c1b512016-09-06 20:57:50536
Zachary Turner24bd3172016-11-17 01:37:52537 var_sp = variable_list->FindVariable(name_const_string, false);
Kate Stoneb9c1b512016-09-06 20:57:50538
Zachary Turner24bd3172016-11-17 01:37:52539 bool synthetically_added_instance_object = false;
540
541 if (var_sp) {
542 var_expr = var_expr.drop_front(name_const_string.GetLength());
543 }
544
545 if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) {
Adrian Prantl05097242018-04-30 16:49:04546 // Check for direct ivars access which helps us with implicit access to
547 // ivars with the "this->" or "self->"
Zachary Turner24bd3172016-11-17 01:37:52548 GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock);
549 lldb::LanguageType method_language = eLanguageTypeUnknown;
550 bool is_instance_method = false;
551 ConstString method_object_name;
552 if (m_sc.GetFunctionMethodInfo(method_language, is_instance_method,
553 method_object_name)) {
554 if (is_instance_method && method_object_name) {
555 var_sp = variable_list->FindVariable(method_object_name);
556 if (var_sp) {
557 separator_idx = 0;
558 var_expr_storage = "->";
559 var_expr_storage += var_expr;
560 var_expr = var_expr_storage;
561 synthetically_added_instance_object = true;
Greg Clayton288bdf92010-09-02 02:59:18562 }
Kate Stoneb9c1b512016-09-06 20:57:50563 }
Zachary Turner24bd3172016-11-17 01:37:52564 }
565 }
Kate Stoneb9c1b512016-09-06 20:57:50566
Zachary Turner24bd3172016-11-17 01:37:52567 if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) {
568 // Check if any anonymous unions are there which contain a variable with
569 // the name we need
570 for (size_t i = 0; i < variable_list->GetSize(); i++) {
571 VariableSP variable_sp = variable_list->GetVariableAtIndex(i);
572 if (!variable_sp)
573 continue;
574 if (!variable_sp->GetName().IsEmpty())
575 continue;
576
577 Type *var_type = variable_sp->GetType();
578 if (!var_type)
579 continue;
580
581 if (!var_type->GetForwardCompilerType().IsAnonymousType())
582 continue;
583 valobj_sp = GetValueObjectForFrameVariable(variable_sp, use_dynamic);
584 if (!valobj_sp)
585 return valobj_sp;
586 valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string, true);
587 if (valobj_sp)
588 break;
589 }
590 }
591
592 if (var_sp && !valobj_sp) {
593 valobj_sp = GetValueObjectForFrameVariable(var_sp, use_dynamic);
594 if (!valobj_sp)
595 return valobj_sp;
596 }
597 if (!valobj_sp) {
598 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
599 name_const_string.GetCString());
600 return ValueObjectSP();
601 }
602
603 // We are dumping at least one child
604 while (separator_idx != std::string::npos) {
605 // Calculate the next separator index ahead of time
606 ValueObjectSP child_valobj_sp;
607 const char separator_type = var_expr[0];
Tamas Berghammer4c08fe22017-03-31 20:23:22608 bool expr_is_ptr = false;
Zachary Turner24bd3172016-11-17 01:37:52609 switch (separator_type) {
610 case '-':
Tamas Berghammer4c08fe22017-03-31 20:23:22611 expr_is_ptr = true;
Zachary Turner24bd3172016-11-17 01:37:52612 if (var_expr.size() >= 2 && var_expr[1] != '>')
613 return ValueObjectSP();
614
615 if (no_fragile_ivar) {
616 // Make sure we aren't trying to deref an objective
617 // C ivar if this is not allowed
618 const uint32_t pointer_type_flags =
619 valobj_sp->GetCompilerType().GetTypeInfo(nullptr);
620 if ((pointer_type_flags & eTypeIsObjC) &&
621 (pointer_type_flags & eTypeIsPointer)) {
Adrian Prantl05097242018-04-30 16:49:04622 // This was an objective C object pointer and it was requested we
623 // skip any fragile ivars so return nothing here
Zachary Turner24bd3172016-11-17 01:37:52624 return ValueObjectSP();
Kate Stoneb9c1b512016-09-06 20:57:50625 }
626 }
Tamas Berghammer4c08fe22017-03-31 20:23:22627
628 // If we have a non pointer type with a sythetic value then lets check if
629 // we have an sythetic dereference specified.
630 if (!valobj_sp->IsPointerType() && valobj_sp->HasSyntheticValue()) {
Zachary Turner97206d52017-05-12 04:51:55631 Status deref_error;
Tamas Berghammer4c08fe22017-03-31 20:23:22632 if (valobj_sp->GetCompilerType().IsReferenceType()) {
633 valobj_sp = valobj_sp->GetSyntheticValue()->Dereference(deref_error);
634 if (error.Fail()) {
635 error.SetErrorStringWithFormatv(
636 "Failed to dereference reference type: %s", deref_error);
637 return ValueObjectSP();
638 }
639 }
640
641 valobj_sp = valobj_sp->Dereference(deref_error);
642 if (error.Fail()) {
643 error.SetErrorStringWithFormatv(
644 "Failed to dereference sythetic value: %s", deref_error);
645 return ValueObjectSP();
646 }
647 expr_is_ptr = false;
648 }
649
Zachary Turner24bd3172016-11-17 01:37:52650 var_expr = var_expr.drop_front(); // Remove the '-'
651 LLVM_FALLTHROUGH;
652 case '.': {
Zachary Turner24bd3172016-11-17 01:37:52653 var_expr = var_expr.drop_front(); // Remove the '.' or '>'
654 separator_idx = var_expr.find_first_of(".-[");
655 ConstString child_name(var_expr.substr(0, var_expr.find_first_of(".-[")));
656
657 if (check_ptr_vs_member) {
Adrian Prantl05097242018-04-30 16:49:04658 // We either have a pointer type and need to verify valobj_sp is a
659 // pointer, or we have a member of a class/union/struct being accessed
660 // with the . syntax and need to verify we don't have a pointer.
Zachary Turner24bd3172016-11-17 01:37:52661 const bool actual_is_ptr = valobj_sp->IsPointerType();
662
663 if (actual_is_ptr != expr_is_ptr) {
Adrian Prantl05097242018-04-30 16:49:04664 // Incorrect use of "." with a pointer, or "->" with a
665 // class/union/struct instance or reference.
Zachary Turner24bd3172016-11-17 01:37:52666 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
667 if (actual_is_ptr)
668 error.SetErrorStringWithFormat(
669 "\"%s\" is a pointer and . was used to attempt to access "
670 "\"%s\". Did you mean \"%s->%s\"?",
671 var_expr_path_strm.GetData(), child_name.GetCString(),
672 var_expr_path_strm.GetData(), var_expr.str().c_str());
673 else
674 error.SetErrorStringWithFormat(
675 "\"%s\" is not a pointer and -> was used to attempt to "
676 "access \"%s\". Did you mean \"%s.%s\"?",
677 var_expr_path_strm.GetData(), child_name.GetCString(),
678 var_expr_path_strm.GetData(), var_expr.str().c_str());
679 return ValueObjectSP();
680 }
Kate Stoneb9c1b512016-09-06 20:57:50681 }
Zachary Turner24bd3172016-11-17 01:37:52682 child_valobj_sp = valobj_sp->GetChildMemberWithName(child_name, true);
683 if (!child_valobj_sp) {
684 if (!no_synth_child) {
685 child_valobj_sp = valobj_sp->GetSyntheticValue();
686 if (child_valobj_sp)
Kate Stoneb9c1b512016-09-06 20:57:50687 child_valobj_sp =
Zachary Turner24bd3172016-11-17 01:37:52688 child_valobj_sp->GetChildMemberWithName(child_name, true);
689 }
Kate Stoneb9c1b512016-09-06 20:57:50690
Zachary Turner24bd3172016-11-17 01:37:52691 if (no_synth_child || !child_valobj_sp) {
692 // No child member with name "child_name"
693 if (synthetically_added_instance_object) {
694 // We added a "this->" or "self->" to the beginning of the
Adrian Prantl05097242018-04-30 16:49:04695 // expression and this is the first pointer ivar access, so just
696 // return the normal error
Zachary Turner24bd3172016-11-17 01:37:52697 error.SetErrorStringWithFormat(
698 "no variable or instance variable named '%s' found in "
699 "this frame",
700 name_const_string.GetCString());
701 } else {
702 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
703 if (child_name) {
704 error.SetErrorStringWithFormat(
705 "\"%s\" is not a member of \"(%s) %s\"",
706 child_name.GetCString(),
707 valobj_sp->GetTypeName().AsCString("<invalid type>"),
708 var_expr_path_strm.GetData());
Kate Stoneb9c1b512016-09-06 20:57:50709 } else {
710 error.SetErrorStringWithFormat(
Zachary Turner24bd3172016-11-17 01:37:52711 "incomplete expression path after \"%s\" in \"%s\"",
Zachary Turner0eb31a12016-11-17 05:14:32712 var_expr_path_strm.GetData(),
713 original_var_expr.str().c_str());
Kate Stoneb9c1b512016-09-06 20:57:50714 }
Zachary Turner24bd3172016-11-17 01:37:52715 }
716 return ValueObjectSP();
717 }
718 }
719 synthetically_added_instance_object = false;
720 // Remove the child name from the path
721 var_expr = var_expr.drop_front(child_name.GetLength());
722 if (use_dynamic != eNoDynamicValues) {
723 ValueObjectSP dynamic_value_sp(
724 child_valobj_sp->GetDynamicValue(use_dynamic));
725 if (dynamic_value_sp)
726 child_valobj_sp = dynamic_value_sp;
727 }
728 } break;
Kate Stoneb9c1b512016-09-06 20:57:50729
Zachary Turner24bd3172016-11-17 01:37:52730 case '[': {
Adrian Prantl05097242018-04-30 16:49:04731 // Array member access, or treating pointer as an array Need at least two
732 // brackets and a number
Zachary Turner24bd3172016-11-17 01:37:52733 if (var_expr.size() <= 2) {
734 error.SetErrorStringWithFormat(
735 "invalid square bracket encountered after \"%s\" in \"%s\"",
736 var_expr_path_strm.GetData(), var_expr.str().c_str());
737 return ValueObjectSP();
738 }
739
740 // Drop the open brace.
741 var_expr = var_expr.drop_front();
742 long child_index = 0;
743
744 // If there's no closing brace, this is an invalid expression.
745 size_t end_pos = var_expr.find_first_of(']');
746 if (end_pos == llvm::StringRef::npos) {
747 error.SetErrorStringWithFormat(
748 "missing closing square bracket in expression \"%s\"",
749 var_expr_path_strm.GetData());
750 return ValueObjectSP();
751 }
752 llvm::StringRef index_expr = var_expr.take_front(end_pos);
753 llvm::StringRef original_index_expr = index_expr;
754 // Drop all of "[index_expr]"
755 var_expr = var_expr.drop_front(end_pos + 1);
756
757 if (index_expr.consumeInteger(0, child_index)) {
758 // If there was no integer anywhere in the index expression, this is
759 // erroneous expression.
760 error.SetErrorStringWithFormat("invalid index expression \"%s\"",
761 index_expr.str().c_str());
762 return ValueObjectSP();
763 }
764
765 if (index_expr.empty()) {
766 // The entire index expression was a single integer.
767
768 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) {
769 // what we have is *ptr[low]. the most similar C++ syntax is to deref
770 // ptr and extract bit low out of it. reading array item low would be
771 // done by saying ptr[low], without a deref * sign
Zachary Turner97206d52017-05-12 04:51:55772 Status error;
Zachary Turner24bd3172016-11-17 01:37:52773 ValueObjectSP temp(valobj_sp->Dereference(error));
774 if (error.Fail()) {
775 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
776 error.SetErrorStringWithFormat(
777 "could not dereference \"(%s) %s\"",
778 valobj_sp->GetTypeName().AsCString("<invalid type>"),
779 var_expr_path_strm.GetData());
780 return ValueObjectSP();
781 }
782 valobj_sp = temp;
783 deref = false;
784 } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() &&
785 deref) {
Adrian Prantl05097242018-04-30 16:49:04786 // what we have is *arr[low]. the most similar C++ syntax is to get
787 // arr[0] (an operation that is equivalent to deref-ing arr) and
788 // extract bit low out of it. reading array item low would be done by
789 // saying arr[low], without a deref * sign
Zachary Turner97206d52017-05-12 04:51:55790 Status error;
Zachary Turner24bd3172016-11-17 01:37:52791 ValueObjectSP temp(valobj_sp->GetChildAtIndex(0, true));
792 if (error.Fail()) {
793 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
794 error.SetErrorStringWithFormat(
795 "could not get item 0 for \"(%s) %s\"",
796 valobj_sp->GetTypeName().AsCString("<invalid type>"),
797 var_expr_path_strm.GetData());
798 return ValueObjectSP();
799 }
800 valobj_sp = temp;
801 deref = false;
802 }
803
804 bool is_incomplete_array = false;
805 if (valobj_sp->IsPointerType()) {
806 bool is_objc_pointer = true;
807
808 if (valobj_sp->GetCompilerType().GetMinimumLanguage() !=
809 eLanguageTypeObjC)
810 is_objc_pointer = false;
811 else if (!valobj_sp->GetCompilerType().IsPointerType())
812 is_objc_pointer = false;
813
814 if (no_synth_child && is_objc_pointer) {
815 error.SetErrorStringWithFormat(
816 "\"(%s) %s\" is an Objective-C pointer, and cannot be "
817 "subscripted",
818 valobj_sp->GetTypeName().AsCString("<invalid type>"),
819 var_expr_path_strm.GetData());
820
821 return ValueObjectSP();
822 } else if (is_objc_pointer) {
Adrian Prantl05097242018-04-30 16:49:04823 // dereferencing ObjC variables is not valid.. so let's try and
824 // recur to synthetic children
Zachary Turner24bd3172016-11-17 01:37:52825 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
826 if (!synthetic /* no synthetic */
827 || synthetic == valobj_sp) /* synthetic is the same as
828 the original object */
Kate Stoneb9c1b512016-09-06 20:57:50829 {
830 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
831 error.SetErrorStringWithFormat(
Zachary Turner24bd3172016-11-17 01:37:52832 "\"(%s) %s\" is not an array type",
833 valobj_sp->GetTypeName().AsCString("<invalid type>"),
834 var_expr_path_strm.GetData());
835 } else if (
836 static_cast<uint32_t>(child_index) >=
837 synthetic
838 ->GetNumChildren() /* synthetic does not have that many values */) {
839 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
840 error.SetErrorStringWithFormat(
841 "array index %ld is not valid for \"(%s) %s\"", child_index,
842 valobj_sp->GetTypeName().AsCString("<invalid type>"),
843 var_expr_path_strm.GetData());
844 } else {
845 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
846 if (!child_valobj_sp) {
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 }
853 }
854 } else {
855 child_valobj_sp =
856 valobj_sp->GetSyntheticArrayMember(child_index, true);
857 if (!child_valobj_sp) {
858 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
859 error.SetErrorStringWithFormat(
860 "failed to use pointer as array for index %ld for "
861 "\"(%s) %s\"",
862 child_index,
863 valobj_sp->GetTypeName().AsCString("<invalid type>"),
864 var_expr_path_strm.GetData());
Kate Stoneb9c1b512016-09-06 20:57:50865 }
866 }
Zachary Turner24bd3172016-11-17 01:37:52867 } else if (valobj_sp->GetCompilerType().IsArrayType(
868 nullptr, nullptr, &is_incomplete_array)) {
Adrian Prantl05097242018-04-30 16:49:04869 // Pass false to dynamic_value here so we can tell the difference
870 // between no dynamic value and no member of this type...
Zachary Turner24bd3172016-11-17 01:37:52871 child_valobj_sp = valobj_sp->GetChildAtIndex(child_index, true);
872 if (!child_valobj_sp && (is_incomplete_array || !no_synth_child))
873 child_valobj_sp =
874 valobj_sp->GetSyntheticArrayMember(child_index, true);
Kate Stoneb9c1b512016-09-06 20:57:50875
Zachary Turner24bd3172016-11-17 01:37:52876 if (!child_valobj_sp) {
877 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
878 error.SetErrorStringWithFormat(
879 "array index %ld is not valid for \"(%s) %s\"", child_index,
880 valobj_sp->GetTypeName().AsCString("<invalid type>"),
881 var_expr_path_strm.GetData());
882 }
883 } else if (valobj_sp->GetCompilerType().IsScalarType()) {
884 // this is a bitfield asking to display just one bit
885 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(
886 child_index, child_index, true);
887 if (!child_valobj_sp) {
888 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
889 error.SetErrorStringWithFormat(
890 "bitfield range %ld-%ld is not valid for \"(%s) %s\"",
891 child_index, child_index,
892 valobj_sp->GetTypeName().AsCString("<invalid type>"),
893 var_expr_path_strm.GetData());
894 }
895 } else {
896 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
897 if (no_synth_child /* synthetic is forbidden */ ||
898 !synthetic /* no synthetic */
899 || synthetic == valobj_sp) /* synthetic is the same as the
900 original object */
901 {
902 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
903 error.SetErrorStringWithFormat(
904 "\"(%s) %s\" is not an array type",
905 valobj_sp->GetTypeName().AsCString("<invalid type>"),
906 var_expr_path_strm.GetData());
907 } else if (
908 static_cast<uint32_t>(child_index) >=
909 synthetic
910 ->GetNumChildren() /* synthetic does not have that many values */) {
911 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
912 error.SetErrorStringWithFormat(
913 "array index %ld is not valid for \"(%s) %s\"", child_index,
914 valobj_sp->GetTypeName().AsCString("<invalid type>"),
915 var_expr_path_strm.GetData());
916 } else {
917 child_valobj_sp = synthetic->GetChildAtIndex(child_index, true);
918 if (!child_valobj_sp) {
919 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
920 error.SetErrorStringWithFormat(
921 "array index %ld is not valid for \"(%s) %s\"", child_index,
922 valobj_sp->GetTypeName().AsCString("<invalid type>"),
923 var_expr_path_strm.GetData());
924 }
Kate Stoneb9c1b512016-09-06 20:57:50925 }
926 }
Zachary Turner24bd3172016-11-17 01:37:52927
928 if (!child_valobj_sp) {
929 // Invalid array index...
930 return ValueObjectSP();
931 }
932
933 separator_idx = var_expr.find_first_of(".-[");
934 if (use_dynamic != eNoDynamicValues) {
935 ValueObjectSP dynamic_value_sp(
936 child_valobj_sp->GetDynamicValue(use_dynamic));
937 if (dynamic_value_sp)
938 child_valobj_sp = dynamic_value_sp;
939 }
940 // Break out early from the switch since we were able to find the child
941 // member
942 break;
943 }
944
945 // this is most probably a BitField, let's take a look
946 if (index_expr.front() != '-') {
947 error.SetErrorStringWithFormat("invalid range expression \"'%s'\"",
948 original_index_expr.str().c_str());
949 return ValueObjectSP();
950 }
951
Zachary Turner7edc3a62016-11-21 23:18:13952 index_expr = index_expr.drop_front();
Zachary Turner24bd3172016-11-17 01:37:52953 long final_index = 0;
954 if (index_expr.getAsInteger(0, final_index)) {
955 error.SetErrorStringWithFormat("invalid range expression \"'%s'\"",
956 original_index_expr.str().c_str());
957 return ValueObjectSP();
958 }
959
960 // if the format given is [high-low], swap range
961 if (child_index > final_index) {
962 long temp = child_index;
963 child_index = final_index;
964 final_index = temp;
965 }
966
967 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) {
968 // what we have is *ptr[low-high]. the most similar C++ syntax is to
969 // deref ptr and extract bits low thru high out of it. reading array
Adrian Prantl05097242018-04-30 16:49:04970 // items low thru high would be done by saying ptr[low-high], without a
971 // deref * sign
Zachary Turner97206d52017-05-12 04:51:55972 Status error;
Zachary Turner24bd3172016-11-17 01:37:52973 ValueObjectSP temp(valobj_sp->Dereference(error));
974 if (error.Fail()) {
975 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
976 error.SetErrorStringWithFormat(
977 "could not dereference \"(%s) %s\"",
978 valobj_sp->GetTypeName().AsCString("<invalid type>"),
979 var_expr_path_strm.GetData());
980 return ValueObjectSP();
981 }
982 valobj_sp = temp;
983 deref = false;
984 } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) {
Adrian Prantl05097242018-04-30 16:49:04985 // what we have is *arr[low-high]. the most similar C++ syntax is to
986 // get arr[0] (an operation that is equivalent to deref-ing arr) and
987 // extract bits low thru high out of it. reading array items low thru
988 // high would be done by saying arr[low-high], without a deref * sign
Zachary Turner97206d52017-05-12 04:51:55989 Status error;
Zachary Turner24bd3172016-11-17 01:37:52990 ValueObjectSP temp(valobj_sp->GetChildAtIndex(0, true));
991 if (error.Fail()) {
992 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
993 error.SetErrorStringWithFormat(
994 "could not get item 0 for \"(%s) %s\"",
995 valobj_sp->GetTypeName().AsCString("<invalid type>"),
996 var_expr_path_strm.GetData());
997 return ValueObjectSP();
998 }
999 valobj_sp = temp;
1000 deref = false;
1001 }
1002
1003 child_valobj_sp =
1004 valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1005 if (!child_valobj_sp) {
1006 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
Kate Stoneb9c1b512016-09-06 20:57:501007 error.SetErrorStringWithFormat(
Zachary Turner24bd3172016-11-17 01:37:521008 "bitfield range %ld-%ld is not valid for \"(%s) %s\"", child_index,
1009 final_index, valobj_sp->GetTypeName().AsCString("<invalid type>"),
1010 var_expr_path_strm.GetData());
1011 }
1012
1013 if (!child_valobj_sp) {
1014 // Invalid bitfield range...
1015 return ValueObjectSP();
1016 }
1017
1018 separator_idx = var_expr.find_first_of(".-[");
1019 if (use_dynamic != eNoDynamicValues) {
1020 ValueObjectSP dynamic_value_sp(
1021 child_valobj_sp->GetDynamicValue(use_dynamic));
1022 if (dynamic_value_sp)
1023 child_valobj_sp = dynamic_value_sp;
1024 }
1025 // Break out early from the switch since we were able to find the child
1026 // member
1027 break;
1028 }
1029 default:
1030 // Failure...
1031 {
1032 valobj_sp->GetExpressionPath(var_expr_path_strm, false);
1033 error.SetErrorStringWithFormat(
1034 "unexpected char '%c' encountered after \"%s\" in \"%s\"",
1035 separator_type, var_expr_path_strm.GetData(),
1036 var_expr.str().c_str());
1037
1038 return ValueObjectSP();
Kate Stoneb9c1b512016-09-06 20:57:501039 }
Greg Clayton288bdf92010-09-02 02:59:181040 }
Zachary Turner24bd3172016-11-17 01:37:521041
1042 if (child_valobj_sp)
1043 valobj_sp = child_valobj_sp;
1044
1045 if (var_expr.empty())
1046 break;
Kate Stoneb9c1b512016-09-06 20:57:501047 }
Zachary Turner24bd3172016-11-17 01:37:521048 if (valobj_sp) {
1049 if (deref) {
1050 ValueObjectSP deref_valobj_sp(valobj_sp->Dereference(error));
1051 valobj_sp = deref_valobj_sp;
1052 } else if (address_of) {
1053 ValueObjectSP address_of_valobj_sp(valobj_sp->AddressOf(error));
1054 valobj_sp = address_of_valobj_sp;
1055 }
1056 }
1057 return valobj_sp;
Kate Stoneb9c1b512016-09-06 20:57:501058}
1059
Zachary Turner97206d52017-05-12 04:51:551060bool StackFrame::GetFrameBaseValue(Scalar &frame_base, Status *error_ptr) {
Kate Stoneb9c1b512016-09-06 20:57:501061 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1062 if (!m_cfa_is_valid) {
1063 m_frame_base_error.SetErrorString(
1064 "No frame base available for this historical stack frame.");
1065 return false;
1066 }
1067
1068 if (m_flags.IsClear(GOT_FRAME_BASE)) {
1069 if (m_sc.function) {
1070 m_frame_base.Clear();
1071 m_frame_base_error.Clear();
1072
1073 m_flags.Set(GOT_FRAME_BASE);
1074 ExecutionContext exe_ctx(shared_from_this());
1075 Value expr_value;
1076 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1077 if (m_sc.function->GetFrameBaseExpression().IsLocationList())
1078 loclist_base_addr =
1079 m_sc.function->GetAddressRange().GetBaseAddress().GetLoadAddress(
1080 exe_ctx.GetTargetPtr());
1081
Jonas Devliegherea6682a42018-12-15 00:15:331082 if (!m_sc.function->GetFrameBaseExpression().Evaluate(
Tamas Berghammerbba2c832017-08-16 11:45:101083 &exe_ctx, nullptr, loclist_base_addr, nullptr, nullptr,
Jonas Devliegherea6682a42018-12-15 00:15:331084 expr_value, &m_frame_base_error)) {
Adrian Prantl05097242018-04-30 16:49:041085 // We should really have an error if evaluate returns, but in case we
1086 // don't, lets set the error to something at least.
Kate Stoneb9c1b512016-09-06 20:57:501087 if (m_frame_base_error.Success())
1088 m_frame_base_error.SetErrorString(
1089 "Evaluation of the frame base expression failed.");
1090 } else {
1091 m_frame_base = expr_value.ResolveValue(&exe_ctx);
1092 }
1093 } else {
1094 m_frame_base_error.SetErrorString("No function in symbol context.");
Jim Ingham78a685a2011-04-16 00:01:131095 }
Kate Stoneb9c1b512016-09-06 20:57:501096 }
1097
1098 if (m_frame_base_error.Success())
1099 frame_base = m_frame_base;
1100
1101 if (error_ptr)
1102 *error_ptr = m_frame_base_error;
1103 return m_frame_base_error.Success();
1104}
1105
Zachary Turner97206d52017-05-12 04:51:551106DWARFExpression *StackFrame::GetFrameBaseExpression(Status *error_ptr) {
Kate Stoneb9c1b512016-09-06 20:57:501107 if (!m_sc.function) {
1108 if (error_ptr) {
1109 error_ptr->SetErrorString("No function in symbol context.");
1110 }
1111 return nullptr;
1112 }
1113
1114 return &m_sc.function->GetFrameBaseExpression();
1115}
1116
1117RegisterContextSP StackFrame::GetRegisterContext() {
1118 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1119 if (!m_reg_context_sp) {
1120 ThreadSP thread_sp(GetThread());
1121 if (thread_sp)
1122 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame(this);
1123 }
1124 return m_reg_context_sp;
1125}
1126
1127bool StackFrame::HasDebugInformation() {
1128 GetSymbolContext(eSymbolContextLineEntry);
1129 return m_sc.line_entry.IsValid();
Greg Clayton288bdf92010-09-02 02:59:181130}
1131
1132ValueObjectSP
Kate Stoneb9c1b512016-09-06 20:57:501133StackFrame::GetValueObjectForFrameVariable(const VariableSP &variable_sp,
1134 DynamicValueType use_dynamic) {
1135 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1136 ValueObjectSP valobj_sp;
Vedant Kumar4b36f792018-10-05 23:23:151137 if (IsHistorical()) {
Greg Clayton288bdf92010-09-02 02:59:181138 return valobj_sp;
Kate Stoneb9c1b512016-09-06 20:57:501139 }
1140 VariableList *var_list = GetVariableList(true);
1141 if (var_list) {
1142 // Make sure the variable is a frame variable
1143 const uint32_t var_idx = var_list->FindIndexForVariable(variable_sp.get());
1144 const uint32_t num_variables = var_list->GetSize();
1145 if (var_idx < num_variables) {
1146 valobj_sp = m_variable_list_value_objects.GetValueObjectAtIndex(var_idx);
1147 if (!valobj_sp) {
1148 if (m_variable_list_value_objects.GetSize() < num_variables)
1149 m_variable_list_value_objects.Resize(num_variables);
1150 valobj_sp = ValueObjectVariable::Create(this, variable_sp);
1151 m_variable_list_value_objects.SetValueObjectAtIndex(var_idx, valobj_sp);
1152 }
Enrico Granata592afe72016-03-15 21:50:511153 }
Kate Stoneb9c1b512016-09-06 20:57:501154 }
1155 if (use_dynamic != eNoDynamicValues && valobj_sp) {
1156 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue(use_dynamic);
1157 if (dynamic_sp)
1158 return dynamic_sp;
1159 }
1160 return valobj_sp;
Enrico Granata592afe72016-03-15 21:50:511161}
1162
Kate Stoneb9c1b512016-09-06 20:57:501163ValueObjectSP StackFrame::TrackGlobalVariable(const VariableSP &variable_sp,
1164 DynamicValueType use_dynamic) {
1165 std::lock_guard<std::recursive_mutex> guard(m_mutex);
Vedant Kumar4b36f792018-10-05 23:23:151166 if (IsHistorical())
Kate Stoneb9c1b512016-09-06 20:57:501167 return ValueObjectSP();
1168
1169 // Check to make sure we aren't already tracking this variable?
1170 ValueObjectSP valobj_sp(
1171 GetValueObjectForFrameVariable(variable_sp, use_dynamic));
1172 if (!valobj_sp) {
1173 // We aren't already tracking this global
1174 VariableList *var_list = GetVariableList(true);
1175 // If this frame has no variables, create a new list
1176 if (var_list == nullptr)
1177 m_variable_list_sp.reset(new VariableList());
1178
1179 // Add the global/static variable to this frame
1180 m_variable_list_sp->AddVariable(variable_sp);
1181
1182 // Now make a value object for it so we can track its changes
1183 valobj_sp = GetValueObjectForFrameVariable(variable_sp, use_dynamic);
1184 }
1185 return valobj_sp;
1186}
1187
1188bool StackFrame::IsInlined() {
1189 if (m_sc.block == nullptr)
1190 GetSymbolContext(eSymbolContextBlock);
1191 if (m_sc.block)
1192 return m_sc.block->GetContainingInlinedBlock() != nullptr;
1193 return false;
1194}
1195
Vedant Kumar4b36f792018-10-05 23:23:151196bool StackFrame::IsHistorical() const {
1197 return m_stack_frame_kind == StackFrame::Kind::History;
1198}
1199
1200bool StackFrame::IsArtificial() const {
1201 return m_stack_frame_kind == StackFrame::Kind::Artificial;
1202}
1203
Kate Stoneb9c1b512016-09-06 20:57:501204lldb::LanguageType StackFrame::GetLanguage() {
1205 CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
1206 if (cu)
1207 return cu->GetLanguage();
1208 return lldb::eLanguageTypeUnknown;
1209}
1210
1211lldb::LanguageType StackFrame::GuessLanguage() {
1212 LanguageType lang_type = GetLanguage();
1213
1214 if (lang_type == eLanguageTypeUnknown) {
Jim Inghambdbdd222017-04-12 00:19:541215 SymbolContext sc = GetSymbolContext(eSymbolContextFunction
1216 | eSymbolContextSymbol);
1217 if (sc.function) {
1218 lang_type = sc.function->GetMangled().GuessLanguage();
1219 }
1220 else if (sc.symbol)
1221 {
1222 lang_type = sc.symbol->GetMangled().GuessLanguage();
Sean Callanan4740a732016-09-06 04:48:361223 }
Kate Stoneb9c1b512016-09-06 20:57:501224 }
1225
1226 return lang_type;
1227}
1228
1229namespace {
1230std::pair<const Instruction::Operand *, int64_t>
1231GetBaseExplainingValue(const Instruction::Operand &operand,
1232 RegisterContext &register_context, lldb::addr_t value) {
1233 switch (operand.m_type) {
1234 case Instruction::Operand::Type::Dereference:
1235 case Instruction::Operand::Type::Immediate:
1236 case Instruction::Operand::Type::Invalid:
1237 case Instruction::Operand::Type::Product:
1238 // These are not currently interesting
1239 return std::make_pair(nullptr, 0);
1240 case Instruction::Operand::Type::Sum: {
1241 const Instruction::Operand *immediate_child = nullptr;
1242 const Instruction::Operand *variable_child = nullptr;
1243 if (operand.m_children[0].m_type == Instruction::Operand::Type::Immediate) {
1244 immediate_child = &operand.m_children[0];
1245 variable_child = &operand.m_children[1];
1246 } else if (operand.m_children[1].m_type ==
1247 Instruction::Operand::Type::Immediate) {
1248 immediate_child = &operand.m_children[1];
1249 variable_child = &operand.m_children[0];
Sean Callanan4740a732016-09-06 04:48:361250 }
Kate Stoneb9c1b512016-09-06 20:57:501251 if (!immediate_child) {
1252 return std::make_pair(nullptr, 0);
1253 }
1254 lldb::addr_t adjusted_value = value;
1255 if (immediate_child->m_negative) {
1256 adjusted_value += immediate_child->m_immediate;
1257 } else {
1258 adjusted_value -= immediate_child->m_immediate;
1259 }
1260 std::pair<const Instruction::Operand *, int64_t> base_and_offset =
1261 GetBaseExplainingValue(*variable_child, register_context,
1262 adjusted_value);
1263 if (!base_and_offset.first) {
1264 return std::make_pair(nullptr, 0);
1265 }
1266 if (immediate_child->m_negative) {
1267 base_and_offset.second -= immediate_child->m_immediate;
1268 } else {
1269 base_and_offset.second += immediate_child->m_immediate;
1270 }
1271 return base_and_offset;
1272 }
1273 case Instruction::Operand::Type::Register: {
1274 const RegisterInfo *info =
1275 register_context.GetRegisterInfoByName(operand.m_register.AsCString());
1276 if (!info) {
1277 return std::make_pair(nullptr, 0);
1278 }
1279 RegisterValue reg_value;
1280 if (!register_context.ReadRegister(info, reg_value)) {
1281 return std::make_pair(nullptr, 0);
1282 }
1283 if (reg_value.GetAsUInt64() == value) {
1284 return std::make_pair(&operand, 0);
1285 } else {
1286 return std::make_pair(nullptr, 0);
1287 }
1288 }
1289 }
Zachary Turner5a8ad4592016-10-05 17:07:341290 return std::make_pair(nullptr, 0);
Kate Stoneb9c1b512016-09-06 20:57:501291}
1292
1293std::pair<const Instruction::Operand *, int64_t>
1294GetBaseExplainingDereference(const Instruction::Operand &operand,
1295 RegisterContext &register_context,
1296 lldb::addr_t addr) {
1297 if (operand.m_type == Instruction::Operand::Type::Dereference) {
1298 return GetBaseExplainingValue(operand.m_children[0], register_context,
1299 addr);
1300 }
1301 return std::make_pair(nullptr, 0);
1302}
Ilia K4f730dc2016-09-12 05:25:331303}
Sean Callanan4740a732016-09-06 04:48:361304
Kate Stoneb9c1b512016-09-06 20:57:501305lldb::ValueObjectSP StackFrame::GuessValueForAddress(lldb::addr_t addr) {
1306 TargetSP target_sp = CalculateTarget();
Sean Callanan4740a732016-09-06 04:48:361307
Kate Stoneb9c1b512016-09-06 20:57:501308 const ArchSpec &target_arch = target_sp->GetArchitecture();
1309
1310 AddressRange pc_range;
1311 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1312 pc_range.SetByteSize(target_arch.GetMaximumOpcodeByteSize());
1313
1314 ExecutionContext exe_ctx(shared_from_this());
1315
1316 const char *plugin_name = nullptr;
1317 const char *flavor = nullptr;
1318 const bool prefer_file_cache = false;
1319
1320 DisassemblerSP disassembler_sp = Disassembler::DisassembleRange(
1321 target_arch, plugin_name, flavor, exe_ctx, pc_range, prefer_file_cache);
1322
Jim Ingham99d1e282017-03-31 22:39:551323 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
Sean Callanan4740a732016-09-06 04:48:361324 return ValueObjectSP();
Kate Stoneb9c1b512016-09-06 20:57:501325 }
Sean Callanan4740a732016-09-06 04:48:361326
Kate Stoneb9c1b512016-09-06 20:57:501327 InstructionSP instruction_sp =
1328 disassembler_sp->GetInstructionList().GetInstructionAtIndex(0);
1329
1330 llvm::SmallVector<Instruction::Operand, 3> operands;
1331
1332 if (!instruction_sp->ParseOperands(operands)) {
1333 return ValueObjectSP();
1334 }
1335
1336 RegisterContextSP register_context_sp = GetRegisterContext();
1337
1338 if (!register_context_sp) {
1339 return ValueObjectSP();
1340 }
1341
1342 for (const Instruction::Operand &operand : operands) {
1343 std::pair<const Instruction::Operand *, int64_t> base_and_offset =
1344 GetBaseExplainingDereference(operand, *register_context_sp, addr);
1345
1346 if (!base_and_offset.first) {
1347 continue;
Sean Callanan4740a732016-09-06 04:48:361348 }
Sean Callanan4740a732016-09-06 04:48:361349
Kate Stoneb9c1b512016-09-06 20:57:501350 switch (base_and_offset.first->m_type) {
1351 case Instruction::Operand::Type::Immediate: {
1352 lldb_private::Address addr;
1353 if (target_sp->ResolveLoadAddress(base_and_offset.first->m_immediate +
1354 base_and_offset.second,
1355 addr)) {
1356 TypeSystem *c_type_system =
1357 target_sp->GetScratchTypeSystemForLanguage(nullptr, eLanguageTypeC);
1358 if (!c_type_system) {
1359 return ValueObjectSP();
1360 } else {
1361 CompilerType void_ptr_type =
1362 c_type_system
1363 ->GetBasicTypeFromAST(lldb::BasicType::eBasicTypeChar)
1364 .GetPointerType();
1365 return ValueObjectMemory::Create(this, "", addr, void_ptr_type);
Sean Callanan4740a732016-09-06 04:48:361366 }
Kate Stoneb9c1b512016-09-06 20:57:501367 } else {
Sean Callanan4740a732016-09-06 04:48:361368 return ValueObjectSP();
Kate Stoneb9c1b512016-09-06 20:57:501369 }
1370 break;
Sean Callanan4740a732016-09-06 04:48:361371 }
Kate Stoneb9c1b512016-09-06 20:57:501372 case Instruction::Operand::Type::Register: {
1373 return GuessValueForRegisterAndOffset(base_and_offset.first->m_register,
1374 base_and_offset.second);
1375 }
1376 default:
1377 return ValueObjectSP();
1378 }
1379 }
1380
1381 return ValueObjectSP();
Sean Callanan4740a732016-09-06 04:48:361382}
1383
Kate Stoneb9c1b512016-09-06 20:57:501384namespace {
1385ValueObjectSP GetValueForOffset(StackFrame &frame, ValueObjectSP &parent,
1386 int64_t offset) {
1387 if (offset < 0 || uint64_t(offset) >= parent->GetByteSize()) {
1388 return ValueObjectSP();
1389 }
Sean Callanan4740a732016-09-06 04:48:361390
Kate Stoneb9c1b512016-09-06 20:57:501391 if (parent->IsPointerOrReferenceType()) {
1392 return parent;
1393 }
1394
1395 for (int ci = 0, ce = parent->GetNumChildren(); ci != ce; ++ci) {
1396 const bool can_create = true;
1397 ValueObjectSP child_sp = parent->GetChildAtIndex(ci, can_create);
1398
1399 if (!child_sp) {
1400 return ValueObjectSP();
Sean Callanan4740a732016-09-06 04:48:361401 }
1402
Kate Stoneb9c1b512016-09-06 20:57:501403 int64_t child_offset = child_sp->GetByteOffset();
1404 int64_t child_size = child_sp->GetByteSize();
1405
1406 if (offset >= child_offset && offset < (child_offset + child_size)) {
1407 return GetValueForOffset(frame, child_sp, offset - child_offset);
Sean Callanan4740a732016-09-06 04:48:361408 }
Kate Stoneb9c1b512016-09-06 20:57:501409 }
Sean Callanan4740a732016-09-06 04:48:361410
Kate Stoneb9c1b512016-09-06 20:57:501411 if (offset == 0) {
1412 return parent;
1413 } else {
1414 return ValueObjectSP();
1415 }
1416}
1417
1418ValueObjectSP GetValueForDereferincingOffset(StackFrame &frame,
1419 ValueObjectSP &base,
1420 int64_t offset) {
1421 // base is a pointer to something
Adrian Prantl05097242018-04-30 16:49:041422 // offset is the thing to add to the pointer We return the most sensible
1423 // ValueObject for the result of *(base+offset)
Kate Stoneb9c1b512016-09-06 20:57:501424
1425 if (!base->IsPointerOrReferenceType()) {
1426 return ValueObjectSP();
1427 }
1428
Zachary Turner97206d52017-05-12 04:51:551429 Status error;
Kate Stoneb9c1b512016-09-06 20:57:501430 ValueObjectSP pointee = base->Dereference(error);
Sean Callanana0a1d2d2016-09-29 00:16:371431
1432 if (!pointee) {
1433 return ValueObjectSP();
1434 }
Kate Stoneb9c1b512016-09-06 20:57:501435
Ilia K4f730dc2016-09-12 05:25:331436 if (offset >= 0 && uint64_t(offset) >= pointee->GetByteSize()) {
Kate Stoneb9c1b512016-09-06 20:57:501437 int64_t index = offset / pointee->GetByteSize();
1438 offset = offset % pointee->GetByteSize();
1439 const bool can_create = true;
1440 pointee = base->GetSyntheticArrayMember(index, can_create);
1441 }
1442
1443 if (!pointee || error.Fail()) {
1444 return ValueObjectSP();
1445 }
1446
1447 return GetValueForOffset(frame, pointee, offset);
1448}
1449
1450//------------------------------------------------------------------
1451/// Attempt to reconstruct the ValueObject for the address contained in a
1452/// given register plus an offset.
1453///
1454/// @params [in] frame
1455/// The current stack frame.
1456///
1457/// @params [in] reg
1458/// The register.
1459///
1460/// @params [in] offset
1461/// The offset from the register.
1462///
1463/// @param [in] disassembler
1464/// A disassembler containing instructions valid up to the current PC.
1465///
1466/// @param [in] variables
1467/// The variable list from the current frame,
1468///
1469/// @param [in] pc
1470/// The program counter for the instruction considered the 'user'.
1471///
1472/// @return
1473/// A string describing the base for the ExpressionPath. This could be a
1474/// variable, a register value, an argument, or a function return value.
1475/// The ValueObject if found. If valid, it has a valid ExpressionPath.
1476//------------------------------------------------------------------
1477lldb::ValueObjectSP DoGuessValueAt(StackFrame &frame, ConstString reg,
1478 int64_t offset, Disassembler &disassembler,
1479 VariableList &variables, const Address &pc) {
1480 // Example of operation for Intel:
1481 //
1482 // +14: movq -0x8(%rbp), %rdi
1483 // +18: movq 0x8(%rdi), %rdi
1484 // +22: addl 0x4(%rdi), %eax
1485 //
1486 // f, a pointer to a struct, is known to be at -0x8(%rbp).
1487 //
Adrian Prantl05097242018-04-30 16:49:041488 // DoGuessValueAt(frame, rdi, 4, dis, vars, 0x22) finds the instruction at
1489 // +18 that assigns to rdi, and calls itself recursively for that dereference
Kate Stoneb9c1b512016-09-06 20:57:501490 // DoGuessValueAt(frame, rdi, 8, dis, vars, 0x18) finds the instruction at
1491 // +14 that assigns to rdi, and calls itself recursively for that
1492 // derefernece
1493 // DoGuessValueAt(frame, rbp, -8, dis, vars, 0x14) finds "f" in the
1494 // variable list.
1495 // Returns a ValueObject for f. (That's what was stored at rbp-8 at +14)
1496 // Returns a ValueObject for *(f+8) or f->b (That's what was stored at rdi+8
1497 // at +18)
1498 // Returns a ValueObject for *(f->b+4) or f->b->a (That's what was stored at
1499 // rdi+4 at +22)
1500
1501 // First, check the variable list to see if anything is at the specified
1502 // location.
Sean Callanan807ee2f2016-09-13 21:18:271503
Sean Callanan50857102016-09-14 00:48:191504 using namespace OperandMatchers;
1505
Sean Callanan0ac172d2016-09-14 20:29:571506 const RegisterInfo *reg_info =
1507 frame.GetRegisterContext()->GetRegisterInfoByName(reg.AsCString());
1508 if (!reg_info) {
1509 return ValueObjectSP();
1510 }
1511
Sean Callanan807ee2f2016-09-13 21:18:271512 Instruction::Operand op =
1513 offset ? Instruction::Operand::BuildDereference(
1514 Instruction::Operand::BuildSum(
1515 Instruction::Operand::BuildRegister(reg),
1516 Instruction::Operand::BuildImmediate(offset)))
1517 : Instruction::Operand::BuildDereference(
1518 Instruction::Operand::BuildRegister(reg));
1519
Kate Stoneb9c1b512016-09-06 20:57:501520 for (size_t vi = 0, ve = variables.GetSize(); vi != ve; ++vi) {
1521 VariableSP var_sp = variables.GetVariableAtIndex(vi);
Sean Callanan807ee2f2016-09-13 21:18:271522 if (var_sp->LocationExpression().MatchesOperand(frame, op)) {
1523 return frame.GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
Sean Callanan4740a732016-09-06 04:48:361524 }
Kate Stoneb9c1b512016-09-06 20:57:501525 }
1526
Kate Stoneb9c1b512016-09-06 20:57:501527 const uint32_t current_inst =
1528 disassembler.GetInstructionList().GetIndexOfInstructionAtAddress(pc);
1529 if (current_inst == UINT32_MAX) {
1530 return ValueObjectSP();
1531 }
Chris Lattner30fdc8d2010-06-08 16:52:241532
Kate Stoneb9c1b512016-09-06 20:57:501533 for (uint32_t ii = current_inst - 1; ii != (uint32_t)-1; --ii) {
1534 // This is not an exact algorithm, and it sacrifices accuracy for
Adrian Prantl05097242018-04-30 16:49:041535 // generality. Recognizing "mov" and "ld" instructions –– and which
1536 // are their source and destination operands -- is something the
1537 // disassembler should do for us.
Kate Stoneb9c1b512016-09-06 20:57:501538 InstructionSP instruction_sp =
1539 disassembler.GetInstructionList().GetInstructionAtIndex(ii);
Chris Lattner30fdc8d2010-06-08 16:52:241540
Sean Callanan50857102016-09-14 00:48:191541 if (instruction_sp->IsCall()) {
1542 ABISP abi_sp = frame.CalculateProcess()->GetABI();
1543 if (!abi_sp) {
1544 continue;
1545 }
1546
1547 const char *return_register_name;
1548 if (!abi_sp->GetPointerReturnRegister(return_register_name)) {
1549 continue;
1550 }
1551
1552 const RegisterInfo *return_register_info =
1553 frame.GetRegisterContext()->GetRegisterInfoByName(
1554 return_register_name);
1555 if (!return_register_info) {
1556 continue;
1557 }
1558
1559 int64_t offset = 0;
1560
1561 if (!MatchUnaryOp(MatchOpType(Instruction::Operand::Type::Dereference),
1562 MatchRegOp(*return_register_info))(op) &&
1563 !MatchUnaryOp(
1564 MatchOpType(Instruction::Operand::Type::Dereference),
1565 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum),
1566 MatchRegOp(*return_register_info),
1567 FetchImmOp(offset)))(op)) {
1568 continue;
1569 }
1570
Kate Stoneb9c1b512016-09-06 20:57:501571 llvm::SmallVector<Instruction::Operand, 1> operands;
1572 if (!instruction_sp->ParseOperands(operands) || operands.size() != 1) {
1573 continue;
1574 }
Chris Lattner30fdc8d2010-06-08 16:52:241575
Kate Stoneb9c1b512016-09-06 20:57:501576 switch (operands[0].m_type) {
1577 default:
1578 break;
1579 case Instruction::Operand::Type::Immediate: {
1580 SymbolContext sc;
1581 Address load_address;
1582 if (!frame.CalculateTarget()->ResolveLoadAddress(
1583 operands[0].m_immediate, load_address)) {
1584 break;
Greg Clayton7260f622011-04-18 08:33:371585 }
Kate Stoneb9c1b512016-09-06 20:57:501586 frame.CalculateTarget()->GetImages().ResolveSymbolContextForAddress(
1587 load_address, eSymbolContextFunction, sc);
1588 if (!sc.function) {
1589 break;
1590 }
1591 CompilerType function_type = sc.function->GetCompilerType();
1592 if (!function_type.IsFunctionType()) {
1593 break;
1594 }
1595 CompilerType return_type = function_type.GetFunctionReturnType();
1596 RegisterValue return_value;
Sean Callanan50857102016-09-14 00:48:191597 if (!frame.GetRegisterContext()->ReadRegister(return_register_info,
Kate Stoneb9c1b512016-09-06 20:57:501598 return_value)) {
1599 break;
1600 }
1601 std::string name_str(
1602 sc.function->GetName().AsCString("<unknown function>"));
1603 name_str.append("()");
1604 Address return_value_address(return_value.GetAsUInt64());
1605 ValueObjectSP return_value_sp = ValueObjectMemory::Create(
Zachary Turner22a26282016-11-12 18:17:361606 &frame, name_str, return_value_address, return_type);
Kate Stoneb9c1b512016-09-06 20:57:501607 return GetValueForDereferincingOffset(frame, return_value_sp, offset);
1608 }
1609 }
1610
1611 continue;
Greg Clayton7260f622011-04-18 08:33:371612 }
Kate Stoneb9c1b512016-09-06 20:57:501613
1614 llvm::SmallVector<Instruction::Operand, 2> operands;
1615 if (!instruction_sp->ParseOperands(operands) || operands.size() != 2) {
1616 continue;
1617 }
1618
Kate Stoneb9c1b512016-09-06 20:57:501619 Instruction::Operand *origin_operand = nullptr;
Sean Callananaa4b44c2016-09-14 20:58:311620 auto clobbered_reg_matcher = [reg_info](const Instruction::Operand &op) {
1621 return MatchRegOp(*reg_info)(op) && op.m_clobbered;
1622 };
Sean Callanan0ac172d2016-09-14 20:29:571623
1624 if (clobbered_reg_matcher(operands[0])) {
Kate Stoneb9c1b512016-09-06 20:57:501625 origin_operand = &operands[1];
Sean Callanan0ac172d2016-09-14 20:29:571626 }
1627 else if (clobbered_reg_matcher(operands[1])) {
Kate Stoneb9c1b512016-09-06 20:57:501628 origin_operand = &operands[0];
Sean Callanan0ac172d2016-09-14 20:29:571629 }
1630 else {
Kate Stoneb9c1b512016-09-06 20:57:501631 continue;
1632 }
1633
1634 // We have an origin operand. Can we track its value down?
Sean Callanan561a9bb2016-09-14 21:54:281635 ValueObjectSP source_path;
1636 ConstString origin_register;
1637 int64_t origin_offset = 0;
1638
1639 if (FetchRegOp(origin_register)(*origin_operand)) {
1640 source_path = DoGuessValueAt(frame, origin_register, 0, disassembler,
1641 variables, instruction_sp->GetAddress());
1642 } else if (MatchUnaryOp(
1643 MatchOpType(Instruction::Operand::Type::Dereference),
1644 FetchRegOp(origin_register))(*origin_operand) ||
1645 MatchUnaryOp(
1646 MatchOpType(Instruction::Operand::Type::Dereference),
1647 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum),
1648 FetchRegOp(origin_register),
1649 FetchImmOp(origin_offset)))(*origin_operand)) {
Kate Stoneb9c1b512016-09-06 20:57:501650 source_path =
Sean Callanan561a9bb2016-09-14 21:54:281651 DoGuessValueAt(frame, origin_register, origin_offset, disassembler,
Kate Stoneb9c1b512016-09-06 20:57:501652 variables, instruction_sp->GetAddress());
Sean Callanan561a9bb2016-09-14 21:54:281653 if (!source_path) {
1654 continue;
Kate Stoneb9c1b512016-09-06 20:57:501655 }
Sean Callanan561a9bb2016-09-14 21:54:281656 source_path =
1657 GetValueForDereferincingOffset(frame, source_path, offset);
Kate Stoneb9c1b512016-09-06 20:57:501658 }
1659
1660 if (source_path) {
1661 return source_path;
1662 }
1663 }
1664
1665 return ValueObjectSP();
1666}
1667}
1668
1669lldb::ValueObjectSP StackFrame::GuessValueForRegisterAndOffset(ConstString reg,
1670 int64_t offset) {
1671 TargetSP target_sp = CalculateTarget();
1672
1673 const ArchSpec &target_arch = target_sp->GetArchitecture();
1674
1675 Block *frame_block = GetFrameBlock();
1676
1677 if (!frame_block) {
1678 return ValueObjectSP();
1679 }
1680
1681 Function *function = frame_block->CalculateSymbolContextFunction();
1682 if (!function) {
1683 return ValueObjectSP();
1684 }
1685
1686 AddressRange pc_range = function->GetAddressRange();
1687
1688 if (GetFrameCodeAddress().GetFileAddress() <
1689 pc_range.GetBaseAddress().GetFileAddress() ||
1690 GetFrameCodeAddress().GetFileAddress() -
1691 pc_range.GetBaseAddress().GetFileAddress() >=
1692 pc_range.GetByteSize()) {
1693 return ValueObjectSP();
1694 }
1695
1696 ExecutionContext exe_ctx(shared_from_this());
1697
1698 const char *plugin_name = nullptr;
1699 const char *flavor = nullptr;
1700 const bool prefer_file_cache = false;
1701 DisassemblerSP disassembler_sp = Disassembler::DisassembleRange(
1702 target_arch, plugin_name, flavor, exe_ctx, pc_range, prefer_file_cache);
1703
1704 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
1705 return ValueObjectSP();
1706 }
1707
1708 const bool get_file_globals = false;
1709 VariableList *variables = GetVariableList(get_file_globals);
1710
1711 if (!variables) {
1712 return ValueObjectSP();
1713 }
1714
1715 return DoGuessValueAt(*this, reg, offset, *disassembler_sp, *variables,
1716 GetFrameCodeAddress());
1717}
1718
Shafik Yaghmoure23d0b632018-09-20 17:06:341719lldb::ValueObjectSP StackFrame::FindVariable(ConstString name) {
1720 ValueObjectSP value_sp;
1721
1722 if (!name)
1723 return value_sp;
1724
1725 TargetSP target_sp = CalculateTarget();
1726 ProcessSP process_sp = CalculateProcess();
1727
1728 if (!target_sp && !process_sp)
1729 return value_sp;
1730
1731 VariableList variable_list;
1732 VariableSP var_sp;
1733 SymbolContext sc(GetSymbolContext(eSymbolContextBlock));
1734
1735 if (sc.block) {
1736 const bool can_create = true;
1737 const bool get_parent_variables = true;
1738 const bool stop_if_block_is_inlined_function = true;
1739
1740 if (sc.block->AppendVariables(
1741 can_create, get_parent_variables, stop_if_block_is_inlined_function,
1742 [this](Variable *v) { return v->IsInScope(this); },
1743 &variable_list)) {
1744 var_sp = variable_list.FindVariable(name);
1745 }
1746
1747 if (var_sp)
1748 value_sp = GetValueObjectForFrameVariable(var_sp, eNoDynamicValues);
1749 }
1750
1751 return value_sp;
1752}
1753
Kate Stoneb9c1b512016-09-06 20:57:501754TargetSP StackFrame::CalculateTarget() {
1755 TargetSP target_sp;
1756 ThreadSP thread_sp(GetThread());
1757 if (thread_sp) {
1758 ProcessSP process_sp(thread_sp->CalculateProcess());
1759 if (process_sp)
1760 target_sp = process_sp->CalculateTarget();
1761 }
1762 return target_sp;
1763}
1764
1765ProcessSP StackFrame::CalculateProcess() {
1766 ProcessSP process_sp;
1767 ThreadSP thread_sp(GetThread());
1768 if (thread_sp)
1769 process_sp = thread_sp->CalculateProcess();
1770 return process_sp;
1771}
1772
1773ThreadSP StackFrame::CalculateThread() { return GetThread(); }
1774
1775StackFrameSP StackFrame::CalculateStackFrame() { return shared_from_this(); }
1776
1777void StackFrame::CalculateExecutionContext(ExecutionContext &exe_ctx) {
1778 exe_ctx.SetContext(shared_from_this());
1779}
1780
Pavel Labath7f1c1212017-06-12 16:25:241781void StackFrame::DumpUsingSettingsFormat(Stream *strm, bool show_unique,
Kate Stoneb9c1b512016-09-06 20:57:501782 const char *frame_marker) {
1783 if (strm == nullptr)
1784 return;
1785
1786 GetSymbolContext(eSymbolContextEverything);
1787 ExecutionContext exe_ctx(shared_from_this());
1788 StreamString s;
1789
1790 if (frame_marker)
1791 s.PutCString(frame_marker);
1792
1793 const FormatEntity::Entry *frame_format = nullptr;
1794 Target *target = exe_ctx.GetTargetPtr();
Pavel Labath7f1c1212017-06-12 16:25:241795 if (target) {
1796 if (show_unique) {
1797 frame_format = target->GetDebugger().GetFrameFormatUnique();
1798 } else {
1799 frame_format = target->GetDebugger().GetFrameFormat();
1800 }
1801 }
Kate Stoneb9c1b512016-09-06 20:57:501802 if (frame_format && FormatEntity::Format(*frame_format, s, &m_sc, &exe_ctx,
1803 nullptr, nullptr, false, false)) {
Zachary Turnerc1564272016-11-16 21:15:241804 strm->PutCString(s.GetString());
Kate Stoneb9c1b512016-09-06 20:57:501805 } else {
1806 Dump(strm, true, false);
1807 strm->EOL();
1808 }
1809}
1810
1811void StackFrame::Dump(Stream *strm, bool show_frame_index,
1812 bool show_fullpaths) {
1813 if (strm == nullptr)
1814 return;
1815
1816 if (show_frame_index)
1817 strm->Printf("frame #%u: ", m_frame_index);
1818 ExecutionContext exe_ctx(shared_from_this());
1819 Target *target = exe_ctx.GetTargetPtr();
1820 strm->Printf("0x%0*" PRIx64 " ",
1821 target ? (target->GetArchitecture().GetAddressByteSize() * 2)
1822 : 16,
1823 GetFrameCodeAddress().GetLoadAddress(target));
1824 GetSymbolContext(eSymbolContextEverything);
1825 const bool show_module = true;
1826 const bool show_inline = true;
1827 const bool show_function_arguments = true;
1828 const bool show_function_name = true;
1829 m_sc.DumpStopContext(strm, exe_ctx.GetBestExecutionContextScope(),
1830 GetFrameCodeAddress(), show_fullpaths, show_module,
1831 show_inline, show_function_arguments,
1832 show_function_name);
1833}
1834
1835void StackFrame::UpdateCurrentFrameFromPreviousFrame(StackFrame &prev_frame) {
1836 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1837 assert(GetStackID() ==
1838 prev_frame.GetStackID()); // TODO: remove this after some testing
1839 m_variable_list_sp = prev_frame.m_variable_list_sp;
1840 m_variable_list_value_objects.Swap(prev_frame.m_variable_list_value_objects);
Zachary Turnerc1564272016-11-16 21:15:241841 if (!m_disassembly.GetString().empty()) {
1842 m_disassembly.Clear();
1843 m_disassembly.PutCString(prev_frame.m_disassembly.GetString());
1844 }
Kate Stoneb9c1b512016-09-06 20:57:501845}
1846
1847void StackFrame::UpdatePreviousFrameFromCurrentFrame(StackFrame &curr_frame) {
1848 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1849 assert(GetStackID() ==
1850 curr_frame.GetStackID()); // TODO: remove this after some testing
1851 m_id.SetPC(curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1852 assert(GetThread() == curr_frame.GetThread());
1853 m_frame_index = curr_frame.m_frame_index;
1854 m_concrete_frame_index = curr_frame.m_concrete_frame_index;
1855 m_reg_context_sp = curr_frame.m_reg_context_sp;
1856 m_frame_code_addr = curr_frame.m_frame_code_addr;
1857 assert(!m_sc.target_sp || !curr_frame.m_sc.target_sp ||
1858 m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get());
1859 assert(!m_sc.module_sp || !curr_frame.m_sc.module_sp ||
1860 m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get());
1861 assert(m_sc.comp_unit == nullptr || curr_frame.m_sc.comp_unit == nullptr ||
1862 m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1863 assert(m_sc.function == nullptr || curr_frame.m_sc.function == nullptr ||
1864 m_sc.function == curr_frame.m_sc.function);
1865 m_sc = curr_frame.m_sc;
1866 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1867 m_flags.Set(m_sc.GetResolvedMask());
1868 m_frame_base.Clear();
1869 m_frame_base_error.Clear();
1870}
1871
1872bool StackFrame::HasCachedData() const {
1873 if (m_variable_list_sp)
Greg Clayton7260f622011-04-18 08:33:371874 return true;
Kate Stoneb9c1b512016-09-06 20:57:501875 if (m_variable_list_value_objects.GetSize() > 0)
1876 return true;
1877 if (!m_disassembly.GetString().empty())
1878 return true;
1879 return false;
1880}
1881
1882bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source,
Pavel Labath7f1c1212017-06-12 16:25:241883 bool show_unique, const char *frame_marker) {
Kate Stoneb9c1b512016-09-06 20:57:501884 if (show_frame_info) {
1885 strm.Indent();
Pavel Labath7f1c1212017-06-12 16:25:241886 DumpUsingSettingsFormat(&strm, show_unique, frame_marker);
Kate Stoneb9c1b512016-09-06 20:57:501887 }
1888
1889 if (show_source) {
1890 ExecutionContext exe_ctx(shared_from_this());
1891 bool have_source = false, have_debuginfo = false;
1892 Debugger::StopDisassemblyType disasm_display =
1893 Debugger::eStopDisassemblyTypeNever;
1894 Target *target = exe_ctx.GetTargetPtr();
1895 if (target) {
1896 Debugger &debugger = target->GetDebugger();
1897 const uint32_t source_lines_before =
1898 debugger.GetStopSourceLineCount(true);
1899 const uint32_t source_lines_after =
1900 debugger.GetStopSourceLineCount(false);
1901 disasm_display = debugger.GetStopDisassemblyDisplay();
1902
1903 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1904 if (m_sc.comp_unit && m_sc.line_entry.IsValid()) {
1905 have_debuginfo = true;
1906 if (source_lines_before > 0 || source_lines_after > 0) {
1907 size_t num_lines =
1908 target->GetSourceManager().DisplaySourceLinesWithLineNumbers(
1909 m_sc.line_entry.file, m_sc.line_entry.line,
Todd Fiala9666ba72016-09-21 20:13:141910 m_sc.line_entry.column, source_lines_before,
1911 source_lines_after, "->", &strm);
Kate Stoneb9c1b512016-09-06 20:57:501912 if (num_lines != 0)
1913 have_source = true;
1914 // TODO: Give here a one time warning if source file is missing.
1915 }
1916 }
1917 switch (disasm_display) {
1918 case Debugger::eStopDisassemblyTypeNever:
1919 break;
1920
1921 case Debugger::eStopDisassemblyTypeNoDebugInfo:
1922 if (have_debuginfo)
1923 break;
1924 LLVM_FALLTHROUGH;
1925
1926 case Debugger::eStopDisassemblyTypeNoSource:
1927 if (have_source)
1928 break;
1929 LLVM_FALLTHROUGH;
1930
1931 case Debugger::eStopDisassemblyTypeAlways:
1932 if (target) {
1933 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1934 if (disasm_lines > 0) {
1935 const ArchSpec &target_arch = target->GetArchitecture();
1936 AddressRange pc_range;
1937 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1938 pc_range.SetByteSize(disasm_lines *
1939 target_arch.GetMaximumOpcodeByteSize());
1940 const char *plugin_name = nullptr;
1941 const char *flavor = nullptr;
Jason Molenda0b4c26b2016-09-08 05:12:411942 const bool mixed_source_and_assembly = false;
1943 Disassembler::Disassemble(
1944 target->GetDebugger(), target_arch, plugin_name, flavor,
1945 exe_ctx, pc_range, disasm_lines, mixed_source_and_assembly, 0,
1946 Disassembler::eOptionMarkPCAddress, strm);
Kate Stoneb9c1b512016-09-06 20:57:501947 }
1948 }
1949 break;
1950 }
1951 }
1952 }
1953 return true;
Greg Clayton7260f622011-04-18 08:33:371954}
Kuba Mracek41ae8e72018-10-31 04:00:221955
1956RecognizedStackFrameSP StackFrame::GetRecognizedFrame() {
1957 if (!m_recognized_frame_sp) {
1958 m_recognized_frame_sp =
1959 StackFrameRecognizerManager::RecognizeFrame(CalculateStackFrame());
1960 }
1961 return m_recognized_frame_sp;
1962}