Initial debugger

This commit is contained in:
Jeffrey Pfau 2013-04-12 01:32:43 -07:00
parent b07e052698
commit 1db7f5b179
4 changed files with 77 additions and 6 deletions

View File

@ -1,5 +1,6 @@
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
project(GBAc) project(GBAc)
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra") set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Wextra")
file(GLOB SOURCES src/*.c) file(GLOB SOURCES src/*.c third-party/linenoise/linenoise.c)
include_directories(${CMAKE_SOURCE_DIR}/third-party/linenoise)
add_executable(gbac ${SOURCES}) add_executable(gbac ${SOURCES})

60
src/debugger.c Normal file
View File

@ -0,0 +1,60 @@
#include "debugger.h"
#include "arm.h"
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include "linenoise.h"
enum {
CMD_QUIT,
CMD_NEXT
};
static inline void _printPSR(union PSR psr) {
printf("%08x [%c%c%c%c%c%c%c]\n", psr.packed,
psr.n ? 'N' : '-',
psr.z ? 'Z' : '-',
psr.c ? 'C' : '-',
psr.v ? 'V' : '-',
psr.i ? 'I' : '-',
psr.f ? 'F' : '-',
psr.t ? 'T' : '-');
}
static void _printStatus(struct ARMDebugger* debugger) {
int r;
for (r = 0; r < 4; ++r) {
printf("%08x %08x %08x %08x\n",
debugger->cpu->gprs[r << 2],
debugger->cpu->gprs[(r << 2) + 1],
debugger->cpu->gprs[(r << 2) + 1],
debugger->cpu->gprs[(r << 2) + 3]);
}
_printPSR(debugger->cpu->cpsr);
}
static int _parse(struct ARMDebugger* debugger, const char* line) {
if (strcasecmp(line, "q") == 0 || strcasecmp(line, "quit") == 0) {
return CMD_QUIT;
}
ARMRun(debugger->cpu);
_printStatus(debugger);
return CMD_NEXT;
}
void ARMDebuggerInit(struct ARMDebugger* debugger, struct ARMCore* cpu) {
debugger->cpu = cpu;
}
void ARMDebuggerEnter(struct ARMDebugger* debugger) {
char* line;
_printStatus(debugger);
while ((line = linenoise("> "))) {
if (_parse(debugger, line) == CMD_QUIT) {
break;
}
free(line);
}
}

11
src/debugger.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef DEBUGGER_H
#define DEBUGGER_H
struct ARMDebugger {
struct ARMCore* cpu;
};
void ARMDebuggerInit(struct ARMDebugger*, struct ARMCore*);
void ARMDebuggerEnter(struct ARMDebugger*);
#endif

View File

@ -1,22 +1,21 @@
#include "arm.h" #include "arm.h"
#include "debugger.h"
#include "gba.h" #include "gba.h"
#include "isa-arm.h"
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
int main(int argc, char** argv) { int main(int argc, char** argv) {
struct ARMDebugger debugger;
struct GBA gba; struct GBA gba;
GBAInit(&gba); GBAInit(&gba);
int fd = open("test.rom", O_RDONLY); int fd = open("test.rom", O_RDONLY);
GBALoadROM(&gba, fd); GBALoadROM(&gba, fd);
gba.cpu.gprs[ARM_PC] = 0x08000004; gba.cpu.gprs[ARM_PC] = 0x08000004;
gba.memory.d.setActiveRegion(&gba.memory.d, gba.cpu.gprs[ARM_PC]); gba.memory.d.setActiveRegion(&gba.memory.d, gba.cpu.gprs[ARM_PC]);
int i; ARMDebuggerInit(&debugger, &gba.cpu);
for (i = 0; i < 1024 * 1024 * 16; ++i) { ARMDebuggerEnter(&debugger);
ARMRun(&gba.cpu);
}
GBADeinit(&gba); GBADeinit(&gba);
close(fd); close(fd);