From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Stefan Weil <sw@weilnetz.de>
Subject: Re: [Qemu-devel] Win32 stdio not working if SDL is enabled
Date: Thu, 13 Aug 2015 15:18:49 +0100 [thread overview]
Message-ID: <20150813141849.GB11756@redhat.com> (raw)
In-Reply-To: <20150813120643.GF430@redhat.com>
On Thu, Aug 13, 2015 at 01:06:43PM +0100, Daniel P. Berrange wrote:
> When debugging some patches on Windows, I discovered that nothing printed
> to stderr ever appears on the console. Eventually I discovered that if I
> build with --disable-sdl, then stderr appears just fine.
>
> Looking at the code in vl.c I see a hack for SDL introduced in
>
> commit 59a36a2f6728081050afc6ec97d0018467999f79
> Author: Stefan Weil <weil@mail.berlios.de>
> Date: Thu Jun 18 20:11:03 2009 +0200
>
> Win32: Fix compilation with SDL.
>
>
> If I mostly kill the hack from vl.c, and just leave a plain '#undef main'
> then I get working console stderr once again.
[snip]
> to get it to print an error about bad -object arg. The message
> never appears unless I apply that patch above, though I lack any
> explanation as to why this is happening, aside from "SDL black magic"
So I figured out what's going on here
The sdl-config program is adding "-Dmain=SDL_main" to the compiler flags.
So when vl.c does this:
#include <SDL.h>
int qemu_main(int argc, char **argv, char **envp);
int main(int argc, char **argv)
{
return qemu_main(argc, argv, NULL);
}
#undef main
#define main qemu_main
We have an extra level of substitution going on. So we end up
the program starting in a
main(int argc, char **argv)
that is provided by SDL.dll, which in turn calls this stub
we define at the top of vl.c:
int main(int argc, char **argv)
{
return qemu_main(argc, argv, NULL);
}
where 'main' is actually changed to 'SDL_main', and 'qemu_main'
is auctally the real 'main' at the bottom of vl.c
Looking in SDL sources, one of the things it does in its replacement
main() method is to kill off default stdout & stderr streams,
replacing them with a stream that writes data to stdout.txt and
stderr.txt in the current directory.
As well as breaking the ability to see error messages on stderr,
this stupid SDL redirection also breaks the ability to use the
monitor via '-monitor stdio'.
All this is done even if you are not actually using SDL as the
QEMU display output too.
By replacing that current hack:
#include <SDL.h>
int qemu_main(int argc, char **argv, char **envp);
int main(int argc, char **argv)
{
return qemu_main(argc, argv, NULL);
}
#undef main
#define main qemu_main
With just
#include <SDL.h>
#undef main
we get rid of SDL.dll's replacement main() method entirely and execution
directly starts in QEMU's main() from vl.c. This avoids the stupid
console output redirection SDL does, and AFAICT, the SDL UI still works
after this, so the other setup things SDL.dll does don't seem to be too
critical
Regards,
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
next prev parent reply other threads:[~2015-08-13 14:19 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-13 12:06 [Qemu-devel] Win32 stdio not working if SDL is enabled Daniel P. Berrange
2015-08-13 12:14 ` Pavel Fedin
2015-08-13 14:18 ` Daniel P. Berrange [this message]
2015-08-13 17:48 ` Stefan Weil
2015-08-14 11:14 ` Daniel P. Berrange
2015-08-14 12:15 ` Daniel P. Berrange
2015-08-14 14:59 ` Liviu Ionescu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150813141849.GB11756@redhat.com \
--to=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).