This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA] Avoid infinite height for mingw GDB


>   The mingw32 GDB debugger starts always with height set to infinite.

I just wanted to confirm: This is when starging GDB in a Windows CMD
window, right? There are other modes for GDB, for instance when started
inside a cygwin "terminal", or through cygwin ssh. In that case, cygwin
sets stdin/stdout as pipes, rather than pseudo ttys...

> 2012-10-17  Pierre Muller  <muller@ics.u-strasbg.fr>
> 
>         * windows-termcap.c (tgetent): Handle "li" and "co"
>         parameter.

Thinko: tgetent -> tgetnum :).

Some thoughts about the idea behind the patch:

The problem with using rl_get_screen_size is that it does not really
allow us to return a failure condition if unable to determine the
screen size: rl_get_screen_size tries in that order:
  - the Windows API
  - the "COLUMNS"/"LINES" environment variable
  - tgetnum (hence the need for your guard)
And if all of them fail, then it defaults to 80x24.

A priori, I don't see anything that would break because of this.
But I am not sure if this is the best thing to be doing. The Windows
API seems to be straightforward, and I am wondering whether it might
be just safer to use that in our tgetnum emulation. I know it's code
duplication, and perhaps we could reuse the code in readline if
_win_get_screensize was made non-static. But it really looks like
re-use wouldn't bring us much in this case. If you simplify it a bit,
it's a case of:

    hConOut = GetStdHandle (STD_OUTPUT_HANDLE);
    GetConsoleScreenBufferInfo (hConOut, &scr)


> 
> Index: src/gdb/windows-termcap.c
> ===================================================================
> RCS file: /cvs/src/src/gdb/windows-termcap.c,v
> retrieving revision 1.11
> diff -u -p -r1.11 windows-termcap.c
> --- src/gdb/windows-termcap.c   2 Mar 2012 12:56:50 -0000       1.11
> +++ src/gdb/windows-termcap.c   16 Oct 2012 22:58:35 -0000
> @@ -20,6 +20,9 @@
>     along with this program.  If not, see <http://www.gnu.org/licenses/>.
> */
> 
>  #include <stdlib.h>
> +#include <strings.h>
> +#include "defs.h"
> +#include "readline/readline.h"
> 
>  /* -Wmissing-prototypes */
>  extern int tgetent (char *buffer, char *termtype);
> @@ -42,6 +45,26 @@ tgetent (char *buffer, char *termtype)
>  int
>  tgetnum (char *name)
>  {
> +  static int tgetnum_level = 0;
> +  tgetnum_level++;
> +  /* Avoid resetting of height to unlimited in init_page_info function.  */
> +  if (((strcmp (name, "li") == 0) || (strcmp (name, "co") == 0))
> +      && (tgetnum_level == 1))
> +    {
> +      int cols, lines;
> +      /* This only works because __MINGW32__ specific code does not call
> +         tgetnum function within rl_get_screen_size, if the current
> +        output is a valid Windows console.
> +         The values of COLS and LINES are set earlier inside that function
> +         by a call to Windows API function GetConsoleScreenBufferInfo.  */
> +      rl_get_screen_size (&cols, &lines);
> +      tgetnum_level--;
> +      if (strcmp (name, "li") == 0)
> +       return lines;
> +      else
> +       return cols;
> +    }
> +  tgetnum_level--;
>    return -1;
>  }

-- 
Joel


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]