LLDB mainline
StackID.cpp
Go to the documentation of this file.
1//===-- StackID.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/Symbol/Block.h"
11#include "lldb/Symbol/Symbol.h"
14#include "lldb/Target/Process.h"
15#include "lldb/Utility/Stream.h"
16
17using namespace lldb_private;
18
20 SymbolContextScope *symbol_scope, Process *process)
21 : m_pc(pc), m_cfa(cfa), m_cfa_with_metadata(cfa),
22 m_symbol_scope(symbol_scope) {
23 if (process) {
24 m_pc = process->FixCodeAddress(m_pc);
25 m_cfa = process->FixDataAddress(m_cfa);
26 }
27}
28
30 m_pc = process ? process->FixCodeAddress(pc) : pc;
31}
32
35 m_cfa = process ? process->FixDataAddress(cfa) : cfa;
36}
37
39 s->Printf("StackID (pc = 0x%16.16" PRIx64 ", cfa = 0x%16.16" PRIx64
40 ", symbol_scope = %p",
41 m_pc, m_cfa, static_cast<void *>(m_symbol_scope));
43 s->Printf(", tail_call_depth = %u", m_tail_call_depth);
44 if (m_symbol_scope) {
46
47 m_symbol_scope->CalculateSymbolContext(&sc);
48 if (sc.block)
49 s->Printf(" (Block {0x%8.8" PRIx64 "})", sc.block->GetID());
50 else if (sc.symbol)
51 s->Printf(" (Symbol{0x%8.8x})", sc.symbol->GetID());
52 }
53 s->PutCString(") ");
54}
55
56bool lldb_private::operator==(const StackID &lhs, const StackID &rhs) {
59 return false;
60
61 if (lhs.GetTailCallDepth() != rhs.GetTailCallDepth())
62 return false;
63
66
67 // Only compare the PC values if both symbol context scopes are nullptr
68 if (lhs_scope == nullptr && rhs_scope == nullptr)
69 return lhs.GetPC() == rhs.GetPC();
70
71 return lhs_scope == rhs_scope;
72}
73
74bool lldb_private::operator!=(const StackID &lhs, const StackID &rhs) {
75 return !(lhs == rhs);
76}
77
78bool StackID::IsYoungerThan(const StackID &other, Process &process) const {
79 CFAComparison comparison = process.CompareCFAs(*this, other);
80 if (comparison == CFAComparison::NoOpinion)
81 comparison = LanguageRuntime::CompareCFAs(process, *this, other);
82 switch (comparison) {
84 return true;
86 return false;
88 break;
89 }
90
93
94 // FIXME: We are assuming that the stacks grow downward in memory. That's not
95 // necessary, but true on
96 // all the machines we care about at present. If this changes, we'll have to
97 // deal with that. The ABI is the agent who knows this ordering, but the
98 // StackID has no access to the ABI. The most straightforward way to handle
99 // this is to add a "m_grows_downward" bool to the StackID, and set it in the
100 // constructor. But I'm not going to waste a bool per StackID on this till we
101 // need it.
102
103 if (lhs_cfa != rhs_cfa)
104 return lhs_cfa < rhs_cfa;
105
106 // Tail call frames share the CFA of the younger frames that replaced them.
109
111 SymbolContextScope *rhs_scope = other.GetSymbolContextScope();
112
113 if (lhs_scope != nullptr && rhs_scope != nullptr) {
114 // Same exact scope, lhs is not less than (younger than rhs)
115 if (lhs_scope == rhs_scope)
116 return false;
117
118 SymbolContext lhs_sc;
119 SymbolContext rhs_sc;
120 lhs_scope->CalculateSymbolContext(&lhs_sc);
121 rhs_scope->CalculateSymbolContext(&rhs_sc);
122
123 // Items with the same function can only be compared
124 if (lhs_sc.function == rhs_sc.function && lhs_sc.function != nullptr &&
125 lhs_sc.block != nullptr && rhs_sc.function != nullptr &&
126 rhs_sc.block != nullptr) {
127 return rhs_sc.block->Contains(lhs_sc.block);
128 }
129 }
130 return false;
131}
bool Contains(lldb::addr_t range_offset) const
Check if an offset is in one of the block offset ranges.
Definition Block.cpp:180
static CFAComparison CompareCFAs(Process &process, const StackID &lhs, const StackID &rhs)
Compares the frames identified by lhs and rhs, if a language runtime of process can order them.
A plug-in interface definition class for debugging a process.
Definition Process.h:370
lldb::addr_t FixDataAddress(lldb::addr_t pc)
Definition Process.cpp:6476
lldb::addr_t FixCodeAddress(lldb::addr_t pc)
Some targets might use bits in a code address to indicate a mode switch, ARM uses bit zero to signify...
Definition Process.cpp:6470
virtual CFAComparison CompareCFAs(const StackID &lhs, const StackID &rhs)
Compares the call frame addresses of two frames.
Definition Process.h:1514
void Dump(Stream *s)
Definition StackID.cpp:38
lldb::addr_t m_cfa
The call frame address (stack pointer) value at the beginning of the function that uniquely identifie...
Definition StackID.h:83
lldb::addr_t GetCallFrameAddressWithoutMetadata() const
Definition StackID.h:36
void SetPC(lldb::addr_t pc, Process *process)
Definition StackID.cpp:29
SymbolContextScope * GetSymbolContextScope() const
Definition StackID.h:38
uint32_t m_tail_call_depth
For a synthesized tail call frame, which has the CFA of the younger frame that replaced it,...
Definition StackID.h:98
lldb::addr_t m_pc
The pc value for the function/symbol for this frame.
Definition StackID.h:78
lldb::addr_t GetPC() const
Definition StackID.h:30
lldb::addr_t m_cfa_with_metadata
The cfa with metadata (i.e. prior to Process::FixAddress).
Definition StackID.h:86
SymbolContextScope * m_symbol_scope
If nullptr, there is no block or symbol for this frame.
Definition StackID.h:93
uint32_t GetTailCallDepth() const
Definition StackID.h:44
bool IsYoungerThan(const StackID &other, Process &process) const
Returns true if this StackID corresponds to a frame younger (i.e.
Definition StackID.cpp:78
void SetCFA(lldb::addr_t cfa, Process *process)
Definition StackID.cpp:33
A stream class that can stream formatted output to a file.
Definition Stream.h:28
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:63
"lldb/Symbol/SymbolContextScope.h" Inherit from this if your object is part of a symbol context and c...
virtual void CalculateSymbolContext(SymbolContext *sc)=0
Reconstruct the object's symbol context into sc.
Defines a symbol context baton that can be handed other debug core functions.
Function * function
The Function for a given query.
Block * block
The Block for a given query.
Symbol * symbol
The Symbol for a given query.
uint32_t GetID() const
Definition Symbol.h:152
A class that represents a running process on the host machine.
bool operator!=(const Address &lhs, const Address &rhs)
Definition Address.cpp:1011
bool operator==(const Address &lhs, const Address &rhs)
Definition Address.cpp:1005
CFAComparison
How the call frame addresses of two frames order them.
Definition StackID.h:19
uint64_t addr_t
Definition lldb-types.h:80
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition UserID.h:47