diff mbox series

[17/19] pdbg/gdbserver: Detach from client

Message ID 20180829015047.7355-18-rashmica.g@gmail.com
State Superseded
Headers show
Series Basic gdbserver for POWER8 | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/build-multiarch success Test build-multiarch on branch master

Commit Message

Rashmica Gupta Aug. 29, 2018, 1:50 a.m. UTC
Signed-off-by: Rashmica Gupta <rashmica.g@gmail.com>
---
 src/gdb_parser.rl | 5 ++++-
 src/pdbgproxy.c   | 9 +++++++++
 src/pdbgproxy.h   | 2 +-
 3 files changed, 14 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/gdb_parser.rl b/src/gdb_parser.rl
index 18dfac7..6259b96 100644
--- a/src/gdb_parser.rl
+++ b/src/gdb_parser.rl
@@ -76,6 +76,9 @@ 
 
 	set_thread = ('H' any* @{cmd = SET_THREAD;});
 
+	disconnect = ('D' @{cmd = DISCONNECT;}
+		     xdigit+ $hex_digit %push);
+
 	# TODO: We don't actually listen to what's supported
 	q_attached = ('qAttached:' xdigit* @{rsp = "1";});
 	q_C = ('qC' @{rsp = "QC1";});
@@ -91,7 +94,7 @@ 
 
 	commands = (get_mem | get_gprs | get_spr | stop_reason | set_thread |
 		    q_attached | q_C | q_supported | qf_threadinfo | q_C |
-		    v_contq | v_contc | v_conts | put_mem );
+		    v_contq | v_contc | v_conts | put_mem | disconnect );
 
 	cmd = ((commands & ^'#'*) | ^'#'*) $crc
 	      ('#' xdigit{2} $hex_digit @end);
diff --git a/src/pdbgproxy.c b/src/pdbgproxy.c
index ac0b3ae..eb7c0ae 100644
--- a/src/pdbgproxy.c
+++ b/src/pdbgproxy.c
@@ -36,6 +36,8 @@  static int fd = -1;
 enum client_state {IDLE, SIGNAL_WAIT};
 static enum client_state state = IDLE;
 
+static void destroy_client(int dead_fd);
+
 static uint8_t gdbcrc(char *data)
 {
 	uint8_t crc = 0;
@@ -80,6 +82,12 @@  static void stop_reason(uint64_t *stack, void *priv)
 	send_response(fd, "S05");
 }
 
+static void disconnect(uint64_t *stack, void *priv)
+{
+	printf("Terminating connection with client. pid %16" PRIi64 "\n", stack[0]);
+	send_response(fd, "OK");
+}
+
 /* 32 registers represented as 16 char hex numbers with null-termination */
 #define REG_DATA_SIZE (32*16+1)
 static void get_gprs(uint64_t *stack, void *priv)
@@ -413,6 +421,7 @@  command_cb callbacks[LAST_CMD + 1] = {
 	v_conts,
 	put_mem,
 	interrupt,
+	disconnect,
 	NULL};
 
 int gdbserver_start(struct pdbg_target *target, uint16_t port)
diff --git a/src/pdbgproxy.h b/src/pdbgproxy.h
index bd12b5e..1fe67f2 100644
--- a/src/pdbgproxy.h
+++ b/src/pdbgproxy.h
@@ -3,7 +3,7 @@ 
 
 enum gdb_command {NONE, GET_GPRS, GET_SPR, GET_MEM,
                  STOP_REASON, SET_THREAD, V_CONTC, V_CONTS,
-                 PUT_MEM, INTERRUPT, LAST_CMD};
+                 PUT_MEM, INTERRUPT, DISCONNECT, LAST_CMD};
 typedef void (*command_cb)(uint64_t *stack, void *priv);
 
 void parser_init(command_cb *callbacks);