From 1be1abc0afdbeb3086b279b124f8f2b823626ca0 Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sat, 24 Feb 2018 18:57:00 -0600 Subject: [PATCH] Add printaddr, printstate --- include/vm_debug.h | 12 +++++++----- src/vm_debug.c | 28 ++++++++++++++++++++++++---- tests/vm_debug.c | 14 ++++++++++++++ 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/include/vm_debug.h b/include/vm_debug.h index 51a54b0..7ad1a42 100644 --- a/include/vm_debug.h +++ b/include/vm_debug.h @@ -15,16 +15,16 @@ typedef struct { char *name; char *abbrev; - /* - * The number of arguments we expect to see - */ - int nargs; - /* * The function that will do something with the command's input */ vm_debug_func handler; + /* + * The number of arguments we expect to see + */ + int nargs; + /* * What do our arguments look like? */ @@ -68,6 +68,8 @@ extern vm_debug_cmd *vm_debug_find_cmd(const char *); extern void vm_debug_execute(const char *); extern DEBUG_CMD(help); +extern DEBUG_CMD(printaddr); +extern DEBUG_CMD(printstate); extern DEBUG_CMD(resume); #endif diff --git a/src/vm_debug.c b/src/vm_debug.c index eaa37d9..238e3ee 100644 --- a/src/vm_debug.c +++ b/src/vm_debug.c @@ -7,14 +7,19 @@ #include #include +#include "mos6502.h" #include "vm_debug.h" #include "vm_di.h" #include "vm_reflect.h" vm_debug_cmd cmdtable[] = { - { "help", "h", 0, vm_debug_cmd_help, "", + { "help", "h", vm_debug_cmd_help, 0, "", "Print out this list of commands", }, - { "resume", "r", 0, vm_debug_cmd_resume, "", + { "printaddr", "pa", vm_debug_cmd_printaddr, 1, "", + "Print the value at memory address ", }, + { "printstate", "ps", vm_debug_cmd_printstate, 0, "", + "Print the machine and CPU state", }, + { "resume", "r", vm_debug_cmd_resume, 0, "", "Resume execution", }, }; @@ -37,8 +42,7 @@ vm_debug_next_arg(char **str) break; } - return tok; -} + return tok; } int vm_debug_addr(const char *str) @@ -161,3 +165,19 @@ DEBUG_CMD(resume) { vm_reflect_pause(NULL); } + +DEBUG_CMD(printstate) +{ + vm_reflect_cpu_info(NULL); + vm_reflect_machine_info(NULL); +} + +DEBUG_CMD(printaddr) +{ + // FIXME: This is... too machine-specific; we need to abstract this logic + + mos6502 *cpu = (mos6502 *)vm_di_get(VM_CPU); + FILE *stream = (FILE *)vm_di_get(VM_OUTPUT); + + fprintf(stream, "$%02X\n", mos6502_get(cpu, args->addr1)); +} diff --git a/tests/vm_debug.c b/tests/vm_debug.c index 83a7367..d8cfb11 100644 --- a/tests/vm_debug.c +++ b/tests/vm_debug.c @@ -94,3 +94,17 @@ Test(vm_debug, cmd_resume) cr_assert_eq(mach->paused, false); } + +Test(vm_debug, cmd_printstate) +{ + vm_debug_cmd_printstate(&args); + cr_assert_neq(strlen(buf), 0); +} + +Test(vm_debug, cmd_printaddr) +{ + args.addr1 = 123; + mos6502_set(mach->cpu, args.addr1, 127); + vm_debug_cmd_printaddr(&args); + cr_assert_str_eq(buf, "$7F\n"); +}