libcwdversion 2.0.0
The C++ Debugging Support Library
Loading...
Searching...
No Matches
Nesting Debug Output

Keeping debug output readable when it is nested or split over several calls.

Calling functions inside Dout

Consider the following code:

int foobar() __attribute__ ((const));
int foobar()
{
Dout(dc::notice, "Entering foobar()");
Dout(dc::notice, "Leaving foobar()");
return 1;
}
int main()
{
Dout(dc::kernel, "The value of foobar() = " << foobar()
<< ", aint that nice?");
return foobar();
}
#define Dout(cntrl,...)
Macro for writing debug output.
Definition debug.h:97

This code would start a new debug message before the previous debug message is finished.  Libcwd detects this and will output:

NOTICE:     Entering foobar()
NOTICE:     Leaving foobar()
KERNEL: The value of foobar() = 2, aint that nice?

Note the indentation and the fact that the printing of the label KERNEL was delayed.

Using continued_cf, dc::continued and dc::finish

In the previous section foobar() was a const function: it didn't matter whether or not it was called for the functionality of the application. But when it does matter, then one might want to do something like this:

Dout(dc::kernel|flush_cf|continued_cf, "Generating tables... ");
generate_tables();
Dout(dc::finish, "done");

If generate_tables() would not print debug messages, then the output will look like:

KERNEL: Generating tables... done

When it does generated debug output, then the <unfinished> and <continued> labels are printed also:

KERNEL: Generating tables... <unfinished>
NOTICE:     Inside generate_tables()
KERNEL: <continued> done

Finally, it is also possible to split a debug line into more than two parts by using the special dc::continued debug channel.

Dout(dc::notice|flush_cf|continued_cf, "Generating tables.");
for (int i = 0; i < 8; ++i)
{
generate_table(i);
Dout(dc::continued, '.');
}
Dout(dc::finish, " done");

When generate_table(i) doesn't print debug messages, then the output will look like:

NOTICE: Generating tables......... done

When it does generate debug output, then each dot would be surrounded by a <continued> .<unfinished> :

NOTICE: Generating tables.<unfinished>
TABLE :     Inside generate_table(0)
NOTICE: <continued> .<unfinished>

etc.