1 /*
2 * Copyright © 2009 Pauli Nieminen
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
16 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
17 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
18 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
19 * USE OR OTHER DEALINGS IN THE SOFTWARE.
20 *
21 * The above copyright notice and this permission notice (including the
22 * next paragraph) shall be included in all copies or substantial portions
23 * of the Software.
24 */
25 /*
26 * Authors:
27 * Pauli Nieminen <suokkos@gmail.com>
28 */
29
30 #include "util/debug.h"
31
32 #include "radeon_common_context.h"
33 #include "radeon_debug.h"
34
35 #include <stdarg.h>
36 #include <stdio.h>
37
38 static const struct debug_control debug_control[] = {
39 {"fall", RADEON_FALLBACKS},
40 {"tex", RADEON_TEXTURE},
41 {"ioctl", RADEON_IOCTL},
42 {"verts", RADEON_VERTS},
43 {"render", RADEON_RENDER},
44 {"swrender", RADEON_SWRENDER},
45 {"state", RADEON_STATE},
46 {"shader", RADEON_SHADER},
47 {"vfmt", RADEON_VFMT},
48 {"vtxf", RADEON_VFMT},
49 {"dri", RADEON_DRI},
50 {"dma", RADEON_DMA},
51 {"sanity", RADEON_SANITY},
52 {"sync", RADEON_SYNC},
53 {"pixel", RADEON_PIXEL},
54 {"mem", RADEON_MEMORY},
55 {"cs", RADEON_CS},
56 {"allmsg", ~RADEON_SYNC}, /* avoid the term "sync" because the parser uses strstr */
57 {NULL, 0}
58 };
59
60 #if defined(RADEON_R200)
61 radeon_debug_type_t r200_enabled_debug_types;
62 #elif defined(RADEON_R100)
63 radeon_debug_type_t r100_enabled_debug_types;
64 #endif
65
radeon_init_debug(void)66 void radeon_init_debug(void)
67 {
68 RADEON_DEBUG = parse_debug_string(getenv("RADEON_DEBUG"), debug_control);
69
70 RADEON_DEBUG |= RADEON_GENERAL;
71 }
72
_radeon_debug_add_indent(void)73 void _radeon_debug_add_indent(void)
74 {
75 GET_CURRENT_CONTEXT(ctx);
76 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
77 const size_t length = sizeof(radeon->debug.indent)
78 / sizeof(radeon->debug.indent[0]);
79 if (radeon->debug.indent_depth < length - 1) {
80 radeon->debug.indent[radeon->debug.indent_depth] = '\t';
81 ++radeon->debug.indent_depth;
82 }
83 }
84
_radeon_debug_remove_indent(void)85 void _radeon_debug_remove_indent(void)
86 {
87 GET_CURRENT_CONTEXT(ctx);
88 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
89 if (radeon->debug.indent_depth > 0) {
90 radeon->debug.indent[radeon->debug.indent_depth] = '\0';
91 --radeon->debug.indent_depth;
92 }
93 }
94
_radeon_print(const radeon_debug_type_t type,const radeon_debug_level_t level,const char * message,...)95 void _radeon_print(const radeon_debug_type_t type,
96 const radeon_debug_level_t level,
97 const char* message,
98 ...)
99 {
100 va_list values;
101
102 GET_CURRENT_CONTEXT(ctx);
103 if (ctx) {
104 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
105 // FIXME: Make this multi thread safe
106 if (radeon->debug.indent_depth)
107 fprintf(stderr, "%s", radeon->debug.indent);
108 }
109 va_start( values, message );
110 vfprintf(stderr, message, values);
111 va_end( values );
112 }
113