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_macro.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
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 "AS IS"
   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 Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        db_macro.c,v $
   29  * Revision 2.5  93/01/14  17:25:17  danner
   30  *      Cleaned db_del_macro_cmd to quiet gcc warnings.
   31  *      [92/08/12            jfriedl]
   32  * 
   33  * Revision 2.4  92/08/03  17:31:33  jfriedl
   34  *      removed silly prototypes
   35  *      [92/08/02            jfriedl]
   36  * 
   37  * Revision 2.3  92/05/21  17:07:15  jfriedl
   38  *      Removed unused variable from db_exec_macro().
   39  *      Added include of <ddb/db_command.h>.
   40  *      [92/05/16            jfriedl]
   41  * 
   42  * Revision 2.2  91/10/09  16:01:09  af
   43  *       Revision 2.1.3.1  91/10/05  13:06:40  jeffreyh
   44  *              Created for macro support.
   45  *              [91/08/29            tak]
   46  * 
   47  * Revision 2.1.3.1  91/10/05  13:06:40  jeffreyh
   48  *      Created for macro support.
   49  *      [91/08/29            tak]
   50  * 
   51  */
   52 #include <kern/thread.h>
   53 
   54 #include <machine/db_machdep.h>
   55 #include <ddb/db_lex.h>
   56 #include <ddb/db_variables.h>
   57 #include <ddb/db_command.h>
   58 
   59 
   60 
   61 /*
   62  * debugger macro support
   63  */
   64 
   65 #define DB_MACRO_LEVEL  5               /* max macro nesting */
   66 #define DB_NARGS        10              /* max args */
   67 #define DB_NUSER_MACRO  10              /* max user macros */
   68 
   69 int             db_macro_free = DB_NUSER_MACRO;
   70 struct db_user_macro {
   71         char    m_name[TOK_STRING_SIZE];
   72         char    m_lbuf[DB_LEX_LINE_SIZE];
   73         int     m_size;
   74 } db_user_macro[DB_NUSER_MACRO];
   75 
   76 int             db_macro_level = 0;
   77 db_expr_t       db_macro_args[DB_MACRO_LEVEL][DB_NARGS];
   78 
   79 static struct db_user_macro *
   80 db_lookup_macro(name)
   81         char *name;
   82 {
   83         register struct db_user_macro *mp;
   84 
   85         for (mp = db_user_macro; mp < &db_user_macro[DB_NUSER_MACRO]; mp++) {
   86             if (mp->m_name[0] == 0)
   87                 continue;
   88             if (strcmp(mp->m_name, name) == 0)
   89                 return(mp);
   90         }
   91         return(0);
   92 }
   93 
   94 void
   95 db_def_macro_cmd()
   96 {
   97         register char *p;
   98         register c;
   99         register struct db_user_macro *mp, *ep;
  100 
  101         if (db_read_token() != tIDENT) {
  102             db_printf("Bad macro name \"%s\"\n", db_tok_string);
  103             db_error(0);
  104             /* NOTREACHED */
  105         }
  106         if ((mp = db_lookup_macro(db_tok_string)) == 0) {
  107             if (db_macro_free <= 0)
  108                 db_error("Too many macros\n");
  109                 /* NOTREACHED */
  110             ep = &db_user_macro[DB_NUSER_MACRO];
  111             for (mp = db_user_macro; mp < ep && mp->m_name[0]; mp++);
  112             if (mp >= ep)
  113                 db_error("ddb: internal error(macro)\n");
  114                 /* NOTREACHED */
  115             db_macro_free--;
  116             db_strcpy(mp->m_name, db_tok_string);
  117         }
  118         for (c = db_read_char(); c == ' ' || c == '\t'; c = db_read_char());
  119         for (p = mp->m_lbuf; c > 0; c = db_read_char())
  120             *p++ = c;
  121         *p = 0;
  122         mp->m_size = p - mp->m_lbuf;
  123 }
  124 
  125 void
  126 db_del_macro_cmd()
  127 {
  128         register struct db_user_macro *mp;
  129 
  130         if (db_read_token() != tIDENT 
  131             || (mp = db_lookup_macro(db_tok_string)) == 0) {
  132             db_printf("No such macro \"%s\"\n", db_tok_string);
  133             db_error(0);
  134             /* NOTREACHED */
  135         } else {
  136             mp->m_name[0] = 0;
  137             db_macro_free++;
  138         }
  139 }
  140 
  141 void
  142 db_show_macro()
  143 {
  144         register struct db_user_macro *mp;
  145         int  t;
  146         char *name = 0;
  147 
  148         if ((t = db_read_token()) == tIDENT)
  149             name = db_tok_string;
  150         else
  151             db_unread_token(t);
  152         for (mp = db_user_macro; mp < &db_user_macro[DB_NUSER_MACRO]; mp++) {
  153             if (mp->m_name[0] == 0)
  154                 continue;
  155             if (name && strcmp(mp->m_name, name))
  156                 continue;
  157             db_printf("%s: %s", mp->m_name, mp->m_lbuf);
  158         }
  159 }
  160         
  161 int
  162 db_exec_macro(name)
  163         char *name;
  164 {
  165         register struct db_user_macro *mp;
  166         register n;
  167 
  168         if ((mp = db_lookup_macro(name)) == 0)
  169             return(-1);
  170         if (db_macro_level+1 >= DB_MACRO_LEVEL) {
  171             db_macro_level = 0;
  172             db_error("Too many macro nest\n");
  173             /* NOTREACHED */
  174         }
  175         for (n = 0;
  176              n < DB_NARGS && 
  177              db_expression(&db_macro_args[db_macro_level+1][n]);
  178              n++);
  179         while (n < DB_NARGS)
  180             db_macro_args[db_macro_level+1][n++] = 0;
  181         db_macro_level++;
  182         db_exec_cmd_nest(mp->m_lbuf, mp->m_size);
  183         db_macro_level--;
  184         return(0);
  185 }
  186 
  187 int
  188 /* ARGSUSED */
  189 db_arg_variable(vp, valuep, flag, ap)
  190         struct db_variable      *vp;
  191         db_expr_t               *valuep;
  192         int                     flag;
  193         db_var_aux_param_t      ap;
  194 {
  195         if (ap->level != 1 || ap->suffix[0] < 1 || ap->suffix[0] > DB_NARGS) {
  196             db_error("Bad $arg variable\n");
  197             /* NOTREACHED */
  198         }
  199         if (flag == DB_VAR_GET)
  200             *valuep = db_macro_args[db_macro_level][ap->suffix[0]-1];
  201         else
  202             db_macro_args[db_macro_level][ap->suffix[0]-1] = *valuep;
  203         return(0);
  204 }

Cache object: 628b52bd5e82397a1e7ff77acf30d4f8


[ 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.