Classes | |
class | concepts::Stacktrace |
class | concepts::Assertion |
Macros | |
#define | DEBUGL(doit, msg) |
#define | conceptsAssert(cond, exc) { } |
#define | conceptsThrowSimpleE(msg) |
#define | conceptsAssert3(cond, exc, msg) { } |
Various methods and tools for debugging parts of the library or your application.
This is quite simple: make sure you use the -g
flag of the compiler for compiling the library and your application and then use a debugger on the resulting binary. Examples for debuggers are:
I prefer DDD, which should be part of every Linux distribution and is installed on the ETH workstations.
There exists a header file to simplify the creation of debugging output statements: debug.hh. It contains one compiler macros which is important: DEBUGL. This macro is only evaluated if the DEBUG
symbol is defined.
In order to have fine grained debugging possibilities, you should use different symbols in a local debugging header file. For instance:
In our example, all statements with dgBDiffApplOperator_D
are executed. Such a statement could look like this:
The output of the statment above looks like
If you have more complex statements which you would like to hide for production use, you can do something like the following
Like before, these statements are only executed (and even only compiled) if \c DEBUG is defined and \c dgBDiffApplOperator_D is true (ie. non-zero). <h3>Assertions</h3> The class concepts::Assertion can be used to assert certain conditions. \code #include "basics/exceptions.hh"
// ...
const int* m = dynamic_cast<const int*>(n); conceptsAssert(m != 0, Assertion()); cout << *m << endl;
// ...
conceptsAssert3(a == b, Assertion(), "a = " << a << ", b = " << b);
If the assertion fails, an exception of type concepts::Assertion is thrown. If the macro \c conceptsAssert3 is used instead of \c conceptsAssert, the additional information given as the third argument is printed in case of an error. It can be caught by \code try {
// here, an assertion might fail } catch (Assertion& e) { std::cout << e << std::endl; } Instead of catching Assertion
it is also possible to catch ExceptionBase
(the base class of all exceptions in the library).
In case an assertion fails, a stacktrace is printed by calling gdb in concepts::Stacktrace::print. This can be controlled by concepts::Stacktrace::doit:
inhibits printing stack traces.
#define conceptsAssert | ( | cond, | |
exc | |||
) | { } |
Assert that a certain condition is fulfilled. Otherwise, issue an exception (if its not catched, the program is aborted). This is the main routine in the exception mechanism for debug mode error checking. See the Assertion class for more information.
cond | Condition, if unfulfill an exception is thrown |
exc | Exception to throw, if the condition is unfulfilled |
Definition at line 394 of file exceptions.hh.
#define conceptsAssert3 | ( | cond, | |
exc, | |||
msg | |||
) | { } |
Assert that a certain condition is fulfilled. Otherwise, issue an exception (if its not catched, the program is aborted). This is an extention to the conceptsAssert
macro. The additional feature is the third parameter msg:
conceptsAssert3(1 == 0, Assertion(), "add " << "a message" << " here");
gives
[file.cc, line 34] int main(int, char**) -- error Assertion() by violating condition <1 == 0>, add a message here
as error message.
cond | Condition, if unfulfill an exception is thrown |
exc | Exception to throw, if the condition is unfulfilled |
msg | Additional message in stream notation |
Definition at line 442 of file exceptions.hh.
#define conceptsThrowSimpleE | ( | msg | ) |
Throws a equivalent to conceptsAssert(false, exc)
Definition at line 411 of file exceptions.hh.
#define DEBUGL | ( | doit, | |
msg | |||
) |
Debug Line. Prints a debugging message with information about file, line and function where it is located. At the end, the line is wrapped. The message looks like
[file.cc, line 62] void function(double) -- this is the message
doit | The line is only printed if true |
msg | Text in a stream (can include variables etc.) to be printed |