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"
18#include "lldb/Symbol/Symbol.h"
21#include "lldb/Symbol/Type.h"
23#include "lldb/Target/ABI.h"
26#include "lldb/Target/Process.h"
29#include "lldb/Target/Target.h"
30#include "lldb/Target/Thread.h"
32#include "lldb/Utility/Log.h"
37
39
40#include <memory>
41
42using namespace lldb;
43using namespace lldb_private;
44
45// The first bits in the flags are reserved for the SymbolContext::Scope bits
46// so we know if we have tried to look up information in our internal symbol
47// context (m_sc) already.
48#define RESOLVED_FRAME_CODE_ADDR (uint32_t(eSymbolContextLastItem) << 1)
49#define RESOLVED_FRAME_ID_SYMBOL_SCOPE (RESOLVED_FRAME_CODE_ADDR << 1)
50#define GOT_FRAME_BASE (RESOLVED_FRAME_ID_SYMBOL_SCOPE << 1)
51#define RESOLVED_VARIABLES (GOT_FRAME_BASE << 1)
52#define RESOLVED_GLOBAL_VARIABLES (RESOLVED_VARIABLES << 1)
53
54StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
55 user_id_t unwind_frame_index, addr_t cfa,
56 bool cfa_is_valid, addr_t pc, StackFrame::Kind kind,
57 bool behaves_like_zeroth_frame,
58 const SymbolContext *sc_ptr)
59 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
60 m_concrete_frame_index(unwind_frame_index), m_reg_context_sp(),
61 m_id(pc, cfa, nullptr), m_frame_code_addr(pc), m_sc(), m_flags(),
62 m_frame_base(), m_frame_base_error(), m_cfa_is_valid(cfa_is_valid),
63 m_stack_frame_kind(kind),
64 m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
65 m_variable_list_sp(), m_variable_list_value_objects(),
66 m_recognized_frame_sp(), m_disassembly(), m_mutex() {
67 // If we don't have a CFA value, use the frame index for our StackID so that
68 // recursive functions properly aren't confused with one another on a history
69 // stack.
70 if (IsHistorical() && !m_cfa_is_valid) {
72 }
73
74 if (sc_ptr != nullptr) {
75 m_sc = *sc_ptr;
77 }
78}
79
80StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
81 user_id_t unwind_frame_index,
82 const RegisterContextSP &reg_context_sp, addr_t cfa,
83 addr_t pc, bool behaves_like_zeroth_frame,
84 const SymbolContext *sc_ptr)
85 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
86 m_concrete_frame_index(unwind_frame_index),
87 m_reg_context_sp(reg_context_sp), m_id(pc, cfa, nullptr),
88 m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(),
89 m_frame_base_error(), m_cfa_is_valid(true),
90 m_stack_frame_kind(StackFrame::Kind::Regular),
91 m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
92 m_variable_list_sp(), m_variable_list_value_objects(),
93 m_recognized_frame_sp(), m_disassembly(), m_mutex() {
94 if (sc_ptr != nullptr) {
95 m_sc = *sc_ptr;
97 }
98
99 if (reg_context_sp && !m_sc.target_sp) {
100 m_sc.target_sp = reg_context_sp->CalculateTarget();
101 if (m_sc.target_sp)
102 m_flags.Set(eSymbolContextTarget);
103 }
104}
105
106StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
107 user_id_t unwind_frame_index,
108 const RegisterContextSP &reg_context_sp, addr_t cfa,
109 const Address &pc_addr, bool behaves_like_zeroth_frame,
110 const SymbolContext *sc_ptr)
111 : m_thread_wp(thread_sp), m_frame_index(frame_idx),
112 m_concrete_frame_index(unwind_frame_index),
113 m_reg_context_sp(reg_context_sp),
114 m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa,
115 nullptr),
116 m_frame_code_addr(pc_addr), m_sc(), m_flags(), m_frame_base(),
117 m_frame_base_error(), m_cfa_is_valid(true),
118 m_stack_frame_kind(StackFrame::Kind::Regular),
119 m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
120 m_variable_list_sp(), m_variable_list_value_objects(),
121 m_recognized_frame_sp(), m_disassembly(), m_mutex() {
122 if (sc_ptr != nullptr) {
123 m_sc = *sc_ptr;
125 }
126
127 if (!m_sc.target_sp && reg_context_sp) {
128 m_sc.target_sp = reg_context_sp->CalculateTarget();
129 if (m_sc.target_sp)
130 m_flags.Set(eSymbolContextTarget);
131 }
132
133 ModuleSP pc_module_sp(pc_addr.GetModule());
134 if (!m_sc.module_sp || m_sc.module_sp != pc_module_sp) {
135 if (pc_module_sp) {
136 m_sc.module_sp = pc_module_sp;
137 m_flags.Set(eSymbolContextModule);
138 } else {
139 m_sc.module_sp.reset();
140 }
141 }
142}
143
144StackFrame::~StackFrame() = default;
145
147 std::lock_guard<std::recursive_mutex> guard(m_mutex);
148 // Make sure we have resolved the StackID object's symbol context scope if we
149 // already haven't looked it up.
150
153 // We already have a symbol context scope, we just don't have our flag
154 // bit set.
156 } else {
157 // Calculate the frame block and use this for the stack ID symbol context
158 // scope if we have one.
160 if (scope == nullptr) {
161 // We don't have a block, so use the symbol
162 if (m_flags.IsClear(eSymbolContextSymbol))
163 GetSymbolContext(eSymbolContextSymbol);
164
165 // It is ok if m_sc.symbol is nullptr here
166 scope = m_sc.symbol;
167 }
168 // Set the symbol context scope (the accessor will set the
169 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
171 }
172 }
173 return m_id;
174}
175
177 ThreadSP thread_sp = GetThread();
178 if (thread_sp)
179 return thread_sp->GetStackFrameList()->GetVisibleStackFrameIndex(
181 else
182 return m_frame_index;
183}
184
186 std::lock_guard<std::recursive_mutex> guard(m_mutex);
188 m_id.SetSymbolContextScope(symbol_scope);
189}
190
192 std::lock_guard<std::recursive_mutex> guard(m_mutex);
196
197 // Resolve the PC into a temporary address because if ResolveLoadAddress
198 // fails to resolve the address, it will clear the address object...
199 ThreadSP thread_sp(GetThread());
200 if (thread_sp) {
201 TargetSP target_sp(thread_sp->CalculateTarget());
202 if (target_sp) {
203 const bool allow_section_end = true;
205 m_frame_code_addr.GetOffset(), target_sp.get(),
206 AddressClass::eCode, allow_section_end)) {
208 if (module_sp) {
209 m_sc.module_sp = module_sp;
210 m_flags.Set(eSymbolContextModule);
211 }
212 }
213 }
214 }
215 }
216 return m_frame_code_addr;
217}
218
219// This can't be rewritten into a call to
220// RegisterContext::GetPCForSymbolication because this
221// StackFrame may have been constructed with a special pc,
222// e.g. tail-call artificial frames.
224 Address lookup_addr(GetFrameCodeAddress());
225 if (!lookup_addr.IsValid())
226 return lookup_addr;
228 return lookup_addr;
229
230 addr_t offset = lookup_addr.GetOffset();
231 if (offset > 0) {
232 lookup_addr.SetOffset(offset - 1);
233 } else {
234 // lookup_addr is the start of a section. We need do the math on the
235 // actual load address and re-compute the section. We're working with
236 // a 'noreturn' function at the end of a section.
237 TargetSP target_sp = CalculateTarget();
238 if (target_sp) {
239 addr_t addr_minus_one = lookup_addr.GetOpcodeLoadAddress(
240 target_sp.get(), AddressClass::eCode) -
241 1;
242 lookup_addr.SetOpcodeLoadAddress(addr_minus_one, target_sp.get());
243 }
244 }
245 return lookup_addr;
246}
247
249 std::lock_guard<std::recursive_mutex> guard(m_mutex);
250 // We can't change the pc value of a history stack frame - it is immutable.
251 if (IsHistorical())
252 return false;
254 m_sc.Clear(false);
255 m_flags.Reset(0);
256 ThreadSP thread_sp(GetThread());
257 if (thread_sp)
258 thread_sp->ClearStackFrames();
259 return true;
260}
261
263 std::lock_guard<std::recursive_mutex> guard(m_mutex);
264 if (!m_disassembly.Empty())
265 return m_disassembly.GetData();
266
267 ExecutionContext exe_ctx(shared_from_this());
268 if (Target *target = exe_ctx.GetTargetPtr()) {
269 Disassembler::Disassemble(target->GetDebugger(), target->GetArchitecture(),
270 *this, m_disassembly);
271 }
272
273 return m_disassembly.Empty() ? nullptr : m_disassembly.GetData();
274}
275
277 if (m_sc.block == nullptr && m_flags.IsClear(eSymbolContextBlock))
278 GetSymbolContext(eSymbolContextBlock);
279
280 if (m_sc.block) {
281 Block *inline_block = m_sc.block->GetContainingInlinedBlock();
282 if (inline_block) {
283 // Use the block with the inlined function info as the frame block we
284 // want this frame to have only the variables for the inlined function
285 // and its non-inlined block child blocks.
286 return inline_block;
287 } else {
288 // This block is not contained within any inlined function blocks with so
289 // we want to use the top most function block.
290 return &m_sc.function->GetBlock(false);
291 }
292 }
293 return nullptr;
294}
295
296// Get the symbol context if we already haven't done so by resolving the
297// PC address as much as possible. This way when we pass around a
298// StackFrame object, everyone will have as much information as possible and no
299// one will ever have to look things up manually.
300const SymbolContext &
301StackFrame::GetSymbolContext(SymbolContextItem resolve_scope) {
302 std::lock_guard<std::recursive_mutex> guard(m_mutex);
303 // Copy our internal symbol context into "sc".
304 if ((m_flags.Get() & resolve_scope) != resolve_scope) {
305 uint32_t resolved = 0;
306
307 // If the target was requested add that:
308 if (!m_sc.target_sp) {
310 if (m_sc.target_sp)
311 resolved |= eSymbolContextTarget;
312 }
313
314 // Resolve our PC to section offset if we haven't already done so and if we
315 // don't have a module. The resolved address section will contain the
316 // module to which it belongs
319
320 // If this is not frame zero, then we need to subtract 1 from the PC value
321 // when doing address lookups since the PC will be on the instruction
322 // following the function call instruction...
324
325 if (m_sc.module_sp) {
326 // We have something in our stack frame symbol context, lets check if we
327 // haven't already tried to lookup one of those things. If we haven't
328 // then we will do the query.
329
330 SymbolContextItem actual_resolve_scope = SymbolContextItem(0);
331
332 if (resolve_scope & eSymbolContextCompUnit) {
333 if (m_flags.IsClear(eSymbolContextCompUnit)) {
334 if (m_sc.comp_unit)
335 resolved |= eSymbolContextCompUnit;
336 else
337 actual_resolve_scope |= eSymbolContextCompUnit;
338 }
339 }
340
341 if (resolve_scope & eSymbolContextFunction) {
342 if (m_flags.IsClear(eSymbolContextFunction)) {
343 if (m_sc.function)
344 resolved |= eSymbolContextFunction;
345 else
346 actual_resolve_scope |= eSymbolContextFunction;
347 }
348 }
349
350 if (resolve_scope & eSymbolContextBlock) {
351 if (m_flags.IsClear(eSymbolContextBlock)) {
352 if (m_sc.block)
353 resolved |= eSymbolContextBlock;
354 else
355 actual_resolve_scope |= eSymbolContextBlock;
356 }
357 }
358
359 if (resolve_scope & eSymbolContextSymbol) {
360 if (m_flags.IsClear(eSymbolContextSymbol)) {
361 if (m_sc.symbol)
362 resolved |= eSymbolContextSymbol;
363 else
364 actual_resolve_scope |= eSymbolContextSymbol;
365 }
366 }
367
368 if (resolve_scope & eSymbolContextLineEntry) {
369 if (m_flags.IsClear(eSymbolContextLineEntry)) {
370 if (m_sc.line_entry.IsValid())
371 resolved |= eSymbolContextLineEntry;
372 else
373 actual_resolve_scope |= eSymbolContextLineEntry;
374 }
375 }
376
377 if (actual_resolve_scope) {
378 // We might be resolving less information than what is already in our
379 // current symbol context so resolve into a temporary symbol context
380 // "sc" so we don't clear out data we have already found in "m_sc"
381 SymbolContext sc;
382 // Set flags that indicate what we have tried to resolve
383 resolved |= m_sc.module_sp->ResolveSymbolContextForAddress(
384 lookup_addr, actual_resolve_scope, sc);
385 // Only replace what we didn't already have as we may have information
386 // for an inlined function scope that won't match what a standard
387 // lookup by address would match
388 if ((resolved & eSymbolContextCompUnit) && m_sc.comp_unit == nullptr)
390 if ((resolved & eSymbolContextFunction) && m_sc.function == nullptr)
392 if ((resolved & eSymbolContextBlock) && m_sc.block == nullptr)
393 m_sc.block = sc.block;
394 if ((resolved & eSymbolContextSymbol) && m_sc.symbol == nullptr)
395 m_sc.symbol = sc.symbol;
396 if ((resolved & eSymbolContextLineEntry) &&
400 }
401 }
402 } else {
403 // If we don't have a module, then we can't have the compile unit,
404 // function, block, line entry or symbol, so we can safely call
405 // ResolveSymbolContextForAddress with our symbol context member m_sc.
406 if (m_sc.target_sp) {
407 resolved |= m_sc.target_sp->GetImages().ResolveSymbolContextForAddress(
408 lookup_addr, resolve_scope, m_sc);
409 }
410 }
411
412 // Update our internal flags so we remember what we have tried to locate so
413 // we don't have to keep trying when more calls to this function are made.
414 // We might have dug up more information that was requested (for example if
415 // we were asked to only get the block, we will have gotten the compile
416 // unit, and function) so set any additional bits that we resolved
417 m_flags.Set(resolve_scope | resolved);
418 }
419
420 // Return the symbol context with everything that was possible to resolve
421 // resolved.
422 return m_sc;
423}
424
426 Status *error_ptr) {
427 std::lock_guard<std::recursive_mutex> guard(m_mutex);
430 m_variable_list_sp = std::make_shared<VariableList>();
431
432 Block *frame_block = GetFrameBlock();
433
434 if (frame_block) {
435 const bool get_child_variables = true;
436 const bool can_create = true;
437 const bool stop_if_child_block_is_inlined_function = true;
438 frame_block->AppendBlockVariables(can_create, get_child_variables,
439 stop_if_child_block_is_inlined_function,
440 [](Variable *v) { return true; },
441 m_variable_list_sp.get());
442 }
443 }
444
445 if (m_flags.IsClear(RESOLVED_GLOBAL_VARIABLES) && get_file_globals) {
447
448 if (m_flags.IsClear(eSymbolContextCompUnit))
449 GetSymbolContext(eSymbolContextCompUnit);
450
451 if (m_sc.comp_unit) {
452 VariableListSP global_variable_list_sp(
455 m_variable_list_sp->AddVariables(global_variable_list_sp.get());
456 else
457 m_variable_list_sp = global_variable_list_sp;
458 }
459 }
460
461 if (error_ptr && m_variable_list_sp->GetSize() == 0) {
462 // Check with the symbol file to check if there is an error for why we
463 // don't have variables that the user might need to know about.
464 GetSymbolContext(eSymbolContextEverything);
465 if (m_sc.module_sp) {
466 SymbolFile *sym_file = m_sc.module_sp->GetSymbolFile();
467 if (sym_file)
468 *error_ptr = sym_file->GetFrameVariableError(*this);
469 }
470 }
471
472 return m_variable_list_sp.get();
473}
474
477 bool must_have_valid_location) {
478 std::lock_guard<std::recursive_mutex> guard(m_mutex);
479 // We can't fetch variable information for a history stack frame.
480 if (IsHistorical())
481 return VariableListSP();
482
483 VariableListSP var_list_sp(new VariableList);
484 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextBlock);
485
486 if (m_sc.block) {
487 const bool can_create = true;
488 const bool get_parent_variables = true;
489 const bool stop_if_block_is_inlined_function = true;
491 can_create, get_parent_variables, stop_if_block_is_inlined_function,
492 [this, must_have_valid_location](Variable *v) {
493 return v->IsInScope(this) && (!must_have_valid_location ||
494 v->LocationIsValidForFrame(this));
495 },
496 var_list_sp.get());
497 }
498
499 if (m_sc.comp_unit && get_file_globals) {
500 VariableListSP global_variable_list_sp(
502 if (global_variable_list_sp)
503 var_list_sp->AddVariables(global_variable_list_sp.get());
504 }
505
506 return var_list_sp;
507}
508
510 llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options,
511 VariableSP &var_sp, Status &error) {
512 ExecutionContext exe_ctx;
514 bool use_DIL = exe_ctx.GetTargetRef().GetUseDIL(&exe_ctx);
515 if (use_DIL)
516 return DILGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
517 var_sp, error);
518
519 return LegacyGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
520 var_sp, error);
521}
522
524 llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic,
525 uint32_t options, lldb::VariableSP &var_sp, Status &error) {
526 // This is a place-holder for the calls into the DIL parser and
527 // evaluator. For now, just call the "real" frame variable implementation.
528 return LegacyGetValueForVariableExpressionPath(var_expr, use_dynamic, options,
529 var_sp, error);
530}
531
533 llvm::StringRef var_expr, DynamicValueType use_dynamic, uint32_t options,
534 VariableSP &var_sp, Status &error) {
535 llvm::StringRef original_var_expr = var_expr;
536 // We can't fetch variable information for a history stack frame.
537 if (IsHistorical())
538 return ValueObjectSP();
539
540 if (var_expr.empty()) {
541 error = Status::FromErrorStringWithFormatv("invalid variable path '{0}'",
542 var_expr);
543 return ValueObjectSP();
544 }
545
546 const bool check_ptr_vs_member =
548 const bool no_fragile_ivar =
550 const bool no_synth_child =
552 // const bool no_synth_array = (options &
553 // eExpressionPathOptionsNoSyntheticArrayRange) != 0;
554 error.Clear();
555 bool deref = false;
556 bool address_of = false;
557 ValueObjectSP valobj_sp;
558 const bool get_file_globals = true;
559 // When looking up a variable for an expression, we need only consider the
560 // variables that are in scope.
561 VariableListSP var_list_sp(GetInScopeVariableList(get_file_globals));
562 VariableList *variable_list = var_list_sp.get();
563
564 if (!variable_list)
565 return ValueObjectSP();
566
567 // If first character is a '*', then show pointer contents
568 std::string var_expr_storage;
569 if (var_expr[0] == '*') {
570 deref = true;
571 var_expr = var_expr.drop_front(); // Skip the '*'
572 } else if (var_expr[0] == '&') {
573 address_of = true;
574 var_expr = var_expr.drop_front(); // Skip the '&'
575 }
576
577 size_t separator_idx = var_expr.find_first_of(".-[=+~|&^%#@!/?,<>{}");
578 StreamString var_expr_path_strm;
579
580 ConstString name_const_string(var_expr.substr(0, separator_idx));
581
582 var_sp = variable_list->FindVariable(name_const_string, false);
583
584 bool synthetically_added_instance_object = false;
585
586 if (var_sp) {
587 var_expr = var_expr.drop_front(name_const_string.GetLength());
588 }
589
590 if (!var_sp && (options & eExpressionPathOptionsAllowDirectIVarAccess)) {
591 // Check for direct ivars access which helps us with implicit access to
592 // ivars using "this" or "self".
593 GetSymbolContext(eSymbolContextFunction | eSymbolContextBlock);
594 llvm::StringRef instance_var_name = m_sc.GetInstanceVariableName();
595 if (!instance_var_name.empty()) {
596 var_sp = variable_list->FindVariable(ConstString(instance_var_name));
597 if (var_sp) {
598 separator_idx = 0;
599 if (Type *var_type = var_sp->GetType())
600 if (auto compiler_type = var_type->GetForwardCompilerType())
601 if (!compiler_type.IsPointerType())
602 var_expr_storage = ".";
603
604 if (var_expr_storage.empty())
605 var_expr_storage = "->";
606 var_expr_storage += var_expr;
607 var_expr = var_expr_storage;
608 synthetically_added_instance_object = true;
609 }
610 }
611 }
612
613 if (!var_sp && (options & eExpressionPathOptionsInspectAnonymousUnions)) {
614 // Check if any anonymous unions are there which contain a variable with
615 // the name we need
616 for (const VariableSP &variable_sp : *variable_list) {
617 if (!variable_sp)
618 continue;
619 if (!variable_sp->GetName().IsEmpty())
620 continue;
621
622 Type *var_type = variable_sp->GetType();
623 if (!var_type)
624 continue;
625
626 if (!var_type->GetForwardCompilerType().IsAnonymousType())
627 continue;
628 valobj_sp = GetValueObjectForFrameVariable(variable_sp, use_dynamic);
629 if (!valobj_sp)
630 return valobj_sp;
631 valobj_sp = valobj_sp->GetChildMemberWithName(name_const_string);
632 if (valobj_sp)
633 break;
634 }
635 }
636
637 if (var_sp && !valobj_sp) {
638 valobj_sp = GetValueObjectForFrameVariable(var_sp, use_dynamic);
639 if (!valobj_sp)
640 return valobj_sp;
641 }
642 if (!valobj_sp) {
644 "no variable named '{0}' found in this frame", name_const_string);
645 return ValueObjectSP();
646 }
647
648 // We are dumping at least one child
649 while (!var_expr.empty()) {
650 // Calculate the next separator index ahead of time
651 ValueObjectSP child_valobj_sp;
652 const char separator_type = var_expr[0];
653 bool expr_is_ptr = false;
654 switch (separator_type) {
655 case '-':
656 expr_is_ptr = true;
657 if (var_expr.size() >= 2 && var_expr[1] != '>')
658 return ValueObjectSP();
659
660 if (no_fragile_ivar) {
661 // Make sure we aren't trying to deref an objective
662 // C ivar if this is not allowed
663 const uint32_t pointer_type_flags =
664 valobj_sp->GetCompilerType().GetTypeInfo(nullptr);
665 if ((pointer_type_flags & eTypeIsObjC) &&
666 (pointer_type_flags & eTypeIsPointer)) {
667 // This was an objective C object pointer and it was requested we
668 // skip any fragile ivars so return nothing here
669 return ValueObjectSP();
670 }
671 }
672
673 // If we have a non-pointer type with a synthetic value then lets check if
674 // we have a synthetic dereference specified.
675 if (!valobj_sp->IsPointerType() && valobj_sp->HasSyntheticValue()) {
676 Status deref_error;
677 if (valobj_sp->GetCompilerType().IsReferenceType()) {
678 valobj_sp = valobj_sp->GetSyntheticValue()->Dereference(deref_error);
679 if (!valobj_sp || deref_error.Fail()) {
681 "Failed to dereference reference type: {0}", deref_error);
682 return ValueObjectSP();
683 }
684 }
685
686 valobj_sp = valobj_sp->Dereference(deref_error);
687 if (!valobj_sp || deref_error.Fail()) {
689 "Failed to dereference synthetic value: {0}", deref_error);
690 return ValueObjectSP();
691 }
692 // Some synthetic plug-ins fail to set the error in Dereference
693 if (!valobj_sp) {
694 error =
695 Status::FromErrorString("Failed to dereference synthetic value");
696 return ValueObjectSP();
697 }
698 expr_is_ptr = false;
699 }
700
701 var_expr = var_expr.drop_front(); // Remove the '-'
702 [[fallthrough]];
703 case '.': {
704 var_expr = var_expr.drop_front(); // Remove the '.' or '>'
705 separator_idx = var_expr.find_first_of(".-[");
706 ConstString child_name(var_expr.substr(0, var_expr.find_first_of(".-[")));
707
708 if (check_ptr_vs_member) {
709 // We either have a pointer type and need to verify valobj_sp is a
710 // pointer, or we have a member of a class/union/struct being accessed
711 // with the . syntax and need to verify we don't have a pointer.
712 const bool actual_is_ptr = valobj_sp->IsPointerType();
713
714 if (actual_is_ptr != expr_is_ptr) {
715 // Incorrect use of "." with a pointer, or "->" with a
716 // class/union/struct instance or reference.
717 valobj_sp->GetExpressionPath(var_expr_path_strm);
718 if (actual_is_ptr)
720 "\"%s\" is a pointer and . was used to attempt to access "
721 "\"%s\". Did you mean \"%s->%s\"?",
722 var_expr_path_strm.GetData(), child_name.GetCString(),
723 var_expr_path_strm.GetData(), var_expr.str().c_str());
724 else
726 "\"%s\" is not a pointer and -> was used to attempt to "
727 "access \"%s\". Did you mean \"%s.%s\"?",
728 var_expr_path_strm.GetData(), child_name.GetCString(),
729 var_expr_path_strm.GetData(), var_expr.str().c_str());
730 return ValueObjectSP();
731 }
732 }
733 child_valobj_sp = valobj_sp->GetChildMemberWithName(child_name);
734 if (!child_valobj_sp) {
735 if (!no_synth_child) {
736 child_valobj_sp = valobj_sp->GetSyntheticValue();
737 if (child_valobj_sp)
738 child_valobj_sp =
739 child_valobj_sp->GetChildMemberWithName(child_name);
740 }
741
742 if (no_synth_child || !child_valobj_sp) {
743 // No child member with name "child_name"
744 if (synthetically_added_instance_object) {
745 // We added a "this->" or "self->" to the beginning of the
746 // expression and this is the first pointer ivar access, so just
747 // return the normal error
749 "no variable or instance variable named '%s' found in "
750 "this frame",
751 name_const_string.GetCString());
752 } else {
753 valobj_sp->GetExpressionPath(var_expr_path_strm);
754 if (child_name) {
756 "\"%s\" is not a member of \"(%s) %s\"",
757 child_name.GetCString(),
758 valobj_sp->GetTypeName().AsCString("<invalid type>"),
759 var_expr_path_strm.GetData());
760 } else {
762 "incomplete expression path after \"%s\" in \"%s\"",
763 var_expr_path_strm.GetData(),
764 original_var_expr.str().c_str());
765 }
766 }
767 return ValueObjectSP();
768 }
769 }
770 synthetically_added_instance_object = false;
771 // Remove the child name from the path
772 var_expr = var_expr.drop_front(child_name.GetLength());
773 if (use_dynamic != eNoDynamicValues) {
774 ValueObjectSP dynamic_value_sp(
775 child_valobj_sp->GetDynamicValue(use_dynamic));
776 if (dynamic_value_sp)
777 child_valobj_sp = dynamic_value_sp;
778 }
779 } break;
780
781 case '[': {
782 // Array member access, or treating pointer as an array Need at least two
783 // brackets and a number
784 if (var_expr.size() <= 2) {
786 "invalid square bracket encountered after \"%s\" in \"%s\"",
787 var_expr_path_strm.GetData(), var_expr.str().c_str());
788 return ValueObjectSP();
789 }
790
791 // Drop the open brace.
792 var_expr = var_expr.drop_front();
793 long child_index = 0;
794
795 // If there's no closing brace, this is an invalid expression.
796 size_t end_pos = var_expr.find_first_of(']');
797 if (end_pos == llvm::StringRef::npos) {
799 "missing closing square bracket in expression \"%s\"",
800 var_expr_path_strm.GetData());
801 return ValueObjectSP();
802 }
803 llvm::StringRef index_expr = var_expr.take_front(end_pos);
804 llvm::StringRef original_index_expr = index_expr;
805 // Drop all of "[index_expr]"
806 var_expr = var_expr.drop_front(end_pos + 1);
807
808 if (index_expr.consumeInteger(0, child_index)) {
809 // If there was no integer anywhere in the index expression, this is
810 // erroneous expression.
812 "invalid index expression \"%s\"", index_expr.str().c_str());
813 return ValueObjectSP();
814 }
815
816 if (index_expr.empty()) {
817 // The entire index expression was a single integer.
818
819 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) {
820 // what we have is *ptr[low]. the most similar C++ syntax is to deref
821 // ptr and extract bit low out of it. reading array item low would be
822 // done by saying ptr[low], without a deref * sign
823 Status deref_error;
824 ValueObjectSP temp(valobj_sp->Dereference(deref_error));
825 if (!temp || deref_error.Fail()) {
826 valobj_sp->GetExpressionPath(var_expr_path_strm);
828 "could not dereference \"(%s) %s\"",
829 valobj_sp->GetTypeName().AsCString("<invalid type>"),
830 var_expr_path_strm.GetData());
831 return ValueObjectSP();
832 }
833 valobj_sp = temp;
834 deref = false;
835 } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() &&
836 deref) {
837 // what we have is *arr[low]. the most similar C++ syntax is to get
838 // arr[0] (an operation that is equivalent to deref-ing arr) and
839 // extract bit low out of it. reading array item low would be done by
840 // saying arr[low], without a deref * sign
841 ValueObjectSP temp(valobj_sp->GetChildAtIndex(0));
842 if (!temp) {
843 valobj_sp->GetExpressionPath(var_expr_path_strm);
845 "could not get item 0 for \"(%s) %s\"",
846 valobj_sp->GetTypeName().AsCString("<invalid type>"),
847 var_expr_path_strm.GetData());
848 return ValueObjectSP();
849 }
850 valobj_sp = temp;
851 deref = false;
852 }
853
854 bool is_incomplete_array = false;
855 if (valobj_sp->IsPointerType()) {
856 bool is_objc_pointer = true;
857
858 if (valobj_sp->GetCompilerType().GetMinimumLanguage() !=
860 is_objc_pointer = false;
861 else if (!valobj_sp->GetCompilerType().IsPointerType())
862 is_objc_pointer = false;
863
864 if (no_synth_child && is_objc_pointer) {
866 "\"(%s) %s\" is an Objective-C pointer, and cannot be "
867 "subscripted",
868 valobj_sp->GetTypeName().AsCString("<invalid type>"),
869 var_expr_path_strm.GetData());
870
871 return ValueObjectSP();
872 } else if (is_objc_pointer) {
873 // dereferencing ObjC variables is not valid.. so let's try and
874 // recur to synthetic children
875 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
876 if (!synthetic /* no synthetic */
877 || synthetic == valobj_sp) /* synthetic is the same as
878 the original object */
879 {
880 valobj_sp->GetExpressionPath(var_expr_path_strm);
882 "\"(%s) %s\" is not an array type",
883 valobj_sp->GetTypeName().AsCString("<invalid type>"),
884 var_expr_path_strm.GetData());
885 } else if (static_cast<uint32_t>(child_index) >=
886 synthetic
887 ->GetNumChildrenIgnoringErrors() /* synthetic does
888 not have that
889 many values */) {
890 valobj_sp->GetExpressionPath(var_expr_path_strm);
892 "array index %ld is not valid for \"(%s) %s\"", child_index,
893 valobj_sp->GetTypeName().AsCString("<invalid type>"),
894 var_expr_path_strm.GetData());
895 } else {
896 child_valobj_sp = synthetic->GetChildAtIndex(child_index);
897 if (!child_valobj_sp) {
898 valobj_sp->GetExpressionPath(var_expr_path_strm);
900 "array index %ld is not valid for \"(%s) %s\"", child_index,
901 valobj_sp->GetTypeName().AsCString("<invalid type>"),
902 var_expr_path_strm.GetData());
903 }
904 }
905 } else {
906 child_valobj_sp =
907 valobj_sp->GetSyntheticArrayMember(child_index, true);
908 if (!child_valobj_sp) {
909 valobj_sp->GetExpressionPath(var_expr_path_strm);
911 "failed to use pointer as array for index %ld for "
912 "\"(%s) %s\"",
913 child_index,
914 valobj_sp->GetTypeName().AsCString("<invalid type>"),
915 var_expr_path_strm.GetData());
916 }
917 }
918 } else if (valobj_sp->GetCompilerType().IsArrayType(
919 nullptr, nullptr, &is_incomplete_array)) {
920 // Pass false to dynamic_value here so we can tell the difference
921 // between no dynamic value and no member of this type...
922 child_valobj_sp = valobj_sp->GetChildAtIndex(child_index);
923 if (!child_valobj_sp && (is_incomplete_array || !no_synth_child))
924 child_valobj_sp =
925 valobj_sp->GetSyntheticArrayMember(child_index, true);
926
927 if (!child_valobj_sp) {
928 valobj_sp->GetExpressionPath(var_expr_path_strm);
930 "array index %ld is not valid for \"(%s) %s\"", child_index,
931 valobj_sp->GetTypeName().AsCString("<invalid type>"),
932 var_expr_path_strm.GetData());
933 }
934 } else if (valobj_sp->GetCompilerType().IsScalarType()) {
935 // this is a bitfield asking to display just one bit
936 child_valobj_sp = valobj_sp->GetSyntheticBitFieldChild(
937 child_index, child_index, true);
938 if (!child_valobj_sp) {
939 valobj_sp->GetExpressionPath(var_expr_path_strm);
941 "bitfield range %ld-%ld is not valid for \"(%s) %s\"",
942 child_index, child_index,
943 valobj_sp->GetTypeName().AsCString("<invalid type>"),
944 var_expr_path_strm.GetData());
945 }
946 } else {
947 ValueObjectSP synthetic = valobj_sp->GetSyntheticValue();
948 if (no_synth_child /* synthetic is forbidden */ ||
949 !synthetic /* no synthetic */
950 || synthetic == valobj_sp) /* synthetic is the same as the
951 original object */
952 {
953 valobj_sp->GetExpressionPath(var_expr_path_strm);
955 "\"(%s) %s\" is not an array type",
956 valobj_sp->GetTypeName().AsCString("<invalid type>"),
957 var_expr_path_strm.GetData());
958 } else if (static_cast<uint32_t>(child_index) >=
959 synthetic->GetNumChildrenIgnoringErrors() /* synthetic
960 does not have that many values */) {
961 valobj_sp->GetExpressionPath(var_expr_path_strm);
963 "array index %ld is not valid for \"(%s) %s\"", child_index,
964 valobj_sp->GetTypeName().AsCString("<invalid type>"),
965 var_expr_path_strm.GetData());
966 } else {
967 child_valobj_sp = synthetic->GetChildAtIndex(child_index);
968 if (!child_valobj_sp) {
969 valobj_sp->GetExpressionPath(var_expr_path_strm);
971 "array index %ld is not valid for \"(%s) %s\"", child_index,
972 valobj_sp->GetTypeName().AsCString("<invalid type>"),
973 var_expr_path_strm.GetData());
974 }
975 }
976 }
977
978 if (!child_valobj_sp) {
979 // Invalid array index...
980 return ValueObjectSP();
981 }
982
983 if (use_dynamic != eNoDynamicValues) {
984 ValueObjectSP dynamic_value_sp(
985 child_valobj_sp->GetDynamicValue(use_dynamic));
986 if (dynamic_value_sp)
987 child_valobj_sp = dynamic_value_sp;
988 }
989 // Break out early from the switch since we were able to find the child
990 // member
991 break;
992 }
993
994 // this is most probably a BitField, let's take a look
995 if (index_expr.front() != '-') {
997 "invalid range expression \"'%s'\"",
998 original_index_expr.str().c_str());
999 return ValueObjectSP();
1000 }
1001
1002 index_expr = index_expr.drop_front();
1003 long final_index = 0;
1004 if (index_expr.getAsInteger(0, final_index)) {
1006 "invalid range expression \"'%s'\"",
1007 original_index_expr.str().c_str());
1008 return ValueObjectSP();
1009 }
1010
1011 // if the format given is [high-low], swap range
1012 if (child_index > final_index) {
1013 long temp = child_index;
1014 child_index = final_index;
1015 final_index = temp;
1016 }
1017
1018 if (valobj_sp->GetCompilerType().IsPointerToScalarType() && deref) {
1019 // what we have is *ptr[low-high]. the most similar C++ syntax is to
1020 // deref ptr and extract bits low thru high out of it. reading array
1021 // items low thru high would be done by saying ptr[low-high], without a
1022 // deref * sign
1023 Status deref_error;
1024 ValueObjectSP temp(valobj_sp->Dereference(deref_error));
1025 if (!temp || deref_error.Fail()) {
1026 valobj_sp->GetExpressionPath(var_expr_path_strm);
1028 "could not dereference \"(%s) %s\"",
1029 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1030 var_expr_path_strm.GetData());
1031 return ValueObjectSP();
1032 }
1033 valobj_sp = temp;
1034 deref = false;
1035 } else if (valobj_sp->GetCompilerType().IsArrayOfScalarType() && deref) {
1036 // what we have is *arr[low-high]. the most similar C++ syntax is to
1037 // get arr[0] (an operation that is equivalent to deref-ing arr) and
1038 // extract bits low thru high out of it. reading array items low thru
1039 // high would be done by saying arr[low-high], without a deref * sign
1040 ValueObjectSP temp(valobj_sp->GetChildAtIndex(0));
1041 if (!temp) {
1042 valobj_sp->GetExpressionPath(var_expr_path_strm);
1044 "could not get item 0 for \"(%s) %s\"",
1045 valobj_sp->GetTypeName().AsCString("<invalid type>"),
1046 var_expr_path_strm.GetData());
1047 return ValueObjectSP();
1048 }
1049 valobj_sp = temp;
1050 deref = false;
1051 }
1052
1053 child_valobj_sp =
1054 valobj_sp->GetSyntheticBitFieldChild(child_index, final_index, true);
1055 if (!child_valobj_sp) {
1056 valobj_sp->GetExpressionPath(var_expr_path_strm);
1058 "bitfield range %ld-%ld is not valid for \"(%s) %s\"", child_index,
1059 final_index, valobj_sp->GetTypeName().AsCString("<invalid type>"),
1060 var_expr_path_strm.GetData());
1061 }
1062
1063 if (!child_valobj_sp) {
1064 // Invalid bitfield range...
1065 return ValueObjectSP();
1066 }
1067
1068 if (use_dynamic != eNoDynamicValues) {
1069 ValueObjectSP dynamic_value_sp(
1070 child_valobj_sp->GetDynamicValue(use_dynamic));
1071 if (dynamic_value_sp)
1072 child_valobj_sp = dynamic_value_sp;
1073 }
1074 // Break out early from the switch since we were able to find the child
1075 // member
1076 break;
1077 }
1078 default:
1079 // Failure...
1080 {
1081 valobj_sp->GetExpressionPath(var_expr_path_strm);
1083 "unexpected char '%c' encountered after \"%s\" in \"%s\"",
1084 separator_type, var_expr_path_strm.GetData(),
1085 var_expr.str().c_str());
1086
1087 return ValueObjectSP();
1088 }
1089 }
1090
1091 if (child_valobj_sp)
1092 valobj_sp = child_valobj_sp;
1093 }
1094 if (valobj_sp) {
1095 if (deref) {
1096 ValueObjectSP deref_valobj_sp(valobj_sp->Dereference(error));
1097 valobj_sp = deref_valobj_sp;
1098 } else if (address_of) {
1099 ValueObjectSP address_of_valobj_sp(valobj_sp->AddressOf(error));
1100 valobj_sp = address_of_valobj_sp;
1101 }
1102 }
1103 return valobj_sp;
1104}
1105
1106llvm::Error StackFrame::GetFrameBaseValue(Scalar &frame_base) {
1107 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1108 if (!m_cfa_is_valid) {
1110 "No frame base available for this historical stack frame.");
1111 return m_frame_base_error.ToError();
1112 }
1113
1115 if (m_sc.function) {
1118
1120 ExecutionContext exe_ctx(shared_from_this());
1121 addr_t loclist_base_addr = LLDB_INVALID_ADDRESS;
1123 loclist_base_addr =
1125
1126 llvm::Expected<Value> expr_value =
1128 &exe_ctx, nullptr, loclist_base_addr, nullptr, nullptr);
1129 if (!expr_value)
1130 m_frame_base_error = Status::FromError(expr_value.takeError());
1131 else
1132 m_frame_base = expr_value->ResolveValue(&exe_ctx);
1133 } else {
1135 Status::FromErrorString("No function in symbol context.");
1136 }
1137 }
1138
1140 return m_frame_base_error.ToError();
1141
1142 frame_base = m_frame_base;
1143 return llvm::Error::success();
1144}
1145
1147 if (!m_sc.function) {
1148 if (error_ptr) {
1149 *error_ptr = Status::FromErrorString("No function in symbol context.");
1150 }
1151 return nullptr;
1152 }
1153
1155}
1156
1158 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1159 if (!m_reg_context_sp) {
1160 ThreadSP thread_sp(GetThread());
1161 if (thread_sp)
1162 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame(this);
1163 }
1164 return m_reg_context_sp;
1165}
1166
1168 GetSymbolContext(eSymbolContextLineEntry);
1169 return m_sc.line_entry.IsValid();
1170}
1171
1174 DynamicValueType use_dynamic) {
1175 ValueObjectSP valobj_sp;
1176 { // Scope for stack frame mutex. We need to drop this mutex before we figure
1177 // out the dynamic value. That will require converting the StackID in the
1178 // VO back to a StackFrame, which will in turn require locking the
1179 // StackFrameList. If we still hold the StackFrame mutex, we could suffer
1180 // lock inversion against the pattern of getting the StackFrameList and
1181 // then the stack frame, which is fairly common.
1182 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1183 if (IsHistorical()) {
1184 return valobj_sp;
1185 }
1186 VariableList *var_list = GetVariableList(true, nullptr);
1187 if (var_list) {
1188 // Make sure the variable is a frame variable
1189 const uint32_t var_idx = var_list->FindIndexForVariable(variable_sp.get());
1190 const uint32_t num_variables = var_list->GetSize();
1191 if (var_idx < num_variables) {
1193 if (!valobj_sp) {
1194 if (m_variable_list_value_objects.GetSize() < num_variables)
1196 valobj_sp = ValueObjectVariable::Create(this, variable_sp);
1198 valobj_sp);
1199 }
1200 }
1201 }
1202 } // End of StackFrame mutex scope.
1203 if (use_dynamic != eNoDynamicValues && valobj_sp) {
1204 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue(use_dynamic);
1205 if (dynamic_sp)
1206 return dynamic_sp;
1207 }
1208 return valobj_sp;
1209}
1210
1212 if (m_sc.block == nullptr)
1213 GetSymbolContext(eSymbolContextBlock);
1214 if (m_sc.block)
1215 return m_sc.block->GetContainingInlinedBlock() != nullptr;
1216 return false;
1217}
1218
1221}
1222
1225}
1226
1228 if (auto recognized_frame_sp = GetRecognizedFrame())
1229 return recognized_frame_sp->ShouldHide();
1230 return false;
1231}
1232
1234 auto process_sp = CalculateProcess();
1235 SourceLanguage language = GetLanguage();
1236 if (!language)
1237 return {};
1238 if (auto runtime_sp =
1239 process_sp->GetLanguageRuntime(language.AsLanguageType()))
1240 return runtime_sp->GetLanguageSpecificData(
1241 GetSymbolContext(eSymbolContextFunction));
1242 return {};
1243}
1244
1246 const char *name = nullptr;
1248 eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1249 if (sc.block) {
1250 Block *inlined_block = sc.block->GetContainingInlinedBlock();
1251 if (inlined_block) {
1252 const InlineFunctionInfo *inlined_info =
1253 inlined_block->GetInlinedFunctionInfo();
1254 if (inlined_info)
1255 name = inlined_info->GetName().AsCString();
1256 }
1257 }
1258
1259 if (name == nullptr) {
1260 if (sc.function)
1261 name = sc.function->GetName().GetCString();
1262 }
1263
1264 if (name == nullptr) {
1265 if (sc.symbol)
1266 name = sc.symbol->GetName().GetCString();
1267 }
1268
1269 return name;
1270}
1271
1273 const char *name = nullptr;
1275 eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1276 if (sc.block) {
1277 Block *inlined_block = sc.block->GetContainingInlinedBlock();
1278 if (inlined_block) {
1279 const InlineFunctionInfo *inlined_info =
1280 inlined_block->GetInlinedFunctionInfo();
1281 if (inlined_info)
1282 name = inlined_info->GetDisplayName().AsCString();
1283 }
1284 }
1285
1286 if (name == nullptr) {
1287 if (sc.function)
1288 name = sc.function->GetDisplayName().GetCString();
1289 }
1290
1291 if (name == nullptr) {
1292 if (sc.symbol)
1293 name = sc.symbol->GetDisplayName().GetCString();
1294 }
1295 return name;
1296}
1297
1299 CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
1300 if (cu)
1301 return cu->GetLanguage();
1302 return {};
1303}
1304
1306 SourceLanguage lang_type = GetLanguage();
1307
1308 if (lang_type == eLanguageTypeUnknown) {
1309 SymbolContext sc =
1310 GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol);
1311 if (sc.function)
1312 lang_type = LanguageType(sc.function->GetMangled().GuessLanguage());
1313 else if (sc.symbol)
1314 lang_type = SourceLanguage(sc.symbol->GetMangled().GuessLanguage());
1315 }
1316
1317 return lang_type;
1318}
1319
1320namespace {
1321std::pair<const Instruction::Operand *, int64_t>
1322GetBaseExplainingValue(const Instruction::Operand &operand,
1323 RegisterContext &register_context, lldb::addr_t value) {
1324 switch (operand.m_type) {
1329 // These are not currently interesting
1330 return std::make_pair(nullptr, 0);
1332 const Instruction::Operand *immediate_child = nullptr;
1333 const Instruction::Operand *variable_child = nullptr;
1334 if (operand.m_children[0].m_type == Instruction::Operand::Type::Immediate) {
1335 immediate_child = &operand.m_children[0];
1336 variable_child = &operand.m_children[1];
1337 } else if (operand.m_children[1].m_type ==
1339 immediate_child = &operand.m_children[1];
1340 variable_child = &operand.m_children[0];
1341 }
1342 if (!immediate_child) {
1343 return std::make_pair(nullptr, 0);
1344 }
1345 lldb::addr_t adjusted_value = value;
1346 if (immediate_child->m_negative) {
1347 adjusted_value += immediate_child->m_immediate;
1348 } else {
1349 adjusted_value -= immediate_child->m_immediate;
1350 }
1351 std::pair<const Instruction::Operand *, int64_t> base_and_offset =
1352 GetBaseExplainingValue(*variable_child, register_context,
1353 adjusted_value);
1354 if (!base_and_offset.first) {
1355 return std::make_pair(nullptr, 0);
1356 }
1357 if (immediate_child->m_negative) {
1358 base_and_offset.second -= immediate_child->m_immediate;
1359 } else {
1360 base_and_offset.second += immediate_child->m_immediate;
1361 }
1362 return base_and_offset;
1363 }
1365 const RegisterInfo *info =
1366 register_context.GetRegisterInfoByName(operand.m_register.AsCString());
1367 if (!info) {
1368 return std::make_pair(nullptr, 0);
1369 }
1370 RegisterValue reg_value;
1371 if (!register_context.ReadRegister(info, reg_value)) {
1372 return std::make_pair(nullptr, 0);
1373 }
1374 if (reg_value.GetAsUInt64() == value) {
1375 return std::make_pair(&operand, 0);
1376 } else {
1377 return std::make_pair(nullptr, 0);
1378 }
1379 }
1380 }
1381 return std::make_pair(nullptr, 0);
1382}
1383
1384std::pair<const Instruction::Operand *, int64_t>
1385GetBaseExplainingDereference(const Instruction::Operand &operand,
1386 RegisterContext &register_context,
1387 lldb::addr_t addr) {
1389 return GetBaseExplainingValue(operand.m_children[0], register_context,
1390 addr);
1391 }
1392 return std::make_pair(nullptr, 0);
1393}
1394} // namespace
1395
1397 TargetSP target_sp = CalculateTarget();
1398
1399 const ArchSpec &target_arch = target_sp->GetArchitecture();
1400
1401 AddressRange pc_range;
1402 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1403 pc_range.SetByteSize(target_arch.GetMaximumOpcodeByteSize());
1404
1405 const char *plugin_name = nullptr;
1406 const char *flavor = nullptr;
1407 const char *cpu = nullptr;
1408 const char *features = nullptr;
1409 const bool force_live_memory = true;
1410
1412 target_arch, plugin_name, flavor, cpu, features, *target_sp, pc_range,
1413 force_live_memory);
1414
1415 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
1416 return ValueObjectSP();
1417 }
1418
1419 InstructionSP instruction_sp =
1420 disassembler_sp->GetInstructionList().GetInstructionAtIndex(0);
1421
1422 llvm::SmallVector<Instruction::Operand, 3> operands;
1423
1424 if (!instruction_sp->ParseOperands(operands)) {
1425 return ValueObjectSP();
1426 }
1427
1428 RegisterContextSP register_context_sp = GetRegisterContext();
1429
1430 if (!register_context_sp) {
1431 return ValueObjectSP();
1432 }
1433
1434 for (const Instruction::Operand &operand : operands) {
1435 std::pair<const Instruction::Operand *, int64_t> base_and_offset =
1436 GetBaseExplainingDereference(operand, *register_context_sp, addr);
1437
1438 if (!base_and_offset.first) {
1439 continue;
1440 }
1441
1442 switch (base_and_offset.first->m_type) {
1445 if (target_sp->ResolveLoadAddress(base_and_offset.first->m_immediate +
1446 base_and_offset.second,
1447 addr)) {
1448 auto c_type_system_or_err =
1449 target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeC);
1450 if (auto err = c_type_system_or_err.takeError()) {
1451 LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), std::move(err),
1452 "Unable to guess value for given address: {0}");
1453 return ValueObjectSP();
1454 } else {
1455 auto ts = *c_type_system_or_err;
1456 if (!ts)
1457 return {};
1458 CompilerType void_ptr_type =
1460 .GetPointerType();
1461 return ValueObjectMemory::Create(this, "", addr, void_ptr_type);
1462 }
1463 } else {
1464 return ValueObjectSP();
1465 }
1466 break;
1467 }
1469 return GuessValueForRegisterAndOffset(base_and_offset.first->m_register,
1470 base_and_offset.second);
1471 }
1472 default:
1473 return ValueObjectSP();
1474 }
1475 }
1476
1477 return ValueObjectSP();
1478}
1479
1480namespace {
1481ValueObjectSP GetValueForOffset(StackFrame &frame, ValueObjectSP &parent,
1482 int64_t offset) {
1483 if (offset < 0 || uint64_t(offset) >= parent->GetByteSize()) {
1484 return ValueObjectSP();
1485 }
1486
1487 if (parent->IsPointerOrReferenceType()) {
1488 return parent;
1489 }
1490
1491 for (int ci = 0, ce = parent->GetNumChildrenIgnoringErrors(); ci != ce;
1492 ++ci) {
1493 ValueObjectSP child_sp = parent->GetChildAtIndex(ci);
1494
1495 if (!child_sp) {
1496 return ValueObjectSP();
1497 }
1498
1499 int64_t child_offset = child_sp->GetByteOffset();
1500 int64_t child_size = child_sp->GetByteSize().value_or(0);
1501
1502 if (offset >= child_offset && offset < (child_offset + child_size)) {
1503 return GetValueForOffset(frame, child_sp, offset - child_offset);
1504 }
1505 }
1506
1507 if (offset == 0) {
1508 return parent;
1509 } else {
1510 return ValueObjectSP();
1511 }
1512}
1513
1514ValueObjectSP GetValueForDereferincingOffset(StackFrame &frame,
1515 ValueObjectSP &base,
1516 int64_t offset) {
1517 // base is a pointer to something
1518 // offset is the thing to add to the pointer We return the most sensible
1519 // ValueObject for the result of *(base+offset)
1520
1521 if (!base->IsPointerOrReferenceType()) {
1522 return ValueObjectSP();
1523 }
1524
1525 Status error;
1526 ValueObjectSP pointee = base->Dereference(error);
1527
1528 if (!pointee) {
1529 return ValueObjectSP();
1530 }
1531
1532 if (offset >= 0 && uint64_t(offset) >= pointee->GetByteSize()) {
1533 int64_t index = offset / pointee->GetByteSize().value_or(1);
1534 offset = offset % pointee->GetByteSize().value_or(1);
1535 const bool can_create = true;
1536 pointee = base->GetSyntheticArrayMember(index, can_create);
1537 }
1538
1539 if (!pointee || error.Fail()) {
1540 return ValueObjectSP();
1541 }
1542
1543 return GetValueForOffset(frame, pointee, offset);
1544}
1545
1546/// Attempt to reconstruct the ValueObject for the address contained in a
1547/// given register plus an offset.
1548///
1549/// \param [in] frame
1550/// The current stack frame.
1551///
1552/// \param [in] reg
1553/// The register.
1554///
1555/// \param [in] offset
1556/// The offset from the register.
1557///
1558/// \param [in] disassembler
1559/// A disassembler containing instructions valid up to the current PC.
1560///
1561/// \param [in] variables
1562/// The variable list from the current frame,
1563///
1564/// \param [in] pc
1565/// The program counter for the instruction considered the 'user'.
1566///
1567/// \return
1568/// A string describing the base for the ExpressionPath. This could be a
1569/// variable, a register value, an argument, or a function return value.
1570/// The ValueObject if found. If valid, it has a valid ExpressionPath.
1571lldb::ValueObjectSP DoGuessValueAt(StackFrame &frame, ConstString reg,
1572 int64_t offset, Disassembler &disassembler,
1573 VariableList &variables, const Address &pc) {
1574 // Example of operation for Intel:
1575 //
1576 // +14: movq -0x8(%rbp), %rdi
1577 // +18: movq 0x8(%rdi), %rdi
1578 // +22: addl 0x4(%rdi), %eax
1579 //
1580 // f, a pointer to a struct, is known to be at -0x8(%rbp).
1581 //
1582 // DoGuessValueAt(frame, rdi, 4, dis, vars, 0x22) finds the instruction at
1583 // +18 that assigns to rdi, and calls itself recursively for that dereference
1584 // DoGuessValueAt(frame, rdi, 8, dis, vars, 0x18) finds the instruction at
1585 // +14 that assigns to rdi, and calls itself recursively for that
1586 // dereference
1587 // DoGuessValueAt(frame, rbp, -8, dis, vars, 0x14) finds "f" in the
1588 // variable list.
1589 // Returns a ValueObject for f. (That's what was stored at rbp-8 at +14)
1590 // Returns a ValueObject for *(f+8) or f->b (That's what was stored at rdi+8
1591 // at +18)
1592 // Returns a ValueObject for *(f->b+4) or f->b->a (That's what was stored at
1593 // rdi+4 at +22)
1594
1595 // First, check the variable list to see if anything is at the specified
1596 // location.
1597
1598 using namespace OperandMatchers;
1599
1600 const RegisterInfo *reg_info =
1601 frame.GetRegisterContext()->GetRegisterInfoByName(reg.AsCString());
1602 if (!reg_info) {
1603 return ValueObjectSP();
1604 }
1605
1611 : Instruction::Operand::BuildDereference(
1612 Instruction::Operand::BuildRegister(reg));
1613
1614 for (VariableSP var_sp : variables) {
1615 if (var_sp->LocationExpressionList().MatchesOperand(frame, op))
1617 }
1618
1619 const uint32_t current_inst =
1621 if (current_inst == UINT32_MAX) {
1622 return ValueObjectSP();
1623 }
1624
1625 for (uint32_t ii = current_inst - 1; ii != (uint32_t)-1; --ii) {
1626 // This is not an exact algorithm, and it sacrifices accuracy for
1627 // generality. Recognizing "mov" and "ld" instructions –– and which
1628 // are their source and destination operands -- is something the
1629 // disassembler should do for us.
1630 InstructionSP instruction_sp =
1631 disassembler.GetInstructionList().GetInstructionAtIndex(ii);
1632
1633 if (instruction_sp->IsCall()) {
1634 ABISP abi_sp = frame.CalculateProcess()->GetABI();
1635 if (!abi_sp) {
1636 continue;
1637 }
1638
1639 const char *return_register_name;
1640 if (!abi_sp->GetPointerReturnRegister(return_register_name)) {
1641 continue;
1642 }
1643
1644 const RegisterInfo *return_register_info =
1645 frame.GetRegisterContext()->GetRegisterInfoByName(
1646 return_register_name);
1647 if (!return_register_info) {
1648 continue;
1649 }
1650
1651 int64_t offset = 0;
1652
1654 MatchRegOp(*return_register_info))(op) &&
1655 !MatchUnaryOp(
1658 MatchRegOp(*return_register_info),
1659 FetchImmOp(offset)))(op)) {
1660 continue;
1661 }
1662
1663 llvm::SmallVector<Instruction::Operand, 1> operands;
1664 if (!instruction_sp->ParseOperands(operands) || operands.size() != 1) {
1665 continue;
1666 }
1667
1668 switch (operands[0].m_type) {
1669 default:
1670 break;
1672 SymbolContext sc;
1673 Address load_address;
1674 if (!frame.CalculateTarget()->ResolveLoadAddress(
1675 operands[0].m_immediate, load_address)) {
1676 break;
1677 }
1678 frame.CalculateTarget()->GetImages().ResolveSymbolContextForAddress(
1679 load_address, eSymbolContextFunction, sc);
1680 if (!sc.function) {
1681 break;
1682 }
1683 CompilerType function_type = sc.function->GetCompilerType();
1684 if (!function_type.IsFunctionType()) {
1685 break;
1686 }
1687 CompilerType return_type = function_type.GetFunctionReturnType();
1688 RegisterValue return_value;
1689 if (!frame.GetRegisterContext()->ReadRegister(return_register_info,
1690 return_value)) {
1691 break;
1692 }
1693 std::string name_str(
1694 sc.function->GetName().AsCString("<unknown function>"));
1695 name_str.append("()");
1696 Address return_value_address(return_value.GetAsUInt64());
1697 ValueObjectSP return_value_sp = ValueObjectMemory::Create(
1698 &frame, name_str, return_value_address, return_type);
1699 return GetValueForDereferincingOffset(frame, return_value_sp, offset);
1700 }
1701 }
1702
1703 continue;
1704 }
1705
1706 llvm::SmallVector<Instruction::Operand, 2> operands;
1707 if (!instruction_sp->ParseOperands(operands) || operands.size() != 2) {
1708 continue;
1709 }
1710
1711 Instruction::Operand *origin_operand = nullptr;
1712 auto clobbered_reg_matcher = [reg_info](const Instruction::Operand &op) {
1713 return MatchRegOp(*reg_info)(op) && op.m_clobbered;
1714 };
1715
1716 if (clobbered_reg_matcher(operands[0])) {
1717 origin_operand = &operands[1];
1718 }
1719 else if (clobbered_reg_matcher(operands[1])) {
1720 origin_operand = &operands[0];
1721 }
1722 else {
1723 continue;
1724 }
1725
1726 // We have an origin operand. Can we track its value down?
1727 ValueObjectSP source_path;
1728 ConstString origin_register;
1729 int64_t origin_offset = 0;
1730
1731 if (FetchRegOp(origin_register)(*origin_operand)) {
1732 source_path = DoGuessValueAt(frame, origin_register, 0, disassembler,
1733 variables, instruction_sp->GetAddress());
1734 } else if (MatchUnaryOp(
1736 FetchRegOp(origin_register))(*origin_operand) ||
1740 FetchRegOp(origin_register),
1741 FetchImmOp(origin_offset)))(*origin_operand)) {
1742 source_path =
1743 DoGuessValueAt(frame, origin_register, origin_offset, disassembler,
1744 variables, instruction_sp->GetAddress());
1745 if (!source_path) {
1746 continue;
1747 }
1748 source_path =
1749 GetValueForDereferincingOffset(frame, source_path, offset);
1750 }
1751
1752 if (source_path) {
1753 return source_path;
1754 }
1755 }
1756
1757 return ValueObjectSP();
1758}
1759}
1760
1762 int64_t offset) {
1763 TargetSP target_sp = CalculateTarget();
1764
1765 const ArchSpec &target_arch = target_sp->GetArchitecture();
1766
1767 Block *frame_block = GetFrameBlock();
1768
1769 if (!frame_block) {
1770 return ValueObjectSP();
1771 }
1772
1773 Function *function = frame_block->CalculateSymbolContextFunction();
1774 if (!function) {
1775 return ValueObjectSP();
1776 }
1777
1778 AddressRange pc_range = function->GetAddressRange();
1779
1780 if (GetFrameCodeAddress().GetFileAddress() <
1781 pc_range.GetBaseAddress().GetFileAddress() ||
1782 GetFrameCodeAddress().GetFileAddress() -
1783 pc_range.GetBaseAddress().GetFileAddress() >=
1784 pc_range.GetByteSize()) {
1785 return ValueObjectSP();
1786 }
1787
1788 const char *plugin_name = nullptr;
1789 const char *flavor = nullptr;
1790 const char *cpu = nullptr;
1791 const char *features = nullptr;
1792 const bool force_live_memory = true;
1794 target_arch, plugin_name, flavor, cpu, features, *target_sp, pc_range,
1795 force_live_memory);
1796
1797 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
1798 return ValueObjectSP();
1799 }
1800
1801 const bool get_file_globals = false;
1802 VariableList *variables = GetVariableList(get_file_globals, nullptr);
1803
1804 if (!variables) {
1805 return ValueObjectSP();
1806 }
1807
1808 return DoGuessValueAt(*this, reg, offset, *disassembler_sp, *variables,
1810}
1811
1813 ValueObjectSP value_sp;
1814
1815 if (!name)
1816 return value_sp;
1817
1818 TargetSP target_sp = CalculateTarget();
1819 ProcessSP process_sp = CalculateProcess();
1820
1821 if (!target_sp && !process_sp)
1822 return value_sp;
1823
1824 VariableList variable_list;
1825 VariableSP var_sp;
1826 SymbolContext sc(GetSymbolContext(eSymbolContextBlock));
1827
1828 if (sc.block) {
1829 const bool can_create = true;
1830 const bool get_parent_variables = true;
1831 const bool stop_if_block_is_inlined_function = true;
1832
1833 if (sc.block->AppendVariables(
1834 can_create, get_parent_variables, stop_if_block_is_inlined_function,
1835 [this](Variable *v) { return v->IsInScope(this); },
1836 &variable_list)) {
1837 var_sp = variable_list.FindVariable(name);
1838 }
1839
1840 if (var_sp)
1842 }
1843
1844 return value_sp;
1845}
1846
1848 TargetSP target_sp;
1849 ThreadSP thread_sp(GetThread());
1850 if (thread_sp) {
1851 ProcessSP process_sp(thread_sp->CalculateProcess());
1852 if (process_sp)
1853 target_sp = process_sp->CalculateTarget();
1854 }
1855 return target_sp;
1856}
1857
1859 ProcessSP process_sp;
1860 ThreadSP thread_sp(GetThread());
1861 if (thread_sp)
1862 process_sp = thread_sp->CalculateProcess();
1863 return process_sp;
1864}
1865
1867
1868StackFrameSP StackFrame::CalculateStackFrame() { return shared_from_this(); }
1869
1871 exe_ctx.SetContext(shared_from_this());
1872}
1873
1875 const FormatEntity::Entry *format,
1876 llvm::StringRef frame_marker) {
1877 GetSymbolContext(eSymbolContextEverything);
1878 ExecutionContext exe_ctx(shared_from_this());
1879 StreamString s;
1880 s.PutCString(frame_marker);
1881
1882 if (format && FormatEntity::Format(*format, s, &m_sc, &exe_ctx, nullptr,
1883 nullptr, false, false)) {
1884 strm.PutCString(s.GetString());
1885 return true;
1886 }
1887 return false;
1888}
1889
1890void StackFrame::DumpUsingSettingsFormat(Stream *strm, bool show_unique,
1891 const char *frame_marker) {
1892 if (strm == nullptr)
1893 return;
1894
1895 ExecutionContext exe_ctx(shared_from_this());
1896
1897 const FormatEntity::Entry *frame_format = nullptr;
1898 Target *target = exe_ctx.GetTargetPtr();
1899 if (target) {
1900 if (show_unique) {
1901 frame_format = target->GetDebugger().GetFrameFormatUnique();
1902 } else {
1903 frame_format = target->GetDebugger().GetFrameFormat();
1904 }
1905 }
1906 if (!DumpUsingFormat(*strm, frame_format, frame_marker)) {
1907 Dump(strm, true, false);
1908 strm->EOL();
1909 }
1910}
1911
1912void StackFrame::Dump(Stream *strm, bool show_frame_index,
1913 bool show_fullpaths) {
1914 if (strm == nullptr)
1915 return;
1916
1917 if (show_frame_index)
1918 strm->Printf("frame #%u: ", m_frame_index);
1919 ExecutionContext exe_ctx(shared_from_this());
1920 Target *target = exe_ctx.GetTargetPtr();
1921 strm->Printf("0x%0*" PRIx64 " ",
1922 target ? (target->GetArchitecture().GetAddressByteSize() * 2)
1923 : 16,
1924 GetFrameCodeAddress().GetLoadAddress(target));
1925 GetSymbolContext(eSymbolContextEverything);
1926 const bool show_module = true;
1927 const bool show_inline = true;
1928 const bool show_function_arguments = true;
1929 const bool show_function_name = true;
1931 GetFrameCodeAddress(), show_fullpaths, show_module,
1932 show_inline, show_function_arguments,
1933 show_function_name);
1934}
1935
1937 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1938 assert(GetStackID() ==
1939 prev_frame.GetStackID()); // TODO: remove this after some testing
1942 if (!m_disassembly.GetString().empty()) {
1945 }
1946}
1947
1949 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1950 assert(GetStackID() ==
1951 curr_frame.GetStackID()); // TODO: remove this after some testing
1952 m_id.SetPC(curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1953 assert(GetThread() == curr_frame.GetThread());
1954 m_frame_index = curr_frame.m_frame_index;
1959 assert(!m_sc.target_sp || !curr_frame.m_sc.target_sp ||
1960 m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get());
1961 assert(!m_sc.module_sp || !curr_frame.m_sc.module_sp ||
1962 m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get());
1963 assert(m_sc.comp_unit == nullptr || curr_frame.m_sc.comp_unit == nullptr ||
1964 m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1965 assert(m_sc.function == nullptr || curr_frame.m_sc.function == nullptr ||
1966 m_sc.function == curr_frame.m_sc.function);
1967 m_sc = curr_frame.m_sc;
1968 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1972}
1973
1976 return true;
1978 return true;
1979 if (!m_disassembly.GetString().empty())
1980 return true;
1981 return false;
1982}
1983
1984bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source,
1985 bool show_unique, const char *frame_marker) {
1986 if (show_frame_info) {
1987 strm.Indent();
1988 DumpUsingSettingsFormat(&strm, show_unique, frame_marker);
1989 }
1990
1991 if (show_source) {
1992 ExecutionContext exe_ctx(shared_from_this());
1993 bool have_source = false, have_debuginfo = false;
1994 Debugger::StopDisassemblyType disasm_display =
1996 Target *target = exe_ctx.GetTargetPtr();
1997 if (target) {
1998 Debugger &debugger = target->GetDebugger();
1999 const uint32_t source_lines_before =
2000 debugger.GetStopSourceLineCount(true);
2001 const uint32_t source_lines_after =
2002 debugger.GetStopSourceLineCount(false);
2003 disasm_display = debugger.GetStopDisassemblyDisplay();
2004
2005 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
2007 have_debuginfo = true;
2008 if (source_lines_before > 0 || source_lines_after > 0) {
2009 SupportFileSP source_file_sp = m_sc.line_entry.file_sp;
2010 uint32_t start_line = m_sc.line_entry.line;
2011 if (!start_line && m_sc.function) {
2012 m_sc.function->GetStartLineSourceInfo(source_file_sp, start_line);
2013 }
2014
2015 size_t num_lines =
2017 source_file_sp, start_line, m_sc.line_entry.column,
2018 source_lines_before, source_lines_after, "->", &strm);
2019 if (num_lines != 0)
2020 have_source = true;
2021 // TODO: Give here a one time warning if source file is missing.
2022 if (!m_sc.line_entry.line)
2023 strm << "note: This address is not associated with a specific line "
2024 "of code. This may be due to compiler optimizations.\n";
2025 }
2026 }
2027 switch (disasm_display) {
2029 break;
2030
2032 if (have_debuginfo)
2033 break;
2034 [[fallthrough]];
2035
2037 if (have_source)
2038 break;
2039 [[fallthrough]];
2040
2042 if (target) {
2043 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
2044 if (disasm_lines > 0) {
2045 const ArchSpec &target_arch = target->GetArchitecture();
2046 const char *plugin_name = nullptr;
2047 const char *flavor = nullptr;
2048 const bool mixed_source_and_assembly = false;
2050 target->GetDebugger(), target_arch, plugin_name, flavor,
2051 target->GetDisassemblyCPU(), target->GetDisassemblyFeatures(),
2052 exe_ctx, GetFrameCodeAddress(),
2053 {Disassembler::Limit::Instructions, disasm_lines},
2054 mixed_source_and_assembly, 0,
2056 }
2057 }
2058 break;
2059 }
2060 }
2061 }
2062 return true;
2063}
2064
2066 auto process = GetThread()->GetProcess();
2067 if (!process)
2068 return {};
2069 // If recognizer list has been modified, discard cache.
2070 auto &manager = process->GetTarget().GetFrameRecognizerManager();
2071 auto new_generation = manager.GetGeneration();
2072 if (m_frame_recognizer_generation != new_generation)
2073 m_recognized_frame_sp.reset();
2074 m_frame_recognizer_generation = new_generation;
2075 if (!m_recognized_frame_sp.has_value())
2076 m_recognized_frame_sp = manager.RecognizeFrame(CalculateStackFrame());
2077 return m_recognized_frame_sp.value();
2078}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:392
#define GOT_FRAME_BASE
Definition: StackFrame.cpp:50
#define RESOLVED_GLOBAL_VARIABLES
Definition: StackFrame.cpp:52
#define RESOLVED_FRAME_ID_SYMBOL_SCOPE
Definition: StackFrame.cpp:49
#define RESOLVED_FRAME_CODE_ADDR
Definition: StackFrame.cpp:48
#define RESOLVED_VARIABLES
Definition: StackFrame.cpp:51
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:712
uint32_t GetMaximumOpcodeByteSize() const
Definition: ArchSpec.cpp:958
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:200
const InlineFunctionInfo * GetInlinedFunctionInfo() const
Get const accessor for any inlined function information.
Definition: Block.h:266
Function * CalculateSymbolContextFunction() override
Definition: Block.cpp:150
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:449
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:419
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
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:558
StopDisassemblyType GetStopDisassemblyDisplay() const
Definition: Debugger.cpp:551
uint64_t GetStopSourceLineCount(bool before) const
Definition: Debugger.cpp:544
const FormatEntity::Entry * GetFrameFormat() const
Definition: Debugger.cpp:284
const FormatEntity::Entry * GetFrameFormatUnique() const
Definition: Debugger.cpp:289
static bool Disassemble(Debugger &debugger, const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, 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)
static lldb::DisassemblerSP DisassembleRange(const ArchSpec &arch, const char *plugin_name, const char *flavor, const char *cpu, const char *features, Target &target, const AddressRange &disasm_range, bool force_live_memory=false)
InstructionList & GetInstructionList()
"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.
Target & GetTargetRef() const
Returns a reference to the target object.
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 Address & GetAddress() const
Return the address of the function (its entry point).
Definition: Function.h:455
void GetStartLineSourceInfo(lldb::SupportFileSP &source_file_sp, uint32_t &line_no)
Find the file and line number of the source location of the start of the function.
Definition: Function.cpp:295
const AddressRange & GetAddressRange()
DEPRECATED: Use GetAddressRanges instead.
Definition: Function.h:448
CompilerType GetCompilerType()
Definition: Function.cpp:587
DWARFExpressionList & GetFrameBaseExpression()
Get accessor for the frame base location.
Definition: Function.h:523
ConstString GetName() const
Definition: Function.cpp:719
const Mangled & GetMangled() const
Definition: Function.h:537
ConstString GetDisplayName() const
Definition: Function.cpp:548
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:396
A class that describes information for an inlined function.
Definition: Function.h:125
ConstString GetDisplayName() const
Definition: Function.cpp:102
ConstString GetName() const
Definition: Function.cpp:96
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(lldb::SupportFileSP support_file_sp, 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:44
void SetSymbolContextScope(SymbolContextScope *symbol_scope)
Definition: StackFrame.cpp:185
uint16_t m_frame_recognizer_generation
Definition: StackFrame.h:566
lldb::VariableListSP m_variable_list_sp
Definition: StackFrame.h:576
void UpdatePreviousFrameFromCurrentFrame(StackFrame &curr_frame)
lldb::ThreadSP GetThread() const
Definition: StackFrame.h:128
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:561
@ eExpressionPathOptionsInspectAnonymousUnions
Definition: StackFrame.h:52
@ eExpressionPathOptionsAllowDirectIVarAccess
Definition: StackFrame.h:51
@ eExpressionPathOptionsNoSyntheticChildren
Definition: StackFrame.h:49
const char * GetFunctionName()
Get the frame's demangled name.
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:425
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:578
bool m_cfa_is_valid
Does this frame have a CFA? Different from CFA == LLDB_INVALID_ADDRESS.
Definition: StackFrame.h:568
llvm::Error GetFrameBaseValue(Scalar &value)
Return the Canonical Frame Address (DWARF term) for this frame.
std::optional< lldb::RecognizedStackFrameSP > m_recognized_frame_sp
Definition: StackFrame.h:579
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:509
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:555
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:476
StructuredData::ObjectSP GetLanguageSpecificData()
Language plugins can use this API to report language-specific runtime information about this compile ...
Address GetFrameCodeAddressForSymbolication()
Get the current code Address suitable for symbolication, may not be the same as GetFrameCodeAddress()...
Definition: StackFrame.cpp:223
@ 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:554
lldb::ValueObjectSP DILGetValueForVariableExpressionPath(llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic, uint32_t options, lldb::VariableSP &var_sp, Status &error)
Definition: StackFrame.cpp:523
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:575
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:248
lldb::ValueObjectSP LegacyGetValueForVariableExpressionPath(llvm::StringRef var_expr, lldb::DynamicValueType use_dynamic, uint32_t options, lldb::VariableSP &var_sp, Status &error)
Private methods, called from GetValueForVariableExpressionPath.
Definition: StackFrame.cpp:532
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:580
lldb::StackFrameSP CalculateStackFrame() override
const SymbolContext & GetSymbolContext(lldb::SymbolContextItem resolve_scope)
Provide a SymbolContext for this StackFrame's current pc value.
Definition: StackFrame.cpp:301
const char * GetDisplayFunctionName()
Get the frame's demangled display name.
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:262
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:176
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:276
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:581
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:54
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:191
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:118
void Clear()
Clear the object state.
Definition: Status.cpp:215
llvm::Error ToError() const
FIXME: Replace all uses with takeError() instead.
Definition: Status.cpp:139
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:141
bool Fail() const
Test for error condition.
Definition: Status.cpp:294
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition: Status.h:151
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition: Status.cpp:137
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
std::shared_ptr< Object > ObjectSP
"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.
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
ConstString GetName() const
Definition: Symbol.cpp:548
ConstString GetDisplayName() const
Definition: Symbol.cpp:169
const char * GetDisassemblyFeatures() const
Definition: Target.cpp:4517
const char * GetDisassemblyCPU() const
Definition: Target.cpp:4510
bool GetUseDIL(ExecutionContext *exe_ctx) const
Definition: Target.cpp:4384
SourceManager & GetSourceManager()
Definition: Target.cpp:2951
Debugger & GetDebugger()
Definition: Target.h:1080
const ArchSpec & GetArchitecture() const
Definition: Target.h:1039
CompilerType GetForwardCompilerType()
Definition: Type.cpp:774
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:274
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:332
Definition: SBAddress.h:15
std::shared_ptr< lldb_private::ABI > ABISP
Definition: lldb-forward.h:317
std::shared_ptr< lldb_private::StackFrame > StackFrameSP
Definition: lldb-forward.h:424
std::shared_ptr< lldb_private::RecognizedStackFrame > RecognizedStackFrameSP
Definition: lldb-forward.h:403
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:450
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
Definition: lldb-forward.h:484
std::shared_ptr< lldb_private::SupportFile > SupportFileSP
Definition: lldb-forward.h:479
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:358
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:389
std::shared_ptr< lldb_private::Disassembler > DisassemblerSP
Definition: lldb-forward.h:341
std::shared_ptr< lldb_private::VariableList > VariableListSP
Definition: lldb-forward.h:487
std::shared_ptr< lldb_private::Variable > VariableSP
Definition: lldb-forward.h:486
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:448
@ eNoDynamicValues
std::shared_ptr< lldb_private::RegisterContext > RegisterContextSP
Definition: lldb-forward.h:394
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
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
lldb::SupportFileSP file_sp
The source file, possibly mapped by the target.source-map setting.
Definition: LineEntry.h:140
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.
lldb::LanguageType AsLanguageType() const
Definition: Language.cpp:554