summaryrefslogtreecommitdiff
path: root/src/server/gdb_server.c
diff options
context:
space:
mode:
authordrath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2006-07-17 14:13:27 +0000
committerdrath <drath@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2006-07-17 14:13:27 +0000
commit82d2633b5f550115e9e7c7d0520babb6680aa38f (patch)
treefa9895a6117d4a238be1b76293edcc7de11a88c2 /src/server/gdb_server.c
parent1960973baf8022b4525e3ac94aed8dace7f9b478 (diff)
downloadopenocd_libswd-82d2633b5f550115e9e7c7d0520babb6680aa38f.tar.gz
openocd_libswd-82d2633b5f550115e9e7c7d0520babb6680aa38f.tar.bz2
openocd_libswd-82d2633b5f550115e9e7c7d0520babb6680aa38f.tar.xz
openocd_libswd-82d2633b5f550115e9e7c7d0520babb6680aa38f.zip
- Added support for native MinGW builds (thanks to Spencer Oliver and Michael Fischer) - you still need to install GiveIO (not part of OpenOCD)
- Added state-move support to ftd2xx and bitbang JTAG drivers (required for XScale, possibly useful for other targets, too) - various fixes git-svn-id: svn://svn.berlios.de/openocd/trunk@78 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/server/gdb_server.c')
-rw-r--r--src/server/gdb_server.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index b0c09961..4b99922c 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -17,7 +17,11 @@
* 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"
@@ -32,21 +36,6 @@
#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;
}