Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/ddb Add command to print device list.



details:   https://anonhg.NetBSD.org/src/rev/b3638c32d997
branches:  trunk
changeset: 320885:b3638c32d997
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Sun Mar 04 07:14:50 2018 +0000

description:
Add command to print device list.

diffstat:

 sys/ddb/db_autoconf.c  |  89 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sys/ddb/db_autoconf.h  |  35 +++++++++++++++++++
 sys/ddb/db_command.c   |   5 +-
 sys/ddb/db_interface.h |   9 ++++-
 sys/ddb/ddb.h          |   3 +-
 sys/ddb/files.ddb      |   3 +-
 6 files changed, 139 insertions(+), 5 deletions(-)

diffs (214 lines):

diff -r 62847e34147a -r b3638c32d997 sys/ddb/db_autoconf.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/ddb/db_autoconf.c     Sun Mar 04 07:14:50 2018 +0000
@@ -0,0 +1,89 @@
+/*     $NetBSD: db_autoconf.c,v 1.1 2018/03/04 07:14:50 mlelstv Exp $  */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: db_autoconf.c,v 1.1 2018/03/04 07:14:50 mlelstv Exp $");
+
+#ifndef _KERNEL
+#include <stdbool.h>
+#endif
+
+#include <sys/param.h>
+#include <sys/device.h>
+
+#include <ddb/ddb.h>
+
+static const char *classnames[] = {
+       "dull", "cpu", "disk", "ifnet", "tape", "tty",
+       "audiodev", "displaydev", "bus", "virtual"
+};
+
+struct device *
+db_device_first(void)
+{
+
+       return db_read_ptr("alldevs");
+}
+
+struct device *
+db_device_next(struct device *dv)
+{
+
+       db_read_bytes((db_addr_t)&dv->dv_list.tqe_next, sizeof(dv),
+           (char *)&dv);
+       return dv;
+}
+
+void
+db_show_all_devices(db_expr_t addr, bool haddr, db_expr_t count,
+                 const char *modif)
+{
+       struct device buf;
+       struct device *dv;
+       const char *cl;
+
+       db_printf("%-16s %10s %4s %18s %18s\n",
+               "NAME","CLASS","UNIT","DEVICE_T","PRIVATE");
+
+       for (dv = db_device_first(); dv != NULL; dv = db_device_next(dv)) {
+               db_read_bytes((db_addr_t)dv, sizeof(buf), (char *)&buf);
+
+               if (buf.dv_class < 0 ||
+                   buf.dv_class > __arraycount(classnames))
+                       cl = "????";
+               else
+                       cl = classnames[buf.dv_class];
+
+               db_printf("%-16.16s", buf.dv_xname);
+               db_printf(" %10s", cl);
+               db_printf(" %4u", buf.dv_unit);
+               db_printf(" %18" PRIxPTR, (uintptr_t)dv);
+               db_printf(" %18" PRIxPTR, (uintptr_t)buf.dv_private);
+               db_printf("\n");
+       }
+}
diff -r 62847e34147a -r b3638c32d997 sys/ddb/db_autoconf.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/ddb/db_autoconf.h     Sun Mar 04 07:14:50 2018 +0000
@@ -0,0 +1,35 @@
+/*     $NetBSD: db_autoconf.h,v 1.1 2018/03/04 07:14:50 mlelstv Exp $  */
+
+/*-
+ * Copyright (c) 2016 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _DDB_DB_AUTOCONF_H_
+#define _DDB_DB_AUTOCONF_H_
+
+struct device *db_device_first(void);
+struct device *db_device_next(struct device *);
+
+#endif /* _DDB_DB_AUTOCONF_H_ */
diff -r 62847e34147a -r b3638c32d997 sys/ddb/db_command.c
--- a/sys/ddb/db_command.c      Sun Mar 04 07:13:11 2018 +0000
+++ b/sys/ddb/db_command.c      Sun Mar 04 07:14:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_command.c,v 1.148 2017/01/11 12:17:34 joerg Exp $   */
+/*     $NetBSD: db_command.c,v 1.149 2018/03/04 07:14:50 mlelstv Exp $ */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 1999, 2002, 2009 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.148 2017/01/11 12:17:34 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_command.c,v 1.149 2018/03/04 07:14:50 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_aio.h"
@@ -241,6 +241,7 @@
 #endif
        { DDB_ADD_CMD("buf",    db_buf_print_cmd,       0,
            "Print the struct buf at address.", "[/f] address",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) },
        { DDB_ADD_CMD("files", db_show_files_cmd,       0,
diff -r 62847e34147a -r b3638c32d997 sys/ddb/db_interface.h
--- a/sys/ddb/db_interface.h    Sun Mar 04 07:13:11 2018 +0000
+++ b/sys/ddb/db_interface.h    Sun Mar 04 07:14:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_interface.h,v 1.35 2017/10/27 12:25:15 joerg Exp $  */
+/*     $NetBSD: db_interface.h,v 1.36 2018/03/04 07:14:50 mlelstv Exp $        */
 
 /*-
  * Copyright (c) 1995 The NetBSD Foundation, Inc.
@@ -73,6 +73,13 @@
 /* kern/subr_vmem.c */
 void           db_show_all_vmems(db_expr_t, bool, db_expr_t, const char *);
 
+/* kern/subr_autoconf.c */
+void           db_show_all_devices(db_expr_t, bool, db_expr_t, const char *);
+void           db_show_all_device(db_expr_t, bool, db_expr_t, const char *);
+
+/* kern/subr_disk.c, dev/dksubr.c */
+void           db_show_disk(db_expr_t, bool, db_expr_t, const char *);
+
 #define        db_stacktrace() \
     db_stack_trace_print((db_expr_t)(intptr_t)__builtin_frame_address(0), \
        true, 65535, "", printf)
diff -r 62847e34147a -r b3638c32d997 sys/ddb/ddb.h
--- a/sys/ddb/ddb.h     Sun Mar 04 07:13:11 2018 +0000
+++ b/sys/ddb/ddb.h     Sun Mar 04 07:14:50 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ddb.h,v 1.2 2009/04/10 22:29:30 ad Exp $       */
+/*     $NetBSD: ddb.h,v 1.3 2018/03/04 07:14:50 mlelstv Exp $  */
 
 /*-
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -49,5 +49,6 @@
 #include <ddb/db_access.h>
 #include <ddb/db_proc.h>
 #include <ddb/db_cpu.h>
+#include <ddb/db_autoconf.h>
 
 #endif /* _DDB_DDB_H_ */
diff -r 62847e34147a -r b3638c32d997 sys/ddb/files.ddb
--- a/sys/ddb/files.ddb Sun Mar 04 07:13:11 2018 +0000
+++ b/sys/ddb/files.ddb Sun Mar 04 07:14:50 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.ddb,v 1.11 2017/12/28 17:51:19 christos Exp $
+#      $NetBSD: files.ddb,v 1.12 2018/03/04 07:14:50 mlelstv Exp $
 
 #
 # DDB options
@@ -10,6 +10,7 @@
 
 define ddb
 file   ddb/db_access.c                 ddb | kgdb
+file   ddb/db_autoconf.c               ddb
 file   ddb/db_break.c                  ddb
 file   ddb/db_command.c                ddb
 file   ddb/db_cpu.c                    ddb



Home | Main Index | Thread Index | Old Index