all repos — mgba @ fb267a32ff4b9ff6dc8688610b936cb8450edd8e

mGBA Game Boy Advance Emulator

Stack trace: coding style cleanup
Adam Higerd chighland@gmail.com
Mon, 27 Jul 2020 22:30:43 -0500
commit

fb267a32ff4b9ff6dc8688610b936cb8450edd8e

parent

1a9ead1e25587c0ce424ca3063b6c0abdb6f5328

M include/mgba/internal/arm/arm.hinclude/mgba/internal/arm/arm.h

@@ -70,7 +70,7 @@ struct ARMCore;

union PSR { struct { -#if defined(__BIG_ENDIAN__) +#ifdef __BIG_ENDIAN__ unsigned n : 1; unsigned z : 1; unsigned c : 1;

@@ -94,7 +94,7 @@ #endif

}; struct { -#if defined(__BIG_ENDIAN__) +#ifdef __BIG_ENDIAN__ uint8_t flags; uint8_t status; uint8_t extension;
M include/mgba/internal/arm/isa-inlines.hinclude/mgba/internal/arm/isa-inlines.h

@@ -99,15 +99,12 @@ ARMSetPrivilegeMode(cpu, cpu->cpsr.priv);

cpu->irqh.readCPSR(cpu); } +static inline uint32_t _ARMInstructionLength(struct ARMCore* cpu) { + return cpu->cpsr.t == MODE_ARM ? WORD_SIZE_ARM : WORD_SIZE_THUMB; +} + static inline uint32_t _ARMPCAddress(struct ARMCore* cpu) { - int instructionLength; - enum ExecutionMode mode = cpu->cpsr.t; - if (mode == MODE_ARM) { - instructionLength = WORD_SIZE_ARM; - } else { - instructionLength = WORD_SIZE_THUMB; - } - return cpu->gprs[ARM_PC] - instructionLength * 2; + return cpu->gprs[ARM_PC] - _ARMInstructionLength(cpu) * 2; } #endif
M include/mgba/internal/debugger/stack-trace.hinclude/mgba/internal/debugger/stack-trace.h

@@ -1,4 +1,4 @@

-/* Copyright (c) 2013-2019 Jeffrey Pfau +/* Copyright (c) 2013-2020 Jeffrey Pfau * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
M include/mgba/internal/sm83/sm83.hinclude/mgba/internal/sm83/sm83.h

@@ -74,7 +74,7 @@

void (*hitIllegal)(struct SM83Core* cpu); }; -#if defined(__BIG_ENDIAN__) +#ifdef __BIG_ENDIAN__ #define SM83_REGISTER_PAIR(HIGH, LOW) union { \ struct { \ uint8_t HIGH; \
M src/arm/debugger/debugger.csrc/arm/debugger/debugger.c

@@ -13,13 +13,8 @@ #include <mgba/internal/arm/debugger/memory-debugger.h>

#include <mgba/internal/debugger/parser.h> #include <mgba/internal/debugger/stack-trace.h> #include <mgba-util/math.h> -#include <stdint.h> DEFINE_VECTOR(ARMDebugBreakpointList, struct ARMDebugBreakpoint); - -static inline uint32_t ARMDebuggerGetInstructionLength(struct ARMCore* cpu) { - return cpu->cpsr.t == MODE_ARM ? WORD_SIZE_ARM : WORD_SIZE_THUMB; -} static bool ARMDebuggerUpdateStackTraceInternal(struct mDebuggerPlatform* d, uint32_t pc) { struct ARMDebugger* debugger = (struct ARMDebugger*) d;

@@ -34,7 +29,7 @@ if (_ARMModeHasSPSR(cpu->cpsr.priv)) {

struct mStackFrame* irqFrame = mStackTraceGetFrame(stack, 0); // TODO: uint32_t ivtBase = ARMControlRegIsVE(cpu->cp15.r1.c0) ? 0xFFFF0000 : 0x00000000; uint32_t ivtBase = 0x00000000; - if (ivtBase <= pc && pc < ivtBase + 0x20 && !(irqFrame && _ARMModeHasSPSR(((struct ARMRegisterFile*)irqFrame->regs)->cpsr.priv))) { + if (ivtBase <= pc && pc < ivtBase + 0x20 && !(irqFrame && _ARMModeHasSPSR(((struct ARMRegisterFile*) irqFrame->regs)->cpsr.priv))) { // TODO: Potential enhancement opportunity: add break-on-exception mode irqFrame = mStackTracePush(stack, pc, pc, cpu->gprs[ARM_SP], &cpu->regs); irqFrame->interrupt = true;

@@ -79,7 +74,8 @@ return false;

} destAddress = cpu->gprs[info.op1.reg]; } else { - abort(); // Should be unreachable + mLOG(DEBUGGER, ERROR, "Unknown branch operand in stack trace"); + return false; } if (info.branchType & ARM_BRANCH_INDIRECT) {

@@ -87,7 +83,7 @@ destAddress = cpu->memory.load32(cpu, destAddress, NULL);

} if (isCall) { - int instructionLength = ARMDebuggerGetInstructionLength(debugger->cpu); + int instructionLength = _ARMInstructionLength(debugger->cpu); frame = mStackTracePush(stack, pc, destAddress + instructionLength, cpu->gprs[ARM_SP], &cpu->regs); if (!(debugger->stackTraceMode & STACK_TRACE_BREAK_ON_CALL)) { return false;

@@ -138,7 +134,7 @@ }

static void ARMDebuggerCheckBreakpoints(struct mDebuggerPlatform* d) { struct ARMDebugger* debugger = (struct ARMDebugger*) d; - int instructionLength = ARMDebuggerGetInstructionLength(debugger->cpu); + int instructionLength = _ARMInstructionLength(debugger->cpu); uint32_t pc = debugger->cpu->gprs[ARM_PC] - instructionLength; if (debugger->stackTraceMode != STACK_TRACE_DISABLED && ARMDebuggerUpdateStackTraceInternal(d, pc)) { return;

@@ -241,7 +237,6 @@ _destroyWatchpoint(mWatchpointListGetPointer(&debugger->watchpoints, i));

} ARMDebugBreakpointListDeinit(&debugger->swBreakpoints); mWatchpointListDeinit(&debugger->watchpoints); - mStackTraceDeinit(&platform->p->stackTrace); }

@@ -432,7 +427,8 @@ }

size_t regStringLen = *length; ARMDebuggerFormatRegisters(&cpu->regs, out, &regStringLen); - *length = regStringLen + snprintf(out + regStringLen, *length - regStringLen, " | %s", disassembly); + regStringLen += snprintf(out + regStringLen, *length - regStringLen, " | %s", disassembly); + *length = regStringLen; } static void ARMDebuggerFormatRegisters(struct ARMRegisterFile* regs, char* out, size_t* length) {

@@ -445,7 +441,7 @@ regs->cpsr.packed);

} static void ARMDebuggerFrameFormatRegisters(struct mStackFrame* frame, char* out, size_t* length) { - ARMDebuggerFormatRegisters((struct ARMRegisterFile*)frame->regs, out, length); + ARMDebuggerFormatRegisters(frame->regs, out, length); } bool ARMDebuggerGetRegister(struct mDebuggerPlatform* d, const char* name, int32_t* value) {

@@ -540,7 +536,7 @@ }

static bool ARMDebuggerUpdateStackTrace(struct mDebuggerPlatform* d) { struct ARMDebugger* debugger = (struct ARMDebugger*) d; - int instructionLength = ARMDebuggerGetInstructionLength(debugger->cpu); + int instructionLength = _ARMInstructionLength(debugger->cpu); uint32_t pc = debugger->cpu->gprs[ARM_PC] - instructionLength; if (debugger->stackTraceMode != STACK_TRACE_DISABLED) { return ARMDebuggerUpdateStackTraceInternal(d, pc);
M src/debugger/cli-debugger.csrc/debugger/cli-debugger.c

@@ -178,8 +178,8 @@ debugger->d.state = debugger->traceRemaining != 0 ? DEBUGGER_CALLBACK : DEBUGGER_RUNNING;

} static void _next(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { - struct mDebuggerPlatform* platform = debugger->d.platform; UNUSED(dv); + struct mDebuggerPlatform* platform = debugger->d.platform; debugger->d.core->step(debugger->d.core); if (platform->getStackTraceMode && platform->getStackTraceMode(platform) != STACK_TRACE_DISABLED) { platform->updateStackTrace(platform);
M src/debugger/stack-trace.csrc/debugger/stack-trace.c

@@ -1,4 +1,4 @@

-/* Copyright (c) 2013-2016 Jeffrey Pfau +/* Copyright (c) 2013-2020 Jeffrey Pfau * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this