2 * Acess2 libnative (Kernel Simulation Library)
3 * - By John Hodge (thePowersGang)
12 #include <acess_logging.h>
15 #include <shortlock.h>
17 extern int Threads_GetTID();
19 #define LOGHDR(col,type) fprintf(stderr, "\e["col"m[%-8.8s]"type"%2i ", Ident, Threads_GetTID())
20 #define LOGTAIL() fprintf(stderr, "\e[0m\n")
22 #define LOG_LOCK_ACQUIRE() do{ \
23 if(!gbThreadInLog) SHORTLOCK(&glDebugLock); \
26 #define LOG_LOCK_RELEASE() do {\
28 if(!gbThreadInLog) SHORTREL(&glDebugLock); \
31 #define PUTERR(col,type) {\
34 va_list args; va_start(args, Message);\
35 vfprintf(stderr, Message, args);\
42 int __thread gbThreadInLog;
43 tShortSpinlock glDebugLock;
46 void Log_KernelPanic(const char *Ident, const char *Message, ...) {
50 void Log_Panic(const char *Ident, const char *Message, ...)
52 void Log_Error(const char *Ident, const char *Message, ...)
54 void Log_Warning(const char *Ident, const char *Message, ...)
56 void Log_Notice(const char *Ident, const char *Message, ...)
58 void Log_Log(const char *Ident, const char *Message, ...)
60 void Log_Debug(const char *Ident, const char *Message, ...)
63 void Panic(const char *Message, ...) {
64 const char *Ident = "";
68 void Warning(const char *Message, ...) {
69 const char *Ident = "";
72 void Log(const char *Message, ...) {
73 const char *Ident = "";
76 void Debug(const char *Message, ...) {
77 const char *Ident = "";
81 void Debug_HexDump(const char *Prefix, const void *Data, size_t Length)
83 const uint8_t *data = Data;
86 fprintf(stderr, "[HexDump ]d %s: %i bytes\n", Prefix, (int)Length);
87 for( ofs = 0; ofs + 16 <= Length; ofs += 16 )
89 fprintf(stderr, "[HexDump ]d %s:", Prefix);
90 fprintf(stderr, " %02x %02x %02x %02x %02x %02x %02x %02x",
91 data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
93 fprintf(stderr, " %02x %02x %02x %02x %02x %02x %02x %02x",
94 data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
96 fprintf(stderr, "\n");
99 fprintf(stderr, "[HexDump ]d %s:", Prefix);
100 for( ; ofs < Length; ofs ++ )
102 if( ofs % 8 == 0 ) fprintf(stderr, " ");
103 fprintf(stderr, " %02x", data[ofs%16]);
105 fprintf(stderr, "\n");
109 int giDebug_TraceLevel = 0;
111 void Debug_TraceEnter(const char *Function, const char *Format, ...)
114 //const char *Ident = "Trace";
116 for( int i = 0; i < giDebug_TraceLevel; i ++ )
117 fprintf(stderr, " ");
118 fprintf(stderr, "%s: (", Function);
121 va_start(args, Format);
126 while( *Format && isblank(*Format) )
128 if( !*Format ) break;
130 char type = *Format++;
131 const char *start = Format;
132 while( *Format && !isblank(*Format) )
136 fprintf(stderr, ",");
139 fprintf(stderr, "%.*s=", (int)(Format-start), start);
143 fprintf(stderr, "%p", va_arg(args,const void *));
146 fprintf(stderr, "\"%s\"", va_arg(args,const char *));
149 fprintf(stderr, "%i", va_arg(args,int));
152 fprintf(stderr, "0x%x", va_arg(args,unsigned int));
155 fprintf(stderr, "0x%"PRIx64, va_arg(args,uint64_t));
158 va_arg(args,uintptr_t);
159 fprintf(stderr, "?");
166 fprintf(stderr, ")");
168 giDebug_TraceLevel ++;
172 void Debug_TraceLog(const char *Function, const char *Format, ...)
175 //const char *Ident = "Trace";
178 for( int i = 0; i < giDebug_TraceLevel; i ++ )
179 fprintf(stderr, " ");
180 fprintf(stderr, "%s: ", Function);
183 va_start(args, Format);
185 vfprintf(stderr, Format, args);
192 void Debug_TraceLeave(const char *Function, char Type, ...)
194 if( giDebug_TraceLevel == 0 ) {
195 Log_Error("Debug", "Function %s called LEAVE without ENTER", Function);
199 //const char *Ident = "Trace";
203 va_start(args, Type);
205 if( giDebug_TraceLevel > 0 )
207 giDebug_TraceLevel --;
208 for( int i = 0; i < giDebug_TraceLevel; i ++ )
209 fprintf(stderr, " ");
211 fprintf(stderr, "%s: RETURN", Function);
217 fprintf(stderr, " %i", va_arg(args, int));
220 fprintf(stderr, " 0x%x", va_arg(args, unsigned int));
223 fprintf(stderr, " 0x%"PRIx64, va_arg(args,uint64_t));
226 fprintf(stderr, " \"%s\"", va_arg(args, const char *));
229 fprintf(stderr, " %p", va_arg(args, const void *));
232 fprintf(stderr, " NULL");
235 fprintf(stderr, " ?");