[Lldb-commits] [lldb] 39a2449 - [lldb] [Commands] Fix reporting errors in 'platform file read/write'
Michał Górny via lldb-commits
lldb-commits at lists.llvm.org
Wed Sep 8 02:01:44 PDT 2021
Author: Michał Górny
Date: 2021-09-08T10:58:12+02:00
New Revision: 39a2449ea1333886a9c9104b5afb4ff9c4932403
URL: https://github.com/llvm/llvm-project/commit/39a2449ea1333886a9c9104b5afb4ff9c4932403
DIFF: https://github.com/llvm/llvm-project/commit/39a2449ea1333886a9c9104b5afb4ff9c4932403.diff
LOG: [lldb] [Commands] Fix reporting errors in 'platform file read/write'
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.
Differential Revision: https://reviews.llvm.org/D107665
Added:
Modified:
lldb/source/Commands/CommandObjectPlatform.cpp
lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
Removed:
################################################################################
diff --git a/lldb/source/Commands/CommandObjectPlatform.cpp b/lldb/source/Commands/CommandObjectPlatform.cpp
index 68e1fa6c07b44..8dd0512141645 100644
--- a/lldb/source/Commands/CommandObjectPlatform.cpp
+++ b/lldb/source/Commands/CommandObjectPlatform.cpp
@@ -589,11 +589,15 @@ class CommandObjectPlatformFRead : public CommandObjectParsed {
}
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 != UINT64_MAX) {
+ result.AppendMessageWithFormat("Return = %" PRIu64 "\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");
}
@@ -678,11 +682,15 @@ class CommandObjectPlatformFWrite : public CommandObjectParsed {
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 != UINT64_MAX) {
+ result.AppendMessageWithFormat("Return = %" PRIu64 "\n", retcode);
+ result.SetStatus(eReturnStatusSuccessFinishResult);
+ } else {
+ result.AppendError(error.AsCString());
+ }
} else {
result.AppendError("no platform currently selected\n");
}
diff --git a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
index 264e11032ecaf..4ba23870e4a0e 100644
--- a/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
+++ b/lldb/test/API/functionalities/gdb_remote_client/TestGDBRemotePlatformFile.py
@@ -60,11 +60,12 @@ def vFile(self, packet):
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)
More information about the lldb-commits
mailing list