4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 * Copyright 2016 Joyent, Inc.
29 * Handling of unintentional faults (i.e. bugs) in the debugger.
34 #include <kmdb/kmdb_fault.h>
35 #include <kmdb/kmdb_promif.h>
36 #include <kmdb/kmdb_kdi.h>
37 #include <kmdb/kmdb_dpi.h>
38 #include <mdb/mdb_debug.h>
39 #include <mdb/mdb_kreg.h>
40 #include <mdb/mdb_io_impl.h>
44 kmdb_fault(kreg_t tt
, kreg_t pc
, kreg_t sp
, int cpuid
)
46 int debug_self_confirm
= 0;
51 /* Make absolutely sure */
52 kmdb_kdi_system_claim();
55 if (setjmp(pcb
) != 0) {
57 mdb_iob_printf(mdb
.m_err
,
58 "\n*** First stack trace attempt failed. "
59 "Trying safe mode.\n\n");
61 kmdb_fault_display(tt
, pc
, sp
, 1);
63 mdb_iob_printf(mdb
.m_err
,
64 "\n*** Unable to print stack trace.\n");
68 old
= kmdb_dpi_set_fault_hdlr(&pcb
);
70 mdb_iob_printf(mdb
.m_err
, "\n*** Debugger Fault (CPU %d)\n\n",
72 kmdb_fault_display(tt
, pc
, sp
, 0);
75 kmdb_dpi_restore_fault_hdlr(old
);
77 if (mdb
.m_term
!= NULL
) {
79 mdb_iob_printf(mdb
.m_err
, "\n%s: "
81 ", or (d)ebug with self? ", mdb
.m_pname
);
82 mdb_iob_flush(mdb
.m_err
);
84 if (IOP_READ(mdb
.m_term
, &c
, sizeof (c
)) != sizeof (c
))
87 mdb_iob_printf(mdb
.m_err
, "\n");
103 * Debug self - get confirmation, because they
104 * can't go back to their running system if
105 * they choose this one.
107 if (debug_self_confirm
== 0) {
108 mdb_iob_printf(mdb
.m_err
,
109 "NOTE: You will not be able to "
110 "resume your system if you "
111 "choose this option.\nPlease "
112 "select 'd' again to confirm.\n");
113 debug_self_confirm
= 1;
117 kmdb_dpi_set_state(DPI_STATE_LOST
, 0);