FreeBSD/Linux Kernel Cross Reference
sys/ddb/db_trap.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: db_trap.c,v $
29 * Revision 2.12 93/11/17 16:26:12 dbg
30 * ANSI-fied.
31 * [93/10/13 dbg]
32 *
33 * Revision 2.11 93/01/14 17:26:00 danner
34 * 64bit cleanup.
35 * [92/12/10 16:22:07 af]
36 *
37 * Revision 2.10 92/08/03 17:32:15 jfriedl
38 * removed silly prototypes
39 * [92/08/02 jfriedl]
40 *
41 * Revision 2.9 92/05/21 17:08:04 jfriedl
42 * tried prototypes.
43 * [92/05/20 jfriedl]
44 *
45 * Revision 2.8 91/10/09 16:03:34 af
46 * Replaced db_trap function with db_task_trap, and changed
47 * db_trap to call db_task_trap with user_space parameter.
48 * db_trap exists only for backward compatibility.
49 * Passed task parameter for user space break point support.
50 * [91/08/29 tak]
51 *
52 * Revision 2.7 91/05/18 14:29:20 rpd
53 * Protect against faults in db_print_loc_and_inst.
54 * [91/05/14 rpd]
55 *
56 * Revision 2.6 91/05/14 15:36:39 mrt
57 * Correcting copyright
58 *
59 * Revision 2.5 91/02/05 17:07:16 mrt
60 * Changed to new Mach copyright
61 * [91/01/31 16:19:35 mrt]
62 *
63 * Revision 2.4 91/01/08 15:09:17 rpd
64 * Changed db_stop_at_pc's arguments.
65 * Print db_inst_count, db_load_count, db_store_count.
66 * [90/11/27 rpd]
67 *
68 * Revision 2.3 90/10/25 14:44:11 rwd
69 * From rpd.
70 * [90/10/19 17:03:17 rwd]
71 *
72 * Generalized the watchpoint support.
73 * [90/10/16 rwd]
74 * Added watchpoint support.
75 * [90/10/16 rpd]
76 *
77 * Revision 2.2 90/08/27 21:52:52 dbg
78 * Assign to db_dot before calling the print function.
79 * [90/08/20 af]
80 * Reduce lint.
81 * [90/08/07 dbg]
82 * Created.
83 * [90/07/25 dbg]
84 *
85 */
86 /*
87 * Author: David B. Golub, Carnegie Mellon University
88 * Date: 7/90
89 */
90
91 /*
92 * Trap entry point to kernel debugger.
93 */
94 #include <mach/boolean.h>
95 #include <machine/db_machdep.h>
96 #include <ddb/db_access.h>
97 #include <ddb/db_break.h>
98 #include <ddb/db_command.h>
99 #include <ddb/db_examine.h>
100 #include <ddb/db_output.h>
101 #include <ddb/db_run.h>
102 #include <ddb/db_task_thread.h>
103
104
105 extern int db_inst_count;
106 extern int db_load_count;
107 extern int db_store_count;
108
109 void
110 db_task_trap(
111 int type,
112 int code,
113 boolean_t user_space)
114 {
115 jmp_buf_t db_jmpbuf;
116 jmp_buf_t *prev;
117 boolean_t bkpt;
118 boolean_t watchpt;
119 task_t task_space;
120
121 task_space = db_target_space(current_thread(), user_space);
122 bkpt = IS_BREAKPOINT_TRAP(type, code);
123 watchpt = IS_WATCHPOINT_TRAP(type, code);
124
125 db_init_default_thread();
126 db_check_breakpoint_valid();
127 if (db_stop_at_pc(&bkpt, task_space)) {
128 if (db_inst_count) {
129 db_printf("After %d instructions (%d loads, %d stores),\n",
130 db_inst_count, db_load_count, db_store_count);
131 }
132 if (bkpt)
133 db_printf("Breakpoint at ");
134 else if (watchpt)
135 db_printf("Watchpoint at ");
136 else
137 db_printf("Stopped at ");
138 db_dot = PC_REGS(DDB_REGS);
139
140 prev = db_recover;
141 if (_setjmp(db_recover = &db_jmpbuf) == 0)
142 db_print_loc_and_inst(db_dot, task_space);
143 else
144 db_printf("Trouble printing location %#X.\n", db_dot);
145 db_recover = prev;
146
147 db_command_loop();
148 }
149
150 db_restart_at_pc(watchpt, task_space);
151 }
152
153 void
154 db_trap(
155 int type,
156 int code)
157 {
158 db_task_trap(type, code, !DB_VALID_KERN_ADDR(PC_REGS(DDB_REGS)));
159 }
Cache object: 56c30987a4587645c28f8fa4606f0be3
|