Commit 0e767bc8f4130df4f0aa71b6ee36ee1180bde903

Authored by Imanol-Mikel Barba Sabariego
1 parent bafce57a

Implemented exit command and break on CTRL+C

Showing 1 changed file with 22 additions and 2 deletions
@@ -5,12 +5,24 @@ @@ -5,12 +5,24 @@
5 #include <malloc.h> 5 #include <malloc.h>
6 #include <string.h> 6 #include <string.h>
7 #include "debug.h" 7 #include "debug.h"
  8 +#include <signal.h>
8 9
9 //uint32_t cycle_count = 0; 10 //uint32_t cycle_count = 0;
10 uint8_t breakpoint = 1; 11 uint8_t breakpoint = 1;
11 uint16_t breakpoints[0xFF]; 12 uint16_t breakpoints[0xFF];
12 uint16_t nbpoints = 0; 13 uint16_t nbpoints = 0;
13 char lastchoice = 0; 14 char lastchoice = 0;
  15 +uint8_t terminate = 0;
  16 +
  17 +void to_debugger(int signal)
  18 +{
  19 + if(signal == SIGINT)
  20 + {
  21 + breakpoint = 1;
  22 + return;
  23 + }
  24 + core_dump();
  25 +}
14 26
15 void load_state(char *filename) 27 void load_state(char *filename)
16 { 28 {
@@ -123,6 +135,10 @@ void query() @@ -123,6 +135,10 @@ void query()
123 fprintf(stderr,"Setting register %d to %d",reg,value); 135 fprintf(stderr,"Setting register %d to %d",reg,value);
124 regs[reg] = value; 136 regs[reg] = value;
125 break; 137 break;
  138 + case 'q':
  139 + terminate = 1;
  140 + end = 1;
  141 + break;
126 default: 142 default:
127 break; 143 break;
128 } 144 }
@@ -274,6 +290,7 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3) @@ -274,6 +290,7 @@ void print_instruction(uint16_t opcode, uint16_t a1, uint16_t a2, uint16_t a3)
274 290
275 void debug_program() 291 void debug_program()
276 { 292 {
  293 + signal(SIGINT, to_debugger);
277 memset(breakpoints,0x00,0xFF); 294 memset(breakpoints,0x00,0xFF);
278 uint16_t arg1; 295 uint16_t arg1;
279 uint16_t arg2; 296 uint16_t arg2;
@@ -285,12 +302,15 @@ void debug_program() @@ -285,12 +302,15 @@ void debug_program()
285 breakpoint = 1; 302 breakpoint = 1;
286 fprintf(stderr,"Breakpoint hit @ pc=%02X",pc); 303 fprintf(stderr,"Breakpoint hit @ pc=%02X",pc);
287 } 304 }
288 - if(in_breakpoint(pc) || breakpoint) 305 + if(breakpoint)
289 { 306 {
290 - breakpoint = 1;  
291 fprintf(stderr, "%02X: ", pc); 307 fprintf(stderr, "%02X: ", pc);
292 print_instruction(mem[pc], mem[pc+1], mem[pc+2], mem[pc+3]); 308 print_instruction(mem[pc], mem[pc+1], mem[pc+2], mem[pc+3]);
293 query(); 309 query();
  310 + if(terminate)
  311 + {
  312 + return;
  313 + }
294 } 314 }
295 uint16_t opcode = fetch_debug(); 315 uint16_t opcode = fetch_debug();
296 decode_instruction(opcode, &arg1, &arg2, &arg3); 316 decode_instruction(opcode, &arg1, &arg2, &arg3);