ReactOS 0.4.16-dev-334-g4d9f67c
wine_debug.c File Reference
#include <windef.h>
#include <ndk/rtlfuncs.h>
#include <wine/debug.h>
Include dependency graph for wine_debug.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define __wine_dbg_get_channel_flags(channel)    ((channel) ? (channel)->flags : 0)
 

Functions

NTSTATUS NTAPI vDbgPrintExWithPrefix (PCCH, ULONG, ULONG, PCCH, va_list)
 
static int find_thread_slot ()
 
static int get_thread_slot ()
 
static charalloc_buffer (size_t size)
 
static void free_buffers (void)
 
const charwine_dbg_vsprintf (const char *format, va_list valist)
 
const charwine_dbg_sprintf (const char *format,...)
 
const charwine_dbgstr_wn (const WCHAR *str, int n)
 
LPCSTR debugstr_us (const UNICODE_STRING *us)
 
static int default_dbg_vprintf (const char *format, va_list args)
 
int wine_dbg_printf (const char *format,...)
 
static int winefmt_default_dbg_vlog (enum __wine_debug_class cls, struct __wine_debug_channel *channel, const char *file, const char *func, const int line, const char *format, va_list args)
 
int ros_dbg_log (enum __wine_debug_class cls, struct __wine_debug_channel *channel, const char *file, const char *func, const int line, const char *format,...)
 

Variables

struct {
   HANDLE   thread
 
