]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_macro.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
28 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
32 * Import of OSF Mach kernel (~mburg)
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]
38 * Merged '64-bit safe' changes from DEC alpha port.
39 * [1995/11/21 18:03:15 jfraser]
41 * Revision 1.2.10.3 1995/01/06 19:10:28 devrcs
42 * mk6 CR668 - 1.3b26 merge
44 * [1994/11/04 08:49:38 dwm]
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]
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]
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.
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]
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]
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]
74 * Revision 1.2 1993/04/19 16:02:25 devrcs
76 * Removed unused variable from db_exec_macro().
77 * Added include of <ddb/db_command.h>.
81 * Revision 1.1 1992/09/30 02:01:12 robert
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.
93 * Revision 2.1.3.1 91/10/05 13:06:40 jeffreyh
94 * Created for macro support.
100 * Mach Operating System
101 * Copyright (c) 1991,1990 Carnegie Mellon University
102 * All Rights Reserved.
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.
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.
114 * Carnegie Mellon requests users of this software to return to
116 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
117 * School of Computer Science
118 * Carnegie Mellon University
119 * Pittsburgh PA 15213-3890
121 * any improvements or extensions that they make and grant Carnegie Mellon
122 * the rights to redistribute these changes.
126 #include <kern/thread.h>
127 #include <string.h> /* For strcmp(), strcpy() */
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>
139 * debugger macro support
142 #define DB_NUSER_MACRO 10 /* max user macros */
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
];
149 } db_user_macro
[DB_NUSER_MACRO
];
151 int db_macro_level
= -1;
152 db_expr_t db_macro_args
[DB_MACRO_LEVEL
][DB_MACRO_NARGS
];
155 /* Prototypes for functions local to this file.
157 static struct db_user_macro
*db_lookup_macro(char *name
);
160 static struct db_user_macro
*
161 db_lookup_macro(char *name
)
163 register struct db_user_macro
*mp
;
165 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
166 if (mp
->m_name
[0] == 0)
168 if (strcmp(mp
->m_name
, name
) == 0)
175 db_def_macro_cmd(void)
179 register struct db_user_macro
*mp
, *ep
;
181 if (db_read_token() != tIDENT
) {
182 db_printf("Bad macro name \"%s\"\n", db_tok_string
);
186 if ((mp
= db_lookup_macro(db_tok_string
)) == 0) {
187 if (db_macro_free
<= 0)
188 db_error("Too many macros\n");
190 ep
= &db_user_macro
[DB_NUSER_MACRO
];
191 for (mp
= db_user_macro
; mp
< ep
&& mp
->m_name
[0]; mp
++);
193 db_error("ddb: internal error(macro)\n");
196 strcpy(mp
->m_name
, db_tok_string
);
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())
202 mp
->m_size
= p
- mp
->m_lbuf
;
206 db_del_macro_cmd(void)
208 register struct db_user_macro
*mp
;
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
);
223 register struct db_user_macro
*mp
;
227 if ((t
= db_read_token()) == tIDENT
)
228 name
= db_tok_string
;
231 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
232 if (mp
->m_name
[0] == 0)
234 if (name
&& strcmp(mp
->m_name
, name
))
236 db_printf("%s: %s", mp
->m_name
, mp
->m_lbuf
);
241 db_exec_macro(char *name
)
243 register struct db_user_macro
*mp
;
246 if ((mp
= db_lookup_macro(name
)) == 0)
248 if (db_macro_level
+1 >= DB_MACRO_LEVEL
) {
250 db_error("Too many macro nest\n");
254 n
< DB_MACRO_NARGS
&&
255 db_expression(&db_macro_args
[db_macro_level
+1][n
]);
257 while (n
< DB_MACRO_NARGS
)
258 db_macro_args
[db_macro_level
+1][n
++] = 0;
260 db_exec_cmd_nest(mp
->m_lbuf
, mp
->m_size
);
267 struct db_variable
*vp
,
270 db_var_aux_param_t ap
)
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
);
283 db_printf("+%#r", offset
);
288 if (ap
->level
!= 1 || ap
->suffix
[0] < 1 ||
289 ap
->suffix
[0] > DB_MACRO_NARGS
) {
290 db_error("Bad $arg variable\n");
293 if (flag
== DB_VAR_GET
)
294 *valuep
= db_macro_args
[db_macro_level
][ap
->suffix
[0]-1];
296 db_macro_args
[db_macro_level
][ap
->suffix
[0]-1] = *valuep
;