git: 1ea833a57290 - main - kdb: set kdb_why when entered via reboot and panic

From: Tom Jones <thj_at_FreeBSD.org>
Date: Tue, 12 Apr 2022 09:35:23 UTC
The branch main has been updated by thj:

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

commit 1ea833a57290e04a5dfa8eebd6d4fa28204a807b
Author:     Tom Jones <thj@FreeBSD.org>
AuthorDate: 2022-04-12 09:30:22 +0000
Commit:     Tom Jones <thj@FreeBSD.org>
CommitDate: 2022-04-12 09:34:40 +0000

    kdb: set kdb_why when entered via reboot and panic
    
    Reviewed by:    jhb
    Sponsored by:   NetApp, Inc.
    Sponsored by:   Klara, Inc.
    X-NetApp-PR:    #74
    Differential Revision:  https://reviews.freebsd.org/D34551
---
 sys/kern/subr_kdb.c | 4 +++-
 sys/sys/kdb.h       | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/sys/kern/subr_kdb.c b/sys/kern/subr_kdb.c
index b189fe303e0f..6aa8bd17e048 100644
--- a/sys/kern/subr_kdb.c
+++ b/sys/kern/subr_kdb.c
@@ -292,6 +292,7 @@ void
 kdb_panic(const char *msg)
 {
 
+	kdb_why = KDB_WHY_PANIC;
 	printf("KDB: panic\n");
 	panic("%s", msg);
 }
@@ -300,6 +301,7 @@ void
 kdb_reboot(void)
 {
 
+	kdb_why = KDB_WHY_REBOOT;
 	printf("KDB: reboot requested\n");
 	shutdown_nice(0);
 }
@@ -498,9 +500,9 @@ kdb_enter(const char *why, const char *msg)
 {
 
 	if (kdb_dbbe != NULL && kdb_active == 0) {
+		kdb_why = why;
 		if (msg != NULL)
 			printf("KDB: enter: %s\n", msg);
-		kdb_why = why;
 		breakpoint();
 		kdb_why = KDB_WHY_UNSET;
 	}
diff --git a/sys/sys/kdb.h b/sys/sys/kdb.h
index 746abb0ee4f4..4669a3f9f551 100644
--- a/sys/sys/kdb.h
+++ b/sys/sys/kdb.h
@@ -121,6 +121,7 @@ extern const char * volatile kdb_why;
 #define	KDB_WHY_POWERPC		"powerpc"	/* Unhandled powerpc intr. */
 #define	KDB_WHY_UNIONFS		"unionfs"	/* Unionfs bug. */
 #define	KDB_WHY_DTRACE		"dtrace"	/* DTrace action entered debugger. */
+#define	KDB_WHY_REBOOT		"reboot"	/* reboot was requested. */
 
 /* Return values for kdb_alt_break */
 #define	KDB_REQ_DEBUGGER	1	/* User requested Debugger */