aboutsummaryrefslogtreecommitdiff
path: root/src/server/gdb_server.c
diff options
context:
space:
mode:
authorTim Newsome <tim@sifive.com>2023-10-27 09:00:59 -0700
committerTim Newsome <tim@sifive.com>2023-10-27 09:00:59 -0700
commitf02fe0960cca39024afbb6edbf27490cee3afb1d (patch)
tree3427e34aa27e2340274f3d2855f697f70d492071 /src/server/gdb_server.c
parent89260a5f1f76ef9490d602b004a862bd14681df5 (diff)
parent9f23a1d7c1e27c556ef9787b9d3f263f5c1ecf24 (diff)
downloadriscv-openocd-f02fe0960cca39024afbb6edbf27490cee3afb1d.zip
riscv-openocd-f02fe0960cca39024afbb6edbf27490cee3afb1d.tar.gz
riscv-openocd-f02fe0960cca39024afbb6edbf27490cee3afb1d.tar.bz2
Merge commit '9f23a1d7c1e27c556ef9787b9d3f263f5c1ecf24' into from_upstream
Conflicts: HACKING src/target/riscv/riscv-013.c Change-Id: I43ccb143cae8daa39212d66a8824ae3ad2af6fef
Diffstat (limited to 'src/server/gdb_server.c')
-rw-r--r--src/server/gdb_server.c59
1 files changed, 25 insertions, 34 deletions
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index aa23938..8409012 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -117,7 +117,7 @@ static void gdb_sig_halted(struct connection *connection);
/* number of gdb connections, mainly to suppress gdb related debugging spam
* in helper/log.c when no gdb connections are actually active */
-int gdb_actual_connections;
+static int gdb_actual_connections;
/* set if we are sending a memory map to gdb
* via qXfer:memory-map:read packet */
@@ -186,6 +186,9 @@ static bool gdb_connection_includes_target(struct connection *connection, struct
static int gdb_last_signal(struct target *target)
{
+ LOG_TARGET_DEBUG(target, "Debug reason is: %s",
+ target_debug_reason_str(target->debug_reason));
+
switch (target->debug_reason) {
case DBG_REASON_DBGRQ:
return 0x2; /* SIGINT */
@@ -200,8 +203,9 @@ static int gdb_last_signal(struct target *target)
case DBG_REASON_NOTHALTED:
return 0x0; /* no signal... shouldn't happen */
default:
- LOG_USER("undefined debug reason %d - target needs reset",
- target->debug_reason);
+ LOG_USER("undefined debug reason %d (%s) - target needs reset",
+ target->debug_reason,
+ target_debug_reason_str(target->debug_reason));
return 0x0;
}
}
@@ -272,39 +276,20 @@ static int gdb_get_char_inner(struct connection *connection, int *next_char)
}
#ifdef _WIN32
- errno = WSAGetLastError();
-
- switch (errno) {
- case WSAEWOULDBLOCK:
- usleep(1000);
- break;
- case WSAECONNABORTED:
- gdb_con->closed = true;
- return ERROR_SERVER_REMOTE_CLOSED;
- case WSAECONNRESET:
- gdb_con->closed = true;
- return ERROR_SERVER_REMOTE_CLOSED;
- default:
- LOG_ERROR("read: %d", errno);
- exit(-1);
- }
+ bool retry = (WSAGetLastError() == WSAEWOULDBLOCK);
#else
- switch (errno) {
- case EAGAIN:
- usleep(1000);
- break;
- case ECONNABORTED:
- gdb_con->closed = true;
- return ERROR_SERVER_REMOTE_CLOSED;
- case ECONNRESET:
- gdb_con->closed = true;
- return ERROR_SERVER_REMOTE_CLOSED;
- default:
- LOG_ERROR("read: %s", strerror(errno));
- gdb_con->closed = true;
- return ERROR_SERVER_REMOTE_CLOSED;
- }
+ bool retry = (errno == EAGAIN);
#endif
+
+ if (retry) {
+ // Try again after a delay
+ usleep(1000);
+ } else {
+ // Print error and close the socket
+ log_socket_error("GDB");
+ gdb_con->closed = true;
+ return ERROR_SERVER_REMOTE_CLOSED;
+ }
}
#ifdef _DEBUG_GDB_IO_
@@ -844,6 +829,7 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio
}
if (gdb_connection->ctrl_c) {
+ LOG_TARGET_DEBUG(target, "Responding with signal 2 (SIGINT) to debugger due to Ctrl-C");
signal_var = 0x2;
} else
signal_var = gdb_last_signal(ct);
@@ -4201,3 +4187,8 @@ void gdb_service_free(void)
free(gdb_port);
free(gdb_port_next);
}
+
+int gdb_get_actual_connections(void)
+{
+ return gdb_actual_connections;
+}