#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <typeinfo>
#include <cstdlib>
#include <algorithm>
#include <stdexcept>
#include <memory>
#include <type_traits>
#include <execinfo.h>
#include <cxxabi.h>
#include <signal.h>
#include <map>
Go to the source code of this file.
DebugPrinter header-only lib.
Creates a static object named
dout
and defines debugging macros.
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.
Definition in file DebugPrinter.hpp.
Classes | |
class | fsc::DebugPrinter |
Class for global static dout object. More... | |
Namespaces | |
fsc | |
General fsc namespace. | |
Macros | |
#define | DEBUGPRINTER_DIRSEP '/' |
#define | dout_HERE |
Print current line in the form filename:line (function) More... | |
#define | dout_FUNC |
Print current function signature. More... | |
#define | dout_VAL(...) |
Print highlighted 'name = value' of given variable or expression. More... | |
#define | dout_TYPE(...) |
Print demangled type information of given type. More... | |
#define | dout_TYPE_OF(...) |
Print demangled type information of given variable or expression. More... | |
#define | dout_STACK |
Print a stack trace. More... | |
#define | dout_PAUSE(...) |
Pause execution (optionally) and wait for user key press (ENTER). More... | |
Functions | |
template<typename T > | |
DebugPrinter & | fsc::operator<< (DebugPrinter &d, const T &output) |
operator<< overload for std::ostream | |
DebugPrinter & | fsc::operator<< (DebugPrinter &d, std::ostream &(*pf)(std::ostream &)) |
operator<< overload for std::ostream manipulators | |
template<typename T > | |
DebugPrinter & | fsc::operator, (DebugPrinter &d, const T &output) |
operator, overload for std::ostream | |
DebugPrinter & | fsc::operator, (DebugPrinter &d, std::ostream &(*pf)(std::ostream &)) |
operator, overload for std::ostream manipulators | |
#define dout_FUNC |
Print current function signature.
Example usage:
Shortcut for:
Needs to be compiled with -rdynamic
(you will get an error message otherwise)
Definition at line 750 of file DebugPrinter.hpp.
#define dout_HERE |
Print current line in the form filename:line (function)
Example usage:
Shortcut for (pseudocode):
Definition at line 731 of file DebugPrinter.hpp.
#define dout_PAUSE | ( | ... | ) |
Pause execution (optionally) and wait for user key press (ENTER).
... | A string literal can be specified as argument to act as label. A pause condition can be specified as argument. This must be a valid expression for an if-statement. |
Example usage:
Definition at line 835 of file DebugPrinter.hpp.
#define dout_STACK |
Print a stack trace.
Example usage:
Shortcut for
Needs to be compiled with -rdynamic
(you will get an error message otherwise). Keep in mind that compiler optimisations will inline functions.
Definition at line 819 of file DebugPrinter.hpp.
#define dout_TYPE | ( | ... | ) |
Print demangled type information of given type.
... | can't be an incomplete type. |
This macro prints the instantiated demangled input type.
Example usage:
Definition at line 779 of file DebugPrinter.hpp.
#define dout_TYPE_OF | ( | ... | ) |
Print demangled type information of given variable or expression.
... | can't have an incomplete type. |
This macro prints the demangled (as specified by the local cxxabi) RTTI of the input variable or resolved expression, including cvr qualifiers and valueness.
Example usage:
Definition at line 795 of file DebugPrinter.hpp.
#define dout_VAL | ( | ... | ) |
Print highlighted 'name = value' of given variable or expression.
... | the expression to print; must be streamable into the stream object assigned to the currently used fsc::DebugPrinter |
Example usage:
This is a shortcut for preprocessed equivalent of:
Definition at line 768 of file DebugPrinter.hpp.