Module Name:    src
Committed By:   ad
Date:           Sat Oct  7 20:27:20 UTC 2023

Modified Files:
        src/sys/ddb: db_command.c db_interface.h db_xxx.c

Log Message:
Add some simple DDB show commands: condvar, selinfo, sleepq


To generate a diff of this commit:
cvs rdiff -u -r1.185 -r1.186 src/sys/ddb/db_command.c
cvs rdiff -u -r1.40 -r1.41 src/sys/ddb/db_interface.h
cvs rdiff -u -r1.75 -r1.76 src/sys/ddb/db_xxx.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ddb/db_command.c
diff -u src/sys/ddb/db_command.c:1.185 src/sys/ddb/db_command.c:1.186
--- src/sys/ddb/db_command.c:1.185	Mon Jul 17 12:55:03 2023
+++ src/sys/ddb/db_command.c	Sat Oct  7 20:27:20 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_command.c,v 1.185 2023/07/17 12:55:03 riastradh Exp $	*/
+/*	$NetBSD: db_command.c,v 1.186 2023/10/07 20:27:20 ad Exp $	*/
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009, 2019
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.185 2023/07/17 12:55:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.186 2023/10/07 20:27:20 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -249,6 +249,8 @@ static const struct db_command db_show_c
 	/* added from all sub cmds */
 	{ DDB_ADD_CMD("callout",  db_show_callout,
 	    0 ,"List all used callout functions.",NULL,NULL) },
+	{ DDB_ADD_CMD("condvar", db_show_condvar,
+	    0 ,"Show the contents of a condition variable.",NULL,NULL) },
 	{ DDB_ADD_CMD("devices", db_show_all_devices,	0,NULL,NULL,NULL) },
 	{ DDB_ADD_CMD("event",	db_event_print_cmd,	0,
 	    "Print all the non-zero evcnt(9) event counters.", "[/fitm]",NULL) },
@@ -317,6 +319,10 @@ static const struct db_command db_show_c
 	{ DDB_ADD_CMD("sched_qs",	db_show_sched_qs,	0,
 	    "Print the state of the scheduler's run queues.",
 	    NULL,NULL) },
+	{ DDB_ADD_CMD("selinfo", db_show_selinfo,
+	    0 ,"Show the contents of a selinfo.",NULL,NULL) },
+	{ DDB_ADD_CMD("sleepq", db_show_sleepq,
+	    0 ,"Show the contents of a sleep queue.",NULL,NULL) },
 	{ DDB_ADD_CMD("socket",	db_socket_print_cmd,	0,NULL,NULL,NULL) },
 	{ DDB_ADD_CMD("tstiles", db_show_all_tstiles,
 	    0, "Show who's holding up tstiles", "[/t]", NULL) },

Index: src/sys/ddb/db_interface.h
diff -u src/sys/ddb/db_interface.h:1.40 src/sys/ddb/db_interface.h:1.41
--- src/sys/ddb/db_interface.h:1.40	Sun Apr 18 01:28:50 2021
+++ src/sys/ddb/db_interface.h	Sat Oct  7 20:27:20 2023
@@ -1,7 +1,7 @@
-/*	$NetBSD: db_interface.h,v 1.40 2021/04/18 01:28:50 mrg Exp $	*/
+/*	$NetBSD: db_interface.h,v 1.41 2023/10/07 20:27:20 ad Exp $	*/
 
 /*-
- * Copyright (c) 1995 The NetBSD Foundation, Inc.
+ * Copyright (c) 1995, 2023 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -52,7 +52,7 @@ void		db_show_all_procs(db_expr_t, bool,
 void		db_show_all_pools(db_expr_t, bool, db_expr_t, const char *);
 void		db_show_sched_qs(db_expr_t, bool, db_expr_t, const char *);
 
-/* kern/kern_clock.c */
+/* kern/kern_timeout.c */
 void		db_show_callout(db_expr_t, bool, db_expr_t, const char *);
 
 /* kern/subr_log.c */
