Add support for cross compiling to windows for ARM. No clue if it actually works at all though.

This commit is contained in:
UnknownShadow200 2020-06-28 00:01:27 +10:00
parent e29e8e1ae9
commit 2484ff0117

View File

@ -179,7 +179,10 @@ struct SymbolAndName { IMAGEHLP_SYMBOL Symbol; char Name[256]; };
static int GetFrames(CONTEXT* ctx, cc_uintptr* addrs, int max) { static int GetFrames(CONTEXT* ctx, cc_uintptr* addrs, int max) {
STACKFRAME frame = { 0 }; STACKFRAME frame = { 0 };
DWORD type; HANDLE process, thread;
int count, type;
CONTEXT copy;
frame.AddrPC.Mode = AddrModeFlat; frame.AddrPC.Mode = AddrModeFlat;
frame.AddrFrame.Mode = AddrModeFlat; frame.AddrFrame.Mode = AddrModeFlat;
frame.AddrStack.Mode = AddrModeFlat; frame.AddrStack.Mode = AddrModeFlat;
@ -195,13 +198,12 @@ static int GetFrames(CONTEXT* ctx, cc_uintptr* addrs, int max) {
frame.AddrFrame.Offset = ctx->Rsp; frame.AddrFrame.Offset = ctx->Rsp;
frame.AddrStack.Offset = ctx->Rsp; frame.AddrStack.Offset = ctx->Rsp;
#else #else
#error "Unknown CPU architecture" /* Always available after XP, so use that */
return RtlCaptureStackBackTrace(0, max, (void**)addrs, NULL);
#endif #endif
process = GetCurrentProcess();
HANDLE process = GetCurrentProcess(); thread = GetCurrentThread();
HANDLE thread = GetCurrentThread(); copy = *ctx;
int count;
CONTEXT copy = *ctx;
for (count = 0; count < max; count++) { for (count = 0; count < max; count++) {
if (!StackWalk(type, process, thread, &frame, &copy, NULL, SymFunctionTableAccess, SymGetModuleBase, NULL)) break; if (!StackWalk(type, process, thread, &frame, &copy, NULL, SymFunctionTableAccess, SymGetModuleBase, NULL)) break;
@ -357,8 +359,9 @@ String_Format3(str, "pc =%x lr =%x ctr=%x" _NL, REG_GET_PC(), REG_GET_LR(), REG
String_Format3(str, "r0 =%x r1 =%x r2 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2));\ 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, "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, "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, "r9 =%x r10=%x fp =%x" _NL, REG_GNUM(9), REG_GNUM(10), REG_GET_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, "ip =%x sp =%x lr =%x" _NL, REG_GET_IP(),REG_GET(sp,Sp),REG_GET(lr,Lr));\
String_Format1(str, "pc =%x" _NL, REG_GET(pc,Pc));
#define Dump_ARM64() \ #define 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, "r0 =%x r1 =%x r2 =%x r3 =%x" _NL, REG_GNUM(0), REG_GNUM(1), REG_GNUM(2), REG_GNUM(3)); \
@ -390,6 +393,12 @@ static void PrintRegisters(String* str, void* ctx) {
#elif defined _M_X64 #elif defined _M_X64
#define REG_GET(reg, ign) &r->R ## reg #define REG_GET(reg, ign) &r->R ## reg
Dump_X64() Dump_X64()
#elif defined _M_ARM
#define REG_GNUM(num) &r->R ## num
#define REG_GET(ign,reg) &r-> ## reg
#define REG_GET_FP() &r->R11
#define REG_GET_IP() &r->R12
Dump_ARM32()
#else #else
#error "Unknown CPU architecture" #error "Unknown CPU architecture"
#endif #endif
@ -458,6 +467,8 @@ static void PrintRegisters(String* str, void* ctx) {
#elif defined __arm__ #elif defined __arm__
#define REG_GNUM(num) &r.arm_r##num #define REG_GNUM(num) &r.arm_r##num
#define REG_GET(reg,ign) &r.arm_##reg #define REG_GET(reg,ign) &r.arm_##reg
#define REG_GET_FP() &r.arm_fp
#define REG_GET_IP() &r.arm_ip
Dump_ARM32() Dump_ARM32()
#elif defined __sparc__ #elif defined __sparc__
#define REG_GET(ign, reg) &r.gregs[REG_##reg] #define REG_GET(ign, reg) &r.gregs[REG_##reg]