]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_macro.c
7e33231e7407bd1d7c0a5c62fab85da546493d23
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
31 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
32 * Import of Mac OS X kernel (~semeria)
34 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
35 * Import of OSF Mach kernel (~mburg)
37 * Revision 1.2.10.4 1996/01/09 19:15:54 devrcs
38 * Change 'register foo' to 'register int foo'.
39 * [1995/12/01 21:42:14 jfraser]
41 * Merged '64-bit safe' changes from DEC alpha port.
42 * [1995/11/21 18:03:15 jfraser]
44 * Revision 1.2.10.3 1995/01/06 19:10:28 devrcs
45 * mk6 CR668 - 1.3b26 merge
47 * [1994/11/04 08:49:38 dwm]
49 * Revision 1.2.10.2 1994/09/23 01:20:19 ezf
50 * change marker to not FREE
51 * [1994/09/22 21:10:23 ezf]
53 * Revision 1.2.10.1 1994/06/11 21:11:52 bolinger
54 * Merge up to NMK17.2.
55 * [1994/06/11 20:01:51 bolinger]
57 * Revision 1.2.8.1 1994/02/08 10:58:03 bernadat
58 * Fixed reinitialization of db_macro_level to -1.
59 * Put DB_MACRO_LEVEL and DB_NARGS macros to <ddb/db_variables.h>.
60 * Changed name of DB_NARGS to DB_MACRO_NARGS.
61 * Added support of DB_VAR_SHOW.
65 * Revision 1.2.2.4 1993/08/11 20:37:58 elliston
66 * Add ANSI Prototypes. CR #9523.
67 * [1993/08/11 03:33:33 elliston]
69 * Revision 1.2.2.3 1993/07/27 18:27:42 elliston
70 * Add ANSI prototypes. CR #9523.
71 * [1993/07/27 18:12:24 elliston]
73 * Revision 1.2.2.2 1993/06/09 02:20:18 gm
74 * Added to OSF/1 R1.3 from NMK15.0.
75 * [1993/06/02 20:56:40 jeffc]
77 * Revision 1.2 1993/04/19 16:02:25 devrcs
79 * Removed unused variable from db_exec_macro().
80 * Added include of <ddb/db_command.h>.
84 * Revision 1.1 1992/09/30 02:01:12 robert
91 * Revision 2.2 91/10/09 16:01:09 af
92 * Revision 2.1.3.1 91/10/05 13:06:40 jeffreyh
93 * Created for macro support.
96 * Revision 2.1.3.1 91/10/05 13:06:40 jeffreyh
97 * Created for macro support.
103 * Mach Operating System
104 * Copyright (c) 1991,1990 Carnegie Mellon University
105 * All Rights Reserved.
107 * Permission to use, copy, modify and distribute this software and its
108 * documentation is hereby granted, provided that both the copyright
109 * notice and this permission notice appear in all copies of the
110 * software, derivative works or modified versions, and any portions
111 * thereof, and that both notices appear in supporting documentation.
113 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
114 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
115 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
117 * Carnegie Mellon requests users of this software to return to
119 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
120 * School of Computer Science
121 * Carnegie Mellon University
122 * Pittsburgh PA 15213-3890
124 * any improvements or extensions that they make and grant Carnegie Mellon
125 * the rights to redistribute these changes.
129 #include <kern/thread.h>
130 #include <string.h> /* For strcmp(), strcpy() */
132 #include <machine/db_machdep.h>
133 #include <ddb/db_command.h>
134 #include <ddb/db_expr.h>
135 #include <ddb/db_lex.h>
136 #include <ddb/db_macro.h>
137 #include <ddb/db_output.h> /* For db_printf() */
138 #include <ddb/db_sym.h>
139 #include <ddb/db_variables.h>
142 * debugger macro support
145 #define DB_NUSER_MACRO 10 /* max user macros */
147 int db_macro_free
= DB_NUSER_MACRO
;
148 struct db_user_macro
{
149 char m_name
[TOK_STRING_SIZE
];
150 char m_lbuf
[DB_LEX_LINE_SIZE
];
152 } db_user_macro
[DB_NUSER_MACRO
];
154 int db_macro_level
= -1;
155 db_expr_t db_macro_args
[DB_MACRO_LEVEL
][DB_MACRO_NARGS
];
158 /* Prototypes for functions local to this file.
160 static struct db_user_macro
*db_lookup_macro(char *name
);
163 static struct db_user_macro
*
164 db_lookup_macro(char *name
)
166 register struct db_user_macro
*mp
;
168 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
169 if (mp
->m_name
[0] == 0)
171 if (strcmp(mp
->m_name
, name
) == 0)
178 db_def_macro_cmd(void)
182 register struct db_user_macro
*mp
, *ep
;
184 if (db_read_token() != tIDENT
) {
185 db_printf("Bad macro name \"%s\"\n", db_tok_string
);
189 if ((mp
= db_lookup_macro(db_tok_string
)) == 0) {
190 if (db_macro_free
<= 0)
191 db_error("Too many macros\n");
193 ep
= &db_user_macro
[DB_NUSER_MACRO
];
194 for (mp
= db_user_macro
; mp
< ep
&& mp
->m_name
[0]; mp
++);
196 db_error("ddb: internal error(macro)\n");
199 strcpy(mp
->m_name
, db_tok_string
);
201 for (c
= db_read_char(); c
== ' ' || c
== '\t'; c
= db_read_char());
202 for (p
= mp
->m_lbuf
; c
> 0; c
= db_read_char())
205 mp
->m_size
= p
- mp
->m_lbuf
;
209 db_del_macro_cmd(void)
211 register struct db_user_macro
*mp
;
213 if (db_read_token() != tIDENT
214 || (mp
= db_lookup_macro(db_tok_string
)) == 0) {
215 db_printf("No such macro \"%s\"\n", db_tok_string
);
226 register struct db_user_macro
*mp
;
230 if ((t
= db_read_token()) == tIDENT
)
231 name
= db_tok_string
;
234 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
235 if (mp
->m_name
[0] == 0)
237 if (name
&& strcmp(mp
->m_name
, name
))
239 db_printf("%s: %s", mp
->m_name
, mp
->m_lbuf
);
244 db_exec_macro(char *name
)
246 register struct db_user_macro
*mp
;
249 if ((mp
= db_lookup_macro(name
)) == 0)
251 if (db_macro_level
+1 >= DB_MACRO_LEVEL
) {
253 db_error("Too many macro nest\n");
257 n
< DB_MACRO_NARGS
&&
258 db_expression(&db_macro_args
[db_macro_level
+1][n
]);
260 while (n
< DB_MACRO_NARGS
)
261 db_macro_args
[db_macro_level
+1][n
++] = 0;
263 db_exec_cmd_nest(mp
->m_lbuf
, mp
->m_size
);
270 struct db_variable
*vp
,
273 db_var_aux_param_t ap
)
279 if (flag
== DB_VAR_SHOW
) {
280 value
= db_macro_args
[ap
->hidden_level
][ap
->suffix
[0]-1];
281 db_printf("%#n", value
);
282 db_find_xtrn_task_sym_and_offset(value
, &name
, &offset
, TASK_NULL
);
283 if (name
!= (char *)0 && offset
<= db_maxoff
&& offset
!= value
) {
284 db_printf("\t%s", name
);
286 db_printf("+%#r", offset
);
291 if (ap
->level
!= 1 || ap
->suffix
[0] < 1 ||
292 ap
->suffix
[0] > DB_MACRO_NARGS
) {
293 db_error("Bad $arg variable\n");
296 if (flag
== DB_VAR_GET
)
297 *valuep
= db_macro_args
[db_macro_level
][ap
->suffix
[0]-1];
299 db_macro_args
[db_macro_level
][ap
->suffix
[0]-1] = *valuep
;