summaryrefslogtreecommitdiff
path: root/src/server
diff options
context:
space:
mode:
authorZachary T Welch <zw@superlucidity.net>2009-11-28 18:56:23 -0800
committerZachary T Welch <zw@superlucidity.net>2009-11-30 16:29:24 -0800
commitec6c1962c2398a574a5c413b41483370347b9f5b (patch)
treebfc86b1688a97f2495e7d2c58c42dd36ae72848c /src/server
parent2264270fe49a447e6f06ec4069a816cc86c3cf0b (diff)
downloadopenocd_libswd-ec6c1962c2398a574a5c413b41483370347b9f5b.tar.gz
openocd_libswd-ec6c1962c2398a574a5c413b41483370347b9f5b.tar.bz2
openocd_libswd-ec6c1962c2398a574a5c413b41483370347b9f5b.tar.xz
openocd_libswd-ec6c1962c2398a574a5c413b41483370347b9f5b.zip
improve gdb_init() sequence
Rework gdb_init to create flexible APIs (gdb_target_add_{one,all}) and static helper (gdb_target_start) for starting GDB services. Eliminates duplicated code and provides general mechanisms for adding GDB services. The 'init' command is updated to call the new API, and later patches can decouple its policy of adding all targets therein. Provides the new capability to use both piped and TCP servers when multiple targets are defined. The first target fills the pipe, and others will be started on TCP ports (unless disabled, i.e. gdb_port=0).
Diffstat (limited to 'src/server')
-rw-r--r--src/server/gdb_server.c79
-rw-r--r--src/server/gdb_server.h3
2 files changed, 48 insertions, 34 deletions
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index 3c099fa0..7fb36e41 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -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;
diff --git a/src/server/gdb_server.h b/src/server/gdb_server.h
index a8e8dadb..04149751 100644
--- a/src/server/gdb_server.h
+++ b/src/server/gdb_server.h
@@ -52,7 +52,8 @@ struct gdb_service
struct target *target;
};
-int gdb_init(void);
+int gdb_target_add_one(struct target *target);
+int gdb_target_add_all(struct target *target);
int gdb_register_commands(struct command_context *command_context);
#define ERROR_GDB_BUFFER_TOO_SMALL (-800)