git: 1c002413c3d5 - stable/12 - gdb(4): allow bulk write of registers

Mitchell Horne mhorne at FreeBSD.org
Mon Jan 4 21:11:17 UTC 2021


The branch stable/12 has been updated by mhorne:

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

commit 1c002413c3d5bc9a4b9f9258d4113e92a55b1ae7
Author:     Mitchell Horne <mhorne at FreeBSD.org>
AuthorDate: 2020-12-23 18:37:05 +0000
Commit:     Mitchell Horne <mhorne at FreeBSD.org>
CommitDate: 2021-01-04 21:00:42 +0000

    gdb(4): allow bulk write of registers
    
    Add support for the remote 'G' packet. This is not widely used by gdb
    when 'P' is supported, but is technically required by any remote gdb
    stub implementation [1].
    
    [1] https://sourceware.org/gdb/current/onlinedocs/gdb/Overview.html
    
    Sponsored by:   NetApp, Inc.
    Sponsored by:   Klara, Inc.
    
    (cherry picked from commit 3f3cc995a35a3e9136204a98af0af5808c11047f)
---
 sys/gdb/gdb_main.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/sys/gdb/gdb_main.c b/sys/gdb/gdb_main.c
index 4c16e06daecf..c5a77430ca5f 100644
--- a/sys/gdb/gdb_main.c
+++ b/sys/gdb/gdb_main.c
@@ -199,9 +199,23 @@ gdb_trap(int type, int code)
 			gdb_tx_end();
 			break;
 		}
-		case 'G':	/* Write registers. */
-			gdb_tx_err(0);
+		case 'G': {	/* Write registers. */
+			char *val;
+			bool success;
+			size_t r;
+			for (success = true, r = 0; r < GDB_NREGS; r++) {
+				val = gdb_rxp;
+				if (!gdb_rx_mem(val, gdb_cpu_regsz(r))) {
+					gdb_tx_err(EINVAL);
+					success = false;
+					break;
+				}
+				gdb_cpu_setreg(r, val);
+			}
+			if (success)
+				gdb_tx_ok();
 			break;
+		}
 		case 'H': {	/* Set thread. */
 			intmax_t tid;
 			struct thread *thr;


More information about the dev-commits-src-all mailing list