ReactOS 0.4.17-dev-934-g091855f
vkd3d_debug.h File Reference
#include "vkd3d_common.h"
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
Include dependency graph for vkd3d_debug.h:

Go to the source code of this file.

Classes

struct  vkd3d_debug_option
 

Macros

#define VKD3D_DBG_LOG(level)
 
#define VKD3D_DBG_LOG_ONCE(first_time_level, level)
 
#define VKD3D_DBG_PRINTF(...)    vkd3d_dbg_printf(vkd3d_dbg_level, __FUNCTION__, __VA_ARGS__); } while (0)
 
#define ERR   VKD3D_DBG_LOG(ERR)
 
#define FIXME_ONCE   VKD3D_DBG_LOG_ONCE(FIXME, WARN)
 
#define VKD3D_DEBUG_ENV_NAME(name)   const char *const vkd3d_dbg_env_name = name
 
#define TO_STR(u)   case u: return #u;
 

Enumerations

enum  vkd3d_dbg_level {
  VKD3D_DBG_LEVEL_NONE , VKD3D_DBG_LEVEL_MESSAGE , VKD3D_DBG_LEVEL_ERR , VKD3D_DBG_LEVEL_FIXME ,
  VKD3D_DBG_LEVEL_WARN , VKD3D_DBG_LEVEL_TRACE , VKD3D_DBG_LEVEL_NONE , VKD3D_DBG_LEVEL_ERR ,
  VKD3D_DBG_LEVEL_FIXME , VKD3D_DBG_LEVEL_WARN , VKD3D_DBG_LEVEL_TRACE
}
 

Functions

enum vkd3d_dbg_level vkd3d_dbg_get_level (void)
 
