Annotation of Gnu-Mach/ddb/db_macro.c, revision 1.1.1.4

1.1.1.2   root        1: /*
1.1       root        2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990 Carnegie Mellon University
                      4:  * All Rights Reserved.
1.1.1.2   root        5:  *
1.1       root        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.
1.1.1.2   root       11:  *
1.1       root       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.
1.1.1.2   root       15:  *
1.1       root       16:  * Carnegie Mellon requests users of this software to return to
1.1.1.2   root       17:  *
1.1       root       18:  *  Software Distribution Coordinator  or  [email protected]
                     19:  *  School of Computer Science
                     20:  *  Carnegie Mellon University
                     21:  *  Pittsburgh PA 15213-3890
1.1.1.2   root       22:  *
1.1       root       23:  * any improvements or extensions that they make and grant Carnegie Mellon
                     24:  * the rights to redistribute these changes.
                     25:  */
1.1.1.3   root       26: 
1.1       root       27: #if MACH_KDB
                     28: 
1.1.1.3   root       29: #include <string.h>
1.1       root       30: #include <kern/thread.h>
                     31: 
                     32: #include <machine/db_machdep.h>
                     33: #include <ddb/db_lex.h>
                     34: #include <ddb/db_variables.h>
                     35: #include <ddb/db_command.h>
1.1.1.3   root       36: #include <ddb/db_examine.h>
                     37: #include <ddb/db_expr.h>
                     38: #include <ddb/db_macro.h>
                     39: #include <ddb/db_output.h>
1.1       root       40: 
                     41: 
                     42: /*
                     43:  * debugger macro support
                     44:  */
                     45: 
                     46: #define DB_MACRO_LEVEL 5               /* max macro nesting */
                     47: #define DB_NARGS       10              /* max args */
                     48: #define DB_NUSER_MACRO 10              /* max user macros */
                     49: 
                     50: int            db_macro_free = DB_NUSER_MACRO;
                     51: struct db_user_macro {
                     52:        char    m_name[TOK_STRING_SIZE];
                     53:        char    m_lbuf[DB_LEX_LINE_SIZE];
                     54:        int     m_size;
                     55: } db_user_macro[DB_NUSER_MACRO];
                     56: 
                     57: int            db_macro_level = 0;
                     58: db_expr_t      db_macro_args[DB_MACRO_LEVEL][DB_NARGS];
                     59: 
                     60: static struct db_user_macro *
                     61: db_lookup_macro(name)
1.1.1.4 ! root       62:        const char *name;
1.1       root       63: {
1.1.1.4 ! root       64:        struct db_user_macro *mp;
1.1       root       65: 
                     66:        for (mp = db_user_macro; mp < &db_user_macro[DB_NUSER_MACRO]; mp++) {
                     67:            if (mp->m_name[0] == 0)
                     68:                continue;
                     69:            if (strcmp(mp->m_name, name) == 0)
                     70:                return(mp);
                     71:        }
                     72:        return(0);
                     73: }
                     74: 
                     75: void
1.1.1.4 ! root       76: db_def_macro_cmd(void)
1.1       root       77: {
1.1.1.4 ! root       78:        char *p;
        !            79:        int c;
        !            80:        struct db_user_macro *mp, *ep;
1.1       root       81: 
                     82:        if (db_read_token() != tIDENT) {
                     83:            db_printf("Bad macro name \"%s\"\n", db_tok_string);
                     84:            db_error(0);
                     85:            /* NOTREACHED */
                     86:        }
                     87:        if ((mp = db_lookup_macro(db_tok_string)) == 0) {
                     88:            if (db_macro_free <= 0)
                     89:                db_error("Too many macros\n");
                     90:                /* NOTREACHED */
                     91:            ep = &db_user_macro[DB_NUSER_MACRO];
                     92:            for (mp = db_user_macro; mp < ep && mp->m_name[0]; mp++);
                     93:            if (mp >= ep)
                     94:                db_error("ddb: internal error(macro)\n");
                     95:                /* NOTREACHED */
                     96:            db_macro_free--;
                     97:            db_strcpy(mp->m_name, db_tok_string);
                     98:        }
                     99:        for (c = db_read_char(); c == ' ' || c == '\t'; c = db_read_char());
                    100:        for (p = mp->m_lbuf; c > 0; c = db_read_char())
                    101:            *p++ = c;
                    102:        *p = 0;
                    103:        mp->m_size = p - mp->m_lbuf;
                    104: }
                    105: 
                    106: void
