Skip to content

Commit 3ad7af7

Browse files
Merge commit '5d088ba30440' from llvm.org/main into next
2 parents f52ff13 + 5d088ba commit 3ad7af7

File tree

9 files changed

+293
-19
lines changed

9 files changed

+293
-19
lines changed

lldb/include/lldb/Target/StackID.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ class StackID {
2626

2727
lldb::addr_t GetPC() const { return m_pc; }
2828

29-
lldb::addr_t GetCallFrameAddress() const { return m_cfa; }
29+
lldb::addr_t GetCallFrameAddressWithMetadata() const {
30+
return m_cfa_with_metadata;
31+
}
32+
33+
lldb::addr_t GetCallFrameAddressWithoutMetadata() const { return m_cfa; }
3034

3135
SymbolContextScope *GetSymbolContextScope() const { return m_symbol_scope; }
3236

@@ -71,6 +75,9 @@ class StackID {
7175
/// below)
7276
lldb::addr_t m_cfa = LLDB_INVALID_ADDRESS;
7377

78+
/// The cfa with metadata (i.e. prior to Process::FixAddress).
79+
lldb::addr_t m_cfa_with_metadata = LLDB_INVALID_ADDRESS;
80+
7481
/// If nullptr, there is no block or symbol for this frame. If not nullptr,
7582
/// this will either be the scope for the lexical block for the frame, or the
7683
/// scope for the symbol. Symbol context scopes are always be unique pointers

lldb/source/API/SBFrame.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ lldb::addr_t SBFrame::GetCFA() const {
275275
}
276276

277277
if (StackFrame *frame = exe_ctx->GetFramePtr())
278-
return frame->GetStackID().GetCallFrameAddress();
278+
return frame->GetStackID().GetCallFrameAddressWithoutMetadata();
279279
return LLDB_INVALID_ADDRESS;
280280
}
281281

lldb/source/Expression/DWARFExpression.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2279,7 +2279,7 @@ llvm::Expected<Value> DWARFExpression::Evaluate(
22792279
// Note that we don't have to parse FDEs because this DWARF expression
22802280
// is commonly evaluated with a valid stack frame.
22812281
StackID id = frame->GetStackID();
2282-
addr_t cfa = id.GetCallFrameAddress();
2282+
addr_t cfa = id.GetCallFrameAddressWithMetadata();
22832283
if (cfa != LLDB_INVALID_ADDRESS) {
22842284
stack.push_back(Scalar(cfa));
22852285
stack.back().SetValueType(Value::ValueType::LoadAddress);

lldb/source/Target/RegisterContextUnwind.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,8 +2039,6 @@ bool RegisterContextUnwind::ReadFrameAddress(
20392039
reg_info, cfa_reg_contents, reg_info->byte_size, reg_value);
20402040
if (error.Success()) {
20412041
address = reg_value.GetAsUInt64();
2042-
if (abi_sp)
2043-
address = abi_sp->FixCodeAddress(address);
20442042
UnwindLogMsg(
20452043
"CFA value via dereferencing reg %s (%d): reg has val 0x%" PRIx64
20462044
", CFA value is 0x%" PRIx64,
@@ -2062,8 +2060,6 @@ bool RegisterContextUnwind::ReadFrameAddress(
20622060
RegisterNumber cfa_reg(m_thread, row_register_kind,
20632061
fa.GetRegisterNumber());
20642062
if (ReadGPRValue(cfa_reg, cfa_reg_contents)) {
2065-
if (abi_sp)
2066-
cfa_reg_contents = abi_sp->FixDataAddress(cfa_reg_contents);
20672063
if (cfa_reg_contents == LLDB_INVALID_ADDRESS || cfa_reg_contents == 0 ||
20682064
cfa_reg_contents == 1) {
20692065
UnwindLogMsg(
@@ -2100,9 +2096,6 @@ bool RegisterContextUnwind::ReadFrameAddress(
21002096
dwarfexpr.Evaluate(&exe_ctx, this, 0, nullptr, nullptr);
21012097
if (result) {
21022098
address = result->GetScalar().ULongLong();
2103-
if (ABISP abi_sp = m_thread.GetProcess()->GetABI())
2104-
address = abi_sp->FixCodeAddress(address);
2105-
21062099
UnwindLogMsg("CFA value set by DWARF expression is 0x%" PRIx64,
21072100
address);
21082101
return true;
@@ -2143,7 +2136,6 @@ bool RegisterContextUnwind::ReadFrameAddress(
21432136
}
21442137
case UnwindPlan::Row::FAValue::isConstant: {
21452138
address = fa.GetConstant();
2146-
address = m_thread.GetProcess()->FixDataAddress(address);
21472139
UnwindLogMsg("CFA value set by constant is 0x%" PRIx64, address);
21482140
return true;
21492141
}

lldb/source/Target/StackFrameList.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ bool StackFrameList::FetchFramesUpTo(uint32_t end_idx,
462462
}
463463
} else {
464464
unwind_frame_sp = m_frames.front();
465-
cfa = unwind_frame_sp->m_id.GetCallFrameAddress();
465+
cfa = unwind_frame_sp->m_id.GetCallFrameAddressWithoutMetadata();
466466
}
467467
} else {
468468
// Check for interruption when building the frames.

lldb/source/Target/StackID.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ bool StackID::IsCFAOnStack(Process &process) const {
3535

3636
StackID::StackID(lldb::addr_t pc, lldb::addr_t cfa,
3737
SymbolContextScope *symbol_scope, Process *process)
38-
: m_pc(pc), m_cfa(cfa), m_symbol_scope(symbol_scope) {
38+
: m_pc(pc), m_cfa(cfa), m_cfa_with_metadata(cfa),
39+
m_symbol_scope(symbol_scope) {
3940
if (process) {
4041
m_pc = process->FixCodeAddress(m_pc);
4142
m_cfa = process->FixDataAddress(m_cfa);
@@ -47,6 +48,7 @@ void StackID::SetPC(lldb::addr_t pc, Process *process) {
4748
}
4849

4950
void StackID::SetCFA(lldb::addr_t cfa, Process *process) {
51+
m_cfa_with_metadata = cfa;
5052
m_cfa = process ? process->FixDataAddress(cfa) : cfa;
5153
}
5254

@@ -67,7 +69,8 @@ void StackID::Dump(Stream *s) {
6769
}
6870

6971
bool lldb_private::operator==(const StackID &lhs, const StackID &rhs) {
70-
if (lhs.GetCallFrameAddress() != rhs.GetCallFrameAddress())
72+
if (lhs.GetCallFrameAddressWithoutMetadata() !=
73+
rhs.GetCallFrameAddressWithoutMetadata())
7174
return false;
7275

7376
SymbolContextScope *lhs_scope = lhs.GetSymbolContextScope();
@@ -134,8 +137,8 @@ CompareHeapCFAs(const StackID &lhs, const StackID &rhs, Process &process) {
134137
if (!lhs_cfa_on_stack && rhs_cfa_on_stack)
135138
return HeapCFAComparisonResult::Older;
136139

137-
const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddress();
138-
const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddress();
140+
const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddressWithoutMetadata();
141+
const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddressWithoutMetadata();
139142
// If the cfas are the same, fallback to the usual scope comparison.
140143
if (lhs_cfa == rhs_cfa)
141144
return HeapCFAComparisonResult::NoOpinion;
@@ -170,9 +173,9 @@ bool StackID::IsYounger(const StackID &lhs, const StackID &rhs,
170173
break;
171174
}
172175
// END SWIFT
173-
174-
const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddress();
175-
const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddress();
176+
//
177+
const lldb::addr_t lhs_cfa = lhs.GetCallFrameAddressWithoutMetadata();
178+
const lldb::addr_t rhs_cfa = rhs.GetCallFrameAddressWithoutMetadata();
176179

177180
// FIXME: We are assuming that the stacks grow downward in memory. That's not
178181
// necessary, but true on
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ASM_SOURCES := main.s
2+
3+
# This is to appease Makefile.rules, there is no main.c
4+
C_SOURCES := main.c
5+
6+
ASM_OBJS := $(ASM_SOURCES:.s=.o)
7+
8+
%.o: %.s
9+
$(CC) -c -x assembler $< -o $@
10+
11+
include Makefile.rules
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import lldb
2+
from lldbsuite.test.decorators import *
3+
from lldbsuite.test.lldbtest import *
4+
from lldbsuite.test import lldbutil
5+
6+
7+
@skipUnlessDarwin
8+
@skipIf(archs=no_match(["arm64"]))
9+
class TestArmPointerMetadataStripping(TestBase):
10+
def test(self):
11+
self.build()
12+
target, process, thread, bkpt = lldbutil.run_to_name_breakpoint(self, "foo")
13+
14+
# Step over the first two instructions of foo in order to
15+
# toggle the bit of fp and save it on the stack:
16+
# orr x29, x29, #0x1000000000000000
17+
# stp x29, x30, [sp, #-16]!
18+
# This is effectively adding metadata to the CFA of the caller frame (main).
19+
thread.StepInstruction(False)
20+
thread.StepInstruction(False)
21+
22+
# The location of `argv` has been artificially made equal to the CFA of the frame.
23+
# As such, it should have the metadata artificially set previously.
24+
argv_addr = thread.frames[1].GetValueForVariablePath("&argv")
25+
self.assertTrue(argv_addr.IsValid())
26+
argv_addr_uint = argv_addr.GetValueAsUnsigned()
27+
self.assertNotEqual((argv_addr_uint & (1 << 60)), 0)
28+
29+
# GetCFA strips metadata.
30+
cfa = thread.frames[1].GetCFA()
31+
self.assertEqual((cfa & (1 << 60)), 0)
32+
33+
# If the test worked correctly, the cfa and the location should be identical,
34+
# modulo the metadata.
35+
self.assertEqual(cfa | (1 << 60), argv_addr_uint)

0 commit comments

Comments
 (0)