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

Cache object: 5a56c53bfa316b1491fb3cd26919c3a8


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