- add ability for openocd to communicate to gdb using pipes (stdin/stdout).
[openocd.git] / src / server / gdb_server.c
index 06e24486396c910e750acaaa7ec90d68112b4c04..72f14095a244ed13185ef20a0110252c2b511d28 100644 (file)
@@ -169,10 +169,18 @@ int gdb_get_char(connection_t *connection, int* next_char)
 
        for (;;)
        {
-               retval=check_pending(connection, 1, NULL);
-               if (retval!=ERROR_OK)
-                       return retval;
-               gdb_con->buf_cnt = read_socket(connection->fd, gdb_con->buffer, GDB_BUFFER_SIZE);
+               if (connection->service->type == CONNECTION_PIPE)
+               {
+                       gdb_con->buf_cnt = read(connection->fd, gdb_con->buffer, GDB_BUFFER_SIZE);
+               }
+               else
+               {
+                       retval = check_pending(connection, 1, NULL);
+                       if (retval != ERROR_OK)
+                               return retval;
+                       gdb_con->buf_cnt = read_socket(connection->fd, gdb_con->buffer, GDB_BUFFER_SIZE);
+               }
+               
                if (gdb_con->buf_cnt > 0)
                {
                        break;
@@ -268,10 +276,21 @@ int gdb_write(connection_t *connection, void *data, int len)
        gdb_connection_t *gdb_con = connection->priv;
        if (gdb_con->closed)
                return ERROR_SERVER_REMOTE_CLOSED;
-
-       if (write_socket(connection->fd, data, len) == len)
+       
+       if (connection->service->type == CONNECTION_PIPE)
        {
-               return ERROR_OK;
+               /* write to stdout */
+               if (write(STDOUT_FILENO, data, len) == len)
+               {
+                       return ERROR_OK;
+               }
+       }
+       else
+       {
+               if (write_socket(connection->fd, data, len) == len)
+               {
+                       return ERROR_OK;
+               }
        }
        gdb_con->closed = 1;
        return ERROR_SERVER_REMOTE_CLOSED;
@@ -2158,7 +2177,7 @@ int gdb_input(connection_t *connection)
        if (retval == ERROR_SERVER_REMOTE_CLOSED)
                return retval;
 
-       /* logging does not propagate the error, yet can set th gdb_con->closed flag */
+       /* logging does not propagate the error, yet can set the gdb_con->closed flag */
        if (gdb_con->closed)
                return ERROR_SERVER_REMOTE_CLOSED;
 
@@ -2177,34 +2196,37 @@ int gdb_init(void)
                return ERROR_OK;
        }
 
-       if (gdb_port == 0)
+       if (gdb_port == 0 && server_use_pipes == 0)
        {
                LOG_WARNING("no gdb port specified, using default port 3333");
                gdb_port = 3333;
        }
 
-       while (target)
+       if (server_use_pipes)
        {
-               char service_name[8];
-
-               snprintf(service_name, 8, "gdb-%2.2i", target->target_number);
-
+               /* only a single gdb connection when using a pipe */
+               
                gdb_service = malloc(sizeof(gdb_service_t));
                gdb_service->target = target;
 
-               add_service("gdb", CONNECTION_GDB,
-                           gdb_port + target->target_number,
-                           1, gdb_new_connection, gdb_input,
-                           gdb_connection_closed,
-                           gdb_service);
-
-               LOG_DEBUG("gdb service for target %s at port %i",
-                         target->type->name,
-                         gdb_port + target->target_number);
+               add_service("gdb", CONNECTION_PIPE, 0, 1, gdb_new_connection, gdb_input, gdb_connection_closed, gdb_service);
 
-               target = target->next;
+               LOG_DEBUG("gdb service for target %s using pipes", target->type->name);
        }
+       else
+       {
+               while (target)
+               {
+                       gdb_service = malloc(sizeof(gdb_service_t));
+                       gdb_service->target = target;
 
+                       add_service("gdb", CONNECTION_TCP, gdb_port + target->target_number, 1, gdb_new_connection, gdb_input, gdb_connection_closed, gdb_service);
+                       
+                       LOG_DEBUG("gdb service for target %s at port %i", target->type->name, gdb_port + target->target_number);
+                       target = target->next;
+               }
+       }
+       
        return ERROR_OK;
 }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)