-
Notifications
You must be signed in to change notification settings - Fork 109
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Redirect Debug/Warning/... to OutputDebugString on Windows #79
Comments
Currently testing in vs2019 - seems to work fine with RelWithDebInfo, and doesn't return true if no debugger attached. |
So it means ... if I run with F5, it says |
Yup, I think that's exactly the case with |
I thought I could use Well, Windows is not my native system, so I'm just guessing -- but I imagine everything sent to |
|
I tried here with MinGW-w64 GCC/GDB on Windows, using both CLion and the MSYS2 build of Qt Creator (I don't use VS because it can't be used with GCC and because it's really bloated).
Notes:
|
Note that you can just always send output to OutputDebugString and, when the application is running outside of Visual Studio, see it using the Sysinternals tool DebugView - see the download page. It was developed outside Microsoft but Microsoft acquired them. I've been using it for years - it's got some handy redirection and filtering capabilities, but you can also run it from the CMD CLI and redirect its output to a file. |
OTOH, thanks to that tweet now I probably know how to catch it even without VS debugger or DebugView attached :) |
When building a Win32 GUI app (CMake
add_executable(... WIN32 ...)
, standard output isn't printed to the IDE output view, and one has to useOutputDebugString()
because ... Windows is special! So we need to comply with that. Fortunately people learned to useDebug
etc. quite extensively,Debug
can have scoped output redirection, and there's nowCorrade::Main
that could do this automagically in the background.Things to do:
std::basic_stringbuf
as seen on https://stackoverflow.com/questions/5248704/how-to-redirect-standard-output-to-output-window-from-visual-studio (but there it seems to be called char-by-char, isn't that slow?!)std::cerr
WaitForDebugEventEx
, the heck is that?!IsDebuggerPresent()
to enable this conditionally only when running from an IDE? Does that function returntrue
also when running a Release build / a build without debugger? Ugh._CrtSetReportMode()
,_CrtSetReportFile()
or_CrtSetReportHook()
which control whether the assertion dialog box gets open or if the message gets printed to stdout etcCc: @hsdk123
The text was updated successfully, but these errors were encountered: