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