build: remove warn_unused_result errors
[fw/openocd] / src / server / gdb_server.c
index 54899589dc622fe5fda07e4c76c4d5d28c07bc56..222af47a0486ebc2dcab316d8d4a3429e9d94325 100644 (file)
@@ -2387,42 +2387,22 @@ static int gdb_input(struct connection *connection)
        return ERROR_OK;
 }
 
-static int gdb_target_start(struct target *target, uint16_t port)
+static int gdb_target_start(struct target *target, const char *port)
 {
-       bool use_pipes = 0 == port;
        struct gdb_service *gdb_service = malloc(sizeof(struct gdb_service));
        if (NULL == gdb_service)
                return -ENOMEM;
 
        gdb_service->target = target;
 
-       add_service("gdb", use_pipes ? CONNECTION_PIPE : CONNECTION_TCP,
+       return add_service("gdb",
                        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;
 }
 
 static int gdb_target_add_one(struct target *target)
 {
-       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_ERROR("Illegal port number");
-               return ERROR_FAIL;
-       }
-
-       int retval = gdb_target_start(target, portnumber_parsed);
+       int retval = gdb_target_start(target, gdb_port_next);
        if (retval == ERROR_OK)
        {
                long portnumber;
@@ -2430,7 +2410,7 @@ static int gdb_target_add_one(struct target *target)
                 * then we increment the port number for the next target.
                 */
                char *end;
-               strtol(gdb_port_next, &end, 0);
+               portnumber = strtol(gdb_port_next, &end, 0);
                if (!*end)
                {
                        if (parse_long(gdb_port_next, &portnumber) == ERROR_OK)
@@ -2486,8 +2466,10 @@ COMMAND_HANDLER(handle_gdb_sync_command)
 COMMAND_HANDLER(handle_gdb_port_command)
 {
        int retval = CALL_COMMAND_HANDLER(server_pipe_command, &gdb_port);
-       if (ERROR_OK == retval)
+       if (ERROR_OK == retval) {
+               free((void*)gdb_port_next);
                gdb_port_next = strdup(gdb_port);
+       }
        return retval;
 }
 
@@ -2565,9 +2547,13 @@ static const struct command_registration gdb_command_handlers[] = {
                .name = "gdb_port",
                .handler = handle_gdb_port_command,
                .mode = COMMAND_ANY,
-               .help = "Display or specify base port on which to listen "
-                       "for incoming GDB connections.  "
-                       "No arguments reports GDB port; zero disables.",
+               .help = "Normally gdb listens to a TCP/IP port. Each subsequent GDB "
+                               "server listens for the next port number after the "
+                               "base port number specified. "
+                               "No arguments reports GDB port. \"pipe\" means listen to stdin "
+                               "output to stdout, an integer is base port number, \"disable\" disables "
+                               "port. Any other string is are interpreted as named pipe to listen to. "
+                               "Output pipe is the same name as input pipe, but with 'o' appended.",
                .usage = "[port_num]",
        },
        {