]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_macro.c
84bf7be03c2f566c924b662f1fa70bd2dbaa8122
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
53 #include <kern/thread.h>
54 #include <string.h> /* For strcmp(), strcpy() */
56 #include <machine/db_machdep.h>
57 #include <ddb/db_command.h>
58 #include <ddb/db_expr.h>
59 #include <ddb/db_lex.h>
60 #include <ddb/db_macro.h>
61 #include <ddb/db_output.h> /* For db_printf() */
62 #include <ddb/db_sym.h>
63 #include <ddb/db_variables.h>
66 * debugger macro support
69 #define DB_NUSER_MACRO 10 /* max user macros */
71 int db_macro_free
= DB_NUSER_MACRO
;
72 struct db_user_macro
{
73 char m_name
[TOK_STRING_SIZE
];
74 char m_lbuf
[DB_LEX_LINE_SIZE
];
76 } db_user_macro
[DB_NUSER_MACRO
];
78 int db_macro_level
= -1;
79 db_expr_t db_macro_args
[DB_MACRO_LEVEL
][DB_MACRO_NARGS
];
82 /* Prototypes for functions local to this file.
84 static struct db_user_macro
*db_lookup_macro(char *name
);
87 static struct db_user_macro
*
88 db_lookup_macro(char *name
)
90 register struct db_user_macro
*mp
;
92 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
93 if (mp
->m_name
[0] == 0)
95 if (strcmp(mp
->m_name
, name
) == 0)
102 db_def_macro_cmd(void)
106 register struct db_user_macro
*mp
, *ep
;
108 if (db_read_token() != tIDENT
) {
109 db_printf("Bad macro name \"%s\"\n", db_tok_string
);
113 if ((mp
= db_lookup_macro(db_tok_string
)) == 0) {
114 if (db_macro_free
<= 0)
115 db_error("Too many macros\n");
117 ep
= &db_user_macro
[DB_NUSER_MACRO
];
118 for (mp
= db_user_macro
; mp
< ep
&& mp
->m_name
[0]; mp
++);
120 db_error("ddb: internal error(macro)\n");
123 strcpy(mp
->m_name
, db_tok_string
);
125 for (c
= db_read_char(); c
== ' ' || c
== '\t'; c
= db_read_char());
126 for (p
= mp
->m_lbuf
; c
> 0; c
= db_read_char())
129 mp
->m_size
= p
- mp
->m_lbuf
;
133 db_del_macro_cmd(void)
135 register struct db_user_macro
*mp
;
137 if (db_read_token() != tIDENT
138 || (mp
= db_lookup_macro(db_tok_string
)) == 0) {
139 db_printf("No such macro \"%s\"\n", db_tok_string
);
150 register struct db_user_macro
*mp
;
154 if ((t
= db_read_token()) == tIDENT
)
155 name
= db_tok_string
;
158 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
159 if (mp
->m_name
[0] == 0)
161 if (name
&& strcmp(mp
->m_name
, name
))
163 db_printf("%s: %s", mp
->m_name
, mp
->m_lbuf
);
168 db_exec_macro(char *name
)
170 register struct db_user_macro
*mp
;
173 if ((mp
= db_lookup_macro(name
)) == 0)
175 if (db_macro_level
+1 >= DB_MACRO_LEVEL
) {
177 db_error("Too many macro nest\n");
181 n
< DB_MACRO_NARGS
&&
182 db_expression(&db_macro_args
[db_macro_level
+1][n
]);
184 while (n
< DB_MACRO_NARGS
)
185 db_macro_args
[db_macro_level
+1][n
++] = 0;
187 db_exec_cmd_nest(mp
->m_lbuf
, mp
->m_size
);
194 struct db_variable
*vp
,
197 db_var_aux_param_t ap
)
203 if (flag
== DB_VAR_SHOW
) {
204 value
= db_macro_args
[ap
->hidden_level
][ap
->suffix
[0]-1];
205 db_printf("%#lln", (unsigned long long)value
);
206 db_find_xtrn_task_sym_and_offset(value
, &name
, &offset
, TASK_NULL
);
207 if (name
!= (char *)0 && offset
<= db_maxoff
&& offset
!= value
) {
208 db_printf("\t%s", name
);
210 db_printf("+%#llr", (unsigned long long)offset
);
215 if (ap
->level
!= 1 || ap
->suffix
[0] < 1 ||
216 ap
->suffix
[0] > DB_MACRO_NARGS
) {
217 db_error("Bad $arg variable\n");
220 if (flag
== DB_VAR_GET
)
221 *valuep
= db_macro_args
[db_macro_level
][ap
->suffix
[0]-1];
223 db_macro_args
[db_macro_level
][ap
->suffix
[0]-1] = *valuep
;