From 0e767bc8f4130df4f0aa71b6ee36ee1180bde903 Mon Sep 17 00:00:00 2001 From: Imanol-Mikel Barba Sabariego Date: Tue, 27 Dec 2016 06:06:55 +0100 Subject: [PATCH] Implemented exit command and break on CTRL+C --- debug.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/debug.c b/debug.c index 7b823cd..17e3648 100644 --- a/debug.c +++ b/debug.c @@ -5,12 +5,24 @@ #include #include #include "debug.h" +#include //uint32_t cycle_count = 0; uint8_t breakpoint = 1; uint16_t breakpoints[0xFF]; uint16_t nbpoints = 0; char lastchoice = 0; +uint8_t terminate = 0; + +void to_debugger(int signal) +{ + if(signal == SIGINT) + { + breakpoint = 1; + return; + } + core_dump(); +} void load_state(char *filename) { @@ -123,6 +135,10 @@ void query() fprintf(stderr,"Setting register %d to %d",reg,value); regs[reg] = value; break; + case 'q': + terminate = 1; + end = 1; + break; default: break; } @@ -274,6 +290,7 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) void debug_program() { + signal(SIGINT, to_debugger); memset(breakpoints,0x00,0xFF); uint16_t arg1; uint16_t arg2; @@ -285,12 +302,15 @@ void debug_program() breakpoint = 1; fprintf(stderr,"Breakpoint hit @ pc=%02X",pc); } - if(in_breakpoint(pc) || breakpoint) + if(breakpoint) { - breakpoint = 1; fprintf(stderr, "%02X: ", pc); print_instruction(mem[pc], mem[pc+1], mem[pc+2], mem[pc+3]); query(); + if(terminate) + { + return; + } } uint16_t opcode = fetch_debug(); decode_instruction(opcode, &arg1, &arg2, &arg3); -- libgit2 0.22.2