diff --git a/debugMenu.c b/debugMenu.c new file mode 100644 index 0000000..d13b617 --- /dev/null +++ b/debugMenu.c @@ -0,0 +1,40 @@ +#ifndef DEBUGMENU +#define DEBUGMENU +#include +#include +#include +#include "stack.c" +#include "stack.c" + +void inspect(struct stack s, int fp){ + char input[20]; + printf("DEBUG [inspect]: stack, datam object?"); + fgets(input,20,stdin); + if (input[0] == 's') printStack(s, fp); + if (input[0] == 'd'){/* todo */ } + if (input[0] == 'o'){/* todo */} +} +void list(){ + //todo +} +void breakpoint(){ + //todo +} + +void debugMenu(int fp, struct stack stack, int* debug){ + char input[20]; + while (true) { + printf("DEBUG: inspect, list, breakpoint, run, step, quit?"); + fgets(input, 20, stdin); + printf("%s",input); + if(input[0] == 'i') {inspect(stack,fp);} + if(input[0] == 'l') list(); + if(input[0] == 'b') breakpoint(); + if(input[0] == 's') break; + if(input[0] == 'r') {*debug = 0; break;}; + if(input[0] == 'q') exit(0); + strcpy(input, ""); + } +} + +#endif /* ifndef DEBUGMENU */ diff --git a/njvm.c b/njvm.c index feab9cb..e0a29de 100644 --- a/njvm.c +++ b/njvm.c @@ -8,6 +8,7 @@ #include "codeReader.c" #include "SDA.c" #include "reg.c" +#include "debugMenu.c" // Debug int debug = 0; @@ -41,10 +42,7 @@ void execute(struct program program) { char charInput; StackSlot tempSlot; for (i = 0; i < *program.size; ++i) { - if (debug == 1) printf("=== DEBUG: Stack before instruction %i ===\n", i); - if (debug == 1) printStack(stack, fp); - if (debug == 1) printf("=== DEBUG: Instruction %i ===\n", i); - + if (debug == 1) debugMenu(fp,stack,&debug); switch (program.program[i] >> 24) { case HALT: if (debug == 1) printf("halt\n"); @@ -213,11 +211,7 @@ void execute(struct program program) { push(stack, stackSlotWitchNumber(popR(reg))); if(debug == 1) printStackR(reg); break; - } - if (debug == 1) printf("=== DEBUG: Stack after instruction %i ===\n", i); - if (debug == 1) printStack(stack, fp); - if (debug == 1) printf("=== DEBUG: Instruction %i ===\n", i); } end: return;