xref: /csrg-svn/old/adb/common_source/defs.h (revision 37342)
1 /*	@(#)defs.h	5.2 (Berkeley) 04/09/89	*/
2 
3 /*
4  * adb: common definitions
5  */
6 
7 #include <sys/param.h>
8 #include <sys/dir.h>
9 #include <sys/user.h>
10 
11 #include <a.out.h>
12 
13 /* machine dependent types and definitions */
14 #include "machdep.h"
15 
16 /*
17  * Signals.  Adb catches SIGINT and SIGQUIT; the variables sigint and
18  * sigquit hold the original state for adb's children.
19  */
20 typedef	int (*sig_t)();		/* for signal syscall */
21 sig_t	sigint;			/* original SIGINT state */
22 sig_t	sigquit;		/* original SIGQUIT state */
23 sig_t	intcatch;		/* interrupt catch routine, or SIG_IGN */
24 
25 /*
26  * Address spaces.  We distinguish only between instruction & data.
27  * The spaces NONE, INSTR, and DATA (without the STAR flag) are also used
28  * to tag symbols.
29  */
30 #define	SP_NONE		0	/* not in any space, just a number */
31 #define	SP_INSTR	1	/* instruction space */
32 #define	SP_DATA		2	/* data space */
33 #define	SP_STAR		4	/* or'ed in; see below */
34 
35 /*
36  * The symbol and core files.
37  */
38 struct {
39 	char	*name;		/* file name */
40 	int	fd;		/* and descriptor */
41 } symfile, corefile;
42 
43 /*
44  * File address maps.
45  */
46 struct m1 {
47 	addr_t	b;		/* begins at b */
48 	addr_t	e;		/* ends at e */
49 	addr_t	f;		/* with offset f */
50 };
51 struct map {
52 	struct	m1 m1;		/* regular map */
53 	struct	m1 m2;		/* `star' (alternate) map */
54 	int	ufd;		/* unix file descriptor */
55 };
56 
57 struct	map txtmap;		/* the `?' or text file */
58 struct	map datmap;		/* the `/' or data/core file */
59 
60 /*
61  * Program and file I/O.
62  */
63 enum rwmode { RWMODE_READ, RWMODE_WRITE };
64 #define	adbread(space, rmtaddr, localaddr, nbytes) \
65 	adbio(RWMODE_READ, space, rmtaddr, (caddr_t)(localaddr), nbytes)
66 #define	adbwrite(space, rmtaddr, localaddr, nbytes) \
67 	adbio(RWMODE_WRITE, space, rmtaddr, (caddr_t)(localaddr), nbytes)
68 
69 addr_t	vtophys();		/* -k: kernel virtual addr to physical */
70 
71 /*
72  * Errors.  errflag should be set to point to the error message when
73  * an error occurs.  error(s) sets errflag to s and jumps back
74  * to the main loop via longjmp().  In some places this is unsafe
75  * or undesirable, and instead errflag is set directly; checkerr()
76  * can be used to test (and jump on) for such errors later.
77  *
78  * mkfault creates a `generic' error after a keyboard interrupt.
79  *
80  * Various error strings are defined in message.c and referenced
81  * through names below.
82  */
83 char	*errflag;		/* the error, or NULL */
84 int	mkfault;		/* interrupted; pretend an error */
85 
86 #define	iserr()	(errflag || mkfault)
87 #define	checkerr() \
88 	if (!iserr()) \
89 		/* void */; \
90 	else \
91 		error(errflag)
92 /* if checkerr() above is undefined, a function version is used instead */
93 
94 /*
95  * Locations.
96  *
97  * HSZ and FSZ are defined here as the sizes of `half' and `full' words
98  * respectively.  While these are not `locations', they are commonly used
99  * to set the value of dotinc.
100  */
101 int	gavedot;		/* true iff this command set dot */
102 addr_t	dot;			/* current location; but see also edot */
103 addr_t	ditto;			/* previous dot */
104 int	dotinc;			/* size of last object examined */
105 
106 extern	char ADDRWRAP[];	/* "address wrap around" */
107 
108 /* compute dot+offset, checking for overflow */
109 #define	inkdot(o) (ADDRESS_WRAP(dot, dot+(o)) ? error(ADDRWRAP), 0 : dot+(o))
110 /* if inkdot() above is undefined, a function version is used instead */
111 
112 /*
113  * Expressions.
114  *
115  * oexpr() evaluates an optional expression; rexpr() does a required
116  * expression, and returns expv as a convenience.
117  *
118  * N.B.: edot is valid only if gavedot.
119  */
120 int	oexpr();		/* returns 1 if found expr, else 0 */
121 expr_t	rexpr();		/* aborts if no expression found */
122 
123 expr_t	edot;			/* dot as an expression (possibly more bits) */
124 int	gavecount;		/* true iff this command gave a count */
125 expr_t	ecount;			/* repeat count from addr,count format */
126 expr_t	expv;			/* value from last expression */
127 expr_t	var[36];		/* adb's 36 variables (0..9 then a..z) */
128 
129 /*
130  * Input.
131  *
132  * The global lp points to the current input line.  The routine
133  * readchar() picks up the next character, incrementing lp, but
134  * can read more if appropriate.  lastc retains the most recently
135  * read character.  unreadc() in effect `puts back' lastc.  rdc()
136  * is like readchar() but skips white space.
137  */
138 char	*lp;			/* pointer into current line */
139 int	lastc;			/* character most recently read */
140 int	readchar();		/* get the next char */
141 int	rdc();			/* get the next nonblank char */
142 #ifndef lint
143 #define	unreadc()	(lastc ? lp-- : 0)
144 #else
145 #define	unreadc()	(lp--)
146 #endif
147 #ifndef lint
148 #define	readchar()	(((lastc = *lp) == 0 ? 0 : lp++), lastc)
149 #endif
150 /* if readchar() above is undefined, a function version is used instead */
151 #define	eol(c)		((c) == '\n' || (c) == ';')
152 
153 /*
154  * Miscellaneous globals, functions, and macros.
155  */
156 int	kernel;			/* debugging kernel (-k flag) */
157 int	kcore;			/* have a post-mortem dump (-k + core) */
158 int	wtflag;			/* adb => 0, adb -w => 2 */
159 int	radix;			/* current radix (input and %r/%R formats) */
160 int	pid;			/* process id being debugged, or 0 */
161 int	signo;			/* signal that stopped process pid */
162 int	sigcode;		/* extension info (machine dependent) */
163 
164 addr_t	maxoff;			/* max offset for symbol match ($s) */
165 #define	MAXOFF	1024		/* default value */
166 
167 int	maxcol;			/* max output column ($w) */
168 #define	MAXCOL	80		/* default value */
169 
170 #define	LINELEN	1024		/* max input line length */
171 #define	SYMLEN	1024		/* max symbol length */
172 
173 int	errno;			/* our old friend */
174 
175 /*
176  * checkfloat() returns an error string if a float or double is
177  * some sort of reserved bit pattern, such that trying to print it
178  * would cause a fault.  It is called with the address of the
179  * float or double, and a 0 or 1 to indicate float and double
180  * respectively.  checkfloat() returns NULL if the number is printable.
181  */
182 char	*checkfloat();		/* check a float or double for correctness */
183 
184 struct reglist *reglookup();	/* find a register by name */
185 
186 struct nlist *lookup();		/* look up a symbol */
187 struct nlist *findsym();	/* like lookup, but allows an offset */
188 struct nlist *nextlocal();	/* given a sym, return the next local sym */
189 
190 struct nlist *symtab;		/* symbol table */
191 struct nlist *esymtab;		/* end of symtab */
192 
193 expr_t	getreg();		/* returns the value in a register */
194 
195 addr_t	eval_localsym();	/* compute the address of a local symbol */
196 
197 /*
198  * eqstr(a, b) is true iff the given strings compare equal.
199  * eqsym(a, b, c) is true if symbols a and b match, but allowing
200  * the `a' symbol to begin with the character `c'.
201  */
202 #define	eqstr(a, b)	(*(a) == *(b) && strcmp(a, b) == 0)
203 #define	eqsym(a, b, c)	(eqstr(a, b) || *(a) == (c) && eqstr((a) + 1, b))
204 
205 /*
206  * The user structure.
207  */
208 union {
209 	struct	user user;		/* the actual user struct */
210 	char	upages[ctob(UPAGES)];	/* u. + kernel stack */
211 } uu;
212 #define	u uu.user
213