void vkd3d_dbg_printf (enum vkd3d_dbg_level level, const char *function, const char *fmt,...) VKD3D_PRINTF_FUNC(3
 
void void vkd3d_dbg_set_log_callback (PFN_vkd3d_log callback)
 
const char * vkd3d_dbg_sprintf (const char *fmt,...) VKD3D_PRINTF_FUNC(1
 
const char const char * vkd3d_dbg_vsprintf (const char *fmt, va_list args)
 
const char * debugstr_a (const char *str)
 
const char * debugstr_an (const char *str, size_t n)
 
const char * debugstr_w (const WCHAR *wstr, size_t wchar_size)
 
static const char * debugstr_guid (const GUID *guid)
 
static const char * debugstr_hresult (HRESULT hr)
 
unsigned int vkd3d_env_var_as_uint (const char *name, unsigned int default_value)
 
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)
 

Macro Definition Documentation

◆ ERR

#define ERR   VKD3D_DBG_LOG(ERR)

Definition at line 86 of file vkd3d_debug.h.

◆ FIXME_ONCE

#define FIXME_ONCE   VKD3D_DBG_LOG_ONCE(FIXME, WARN)

Definition at line 96 of file vkd3d_debug.h.

◆ TO_STR

#define TO_STR (   u)    case u: return #u;

◆ VKD3D_DBG_LOG

#define VKD3D_DBG_LOG (   level)
Value:
do { \
const enum vkd3d_dbg_level vkd3d_dbg_level = VKD3D_DBG_LEVEL_##level; \
GLint level
Definition: gl.h:1546
vkd3d_dbg_level
Definition: vkd3d_common.h:143
#define VKD3D_DBG_PRINTF(...)
Definition: vkd3d_debug.h:71

Definition at line 58 of file vkd3d_debug.h.

◆ VKD3D_DBG_LOG_ONCE

#define VKD3D_DBG_LOG_ONCE (   first_time_level,
  level 
)
Value:
do { \
static bool vkd3d_dbg_next_time; \
const enum vkd3d_dbg_level vkd3d_dbg_level = vkd3d_dbg_next_time \
? VKD3D_DBG_LEVEL_##level : VKD3D_DBG_LEVEL_##first_time_level; \
vkd3d_dbg_next_time = true; \

Definition at line 63 of file vkd3d_debug.h.

◆ VKD3D_DBG_PRINTF

#define VKD3D_DBG_PRINTF (   ...)     vkd3d_dbg_printf(vkd3d_dbg_level, __FUNCTION__, __VA_ARGS__); } while (0)

Definition at line 71 of file vkd3d_debug.h.

◆ VKD3D_DEBUG_ENV_NAME

#define VKD3D_DEBUG_ENV_NAME (   name)    const char *const vkd3d_dbg_env_name = name

Definition at line 98 of file vkd3d_debug.h.

Enumeration Type Documentation

◆ vkd3d_dbg_level

Enumerator
VKD3D_DBG_LEVEL_NONE 
VKD3D_DBG_LEVEL_MESSAGE 
VKD3D_DBG_LEVEL_ERR 
VKD3D_DBG_LEVEL_FIXME 
VKD3D_DBG_LEVEL_WARN 
VKD3D_DBG_LEVEL_TRACE 
VKD3D_DBG_LEVEL_NONE 
VKD3D_DBG_LEVEL_ERR 
VKD3D_DBG_LEVEL_FIXME 
VKD3D_DBG_LEVEL_WARN 
VKD3D_DBG_LEVEL_TRACE 

Definition at line 38 of file vkd3d_debug.h.

39{
45};
@ VKD3D_DBG_LEVEL_WARN
Definition: vkd3d_debug.h:43
@ VKD3D_DBG_LEVEL_NONE
Definition: vkd3d_debug.h:40
@ VKD3D_DBG_LEVEL_TRACE
Definition: vkd3d_debug.h:44
@ VKD3D_DBG_LEVEL_ERR
Definition: vkd3d_debug.h:41
@ VKD3D_DBG_LEVEL_FIXME
Definition: vkd3d_debug.h:42

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_guid()

static const char * debugstr_guid ( const GUID *  guid)
inlinestatic

Definition at line 100 of file vkd3d_debug.h.

101{
102 if (!guid)
103 return "(null)";
104
105 return vkd3d_dbg_sprintf("{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
106 (unsigned long)guid->Data1, guid->Data2, guid->Data3, guid->Data4[0],
107 guid->Data4[1], guid->Data4[2], guid->Data4[3], guid->Data4[4],
108 guid->Data4[5], guid->Data4[6], guid->Data4[7]);
109}
GUID guid
Definition: version.c:147
const char * vkd3d_dbg_sprintf(const char *fmt,...) VKD3D_PRINTF_FUNC(1

◆ debugstr_hresult()

static const char * debugstr_hresult ( HRESULT  hr)
inlinestatic

Definition at line 111 of file vkd3d_debug.h.

112{
113 switch (hr)
114 {
115#define TO_STR(u) case u: return #u;
116 TO_STR(S_OK)
128#undef TO_STR
129 default:
130 return vkd3d_dbg_sprintf("%#x", (int)hr);
131 }
132}
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
HRESULT hr
Definition: delayimp.cpp:582
#define S_OK
Definition: intsafe.h:52
#define TO_STR(u)
#define S_FALSE
Definition: winerror.h:3451
#define DXGI_ERROR_NOT_FOUND
Definition: winerror.h:7122
#define DXGI_ERROR_UNSUPPORTED
Definition: winerror.h:7125
#define E_NOINTERFACE
Definition: winerror.h:3479
#define DXGI_ERROR_MORE_DATA
Definition: winerror.h:7123
#define E_POINTER
Definition: winerror.h:3480
#define E_ABORT
Definition: winerror.h:3481

◆ 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

◆ 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}
#define ARRAY_SIZE(A)
Definition: main.h:20
char *CDECL getenv(const char *name)
Definition: environ.c:227
_ACRTIMP int __cdecl strcmp(const char *, const char *)
Definition: string.c:3324
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_printf()

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

◆ vkd3d_dbg_set_log_callback()

void 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

◆ vkd3d_dbg_sprintf()

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

Referenced by debugstr_guid(), and debugstr_hresult().

◆ vkd3d_dbg_vsprintf()

const char 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
Definition: match.c:390
Definition: dsound.c:943

Referenced by 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 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

◆ 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

◆ 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