xref: /original-bsd/usr.bin/pascal/pdx/process/step.c (revision 014fe330)
1 /* Copyright (c) 1982 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)step.c 1.2 02/11/82";
4 
5 /*
6  * Continue execution up to the next source line.
7  *
8  * We call "nextaddr" from the machine module to figure out
9  * what the object address is that corresponds to the next source line.
10  * If nextaddr returns -1, then the end of the program has been reached.
11  *
12  * There are two ways to define the next source line depending on what
13  * is desired when a procedure or function call is encountered.  Step
14  * stops at the beginning of the procedure or call; next skips over it.
15  */
16 
17 #include "defs.h"
18 #include "process.h"
19 #include "machine.h"
20 #include "breakpoint.h"
21 #include "source.h"
22 #include "mappings.h"
23 #include "process.rep"
24 
25 #   if (isvax)
26 #       include "machine/vaxops.h"
27 
28 	LOCAL ADDRESS getcall();
29 #   endif
30 
31 /*
32  * Stepc is what is called when the step command is given.
33  * It has to play with the "isstopped" information.
34  */
35 
36 stepc()
37 {
38     if (!isstopped) {
39 	error("can't continue execution");
40     }
41     isstopped = FALSE;
42     dostep(FALSE);
43     isstopped = TRUE;
44 }
45 
46 next()
47 {
48     if (!isstopped) {
49 	error("can't continue execution");
50     }
51     isstopped = FALSE;
52     dostep(TRUE);
53     isstopped = TRUE;
54 }
55 
56 step()
57 {
58     dostep(FALSE);
59 }
60 
61 /*
62  * Resume execution up to the given address.  It is assumed that
63  * no breakpoints exist between the current address and the one
64  * we're stepping to.  This saves us from setting all the breakpoints.
65  */
66 
67 stepto(addr)
68 ADDRESS addr;
69 {
70     setbp(addr);
71     resume();
72     unsetbp(addr);
73     if (!isbperr()) {
74 	printstatus();
75     }
76 }
77 
78 LOCAL dostep(isnext)
79 BOOLEAN isnext;
80 {
81     register ADDRESS addr;
82     register LINENO line;
83     char *filename;
84 
85     addr = pc;
86     do {
87 #       if (isvaxpx)
88 	    addr = nextaddr(addr, isnext);
89 #       else
90 	    if (isnext && (addr = getcall(addr)) != 0) {
91 		stepto(addr);
92 	    } else {
93 		pstep(process);
94 		addr = process->pc;
95 		pc = process->pc;
96 		errnum = process->signo;
97 		if (!isbperr()) {
98 		    printstatus();
99 		}
100 	    }
101 #       endif
102 	line = linelookup(addr);
103     } while (line == 0 && !ss_instructions);
104     stepto(addr);
105     curline = line;
106 }
107 
108 # if (isvax)
109 
110 /*
111  * If the current address contains a call instruction, return the
112  * address of the instruction where control will return.
113  *
114  * This function is intentionally dependent on a particular type
115  * of calling sequence.
116  */
117 
118 LOCAL ADDRESS getcall(addr)
119 ADDRESS addr;
120 {
121     VAXOP op;
122 
123     iread(&op, addr, sizeof(addr));
124     if (op == O_CALLS) {
125 	return(addr + 7);
126     } else {
127 	return(0);
128     }
129 }
130 
131 # endif
132