dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / mdb / common / kmdb / kmdb_fault.c
blob36e961088c7e8db5201fa8b712864737e1bf9e54
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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.
32 #include <stdlib.h>
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>
41 #include <mdb/mdb.h>
43 void
44 kmdb_fault(kreg_t tt, kreg_t pc, kreg_t sp, int cpuid)
46 int debug_self_confirm = 0;
47 volatile int try;
48 jmp_buf pcb, *old;
49 char c;
51 /* Make absolutely sure */
52 kmdb_kdi_system_claim();
54 try = 1;
55 if (setjmp(pcb) != 0) {
56 if (++try == 2) {
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);
62 } else {
63 mdb_iob_printf(mdb.m_err,
64 "\n*** Unable to print stack trace.\n");
67 } else {
68 old = kmdb_dpi_set_fault_hdlr(&pcb);
70 mdb_iob_printf(mdb.m_err, "\n*** Debugger Fault (CPU %d)\n\n",
71 cpuid);
72 kmdb_fault_display(tt, pc, sp, 0);
75 kmdb_dpi_restore_fault_hdlr(old);
77 if (mdb.m_term != NULL) {
78 for (;;) {
79 mdb_iob_printf(mdb.m_err, "\n%s: "
80 "reboo(t)"
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))
85 goto fault_obp;
87 mdb_iob_printf(mdb.m_err, "\n");
89 switch (c) {
91 #ifndef sun4v
92 case 'o':
93 case 'O':
94 #endif /* sun4v */
95 case 't':
96 case 'T':
97 kmdb_dpi_enter_mon();
98 continue;
100 case 'd':
101 case 'D':
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;
114 continue;
117 kmdb_dpi_set_state(DPI_STATE_LOST, 0);
118 return;
123 fault_obp:
124 exit(1);
125 /*NOTREACHED*/