1 //===-- StackFrame.cpp ----------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/Target/StackFrame.h"
10 #include "lldb/Core/Debugger.h"
11 #include "lldb/Core/Disassembler.h"
12 #include "lldb/Core/FormatEntity.h"
13 #include "lldb/Core/Mangled.h"
14 #include "lldb/Core/Module.h"
15 #include "lldb/Core/Value.h"
16 #include "lldb/Symbol/CompileUnit.h"
17 #include "lldb/Symbol/Function.h"
18 #include "lldb/Symbol/Symbol.h"
19 #include "lldb/Symbol/SymbolContextScope.h"
20 #include "lldb/Symbol/SymbolFile.h"
21 #include "lldb/Symbol/Type.h"
22 #include "lldb/Symbol/VariableList.h"
23 #include "lldb/Target/ABI.h"
24 #include "lldb/Target/ExecutionContext.h"
25 #include "lldb/Target/LanguageRuntime.h"
26 #include "lldb/Target/Process.h"
27 #include "lldb/Target/RegisterContext.h"
28 #include "lldb/Target/StackFrameRecognizer.h"
29 #include "lldb/Target/Target.h"
30 #include "lldb/Target/Thread.h"
31 #include "lldb/Utility/LLDBLog.h"
32 #include "lldb/Utility/Log.h"
33 #include "lldb/Utility/RegisterValue.h"
34 #include "lldb/ValueObject/ValueObjectConstResult.h"
35 #include "lldb/ValueObject/ValueObjectMemory.h"
36 #include "lldb/ValueObject/ValueObjectVariable.h"
38 #include "lldb/lldb-enumerations.h"
43 using namespace lldb_private
;
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)
54 StackFrame::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
70 if (IsHistorical() && !m_cfa_is_valid
) {
71 m_id
.SetCFA(m_frame_index
);
74 if (sc_ptr
!= nullptr) {
76 m_flags
.Set(m_sc
.GetResolvedMask());
80 StackFrame::StackFrame(const ThreadSP
&thread_sp
, user_id_t frame_idx
,
81 user_id_t unwind_frame_index
,
82 const RegisterContextSP
®_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) {
96 m_flags
.Set(m_sc
.GetResolvedMask());
99 if (reg_context_sp
&& !m_sc
.target_sp
) {
100 m_sc
.target_sp
= reg_context_sp
->CalculateTarget();
102 m_flags
.Set(eSymbolContextTarget
);
106 StackFrame::StackFrame(const ThreadSP
&thread_sp
, user_id_t frame_idx
,
107 user_id_t unwind_frame_index
,
108 const RegisterContextSP
®_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
,
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) {
124 m_flags
.Set(m_sc
.GetResolvedMask());
127 if (!m_sc
.target_sp
&& reg_context_sp
) {
128 m_sc
.target_sp
= reg_context_sp
->CalculateTarget();
130 m_flags
.Set(eSymbolContextTarget
);
133 ModuleSP
pc_module_sp(pc_addr
.GetModule());
134 if (!m_sc
.module_sp
|| m_sc
.module_sp
!= pc_module_sp
) {
136 m_sc
.module_sp
= pc_module_sp
;
137 m_flags
.Set(eSymbolContextModule
);
139 m_sc
.module_sp
.reset();
144 StackFrame::~StackFrame() = default;
146 StackID
&StackFrame::GetStackID() {
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.
151 if (m_flags
.IsClear(RESOLVED_FRAME_ID_SYMBOL_SCOPE
)) {
152 if (m_id
.GetSymbolContextScope()) {
153 // We already have a symbol context scope, we just don't have our flag
155 m_flags
.Set(RESOLVED_FRAME_ID_SYMBOL_SCOPE
);
157 // Calculate the frame block and use this for the stack ID symbol context
158 // scope if we have one.
159 SymbolContextScope
*scope
= GetFrameBlock();
160 if (scope
== nullptr) {
161 // We don't have a block, so use the symbol
162 if (m_flags
.IsClear(eSymbolContextSymbol
))
163 GetSymbolContext(eSymbolContextSymbol
);
165 // It is ok if m_sc.symbol is nullptr here
168 // Set the symbol context scope (the accessor will set the
169 // RESOLVED_FRAME_ID_SYMBOL_SCOPE bit in m_flags).
170 SetSymbolContextScope(scope
);
176 uint32_t StackFrame::GetFrameIndex() const {
177 ThreadSP thread_sp
= GetThread();
179 return thread_sp
->GetStackFrameList()->GetVisibleStackFrameIndex(
182 return m_frame_index
;
185 void StackFrame::SetSymbolContextScope(SymbolContextScope
*symbol_scope
) {
186 std::lock_guard
<std::recursive_mutex
> guard(m_mutex
);
187 m_flags
.Set(RESOLVED_FRAME_ID_SYMBOL_SCOPE
);
188 m_id
.SetSymbolContextScope(symbol_scope
);
191 const Address
&StackFrame::GetFrameCodeAddress() {
192 std::lock_guard
<std::recursive_mutex
> guard(m_mutex
);
193 if (m_flags
.IsClear(RESOLVED_FRAME_CODE_ADDR
) &&
194 !m_frame_code_addr
.IsSectionOffset()) {
195 m_flags
.Set(RESOLVED_FRAME_CODE_ADDR
);
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());
201 TargetSP
target_sp(thread_sp
->CalculateTarget());
203 const bool allow_section_end
= true;
204 if (m_frame_code_addr
.SetOpcodeLoadAddress(
205 m_frame_code_addr
.GetOffset(), target_sp
.get(),
206 AddressClass::eCode
, allow_section_end
)) {
207 ModuleSP
module_sp(m_frame_code_addr
.GetModule());
209 m_sc
.module_sp
= module_sp
;
210 m_flags
.Set(eSymbolContextModule
);
216 return m_frame_code_addr
;
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.
223 Address
StackFrame::GetFrameCodeAddressForSymbolication() {
224 Address
lookup_addr(GetFrameCodeAddress());
225 if (!lookup_addr
.IsValid())
227 if (m_behaves_like_zeroth_frame
)
230 addr_t offset
= lookup_addr
.GetOffset();
232 lookup_addr
.SetOffset(offset
- 1);
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();
239 addr_t addr_minus_one
= lookup_addr
.GetOpcodeLoadAddress(
240 target_sp
.get(), AddressClass::eCode
) -
242 lookup_addr
.SetOpcodeLoadAddress(addr_minus_one
, target_sp
.get());
248 bool StackFrame::ChangePC(addr_t pc
) {
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.
253 m_frame_code_addr
.SetRawAddress(pc
);
256 ThreadSP
thread_sp(GetThread());
258 thread_sp
->ClearStackFrames();
262 const char *StackFrame::Disassemble() {
263 std::lock_guard
<std::recursive_mutex
> guard(m_mutex
);
264 if (!m_disassembly
.Empty())
265 return m_disassembly
.GetData();
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
);
273 return m_disassembly
.Empty() ? nullptr : m_disassembly
.GetData();
276 Block
*StackFrame::GetFrameBlock() {
277 if (m_sc
.block
== nullptr && m_flags
.IsClear(eSymbolContextBlock
))
278 GetSymbolContext(eSymbolContextBlock
);
281 Block
*inline_block
= m_sc
.block
->GetContainingInlinedBlock();
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.
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);
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.
300 const SymbolContext
&
301 StackFrame::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;
307 // If the target was requested add that:
308 if (!m_sc
.target_sp
) {
309 m_sc
.target_sp
= CalculateTarget();
311 resolved
|= eSymbolContextTarget
;
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
317 if (!m_sc
.module_sp
&& m_flags
.IsClear(RESOLVED_FRAME_CODE_ADDR
))
318 GetFrameCodeAddress();
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...
323 Address
lookup_addr(GetFrameCodeAddressForSymbolication());
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.
330 SymbolContextItem actual_resolve_scope
= SymbolContextItem(0);
332 if (resolve_scope
& eSymbolContextCompUnit
) {
333 if (m_flags
.IsClear(eSymbolContextCompUnit
)) {
335 resolved
|= eSymbolContextCompUnit
;
337 actual_resolve_scope
|= eSymbolContextCompUnit
;
341 if (resolve_scope
& eSymbolContextFunction
) {
342 if (m_flags
.IsClear(eSymbolContextFunction
)) {
344 resolved
|= eSymbolContextFunction
;
346 actual_resolve_scope
|= eSymbolContextFunction
;
350 if (resolve_scope
& eSymbolContextBlock
) {
351 if (m_flags
.IsClear(eSymbolContextBlock
)) {
353 resolved
|= eSymbolContextBlock
;
355 actual_resolve_scope
|= eSymbolContextBlock
;
359 if (resolve_scope
& eSymbolContextSymbol
) {
360 if (m_flags
.IsClear(eSymbolContextSymbol
)) {
362 resolved
|= eSymbolContextSymbol
;
364 actual_resolve_scope
|= eSymbolContextSymbol
;
368 if (resolve_scope
& eSymbolContextLineEntry
) {
369 if (m_flags
.IsClear(eSymbolContextLineEntry
)) {
370 if (m_sc
.line_entry
.IsValid())
371 resolved
|= eSymbolContextLineEntry
;
373 actual_resolve_scope
|= eSymbolContextLineEntry
;
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"
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)
389 m_sc
.comp_unit
= sc
.comp_unit
;
390 if ((resolved
& eSymbolContextFunction
) && m_sc
.function
== nullptr)
391 m_sc
.function
= sc
.function
;
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
) &&
397 !m_sc
.line_entry
.IsValid()) {
398 m_sc
.line_entry
= sc
.line_entry
;
399 m_sc
.line_entry
.ApplyFileMappings(m_sc
.target_sp
);
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
);
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
);
420 // Return the symbol context with everything that was possible to resolve
425 VariableList
*StackFrame::GetVariableList(bool get_file_globals
,
427 std::lock_guard
<std::recursive_mutex
> guard(m_mutex
);
428 if (m_flags
.IsClear(RESOLVED_VARIABLES
)) {
429 m_flags
.Set(RESOLVED_VARIABLES
);
430 m_variable_list_sp
= std::make_shared
<VariableList
>();
432 Block
*frame_block
= GetFrameBlock();
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());
445 if (m_flags
.IsClear(RESOLVED_GLOBAL_VARIABLES
) && get_file_globals
) {
446 m_flags
.Set(RESOLVED_GLOBAL_VARIABLES
);
448 if (m_flags
.IsClear(eSymbolContextCompUnit
))
449 GetSymbolContext(eSymbolContextCompUnit
);
451 if (m_sc
.comp_unit
) {
452 VariableListSP
global_variable_list_sp(
453 m_sc
.comp_unit
->GetVariableList(true));
454 if (m_variable_list_sp
)
455 m_variable_list_sp
->AddVariables(global_variable_list_sp
.get());
457 m_variable_list_sp
= global_variable_list_sp
;
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();
468 *error_ptr
= sym_file
->GetFrameVariableError(*this);
472 return m_variable_list_sp
.get();
476 StackFrame::GetInScopeVariableList(bool get_file_globals
,
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.
481 return VariableListSP();
483 VariableListSP
var_list_sp(new VariableList
);
484 GetSymbolContext(eSymbolContextCompUnit
| eSymbolContextBlock
);
487 const bool can_create
= true;
488 const bool get_parent_variables
= true;
489 const bool stop_if_block_is_inlined_function
= true;
490 m_sc
.block
->AppendVariables(
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));
499 if (m_sc
.comp_unit
&& get_file_globals
) {
500 VariableListSP
global_variable_list_sp(
501 m_sc
.comp_unit
->GetVariableList(true));
502 if (global_variable_list_sp
)
503 var_list_sp
->AddVariables(global_variable_list_sp
.get());
509 ValueObjectSP
StackFrame::GetValueForVariableExpressionPath(
510 llvm::StringRef var_expr
, DynamicValueType use_dynamic
, uint32_t options
,
511 VariableSP
&var_sp
, Status
&error
) {
512 ExecutionContext exe_ctx
;
513 CalculateExecutionContext(exe_ctx
);
514 bool use_DIL
= exe_ctx
.GetTargetRef().GetUseDIL(&exe_ctx
);
516 return DILGetValueForVariableExpressionPath(var_expr
, use_dynamic
, options
,
519 return LegacyGetValueForVariableExpressionPath(var_expr
, use_dynamic
, options
,
523 ValueObjectSP
StackFrame::DILGetValueForVariableExpressionPath(
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
,
532 ValueObjectSP
StackFrame::LegacyGetValueForVariableExpressionPath(
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.
538 return ValueObjectSP();
540 if (var_expr
.empty()) {
541 error
= Status::FromErrorStringWithFormatv("invalid variable path '{0}'",
543 return ValueObjectSP();
546 const bool check_ptr_vs_member
=
547 (options
& eExpressionPathOptionCheckPtrVsMember
) != 0;
548 const bool no_fragile_ivar
=
549 (options
& eExpressionPathOptionsNoFragileObjcIvar
) != 0;
550 const bool no_synth_child
=
551 (options
& eExpressionPathOptionsNoSyntheticChildren
) != 0;
552 // const bool no_synth_array = (options &
553 // eExpressionPathOptionsNoSyntheticArrayRange) != 0;
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();
565 return ValueObjectSP();
567 // If first character is a '*', then show pointer contents
568 std::string var_expr_storage
;
569 if (var_expr
[0] == '*') {
571 var_expr
= var_expr
.drop_front(); // Skip the '*'
572 } else if (var_expr
[0] == '&') {
574 var_expr
= var_expr
.drop_front(); // Skip the '&'
577 size_t separator_idx
= var_expr
.find_first_of(".-[=+~|&^%#@!/?,<>{}");
578 StreamString var_expr_path_strm
;
580 ConstString
name_const_string(var_expr
.substr(0, separator_idx
));
582 var_sp
= variable_list
->FindVariable(name_const_string
, false);
584 bool synthetically_added_instance_object
= false;
587 var_expr
= var_expr
.drop_front(name_const_string
.GetLength());
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
));
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
= ".";
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;
613 if (!var_sp
&& (options
& eExpressionPathOptionsInspectAnonymousUnions
)) {
614 // Check if any anonymous unions are there which contain a variable with
616 for (const VariableSP
&variable_sp
: *variable_list
) {
619 if (!variable_sp
->GetName().IsEmpty())
622 Type
*var_type
= variable_sp
->GetType();
626 if (!var_type
->GetForwardCompilerType().IsAnonymousType())
628 valobj_sp
= GetValueObjectForFrameVariable(variable_sp
, use_dynamic
);
631 valobj_sp
= valobj_sp
->GetChildMemberWithName(name_const_string
);
637 if (var_sp
&& !valobj_sp
) {
638 valobj_sp
= GetValueObjectForFrameVariable(var_sp
, use_dynamic
);
643 error
= Status::FromErrorStringWithFormatv(
644 "no variable named '{0}' found in this frame", name_const_string
);
645 return ValueObjectSP();
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
) {
657 if (var_expr
.size() >= 2 && var_expr
[1] != '>')
658 return ValueObjectSP();
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();
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()) {
677 if (valobj_sp
->GetCompilerType().IsReferenceType()) {
678 valobj_sp
= valobj_sp
->GetSyntheticValue()->Dereference(deref_error
);
679 if (!valobj_sp
|| deref_error
.Fail()) {
680 error
= Status::FromErrorStringWithFormatv(
681 "Failed to dereference reference type: {0}", deref_error
);
682 return ValueObjectSP();
686 valobj_sp
= valobj_sp
->Dereference(deref_error
);
687 if (!valobj_sp
|| deref_error
.Fail()) {
688 error
= Status::FromErrorStringWithFormatv(
689 "Failed to dereference synthetic value: {0}", deref_error
);
690 return ValueObjectSP();
692 // Some synthetic plug-ins fail to set the error in Dereference
695 Status::FromErrorString("Failed to dereference synthetic value");
696 return ValueObjectSP();
701 var_expr
= var_expr
.drop_front(); // Remove the '-'
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(".-[")));
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();
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
);
719 error
= Status::FromErrorStringWithFormat(
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());
725 error
= Status::FromErrorStringWithFormat(
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();
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();
739 child_valobj_sp
->GetChildMemberWithName(child_name
);
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
748 error
= Status::FromErrorStringWithFormat(
749 "no variable or instance variable named '%s' found in "
751 name_const_string
.GetCString());
753 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
755 error
= Status::FromErrorStringWithFormat(
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());
761 error
= Status::FromErrorStringWithFormat(
762 "incomplete expression path after \"%s\" in \"%s\"",
763 var_expr_path_strm
.GetData(),
764 original_var_expr
.str().c_str());
767 return ValueObjectSP();
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
;
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) {
785 error
= Status::FromErrorStringWithFormat(
786 "invalid square bracket encountered after \"%s\" in \"%s\"",
787 var_expr_path_strm
.GetData(), var_expr
.str().c_str());
788 return ValueObjectSP();
791 // Drop the open brace.
792 var_expr
= var_expr
.drop_front();
793 long child_index
= 0;
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
) {
798 error
= Status::FromErrorStringWithFormat(
799 "missing closing square bracket in expression \"%s\"",
800 var_expr_path_strm
.GetData());
801 return ValueObjectSP();
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);
808 if (index_expr
.consumeInteger(0, child_index
)) {
809 // If there was no integer anywhere in the index expression, this is
810 // erroneous expression.
811 error
= Status::FromErrorStringWithFormat(
812 "invalid index expression \"%s\"", index_expr
.str().c_str());
813 return ValueObjectSP();
816 if (index_expr
.empty()) {
817 // The entire index expression was a single integer.
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
824 ValueObjectSP
temp(valobj_sp
->Dereference(deref_error
));
825 if (!temp
|| deref_error
.Fail()) {
826 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
827 error
= Status::FromErrorStringWithFormat(
828 "could not dereference \"(%s) %s\"",
829 valobj_sp
->GetTypeName().AsCString("<invalid type>"),
830 var_expr_path_strm
.GetData());
831 return ValueObjectSP();
835 } else if (valobj_sp
->GetCompilerType().IsArrayOfScalarType() &&
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));
843 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
844 error
= Status::FromErrorStringWithFormat(
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();
854 bool is_incomplete_array
= false;
855 if (valobj_sp
->IsPointerType()) {
856 bool is_objc_pointer
= true;
858 if (valobj_sp
->GetCompilerType().GetMinimumLanguage() !=
860 is_objc_pointer
= false;
861 else if (!valobj_sp
->GetCompilerType().IsPointerType())
862 is_objc_pointer
= false;
864 if (no_synth_child
&& is_objc_pointer
) {
865 error
= Status::FromErrorStringWithFormat(
866 "\"(%s) %s\" is an Objective-C pointer, and cannot be "
868 valobj_sp
->GetTypeName().AsCString("<invalid type>"),
869 var_expr_path_strm
.GetData());
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 */
880 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
881 error
= Status::FromErrorStringWithFormat(
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
) >=
887 ->GetNumChildrenIgnoringErrors() /* synthetic does
890 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
891 error
= Status::FromErrorStringWithFormat(
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());
896 child_valobj_sp
= synthetic
->GetChildAtIndex(child_index
);
897 if (!child_valobj_sp
) {
898 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
899 error
= Status::FromErrorStringWithFormat(
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());
907 valobj_sp
->GetSyntheticArrayMember(child_index
, true);
908 if (!child_valobj_sp
) {
909 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
910 error
= Status::FromErrorStringWithFormat(
911 "failed to use pointer as array for index %ld for "
914 valobj_sp
->GetTypeName().AsCString("<invalid type>"),
915 var_expr_path_strm
.GetData());
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
))
925 valobj_sp
->GetSyntheticArrayMember(child_index
, true);
927 if (!child_valobj_sp
) {
928 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
929 error
= Status::FromErrorStringWithFormat(
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());
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
);
940 error
= Status::FromErrorStringWithFormat(
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());
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
953 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
954 error
= Status::FromErrorStringWithFormat(
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
);
962 error
= Status::FromErrorStringWithFormat(
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());
967 child_valobj_sp
= synthetic
->GetChildAtIndex(child_index
);
968 if (!child_valobj_sp
) {
969 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
970 error
= Status::FromErrorStringWithFormat(
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());
978 if (!child_valobj_sp
) {
979 // Invalid array index...
980 return ValueObjectSP();
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
;
989 // Break out early from the switch since we were able to find the child
994 // this is most probably a BitField, let's take a look
995 if (index_expr
.front() != '-') {
996 error
= Status::FromErrorStringWithFormat(
997 "invalid range expression \"'%s'\"",
998 original_index_expr
.str().c_str());
999 return ValueObjectSP();
1002 index_expr
= index_expr
.drop_front();
1003 long final_index
= 0;
1004 if (index_expr
.getAsInteger(0, final_index
)) {
1005 error
= Status::FromErrorStringWithFormat(
1006 "invalid range expression \"'%s'\"",
1007 original_index_expr
.str().c_str());
1008 return ValueObjectSP();
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
;
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
1024 ValueObjectSP
temp(valobj_sp
->Dereference(deref_error
));
1025 if (!temp
|| deref_error
.Fail()) {
1026 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
1027 error
= Status::FromErrorStringWithFormat(
1028 "could not dereference \"(%s) %s\"",
1029 valobj_sp
->GetTypeName().AsCString("<invalid type>"),
1030 var_expr_path_strm
.GetData());
1031 return ValueObjectSP();
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));
1042 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
1043 error
= Status::FromErrorStringWithFormat(
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();
1054 valobj_sp
->GetSyntheticBitFieldChild(child_index
, final_index
, true);
1055 if (!child_valobj_sp
) {
1056 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
1057 error
= Status::FromErrorStringWithFormat(
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());
1063 if (!child_valobj_sp
) {
1064 // Invalid bitfield range...
1065 return ValueObjectSP();
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
;
1074 // Break out early from the switch since we were able to find the child
1081 valobj_sp
->GetExpressionPath(var_expr_path_strm
);
1082 error
= Status::FromErrorStringWithFormat(
1083 "unexpected char '%c' encountered after \"%s\" in \"%s\"",
1084 separator_type
, var_expr_path_strm
.GetData(),
1085 var_expr
.str().c_str());
1087 return ValueObjectSP();
1091 if (child_valobj_sp
)
1092 valobj_sp
= child_valobj_sp
;
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
;
1106 llvm::Error
StackFrame::GetFrameBaseValue(Scalar
&frame_base
) {
1107 std::lock_guard
<std::recursive_mutex
> guard(m_mutex
);
1108 if (!m_cfa_is_valid
) {
1109 m_frame_base_error
= Status::FromErrorString(
1110 "No frame base available for this historical stack frame.");
1111 return m_frame_base_error
.ToError();
1114 if (m_flags
.IsClear(GOT_FRAME_BASE
)) {
1115 if (m_sc
.function
) {
1116 m_frame_base
.Clear();
1117 m_frame_base_error
.Clear();
1119 m_flags
.Set(GOT_FRAME_BASE
);
1120 ExecutionContext
exe_ctx(shared_from_this());
1121 addr_t loclist_base_addr
= LLDB_INVALID_ADDRESS
;
1122 if (!m_sc
.function
->GetFrameBaseExpression().IsAlwaysValidSingleExpr())
1124 m_sc
.function
->GetAddressRange().GetBaseAddress().GetLoadAddress(
1125 exe_ctx
.GetTargetPtr());
1127 llvm::Expected
<Value
> expr_value
=
1128 m_sc
.function
->GetFrameBaseExpression().Evaluate(
1129 &exe_ctx
, nullptr, loclist_base_addr
, nullptr, nullptr);
1131 m_frame_base_error
= Status::FromError(expr_value
.takeError());
1133 m_frame_base
= expr_value
->ResolveValue(&exe_ctx
);
1135 m_frame_base_error
=
1136 Status::FromErrorString("No function in symbol context.");
1140 if (m_frame_base_error
.Fail())
1141 return m_frame_base_error
.ToError();
1143 frame_base
= m_frame_base
;
1144 return llvm::Error::success();
1147 DWARFExpressionList
*StackFrame::GetFrameBaseExpression(Status
*error_ptr
) {
1148 if (!m_sc
.function
) {
1150 *error_ptr
= Status::FromErrorString("No function in symbol context.");
1155 return &m_sc
.function
->GetFrameBaseExpression();
1158 RegisterContextSP
StackFrame::GetRegisterContext() {
1159 std::lock_guard
<std::recursive_mutex
> guard(m_mutex
);
1160 if (!m_reg_context_sp
) {
1161 ThreadSP
thread_sp(GetThread());
1163 m_reg_context_sp
= thread_sp
->CreateRegisterContextForFrame(this);
1165 return m_reg_context_sp
;
1168 bool StackFrame::HasDebugInformation() {
1169 GetSymbolContext(eSymbolContextLineEntry
);
1170 return m_sc
.line_entry
.IsValid();
1174 StackFrame::GetValueObjectForFrameVariable(const VariableSP
&variable_sp
,
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()) {
1187 VariableList
*var_list
= GetVariableList(true, nullptr);
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
) {
1193 valobj_sp
= m_variable_list_value_objects
.GetValueObjectAtIndex(var_idx
);
1195 if (m_variable_list_value_objects
.GetSize() < num_variables
)
1196 m_variable_list_value_objects
.Resize(num_variables
);
1197 valobj_sp
= ValueObjectVariable::Create(this, variable_sp
);
1198 m_variable_list_value_objects
.SetValueObjectAtIndex(var_idx
,
1203 } // End of StackFrame mutex scope.
1204 if (use_dynamic
!= eNoDynamicValues
&& valobj_sp
) {
1205 ValueObjectSP dynamic_sp
= valobj_sp
->GetDynamicValue(use_dynamic
);
1212 bool StackFrame::IsInlined() {
1213 if (m_sc
.block
== nullptr)
1214 GetSymbolContext(eSymbolContextBlock
);
1216 return m_sc
.block
->GetContainingInlinedBlock() != nullptr;
1220 bool StackFrame::IsHistorical() const {
1221 return m_stack_frame_kind
== StackFrame::Kind::History
;
1224 bool StackFrame::IsArtificial() const {
1225 return m_stack_frame_kind
== StackFrame::Kind::Artificial
;
1228 bool StackFrame::IsHidden() {
1229 if (auto recognized_frame_sp
= GetRecognizedFrame())
1230 return recognized_frame_sp
->ShouldHide();
1234 StructuredData::ObjectSP
StackFrame::GetLanguageSpecificData() {
1235 auto process_sp
= CalculateProcess();
1236 SourceLanguage language
= GetLanguage();
1239 if (auto runtime_sp
=
1240 process_sp
->GetLanguageRuntime(language
.AsLanguageType()))
1241 return runtime_sp
->GetLanguageSpecificData(
1242 GetSymbolContext(eSymbolContextFunction
));
1246 const char *StackFrame::GetFunctionName() {
1247 const char *name
= nullptr;
1248 SymbolContext sc
= GetSymbolContext(
1249 eSymbolContextFunction
| eSymbolContextBlock
| eSymbolContextSymbol
);
1251 Block
*inlined_block
= sc
.block
->GetContainingInlinedBlock();
1252 if (inlined_block
) {
1253 const InlineFunctionInfo
*inlined_info
=
1254 inlined_block
->GetInlinedFunctionInfo();
1256 name
= inlined_info
->GetName().AsCString();
1260 if (name
== nullptr) {
1262 name
= sc
.function
->GetName().GetCString();
1265 if (name
== nullptr) {
1267 name
= sc
.symbol
->GetName().GetCString();
1273 const char *StackFrame::GetDisplayFunctionName() {
1274 const char *name
= nullptr;
1275 SymbolContext sc
= GetSymbolContext(
1276 eSymbolContextFunction
| eSymbolContextBlock
| eSymbolContextSymbol
);
1278 Block
*inlined_block
= sc
.block
->GetContainingInlinedBlock();
1279 if (inlined_block
) {
1280 const InlineFunctionInfo
*inlined_info
=
1281 inlined_block
->GetInlinedFunctionInfo();
1283 name
= inlined_info
->GetDisplayName().AsCString();
1287 if (name
== nullptr) {
1289 name
= sc
.function
->GetDisplayName().GetCString();
1292 if (name
== nullptr) {
1294 name
= sc
.symbol
->GetDisplayName().GetCString();
1299 SourceLanguage
StackFrame::GetLanguage() {
1300 CompileUnit
*cu
= GetSymbolContext(eSymbolContextCompUnit
).comp_unit
;
1302 return cu
->GetLanguage();
1306 SourceLanguage
StackFrame::GuessLanguage() {
1307 SourceLanguage lang_type
= GetLanguage();
1309 if (lang_type
== eLanguageTypeUnknown
) {
1311 GetSymbolContext(eSymbolContextFunction
| eSymbolContextSymbol
);
1313 lang_type
= LanguageType(sc
.function
->GetMangled().GuessLanguage());
1315 lang_type
= SourceLanguage(sc
.symbol
->GetMangled().GuessLanguage());
1322 std::pair
<const Instruction::Operand
*, int64_t>
1323 GetBaseExplainingValue(const Instruction::Operand
&operand
,
1324 RegisterContext
®ister_context
, lldb::addr_t value
) {
1325 switch (operand
.m_type
) {
1326 case Instruction::Operand::Type::Dereference
:
1327 case Instruction::Operand::Type::Immediate
:
1328 case Instruction::Operand::Type::Invalid
:
1329 case Instruction::Operand::Type::Product
:
1330 // These are not currently interesting
1331 return std::make_pair(nullptr, 0);
1332 case Instruction::Operand::Type::Sum
: {
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
==
1339 Instruction::Operand::Type::Immediate
) {
1340 immediate_child
= &operand
.m_children
[1];
1341 variable_child
= &operand
.m_children
[0];
1343 if (!immediate_child
) {
1344 return std::make_pair(nullptr, 0);
1346 lldb::addr_t adjusted_value
= value
;
1347 if (immediate_child
->m_negative
) {
1348 adjusted_value
+= immediate_child
->m_immediate
;
1350 adjusted_value
-= immediate_child
->m_immediate
;
1352 std::pair
<const Instruction::Operand
*, int64_t> base_and_offset
=
1353 GetBaseExplainingValue(*variable_child
, register_context
,
1355 if (!base_and_offset
.first
) {
1356 return std::make_pair(nullptr, 0);
1358 if (immediate_child
->m_negative
) {
1359 base_and_offset
.second
-= immediate_child
->m_immediate
;
1361 base_and_offset
.second
+= immediate_child
->m_immediate
;
1363 return base_and_offset
;
1365 case Instruction::Operand::Type::Register
: {
1366 const RegisterInfo
*info
=
1367 register_context
.GetRegisterInfoByName(operand
.m_register
.AsCString());
1369 return std::make_pair(nullptr, 0);
1371 RegisterValue reg_value
;
1372 if (!register_context
.ReadRegister(info
, reg_value
)) {
1373 return std::make_pair(nullptr, 0);
1375 if (reg_value
.GetAsUInt64() == value
) {
1376 return std::make_pair(&operand
, 0);
1378 return std::make_pair(nullptr, 0);
1382 return std::make_pair(nullptr, 0);
1385 std::pair
<const Instruction::Operand
*, int64_t>
1386 GetBaseExplainingDereference(const Instruction::Operand
&operand
,
1387 RegisterContext
®ister_context
,
1388 lldb::addr_t addr
) {
1389 if (operand
.m_type
== Instruction::Operand::Type::Dereference
) {
1390 return GetBaseExplainingValue(operand
.m_children
[0], register_context
,
1393 return std::make_pair(nullptr, 0);
1397 lldb::ValueObjectSP
StackFrame::GuessValueForAddress(lldb::addr_t addr
) {
1398 TargetSP target_sp
= CalculateTarget();
1400 const ArchSpec
&target_arch
= target_sp
->GetArchitecture();
1402 AddressRange pc_range
;
1403 pc_range
.GetBaseAddress() = GetFrameCodeAddress();
1404 pc_range
.SetByteSize(target_arch
.GetMaximumOpcodeByteSize());
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;
1412 DisassemblerSP disassembler_sp
= Disassembler::DisassembleRange(
1413 target_arch
, plugin_name
, flavor
, cpu
, features
, *target_sp
, pc_range
,
1416 if (!disassembler_sp
|| !disassembler_sp
->GetInstructionList().GetSize()) {
1417 return ValueObjectSP();
1420 InstructionSP instruction_sp
=
1421 disassembler_sp
->GetInstructionList().GetInstructionAtIndex(0);
1423 llvm::SmallVector
<Instruction::Operand
, 3> operands
;
1425 if (!instruction_sp
->ParseOperands(operands
)) {
1426 return ValueObjectSP();
1429 RegisterContextSP register_context_sp
= GetRegisterContext();
1431 if (!register_context_sp
) {
1432 return ValueObjectSP();
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
);
1439 if (!base_and_offset
.first
) {
1443 switch (base_and_offset
.first
->m_type
) {
1444 case Instruction::Operand::Type::Immediate
: {
1445 lldb_private::Address addr
;
1446 if (target_sp
->ResolveLoadAddress(base_and_offset
.first
->m_immediate
+
1447 base_and_offset
.second
,
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();
1456 auto ts
= *c_type_system_or_err
;
1459 CompilerType void_ptr_type
=
1460 ts
->GetBasicTypeFromAST(lldb::BasicType::eBasicTypeChar
)
1462 return ValueObjectMemory::Create(this, "", addr
, void_ptr_type
);
1465 return ValueObjectSP();
1469 case Instruction::Operand::Type::Register
: {
1470 return GuessValueForRegisterAndOffset(base_and_offset
.first
->m_register
,
1471 base_and_offset
.second
);
1474 return ValueObjectSP();
1478 return ValueObjectSP();
1482 ValueObjectSP
GetValueForOffset(StackFrame
&frame
, ValueObjectSP
&parent
,
1484 if (offset
< 0 || uint64_t(offset
) >= parent
->GetByteSize()) {
1485 return ValueObjectSP();
1488 if (parent
->IsPointerOrReferenceType()) {
1492 for (int ci
= 0, ce
= parent
->GetNumChildrenIgnoringErrors(); ci
!= ce
;
1494 ValueObjectSP child_sp
= parent
->GetChildAtIndex(ci
);
1497 return ValueObjectSP();
1500 int64_t child_offset
= child_sp
->GetByteOffset();
1501 int64_t child_size
= child_sp
->GetByteSize().value_or(0);
1503 if (offset
>= child_offset
&& offset
< (child_offset
+ child_size
)) {
1504 return GetValueForOffset(frame
, child_sp
, offset
- child_offset
);
1511 return ValueObjectSP();
1515 ValueObjectSP
GetValueForDereferincingOffset(StackFrame
&frame
,
1516 ValueObjectSP
&base
,
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)
1522 if (!base
->IsPointerOrReferenceType()) {
1523 return ValueObjectSP();
1527 ValueObjectSP pointee
= base
->Dereference(error
);
1530 return ValueObjectSP();
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
);
1540 if (!pointee
|| error
.Fail()) {
1541 return ValueObjectSP();
1544 return GetValueForOffset(frame
, pointee
, offset
);
1547 /// Attempt to reconstruct the ValueObject for the address contained in a
1548 /// given register plus an offset.
1550 /// \param [in] frame
1551 /// The current stack frame.
1556 /// \param [in] offset
1557 /// The offset from the register.
1559 /// \param [in] disassembler
1560 /// A disassembler containing instructions valid up to the current PC.
1562 /// \param [in] variables
1563 /// The variable list from the current frame,
1566 /// The program counter for the instruction considered the 'user'.
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.
1572 lldb::ValueObjectSP
DoGuessValueAt(StackFrame
&frame
, ConstString reg
,
1573 int64_t offset
, Disassembler
&disassembler
,
1574 VariableList
&variables
, const Address
&pc
) {
1575 // Example of operation for Intel:
1577 // +14: movq -0x8(%rbp), %rdi
1578 // +18: movq 0x8(%rdi), %rdi
1579 // +22: addl 0x4(%rdi), %eax
1581 // f, a pointer to a struct, is known to be at -0x8(%rbp).
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
1588 // DoGuessValueAt(frame, rbp, -8, dis, vars, 0x14) finds "f" in the
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
1593 // Returns a ValueObject for *(f->b+4) or f->b->a (That's what was stored at
1596 // First, check the variable list to see if anything is at the specified
1599 using namespace OperandMatchers
;
1601 const RegisterInfo
*reg_info
=
1602 frame
.GetRegisterContext()->GetRegisterInfoByName(reg
.AsCString());
1604 return ValueObjectSP();
1607 Instruction::Operand op
=
1608 offset
? Instruction::Operand::BuildDereference(
1609 Instruction::Operand::BuildSum(
1610 Instruction::Operand::BuildRegister(reg
),
1611 Instruction::Operand::BuildImmediate(offset
)))
1612 : Instruction::Operand::BuildDereference(
1613 Instruction::Operand::BuildRegister(reg
));
1615 for (VariableSP var_sp
: variables
) {
1616 if (var_sp
->LocationExpressionList().MatchesOperand(frame
, op
))
1617 return frame
.GetValueObjectForFrameVariable(var_sp
, eNoDynamicValues
);
1620 const uint32_t current_inst
=
1621 disassembler
.GetInstructionList().GetIndexOfInstructionAtAddress(pc
);
1622 if (current_inst
== UINT32_MAX
) {
1623 return ValueObjectSP();
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
);
1634 if (instruction_sp
->IsCall()) {
1635 ABISP abi_sp
= frame
.CalculateProcess()->GetABI();
1640 const char *return_register_name
;
1641 if (!abi_sp
->GetPointerReturnRegister(return_register_name
)) {
1645 const RegisterInfo
*return_register_info
=
1646 frame
.GetRegisterContext()->GetRegisterInfoByName(
1647 return_register_name
);
1648 if (!return_register_info
) {
1654 if (!MatchUnaryOp(MatchOpType(Instruction::Operand::Type::Dereference
),
1655 MatchRegOp(*return_register_info
))(op
) &&
1657 MatchOpType(Instruction::Operand::Type::Dereference
),
1658 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum
),
1659 MatchRegOp(*return_register_info
),
1660 FetchImmOp(offset
)))(op
)) {
1664 llvm::SmallVector
<Instruction::Operand
, 1> operands
;
1665 if (!instruction_sp
->ParseOperands(operands
) || operands
.size() != 1) {
1669 switch (operands
[0].m_type
) {
1672 case Instruction::Operand::Type::Immediate
: {
1674 Address load_address
;
1675 if (!frame
.CalculateTarget()->ResolveLoadAddress(
1676 operands
[0].m_immediate
, load_address
)) {
1679 frame
.CalculateTarget()->GetImages().ResolveSymbolContextForAddress(
1680 load_address
, eSymbolContextFunction
, sc
);
1684 CompilerType function_type
= sc
.function
->GetCompilerType();
1685 if (!function_type
.IsFunctionType()) {
1688 CompilerType return_type
= function_type
.GetFunctionReturnType();
1689 RegisterValue return_value
;
1690 if (!frame
.GetRegisterContext()->ReadRegister(return_register_info
,
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
);
1707 llvm::SmallVector
<Instruction::Operand
, 2> operands
;
1708 if (!instruction_sp
->ParseOperands(operands
) || operands
.size() != 2) {
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
;
1717 if (clobbered_reg_matcher(operands
[0])) {
1718 origin_operand
= &operands
[1];
1720 else if (clobbered_reg_matcher(operands
[1])) {
1721 origin_operand
= &operands
[0];
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;
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(
1736 MatchOpType(Instruction::Operand::Type::Dereference
),
1737 FetchRegOp(origin_register
))(*origin_operand
) ||
1739 MatchOpType(Instruction::Operand::Type::Dereference
),
1740 MatchBinaryOp(MatchOpType(Instruction::Operand::Type::Sum
),
1741 FetchRegOp(origin_register
),
1742 FetchImmOp(origin_offset
)))(*origin_operand
)) {
1744 DoGuessValueAt(frame
, origin_register
, origin_offset
, disassembler
,
1745 variables
, instruction_sp
->GetAddress());
1750 GetValueForDereferincingOffset(frame
, source_path
, offset
);
1758 return ValueObjectSP();
1762 lldb::ValueObjectSP
StackFrame::GuessValueForRegisterAndOffset(ConstString reg
,
1764 TargetSP target_sp
= CalculateTarget();
1766 const ArchSpec
&target_arch
= target_sp
->GetArchitecture();
1768 Block
*frame_block
= GetFrameBlock();
1771 return ValueObjectSP();
1774 Function
*function
= frame_block
->CalculateSymbolContextFunction();
1776 return ValueObjectSP();
1779 AddressRange pc_range
= function
->GetAddressRange();
1781 if (GetFrameCodeAddress().GetFileAddress() <
1782 pc_range
.GetBaseAddress().GetFileAddress() ||
1783 GetFrameCodeAddress().GetFileAddress() -
1784 pc_range
.GetBaseAddress().GetFileAddress() >=
1785 pc_range
.GetByteSize()) {
1786 return ValueObjectSP();
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;
1794 DisassemblerSP disassembler_sp
= Disassembler::DisassembleRange(
1795 target_arch
, plugin_name
, flavor
, cpu
, features
, *target_sp
, pc_range
,
1798 if (!disassembler_sp
|| !disassembler_sp
->GetInstructionList().GetSize()) {
1799 return ValueObjectSP();
1802 const bool get_file_globals
= false;
1803 VariableList
*variables
= GetVariableList(get_file_globals
, nullptr);
1806 return ValueObjectSP();
1809 return DoGuessValueAt(*this, reg
, offset
, *disassembler_sp
, *variables
,
1810 GetFrameCodeAddress());
1813 lldb::ValueObjectSP
StackFrame::FindVariable(ConstString name
) {
1814 ValueObjectSP value_sp
;
1819 TargetSP target_sp
= CalculateTarget();
1820 ProcessSP process_sp
= CalculateProcess();
1822 if (!target_sp
&& !process_sp
)
1825 VariableList variable_list
;
1827 SymbolContext
sc(GetSymbolContext(eSymbolContextBlock
));
1830 const bool can_create
= true;
1831 const bool get_parent_variables
= true;
1832 const bool stop_if_block_is_inlined_function
= true;
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); },
1838 var_sp
= variable_list
.FindVariable(name
);
1842 value_sp
= GetValueObjectForFrameVariable(var_sp
, eNoDynamicValues
);
1848 TargetSP
StackFrame::CalculateTarget() {
1850 ThreadSP
thread_sp(GetThread());
1852 ProcessSP
process_sp(thread_sp
->CalculateProcess());
1854 target_sp
= process_sp
->CalculateTarget();
1859 ProcessSP
StackFrame::CalculateProcess() {
1860 ProcessSP process_sp
;
1861 ThreadSP
thread_sp(GetThread());
1863 process_sp
= thread_sp
->CalculateProcess();
1867 ThreadSP
StackFrame::CalculateThread() { return GetThread(); }
1869 StackFrameSP
StackFrame::CalculateStackFrame() { return shared_from_this(); }
1871 void StackFrame::CalculateExecutionContext(ExecutionContext
&exe_ctx
) {
1872 exe_ctx
.SetContext(shared_from_this());
1875 bool StackFrame::DumpUsingFormat(Stream
&strm
,
1876 const FormatEntity::Entry
*format
,
1877 llvm::StringRef frame_marker
) {
1878 GetSymbolContext(eSymbolContextEverything
);
1879 ExecutionContext
exe_ctx(shared_from_this());
1881 s
.PutCString(frame_marker
);
1883 if (format
&& FormatEntity::Format(*format
, s
, &m_sc
, &exe_ctx
, nullptr,
1884 nullptr, false, false)) {
1885 strm
.PutCString(s
.GetString());
1891 void StackFrame::DumpUsingSettingsFormat(Stream
*strm
, bool show_unique
,
1892 const char *frame_marker
) {
1893 if (strm
== nullptr)
1896 ExecutionContext
exe_ctx(shared_from_this());
1898 const FormatEntity::Entry
*frame_format
= nullptr;
1899 Target
*target
= exe_ctx
.GetTargetPtr();
1902 frame_format
= target
->GetDebugger().GetFrameFormatUnique();
1904 frame_format
= target
->GetDebugger().GetFrameFormat();
1907 if (!DumpUsingFormat(*strm
, frame_format
, frame_marker
)) {
1908 Dump(strm
, true, false);
1913 void StackFrame::Dump(Stream
*strm
, bool show_frame_index
,
1914 bool show_fullpaths
) {
1915 if (strm
== nullptr)
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)
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;
1931 m_sc
.DumpStopContext(strm
, exe_ctx
.GetBestExecutionContextScope(),
1932 GetFrameCodeAddress(), show_fullpaths
, show_module
,
1933 show_inline
, show_function_arguments
,
1934 show_function_name
);
1937 void StackFrame::UpdateCurrentFrameFromPreviousFrame(StackFrame
&prev_frame
) {
1938 std::lock_guard
<std::recursive_mutex
> guard(m_mutex
);
1939 assert(GetStackID() ==
1940 prev_frame
.GetStackID()); // TODO: remove this after some testing
1941 m_variable_list_sp
= prev_frame
.m_variable_list_sp
;
1942 m_variable_list_value_objects
.Swap(prev_frame
.m_variable_list_value_objects
);
1943 if (!m_disassembly
.GetString().empty()) {
1944 m_disassembly
.Clear();
1945 m_disassembly
.PutCString(prev_frame
.m_disassembly
.GetString());
1949 void StackFrame::UpdatePreviousFrameFromCurrentFrame(StackFrame
&curr_frame
) {
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
;
1956 m_concrete_frame_index
= curr_frame
.m_concrete_frame_index
;
1957 m_reg_context_sp
= curr_frame
.m_reg_context_sp
;
1958 m_frame_code_addr
= curr_frame
.m_frame_code_addr
;
1959 m_behaves_like_zeroth_frame
= curr_frame
.m_behaves_like_zeroth_frame
;
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
);
1970 m_flags
.Set(m_sc
.GetResolvedMask());
1971 m_frame_base
.Clear();
1972 m_frame_base_error
.Clear();
1975 bool StackFrame::HasCachedData() const {
1976 if (m_variable_list_sp
)
1978 if (m_variable_list_value_objects
.GetSize() > 0)
1980 if (!m_disassembly
.GetString().empty())
1985 bool StackFrame::GetStatus(Stream
&strm
, bool show_frame_info
, bool show_source
,
1986 bool show_unique
, const char *frame_marker
) {
1987 if (show_frame_info
) {
1989 DumpUsingSettingsFormat(&strm
, show_unique
, frame_marker
);
1993 ExecutionContext
exe_ctx(shared_from_this());
1994 bool have_source
= false, have_debuginfo
= false;
1995 Debugger::StopDisassemblyType disasm_display
=
1996 Debugger::eStopDisassemblyTypeNever
;
1997 Target
*target
= exe_ctx
.GetTargetPtr();
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();
2006 GetSymbolContext(eSymbolContextCompUnit
| eSymbolContextLineEntry
);
2007 if (m_sc
.comp_unit
&& m_sc
.line_entry
.IsValid()) {
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
);
2017 target
->GetSourceManager().DisplaySourceLinesWithLineNumbers(
2018 source_file_sp
, start_line
, m_sc
.line_entry
.column
,
2019 source_lines_before
, source_lines_after
, "->", &strm
);
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";
2028 switch (disasm_display
) {
2029 case Debugger::eStopDisassemblyTypeNever
:
2032 case Debugger::eStopDisassemblyTypeNoDebugInfo
:
2037 case Debugger::eStopDisassemblyTypeNoSource
:
2042 case Debugger::eStopDisassemblyTypeAlways
:
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;
2050 Disassembler::Disassemble(
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,
2056 Disassembler::eOptionMarkPCAddress
, strm
);
2066 RecognizedStackFrameSP
StackFrame::GetRecognizedFrame() {
2067 auto process
= GetThread()->GetProcess();
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();