[Lldb-commits] [lldb] [lldb] gdb rsp file error pass fix (PR #106950)

via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 2 01:37:50 PDT 2024


https://github.com/dlav-sc created https://github.com/llvm/llvm-project/pull/106950

This patch fixes a error code parsing of gdb remote protocol response messages to File-I/O command.

>From 1f853519a648c2ebe3b2b26f9d51cacd2820be87 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev <daniil.avdeev at syntacore.com>
Date: Tue, 23 Jul 2024 11:04:12 +0000
Subject: [PATCH] [lldb] gdb rsp file error pass fix

This patch fixes a error code parsing of gdb remote protocol response
messages to File-I/O command.
---
 .../GDBRemoteCommunicationClient.cpp          | 33 +++++++++++++++----
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
index 0297fe363f69e1..bce50eb4f8a907 100644
--- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
@@ -3064,22 +3064,41 @@ static int gdb_errno_to_system(int err) {
 
 static uint64_t ParseHostIOPacketResponse(StringExtractorGDBRemote &response,
                                           uint64_t fail_result, Status &error) {
+  // The packet is expected to have the following format:
+  // 'F<retcode>,<errno>'
+
   response.SetFilePos(0);
   if (response.GetChar() != 'F')
     return fail_result;
+
   int32_t result = response.GetS32(-2, 16);
   if (result == -2)
     return fail_result;
-  if (response.GetChar() == ',') {
-    int result_errno = gdb_errno_to_system(response.GetS32(-1, 16));
-    if (result_errno != -1)
-      error = Status(result_errno, eErrorTypePOSIX);
-    else
-      error = Status(-1, eErrorTypeGeneric);
-  } else
+
+  if (response.GetChar() != ',') {
     error.Clear();
+    return result;
+  }
+
+  // Response packet should contain a error code at the end. This code
+  // corresponds either to the gdb IOFile error code, or to the posix errno.
+  int32_t result_errno = response.GetS32(-1, 16);
+  if (result_errno == -1) {
+    error.SetError(-1, eErrorTypeGeneric);
+    return result;
+  }
+
+  int rsp_errno = gdb_errno_to_system(result_errno);
+  if (rsp_errno != -1) {
+    error.SetError(rsp_errno, eErrorTypePOSIX);
+    return result;
+  }
+
+  // Have received a system error that isn't described in gdb rsp protocol
+  error.SetError(result_errno, eErrorTypePOSIX);
   return result;
 }
+
 lldb::user_id_t
 GDBRemoteCommunicationClient::OpenFile(const lldb_private::FileSpec &file_spec,
                                        File::OpenOptions flags, mode_t mode,



More information about the lldb-commits mailing list