38,6 → 38,7 |
#include <syscall.h> |
#include <ipc/ipc.h> |
#include <fibril.h> |
#include <loader/loader.h> |
#include <errno.h> |
#include <udebug.h> |
#include <async.h> |
67,6 → 68,86 |
|
volatile int paused; |
|
static task_id_t task_id; |
static loader_t *task_ldr; |
|
static int program_run_fibril(void *arg); |
|
static void program_run(void) |
{ |
fid_t fid; |
|
fid = fibril_create(program_run_fibril, NULL); |
if (fid == 0) { |
printf("Error creating fibril\n"); |
exit(1); |
} |
|
fibril_add_ready(fid); |
} |
|
static int program_run_fibril(void *arg) |
{ |
int rc; |
|
/* |
* This must be done in background as it will block until |
* we let the task reply to this call. |
*/ |
rc = loader_run(task_ldr); |
if (rc != 0) { |
printf("Error running program\n"); |
exit(1); |
} |
|
free(task_ldr); |
task_ldr = NULL; |
|
return 0; |
} |
|
static loader_t *preload_task(const char *path, char *const argv[], |
task_id_t *task_id) |
{ |
loader_t *ldr; |
int rc; |
|
/* Spawn a program loader */ |
ldr = loader_spawn(); |
if (ldr == NULL) |
return 0; |
|
/* Get task ID. */ |
rc = loader_get_task_id(ldr, task_id); |
if (rc != EOK) |
goto error; |
|
/* Send program pathname */ |
rc = loader_set_pathname(ldr, path); |
if (rc != EOK) |
goto error; |
|
/* Send arguments */ |
rc = loader_set_args(ldr, argv); |
if (rc != EOK) |
goto error; |
|
/* Load the program. */ |
rc = loader_load_program(ldr); |
if (rc != EOK) |
goto error; |
|
/* Success */ |
return ldr; |
|
/* Error exit */ |
error: |
loader_abort(ldr); |
free(ldr); |
return NULL; |
} |
|
|
static void command_split(char *cmd_str) |
{ |
char *p = cmd_str; |
171,7 → 252,7 |
thread_stop(); |
} |
|
static int task_connect(task_id_t task_id) |
static int connect_task(task_id_t task_id) |
{ |
int rc; |
unsigned evmask; |
328,9 → 409,8 |
fibril_add_ready(fid); |
} |
|
static void debug_active_task(task_id_t task_id) |
static void debug_task(task_id_t task_id) |
{ |
int taskid; |
int i; |
int rc; |
|
337,16 → 417,6 |
thash_t *thash_buffer; |
int n_threads; |
|
cons_printf("Breakpoint Debugger\n"); |
|
rc = task_connect(task_id); |
if (rc < 0) { |
cons_printf("Failed to connect to task %lld\n", task_id); |
return; |
} |
|
cons_printf("Connected to task %lld\n", task_id); |
|
rc = get_thread_list(&thash_buffer, &n_threads); |
if (rc < 0) { |
cons_printf("Failed to get thread list\n", rc); |
388,31 → 458,96 |
|
static void print_syntax() |
{ |
printf("syntax: debug <task_id>\n"); |
printf("Syntax:\n"); |
printf("\tdebug <executable> [<arg1> [...]]\n"); |
printf("or\tdebug -t <task_id>\n"); |
} |
|
int main(int argc, char *argv[]) |
static int parse_args(int argc, char *argv[]) |
{ |
task_id_t task_id; |
char *arg; |
char *err_p; |
|
if (argc != 2) { |
printf("Mising argument\n"); |
print_syntax(); |
return 1; |
} |
task_id = 0; |
|
task_id = strtol(argv[1], &err_p, 10); |
--argc; ++argv; |
|
while (argc > 0) { |
arg = *argv; |
if (arg[0] == '-') { |
if (arg[1] == 't') { |
/* Trace an already running task */ |
--argc; ++argv; |
task_id = strtol(*argv, &err_p, 10); |
task_ldr = NULL; |
if (*err_p) { |
printf("Task ID syntax error\n"); |
print_syntax(); |
return 1; |
return -1; |
} |
} else { |
printf("Uknown option '%s'\n", arg[0]); |
print_syntax(); |
return -1; |
} |
} else { |
break; |
} |
|
--argc; ++argv; |
} |
|
if (task_id != 0) { |
if (argc == 0) return 0; |
printf("Extra arguments\n"); |
print_syntax(); |
return -1; |
} |
|
if (argc < 1) { |
printf("Missing argument\n"); |
print_syntax(); |
return -1; |
} |
|
/* Preload the specified program file. */ |
printf("Spawning '%s' with arguments:\n", *argv); |
{ |
char **cp = argv; |
while (*cp) printf("'%s'\n", *cp++); |
} |
task_ldr = preload_task(*argv, argv, &task_id); |
|
return 0; |
} |
|
int main(int argc, char *argv[]) |
{ |
int rc; |
|
cons_printf("Breakpoint Debugger\n"); |
|
main_init(); |
debug_active_task(task_id); |
|
if (parse_args(argc, argv) < 0) |
return 1; |
|
rc = connect_task(task_id); |
if (rc < 0) { |
printf("Failed connecting to task %lld\n", task_id); |
return 1; |
} |
|
cons_printf("Connected to task %lld\n", task_id); |
|
if (task_ldr != NULL) { |
program_run(); |
} |
|
debug_task(task_id); |
|
return 0; |
} |
|
/** @} |
*/ |