radeon: Fix null pointer reference in debug system if no context is bind.
[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_debug.h"
33 #include "radeon_common_context.h"
34
35 static const struct dri_debug_control debug_control[] = {
36 {"fall", RADEON_FALLBACKS},
37 {"tex", RADEON_TEXTURE},
38 {"ioctl", RADEON_IOCTL},
39 {"verts", RADEON_RENDER},
40 {"render", RADEON_RENDER},
41 {"swrender", RADEON_SWRENDER},
42 {"state", RADEON_STATE},
43 {"shader", RADEON_SHADER},
44 {"vfmt", RADEON_VFMT},
45 {"vtxf", RADEON_VFMT},
46 {"dri", RADEON_DRI},
47 {"dma", RADEON_DMA},
48 {"sanity", RADEON_SANITY},
49 {"sync", RADEON_SYNC},
50 {"pixel", RADEON_PIXEL},
51 {"mem", RADEON_MEMORY},
52 {"cs", RADEON_CS},
53 {"allmsg", ~RADEON_SYNC}, /* avoid the term "sync" because the parser uses strstr */
54 {NULL, 0}
55 };
56
57 radeon_debug_type_t radeon_enabled_debug_types;
58
59 void radeon_init_debug(void)
60 {
61 radeon_enabled_debug_types = driParseDebugString(getenv("RADEON_DEBUG"), debug_control);
62
63 radeon_enabled_debug_types |= RADEON_GENERAL;
64 }
65
66 void _radeon_debug_add_indent(void)
67 {
68 GET_CURRENT_CONTEXT(ctx);
69 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
70 const size_t length = sizeof(radeon->debug.indent)
71 / sizeof(radeon->debug.indent[0]);
72 if (radeon->debug.indent_depth < length - 1) {
73 radeon->debug.indent[radeon->debug.indent_depth] = '\t';
74 ++radeon->debug.indent_depth;
75 };
76 }
77
78 void _radeon_debug_remove_indent(void)
79 {
80 GET_CURRENT_CONTEXT(ctx);
81 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
82 if (radeon->debug.indent_depth > 0) {
83 radeon->debug.indent[radeon->debug.indent_depth] = '\0';
84 --radeon->debug.indent_depth;
85 }
86 }
87
88 extern void _radeon_print(const radeon_debug_type_t type,
89 const radeon_debug_level_t level,
90 const char* message,
91 va_list values)
92 {
93 GET_CURRENT_CONTEXT(ctx);
94 if (ctx) {
95 radeonContextPtr radeon = RADEON_CONTEXT(ctx);
96 // FIXME: Make this multi thread safe
97 if (radeon->debug.indent_depth)
98 fprintf(stderr, "%s", radeon->debug.indent);
99 }
100 vfprintf(stderr, message, values);
101 }