ReactOS 0.4.17-dev-934-g091855f
debug.c File Reference
#include "vkd3d_common.h"
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include "vkd3d_memory.h"
Include dependency graph for debug.c:

Go to the source code of this file.

Macros

#define VKD3D_DEBUG_BUFFER_COUNT   64
 
#define VKD3D_DEBUG_BUFFER_SIZE   512
 

Functions

enum vkd3d_dbg_level vkd3d_dbg_get_level (void)
 
static void vkd3d_dbg_voutput (const char *fmt, va_list args)
 
static void vkd3d_dbg_output (const char *fmt,...)
 
void vkd3d_dbg_printf (enum vkd3d_dbg_level level, const char *function, const char *fmt,...)
 
void vkd3d_dbg_set_log_callback (PFN_vkd3d_log callback)
 
static char * get_buffer (void)
 
const char * vkd3d_dbg_vsprintf (const char *fmt, va_list args)
 
const char * vkd3d_dbg_sprintf (const char *fmt,...)
 
static int get_escape_char (int c)
 
const char * debugstr_an (const char *str, size_t n)
 
const char * debugstr_a (const char *str)
 
static const char * debugstr_w16 (const uint16_t *wstr)
 
static const char * debugstr_w32 (const uint32_t *wstr)
 
const char * debugstr_w (const WCHAR *wstr, size_t wchar_size)
 
unsigned int vkd3d_env_var_as_uint (const char *name, unsigned int default_value)
 
static bool is_option_separator (char c)
 
bool vkd3d_debug_list_has_member (const char *string, const char *member)
 
uint64_t vkd3d_parse_debug_options (const char *string, const struct vkd3d_debug_option *options, unsigned int option_count)
 
void vkd3d_set_thread_name (const char *name)
 

Variables

const char *const vkd3d_dbg_env_name
 
static const char *const debug_level_names []
 
static PFN_vkd3d_log log_callback
 

Macro Definition Documentation

◆ VKD3D_DEBUG_BUFFER_COUNT

#define VKD3D_DEBUG_BUFFER_COUNT   64

Definition at line 40 of file debug.c.

◆ VKD3D_DEBUG_BUFFER_SIZE

#define VKD3D_DEBUG_BUFFER_SIZE   512

Definition at line 41 of file debug.c.

Function Documentation

◆ debugstr_a()

const char * debugstr_a ( const char *  str)

Definition at line 222 of file debug.c.

223{
224 return debugstr_an(str, SIZE_MAX);
225}
#define SIZE_MAX
Definition: limits.h:49
const WCHAR * str
const char * debugstr_an(const char *str, size_t n)
Definition: debug.c:173

◆ debugstr_an()

const char * debugstr_an ( const char *  str,
size_t  n 
)

Definition at line 173 of file debug.c.

174{
175 char *buffer, *ptr;
176 int escape_char;
177 char c;
178
179 if (!str)
180 return "(null)";
181 if (n == SIZE_MAX)
182 n = strlen(str);
183
184 ptr = buffer = get_buffer();
185
186 *ptr++ = '"';
187 while (n-- && ptr <= buffer + VKD3D_DEBUG_BUFFER_SIZE - 8)
188 {
189 c = *str++;
190
191 if ((escape_char = get_escape_char(c)))
192 {
193 *ptr++ = '\\';
194 *ptr++ = escape_char;
195 continue;
196 }
197
198 if (isprint(c))
199 {
200 *ptr++ = c;
201 }
202 else
203 {
204 *ptr++ = '\\';
205 sprintf(ptr, "%02x", c);
206 ptr += 2;
207 }
208 }
209 *ptr++ = '"';
210
211 if (++n)
212 {
213 *ptr++ = '.';
214 *ptr++ = '.';
215 *ptr++ = '.';
216 }
217 *ptr = '\0';
218
219 return buffer;
220}
#define isprint(c)
Definition: acclib.h:73
_ACRTIMP size_t __cdecl strlen(const char *)
Definition: string.c:1597
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
const GLubyte * c
Definition: glext.h:8905
#define c
Definition: ke_i.h:80
static PVOID ptr
Definition: dispmode.c:27
#define sprintf
Definition: sprintf.c:45
#define VKD3D_DEBUG_BUFFER_SIZE
Definition: debug.c:41
static char * get_buffer(void)
Definition: debug.c:124
static int get_escape_char(int c)
Definition: debug.c:155

