[WiiU] Redo exception handler format strings

Deals with the infamous devkitPPC "int32_t = long int" thing, and
future-proofs in case they ever change it back.
This commit is contained in:
Ash 2017-11-04 17:11:58 +11:00
parent e39c820cee
commit b49268a9e9
No known key found for this signature in database
GPG Key ID: F8C85A8C836C0A7E

View File

@ -18,6 +18,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <wiiu/os.h>
#include "wiiu_dbg.h"
#include "exception_handler.h"
@ -34,7 +35,7 @@ extern unsigned int __code_end;
#define TEXT_END (unsigned int)&__code_end
void test_os_exceptions(void);
void exception_print_symbol(unsigned int addr);
void exception_print_symbol(uint32_t addr);
typedef struct _framerec
{
@ -91,7 +92,7 @@ void __attribute__((__noreturn__)) exception_cb(OSContext* ctx, OSExceptionType
if (type == OS_EXCEPTION_TYPE_DSI) {
/* Exception type and offending instruction location
Also initializes exception_msgbuf, use buf_add from now on */
buf_add("DSI: Instr at %08X", ctx->srr0);
buf_add("DSI: Instr at %08" PRIX32, ctx->srr0);
/* Was this a read or a write? */
if (ctx->dsisr & DSISR_WRITE_ATTEMPTED) {
buf_add(" bad write to");
@ -107,7 +108,7 @@ void __attribute__((__noreturn__)) exception_cb(OSContext* ctx, OSExceptionType
} else if (ctx->dsisr & DSISR_BAD_CACHING) {
buf_add(" uncached memory at");
}
buf_add(" %08X\n", ctx->dar);
buf_add(" %08" PRIX32 "\n", ctx->dar);
} else if (type == OS_EXCEPTION_TYPE_ISI) {
buf_add("ISI: Bad execute of");
if (ctx->srr1 & SRR1_ISI_TRANSLATION_PROT) {
@ -115,7 +116,7 @@ void __attribute__((__noreturn__)) exception_cb(OSContext* ctx, OSExceptionType
} else if (ctx->srr1 & SRR1_ISI_TRANSLATION_MISS) {
buf_add(" unmapped memory at");
}
buf_add(" %08X\n", ctx->srr0);
buf_add(" %08" PRIX32 "\n", ctx->srr0);
} else if (type == OS_EXCEPTION_TYPE_PROGRAM) {
buf_add("PROG:");
if (ctx->srr1 & SRR1_PROG_BAD_INSTR) {
@ -130,9 +131,9 @@ void __attribute__((__noreturn__)) exception_cb(OSContext* ctx, OSExceptionType
buf_add(" Out-of-spec error (!) at");
}
if (ctx->srr1 & SRR1_PROG_SRR0_INACCURATE) {
buf_add("%08X-ish\n", ctx->srr0);
buf_add("%08" PRIX32 "-ish\n", ctx->srr0);
} else {
buf_add("%08X\n", ctx->srr0);
buf_add("%08" PRIX32 "\n", ctx->srr0);
}
}
@ -140,14 +141,14 @@ void __attribute__((__noreturn__)) exception_cb(OSContext* ctx, OSExceptionType
There's space for two more regs at the end of the last line...
Any ideas for what to put there? */
buf_add( \
"r0 %08X r1 %08X r2 %08X r3 %08X r4 %08X\n" \
"r5 %08X r6 %08X r7 %08X r8 %08X r9 %08X\n" \
"r10 %08X r11 %08X r12 %08X r13 %08X r14 %08X\n" \
"r15 %08X r16 %08X r17 %08X r18 %08X r19 %08X\n" \
"r20 %08X r21 %08X r22 %08X r23 %08X r24 %08X\n" \
"r25 %08X r26 %08X r27 %08X r28 %08X r29 %08X\n" \
"r30 %08X r31 %08X lr %08X sr1 %08X dsi %08X\n" \
"ctr %08X cr %08X xer %08X\n",\
"r0 %08" PRIX32 " r1 %08" PRIX32 " r2 %08" PRIX32 " r3 %08" PRIX32 " r4 %08" PRIX32 "\n" \
"r5 %08" PRIX32 " r6 %08" PRIX32 " r7 %08" PRIX32 " r8 %08" PRIX32 " r9 %08" PRIX32 "\n" \
"r10 %08" PRIX32 " r11 %08" PRIX32 " r12 %08" PRIX32 " r13 %08" PRIX32 " r14 %08" PRIX32 "\n" \
"r15 %08" PRIX32 " r16 %08" PRIX32 " r17 %08" PRIX32 " r18 %08" PRIX32 " r19 %08" PRIX32 "\n" \
"r20 %08" PRIX32 " r21 %08" PRIX32 " r22 %08" PRIX32 " r23 %08" PRIX32 " r24 %08" PRIX32 "\n" \
"r25 %08" PRIX32 " r26 %08" PRIX32 " r27 %08" PRIX32 " r28 %08" PRIX32 " r29 %08" PRIX32 "\n" \
"r30 %08" PRIX32 " r31 %08" PRIX32 " lr %08" PRIX32 " sr1 %08" PRIX32 " dsi %08" PRIX32 "\n" \
"ctr %08" PRIX32 " cr %08" PRIX32 " xer %08" PRIX32 "\n",\
ctx->gpr[0], ctx->gpr[1], ctx->gpr[2], ctx->gpr[3], ctx->gpr[4], \
ctx->gpr[5], ctx->gpr[6], ctx->gpr[7], ctx->gpr[8], ctx->gpr[9], \
ctx->gpr[10], ctx->gpr[11], ctx->gpr[12], ctx->gpr[13], ctx->gpr[14], \
@ -190,13 +191,13 @@ BOOL __attribute__((__noreturn__)) exception_prog_cb(OSContext* ctx) {
exception_cb(ctx, OS_EXCEPTION_TYPE_PROGRAM);
}
void exception_print_symbol(unsigned int addr) {
void exception_print_symbol(uint32_t addr) {
/* Check if addr is within this RPX's .text */
if (addr >= TEXT_START && addr < TEXT_END) {
char symbolName[64];
OSGetSymbolName(addr, symbolName, 63);
buf_add("%08X(%08X):%s\n", addr, addr - TEXT_START, symbolName);
buf_add("%08" PRIX32 "(%08" PRIX32 "):%s\n", addr, addr - TEXT_START, symbolName);
}
/* Check if addr is within the system library area... */
else if ((addr >= 0x01000000 && addr < 0x01800000) ||
@ -218,23 +219,23 @@ void exception_print_symbol(unsigned int addr) {
*seperator = '|';
/* We got one! */
if (libAddr) {
buf_add("%08X(%08X):%s\n", addr, addr - (unsigned int)libAddr, symbolName);
buf_add("%08" PRIX32 "(%08" PRIX32 "):%s\n", addr, addr - (unsigned int)libAddr, symbolName);
OSDynLoad_Release(libAddr);
return;
}
}
/* Ah well. We can still print the basics. */
buf_add("%08X( ):%s\n", addr, symbolName);
buf_add("%08" PRIX32 "( ):%s\n", addr, symbolName);
}
/* Check if addr is in the HBL range
TODO there's no real reason we couldn't find the symbol here,
it's just laziness and arguably uneccesary bloat */
else if (addr >= 0x00800000 && addr < 0x01000000) {
buf_add("%08X(%08X):<unknown:HBL>\n", addr, addr - 0x00800000);
buf_add("%08" PRIX32 "(%08" PRIX32 "):<unknown:HBL>\n", addr, addr - 0x00800000);
}
/* If all else fails, just say "unknown" */
else {
buf_add("%08X( ):<unknown>\n", addr);
buf_add("%08" PRIX32 "( ):<unknown>\n", addr);
}
}