3 * Tracing functions for debugging
5 * (c) 1998 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 /*----- Header files ------------------------------------------------------*/
43 /*----- Data structures ---------------------------------------------------*/
45 typedef struct trace_opt
{
51 /*----- Functions provided ------------------------------------------------*/
55 * Arguments: @unsigned l@ = trace level for output
56 * @const char *f@ = a @printf@-style format string
57 * @...@ = other arguments
61 * Use: Reports a message to the trace output.
64 extern void PRINTF_LIKE(2, 3)
65 trace(unsigned /*l*/, const char */
*f*/
, ...);
67 /* --- @trace_block@ --- *
69 * Arguments: @unsigned l@ = trace level for output
70 * @const char *s@ = some header string to write
71 * @const void *b@ = pointer to a block of memory to dump
72 * @size_t sz@ = size of the block of memory
76 * Use: Dumps the contents of a block to the trace output.
79 extern void trace_block(unsigned /*l*/, const char */
*s*/
,
80 const void */
*b*/
, size_t /*sz*/);
82 /* --- @trace_on@ --- *
84 * Arguments: @FILE *fp@ = a file to trace on
85 * @unsigned l@ = trace level to set
89 * Use: Enables tracing to a file.
92 extern void trace_on(FILE */
*fp*/
, unsigned /*l*/);
94 /* --- @trace_custom@ --- *
96 * Arguments: @void (*func)(const char *buf, size_t sz, void *v)@ =
98 * @void *v@ = magic handle to give to function
102 * Use: Sets up a custom trace handler.
105 extern void trace_custom(void (*/
*func*/
)(const char */
*buf*/
,
106 size_t /*sz*/, void */
*v*/
),
109 /* --- @trace_level@ --- *
111 * Arguments: @unsigned l@ = trace level to set
115 * Use: Sets the tracing level.
118 extern void trace_level(unsigned /*l*/);
120 /* --- @tracing@ --- *
124 * Returns: Zero if not tracing, tracing level if tracing.
126 * Use: Informs the caller whether tracing is enabled.
129 extern unsigned tracing(void);
131 /* --- @traceopt@ --- *
133 * Arguments: @const trace_opt *t@ = pointer to trace options table
134 * @const char *p@ = option string supplied by user
135 * @unsigned f@ = initial tracing flags
136 * @unsigned bad@ = forbidden tracing flags
138 * Returns: Trace flags as set by user.
140 * Use: Parses an option string from the user and sets the
141 * appropriate trace flags. If the argument is null or a single
142 * `?' character, a help message is displayed.
145 extern unsigned traceopt(const trace_opt */
*t*/
, const char */
*p*/
,
146 unsigned /*f*/, unsigned /*bad*/);
148 /*----- Tracing macros ----------------------------------------------------*/
152 # define IF_TRACING(l, x) if ((l) & tracing()) x
155 # define IF_TRACING(l, x)
158 /*----- That's all, folks -------------------------------------------------*/