[Lldb-commits] [lldb] [lldb][core] Fix getting summary of a variable pointing to r/o memory (PR #139196)

Igor Kudrin via lldb-commits lldb-commits at lists.llvm.org
Fri May 9 14:25:18 PDT 2025


================
@@ -735,14 +735,25 @@ size_t ValueObject::GetPointeeData(DataExtractor &data, uint32_t item_idx,
     case eAddressTypeLoad: {
       ExecutionContext exe_ctx(GetExecutionContextRef());
       Process *process = exe_ctx.GetProcessPtr();
-      if (process) {
+      if (process && process->IsLiveDebugSession()) {
         heap_buf_ptr->SetByteSize(bytes);
         size_t bytes_read = process->ReadMemory(
             addr + offset, heap_buf_ptr->GetBytes(), bytes, error);
         if (error.Success() || bytes_read > 0) {
           data.SetData(data_sp);
           return bytes_read;
         }
+      } else if (Target *target = exe_ctx.GetTargetPtr()) {
+        Address target_addr;
+        target_addr.SetLoadAddress(addr + offset, target);
+        heap_buf_ptr->SetByteSize(bytes);
+        size_t bytes_read =
+            target->ReadMemory(target_addr, heap_buf_ptr->GetBytes(), bytes,
+                               error, /*force_live_memory=*/true);
----------------
igorkudrin wrote:

The difference is that with `force_live_memory==true`, `Target::ReadMemory()` tries to get the data from the process first, and resorts to reading from the file cache if that fails. With  `force_live_memory==false` and if the data is in a read-only section, it reads from the file cache into a temporary buffer, and then calls `Process::ReadMemory()` anyway. So, with either setting, it prefers the data from the process, but `force_live_memory==true` seems to be just a bit more efficient.

https://github.com/llvm/llvm-project/pull/139196


More information about the lldb-commits mailing list