2 * SPDX-License-Identifier: MIT-CMU
4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
29 * Author: David B. Golub, Carnegie Mellon University
33 #include <sys/cdefs.h>
34 #include <sys/param.h>
35 #include <sys/systm.h>
38 #include <ddb/db_lex.h>
39 #include <ddb/db_variables.h>
41 static int db_find_variable(struct db_variable **varp);
43 static struct db_variable db_vars[] = {
44 { "radix", &db_radix, FCN_NULL },
45 { "maxoff", &db_maxoff, FCN_NULL },
46 { "maxwidth", &db_max_width, FCN_NULL },
47 { "tabstops", &db_tab_stop_width, FCN_NULL },
48 { "lines", &db_lines_per_page, FCN_NULL },
49 { "curcpu", NULL, db_var_curcpu },
50 { "db_cpu", NULL, db_var_db_cpu },
52 { "curvnet", NULL, db_var_curvnet },
53 { "db_vnet", NULL, db_var_db_vnet },
56 static struct db_variable *db_evars = db_vars + nitems(db_vars);
59 db_find_variable(struct db_variable **varp)
61 struct db_variable *vp;
66 for (vp = db_vars; vp < db_evars; vp++) {
67 if (!strcmp(db_tok_string, vp->name)) {
72 for (vp = db_regs; vp < db_eregs; vp++) {
73 if (!strcmp(db_tok_string, vp->name)) {
79 db_error("Unknown variable\n");
84 db_get_variable(db_expr_t *valuep)
86 struct db_variable *vp;
88 if (!db_find_variable(&vp))
91 return (db_read_variable(vp, valuep));
95 db_set_variable(db_expr_t value)
97 struct db_variable *vp;
99 if (!db_find_variable(&vp))
102 return (db_write_variable(vp, value));
106 db_read_variable(struct db_variable *vp, db_expr_t *valuep)
108 db_varfcn_t *func = vp->fcn;
110 if (func == FCN_NULL) {
111 *valuep = *(vp->valuep);
114 return ((*func)(vp, valuep, DB_VAR_GET));
118 db_write_variable(struct db_variable *vp, db_expr_t value)
120 db_varfcn_t *func = vp->fcn;
122 if (func == FCN_NULL) {
123 *(vp->valuep) = value;
126 return ((*func)(vp, &value, DB_VAR_SET));
130 db_set_cmd(db_expr_t dummy1, bool dummy2, db_expr_t dummy3, char *dummy4)
132 struct db_variable *vp;
138 for (vp = db_vars; vp < db_evars; vp++) {
139 if (!db_read_variable(vp, &value)) {
140 db_printf("$%s\n", vp->name);
143 db_printf("$%-8s = %ld\n",
144 vp->name, (unsigned long)value);
149 db_error("Unknown variable\n");
152 if (!db_find_variable(&vp)) {
153 db_error("Unknown variable\n");
161 if (!db_expression(&value)) {
162 db_error("No value\n");
165 if (db_read_token() != tEOL)
168 db_write_variable(vp, value);