2 * SPDX-License-Identifier: MIT-CMU
4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
29 * Author: David B. Golub, Carnegie Mellon University
34 * Commands to run process.
37 #include <sys/cdefs.h>
38 #include <sys/param.h>
42 #include <sys/systm.h>
44 #include <machine/kdb.h>
45 #include <machine/pcb.h>
50 #include <ddb/db_access.h>
51 #include <ddb/db_break.h>
52 #include <ddb/db_command.h>
57 #define STEP_CONTINUE 4
58 #define STEP_INVISIBLE 5
60 static int db_run_mode = STEP_CONTINUE;
62 static bool db_sstep_multiple;
63 static bool db_sstep_print;
64 static int db_loop_count;
65 static int db_call_depth;
72 db_stop_at_pc(int type, int code, bool *is_breakpoint, bool *is_watchpoint)
77 *is_breakpoint = IS_BREAKPOINT_TRAP(type, code);
78 *is_watchpoint = IS_WATCHPOINT_TRAP(type, code);
81 db_clear_single_step();
82 db_clear_breakpoints();
83 db_clear_watchpoints();
85 #ifdef FIXUP_PC_AFTER_BREAK
88 * Breakpoint trap. Fix up the PC if the
89 * machine requires it.
97 * Now check for a breakpoint at this address.
99 bkpt = db_find_breakpoint_here(pc);
101 if (--bkpt->count == 0) {
102 bkpt->count = bkpt->init_count;
103 *is_breakpoint = true;
104 return (true); /* stop here */
106 return (false); /* continue the countdown */
107 } else if (*is_breakpoint) {
113 *is_breakpoint = false; /* might be a breakpoint, but not ours */
116 * If not stepping, then silently ignore single-step traps
117 * (except for clearing the single-step-flag above).
119 * If stepping, then abort if the trap type is unexpected.
120 * Breakpoints owned by us are expected and were handled above.
121 * Single-steps are expected and are handled below. All others
124 * Only do either of these if the MD layer claims to classify
125 * single-step traps unambiguously (by defining IS_SSTEP_TRAP).
126 * Otherwise, fall through to the bad historical behaviour
127 * given by turning unexpected traps into expected traps: if not
128 * stepping, then expect only breakpoints and stop, and if
129 * stepping, then expect only single-steps and step.
132 if (db_run_mode == STEP_CONTINUE && IS_SSTEP_TRAP(type, code))
134 if (db_run_mode != STEP_CONTINUE && !IS_SSTEP_TRAP(type, code)) {
135 printf("Stepping aborted\n");
140 if (db_run_mode == STEP_INVISIBLE) {
141 db_run_mode = STEP_CONTINUE;
142 return (false); /* continue */
144 if (db_run_mode == STEP_COUNT) {
145 return (false); /* continue */
147 if (db_run_mode == STEP_ONCE) {
148 if (--db_loop_count > 0) {
149 if (db_sstep_print) {
151 db_print_loc_and_inst(pc);
153 return (false); /* continue */
156 if (db_run_mode == STEP_RETURN) {
157 /* continue until matching return */
160 ins = db_get_value(pc, sizeof(int), false);
161 if (!inst_trap_return(ins) &&
162 (!inst_return(ins) || --db_call_depth != 0)) {
163 if (db_sstep_print) {
164 if (inst_call(ins) || inst_return(ins)) {
167 db_printf("[after %6d] ", db_inst_count);
168 for (i = db_call_depth; --i > 0; )
170 db_print_loc_and_inst(pc);
175 return (false); /* continue */
178 if (db_run_mode == STEP_CALLT) {
179 /* continue until call or return */
182 ins = db_get_value(pc, sizeof(int), false);
183 if (!inst_call(ins) &&
185 !inst_trap_return(ins)) {
186 return (false); /* continue */
193 db_restart_at_pc(bool watchpt)
195 db_addr_t pc = PC_REGS();
197 if ((db_run_mode == STEP_COUNT) ||
198 ((db_run_mode == STEP_ONCE) && db_sstep_multiple) ||
199 (db_run_mode == STEP_RETURN) ||
200 (db_run_mode == STEP_CALLT)) {
202 * We are about to execute this instruction,
205 db_get_value(pc, sizeof(int), false);
207 db_load_count += inst_load(ins);
208 db_store_count += inst_store(ins);
211 if (db_run_mode == STEP_CONTINUE) {
212 if (watchpt || db_find_breakpoint_here(pc)) {
214 * Step over breakpoint/watchpoint.
216 db_run_mode = STEP_INVISIBLE;
217 db_set_single_step();
219 db_set_breakpoints();
220 db_set_watchpoints();
223 db_set_single_step();
230 db_single_step_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
240 db_run_mode = STEP_ONCE;
241 db_loop_count = count;
242 db_sstep_multiple = (count != 1);
243 db_sstep_print = print;
248 db_cmd_loop_done = 1;
251 /* trace and print until call/return */
254 db_trace_until_call_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
262 db_run_mode = STEP_CALLT;
263 db_sstep_print = print;
268 db_cmd_loop_done = 1;
273 db_trace_until_matching_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
281 db_run_mode = STEP_RETURN;
283 db_sstep_print = print;
288 db_cmd_loop_done = 1;
294 db_continue_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
297 db_run_mode = STEP_COUNT;
299 db_run_mode = STEP_CONTINUE;
304 db_cmd_loop_done = 1;