Unifying the GCC Debugging Interface

Original proposal and discussion: http://gcc.gnu.org/ml/gcc/2012-11/msg00222.html

Problem

It is sometimes hard to remember which printing function is used for debugging a type, or even which type you have.

Solution

We propose to rely on overloading to unify the interface to a small set of function names. Every major data type should have associated debug/dump functionality. We will unify the current *_dump/*_debug functions under the same common overloaded name.

We intend to only apply this approach to functions that take the type to display as an argument, and that are routinely used in debugging.

Proposal

We propose to provide a family of template functions with the same common name: dump.

template<typename T>
dump (const T &ptr, int options = 0, int indent = 0, FILE *f = stderr);

template<typename T>
dump (const T *ptr, int options = 0, int indent = 0, FILE *f = stderr)
{
        if (ptr)
                dump (*ptr, options, indent, f);
        else
                fprintf (f, "<nil>");
}

Data structures that want to use this facility, need to provide an instance of

template<typename T>
dump (const T &ptr, int options = 0, int indent = 0, FILE *f = stderr);

The formatting of the dump is affected by the options flags, which can be combined using bitwise OR expressions. Additionally, we will provide named entry points for common combinations of dump options flags.

The valid option values are defined as values of the enumerated type enum dump_options. Initially, this enumerated type will take all the values of the existing TDF_* macro constants.

It is up to each data structure to define the default format emitted by dump(). Some common alternate entry points:

Other Work

None: cxx-conversion/debugging-dumps (last edited 2012-11-27 20:18:40 by LawrenceCrowl)