LLDB
mainline
llvm-project
lldb
source
Target
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
9
#include "
lldb/Target/StackID.h
"
10
#include "
lldb/Symbol/Block.h
"
11
#include "
lldb/Symbol/Symbol.h
"
12
#include "
lldb/Symbol/SymbolContext.h
"
13
#include "
lldb/Utility/Stream.h
"
14
15
using namespace
lldb_private
;
16
17
void
StackID::Dump
(
Stream
*s) {
18
s->
Printf
(
"StackID (pc = 0x%16.16"
PRIx64
", cfa = 0x%16.16"
PRIx64
19
", symbol_scope = %p"
,
20
m_pc
,
m_cfa
,
static_cast<
void
*
>
(
m_symbol_scope
));
21
if
(
m_symbol_scope
) {
22
SymbolContext
sc;
23
24
m_symbol_scope
->
CalculateSymbolContext
(&sc);
25
if
(sc.
block
)
26
s->
Printf
(
" (Block {0x%8.8"
PRIx64
"})"
, sc.
block
->
GetID
());
27
else
if
(sc.
symbol
)
28
s->
Printf
(
" (Symbol{0x%8.8x})"
, sc.
symbol
->
GetID
());
29
}
30
s->
PutCString
(
") "
);
31
}
32
33
bool
lldb_private::operator==
(
const
StackID
&lhs,
const
StackID
&rhs) {
34
if
(lhs.
GetCallFrameAddress
() != rhs.
GetCallFrameAddress
())
35
return
false
;
36
37
SymbolContextScope
*lhs_scope = lhs.
GetSymbolContextScope
();
38
SymbolContextScope
*rhs_scope = rhs.
GetSymbolContextScope
();
39
40
// Only compare the PC values if both symbol context scopes are nullptr
41
if
(lhs_scope ==
nullptr
&& rhs_scope ==
nullptr
)
42
return
lhs.
GetPC
() == rhs.
GetPC
();
43
44
return
lhs_scope == rhs_scope;
45
}
46
47
bool
lldb_private::operator!=
(
const
StackID
&lhs,
const
StackID
&rhs) {
48
if
(lhs.
GetCallFrameAddress
() != rhs.
GetCallFrameAddress
())
49
return
true
;
50
51
SymbolContextScope
*lhs_scope = lhs.
GetSymbolContextScope
();
52
SymbolContextScope
*rhs_scope = rhs.
GetSymbolContextScope
();
53
54
if
(lhs_scope ==
nullptr
&& rhs_scope ==
nullptr
)
55
return
lhs.
GetPC
() != rhs.
GetPC
();
56
57
return
lhs_scope != rhs_scope;
58
}
59
60
bool
lldb_private::operator<
(
const
StackID
&lhs,
const
StackID
&rhs) {
61
const
lldb::addr_t
lhs_cfa = lhs.
GetCallFrameAddress
();
62
const
lldb::addr_t
rhs_cfa = rhs.
GetCallFrameAddress
();
63
64
// FIXME: We are assuming that the stacks grow downward in memory. That's not
65
// necessary, but true on
66
// all the machines we care about at present. If this changes, we'll have to
67
// deal with that. The ABI is the agent who knows this ordering, but the
68
// StackID has no access to the ABI. The most straightforward way to handle
69
// this is to add a "m_grows_downward" bool to the StackID, and set it in the
70
// constructor. But I'm not going to waste a bool per StackID on this till we
71
// need it.
72
73
if
(lhs_cfa != rhs_cfa)
74
return
lhs_cfa < rhs_cfa;
75
76
SymbolContextScope
*lhs_scope = lhs.
GetSymbolContextScope
();
77
SymbolContextScope
*rhs_scope = rhs.
GetSymbolContextScope
();
78
79
if
(lhs_scope !=
nullptr
&& rhs_scope !=
nullptr
) {
80
// Same exact scope, lhs is not less than (younger than rhs)
81
if
(lhs_scope == rhs_scope)
82
return
false
;
83
84
SymbolContext
lhs_sc;
85
SymbolContext
rhs_sc;
86
lhs_scope->
CalculateSymbolContext
(&lhs_sc);
87
rhs_scope->
CalculateSymbolContext
(&rhs_sc);
88
89
// Items with the same function can only be compared
90
if
(lhs_sc.
function
== rhs_sc.
function
&& lhs_sc.
function
!=
nullptr
&&
91
lhs_sc.
block
!=
nullptr
&& rhs_sc.
function
!=
nullptr
&&
92
rhs_sc.
block
!=
nullptr
) {
93
return
rhs_sc.
block
->
Contains
(lhs_sc.
block
);
94
}
95
}
96
return
false
;
97
}
Block.h
lldb_private::SymbolContext::block
Block * block
The Block for a given query.
Definition:
SymbolContext.h:321
lldb_private::StackID::m_cfa
lldb::addr_t m_cfa
Definition:
StackID.h:78
lldb_private::StackID::m_symbol_scope
SymbolContextScope * m_symbol_scope
Definition:
StackID.h:83
lldb_private::Stream
Definition:
Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition:
lldb-types.h:83
lldb_private::StackID::m_pc
lldb::addr_t m_pc
Definition:
StackID.h:72
lldb_private::SymbolContext
Definition:
SymbolContext.h:33
lldb_private::StackID::GetSymbolContextScope
SymbolContextScope * GetSymbolContextScope() const
Definition:
StackID.h:37
lldb_private::operator==
bool operator==(const Address &lhs, const Address &rhs)
Definition:
Address.cpp:1016
lldb_private::StackID::GetCallFrameAddress
lldb::addr_t GetCallFrameAddress() const
Definition:
StackID.h:35
lldb_private::SymbolContext::symbol
Symbol * symbol
The Symbol for a given query.
Definition:
SymbolContext.h:323
lldb_private::StackID::Dump
void Dump(Stream *s)
Definition:
StackID.cpp:17
lldb_private::SymbolContextScope::CalculateSymbolContext
virtual void CalculateSymbolContext(SymbolContext *sc)=0
Reconstruct the object's symbol context into sc.
lldb_private::SymbolContext::function
Function * function
The Function for a given query.
Definition:
SymbolContext.h:320
lldb_private::StackID::GetPC
lldb::addr_t GetPC() const
Definition:
StackID.h:33
StackID.h
lldb_private::operator!=
bool operator!=(const Address &lhs, const Address &rhs)
Definition:
Address.cpp:1022
lldb_private::SymbolContextScope
Definition:
SymbolContextScope.h:64
lldb_private::UserID::GetID
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition:
UserID.h:47
Symbol.h
lldb_private::Block::Contains
bool Contains(lldb::addr_t range_offset) const
Check if an offset is in one of the block offset ranges.
Definition:
Block.cpp:180
lldb_private::operator<
bool operator<(const Address &lhs, const Address &rhs)
Definition:
Address.cpp:985
lldb_private::Stream::Printf
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition:
Stream.cpp:107
SymbolContext.h
lldb_private
A class that represents a running process on the host machine.
Definition:
SBCommandInterpreterRunOptions.h:16
lldb_private::StackID
Definition:
StackID.h:17
Stream.h
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition:
Stream.cpp:63
lldb_private::Symbol::GetID
uint32_t GetID() const
Definition:
Symbol.h:111
Generated on Sat May 21 2022 01:21:29 for LLDB by
1.8.17