1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
39 #include "pipe/p_compiler.h"
40 #include "pipe/p_util.h"
41 #include "pipe/p_debug.h"
46 rpl_EngDebugPrint(const char *format
, ...)
50 EngDebugPrint("", (PCHAR
)format
, ap
);
54 int rpl_vsnprintf(char *, size_t, const char *, va_list);
55 int rpl_snprintf(char *str
, size_t size
, const char *format
, ...);
56 #define vsnprintf rpl_vsnprintf
57 #define snprintf rpl_snprintf
61 void debug_vprintf(const char *format
, va_list ap
)
65 /* EngDebugPrint does not handle float point arguments, so we need to use
66 * our own vsnprintf implementation */
68 rpl_vsnprintf(buf
, sizeof(buf
), format
, ap
);
69 rpl_EngDebugPrint("%s", buf
);
71 /* TODO: Implement debug print for WINCE */
74 vfprintf(stderr
, format
, ap
);
79 void debug_printf(const char *format
, ...)
83 debug_vprintf(format
, ap
);
88 void debug_print_blob( const char *name
,
92 const unsigned *ublob
= (const unsigned *)blob
;
95 debug_printf("%s (%d dwords%s)\n", name
, size
/4,
96 size
%4 ? "... plus a few bytes" : "");
98 for (i
= 0; i
< size
/4; i
++) {
99 debug_printf("%d:\t%08x\n", i
, ublob
[i
]);
104 /* TODO: implement a debug_abort that calls EngBugCheckEx on WIN32 */
107 static INLINE
void debug_break(void)
109 #if (defined(__i386__) || defined(__386__)) && defined(__GNUC__)
111 #elif (defined(__i386__) || defined(__386__)) && defined(__MSC__)
113 #elif defined(WIN32) && !defined(WINCE)
121 ULONG_PTR debug_config_file
= 0;
122 void *mapped_config_file
= 0;
125 eAssertAbortEn
= 0x1,
128 /* Check for aborts enabled. */
129 static unsigned abort_en()
131 if (!mapped_config_file
)
133 /* Open an 8 byte file for configuration data. */
134 mapped_config_file
= EngMapFile(L
"\\??\\c:\\gaDebug.cfg", 8, &debug_config_file
);
137 /* A value of "0" (ascii) in the configuration file will clear the
138 * first 8 bits in the test byte.
140 * A value of "1" (ascii) in the configuration file will set the
141 * first bit in the test byte.
143 * A value of "2" (ascii) in the configuration file will set the
144 * second bit in the test byte.
146 * Currently the only interesting values are 0 and 1, which clear
147 * and set abort-on-assert behaviour respectively.
149 return ((((char *)mapped_config_file
)[0]) - 0x30) & eAssertAbortEn
;
152 static unsigned abort_en()
154 return !GETENV("GALLIUM_ABORT_ON_ASSERT");
158 void debug_assert_fail(const char *expr
, const char *file
, unsigned line
)
160 debug_printf("%s:%i: Assertion `%s' failed.\n", file
, line
, expr
);
166 debug_printf("continuing...\n");
171 #define DEBUG_MASK_TABLE_SIZE 256
177 * For now we just take the lower bits of the key, and do no attempt to solve
178 * collisions. Use a proper hash table when we have dozens of drivers.
180 static uint32_t debug_mask_table
[DEBUG_MASK_TABLE_SIZE
];
183 void debug_mask_set(uint32_t uuid
, uint32_t mask
)
185 unsigned hash
= uuid
& (DEBUG_MASK_TABLE_SIZE
- 1);
186 debug_mask_table
[hash
] = mask
;
190 uint32_t debug_mask_get(uint32_t uuid
)
192 unsigned hash
= uuid
& (DEBUG_MASK_TABLE_SIZE
- 1);
193 return debug_mask_table
[hash
];
197 void debug_mask_vprintf(uint32_t uuid
, uint32_t what
, const char *format
, va_list ap
)
199 uint32_t mask
= debug_mask_get(uuid
);
201 debug_vprintf(format
, ap
);
206 debug_dump_enum(const struct debug_named_value
*names
,
209 static char rest
[256];
212 if(names
->value
== value
)
217 snprintf(rest
, sizeof(rest
), "0x%08x", value
);
223 debug_dump_flags(const struct debug_named_value
*names
,
226 static char output
[4096];
227 static char rest
[256];
233 if((names
->value
& value
) == names
->value
) {
235 strncat(output
, "|", sizeof(output
));
238 strncat(output
, names
->name
, sizeof(output
));
239 value
&= ~names
->value
;
246 strncat(output
, "|", sizeof(output
));
250 snprintf(rest
, sizeof(rest
), "0x%08x", value
);
251 strncat(output
, rest
, sizeof(output
));