mirror of https://github.com/ClassiCube/ClassiCube
Cleanup Logger.c
Instead of having one giant entangled if ISA if OS function mess for dumping registers, instead separate into per-OS functions
This commit is contained in:
parent
dccabb93c4
commit
9244323a19
|
|
@ -11,6 +11,7 @@
|
|||
*.VC.VC.opendb
|
||||
|
||||
# Build results
|
||||
[Aa]ndroid/
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
|
|
|
|||
|
|
@ -710,7 +710,7 @@ static void Player_CheckSkin(struct Player* p) {
|
|||
if (!p->FetchedSkin && e->Model->UsesSkin) {
|
||||
first = Player_FirstOtherWithSameSkinAndFetchedSkin(p);
|
||||
if (!first) {
|
||||
Http_AsyncGetSkin(&skin, &skin);
|
||||
Http_AsyncGetSkin(&skin);
|
||||
} else {
|
||||
Player_CopySkin(p, first);
|
||||
}
|
||||
|
|
|
|||
32
src/Http.c
32
src/Http.c
|
|
@ -722,10 +722,12 @@ static void Http_SysFree(void) {
|
|||
}
|
||||
#elif defined CC_BUILD_ANDROID
|
||||
#include <android_native_app_glue.h>
|
||||
#include "<jni.h>"
|
||||
#include <jni.h>
|
||||
|
||||
static void CallVoidJavaMethod(const char* name, const char* sig, ..) {
|
||||
jmethodID method = env->GetStaticMethodID(clazz_algo, "init", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
|
||||
static void CallJavaVoid(JNIEnv* env, const char* name, const char* sig, jvalue* args) {
|
||||
jclass clazz = (*env)->FindClass(env, "com/classicube/Wrappers");
|
||||
jmethodID method = (*env)->GetStaticMethodID(env, clazz, name, sig);
|
||||
(*env)->CallStaticVoidMethodA(env, clazz, method, args);
|
||||
}
|
||||
|
||||
bool Http_DescribeError(ReturnCode res, String* dst) {
|
||||
|
|
@ -735,30 +737,38 @@ bool Http_DescribeError(ReturnCode res, String* dst) {
|
|||
static void Http_SysInit(void) { }
|
||||
|
||||
static void Http_AddHeader(const char* key, const String* value) {
|
||||
jni
|
||||
JavaVM* vm = (JavaVM*)VM_Handle;
|
||||
JNIEnv* env;
|
||||
jvalue args[2];
|
||||
|
||||
(*vm)->AttachCurrentThread(vm, &env, NULL);
|
||||
args[0].l = (*env)->NewStringUTF(env, key);
|
||||
jni value
|
||||
|
||||
CallJavaVoid(env, "httpSetHeader", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", args);
|
||||
}
|
||||
|
||||
/* Processes a HTTP header downloaded from the server */
|
||||
static JNIEXPORT void JNICALL Java_com_classicube_Wrappers_httpParseHeader(JNIEnv* env, jlcass, jstring header) {
|
||||
static JNIEXPORT void JNICALL Java_com_classicube_Wrappers_httpParseHeader(JNIEnv* env, jclass c, jstring header) {
|
||||
String line;
|
||||
const char* src = (*env)->GetStringUTFChars(env, header, NULL);
|
||||
jsize length = (*env)->GetStringLength(env, header);
|
||||
|
||||
line = String_Init(src, length, length);
|
||||
Http_ParseHeader(req, &line);
|
||||
(*env)->ReleaseStringUTFChars(env, src);
|
||||
(*env)->ReleaseStringUTFChars(env, header, src);
|
||||
}
|
||||
|
||||
/* Processes a chunk of data downloaded from the web server */
|
||||
static JNIEXPORT void JNICALL Java_com_classicube_Wrappers_httpAppendData(JNIEnv* env, jlcass, jbytearray arr, jint len) {
|
||||
jbyte* src = (*env)->->GetByteArrayElements(env, NULL, 0);
|
||||
static JNIEXPORT void JNICALL Java_com_classicube_Wrappers_httpAppendData(JNIEnv* env, jclass c, jbyteArray arr, jint len) {
|
||||
jbyte* src = (*env)->GetByteArrayElements(env, NULL, 0);
|
||||
|
||||
if (!bufferSize) Http_BufferInit(req);
|
||||
Http_BufferEnsure(req, len);
|
||||
|
||||
Mem_Copy(&req->Data[req->Size], src, len);
|
||||
Http_BufferExpanded(req, len);
|
||||
(*env)->ReleaseByteArrayElements(env, src, JNI_ABORT);
|
||||
(*env)->ReleaseByteArrayElements(env, arr, src, JNI_ABORT);
|
||||
}
|
||||
|
||||
/* Sets general curl options for a request */
|
||||
|
|
@ -868,7 +878,7 @@ static void Http_WorkerLoop(void) {
|
|||
#define SKIN_SERVER "http://static.classicube.net/skins/"
|
||||
#endif
|
||||
|
||||
void Http_AsyncGetSkin(const String* id, const String* skinName) {
|
||||
void Http_AsyncGetSkin(const String* skinName) {
|
||||
String url; char urlBuffer[STRING_SIZE];
|
||||
String_InitArray(url, urlBuffer);
|
||||
|
||||
|
|
@ -879,7 +889,7 @@ void Http_AsyncGetSkin(const String* id, const String* skinName) {
|
|||
String_AppendColorless(&url, skinName);
|
||||
String_AppendConst(&url, ".png");
|
||||
}
|
||||
Http_AsyncGetData(&url, false, id);
|
||||
Http_AsyncGetData(&url, false, skinName);
|
||||
}
|
||||
|
||||
void Http_AsyncGetData(const String* url, bool priority, const String* id) {
|
||||
|
|
|
|||
|
|
@ -42,9 +42,9 @@ struct HttpRequest {
|
|||
void HttpRequest_Free(struct HttpRequest* request);
|
||||
|
||||
/* Aschronously performs a http GET request to download a skin. */
|
||||
/* If url is a skin, this is the same as Http_AsyncGetData. */
|
||||
/* If not, instead downloads from http://static.classicube.net/skins/[skinName].png */
|
||||
void Http_AsyncGetSkin(const String* id, const String* skinName);
|
||||
/* If url is a skin, downloads from there. (if not, http://static.classicube.net/skins/[skinName].png) */
|
||||
/* ID of the request is set to skinName. */
|
||||
void Http_AsyncGetSkin(const String* skinName);
|
||||
/* Asynchronously performs a http GET request. (e.g. to download data) */
|
||||
void Http_AsyncGetData(const String* url, bool priority, const String* id);
|
||||
/* Asynchronously performs a http HEAD request. (e.g. to get Content-Length header) */
|
||||
|
|
|
|||
292
src/Logger.c
292
src/Logger.c
|
|
@ -47,7 +47,7 @@ void Logger_DialogWarn(const String* msg) {
|
|||
String dst; char dstBuffer[512];
|
||||
String_InitArray_NT(dst, dstBuffer);
|
||||
|
||||
String_AppendString(&dst, msg);
|
||||
String_Copy(&dst, msg);
|
||||
dst.buffer[dst.length] = '\0';
|
||||
Window_ShowDialog(Logger_DialogTitle, dst.buffer);
|
||||
}
|
||||
|
|
@ -315,7 +315,7 @@ void Logger_Backtrace(String* trace, void* ctx) {
|
|||
#endif
|
||||
Logger_Log(&str);
|
||||
}
|
||||
String_AppendConst(trace, "\r\n");
|
||||
String_AppendConst(trace, _NL);
|
||||
}
|
||||
#elif defined CC_BUILD_UNWIND
|
||||
#include <unwind.h>
|
||||
|
|
@ -344,7 +344,7 @@ static _Unwind_Reason_Code Logger_DumpFrame(struct _Unwind_Context* ctx, void* a
|
|||
|
||||
void Logger_Backtrace(String* trace, void* ctx) {
|
||||
_Unwind_Backtrace(Logger_DumpFrame, trace);
|
||||
String_AppendConst(trace, "\n");
|
||||
String_AppendConst(trace, _NL);
|
||||
}
|
||||
#elif defined CC_BUILD_POSIX
|
||||
#include <execinfo.h>
|
||||
|
|
@ -370,10 +370,14 @@ void Logger_Backtrace(String* trace, void* ctx) {
|
|||
String_AppendString(trace, &str);
|
||||
Logger_Log(&str);
|
||||
}
|
||||
|
||||
String_AppendConst(trace, "\n");
|
||||
String_AppendConst(trace, _NL);
|
||||
}
|
||||
#endif
|
||||
static void Logger_DumpBacktrace(String* str, void* ctx) {
|
||||
static const String backtrace = String_FromConst("-- backtrace --" _NL);
|
||||
Logger_Log(&backtrace);
|
||||
Logger_Backtrace(str, ctx);
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
|
@ -382,64 +386,60 @@ void Logger_Backtrace(String* trace, void* ctx) {
|
|||
/* Unfortunately, operating systems vary wildly in how they name and access registers for dumping */
|
||||
/* So this is the simplest way to avoid duplicating code on each platform */
|
||||
#define Logger_Dump_X86() \
|
||||
String_Format3(&str, "eax=%x ebx=%x ecx=%x" _NL, REG_GET(ax,AX), REG_GET(bx,BX), REG_GET(cx,CX));\
|
||||
String_Format3(&str, "edx=%x esi=%x edi=%x" _NL, REG_GET(dx,DX), REG_GET(si,SI), REG_GET(di,DI));\
|
||||
String_Format3(&str, "eip=%x ebp=%x esp=%x" _NL, REG_GET(ip,IP), REG_GET(bp,BP), REG_GET(sp,SP));
|
||||
String_Format3(str, "eax=%x ebx=%x ecx=%x" _NL, REG_GET(ax,AX), REG_GET(bx,BX), REG_GET(cx,CX));\
|
||||
String_Format3(str, "edx=%x esi=%x edi=%x" _NL, REG_GET(dx,DX), REG_GET(si,SI), REG_GET(di,DI));\
|
||||
String_Format3(str, "eip=%x ebp=%x esp=%x" _NL, REG_GET(ip,IP), REG_GET(bp,BP), REG_GET(sp,SP));
|
||||
|
||||
#define Logger_Dump_X64() \
|
||||
String_Format3(&str, "rax=%x rbx=%x rcx=%x" _NL, REG_GET(ax,AX), REG_GET(bx,BX), REG_GET(cx,CX));\
|
||||
String_Format3(&str, "rdx=%x rsi=%x rdi=%x" _NL, REG_GET(dx,DX), REG_GET(si,SI), REG_GET(di,DI));\
|
||||
String_Format3(&str, "rip=%x rbp=%x rsp=%x" _NL, REG_GET(ip,IP), REG_GET(bp,BP), REG_GET(sp,SP));\
|
||||
String_Format3(&str, "r8 =%x r9 =%x r10=%x" _NL, REG_GET(8,8), REG_GET(9,9), REG_GET(10,10));\
|
||||
String_Format3(&str, "r11=%x r12=%x r13=%x" _NL, REG_GET(11,11), REG_GET(12,12), REG_GET(13,13));\
|
||||
String_Format2(&str, "r14=%x r15=%x" _NL, REG_GET(14,14), REG_GET(15,15));
|
||||
String_Format3(str, "rax=%x rbx=%x rcx=%x" _NL, REG_GET(ax,AX), REG_GET(bx,BX), REG_GET(cx,CX));\
|
||||
String_Format3(str, "rdx=%x rsi=%x rdi=%x" _NL, REG_GET(dx,DX), REG_GET(si,SI), REG_GET(di,DI));\
|
||||
String_Format3(str, "rip=%x rbp=%x rsp=%x" _NL, REG_GET(ip,IP), REG_GET(bp,BP), REG_GET(sp,SP));\
|
||||
String_Format3(str, "r8 =%x r9 =%x r10=%x" _NL, REG_GET(8,8), REG_GET(9,9), REG_GET(10,10));\
|
||||
String_Format3(str, "r11=%x r12=%x r13=%x" _NL, REG_GET(11,11), REG_GET(12,12), REG_GET(13,13));\
|
||||
String_Format2(str, "r14=%x r15=%x" _NL, REG_GET(14,14), REG_GET(15,15));
|
||||
|
||||
#define Logger_Dump_PPC() \
|
||||
String_Format4(&str, "r0 =%x r1 =%x r2 =%x r3 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2), REG_GNUM(3)); \
|
||||
String_Format4(&str, "r4 =%x r5 =%x r6 =%x r7 =%x" _NL, REG_GNUM(4), REG_GNUM(5), REG_GNUM(6), REG_GNUM(7)); \
|
||||
String_Format4(&str, "r8 =%x r9 =%x r10=%x r11=%x" _NL, REG_GNUM(8), REG_GNUM(9), REG_GNUM(10), REG_GNUM(11)); \
|
||||
String_Format4(&str, "r12=%x r13=%x r14=%x r15=%x" _NL, REG_GNUM(12), REG_GNUM(13), REG_GNUM(14), REG_GNUM(15)); \
|
||||
String_Format4(&str, "r16=%x r17=%x r18=%x r19=%x" _NL, REG_GNUM(16), REG_GNUM(17), REG_GNUM(18), REG_GNUM(19)); \
|
||||
String_Format4(&str, "r20=%x r21=%x r22=%x r23=%x" _NL, REG_GNUM(20), REG_GNUM(21), REG_GNUM(22), REG_GNUM(23)); \
|
||||
String_Format4(&str, "r24=%x r25=%x r26=%x r27=%x" _NL, REG_GNUM(24), REG_GNUM(25), REG_GNUM(26), REG_GNUM(27)); \
|
||||
String_Format4(&str, "r28=%x r29=%x r30=%x r31=%x" _NL, REG_GNUM(28), REG_GNUM(29), REG_GNUM(30), REG_GNUM(31)); \
|
||||
String_Format3(&str, "pc =%x lr =%x ctr=%x" _NL, REG_GET(srr0, SRR0), REG_GET(lr, LR), REG_GET(ctr,CTR));
|
||||
String_Format4(str, "r0 =%x r1 =%x r2 =%x r3 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2), REG_GNUM(3)); \
|
||||
String_Format4(str, "r4 =%x r5 =%x r6 =%x r7 =%x" _NL, REG_GNUM(4), REG_GNUM(5), REG_GNUM(6), REG_GNUM(7)); \
|
||||
String_Format4(str, "r8 =%x r9 =%x r10=%x r11=%x" _NL, REG_GNUM(8), REG_GNUM(9), REG_GNUM(10), REG_GNUM(11)); \
|
||||
String_Format4(str, "r12=%x r13=%x r14=%x r15=%x" _NL, REG_GNUM(12), REG_GNUM(13), REG_GNUM(14), REG_GNUM(15)); \
|
||||
String_Format4(str, "r16=%x r17=%x r18=%x r19=%x" _NL, REG_GNUM(16), REG_GNUM(17), REG_GNUM(18), REG_GNUM(19)); \
|
||||
String_Format4(str, "r20=%x r21=%x r22=%x r23=%x" _NL, REG_GNUM(20), REG_GNUM(21), REG_GNUM(22), REG_GNUM(23)); \
|
||||
String_Format4(str, "r24=%x r25=%x r26=%x r27=%x" _NL, REG_GNUM(24), REG_GNUM(25), REG_GNUM(26), REG_GNUM(27)); \
|
||||
String_Format4(str, "r28=%x r29=%x r30=%x r31=%x" _NL, REG_GNUM(28), REG_GNUM(29), REG_GNUM(30), REG_GNUM(31)); \
|
||||
String_Format3(str, "pc =%x lr =%x ctr=%x" _NL, REG_GET(srr0, SRR0), REG_GET(lr, LR), REG_GET(ctr,CTR));
|
||||
|
||||
#define Logger_Dump_ARM32() \
|
||||
String_Format3(&str, "r0 =%x r1 =%x r2 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2));\
|
||||
String_Format3(&str, "r3 =%x r4 =%x r5 =%x" _NL, REG_GNUM(3), REG_GNUM(4), REG_GNUM(5));\
|
||||
String_Format3(&str, "r6 =%x r7 =%x r8 =%x" _NL, REG_GNUM(6), REG_GNUM(7), REG_GNUM(8));\
|
||||
String_Format3(&str, "r9 =%x r10=%x fp =%x" _NL, REG_GNUM(9), REG_GNUM(10), REG_GET(fp,FP));\
|
||||
String_Format3(&str, "sp =%x lr =%x pc =%x" _NL, REG_GET(sp,SP), REG_GET(lr,LR), REG_GET(pc,PC));
|
||||
String_Format3(str, "r0 =%x r1 =%x r2 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2));\
|
||||
String_Format3(str, "r3 =%x r4 =%x r5 =%x" _NL, REG_GNUM(3), REG_GNUM(4), REG_GNUM(5));\
|
||||
String_Format3(str, "r6 =%x r7 =%x r8 =%x" _NL, REG_GNUM(6), REG_GNUM(7), REG_GNUM(8));\
|
||||
String_Format3(str, "r9 =%x r10=%x fp =%x" _NL, REG_GNUM(9), REG_GNUM(10), REG_GET(fp,FP));\
|
||||
String_Format3(str, "sp =%x lr =%x pc =%x" _NL, REG_GET(sp,SP), REG_GET(lr,LR), REG_GET(pc,PC));
|
||||
|
||||
#define Logger_Dump_ARM64() \
|
||||
String_Format4(&str, "r0 =%x r1 =%x r2 =%x r3 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2), REG_GNUM(3)); \
|
||||
String_Format4(&str, "r4 =%x r5 =%x r6 =%x r7 =%x" _NL, REG_GNUM(4), REG_GNUM(5), REG_GNUM(6), REG_GNUM(7)); \
|
||||
String_Format4(&str, "r8 =%x r9 =%x r10=%x r11=%x" _NL, REG_GNUM(8), REG_GNUM(9), REG_GNUM(10), REG_GNUM(11)); \
|
||||
String_Format4(&str, "r12=%x r13=%x r14=%x r15=%x" _NL, REG_GNUM(12), REG_GNUM(13), REG_GNUM(14), REG_GNUM(15)); \
|
||||
String_Format4(&str, "r16=%x r17=%x r18=%x r19=%x" _NL, REG_GNUM(16), REG_GNUM(17), REG_GNUM(18), REG_GNUM(19)); \
|
||||
String_Format4(&str, "r20=%x r21=%x r22=%x r23=%x" _NL, REG_GNUM(20), REG_GNUM(21), REG_GNUM(22), REG_GNUM(23)); \
|
||||
String_Format4(&str, "r24=%x r25=%x r26=%x r27=%x" _NL, REG_GNUM(24), REG_GNUM(25), REG_GNUM(26), REG_GNUM(27)); \
|
||||
String_Format3(&str, "r28=%x r29=%x r30=%x" _NL, REG_GNUM(28), REG_GNUM(29), REG_GNUM(30)); \
|
||||
String_Format2(&str, "sp =%x pc =%x" _NL, REG_GET(sp,SP), REG_GET(pc,PC));
|
||||
String_Format4(str, "r0 =%x r1 =%x r2 =%x r3 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2), REG_GNUM(3)); \
|
||||
String_Format4(str, "r4 =%x r5 =%x r6 =%x r7 =%x" _NL, REG_GNUM(4), REG_GNUM(5), REG_GNUM(6), REG_GNUM(7)); \
|
||||
String_Format4(str, "r8 =%x r9 =%x r10=%x r11=%x" _NL, REG_GNUM(8), REG_GNUM(9), REG_GNUM(10), REG_GNUM(11)); \
|
||||
String_Format4(str, "r12=%x r13=%x r14=%x r15=%x" _NL, REG_GNUM(12), REG_GNUM(13), REG_GNUM(14), REG_GNUM(15)); \
|
||||
String_Format4(str, "r16=%x r17=%x r18=%x r19=%x" _NL, REG_GNUM(16), REG_GNUM(17), REG_GNUM(18), REG_GNUM(19)); \
|
||||
String_Format4(str, "r20=%x r21=%x r22=%x r23=%x" _NL, REG_GNUM(20), REG_GNUM(21), REG_GNUM(22), REG_GNUM(23)); \
|
||||
String_Format4(str, "r24=%x r25=%x r26=%x r27=%x" _NL, REG_GNUM(24), REG_GNUM(25), REG_GNUM(26), REG_GNUM(27)); \
|
||||
String_Format3(str, "r28=%x r29=%x r30=%x" _NL, REG_GNUM(28), REG_GNUM(29), REG_GNUM(30)); \
|
||||
String_Format2(str, "sp =%x pc =%x" _NL, REG_GET(sp,SP), REG_GET(pc,PC));
|
||||
|
||||
#define Logger_Dump_SPARC() \
|
||||
String_Format4(&str, "o0=%x o1=%x o2=%x o3=%x" _NL, REG_GET(o0,O0), REG_GET(o1,O1), REG_GET(o2,O2), REG_GET(o3,O3)); \
|
||||
String_Format4(&str, "o4=%x o5=%x o6=%x o7=%x" _NL, REG_GET(o4,O4), REG_GET(o5,O5), REG_GET(o6,O6), REG_GET(o7,O7)); \
|
||||
String_Format4(&str, "g1=%x g2=%x g3=%x g4=%x" _NL, REG_GET(g1,G1), REG_GET(g2,G2), REG_GET(g3,G3), REG_GET(g4,G4)); \
|
||||
String_Format4(&str, "g5=%x g6=%x g7=%x y =%x" _NL, REG_GET(g5,G5), REG_GET(g6,G6), REG_GET(g7,G7), REG_GET( y, Y)); \
|
||||
String_Format2(&str, "pc=%x nc=%x" _NL, REG_GET(pc,PC), REG_GET(npc,nPC));
|
||||
String_Format4(str, "o0=%x o1=%x o2=%x o3=%x" _NL, REG_GET(o0,O0), REG_GET(o1,O1), REG_GET(o2,O2), REG_GET(o3,O3)); \
|
||||
String_Format4(str, "o4=%x o5=%x o6=%x o7=%x" _NL, REG_GET(o4,O4), REG_GET(o5,O5), REG_GET(o6,O6), REG_GET(o7,O7)); \
|
||||
String_Format4(str, "g1=%x g2=%x g3=%x g4=%x" _NL, REG_GET(g1,G1), REG_GET(g2,G2), REG_GET(g3,G3), REG_GET(g4,G4)); \
|
||||
String_Format4(str, "g5=%x g6=%x g7=%x y =%x" _NL, REG_GET(g5,G5), REG_GET(g6,G6), REG_GET(g7,G7), REG_GET( y, Y)); \
|
||||
String_Format2(str, "pc=%x nc=%x" _NL, REG_GET(pc,PC), REG_GET(npc,nPC));
|
||||
|
||||
#if defined CC_BUILD_WEB
|
||||
static void Logger_DumpRegisters(void* ctx) { }
|
||||
static void Logger_PrintRegisters(String* str, void* ctx) { }
|
||||
#elif defined CC_BUILD_WIN
|
||||
static void Logger_DumpRegisters(void* ctx) {
|
||||
String str; char strBuffer[512];
|
||||
CONTEXT* r = (CONTEXT*)ctx;
|
||||
|
||||
String_InitArray(str, strBuffer);
|
||||
String_AppendConst(&str, "-- registers --\r\n");
|
||||
|
||||
/* See CONTEXT in WinNT.h */
|
||||
static void Logger_PrintRegisters(String* str, void* ctx) {
|
||||
CONTEXT* r = (CONTEXT*)ctx;
|
||||
#if defined _M_IX86
|
||||
#define REG_GET(reg, ign) &r->E ## reg
|
||||
Logger_Dump_X86()
|
||||
|
|
@ -447,96 +447,126 @@ static void Logger_DumpRegisters(void* ctx) {
|
|||
#define REG_GET(reg, ign) &r->R ## reg
|
||||
Logger_Dump_X64()
|
||||
#else
|
||||
#error "Unknown machine type"
|
||||
#error "Unknown CPU architecture"
|
||||
#endif
|
||||
Logger_Log(&str);
|
||||
}
|
||||
#elif defined CC_BUILD_POSIX
|
||||
static void Logger_DumpRegisters(void* ctx) {
|
||||
String str; char strBuffer[512];
|
||||
#if defined CC_BUILD_OPENBSD
|
||||
struct sigcontext r;
|
||||
r = *((ucontext_t*)ctx);
|
||||
#elif defined CC_BUILD_LINUX && __PPC__ && __WORDSIZE == 32
|
||||
/* see sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h in glibc */
|
||||
mcontext_t r;
|
||||
r = *((ucontext_t*)ctx)->uc_mcontext.uc_regs;
|
||||
#else
|
||||
mcontext_t r;
|
||||
r = ((ucontext_t*)ctx)->uc_mcontext;
|
||||
#endif
|
||||
|
||||
String_InitArray(str, strBuffer);
|
||||
String_AppendConst(&str, "-- registers --\n");
|
||||
|
||||
/* Linux: See /usr/include/sys/ucontext.h */
|
||||
/* OSX: See /usr/include/mach/i386/_structs.h */
|
||||
/* Solaris: See /usr/include/sys/regset.h */
|
||||
/* NetBSD: See /usr/include/i386/mcontext.h */
|
||||
/* OpenBSD: See /usr/include/machine/signal.h */
|
||||
|
||||
#elif defined CC_BUILD_OSX
|
||||
/* See /usr/include/mach/i386/_structs.h */
|
||||
static void Logger_PrintRegisters(String* str, void* ctx) {
|
||||
mcontext_t r = ((ucontext_t*)ctx)->uc_mcontext;
|
||||
#if defined __i386__
|
||||
#if defined CC_BUILD_LINUX
|
||||
#define REG_GET(ign, reg) &r.gregs[REG_E##reg]
|
||||
#elif defined CC_BUILD_OSX
|
||||
#define REG_GET(reg, ign) &r->__ss.__e##reg
|
||||
#elif defined CC_BUILD_SOLARIS
|
||||
#define REG_GET(ign, reg) &r.gregs[E##reg]
|
||||
#elif defined CC_BUILD_FREEBSD
|
||||
#define REG_GET(reg, ign) &r.mc_e##reg
|
||||
#elif defined CC_BUILD_OPENBSD
|
||||
#define REG_GET(reg, ign) &r.sc_e##reg
|
||||
#elif defined CC_BUILD_NETBSD
|
||||
#define REG_GET(ign, reg) &r.__gregs[_REG_E##reg]
|
||||
#endif
|
||||
#define REG_GET(reg, ign) &r->__ss.__e##reg
|
||||
Logger_Dump_X86()
|
||||
#elif defined __x86_64__
|
||||
#if defined CC_BUILD_LINUX
|
||||
#define REG_GET(ign, reg) &r.gregs[REG_R##reg]
|
||||
#elif defined CC_BUILD_OSX
|
||||
#define REG_GET(reg, ign) &r->__ss.__r##reg
|
||||
#elif defined CC_BUILD_SOLARIS
|
||||
#define REG_GET(ign, reg) &r.gregs[REG_R##reg]
|
||||
#elif defined CC_BUILD_FREEBSD
|
||||
#define REG_GET(reg, ign) &r.mc_r##reg
|
||||
#elif defined CC_BUILD_OPENBSD
|
||||
#define REG_GET(reg, ign) &r.sc_r##reg
|
||||
#elif defined CC_BUILD_NETBSD
|
||||
#define REG_GET(ign, reg) &r.__gregs[_REG_R##reg]
|
||||
#endif
|
||||
#define REG_GET(reg, ign) &r->__ss.__r##reg
|
||||
Logger_Dump_X64()
|
||||
#elif defined __ppc__ || defined __PPC__
|
||||
#if defined CC_BUILD_OSX
|
||||
#define REG_GNUM(num) &r->__ss.__r##num
|
||||
#define REG_GET(reg, ign) &r->__ss.__##reg
|
||||
#elif defined CC_BUILD_LINUX
|
||||
#define REG_GNUM(num) &r.gregs[num]
|
||||
#endif
|
||||
#elif defined __ppc__
|
||||
#define REG_GNUM(num) &r->__ss.__r##num
|
||||
#define REG_GET(reg, ign) &r->__ss.__##reg
|
||||
Logger_Dump_PPC()
|
||||
#elif defined __aarch64__
|
||||
#if defined CC_BUILD_LINUX
|
||||
#define REG_GNUM(num) &r.regs[num]
|
||||
#define REG_GET(reg, ign) &r.##reg
|
||||
#endif
|
||||
Logger_Dump_ARM64()
|
||||
#elif defined __arm__
|
||||
#if defined CC_BUILD_LINUX
|
||||
#define REG_GNUM(num) &r.arm_r##num
|
||||
#define REG_GET(reg, ign) &r.arm_##reg
|
||||
#endif
|
||||
Logger_Dump_ARM32()
|
||||
#elif defined __sparc__
|
||||
#if defined CC_BUILD_LINUX
|
||||
#define REG_GET(ign, reg) &r.gregs[REG_##reg]
|
||||
#endif
|
||||
Logger_Dump_SPARC()
|
||||
#else
|
||||
#error "Unknown ISA/architecture"
|
||||
#error "Unknown CPU architecture"
|
||||
#endif
|
||||
}
|
||||
#elif defined CC_BUILD_LINUX
|
||||
/* See /usr/include/sys/ucontext.h */
|
||||
static void Logger_PrintRegisters(String* str, void* ctx) {
|
||||
#if __PPC__ && __WORDSIZE == 32
|
||||
/* See sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h in glibc */
|
||||
mcontext_t r = *((ucontext_t*)ctx)->uc_mcontext.uc_regs;
|
||||
#else
|
||||
mcontext_t r = ((ucontext_t*)ctx)->uc_mcontext;
|
||||
#endif
|
||||
|
||||
Logger_Log(&str);
|
||||
#if defined __i386__
|
||||
#define REG_GET(ign, reg) &r.gregs[REG_E##reg]
|
||||
Logger_Dump_X86()
|
||||
#elif defined __x86_64__
|
||||
#define REG_GET(ign, reg) &r.gregs[REG_R##reg]
|
||||
Logger_Dump_X64()
|
||||
#elif defined __PPC__
|
||||
#define REG_GNUM(num) &r.gregs[num]
|
||||
Logger_Dump_PPC()
|
||||
#elif defined __aarch64__
|
||||
#define REG_GNUM(num) &r.regs[num]
|
||||
#define REG_GET(reg, ign) &r.##reg
|
||||
Logger_Dump_ARM64()
|
||||
#elif defined __arm__
|
||||
#define REG_GNUM(num) &r.arm_r##num
|
||||
#define REG_GET(reg, ign) &r.arm_##reg
|
||||
Logger_Dump_ARM32()
|
||||
#elif defined __sparc__
|
||||
#define REG_GET(ign, reg) &r.gregs[REG_##reg]
|
||||
Logger_Dump_SPARC()
|
||||
#else
|
||||
#error "Unknown CPU architecture"
|
||||
#endif
|
||||
}
|
||||
#elif defined CC_BUILD_SOLARIS
|
||||
/* See /usr/include/sys/regset.h */
|
||||
static void Logger_PrintRegisters(String* str, void* ctx) {
|
||||
mcontext_t r = ((ucontext_t*)ctx)->uc_mcontext;
|
||||
|
||||
#if defined __i386__
|
||||
#define REG_GET(ign, reg) &r.gregs[E##reg]
|
||||
Logger_Dump_X86()
|
||||
#elif defined __x86_64__
|
||||
#define REG_GET(ign, reg) &r.gregs[REG_R##reg]
|
||||
Logger_Dump_X64()
|
||||
#else
|
||||
#error "Unknown CPU architecture"
|
||||
#endif
|
||||
}
|
||||
#elif defined CC_BUILD_NETBSD
|
||||
/* See /usr/include/i386/mcontext.h */
|
||||
static void Logger_PrintRegisters(String* str, void* ctx) {
|
||||
mcontext_t r = ((ucontext_t*)ctx)->uc_mcontext;
|
||||
#if defined __i386__
|
||||
#define REG_GET(ign, reg) &r.__gregs[_REG_E##reg]
|
||||
Logger_Dump_X86()
|
||||
#elif defined __x86_64__
|
||||
#define REG_GET(ign, reg) &r.__gregs[_REG_R##reg]
|
||||
Logger_Dump_X64()
|
||||
#else
|
||||
#error "Unknown CPU architecture"
|
||||
#endif
|
||||
}
|
||||
#elif defined CC_BUILD_FREEBSD
|
||||
static void Logger_PrintRegisters(String* str, void* ctx) {
|
||||
mcontext_t r = ((ucontext_t*)ctx)->uc_mcontext;
|
||||
#if defined __i386__
|
||||
#define REG_GET(reg, ign) &r.mc_e##reg
|
||||
Logger_Dump_X86()
|
||||
#elif defined __x86_64__
|
||||
#define REG_GET(reg, ign) &r.mc_r##reg
|
||||
Logger_Dump_X64()
|
||||
#else
|
||||
#error "Unknown CPU architecture"
|
||||
#endif
|
||||
}
|
||||
#elif defined CC_BUILD_OPENBSD
|
||||
/* See /usr/include/machine/signal.h */
|
||||
static void Logger_PrintRegisters(String* str, void* ctx) {
|
||||
struct sigcontext r = *((ucontext_t*)ctx);
|
||||
#if defined __i386__
|
||||
#define REG_GET(reg, ign) &r.sc_e##reg
|
||||
Logger_Dump_X86()
|
||||
#elif defined __x86_64__
|
||||
#define REG_GET(reg, ign) &r.sc_r##reg
|
||||
Logger_Dump_X64()
|
||||
#else
|
||||
#error "Unknown CPU architecture"
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
static void Logger_DumpRegisters(void* ctx) {
|
||||
String str; char strBuffer[512];
|
||||
String_InitArray(str, strBuffer);
|
||||
|
||||
String_AppendConst(&str, "-- registers --" _NL);
|
||||
Logger_PrintRegisters(&str, ctx);
|
||||
Logger_Log(&str);
|
||||
}
|
||||
|
||||
|
||||
/*########################################################################################################################*
|
||||
|
|
@ -775,12 +805,6 @@ static void Logger_LogCrashHeader(void) {
|
|||
Logger_Log(&msg);
|
||||
}
|
||||
|
||||
static void Logger_DumpBacktrace(String* str, void* ctx) {
|
||||
static const String backtrace = String_FromConst("-- backtrace --" _NL);
|
||||
Logger_Log(&backtrace);
|
||||
Logger_Backtrace(str, ctx);
|
||||
}
|
||||
|
||||
static void Logger_AbortCommon(ReturnCode result, const char* raw_msg, void* ctx) {
|
||||
String msg; char msgBuffer[3070 + 1];
|
||||
String_InitArray_NT(msg, msgBuffer);
|
||||
|
|
|
|||
|
|
@ -22,13 +22,17 @@ typedef int FileHandle;
|
|||
#define UPDATE_FILENAME "update.sh"
|
||||
#endif
|
||||
|
||||
/* android app and VM handle */
|
||||
#ifdef CC_BUILD_ANDROID
|
||||
void* App_Handle;
|
||||
void* VM_Handle;
|
||||
#endif
|
||||
|
||||
/* Origin points for when seeking in a file. */
|
||||
enum File_SeekFrom { FILE_SEEKFROM_BEGIN, FILE_SEEKFROM_CURRENT, FILE_SEEKFROM_END };
|
||||
/* Number of milliseconds since 01/01/0001 to start of unix time. */
|
||||
#define UNIX_EPOCH 62135596800000ULL
|
||||
|
||||
/* Newline for console and text files. */
|
||||
extern const char* Platform_NewLine;
|
||||
extern const ReturnCode ReturnCode_FileShareViolation;
|
||||
extern const ReturnCode ReturnCode_FileNotFound;
|
||||
extern const ReturnCode ReturnCode_SocketInProgess;
|
||||
|
|
|
|||
|
|
@ -177,7 +177,8 @@ int main(int argc, char** argv) {
|
|||
#ifdef CC_BUILD_ANDROID
|
||||
#include <android_native_app_glue.h>
|
||||
void android_main(struct android_app* app) {
|
||||
Window_Handle = app;
|
||||
App_Handle = app;
|
||||
VM_Handle = app->activity->vm;
|
||||
main(0, NULL);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue