Added a debug menue

This commit is contained in:
nils polek 2024-01-15 12:43:49 +00:00
parent 6cc2ff87ca
commit 37843d9356
2 changed files with 42 additions and 8 deletions

40
debugMenu.c Normal file
View File

@ -0,0 +1,40 @@
#ifndef DEBUGMENU
#define DEBUGMENU
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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 */

10
njvm.c
View File

@ -8,6 +8,7 @@
#include "codeReader.c" #include "codeReader.c"
#include "SDA.c" #include "SDA.c"
#include "reg.c" #include "reg.c"
#include "debugMenu.c"
// Debug // Debug
int debug = 0; int debug = 0;
@ -41,10 +42,7 @@ void execute(struct program program) {
char charInput; char charInput;
StackSlot tempSlot; StackSlot tempSlot;
for (i = 0; i < *program.size; ++i) { for (i = 0; i < *program.size; ++i) {
if (debug == 1) printf("=== DEBUG: Stack before instruction %i ===\n", i); if (debug == 1) debugMenu(fp,stack,&debug);
if (debug == 1) printStack(stack, fp);
if (debug == 1) printf("=== DEBUG: Instruction %i ===\n", i);
switch (program.program[i] >> 24) { switch (program.program[i] >> 24) {
case HALT: case HALT:
if (debug == 1) printf("halt\n"); if (debug == 1) printf("halt\n");
@ -213,11 +211,7 @@ void execute(struct program program) {
push(stack, stackSlotWitchNumber(popR(reg))); push(stack, stackSlotWitchNumber(popR(reg)));
if(debug == 1) printStackR(reg); if(debug == 1) printStackR(reg);
break; 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: end:
return; return;