Referenced by debugstr_a().

◆ debugstr_w()

const char * debugstr_w ( const WCHAR *  wstr,
size_t  wchar_size 
)

Definition at line 319 of file debug.c.

320{
321 if (wchar_size == 2)
322 return debugstr_w16((const uint16_t *)wstr);
323 return debugstr_w32((const uint32_t *)wstr);
324}
UINT32 uint32_t
Definition: types.h:75
unsigned short uint16_t
Definition: stdint.h:35
static const char * debugstr_w32(const uint32_t *wstr)
Definition: debug.c:273
static const char * debugstr_w16(const uint16_t *wstr)
Definition: debug.c:227

◆ debugstr_w16()

static const char * debugstr_w16 ( const uint16_t *  wstr)
static

Definition at line 227 of file debug.c.

228{
229 char *buffer, *ptr;
230 uint16_t c;
231
232 if (!wstr)
233 return "(null)";
234
235 ptr = buffer = get_buffer();
236
237 *ptr++ = '"';
238 while ((c = *wstr++) && ptr <= buffer + VKD3D_DEBUG_BUFFER_SIZE - 10)
239 {
240 int escape_char = get_escape_char(c);
241
242 if (escape_char)
243 {
244 *ptr++ = '\\';
245 *ptr++ = escape_char;
246 continue;
247 }
248
249 if (isprint(c))
250 {
251 *ptr++ = c;
252 }
253 else
254 {
255 *ptr++ = '\\';
256 sprintf(ptr, "%04x", c);
257 ptr += 4;
258 }
259 }
260 *ptr++ = '"';
261
262 if (c)
263 {
264 *ptr++ = '.';
265 *ptr++ = '.';
266 *ptr++ = '.';
267 }
268 *ptr = '\0';
269
270 return buffer;
271}

Referenced by debugstr_w().

◆ debugstr_w32()

static const char * debugstr_w32 ( const uint32_t *  wstr)
static

Definition at line 273 of file debug.c.

274{
275 char *buffer, *ptr;
276 uint32_t c;
277
278 if (!wstr)
279 return "(null)";
280
281 ptr = buffer = get_buffer();
282
283 *ptr++ = '"';
284 while ((c = *wstr++) && ptr <= buffer + VKD3D_DEBUG_BUFFER_SIZE - 10)
285 {
286 int escape_char = get_escape_char(c);
287
288 if (escape_char)
289 {
290 *ptr++ = '\\';
291 *ptr++ = escape_char;
292 continue;
293 }
294
295 if (isprint(c))
296 {
297 *ptr++ = c;
298 }
299 else
300 {
301 *ptr++ = '\\';
302 sprintf(ptr, "%04x", c);
303 ptr += 4;
304 }
305 }
306 *ptr++ = '"';
307
308 if (c)
309 {
310 *ptr++ = '.';
311 *ptr++ = '.';
312 *ptr++ = '.';
313 }
314 *ptr = '\0';
315
316 return buffer;
317}

Referenced by debugstr_w().

◆ get_buffer()

static char * get_buffer ( void  )
static

Definition at line 124 of file debug.c.

125{
127 static unsigned int buffer_index;
128 unsigned int current_index;
129
130 current_index = vkd3d_atomic_increment_u32(&buffer_index) % ARRAY_SIZE(buffers);
131 return buffers[current_index];
132}
#define ARRAY_SIZE(A)
Definition: main.h:20
const GLuint * buffers
Definition: glext.h:5916
#define VKD3D_DEBUG_BUFFER_COUNT
Definition: debug.c:40
static uint32_t vkd3d_atomic_increment_u32(uint32_t volatile *x)
Definition: vkd3d_common.h:482

