Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ LEX = lex
RM = rm

LIBLEX = '-ll'
LIBREADLINE = '-lreadline'
ifeq ($(shell ldconfig -p|grep -qw libfl; echo $$?), 0)
LIBLEX = '-lfl'
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
Expand Down
13 changes: 8 additions & 5 deletions debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The XSM debugger.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <readline/readline.h>
#include <readline/history.h>

static debug_status _db_status;

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down