DebugPrinter Documentation

DebugPrinter header-only lib.

Creates a static object named dout and defines debugging macros.


Version
2015.1110
Author
Year Name
2011-2015 Donjan Rodic
2015 Mario Könz
2015 C. Frescolino

 

Compilation

DebugPrinter requires C++14.

Link with -rdynamic in order to get proper stack() frame names and useful dout_FUNC output.

Note: compiler optimisations may inline functions (shorter stack).

Pass DEBUGPRINTER_OFF to turn off all functionality provided here. The debug statements can be left in the code, since all methods and macros become inline and trivial, and thus will be optimised away by the compiler at sufficient optimisation flags. This flag will be automatically assumed if the standard NDEBUG is passed.

Pass DEBUGPRINTER_NO_EXECINFO flag on Windows (makes stack(), dout_STACK and dout_FUNC trivial).

Pass DEBUGPRINTER_NO_CXXABI if you don't have a cxxabi demangle call in your libc distribution (this translates raw type symbols, i.e. the typeid(std::string).name() output Ss to std::string). The stack and type methods will then print the mangled names and a c++filt-ready output.

Pass DEBUGPRINTER_NO_SIGNALS to turn off automatic stack tracing when certain fatal signals occur. Passing this flag is recommended on non-Unix-like systems.

 

Quick Usage Reference

For details, consult the Member Function Documentation of fsc::DebugPrinter, the Macros section of DebugPrinter.hpp, as well as the Examples.

// ...
// basic usage:
dout_HERE // print current file, line and function
dout_FUNC // print full current function signature
dout_STACK // print stack trace
dout_TYPE(std::map<T,U>) // print given type
dout_TYPE_OF(var) // print RTTI of variable
dout_VAL(var) // print highlighted 'name = value'
dout_PAUSE() // wait for user input (enter key)
dout_PAUSE(x < 10) // conditionally wait for user input
// advanced usage (non-exhaustive, check member details):
using fsc::dout;
dout << "foo" << std::endl;
dout, var , 5, " bar ", 6, " foobar ", 7, 8, std::endl;
dout(object); // highlight object
dout(object, label, " at "); // highlight label, object and separator
dout.stack(4, false, 2); // print 4 stack frames, omitting the first
dout = std::cout // set output stream
dout.set_precision(13) // set decimal display precision
dout.set_color("1;34") // set terminal highlighting color

In case the program terminates with SIGSEGV, SIGSYS, SIGABRT or SIGFPE, you will automatically get a stack trace from the raise location. To turn off this behaviour, check the Compilation section.