[PATCH] debug: Add minimalist D_* macros

Martin Schwenke martin at meltin.net
Fri Jan 6 19:53:59 UTC 2017


On Mon, 5 Dec 2016 15:06:58 -0700, Christof Schmitt <cs at samba.org>
wrote:

> > I think we need to distinguish between what our users need to see when
> > something goes wrong and what we, as developers, need for debugging...  
> 
> The question is where do we want to distinguish between those. Hardcoded
> in the code in the use of D_* and DBG_*, a config option or maybe in the
> DEVELOPER build?

That's a good question.  For certain types of problems you want the
production code to spew out a lot of debug so that a user can show it
to a developer.  Depending on the problem, you might even want to do
this at a non-detailed debug level (e.g. DBGLVL_ERR).

Another point-of-view is that you want to log the low-level stuff at
DBGLVL_DEBUG.  In that case you need a recreate with the debug level
ratcheted up to capture useful information.  

The choice might depend on the maturity of the code.  In early use you
want to see a lot of data, in case you missed a test case.  Once it is
mature, you can simplify the debug.

I recently did a couple of rounds of debugging by adding a D_TRACE
macro, something like:

#define D_TRACE  D_DEBUG("TRACE: %s, %s\n", __location__, __func__ );

I peppered the relevant code with this.  After several iterations, it
was enough to help me find or get close to the problems.  However, I
don't think our users should ever see something like that... it is
just line noise...  :-)

> I am not necessarily disagreeing with your approach, i am mainly trying
> to understand it so that the same approach can be used in all new code.
> 
> My understanding from above is that D_* macros should be used for
> messages that can be seen by users and DBG_* macros should be used for
> messages that are only of interest to developers. If that is correct,
> what about adding a comment to lib/util/debug.h and README.Coding to
> document this?

I don't think it is that clear.  I think we need to sit on this for a
bit longer.  :-)

peace & happiness,
martin



More information about the samba-technical mailing list