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/param.h>
41 #include <sys/systm.h>
43 #include <machine/kdb.h>
44 #include <machine/pcb.h>
49 #include <ddb/db_access.h>
50 #include <ddb/db_break.h>
51 #include <ddb/db_command.h>
56 #define STEP_CONTINUE 4
57 #define STEP_INVISIBLE 5
59 static int db_run_mode = STEP_CONTINUE;
61 static bool db_sstep_multiple;
62 static bool db_sstep_print;
63 static int db_loop_count;
64 static int db_call_depth;
71 db_stop_at_pc(int type, int code, bool *is_breakpoint, bool *is_watchpoint)
76 *is_breakpoint = IS_BREAKPOINT_TRAP(type, code);
77 *is_watchpoint = IS_WATCHPOINT_TRAP(type, code);
80 db_clear_single_step();
81 db_clear_breakpoints();
82 db_clear_watchpoints();
84 #ifdef FIXUP_PC_AFTER_BREAK
87 * Breakpoint trap. Fix up the PC if the
88 * machine requires it.
96 * Now check for a breakpoint at this address.
98 bkpt = db_find_breakpoint_here(pc);
100 if (--bkpt->count == 0) {
101 bkpt->count = bkpt->init_count;
102 *is_breakpoint = true;
103 return (true); /* stop here */
105 return (false); /* continue the countdown */
106 } else if (*is_breakpoint) {
112 *is_breakpoint = false; /* might be a breakpoint, but not ours */
115 * If not stepping, then silently ignore single-step traps
116 * (except for clearing the single-step-flag above).
118 * If stepping, then abort if the trap type is unexpected.
119 * Breakpoints owned by us are expected and were handled above.
120 * Single-steps are expected and are handled below. All others
123 * Only do either of these if the MD layer claims to classify
124 * single-step traps unambiguously (by defining IS_SSTEP_TRAP).
125 * Otherwise, fall through to the bad historical behaviour
126 * given by turning unexpected traps into expected traps: if not
127 * stepping, then expect only breakpoints and stop, and if
128 * stepping, then expect only single-steps and step.
131 if (db_run_mode == STEP_CONTINUE && IS_SSTEP_TRAP(type, code))
133 if (db_run_mode != STEP_CONTINUE && !IS_SSTEP_TRAP(type, code)) {
134 printf("Stepping aborted\n");
139 if (db_run_mode == STEP_INVISIBLE) {
140 db_run_mode = STEP_CONTINUE;
141 return (false); /* continue */
143 if (db_run_mode == STEP_COUNT) {
144 return (false); /* continue */
146 if (db_run_mode == STEP_ONCE) {
147 if (--db_loop_count > 0) {
148 if (db_sstep_print) {
150 db_print_loc_and_inst(pc);
152 return (false); /* continue */
155 if (db_run_mode == STEP_RETURN) {
156 /* continue until matching return */
159 ins = db_get_value(pc, sizeof(int), false);
160 if (!inst_trap_return(ins) &&
161 (!inst_return(ins) || --db_call_depth != 0)) {
162 if (db_sstep_print) {
163 if (inst_call(ins) || inst_return(ins)) {
166 db_printf("[after %6d] ", db_inst_count);
167 for (i = db_call_depth; --i > 0; )
169 db_print_loc_and_inst(pc);
174 return (false); /* continue */
177 if (db_run_mode == STEP_CALLT) {
178 /* continue until call or return */
181 ins = db_get_value(pc, sizeof(int), false);
182 if (!inst_call(ins) &&
184 !inst_trap_return(ins)) {
185 return (false); /* continue */
192 db_restart_at_pc(bool watchpt)
194 db_addr_t pc = PC_REGS();
196 if ((db_run_mode == STEP_COUNT) ||
197 ((db_run_mode == STEP_ONCE) && db_sstep_multiple) ||
198 (db_run_mode == STEP_RETURN) ||
199 (db_run_mode == STEP_CALLT)) {
201 * We are about to execute this instruction,
204 db_get_value(pc, sizeof(int), false);
206 db_load_count += inst_load(ins);
207 db_store_count += inst_store(ins);
210 if (db_run_mode == STEP_CONTINUE) {
211 if (watchpt || db_find_breakpoint_here(pc)) {
213 * Step over breakpoint/watchpoint.
215 db_run_mode = STEP_INVISIBLE;
216 db_set_single_step();
218 db_set_breakpoints();
219 db_set_watchpoints();
222 db_set_single_step();
229 db_single_step_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
239 db_run_mode = STEP_ONCE;
240 db_loop_count = count;
241 db_sstep_multiple = (count != 1);
242 db_sstep_print = print;
247 db_cmd_loop_done = 1;
250 /* trace and print until call/return */
253 db_trace_until_call_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
261 db_run_mode = STEP_CALLT;
262 db_sstep_print = print;
267 db_cmd_loop_done = 1;
272 db_trace_until_matching_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
280 db_run_mode = STEP_RETURN;
282 db_sstep_print = print;
287 db_cmd_loop_done = 1;
293 db_continue_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
296 db_run_mode = STEP_COUNT;
298 db_run_mode = STEP_CONTINUE;
303 db_cmd_loop_done = 1;