1.1.1.4 ! root      107: db_del_macro_cmd(void)
1.1       root      108: {
1.1.1.4 ! root      109:        struct db_user_macro *mp;
1.1       root      110: 
1.1.1.2   root      111:        if (db_read_token() != tIDENT
1.1       root      112:            || (mp = db_lookup_macro(db_tok_string)) == 0) {
                    113:            db_printf("No such macro \"%s\"\n", db_tok_string);
                    114:            db_error(0);
                    115:            /* NOTREACHED */
                    116:        } else {
                    117:            mp->m_name[0] = 0;
                    118:            db_macro_free++;
                    119:        }
                    120: }
                    121: 
                    122: void
1.1.1.4 ! root      123: db_show_macro(void)
1.1       root      124: {
1.1.1.4 ! root      125:        struct db_user_macro *mp;
1.1       root      126:        int  t;
                    127:        char *name = 0;
                    128: 
                    129:        if ((t = db_read_token()) == tIDENT)
                    130:            name = db_tok_string;
                    131:        else
                    132:            db_unread_token(t);
                    133:        for (mp = db_user_macro; mp < &db_user_macro[DB_NUSER_MACRO]; mp++) {
                    134:            if (mp->m_name[0] == 0)
                    135:                continue;
                    136:            if (name && strcmp(mp->m_name, name))
                    137:                continue;
                    138:            db_printf("%s: %s", mp->m_name, mp->m_lbuf);
                    139:        }
                    140: }
1.1.1.2   root      141: 
1.1       root      142: int
                    143: db_exec_macro(name)
1.1.1.4 ! root      144:        const char *name;
1.1       root      145: {
1.1.1.4 ! root      146:        struct db_user_macro *mp;
        !           147:        int n;
1.1       root      148: 
                    149:        if ((mp = db_lookup_macro(name)) == 0)
                    150:            return(-1);
                    151:        if (db_macro_level+1 >= DB_MACRO_LEVEL) {
                    152:            db_macro_level = 0;
                    153:            db_error("Too many macro nest\n");
                    154:            /* NOTREACHED */
                    155:        }
                    156:        for (n = 0;
1.1.1.2   root      157:             n < DB_NARGS &&
1.1       root      158:             db_expression(&db_macro_args[db_macro_level+1][n]);
                    159:             n++);
                    160:        while (n < DB_NARGS)
                    161:            db_macro_args[db_macro_level+1][n++] = 0;
                    162:        db_macro_level++;
                    163:        db_exec_cmd_nest(mp->m_lbuf, mp->m_size);
                    164:        db_macro_level--;
                    165:        return(0);
                    166: }
                    167: 
1.1.1.4 ! root      168: void
1.1       root      169: /* ARGSUSED */
1.1.1.4 ! root      170: db_arg_variable(
        !           171:        struct db_variable      *vp,
        !           172:        db_expr_t               *valuep,
        !           173:        int                     flag,
        !           174:        db_var_aux_param_t      ap)
1.1       root      175: {
                    176:        if (ap->level != 1 || ap->suffix[0] < 1 || ap->suffix[0] > DB_NARGS) {
                    177:            db_error("Bad $arg variable\n");
                    178:            /* NOTREACHED */
                    179:        }
                    180:        if (flag == DB_VAR_GET)
                    181:            *valuep = db_macro_args[db_macro_level][ap->suffix[0]-1];
                    182:        else
                    183:            db_macro_args[db_macro_level][ap->suffix[0]-1] = *valuep;
1.1.1.4 ! root      184:        return;
1.1       root      185: }
                    186: 
1.1.1.2   root      187: #endif /* MACH_KDB */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.