Skip to content

Commit b608ee8

Browse files
[lldb] Call FixDataAddress when following Swift async chain
The code comparing async context addresses need to strip any pointer authentication bits, otherwise the integer comparison will always fail. (cherry picked from commit 6e361c7)
1 parent 269d273 commit b608ee8

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

lldb/source/Target/StackID.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ bool lldb_private::operator!=(const StackID &lhs, const StackID &rhs) {
8383
static llvm::Expected<bool> IsReachableParent(lldb::addr_t source,
8484
lldb::addr_t maybe_parent,
8585
Process &process) {
86+
maybe_parent = process.FixDataAddress(maybe_parent);
8687
auto max_num_frames = 512;
8788
for (lldb::addr_t parent_ctx = source; parent_ctx && max_num_frames;
8889
max_num_frames--) {
@@ -94,7 +95,7 @@ static llvm::Expected<bool> IsReachableParent(lldb::addr_t source,
9495
return llvm::createStringError(llvm::formatv(
9596
"Failed to read parent async context of: {0:x}. Error: {1}",
9697
old_parent_ctx, error.AsCString()));
97-
if (parent_ctx == maybe_parent)
98+
if (process.FixDataAddress(parent_ctx) == maybe_parent)
9899
return true;
99100
}
100101
if (max_num_frames == 0)

lldb/unittests/StackID/StackIDTest.cpp

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,27 @@ struct MockStackID : StackID {
7676
};
7777

7878
TEST_F(StackIDTest, StackStackCFAComparison) {
79-
auto process = MockProcess(m_target_sp, Listener::MakeListener("dummy"));
79+
auto process = std::make_shared<MockProcess>(m_target_sp,
80+
Listener::MakeListener("dummy"));
8081

8182
MockStackID small_cfa_on_stack(/*cfa*/ 10, OnStack::Yes);
8283
MockStackID big_cfa_on_stack(/*cfa*/ 100, OnStack::Yes);
8384

8485
EXPECT_TRUE(
85-
StackID::IsYounger(small_cfa_on_stack, big_cfa_on_stack, process));
86+
StackID::IsYounger(small_cfa_on_stack, big_cfa_on_stack, *process));
8687
EXPECT_FALSE(
87-
StackID::IsYounger(big_cfa_on_stack, small_cfa_on_stack, process));
88+
StackID::IsYounger(big_cfa_on_stack, small_cfa_on_stack, *process));
8889
}
8990

9091
TEST_F(StackIDTest, StackHeapCFAComparison) {
91-
auto process = MockProcess(m_target_sp, Listener::MakeListener("dummy"));
92+
auto process = std::make_shared<MockProcess>(m_target_sp,
93+
Listener::MakeListener("dummy"));
9294

9395
MockStackID cfa_on_stack(/*cfa*/ 100, OnStack::Yes);
9496
MockStackID cfa_on_heap(/*cfa*/ 10, OnStack::No);
9597

96-
EXPECT_TRUE(StackID::IsYounger(cfa_on_stack, cfa_on_heap, process));
97-
EXPECT_FALSE(StackID::IsYounger(cfa_on_heap, cfa_on_stack, process));
98+
EXPECT_TRUE(StackID::IsYounger(cfa_on_stack, cfa_on_heap, *process));
99+
EXPECT_FALSE(StackID::IsYounger(cfa_on_heap, cfa_on_stack, *process));
98100
}
99101

100102
TEST_F(StackIDTest, HeapHeapCFAComparison) {
@@ -107,21 +109,21 @@ TEST_F(StackIDTest, HeapHeapCFAComparison) {
107109
memory_map[100] = 108;
108110
memory_map[108] = 116;
109111
memory_map[116] = 0;
110-
auto process = MockProcess(m_target_sp, Listener::MakeListener("dummy"),
111-
std::move(memory_map));
112+
auto process = std::make_shared<MockProcess>(
113+
m_target_sp, Listener::MakeListener("dummy"), std::move(memory_map));
112114

113115
MockStackID oldest_cfa(/*cfa*/ 116, OnStack::No);
114116
MockStackID middle_cfa(/*cfa*/ 108, OnStack::No);
115117
MockStackID youngest_cfa(/*cfa*/ 100, OnStack::No);
116118

117-
EXPECT_TRUE(StackID::IsYounger(youngest_cfa, oldest_cfa, process));
118-
EXPECT_FALSE(StackID::IsYounger(oldest_cfa, youngest_cfa, process));
119+
EXPECT_TRUE(StackID::IsYounger(youngest_cfa, oldest_cfa, *process));
120+
EXPECT_FALSE(StackID::IsYounger(oldest_cfa, youngest_cfa, *process));
119121

120-
EXPECT_TRUE(StackID::IsYounger(youngest_cfa, middle_cfa, process));
121-
EXPECT_FALSE(StackID::IsYounger(middle_cfa, youngest_cfa, process));
122+
EXPECT_TRUE(StackID::IsYounger(youngest_cfa, middle_cfa, *process));
123+
EXPECT_FALSE(StackID::IsYounger(middle_cfa, youngest_cfa, *process));
122124

123-
EXPECT_TRUE(StackID::IsYounger(middle_cfa, oldest_cfa, process));
124-
EXPECT_FALSE(StackID::IsYounger(oldest_cfa, middle_cfa, process));
125+
EXPECT_TRUE(StackID::IsYounger(middle_cfa, oldest_cfa, *process));
126+
EXPECT_FALSE(StackID::IsYounger(oldest_cfa, middle_cfa, *process));
125127
}
126128

127129
TEST_F(StackIDTest, HeapHeapCFAComparisonDecreasing) {
@@ -134,19 +136,19 @@ TEST_F(StackIDTest, HeapHeapCFAComparisonDecreasing) {
134136
memory_map[100] = 90;
135137
memory_map[90] = 80;
136138
memory_map[80] = 0;
137-
auto process = MockProcess(m_target_sp, Listener::MakeListener("dummy"),
138-
std::move(memory_map));
139+
auto process = std::make_shared<MockProcess>(
140+
m_target_sp, Listener::MakeListener("dummy"), std::move(memory_map));
139141

140142
MockStackID oldest_cfa(/*cfa*/ 80, OnStack::No);
141143
MockStackID middle_cfa(/*cfa*/ 90, OnStack::No);
142144
MockStackID youngest_cfa(/*cfa*/ 100, OnStack::No);
143145

144-
EXPECT_TRUE(StackID::IsYounger(youngest_cfa, oldest_cfa, process));
145-
EXPECT_FALSE(StackID::IsYounger(oldest_cfa, youngest_cfa, process));
146+
EXPECT_TRUE(StackID::IsYounger(youngest_cfa, oldest_cfa, *process));
147+
EXPECT_FALSE(StackID::IsYounger(oldest_cfa, youngest_cfa, *process));
146148

147-
EXPECT_TRUE(StackID::IsYounger(youngest_cfa, middle_cfa, process));
148-
EXPECT_FALSE(StackID::IsYounger(middle_cfa, youngest_cfa, process));
149+
EXPECT_TRUE(StackID::IsYounger(youngest_cfa, middle_cfa, *process));
150+
EXPECT_FALSE(StackID::IsYounger(middle_cfa, youngest_cfa, *process));
149151

150-
EXPECT_TRUE(StackID::IsYounger(middle_cfa, oldest_cfa, process));
151-
EXPECT_FALSE(StackID::IsYounger(oldest_cfa, middle_cfa, process));
152+
EXPECT_TRUE(StackID::IsYounger(middle_cfa, oldest_cfa, *process));
153+
EXPECT_FALSE(StackID::IsYounger(oldest_cfa, middle_cfa, *process));
152154
}

0 commit comments

Comments
 (0)