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
);
80 void debug_print_blob( const char *name
,
84 const unsigned *ublob
= (const unsigned *)blob
;
87 debug_printf("%s (%d dwords%s)\n", name
, size
/4,
88 size
%4 ? "... plus a few bytes" : "");
90 for (i
= 0; i
< size
/4; i
++) {
91 debug_printf("%d:\t%08x\n", i
, ublob
[i
]);
97 void _debug_break(void)
99 #if (defined(__i386__) || defined(__386__)) && defined(__GNUC__)
101 #elif (defined(__i386__) || defined(__386__)) && defined(__MSC__)
103 #elif defined(WIN32) && !defined(WINCE)
111 ULONG_PTR debug_config_file
= 0;
112 void *mapped_config_file
= 0;
115 eAssertAbortEn
= 0x1,
118 /* Check for aborts enabled. */
119 static unsigned abort_en()
121 if (!mapped_config_file
)
123 /* Open an 8 byte file for configuration data. */
124 mapped_config_file
= EngMapFile(L
"\\??\\c:\\gaDebug.cfg", 8, &debug_config_file
);
127 /* A value of "0" (ascii) in the configuration file will clear the
128 * first 8 bits in the test byte.
130 * A value of "1" (ascii) in the configuration file will set the
131 * first bit in the test byte.
133 * A value of "2" (ascii) in the configuration file will set the
134 * second bit in the test byte.
136 * Currently the only interesting values are 0 and 1, which clear
137 * and set abort-on-assert behaviour respectively.
139 return ((((char *)mapped_config_file
)[0]) - 0x30) & eAssertAbortEn
;
142 static unsigned abort_en()
144 return !GETENV("GALLIUM_ABORT_ON_ASSERT");
148 void _debug_assert_fail(const char *expr
,
151 const char *function
)
153 _debug_printf("%s:%u:%s: Assertion `%s' failed.\n", file
, line
, function
, expr
);
159 _debug_printf("continuing...\n");
165 debug_dump_enum(const struct debug_named_value
*names
,
168 static char rest
[256];
171 if(names
->value
== value
)
176 snprintf(rest
, sizeof(rest
), "0x%08lx", value
);
182 debug_dump_flags(const struct debug_named_value
*names
,
185 static char output
[4096];
186 static char rest
[256];
192 if((names
->value
& value
) == names
->value
) {
194 strncat(output
, "|", sizeof(output
));
197 strncat(output
, names
->name
, sizeof(output
));
198 value
&= ~names
->value
;
205 strncat(output
, "|", sizeof(output
));
209 snprintf(rest
, sizeof(rest
), "0x%08lx", value
);
210 strncat(output
, rest
, sizeof(output
));