int a2_initialize(void *ctx, int *debugger_stdin, int *debugger_stdout, int *inferior_stdin, int *inferior_stdout) { struct annotate_two *a2 = (struct annotate_two *) ctx; *debugger_stdin = a2->debugger_stdin; *debugger_stdout = a2->debugger_out; a2->data = data_initialize(); a2->sm = state_machine_initialize(); a2->c = commands_initialize(); a2->g = globals_initialize(); a2->client_command_list = tgdb_list_init(); a2_open_new_tty(a2, inferior_stdin, inferior_stdout); /* gdb may already have some breakpoints when it starts. This could happen * if the user puts breakpoints in there .gdbinit. * This makes sure that TGDB asks for the breakpoints on start up. */ if (commands_issue_command(a2->c, a2->client_command_list, ANNOTATE_INFO_BREAKPOINTS, NULL, 0) == -1) { logger_write_pos(logger, __FILE__, __LINE__, "commands_issue_command error"); return -1; } a2->tgdb_initialized = 1; return 0; }
struct tgdb *tgdb_initialize(const char *debugger, int argc, char **argv, int *debugger_fd, tgdb_callbacks callbacks) { /* Initialize the libtgdb context */ struct tgdb *tgdb = initialize_tgdb_context(callbacks); static struct annotations_parser_callbacks annotations_callbacks = { tgdb, tgdb_breakpoints_changed, tgdb_source_location_changed, tgdb_prompt_changed, tgdb_console_output, tgdb_command_error, tgdb_console_at_prompt }; tgdb->debugger_pid = invoke_debugger(debugger, argc, argv, &tgdb->debugger_stdin, &tgdb->debugger_stdout, 0); /* Couldn't invoke process */ if (tgdb->debugger_pid == -1) return NULL; tgdb->c = commands_initialize(tgdb); tgdb->parser = annotations_parser_initialize(annotations_callbacks); tgdb_open_new_tty(tgdb, &tgdb->inferior_stdin, &tgdb->inferior_stdout); /* Need to get source information before breakpoint information otherwise * the TGDB_UPDATE_BREAKPOINTS event will be ignored in process_commands() * because there are no source files to add the breakpoints to. */ tgdb_request_current_location(tgdb); /* gdb may already have some breakpoints when it starts. This could happen * if the user puts breakpoints in there .gdbinit. * This makes sure that TGDB asks for the breakpoints on start up. */ tgdb_issue_request(tgdb, TGDB_REQUEST_BREAKPOINTS, true); /** * Query if disassemble supports the /s flag */ tgdb_issue_request(tgdb, TGDB_REQUEST_DATA_DISASSEMBLE_MODE_QUERY, true); *debugger_fd = tgdb->debugger_stdout; return tgdb; }
int a2_initialize(struct annotate_two *a2, int *debugger_stdin, int *debugger_stdout, int *inferior_stdin, int *inferior_stdout) { *debugger_stdin = a2->debugger_stdin; *debugger_stdout = a2->debugger_out; a2->sm = state_machine_initialize(); a2->c = commands_initialize(a2); a2->client_commands = NULL; a2_open_new_tty(a2, inferior_stdin, inferior_stdout); /* Need to get source information before breakpoint information otherwise * the TGDB_UPDATE_BREAKPOINTS event will be ignored in process_commands() * because there are no source files to add the breakpoints to. */ a2_get_current_location(a2); /* gdb may already have some breakpoints when it starts. This could happen * if the user puts breakpoints in there .gdbinit. * This makes sure that TGDB asks for the breakpoints on start up. */ if (commands_issue_command(a2, ANNOTATE_INFO_BREAKPOINTS, NULL, 0) == -1) { return -1; } /** * Query if disassemble supports the /s flag */ if (commands_issue_command(a2, ANNOTATE_DATA_DISASSEMBLE_MODE_QUERY, NULL, 1) == -1) { return -1; } a2->tgdb_initialized = 1; return 0; }
int a2_initialize(struct annotate_two *a2, int *debugger_stdin, int *debugger_stdout, int *inferior_stdin, int *inferior_stdout) { *debugger_stdin = a2->debugger_stdin; *debugger_stdout = a2->debugger_out; a2->data = data_initialize(); a2->sm = state_machine_initialize(); a2->c = commands_initialize(); a2->g = globals_initialize(); a2->client_command_list = tgdb_list_init(); a2_open_new_tty(a2, inferior_stdin, inferior_stdout); /* Need to get source information before breakpoint information otherwise * the TGDB_UPDATE_BREAKPOINTS event will be ignored in process_commands() * because there are no source files to add the breakpoints to. */ a2_get_current_location(a2, 1); /* gdb may already have some breakpoints when it starts. This could happen * if the user puts breakpoints in there .gdbinit. * This makes sure that TGDB asks for the breakpoints on start up. */ if (commands_issue_command(a2->c, a2->client_command_list, ANNOTATE_INFO_BREAKPOINTS, NULL, 0) == -1) { logger_write_pos(logger, __FILE__, __LINE__, "commands_issue_command error"); return -1; } a2->tgdb_initialized = 1; return 0; }
int main(int argc, char *argv[]) { static struct option long_options[] = { {"listen", required_argument, 0, 'l'}, {"port", required_argument, 0, 'p'}, {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, {"ping-parent", no_argument, 0, 'x'}, {"gcc-command", required_argument, 0, 'g'}, {"vx32sdk", required_argument, 0, 's'}, {"tmpdir", required_argument, 0, 't'}, {"engine", required_argument, 0, 'e'}, {"no-vx32", no_argument, 0, 'n'}, {0, 0, 0, 0} }; struct server *server = (struct server*)st_calloc(1, sizeof(struct server)); server->info_handler = &info_handler; server->quit_handler = &quit_handler; server->process_multi= &process_multi; INIT_LIST_HEAD(&server->root); server->host = "127.0.0.1"; server->port = 22122; struct config *config = (struct config*)st_calloc(1, sizeof(struct config)); server->userdata = config; config->tmpdir = "/tmp"; config->vx32sdk_path = "./untrusted/"; config->vx32sdk_gcc_command = strdup(flatten_argv(NELEM(default_vx32sdk_gcc_command), default_vx32sdk_gcc_command, " ")); config->syscall_limit = 4; /* 4 syscalls per request allowed */ int option_index; int arg; char *engine_name = NULL; while((arg = getopt_long_only(argc, argv, "hxvnl:p:g:s:t:e:", long_options, &option_index)) != EOF) { switch(arg) { case 'h': print_help(server, config); exit(-1); break; case 'v': server->trace = 1; break; case 'x': server->ping_parent = 1; break; case 'l': server->host = optarg; break; case 'p': server->port = atoi(optarg); if(server->port < 0 || server->port > 65536) fatal("Port number broken: %i", server->port); break; case 'g': free(config->vx32sdk_gcc_command); config->vx32sdk_gcc_command = strdup(optarg); break; case 's': config->vx32sdk_path = optarg; break; case 't': config->tmpdir = optarg; break; case 'e': engine_name = optarg; break; case 'n': config->vx32_disabled = 1; break; case 0: default: fatal("\nUnknown option: \"%s\"\n", argv[optind-1]); } } int i; storage_engine_create *engine_create = NULL; storage_engine_destroy *engine_destroy = NULL; for(i=0; i<NELEM(engines); i++) { if(engine_name && 0 == strcmp(engine_name, engines[i].name)) { engine_create = engines[i].create; engine_destroy = engines[i].destroy; } } if(NULL == engine_create) fatal("\nYou must specify a storage engine:" " --engine=[%s]\n", flatten_engine_names() ); log_info("Process pid %i", getpid()); signal(SIGPIPE, SIG_IGN); commands_initialize(); process_initialize(config); char *params = flatten_argv(argc-optind, &argv[optind], ", "); log_info("Loading database engine \"%s\" with parameters \"%s\"", engine_name, params); config->api = engine_create(argc-optind, &argv[optind]); do_event_loop(server); log_info("Quit"); process_destroy(); commands_destroy(); pool_free(); engine_destroy(config->api); free(config->vx32sdk_gcc_command); free(config); free(server); exit(0); return(0); }