Merge branch 'upstream-gallium-0.1' into nouveau-gallium-0.1
[mesa.git] / src / gallium / auxiliary / util / p_debug.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 #include <stdarg.h>
30
31 #ifdef WIN32
32 #include <windows.h>
33 #include <winddi.h>
34 #else
35 #include <stdio.h>
36 #include <stdlib.h>
37 #endif
38
39 #include "pipe/p_debug.h"
40 #include "pipe/p_compiler.h"
41
42
43 void debug_vprintf(const char *format, va_list ap)
44 {
45 #ifdef WIN32
46 EngDebugPrint("Gallium3D: ", (PCHAR)format, ap);
47 #else
48 vfprintf(stderr, format, ap);
49 #endif
50 }
51
52
53 void debug_printf(const char *format, ...)
54 {
55 va_list ap;
56 va_start(ap, format);
57 debug_vprintf(format, ap);
58 va_end(ap);
59 }
60
61
62 static INLINE void debug_abort(void)
63 {
64 #ifdef WIN32
65 EngDebugBreak();
66 #else
67 abort();
68 #endif
69 }
70
71
72 void debug_assert_fail(const char *expr, const char *file, unsigned line)
73 {
74 debug_printf("%s:%i: Assertion `%s' failed.\n", file, line, expr);
75 debug_abort();
76 }