ReactOS 0.4.16-dev-306-g647d351
wine_debug.c
Go to the documentation of this file.
1
2#define WIN32_NO_STATUS
3#include <windef.h>
4#include <ndk/rtlfuncs.h>
5#include <wine/debug.h>
6
8
9static struct
10{
14
15static int find_thread_slot()
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}
27
28static int get_thread_slot()
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}
50
51static char *alloc_buffer(size_t size)
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}
70
71static void free_buffers(void)
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}
90
91const char *wine_dbg_vsprintf(const char *format, va_list valist)
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}
106
107/* printf with temp buffer allocation */
108const char *wine_dbg_sprintf( const char *format, ... )
109{
110 const char *ret;
112
115 va_end(valist);
116 return ret;
117}
118
119const char *wine_dbgstr_wn( const WCHAR *str, int n )
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}
134
135/* From wine/dlls/ntdll/misc.c */
137{
138 if (!us) return "<null>";
139 return debugstr_wn(us->Buffer, us->Length / sizeof(WCHAR));
140}
141
142static int default_dbg_vprintf( const char *format, va_list args )
143{
144 return vDbgPrintExWithPrefix("", -1, 0, format, args);
145}
146
147int wine_dbg_printf(const char *format, ... )
148{
149 int ret;
151
154 va_end(valist);
155 free_buffers();
156 return ret;
157}
158
160 const char *file, const char *func, const int line, const char *format, va_list args )
161{
162 int ret = 0;
163
166
167 if (format)
169 return ret;
170}
171
172#define __wine_dbg_get_channel_flags(channel) \
173 ((channel) ? (channel)->flags : 0)
174
176 const char *file, const char *func, const int line, const char *format, ... )
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
LONG NTSTATUS
Definition: precomp.h:26
#define HandleToULong(h)
Definition: basetsd.h:95
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:590
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:608
#define NULL
Definition: types.h:112
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
GLsizeiptr size
Definition: glext.h:5919
GLenum func
Definition: glext.h:6028
GLdouble n
Definition: glext.h:7729
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
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
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
#define NtCurrentTeb
#define debugstr_wn
Definition: kernel32.h:33
static const BYTE us[]
Definition: encode.c:689
static __ms_va_list valist
Definition: printf.c:66
CONST CHAR * PCCH
Definition: ntbasedef.h:400
#define LOWORD(l)
Definition: pedump.c:82
static unsigned __int64 next
Definition: rand_nt.c:6
#define wine_dbgstr_wn
Definition: testlist.c:2
const WCHAR * str
__wine_debug_class
Definition: debug.h:50
HANDLE UniqueThread
Definition: compat.h:826
HANDLE UniqueProcess
Definition: compat.h:825
Definition: vfat.h:185
Definition: match.c:390
Definition: fci.c:127
Definition: format.c:58
Definition: parser.c:49
#define vsnprintf
Definition: tif_win32.c:406
#define NTAPI
Definition: typedefs.h:36
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
struct _slot slot
Definition: vfat.h:196
int ret
NTSTATUS NTAPI vDbgPrintExWithPrefix(PCCH, ULONG, ULONG, PCCH, va_list)
const char * wine_dbg_sprintf(const char *format,...)
Definition: wine_debug.c:108
#define __wine_dbg_get_channel_flags(channel)
Definition: wine_debug.c:172
const char * wine_dbg_vsprintf(const char *format, va_list valist)
Definition: wine_debug.c:91
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: wine_debug.c:175
static char * alloc_buffer(size_t size)
Definition: wine_debug.c:51
static void free_buffers(void)
Definition: wine_debug.c:71
int wine_dbg_printf(const char *format,...)
Definition: wine_debug.c:147
static struct @5010 s_alloactions[32]
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
LPCSTR debugstr_us(const UNICODE_STRING *us)
Definition: wine_debug.c:136
static int default_dbg_vprintf(const char *format, va_list args)
Definition: wine_debug.c:142
static int find_thread_slot()
Definition: wine_debug.c:15
void * allocations
Definition: wine_debug.c:12
HANDLE thread
Definition: wine_debug.c:11
static int get_thread_slot()
Definition: wine_debug.c:28
_Out_ PCLIENT_ID ClientId
Definition: kefuncs.h:1151
const char * LPCSTR
Definition: xmlstorage.h:183
__wchar_t WCHAR
Definition: xmlstorage.h:180