From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30608 invoked by alias); 21 May 2010 22:28:52 -0000 Received: (qmail 30600 invoked by uid 22791); 21 May 2010 22:28:51 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL,BAYES_00,MSGID_MULTIPLE_AT X-Spam-Check-By: sourceware.org Received: from mailhost.u-strasbg.fr (HELO mailhost.u-strasbg.fr) (130.79.200.154) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 21 May 2010 22:28:46 +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 o4LMSh3k086161 for ; Sat, 22 May 2010 00:28:44 +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 o4LMShsJ024803 for ; Sat, 22 May 2010 00:28:43 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) Received: from d620muller (lec67-4-82-230-53-140.fbx.proxad.net [82.230.53.140]) (user=mullerp mech=LOGIN) by mailserver.u-strasbg.fr (8.14.3/jtpda-5.5pre1) with ESMTP id o4LMShdW013463 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO) for ; Sat, 22 May 2010 00:28:43 +0200 (CEST) (envelope-from pierre.muller@ics-cnrs.unistra.fr) From: "Pierre Muller" To: Subject: [RFA] windows-nat.c: Copy console information for new console Date: Fri, 21 May 2010 22:37:00 -0000 Message-ID: <001901caf934$fd580460$f8080d20$@muller@ics-cnrs.unistra.fr> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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/msg00521.txt.bz2 Using (gdb) set new-console on on Windows native is nice for some features but is also terribly annoying sometimes. Especially on nice big displays, because the newly created console is 25 lines times 80 columns by default which is really not much when you usually work on 60 or more lines. This patch copies the values of the current console (if it exists) and uses the same parameters to start the new-console. I copied both the window and the buffer size (having a long buffer allows to see history of output...). I did, on purpose not set the same position for the new console, which results in a usual shift to the left and down avoid a complete overlap of the windows. This make using new-console much easier to use. A possible extension would be to be able to specify these parameters with something like (gdb) set w32 console lines 45 There is apparently no way to specify the font. This might lead to windows size that are not optimal for the buffer size used, and it is calculated on the current console font which might not be the default font. But I don't know how to find out what the default font is. I tested this patch on Windows XP and on Windows 2008 64-bit run mingw64 GDB. Pierre Muller Pascal language support maintainer for GDB 2010-05-21 Pierre Muller * windows-nat.c (GetConsoleFontSize, GetCurrentConsoleFont): New macros. (windows_create_inferior): Copy current console information into SI structure if on a console if new-console is on. (bad_GetCurrentConsoleFont, bad_GetConsoleFontSize): New functions. (_initialize_loadable): Initialize GetConsoleFontSize and GetCurrentConsoleFont. Index: windows-nat.c =================================================================== RCS file: /cvs/src/src/gdb/windows-nat.c,v retrieving revision 1.208 diff -u -p -r1.208 windows-nat.c --- windows-nat.c 16 Apr 2010 07:49:35 -0000 1.208 +++ windows-nat.c 21 May 2010 21:04:16 -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 static BOOL WINAPI (*AdjustTokenPrivileges)(HANDLE, BOOL, PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD); @@ -87,7 +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); static struct target_ops windows_ops; #undef STARTUPINFO @@ -1933,7 +1940,39 @@ windows_create_inferior (struct target_o flags |= CREATE_NEW_PROCESS_GROUP; if (new_console) - flags |= CREATE_NEW_CONSOLE; + { + HANDLE hconsole = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0); + + /* 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. */ + if (hconsole != INVALID_HANDLE_VALUE) + { + CONSOLE_SCREEN_BUFFER_INFO sbinfo; + COORD font_size; + CONSOLE_FONT_INFO cfi; + GetCurrentConsoleFont (hconsole, FALSE, &cfi); + font_size = GetConsoleFontSize (hconsole, cfi.nFont); + GetConsoleScreenBufferInfo(hconsole, &sbinfo); + si.dwXSize = sbinfo.srWindow.Right - sbinfo.srWindow.Left + 1; + si.dwYSize = sbinfo.srWindow.Bottom - sbinfo.srWindow.Top + 1; + if (font_size.X) + si.dwXSize *= font_size.X; + else + si.dwXSize *= 8; + if (font_size.Y) + si.dwYSize *= font_size.Y; + else + si.dwYSize *= 12; + si.dwXCountChars = sbinfo.dwSize.X; + si.dwYCountChars = sbinfo.dwSize.Y; + si.dwFlags |= STARTF_USESIZE | STARTF_USECOUNTCHARS; + } + flags |= CREATE_NEW_CONSOLE; + } #ifdef __CYGWIN__ if (!useshell) @@ -2570,6 +2609,21 @@ bad_OpenProcessToken (HANDLE w, DWORD x, return FALSE; } +static BOOL WINAPI +bad_GetCurrentConsoleFont (HANDLE w, BOOL bMaxWindow, CONSOLE_FONT_INFO *f) +{ + f->nFont = 0; + return 1; +} +static COORD WINAPI +bad_GetConsoleFontSize (HANDLE w, DWORD nFont) +{ + COORD size; + size.X = 8; + size.Y = 12; + return size; +} + /* Load any functions which may not be available in ancient versions of Windows. */ void @@ -2586,6 +2640,10 @@ _initialize_loadable (void) GetProcAddress (hm, "DebugBreakProcess"); DebugSetProcessKillOnExit = (void *) GetProcAddress (hm, "DebugSetProcessKillOnExit"); + GetConsoleFontSize = (void *) + GetProcAddress (hm, "GetConsoleFontSize"); + GetCurrentConsoleFont = (void *) + GetProcAddress (hm, "GetCurrentConsoleFont"); } /* Set variables to dummy versions of these processes if the function @@ -2597,6 +2655,10 @@ _initialize_loadable (void) DebugActiveProcessStop = bad_DebugActiveProcessStop; DebugSetProcessKillOnExit = bad_DebugSetProcessKillOnExit; } + if (!GetConsoleFontSize) + GetConsoleFontSize = bad_GetConsoleFontSize; + if (!GetCurrentConsoleFont) + GetCurrentConsoleFont = bad_GetCurrentConsoleFont; /* Load optional functions used for retrieving filename information associated with the currently debugged process or its dlls. */