OpenCBM
arch/windows/debug.c
Go to the documentation of this file.
1 
9 #ifndef DBG_KERNELMODE
10 
11  #define DBG_USERMODE
12 #endif // #ifndef DBG_KERNELMODE
13 
14 #include "debug.h"
15 
16 #if DBG
17 
18 #include <stdarg.h>
19 #include <stdio.h>
20 
21 
22 
27 
30 
32 unsigned long DbgFlags = 0 // | 0x7FFFFFFF
33 // | DBGF_BREAK
34 
35 // | DBGF_ENTER
36 // | DBGF_LEAVE
37 // | DBGF_LEAVE_FAILURE
38 // | DBGF_PARAM
39 #ifdef DBG_KERNELMODE
40 // | DBGF_IEC
41 // | DBGF_IRQ
42  | DBGF_ASSERTIRQL
43 // | DBGF_PORT
44  | DBGF_THREAD
45 // | DBGF_IRPPATH
46 // | DBGF_IRP
47 // | DBGF_DPC
48  | DBGF_DBGMEMBUF
49  | DBGF_DBGPRINT
50 
51 #endif // #ifdef DBG_KERNELMODE
52 // | DBGF_PPORT
53 // | DBGF_SUCCESS
54 // | DBGF_ERROR
55 // | DBGF_WARNING
56  | DBGF_ASSERT
57  ;
58 
59 #ifdef DBG_KERNELMODE
60 
64 LONG DebugBufferCounter;
65 
69 LONG DebugBufferUsed[DBG_MAX_BUFFER];
70 
71 #endif // #ifdef DBG_KERNELMODE
72 
73 
90 void
91 DbgOutputIntoBuffer(unsigned long BufferNumber, const char * const Format, ...)
92 {
93  va_list arg_ptr;
94 
95  // Get a pointer to the current position in the given DebugBuffer
96 
97  char *buffer = &DbgBuffer[BufferNumber][DbgBufferPos[BufferNumber]];
98 
99  va_start(arg_ptr, Format);
100 
101  // If there is some space left in the DebugBuffer, append the contents
102 
103  if ((DBG_MAX_BUFFERLEN - DbgBufferPos[BufferNumber] - 1) > 0)
104  {
105  int n;
106 
107  // Output at most the number of bytes which are left in the DebugBuffer
108 
109  n = _vsnprintf(buffer, DBG_MAX_BUFFERLEN - DbgBufferPos[BufferNumber] - 1,
110  Format, arg_ptr);
111 
112  // Was the buffer too small? If yes, the number of bytes
113  // inserted is the size of the remaining buffer, so, set
114  // this value
115 
116  if (n<0)
117  {
118  n = DBG_MAX_BUFFERLEN - DbgBufferPos[BufferNumber] - 1;
119  }
120 
121  // advance the buffer into the DebugBuffer
122 
123  DbgBufferPos[BufferNumber] += n;
124 
125  // Make sure the string is null terminated
126 
127  DbgBuffer[BufferNumber][DbgBufferPos[BufferNumber]] = 0;
128  }
129  va_end(arg_ptr);
130 }
131 
132 #endif // #if DBG
#define DBG_MAX_BUFFERLEN
Maximum size of a debugging buffer.
Definition: debug.h:108
Define makros for debugging purposes.
void DbgOutputIntoBuffer(unsigned long BufferNumber, const char *const Format,...)
Append something to the DebugBuffer.
unsigned long DbgFlags
unsigned char DbgBuffer[DBG_MAX_BUFFER][DBG_MAX_BUFFERLEN]
#define DBGF_ASSERT
Definition: debug.h:191
int DbgBufferPos[DBG_MAX_BUFFER]
#define DBG_MAX_BUFFER
the maximum number of buffers to be used for debugging
Definition: debug.h:118