5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 *
25 * Copyright 2018 Joyent, Inc.
26 */
27
28 #include <kmdb/kmdb_kvm.h>
29 #include <kmdb/kvm.h>
30 #include <kmdb/kmdb_kdi.h>
31 #include <kmdb/kmdb_promif.h>
32 #include <kmdb/kmdb_module.h>
33 #include <kmdb/kmdb_asmutil.h>
34 #include <mdb/mdb_types.h>
35 #include <mdb/mdb_conf.h>
36 #include <mdb/mdb_err.h>
37 #include <mdb/mdb_modapi.h>
38 #include <mdb/mdb_target_impl.h>
39 #include <mdb/mdb_debug.h>
40 #include <mdb/mdb_string.h>
41 #include <mdb/mdb_ctf.h>
42 #include <mdb/mdb_kreg_impl.h>
43 #include <mdb/mdb_ks.h>
44 #include <mdb/mdb.h>
45
46 #include <strings.h>
47 #include <dlfcn.h>
48 #include <sys/isa_defs.h>
49 #include <sys/kobj.h>
50 #include <sys/kobj_impl.h>
51 #include <sys/bitmap.h>
52 #include <vm/as.h>
53
54 static const char KMT_RTLD_NAME[] = "krtld";
55 static const char KMT_MODULE[] = "mdb_ks";
56 static const char KMT_CTFPARENT[] = "genunix";
57
58 static mdb_list_t kmt_defbp_list; /* List of current deferred bp's */
59 static int kmt_defbp_lock; /* For list, running kernel holds */
60 static uint_t kmt_defbp_modchg_isload; /* Whether mod change is load/unload */
61 static struct modctl *kmt_defbp_modchg_modctl; /* modctl for defbp checking */
62 static uint_t kmt_defbp_num; /* Number of referenced def'd bp's */
63 static int kmt_defbp_bpspec; /* vespec for def'd bp activation bp */
64
65 static const mdb_se_ops_t kmt_brkpt_ops;
66 static const mdb_se_ops_t kmt_wapt_ops;
67
68 static void kmt_sync(mdb_tgt_t *);
69
70 typedef struct kmt_symarg {
71 mdb_tgt_sym_f *sym_cb; /* Caller's callback function */
535 if (first) {
536 mdb_printf(msg, NULL);
537 first = 0;
538 }
539
540 mdb_printf(" %s", kmc->kmc_modname);
541 }
542 }
543
544 if (!first && msg != NULL)
545 mdb_printf("\n");
546
547 return (n);
548 }
549
550 /*ARGSUSED*/
551 static int
552 kmt_status_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
553 {
554 struct utsname uts;
555 char uuid[37];
556 kreg_t tt;
557
558 if (mdb_tgt_readsym(mdb.m_target, MDB_TGT_AS_VIRT, &uts, sizeof (uts),
559 "unix", "utsname") != sizeof (uts)) {
560 warn("failed to read 'utsname' struct from kernel\n");
561 bzero(&uts, sizeof (uts));
562 (void) strcpy(uts.nodename, "unknown machine");
563 }
564
565 mdb_printf("debugging live kernel (%d-bit) on %s\n",
566 (int)(sizeof (void *) * NBBY),
567 (*uts.nodename == '\0' ? "(not set)" : uts.nodename));
568 mdb_printf("operating system: %s %s (%s)\n",
569 uts.release, uts.version, uts.machine);
570
571 if (mdb_tgt_readsym(mdb.m_target, MDB_TGT_AS_VIRT, uuid, sizeof (uuid),
572 "genunix", "dump_osimage_uuid") != sizeof (uuid)) {
573 warn("failed to read 'dump_osimage_uuid' string from kernel\n");
574 (void) strcpy(uuid, "(error)");
575 } else if (*uuid == '\0') {
576 (void) strcpy(uuid, "(not set)");
577 } else if (uuid[36] != '\0') {
578 (void) strcpy(uuid, "(invalid)");
579 }
580 mdb_printf("image uuid: %s\n", uuid);
581
582 mdb_printf("DTrace state: %s\n", (kmdb_kdi_dtrace_get_state() ==
583 KDI_DTSTATE_DTRACE_ACTIVE ? "active (debugger breakpoints cannot "
584 "be armed)" : "inactive"));
585
586 (void) kmdb_dpi_get_register("tt", &tt);
587 mdb_printf("stopped on: %s\n", kmt_trapname(tt));
588
589 (void) kmt_dmod_status("pending dmod loads:", KMDB_MC_STATE_LOADING);
590 (void) kmt_dmod_status("pending dmod unloads:",
591 KMDB_MC_STATE_UNLOADING);
592
593 return (DCMD_OK);
594 }
595
596 /*ARGSUSED*/
597 static int
598 kmt_switch(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
599 {
600 if (!(flags & DCMD_ADDRSPEC) || argc != 0)
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 *
25 * Copyright 2019 Joyent, Inc.
26 */
27
28 #include <kmdb/kmdb_kvm.h>
29 #include <kmdb/kvm.h>
30 #include <kmdb/kmdb_kdi.h>
31 #include <kmdb/kmdb_promif.h>
32 #include <kmdb/kmdb_module.h>
33 #include <kmdb/kmdb_asmutil.h>
34 #include <mdb/mdb_types.h>
35 #include <mdb/mdb_conf.h>
36 #include <mdb/mdb_err.h>
37 #include <mdb/mdb_modapi.h>
38 #include <mdb/mdb_target_impl.h>
39 #include <mdb/mdb_debug.h>
40 #include <mdb/mdb_string.h>
41 #include <mdb/mdb_ctf.h>
42 #include <mdb/mdb_kreg_impl.h>
43 #include <mdb/mdb_ks.h>
44 #include <mdb/mdb.h>
45
46 #include <strings.h>
47 #include <dlfcn.h>
48 #include <sys/isa_defs.h>
49 #include <sys/kobj.h>
50 #include <sys/kobj_impl.h>
51 #include <sys/bitmap.h>
52 #include <sys/uuid.h>
53 #include <vm/as.h>
54
55 static const char KMT_RTLD_NAME[] = "krtld";
56 static const char KMT_MODULE[] = "mdb_ks";
57 static const char KMT_CTFPARENT[] = "genunix";
58
59 static mdb_list_t kmt_defbp_list; /* List of current deferred bp's */
60 static int kmt_defbp_lock; /* For list, running kernel holds */
61 static uint_t kmt_defbp_modchg_isload; /* Whether mod change is load/unload */
62 static struct modctl *kmt_defbp_modchg_modctl; /* modctl for defbp checking */
63 static uint_t kmt_defbp_num; /* Number of referenced def'd bp's */
64 static int kmt_defbp_bpspec; /* vespec for def'd bp activation bp */
65
66 static const mdb_se_ops_t kmt_brkpt_ops;
67 static const mdb_se_ops_t kmt_wapt_ops;
68
69 static void kmt_sync(mdb_tgt_t *);
70
71 typedef struct kmt_symarg {
72 mdb_tgt_sym_f *sym_cb; /* Caller's callback function */
536 if (first) {
537 mdb_printf(msg, NULL);
538 first = 0;
539 }
540
541 mdb_printf(" %s", kmc->kmc_modname);
542 }
543 }
544
545 if (!first && msg != NULL)
546 mdb_printf("\n");
547
548 return (n);
549 }
550
551 /*ARGSUSED*/
552 static int
553 kmt_status_dcmd(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
554 {
555 struct utsname uts;
556 char uuid[UUID_PRINTABLE_STRING_LENGTH];
557 kreg_t tt;
558
559 if (mdb_tgt_readsym(mdb.m_target, MDB_TGT_AS_VIRT, &uts, sizeof (uts),
560 "unix", "utsname") != sizeof (uts)) {
561 warn("failed to read 'utsname' struct from kernel\n");
562 bzero(&uts, sizeof (uts));
563 (void) strcpy(uts.nodename, "unknown machine");
564 }
565
566 mdb_printf("debugging live kernel (%d-bit) on %s\n",
567 (int)(sizeof (void *) * NBBY),
568 (*uts.nodename == '\0' ? "(not set)" : uts.nodename));
569 mdb_printf("operating system: %s %s (%s)\n",
570 uts.release, uts.version, uts.machine);
571
572 mdb_print_buildversion();
573
574 if (mdb_readsym(uuid, sizeof (uuid),
575 "dump_osimage_uuid") == sizeof (uuid) &&
576 uuid[sizeof (uuid) - 1] == '\0') {
577 mdb_printf("image uuid: %s\n", uuid[0] != '\0' ?
578 uuid : "(not set)");
579 }
580
581 mdb_printf("DTrace state: %s\n", (kmdb_kdi_dtrace_get_state() ==
582 KDI_DTSTATE_DTRACE_ACTIVE ? "active (debugger breakpoints cannot "
583 "be armed)" : "inactive"));
584
585 (void) kmdb_dpi_get_register("tt", &tt);
586 mdb_printf("stopped on: %s\n", kmt_trapname(tt));
587
588 (void) kmt_dmod_status("pending dmod loads:", KMDB_MC_STATE_LOADING);
589 (void) kmt_dmod_status("pending dmod unloads:",
590 KMDB_MC_STATE_UNLOADING);
591
592 return (DCMD_OK);
593 }
594
595 /*ARGSUSED*/
596 static int
597 kmt_switch(uintptr_t addr, uint_t flags, int argc, const mdb_arg_t *argv)
598 {
599 if (!(flags & DCMD_ADDRSPEC) || argc != 0)
|