Annotation of sys/ddb/db_variables.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: db_variables.c,v 1.12 2006/07/06 19:05:58 miod Exp $ */
2: /* $NetBSD: db_variables.c,v 1.8 1996/02/05 01:57:19 christos Exp $ */
3:
4: /*
5: * Mach Operating System
6: * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
7: * All Rights Reserved.
8: *
9: * Permission to use, copy, modify and distribute this software and its
10: * documentation is hereby granted, provided that both the copyright
11: * notice and this permission notice appear in all copies of the
12: * software, derivative works or modified versions, and any portions
13: * thereof, and that both notices appear in supporting documentation.
14: *
15: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18: *
19: * Carnegie Mellon requests users of this software to return to
20: *
21: * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22: * School of Computer Science
23: * Carnegie Mellon University
24: * Pittsburgh PA 15213-3890
25: *
26: * any improvements or extensions that they make and grant Carnegie Mellon
27: * the rights to redistribute these changes.
28: */
29:
30: #include <sys/param.h>
31: #include <sys/proc.h>
32:
33: #include <uvm/uvm_extern.h>
34:
35: #include <machine/db_machdep.h>
36:
37: #include <ddb/db_lex.h>
38: #include <ddb/db_variables.h>
39: #include <ddb/db_command.h>
40: #include <ddb/db_sym.h>
41: #include <ddb/db_extern.h>
42: #include <ddb/db_var.h>
43:
44: struct db_variable db_vars[] = {
45: { "radix", (long *)&db_radix, db_var_rw_int },
46: { "maxoff", (long *)&db_maxoff, db_var_rw_int },
47: { "maxwidth", (long *)&db_max_width, db_var_rw_int },
48: { "tabstops", (long *)&db_tab_stop_width, db_var_rw_int },
49: { "lines", (long *)&db_max_line, db_var_rw_int },
50: { "log", (long *)&db_log, db_var_rw_int }
51: };
52: struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
53:
54: int
55: db_find_variable(struct db_variable **varp)
56: {
57: int t;
58: struct db_variable *vp;
59:
60: t = db_read_token();
61: if (t == tIDENT) {
62: for (vp = db_vars; vp < db_evars; vp++) {
63: if (!strcmp(db_tok_string, vp->name)) {
64: *varp = vp;
65: return (1);
66: }
67: }
68: for (vp = db_regs; vp < db_eregs; vp++) {
69: if (!strcmp(db_tok_string, vp->name)) {
70: *varp = vp;
71: return (1);
72: }
73: }
74: }
75: db_error("Unknown variable\n");
76: /*NOTREACHED*/
77: return 0;
78: }
79:
80: int
81: db_get_variable(db_expr_t *valuep)
82: {
83: struct db_variable *vp;
84:
85: if (!db_find_variable(&vp))
86: return (0);
87:
88: db_read_variable(vp, valuep);
89:
90: return (1);
91: }
92:
93: int
94: db_set_variable(db_expr_t value)
95: {
96: struct db_variable *vp;
97:
98: if (!db_find_variable(&vp))
99: return (0);
100:
101: db_write_variable(vp, &value);
102:
103: return (1);
104: }
105:
106:
107: void
108: db_read_variable(struct db_variable *vp, db_expr_t *valuep)
109: {
110: int (*func)(struct db_variable *, db_expr_t *, int) = vp->fcn;
111:
112: if (func == FCN_NULL)
113: *valuep = *(vp->valuep);
114: else
115: (*func)(vp, valuep, DB_VAR_GET);
116: }
117:
118: void
119: db_write_variable(struct db_variable *vp, db_expr_t *valuep)
120: {
121: int (*func)(struct db_variable *, db_expr_t *, int) = vp->fcn;
122:
123: if (func == FCN_NULL)
124: *(vp->valuep) = *valuep;
125: else
126: (*func)(vp, valuep, DB_VAR_SET);
127: }
128:
129: /*ARGSUSED*/
130: void
131: db_set_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
132: {
133: db_expr_t value;
134: struct db_variable *vp;
135: int t;
136:
137: t = db_read_token();
138: if (t != tDOLLAR) {
139: db_error("Unknown variable\n");
140: /*NOTREACHED*/
141: }
142: if (!db_find_variable(&vp)) {
143: db_error("Unknown variable\n");
144: /*NOTREACHED*/
145: }
146:
147: t = db_read_token();
148: if (t != tEQ)
149: db_unread_token(t);
150:
151: if (!db_expression(&value)) {
152: db_error("No value\n");
153: /*NOTREACHED*/
154: }
155: if (db_read_token() != tEOL) {
156: db_error("?\n");
157: /*NOTREACHED*/
158: }
159:
160: db_write_variable(vp, &value);
161: }
162:
163: int
164: db_var_rw_int(struct db_variable *var, db_expr_t *expr, int mode)
165: {
166:
167: if (mode == DB_VAR_SET)
168: *var->valuep = *(int *)expr;
169: else
170: *expr = *(int *)var->valuep;
171: return (0);
172: }
173:
CVSweb