diff --git a/Makefile b/Makefile index a6e8bfc..754ba72 100755 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ LEX = lex RM = rm LIBLEX = '-ll' +LIBREADLINE = '-lreadline' ifeq ($(shell ldconfig -p|grep -qw libfl; echo $$?), 0) LIBLEX = '-lfl' endif @@ -11,7 +12,7 @@ endif default: xsm xsm: lex.yy.o machine.o main.o simulator.o word.o memory.o registers.o tokenize.o disk.o debug.o exception.o - $(CC) $(CFLAGS) -o xsm lex.yy.o machine.o main.o simulator.o word.o memory.o registers.o tokenize.o disk.o debug.o exception.o $(LIBLEX) + $(CC) $(CFLAGS) -o xsm lex.yy.o machine.o main.o simulator.o word.o memory.o registers.o tokenize.o disk.o debug.o exception.o $(LIBLEX) $(LIBREADLINE) lex.yy.c: parse.l $(LEX) parse.l diff --git a/debug.c b/debug.c index 90a2a46..075972e 100755 --- a/debug.c +++ b/debug.c @@ -7,6 +7,8 @@ The XSM debugger. #include #include #include +#include +#include static debug_status _db_status; @@ -128,7 +130,7 @@ int debug_next_step(int curr_ip) int debug_show_interface() { int done = FALSE, addr; - char command[DEBUG_COMMAND_LEN], prev_instr[DEBUG_STRING_LEN], next_instr[DEBUG_STRING_LEN]; + char *command, prev_instr[DEBUG_STRING_LEN], next_instr[DEBUG_STRING_LEN]; if (_db_status.skip > 0) { @@ -158,11 +160,12 @@ int debug_show_interface() while (!done) { - printf("debug> "); - fgets(command, DEBUG_COMMAND_LEN, stdin); + command = readline("debug> "); - // Remove the dangling \n from fgets - strtok(command, "\n"); + if(command && *command) + add_history(command); + else + continue; if (!strcmp(command, "\n")) strncpy(command, _db_status.command, DEBUG_COMMAND_LEN);