1251881Speter/* svn_debug.h : handy little debug tools for the SVN developers
2251881Speter *
3251881Speter * ====================================================================
4251881Speter *    Licensed to the Apache Software Foundation (ASF) under one
5251881Speter *    or more contributor license agreements.  See the NOTICE file
6251881Speter *    distributed with this work for additional information
7251881Speter *    regarding copyright ownership.  The ASF licenses this file
8251881Speter *    to you under the Apache License, Version 2.0 (the
9251881Speter *    "License"); you may not use this file except in compliance
10251881Speter *    with the License.  You may obtain a copy of the License at
11251881Speter *
12251881Speter *      http://www.apache.org/licenses/LICENSE-2.0
13251881Speter *
14251881Speter *    Unless required by applicable law or agreed to in writing,
15251881Speter *    software distributed under the License is distributed on an
16251881Speter *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17251881Speter *    KIND, either express or implied.  See the License for the
18251881Speter *    specific language governing permissions and limitations
19251881Speter *    under the License.
20251881Speter * ====================================================================
21251881Speter */
22251881Speter
23251881Speter#ifndef SVN_DEBUG_H
24251881Speter#define SVN_DEBUG_H
25251881Speter
26251881Speter#ifdef SVN_DEBUG
27251881Speter#define SVN_DBG__PROTOTYPES
28251881Speter#endif
29251881Speter
30251881Speter#ifdef SVN_DBG__PROTOTYPES
31251881Speter#define APR_WANT_STDIO
32251881Speter#include <apr_want.h>
33251881Speter#include <apr_hash.h>
34251881Speter#endif
35251881Speter
36251881Speter#ifdef __cplusplus
37251881Speterextern "C" {
38251881Speter#endif /* __cplusplus */
39251881Speter
40251881Speter#ifdef SVN_DBG__PROTOTYPES
41251881Speter/* A few helper functions for the macros below.  */
42251881Spetervoid
43251881Spetersvn_dbg__preamble(const char *file, long line, FILE *output);
44251881Spetervoid
45251881Spetersvn_dbg__printf(const char *fmt, ...)
46251881Speter  __attribute__((format(printf, 1, 2)));
47251881Spetervoid
48251881Spetersvn_dbg__print_props(apr_hash_t *props,
49251881Speter                     const char *header_fmt,
50251881Speter                     ...)
51251881Speter  __attribute__((format(printf, 2, 3)));
52251881Speter#endif
53251881Speter
54251881Speter/* Only available when SVN_DEBUG is defined (ie. svn developers). Note that
55251881Speter   we do *not* provide replacement macros/functions for proper releases.
56251881Speter   The debug stuff should be removed before a commit.
57251881Speter
58251881Speter   ### maybe we will eventually decide to allow certain debug stuff to
59251881Speter   ### remain in the code. at that point, we can rejigger this header.  */
60251881Speter#ifdef SVN_DEBUG
61251881Speter
62251881Speter/* Print to stdout. Edit this line if you need stderr.  */
63251881Speter#define SVN_DBG_OUTPUT stdout
64251881Speter
65251881Speter
66251881Speter/* Defining this symbol in the source file, BEFORE INCLUDING THIS HEADER,
67251881Speter   will switch off the output. Calls will still be made to svn_dbg__preamble()
68251881Speter   for breakpoints.  */
69251881Speter#ifdef SVN_DBG_QUIET
70251881Speter
71251881Speter#define SVN_DBG(ARGS) svn_dbg__preamble(__FILE__, __LINE__, NULL)
72251881Speter#define SVN_DBG_PROPS(ARGS) svn_dbg__preamble(__FILE__, __LINE__, NULL)
73251881Speter
74251881Speter#else
75251881Speter
76251881Speter/** Debug aid macro that prints the file:line of the call and printf-like
77251881Speter * arguments to the #SVN_DBG_OUTPUT stdio stream (#stdout by default).  Typical
78251881Speter * usage:
79251881Speter *
80251881Speter * <pre>
81251881Speter *   SVN_DBG(("rev=%ld kind=%s\n", revnum, svn_node_kind_to_word(kind)));
82251881Speter * </pre>
83251881Speter *
84251881Speter * outputs:
85251881Speter *
86251881Speter * <pre>
87251881Speter *   DBG: kitchensink.c: 42: rev=3141592 kind=file
88251881Speter * </pre>
89251881Speter *
90251881Speter * Note that these output lines are filtered by our test suite automatically,
91251881Speter * so you don't have to worry about throwing off expected output.
92251881Speter */
93251881Speter#define SVN_DBG(ARGS) (svn_dbg__preamble(__FILE__, __LINE__, SVN_DBG_OUTPUT), \
94251881Speter                       svn_dbg__printf ARGS)
95251881Speter#define SVN_DBG_PROPS(ARGS) (svn_dbg__preamble(__FILE__, __LINE__, \
96251881Speter                                               SVN_DBG_OUTPUT), \
97251881Speter                             svn_dbg__print_props ARGS)
98251881Speter
99251881Speter#endif
100251881Speter
101251881Speter#endif /* SVN_DEBUG */
102251881Speter
103251881Speter#ifdef __cplusplus
104251881Speter}
105251881Speter#endif /* __cplusplus */
106251881Speter
107251881Speter#endif /* SVN_DEBUG_H */
108