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);
58 void debug_vprintf(const char *format
, va_list ap
)
62 /* EngDebugPrint does not handle float point arguments, so we need to use
63 * our own vsnprintf implementation */
65 rpl_vsnprintf(buf
, sizeof(buf
), format
, ap
);
66 rpl_EngDebugPrint("%s", buf
);
68 /* TODO: Implement debug print for WINCE */
71 vfprintf(stderr
, format
, ap
);
76 void debug_printf(const char *format
, ...)
80 debug_vprintf(format
, ap
);
85 /* TODO: implement a debug_abort that calls EngBugCheckEx on WIN32 */
88 static INLINE
void debug_break(void)
90 #if (defined(__i386__) || defined(__386__)) && defined(__GNUC__)
92 #elif (defined(__i386__) || defined(__386__)) && defined(__MSC__)
94 #elif defined(WIN32) && !defined(WINCE)
102 ULONG_PTR debug_config_file
= 0;
103 void *mapped_config_file
= 0;
106 eAssertAbortEn
= 0x1,
109 /* Check for aborts enabled. */
110 static unsigned abort_en()
112 if (!mapped_config_file
)
114 /* Open an 8 byte file for configuration data. */
115 mapped_config_file
= EngMapFile(L
"\\??\\c:\\gaDebug.cfg", 8, &debug_config_file
);
117 /* An value of "0" (ascii) in the configuration file will clear the first 8 bits in the test byte. */
118 /* An value of "1" (ascii) in the configuration file will set the first bit in the test byte. */
119 /* An value of "2" (ascii) in the configuration file will set the second bit in the test byte. */
120 return ((((char *)mapped_config_file
)[0]) - 0x30) & eAssertAbortEn
;
123 static unsigned abort_en()
125 return !GETENV("GALLIUM_ABORT_ON_ASSERT");
129 void debug_assert_fail(const char *expr
, const char *file
, unsigned line
)
131 debug_printf("%s:%i: Assertion `%s' failed.\n", file
, line
, expr
);
137 debug_printf("continuing...\n");
142 #define DEBUG_MASK_TABLE_SIZE 256
148 * For now we just take the lower bits of the key, and do no attempt to solve
149 * collisions. Use a proper hash table when we have dozens of drivers.
151 static uint32_t debug_mask_table
[DEBUG_MASK_TABLE_SIZE
];
154 void debug_mask_set(uint32_t uuid
, uint32_t mask
)
156 unsigned hash
= uuid
& (DEBUG_MASK_TABLE_SIZE
- 1);
157 debug_mask_table
[hash
] = mask
;
161 uint32_t debug_mask_get(uint32_t uuid
)
163 unsigned hash
= uuid
& (DEBUG_MASK_TABLE_SIZE
- 1);
164 return debug_mask_table
[hash
];
168 void debug_mask_vprintf(uint32_t uuid
, uint32_t what
, const char *format
, va_list ap
)
170 uint32_t mask
= debug_mask_get(uuid
);
172 debug_vprintf(format
, ap
);