From owner-dev-commits-src-branches@freebsd.org Mon Jan 25 13:43:07 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 3DAD04E27FC; Mon, 25 Jan 2021 13:43:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DPWK71GpDz4RkT; Mon, 25 Jan 2021 13:43:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 13E8917179; Mon, 25 Jan 2021 13:43:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 10PDh7qp023040; Mon, 25 Jan 2021 13:43:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 10PDh7Fm023039; Mon, 25 Jan 2021 13:43:07 GMT (envelope-from git) Date: Mon, 25 Jan 2021 13:43:07 GMT Message-Id: <202101251343.10PDh7Fm023039@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mitchell Horne Subject: git: 28388d8abf8e - stable/12 - ddb: add ability to print user registers MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 28388d8abf8e2c7ac9247b138479832f96bcddc3 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jan 2021 13:43:07 -0000 The branch stable/12 has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=28388d8abf8e2c7ac9247b138479832f96bcddc3 commit 28388d8abf8e2c7ac9247b138479832f96bcddc3 Author: mhorne AuthorDate: 2020-12-18 20:06:46 +0000 Commit: Mitchell Horne CommitDate: 2021-01-25 13:41:39 +0000 ddb: add ability to print user registers Reviewed by: jhb (earlier version), markj, bcr (manpages) Sponsored by: The FreeBSD Foundation (cherry picked from commit 088a7eef95b1f1919fe6eee722a57c4d4e1e0656) --- share/man/man4/ddb.4 | 10 +++------- sys/ddb/db_print.c | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/share/man/man4/ddb.4 b/share/man/man4/ddb.4 index 188b5c8fc5ec..28a54a49322d 100644 --- a/share/man/man4/ddb.4 +++ b/share/man/man4/ddb.4 @@ -934,14 +934,10 @@ at address Display the register set. If the .Cm u -modifier is specified, it displays user registers instead of -kernel registers or the currently saved one. +modifier is specified, the register contents of the thread's previous +trapframe are displayed instead. +Usually, this corresponds to the saved state from userspace. .Pp -.Sy Warning : -The support of the -.Cm u -modifier depends on the machine. -If not supported, incorrect information will be displayed. .\" .Pp .It Ic show Cm rman Ar addr diff --git a/sys/ddb/db_print.c b/sys/ddb/db_print.c index 3ff0b781532d..da929457984d 100644 --- a/sys/ddb/db_print.c +++ b/sys/ddb/db_print.c @@ -49,12 +49,32 @@ __FBSDID("$FreeBSD$"); #include void -db_show_regs(db_expr_t _1, bool _2, db_expr_t _3, char *_4) +db_show_regs(db_expr_t _1, bool _2, db_expr_t _3, char *modif) { + struct trapframe *oldtf; struct db_variable *regp; db_expr_t value, offset; const char *name; + /* + * The 'u' modifier instructs us to print the previous trapframe, most + * often containing state from userspace. This is done by temporarily + * switching out kdb_frame. + * + * NB: curthread is used instead of kdb_thread, so that behaviour is + * consistent with regular `show registers`, which always prints + * curthread's trapframe. + */ + oldtf = kdb_frame; + if (modif[0] == 'u') { + if (curthread->td_frame == NULL || + curthread->td_frame == oldtf) { + db_printf("previous trapframe unavailable"); + return; + } + kdb_frame = curthread->td_frame; + } + for (regp = db_regs; regp < db_eregs; regp++) { if (!db_read_variable(regp, &value)) continue; @@ -70,4 +90,6 @@ db_show_regs(db_expr_t _1, bool _2, db_expr_t _3, char *_4) db_printf("\n"); } db_print_loc_and_inst(PC_REGS()); + + kdb_frame = oldtf; }