Skip to content

Commit 395957e

Browse files
[lldb] Make StackID call Fix{Code,Data} pointers (llvm#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 llvm#150537. This was tested running the LLDB test suite on arm64e. (cherry picked from commit 9c8e716)
1 parent 1afad2b commit 395957e

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

lldb/include/lldb/Target/StackID.h

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

1515
namespace lldb_private {
1616

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

24+
explicit StackID(lldb::addr_t pc, lldb::addr_t cfa,
25+
SymbolContextScope *symbol_scope, Process *process);
26+
2227
StackID(const StackID &rhs) = default;
2328

2429
~StackID() = default;
@@ -68,11 +73,8 @@ class StackID {
6873
protected:
6974
friend class StackFrame;
7075

71-
explicit StackID(lldb::addr_t pc, lldb::addr_t cfa) : m_pc(pc), m_cfa(cfa) {}
72-
73-
void SetPC(lldb::addr_t pc) { m_pc = pc; }
74-
75-
void SetCFA(lldb::addr_t cfa) { m_cfa = cfa; }
76+
void SetPC(lldb::addr_t pc, Process *process);
77+
void SetCFA(lldb::addr_t cfa, Process *process);
7678

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

lldb/source/Target/StackFrame.cpp

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

7879
if (sc_ptr != nullptr) {
@@ -88,9 +89,11 @@ StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
8889
const SymbolContext *sc_ptr)
8990
: m_thread_wp(thread_sp), m_frame_index(frame_idx),
9091
m_concrete_frame_index(unwind_frame_index),
91-
m_reg_context_sp(reg_context_sp), m_id(pc, cfa), m_frame_code_addr(pc),
92-
m_sc(), m_flags(), m_frame_base(), m_frame_base_error(),
93-
m_cfa_is_valid(true), m_stack_frame_kind(StackFrame::Kind::Regular),
92+
m_reg_context_sp(reg_context_sp),
93+
m_id(pc, cfa, nullptr, thread_sp->GetProcess().get()),
94+
m_frame_code_addr(pc), m_sc(), m_flags(), m_frame_base(),
95+
m_frame_base_error(), m_cfa_is_valid(true),
96+
m_stack_frame_kind(StackFrame::Kind::Regular),
9497
m_behaves_like_zeroth_frame(behaves_like_zeroth_frame),
9598
m_variable_list_sp(), m_variable_list_value_objects(),
9699
m_recognized_frame_sp(), m_disassembly(), m_mutex() {
@@ -114,7 +117,8 @@ StackFrame::StackFrame(const ThreadSP &thread_sp, user_id_t frame_idx,
114117
: m_thread_wp(thread_sp), m_frame_index(frame_idx),
115118
m_concrete_frame_index(unwind_frame_index),
116119
m_reg_context_sp(reg_context_sp),
117-
m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa),
120+
m_id(pc_addr.GetLoadAddress(thread_sp->CalculateTarget().get()), cfa,
121+
nullptr, thread_sp->GetProcess().get()),
118122
m_frame_code_addr(pc_addr), m_sc(), m_flags(), m_frame_base(),
119123
m_frame_base_error(), m_cfa_is_valid(true),
120124
m_stack_frame_kind(StackFrame::Kind::Regular),
@@ -2054,7 +2058,9 @@ void StackFrame::UpdatePreviousFrameFromCurrentFrame(StackFrame &curr_frame) {
20542058
std::lock_guard<std::recursive_mutex> guard(m_mutex);
20552059
assert(GetStackID() ==
20562060
curr_frame.GetStackID()); // TODO: remove this after some testing
2057-
m_id.SetPC(curr_frame.m_id.GetPC()); // Update the Stack ID PC value
2061+
m_id.SetPC(
2062+
curr_frame.m_id.GetPC(),
2063+
curr_frame.CalculateProcess().get()); // Update the Stack ID PC value
20582064
assert(GetThread() == curr_frame.GetThread());
20592065
m_frame_index = curr_frame.m_frame_index;
20602066
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
@@ -14,6 +14,7 @@
1414
#include "lldb/Target/Process.h"
1515
#include "lldb/Target/Thread.h"
1616
#include "lldb/Utility/LLDBLog.h"
17+
#include "lldb/Target/Process.h"
1718
#include "lldb/Utility/Stream.h"
1819

1920
using namespace lldb_private;
@@ -32,6 +33,23 @@ bool StackID::IsCFAOnStack(Process &process) const {
3233
return m_cfa_on_stack == eLazyBoolYes;
3334
}
3435

36+
StackID::StackID(lldb::addr_t pc, lldb::addr_t cfa,
37+
SymbolContextScope *symbol_scope, Process *process)
38+
: m_pc(pc), m_cfa(cfa), m_symbol_scope(symbol_scope) {
39+
if (process) {
40+
m_pc = process->FixCodeAddress(m_pc);
41+
m_cfa = process->FixDataAddress(m_cfa);
42+
}
43+
}
44+
45+
void StackID::SetPC(lldb::addr_t pc, Process *process) {
46+
m_pc = process ? process->FixCodeAddress(pc) : pc;
47+
}
48+
49+
void StackID::SetCFA(lldb::addr_t cfa, Process *process) {
50+
m_cfa = process ? process->FixDataAddress(cfa) : cfa;
51+
}
52+
3553
void StackID::Dump(Stream *s) {
3654
s->Printf("StackID (pc = 0x%16.16" PRIx64 ", cfa = 0x%16.16" PRIx64
3755
", cfa_on_stack = %d, symbol_scope = %p",

0 commit comments

Comments
 (0)