* [PATCH] long long for printf on MinGW
@ 2006-10-11 11:21 Andrew STUBBS
2006-10-11 13:03 ` Daniel Jacobowitz
2006-10-11 20:28 ` Mark Kettenis
0 siblings, 2 replies; 11+ messages in thread
From: Andrew STUBBS @ 2006-10-11 11:21 UTC (permalink / raw)
To: GDB Patches
[-- Attachment #1: Type: text/plain, Size: 332 bytes --]
Hi,
Windows/MinGW printf does support printing of long long types, but it
does not do using %lld etc.
This patch converts %ll (or %...ll) to %I64 as required by Windows.
GDB printf still won't accept I64 as input, but then this is not
standard compliant so I don't think it really should.
:ADDPATCH printcmd.c:
Andrew Stubbs
[-- Attachment #2: printf.patch --]
[-- Type: text/plain, Size: 1673 bytes --]
2006-10-11 Andrew Stubbs <andrew.stubbs@st.com>
* printcmd.c (printf_command): Convert %lld to %I64d on MinGW.
Index: src/gdb/printcmd.c
===================================================================
--- src.orig/gdb/printcmd.c 2006-07-17 23:15:55.000000000 +0100
+++ src/gdb/printcmd.c 2006-10-11 11:28:29.000000000 +0100
@@ -1967,8 +1967,24 @@ printf_command (char *arg, int from_tty)
*f);
f++;
- strncpy (current_substring, last_arg, f - last_arg);
- current_substring += f - last_arg;
+#if defined (__MINGW32__)
+ /* Windows' printf does support long long, but not the usual way.
+ Convert %lld to %I64d. */
+ if (lcount > 1)
+ {
+ int length_before_ll = f - last_arg - 1 - lcount;
+ strncpy (current_substring, last_arg, length_before_ll);
+ strcpy (current_substring + length_before_ll, "I64");
+ current_substring[length_before_ll + 3] =
+ last_arg[length_before_ll + lcount];
+ current_substring += length_before_ll + 4;
+ }
+ else
+#endif
+ {
+ strncpy (current_substring, last_arg, f - last_arg);
+ current_substring += f - last_arg;
+ }
*current_substring++ = '\0';
last_arg = f;
argclass[nargs_wanted++] = this_argclass;
@@ -2056,7 +2072,8 @@ printf_command (char *arg, int from_tty)
error (_("long double not supported in printf"));
#endif
case long_long_arg:
-#if defined (CC_HAS_LONG_LONG) && defined (PRINTF_HAS_LONG_LONG)
+#if defined (CC_HAS_LONG_LONG) && (defined (PRINTF_HAS_LONG_LONG) \
+ || defined (__MINGW32__))
{
long long val = value_as_long (val_args[i]);
printf_filtered (current_substring, val);
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] long long for printf on MinGW
2006-10-11 11:21 [PATCH] long long for printf on MinGW Andrew STUBBS
@ 2006-10-11 13:03 ` Daniel Jacobowitz
2006-10-11 15:12 ` Andrew STUBBS
2006-10-11 20:28 ` Mark Kettenis
1 sibling, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2006-10-11 13:03 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: GDB Patches
On Wed, Oct 11, 2006 at 11:57:49AM +0100, Andrew STUBBS wrote:
> Hi,
>
> Windows/MinGW printf does support printing of long long types, but it
> does not do using %lld etc.
>
> This patch converts %ll (or %...ll) to %I64 as required by Windows.
>
> GDB printf still won't accept I64 as input, but then this is not
> standard compliant so I don't think it really should.
>
> :ADDPATCH printcmd.c:
>
> Andrew Stubbs
I don't much like #ifdef __MINGW32__, but I'm not sure what else to do
about it... I suppose we could autoconf for inttypes.h and check for
PRIx64 starting with 'I', but that's no better.
Could you at least do something like this?
#if defined(__MINGW32__)
# define USE_PRINTF_I64 1
# define PRINTF_HAS_LONG_LONG
#else
# define USE_PRINTF_I64 0
#endif
if (lcount > 1 && USE_PRINTF_I64)
The GCC folks learned a hard lesson that conditionally compiled code is
a maintenance burden all its own.
Thanks in advance.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] long long for printf on MinGW
2006-10-11 13:03 ` Daniel Jacobowitz
@ 2006-10-11 15:12 ` Andrew STUBBS
2008-04-22 19:41 ` Daniel Jacobowitz
0 siblings, 1 reply; 11+ messages in thread
From: Andrew STUBBS @ 2006-10-11 15:12 UTC (permalink / raw)
To: GDB Patches
[-- Attachment #1: Type: text/plain, Size: 159 bytes --]
Daniel Jacobowitz wrote:
> Could you at least do something like this?
Ok, how about the attached. I believe I have done it just how you asked.
Andrew Stubbs
[-- Attachment #2: printf.patch --]
[-- Type: text/plain, Size: 1660 bytes --]
2006-10-11 Andrew Stubbs <andrew.stubbs@st.com>
* printcmd.c: Define USE_PRINTF_I64 and PRINTF_HAS_LONG_LONG on MinGW.
(printf_command): Convert %lld to %I64d when USE_PRINTF_I64 set.
Index: src/gdb/printcmd.c
===================================================================
--- src.orig/gdb/printcmd.c 2006-07-17 23:15:55.000000000 +0100
+++ src/gdb/printcmd.c 2006-10-11 14:47:57.000000000 +0100
@@ -48,6 +48,13 @@
#include "tui/tui.h" /* For tui_active et.al. */
#endif
+#if defined(__MINGW32__)
+# define USE_PRINTF_I64 1
+# define PRINTF_HAS_LONG_LONG
+#else
+# define USE_PRINTF_I64 0
+#endif
+
extern int asm_demangle; /* Whether to demangle syms in asm printouts */
extern int addressprint; /* Whether to print hex addresses in HLL " */
@@ -1967,8 +1974,23 @@ printf_command (char *arg, int from_tty)
*f);
f++;
- strncpy (current_substring, last_arg, f - last_arg);
- current_substring += f - last_arg;
+
+ if (lcount > 1 && USE_PRINTF_I64)
+ {
+ /* Windows' printf does support long long, but not the usual way.
+ Convert %lld to %I64d. */
+ int length_before_ll = f - last_arg - 1 - lcount;
+ strncpy (current_substring, last_arg, length_before_ll);
+ strcpy (current_substring + length_before_ll, "I64");
+ current_substring[length_before_ll + 3] =
+ last_arg[length_before_ll + lcount];
+ current_substring += length_before_ll + 4;
+ }
+ else
+ {
+ strncpy (current_substring, last_arg, f - last_arg);
+ current_substring += f - last_arg;
+ }
*current_substring++ = '\0';
last_arg = f;
argclass[nargs_wanted++] = this_argclass;
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] long long for printf on MinGW
2006-10-11 15:12 ` Andrew STUBBS
@ 2008-04-22 19:41 ` Daniel Jacobowitz
2008-04-23 10:26 ` Andrew STUBBS
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2008-04-22 19:41 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: GDB Patches
On Wed, Oct 11, 2006 at 04:12:40PM +0100, Andrew STUBBS wrote:
> 2006-10-11 Andrew Stubbs <andrew.stubbs@st.com>
>
> * printcmd.c: Define USE_PRINTF_I64 and PRINTF_HAS_LONG_LONG on MinGW.
> (printf_command): Convert %lld to %I64d when USE_PRINTF_I64 set.
I'm somewhat willing to approve this patch. Note this is the revised
one from
http://sourceware.org/ml/gdb-patches/2006-10/msg00117.html
I had ambitious plans involving making printf work on target types.
But they aren't going to come through any time soon.
However, for host types we could import the printf (vsprintf-posix)
module from gnulib, then always assume PRINTF_HAS_LONG_LONG as long as
HAVE_LONG_LONG_INT. I did the work of adding gnulib modules already.
So maybe this is a better option. What do you think?
> + /* Windows' printf does support long long, but not the usual way.
> + Convert %lld to %I64d. */
> + int length_before_ll = f - last_arg - 1 - lcount;
> + strncpy (current_substring, last_arg, length_before_ll);
> + strcpy (current_substring + length_before_ll, "I64");
> + current_substring[length_before_ll + 3] =
> + last_arg[length_before_ll + lcount];
> + current_substring += length_before_ll + 4;
You've got enough buffer space to do this but I had to think about it
a couple times to work out why :-)
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] long long for printf on MinGW
2008-04-22 19:41 ` Daniel Jacobowitz
@ 2008-04-23 10:26 ` Andrew STUBBS
2008-04-23 12:18 ` Daniel Jacobowitz
0 siblings, 1 reply; 11+ messages in thread
From: Andrew STUBBS @ 2008-04-23 10:26 UTC (permalink / raw)
To: Andrew STUBBS, GDB Patches
Daniel Jacobowitz wrote:
> However, for host types we could import the printf (vsprintf-posix)
> module from gnulib, then always assume PRINTF_HAS_LONG_LONG as long as
> HAVE_LONG_LONG_INT. I did the work of adding gnulib modules already.
> So maybe this is a better option. What do you think?
I'm not sufficiently familiar with gnulib to know what gotchas there
might be, but I imagine it would at least solve the problem of different
behaviour on different hosts, given the same target.
That said, selfishly speaking, it's overkill for _my_ problem, and I
don't know of any other problems in this area - apart from hosts that
just plain don't have long long, and you seem to suggest that gnulib
won't solve that?
>> + /* Windows' printf does support long long, but not the usual way.
>> + Convert %lld to %I64d. */
>> + int length_before_ll = f - last_arg - 1 - lcount;
>> + strncpy (current_substring, last_arg, length_before_ll);
>> + strcpy (current_substring + length_before_ll, "I64");
>> + current_substring[length_before_ll + 3] =
>> + last_arg[length_before_ll + lcount];
>> + current_substring += length_before_ll + 4;
>
> You've got enough buffer space to do this but I had to think about it
> a couple times to work out why :-)
Unless I'm mistaken, the code reserves enough space for every character
to be in it's own nul-terminated substring, but since the minimum length
%-spec is two characters, that's impossible. In this specific example,
there would be 8 bytes reserved for the string "%lld" - enough for
"%\0l\0l\0d\0", but "%I64d\0" only uses 6.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] long long for printf on MinGW
2008-04-23 10:26 ` Andrew STUBBS
@ 2008-04-23 12:18 ` Daniel Jacobowitz
2008-04-23 16:12 ` Andrew STUBBS
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2008-04-23 12:18 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: GDB Patches
On Wed, Apr 23, 2008 at 10:28:38AM +0100, Andrew STUBBS wrote:
> That said, selfishly speaking, it's overkill for _my_ problem, and I
> don't know of any other problems in this area - apart from hosts that
> just plain don't have long long, and you seem to suggest that gnulib
> won't solve that?
You can't pass a long long by C varargs if your compiler doesn't
support it, and GDB won't do anything sensible anyway - LONGEST
will be a long.
> Unless I'm mistaken, the code reserves enough space for every character
> to be in it's own nul-terminated substring, but since the minimum length
> %-spec is two characters, that's impossible. In this specific example,
> there would be 8 bytes reserved for the string "%lld" - enough for
> "%\0l\0l\0d\0", but "%I64d\0" only uses 6.
Right.
Go ahead with the patch. We can rip it out if we switch to gnulib's
printf.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] long long for printf on MinGW
2008-04-23 12:18 ` Daniel Jacobowitz
@ 2008-04-23 16:12 ` Andrew STUBBS
0 siblings, 0 replies; 11+ messages in thread
From: Andrew STUBBS @ 2008-04-23 16:12 UTC (permalink / raw)
To: Andrew STUBBS, GDB Patches
[-- Attachment #1: Type: text/plain, Size: 243 bytes --]
Daniel Jacobowitz wrote:
> Go ahead with the patch. We can rip it out if we switch to gnulib's
> printf.
Committed.
I've attached the final verion. It's only the patch offsets that have
changed since the last patch posted.
Thanks
Andrew
[-- Attachment #2: updated-printf.patch --]
[-- Type: text/plain, Size: 1727 bytes --]
2008-04-23 Andrew Stubbs <andrew.stubbs@st.com>
* printcmd.c: Define USE_PRINTF_I64 and PRINTF_HAS_LONG_LONG on MinGW.
(printf_command): Convert %lld to %I64d when USE_PRINTF_I64 set.
Index: gdb/printcmd.c
===================================================================
RCS file: /cvs/src/src/gdb/printcmd.c,v
retrieving revision 1.117
diff -u -p -r1.117 printcmd.c
--- gdb/printcmd.c 30 Jan 2008 19:19:51 -0000 1.117
+++ gdb/printcmd.c 23 Apr 2008 12:05:33 -0000
@@ -47,6 +47,13 @@
#include "tui/tui.h" /* For tui_active et.al. */
#endif
+#if defined(__MINGW32__)
+# define USE_PRINTF_I64 1
+# define PRINTF_HAS_LONG_LONG
+#else
+# define USE_PRINTF_I64 0
+#endif
+
extern int asm_demangle; /* Whether to demangle syms in asm printouts */
extern int addressprint; /* Whether to print hex addresses in HLL " */
@@ -2009,8 +2016,23 @@ printf_command (char *arg, int from_tty)
*f);
f++;
- strncpy (current_substring, last_arg, f - last_arg);
- current_substring += f - last_arg;
+
+ if (lcount > 1 && USE_PRINTF_I64)
+ {
+ /* Windows' printf does support long long, but not the usual way.
+ Convert %lld to %I64d. */
+ int length_before_ll = f - last_arg - 1 - lcount;
+ strncpy (current_substring, last_arg, length_before_ll);
+ strcpy (current_substring + length_before_ll, "I64");
+ current_substring[length_before_ll + 3] =
+ last_arg[length_before_ll + lcount];
+ current_substring += length_before_ll + 4;
+ }
+ else
+ {
+ strncpy (current_substring, last_arg, f - last_arg);
+ current_substring += f - last_arg;
+ }
*current_substring++ = '\0';
last_arg = f;
argclass[nargs_wanted++] = this_argclass;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] long long for printf on MinGW
2006-10-11 11:21 [PATCH] long long for printf on MinGW Andrew STUBBS
2006-10-11 13:03 ` Daniel Jacobowitz
@ 2006-10-11 20:28 ` Mark Kettenis
2006-10-11 20:44 ` Daniel Jacobowitz
2006-10-12 10:09 ` Andrew STUBBS
1 sibling, 2 replies; 11+ messages in thread
From: Mark Kettenis @ 2006-10-11 20:28 UTC (permalink / raw)
To: Andrew STUBBS; +Cc: GDB Patches
> Hi,
>
> Windows/MinGW printf does support printing of long long types, but it
> does not do using %lld etc.
>
> This patch converts %ll (or %...ll) to %I64 as required by Windows.
What! Seven years after ISO C99 was ratified, Microsoft still ships a libc
that doesn't support %ll?
Sigh, I don't see why we need to treat MINGW special here. We should
probably
just print an error if PRINTF_HAS_LONG_LONG isn't defined.
Actually I think the way we support size modifiers in gdb's printf are
completely broken. Do they refer to the host types, or the target types?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] long long for printf on MinGW
2006-10-11 20:28 ` Mark Kettenis
@ 2006-10-11 20:44 ` Daniel Jacobowitz
2006-10-12 10:09 ` Andrew STUBBS
1 sibling, 0 replies; 11+ messages in thread
From: Daniel Jacobowitz @ 2006-10-11 20:44 UTC (permalink / raw)
To: Mark Kettenis; +Cc: Andrew STUBBS, GDB Patches
On Wed, Oct 11, 2006 at 10:28:21PM +0200, Mark Kettenis wrote:
> Actually I think the way we support size modifiers in gdb's printf are
> completely broken. Do they refer to the host types, or the target types?
Good question: which do you want them to refer to?
I have already rewritten this file pretty much from scratch once in
2006, so I'm understandably not too eager to do it again :-) But if we
must, then we must.
I do not see any clear way to support target types while still taking
advantage of the host printf, however. Perhaps I should go back to my
prototype patch for line wrapping, which would let us import bits of
"gnulib". Which has a nice thorough printf format string parser
that we might be able to reuse.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] long long for printf on MinGW
2006-10-11 20:28 ` Mark Kettenis
2006-10-11 20:44 ` Daniel Jacobowitz
@ 2006-10-12 10:09 ` Andrew STUBBS
[not found] ` <200610151745.k9FHjvPa017960@elgar.sibelius.xs4all.nl>
1 sibling, 1 reply; 11+ messages in thread
From: Andrew STUBBS @ 2006-10-12 10:09 UTC (permalink / raw)
To: Mark Kettenis; +Cc: GDB Patches
Mark Kettenis wrote:
>> Hi,
>>
>> Windows/MinGW printf does support printing of long long types, but it
>> does not do using %lld etc.
>>
>> This patch converts %ll (or %...ll) to %I64 as required by Windows.
>
> What! Seven years after ISO C99 was ratified, Microsoft still ships a libc
> that doesn't support %ll?
I'm still using Win2K, so I don't think you can count all of those seven
years. So are many of our customers and, no doubt, other users. The MSDN
I have is dated 2002.
> Sigh, I don't see why we need to treat MINGW special here. We should
> probably
> just print an error if PRINTF_HAS_LONG_LONG isn't defined.
That's what it does, and what I don't want it to do. Why shouldn't I be
able to see long long values, as supported by the target, just because I
happen to use a Windows host. It isn't a difficult fixup and doesn't
break or even affect any other host.
Please don't point out some other way of displaying the value, that
isn't the point and is just proof that it ought to work.
> Actually I think the way we support size modifiers in gdb's printf are
> completely broken. Do they refer to the host types, or the target types?
'Completely' broken or not, they work for most peoples' needs, but in
this respect they don't work for Windows users' needs.
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2008-04-23 13:23 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-11 11:21 [PATCH] long long for printf on MinGW Andrew STUBBS
2006-10-11 13:03 ` Daniel Jacobowitz
2006-10-11 15:12 ` Andrew STUBBS
2008-04-22 19:41 ` Daniel Jacobowitz
2008-04-23 10:26 ` Andrew STUBBS
2008-04-23 12:18 ` Daniel Jacobowitz
2008-04-23 16:12 ` Andrew STUBBS
2006-10-11 20:28 ` Mark Kettenis
2006-10-11 20:44 ` Daniel Jacobowitz
2006-10-12 10:09 ` Andrew STUBBS
[not found] ` <200610151745.k9FHjvPa017960@elgar.sibelius.xs4all.nl>
2006-10-16 9:45 ` Andrew STUBBS
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox