From 1ff5d17f195f34a529538f4e4fea63087fd12f1d Mon Sep 17 00:00:00 2001 From: Peter Evans Date: Fri, 9 Mar 2018 16:44:53 -0600 Subject: [PATCH] Add hexdump command --- include/vm_debug.h | 1 + src/vm_debug.c | 17 +++++++++++++++++ tests/vm_debug.c | 14 ++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/include/vm_debug.h b/include/vm_debug.h index c109133..21cf246 100644 --- a/include/vm_debug.h +++ b/include/vm_debug.h @@ -80,6 +80,7 @@ extern void vm_debug_unbreak_all(); extern DEBUG_CMD(break); extern DEBUG_CMD(dblock); extern DEBUG_CMD(disasm); +extern DEBUG_CMD(hdump); extern DEBUG_CMD(help); extern DEBUG_CMD(jump); extern DEBUG_CMD(printaddr); diff --git a/src/vm_debug.c b/src/vm_debug.c index 911fbf6..db14aab 100644 --- a/src/vm_debug.c +++ b/src/vm_debug.c @@ -39,6 +39,8 @@ vm_debug_cmd cmdtable[] = { "Disassemble a block of code", }, { "disasm", "d", vm_debug_cmd_disasm, 0, "", "Toggle disassembly", }, + { "hdump", "hd", vm_debug_cmd_hdump, 2, " ", + "Hex dump memory in a given region", }, { "help", "h", vm_debug_cmd_help, 0, "", "Print out this list of commands", }, { "jump", "j", vm_debug_cmd_jump, 1, "", @@ -454,3 +456,18 @@ DEBUG_CMD(dblock) mos6502_dis_scan(cpu, stream, args->addr1, args->addr2); } + +/* + * Print a hex dump of a region of memory + */ +DEBUG_CMD(hdump) +{ + if (args->addr1 > args->addr2) { + return; + } + + mos6502 *cpu = (mos6502 *)vm_di_get(VM_CPU); + FILE *stream = log_stream(); + + vm_segment_hexdump(cpu->rmem, stream, args->addr1, args->addr2); +} diff --git a/tests/vm_debug.c b/tests/vm_debug.c index 394fcc5..87d8830 100644 --- a/tests/vm_debug.c +++ b/tests/vm_debug.c @@ -288,3 +288,17 @@ Test(vm_debug, cmd_dblock) vm_debug_cmd_dblock(&args); cr_assert_neq(strlen(buf), 0); } + +Test(vm_debug, cmd_hdump) +{ + for (int i = 0; i < 16; i++) { + mos6502_set(mach->cpu, i, i + 0x30); + } + + args.addr1 = 0; + args.addr2 = 32; + + vm_debug_cmd_hdump(&args); + + cr_assert_neq(strlen(buf), 0); +}