Skip to content

Commit 9c8e716

Browse files
[lldb] Make StackID call Fix{Code,Data} pointers (#152796)
In architectures where pointers may contain metadata, such as arm64e, it is important to ignore those bits when comparing two different StackIDs, as the metadata may not be the same even if the pointers are. This patch is a step towards allowing consumers of pointers to decide whether they want to keep or remove metadata, as opposed to discarding metadata at the moment pointers are created. See #150537. This was tested running the LLDB test suite on arm64e.
1 parent 26a0962 commit 9c8e716

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

lldb/include/lldb/Target/StackID.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
namespace lldb_private {
1616

17+
class Process;
18+
1719
class StackID {
1820
public:
1921
// Constructors and Destructors
2022
StackID() = default;
2123

2224
explicit StackID(lldb::addr_t pc, lldb::addr_t cfa,
23-
SymbolContextScope *symbol_scope)
24-
: m_pc(pc), m_cfa(cfa), m_symbol_scope(symbol_scope) {}
25+
SymbolContextScope *symbol_scope, Process *process);
2526

2627
StackID(const StackID &rhs)
2728
: m_pc(rhs.m_pc), m_cfa(rhs.m_cfa), m_symbol_scope(rhs.m_symbol_scope) {}
@@ -63,9 +64,8 @@ class StackID {
6364
protected:
6465
friend class StackFrame;
6566

66-
void SetPC(lldb::addr_t pc) { m_pc = pc; }
67-
68-
void SetCFA(lldb::addr_t cfa) { m_cfa = cfa; }
67+
void SetPC(lldb::addr_t pc, Process *process);
68+
void SetCFA(lldb::addr_t cfa, Process *process);
6969

7070
lldb::addr_t m_pc =
7171
LLDB_INVALID_ADDRESS; // The pc value for the function/symbol for this

lldb/source/Target/StackFrame.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
6161
const SymbolContext *sc_ptr)
6262
: m_thread_wp(thread_sp), m_frame_index(frame_idx),
6363
m_concrete_frame_index(unwind_frame_index), m_reg_context_sp(),
64-
m_id(pc, cfa, nullptr), m_frame_code_addr(pc), m_sc(), m_flags(),
65-
m_frame_base(), m_frame_base_error(), m_cfa_is_valid(cfa_is_valid),
64+
m_id(pc, cfa, nullptr, thread_sp->GetProcess().get()),
65+
m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(),
66+
m_frame_base_error(), m_cfa_is_valid(cfa_is_valid),
6667
m_stack_frame_kind(kind),
6768
m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
6869
m_variable_list_sp(), m_variable_list_value_objects(),
@@ -71,7 +72,7 @@ StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
7172
// recursive functions properly aren't confused with one another on a history
7273
// stack.
7374
if (IsHistorical() && !m_cfa_is_valid) {
74-
m_id.SetCFA(m_frame_index);
75+
m_id.SetCFA(m_frame_index, thread_sp->GetProcess().get());
7576
}
7677

7778
if (sc_ptr != nullptr) {
@@ -87,7 +88,8 @@ StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
8788
const SymbolContext *sc_ptr)
8889
: m_thread_wp(thread_sp), m_frame_index(frame_idx),
8990
m_concrete_frame_index(unwind_frame_index),
90-
m_reg_context_sp(reg_context_sp), m_id(pc, cfa, nullptr),
91+
m_reg_context_sp(reg_context_sp),
92+
m_id(pc, cfa, nullptr, thread_sp->GetProcess().get()),
9193
m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(),
9294
m_frame_base_error(), m_cfa_is_valid(true),
9395
m_stack_frame_kind(StackFrame::Kind::Regular),
@@ -115,7 +117,7 @@ StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
115117
m_concrete_frame_index(unwind_frame_index),
116118
m_reg_context_sp(reg_context_sp),
117119
m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa,
118-
nullptr),
120+
nullptr, thread_sp->GetProcess().get()),
119121
m_frame_code_addr(pc_addr), m_sc(), m_flags(), m_frame_base(),
120122
m_frame_base_error(), m_cfa_is_valid(true),
121123
m_stack_frame_kind(StackFrame::Kind::Regular),
@@ -1995,7 +1997,9 @@ void StackFrame::UpdatePreviousFrameFromCurrentFrame(StackFrame &curr_frame) {
19951997
std::lock_guard<std::recursive_mutex> guard(m_mutex);
19961998
assert(GetStackID() ==
19971999
curr_frame.GetStackID()); // TODO: remove this after some testing
1998-
m_id.SetPC(curr_frame.m_id.GetPC()); // Update the Stack ID PC value
2000+
m_id.SetPC(
2001+
curr_frame.m_id.GetPC(),
2002+
curr_frame.CalculateProcess().get()); // Update the Stack ID PC value
19992003
assert(GetThread() == curr_frame.GetThread());
20002004
m_frame_index = curr_frame.m_frame_index;
20012005
m_concrete_frame_index = curr_frame.m_concrete_frame_index;

lldb/source/Target/StackID.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,28 @@
1010
#include "lldb/Symbol/Block.h"
1111
#include "lldb/Symbol/Symbol.h"
1212
#include "lldb/Symbol/SymbolContext.h"
13+
#include "lldb/Target/Process.h"
1314
#include "lldb/Utility/Stream.h"
1415

1516
using namespace lldb_private;
1617

18+
StackID::StackID(lldb::addr_t pc, lldb::addr_t cfa,
19+
SymbolContextScope *symbol_scope, Process *process)
20+
: m_pc(pc), m_cfa(cfa), m_symbol_scope(symbol_scope) {
21+
if (process) {
22+
m_pc = process->FixCodeAddress(m_pc);
23+
m_cfa = process->FixDataAddress(m_cfa);
24+
}
25+
}
26+
27+
void StackID::SetPC(lldb::addr_t pc, Process *process) {
28+
m_pc = process ? process->FixCodeAddress(pc) : pc;
29+
}
30+
31+
void StackID::SetCFA(lldb::addr_t cfa, Process *process) {
32+
m_cfa = process ? process->FixDataAddress(cfa) : cfa;
33+
}
34+
1735
void StackID::Dump(Stream *s) {
1836
s->Printf("StackID (pc = 0x%16.16" PRIx64 ", cfa = 0x%16.16" PRIx64
1937
", symbol_scope = %p",

0 commit comments

Comments
 (0)