From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22762 invoked by alias); 26 May 2010 07:49:00 -0000 Received: (qmail 22754 invoked by uid 22791); 26 May 2010 07:48:59 -0000 X-SWARE-Spam-Status: No, hits=-0.0 required=5.0 tests=AWL,BAYES_50,MSGID_MULTIPLE_AT,TW_CG X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.155) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 26 May 2010 07:48:54 +0000 Received: from baal.u-strasbg.fr (baal.u-strasbg.fr [IPv6:2001:660:2402::41]) by mailhost.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o4Q7mofM048831 for ; Wed, 26 May 2010 09:48:51 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from mailserver.u-strasbg.fr (ms1.u-strasbg.fr [IPv6:2001:660:2402:d::10]) by baal.u-strasbg.fr (8.14.0/jtpda-5.5pre1) with ESMTP id o4Q7moKb020737 for ; Wed, 26 May 2010 09:48:50 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from d620muller (gw-ics.u-strasbg.fr [130.79.210.225]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o4Q7moO9003045 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Wed, 26 May 2010 09:48:50 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: References: <001901caf934$fd580460$f8080d20$@muller@ics-cnrs.unistra.fr> <20100525205241.GA5298@ednor.casa.cgf.cx> In-Reply-To: <20100525205241.GA5298@ednor.casa.cgf.cx> Subject: RE: [RFA] windows-nat.c: Copy console information for new console Date: Wed, 26 May 2010 08:07:00 -0000 Message-ID: <000601cafca7$ead3af80$c07b0e80$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-05/txt/msg00591.txt.bz2 > -----Message d'origine----- De=A0: gdb-patches-owner@sourceware.org [mailto:gdb-patches- > owner@sourceware.org] De la part de Christopher Faylor > I don't mind the concept but this function is becoming pretty big so I > would appreciate it if you would move all of the logic into a function. > Maybe call it "set_console_info()" and pass it &flags, &si. >=20 > cgf You are right, this is cleaner, nevertheless flags isn't used much, thus I moved the code into a new function called windows_set_console_info, with a unique parameter &si. How does that look like now? Pierre 2010-05-26 Pierre Muller * windows-nat.c (GetConsoleFontSize, GetCurrentConsoleFont): New macros. (windows_set_console_info): New function. (windows_create_inferior): Call windows_set_console_info if NEW_CONSOLE is true. (bad_GetCurrentConsoleFont, bad_GetConsoleFontSize): New functions. (_initialize_loadable): Initialize GetConsoleFontSize and GetCurrentConsoleFont. Index: windows-nat.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.209 diff -u -p -r1.209 windows-nat.c --- windows-nat.c 25 May 2010 07:38:18 -0000 1.209 +++ windows-nat.c 26 May 2010 07:43:22 -0000 @@ -75,6 +75,8 @@ #define GetModuleInformation dyn_GetModuleInformation #define LookupPrivilegeValueA dyn_LookupPrivilegeValueA #define OpenProcessToken dyn_OpenProcessToken +#define GetConsoleFontSize dyn_GetConsoleFontSize +#define GetCurrentConsoleFont dyn_GetCurrentConsoleFont =20 static BOOL WINAPI (*AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); @@ -87,6 +89,8 @@ static BOOL WINAPI (*GetModuleInformatio DWORD); static BOOL WINAPI (*LookupPrivilegeValueA)(LPCSTR, LPCSTR, PLUID); static BOOL WINAPI (*OpenProcessToken)(HANDLE, DWORD, PHANDLE); +static BOOL WINAPI (*GetCurrentConsoleFont) (HANDLE, BOOL, CONSOLE_FONT_INFO *); +static COORD WINAPI (*GetConsoleFontSize) (HANDLE, DWORD); =20 static struct target_ops windows_ops; =20 @@ -1895,6 +1899,43 @@ windows_open (char *arg, int from_tty) error (_("Use the \"run\" command to start a Unix child process.")); } =20 +/* If we are on a console, try to copy the parameters of that console + to create the new console. + The size of the used font is not available on all versions of + Windows OS. Furthermore, the current font might not be the default + font, but this is still better than before. */ + +static void +windows_set_console_info (STARTUPINFO *si) +{ + HANDLE hconsole =3D CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); + + if (hconsole !=3D INVALID_HANDLE_VALUE) + { + CONSOLE_SCREEN_BUFFER_INFO sbinfo; + COORD font_size; + CONSOLE_FONT_INFO cfi; + + GetCurrentConsoleFont (hconsole, FALSE, &cfi); + font_size =3D GetConsoleFontSize (hconsole, cfi.nFont); + GetConsoleScreenBufferInfo(hconsole, &sbinfo); + si->dwXSize =3D sbinfo.srWindow.Right - sbinfo.srWindow.Left + 1; + si->dwYSize =3D sbinfo.srWindow.Bottom - sbinfo.srWindow.Top + 1; + if (font_size.X) + si->dwXSize *=3D font_size.X; + else + si->dwXSize *=3D 8; + if (font_size.Y) + si->dwYSize *=3D font_size.Y; + else + si->dwYSize *=3D 12; + si->dwXCountChars =3D sbinfo.dwSize.X; + si->dwYCountChars =3D sbinfo.dwSize.Y; + si->dwFlags |=3D STARTF_USESIZE | STARTF_USECOUNTCHARS; + } +} + /* Start an inferior windows child process and sets inferior_ptid to its pid. EXEC_FILE is the file to run. ALLARGS is a string containing the arguments to the program. @@ -1937,7 +1978,10 @@ windows_create_inferior (struct target_o flags |=3D CREATE_NEW_PROCESS_GROUP; =20 if (new_console) - flags |=3D CREATE_NEW_CONSOLE; + { + windows_set_console_info (&si); + flags |=3D CREATE_NEW_CONSOLE; + } =20 #ifdef __CYGWIN__ if (!useshell) @@ -2574,6 +2618,21 @@ bad_OpenProcessToken (HANDLE w, DWORD x, return FALSE; } =20 +static BOOL WINAPI +bad_GetCurrentConsoleFont (HANDLE w, BOOL bMaxWindow, CONSOLE_FONT_INFO *f) +{ + f->nFont =3D 0; + return 1; +} +static COORD WINAPI +bad_GetConsoleFontSize (HANDLE w, DWORD nFont) +{ + COORD size; + size.X =3D 8; + size.Y =3D 12; + return size; +} +=20 /* Load any functions which may not be available in ancient versions of Windows. */ void @@ -2590,6 +2649,10 @@ _initialize_loadable (void) GetProcAddress (hm, "DebugBreakProcess"); DebugSetProcessKillOnExit =3D (void *) GetProcAddress (hm, "DebugSetProcessKillOnExit"); + GetConsoleFontSize =3D (void *)=20 + GetProcAddress (hm, "GetConsoleFontSize"); + GetCurrentConsoleFont =3D (void *)=20 + GetProcAddress (hm, "GetCurrentConsoleFont"); } =20 /* Set variables to dummy versions of these processes if the function @@ -2601,6 +2664,10 @@ _initialize_loadable (void) DebugActiveProcessStop =3D bad_DebugActiveProcessStop; DebugSetProcessKillOnExit =3D bad_DebugSetProcessKillOnExit; } + if (!GetConsoleFontSize) + GetConsoleFontSize =3D bad_GetConsoleFontSize; + if (!GetCurrentConsoleFont) + GetCurrentConsoleFont =3D bad_GetCurrentConsoleFont; =20 /* Load optional functions used for retrieving filename information associated with the currently debugged process or its dlls. */