* [RFA] windows-nat.c: Copy console information for new console
@ 2010-05-21 22:37 Pierre Muller
2010-05-25 21:01 ` Christopher Faylor
0 siblings, 1 reply; 10+ messages in thread
From: Pierre Muller @ 2010-05-21 22:37 UTC (permalink / raw)
To: gdb-patches
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 <muller@ics.u-strasbg.fr>
* 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. */
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFA] windows-nat.c: Copy console information for new console
2010-05-21 22:37 [RFA] windows-nat.c: Copy console information for new console Pierre Muller
@ 2010-05-25 21:01 ` Christopher Faylor
2010-05-26 8:07 ` Pierre Muller
0 siblings, 1 reply; 10+ messages in thread
From: Christopher Faylor @ 2010-05-25 21:01 UTC (permalink / raw)
To: gdb-patches, Pierre Muller
On Sat, May 22, 2010 at 12:28:51AM +0200, Pierre Muller wrote:
> 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 <muller@ics.u-strasbg.fr>
>
> * 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.
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.
cgf
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFA] windows-nat.c: Copy console information for new console
2010-05-25 21:01 ` Christopher Faylor
@ 2010-05-26 8:07 ` Pierre Muller
2010-05-26 17:20 ` Christopher Faylor
0 siblings, 1 reply; 10+ messages in thread
From: Pierre Muller @ 2010-05-26 8:07 UTC (permalink / raw)
To: gdb-patches
> -----Message d'origine-----
De : 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.
>
> 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 <muller@ics.u-strasbg.fr>
* 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
===================================================================
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
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);
static struct target_ops windows_ops;
@@ -1895,6 +1899,43 @@ windows_open (char *arg, int from_tty)
error (_("Use the \"run\" command to start a Unix child process."));
}
+/* 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 = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+
+ 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;
+ }
+}
+
/* 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 |= CREATE_NEW_PROCESS_GROUP;
if (new_console)
- flags |= CREATE_NEW_CONSOLE;
+ {
+ windows_set_console_info (&si);
+ flags |= CREATE_NEW_CONSOLE;
+ }
#ifdef __CYGWIN__
if (!useshell)
@@ -2574,6 +2618,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
@@ -2590,6 +2649,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
@@ -2601,6 +2664,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. */
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFA] windows-nat.c: Copy console information for new console
2010-05-26 8:07 ` Pierre Muller
@ 2010-05-26 17:20 ` Christopher Faylor
2010-05-27 7:14 ` Pierre Muller
0 siblings, 1 reply; 10+ messages in thread
From: Christopher Faylor @ 2010-05-26 17:20 UTC (permalink / raw)
To: gdb-patches, Pierre Muller
On Wed, May 26, 2010 at 09:49:05AM +0200, Pierre Muller wrote:
>> -----Message d'origine-----
> De?: 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.
>>
>> cgf
>
>
> You are right, this is cleaner, nevertheless flags isn't
>used much,
I actually thought fairly carefully about flags. If you have a function
which controls console info, then the function should set the flags
appropriately to deal with the console info.
cgf
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFA] windows-nat.c: Copy console information for new console
2010-05-26 17:20 ` Christopher Faylor
@ 2010-05-27 7:14 ` Pierre Muller
2010-05-27 12:59 ` Pierre Muller
0 siblings, 1 reply; 10+ messages in thread
From: Pierre Muller @ 2010-05-27 7:14 UTC (permalink / raw)
To: gdb-patches
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Christopher Faylor
> Envoyé : Wednesday, May 26, 2010 7:07 PM
> À : gdb-patches@sourceware.org; Pierre Muller
> Objet : Re: [RFA] windows-nat.c: Copy console information for new
> console
>
> On Wed, May 26, 2010 at 09:49:05AM +0200, Pierre Muller wrote:
> >> -----Message d'origine-----
> > De?: 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.
> >>
> >> cgf
> >
> >
> > You are right, this is cleaner, nevertheless flags isn't
> >used much,
>
> I actually thought fairly carefully about flags. If you have a
> function
> which controls console info, then the function should set the flags
> appropriately to deal with the console info.
As you prefer,
here is a new version that also takes DWORD *flags as parameter.
I also tried to explain a little bit better
what the function tries to do.
Pierre Muller
2010-05-26 Pierre Muller <muller@ics.u-strasbg.fr>
* 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
===================================================================
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 27 May 2010 06:43:19 -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,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);
static struct target_ops windows_ops;
@@ -1895,6 +1899,51 @@ windows_open (char *arg, int from_tty)
error (_("Use the \"run\" command to start a Unix child process."));
}
+/* Modify CreateProcess parameters for use of a new separate console.
+ Parameters are:
+ *FLAGS: DWORD parameter for general process creation flags.
+ *SI: STARTUPINFO structure, for which the console window size and
+ console buffer size is filled in if GDB is running in a 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 the windows and buffer sizes are computed,
+ SI->DWFLAGS is changed so that this information is used
+ by CreateProcess function. */
+
+static void
+windows_set_console_info (STARTUPINFO *si, DWORD *flags)
+{
+ HANDLE hconsole = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+
+ 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;
+}
+
/* 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 +1986,7 @@ windows_create_inferior (struct target_o
flags |= CREATE_NEW_PROCESS_GROUP;
if (new_console)
- flags |= CREATE_NEW_CONSOLE;
+ windows_set_console_info (&si, &flags);
#ifdef __CYGWIN__
if (!useshell)
@@ -2574,6 +2623,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
@@ -2590,6 +2654,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
@@ -2601,6 +2669,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. */
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFA] windows-nat.c: Copy console information for new console
2010-05-27 7:14 ` Pierre Muller
@ 2010-05-27 12:59 ` Pierre Muller
2010-05-27 15:43 ` Christopher Faylor
0 siblings, 1 reply; 10+ messages in thread
From: Pierre Muller @ 2010-05-27 12:59 UTC (permalink / raw)
To: gdb-patches
Please disregard the patch in the previous email,
it contains an error that generates a compilation failure,
sorry about this.
> From Christopher Faylor
> I actually thought fairly carefully about flags. If you have a
> function
> which controls console info, then the function should set the flags
> appropriately to deal with the console info.
As you prefer,
here is a new version that also takes DWORD *flags as parameter.
I also tried to explain a little bit better
what the function tries to do.
Pierre Muller
2010-05-26 Pierre Muller <muller@ics.u-strasbg.fr>
* 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
===================================================================
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 27 May 2010 07:11:40 -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,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);
static struct target_ops windows_ops;
@@ -1895,6 +1899,51 @@ windows_open (char *arg, int from_tty)
error (_("Use the \"run\" command to start a Unix child process."));
}
+/* Modify CreateProcess parameters for use of a new separate console.
+ Parameters are:
+ *FLAGS: DWORD parameter for general process creation flags.
+ *SI: STARTUPINFO structure, for which the console window size and
+ console buffer size is filled in if GDB is running in a 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 the windows and buffer sizes are computed,
+ SI->DWFLAGS is changed so that this information is used
+ by CreateProcess function. */
+
+static void
+windows_set_console_info (STARTUPINFO *si, DWORD *flags)
+{
+ HANDLE hconsole = CreateFile ("CONOUT$", GENERIC_READ | GENERIC_WRITE,
+ FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
+
+ 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;
+}
+
/* 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 +1986,7 @@ windows_create_inferior (struct target_o
flags |= CREATE_NEW_PROCESS_GROUP;
if (new_console)
- flags |= CREATE_NEW_CONSOLE;
+ windows_set_console_info (&si, &flags);
#ifdef __CYGWIN__
if (!useshell)
@@ -2574,6 +2623,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
@@ -2590,6 +2654,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
@@ -2601,6 +2669,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. */
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFA] windows-nat.c: Copy console information for new console
2010-05-27 12:59 ` Pierre Muller
@ 2010-05-27 15:43 ` Christopher Faylor
2010-05-28 15:28 ` Pierre Muller
0 siblings, 1 reply; 10+ messages in thread
From: Christopher Faylor @ 2010-05-27 15:43 UTC (permalink / raw)
To: gdb-patches, Pierre Muller
On Thu, May 27, 2010 at 09:13:53AM +0200, Pierre Muller wrote:
> Please disregard the patch in the previous email,
>it contains an error that generates a compilation failure,
>sorry about this.
>
>> From Christopher Faylor
>> I actually thought fairly carefully about flags. If you have a
>> function
>> which controls console info, then the function should set the flags
>> appropriately to deal with the console info.
>
>
> As you prefer,
>here is a new version that also takes DWORD *flags as parameter.
> I also tried to explain a little bit better
>what the function tries to do.
Thanks. Looks good. I forgot to say: Thanks for doing this. It looks like
a nice improvement.
cgf
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFA] windows-nat.c: Copy console information for new console
2010-05-27 15:43 ` Christopher Faylor
@ 2010-05-28 15:28 ` Pierre Muller
2010-05-30 18:00 ` Christopher Faylor
0 siblings, 1 reply; 10+ messages in thread
From: Pierre Muller @ 2010-05-28 15:28 UTC (permalink / raw)
To: gdb-patches
> >> From Christopher Faylor
> >> I actually thought fairly carefully about flags. If you have a
> >> function
> >> which controls console info, then the function should set the flags
> >> appropriately to deal with the console info.
> >
> >
> > As you prefer,
> >here is a new version that also takes DWORD *flags as parameter.
> > I also tried to explain a little bit better
> >what the function tries to do.
>
> Thanks. Looks good. I forgot to say: Thanks for doing this. It
> looks like
> a nice improvement.
Hi Christopher,
does this mean that you want to test it
a little bit more before you give some more detailed
review or should I understand this as an approval?
Pierre
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFA] windows-nat.c: Copy console information for new console
2010-05-28 15:28 ` Pierre Muller
@ 2010-05-30 18:00 ` Christopher Faylor
2010-06-01 6:57 ` [RFC] windows-nat.c: New oddity after copy console information for new console patch Pierre Muller
0 siblings, 1 reply; 10+ messages in thread
From: Christopher Faylor @ 2010-05-30 18:00 UTC (permalink / raw)
To: gdb-patches, Pierre Muller
On Fri, May 28, 2010 at 12:16:59PM +0200, Pierre Muller wrote:
>> >> From Christopher Faylor
>> >> I actually thought fairly carefully about flags. If you have a
>> >> function
>> >> which controls console info, then the function should set the flags
>> >> appropriately to deal with the console info.
>> >
>> >
>> > As you prefer,
>> >here is a new version that also takes DWORD *flags as parameter.
>> > I also tried to explain a little bit better
>> >what the function tries to do.
>>
>> Thanks. Looks good. I forgot to say: Thanks for doing this. It
>> looks like
>> a nice improvement.
>
> Hi Christopher,
> does this mean that you want to test it
>a little bit more before you give some more detailed
>review or should I understand this as an approval?
Wow. You like to go back and forth don't you?
Just apply it already.
cgf
^ permalink raw reply [flat|nested] 10+ messages in thread
* [RFC] windows-nat.c: New oddity after copy console information for new console patch.
2010-05-30 18:00 ` Christopher Faylor
@ 2010-06-01 6:57 ` Pierre Muller
0 siblings, 0 replies; 10+ messages in thread
From: Pierre Muller @ 2010-06-01 6:57 UTC (permalink / raw)
To: gdb-patches
> -----Message d'origine-----
> De : gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] De la part de Christopher Faylor
> Envoyé : Sunday, May 30, 2010 7:11 PM
> À : gdb-patches@sourceware.org; Pierre Muller
> Objet : Re: [RFA] windows-nat.c: Copy console information for new
> console
>
> On Fri, May 28, 2010 at 12:16:59PM +0200, Pierre Muller wrote:
> >> >> From Christopher Faylor
> >> >> I actually thought fairly carefully about flags. If you have a
> >> >> function
> >> >> which controls console info, then the function should set the
> flags
> >> >> appropriately to deal with the console info.
> >> >
> >> >
> >> > As you prefer,
> >> >here is a new version that also takes DWORD *flags as parameter.
> >> > I also tried to explain a little bit better
> >> >what the function tries to do.
> >>
> >> Thanks. Looks good. I forgot to say: Thanks for doing this. It
> >> looks like
> >> a nice improvement.
> >
> > Hi Christopher,
> > does this mean that you want to test it
> >a little bit more before you give some more detailed
> >review or should I understand this as an approval?
>
> Wow. You like to go back and forth don't you?
Not really, but I prefer to ask once more rather
than doing something wrong.
> Just apply it already.
Applied yesterday...
But I just noticed a strange, probably unwanted effect of my patch:
I you debug a GUI application that starts its main window at default size,
this size is now different depending on the
state on the `new-console' switch:
- if new-console is off, the default size is chosen by the system
(probably as before my patch),
- if new-console is on, the size of the start window will be forced
by the settings of dwXSize and dwYSize fields of the STARTUPINFO
structure together with the STARTF_USESIZE flag.
Should we change this?
We could condition the call to windows_set_console_info
on the fact that the executable to start is not a GUI application,
but I am not sure how to check this within GDB code.
Suggestions most welcome,
Pierre Muller
Pascal language support maintainer for GDB
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2010-06-01 6:57 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-21 22:37 [RFA] windows-nat.c: Copy console information for new console Pierre Muller
2010-05-25 21:01 ` Christopher Faylor
2010-05-26 8:07 ` Pierre Muller
2010-05-26 17:20 ` Christopher Faylor
2010-05-27 7:14 ` Pierre Muller
2010-05-27 12:59 ` Pierre Muller
2010-05-27 15:43 ` Christopher Faylor
2010-05-28 15:28 ` Pierre Muller
2010-05-30 18:00 ` Christopher Faylor
2010-06-01 6:57 ` [RFC] windows-nat.c: New oddity after copy console information for new console patch Pierre Muller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox