1/* svn_debug.h : handy little debug tools for the SVN developers
2 *
3 * ====================================================================
4 *    Licensed to the Apache Software Foundation (ASF) under one
5 *    or more contributor license agreements.  See the NOTICE file
6 *    distributed with this work for additional information
7 *    regarding copyright ownership.  The ASF licenses this file
8 *    to you under the Apache License, Version 2.0 (the
9 *    "License"); you may not use this file except in compliance
10 *    with the License.  You may obtain a copy of the License at
11 *
12 *      http://www.apache.org/licenses/LICENSE-2.0
13 *
14 *    Unless required by applicable law or agreed to in writing,
15 *    software distributed under the License is distributed on an
16 *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 *    KIND, either express or implied.  See the License for the
18 *    specific language governing permissions and limitations
19 *    under the License.
20 * ====================================================================
21 */
22
23#ifndef SVN_DEBUG_H
24#define SVN_DEBUG_H
25
26#ifdef SVN_DEBUG
27#define SVN_DBG__PROTOTYPES
28#endif
29
30#ifdef SVN_DBG__PROTOTYPES
31#define APR_WANT_STDIO
32#include <apr_want.h>
33#include <apr_hash.h>
34#endif
35
36#ifdef __cplusplus
37extern "C" {
38#endif /* __cplusplus */
39
40#ifdef SVN_DBG__PROTOTYPES
41/* A few helper functions for the macros below.  */
42void
43svn_dbg__preamble(const char *file, long line, FILE *output);
44void
45svn_dbg__printf(const char *fmt, ...)
46  __attribute__((format(printf, 1, 2)));
47void
48svn_dbg__print_props(apr_hash_t *props,
49                     const char *header_fmt,
50                     ...)
51  __attribute__((format(printf, 2, 3)));
52#endif
53
54/* Only available when SVN_DEBUG is defined (ie. svn developers). Note that
55   we do *not* provide replacement macros/functions for proper releases.
56   The debug stuff should be removed before a commit.
57
58   ### maybe we will eventually decide to allow certain debug stuff to
59   ### remain in the code. at that point, we can rejigger this header.  */
60#ifdef SVN_DEBUG
61
62/* Print to stdout. Edit this line if you need stderr.  */
63#define SVN_DBG_OUTPUT stdout
64
65
66/* Defining this symbol in the source file, BEFORE INCLUDING THIS HEADER,
67   will switch off the output. Calls will still be made to svn_dbg__preamble()
68   for breakpoints.  */
69#ifdef SVN_DBG_QUIET
70
71#define SVN_DBG(ARGS) svn_dbg__preamble(__FILE__, __LINE__, NULL)
72#define SVN_DBG_PROPS(ARGS) svn_dbg__preamble(__FILE__, __LINE__, NULL)
73
74#else
75
76/** Debug aid macro that prints the file:line of the call and printf-like
77 * arguments to the #SVN_DBG_OUTPUT stdio stream (#stdout by default).  Typical
78 * usage:
79 *
80 * <pre>
81 *   SVN_DBG(("rev=%ld kind=%s\n", revnum, svn_node_kind_to_word(kind)));
82 * </pre>
83 *
84 * outputs:
85 *
86 * <pre>
87 *   DBG: kitchensink.c: 42: rev=3141592 kind=file
88 * </pre>
89 *
90 * Note that these output lines are filtered by our test suite automatically,
91 * so you don't have to worry about throwing off expected output.
92 */
93#define SVN_DBG(ARGS) (svn_dbg__preamble(__FILE__, __LINE__, SVN_DBG_OUTPUT), \
94                       svn_dbg__printf ARGS)
95#define SVN_DBG_PROPS(ARGS) (svn_dbg__preamble(__FILE__, __LINE__, \
96                                               SVN_DBG_OUTPUT), \
97                             svn_dbg__print_props ARGS)
98
99#endif
100
101#endif /* SVN_DEBUG */
102
103#ifdef __cplusplus
104}
105#endif /* __cplusplus */
106
107#endif /* SVN_DEBUG_H */
108