LLDB mainline
StackFrame.cpp
Go to the documentation of this file.
1//===-- StackFrame.cpp ----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
10#include "lldb/Core/Debugger.h"
13#include "lldb/Core/Mangled.h"
14#include "lldb/Core/Module.h"
15#include "lldb/Core/Value.h"
21#include "lldb/Symbol/Symbol.h"
24#include "lldb/Symbol/Type.h"
26#include "lldb/Target/ABI.h"
28#include "lldb/Target/Process.h"
31#include "lldb/Target/Target.h"
32#include "lldb/Target/Thread.h"
34#include "lldb/Utility/Log.h"
36
38
39#include <memory>
40
41using namespace lldb;
42using namespace lldb_private;
43
44// The first bits in the flags are reserved for the SymbolContext::Scope bits
45// so we know if we have tried to look up information in our internal symbol
46// context (m_sc) already.
47#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextLastItem) << 1)
48#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
49#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
50#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
51#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
52
53StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
54 user_id_t unwind_frame_index, addr_t cfa,
55 bool cfa_is_valid, addr_t pc, StackFrame::Kind kind,
56 bool behaves_like_zeroth_frame,
57 const SymbolContext *sc_ptr)
58 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
59 m_concrete_frame_index(unwind_frame_index), m_reg_context_sp(),
60 m_id(pc, cfa, nullptr), m_frame_code_addr(pc), m_sc(), m_flags(),
61 m_frame_base(), m_frame_base_error(), m_cfa_is_valid(cfa_is_valid),
62 m_stack_frame_kind(kind),
63 m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
64 m_variable_list_sp(), m_variable_list_value_objects(),
65 m_recognized_frame_sp(), m_disassembly(), m_mutex() {
66 // If we don't have a CFA value, use the frame index for our StackID so that
67 // recursive functions properly aren't confused with one another on a history
68 // stack.
69 if (IsHistorical() && !m_cfa_is_valid) {
71 }
72
73 if (sc_ptr != nullptr) {
74 m_sc = *sc_ptr;
76 }
77}
78
79StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
80 user_id_t unwind_frame_index,
81 const RegisterContextSP &reg_context_sp, addr_t cfa,
82 addr_t pc, bool behaves_like_zeroth_frame,
83 const SymbolContext *sc_ptr)
84 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
85 m_concrete_frame_index(unwind_frame_index),
86 m_reg_context_sp(reg_context_sp), m_id(pc, cfa, nullptr),
87 m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(),
88 m_frame_base_error(), m_cfa_is_valid(true),
89 m_stack_frame_kind(StackFrame::Kind::Regular),
90 m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
91 m_variable_list_sp(), m_variable_list_value_objects(),
92 m_recognized_frame_sp(), m_disassembly(), m_mutex() {
93 if (sc_ptr != nullptr) {
94 m_sc = *sc_ptr;
96 }
97
98 if (reg_context_sp && !m_sc.target_sp) {
99 m_sc.target_sp = reg_context_sp->CalculateTarget();
100 if (m_sc.target_sp)
101 m_flags.Set(eSymbolContextTarget);
102 }
103}
104
105StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
106 user_id_t unwind_frame_index,
107 const RegisterContextSP &reg_context_sp, addr_t cfa,
108 const Address &pc_addr, bool behaves_like_zeroth_frame,
109 const SymbolContext *sc_ptr)
110 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
111 m_concrete_frame_index(unwind_frame_index),
112 m_reg_context_sp(reg_context_sp),
113 m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa,
114 nullptr),
115 m_frame_code_addr(pc_addr), m_sc(), m_flags(), m_frame_base(),
116 m_frame_base_error(), m_cfa_is_valid(true),
117 m_stack_frame_kind(StackFrame::Kind::Regular),
118 m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
119 m_variable_list_sp(), m_variable_list_value_objects(),
120 m_recognized_frame_sp(), m_disassembly(), m_mutex() {
121 if (sc_ptr != nullptr) {
122 m_sc = *sc_ptr;
124 }
125
126 if (!m_sc.target_sp && reg_context_sp) {
127 m_sc.target_sp = reg_context_sp->CalculateTarget();
128 if (m_sc.target_sp)
129 m_flags.Set(eSymbolContextTarget);
130 }
131
132 ModuleSP pc_module_sp(pc_addr.GetModule());
133 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) {
134 if (pc_module_sp) {
135 m_sc.module_sp = pc_module_sp;
136 m_flags.Set(eSymbolContextModule);
137 } else {
138 m_sc.module_sp.reset();
139 }
140 }
141}
142
143StackFrame::~StackFrame() = default;
144
146 std::lock_guard<std::recursive_mutex> guard(m_mutex);
147 // Make sure we have resolved the StackID object's symbol context scope if we
148 // already haven't looked it up.
149
152 // We already have a symbol context scope, we just don't have our flag
153 // bit set.
155 } else {
156 // Calculate the frame block and use this for the stack ID symbol context
157 // scope if we have one.
159 if (scope == nullptr) {
160 // We don't have a block, so use the symbol
161 if (m_flags.IsClear(eSymbolContextSymbol))
162 GetSymbolContext(eSymbolContextSymbol);
163
164 // It is ok if m_sc.symbol is nullptr here
165 scope = m_sc.symbol;
166 }
167 // Set the symbol context scope (the accessor will set the
168 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
170 }
171 }
172 return m_id;
173}
174
176 ThreadSP thread_sp = GetThread();
177 if (thread_sp)
178 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(
180 else
181 return m_frame_index;
182}
183
185 std::lock_guard<std::recursive_mutex> guard(m_mutex);
187 m_id.SetSymbolContextScope(symbol_scope);
188}
189
191 std::lock_guard<std::recursive_mutex> guard(m_mutex);
195
196 // Resolve the PC into a temporary address because if ResolveLoadAddress
197 // fails to resolve the address, it will clear the address object...
198 ThreadSP thread_sp(GetThread());
199 if (thread_sp) {
200 TargetSP target_sp(thread_sp->CalculateTarget());
201 if (target_sp) {
202 const bool allow_section_end = true;
204 m_frame_code_addr.GetOffset(), target_sp.get(),
205 AddressClass::eCode, allow_section_end)) {
207 if (module_sp) {
208 m_sc.module_sp = module_sp;
209 m_flags.Set(eSymbolContextModule);
210 }
211 }
212 }
213 }
214 }
215 return m_frame_code_addr;
216}
217
218// This can't be rewritten into a call to
219// RegisterContext::GetPCForSymbolication because this
220// StackFrame may have been constructed with a special pc,
221// e.g. tail-call artificial frames.
223 Address lookup_addr(GetFrameCodeAddress());
224 if (!lookup_addr.IsValid())
225 return lookup_addr;
227 return lookup_addr;
228
229 addr_t offset = lookup_addr.GetOffset();
230 if (offset > 0) {
231 lookup_addr.SetOffset(offset - 1);
232 } else {
233 // lookup_addr is the start of a section. We need do the math on the
234 // actual load address and re-compute the section. We're working with
235 // a 'noreturn' function at the end of a section.
236 TargetSP target_sp = CalculateTarget();
237 if (target_sp) {
238 addr_t addr_minus_one = lookup_addr.GetOpcodeLoadAddress(
239 target_sp.get(), AddressClass::eCode) -
240 1;
241 lookup_addr.SetOpcodeLoadAddress(addr_minus_one, target_sp.get());
242 }
243 }
244 return lookup_addr;
245}
246
248 std::lock_guard<std::recursive_mutex> guard(m_mutex);
249 // We can't change the pc value of a history stack frame - it is immutable.
250 if (IsHistorical())
251 return false;
253 m_sc.Clear(false);
254 m_flags.Reset(0);
255 ThreadSP thread_sp(GetThread());
256 if (thread_sp)
257 thread_sp->ClearStackFrames();
258 return true;
259}
260
262 std::lock_guard<std::recursive_mutex> guard(m_mutex);
263 if (!m_disassembly.Empty())
264 return m_disassembly.GetData();
265
266 ExecutionContext exe_ctx(shared_from_this());
267 if (Target *target = exe_ctx.GetTargetPtr()) {
268 Disassembler::Disassemble(target->GetDebugger(), target->GetArchitecture(),
269 *this, m_disassembly);
270 }
271
272 return m_disassembly.Empty() ? nullptr : m_disassembly.GetData();
273}
274
276 if (m_sc.block == nullptr && m_flags.IsClear(eSymbolContextBlock))
277 GetSymbolContext(eSymbolContextBlock);
278
279 if (m_sc.block) {
280 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
281 if (inline_block) {
282 // Use the block with the inlined function info as the frame block we
283 // want this frame to have only the variables for the inlined function
284 // and its non-inlined block child blocks.
285 return inline_block;
286 } else {
287 // This block is not contained within any inlined function blocks with so
288 // we want to use the top most function block.
289 return &m_sc.function->GetBlock(false);
290 }
291 }
292 return nullptr;
293}
294
295// Get the symbol context if we already haven't done so by resolving the
296// PC address as much as possible. This way when we pass around a
297// StackFrame object, everyone will have as much information as possible and no
298// one will ever have to look things up manually.
299const SymbolContext &
300StackFrame::GetSymbolContext(SymbolContextItem resolve_scope) {
301 std::lock_guard<std::recursive_mutex> guard(m_mutex);
302 // Copy our internal symbol context into "sc".
303 if ((m_flags.Get() & resolve_scope) != resolve_scope) {
304 uint32_t resolved = 0;
305
306 // If the target was requested add that:
307 if (!m_sc.target_sp) {
309 if (m_sc.target_sp)
310 resolved |= eSymbolContextTarget;
311 }
312
313 // Resolve our PC to section offset if we haven't already done so and if we
314 // don't have a module. The resolved address section will contain the
315 // module to which it belongs
318
319 // If this is not frame zero, then we need to subtract 1 from the PC value
320 // when doing address lookups since the PC will be on the instruction
321 // following the function call instruction...
323
324 if (m_sc.module_sp) {
325 // We have something in our stack frame symbol context, lets check if we
326 // haven't already tried to lookup one of those things. If we haven't
327 // then we will do the query.
328
329 SymbolContextItem actual_resolve_scope = SymbolContextItem(0);
330
331 if (resolve_scope & eSymbolContextCompUnit) {
332 if (m_flags.IsClear(eSymbolContextCompUnit)) {
333 if (m_sc.comp_unit)
334 resolved |= eSymbolContextCompUnit;
335 else
336 actual_resolve_scope |= eSymbolContextCompUnit;
337 }
338 }
339
340 if (resolve_scope & eSymbolContextFunction) {
341 if (m_flags.IsClear(eSymbolContextFunction)) {
342 if (m_sc.function)
343 resolved |= eSymbolContextFunction;
344 else
345 actual_resolve_scope |= eSymbolContextFunction;
346 }
347 }
348
349 if (resolve_scope & eSymbolContextBlock) {
350 if (m_flags.IsClear(eSymbolContextBlock)) {
351 if (m_sc.block)
352 resolved |= eSymbolContextBlock;
353 else
354 actual_resolve_scope |= eSymbolContextBlock;
355 }
356 }
357
358 if (resolve_scope & eSymbolContextSymbol) {
359 if (m_flags.IsClear(eSymbolContextSymbol)) {
360 if (m_sc.symbol)
361 resolved |= eSymbolContextSymbol;
362 else
363 actual_resolve_scope |= eSymbolContextSymbol;
364 }
365 }
366
367 if (resolve_scope & eSymbolContextLineEntry) {
368 if (m_flags.IsClear(eSymbolContextLineEntry)) {
369 if (m_sc.line_entry.IsValid())
370 resolved |= eSymbolContextLineEntry;
371 else
372 actual_resolve_scope |= eSymbolContextLineEntry;
373 }
374 }
375
376 if (actual_resolve_scope) {
377 // We might be resolving less information than what is already in our
378 // current symbol context so resolve into a temporary symbol context
379 // "sc" so we don't clear out data we have already found in "m_sc"
380 SymbolContext sc;
381 // Set flags that indicate what we have tried to resolve
382 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress(
383 lookup_addr, actual_resolve_scope, sc);
384 // Only replace what we didn't already have as we may have information
385 // for an inlined function scope that won't match what a standard
386 // lookup by address would match
387 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == nullptr)
389 if ((resolved & eSymbolContextFunction) && m_sc.function == nullptr)
391 if ((resolved & eSymbolContextBlock) && m_sc.block == nullptr)
392 m_sc.block = sc.block;
393 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == nullptr)
394 m_sc.symbol = sc.symbol;
395 if ((resolved & eSymbolContextLineEntry) &&
399 }
400 }
401 } else {
402 // If we don't have a module, then we can't have the compile unit,
403 // function, block, line entry or symbol, so we can safely call
404 // ResolveSymbolContextForAddress with our symbol context member m_sc.
405 if (m_sc.target_sp) {
406 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress(
407 lookup_addr, resolve_scope, m_sc);
408 }
409 }
410
411 // Update our internal flags so we remember what we have tried to locate so
412 // we don't have to keep trying when more calls to this function are made.
413 // We might have dug up more information that was requested (for example if
414 // we were asked to only get the block, we will have gotten the compile
415 // unit, and function) so set any additional bits that we resolved
416 m_flags.Set(resolve_scope | resolved);
417 }
418
419 // Return the symbol context with everything that was possible to resolve
420 // resolved.
421 return m_sc;
422}
423
425 Status *error_ptr) {
426 std::lock_guard<std::recursive_mutex> guard(m_mutex);
429 m_variable_list_sp = std::make_shared<VariableList>();
430
431 Block *frame_block = GetFrameBlock();
432
433 if (frame_block) {
434 const bool get_child_variables = true;
435 const bool can_create = true;
436 const bool stop_if_child_block_is_inlined_function = true;
437 frame_block->AppendBlockVariables(can_create, get_child_variables,
438 stop_if_child_block_is_inlined_function,
439 [](Variable *v) { return true; },
440 m_variable_list_sp.get());
441 }
442 }
443
444 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && get_file_globals) {
446
447 if (m_flags.IsClear(eSymbolContextCompUnit))
448 GetSymbolContext(eSymbolContextCompUnit);
449
450 if (m_sc.comp_unit) {
451 VariableListSP global_variable_list_sp(
454 m_variable_list_sp->AddVariables(global_variable_list_sp.get());
455 else
456 m_variable_list_sp = global_variable_list_sp;
457 }
458 }
459
460 if (error_ptr && m_variable_list_sp->GetSize() == 0) {
461 // Check with the symbol file to check if there is an error for why we
462 // don't have variables that the user might need to know about.
463 GetSymbolContext(eSymbolContextEverything);
464 if (m_sc.module_sp) {
465 SymbolFile *sym_file = m_sc.module_sp->GetSymbolFile();
466 if (sym_file)
467 *error_ptr = sym_file->GetFrameVariableError(*this);
468 }
469 }
470
471 return m_variable_list_sp.get();
472}
473
476 bool must_have_valid_location) {
477 std::lock_guard<std::recursive_mutex> guard(m_mutex);
478 // We can't fetch variable information for a history stack frame.
479 if (IsHistorical())
480 return VariableListSP();
481
482 VariableListSP var_list_sp(new VariableList);
483 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextBlock);
484
485 if (m_sc.block) {
486 const bool can_create = true;
487 const bool get_parent_variables = true;
488 const bool stop_if_block_is_inlined_function = true;
490 can_create, get_parent_variables, stop_if_block_is_inlined_function,
491 [this, must_have_valid_location](Variable *v) {
492 return v->IsInScope(this) && (!must_have_valid_location ||
493 v->LocationIsValidForFrame(this));
494 },
495 var_list_sp.get());
496 }
497
498 if (m_sc.comp_unit && get_file_globals) {
499 VariableListSP global_variable_list_sp(
501 if (global_variable_list_sp)
502 var_list_sp->AddVariables(global_variable_list_sp.get());
503 }
504
505 return var_list_sp;
506}
507
509 llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options,
510 VariableSP &var_sp, Status &error) {
511 llvm::StringRef original_var_expr = var_expr;
512 // We can't fetch variable information for a history stack frame.
513 if (IsHistorical())
514 return ValueObjectSP();
515
516 if (var_expr.empty()) {
517 error.SetErrorStringWithFormat("invalid variable path '%s'",
518 var_expr.str().c_str());
519 return ValueObjectSP();
520 }
521
522 const bool check_ptr_vs_member =
524 const bool no_fragile_ivar =
526 const bool no_synth_child =
528 // const bool no_synth_array = (options &
529 // eExpressionPathOptionsNoSyntheticArrayRange) != 0;
530 error.Clear();
531 bool deref = false;
532 bool address_of = false;
533 ValueObjectSP valobj_sp;
534 const bool get_file_globals = true;
535 // When looking up a variable for an expression, we need only consider the
536 // variables that are in scope.
537 VariableListSP var_list_sp(GetInScopeVariableList(get_file_globals));
538 VariableList *variable_list = var_list_sp.get();
539
540 if (!variable_list)
541 return ValueObjectSP();
542
543 // If first character is a '*', then show pointer contents
544 std::string var_expr_storage;
545 if (var_expr[0] == '*') {
546 deref = true;
547 var_expr = var_expr.drop_front(); // Skip the '*'
548 } else if (var_expr[0] == '&') {
549 address_of = true;
550 var_expr = var_expr.drop_front(); // Skip the '&'
551 }
552
553 size_t separator_idx = var_expr.find_first_of(".-[=+~|&^%#@!/?,<>{}");
554 StreamString var_expr_path_strm;
555
556 ConstString name_const_string(var_expr.substr(0, separator_idx));
557
558 var_sp = variable_list->FindVariable(name_const_string, false);
559
560 bool synthetically_added_instance_object = false;
561
562 if (var_sp) {
563 var_expr = var_expr.drop_front(name_const_string.GetLength());
564 }
565
566 if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) {
567 // Check for direct ivars access which helps us with implicit access to
568 // ivars using "this" or "self".
569 GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock);
570 llvm::StringRef instance_var_name = m_sc.GetInstanceVariableName();
571 if (!instance_var_name.empty()) {
572 var_sp = variable_list->FindVariable(ConstString(instance_var_name));
573 if (var_sp) {
574 separator_idx = 0;
575 if (Type *var_type = var_sp->GetType())
576 if (auto compiler_type = var_type->GetForwardCompilerType())
577 if (!compiler_type.IsPointerType())
578 var_expr_storage = ".";
579
580 if (var_expr_storage.empty())
581 var_expr_storage = "->";
582 var_expr_storage += var_expr;
583 var_expr = var_expr_storage;
584 synthetically_added_instance_object = true;
585 }
586 }
587 }
588
589 if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) {
590 // Check if any anonymous unions are there which contain a variable with
591 // the name we need
592 for (const VariableSP &variable_sp : *variable_list) {
593 if (!variable_sp)
594 continue;
595 if (!variable_sp->GetName().IsEmpty())
596 continue;
597
598 Type *var_type = variable_sp->GetType();
599 if (!var_type)
600 continue;
601
602 if (!var_type->GetForwardCompilerType().IsAnonymousType())
603 continue;
604 valobj_sp = GetValueObjectForFrameVariable(variable_sp, use_dynamic);
605 if (!valobj_sp)
606 return valobj_sp;
607 valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string);
608 if (valobj_sp)
609 break;
610 }
611 }
612
613 if (var_sp && !valobj_sp) {
614 valobj_sp = GetValueObjectForFrameVariable(var_sp, use_dynamic);
615 if (!valobj_sp)
616 return valobj_sp;
617 }
618 if (!valobj_sp) {
619 error.SetErrorStringWithFormat("no variable named '%s' found in this frame",
620 name_const_string.GetCString());
621 return ValueObjectSP();
622 }
623
624 // We are dumping at least one child
625 while (!var_expr.empty()) {
626 // Calculate the next separator index ahead of time
627 ValueObjectSP child_valobj_sp;
628 const char separator_type = var_expr[0];
629 bool expr_is_ptr = false;
630 switch (separator_type) {
631 case '-':
632 expr_is_ptr = true;
633 if (var_expr.size() >= 2 && var_expr[1] != '>')
634 return ValueObjectSP();
635
636 if (no_fragile_ivar) {
637 // Make sure we aren't trying to deref an objective
638 // C ivar if this is not allowed
639 const uint32_t pointer_type_flags =
640 valobj_sp->GetCompilerType().GetTypeInfo(nullptr);
641 if ((pointer_type_flags & eTypeIsObjC) &&
642 (pointer_type_flags & eTypeIsPointer)) {
643 // This was an objective C object pointer and it was requested we
644 // skip any fragile ivars so return nothing here
645 return ValueObjectSP();
646 }
647 }
648
649 // If we have a non pointer type with a sythetic value then lets check if
650 // we have an sythetic dereference specified.
651 if (!valobj_sp->IsPointerType() && valobj_sp->HasSyntheticValue()) {
652 Status deref_error;
653 if (valobj_sp->GetCompilerType().IsReferenceType()) {
654 valobj_sp = valobj_sp->GetSyntheticValue()->Dereference(deref_error);
655 if (!valobj_sp || deref_error.Fail()) {
656 error.SetErrorStringWithFormatv(
657 "Failed to dereference reference type: %s", deref_error);
658 return ValueObjectSP();
659 }
660 }
661
662 valobj_sp = valobj_sp->Dereference(deref_error);
663 if (!valobj_sp || deref_error.Fail()) {
664 error.SetErrorStringWithFormatv(
665 "Failed to dereference sythetic value: {0}", deref_error);
666 return ValueObjectSP();
667 }
668 // Some synthetic plug-ins fail to set the error in Dereference
669 if (!valobj_sp) {
670 error.SetErrorString("Failed to dereference sythetic value");
671 return ValueObjectSP();
672 }
673 expr_is_ptr = false;
674 }
675
676 var_expr = var_expr.drop_front(); // Remove the '-'
677 [[fallthrough]];
678 case '.': {
679 var_expr = var_expr.drop_front(); // Remove the '.' or '>'
680 separator_idx = var_expr.find_first_of(".-[");
681 ConstString child_name(var_expr.substr(0, var_expr.find_first_of(".-[")));
682
683 if (check_ptr_vs_member) {
684 // We either have a pointer type and need to verify valobj_sp is a
685 // pointer, or we have a member of a class/union/struct being accessed
686 // with the . syntax and need to verify we don't have a pointer.
687 const bool actual_is_ptr = valobj_sp->IsPointerType();
688
689 if (actual_is_ptr != expr_is_ptr) {
690 // Incorrect use of "." with a pointer, or "->" with a
691 // class/union/struct instance or reference.
692 valobj_sp->GetExpressionPath(var_expr_path_strm);
693 if (actual_is_ptr)
694 error.SetErrorStringWithFormat(
695 "\"%s\" is a pointer and . was used to attempt to access "
696 "\"%s\". Did you mean \"%s->%s\"?",
697 var_expr_path_strm.GetData(), child_name.GetCString(),
698 var_expr_path_strm.GetData(), var_expr.str().c_str());
699 else
700 error.SetErrorStringWithFormat(
701 "\"%s\" is not a pointer and -> was used to attempt to "
702 "access \"%s\". Did you mean \"%s.%s\"?",
703 var_expr_path_strm.GetData(), child_name.GetCString(),
704 var_expr_path_strm.GetData(), var_expr.str().c_str());
705 return ValueObjectSP();
706 }
707 }
708 child_valobj_sp = valobj_sp->GetChildMemberWithName(child_name);
709 if (!child_valobj_sp) {
710 if (!no_synth_child) {
711 child_valobj_sp = valobj_sp->GetSyntheticValue();
712 if (child_valobj_sp)
713 child_valobj_sp =
714 child_valobj_sp->GetChildMemberWithName(child_name);
715 }
716
717 if (no_synth_child || !child_valobj_sp) {
718 // No child member with name "child_name"
719 if (synthetically_added_instance_object) {
720 // We added a "this->" or "self->" to the beginning of the
721 // expression and this is the first pointer ivar access, so just
722 // return the normal error
723 error.SetErrorStringWithFormat(
724 "no variable or instance variable named '%s' found in "
725 "this frame",
726 name_const_string.GetCString());
727 } else {
728 valobj_sp->GetExpressionPath(var_expr_path_strm);
729 if (child_name) {
730 error.SetErrorStringWithFormat(
731 "\"%s\" is not a member of \"(%s) %s\"",
732 child_name.GetCString(),
733 valobj_sp->GetTypeName().AsCString("<invalid type>"),
734 var_expr_path_strm.GetData());
735 } else {
736 error.SetErrorStringWithFormat(
737 "incomplete expression path after \"%s\" in \"%s\"",
738 var_expr_path_strm.GetData(),
739 original_var_expr.str().c_str());
740 }
741 }
742 return ValueObjectSP();
743 }
744 }
745 synthetically_added_instance_object = false;
746 // Remove the child name from the path
747 var_expr = var_expr.drop_front(child_name.GetLength());
748 if (use_dynamic != eNoDynamicValues) {
749 ValueObjectSP dynamic_value_sp(
750 child_valobj_sp->GetDynamicValue(use_dynamic));
751 if (dynamic_value_sp)
752 child_valobj_sp = dynamic_value_sp;
753 }
754 } break;
755
756 case '[': {
757 // Array member access, or treating pointer as an array Need at least two
758 // brackets and a number
759 if (var_expr.size() <= 2) {
760 error.SetErrorStringWithFormat(
761 "invalid square bracket encountered after \"%s\" in \"%s\"",
762 var_expr_path_strm.GetData(), var_expr.str().c_str());
763 return ValueObjectSP();
764 }
765
766 // Drop the open brace.
767 var_expr = var_expr.drop_front();
768 long child_index = 0;
769
770 // If there's no closing brace, this is an invalid expression.
771 size_t end_pos = var_expr.find_first_of(']');
772 if (end_pos == llvm::StringRef::npos) {
773 error.SetErrorStringWithFormat(
774 "missing closing square bracket in expression \"%s\"",
775 var_expr_path_strm.GetData());
776 return ValueObjectSP();
777 }
778 llvm::StringRef index_expr = var_expr.take_front(end_pos);
779 llvm::StringRef original_index_expr = index_expr;
780 // Drop all of "[index_expr]"
781 var_expr = var_expr.drop_front(end_pos + 1);
782
783 if (index_expr.consumeInteger(0, child_index)) {
784 // If there was no integer anywhere in the index expression, this is
785 // erroneous expression.
786 error.SetErrorStringWithFormat("invalid index expression \"%s\"",
787 index_expr.str().c_str());
788 return ValueObjectSP();
789 }
790
791 if (index_expr.empty()) {
792 // The entire index expression was a single integer.
793
794 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) {
795 // what we have is *ptr[low]. the most similar C++ syntax is to deref
796 // ptr and extract bit low out of it. reading array item low would be
797 // done by saying ptr[low], without a deref * sign
798 Status deref_error;
799 ValueObjectSP temp(valobj_sp->Dereference(deref_error));
800 if (!temp || deref_error.Fail()) {
801 valobj_sp->GetExpressionPath(var_expr_path_strm);
802 error.SetErrorStringWithFormat(
803 "could not dereference \"(%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 } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() &&
811 deref) {
812 // what we have is *arr[low]. the most similar C++ syntax is to get
813 // arr[0] (an operation that is equivalent to deref-ing arr) and
814 // extract bit low out of it. reading array item low would be done by
815 // saying arr[low], without a deref * sign
816 ValueObjectSP temp(valobj_sp->GetChildAtIndex(0));
817 if (!temp) {
818 valobj_sp->GetExpressionPath(var_expr_path_strm);
819 error.SetErrorStringWithFormat(
820 "could not get item 0 for \"(%s) %s\"",
821 valobj_sp->GetTypeName().AsCString("<invalid type>"),
822 var_expr_path_strm.GetData());
823 return ValueObjectSP();
824 }
825 valobj_sp = temp;
826 deref = false;
827 }
828
829 bool is_incomplete_array = false;
830 if (valobj_sp->IsPointerType()) {
831 bool is_objc_pointer = true;
832
833 if (valobj_sp->GetCompilerType().GetMinimumLanguage() !=
835 is_objc_pointer = false;
836 else if (!valobj_sp->GetCompilerType().IsPointerType())
837 is_objc_pointer = false;
838
839 if (no_synth_child && is_objc_pointer) {
840 error.SetErrorStringWithFormat(
841 "\"(%s) %s\" is an Objective-C pointer, and cannot be "
842 "subscripted",
843 valobj_sp->GetTypeName().AsCString("<invalid type>"),
844 var_expr_path_strm.GetData());
845
846 return ValueObjectSP();
847 } else if (is_objc_pointer) {
848 // dereferencing ObjC variables is not valid.. so let's try and
849 // recur to synthetic children
850 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
851 if (!synthetic /* no synthetic */
852 || synthetic == valobj_sp) /* synthetic is the same as
853 the original object */
854 {
855 valobj_sp->GetExpressionPath(var_expr_path_strm);
856 error.SetErrorStringWithFormat(
857 "\"(%s) %s\" is not an array type",
858 valobj_sp->GetTypeName().AsCString("<invalid type>"),
859 var_expr_path_strm.GetData());
860 } else if (static_cast<uint32_t>(child_index) >=
861 synthetic
862 ->GetNumChildrenIgnoringErrors() /* synthetic does
863 not have that
864 many values */) {
865 valobj_sp->GetExpressionPath(var_expr_path_strm);
866 error.SetErrorStringWithFormat(
867 "array index %ld is not valid for \"(%s) %s\"", child_index,
868 valobj_sp->GetTypeName().AsCString("<invalid type>"),
869 var_expr_path_strm.GetData());
870 } else {
871 child_valobj_sp = synthetic->GetChildAtIndex(child_index);
872 if (!child_valobj_sp) {
873 valobj_sp->GetExpressionPath(var_expr_path_strm);
874 error.SetErrorStringWithFormat(
875 "array index %ld is not valid for \"(%s) %s\"", child_index,
876 valobj_sp->GetTypeName().AsCString("<invalid type>"),
877 var_expr_path_strm.GetData());
878 }
879 }
880 } else {
881 child_valobj_sp =
882 valobj_sp->GetSyntheticArrayMember(child_index, true);
883 if (!child_valobj_sp) {
884 valobj_sp->GetExpressionPath(var_expr_path_strm);
885 error.SetErrorStringWithFormat(
886 "failed to use pointer as array for index %ld for "
887 "\"(%s) %s\"",
888 child_index,
889 valobj_sp->GetTypeName().AsCString("<invalid type>"),
890 var_expr_path_strm.GetData());
891 }
892 }
893 } else if (valobj_sp->GetCompilerType().IsArrayType(
894 nullptr, nullptr, &is_incomplete_array)) {
895 // Pass false to dynamic_value here so we can tell the difference
896 // between no dynamic value and no member of this type...
897 child_valobj_sp = valobj_sp->GetChildAtIndex(child_index);
898 if (!child_valobj_sp && (is_incomplete_array || !no_synth_child))
899 child_valobj_sp =
900 valobj_sp->GetSyntheticArrayMember(child_index, true);
901
902 if (!child_valobj_sp) {
903 valobj_sp->GetExpressionPath(var_expr_path_strm);
904 error.SetErrorStringWithFormat(
905 "array index %ld is not valid for \"(%s) %s\"", child_index,
906 valobj_sp->GetTypeName().AsCString("<invalid type>"),
907 var_expr_path_strm.GetData());
908 }
909 } else if (valobj_sp->GetCompilerType().IsScalarType()) {
910 // this is a bitfield asking to display just one bit
911 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(
912 child_index, child_index, true);
913 if (!child_valobj_sp) {
914 valobj_sp->GetExpressionPath(var_expr_path_strm);
915 error.SetErrorStringWithFormat(
916 "bitfield range %ld-%ld is not valid for \"(%s) %s\"",
917 child_index, child_index,
918 valobj_sp->GetTypeName().AsCString("<invalid type>"),
919 var_expr_path_strm.GetData());
920 }
921 } else {
922 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
923 if (no_synth_child /* synthetic is forbidden */ ||
924 !synthetic /* no synthetic */
925 || synthetic == valobj_sp) /* synthetic is the same as the
926 original object */
927 {
928 valobj_sp->GetExpressionPath(var_expr_path_strm);
929 error.SetErrorStringWithFormat(
930 "\"(%s) %s\" is not an array type",
931 valobj_sp->GetTypeName().AsCString("<invalid type>"),
932 var_expr_path_strm.GetData());
933 } else if (static_cast<uint32_t>(child_index) >=
934 synthetic->GetNumChildrenIgnoringErrors() /* synthetic
935 does not have that many values */) {
936 valobj_sp->GetExpressionPath(var_expr_path_strm);
937 error.SetErrorStringWithFormat(
938 "array index %ld is not valid for \"(%s) %s\"", child_index,
939 valobj_sp->GetTypeName().AsCString("<invalid type>"),
940 var_expr_path_strm.GetData());
941 } else {
942 child_valobj_sp = synthetic->GetChildAtIndex(child_index);
943 if (!child_valobj_sp) {
944 valobj_sp->GetExpressionPath(var_expr_path_strm);
945 error.SetErrorStringWithFormat(
946 "array index %ld is not valid for \"(%s) %s\"", child_index,
947 valobj_sp->GetTypeName().AsCString("<invalid type>"),
948 var_expr_path_strm.GetData());
949 }
950 }
951 }
952
953 if (!child_valobj_sp) {
954 // Invalid array index...
955 return ValueObjectSP();
956 }
957
958 if (use_dynamic != eNoDynamicValues) {
959 ValueObjectSP dynamic_value_sp(
960 child_valobj_sp->GetDynamicValue(use_dynamic));
961 if (dynamic_value_sp)
962 child_valobj_sp = dynamic_value_sp;
963 }
964 // Break out early from the switch since we were able to find the child
965 // member
966 break;
967 }
968
969 // this is most probably a BitField, let's take a look
970 if (index_expr.front() != '-') {
971 error.SetErrorStringWithFormat("invalid range expression \"'%s'\"",
972 original_index_expr.str().c_str());
973 return ValueObjectSP();
974 }
975
976 index_expr = index_expr.drop_front();
977 long final_index = 0;
978 if (index_expr.getAsInteger(0, final_index)) {
979 error.SetErrorStringWithFormat("invalid range expression \"'%s'\"",
980 original_index_expr.str().c_str());
981 return ValueObjectSP();
982 }
983
984 // if the format given is [high-low], swap range
985 if (child_index > final_index) {
986 long temp = child_index;
987 child_index = final_index;
988 final_index = temp;
989 }
990
991 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) {
992 // what we have is *ptr[low-high]. the most similar C++ syntax is to
993 // deref ptr and extract bits low thru high out of it. reading array
994 // items low thru high would be done by saying ptr[low-high], without a
995 // deref * sign
996 Status deref_error;
997 ValueObjectSP temp(valobj_sp->Dereference(deref_error));
998 if (!temp || deref_error.Fail()) {
999 valobj_sp->GetExpressionPath(var_expr_path_strm);
1000 error.SetErrorStringWithFormat(
1001 "could not dereference \"(%s) %s\"",
1002 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1003 var_expr_path_strm.GetData());
1004 return ValueObjectSP();
1005 }
1006 valobj_sp = temp;
1007 deref = false;
1008 } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) {
1009 // what we have is *arr[low-high]. the most similar C++ syntax is to
1010 // get arr[0] (an operation that is equivalent to deref-ing arr) and
1011 // extract bits low thru high out of it. reading array items low thru
1012 // high would be done by saying arr[low-high], without a deref * sign
1013 ValueObjectSP temp(valobj_sp->GetChildAtIndex(0));
1014 if (!temp) {
1015 valobj_sp->GetExpressionPath(var_expr_path_strm);
1016 error.SetErrorStringWithFormat(
1017 "could not get item 0 for \"(%s) %s\"",
1018 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1019 var_expr_path_strm.GetData());
1020 return ValueObjectSP();
1021 }
1022 valobj_sp = temp;
1023 deref = false;
1024 }
1025
1026 child_valobj_sp =
1027 valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1028 if (!child_valobj_sp) {
1029 valobj_sp->GetExpressionPath(var_expr_path_strm);
1030 error.SetErrorStringWithFormat(
1031 "bitfield range %ld-%ld is not valid for \"(%s) %s\"", child_index,
1032 final_index, valobj_sp->GetTypeName().AsCString("<invalid type>"),
1033 var_expr_path_strm.GetData());
1034 }
1035
1036 if (!child_valobj_sp) {
1037 // Invalid bitfield range...
1038 return ValueObjectSP();
1039 }
1040
1041 if (use_dynamic != eNoDynamicValues) {
1042 ValueObjectSP dynamic_value_sp(
1043 child_valobj_sp->GetDynamicValue(use_dynamic));
1044 if (dynamic_value_sp)
1045 child_valobj_sp = dynamic_value_sp;
1046 }
1047 // Break out early from the switch since we were able to find the child
1048 // member
1049 break;
1050 }
1051 default:
1052 // Failure...
1053 {
1054 valobj_sp->GetExpressionPath(var_expr_path_strm);
1055 error.SetErrorStringWithFormat(
1056 "unexpected char '%c' encountered after \"%s\" in \"%s\"",
1057 separator_type, var_expr_path_strm.GetData(),
1058 var_expr.str().c_str());
1059
1060 return ValueObjectSP();
1061 }
1062 }
1063
1064 if (child_valobj_sp)
1065 valobj_sp = child_valobj_sp;
1066 }
1067 if (valobj_sp) {
1068 if (deref) {
1069 ValueObjectSP deref_valobj_sp(valobj_sp->Dereference(error));
1070 valobj_sp = deref_valobj_sp;
1071 } else if (address_of) {
1072 ValueObjectSP address_of_valobj_sp(valobj_sp->AddressOf(error));
1073 valobj_sp = address_of_valobj_sp;
1074 }
1075 }
1076 return valobj_sp;
1077}
1078
1079bool StackFrame::GetFrameBaseValue(Scalar &frame_base, Status *error_ptr) {
1080 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1081 if (!m_cfa_is_valid) {
1083 "No frame base available for this historical stack frame.");
1084 return false;
1085 }
1086
1088 if (m_sc.function) {
1091
1093 ExecutionContext exe_ctx(shared_from_this());
1094 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1096 loclist_base_addr =
1098 exe_ctx.GetTargetPtr());
1099
1100 llvm::Expected<Value> expr_value =
1102 &exe_ctx, nullptr, loclist_base_addr, nullptr, nullptr);
1103 if (!expr_value)
1104 m_frame_base_error = expr_value.takeError();
1105 else
1106 m_frame_base = expr_value->ResolveValue(&exe_ctx);
1107 } else {
1108 m_frame_base_error.SetErrorString("No function in symbol context.");
1109 }
1110 }
1111
1113 frame_base = m_frame_base;
1114
1115 if (error_ptr)
1116 *error_ptr = m_frame_base_error;
1117 return m_frame_base_error.Success();
1118}
1119
1121 if (!m_sc.function) {
1122 if (error_ptr) {
1123 error_ptr->SetErrorString("No function in symbol context.");
1124 }
1125 return nullptr;
1126 }
1127
1129}
1130
1132 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1133 if (!m_reg_context_sp) {
1134 ThreadSP thread_sp(GetThread());
1135 if (thread_sp)
1136 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame(this);
1137 }
1138 return m_reg_context_sp;
1139}
1140
1142 GetSymbolContext(eSymbolContextLineEntry);
1143 return m_sc.line_entry.IsValid();
1144}
1145
1148 DynamicValueType use_dynamic) {
1149 ValueObjectSP valobj_sp;
1150 { // Scope for stack frame mutex. We need to drop this mutex before we figure
1151 // out the dynamic value. That will require converting the StackID in the
1152 // VO back to a StackFrame, which will in turn require locking the
1153 // StackFrameList. If we still hold the StackFrame mutex, we could suffer
1154 // lock inversion against the pattern of getting the StackFrameList and
1155 // then the stack frame, which is fairly common.
1156 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1157 if (IsHistorical()) {
1158 return valobj_sp;
1159 }
1160 VariableList *var_list = GetVariableList(true, nullptr);
1161 if (var_list) {
1162 // Make sure the variable is a frame variable
1163 const uint32_t var_idx = var_list->FindIndexForVariable(variable_sp.get());
1164 const uint32_t num_variables = var_list->GetSize();
1165 if (var_idx < num_variables) {
1167 if (!valobj_sp) {
1168 if (m_variable_list_value_objects.GetSize() < num_variables)
1170 valobj_sp = ValueObjectVariable::Create(this, variable_sp);
1172 valobj_sp);
1173 }
1174 }
1175 }
1176 } // End of StackFrame mutex scope.
1177 if (use_dynamic != eNoDynamicValues && valobj_sp) {
1178 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue(use_dynamic);
1179 if (dynamic_sp)
1180 return dynamic_sp;
1181 }
1182 return valobj_sp;
1183}
1184
1186 if (m_sc.block == nullptr)
1187 GetSymbolContext(eSymbolContextBlock);
1188 if (m_sc.block)
1189 return m_sc.block->GetContainingInlinedBlock() != nullptr;
1190 return false;
1191}
1192
1195}
1196
1199}
1200
1202 if (auto recognized_frame_sp = GetRecognizedFrame())
1203 return recognized_frame_sp->ShouldHide();
1204 return false;
1205}
1206
1208 CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
1209 if (cu)
1210 return cu->GetLanguage();
1211 return {};
1212}
1213
1215 SourceLanguage lang_type = GetLanguage();
1216
1217 if (lang_type == eLanguageTypeUnknown) {
1218 SymbolContext sc =
1219 GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol);
1220 if (sc.function)
1221 lang_type = LanguageType(sc.function->GetMangled().GuessLanguage());
1222 else if (sc.symbol)
1223 lang_type = SourceLanguage(sc.symbol->GetMangled().GuessLanguage());
1224 }
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) {
1238 // These are not currently interesting
1239 return std::make_pair(nullptr, 0);
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 ==
1248 immediate_child = &operand.m_children[1];
1249 variable_child = &operand.m_children[0];
1250 }
1251 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 }
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 }
1290 return std::make_pair(nullptr, 0);
1291}
1292
1293std::pair<const Instruction::Operand *, int64_t>
1294GetBaseExplainingDereference(const Instruction::Operand &operand,
1295 RegisterContext &register_context,
1296 lldb::addr_t addr) {
1298 return GetBaseExplainingValue(operand.m_children[0], register_context,
1299 addr);
1300 }
1301 return std::make_pair(nullptr, 0);
1302}
1303} // namespace
1304
1306 TargetSP target_sp = CalculateTarget();
1307
1308 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 const char *plugin_name = nullptr;
1315 const char *flavor = nullptr;
1316 const bool force_live_memory = true;
1317
1318 DisassemblerSP disassembler_sp =
1319 Disassembler::DisassembleRange(target_arch, plugin_name, flavor,
1320 *target_sp, pc_range, force_live_memory);
1321
1322 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
1323 return ValueObjectSP();
1324 }
1325
1326 InstructionSP instruction_sp =
1327 disassembler_sp->GetInstructionList().GetInstructionAtIndex(0);
1328
1329 llvm::SmallVector<Instruction::Operand, 3> operands;
1330
1331 if (!instruction_sp->ParseOperands(operands)) {
1332 return ValueObjectSP();
1333 }
1334
1335 RegisterContextSP register_context_sp = GetRegisterContext();
1336
1337 if (!register_context_sp) {
1338 return ValueObjectSP();
1339 }
1340
1341 for (const Instruction::Operand &operand : operands) {
1342 std::pair<const Instruction::Operand *, int64_t> base_and_offset =
1343 GetBaseExplainingDereference(operand, *register_context_sp, addr);
1344
1345 if (!base_and_offset.first) {
1346 continue;
1347 }
1348
1349 switch (base_and_offset.first->m_type) {
1352 if (target_sp->ResolveLoadAddress(base_and_offset.first->m_immediate +
1353 base_and_offset.second,
1354 addr)) {
1355 auto c_type_system_or_err =
1356 target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeC);
1357 if (auto err = c_type_system_or_err.takeError()) {
1358 LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), std::move(err),
1359 "Unable to guess value for given address: {0}");
1360 return ValueObjectSP();
1361 } else {
1362 auto ts = *c_type_system_or_err;
1363 if (!ts)
1364 return {};
1365 CompilerType void_ptr_type =
1367 .GetPointerType();
1368 return ValueObjectMemory::Create(this, "", addr, void_ptr_type);
1369 }
1370 } else {
1371 return ValueObjectSP();
1372 }
1373 break;
1374 }
1376 return GuessValueForRegisterAndOffset(base_and_offset.first->m_register,
1377 base_and_offset.second);
1378 }
1379 default:
1380 return ValueObjectSP();
1381 }
1382 }
1383
1384 return ValueObjectSP();
1385}
1386
1387namespace {
1388ValueObjectSP GetValueForOffset(StackFrame &frame, ValueObjectSP &parent,
1389 int64_t offset) {
1390 if (offset < 0 || uint64_t(offset) >= parent->GetByteSize()) {
1391 return ValueObjectSP();
1392 }
1393
1394 if (parent->IsPointerOrReferenceType()) {
1395 return parent;
1396 }
1397
1398 for (int ci = 0, ce = parent->GetNumChildrenIgnoringErrors(); ci != ce;
1399 ++ci) {
1400 ValueObjectSP child_sp = parent->GetChildAtIndex(ci);
1401
1402 if (!child_sp) {
1403 return ValueObjectSP();
1404 }
1405
1406 int64_t child_offset = child_sp->GetByteOffset();
1407 int64_t child_size = child_sp->GetByteSize().value_or(0);
1408
1409 if (offset >= child_offset && offset < (child_offset + child_size)) {
1410 return GetValueForOffset(frame, child_sp, offset - child_offset);
1411 }
1412 }
1413
1414 if (offset == 0) {
1415 return parent;
1416 } else {
1417 return ValueObjectSP();
1418 }
1419}
1420
1421ValueObjectSP GetValueForDereferincingOffset(StackFrame &frame,
1422 ValueObjectSP &base,
1423 int64_t offset) {
1424 // base is a pointer to something
1425 // offset is the thing to add to the pointer We return the most sensible
1426 // ValueObject for the result of *(base+offset)
1427
1428 if (!base->IsPointerOrReferenceType()) {
1429 return ValueObjectSP();
1430 }
1431
1432 Status error;
1433 ValueObjectSP pointee = base->Dereference(error);
1434
1435 if (!pointee) {
1436 return ValueObjectSP();
1437 }
1438
1439 if (offset >= 0 && uint64_t(offset) >= pointee->GetByteSize()) {
1440 int64_t index = offset / pointee->GetByteSize().value_or(1);
1441 offset = offset % pointee->GetByteSize().value_or(1);
1442 const bool can_create = true;
1443 pointee = base->GetSyntheticArrayMember(index, can_create);
1444 }
1445
1446 if (!pointee || error.Fail()) {
1447 return ValueObjectSP();
1448 }
1449
1450 return GetValueForOffset(frame, pointee, offset);
1451}
1452
1453/// Attempt to reconstruct the ValueObject for the address contained in a
1454/// given register plus an offset.
1455///
1456/// \param [in] frame
1457/// The current stack frame.
1458///
1459/// \param [in] reg
1460/// The register.
1461///
1462/// \param [in] offset
1463/// The offset from the register.
1464///
1465/// \param [in] disassembler
1466/// A disassembler containing instructions valid up to the current PC.
1467///
1468/// \param [in] variables
1469/// The variable list from the current frame,
1470///
1471/// \param [in] pc
1472/// The program counter for the instruction considered the 'user'.
1473///
1474/// \return
1475/// A string describing the base for the ExpressionPath. This could be a
1476/// variable, a register value, an argument, or a function return value.
1477/// The ValueObject if found. If valid, it has a valid ExpressionPath.
1478lldb::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
1490 // +18 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 // dereference
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.
1504
1505 using namespace OperandMatchers;
1506
1507 const RegisterInfo *reg_info =
1508 frame.GetRegisterContext()->GetRegisterInfoByName(reg.AsCString());
1509 if (!reg_info) {
1510 return ValueObjectSP();
1511 }
1512
1518 : Instruction::Operand::BuildDereference(
1519 Instruction::Operand::BuildRegister(reg));
1520
1521 for (VariableSP var_sp : variables) {
1522 if (var_sp->LocationExpressionList().MatchesOperand(frame, op))
1524 }
1525
1526 const uint32_t current_inst =
1528 if (current_inst == UINT32_MAX) {
1529 return ValueObjectSP();
1530 }
1531
1532 for (uint32_t ii = current_inst - 1; ii != (uint32_t)-1; --ii) {
1533 // This is not an exact algorithm, and it sacrifices accuracy for
1534 // generality. Recognizing "mov" and "ld" instructions –– and which
1535 // are their source and destination operands -- is something the
1536 // disassembler should do for us.
1537 InstructionSP instruction_sp =
1538 disassembler.GetInstructionList().GetInstructionAtIndex(ii);
1539
1540 if (instruction_sp->IsCall()) {
1541 ABISP abi_sp = frame.CalculateProcess()->GetABI();
1542 if (!abi_sp) {
1543 continue;
1544 }
1545
1546 const char *return_register_name;
1547 if (!abi_sp->GetPointerReturnRegister(return_register_name)) {
1548 continue;
1549 }
1550
1551 const RegisterInfo *return_register_info =
1552 frame.GetRegisterContext()->GetRegisterInfoByName(
1553 return_register_name);
1554 if (!return_register_info) {
1555 continue;
1556 }
1557
1558 int64_t offset = 0;
1559
1561 MatchRegOp(*return_register_info))(op) &&
1562 !MatchUnaryOp(
1565 MatchRegOp(*return_register_info),
1566 FetchImmOp(offset)))(op)) {
1567 continue;
1568 }
1569
1570 llvm::SmallVector<Instruction::Operand, 1> operands;
1571 if (!instruction_sp->ParseOperands(operands) || operands.size() != 1) {
1572 continue;
1573 }
1574
1575 switch (operands[0].m_type) {
1576 default:
1577 break;
1579 SymbolContext sc;
1580 Address load_address;
1581 if (!frame.CalculateTarget()->ResolveLoadAddress(
1582 operands[0].m_immediate, load_address)) {
1583 break;
1584 }
1585 frame.CalculateTarget()->GetImages().ResolveSymbolContextForAddress(
1586 load_address, eSymbolContextFunction, sc);
1587 if (!sc.function) {
1588 break;
1589 }
1590 CompilerType function_type = sc.function->GetCompilerType();
1591 if (!function_type.IsFunctionType()) {
1592 break;
1593 }
1594 CompilerType return_type = function_type.GetFunctionReturnType();
1595 RegisterValue return_value;
1596 if (!frame.GetRegisterContext()->ReadRegister(return_register_info,
1597 return_value)) {
1598 break;
1599 }
1600 std::string name_str(
1601 sc.function->GetName().AsCString("<unknown function>"));
1602 name_str.append("()");
1603 Address return_value_address(return_value.GetAsUInt64());
1604 ValueObjectSP return_value_sp = ValueObjectMemory::Create(
1605 &frame, name_str, return_value_address, return_type);
1606 return GetValueForDereferincingOffset(frame, return_value_sp, offset);
1607 }
1608 }
1609
1610 continue;
1611 }
1612
1613 llvm::SmallVector<Instruction::Operand, 2> operands;
1614 if (!instruction_sp->ParseOperands(operands) || operands.size() != 2) {
1615 continue;
1616 }
1617
1618 Instruction::Operand *origin_operand = nullptr;
1619 auto clobbered_reg_matcher = [reg_info](const Instruction::Operand &op) {
1620 return MatchRegOp(*reg_info)(op) && op.m_clobbered;
1621 };
1622
1623 if (clobbered_reg_matcher(operands[0])) {
1624 origin_operand = &operands[1];
1625 }
1626 else if (clobbered_reg_matcher(operands[1])) {
1627 origin_operand = &operands[0];
1628 }
1629 else {
1630 continue;
1631 }
1632
1633 // We have an origin operand. Can we track its value down?
1634 ValueObjectSP source_path;
1635 ConstString origin_register;
1636 int64_t origin_offset = 0;
1637
1638 if (FetchRegOp(origin_register)(*origin_operand)) {
1639 source_path = DoGuessValueAt(frame, origin_register, 0, disassembler,
1640 variables, instruction_sp->GetAddress());
1641 } else if (MatchUnaryOp(
1643 FetchRegOp(origin_register))(*origin_operand) ||
1647 FetchRegOp(origin_register),
1648 FetchImmOp(origin_offset)))(*origin_operand)) {
1649 source_path =
1650 DoGuessValueAt(frame, origin_register, origin_offset, disassembler,
1651 variables, instruction_sp->GetAddress());
1652 if (!source_path) {
1653 continue;
1654 }
1655 source_path =
1656 GetValueForDereferincingOffset(frame, source_path, offset);
1657 }
1658
1659 if (source_path) {
1660 return source_path;
1661 }
1662 }
1663
1664 return ValueObjectSP();
1665}
1666}
1667
1669 int64_t offset) {
1670 TargetSP target_sp = CalculateTarget();
1671
1672 const ArchSpec &target_arch = target_sp->GetArchitecture();
1673
1674 Block *frame_block = GetFrameBlock();
1675
1676 if (!frame_block) {
1677 return ValueObjectSP();
1678 }
1679
1680 Function *function = frame_block->CalculateSymbolContextFunction();
1681 if (!function) {
1682 return ValueObjectSP();
1683 }
1684
1685 AddressRange pc_range = function->GetAddressRange();
1686
1687 if (GetFrameCodeAddress().GetFileAddress() <
1688 pc_range.GetBaseAddress().GetFileAddress() ||
1689 GetFrameCodeAddress().GetFileAddress() -
1690 pc_range.GetBaseAddress().GetFileAddress() >=
1691 pc_range.GetByteSize()) {
1692 return ValueObjectSP();
1693 }
1694
1695 const char *plugin_name = nullptr;
1696 const char *flavor = nullptr;
1697 const bool force_live_memory = true;
1698 DisassemblerSP disassembler_sp =
1699 Disassembler::DisassembleRange(target_arch, plugin_name, flavor,
1700 *target_sp, pc_range, force_live_memory);
1701
1702 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
1703 return ValueObjectSP();
1704 }
1705
1706 const bool get_file_globals = false;
1707 VariableList *variables = GetVariableList(get_file_globals, nullptr);
1708
1709 if (!variables) {
1710 return ValueObjectSP();
1711 }
1712
1713 return DoGuessValueAt(*this, reg, offset, *disassembler_sp, *variables,
1715}
1716
1718 ValueObjectSP value_sp;
1719
1720 if (!name)
1721 return value_sp;
1722
1723 TargetSP target_sp = CalculateTarget();
1724 ProcessSP process_sp = CalculateProcess();
1725
1726 if (!target_sp && !process_sp)
1727 return value_sp;
1728
1729 VariableList variable_list;
1730 VariableSP var_sp;
1731 SymbolContext sc(GetSymbolContext(eSymbolContextBlock));
1732
1733 if (sc.block) {
1734 const bool can_create = true;
1735 const bool get_parent_variables = true;
1736 const bool stop_if_block_is_inlined_function = true;
1737
1738 if (sc.block->AppendVariables(
1739 can_create, get_parent_variables, stop_if_block_is_inlined_function,
1740 [this](Variable *v) { return v->IsInScope(this); },
1741 &variable_list)) {
1742 var_sp = variable_list.FindVariable(name);
1743 }
1744
1745 if (var_sp)
1747 }
1748
1749 return value_sp;
1750}
1751
1753 TargetSP target_sp;
1754 ThreadSP thread_sp(GetThread());
1755 if (thread_sp) {
1756 ProcessSP process_sp(thread_sp->CalculateProcess());
1757 if (process_sp)
1758 target_sp = process_sp->CalculateTarget();
1759 }
1760 return target_sp;
1761}
1762
1764 ProcessSP process_sp;
1765 ThreadSP thread_sp(GetThread());
1766 if (thread_sp)
1767 process_sp = thread_sp->CalculateProcess();
1768 return process_sp;
1769}
1770
1772
1773StackFrameSP StackFrame::CalculateStackFrame() { return shared_from_this(); }
1774
1776 exe_ctx.SetContext(shared_from_this());
1777}
1778
1780 const FormatEntity::Entry *format,
1781 llvm::StringRef frame_marker) {
1782 GetSymbolContext(eSymbolContextEverything);
1783 ExecutionContext exe_ctx(shared_from_this());
1784 StreamString s;
1785 s.PutCString(frame_marker);
1786
1787 if (format && FormatEntity::Format(*format, s, &m_sc, &exe_ctx, nullptr,
1788 nullptr, false, false)) {
1789 strm.PutCString(s.GetString());
1790 return true;
1791 }
1792 return false;
1793}
1794
1795void StackFrame::DumpUsingSettingsFormat(Stream *strm, bool show_unique,
1796 const char *frame_marker) {
1797 if (strm == nullptr)
1798 return;
1799
1800 ExecutionContext exe_ctx(shared_from_this());
1801
1802 const FormatEntity::Entry *frame_format = nullptr;
1803 Target *target = exe_ctx.GetTargetPtr();
1804 if (target) {
1805 if (show_unique) {
1806 frame_format = target->GetDebugger().GetFrameFormatUnique();
1807 } else {
1808 frame_format = target->GetDebugger().GetFrameFormat();
1809 }
1810 }
1811 if (!DumpUsingFormat(*strm, frame_format, frame_marker)) {
1812 Dump(strm, true, false);
1813 strm->EOL();
1814 }
1815}
1816
1817void StackFrame::Dump(Stream *strm, bool show_frame_index,
1818 bool show_fullpaths) {
1819 if (strm == nullptr)
1820 return;
1821
1822 if (show_frame_index)
1823 strm->Printf("frame #%u: ", m_frame_index);
1824 ExecutionContext exe_ctx(shared_from_this());
1825 Target *target = exe_ctx.GetTargetPtr();
1826 strm->Printf("0x%0*" PRIx64 " ",
1827 target ? (target->GetArchitecture().GetAddressByteSize() * 2)
1828 : 16,
1829 GetFrameCodeAddress().GetLoadAddress(target));
1830 GetSymbolContext(eSymbolContextEverything);
1831 const bool show_module = true;
1832 const bool show_inline = true;
1833 const bool show_function_arguments = true;
1834 const bool show_function_name = true;
1836 GetFrameCodeAddress(), show_fullpaths, show_module,
1837 show_inline, show_function_arguments,
1838 show_function_name);
1839}
1840
1842 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1843 assert(GetStackID() ==
1844 prev_frame.GetStackID()); // TODO: remove this after some testing
1847 if (!m_disassembly.GetString().empty()) {
1850 }
1851}
1852
1854 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1855 assert(GetStackID() ==
1856 curr_frame.GetStackID()); // TODO: remove this after some testing
1857 m_id.SetPC(curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1858 assert(GetThread() == curr_frame.GetThread());
1859 m_frame_index = curr_frame.m_frame_index;
1864 assert(!m_sc.target_sp || !curr_frame.m_sc.target_sp ||
1865 m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get());
1866 assert(!m_sc.module_sp || !curr_frame.m_sc.module_sp ||
1867 m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get());
1868 assert(m_sc.comp_unit == nullptr || curr_frame.m_sc.comp_unit == nullptr ||
1869 m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1870 assert(m_sc.function == nullptr || curr_frame.m_sc.function == nullptr ||
1871 m_sc.function == curr_frame.m_sc.function);
1872 m_sc = curr_frame.m_sc;
1873 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1877}
1878
1881 return true;
1883 return true;
1884 if (!m_disassembly.GetString().empty())
1885 return true;
1886 return false;
1887}
1888
1889bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source,
1890 bool show_unique, const char *frame_marker) {
1891 if (show_frame_info) {
1892 strm.Indent();
1893 DumpUsingSettingsFormat(&strm, show_unique, frame_marker);
1894 }
1895
1896 if (show_source) {
1897 ExecutionContext exe_ctx(shared_from_this());
1898 bool have_source = false, have_debuginfo = false;
1899 Debugger::StopDisassemblyType disasm_display =
1901 Target *target = exe_ctx.GetTargetPtr();
1902 if (target) {
1903 Debugger &debugger = target->GetDebugger();
1904 const uint32_t source_lines_before =
1905 debugger.GetStopSourceLineCount(true);
1906 const uint32_t source_lines_after =
1907 debugger.GetStopSourceLineCount(false);
1908 disasm_display = debugger.GetStopDisassemblyDisplay();
1909
1910 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
1912 have_debuginfo = true;
1913 if (source_lines_before > 0 || source_lines_after > 0) {
1914 uint32_t start_line = m_sc.line_entry.line;
1915 if (!start_line && m_sc.function) {
1916 FileSpec source_file;
1917 m_sc.function->GetStartLineSourceInfo(source_file, start_line);
1918 }
1919
1920 size_t num_lines =
1923 source_lines_before, source_lines_after, "->", &strm);
1924 if (num_lines != 0)
1925 have_source = true;
1926 // TODO: Give here a one time warning if source file is missing.
1927 if (!m_sc.line_entry.line) {
1928 ConstString fn_name = m_sc.GetFunctionName();
1929
1930 if (!fn_name.IsEmpty())
1931 strm.Printf(
1932 "Note: this address is compiler-generated code in function "
1933 "%s that has no source code associated with it.",
1934 fn_name.AsCString());
1935 else
1936 strm.Printf("Note: this address is compiler-generated code that "
1937 "has no source code associated with it.");
1938 strm.EOL();
1939 }
1940 }
1941 }
1942 switch (disasm_display) {
1944 break;
1945
1947 if (have_debuginfo)
1948 break;
1949 [[fallthrough]];
1950
1952 if (have_source)
1953 break;
1954 [[fallthrough]];
1955
1957 if (target) {
1958 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
1959 if (disasm_lines > 0) {
1960 const ArchSpec &target_arch = target->GetArchitecture();
1961 const char *plugin_name = nullptr;
1962 const char *flavor = nullptr;
1963 const bool mixed_source_and_assembly = false;
1965 target->GetDebugger(), target_arch, plugin_name, flavor,
1966 exe_ctx, GetFrameCodeAddress(),
1967 {Disassembler::Limit::Instructions, disasm_lines},
1968 mixed_source_and_assembly, 0,
1970 }
1971 }
1972 break;
1973 }
1974 }
1975 }
1976 return true;
1977}
1978
1980 auto process = GetThread()->GetProcess();
1981 if (!process)
1982 return {};
1983 // If recognizer list has been modified, discard cache.
1984 auto &manager = process->GetTarget().GetFrameRecognizerManager();
1985 auto new_generation = manager.GetGeneration();
1986 if (m_frame_recognizer_generation != new_generation)
1987 m_recognized_frame_sp.reset();
1988 m_frame_recognizer_generation = new_generation;
1989 if (!m_recognized_frame_sp.has_value())
1990 m_recognized_frame_sp = manager.RecognizeFrame(CalculateStackFrame());
1991 return m_recognized_frame_sp.value();
1992}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:382
#define GOT_FRAME_BASE
Definition: StackFrame.cpp:49
#define RESOLVED_GLOBAL_VARIABLES
Definition: StackFrame.cpp:51
#define RESOLVED_FRAME_ID_SYMBOL_SCOPE
Definition: StackFrame.cpp:48
#define RESOLVED_FRAME_CODE_ADDR
Definition: StackFrame.cpp:47
#define RESOLVED_VARIABLES
Definition: StackFrame.cpp:50
A section + offset based address range class.
Definition: AddressRange.h:25
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:211
void SetByteSize(lldb::addr_t byte_size)
Set accessor for the byte size of this range.
Definition: AddressRange.h:239
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:223
A section + offset based address class.
Definition: Address.h:62
lldb::addr_t GetLoadAddress(Target *target) const
Get the load address.
Definition: Address.cpp:313
lldb::addr_t GetOpcodeLoadAddress(Target *target, AddressClass addr_class=AddressClass::eInvalid) const
Get the load address as an opcode load address.
Definition: Address.cpp:370
bool SetOpcodeLoadAddress(lldb::addr_t load_addr, Target *target, AddressClass addr_class=AddressClass::eInvalid, bool allow_section_end=false)
Definition: Address.cpp:381
void SetRawAddress(lldb::addr_t addr)
Definition: Address.h:454
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:285
lldb::addr_t GetFileAddress() const
Get the file address.
Definition: Address.cpp:293
lldb::addr_t GetOffset() const
Get the section relative offset value.
Definition: Address.h:329
bool IsValid() const
Check if the object state is valid.
Definition: Address.h:355
bool IsSectionOffset() const
Check if an address is section offset.
Definition: Address.h:342
bool SetOffset(lldb::addr_t offset)
Set accessor for the offset.
Definition: Address.h:448
An architecture specification class.
Definition: ArchSpec.h:31
uint32_t GetAddressByteSize() const
Returns the size in bytes of an address of the current architecture.
Definition: ArchSpec.cpp:691
uint32_t GetMaximumOpcodeByteSize() const
Definition: ArchSpec.cpp:934
A class that describes a single lexical block.
Definition: Block.h:41
Block * GetContainingInlinedBlock()
Get the inlined block that contains this block.
Definition: Block.cpp:208
Function * CalculateSymbolContextFunction() override
Definition: Block.cpp:154
uint32_t AppendVariables(bool can_create, bool get_parent_variables, bool stop_if_block_is_inlined_function, const std::function< bool(Variable *)> &filter, VariableList *variable_list)
Appends the variables from this block, and optionally from all parent blocks, to variable_list.
Definition: Block.cpp:459
uint32_t AppendBlockVariables(bool can_create, bool get_child_block_variables, bool stop_if_child_block_is_inlined_function, const std::function< bool(Variable *)> &filter, VariableList *variable_list)
Get the variable list for this block and optionally all child blocks if get_child_variables is true.
Definition: Block.cpp:429
A class that describes a compilation unit.
Definition: CompileUnit.h:43
lldb::VariableListSP GetVariableList(bool can_create)
Get the variable list for a compile unit.
lldb::LanguageType GetLanguage()
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
CompilerType GetBasicTypeFromAST(lldb::BasicType basic_type) const
Create related types using the current type's AST.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
CompilerType GetFunctionReturnType() const
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
bool IsEmpty() const
Test for empty string.
Definition: ConstString.h:304
size_t GetLength() const
Get the length in bytes of string value.
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
"lldb/Expression/DWARFExpressionList.h" Encapsulates a range map from file address range to a single ...
llvm::Expected< Value > Evaluate(ExecutionContext *exe_ctx, RegisterContext *reg_ctx, lldb::addr_t func_load_addr, const Value *initial_value_ptr, const Value *object_address_ptr) const
A class to manage flag bits.
Definition: Debugger.h:80
uint64_t GetDisassemblyLineCount() const
Definition: Debugger.cpp:540
StopDisassemblyType GetStopDisassemblyDisplay() const
Definition: Debugger.cpp:533
uint64_t GetStopSourceLineCount(bool before) const
Definition: Debugger.cpp:526
const FormatEntity::Entry * GetFrameFormat() const
Definition: Debugger.cpp:284
const FormatEntity::Entry * GetFrameFormatUnique() const
Definition: Debugger.cpp:289
InstructionList & GetInstructionList()
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, Target &target, const AddressRange &disasm_range, bool force_live_memory=false)
static bool Disassemble(Debugger &debugger, const ArchSpec &arch, const char *plugin_name, const char *flavor, const ExecutionContext &exe_ctx, const Address &start, Limit limit, bool mixed_source_and_assembly, uint32_t num_mixed_context_lines, uint32_t options, Stream &strm)
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
ExecutionContextScope * GetBestExecutionContextScope() const
void SetContext(const lldb::TargetSP &target_sp, bool get_process)
Target * GetTargetPtr() const
Returns a pointer to the target object.
A file utility class.
Definition: FileSpec.h:56
bool IsClear(ValueType bit) const
Test a single flag bit to see if it is clear (zero).
Definition: Flags.h:111
ValueType Get() const
Get accessor for all flags.
Definition: Flags.h:40
ValueType Clear(ValueType mask=~static_cast< ValueType >(0))
Clear one or more flags.
Definition: Flags.h:61
void Reset(ValueType flags)
Set accessor for all flags.
Definition: Flags.h:52
ValueType Set(ValueType mask)
Set one or more flags by logical OR'ing mask with the current flags.
Definition: Flags.h:73
A class that describes a function.
Definition: Function.h:399
const AddressRange & GetAddressRange()
Definition: Function.h:447
CompilerType GetCompilerType()
Definition: Function.cpp:560
DWARFExpressionList & GetFrameBaseExpression()
Get accessor for the frame base location.
Definition: Function.h:514
ConstString GetName() const
Definition: Function.cpp:693
const Mangled & GetMangled() const
Definition: Function.h:528
void GetStartLineSourceInfo(FileSpec &source_file, uint32_t &line_no)
Find the file and line number of the source location of the start of the function.
Definition: Function.cpp:270
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:371
uint32_t GetIndexOfInstructionAtAddress(const Address &addr)
lldb::InstructionSP GetInstructionAtIndex(size_t idx) const
lldb::LanguageType GuessLanguage() const
Try to guess the language from the mangling.
Definition: Mangled.cpp:391
const RegisterInfo * GetRegisterInfoByName(llvm::StringRef reg_name, uint32_t start_idx=0)
virtual bool ReadRegister(const RegisterInfo *reg_info, RegisterValue &reg_value)=0
uint64_t GetAsUInt64(uint64_t fail_value=UINT64_MAX, bool *success_ptr=nullptr) const
size_t DisplaySourceLinesWithLineNumbers(const FileSpec &file, uint32_t line, uint32_t column, uint32_t context_before, uint32_t context_after, const char *current_line_cstr, Stream *s, const SymbolContextList *bp_locs=nullptr)
This base class provides an interface to stack frames.
Definition: StackFrame.h:43
void SetSymbolContextScope(SymbolContextScope *symbol_scope)
Definition: StackFrame.cpp:184
uint16_t m_frame_recognizer_generation
Definition: StackFrame.h:542
lldb::VariableListSP m_variable_list_sp
Definition: StackFrame.h:552
void UpdatePreviousFrameFromCurrentFrame(StackFrame &curr_frame)
lldb::ThreadSP GetThread() const
Definition: StackFrame.h:127
Address m_frame_code_addr
The frame code address (might not be the same as the actual PC for inlined frames) as a section/offse...
Definition: StackFrame.h:537
@ eExpressionPathOptionsInspectAnonymousUnions
Definition: StackFrame.h:51
@ eExpressionPathOptionsAllowDirectIVarAccess
Definition: StackFrame.h:50
@ eExpressionPathOptionsNoSyntheticChildren
Definition: StackFrame.h:48
bool IsHidden()
Query whether this frame should be hidden from backtraces.
VariableList * GetVariableList(bool get_file_globals, Status *error_ptr)
Retrieve the list of variables that are in scope at this StackFrame's pc.
Definition: StackFrame.cpp:424
DWARFExpressionList * GetFrameBaseExpression(Status *error_ptr)
Get the DWARFExpressionList corresponding to the Canonical Frame Address.
void UpdateCurrentFrameFromPreviousFrame(StackFrame &prev_frame)
ValueObjectList m_variable_list_value_objects
Value objects for each variable in m_variable_list_sp.
Definition: StackFrame.h:554
bool m_cfa_is_valid
Does this frame have a CFA? Different from CFA == LLDB_INVALID_ADDRESS.
Definition: StackFrame.h:544
std::optional< lldb::RecognizedStackFrameSP > m_recognized_frame_sp
Definition: StackFrame.h:555
void DumpUsingSettingsFormat(Stream *strm, bool show_unique=false, const char *frame_marker=nullptr)
Print a description for this frame using the frame-format formatter settings.
bool IsInlined()
Query whether this frame is a concrete frame on the call stack, or if it is an inlined frame derived ...
lldb::ValueObjectSP GetValueForVariableExpressionPath(llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic, uint32_t options, lldb::VariableSP &var_sp, Status &error)
Create a ValueObject for a variable name / pathname, possibly including simple dereference/child sele...
Definition: StackFrame.cpp:508
SourceLanguage GuessLanguage()
Similar to GetLanguage(), but is allowed to take a potentially incorrect guess if exact information i...
lldb::RegisterContextSP GetRegisterContext()
Get the RegisterContext for this frame, if possible.
lldb::RegisterContextSP m_reg_context_sp
Definition: StackFrame.h:531
lldb::ValueObjectSP GuessValueForRegisterAndOffset(ConstString reg, int64_t offset)
Attempt to reconstruct the ValueObject for the address contained in a given register plus an offset.
lldb::VariableListSP GetInScopeVariableList(bool get_file_globals, bool must_have_valid_location=false)
Retrieve the list of variables that are in scope at this StackFrame's pc.
Definition: StackFrame.cpp:475
Address GetFrameCodeAddressForSymbolication()
Get the current code Address suitable for symbolication, may not be the same as GetFrameCodeAddress()...
Definition: StackFrame.cpp:222
@ History
A historical stack frame – possibly without CFA or registers or local variables.
@ Artificial
An artificial stack frame (e.g.
uint32_t m_concrete_frame_index
Definition: StackFrame.h:530
bool m_behaves_like_zeroth_frame
Whether this frame behaves like the zeroth frame, in the sense that its pc value might not immediatel...
Definition: StackFrame.h:551
lldb::ValueObjectSP GuessValueForAddress(lldb::addr_t addr)
Attempt to econstruct the ValueObject for a given raw address touched by the current instruction.
bool ChangePC(lldb::addr_t pc)
Change the pc value for a given thread.
Definition: StackFrame.cpp:247
lldb::ThreadSP CalculateThread() override
SourceLanguage GetLanguage()
Query this frame to determine what the default language should be when parsing expressions given the ...
lldb::ValueObjectSP GetValueObjectForFrameVariable(const lldb::VariableSP &variable_sp, lldb::DynamicValueType use_dynamic)
Create a ValueObject for a given Variable in this StackFrame.
StreamString m_disassembly
Definition: StackFrame.h:556
lldb::StackFrameSP CalculateStackFrame() override
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:300
bool IsHistorical() const
Query whether this frame is part of a historical backtrace.
const char * Disassemble()
Return the disassembly for the instructions of this StackFrame's function as a single C string.
Definition: StackFrame.cpp:261
bool IsArtificial() const
Query whether this frame is artificial (e.g a synthesized result of inferring missing tail call frame...
void CalculateExecutionContext(ExecutionContext &exe_ctx) override
Reconstruct the object's execution context into sc.
void Dump(Stream *strm, bool show_frame_index, bool show_fullpaths)
Print a description for this frame using a default format.
uint32_t GetFrameIndex() const
Query this frame to find what frame it is in this Thread's StackFrameList.
Definition: StackFrame.cpp:175
bool HasDebugInformation()
Determine whether this StackFrame has debug information available or not.
bool GetStatus(Stream &strm, bool show_frame_info, bool show_source, bool show_unique=false, const char *frame_marker=nullptr)
Print a description of this stack frame and/or the source context/assembly for this stack frame.
Block * GetFrameBlock()
Get the current lexical scope block for this StackFrame, if possible.
Definition: StackFrame.cpp:275
bool GetFrameBaseValue(Scalar &value, Status *error_ptr)
Return the Canonical Frame Address (DWARF term) for this frame.
bool DumpUsingFormat(Stream &strm, const lldb_private::FormatEntity::Entry *format, llvm::StringRef frame_marker={})
Print a description of this frame using the provided frame format.
lldb::ProcessSP CalculateProcess() override
lldb::RecognizedStackFrameSP GetRecognizedFrame()
std::recursive_mutex m_mutex
Definition: StackFrame.h:557
StackFrame(const lldb::ThreadSP &thread_sp, lldb::user_id_t frame_idx, lldb::user_id_t concrete_frame_idx, lldb::addr_t cfa, bool cfa_is_valid, lldb::addr_t pc, Kind frame_kind, bool behaves_like_zeroth_frame, const SymbolContext *sc_ptr)
Construct a StackFrame object without supplying a RegisterContextSP.
Definition: StackFrame.cpp:53
lldb::ValueObjectSP FindVariable(ConstString name)
Attempt to reconstruct the ValueObject for a variable with a given name from within the current Stack...
const Address & GetFrameCodeAddress()
Get an Address for the current pc value in this StackFrame.
Definition: StackFrame.cpp:190
lldb::TargetSP CalculateTarget() override
void SetPC(lldb::addr_t pc)
Definition: StackID.h:66
SymbolContextScope * GetSymbolContextScope() const
Definition: StackID.h:35
lldb::addr_t GetPC() const
Definition: StackID.h:31
void SetSymbolContextScope(SymbolContextScope *symbol_scope)
Definition: StackID.h:37
void SetCFA(lldb::addr_t cfa)
Definition: StackID.h:68
An error handling class.
Definition: Status.h:44
void Clear()
Clear the object state.
Definition: Status.cpp:166
bool Fail() const
Test for error condition.
Definition: Status.cpp:180
void SetErrorString(llvm::StringRef err_str)
Set the current error string to err_str.
Definition: Status.cpp:232
bool Success() const
Test for success condition.
Definition: Status.cpp:278
const char * GetData() const
Definition: StreamString.h:45
llvm::StringRef GetString() const
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Indent(llvm::StringRef s="")
Indent the current line in the stream.
Definition: Stream.cpp:157
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
size_t EOL()
Output and End of Line character to the stream.
Definition: Stream.cpp:155
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
llvm::StringRef GetInstanceVariableName()
Determines the name of the instance variable for the this decl context.
ConstString GetFunctionName(Mangled::NamePreference preference=Mangled::ePreferDemangled) const
Find a name of the innermost function for the symbol context.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
bool DumpStopContext(Stream *s, ExecutionContextScope *exe_scope, const Address &so_addr, bool show_fullpaths, bool show_module, bool show_inlined_frames, bool show_function_arguments, bool show_function_name, bool show_function_display_name=false, std::optional< Stream::HighlightSettings > settings=std::nullopt) const
Dump the stop context in this object to a Stream.
uint32_t GetResolvedMask() const
void Clear(bool clear_target)
Clear the object's state.
Symbol * symbol
The Symbol for a given query.
lldb::TargetSP target_sp
The Target for a given query.
LineEntry line_entry
The LineEntry for a given query.
Provides public interface for all SymbolFiles.
Definition: SymbolFile.h:50
Status GetFrameVariableError(StackFrame &frame)
Get an error that describes why variables might be missing for a given symbol context.
Definition: SymbolFile.h:279
Mangled & GetMangled()
Definition: Symbol.h:146
SourceManager & GetSourceManager()
Definition: Target.cpp:2826
Debugger & GetDebugger()
Definition: Target.h:1069
const ArchSpec & GetArchitecture() const
Definition: Target.h:1028
CompilerType GetForwardCompilerType()
Definition: Type.cpp:754
void SetValueObjectAtIndex(size_t idx, const lldb::ValueObjectSP &valobj_sp)
lldb::ValueObjectSP GetValueObjectAtIndex(size_t idx)
void Swap(ValueObjectList &value_object_list)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, llvm::StringRef name, const Address &address, lldb::TypeSP &type_sp)
static lldb::ValueObjectSP Create(ExecutionContextScope *exe_scope, const lldb::VariableSP &var_sp)
lldb::VariableSP FindVariable(ConstString name, bool include_static_members=true)
uint32_t FindIndexForVariable(Variable *variable)
bool IsInScope(StackFrame *frame)
Definition: Variable.cpp:275
bool LocationIsValidForFrame(StackFrame *frame)
Definition: Variable.cpp:216
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define UINT32_MAX
Definition: lldb-defines.h:19
bool Format(const Entry &entry, Stream &s, const SymbolContext *sc, const ExecutionContext *exe_ctx, const Address *addr, ValueObject *valobj, bool function_changed, bool initial_function)
std::function< bool(const Instruction::Operand &)> MatchRegOp(const RegisterInfo &info)
std::function< bool(const Instruction::Operand &)> FetchRegOp(ConstString &reg)
std::function< bool(const Instruction::Operand &)> FetchImmOp(int64_t &imm)
std::function< bool(const Instruction::Operand &)> MatchOpType(Instruction::Operand::Type type)
std::function< bool(const Instruction::Operand &)> MatchBinaryOp(std::function< bool(const Instruction::Operand &)> base, std::function< bool(const Instruction::Operand &)> left, std::function< bool(const Instruction::Operand &)> right)
std::function< bool(const Instruction::Operand &)> MatchUnaryOp(std::function< bool(const Instruction::Operand &)> base, std::function< bool(const Instruction::Operand &)> child)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:331
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:315
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:420
std::shared_ptr< lldb_private::RecognizedStackFrame > RecognizedStackFrameSP
Definition: lldb-forward.h:401
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:446
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:480
LanguageType
Programming language type.
@ eLanguageTypeUnknown
Unknown or invalid language value.
@ eLanguageTypeC
Non-standardized C, such as K&R.
@ eLanguageTypeObjC
Objective-C.
std::shared_ptr< lldb_private::Instruction > InstructionSP
Definition: lldb-forward.h:356
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:387
std::shared_ptr< lldb_private::Disassembler > DisassemblerSP
Definition: lldb-forward.h:339
std::shared_ptr< lldb_private::VariableList > VariableListSP
Definition: lldb-forward.h:483
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:482
uint64_t user_id_t
Definition: lldb-types.h:82
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:444
@ eNoDynamicValues
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Definition: lldb-forward.h:392
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:371
enum lldb_private::Instruction::Operand::Type m_type
static Operand BuildImmediate(lldb::addr_t imm, bool neg)
static Operand BuildDereference(const Operand &ref)
std::vector< Operand > m_children
Definition: Disassembler.h:209
static Operand BuildSum(const Operand &lhs, const Operand &rhs)
static Operand BuildRegister(ConstString &r)
uint16_t column
The column number of the source line, or zero if there is no column information.
Definition: LineEntry.h:151
bool IsValid() const
Check if a line entry object is valid.
Definition: LineEntry.cpp:35
uint32_t line
The source line number, or LLDB_INVALID_LINE_NUMBER if there is no line number information.
Definition: LineEntry.h:147
const FileSpec & GetFile() const
Helper to access the file.
Definition: LineEntry.h:134
void ApplyFileMappings(lldb::TargetSP target_sp)
Apply file mappings from target.source-map to the LineEntry's file.
Definition: LineEntry.cpp:244
Every register is described in detail including its name, alternate name (optional),...
A type-erased pair of llvm::dwarf::SourceLanguageName and version.