================
@@ -906,6 +907,35 @@ size_t SBProcess::ReadMemory(addr_t addr, void *dst, 
size_t dst_len,
   return bytes_read;
 }
 
+size_t SBProcess::ReadMemoryFromSpec(SBAddressSpec addr_spec, void *dst,
+                                     size_t dst_len, SBError &sb_error) {
+  LLDB_INSTRUMENT_VA(this, addr_spec, dst, dst_len, sb_error);
+
+  if (!dst) {
+    sb_error = Status::FromErrorStringWithFormat(
+        "no buffer provided to read %zu bytes into", dst_len);
+    return 0;
+  }
+
+  size_t bytes_read = 0;
+  ProcessSP process_sp(GetSP());
+  if (process_sp) {
+    Process::StopLocker stop_locker;
+    if (stop_locker.TryLock(&process_sp->GetRunLock())) {
+      std::lock_guard<std::recursive_mutex> guard(
+          process_sp->GetTarget().GetAPIMutex());
+      bytes_read =
+          process_sp->ReadMemory(addr_spec.ref(), dst, dst_len, 
sb_error.ref());
+    } else {
+      sb_error = Status::FromErrorString("process is running");
+    }
+  } else {
+    sb_error = Status::FromErrorString("SBProcess is invalid");
+  }
+
+  return bytes_read;
----------------
Teemperor wrote:

I think there is plenty of opportunities for early-exiting in this code.

https://github.com/llvm/llvm-project/pull/206370
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to