1 /*
2  * Wine debugging interface
3  *
4  * Copyright 1999 Patrik Stridvall
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
21 #ifndef __WINE_WINE_DEBUG_H
22 #define __WINE_WINE_DEBUG_H
23 
24 #include <stdarg.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <glib.h>
30 
31 G_BEGIN_DECLS
32 
33 /*
34  * Internal definitions (do not use these directly)
35  */
36 
37 enum __wine_debug_class
38 {
39     DBCL_FIXME,
40     DBCL_ERR,
41     DBCL_WARN,
42     DBCL_TRACE,
43 
44     DBCL_INIT = 7  /* lazy init flag */
45 };
46 
47 /*
48  * Exported definitions and macros
49  */
50 
51 /* These functions return a printable version of a string, including
52    quotes.  The string will be valid for some time, but not indefinitely
53    as strings are re-used.  */
wine_dbgstr_an(const char * s,int n)54 static inline const char *wine_dbgstr_an( const char * s, int n )
55 {
56     if (!s) return "";
57     return s;
58 }
59 
60 const char *wine_dbg_sprintf( const char *format, ...) G_GNUC_PRINTF (1, 2);;
61 
62 #define wine_dbg_printf(format,...) (printf(format, ## __VA_ARGS__), fflush(stdout))
63 #define WINE_DPRINTF(class, function, format, ...) \
64      wine_dbg_printf(#class ":%s:" format, function, ## __VA_ARGS__)
65 
wine_dbgstr_a(const char * s)66 static inline const char *wine_dbgstr_a( const char *s )
67 {
68     return wine_dbgstr_an( s, -1 );
69 }
70 
wine_dbgstr_guid(const uint8_t * id)71 static inline const char *wine_dbgstr_guid( const uint8_t *id )
72 {
73     return wine_dbg_sprintf( "{%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
74              id[0], id[1], id[2], id[3], id[4], id[5], id[6], id[7],
75              id[8], id[9], id[10], id[11], id[12], id[13], id[14], id[15]);
76 }
77 
wine_dbgstr_longlong(unsigned long long ll)78 static inline const char *wine_dbgstr_longlong( unsigned long long ll )
79 {
80     if (sizeof(ll) > sizeof(unsigned long) && ll >> 32)
81         return wine_dbg_sprintf( "%lx%08lx", (unsigned long)(ll >> 32), (unsigned long)ll );
82     else return wine_dbg_sprintf( "%lx", (unsigned long)ll );
83 }
84 
85 /* Wine uses shorter names that are very likely to conflict with other software */
86 
debugstr_an(const char * s,int n)87 static inline const char *debugstr_an( const char * s, int n ) { return wine_dbgstr_an( s, n ); }
debugstr_guid(const uint8_t * id)88 static inline const char *debugstr_guid( const uint8_t *id )  { return wine_dbgstr_guid( id ); }
debugstr_a(const char * s)89 static inline const char *debugstr_a( const char *s )  { return wine_dbgstr_an( s, -1 ); }
90 
91 #ifndef TRACE_ON
92 #define TRACE_ON  0
93 #endif
94 
95 #define TRACE(fmt, ...)     G_STMT_START{       \
96   if (TRACE_ON) {                               \
97      g_debug(G_STRLOC " " fmt, ## __VA_ARGS__); \
98   }                                             \
99 }G_STMT_END
100 
101 G_END_DECLS
102 
103 #endif  /* __WINE_WINE_DEBUG_H */
104