https://github.com/felipepiovezan updated 
https://github.com/llvm/llvm-project/pull/153585

>From ce9c2cc6748c22ce4b0f5178b66668f5e877d430 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiove...@apple.com>
Date: Wed, 13 Aug 2025 18:38:23 -0700
Subject: [PATCH 1/3] [lldb] Call FixUpPointer in WritePointerToMemory (try 2)

In architectures where pointers may contain metadata, such as arm64e,
the metadata may need to be cleaned prior to sending this pointer to be
used in expression evaluation generated code.

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.

(The first attempt at this patch caused a failure in
TestScriptedProcessEmptyMemoryRegion.py. This test exercises a case
where IRMemoryMap uses host memory in its allocations; pointers to such
allocations should not be fixed, which is what the original patch failed
to account for).
---
 lldb/source/Expression/IRMemoryMap.cpp | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lldb/source/Expression/IRMemoryMap.cpp 
b/lldb/source/Expression/IRMemoryMap.cpp
index 150699352a2e3..3ac42649d0834 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -640,6 +640,13 @@ void IRMemoryMap::WritePointerToMemory(lldb::addr_t 
process_address,
                                        lldb::addr_t address, Status &error) {
   error.Clear();
 
+  /// Only ask the Process to fix the address if this address belongs to the
+  /// process (host allocations are stored in m_data).
+  if (auto it = FindAllocation(process_address, 1);
+      it != m_allocations.end() && it->second.m_data.GetByteSize() == 0)
+    if (auto process_sp = GetProcessWP().lock())
+      address = process_sp->FixAnyAddress(address);
+
   Scalar scalar(address);
 
   WriteScalarToMemory(process_address, scalar, GetAddressByteSize(), error);

>From 36dcebb09eecd46f649feb4073c4f10b75423699 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiove...@apple.com>
Date: Thu, 14 Aug 2025 08:22:44 -0700
Subject: [PATCH 2/3] fixup! Improve comment

---
 lldb/source/Expression/IRMemoryMap.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Expression/IRMemoryMap.cpp 
b/lldb/source/Expression/IRMemoryMap.cpp
index 3ac42649d0834..7faf6809383eb 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -641,7 +641,8 @@ void IRMemoryMap::WritePointerToMemory(lldb::addr_t 
process_address,
   error.Clear();
 
   /// Only ask the Process to fix the address if this address belongs to the
-  /// process (host allocations are stored in m_data).
+  /// process. An address belongs to the process if the Allocation contains a
+  /// non-empty m_data member.
   if (auto it = FindAllocation(process_address, 1);
       it != m_allocations.end() && it->second.m_data.GetByteSize() == 0)
     if (auto process_sp = GetProcessWP().lock())

>From 579c985eb3bbce4d10e86de7ff87238541936232 Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan <fpiove...@apple.com>
Date: Thu, 14 Aug 2025 08:22:58 -0700
Subject: [PATCH 3/3] fixup! Add {} to if statement

---
 lldb/source/Expression/IRMemoryMap.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lldb/source/Expression/IRMemoryMap.cpp 
b/lldb/source/Expression/IRMemoryMap.cpp
index 7faf6809383eb..8b6d87b589c1b 100644
--- a/lldb/source/Expression/IRMemoryMap.cpp
+++ b/lldb/source/Expression/IRMemoryMap.cpp
@@ -644,9 +644,10 @@ void IRMemoryMap::WritePointerToMemory(lldb::addr_t 
process_address,
   /// process. An address belongs to the process if the Allocation contains a
   /// non-empty m_data member.
   if (auto it = FindAllocation(process_address, 1);
-      it != m_allocations.end() && it->second.m_data.GetByteSize() == 0)
+      it != m_allocations.end() && it->second.m_data.GetByteSize() == 0) {
     if (auto process_sp = GetProcessWP().lock())
       address = process_sp->FixAnyAddress(address);
+  }
 
   Scalar scalar(address);
 

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to