Skip to content

Commit 1f85351

Browse files
committed
[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.
1 parent 34b10e1 commit 1f85351

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,22 +3064,41 @@ static int gdb_errno_to_system(int err) {
30643064

30653065
static uint64_t ParseHostIOPacketResponse(StringExtractorGDBRemote &response,
30663066
uint64_t fail_result, Status &error) {
3067+
// The packet is expected to have the following format:
3068+
// 'F<retcode>,<errno>'
3069+
30673070
response.SetFilePos(0);
30683071
if (response.GetChar() != 'F')
30693072
return fail_result;
3073+
30703074
int32_t result = response.GetS32(-2, 16);
30713075
if (result == -2)
30723076
return fail_result;
3073-
if (response.GetChar() == ',') {
3074-
int result_errno = gdb_errno_to_system(response.GetS32(-1, 16));
3075-
if (result_errno != -1)
3076-
error = Status(result_errno, eErrorTypePOSIX);
3077-
else
3078-
error = Status(-1, eErrorTypeGeneric);
3079-
} else
3077+
3078+
if (response.GetChar() != ',') {
30803079
error.Clear();
3080+
return result;
3081+
}
3082+
3083+
// Response packet should contain a error code at the end. This code
3084+
// corresponds either to the gdb IOFile error code, or to the posix errno.
3085+
int32_t result_errno = response.GetS32(-1, 16);
3086+
if (result_errno == -1) {
3087+
error.SetError(-1, eErrorTypeGeneric);
3088+
return result;
3089+
}
3090+
3091+
int rsp_errno = gdb_errno_to_system(result_errno);
3092+
if (rsp_errno != -1) {
3093+
error.SetError(rsp_errno, eErrorTypePOSIX);
3094+
return result;
3095+
}
3096+
3097+
// Have received a system error that isn't described in gdb rsp protocol
3098+
error.SetError(result_errno, eErrorTypePOSIX);
30813099
return result;
30823100
}
3101+
30833102
lldb::user_id_t
30843103
GDBRemoteCommunicationClient::OpenFile(const lldb_private::FileSpec &file_spec,
30853104
File::OpenOptions flags, mode_t mode,

0 commit comments

Comments
 (0)