|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * The contents of this file constitute Original Code as defined in and ! 7: * are subject to the Apple Public Source License Version 1.1 (the ! 8: * "License"). You may not use this file except in compliance with the ! 9: * License. Please obtain a copy of the License at ! 10: * http://www.apple.com/publicsource and read it before using this file. ! 11: * ! 12: * This Original Code and all software distributed under the License are ! 13: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 14: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 15: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 16: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 17: * License for the specific language governing rights and limitations ! 18: * under the License. ! 19: * ! 20: * @APPLE_LICENSE_HEADER_END@ ! 21: */ ! 22: /* ! 23: * @OSF_COPYRIGHT@ ! 24: */ ! 25: /* ! 26: * HISTORY ! 27: * ! 28: * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez ! 29: * Import of Mac OS X kernel (~semeria) ! 30: * ! 31: * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez ! 32: * Import of OSF Mach kernel (~mburg) ! 33: * ! 34: * Revision 1.2.10.4 1996/01/09 19:15:54 devrcs ! 35: * Change 'register foo' to 'register int foo'. ! 36: * [1995/12/01 21:42:14 jfraser] ! 37: * ! 38: * Merged '64-bit safe' changes from DEC alpha port. ! 39: * [1995/11/21 18:03:15 jfraser] ! 40: * ! 41: * Revision 1.2.10.3 1995/01/06 19:10:28 devrcs ! 42: * mk6 CR668 - 1.3b26 merge ! 43: * fix typing ! 44: * [1994/11/04 08:49:38 dwm] ! 45: * ! 46: * Revision 1.2.10.2 1994/09/23 01:20:19 ezf ! 47: * change marker to not FREE ! 48: * [1994/09/22 21:10:23 ezf] ! 49: * ! 50: * Revision 1.2.10.1 1994/06/11 21:11:52 bolinger ! 51: * Merge up to NMK17.2. ! 52: * [1994/06/11 20:01:51 bolinger] ! 53: * ! 54: * Revision 1.2.8.1 1994/02/08 10:58:03 bernadat ! 55: * Fixed reinitialization of db_macro_level to -1. ! 56: * Put DB_MACRO_LEVEL and DB_NARGS macros to <ddb/db_variables.h>. ! 57: * Changed name of DB_NARGS to DB_MACRO_NARGS. ! 58: * Added support of DB_VAR_SHOW. ! 59: * [93/08/12 paire] ! 60: * [94/02/07 bernadat] ! 61: * ! 62: * Revision 1.2.2.4 1993/08/11 20:37:58 elliston ! 63: * Add ANSI Prototypes. CR #9523. ! 64: * [1993/08/11 03:33:33 elliston] ! 65: * ! 66: * Revision 1.2.2.3 1993/07/27 18:27:42 elliston ! 67: * Add ANSI prototypes. CR #9523. ! 68: * [1993/07/27 18:12:24 elliston] ! 69: * ! 70: * Revision 1.2.2.2 1993/06/09 02:20:18 gm ! 71: * Added to OSF/1 R1.3 from NMK15.0. ! 72: * [1993/06/02 20:56:40 jeffc] ! 73: * ! 74: * Revision 1.2 1993/04/19 16:02:25 devrcs ! 75: * Changes from mk78: ! 76: * Removed unused variable from db_exec_macro(). ! 77: * Added include of <ddb/db_command.h>. ! 78: * [92/05/16 jfriedl] ! 79: * [93/02/02 bruel] ! 80: * ! 81: * Revision 1.1 1992/09/30 02:01:12 robert ! 82: * Initial revision ! 83: * ! 84: * $EndLog$ ! 85: */ ! 86: /* CMU_HIST */ ! 87: /* ! 88: * Revision 2.2 91/10/09 16:01:09 af ! 89: * Revision 2.1.3.1 91/10/05 13:06:40 jeffreyh ! 90: * Created for macro support. ! 91: * [91/08/29 tak] ! 92: * ! 93: * Revision 2.1.3.1 91/10/05 13:06:40 jeffreyh ! 94: * Created for macro support. ! 95: * [91/08/29 tak] ! 96: * ! 97: */ ! 98: /* CMU_ENDHIST */ ! 99: /* ! 100: * Mach Operating System ! 101: * Copyright (c) 1991,1990 Carnegie Mellon University ! 102: * All Rights Reserved. ! 103: * ! 104: * Permission to use, copy, modify and distribute this software and its ! 105: * documentation is hereby granted, provided that both the copyright ! 106: * notice and this permission notice appear in all copies of the ! 107: * software, derivative works or modified versions, and any portions ! 108: * thereof, and that both notices appear in supporting documentation. ! 109: * ! 110: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" ! 111: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR ! 112: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. ! 113: * ! 114: * Carnegie Mellon requests users of this software to return to ! 115: * ! 116: * Software Distribution Coordinator or [email protected] ! 117: * School of Computer Science ! 118: * Carnegie Mellon University ! 119: * Pittsburgh PA 15213-3890 ! 120: * ! 121: * any improvements or extensions that they make and grant Carnegie Mellon ! 122: * the rights to redistribute these changes. ! 123: */ ! 124: /* ! 125: */ ! 126: #include <kern/thread.h> ! 127: #include <string.h> /* For strcmp(), strcpy() */ ! 128: ! 129: #include <machine/db_machdep.h> ! 130: #include <ddb/db_command.h> ! 131: #include <ddb/db_expr.h> ! 132: #include <ddb/db_lex.h> ! 133: #include <ddb/db_macro.h> ! 134: #include <ddb/db_output.h> /* For db_printf() */ ! 135: #include <ddb/db_sym.h> ! 136: #include <ddb/db_variables.h> ! 137: ! 138: /* ! 139: * debugger macro support ! 140: */ ! 141: ! 142: #define DB_NUSER_MACRO 10 /* max user macros */ ! 143: ! 144: int db_macro_free = DB_NUSER_MACRO; ! 145: struct db_user_macro { ! 146: char m_name[TOK_STRING_SIZE]; ! 147: char m_lbuf[DB_LEX_LINE_SIZE]; ! 148: int m_size; ! 149: } db_user_macro[DB_NUSER_MACRO]; ! 150: ! 151: int db_macro_level = -1; ! 152: db_expr_t db_macro_args[DB_MACRO_LEVEL][DB_MACRO_NARGS]; ! 153: ! 154: ! 155: /* Prototypes for functions local to this file. ! 156: */ ! 157: static struct db_user_macro *db_lookup_macro(char *name); ! 158: ! 159: ! 160: static struct db_user_macro * ! 161: db_lookup_macro(char *name) ! 162: { ! 163: register struct db_user_macro *mp; ! 164: ! 165: for (mp = db_user_macro; mp < &db_user_macro[DB_NUSER_MACRO]; mp++) { ! 166: if (mp->m_name[0] == 0) ! 167: continue; ! 168: if (strcmp(mp->m_name, name) == 0) ! 169: return(mp); ! 170: } ! 171: return(0); ! 172: } ! 173: ! 174: void ! 175: db_def_macro_cmd(void) ! 176: { ! 177: register char *p; ! 178: register int c; ! 179: register struct db_user_macro *mp, *ep; ! 180: ! 181: if (db_read_token() != tIDENT) { ! 182: db_printf("Bad macro name \"%s\"\n", db_tok_string); ! 183: db_error(0); ! 184: /* NOTREACHED */ ! 185: } ! 186: if ((mp = db_lookup_macro(db_tok_string)) == 0) { ! 187: if (db_macro_free <= 0) ! 188: db_error("Too many macros\n"); ! 189: /* NOTREACHED */ ! 190: ep = &db_user_macro[DB_NUSER_MACRO]; ! 191: for (mp = db_user_macro; mp < ep && mp->m_name[0]; mp++); ! 192: if (mp >= ep) ! 193: db_error("ddb: internal error(macro)\n"); ! 194: /* NOTREACHED */ ! 195: db_macro_free--; ! 196: strcpy(mp->m_name, db_tok_string); ! 197: } ! 198: for (c = db_read_char(); c == ' ' || c == '\t'; c = db_read_char()); ! 199: for (p = mp->m_lbuf; c > 0; c = db_read_char()) ! 200: *p++ = c; ! 201: *p = 0; ! 202: mp->m_size = p - mp->m_lbuf; ! 203: } ! 204: ! 205: void ! 206: db_del_macro_cmd(void) ! 207: { ! 208: register struct db_user_macro *mp; ! 209: ! 210: if (db_read_token() != tIDENT ! 211: || (mp = db_lookup_macro(db_tok_string)) == 0) { ! 212: db_printf("No such macro \"%s\"\n", db_tok_string); ! 213: db_error(0); ! 214: /* NOTREACHED */ ! 215: } ! 216: mp->m_name[0] = 0; ! 217: db_macro_free++; ! 218: } ! 219: ! 220: void ! 221: db_show_macro(void) ! 222: { ! 223: register struct db_user_macro *mp; ! 224: int t; ! 225: char *name = 0; ! 226: ! 227: if ((t = db_read_token()) == tIDENT) ! 228: name = db_tok_string; ! 229: else ! 230: db_unread_token(t); ! 231: for (mp = db_user_macro; mp < &db_user_macro[DB_NUSER_MACRO]; mp++) { ! 232: if (mp->m_name[0] == 0) ! 233: continue; ! 234: if (name && strcmp(mp->m_name, name)) ! 235: continue; ! 236: db_printf("%s: %s", mp->m_name, mp->m_lbuf); ! 237: } ! 238: } ! 239: ! 240: int ! 241: db_exec_macro(char *name) ! 242: { ! 243: register struct db_user_macro *mp; ! 244: register int n; ! 245: ! 246: if ((mp = db_lookup_macro(name)) == 0) ! 247: return(-1); ! 248: if (db_macro_level+1 >= DB_MACRO_LEVEL) { ! 249: db_macro_level = -1; ! 250: db_error("Too many macro nest\n"); ! 251: /* NOTREACHED */ ! 252: } ! 253: for (n = 0; ! 254: n < DB_MACRO_NARGS && ! 255: db_expression(&db_macro_args[db_macro_level+1][n]); ! 256: n++); ! 257: while (n < DB_MACRO_NARGS) ! 258: db_macro_args[db_macro_level+1][n++] = 0; ! 259: db_macro_level++; ! 260: db_exec_cmd_nest(mp->m_lbuf, mp->m_size); ! 261: db_macro_level--; ! 262: return(0); ! 263: } ! 264: ! 265: int ! 266: db_arg_variable( ! 267: struct db_variable *vp, ! 268: db_expr_t *valuep, ! 269: int flag, ! 270: db_var_aux_param_t ap) ! 271: { ! 272: db_expr_t value; ! 273: char *name; ! 274: db_addr_t offset; ! 275: ! 276: if (flag == DB_VAR_SHOW) { ! 277: value = db_macro_args[ap->hidden_level][ap->suffix[0]-1]; ! 278: db_printf("%#n", value); ! 279: db_find_xtrn_task_sym_and_offset(value, &name, &offset, TASK_NULL); ! 280: if (name != (char *)0 && offset <= db_maxoff && offset != value) { ! 281: db_printf("\t%s", name); ! 282: if (offset != 0) ! 283: db_printf("+%#r", offset); ! 284: } ! 285: return(0); ! 286: } ! 287: ! 288: if (ap->level != 1 || ap->suffix[0] < 1 || ! 289: ap->suffix[0] > DB_MACRO_NARGS) { ! 290: db_error("Bad $arg variable\n"); ! 291: /* NOTREACHED */ ! 292: } ! 293: if (flag == DB_VAR_GET) ! 294: *valuep = db_macro_args[db_macro_level][ap->suffix[0]-1]; ! 295: else ! 296: db_macro_args[db_macro_level][ap->suffix[0]-1] = *valuep; ! 297: return(0); ! 298: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.