The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ddb/db_variables.c

Version: -  FREEBSD  -  FREEBSD11  -  FREEBSD10  -  FREEBSD9  -  FREEBSD92  -  FREEBSD91  -  FREEBSD90  -  FREEBSD8  -  FREEBSD82  -  FREEBSD81  -  FREEBSD80  -  FREEBSD7  -  FREEBSD74  -  FREEBSD73  -  FREEBSD72  -  FREEBSD71  -  FREEBSD70  -  FREEBSD6  -  FREEBSD64  -  FREEBSD63  -  FREEBSD62  -  FREEBSD61  -  FREEBSD60  -  FREEBSD5  -  FREEBSD55  -  FREEBSD54  -  FREEBSD53  -  FREEBSD52  -  FREEBSD51  -  FREEBSD50  -  FREEBSD4  -  FREEBSD3  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Mach Operating System
    3  * Copyright (c) 1991,1990 Carnegie Mellon University
    4  * All Rights Reserved.
    5  *
    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.
   11  *
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  *
   16  * Carnegie Mellon requests users of this software to return to
   17  *
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  *
   23  * any improvements or extensions that they make and grant Carnegie the
   24  * rights to redistribute these changes.
   25  */
   26 /*
   27  *      Author: David B. Golub, Carnegie Mellon University
   28  *      Date:   7/90
   29  */
   30 
   31 #include <sys/cdefs.h>
   32 __FBSDID("$FreeBSD: stable/9/sys/ddb/db_variables.c 195699 2009-07-14 22:48:30Z rwatson $");
   33 
   34 #include <sys/param.h>
   35 #include <sys/systm.h>
   36 
   37 #include <ddb/ddb.h>
   38 #include <ddb/db_lex.h>
   39 #include <ddb/db_variables.h>
   40 
   41 static int      db_find_variable(struct db_variable **varp);
   42 
   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 },
   51 #ifdef VIMAGE
   52         { "curvnet",    NULL, db_var_curvnet },
   53         { "db_vnet",    NULL, db_var_db_vnet },
   54 #endif
   55 };
   56 static struct db_variable *db_evars =
   57         db_vars + sizeof(db_vars)/sizeof(db_vars[0]);
   58 
   59 static int
   60 db_find_variable(struct db_variable **varp)
   61 {
   62         struct db_variable *vp;
   63         int t;
   64 
   65         t = db_read_token();
   66         if (t == tIDENT) {
   67                 for (vp = db_vars; vp < db_evars; vp++) {
   68                         if (!strcmp(db_tok_string, vp->name)) {
   69                                 *varp = vp;
   70                                 return (1);
   71                         }
   72                 }
   73                 for (vp = db_regs; vp < db_eregs; vp++) {
   74                         if (!strcmp(db_tok_string, vp->name)) {
   75                                 *varp = vp;
   76                                 return (1);
   77                         }
   78                 }
   79         }
   80         db_error("Unknown variable\n");
   81         return (0);
   82 }
   83 
   84 int
   85 db_get_variable(db_expr_t *valuep)
   86 {
   87         struct db_variable *vp;
   88 
   89         if (!db_find_variable(&vp))
   90                 return (0);
   91 
   92         return (db_read_variable(vp, valuep));
   93 }
   94 
   95 int
   96 db_set_variable(db_expr_t value)
   97 {
   98         struct db_variable *vp;
   99 
  100         if (!db_find_variable(&vp))
  101                 return (0);
  102 
  103         return (db_write_variable(vp, value));
  104 }
  105 
  106 int
  107 db_read_variable(struct db_variable *vp, db_expr_t *valuep)
  108 {
  109         db_varfcn_t *func = vp->fcn;
  110 
  111         if (func == FCN_NULL) {
  112                 *valuep = *(vp->valuep);
  113                 return (1);
  114         }
  115         return ((*func)(vp, valuep, DB_VAR_GET));
  116 }
  117 
  118 int
  119 db_write_variable(struct db_variable *vp, db_expr_t value)
  120 {
  121         db_varfcn_t *func = vp->fcn;
  122 
  123         if (func == FCN_NULL) {
  124                 *(vp->valuep) = value;
  125                 return (1);
  126         }
  127         return ((*func)(vp, &value, DB_VAR_SET));
  128 }
  129 
  130 void
  131 db_set_cmd(db_expr_t dummy1, boolean_t dummy2, db_expr_t dummy3, char *dummy4)
  132 {
  133         struct db_variable *vp;
  134         db_expr_t value;
  135         int t;
  136 
  137         t = db_read_token();
  138         if (t != tDOLLAR) {
  139                 db_error("Unknown variable\n");
  140                 return;
  141         }
  142         if (!db_find_variable(&vp)) {
  143                 db_error("Unknown variable\n");
  144                 return;
  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                 return;
  154         }
  155         if (db_read_token() != tEOL)
  156                 db_error("?\n");
  157 
  158         db_write_variable(vp, value);
  159 }

Cache object: 4f339b7e46c20010c08b6a1455d25e66


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.