   void *   allocations
 
s_alloactions [32]
 

Macro Definition Documentation

◆ __wine_dbg_get_channel_flags

#define __wine_dbg_get_channel_flags (   channel)     ((channel) ? (channel)->flags : 0)

Definition at line 172 of file wine_debug.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 2 of file wine_debug.c.

Function Documentation

◆ alloc_buffer()

static char * alloc_buffer ( size_t  size)
static

Definition at line 51 of file wine_debug.c.

52{
53 int slot = get_thread_slot();
54 if (slot == -1)
55 {
56 return NULL;
57 }
58
59 void** buffer = (void**)RtlAllocateHeap(RtlGetProcessHeap(), 0, size + sizeof(void*));
60 if (buffer == NULL)
61 {
62 return NULL;
63 }
64
65 *buffer = s_alloactions[slot].allocations;
66 s_alloactions[slot].allocations = buffer;
67
68 return (char*)(buffer + 1);
69}
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
#define NULL
Definition: types.h:112
GLsizeiptr size
Definition: glext.h:5919
GLuint buffer
Definition: glext.h:5915
Definition: vfat.h:185
struct _slot slot
Definition: vfat.h:196
static struct @5011 s_alloactions[32]
static int get_thread_slot()
Definition: wine_debug.c:28

Referenced by wine_dbg_vsprintf().

◆ debugstr_us()

LPCSTR debugstr_us ( const UNICODE_STRING us)

Definition at line 136 of file wine_debug.c.

137{
138 if (!us) return "<null>";
139 return debugstr_wn(us->Buffer, us->Length / sizeof(WCHAR));
140}
#define debugstr_wn
Definition: kernel32.h:33
static const BYTE us[]
Definition: encode.c:689
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by find_string_index(), find_window_class(), and RtlFindActivationContextSectionString().

◆ default_dbg_vprintf()

static int default_dbg_vprintf ( const char format,
va_list  args 
)
static

Definition at line 142 of file wine_debug.c.

143{
144 return vDbgPrintExWithPrefix("", -1, 0, format, args);
145}
Definition: match.c:390
Definition: format.c:58
NTSTATUS NTAPI vDbgPrintExWithPrefix(PCCH, ULONG, ULONG, PCCH, va_list)

Referenced by wine_dbg_printf(), and winefmt_default_dbg_vlog().

◆ find_thread_slot()

static int find_thread_slot ( )
static

Definition at line 15 of file wine_debug.c.

16{
17 HANDLE thread = NtCurrentTeb()->ClientId.UniqueThread;
18 for (int i = 0; i < ARRAYSIZE(s_alloactions); i++)
19 {
21 {
22 return i;
23 }
24 }
25 return -1;
26}
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
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
#define NtCurrentTeb
HANDLE thread
Definition: wine_debug.c:11

Referenced by free_buffers(), and get_thread_slot().

◆ free_buffers()

static void free_buffers ( void  )
static

Definition at line 71 of file wine_debug.c.

72{
73 int slot = find_thread_slot();
74 if (slot != -1)
75 {
76 return;
77 }
78
79 void* buffer = s_alloactions[slot].allocations;
80 while (buffer != NULL)
81 {
82 void* next = *(void**)buffer;
83 RtlFreeHeap(RtlGetProcessHeap(), 0, buffer);
84 buffer = next;
85 }
86
87 s_alloactions[slot].allocations = NULL;
88 s_alloactions[slot].thread = NULL;
89}
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
static unsigned __int64 next
Definition: rand_nt.c:6
static int find_thread_slot()
Definition: wine_debug.c:15

Referenced by test_communication(), and wine_dbg_printf().

◆ get_thread_slot()

static int get_thread_slot ( )
static

Definition at line 28 of file wine_debug.c.

29{
30 int slot = find_thread_slot();
31 if (slot != -1)
32 {
33 return slot;
34 }
35
36 HANDLE thread = NtCurrentTeb()->ClientId.UniqueThread;
37 for (int i = 0; i < ARRAYSIZE(s_alloactions); i++)
38 {
39 if (s_alloactions[i].thread == NULL)
40 {
42 {
43 return i;
44 }
45 }
46 }
47
48 return -1;
49}
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129

Referenced by alloc_buffer().

◆ ros_dbg_log()

int ros_dbg_log ( enum __wine_debug_class  cls,
struct __wine_debug_channel channel,
const char file,
const char func,
const int  line,
const char format,
  ... 
)

Definition at line 175 of file wine_debug.c.

177{
178 int ret;
180
181 if (!(__wine_dbg_get_channel_flags(channel) & (1 << cls))) return -1;
182
185 va_end(valist);
186 return ret;
187}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLenum func
Definition: glext.h:6028
static __ms_va_list valist
Definition: printf.c:66
Definition: fci.c:127
Definition: parser.c:49
int ret
#define __wine_dbg_get_channel_flags(channel)
Definition: wine_debug.c:172
static int winefmt_default_dbg_vlog(enum __wine_debug_class cls, struct __wine_debug_channel *channel, const char *file, const char *func, const int line, const char *format, va_list args)
Definition: wine_debug.c:159

◆ vDbgPrintExWithPrefix()

NTSTATUS NTAPI vDbgPrintExWithPrefix ( PCCH  ,
ULONG  ,
ULONG  ,
PCCH  ,
va_list   
)

Referenced by default_dbg_vprintf().

◆ wine_dbg_printf()

int wine_dbg_printf ( const char format,
  ... 
)

Definition at line 147 of file wine_debug.c.

148{
149 int ret;
151
154 va_end(valist);
155 free_buffers();
156 return ret;
157}
static void free_buffers(void)
Definition: wine_debug.c:71
static int default_dbg_vprintf(const char *format, va_list args)
Definition: wine_debug.c:142

Referenced by winefmt_default_dbg_vlog().

◆ wine_dbg_sprintf()

const char * wine_dbg_sprintf ( const char format,
  ... 
)

Definition at line 108 of file wine_debug.c.

109{
110 const char *ret;
112
115 va_end(valist);
116 return ret;
117}
const char * wine_dbg_vsprintf(const char *format, va_list valist)
Definition: wine_debug.c:91

Referenced by wine_dbgstr_longlong(), and wine_dbgstr_wn().

◆ wine_dbg_vsprintf()

const char * wine_dbg_vsprintf ( const char format,
va_list  valist 
)

Definition at line 91 of file wine_debug.c.

92{
93 char* buffer;
94 int len;
95
97 buffer = alloc_buffer(len + 1);
98 if (buffer == NULL)
99 {
100 return "<allocation failed>";
101 }
103 buffer[len] = 0;
104 return buffer;
105}
GLenum GLsizei len
Definition: glext.h:6722
#define vsnprintf
Definition: tif_win32.c:406
static char * alloc_buffer(size_t size)
Definition: wine_debug.c:51

Referenced by wine_dbg_sprintf().

◆ wine_dbgstr_wn()

const char * wine_dbgstr_wn ( const WCHAR str,
int  n 
)

Definition at line 119 of file wine_debug.c.

120{
121 if (!((ULONG_PTR)str >> 16))
122 {
123 if (!str) return "(null)";
124 return wine_dbg_sprintf("#%04x", LOWORD(str) );
125 }
126 if (n == -1)
127 {
128 n = (int)wcslen(str);
129 }
130 if (n < 0) n = 0;
131
132 return wine_dbg_sprintf("%.*S", n, str);
133}
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLdouble n
Definition: glext.h:7729
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define LOWORD(l)
Definition: pedump.c:82
const WCHAR * str
uint32_t ULONG_PTR
Definition: typedefs.h:65
const char * wine_dbg_sprintf(const char *format,...)
Definition: wine_debug.c:108

◆ winefmt_default_dbg_vlog()

static int winefmt_default_dbg_vlog ( enum __wine_debug_class  cls,
struct __wine_debug_channel channel,
const char file,
const char func,
const int  line,
const char format,
va_list  args 
)
static

Definition at line 159 of file wine_debug.c.

161{
162 int ret = 0;
163
166
167 if (format)
169 return ret;
170}
#define HandleToULong(h)
Definition: basetsd.h:95
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
int wine_dbg_printf(const char *format,...)
Definition: wine_debug.c:147
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151

Referenced by ros_dbg_log().

Variable Documentation

◆ allocations

void* allocations

Definition at line 12 of file wine_debug.c.

◆ 

struct { ... } s_alloactions[32]

◆ thread

HANDLE thread

Definition at line 11 of file wine_debug.c.

Referenced by find_thread_slot(), and get_thread_slot().