Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can my Visual C++ program listen to its own debug output?

My program uses a ton of third party libraries that sometimes put useful error messages into debugger output (using OutputDebugString()).

Can my program somehow programmatically access that output so that it can parse it and report it to me in some more convenient manner?

like image 615
sharptooth Avatar asked May 06 '14 09:05

sharptooth


People also ask

How do I view debug log in Visual Studio?

To see the debug output window, in Microsoft Visual Studio, click View, click Other Windows, and then click Output. You can view the debug output in this window only if the debugger is attached to the process that is writing to the output window.

What is a debug output?

Debug Output is an OpenGL feature that makes debugging and optimizing OpenGL applications easier. Briefly, this feature provides a method for the driver to provide textual message information back to the application.

What is Trace in Visual Studio?

Tracing is a feature in Visual Studio that allows the programmer to put a log message onto the main output window. The mechanism is fairly simple to use. It is only active with debug builds, in a release build none of the trace messages will be displayed.


1 Answers

There is no API that gives you access to strings output through OutputDebugString.

There are two ways of getting the data:

  • Bad idea: implement the client side of the OutputDebugString protocol.
  • Better idea: hook the OutputDebugStringA function.

The OutputDebugString protocol only supports a single listener so the first approach isn't compatible with multiple instances of your application, other applications doing the same thing or debuggers. It would also capture output from all applications. It is not a good idea. I mention it only because it is an obvious but wrong solution.

OutputDebugStringW is (unusually) a wrapper around OutputDebugStringA so the latter is the function to hook. There are lots of libraries that make hooking easy so every call to OutputDebugString will become a call to a function you define, and you can do anything you like with the data.

like image 180
arx Avatar answered Oct 18 '22 22:10

arx