================
@@ -1158,6 +1159,88 @@ 
GDBRemoteCommunicationClient::GetProcessStandaloneBinaries() {
   return m_binary_addresses;
 }
 
+std::vector<AddressSpaceInfo> GDBRemoteCommunicationClient::GetAddressSpaces() 
{
+  // The server replies with the unsupported response when it has no address
+  // spaces, so cache that to avoid re-sending the packet on every call.
+  if (m_supports_address_spaces == eLazyBoolNo)
+    return {};
+
+  StringExtractorGDBRemote response;
+  response.SetResponseValidatorToJSON();
+  if (SendPacketAndWaitForResponse("jAddressSpacesInfo", response) !=
+      PacketResult::Success)
+    return {};
+
+  if (response.IsUnsupportedResponse() || response.IsErrorResponse()) {
+    m_supports_address_spaces = eLazyBoolNo;
+    return {};
+  }
+  m_supports_address_spaces = eLazyBoolYes;
+
+  llvm::Expected<std::vector<AddressSpaceInfo>> info =
+      llvm::json::parse<std::vector<AddressSpaceInfo>>(response.Peek(),
+                                                       "AddressSpaceInfo");
+  if (info)
+    return std::move(*info);
+
+  // A bare JSON parse error is meaningless on its own, so log both the full
+  // response and the parse error rather than surfacing it to the user.
+  Log *log = GetLog(GDBRLog::Process);
+  LLDB_LOG_ERROR(log, info.takeError(),
+                 "malformed jAddressSpacesInfo response '{1}': {0}",
+                 response.GetStringRef());
+  return {};
+}
+
+size_t GDBRemoteCommunicationClient::ReadMemory(ProcessGDBRemote *process,
+                                                const AddressSpec &addr_spec,
+                                                const AddressSpaceInfo &info,
+                                                void *buf, size_t size,
+                                                Status &error) {
+  // Make sure this packet is supported.
+  if (m_supports_address_spaces == eLazyBoolNo) {
+    error = Status::FromErrorString("address spaces are not supported");
+    return 0;
+  }
+  StreamString packet;
+  packet.PutCString("qMemRead:");
+  packet.PutCString("addr:");
+  packet.PutHex64(addr_spec.GetValue());
+  packet.PutChar(';');
+  packet.PutCString("space:");
+  packet.PutHex64(info.value);
+  packet.PutChar(';');
+  packet.PutCString("length:");
+  packet.PutHex64(size);
+  packet.PutChar(';');
+  if (info.is_thread_specific) {
+    if (llvm::Expected<lldb::ThreadSP> thread = addr_spec.GetThread()) {
+      packet.PutCString("tid:");
+      packet.PutHex64((*thread)->GetID());
+      packet.PutChar(';');
+    } else {
+      error = Status::FromError(thread.takeError());
+    }
+  }
+
+  StringExtractorGDBRemote response;
+  if (SendPacketAndWaitForResponse(packet.GetString(), response) ==
----------------
Teemperor wrote:

More early-exit potential here.

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