gdb_server: add per target option "-gdb-port"

The argument passed to global config command "gdb_port" is usually,
but not always, a TCP port number. In case of multiple targets, this
numeric value is used as the first port of a set of consecutive TCP
ports assigned one per target.
If the argument is not a numeric value (e.g. "pipe", "disabled", ...)
then incrementing it for the next target has no sense.

Add the option "-gdb-port number" to the commands "target create" and
"$target_name configure" to override, for the specific target, the
general global configuration.

This permits to use a per target "-gdb-port disabled", when no gdb
port is required for that specific target.

It also makes possible to choose a custom TCP port number for each
target, overriding the usual sequence of consecutive port numbers.

Change-Id: I3b9a1910b28ab4bc757e839d0e5d08ffc29f7ab4
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4530
Tested-by: jenkins
Reviewed-by: Christopher Head <chead@zaber.com>
Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
This commit is contained in:
Antonio Borneo
2018-05-21 16:14:33 +02:00
committed by Matthias Welwarsky
parent 11019a824d
commit ab858febb6
4 changed files with 55 additions and 9 deletions

View File

@@ -3373,6 +3373,8 @@ static int gdb_target_start(struct target *target, const char *port)
if (NULL == gdb_service)
return -ENOMEM;
LOG_DEBUG("starting gdb server for %s on %s", target_name(target), port);
gdb_service->target = target;
gdb_service->core[0] = -1;
gdb_service->core[1] = -1;
@@ -3398,16 +3400,30 @@ static int gdb_target_start(struct target *target, const char *port)
static int gdb_target_add_one(struct target *target)
{
/* one gdb instance per smp list */
if ((target->smp) && (target->gdb_service))
return ERROR_OK;
if (target->gdb_port_override) {
if (strcmp(target->gdb_port_override, "disabled") == 0) {
LOG_INFO("gdb port disabled");
return ERROR_OK;
}
return gdb_target_start(target, target->gdb_port_override);
}
if (strcmp(gdb_port, "disabled") == 0) {
LOG_INFO("gdb port disabled");
return ERROR_OK;
}
/* one gdb instance per smp list */
if ((target->smp) && (target->gdb_service))
return ERROR_OK;
int retval = gdb_target_start(target, gdb_port_next);
if (retval == ERROR_OK) {
/* save the port number so can be queried with
* $target_name cget -gdb-port
*/
target->gdb_port_override = strdup(gdb_port_next);
long portnumber;
/* If we can parse the port number
* then we increment the port number for the next target.
@@ -3432,11 +3448,6 @@ static int gdb_target_add_one(struct target *target)
int gdb_target_add_all(struct target *target)
{
if (strcmp(gdb_port, "disabled") == 0) {
LOG_INFO("gdb server disabled");
return ERROR_OK;
}
if (NULL == target) {
LOG_WARNING("gdb services need one or more targets defined");
return ERROR_OK;