1 /* $OpenBSD: db_trap.c,v 1.10 2001/11/06 19:53:18 miod Exp $ */
2 /* $NetBSD: db_trap.c,v 1.9 1996/02/05 01:57:18 christos Exp $ */
3
4 /*
5 * Mach Operating System
6 * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
7 * All Rights Reserved.
8 *
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie Mellon
27 * the rights to redistribute these changes.
28 *
29 * Author: David B. Golub, Carnegie Mellon University
30 * Date: 7/90
31 */
32
33 /*
34 * Trap entry point to kernel debugger.
35 */
36 #include <sys/param.h>
37 #include <sys/proc.h>
38 #include <sys/systm.h>
39
40 #include <uvm/uvm_extern.h>
41
42 #include <machine/db_machdep.h>
43
44 #include <ddb/db_run.h>
45 #include <ddb/db_command.h>
46 #include <ddb/db_break.h>
47 #include <ddb/db_output.h>
48 #include <ddb/db_sym.h>
49 #include <ddb/db_extern.h>
50
51 extern label_t *db_recover;
52 void
db_trap(type,code)53 db_trap(type, code)
54 int type, code;
55 {
56 boolean_t bkpt;
57 boolean_t watchpt;
58 label_t db_jmpbuf;
59 label_t *savejmp;
60
61
62 bkpt = IS_BREAKPOINT_TRAP(type, code);
63 watchpt = IS_WATCHPOINT_TRAP(type, code);
64
65 if (db_stop_at_pc(DDB_REGS, &bkpt)) {
66 if (db_inst_count) {
67 db_printf("After %d instructions ", db_inst_count);
68 db_printf("(%d loads, %d stores),\n", db_load_count,
69 db_store_count);
70 }
71 if (bkpt)
72 db_printf("Breakpoint at\t");
73 else if (watchpt)
74 db_printf("Watchpoint at\t");
75 else
76 db_printf("Stopped at\t");
77 db_dot = PC_REGS(DDB_REGS);
78
79
80 savejmp = db_recover;
81 db_recover = &db_jmpbuf;
82 if (setjmp(&db_jmpbuf) == 0)
83 db_print_loc_and_inst(db_dot);
84
85 db_recover = savejmp;
86
87 if (panicstr != NULL) {
88 if (db_print_position() != 0)
89 db_printf("\n");
90 db_printf("RUN AT LEAST 'trace' AND 'ps' AND INCLUDE "
91 "OUTPUT WHEN REPORTING THIS PANIC!\n");
92 db_printf("DO NOT EVEN BOTHER REPORTING THIS WITHOUT "
93 "INCLUDING THAT INFORMATION!\n");
94 }
95
96 db_command_loop();
97 }
98
99 db_restart_at_pc(DDB_REGS, watchpt);
100 }
101