Referenced by debugstr_an(), debugstr_w16(), debugstr_w32(), find_actctx_dll(), jpeg_fill_bit_buffer(), jpeg_huff_decode(), RtlDosApplyFileIsolationRedirection_Ustr(), and vkd3d_dbg_vsprintf().

◆ get_escape_char()

static int get_escape_char ( int  c)
static

Definition at line 155 of file debug.c.

156{
157 switch (c)
158 {
159 case '"':
160 case '\\':
161 return c;
162 case '\t':
163 return 't';
164 case '\n':
165 return 'n';
166 case '\r':
167 return 'r';
168 default:
169 return 0;
170 }
171}

Referenced by debugstr_an(), debugstr_w16(), and debugstr_w32().

◆ is_option_separator()

static bool is_option_separator ( char  c)
static

Definition at line 343 of file debug.c.

344{
345 return c == ',' || c == ';' || c == '\0';
346}

Referenced by vkd3d_debug_list_has_member().

◆ vkd3d_dbg_get_level()

enum vkd3d_dbg_level vkd3d_dbg_get_level ( void  )

Definition at line 55 of file debug.c.

56{
57 static unsigned int level = ~0u;
58 const char *vkd3d_debug;
59 unsigned int i;
60
61 if (level != ~0u)
62 return level;
63
64 if (!(vkd3d_debug = getenv(vkd3d_dbg_env_name)))
65 vkd3d_debug = "";
66
67 for (i = 0; i < ARRAY_SIZE(debug_level_names); ++i)
68 {
69 if (!strcmp(debug_level_names[i], vkd3d_debug))
70 {
71 level = i;
72 return level;
73 }
74 }
75
76 /* Default debug level. */
78 return level;
79}
char *CDECL getenv(const char *name)
Definition: environ.c:227
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
GLint level
Definition: gl.h:1546
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
static const char *const debug_level_names[]
Definition: debug.c:45
const char *const vkd3d_dbg_env_name
@ VKD3D_DBG_LEVEL_FIXME
Definition: vkd3d_common.h:147

Referenced by vkd3d_dbg_printf().

◆ vkd3d_dbg_output()

static void vkd3d_dbg_output ( const char *  fmt,
  ... 
)
static

Definition at line 91 of file debug.c.

92{
94
97 va_end(args);
98}
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
static void vkd3d_dbg_voutput(const char *fmt, va_list args)
Definition: debug.c:83
#define args
Definition: format.c:66
Definition: match.c:390
Definition: dsound.c:943

Referenced by vkd3d_dbg_printf().

◆ vkd3d_dbg_printf()

void vkd3d_dbg_printf ( enum vkd3d_dbg_level  level,
const char *  function,
const char *  fmt,
  ... 
)

Definition at line 100 of file debug.c.

101{
103
105 return;
106
107#ifdef _WIN32
108 vkd3d_dbg_output("vkd3d:%04lx:%s:%s ", GetCurrentThreadId(), debug_level_names[level], function);
109#elif HAVE_GETTID
110 vkd3d_dbg_output("vkd3d:%u:%s:%s ", gettid(), debug_level_names[level], function);
111#else
112 vkd3d_dbg_output("vkd3d:%s:%s ", debug_level_names[level], function);
113#endif
114 va_start(args, fmt);
116 va_end(args);
117}
pid_t gettid(void)
enum vkd3d_dbg_level vkd3d_dbg_get_level(void)
Definition: debug.c:55
static void vkd3d_dbg_output(const char *fmt,...)
Definition: debug.c:91
DWORD WINAPI GetCurrentThreadId(void)
Definition: thread.c:459

◆ vkd3d_dbg_set_log_callback()

void vkd3d_dbg_set_log_callback ( PFN_vkd3d_log  callback)

Definition at line 119 of file debug.c.

