Static-const-ify ICD loader info strings
[ocl-icd] / ocl_icd_debug.h
1 /**
2 Copyright (c) 2012, Vincent Danjean <Vincent.Danjean@ens-lyon.org>
3 All rights reserved.
4       
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7     
8 1. Redistributions of source code must retain the above copyright notice, this
9    list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright notice,
11    this list of conditions and the following disclaimer in the documentation
12    and/or other materials provided with the distribution.
13         
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25 #ifndef OCL_ICD_LOADER_DEBUG_H
26 #define OCL_ICD_LOADER_DEBUG_H
27
28 #ifdef DEBUG_OCL_ICD_PROVIDE_DUMP_FIELD
29 #  pragma GCC diagnostic push
30 #  pragma GCC diagnostic ignored "-Wcpp"
31 #  define CL_USE_DEPRECATED_OPENCL_1_1_APIS
32 #endif
33 #include <CL/cl.h>
34 #ifdef DEBUG_OCL_ICD_PROVIDE_DUMP_FIELD
35 #  pragma GCC diagnostic pop
36 #endif
37
38 #pragma GCC visibility push(hidden)
39
40 #include "config.h"
41
42 #define D_ALWAYS 0
43 #define D_WARN 1
44 #define D_LOG 2
45 #define D_TRACE 4
46 #define D_DUMP 8
47 #ifdef DEBUG_OCL_ICD
48 #  pragma GCC visibility push(default)
49 #  include <stdio.h>
50 #  include <stdlib.h>
51 #  pragma GCC visibility pop
52 extern int debug_ocl_icd_mask;
53 #  define debug(mask, fmt, ...) do {\
54         if (((mask)==D_ALWAYS) || (debug_ocl_icd_mask & (mask))) {                      \
55                 fprintf(stderr, "ocl-icd(%s:%i): %s: " fmt "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__); \
56         } \
57    } while(0)
58 #  define RETURN(val) do { \
59         __typeof__(val) ret=(val); \
60         debug(D_TRACE, "return: %ld/0x%lx", (long)ret, (long)ret);      \
61         return ret; \
62    } while(0)
63 #  define RETURN_STR(val) do { \
64         char* _ret=(char*)(val);                \
65         debug(D_TRACE, "return: %s", _ret);     \
66         return _ret; \
67    } while(0)
68 #  ifdef DEBUG_OCL_ICD_PROVIDE_DUMP_FIELD
69 #    pragma GCC diagnostic push
70 #      pragma GCC diagnostic ignored "-Wdeprecated-declarations"
71 typedef __typeof__(clGetExtensionFunctionAddress) *clGEFA_t;
72 #    pragma GCC diagnostic pop
73 void dump_platform(clGEFA_t f, cl_platform_id pid);
74 #  endif
75 static inline void debug_init(void) {
76   static int done=0;
77   if (!done) {
78     char *debug=getenv("OCL_ICD_DEBUG");
79     if (debug) {
80       debug_ocl_icd_mask=atoi(debug);
81       if (*debug == 0)
82         debug_ocl_icd_mask=1;
83     }
84     done=1;
85   }
86 }
87
88 #  define dump_field(pid, f, name) \
89     debug(D_ALWAYS, "%40s=%p [%p/%p]", #name, pid->dispatch->name, f(#name), ((long)(pid->dispatch->clGetExtensionFunctionAddressForPlatform)>10)?pid->dispatch->clGetExtensionFunctionAddressForPlatform(pid, #name):NULL)
90
91 #else
92 #  define debug(...) (void)0
93 #  define RETURN(val) return (val)
94 #  define RETURN_STR(val) return (val)
95 #  define debug_init() (void)0
96 #endif
97
98 #define debug_trace() debug(D_TRACE, "Entering")
99
100 #pragma GCC visibility pop
101
102 #endif