From a0becc9532815c1024d86960f67b63bdc243b01b Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Wed, 28 Dec 2016 21:23:49 +0100 Subject: [PATCH] Implemented next/step --- debug.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/debug.c b/debug.c index 95e1644..e671c18 100644 --- a/debug.c +++ b/debug.c @@ -13,6 +13,7 @@ uint16_t breakpoints[0xFF]; uint16_t nbpoints = 0; char lastchoice = 0; uint8_t terminate = 0; +uint8_t break_on_next = 0; void to_debugger(int signal) { @@ -112,6 +113,7 @@ void query() end = 1; break; case 'n': + break_on_next = 1; end = 1; break; case 'r': @@ -121,11 +123,14 @@ void query() sscanf(input,"m %hX\n",&mempos); fprintf(stderr,"%02X: %02x\n",mempos,mem[mempos]); break; - case 's': - sscanf(input,"s %s\n",filename); + case 't': + sscanf(input,"t %s\n",filename); save_state(filename); fprintf(stderr,"Saved state as %s",filename); break; + case 's': + end = 1; + break; case 'l': sscanf(input,"l %s\n",filename); load_state(filename); @@ -140,6 +145,9 @@ void query() terminate = 1; end = 1; break; + case 'h': + //print_debug_commands(); + break; default: break; } @@ -301,6 +309,7 @@ void debug_program() } if(breakpoint) { + break_on_next = 0; fprintf(stderr, "cycle: %d\n", cycle_count); fprintf(stderr, "%02X: ", pc); print_instruction(mem[pc], mem[pc+1], mem[pc+2], mem[pc+3]); @@ -315,6 +324,19 @@ void debug_program() } } uint16_t opcode = fetch_debug(); + if(opcode == CALL && break_on_next != 0) + { + breakpoint = 0; + break_on_next++; + } + else if(opcode == RET && break_on_next != 0) + { + if(--break_on_next == 1) + { + breakpoint = 1; + break_on_next = 0; + } + } decode_instruction(opcode, &arg1, &arg2, &arg3); if (execute_instruction(opcode, arg1, arg2, arg3)) { -- libgit2 0.22.2