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