Date: Tue, 19 Nov 1996 16:06:36 +0200 (IST) From: Eli Zaretskii To: djgpp-workers AT delorie DOT com Subject: GDB hangs when you quit before program exits Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII GDB 4.16 will hang after asking whether you want to kill the debuggee, if the debuggee has switched stdin to binary mode (like e.g. Emacs and Less do). Patches below; I've submitted them to FSF as well. *** gdb/top.c~0 Sat Apr 13 11:51:42 1996 --- gdb/top.c Tue Nov 19 14:22:06 1996 *************** *** 1322,1327 **** --- 1322,1335 ---- int input_index = 0; int result_size = 80; + #ifdef __DJGPP__ + /* On MSDOS, the debugger and the debuggee share file handles. + If the debuggee switches its stdin to binary mode, the same + happens to the debugger's stdin, and fgetc below loses. We + need therefore to switch stdin to TEXT mode. */ + int saved_mode = setmode (fileno (stdin), O_TEXT); + #endif + if (prrompt) { /* Don't use a _filtered function here. It causes the assumed *************** *** 1352,1357 **** --- 1360,1369 ---- we'll return NULL then. */ break; free (result); + #ifdef __DJGPP__ + /* Restore the handle mode. */ + setmode (fileno (stdin), saved_mode); + #endif return NULL; } *************** *** 1367,1372 **** --- 1379,1388 ---- } result[input_index++] = '\0'; + #ifdef __DJGPP__ + /* Restore the handle mode. */ + setmode (fileno (stdin), saved_mode); + #endif return result; } *** gdb/utils.c~0 Tue Apr 23 11:35:12 1996 --- gdb/utils.c Tue Nov 19 14:35:30 1996 *************** *** 23,28 **** --- 23,31 ---- #include #include #endif + #ifdef __DJGPP__ + #include + #endif #ifdef ANSI_PROTOTYPES #include #else *************** *** 901,906 **** --- 904,913 ---- register int ans2; int retval; + #ifdef __DJGPP__ + int saved_mode; + #endif + #ifdef ANSI_PROTOTYPES va_start (args, ctlstr); #else *************** *** 923,928 **** --- 930,943 ---- return 1; #endif /* MPW */ + #ifdef __DJGPP__ + /* On MSDOS, the debugger and the debuggee share file handles. + If the debuggee switches its stdin to binary mode, the same + happens to the debugger's stdin, and fgetc below loses. We + need therefore to make sure stdin is in TEXT mode. */ + saved_mode = setmode (fileno (stdin), O_TEXT); + #endif + while (1) { wrap_here (""); /* Flush any buffered output */ *************** *** 976,981 **** --- 991,1000 ---- if (annotation_level > 1) printf_filtered ("\n\032\032post-query\n"); + #ifdef __DJGPP__ + /* Restore the handle mode. */ + setmode (fileno (stdin), saved_mode); + #endif return retval; }