X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fserver%2Fgdb_server.c;h=40380a899336ef8a3148df1eaf5a0994477f3336;hb=2b2d5ec1e38efdd10ec64f8e880588350fb4edea;hp=bd1d047d5c9fd051726a7d24f811610a7537436a;hpb=2653b8030722c85393974cd6c0ebcdbd1ae27c72;p=openocd.git diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index bd1d047d5c..40380a8993 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -27,14 +27,14 @@ #include "config.h" #endif -#include "breakpoints.h" -#include "target_request.h" -#include "register.h" +#include +#include +#include #include "server.h" -#include "flash.h" +#include #include "gdb_server.h" -#include "image.h" -#include "jtag.h" +#include +#include #if 0 @@ -53,7 +53,7 @@ static const char *DIGITS = "0123456789abcdef"; static void gdb_log_callback(void *priv, const char *file, unsigned line, const char *function, const char *string); -/* number of gdb connections, mainly to supress gdb related debugging spam +/* number of gdb connections, mainly to suppress gdb related debugging spam * in helper/log.c when no gdb connections are actually active */ int gdb_actual_connections; @@ -568,7 +568,7 @@ int gdb_get_packet_inner(struct connection *connection, char *buffer, int *len) break; case '+': /* gdb sends a dummy ack '+' at every remote connect - see remote_start_remote (remote.c) - * incase anyone tries to debug why they receive this warning every time */ + * in case anyone tries to debug why they receive this warning every time */ LOG_WARNING("acknowledgment received, but no packet pending"); break; case '-': @@ -859,7 +859,7 @@ static int gdb_reg_pos(struct target *target, int pos, int len) * register might be non-divisible by 8(a byte), in which * case an entire byte is shown. * - * NB! the format on the wire is the target endianess + * NB! the format on the wire is the target endianness * * The format of reg->value is little endian * @@ -2141,7 +2141,7 @@ int gdb_input_inner(struct connection *connection) target_name(target)); break; default: - /* ignore unkown packets */ + /* ignore unknown packets */ LOG_DEBUG("ignoring 0x%2.2x packet", packet[0]); gdb_put_packet(connection, NULL, 0); break; @@ -2189,55 +2189,68 @@ int gdb_input(struct connection *connection) return ERROR_OK; } -int gdb_init(void) +static int gdb_target_start(struct target *target, uint16_t port) { - struct gdb_service *gdb_service; - struct target *target = all_targets; + bool use_pipes = 0 == port; + struct gdb_service *gdb_service = malloc(sizeof(struct gdb_service)); + if (NULL == gdb_service) + return -ENOMEM; - if (!target) - { - LOG_WARNING("no gdb ports allocated as no target has been specified"); - return ERROR_OK; - } + gdb_service->target = target; + add_service("gdb", use_pipes ? CONNECTION_PIPE : CONNECTION_TCP, + port, 1, &gdb_new_connection, &gdb_input, + &gdb_connection_closed, gdb_service); + + const char *name = target_name(target); + if (use_pipes) + LOG_DEBUG("gdb service for target '%s' using pipes", name); + else + LOG_DEBUG("gdb service for target '%s' on TCP port %u", name, port); + return ERROR_OK; +} + +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 (server_use_pipes) + bool use_pipes = server_use_pipes; + static bool server_started_with_pipes = false; + if (server_started_with_pipes) { - /* only a single gdb connection when using a pipe */ + LOG_WARNING("gdb service permits one target when using pipes"); + if (0 == gdb_port) + return ERROR_OK; - gdb_service = malloc(sizeof(struct gdb_service)); - gdb_service->target = target; + use_pipes = false; + } - add_service("gdb", CONNECTION_PIPE, 0, 1, gdb_new_connection, gdb_input, gdb_connection_closed, gdb_service); + int e = gdb_target_start(target, use_pipes ? 0 : gdb_port++); + if (ERROR_OK == e) + server_started_with_pipes |= use_pipes; - LOG_DEBUG("gdb service for target %s using pipes", - target_name(target)); + return e; +} + +int gdb_target_add_all(struct target *target) +{ + if (NULL == target) + { + LOG_WARNING("gdb services need one or more targets defined"); + return ERROR_OK; } - else + + while (NULL != target) { - unsigned short port = gdb_port; + int retval = gdb_target_add_one(target); + if (ERROR_OK != retval) + return retval; - while (target) - { - gdb_service = malloc(sizeof(struct gdb_service)); - gdb_service->target = target; - - add_service("gdb", CONNECTION_TCP, - port, 1, - gdb_new_connection, gdb_input, - gdb_connection_closed, gdb_service); - - LOG_DEBUG("gdb service for target %s at TCP port %i", - target_name(target), - port); - target = target->next; - port++; - } + target = target->next; } return ERROR_OK; @@ -2320,7 +2333,7 @@ COMMAND_HANDLER(handle_gdb_breakpoint_override_command) LOG_USER("force %s breakpoints", (gdb_breakpoint_override_type == BKPT_HARD)?"hard":"soft"); } else { - LOG_USER("breakpoint type is not overriden"); + LOG_USER("breakpoint type is not overridden"); } return ERROR_OK;