LCOV - code coverage report
Current view: top level - ddb - db_variables.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 66 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: db_variables.c,v 1.18 2016/01/25 14:30:30 mpi 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/systm.h>
      32             : 
      33             : #include <machine/db_machdep.h>
      34             : 
      35             : #include <ddb/db_lex.h>
      36             : #include <ddb/db_variables.h>
      37             : #include <ddb/db_command.h>
      38             : #include <ddb/db_sym.h>
      39             : #include <ddb/db_extern.h>
      40             : #include <ddb/db_var.h>
      41             : 
      42             : struct db_variable db_vars[] = {
      43             :         { "radix",    (long *)&db_radix, db_var_rw_int },
      44             :         { "maxoff",   (long *)&db_maxoff, db_var_rw_int },
      45             :         { "maxwidth", (long *)&db_max_width, db_var_rw_int },
      46             :         { "tabstops", (long *)&db_tab_stop_width, db_var_rw_int },
      47             :         { "lines",    (long *)&db_max_line, db_var_rw_int },
      48             :         { "log",      (long *)&db_log, db_var_rw_int }
      49             : };
      50             : struct db_variable *db_evars = db_vars + nitems(db_vars);
      51             : 
      52             : int
      53           0 : db_find_variable(struct db_variable **varp)
      54             : {
      55             :         int     t;
      56             :         struct db_variable *vp;
      57             : 
      58           0 :         t = db_read_token();
      59           0 :         if (t == tIDENT) {
      60           0 :             for (vp = db_vars; vp < db_evars; vp++) {
      61           0 :                 if (!strcmp(db_tok_string, vp->name)) {
      62           0 :                     *varp = vp;
      63           0 :                     return (1);
      64             :                 }
      65             :             }
      66           0 :             for (vp = db_regs; vp < db_eregs; vp++) {
      67           0 :                 if (!strcmp(db_tok_string, vp->name)) {
      68           0 :                     *varp = vp;
      69           0 :                     return (1);
      70             :                 }
      71             :             }
      72             :         }
      73           0 :         db_error("Unknown variable\n");
      74             :         /*NOTREACHED*/
      75           0 :         return 0;
      76           0 : }
      77             : 
      78             : int
      79           0 : db_get_variable(db_expr_t *valuep)
      80             : {
      81           0 :         struct db_variable *vp;
      82             : 
      83           0 :         if (!db_find_variable(&vp))
      84           0 :             return (0);
      85             : 
      86           0 :         db_read_variable(vp, valuep);
      87             : 
      88           0 :         return (1);
      89           0 : }
      90             : 
      91             : int
      92           0 : db_set_variable(db_expr_t value)
      93             : {
      94           0 :         struct db_variable *vp;
      95             : 
      96           0 :         if (!db_find_variable(&vp))
      97           0 :             return (0);
      98             : 
      99           0 :         db_write_variable(vp, &value);
     100             : 
     101           0 :         return (1);
     102           0 : }
     103             : 
     104             : 
     105             : void
     106           0 : db_read_variable(struct db_variable *vp, db_expr_t *valuep)
     107             : {
     108           0 :         int     (*func)(struct db_variable *, db_expr_t *, int) = vp->fcn;
     109             : 
     110           0 :         if (func == FCN_NULL)
     111           0 :             *valuep = *(vp->valuep);
     112             :         else
     113           0 :             (*func)(vp, valuep, DB_VAR_GET);
     114           0 : }
     115             : 
     116             : void
     117           0 : db_write_variable(struct db_variable *vp, db_expr_t *valuep)
     118             : {
     119           0 :         int     (*func)(struct db_variable *, db_expr_t *, int) = vp->fcn;
     120             : 
     121           0 :         if (func == FCN_NULL)
     122           0 :             *(vp->valuep) = *valuep;
     123             :         else
     124           0 :             (*func)(vp, valuep, DB_VAR_SET);
     125           0 : }
     126             : 
     127             : /*ARGSUSED*/
     128             : void
     129           0 : db_set_cmd(db_expr_t addr, int have_addr, db_expr_t count, char *modif)
     130             : {
     131           0 :         db_expr_t       value;
     132           0 :         struct db_variable *vp;
     133             :         int     t;
     134             : 
     135           0 :         t = db_read_token();
     136           0 :         if (t != tDOLLAR) {
     137           0 :             db_error("Unknown variable\n");
     138             :             /*NOTREACHED*/
     139           0 :         }
     140           0 :         if (!db_find_variable(&vp)) {
     141           0 :             db_error("Unknown variable\n");
     142             :             /*NOTREACHED*/
     143           0 :         }
     144             : 
     145           0 :         t = db_read_token();
     146           0 :         if (t != tEQ)
     147           0 :             db_unread_token(t);
     148             : 
     149           0 :         if (!db_expression(&value)) {
     150           0 :             db_error("No value\n");
     151             :             /*NOTREACHED*/
     152           0 :         }
     153           0 :         if (db_read_token() != tEOL) {
     154           0 :             db_error("?\n");
     155             :             /*NOTREACHED*/
     156           0 :         }
     157             : 
     158           0 :         db_write_variable(vp, &value);
     159           0 : }
     160             : 
     161             : int
     162           0 : db_var_rw_int(struct db_variable *var, db_expr_t *expr, int mode)
     163             : {
     164             : 
     165           0 :         if (mode == DB_VAR_SET)
     166           0 :                 *var->valuep = *(int *)expr;
     167             :         else
     168           0 :                 *expr = *(int *)var->valuep;
     169           0 :         return (0);
     170             : }
     171             : 

Generated by: LCOV version 1.13