From 6c137a2fc0bf53b9c0b8eda51e6f5361552b0112 Mon Sep 17 00:00:00 2001 From: Øyvind Harboe Date: Mon, 27 Sep 2010 08:48:31 +0200 Subject: server: specify port as a string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will allow switching to using named pipes. Split this out as a seperate commit to make changes easier to follow. Signed-off-by: Øyvind Harboe --- src/server/gdb_server.c | 57 +++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 25 deletions(-) (limited to 'src/server/gdb_server.c') diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 170dadc5..54899589 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -80,8 +80,8 @@ static int gdb_breakpoint_override; static enum breakpoint_type gdb_breakpoint_override_type; static int gdb_error(struct connection *connection, int retval); -static unsigned short gdb_port = 3333; -static unsigned short gdb_port_next = 0; +static const char *gdb_port; +static const char *gdb_port_next; static const char DIGITS[16] = "0123456789abcdef"; static void gdb_log_callback(void *priv, const char *file, unsigned line, @@ -2410,32 +2410,37 @@ static int gdb_target_start(struct target *target, uint16_t port) static int gdb_target_add_one(struct target *target) { - if (gdb_port == 0 && server_use_pipes == 0) - { - LOG_INFO("gdb port disabled"); - return ERROR_OK; - } - if (0 == gdb_port_next) - gdb_port_next = gdb_port; - - bool use_pipes = server_use_pipes; - static bool server_started_with_pipes = false; - if (server_started_with_pipes) + long portnumber_parsed; + /* If we can parse the port number + * then we increment the port number for the next target. + */ + char *end_parse; + portnumber_parsed = strtol(gdb_port_next, &end_parse, 0); + if (!*end_parse) { - LOG_WARNING("gdb service permits one target when using pipes"); - if (0 == gdb_port) - return ERROR_OK; - - use_pipes = false; + LOG_ERROR("Illegal port number"); + return ERROR_FAIL; } - int e = gdb_target_start(target, use_pipes ? 0 : gdb_port_next); - if (ERROR_OK == e) + int retval = gdb_target_start(target, portnumber_parsed); + if (retval == ERROR_OK) { - server_started_with_pipes |= use_pipes; - gdb_port_next++; + long portnumber; + /* If we can parse the port number + * then we increment the port number for the next target. + */ + char *end; + strtol(gdb_port_next, &end, 0); + if (!*end) + { + if (parse_long(gdb_port_next, &portnumber) == ERROR_OK) + { + free((void *)gdb_port_next); + gdb_port_next = alloc_printf("%d", portnumber+1); + } + } } - return e; + return retval; } int gdb_target_add_all(struct target *target) @@ -2480,9 +2485,9 @@ COMMAND_HANDLER(handle_gdb_sync_command) /* daemon configuration command gdb_port */ COMMAND_HANDLER(handle_gdb_port_command) { - int retval = CALL_COMMAND_HANDLER(server_port_command, &gdb_port); + int retval = CALL_COMMAND_HANDLER(server_pipe_command, &gdb_port); if (ERROR_OK == retval) - gdb_port_next = gdb_port; + gdb_port_next = strdup(gdb_port); return retval; } @@ -2599,5 +2604,7 @@ static const struct command_registration gdb_command_handlers[] = { int gdb_register_commands(struct command_context *cmd_ctx) { + gdb_port = strdup("3333"); + gdb_port_next = strdup("3333"); return register_commands(cmd_ctx, NULL, gdb_command_handlers); } -- cgit v1.2.3