120{
122}
static IPrintDialogCallback callback
Definition: printdlg.c:325
static PFN_vkd3d_log log_callback
Definition: debug.c:81

Referenced by vkd3d_set_log_callback(), and vkd3d_shader_set_log_callback().

◆ vkd3d_dbg_sprintf()

const char * vkd3d_dbg_sprintf ( const char *  fmt,
  ... 
)

Definition at line 144 of file debug.c.

145{
146 const char *buffer;
148
149 va_start(args, fmt);
151 va_end(args);
152 return buffer;
153}
const char * vkd3d_dbg_vsprintf(const char *fmt, va_list args)
Definition: debug.c:134

◆ vkd3d_dbg_voutput()

static void vkd3d_dbg_voutput ( const char *  fmt,
va_list  args 
)
static

Definition at line 83 of file debug.c.

84{
85 if (log_callback)
87 else
89}
int CDECL vfprintf(FILE *file, const char *format, va_list valist)
Definition: file.c:5349
#define stderr

Referenced by vkd3d_dbg_output(), and vkd3d_dbg_printf().

◆ vkd3d_dbg_vsprintf()

const char * vkd3d_dbg_vsprintf ( const char *  fmt,
va_list  args 
)

Definition at line 134 of file debug.c.

135{
136 char *buffer;
137
138 buffer = get_buffer();
141 return buffer;
142}
#define vsnprintf
Definition: acwin.h:108

Referenced by d3d12_command_list_mark_as_invalid(), d3d12_device_mark_as_removed(), and vkd3d_dbg_sprintf().

◆ vkd3d_debug_list_has_member()

bool vkd3d_debug_list_has_member ( const char *  string,
const char *  member 
)

Definition at line 348 of file debug.c.

349{
350 char prev_char, next_char;
351 const char *p;
352
353 p = string;
354 while (p)
355 {
356 if ((p = strstr(p, member)))
357 {
358 prev_char = p > string ? p[-1] : 0;
359 p += strlen(member);
360 next_char = *p;
361
362 if (is_option_separator(prev_char) && is_option_separator(next_char))
363 return true;
364 }
365 }
366
367 return false;
368}
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3420
GLfloat GLfloat p
Definition: glext.h:8902
char string[160]
Definition: util.h:11
static bool is_option_separator(char c)
Definition: debug.c:343

Referenced by is_extension_disabled(), and vkd3d_parse_debug_options().

◆ vkd3d_env_var_as_uint()

unsigned int vkd3d_env_var_as_uint ( const char *  name,
unsigned int  default_value 
)

Definition at line 326 of file debug.c.

327{
328 const char *value = getenv(name);
329 unsigned long r;
330 char *end_ptr;
331
332 if (value)
333 {
334 errno = 0;
335 r = strtoul(value, &end_ptr, 0);
336 if (!errno && end_ptr != value)
337 return min(r, UINT_MAX);
338 }
339
340 return default_value;
341}
#define errno
Definition: errno.h:120
#define UINT_MAX
Definition: limits.h:27
_ACRTIMP __msvcrt_ulong __cdecl strtoul(const char *, char **, int)
Definition: string.c:1864
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
#define min(a, b)
Definition: monoChain.cc:55
Definition: name.c:39
Definition: pdh_main.c:64

Referenced by vkd3d_create_vk_device().

◆ vkd3d_parse_debug_options()

uint64_t vkd3d_parse_debug_options ( const char *  string,
const struct vkd3d_debug_option *  options,
unsigned int  option_count 
)

Definition at line 370 of file debug.c.

372{
373 uint64_t flags = 0;
374 unsigned int i;
375
376 for (i = 0; i < option_count; ++i)
377 {
378 const struct vkd3d_debug_option *opt = &options[i];
379
380 if (vkd3d_debug_list_has_member(string, opt->name))
381 flags |= opt->flag;
382 }
383
384 return flags;
385}
UINT64 uint64_t
Definition: types.h:77
GLbitfield flags
Definition: glext.h:7161
bool vkd3d_debug_list_has_member(const char *string, const char *member)
Definition: debug.c:348
const char * name
Definition: vkd3d_common.h:271

