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"
13#include "lldb/Target/Process.h"
14#include "lldb/Utility/Stream.h"
15
16using namespace lldb_private;
17
19 SymbolContextScope *symbol_scope, Process *process)
20 : m_pc(pc), m_cfa(cfa), m_cfa_with_metadata(cfa),
21 m_symbol_scope(symbol_scope) {
22 if (process) {
23 m_pc = process->FixCodeAddress(m_pc);
24 m_cfa = process->FixDataAddress(m_cfa);
25 }
26}
27
29 m_pc = process ? process->FixCodeAddress(pc) : pc;
30}
31
34 m_cfa = process ? process->FixDataAddress(cfa) : cfa;
35}
36
38 s->Printf("StackID (pc = 0x%16.16" PRIx64 ", cfa = 0x%16.16" PRIx64
39 ", symbol_scope = %p",
40 m_pc, m_cfa, static_cast<void *>(m_symbol_scope));
41 if (m_symbol_scope) {
43
44 m_symbol_scope->CalculateSymbolContext(&sc);
45 if (sc.block)
46 s->Printf(" (Block {0x%8.8" PRIx64 "})", sc.block->GetID());
47 else if (sc.symbol)
48 s->Printf(" (Symbol{0x%8.8x})", sc.symbol->GetID());
49 }
50 s->PutCString(") ");
51}
52
53bool lldb_private::operator==(const StackID &lhs, const StackID &rhs) {
56 return false;
57
60
61 // Only compare the PC values if both symbol context scopes are nullptr
62 if (lhs_scope == nullptr && rhs_scope == nullptr)
63 return lhs.GetPC() == rhs.GetPC();
64
65 return lhs_scope == rhs_scope;
66}
67
68bool lldb_private::operator!=(const StackID &lhs, const StackID &rhs) {
69 return !(lhs == rhs);
70}
71
72bool lldb_private::operator<(const StackID &lhs, const StackID &rhs) {
75
76 // FIXME: We are assuming that the stacks grow downward in memory. That's not
77 // necessary, but true on
78 // all the machines we care about at present. If this changes, we'll have to
79 // deal with that. The ABI is the agent who knows this ordering, but the
80 // StackID has no access to the ABI. The most straightforward way to handle
81 // this is to add a "m_grows_downward" bool to the StackID, and set it in the
82 // constructor. But I'm not going to waste a bool per StackID on this till we
83 // need it.
84
85 if (lhs_cfa != rhs_cfa)
86 return lhs_cfa < rhs_cfa;
87
90
91 if (lhs_scope != nullptr && rhs_scope != nullptr) {
92 // Same exact scope, lhs is not less than (younger than rhs)
93 if (lhs_scope == rhs_scope)
94 return false;
95
96 SymbolContext lhs_sc;
97 SymbolContext rhs_sc;
98 lhs_scope->CalculateSymbolContext(&lhs_sc);
99 rhs_scope->CalculateSymbolContext(&rhs_sc);
100
101 // Items with the same function can only be compared
102 if (lhs_sc.function == rhs_sc.function && lhs_sc.function != nullptr &&
103 lhs_sc.block != nullptr && rhs_sc.function != nullptr &&
104 rhs_sc.block != nullptr) {
105 return rhs_sc.block->Contains(lhs_sc.block);
106 }
107 }
108 return false;
109}
bool Contains(lldb::addr_t range_offset) const
Check if an offset is in one of the block offset ranges.
Definition Block.cpp:180
A plug-in interface definition class for debugging a process.
Definition Process.h:357
lldb::addr_t FixDataAddress(lldb::addr_t pc)
Definition Process.cpp:5962
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:5956
void Dump(Stream *s)
Definition StackID.cpp:37
lldb::addr_t m_cfa
The call frame address (stack pointer) value at the beginning of the function that uniquely identifie...
Definition StackID.h:67
lldb::addr_t GetCallFrameAddressWithoutMetadata() const
Definition StackID.h:33
void SetPC(lldb::addr_t pc, Process *process)
Definition StackID.cpp:28
SymbolContextScope * GetSymbolContextScope() const
Definition StackID.h:35
lldb::addr_t m_pc
The pc value for the function/symbol for this frame.
Definition StackID.h:62
lldb::addr_t GetPC() const
Definition StackID.h:27
lldb::addr_t m_cfa_with_metadata
The cfa with metadata (i.e. prior to Process::FixAddress).
Definition StackID.h:70
SymbolContextScope * m_symbol_scope
If nullptr, there is no block or symbol for this frame.
Definition StackID.h:77
void SetCFA(lldb::addr_t cfa, Process *process)
Definition StackID.cpp:32
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:65
"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:137
A class that represents a running process on the host machine.
bool operator!=(const Address &lhs, const Address &rhs)
Definition Address.cpp:1017
bool operator==(const Address &lhs, const Address &rhs)
Definition Address.cpp:1011
bool operator<(const Address &lhs, const Address &rhs)
Definition Address.cpp:980
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