libcwd: The C++ Debugging Support Library - Reference Manual
Author: Carlo Wood
Description: C++ debugging support library with ostream debug output
Keywords: libcwd, debug output, debug facility, debug channel, object orientation, OO, C++, nested debug output, ostream, memory allocation, debugging, source file and line number

Main Page Reference Manual Namespace List Compound List Namespace Members Compound Members File Members

# Nesting Debug Output
[Writing Debug Output]

Collaboration diagram for Nesting Debug Output:

## Calling functions inside Dout

Consider the following code:

    int foobar(void) __attribute__ ((const));

    int foobar(void)
    {
      Dout( dc::notice, "Entering foobar()" );
      Dout( dc::notice, "Leaving foobar()" );
      return 1;
    }

    int main(void)
    {
      Dout( dc::kernel, "The value of foobar() = " << foobar()
          << ", aint that nice?" );
      return foobar();
    }

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.