|
|
1.1.1.2 root 1: /*
1.1 root 2: * Mach Operating System
3: * Copyright (c) 1991,1990 Carnegie Mellon University
4: * All Rights Reserved.
1.1.1.2 root 5: *
1.1 root 6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
1.1.1.2 root 11: *
1.1 root 12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1.1.1.2 root 15: *
1.1 root 16: * Carnegie Mellon requests users of this software to return to
1.1.1.2 root 17: *
1.1 root 18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
1.1.1.2 root 22: *
1.1 root 23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /*
27: * Author: David B. Golub, Carnegie Mellon University
28: * Date: 7/90
29: */
30:
31: #if MACH_KDB
32:
33: #include <machine/db_machdep.h>
34:
1.1.1.3 root 35: #include <ddb/db_command.h>
36: #include <ddb/db_examine.h>
37: #include <ddb/db_expr.h>
1.1 root 38: #include <ddb/db_lex.h>
1.1.1.3 root 39: #include <ddb/db_output.h>
1.1 root 40: #include <ddb/db_variables.h>
41: #include <ddb/db_task_thread.h>
1.1.1.4 ! root 42: #include <ddb/db_macro.h>
1.1 root 43:
44: extern unsigned long db_maxoff;
45:
46: extern db_expr_t db_radix;
47: extern db_expr_t db_max_width;
48: extern db_expr_t db_tab_stop_width;
49: extern db_expr_t db_max_line;
50:
51: #define DB_NWORK 32 /* number of work variable */
52:
53: db_expr_t db_work[DB_NWORK]; /* work variable */
54:
55: struct db_variable db_vars[] = {
56: { "radix", &db_radix, FCN_NULL },
57: { "maxoff", (db_expr_t*)&db_maxoff, FCN_NULL },
58: { "maxwidth", &db_max_width, FCN_NULL },
59: { "tabstops", &db_tab_stop_width, FCN_NULL },
60: { "lines", &db_max_line, FCN_NULL },
61: { "thread", 0, db_set_default_thread },
62: { "task", 0, db_get_task_thread,
63: 1, 2, -1, -1 },
64: { "work", &db_work[0], FCN_NULL,
65: 1, 1, 0, DB_NWORK-1 },
66: { "arg", 0, db_arg_variable,
67: 1, 1, -1, -1 },
68: };
69: struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
70:
1.1.1.4 ! root 71: const char *
1.1 root 72: db_get_suffix(suffix, suffix_value)
1.1.1.4 ! root 73: const char *suffix;
1.1 root 74: short *suffix_value;
75: {
1.1.1.4 ! root 76: int value;
1.1 root 77:
78: for (value = 0; *suffix && *suffix != '.' && *suffix != ':'; suffix++) {
79: if (*suffix < '0' || *suffix > '9')
80: return(0);
81: value = value*10 + *suffix - '0';
82: }
83: *suffix_value = value;
84: if (*suffix == '.')
85: suffix++;
86: return(suffix);
87: }
1.1.1.2 root 88:
1.1 root 89: static boolean_t
90: db_cmp_variable_name(vp, name, ap)
91: struct db_variable *vp;
92: char *name;
1.1.1.4 ! root 93: const db_var_aux_param_t ap;
1.1 root 94: {
1.1.1.4 ! root 95: char *var_np;
! 96: const char *np;
! 97: int level;
1.1.1.2 root 98:
1.1 root 99: for (np = name, var_np = vp->name; *var_np; ) {
100: if (*np++ != *var_np++)
101: return(FALSE);
102: }
103: for (level = 0; *np && *np != ':' && level < vp->max_level; level++){
104: if ((np = db_get_suffix(np, &ap->suffix[level])) == 0)
105: return(FALSE);
106: }
107: if ((*np && *np != ':') || level < vp->min_level
1.1.1.2 root 108: || (level > 0 && (ap->suffix[0] < vp->low
1.1 root 109: || (vp->high >= 0 && ap->suffix[0] > vp->high))))
110: return(FALSE);
111: db_strcpy(ap->modif, (*np)? np+1: "");
112: ap->thread = (db_option(ap->modif, 't')?db_default_thread: THREAD_NULL);
113: ap->level = level;
114: return(TRUE);
115: }
116:
117: int
1.1.1.4 ! root 118: db_find_variable(
! 119: struct db_variable **varp,
! 120: db_var_aux_param_t ap)
1.1 root 121: {
122: int t;
123: struct db_variable *vp;
124:
125: t = db_read_token();
126: if (t == tIDENT) {
127: for (vp = db_vars; vp < db_evars; vp++) {
128: if (db_cmp_variable_name(vp, db_tok_string, ap)) {
129: *varp = vp;
130: return (1);
131: }
132: }
133: for (vp = db_regs; vp < db_eregs; vp++) {
134: if (db_cmp_variable_name(vp, db_tok_string, ap)) {
135: *varp = vp;
136: return (1);
137: }
138: }
139: }
140: db_printf("Unknown variable \"$%s\"\n", db_tok_string);
141: db_error(0);
142: return (0);
143: }
144:
145: int
1.1.1.4 ! root 146: db_get_variable(db_expr_t *valuep)
1.1 root 147: {
148: struct db_variable *vp;
149: struct db_var_aux_param aux_param;
150: char modif[TOK_STRING_SIZE];
151:
152: aux_param.modif = modif;
153: if (!db_find_variable(&vp, &aux_param))
154: return (0);
155:
156: db_read_write_variable(vp, valuep, DB_VAR_GET, &aux_param);
157:
158: return (1);
159: }
160:
161: int
1.1.1.4 ! root 162: db_set_variable(db_expr_t value)
1.1 root 163: {
164: struct db_variable *vp;
165: struct db_var_aux_param aux_param;
166: char modif[TOK_STRING_SIZE];
167:
168: aux_param.modif = modif;
169: if (!db_find_variable(&vp, &aux_param))
170: return (0);
171:
172: db_read_write_variable(vp, &value, DB_VAR_SET, &aux_param);
173:
174: return (1);
175: }
176:
177: void
1.1.1.4 ! root 178: db_read_write_variable(
! 179: struct db_variable *vp,
! 180: db_expr_t *valuep,
! 181: int rw_flag,
! 182: db_var_aux_param_t ap)
1.1 root 183: {
1.1.1.4 ! root 184: void (*func)() = vp->fcn;
1.1 root 185: struct db_var_aux_param aux_param;
186:
187: if (ap == 0) {
188: ap = &aux_param;
189: ap->modif = "";
190: ap->level = 0;
191: ap->thread = THREAD_NULL;
192: }
193: if (func == FCN_NULL) {
194: if (rw_flag == DB_VAR_SET)
195: vp->valuep[(ap->level)? (ap->suffix[0] - vp->low): 0] = *valuep;
196: else
197: *valuep = vp->valuep[(ap->level)? (ap->suffix[0] - vp->low): 0];
198: } else
199: (*func)(vp, valuep, rw_flag, ap);
200: }
201:
202: void
1.1.1.4 ! root 203: db_set_cmd(void)
1.1 root 204: {
205: db_expr_t value;
206: int t;
207: struct db_variable *vp;
208: struct db_var_aux_param aux_param;
209: char modif[TOK_STRING_SIZE];
210:
211: aux_param.modif = modif;
212: t = db_read_token();
213: if (t != tDOLLAR) {
214: db_error("Variable name should be prefixed with $\n");
215: return;
216: }
217: if (!db_find_variable(&vp, &aux_param)) {
218: db_error("Unknown variable\n");
219: return;
220: }
221:
222: t = db_read_token();
223: if (t != tEQ)
224: db_unread_token(t);
225:
226: if (!db_expression(&value)) {
227: db_error("No value\n");
228: return;
229: }
230: if ((t = db_read_token()) == tSEMI_COLON)
231: db_unread_token(t);
232: else if (t != tEOL)
233: db_error("?\n");
234:
235: db_read_write_variable(vp, &value, DB_VAR_SET, &aux_param);
236: }
237:
1.1.1.2 root 238: #endif /* MACH_KDB */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.