Debugging Concepts

Various methods and tools for debugging parts of the library or your application. More...

Classes

class  concepts::Assertion
 Exception class for assertions. More...
 
class  concepts::Stacktrace
 Dumps a stack trace using gdb. More...
 

Macros

#define conceptsAssert(cond, exc)   { }
 Assert that a certain condition is fulfilled. More...
 
#define conceptsAssert3(cond, exc, msg)   { }
 Assert that a certain condition is fulfilled. More...
 
#define conceptsThrowSimpleE(msg)
 Throws a equivalent to conceptsAssert(false, exc) More...
 
#define DEBUGL(doit, msg)
 

Detailed Description

Various methods and tools for debugging parts of the library or your application.

Debugging Concepts with a Debugger

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:

  • GDB: The GNU Debugger, no graphical frontend
  • xxgdb, a graphical frontend to GDB
  • DDD: The Data Display Debugger, a Motif/Lesstif frontend to GDB
  • KDbg, a QT/KDE frontend to GDB
  • UPS, Ups is a source level C,C++ and Fortran debugger that runs under X11. It runs native on some versions of UNIX® (e.g. BSD/OS, FreeBSD, Linux, SunOS & Solaris, etc.), on others it can be built as a front end to GDB.

I prefer DDD, which should be part of every Linux distribution and is installed on the ETH workstations.

Debugging Concepts with Output Statements and Assertions

Output Statements

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:

#include "basics/debug.h"
#ifndef dgDebug_h
#define dgDebug_h
#define dgBDiffApplOperator_D 1
#define dgBDiffIntegrateEdge_D 0
#endif

In our example, all statements with dgBDiffApplOperator_D are executed. Such a statement could look like this:

DEBUGL(dgBDiffApplOperator_D, "elmX: " << quadX.key()
<< ", elmY:", quadY.key());

The output of the statment above looks like

[../dg/dgBForm.cc, line 36] dg_BDiffusion::operator() -- elmX: 1, elmY: 0

If you have more complex statements which you would like to hide for production use, you can do something like the following

#if dgBDiffApplOperator_D
cout << "[" << __FILE__ << ", line " << __LINE__
<< "] dg_BDiffusion::operator() --" << endl;
cout << "blah blub" << endl;
#endif
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).

Stacktrace

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.

Author
Philipp Frauenfelder, 2004

Macro Definition Documentation

◆ conceptsAssert

#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.

Parameters
condCondition, if unfulfill an exception is thrown
excException to throw, if the condition is unfulfilled
See also
Assertion
Test:
test::ExceptionTest
Author
Philipp Frauenfelder, 2000
Examples
hpFEM2d.cc, linearFEM1d-simple.cc, and linearFEM1d.cc.

Definition at line 395 of file exceptions.hh.

◆ conceptsAssert3

#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.

Parameters
condCondition, if unfulfill an exception is thrown
excException to throw, if the condition is unfulfilled
msgAdditional message in stream notation
See also
Assertion
Test:
test::ExceptionTest
Author
Philipp Frauenfelder, 2003

Definition at line 443 of file exceptions.hh.

◆ conceptsThrowSimpleE

#define conceptsThrowSimpleE (   msg)
Value:
{ \
std::stringstream errorMsg; \
errorMsg << msg; \
exception_throw_assert(std::string(__FILE__), __LINE__, \
std::string(__PRETTY_FUNCTION__), \
std::string("SimpleException"), errorMsg.str(), concepts::Assertion()); \
}

Throws a equivalent to conceptsAssert(false, exc)

Author
Holger Brandsmeier, 2010

Definition at line 412 of file exceptions.hh.

◆ DEBUGL

#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
Parameters
doitThe line is only printed if true
msgText in a stream (can include variables etc.) to be printed
Examples
meshes.cc.
static bool & doit()
If doit is set to false, no stacktrace is printed.
Definition: exceptions.hh:39
#define DEBUGL(doit, msg)
Exception class for assertions.
Definition: exceptions.hh:258
#define __PRETTY_FUNCTION__
Definition: exceptions.hh:296
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich