You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.1 KiB
60 lines
2.1 KiB
#include "common.h" |
|
|
|
#include "dwarf.c" |
|
#include "util.c" |
|
#include "command.c" |
|
|
|
int |
|
main(int argc, char *argv[]) |
|
{ |
|
if (argc != 2) { |
|
printf("Usage: %s executable\n", argv[0]); |
|
return(1); |
|
} |
|
|
|
struct mi_process process = process_create(argv[1]); |
|
printf("pid of child = %d\n", process.pid); |
|
|
|
size_t max_command_length = 1023; |
|
int command_length = 0; |
|
char *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"); |
|
|
|
printf("Base address: %#lx\n", process.base_address); |
|
printf("Main address: %#lx\n", process.main_address); |
|
|
|
printf("> "); |
|
fflush(stdout); |
|
|
|
construct_line_number_table(process.elf, 0, &process.sp_count); |
|
process.sp_table = malloc(process.sp_count * sizeof(struct mi_sourcepoint)); |
|
construct_line_number_table(process.elf, process.sp_table, 0); |
|
|
|
while ((command_length = getline(&command, &max_command_length, stdin))) { |
|
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)) { |
|
command_regs(process); |
|
} else if (0 == strncmp(command, "step\n", command_length)) { |
|
command_step(process); |
|
} else if (0 == strncmp(command, "start\n", command_length)) { |
|
command_start(process); |
|
} else if (0 == strncmp(command, "next\n", command_length)) { |
|
command_next(process); |
|
} else if (0 == strncmp(command, "line\n", command_length)) { |
|
command_list(process); |
|
} else if (0 == strncmp(command, "cont\n", command_length)) { |
|
command_cont(process); |
|
} else if (0 == strncmp(command, "stop\n", command_length)) { |
|
command_stop(process); |
|
} else { |
|
printf("Unknown command: %*s", command_length, command); |
|
} |
|
|
|
printf("> "); |
|
} |
|
|
|
return(0); |
|
} |