Referenced by vkd3d_init_config_flags(), and vkd3d_shader_init_config_flags().

◆ vkd3d_set_thread_name()

void vkd3d_set_thread_name ( const char *  name)

Definition at line 405 of file debug.c.

406{
407#ifdef _WIN32
409 WCHAR *wname;
410 int ret;
411
412 InitOnceExecuteOnce(&init_once, resolve_SetThreadDescription, NULL, NULL);
413 if (!pfn_SetThreadDescription)
414 return;
415
416 if ((ret = MultiByteToWideChar(CP_UTF8, 0, name, -1, NULL, 0)) <= 0)
417 return;
418
419 if (!(wname = vkd3d_malloc(ret * sizeof(*wname))))
420 return;
421
422 if ((ret = MultiByteToWideChar(CP_UTF8, 0, name, -1, wname, ret)) > 0)
423 pfn_SetThreadDescription(GetCurrentThread(), wname);
424
425 vkd3d_free(wname);
426#elif defined(HAVE_PTHREAD_SETNAME_NP_2)
427 pthread_setname_np(pthread_self(), name);
428#elif defined(HAVE_PTHREAD_SETNAME_NP_1)
429 pthread_setname_np(name);
430#endif
431}
#define NULL
Definition: types.h:112
#define MultiByteToWideChar
Definition: compat.h:110
BOOL WINAPI InitOnceExecuteOnce(_Inout_ PINIT_ONCE InitOnce, _In_ __callback PINIT_ONCE_FN InitFn, _Inout_opt_ PVOID Parameter, _Outptr_opt_result_maybenull_ LPVOID *Context)
Definition: InitOnce.c:12
return ret
Definition: mutex.c:147
short WCHAR
Definition: pedump.c:58
#define CP_UTF8
Definition: nls.h:20
static INIT_ONCE init_once
Definition: vfwcapture.c:981
static void vkd3d_free(void *ptr)
Definition: vkd3d_memory.h:52
static void * vkd3d_malloc(size_t size)
Definition: vkd3d_memory.h:28
HANDLE WINAPI GetCurrentThread(void)
Definition: proc.c:1195
RTL_RUN_ONCE INIT_ONCE
Definition: winbase.h:3654
#define INIT_ONCE_STATIC_INIT
Definition: winbase.h:591

Referenced by device_worker_main(), and vkd3d_fence_worker_main().

Variable Documentation

◆ debug_level_names

const char* const debug_level_names[]
static
Initial value:
=
{
[VKD3D_DBG_LEVEL_NONE ] = "none",
[VKD3D_DBG_LEVEL_MESSAGE] = "message",
[VKD3D_DBG_LEVEL_ERR ] = "err",
[VKD3D_DBG_LEVEL_FIXME] = "fixme",
[VKD3D_DBG_LEVEL_WARN ] = "warn",
[VKD3D_DBG_LEVEL_TRACE] = "trace",
}
@ VKD3D_DBG_LEVEL_WARN
Definition: vkd3d_common.h:148
@ VKD3D_DBG_LEVEL_NONE
Definition: vkd3d_common.h:144
@ VKD3D_DBG_LEVEL_TRACE
Definition: vkd3d_common.h:149
@ VKD3D_DBG_LEVEL_MESSAGE
Definition: vkd3d_common.h:145
@ VKD3D_DBG_LEVEL_ERR
Definition: vkd3d_common.h:146

Definition at line 45 of file debug.c.

Referenced by vkd3d_dbg_get_level(), and vkd3d_dbg_printf().

◆ log_callback

PFN_vkd3d_log log_callback
static

Definition at line 81 of file debug.c.

Referenced by vkd3d_dbg_set_log_callback(), and vkd3d_dbg_voutput().

◆ vkd3d_dbg_env_name

const char* const vkd3d_dbg_env_name
extern

Referenced by vkd3d_dbg_get_level().