diff --git a/main.c b/main.c index 580f19a..9b84e7a 100644 --- a/main.c +++ b/main.c @@ -18,6 +18,7 @@ main(int argc, char *argv[]) size_t max_command_length = 1023; int command_length = 0; char *command = malloc(max_command_length + 1); + char *last_command = malloc(max_command_length + 1); process.base_address = 0x555555554000UL; // get_executable_base_address(file, proc.pid); process.main_address = get_address_of_subroutine(process.elf, "main"); @@ -35,6 +36,11 @@ main(int argc, char *argv[]) construct_line_number_table(process.elf, process.sp_table, process.source_file_names, 0, 0); while ((command_length = getline(&command, &max_command_length, stdin))) { + if (command_length == 1) { + memset(command, 0, max_command_length); + memcpy(command, last_command, command_length); + } + if (0 == strncmp(command, "exit\n", command_length) || 0 == strncmp(command, "q\n", command_length)) { break; } else if (0 == strncmp(command, "regs\n", command_length)) { @@ -55,6 +61,9 @@ main(int argc, char *argv[]) printf("Unknown command: %*s", command_length, command); } + memset(last_command, 0, max_command_length); + memcpy(last_command, command, command_length); + printf("> "); }