|
1 /* Copyright (c) 2009 The Khronos Group Inc. |
|
2 * |
|
3 * Permission is hereby granted, free of charge, to any person obtaining a |
|
4 * copy of this software and/or associated documentation files (the |
|
5 * "Materials"), to deal in the Materials without restriction, including |
|
6 * without limitation the rights to use, copy, modify, merge, publish, |
|
7 * distribute, sublicense, and/or sell copies of the Materials, and to |
|
8 * permit persons to whom the Materials are furnished to do so, subject to |
|
9 * the following conditions: |
|
10 * |
|
11 * The above copyright notice and this permission notice shall be included |
|
12 * in all copies or substantial portions of the Materials. |
|
13 * |
|
14 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
|
15 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
17 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
18 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
19 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
20 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
|
21 */ |
|
22 |
|
23 |
|
24 #include "owfdebug.h" |
|
25 #ifdef DEBUG_LOG |
|
26 |
|
27 #include <pthread.h> |
|
28 |
|
29 #include "owfdebug.h" |
|
30 #include "owftypes.h" |
|
31 #include "owfdebug.h" |
|
32 |
|
33 #ifdef __cplusplus |
|
34 extern "C" { |
|
35 #endif |
|
36 |
|
37 |
|
38 #ifndef OWF_DEBUG_PREFIX |
|
39 #define OWF_DEBUG_PREFIX "OWF: " |
|
40 #endif |
|
41 int xprintf(const char* aFormat, ...); |
|
42 |
|
43 /* This pair of macros are a standard trick |
|
44 * to convert the content of a macro into a string after expansion |
|
45 * TOSTR causes the macro to be expanded, then TOSTR2 applies quotes. |
|
46 * This is used because .MMP MACRO does not consistantly process macro value quotes. |
|
47 */ |
|
48 #define TOSTR2(x) #x |
|
49 #define TOSTR(x) TOSTR2(x) |
|
50 |
|
51 |
|
52 /* Filters debug messages based on filename or function name. |
|
53 * @param symbol the file or function name string generated by predefined macros |
|
54 * @param symlen the length of the string (calculated at compile-time) |
|
55 * Defining DEBUG_LOG enables all log file output. Do this in the make or .MMP file |
|
56 * The file output can be filtered by filename or by function name: |
|
57 * Defining DEBUG_FUNCTION=fnname will filter for all functions STARTING with the name fnname |
|
58 * Defining DEBUG_FILE=filename will filter for all functions ending with the name filename |
|
59 * |
|
60 * These filters utilise the predefined macros __FILE__ and __FUNCTION__ which are defined in current standards, |
|
61 * but may contain platform-specific features such as path names, or linkage decoration, |
|
62 * so the filter-string may require some platform-specific tuning. |
|
63 * |
|
64 * Note that use of #pragma message may also be platform-specific, and is only present in order to |
|
65 * print clues about the format of the __FILE__ and __FUNCTION__ macros. |
|
66 */ |
|
67 int OWF_Debug_DoLog(const char* symbol,int symlen) |
|
68 { |
|
69 #if defined(DEBUG_LOG_FILE) |
|
70 #pragma message ("DEBUG filter DEBUG_FILE= '" TOSTR(DEBUG_FILE) "' eg= '" __FILE__ "'") |
|
71 if (symlen>=(sizeof(TOSTR(DEBUG_FILE))-1)) |
|
72 { |
|
73 return strncmp( symbol+symlen-(sizeof(TOSTR(DEBUG_FILE))-1) , TOSTR(DEBUG_FILE) , sizeof(TOSTR(DEBUG_FILE))-1 )==0; |
|
74 } |
|
75 else |
|
76 return 0; |
|
77 #elif defined(DEBUG_LOG_FUNCTION) |
|
78 #pragma message("DEBUG filter DEBUG_FUNCTION= '" TOSTR(DEBUG_FUNCTION) "' eg= '" __FUNCTION__ "'") |
|
79 if (symlen>=(sizeof(TOSTR(DEBUG_FILE))-1)) |
|
80 { |
|
81 return(strncmp(TOSTR(DEBUG_FUNCTION),symbol,sizeof(TOSTR(DEBUG_FUNCTION))-1)==0); |
|
82 } |
|
83 else |
|
84 return 0; |
|
85 #else |
|
86 (void)symbol; |
|
87 (void)symlen; |
|
88 return 1; |
|
89 #endif |
|
90 |
|
91 } |
|
92 |
|
93 void OWF_Debug_Print(const char* format, ...) |
|
94 { |
|
95 va_list ap; |
|
96 char __spager[512]; |
|
97 |
|
98 va_start(ap, format); |
|
99 __spager[0] = 0; |
|
100 vsnprintf(__spager, 511, format, ap); |
|
101 xprintf("%s %s\n", OWF_DEBUG_PREFIX, __spager); |
|
102 va_end(ap); |
|
103 } |
|
104 |
|
105 |
|
106 void OWF_Debug_Trace(const char* fmt, ...) |
|
107 { |
|
108 fmt = fmt; |
|
109 } |
|
110 |
|
111 |
|
112 |
|
113 void OWF_Debug_TraceIndent() |
|
114 { |
|
115 } |
|
116 |
|
117 void OWF_Debug_TraceUndent() |
|
118 { |
|
119 } |
|
120 |
|
121 void OWF_Debug_TraceEnter(const char* func) |
|
122 { |
|
123 if (func) |
|
124 { |
|
125 OWF_Debug_Trace("ENTER %s", func); |
|
126 } |
|
127 OWF_Debug_TraceIndent(); |
|
128 } |
|
129 |
|
130 void OWF_Debug_TraceExit(const char* func) |
|
131 { |
|
132 OWF_Debug_TraceUndent(); |
|
133 if (func) |
|
134 { |
|
135 OWF_Debug_Trace("EXIT %s", func); |
|
136 } |
|
137 } |
|
138 |
|
139 |
|
140 #ifdef __cplusplus |
|
141 } |
|
142 #endif |
|
143 |
|
144 #else |
|
145 |
|
146 |
|
147 #endif /* DEBUG */ |