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 PUTERR(col,type) {\
23 if(!gbThreadInLog) SHORTLOCK(&glDebugLock); \
26 va_list args; va_start(args, Message);\
27 vfprintf(stderr, Message, args);\
31 if(!gbThreadInLog) SHORTREL(&glDebugLock); \
35 int __thread gbThreadInLog;
36 tShortSpinlock glDebugLock;
39 void Log_KernelPanic(const char *Ident, const char *Message, ...) {
43 void Log_Panic(const char *Ident, const char *Message, ...)
45 void Log_Error(const char *Ident, const char *Message, ...)
47 void Log_Warning(const char *Ident, const char *Message, ...)
49 void Log_Notice(const char *Ident, const char *Message, ...)
51 void Log_Log(const char *Ident, const char *Message, ...)
53 void Log_Debug(const char *Ident, const char *Message, ...)
56 void Panic(const char *Message, ...) {
57 const char *Ident = "";
61 void Warning(const char *Message, ...) {
62 const char *Ident = "";
65 void Log(const char *Message, ...) {
66 const char *Ident = "";
70 void Debug_HexDump(const char *Prefix, const void *Data, size_t Length)
72 const uint8_t *data = Data;
74 fprintf(stderr, "[HexDump ]d %s: %i bytes\n", Prefix, (int)Length);
75 for( ofs = 0; ofs + 16 <= Length; ofs += 16 )
77 fprintf(stderr, "[HexDump ]d %s:", Prefix);
78 fprintf(stderr, " %02x %02x %02x %02x %02x %02x %02x %02x",
79 data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
81 fprintf(stderr, " %02x %02x %02x %02x %02x %02x %02x %02x",
82 data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7]);
84 fprintf(stderr, "\n");
87 fprintf(stderr, "[HexDump ]d %s:", Prefix);
88 for( ; ofs < Length; ofs ++ )
90 if( ofs % 8 == 0 ) fprintf(stderr, " ");
91 fprintf(stderr, " %02x", data[ofs%16]);
93 fprintf(stderr, "\n");
96 int giDebug_TraceLevel = 0;
98 void Debug_TraceEnter(const char *Function, const char *Format, ...)
100 const char *Ident = "Trace";
102 for( int i = 0; i < giDebug_TraceLevel; i ++ )
103 fprintf(stderr, " ");
104 fprintf(stderr, "%s: (", Function);
107 va_start(args, Format);
112 while( *Format && isblank(*Format) )
114 if( !*Format ) break;
116 char type = *Format++;
117 const char *start = Format;
118 while( *Format && !isblank(*Format) )
122 fprintf(stderr, ",");
125 fprintf(stderr, "%.*s=", (int)(Format-start), start);
129 fprintf(stderr, "%p", va_arg(args,const void *));
132 fprintf(stderr, "\"%s\"", va_arg(args,const char *));
135 fprintf(stderr, "%i", va_arg(args,int));
138 fprintf(stderr, "0x%x", va_arg(args,unsigned int));
141 fprintf(stderr, "0x%"PRIx64, va_arg(args,uint64_t));
144 va_arg(args,uintptr_t);
145 fprintf(stderr, "?");
152 fprintf(stderr, ")");
154 giDebug_TraceLevel ++;
157 void Debug_TraceLog(const char *Function, const char *Format, ...)
159 const char *Ident = "Trace";
162 for( int i = 0; i < giDebug_TraceLevel; i ++ )
163 fprintf(stderr, " ");
164 fprintf(stderr, "%s: ", Function);
167 va_start(args, Format);
169 vfprintf(stderr, Format, args);
175 void Debug_TraceLeave(const char *Function, char Type, ...)
177 if( giDebug_TraceLevel == 0 ) {
178 Log_Error("Debug", "Function %s called LEAVE without ENTER", Function);
181 const char *Ident = "Trace";
185 va_start(args, Type);
187 if( giDebug_TraceLevel > 0 )
189 giDebug_TraceLevel --;
190 for( int i = 0; i < giDebug_TraceLevel; i ++ )
191 fprintf(stderr, " ");
193 fprintf(stderr, "%s: RETURN", Function);
199 fprintf(stderr, " %i", va_arg(args, int));
202 fprintf(stderr, " 0x%x", va_arg(args, unsigned int));
205 fprintf(stderr, " 0x%"PRIx64, va_arg(args,uint64_t));
208 fprintf(stderr, " \"%s\"", va_arg(args, const char *));
211 fprintf(stderr, " %p", va_arg(args, const void *));
214 fprintf(stderr, " NULL");
217 fprintf(stderr, " ?");