@@ -1211,41 +1211,19 @@ static inline void run_remote_debugger_script(const char *path)
12111211 return ;
12121212 }
12131213
1214- int fd = PyObject_AsFileDescriptor (fileobj );
1215- if (fd == -1 ) {
1216- PyErr_FormatUnraisable ("Can't find fd for debugger script %s" , path );
1217- }
1218- else {
1219- int dup_fd = -1 ;
1220- FILE * f = NULL ;
1221-
1222- #ifdef MS_WINDOWS
1223- dup_fd = _dup (fd );
1224- if (dup_fd != -1 ) {
1225- f = _fdopen (dup_fd , "r" );
1226- }
1227- if (!f ) {
1228- _close (dup_fd );
1229- }
1230- #else
1231- dup_fd = dup (fd );
1232- if (dup_fd != -1 ) {
1233- f = fdopen (dup_fd , "r" );
1234- }
1235- if (!f ) {
1236- close (dup_fd );
1237- }
1238- #endif
1239- if (!f ) {
1240- PyErr_SetFromErrno (PyExc_OSError );
1241- }
1242- else {
1243- PyRun_AnyFileEx (f , path , 1 );
1244- }
1245-
1246- if (PyErr_Occurred ()) {
1247- PyErr_FormatUnraisable ("Error executing debugger script %s" , path );
1214+ PyObject * source = PyObject_CallMethod (fileobj , "read" , NULL );
1215+ if (!source ) {
1216+ PyErr_FormatUnraisable ("Error reading debugger script %s" , path );
1217+ } else {
1218+ if (PyBytes_Check (source )) {
1219+ const char * str = PyBytes_AsString (source );
1220+ if (str ) {
1221+ PyRun_SimpleString (str );
1222+ } else {
1223+ PyErr_FormatUnraisable ("Error reading debugger script %s" , path );
1224+ }
12481225 }
1226+ Py_DECREF (source );
12491227 }
12501228
12511229 PyObject * res = PyObject_CallMethodNoArgs (fileobj , & _Py_ID (close ));
@@ -1255,6 +1233,12 @@ static inline void run_remote_debugger_script(const char *path)
12551233 Py_DECREF (res );
12561234 }
12571235 Py_DECREF (fileobj );
1236+
1237+
1238+ if (PyErr_Occurred ()) {
1239+ PyErr_FormatUnraisable ("Error executing debugger script %s" , path );
1240+ }
1241+
12581242}
12591243#endif
12601244
0 commit comments