mgorny created this revision.
mgorny added reviewers: labath, emaste, krytarowski, jasonmolenda, clayborg, 
JDevlieghere.
mgorny requested review of this revision.

Fix 'platform file read' and 'platform file write' commands to correctly
detect erraneous return and report it as such.  Currently, errors were
implicitly printed as a return value of -1, and the commands were
assumed to be successful.


https://reviews.llvm.org/D107665

Files:
  lldb/source/Commands/CommandObjectPlatform.cpp
  lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py


Index: 
lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
@@ -60,11 +60,12 @@
             self.match("platform file open /some/file.txt -v 0755",
                        [r"error: Invalid argument"],
                        error=True)
-            # TODO: fix the commands to fail on unsuccessful result
             self.match("platform file read 16 -o 11 -c 13",
-                       [r"Return = -1\nData = \"\""])
+                       [r"error: Invalid argument"],
+                       error=True)
             self.match("platform file write 16 -o 11 -d teststring",
-                       [r"Return = -1"])
+                       [r"error: Invalid argument"],
+                       error=True)
             self.match("platform file close 16",
                        [r"error: Invalid argument"],
                        error=True)
Index: lldb/source/Commands/CommandObjectPlatform.cpp
===================================================================
--- lldb/source/Commands/CommandObjectPlatform.cpp
+++ lldb/source/Commands/CommandObjectPlatform.cpp
@@ -588,11 +588,15 @@
       }
       std::string buffer(m_options.m_count, 0);
       Status error;
-      uint32_t retcode = platform_sp->ReadFile(
+      uint64_t retcode = platform_sp->ReadFile(
           fd, m_options.m_offset, &buffer[0], m_options.m_count, error);
-      result.AppendMessageWithFormat("Return = %d\n", retcode);
-      result.AppendMessageWithFormat("Data = \"%s\"\n", buffer.c_str());
-      result.SetStatus(eReturnStatusSuccessFinishResult);
+      if (retcode != -1) {
+        result.AppendMessageWithFormat("Return = %d\n", retcode);
+        result.AppendMessageWithFormat("Data = \"%s\"\n", buffer.c_str());
+        result.SetStatus(eReturnStatusSuccessFinishResult);
+      } else {
+        result.AppendError(error.AsCString());
+      }
     } else {
       result.AppendError("no platform currently selected\n");
     }
@@ -677,11 +681,15 @@
                                       cmd_line);
         return result.Succeeded();
       }
-      uint32_t retcode =
+      uint64_t retcode =
           platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0],
                                  m_options.m_data.size(), error);
-      result.AppendMessageWithFormat("Return = %d\n", retcode);
-      result.SetStatus(eReturnStatusSuccessFinishResult);
+      if (retcode != -1) {
+        result.AppendMessageWithFormat("Return = %d\n", retcode);
+        result.SetStatus(eReturnStatusSuccessFinishResult);
+      } else {
+        result.AppendError(error.AsCString());
+      }
     } else {
       result.AppendError("no platform currently selected\n");
     }


Index: lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
===================================================================
--- lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
+++ lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
@@ -60,11 +60,12 @@
             self.match("platform file open /some/file.txt -v 0755",
                        [r"error: Invalid argument"],
                        error=True)
-            # TODO: fix the commands to fail on unsuccessful result
             self.match("platform file read 16 -o 11 -c 13",
-                       [r"Return = -1\nData = \"\""])
+                       [r"error: Invalid argument"],
+                       error=True)
             self.match("platform file write 16 -o 11 -d teststring",
-                       [r"Return = -1"])
+                       [r"error: Invalid argument"],
+                       error=True)
             self.match("platform file close 16",
                        [r"error: Invalid argument"],
                        error=True)
Index: lldb/source/Commands/CommandObjectPlatform.cpp
===================================================================
--- lldb/source/Commands/CommandObjectPlatform.cpp
+++ lldb/source/Commands/CommandObjectPlatform.cpp
@@ -588,11 +588,15 @@
       }
       std::string buffer(m_options.m_count, 0);
       Status error;
-      uint32_t retcode = platform_sp->ReadFile(
+      uint64_t retcode = platform_sp->ReadFile(
           fd, m_options.m_offset, &buffer[0], m_options.m_count, error);
-      result.AppendMessageWithFormat("Return = %d\n", retcode);
-      result.AppendMessageWithFormat("Data = \"%s\"\n", buffer.c_str());
-      result.SetStatus(eReturnStatusSuccessFinishResult);
+      if (retcode != -1) {
+        result.AppendMessageWithFormat("Return = %d\n", retcode);
+        result.AppendMessageWithFormat("Data = \"%s\"\n", buffer.c_str());
+        result.SetStatus(eReturnStatusSuccessFinishResult);
+      } else {
+        result.AppendError(error.AsCString());
+      }
     } else {
       result.AppendError("no platform currently selected\n");
     }
@@ -677,11 +681,15 @@
                                       cmd_line);
         return result.Succeeded();
       }
-      uint32_t retcode =
+      uint64_t retcode =
           platform_sp->WriteFile(fd, m_options.m_offset, &m_options.m_data[0],
                                  m_options.m_data.size(), error);
-      result.AppendMessageWithFormat("Return = %d\n", retcode);
-      result.SetStatus(eReturnStatusSuccessFinishResult);
+      if (retcode != -1) {
+        result.AppendMessageWithFormat("Return = %d\n", retcode);
+        result.SetStatus(eReturnStatusSuccessFinishResult);
+      } else {
+        result.AppendError(error.AsCString());
+      }
     } else {
       result.AppendError("no platform currently selected\n");
     }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to