@@ -3064,22 +3064,41 @@ static int gdb_errno_to_system(int err) {
3064
3064
3065
3065
static uint64_t ParseHostIOPacketResponse (StringExtractorGDBRemote &response,
3066
3066
uint64_t fail_result, Status &error) {
3067
+ // The packet is expected to have the following format:
3068
+ // 'F<retcode>,<errno>'
3069
+
3067
3070
response.SetFilePos (0 );
3068
3071
if (response.GetChar () != ' F' )
3069
3072
return fail_result;
3073
+
3070
3074
int32_t result = response.GetS32 (-2 , 16 );
3071
3075
if (result == -2 )
3072
3076
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 () != ' ,' ) {
3080
3079
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);
3081
3099
return result;
3082
3100
}
3101
+
3083
3102
lldb::user_id_t
3084
3103
GDBRemoteCommunicationClient::OpenFile (const lldb_private::FileSpec &file_spec,
3085
3104
File::OpenOptions flags, mode_t mode,
0 commit comments