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