@@ -80,6 +80,15 @@ void		db_show_all_device(db_expr_t, bool
 /* kern/subr_disk.c, dev/dksubr.c */
 void		db_show_disk(db_expr_t, bool, db_expr_t, const char *);
 
+/* kern/kern_sleepq.c */
+void		db_show_sleepq(db_expr_t, bool, db_expr_t, const char *);
+
+/* kern/kern_condvar.c */
+void		db_show_condvar(db_expr_t, bool, db_expr_t, const char *);
+
+/* kern/sys_select.c */
+void		db_show_selinfo(db_expr_t, bool, db_expr_t, const char *);
+
 /* The db_stacktrace_print macro may be overridden by an MD macro */
 #ifndef db_stacktrace_print
 #define	db_stacktrace_print(prfunc) \

Index: src/sys/ddb/db_xxx.c
diff -u src/sys/ddb/db_xxx.c:1.75 src/sys/ddb/db_xxx.c:1.76
--- src/sys/ddb/db_xxx.c:1.75	Sat May 23 23:42:42 2020
+++ src/sys/ddb/db_xxx.c	Sat Oct  7 20:27:20 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: db_xxx.c,v 1.75 2020/05/23 23:42:42 ad Exp $	*/
+/*	$NetBSD: db_xxx.c,v 1.76 2023/10/07 20:27:20 ad Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1991, 1993
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.75 2020/05/23 23:42:42 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1.76 2023/10/07 20:27:20 ad Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_kgdb.h"
@@ -69,6 +69,9 @@ __KERNEL_RCSID(0, "$NetBSD: db_xxx.c,v 1
 #include <sys/module.h>
 #include <sys/cpu.h>
 #include <sys/vmem.h>
+#include <sys/condvar.h>
+#include <sys/sleepq.h>
+#include <sys/selinfo.h>
 
 #include <ddb/ddb.h>
 #include <ddb/db_user.h>
@@ -325,3 +328,52 @@ db_show_panic(db_expr_t addr, bool haddr
 	(void)splx(s);
 #endif
 }
+
+void
+db_show_condvar(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
+{
+	kcondvar_t *cv = (kcondvar_t *)addr;
+	char buf[9], *wmesg;
+
+	/* XXX messing with kcondvar_t guts without defs */
+	db_read_bytes((db_addr_t)&cv->cv_opaque[1], sizeof(wmesg),
+	    (char *)&wmesg);
+	db_read_bytes((db_addr_t)wmesg, sizeof(buf) - 1, buf);
+	buf[sizeof(buf) - 1] = '\0';
+	db_printf("wmesg=%s ", buf);
+	db_show_sleepq((db_addr_t)&cv->cv_opaque[0], false, 0, modif);
+}
+
+void
+db_show_sleepq(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
+{
+	sleepq_t sq;
+	lwp_t *lp;
+
+	db_read_bytes(addr, sizeof(lp), (char *)&sq);
+	db_printf("sleepq=");
+	if ((lp = LIST_FIRST(&sq)) == NULL) {
+		db_printf("<empty>");
+	}
+	while (lp != NULL) {
+		db_printf("%p", lp);
+		db_read_bytes((db_addr_t)&lp->l_sleepchain.le_next, sizeof(lp),
+		    (char *)&lp);
+		if (lp != NULL)
+			db_printf(",");
+	}
+	db_printf("\n");
+}
+
+void
+db_show_selinfo(db_expr_t addr, bool haddr, db_expr_t count, const char *modif)
+{
+	struct selinfo sel;
+
+	db_read_bytes(addr, sizeof(sel), (char *)&sel);
+
+	db_printf("collision=%llx klist=%p cluster=%p lwp=%p fdinfo=%lx "
+	    "sel_chain=%p\n", (long long)sel.sel_collision,
+	    SLIST_FIRST(&sel.sel_klist), sel.sel_cluster, sel.sel_lwp,
+	    (long)sel.sel_fdinfo, sel.sel_chain.sle_next);
+}

Reply via email to