xref: /freebsd/sys/ddb/db_run.c (revision b792434150d66b9b2356fb9a7548f4c7f0a0f16c)
1dd3cb568SWarner Losh /*-
2796df753SPedro F. Giffuni  * SPDX-License-Identifier: MIT-CMU
3796df753SPedro F. Giffuni  *
45b81b6b3SRodney W. Grimes  * Mach Operating System
55b81b6b3SRodney W. Grimes  * Copyright (c) 1991,1990 Carnegie Mellon University
65b81b6b3SRodney W. Grimes  * All Rights Reserved.
75b81b6b3SRodney W. Grimes  *
85b81b6b3SRodney W. Grimes  * Permission to use, copy, modify and distribute this software and its
95b81b6b3SRodney W. Grimes  * documentation is hereby granted, provided that both the copyright
105b81b6b3SRodney W. Grimes  * notice and this permission notice appear in all copies of the
115b81b6b3SRodney W. Grimes  * software, derivative works or modified versions, and any portions
125b81b6b3SRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
135b81b6b3SRodney W. Grimes  *
145b81b6b3SRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
155b81b6b3SRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
165b81b6b3SRodney W. Grimes  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
175b81b6b3SRodney W. Grimes  *
185b81b6b3SRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
195b81b6b3SRodney W. Grimes  *
205b81b6b3SRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
215b81b6b3SRodney W. Grimes  *  School of Computer Science
225b81b6b3SRodney W. Grimes  *  Carnegie Mellon University
235b81b6b3SRodney W. Grimes  *  Pittsburgh PA 15213-3890
245b81b6b3SRodney W. Grimes  *
255b81b6b3SRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
265b81b6b3SRodney W. Grimes  * rights to redistribute these changes.
275b81b6b3SRodney W. Grimes  */
285b81b6b3SRodney W. Grimes /*
295b81b6b3SRodney W. Grimes  * 	Author: David B. Golub, Carnegie Mellon University
305b81b6b3SRodney W. Grimes  *	Date:	7/90
315b81b6b3SRodney W. Grimes  */
325b81b6b3SRodney W. Grimes 
335b81b6b3SRodney W. Grimes /*
345b81b6b3SRodney W. Grimes  * Commands to run process.
355b81b6b3SRodney W. Grimes  */
36753960f7SDavid E. O'Brien 
37753960f7SDavid E. O'Brien #include <sys/cdefs.h>
38753960f7SDavid E. O'Brien __FBSDID("$FreeBSD$");
39753960f7SDavid E. O'Brien 
40f540b106SGarrett Wollman #include <sys/param.h>
4137224cd3SMarcel Moolenaar #include <sys/kdb.h>
4220984f2fSPeter Wemm #include <sys/proc.h>
43*b7924341SAndrew Turner #include <sys/reg.h>
443f289c3fSJeff Roberson #include <sys/systm.h>
4537224cd3SMarcel Moolenaar 
4637224cd3SMarcel Moolenaar #include <machine/kdb.h>
4737224cd3SMarcel Moolenaar #include <machine/pcb.h>
485b81b6b3SRodney W. Grimes 
495ccbc3ccSBruce Evans #include <vm/vm.h>
505ccbc3ccSBruce Evans 
515ccbc3ccSBruce Evans #include <ddb/ddb.h>
525b81b6b3SRodney W. Grimes #include <ddb/db_access.h>
533c40d3fcSConrad Meyer #include <ddb/db_break.h>
543c40d3fcSConrad Meyer #include <ddb/db_command.h>
555b81b6b3SRodney W. Grimes 
565b81b6b3SRodney W. Grimes #define	STEP_ONCE	1
575b81b6b3SRodney W. Grimes #define	STEP_RETURN	2
585b81b6b3SRodney W. Grimes #define	STEP_CALLT	3
595b81b6b3SRodney W. Grimes #define	STEP_CONTINUE	4
605b81b6b3SRodney W. Grimes #define	STEP_INVISIBLE	5
615b81b6b3SRodney W. Grimes #define	STEP_COUNT	6
621e24fd3bSBruce Evans static int	db_run_mode = STEP_CONTINUE;
635b81b6b3SRodney W. Grimes 
64bd20334cSBruce Evans static bool		db_sstep_multiple;
65cd508278SPedro F. Giffuni static bool		db_sstep_print;
6625eb640dSPoul-Henning Kamp static int		db_loop_count;
6725eb640dSPoul-Henning Kamp static int		db_call_depth;
685b81b6b3SRodney W. Grimes 
695b81b6b3SRodney W. Grimes int		db_inst_count;
705b81b6b3SRodney W. Grimes int		db_load_count;
715b81b6b3SRodney W. Grimes int		db_store_count;
725b81b6b3SRodney W. Grimes 
73cdf23c19SZbigniew Bodek #ifdef SOFTWARE_SSTEP
74cdf23c19SZbigniew Bodek db_breakpoint_t	db_not_taken_bkpt = 0;
75cdf23c19SZbigniew Bodek db_breakpoint_t	db_taken_bkpt = 0;
76cdf23c19SZbigniew Bodek #endif
77cdf23c19SZbigniew Bodek 
785b81b6b3SRodney W. Grimes #ifndef db_set_single_step
7937224cd3SMarcel Moolenaar void db_set_single_step(void);
805b81b6b3SRodney W. Grimes #endif
815b81b6b3SRodney W. Grimes #ifndef db_clear_single_step
8237224cd3SMarcel Moolenaar void db_clear_single_step(void);
83f73a856dSPoul-Henning Kamp #endif
84cdf23c19SZbigniew Bodek #ifndef db_pc_is_singlestep
85cdf23c19SZbigniew Bodek static bool
86cdf23c19SZbigniew Bodek db_pc_is_singlestep(db_addr_t pc)
87cdf23c19SZbigniew Bodek {
8875f88c7cSOlivier Houchard #ifdef SOFTWARE_SSTEP
89cdf23c19SZbigniew Bodek 	if ((db_not_taken_bkpt != 0 && pc == db_not_taken_bkpt->address)
90cdf23c19SZbigniew Bodek 	    || (db_taken_bkpt != 0 && pc == db_taken_bkpt->address))
91cdf23c19SZbigniew Bodek 		return (true);
92cdf23c19SZbigniew Bodek #endif
93cdf23c19SZbigniew Bodek 	return (false);
94cdf23c19SZbigniew Bodek }
9575f88c7cSOlivier Houchard #endif
9675f88c7cSOlivier Houchard 
97cd508278SPedro F. Giffuni bool
985c48342fSBruce Evans db_stop_at_pc(int type, int code, bool *is_breakpoint, bool *is_watchpoint)
995b81b6b3SRodney W. Grimes {
1000a95ab74SPedro F. Giffuni 	db_addr_t	pc;
1010a95ab74SPedro F. Giffuni 	db_breakpoint_t bkpt;
1025b81b6b3SRodney W. Grimes 
1035c48342fSBruce Evans 	*is_breakpoint = IS_BREAKPOINT_TRAP(type, code);
1045c48342fSBruce Evans 	*is_watchpoint = IS_WATCHPOINT_TRAP(type, code);
10575f88c7cSOlivier Houchard 	pc = PC_REGS();
106cdf23c19SZbigniew Bodek 	if (db_pc_is_singlestep(pc))
1072b490bc7SPedro F. Giffuni 		*is_breakpoint = false;
10875f88c7cSOlivier Houchard 
10937224cd3SMarcel Moolenaar 	db_clear_single_step();
1105b81b6b3SRodney W. Grimes 	db_clear_breakpoints();
1115b81b6b3SRodney W. Grimes 	db_clear_watchpoints();
1125b81b6b3SRodney W. Grimes 
1135b81b6b3SRodney W. Grimes #ifdef	FIXUP_PC_AFTER_BREAK
1145b81b6b3SRodney W. Grimes 	if (*is_breakpoint) {
1155b81b6b3SRodney W. Grimes 	    /*
1165b81b6b3SRodney W. Grimes 	     * Breakpoint trap.  Fix up the PC if the
1175b81b6b3SRodney W. Grimes 	     * machine requires it.
1185b81b6b3SRodney W. Grimes 	     */
1195b81b6b3SRodney W. Grimes 	    FIXUP_PC_AFTER_BREAK
12037224cd3SMarcel Moolenaar 	    pc = PC_REGS();
1215b81b6b3SRodney W. Grimes 	}
1225b81b6b3SRodney W. Grimes #endif
1235b81b6b3SRodney W. Grimes 
1245b81b6b3SRodney W. Grimes 	/*
1255b81b6b3SRodney W. Grimes 	 * Now check for a breakpoint at this address.
1265b81b6b3SRodney W. Grimes 	 */
1275b81b6b3SRodney W. Grimes 	bkpt = db_find_breakpoint_here(pc);
1285b81b6b3SRodney W. Grimes 	if (bkpt) {
1295b81b6b3SRodney W. Grimes 	    if (--bkpt->count == 0) {
1305b81b6b3SRodney W. Grimes 		bkpt->count = bkpt->init_count;
1312b490bc7SPedro F. Giffuni 		*is_breakpoint = true;
1322b490bc7SPedro F. Giffuni 		return (true);	/* stop here */
1335b81b6b3SRodney W. Grimes 	    }
13410c458ccSBruce Evans 	    return (false);	/* continue the countdown */
1355b81b6b3SRodney W. Grimes 	} else if (*is_breakpoint) {
1363a0b4f25SDoug Rabson #ifdef BKPT_SKIP
1373a0b4f25SDoug Rabson 		BKPT_SKIP;
138ecbb00a2SDoug Rabson #endif
1395b81b6b3SRodney W. Grimes 	}
1405b81b6b3SRodney W. Grimes 
141bd20334cSBruce Evans 	*is_breakpoint = false;	/* might be a breakpoint, but not ours */
142bd20334cSBruce Evans 
143bd20334cSBruce Evans 	/*
144e1e554a3SBruce Evans 	 * If not stepping, then silently ignore single-step traps
145e1e554a3SBruce Evans 	 * (except for clearing the single-step-flag above).
146e1e554a3SBruce Evans 	 *
147bd20334cSBruce Evans 	 * If stepping, then abort if the trap type is unexpected.
148bd20334cSBruce Evans 	 * Breakpoints owned by us are expected and were handled above.
149bd20334cSBruce Evans 	 * Single-steps are expected and are handled below.  All others
150bd20334cSBruce Evans 	 * are unexpected.
151bd20334cSBruce Evans 	 *
152e1e554a3SBruce Evans 	 * Only do either of these if the MD layer claims to classify
153e1e554a3SBruce Evans 	 * single-step traps unambiguously (by defining IS_SSTEP_TRAP).
154e1e554a3SBruce Evans 	 * Otherwise, fall through to the bad historical behaviour
155e1e554a3SBruce Evans 	 * given by turning unexpected traps into expected traps: if not
156e1e554a3SBruce Evans 	 * stepping, then expect only breakpoints and stop, and if
157e1e554a3SBruce Evans 	 * stepping, then expect only single-steps and step.
158bd20334cSBruce Evans 	 */
159e1e554a3SBruce Evans #ifdef IS_SSTEP_TRAP
160e1e554a3SBruce Evans 	if (db_run_mode == STEP_CONTINUE && IS_SSTEP_TRAP(type, code))
161e1e554a3SBruce Evans 	    return (false);
162bd20334cSBruce Evans 	if (db_run_mode != STEP_CONTINUE && !IS_SSTEP_TRAP(type, code)) {
163bd20334cSBruce Evans 	    printf("Stepping aborted\n");
164bd20334cSBruce Evans 	    return (true);
165bd20334cSBruce Evans 	}
166e1e554a3SBruce Evans #endif
1675b81b6b3SRodney W. Grimes 
1685b81b6b3SRodney W. Grimes 	if (db_run_mode == STEP_INVISIBLE) {
1695b81b6b3SRodney W. Grimes 	    db_run_mode = STEP_CONTINUE;
1702b490bc7SPedro F. Giffuni 	    return (false);	/* continue */
1715b81b6b3SRodney W. Grimes 	}
1725b81b6b3SRodney W. Grimes 	if (db_run_mode == STEP_COUNT) {
1732b490bc7SPedro F. Giffuni 	    return (false); /* continue */
1745b81b6b3SRodney W. Grimes 	}
1755b81b6b3SRodney W. Grimes 	if (db_run_mode == STEP_ONCE) {
1765b81b6b3SRodney W. Grimes 	    if (--db_loop_count > 0) {
1775b81b6b3SRodney W. Grimes 		if (db_sstep_print) {
1785b81b6b3SRodney W. Grimes 		    db_printf("\t\t");
1795b81b6b3SRodney W. Grimes 		    db_print_loc_and_inst(pc);
1805b81b6b3SRodney W. Grimes 		}
1812b490bc7SPedro F. Giffuni 		return (false);	/* continue */
1825b81b6b3SRodney W. Grimes 	    }
1835b81b6b3SRodney W. Grimes 	}
1845b81b6b3SRodney W. Grimes 	if (db_run_mode == STEP_RETURN) {
1855b81b6b3SRodney W. Grimes 	    /* continue until matching return */
18653b3e912SMaxime Henrion 	    db_expr_t ins;
1875b81b6b3SRodney W. Grimes 
1882b490bc7SPedro F. Giffuni 	    ins = db_get_value(pc, sizeof(int), false);
1895b81b6b3SRodney W. Grimes 	    if (!inst_trap_return(ins) &&
1905b81b6b3SRodney W. Grimes 		(!inst_return(ins) || --db_call_depth != 0)) {
1915b81b6b3SRodney W. Grimes 		if (db_sstep_print) {
1925b81b6b3SRodney W. Grimes 		    if (inst_call(ins) || inst_return(ins)) {
1930a95ab74SPedro F. Giffuni 			int i;
1945b81b6b3SRodney W. Grimes 
1955b81b6b3SRodney W. Grimes 			db_printf("[after %6d]     ", db_inst_count);
1965b81b6b3SRodney W. Grimes 			for (i = db_call_depth; --i > 0; )
1975b81b6b3SRodney W. Grimes 			    db_printf("  ");
1985b81b6b3SRodney W. Grimes 			db_print_loc_and_inst(pc);
1995b81b6b3SRodney W. Grimes 		    }
2005b81b6b3SRodney W. Grimes 		}
2015b81b6b3SRodney W. Grimes 		if (inst_call(ins))
2025b81b6b3SRodney W. Grimes 		    db_call_depth++;
2032b490bc7SPedro F. Giffuni 		return (false);	/* continue */
2045b81b6b3SRodney W. Grimes 	    }
2055b81b6b3SRodney W. Grimes 	}
2065b81b6b3SRodney W. Grimes 	if (db_run_mode == STEP_CALLT) {
2075b81b6b3SRodney W. Grimes 	    /* continue until call or return */
20853b3e912SMaxime Henrion 	    db_expr_t ins;
2095b81b6b3SRodney W. Grimes 
2102b490bc7SPedro F. Giffuni 	    ins = db_get_value(pc, sizeof(int), false);
2115b81b6b3SRodney W. Grimes 	    if (!inst_call(ins) &&
2125b81b6b3SRodney W. Grimes 		!inst_return(ins) &&
2135b81b6b3SRodney W. Grimes 		!inst_trap_return(ins)) {
2142b490bc7SPedro F. Giffuni 		return (false);	/* continue */
2155b81b6b3SRodney W. Grimes 	    }
2165b81b6b3SRodney W. Grimes 	}
2172b490bc7SPedro F. Giffuni 	return (true);
2185b81b6b3SRodney W. Grimes }
2195b81b6b3SRodney W. Grimes 
2205b81b6b3SRodney W. Grimes void
221cd508278SPedro F. Giffuni db_restart_at_pc(bool watchpt)
2225b81b6b3SRodney W. Grimes {
2230a95ab74SPedro F. Giffuni 	db_addr_t	pc = PC_REGS();
2245b81b6b3SRodney W. Grimes 
2255b81b6b3SRodney W. Grimes 	if ((db_run_mode == STEP_COUNT) ||
226bd20334cSBruce Evans 	    ((db_run_mode == STEP_ONCE) && db_sstep_multiple) ||
2275b81b6b3SRodney W. Grimes 	    (db_run_mode == STEP_RETURN) ||
2285b81b6b3SRodney W. Grimes 	    (db_run_mode == STEP_CALLT)) {
2295b81b6b3SRodney W. Grimes 	    /*
2305b81b6b3SRodney W. Grimes 	     * We are about to execute this instruction,
2315b81b6b3SRodney W. Grimes 	     * so count it now.
2325b81b6b3SRodney W. Grimes 	     */
233c6cb86ccSWarner Losh #ifdef	SOFTWARE_SSTEP
234c6cb86ccSWarner Losh 	    db_expr_t		ins =
235c6cb86ccSWarner Losh #endif
2362b490bc7SPedro F. Giffuni 	    db_get_value(pc, sizeof(int), false);
2375b81b6b3SRodney W. Grimes 	    db_inst_count++;
2385b81b6b3SRodney W. Grimes 	    db_load_count += inst_load(ins);
2395b81b6b3SRodney W. Grimes 	    db_store_count += inst_store(ins);
2405b81b6b3SRodney W. Grimes #ifdef	SOFTWARE_SSTEP
2415b81b6b3SRodney W. Grimes 	    /* XXX works on mips, but... */
2425b81b6b3SRodney W. Grimes 	    if (inst_branch(ins) || inst_call(ins)) {
2435b81b6b3SRodney W. Grimes 		ins = db_get_value(next_instr_address(pc,1),
2442b490bc7SPedro F. Giffuni 				   sizeof(int), false);
2455b81b6b3SRodney W. Grimes 		db_inst_count++;
2465b81b6b3SRodney W. Grimes 		db_load_count += inst_load(ins);
2475b81b6b3SRodney W. Grimes 		db_store_count += inst_store(ins);
2485b81b6b3SRodney W. Grimes 	    }
24968016904SDavid E. O'Brien #endif	/* SOFTWARE_SSTEP */
2505b81b6b3SRodney W. Grimes 	}
2515b81b6b3SRodney W. Grimes 
2525b81b6b3SRodney W. Grimes 	if (db_run_mode == STEP_CONTINUE) {
2535b81b6b3SRodney W. Grimes 	    if (watchpt || db_find_breakpoint_here(pc)) {
2545b81b6b3SRodney W. Grimes 		/*
2555b81b6b3SRodney W. Grimes 		 * Step over breakpoint/watchpoint.
2565b81b6b3SRodney W. Grimes 		 */
2575b81b6b3SRodney W. Grimes 		db_run_mode = STEP_INVISIBLE;
25837224cd3SMarcel Moolenaar 		db_set_single_step();
2595b81b6b3SRodney W. Grimes 	    } else {
2605b81b6b3SRodney W. Grimes 		db_set_breakpoints();
2615b81b6b3SRodney W. Grimes 		db_set_watchpoints();
2625b81b6b3SRodney W. Grimes 	    }
2635b81b6b3SRodney W. Grimes 	} else {
26437224cd3SMarcel Moolenaar 	    db_set_single_step();
2655b81b6b3SRodney W. Grimes 	}
2665b81b6b3SRodney W. Grimes }
2675b81b6b3SRodney W. Grimes 
2685b81b6b3SRodney W. Grimes #ifdef	SOFTWARE_SSTEP
2695b81b6b3SRodney W. Grimes /*
2705b81b6b3SRodney W. Grimes  *	Software implementation of single-stepping.
2715b81b6b3SRodney W. Grimes  *	If your machine does not have a trace mode
2725b81b6b3SRodney W. Grimes  *	similar to the vax or sun ones you can use
2735b81b6b3SRodney W. Grimes  *	this implementation, done for the mips.
2745b81b6b3SRodney W. Grimes  *	Just define the above conditional and provide
2755b81b6b3SRodney W. Grimes  *	the functions/macros defined below.
2765b81b6b3SRodney W. Grimes  *
277cd508278SPedro F. Giffuni  * extern bool
2785b81b6b3SRodney W. Grimes  *	inst_branch(),		returns true if the instruction might branch
2795b81b6b3SRodney W. Grimes  * extern unsigned
2805b81b6b3SRodney W. Grimes  *	branch_taken(),		return the address the instruction might
2815b81b6b3SRodney W. Grimes  *				branch to
2825b81b6b3SRodney W. Grimes  *	db_getreg_val();	return the value of a user register,
2835b81b6b3SRodney W. Grimes  *				as indicated in the hardware instruction
2845b81b6b3SRodney W. Grimes  *				encoding, e.g. 8 for r8
2855b81b6b3SRodney W. Grimes  *
2865b81b6b3SRodney W. Grimes  * next_instr_address(pc,bd)	returns the address of the first
2875b81b6b3SRodney W. Grimes  *				instruction following the one at "pc",
2885b81b6b3SRodney W. Grimes  *				which is either in the taken path of
2895b81b6b3SRodney W. Grimes  *				the branch (bd==1) or not.  This is
2905b81b6b3SRodney W. Grimes  *				for machines (mips) with branch delays.
2915b81b6b3SRodney W. Grimes  *
2925b81b6b3SRodney W. Grimes  *	A single-step may involve at most 2 breakpoints -
2935b81b6b3SRodney W. Grimes  *	one for branch-not-taken and one for branch taken.
2945b81b6b3SRodney W. Grimes  *	If one of these addresses does not already have a breakpoint,
2955b81b6b3SRodney W. Grimes  *	we allocate a breakpoint and save it here.
2965b81b6b3SRodney W. Grimes  *	These breakpoints are deleted on return.
2975b81b6b3SRodney W. Grimes  */
2985b81b6b3SRodney W. Grimes 
2995b81b6b3SRodney W. Grimes void
30037224cd3SMarcel Moolenaar db_set_single_step(void)
3015b81b6b3SRodney W. Grimes {
30237224cd3SMarcel Moolenaar 	db_addr_t pc = PC_REGS(), brpc;
3037045d394SDoug Rabson 	unsigned inst;
3045b81b6b3SRodney W. Grimes 
3055b81b6b3SRodney W. Grimes 	/*
3065b81b6b3SRodney W. Grimes 	 *	User was stopped at pc, e.g. the instruction
3075b81b6b3SRodney W. Grimes 	 *	at pc was not executed.
3085b81b6b3SRodney W. Grimes 	 */
3092b490bc7SPedro F. Giffuni 	inst = db_get_value(pc, sizeof(int), false);
31008cfba5dSOlivier Houchard 	if (inst_branch(inst) || inst_call(inst) || inst_return(inst)) {
31137224cd3SMarcel Moolenaar 		brpc = branch_taken(inst, pc);
3125b81b6b3SRodney W. Grimes 		if (brpc != pc) {	/* self-branches are hopeless */
3135b81b6b3SRodney W. Grimes 			db_taken_bkpt = db_set_temp_breakpoint(brpc);
3145b81b6b3SRodney W. Grimes 		}
3155b81b6b3SRodney W. Grimes 		pc = next_instr_address(pc, 1);
3165b81b6b3SRodney W. Grimes 	}
3175b81b6b3SRodney W. Grimes 	pc = next_instr_address(pc, 0);
3185b81b6b3SRodney W. Grimes 	db_not_taken_bkpt = db_set_temp_breakpoint(pc);
3195b81b6b3SRodney W. Grimes }
3205b81b6b3SRodney W. Grimes 
3215b81b6b3SRodney W. Grimes void
32237224cd3SMarcel Moolenaar db_clear_single_step(void)
3235b81b6b3SRodney W. Grimes {
3245b81b6b3SRodney W. Grimes 
3255b81b6b3SRodney W. Grimes 	if (db_not_taken_bkpt != 0) {
3265b81b6b3SRodney W. Grimes 		db_delete_temp_breakpoint(db_not_taken_bkpt);
3275b81b6b3SRodney W. Grimes 		db_not_taken_bkpt = 0;
3285b81b6b3SRodney W. Grimes 	}
32946e5fdffSDoug Rabson 	if (db_taken_bkpt != 0) {
33046e5fdffSDoug Rabson 		db_delete_temp_breakpoint(db_taken_bkpt);
33146e5fdffSDoug Rabson 		db_taken_bkpt = 0;
33246e5fdffSDoug Rabson 	}
3335b81b6b3SRodney W. Grimes }
3345b81b6b3SRodney W. Grimes 
33568016904SDavid E. O'Brien #endif	/* SOFTWARE_SSTEP */
3365b81b6b3SRodney W. Grimes 
3375b81b6b3SRodney W. Grimes /* single-step */
3385b81b6b3SRodney W. Grimes /*ARGSUSED*/
3395b81b6b3SRodney W. Grimes void
340cd508278SPedro F. Giffuni db_single_step_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
3415b81b6b3SRodney W. Grimes {
342cd508278SPedro F. Giffuni 	bool		print = false;
3435b81b6b3SRodney W. Grimes 
3445b81b6b3SRodney W. Grimes 	if (count == -1)
3455b81b6b3SRodney W. Grimes 	    count = 1;
3465b81b6b3SRodney W. Grimes 
3475b81b6b3SRodney W. Grimes 	if (modif[0] == 'p')
3482b490bc7SPedro F. Giffuni 	    print = true;
3495b81b6b3SRodney W. Grimes 
3505b81b6b3SRodney W. Grimes 	db_run_mode = STEP_ONCE;
3515b81b6b3SRodney W. Grimes 	db_loop_count = count;
352bd20334cSBruce Evans 	db_sstep_multiple = (count != 1);
3535b81b6b3SRodney W. Grimes 	db_sstep_print = print;
3545b81b6b3SRodney W. Grimes 	db_inst_count = 0;
3555b81b6b3SRodney W. Grimes 	db_load_count = 0;
3565b81b6b3SRodney W. Grimes 	db_store_count = 0;
3575b81b6b3SRodney W. Grimes 
3585b81b6b3SRodney W. Grimes 	db_cmd_loop_done = 1;
3595b81b6b3SRodney W. Grimes }
3605b81b6b3SRodney W. Grimes 
3615b81b6b3SRodney W. Grimes /* trace and print until call/return */
3625b81b6b3SRodney W. Grimes /*ARGSUSED*/
3635b81b6b3SRodney W. Grimes void
364cd508278SPedro F. Giffuni db_trace_until_call_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
365a41dd031SPedro F. Giffuni     char *modif)
3665b81b6b3SRodney W. Grimes {
367cd508278SPedro F. Giffuni 	bool	print = false;
3685b81b6b3SRodney W. Grimes 
3695b81b6b3SRodney W. Grimes 	if (modif[0] == 'p')
3702b490bc7SPedro F. Giffuni 	    print = true;
3715b81b6b3SRodney W. Grimes 
3725b81b6b3SRodney W. Grimes 	db_run_mode = STEP_CALLT;
3735b81b6b3SRodney W. Grimes 	db_sstep_print = print;
3745b81b6b3SRodney W. Grimes 	db_inst_count = 0;
3755b81b6b3SRodney W. Grimes 	db_load_count = 0;
3765b81b6b3SRodney W. Grimes 	db_store_count = 0;
3775b81b6b3SRodney W. Grimes 
3785b81b6b3SRodney W. Grimes 	db_cmd_loop_done = 1;
3795b81b6b3SRodney W. Grimes }
3805b81b6b3SRodney W. Grimes 
3815b81b6b3SRodney W. Grimes /*ARGSUSED*/
3825b81b6b3SRodney W. Grimes void
383cd508278SPedro F. Giffuni db_trace_until_matching_cmd(db_expr_t addr, bool have_addr, db_expr_t count,
384cd508278SPedro F. Giffuni     char *modif)
3855b81b6b3SRodney W. Grimes {
386cd508278SPedro F. Giffuni 	bool	print = false;
3875b81b6b3SRodney W. Grimes 
3885b81b6b3SRodney W. Grimes 	if (modif[0] == 'p')
3892b490bc7SPedro F. Giffuni 	    print = true;
3905b81b6b3SRodney W. Grimes 
3915b81b6b3SRodney W. Grimes 	db_run_mode = STEP_RETURN;
3925b81b6b3SRodney W. Grimes 	db_call_depth = 1;
3935b81b6b3SRodney W. Grimes 	db_sstep_print = print;
3945b81b6b3SRodney W. Grimes 	db_inst_count = 0;
3955b81b6b3SRodney W. Grimes 	db_load_count = 0;
3965b81b6b3SRodney W. Grimes 	db_store_count = 0;
3975b81b6b3SRodney W. Grimes 
3985b81b6b3SRodney W. Grimes 	db_cmd_loop_done = 1;
3995b81b6b3SRodney W. Grimes }
4005b81b6b3SRodney W. Grimes 
4015b81b6b3SRodney W. Grimes /* continue */
4025b81b6b3SRodney W. Grimes /*ARGSUSED*/
4035b81b6b3SRodney W. Grimes void
404cd508278SPedro F. Giffuni db_continue_cmd(db_expr_t addr, bool have_addr, db_expr_t count, char *modif)
4055b81b6b3SRodney W. Grimes {
4065b81b6b3SRodney W. Grimes 	if (modif[0] == 'c')
4075b81b6b3SRodney W. Grimes 	    db_run_mode = STEP_COUNT;
4085b81b6b3SRodney W. Grimes 	else
4095b81b6b3SRodney W. Grimes 	    db_run_mode = STEP_CONTINUE;
4105b81b6b3SRodney W. Grimes 	db_inst_count = 0;
4115b81b6b3SRodney W. Grimes 	db_load_count = 0;
4125b81b6b3SRodney W. Grimes 	db_store_count = 0;
4135b81b6b3SRodney W. Grimes 
4145b81b6b3SRodney W. Grimes 	db_cmd_loop_done = 1;
4155b81b6b3SRodney W. Grimes }
416