Support for w*ndows

Niels Möller nisse at
Fri Dec 16 12:16:04 CET 2011

Torbjorn Granlund <tg at> writes:

> nisse at (Niels Möller) writes:

>   gmp_vsnprintf return value wrong
>     fmt       |%Md|
>     bufsize   0
>     got       |!0|
>     want      ||
>     want full |0|
>     ret       13
>     want_len  1
>   FAIL: t-printf.exe
>   ../../../../hack/gmp/tests/misc/t-scanf.c:1495: GNU MP assertion failed: ret == (-1)
>   FAIL: t-scanf.exe
>   Could of course be a bug in wine, if these tests succeed on native
>   windows.
> You are of course most welcome to debug these failures...

I have now given it a try. Setup:

0. Recompile gmp with debugging information (still cross compiled with
   --host=i586-mingw32msvc). Also recompile snprntffuns.c without

1. Compile a cross gdb (--host=x86_64-unknown-linux-gnu

2. Cross compile gdbserver (--host=i586-mingw32msvc
   --target=i586-mingw32msvc). I had to add an #include <stdint.h> to
   one file to make that work.

3. Run the program to be debugged as

   wine /usr/local/w32/bin/i586-pc-mingw32msvc-gdbserver.exe host:4711 t-printf.exe 

4. Do M-x gud-gdb in emacs, with the command line

     i586-pc-mingw32msvc-gdb --fullname t-printf.exe

   and type

      target remote localhost:4711

   Then, set some suitable breakpoint and type c.
Now, it turns out that the failing case is a call to gmp_vsnprintf, with
a buffer size of zero, format %Md, and a va_list argument which is
supposed to point at a zero limb.

This boils down to a call to gmp_snprintf_format with the format "%ld"
and the same va_list, When the buffer size is zero, this function
decides to allocate a buffer to write into (why???), and then calls
vsnprintf with a copy of the valist. This call then writes the string
"4653142004841054208" into that buffer, and returns 19. Gives a failure
message just like quoted above, but with "ret 19" instead of "ret 13".

So it appears that the limb value is destroyed somewhere on the way.

It would still be nice if someone could run the tests on a native
(32-bit) windows box, to see if it occurs there as well, or if it is a
bug in the wine environment and whatever vsnprintf implementation it

Is there any way to examine a va_list in gdb? It seems to be a gcc
builtin type, so a look in stdarg.h gives no hints about the internal


Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.

More information about the gmp-devel mailing list