[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
11.4 Debugging support
When debugging a CLN application with GNU gdb
, two facilities are
available from the library:
- The library does type checks, range checks, consistency checks at
many places. When one of these fails, an exception of a type derived from
runtime_exception
is thrown. When an exception is cought, the stack has already been unwound, so it is may not be possible to tell at which point the exception was thrown. For debugging, it is best to set up a catchpoint at the event of throwning a C++ exception:(gdb) catch throw
When this catchpoint is hit, look at the stack’s backtrace:
(gdb) where
When control over the type of exception is required, it may be possible to set a breakpoint at the
g++
runtime library function__raise_exception
. Refer to the documentation of GNUgdb
for details. - The debugger’s normal
print
command doesn’t know about CLN’s types and therefore prints mostly useless hexadecimal addresses. CLN offers a functioncl_print
, callable from the debugger, for printing number objects. In order to get this function, you have to define the macro ‘CL_DEBUG’ and then include all the header files for which you wantcl_print
debugging support. For example:#define CL_DEBUG #include <cln/string.h>
Now, if you have in your program a variable
cl_string s
, and inspect it undergdb
, the output may look like this:(gdb) print s $7 = {<cl_gcpointer> = { = {pointer = 0x8055b60, heappointer = 0x8055b60, word = 134568800}}, } (gdb) call cl_print(s) (cl_string) "" $8 = 134568800
Note that the output of
cl_print
goes to the program’s error output, not to gdb’s standard output.Note, however, that the above facility does not work with all CLN types, only with number objects and similar. Therefore CLN offers a member function
debug_print()
on all CLN types. The same macro ‘CL_DEBUG’ is needed for this member function to be implemented. Undergdb
, you call it like this:(gdb) print s $7 = {<cl_gcpointer> = { = {pointer = 0x8055b60, heappointer = 0x8055b60, word = 134568800}}, } (gdb) call s.debug_print() (cl_string) "" (gdb) define cprint >call ($1).debug_print() >end (gdb) cprint s (cl_string) ""
Unfortunately, this feature does not seem to work under all circumstances.
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on August 27, 2013 using texi2html 5.0.