[Lldb-commits] [PATCH] D114675: [lldb] [Target] Support fallback to file address in ReadMemory()

Michał Górny via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Nov 28 06:41:44 PST 2021


mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski.
Herald added a subscriber: arichardson.
mgorny requested review of this revision.

Add a fallback to `GetFileAddress()` when `GetLoadAddress()` fails
in `ReadMemory()`.  This is consistent with how expression evaluation
behaves, and fixes the inconsistency between the two following commands
run on top of FreeBSD vmcore:

- `p *(int *)&hz` (prints correct value)
- `memory read &hz` (prints zeros)


https://reviews.llvm.org/D114675

Files:
  lldb/source/Target/Target.cpp


Index: lldb/source/Target/Target.cpp
===================================================================
--- lldb/source/Target/Target.cpp
+++ lldb/source/Target/Target.cpp
@@ -1782,36 +1782,27 @@
   if (ProcessIsValid()) {
     if (load_addr == LLDB_INVALID_ADDRESS)
       load_addr = resolved_addr.GetLoadAddress(this);
-
-    if (load_addr == LLDB_INVALID_ADDRESS) {
-      ModuleSP addr_module_sp(resolved_addr.GetModule());
-      if (addr_module_sp && addr_module_sp->GetFileSpec())
-        error.SetErrorStringWithFormatv(
-            "{0:F}[{1:x+}] can't be resolved, {0:F} is not currently loaded",
-            addr_module_sp->GetFileSpec(), resolved_addr.GetFileAddress());
-      else
-        error.SetErrorStringWithFormat("0x%" PRIx64 " can't be resolved",
-                                       resolved_addr.GetFileAddress());
-    } else {
-      bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
-      if (bytes_read != dst_len) {
-        if (error.Success()) {
-          if (bytes_read == 0)
-            error.SetErrorStringWithFormat(
-                "read memory from 0x%" PRIx64 " failed", load_addr);
-          else
-            error.SetErrorStringWithFormat(
-                "only %" PRIu64 " of %" PRIu64
-                " bytes were read from memory at 0x%" PRIx64,
-                (uint64_t)bytes_read, (uint64_t)dst_len, load_addr);
-        }
-      }
-      if (bytes_read) {
-        if (load_addr_ptr)
-          *load_addr_ptr = load_addr;
-        return bytes_read;
+    if (load_addr == LLDB_INVALID_ADDRESS)
+      load_addr = resolved_addr.GetFileAddress();
+
+    bytes_read = m_process_sp->ReadMemory(load_addr, dst, dst_len, error);
+    if (bytes_read != dst_len) {
+      if (error.Success()) {
+        if (bytes_read == 0)
+          error.SetErrorStringWithFormat(
+              "read memory from 0x%" PRIx64 " failed", load_addr);
+        else
+          error.SetErrorStringWithFormat(
+              "only %" PRIu64 " of %" PRIu64
+              " bytes were read from memory at 0x%" PRIx64,
+              (uint64_t)bytes_read, (uint64_t)dst_len, load_addr);
       }
     }
+    if (bytes_read) {
+      if (load_addr_ptr)
+        *load_addr_ptr = load_addr;
+      return bytes_read;
+    }
   }
 
   if (file_cache_read_buffer && file_cache_bytes_read > 0) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D114675.390200.patch
Type: text/x-patch
Size: 2351 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20211128/4b328967/attachment.bin>


More information about the lldb-commits mailing list