git: e6516294f4c7 - main - bhyve: Add support for the 'p' query

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 07 Feb 2024 13:53:09 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=e6516294f4c7afa9da40a39caab86a5cd2aeb35a

commit e6516294f4c7afa9da40a39caab86a5cd2aeb35a
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2024-02-07 13:46:59 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-02-07 13:46:59 +0000

    bhyve: Add support for the 'p' query
    
    This lets gdb query individual registers.  It's easy to implement and is
    used by gdb when attaching to a CHERI target, so let's support it.
    
    Sponsored by:   Innovate UK
    Reviewed by:    corvink, jhb
    MFC after:      2 weeks
    Differential Revision:  https://reviews.freebsd.org/D43664
---
 usr.sbin/bhyve/gdb.c | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c
index 4f427b1a0863..84e725f9085e 100644
--- a/usr.sbin/bhyve/gdb.c
+++ b/usr.sbin/bhyve/gdb.c
@@ -1035,6 +1035,29 @@ gdb_read_regs(void)
 	finish_packet();
 }
 
+static void
+gdb_read_one_reg(const uint8_t *data, size_t len)
+{
+	uint64_t regval;
+	uintmax_t reg;
+
+	reg = parse_integer(data, len);
+	if (reg >= nitems(gdb_regset)) {
+		send_error(EINVAL);
+		return;
+	}
+
+	if (vm_get_register(vcpus[cur_vcpu], gdb_regset[reg].id, &regval) ==
+	    -1) {
+		send_error(errno);
+		return;
+	}
+
+	start_packet();
+	append_unsigned_native(regval, gdb_regset[reg].size);
+	finish_packet();
+}
+
 static void
 gdb_read_mem(const uint8_t *data, size_t len)
 {
@@ -1597,10 +1620,12 @@ handle_command(const uint8_t *data, size_t len)
 
 		/* TODO: Resume any stopped CPUs. */
 		break;
-	case 'g': {
+	case 'g':
 		gdb_read_regs();
 		break;
-	}
+	case 'p':
+		gdb_read_one_reg(data + 1, len - 1);
+		break;
 	case 'H': {
 		int tid;
 
@@ -1672,7 +1697,6 @@ handle_command(const uint8_t *data, size_t len)
 	case 'v':
 		/* Handle 'vCont' */
 		/* 'vCtrlC' */
-	case 'p': /* TODO */
 	case 'P': /* TODO */
 	case 'Q': /* TODO */
 	case 't': /* TODO */