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 exe_ctx.GetTargetPtr());
1126
1127 llvm::Expected<Value> expr_value =
1129 &exe_ctx, nullptr, loclist_base_addr, nullptr, nullptr);
1130 if (!expr_value)
1131 m_frame_base_error = Status::FromError(expr_value.takeError());
1132 else
1133 m_frame_base = expr_value->ResolveValue(&exe_ctx);
1134 } else {
1136 Status::FromErrorString("No function in symbol context.");
1137 }
1138 }
1139
1141 return m_frame_base_error.ToError();
1142
1143 frame_base = m_frame_base;
1144 return llvm::Error::success();
1145}
1146
1148 if (!m_sc.function) {
1149 if (error_ptr) {
1150 *error_ptr = Status::FromErrorString("No function in symbol context.");
1151 }
1152 return nullptr;
1153 }
1154
1156}
1157
1159 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1160 if (!m_reg_context_sp) {
1161 ThreadSP thread_sp(GetThread());
1162 if (thread_sp)
1163 m_reg_context_sp = thread_sp->CreateRegisterContextForFrame(this);
1164 }
1165 return m_reg_context_sp;
1166}
1167
1169 GetSymbolContext(eSymbolContextLineEntry);
1170 return m_sc.line_entry.IsValid();
1171}
1172
1175 DynamicValueType use_dynamic) {
1176 ValueObjectSP valobj_sp;
1177 { // Scope for stack frame mutex. We need to drop this mutex before we figure
1178 // out the dynamic value. That will require converting the StackID in the
1179 // VO back to a StackFrame, which will in turn require locking the
1180 // StackFrameList. If we still hold the StackFrame mutex, we could suffer
1181 // lock inversion against the pattern of getting the StackFrameList and
1182 // then the stack frame, which is fairly common.
1183 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1184 if (IsHistorical()) {
1185 return valobj_sp;
1186 }
1187 VariableList *var_list = GetVariableList(true, nullptr);
1188 if (var_list) {
1189 // Make sure the variable is a frame variable
1190 const uint32_t var_idx = var_list->FindIndexForVariable(variable_sp.get());
1191 const uint32_t num_variables = var_list->GetSize();
1192 if (var_idx < num_variables) {
1194 if (!valobj_sp) {
1195 if (m_variable_list_value_objects.GetSize() < num_variables)
1197 valobj_sp = ValueObjectVariable::Create(this, variable_sp);
1199 valobj_sp);
1200 }
1201 }
1202 }
1203 } // End of StackFrame mutex scope.
1204 if (use_dynamic != eNoDynamicValues && valobj_sp) {
1205 ValueObjectSP dynamic_sp = valobj_sp->GetDynamicValue(use_dynamic);
1206 if (dynamic_sp)
1207 return dynamic_sp;
1208 }
1209 return valobj_sp;
1210}
1211
1213 if (m_sc.block == nullptr)
1214 GetSymbolContext(eSymbolContextBlock);
1215 if (m_sc.block)
1216 return m_sc.block->GetContainingInlinedBlock() != nullptr;
1217 return false;
1218}
1219
1222}
1223
1226}
1227
1229 if (auto recognized_frame_sp = GetRecognizedFrame())
1230 return recognized_frame_sp->ShouldHide();
1231 return false;
1232}
1233
1235 auto process_sp = CalculateProcess();
1236 SourceLanguage language = GetLanguage();
1237 if (!language)
1238 return {};
1239 if (auto runtime_sp =
1240 process_sp->GetLanguageRuntime(language.AsLanguageType()))
1241 return runtime_sp->GetLanguageSpecificData(
1242 GetSymbolContext(eSymbolContextFunction));
1243 return {};
1244}
1245
1247 const char *name = nullptr;
1249 eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1250 if (sc.block) {
1251 Block *inlined_block = sc.block->GetContainingInlinedBlock();
1252 if (inlined_block) {
1253 const InlineFunctionInfo *inlined_info =
1254 inlined_block->GetInlinedFunctionInfo();
1255 if (inlined_info)
1256 name = inlined_info->GetName().AsCString();
1257 }
1258 }
1259
1260 if (name == nullptr) {
1261 if (sc.function)
1262 name = sc.function->GetName().GetCString();
1263 }
1264
1265 if (name == nullptr) {
1266 if (sc.symbol)
1267 name = sc.symbol->GetName().GetCString();
1268 }
1269
1270 return name;
1271}
1272
1274 const char *name = nullptr;
1276 eSymbolContextFunction | eSymbolContextBlock | eSymbolContextSymbol);
1277 if (sc.block) {
1278 Block *inlined_block = sc.block->GetContainingInlinedBlock();
1279 if (inlined_block) {
1280 const InlineFunctionInfo *inlined_info =
1281 inlined_block->GetInlinedFunctionInfo();
1282 if (inlined_info)
1283 name = inlined_info->GetDisplayName().AsCString();
1284 }
1285 }
1286
1287 if (name == nullptr) {
1288 if (sc.function)
1289 name = sc.function->GetDisplayName().GetCString();
1290 }
1291
1292 if (name == nullptr) {
1293 if (sc.symbol)
1294 name = sc.symbol->GetDisplayName().GetCString();
1295 }
1296 return name;
1297}
1298
1300 CompileUnit *cu = GetSymbolContext(eSymbolContextCompUnit).comp_unit;
1301 if (cu)
1302 return cu->GetLanguage();
1303 return {};
1304}
1305
1307 SourceLanguage lang_type = GetLanguage();
1308
1309 if (lang_type == eLanguageTypeUnknown) {
1310 SymbolContext sc =
1311 GetSymbolContext(eSymbolContextFunction | eSymbolContextSymbol);
1312 if (sc.function)
1313 lang_type = LanguageType(sc.function->GetMangled().GuessLanguage());
1314 else if (sc.symbol)
1315 lang_type = SourceLanguage(sc.symbol->GetMangled().GuessLanguage());
1316 }
1317
1318 return lang_type;
1319}
1320
1321namespace {
1322std::pair<const Instruction::Operand *, int64_t>
1323GetBaseExplainingValue(const Instruction::Operand &operand,
1324 RegisterContext &register_context, lldb::addr_t value) {
1325 switch (operand.m_type) {
1330 // These are not currently interesting
1331 return std::make_pair(nullptr, 0);
1333 const Instruction::Operand *immediate_child = nullptr;
1334 const Instruction::Operand *variable_child = nullptr;
1335 if (operand.m_children[0].m_type == Instruction::Operand::Type::Immediate) {
1336 immediate_child = &operand.m_children[0];
1337 variable_child = &operand.m_children[1];
1338 } else if (operand.m_children[1].m_type ==
1340 immediate_child = &operand.m_children[1];
1341 variable_child = &operand.m_children[0];
1342 }
1343 if (!immediate_child) {
1344 return std::make_pair(nullptr, 0);
1345 }
1346 lldb::addr_t adjusted_value = value;
1347 if (immediate_child->m_negative) {
1348 adjusted_value += immediate_child->m_immediate;
1349 } else {
1350 adjusted_value -= immediate_child->m_immediate;
1351 }
1352 std::pair<const Instruction::Operand *, int64_t> base_and_offset =
1353 GetBaseExplainingValue(*variable_child, register_context,
1354 adjusted_value);
1355 if (!base_and_offset.first) {
1356 return std::make_pair(nullptr, 0);
1357 }
1358 if (immediate_child->m_negative) {
1359 base_and_offset.second -= immediate_child->m_immediate;
1360 } else {
1361 base_and_offset.second += immediate_child->m_immediate;
1362 }
1363 return base_and_offset;
1364 }
1366 const RegisterInfo *info =
1367 register_context.GetRegisterInfoByName(operand.m_register.AsCString());
1368 if (!info) {
1369 return std::make_pair(nullptr, 0);
1370 }
1371 RegisterValue reg_value;
1372 if (!register_context.ReadRegister(info, reg_value)) {
1373 return std::make_pair(nullptr, 0);
1374 }
1375 if (reg_value.GetAsUInt64() == value) {
1376 return std::make_pair(&operand, 0);
1377 } else {
1378 return std::make_pair(nullptr, 0);
1379 }
1380 }
1381 }
1382 return std::make_pair(nullptr, 0);
1383}
1384
1385std::pair<const Instruction::Operand *, int64_t>
1386GetBaseExplainingDereference(const Instruction::Operand &operand,
1387 RegisterContext &register_context,
1388 lldb::addr_t addr) {
1390 return GetBaseExplainingValue(operand.m_children[0], register_context,
1391 addr);
1392 }
1393 return std::make_pair(nullptr, 0);
1394}
1395} // namespace
1396
1398 TargetSP target_sp = CalculateTarget();
1399
1400 const ArchSpec &target_arch = target_sp->GetArchitecture();
1401
1402 AddressRange pc_range;
1403 pc_range.GetBaseAddress() = GetFrameCodeAddress();
1404 pc_range.SetByteSize(target_arch.GetMaximumOpcodeByteSize());
1405
1406 const char *plugin_name = nullptr;
1407 const char *flavor = nullptr;
1408 const char *cpu = nullptr;
1409 const char *features = nullptr;
1410 const bool force_live_memory = true;
1411
1413 target_arch, plugin_name, flavor, cpu, features, *target_sp, pc_range,
1414 force_live_memory);
1415
1416 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
1417 return ValueObjectSP();
1418 }
1419
1420 InstructionSP instruction_sp =
1421 disassembler_sp->GetInstructionList().GetInstructionAtIndex(0);
1422
1423 llvm::SmallVector<Instruction::Operand, 3> operands;
1424
1425 if (!instruction_sp->ParseOperands(operands)) {
1426 return ValueObjectSP();
1427 }
1428
1429 RegisterContextSP register_context_sp = GetRegisterContext();
1430
1431 if (!register_context_sp) {
1432 return ValueObjectSP();
1433 }
1434
1435 for (const Instruction::Operand &operand : operands) {
1436 std::pair<const Instruction::Operand *, int64_t> base_and_offset =
1437 GetBaseExplainingDereference(operand, *register_context_sp, addr);
1438
1439 if (!base_and_offset.first) {
1440 continue;
1441 }
1442
1443 switch (base_and_offset.first->m_type) {
1446 if (target_sp->ResolveLoadAddress(base_and_offset.first->m_immediate +
1447 base_and_offset.second,
1448 addr)) {
1449 auto c_type_system_or_err =
1450 target_sp->GetScratchTypeSystemForLanguage(eLanguageTypeC);
1451 if (auto err = c_type_system_or_err.takeError()) {
1452 LLDB_LOG_ERROR(GetLog(LLDBLog::Thread), std::move(err),
1453 "Unable to guess value for given address: {0}");
1454 return ValueObjectSP();
1455 } else {
1456 auto ts = *c_type_system_or_err;
1457 if (!ts)
1458 return {};
1459 CompilerType void_ptr_type =
1461 .GetPointerType();
1462 return ValueObjectMemory::Create(this, "", addr, void_ptr_type);
1463 }
1464 } else {
1465 return ValueObjectSP();
1466 }
1467 break;
1468 }
1470 return GuessValueForRegisterAndOffset(base_and_offset.first->m_register,
1471 base_and_offset.second);
1472 }
1473 default:
1474 return ValueObjectSP();
1475 }
1476 }
1477
1478 return ValueObjectSP();
1479}
1480
1481namespace {
1482ValueObjectSP GetValueForOffset(StackFrame &frame, ValueObjectSP &parent,
1483 int64_t offset) {
1484 if (offset < 0 || uint64_t(offset) >= parent->GetByteSize()) {
1485 return ValueObjectSP();
1486 }
1487
1488 if (parent->IsPointerOrReferenceType()) {
1489 return parent;
1490 }
1491
1492 for (int ci = 0, ce = parent->GetNumChildrenIgnoringErrors(); ci != ce;
1493 ++ci) {
1494 ValueObjectSP child_sp = parent->GetChildAtIndex(ci);
1495
1496 if (!child_sp) {
1497 return ValueObjectSP();
1498 }
1499
1500 int64_t child_offset = child_sp->GetByteOffset();
1501 int64_t child_size = child_sp->GetByteSize().value_or(0);
1502
1503 if (offset >= child_offset && offset < (child_offset + child_size)) {
1504 return GetValueForOffset(frame, child_sp, offset - child_offset);
1505 }
1506 }
1507
1508 if (offset == 0) {
1509 return parent;
1510 } else {
1511 return ValueObjectSP();
1512 }
1513}
1514
1515ValueObjectSP GetValueForDereferincingOffset(StackFrame &frame,
1516 ValueObjectSP &base,
1517 int64_t offset) {
1518 // base is a pointer to something
1519 // offset is the thing to add to the pointer We return the most sensible
1520 // ValueObject for the result of *(base+offset)
1521
1522 if (!base->IsPointerOrReferenceType()) {
1523 return ValueObjectSP();
1524 }
1525
1526 Status error;
1527 ValueObjectSP pointee = base->Dereference(error);
1528
1529 if (!pointee) {
1530 return ValueObjectSP();
1531 }
1532
1533 if (offset >= 0 && uint64_t(offset) >= pointee->GetByteSize()) {
1534 int64_t index = offset / pointee->GetByteSize().value_or(1);
1535 offset = offset % pointee->GetByteSize().value_or(1);
1536 const bool can_create = true;
1537 pointee = base->GetSyntheticArrayMember(index, can_create);
1538 }
1539
1540 if (!pointee || error.Fail()) {
1541 return ValueObjectSP();
1542 }
1543
1544 return GetValueForOffset(frame, pointee, offset);
1545}
1546
1547/// Attempt to reconstruct the ValueObject for the address contained in a
1548/// given register plus an offset.
1549///
1550/// \param [in] frame
1551/// The current stack frame.
1552///
1553/// \param [in] reg
1554/// The register.
1555///
1556/// \param [in] offset
1557/// The offset from the register.
1558///
1559/// \param [in] disassembler
1560/// A disassembler containing instructions valid up to the current PC.
1561///
1562/// \param [in] variables
1563/// The variable list from the current frame,
1564///
1565/// \param [in] pc
1566/// The program counter for the instruction considered the 'user'.
1567///
1568/// \return
1569/// A string describing the base for the ExpressionPath. This could be a
1570/// variable, a register value, an argument, or a function return value.
1571/// The ValueObject if found. If valid, it has a valid ExpressionPath.
1572lldb::ValueObjectSP DoGuessValueAt(StackFrame &frame, ConstString reg,
1573 int64_t offset, Disassembler &disassembler,
1574 VariableList &variables, const Address &pc) {
1575 // Example of operation for Intel:
1576 //
1577 // +14: movq -0x8(%rbp), %rdi
1578 // +18: movq 0x8(%rdi), %rdi
1579 // +22: addl 0x4(%rdi), %eax
1580 //
1581 // f, a pointer to a struct, is known to be at -0x8(%rbp).
1582 //
1583 // DoGuessValueAt(frame, rdi, 4, dis, vars, 0x22) finds the instruction at
1584 // +18 that assigns to rdi, and calls itself recursively for that dereference
1585 // DoGuessValueAt(frame, rdi, 8, dis, vars, 0x18) finds the instruction at
1586 // +14 that assigns to rdi, and calls itself recursively for that
1587 // dereference
1588 // DoGuessValueAt(frame, rbp, -8, dis, vars, 0x14) finds "f" in the
1589 // variable list.
1590 // Returns a ValueObject for f. (That's what was stored at rbp-8 at +14)
1591 // Returns a ValueObject for *(f+8) or f->b (That's what was stored at rdi+8
1592 // at +18)
1593 // Returns a ValueObject for *(f->b+4) or f->b->a (That's what was stored at
1594 // rdi+4 at +22)
1595
1596 // First, check the variable list to see if anything is at the specified
1597 // location.
1598
1599 using namespace OperandMatchers;
1600
1601 const RegisterInfo *reg_info =
1602 frame.GetRegisterContext()->GetRegisterInfoByName(reg.AsCString());
1603 if (!reg_info) {
1604 return ValueObjectSP();
1605 }
1606
1612 : Instruction::Operand::BuildDereference(
1613 Instruction::Operand::BuildRegister(reg));
1614
1615 for (VariableSP var_sp : variables) {
1616 if (var_sp->LocationExpressionList().MatchesOperand(frame, op))
1618 }
1619
1620 const uint32_t current_inst =
1622 if (current_inst == UINT32_MAX) {
1623 return ValueObjectSP();
1624 }
1625
1626 for (uint32_t ii = current_inst - 1; ii != (uint32_t)-1; --ii) {
1627 // This is not an exact algorithm, and it sacrifices accuracy for
1628 // generality. Recognizing "mov" and "ld" instructions –– and which
1629 // are their source and destination operands -- is something the
1630 // disassembler should do for us.
1631 InstructionSP instruction_sp =
1632 disassembler.GetInstructionList().GetInstructionAtIndex(ii);
1633
1634 if (instruction_sp->IsCall()) {
1635 ABISP abi_sp = frame.CalculateProcess()->GetABI();
1636 if (!abi_sp) {
1637 continue;
1638 }
1639
1640 const char *return_register_name;
1641 if (!abi_sp->GetPointerReturnRegister(return_register_name)) {
1642 continue;
1643 }
1644
1645 const RegisterInfo *return_register_info =
1646 frame.GetRegisterContext()->GetRegisterInfoByName(
1647 return_register_name);
1648 if (!return_register_info) {
1649 continue;
1650 }
1651
1652 int64_t offset = 0;
1653
1655 MatchRegOp(*return_register_info))(op) &&
1656 !MatchUnaryOp(
1659 MatchRegOp(*return_register_info),
1660 FetchImmOp(offset)))(op)) {
1661 continue;
1662 }
1663
1664 llvm::SmallVector<Instruction::Operand, 1> operands;
1665 if (!instruction_sp->ParseOperands(operands) || operands.size() != 1) {
1666 continue;
1667 }
1668
1669 switch (operands[0].m_type) {
1670 default:
1671 break;
1673 SymbolContext sc;
1674 Address load_address;
1675 if (!frame.CalculateTarget()->ResolveLoadAddress(
1676 operands[0].m_immediate, load_address)) {
1677 break;
1678 }
1679 frame.CalculateTarget()->GetImages().ResolveSymbolContextForAddress(
1680 load_address, eSymbolContextFunction, sc);
1681 if (!sc.function) {
1682 break;
1683 }
1684 CompilerType function_type = sc.function->GetCompilerType();
1685 if (!function_type.IsFunctionType()) {
1686 break;
1687 }
1688 CompilerType return_type = function_type.GetFunctionReturnType();
1689 RegisterValue return_value;
1690 if (!frame.GetRegisterContext()->ReadRegister(return_register_info,
1691 return_value)) {
1692 break;
1693 }
1694 std::string name_str(
1695 sc.function->GetName().AsCString("<unknown function>"));
1696 name_str.append("()");
1697 Address return_value_address(return_value.GetAsUInt64());
1698 ValueObjectSP return_value_sp = ValueObjectMemory::Create(
1699 &frame, name_str, return_value_address, return_type);
1700 return GetValueForDereferincingOffset(frame, return_value_sp, offset);
1701 }
1702 }
1703
1704 continue;
1705 }
1706
1707 llvm::SmallVector<Instruction::Operand, 2> operands;
1708 if (!instruction_sp->ParseOperands(operands) || operands.size() != 2) {
1709 continue;
1710 }
1711
1712 Instruction::Operand *origin_operand = nullptr;
1713 auto clobbered_reg_matcher = [reg_info](const Instruction::Operand &op) {
1714 return MatchRegOp(*reg_info)(op) && op.m_clobbered;
1715 };
1716
1717 if (clobbered_reg_matcher(operands[0])) {
1718 origin_operand = &operands[1];
1719 }
1720 else if (clobbered_reg_matcher(operands[1])) {
1721 origin_operand = &operands[0];
1722 }
1723 else {
1724 continue;
1725 }
1726
1727 // We have an origin operand. Can we track its value down?
1728 ValueObjectSP source_path;
1729 ConstString origin_register;
1730 int64_t origin_offset = 0;
1731
1732 if (FetchRegOp(origin_register)(*origin_operand)) {
1733 source_path = DoGuessValueAt(frame, origin_register, 0, disassembler,
1734 variables, instruction_sp->GetAddress());
1735 } else if (MatchUnaryOp(
1737 FetchRegOp(origin_register))(*origin_operand) ||
1741 FetchRegOp(origin_register),
1742 FetchImmOp(origin_offset)))(*origin_operand)) {
1743 source_path =
1744 DoGuessValueAt(frame, origin_register, origin_offset, disassembler,
1745 variables, instruction_sp->GetAddress());
1746 if (!source_path) {
1747 continue;
1748 }
1749 source_path =
1750 GetValueForDereferincingOffset(frame, source_path, offset);
1751 }
1752
1753 if (source_path) {
1754 return source_path;
1755 }
1756 }
1757
1758 return ValueObjectSP();
1759}
1760}
1761
1763 int64_t offset) {
1764 TargetSP target_sp = CalculateTarget();
1765
1766 const ArchSpec &target_arch = target_sp->GetArchitecture();
1767
1768 Block *frame_block = GetFrameBlock();
1769
1770 if (!frame_block) {
1771 return ValueObjectSP();
1772 }
1773
1774 Function *function = frame_block->CalculateSymbolContextFunction();
1775 if (!function) {
1776 return ValueObjectSP();
1777 }
1778
1779 AddressRange pc_range = function->GetAddressRange();
1780
1781 if (GetFrameCodeAddress().GetFileAddress() <
1782 pc_range.GetBaseAddress().GetFileAddress() ||
1783 GetFrameCodeAddress().GetFileAddress() -
1784 pc_range.GetBaseAddress().GetFileAddress() >=
1785 pc_range.GetByteSize()) {
1786 return ValueObjectSP();
1787 }
1788
1789 const char *plugin_name = nullptr;
1790 const char *flavor = nullptr;
1791 const char *cpu = nullptr;
1792 const char *features = nullptr;
1793 const bool force_live_memory = true;
1795 target_arch, plugin_name, flavor, cpu, features, *target_sp, pc_range,
1796 force_live_memory);
1797
1798 if (!disassembler_sp || !disassembler_sp->GetInstructionList().GetSize()) {
1799 return ValueObjectSP();
1800 }
1801
1802 const bool get_file_globals = false;
1803 VariableList *variables = GetVariableList(get_file_globals, nullptr);
1804
1805 if (!variables) {
1806 return ValueObjectSP();
1807 }
1808
1809 return DoGuessValueAt(*this, reg, offset, *disassembler_sp, *variables,
1811}
1812
1814 ValueObjectSP value_sp;
1815
1816 if (!name)
1817 return value_sp;
1818
1819 TargetSP target_sp = CalculateTarget();
1820 ProcessSP process_sp = CalculateProcess();
1821
1822 if (!target_sp && !process_sp)
1823 return value_sp;
1824
1825 VariableList variable_list;
1826 VariableSP var_sp;
1827 SymbolContext sc(GetSymbolContext(eSymbolContextBlock));
1828
1829 if (sc.block) {
1830 const bool can_create = true;
1831 const bool get_parent_variables = true;
1832 const bool stop_if_block_is_inlined_function = true;
1833
1834 if (sc.block->AppendVariables(
1835 can_create, get_parent_variables, stop_if_block_is_inlined_function,
1836 [this](Variable *v) { return v->IsInScope(this); },
1837 &variable_list)) {
1838 var_sp = variable_list.FindVariable(name);
1839 }
1840
1841 if (var_sp)
1843 }
1844
1845 return value_sp;
1846}
1847
1849 TargetSP target_sp;
1850 ThreadSP thread_sp(GetThread());
1851 if (thread_sp) {
1852 ProcessSP process_sp(thread_sp->CalculateProcess());
1853 if (process_sp)
1854 target_sp = process_sp->CalculateTarget();
1855 }
1856 return target_sp;
1857}
1858
1860 ProcessSP process_sp;
1861 ThreadSP thread_sp(GetThread());
1862 if (thread_sp)
1863 process_sp = thread_sp->CalculateProcess();
1864 return process_sp;
1865}
1866
1868
1869StackFrameSP StackFrame::CalculateStackFrame() { return shared_from_this(); }
1870
1872 exe_ctx.SetContext(shared_from_this());
1873}
1874
1876 const FormatEntity::Entry *format,
1877 llvm::StringRef frame_marker) {
1878 GetSymbolContext(eSymbolContextEverything);
1879 ExecutionContext exe_ctx(shared_from_this());
1880 StreamString s;
1881 s.PutCString(frame_marker);
1882
1883 if (format && FormatEntity::Format(*format, s, &m_sc, &exe_ctx, nullptr,
1884 nullptr, false, false)) {
1885 strm.PutCString(s.GetString());
1886 return true;
1887 }
1888 return false;
1889}
1890
1891void StackFrame::DumpUsingSettingsFormat(Stream *strm, bool show_unique,
1892 const char *frame_marker) {
1893 if (strm == nullptr)
1894 return;
1895
1896 ExecutionContext exe_ctx(shared_from_this());
1897
1898 const FormatEntity::Entry *frame_format = nullptr;
1899 Target *target = exe_ctx.GetTargetPtr();
1900 if (target) {
1901 if (show_unique) {
1902 frame_format = target->GetDebugger().GetFrameFormatUnique();
1903 } else {
1904 frame_format = target->GetDebugger().GetFrameFormat();
1905 }
1906 }
1907 if (!DumpUsingFormat(*strm, frame_format, frame_marker)) {
1908 Dump(strm, true, false);
1909 strm->EOL();
1910 }
1911}
1912
1913void StackFrame::Dump(Stream *strm, bool show_frame_index,
1914 bool show_fullpaths) {
1915 if (strm == nullptr)
1916 return;
1917
1918 if (show_frame_index)
1919 strm->Printf("frame #%u: ", m_frame_index);
1920 ExecutionContext exe_ctx(shared_from_this());
1921 Target *target = exe_ctx.GetTargetPtr();
1922 strm->Printf("0x%0*" PRIx64 " ",
1923 target ? (target->GetArchitecture().GetAddressByteSize() * 2)
1924 : 16,
1925 GetFrameCodeAddress().GetLoadAddress(target));
1926 GetSymbolContext(eSymbolContextEverything);
1927 const bool show_module = true;
1928 const bool show_inline = true;
1929 const bool show_function_arguments = true;
1930 const bool show_function_name = true;
1932 GetFrameCodeAddress(), show_fullpaths, show_module,
1933 show_inline, show_function_arguments,
1934 show_function_name);
1935}
1936
1938 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1939 assert(GetStackID() ==
1940 prev_frame.GetStackID()); // TODO: remove this after some testing
1943 if (!m_disassembly.GetString().empty()) {
1946 }
1947}
1948
1950 std::lock_guard<std::recursive_mutex> guard(m_mutex);
1951 assert(GetStackID() ==
1952 curr_frame.GetStackID()); // TODO: remove this after some testing
1953 m_id.SetPC(curr_frame.m_id.GetPC()); // Update the Stack ID PC value
1954 assert(GetThread() == curr_frame.GetThread());
1955 m_frame_index = curr_frame.m_frame_index;
1960 assert(!m_sc.target_sp || !curr_frame.m_sc.target_sp ||
1961 m_sc.target_sp.get() == curr_frame.m_sc.target_sp.get());
1962 assert(!m_sc.module_sp || !curr_frame.m_sc.module_sp ||
1963 m_sc.module_sp.get() == curr_frame.m_sc.module_sp.get());
1964 assert(m_sc.comp_unit == nullptr || curr_frame.m_sc.comp_unit == nullptr ||
1965 m_sc.comp_unit == curr_frame.m_sc.comp_unit);
1966 assert(m_sc.function == nullptr || curr_frame.m_sc.function == nullptr ||
1967 m_sc.function == curr_frame.m_sc.function);
1968 m_sc = curr_frame.m_sc;
1969 m_flags.Clear(GOT_FRAME_BASE | eSymbolContextEverything);
1973}
1974
1977 return true;
1979 return true;
1980 if (!m_disassembly.GetString().empty())
1981 return true;
1982 return false;
1983}
1984
1985bool StackFrame::GetStatus(Stream &strm, bool show_frame_info, bool show_source,
1986 bool show_unique, const char *frame_marker) {
1987 if (show_frame_info) {
1988 strm.Indent();
1989 DumpUsingSettingsFormat(&strm, show_unique, frame_marker);
1990 }
1991
1992 if (show_source) {
1993 ExecutionContext exe_ctx(shared_from_this());
1994 bool have_source = false, have_debuginfo = false;
1995 Debugger::StopDisassemblyType disasm_display =
1997 Target *target = exe_ctx.GetTargetPtr();
1998 if (target) {
1999 Debugger &debugger = target->GetDebugger();
2000 const uint32_t source_lines_before =
2001 debugger.GetStopSourceLineCount(true);
2002 const uint32_t source_lines_after =
2003 debugger.GetStopSourceLineCount(false);
2004 disasm_display = debugger.GetStopDisassemblyDisplay();
2005
2006 GetSymbolContext(eSymbolContextCompUnit | eSymbolContextLineEntry);
2008 have_debuginfo = true;
2009 if (source_lines_before > 0 || source_lines_after > 0) {
2010 SupportFileSP source_file_sp = m_sc.line_entry.file_sp;
2011 uint32_t start_line = m_sc.line_entry.line;
2012 if (!start_line && m_sc.function) {
2013 m_sc.function->GetStartLineSourceInfo(source_file_sp, start_line);
2014 }
2015
2016 size_t num_lines =
2018 source_file_sp, start_line, m_sc.line_entry.column,
2019 source_lines_before, source_lines_after, "->", &strm);
2020 if (num_lines != 0)
2021 have_source = true;
2022 // TODO: Give here a one time warning if source file is missing.
2023 if (!m_sc.line_entry.line)
2024 strm << "note: This address is not associated with a specific line "
2025 "of code. This may be due to compiler optimizations.\n";
2026 }
2027 }
2028 switch (disasm_display) {
2030 break;
2031
2033 if (have_debuginfo)
2034 break;
2035 [[fallthrough]];
2036
2038 if (have_source)
2039 break;
2040 [[fallthrough]];
2041
2043 if (target) {
2044 const uint32_t disasm_lines = debugger.GetDisassemblyLineCount();
2045 if (disasm_lines > 0) {
2046 const ArchSpec &target_arch = target->GetArchitecture();
2047 const char *plugin_name = nullptr;
2048 const char *flavor = nullptr;
2049 const bool mixed_source_and_assembly = false;
2051 target->GetDebugger(), target_arch, plugin_name, flavor,
2052 target->GetDisassemblyCPU(), target->GetDisassemblyFeatures(),
2053 exe_ctx, GetFrameCodeAddress(),
2054 {Disassembler::Limit::Instructions, disasm_lines},
2055 mixed_source_and_assembly, 0,
2057 }
2058 }
2059 break;
2060 }
2061 }
2062 }
2063 return true;
2064}
2065
2067 auto process = GetThread()->GetProcess();
2068 if (!process)
2069 return {};
2070 // If recognizer list has been modified, discard cache.
2071 auto &manager = process->GetTarget().GetFrameRecognizerManager();
2072 auto new_generation = manager.GetGeneration();
2073 if (m_frame_recognizer_generation != new_generation)
2074 m_recognized_frame_sp.reset();
2075 m_frame_recognizer_generation = new_generation;
2076 if (!m_recognized_frame_sp.has_value())
2077 m_recognized_frame_sp = manager.RecognizeFrame(CalculateStackFrame());
2078 return m_recognized_frame_sp.value();
2079}
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:709
uint32_t GetMaximumOpcodeByteSize() const
Definition: ArchSpec.cpp:955
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:201
const InlineFunctionInfo * GetInlinedFunctionInfo() const
Get const accessor for any inlined function information.
Definition: Block.h:266
Function * CalculateSymbolContextFunction() override
Definition: Block.cpp:151
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:451
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:421
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
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:294
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:518
ConstString GetName() const
Definition: Function.cpp:720
const Mangled & GetMangled() const
Definition: Function.h:532
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: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: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