www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/04/11/04:57:48

Date: Thu, 11 Apr 1996 11:53:19 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: djgpp AT delorie DOT com
Subject: GDB patch
Message-Id: <Pine.SUN.3.91.960411114854.27524S-100000@is>
Mime-Version: 1.0

Ever used GDB to debug a program that switches its stdin to binary?  Ever
tried to print a backtrace or disassemble a function, or do something else
that causes GDB to print more than a screenful of info?  If so, then you 
prbably know that the only thing that will help you after that is 
Ctrl-Alt-Del, right?

Well, help is on its way.  Apply the patch below to GDB sources, and life 
begins again!

*** gdb/main.c~0	Wed Jul 27 08:48:54 1994
--- gdb/main.c	Mon Apr  8 17:44:10 1996
*************** gdb_readline (prrompt)
*** 1140,1146 ****
--- 1140,1163 ----
      {
        /* Read from stdin if we are executing a user defined command.
  	 This is the right thing for prompt_for_continue, at least.  */
+ 
+ #ifdef __DJGPP__
+ 
+       /* Under DJGPP, setting stdin to binary (in the debuggee) also
+          affects the debugger, in particular it breaks single-character
+          reads with `fgetc'.  We must momentarily switch stdin to text
+          mode and back for `fgetc' to work.  */
+ 
+       int current_mode = (instream && instream != stdin)
+                            ? -1
+                              : setmode (fileno (stdin), O_TEXT);
        c = fgetc (instream ? instream : stdin);
+       if (current_mode == O_BINARY)
+         setmode (fileno (stdin), O_BINARY);
+ 
+ #else
+       c = fgetc (instream ? instream : stdin);
+ #endif
  
        if (c == EOF)
  	{
*** gdb/utils.c~0	Fri Jun 23 07:53:16 1995
--- gdb/utils.c	Mon Apr  8 17:51:22 1996
*************** print_spaces (n, file)
*** 775,780 ****
--- 775,784 ----
     The first, a control string, should end in "? ".
     It should not say how to answer, because we do that.  */
  
+ #ifdef __DJGPP__
+ #include <fcntl.h>
+ #endif
+ 
  /* VARARGS */
  int
  query (va_alist)
*************** query (va_alist)
*** 785,790 ****
--- 789,807 ----
    register int answer;
    register int ans2;
  
+ #ifdef __DJGPP__
+ 
+   /* Under DJGPP, setting stdin to binary (in the debuggee) also
+      affects the debugger, in particular it breaks single-character
+      reads with `fgetc'.  We must momentarily switch stdin to text
+      mode and back for `fgetc' to work.  */
+ 
+   int current_mode = input_from_terminal_p () ?
+                      setmode (fileno (stdin), O_TEXT) :
+                        -1;
+ 
+ #endif
+ 
    /* Automatically answer "yes" if input is not from a terminal.  */
    if (!input_from_terminal_p ())
      return 1;
*************** query (va_alist)
*** 801,806 ****
--- 818,828 ----
        gdb_flush (gdb_stdout);
        answer = fgetc (stdin);
        clearerr (stdin);		/* in case of C-d */
+ #ifdef __DJGPP__
+       if (answer == EOF)
+         if (current_mode == O_BINARY)
+           setmode (fileno (stdin), O_BINARY);
+ #endif
        if (answer == EOF)	/* C-d */
          return 1;
        if (answer != '\n')	/* Eat rest of input line, to EOF or newline */
*************** query (va_alist)
*** 812,817 ****
--- 834,844 ----
          while (ans2 != EOF && ans2 != '\n');
        if (answer >= 'a')
  	answer -= 040;
+ #ifdef __DJGPP__
+       if (answer == 'Y' || answer == 'N')
+         if (current_mode == O_BINARY)
+           setmode (fileno (stdin), O_BINARY);
+ #endif
        if (answer == 'Y')
  	return 1;
        if (answer == 'N')

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019