- Added support for native MinGW builds (thanks to Spencer Oliver and Michael Fischer...
[openocd.git] / src / server / gdb_server.c
index b0c0996119031af4590862443b08d5c69bd5f3da..4b99922cc72d84ed865a236d7378325b96d46596 100644 (file)
  *   Free Software Foundation, Inc.,                                       *
  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  ***************************************************************************/
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
+
+#include "replacements.h"
 
 #include "gdb_server.h"
 
 #include <unistd.h>
 #include <stdlib.h>
 
-#ifndef HAVE_STRNDUP
-#include <stdio.h>
-char* strndup(const char *s, size_t n)
-{
-       size_t len = strnlen (s, n);
-       char *new = (char *) malloc (len + 1);
-
-       if (new == NULL)
-               return NULL;
-
-       new[len] = '\0';
-       return (char *) memcpy (new, s, len);
-}
-#endif
-
 #if 0
 #define _DEBUG_GDB_IO_
 #endif
@@ -93,11 +82,26 @@ int gdb_get_char(connection_t *connection, int* next_char)
                return ERROR_OK;
        }
 
-       while ((gdb_con->buf_cnt = read(connection->fd, gdb_con->buffer, GDB_BUFFER_SIZE)) <= 0)
+       while ((gdb_con->buf_cnt = read_socket(connection->fd, gdb_con->buffer, GDB_BUFFER_SIZE)) <= 0)
        {
                if (gdb_con->buf_cnt == 0)
                        return ERROR_SERVER_REMOTE_CLOSED;
                
+#ifdef _WIN32
+               errno = WSAGetLastError();
+
+               switch(errno)
+               {
+                       case WSAEWOULDBLOCK:
+                               usleep(1000);
+                               break;
+                       case WSAECONNABORTED:
+                               return ERROR_SERVER_REMOTE_CLOSED;
+                       default:
+                               ERROR("read: %d", strerror(errno));
+                               exit(-1);
+               }
+#else
                switch(errno)
                {
                        case EAGAIN:
@@ -111,6 +115,7 @@ int gdb_get_char(connection_t *connection, int* next_char)
                                ERROR("read: %s", strerror(errno));
                                exit(-1);
                }
+#endif
        }
        
        debug_buffer = malloc(gdb_con->buf_cnt + 1);
@@ -155,14 +160,14 @@ int gdb_put_packet(connection_t *connection, char *buffer, int len)
                DEBUG("sending packet '$%s#%2.2x'", debug_buffer, my_checksum);
                free(debug_buffer);
                
-               write(connection->fd, "$", 1);
+               write_socket(connection->fd, "$", 1);
                if (len > 0)
-                       write(connection->fd, buffer, len);
-               write(connection->fd, "#", 1);
+                       write_socket(connection->fd, buffer, len);
+               write_socket(connection->fd, "#", 1);
        
                snprintf(checksum, 3, "%2.2x", my_checksum);
        
-               write(connection->fd, checksum, 2);
+               write_socket(connection->fd, checksum, 2);
 
                if ((retval = gdb_get_char(connection, &reply)) != ERROR_OK)
                        return retval;
@@ -310,12 +315,12 @@ int gdb_get_packet(connection_t *connection, char *buffer, int *len)
                
                if (my_checksum == strtoul(checksum, NULL, 16))
                {
-                       write (connection->fd, "+", 1);
+                       write_socket(connection->fd, "+", 1);
                        break;
                }
 
                WARNING("checksum error, requesting retransmission");
-               write(connection->fd, "-", 1);
+               write_socket(connection->fd, "-", 1);
        }
 
        return ERROR_OK;
@@ -1087,6 +1092,7 @@ int gdb_init()
                
                DEBUG("gdb service for target %s at port %i", target->type->name, gdb_port + i);
                
+               i++;
                target = target->next;
        }
        

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)