db_trap.c revision 1.22 1 1.22 perry /* $NetBSD: db_trap.c,v 1.22 2005/02/26 23:04:17 perry Exp $ */
2 1.5 cgd
3 1.19 simonb /*
4 1.1 cgd * Mach Operating System
5 1.1 cgd * Copyright (c) 1991,1990 Carnegie Mellon University
6 1.1 cgd * All Rights Reserved.
7 1.19 simonb *
8 1.1 cgd * Permission to use, copy, modify and distribute this software and its
9 1.1 cgd * documentation is hereby granted, provided that both the copyright
10 1.1 cgd * notice and this permission notice appear in all copies of the
11 1.1 cgd * software, derivative works or modified versions, and any portions
12 1.1 cgd * thereof, and that both notices appear in supporting documentation.
13 1.19 simonb *
14 1.14 pk * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 1.1 cgd * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 1.1 cgd * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 1.19 simonb *
18 1.1 cgd * Carnegie Mellon requests users of this software to return to
19 1.19 simonb *
20 1.1 cgd * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 1.1 cgd * School of Computer Science
22 1.1 cgd * Carnegie Mellon University
23 1.1 cgd * Pittsburgh PA 15213-3890
24 1.19 simonb *
25 1.1 cgd * any improvements or extensions that they make and grant Carnegie the
26 1.1 cgd * rights to redistribute these changes.
27 1.1 cgd *
28 1.1 cgd * Author: David B. Golub, Carnegie Mellon University
29 1.1 cgd * Date: 7/90
30 1.1 cgd */
31 1.1 cgd
32 1.1 cgd /*
33 1.1 cgd * Trap entry point to kernel debugger.
34 1.1 cgd */
35 1.18 lukem
36 1.18 lukem #include <sys/cdefs.h>
37 1.22 perry __KERNEL_RCSID(0, "$NetBSD: db_trap.c,v 1.22 2005/02/26 23:04:17 perry Exp $");
38 1.18 lukem
39 1.7 mycroft #include <sys/param.h>
40 1.7 mycroft #include <sys/proc.h>
41 1.7 mycroft
42 1.7 mycroft #include <machine/db_machdep.h>
43 1.7 mycroft
44 1.6 mycroft #include <ddb/db_run.h>
45 1.1 cgd #include <ddb/db_command.h>
46 1.1 cgd #include <ddb/db_break.h>
47 1.9 christos #include <ddb/db_output.h>
48 1.9 christos #include <ddb/db_sym.h>
49 1.9 christos #include <ddb/db_extern.h>
50 1.1 cgd
51 1.16 jeffs /*
52 1.16 jeffs * db_trap_callback can be hooked by MD port code to handle special
53 1.16 jeffs * cases such as disabling hardware watchdogs while in DDB.
54 1.16 jeffs */
55 1.15 jeffs void (*db_trap_callback)(int);
56 1.15 jeffs
57 1.21 briggs int db_trap_type;
58 1.21 briggs
59 1.9 christos void
60 1.19 simonb db_trap(int type, int code)
61 1.1 cgd {
62 1.1 cgd boolean_t bkpt;
63 1.1 cgd boolean_t watchpt;
64 1.21 briggs
65 1.21 briggs db_trap_type = type;
66 1.1 cgd
67 1.1 cgd bkpt = IS_BREAKPOINT_TRAP(type, code);
68 1.1 cgd watchpt = IS_WATCHPOINT_TRAP(type, code);
69 1.1 cgd
70 1.15 jeffs if (db_trap_callback) db_trap_callback(1);
71 1.15 jeffs
72 1.6 mycroft if (db_stop_at_pc(DDB_REGS, &bkpt)) {
73 1.19 simonb if (db_inst_count) {
74 1.19 simonb db_printf("After %d instructions "
75 1.19 simonb "(%d loads, %d stores),\n",
76 1.19 simonb db_inst_count, db_load_count, db_store_count);
77 1.19 simonb }
78 1.20 thorpej if (curlwp != NULL) {
79 1.19 simonb if (bkpt)
80 1.19 simonb db_printf("Breakpoint");
81 1.19 simonb else if (watchpt)
82 1.19 simonb db_printf("Watchpoint");
83 1.19 simonb else
84 1.19 simonb db_printf("Stopped");
85 1.20 thorpej if (curproc == NULL)
86 1.20 thorpej db_printf("; curlwp = %p,"
87 1.20 thorpej " curproc is NULL at\t", curlwp);
88 1.20 thorpej else
89 1.22 perry db_printf(" in pid %d.%d (%s) at\t",
90 1.20 thorpej curproc->p_pid, curlwp->l_lid,
91 1.20 thorpej curproc->p_comm);
92 1.19 simonb } else if (bkpt)
93 1.19 simonb db_printf("Breakpoint at\t");
94 1.12 rvb else if (watchpt)
95 1.19 simonb db_printf("Watchpoint at\t");
96 1.12 rvb else
97 1.19 simonb db_printf("Stopped at\t");
98 1.19 simonb db_dot = PC_REGS(DDB_REGS);
99 1.19 simonb db_print_loc_and_inst(db_dot);
100 1.1 cgd
101 1.19 simonb db_command_loop();
102 1.1 cgd }
103 1.1 cgd
104 1.6 mycroft db_restart_at_pc(DDB_REGS, watchpt);
105 1.15 jeffs
106 1.19 simonb if (db_trap_callback)
107 1.19 simonb db_trap_callback(0);
108 1.1 cgd }
109