1 /* $OpenBSD: db_variables.c,v 1.9 2002/03/14 01:26:51 millert 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, FCN_NULL },
46 { "maxoff", (long *)&db_maxoff, FCN_NULL },
47 { "maxwidth", (long *)&db_max_width, FCN_NULL },
48 { "tabstops", (long *)&db_tab_stop_width, FCN_NULL },
49 { "lines", (long *)&db_max_line, FCN_NULL },
50 };
51 struct db_variable *db_evars = db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
52
53 int
db_find_variable(varp)54 db_find_variable(varp)
55 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
db_get_variable(valuep)81 db_get_variable(valuep)
82 db_expr_t *valuep;
83 {
84 struct db_variable *vp;
85
86 if (!db_find_variable(&vp))
87 return (0);
88
89 db_read_variable(vp, valuep);
90
91 return (1);
92 }
93
94 int
db_set_variable(value)95 db_set_variable(value)
96 db_expr_t value;
97 {
98 struct db_variable *vp;
99
100 if (!db_find_variable(&vp))
101 return (0);
102
103 db_write_variable(vp, &value);
104
105 return (1);
106 }
107
108
109 void
db_read_variable(vp,valuep)110 db_read_variable(vp, valuep)
111 struct db_variable *vp;
112 db_expr_t *valuep;
113 {
114 int (*func)(struct db_variable *, db_expr_t *, int) = vp->fcn;
115
116 if (func == FCN_NULL)
117 *valuep = *(vp->valuep);
118 else
119 (*func)(vp, valuep, DB_VAR_GET);
120 }
121
122 void
db_write_variable(vp,valuep)123 db_write_variable(vp, valuep)
124 struct db_variable *vp;
125 db_expr_t *valuep;
126 {
127 int (*func)(struct db_variable *, db_expr_t *, int) = vp->fcn;
128
129 if (func == FCN_NULL)
130 *(vp->valuep) = *valuep;
131 else
132 (*func)(vp, valuep, DB_VAR_SET);
133 }
134
135 /*ARGSUSED*/
136 void
db_set_cmd(addr,have_addr,count,modif)137 db_set_cmd(addr, have_addr, count, modif)
138 db_expr_t addr;
139 int have_addr;
140 db_expr_t count;
141 char * modif;
142 {
143 db_expr_t value;
144 struct db_variable *vp;
145 int t;
146
147 t = db_read_token();
148 if (t != tDOLLAR) {
149 db_error("Unknown variable\n");
150 /*NOTREACHED*/
151 }
152 if (!db_find_variable(&vp)) {
153 db_error("Unknown variable\n");
154 /*NOTREACHED*/
155 }
156
157 t = db_read_token();
158 if (t != tEQ)
159 db_unread_token(t);
160
161 if (!db_expression(&value)) {
162 db_error("No value\n");
163 /*NOTREACHED*/
164 }
165 if (db_read_token() != tEOL) {
166 db_error("?\n");
167 /*NOTREACHED*/
168 }
169
170 db_write_variable(vp, &value);
171 }
172