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