7ddba1ae85f172cf2172947a6d82ddad8b456a93
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_debug.c
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 "utils.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 dri_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 radeon_debug_type_t radeon_enabled_debug_types;
61
62 void radeon_init_debug(void)
63 {
64 radeon_enabled_debug_types = driParseDebugString(getenv("RADEON_DEBUG"), debug_control);
65
66 radeon_enabled_debug_types |= RADEON_GENERAL;
67 }
68
69 void _radeon_debug_add_indent(void)
70 {
71 GET_CURRENT_CONTEXT(ctx);
72 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
73 const size_t length = sizeof(radeon->debug.indent)
74 / sizeof(radeon->debug.indent[0]);
75 if (radeon->debug.indent_depth < length - 1) {
76 radeon->debug.indent[radeon->debug.indent_depth] = '\t';
77 ++radeon->debug.indent_depth;
78 };
79 }
80
81 void _radeon_debug_remove_indent(void)
82 {
83 GET_CURRENT_CONTEXT(ctx);
84 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
85 if (radeon->debug.indent_depth > 0) {
86 radeon->debug.indent[radeon->debug.indent_depth] = '\0';
87 --radeon->debug.indent_depth;
88 }
89 }
90
91 void _radeon_print(const radeon_debug_type_t type,
92 const radeon_debug_level_t level,
93 const char* message,
94 ...)
95 {
96 va_list values;
97
98 GET_CURRENT_CONTEXT(ctx);
99 if (ctx) {
100 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
101 // FIXME: Make this multi thread safe
102 if (radeon->debug.indent_depth)
103 fprintf(stderr, "%s", radeon->debug.indent);
104 }
105 va_start( values, message );
106 vfprintf(stderr, message, values);
107 va_end( values );
108 }