From 01f230dc853e33410505710d22ebd0ec0bb1fcfb Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Sun, 25 Feb 2018 14:38:24 -0600 Subject: [PATCH] Add unbreak command, unbreak_all() function for testing --- include/vm_debug.h | 4 ++++ src/vm_debug.c | 41 ++++++++++++++++++++++++++++++++++++----- tests/vm_debug.c | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/include/vm_debug.h b/include/vm_debug.h index f6b0d69..fe8212b 100644 --- a/include/vm_debug.h +++ b/include/vm_debug.h @@ -72,13 +72,17 @@ extern vm_debug_cmd *vm_debug_find_cmd(const char *); extern void vm_debug_break(int); extern void vm_debug_execute(const char *); extern void vm_debug_quit(); +extern void vm_debug_unbreak(int); +extern void vm_debug_unbreak_all(); +extern DEBUG_CMD(break); extern DEBUG_CMD(help); extern DEBUG_CMD(jump); extern DEBUG_CMD(printaddr); extern DEBUG_CMD(printstate); extern DEBUG_CMD(quit); extern DEBUG_CMD(resume); +extern DEBUG_CMD(unbreak); extern DEBUG_CMD(writeaddr); extern DEBUG_CMD(writestate); diff --git a/src/vm_debug.c b/src/vm_debug.c index 9eaf7b3..bea7f46 100644 --- a/src/vm_debug.c +++ b/src/vm_debug.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -20,12 +21,14 @@ /* * A table of breakpoints, arranged by address in a CPU. If - * breakpoints[i] is zero, then there is no breakpoint. If it is - * non-zero, then there is a breakpoint at address i. + * breakpoints[i] is false, then there is no breakpoint. If it is + * true, then there is a breakpoint at address i. */ -static int breakpoints[BREAKPOINTS_MAX]; +static bool breakpoints[BREAKPOINTS_MAX]; vm_debug_cmd cmdtable[] = { + { "break", "b", vm_debug_cmd_break, 1, "", + "Add breakpoint at ", }, { "help", "h", vm_debug_cmd_help, 0, "", "Print out this list of commands", }, { "jump", "j", vm_debug_cmd_jump, 1, "", @@ -38,6 +41,8 @@ vm_debug_cmd cmdtable[] = { "Quit the emulator", }, { "resume", "r", vm_debug_cmd_resume, 0, "", "Resume execution", }, + { "unbreak", "u", vm_debug_cmd_unbreak, 1, "", + "Remove breakpoint at ", }, { "writeaddr", "wa", vm_debug_cmd_writeaddr, 2, " ", "Write at ", }, { "writestate", "ws", vm_debug_cmd_writestate, 2, " ", @@ -90,7 +95,17 @@ vm_debug_break(int addr) return; } - breakpoints[addr] = 1; + breakpoints[addr] = true; +} + +void +vm_debug_unbreak(int addr) +{ + if (addr < 0 || addr >= BREAKPOINTS_MAX) { + return; + } + + breakpoints[addr] = false; } bool @@ -100,7 +115,13 @@ vm_debug_broke(int addr) return false; } - return breakpoints[addr] != 0; + return breakpoints[addr]; +} + +void +vm_debug_unbreak_all() +{ + memset(breakpoints, false, BREAKPOINTS_MAX); } char * @@ -215,6 +236,11 @@ vm_debug_find_cmd(const char *str) sizeof(vm_debug_cmd), cmd_compar); } +DEBUG_CMD(break) +{ + vm_debug_break(args->addr1); +} + DEBUG_CMD(help) { FILE *stream = (FILE *)vm_di_get(VM_OUTPUT); @@ -280,3 +306,8 @@ DEBUG_CMD(quit) { exit(0); } + +DEBUG_CMD(unbreak) +{ + vm_debug_unbreak(args->addr1); +} diff --git a/tests/vm_debug.c b/tests/vm_debug.c index c730855..6d3ec00 100644 --- a/tests/vm_debug.c +++ b/tests/vm_debug.c @@ -49,6 +49,8 @@ teardown() fclose(stream); apple2_free(mach); + + vm_debug_unbreak_all(); } TestSuite(vm_debug, .init = setup, .fini = teardown); @@ -177,4 +179,37 @@ Test(vm_debug, broke) cr_assert_eq(vm_debug_broke(0x23), true); } +Test(vm_debug, unbreak) +{ + vm_debug_break(0x23); + + cr_assert_eq(vm_debug_broke(0x23), true); + vm_debug_unbreak(0x23); + cr_assert_eq(vm_debug_broke(0x23), false); +} + +Test(vm_debug, cmd_break) +{ + args.addr1 = 123; + vm_debug_cmd_break(&args); + + cr_assert_eq(vm_debug_broke(123), true); +} + +Test(vm_debug, cmd_unbreak) +{ + args.addr1 = 123; + vm_debug_cmd_break(&args); + cr_assert_eq(vm_debug_broke(123), true); + vm_debug_cmd_unbreak(&args); + cr_assert_eq(vm_debug_broke(123), false); +} + +Test(vm_debug, unbreak_all) +{ + vm_debug_break(55555); + vm_debug_unbreak_all(); + cr_assert_eq(vm_debug_broke(55555), false); +} + /* Test(vm_debug, quit) */