[Lldb-commits] [lldb] c489679 - [lldb] Rebuild stack frames when a process address mask changes (#224989)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 25 23:42:47 PDT 2026
Author: Med Ismail Bennani
Date: 2026-09-25T23:42:40-07:00
New Revision: c4896792fb97b2ad237c5c404cdda2d0cd4fcf61
URL: https://github.com/llvm/llvm-project/commit/c4896792fb97b2ad237c5c404cdda2d0cd4fcf61
DIFF: https://github.com/llvm/llvm-project/commit/c4896792fb97b2ad237c5c404cdda2d0cd4fcf61.diff
LOG: [lldb] Rebuild stack frames when a process address mask changes (#224989)
Added:
Modified:
lldb/include/lldb/Target/Process.h
lldb/source/API/SBProcess.cpp
lldb/source/Target/Process.cpp
lldb/test/API/python_api/process/address-masks/TestAddressMasks.py
Removed:
################################################################################
diff --git a/lldb/include/lldb/Target/Process.h b/lldb/include/lldb/Target/Process.h
index 3a124464468782..984a4ef880800e 100644
--- a/lldb/include/lldb/Target/Process.h
+++ b/lldb/include/lldb/Target/Process.h
@@ -99,6 +99,7 @@ class ProcessProperties : public Properties {
void SetVirtualAddressableBits(uint32_t bits);
uint32_t GetHighmemVirtualAddressableBits() const;
void SetHighmemVirtualAddressableBits(uint32_t bits);
+ void AddressMaskChangedCallback();
void SetPythonOSPluginPath(const FileSpec &file);
bool GetIgnoreBreakpointsInExpressions() const;
void SetIgnoreBreakpointsInExpressions(bool ignore);
diff --git a/lldb/source/API/SBProcess.cpp b/lldb/source/API/SBProcess.cpp
index 288acfad62b2bb..53d8d3c3e5ddf8 100644
--- a/lldb/source/API/SBProcess.cpp
+++ b/lldb/source/API/SBProcess.cpp
@@ -1454,6 +1454,8 @@ void SBProcess::SetAddressMask(AddressMaskType type, addr_t mask,
LLDB_INSTRUMENT_VA(this, type, mask, addr_range);
if (ProcessSP process_sp = GetSP()) {
+ TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
+ std::lock_guard<TargetAPIMutex> guard(api_lock);
switch (type) {
case eAddressMaskTypeCode:
if (addr_range == eAddressMaskRangeAll) {
@@ -1490,6 +1492,7 @@ void SBProcess::SetAddressMask(AddressMaskType type, addr_t mask,
}
break;
}
+ process_sp->AddressMaskChangedCallback();
}
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 71280e8d3262e8..c86160ae0432d6 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -200,6 +200,12 @@ ProcessProperties::ProcessProperties(lldb_private::Process *process)
m_collection_sp->SetValueChangedCallback(
ePropertyDisableLangRuntimeUnwindPlans,
[this] { DisableLanguageRuntimeUnwindPlansCallback(); });
+ m_collection_sp->SetValueChangedCallback(
+ ePropertyVirtualAddressableBits,
+ [this] { AddressMaskChangedCallback(); });
+ m_collection_sp->SetValueChangedCallback(
+ ePropertyHighmemVirtualAddressableBits,
+ [this] { AddressMaskChangedCallback(); });
}
}
@@ -264,6 +270,18 @@ void ProcessProperties::SetHighmemVirtualAddressableBits(uint32_t bits) {
SetPropertyAtIndex(idx, static_cast<uint64_t>(bits));
}
+void ProcessProperties::AddressMaskChangedCallback() {
+ if (!m_process)
+ return;
+ Process::StopLocker stop_locker;
+ if (!stop_locker.TryLock(&m_process->GetRunLock()))
+ return;
+ // Never call this from address-fixing code, which runs while frames are being
+ // constructed.
+ for (ThreadSP thread_sp : m_process->Threads())
+ thread_sp->ClearStackFrames();
+}
+
void ProcessProperties::SetPythonOSPluginPath(const FileSpec &file) {
const uint32_t idx = ePropertyPythonOSPluginPath;
SetPropertyAtIndex(idx, file);
diff --git a/lldb/test/API/python_api/process/address-masks/TestAddressMasks.py b/lldb/test/API/python_api/process/address-masks/TestAddressMasks.py
index 83a2e294b0542d..38a73c17558d4a 100644
--- a/lldb/test/API/python_api/process/address-masks/TestAddressMasks.py
+++ b/lldb/test/API/python_api/process/address-masks/TestAddressMasks.py
@@ -111,6 +111,28 @@ def test_address_masks_target_supports_highmem_tests(self):
self.assertEqual(0x000002950001F694, process.FixAddress(0x00265E950001F694))
self.reset_all_masks(process)
+ @skipIf(archs=no_match(["arm64", "arm64e", "aarch64"]))
+ def test_changing_mask_invalidates_stack_frames(self):
+ self.build()
+ (target, process, thread, bp) = lldbutil.run_to_source_breakpoint(
+ self, "break here", lldb.SBFileSpec("main.c")
+ )
+
+ pc = thread.GetFrameAtIndex(0).GetPC()
+ self.assertNotEqual(pc & ~0x7FFF, 0)
+
+ process.SetAddressableBits(lldb.eAddressMaskTypeAll, 15)
+ self.assertEqual(thread.GetFrameAtIndex(0).GetPC(), pc & 0x7FFF)
+
+ process.SetAddressableBits(lldb.eAddressMaskTypeAll, 64)
+ self.assertEqual(thread.GetFrameAtIndex(0).GetPC(), pc)
+
+ self.runCmd("settings set target.process.virtual-addressable-bits 15")
+ self.assertEqual(thread.GetFrameAtIndex(0).GetPC(), pc & 0x7FFF)
+
+ self.reset_all_masks(process)
+ self.assertEqual(thread.GetFrameAtIndex(0).GetPC(), pc)
+
# On most targets where we have a single mask for all address range, confirm
# that the high memory masks are ignored.
@skipIf(archs=["arm64", "arm64e", "aarch64"])
More information about the lldb-commits
mailing list