]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_macro.c
19c210e27302eeef15155730b2559d34e37ccd78
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
60 #include <kern/thread.h>
61 #include <string.h> /* For strcmp(), strcpy() */
63 #include <machine/db_machdep.h>
64 #include <ddb/db_command.h>
65 #include <ddb/db_expr.h>
66 #include <ddb/db_lex.h>
67 #include <ddb/db_macro.h>
68 #include <ddb/db_output.h> /* For db_printf() */
69 #include <ddb/db_sym.h>
70 #include <ddb/db_variables.h>
73 * debugger macro support
76 #define DB_NUSER_MACRO 10 /* max user macros */
78 int db_macro_free
= DB_NUSER_MACRO
;
79 struct db_user_macro
{
80 char m_name
[TOK_STRING_SIZE
];
81 char m_lbuf
[DB_LEX_LINE_SIZE
];
83 } db_user_macro
[DB_NUSER_MACRO
];
85 int db_macro_level
= -1;
86 db_expr_t db_macro_args
[DB_MACRO_LEVEL
][DB_MACRO_NARGS
];
89 /* Prototypes for functions local to this file.
91 static struct db_user_macro
*db_lookup_macro(char *name
);
94 static struct db_user_macro
*
95 db_lookup_macro(char *name
)
97 register struct db_user_macro
*mp
;
99 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
100 if (mp
->m_name
[0] == 0)
102 if (strcmp(mp
->m_name
, name
) == 0)
109 db_def_macro_cmd(void)
113 register struct db_user_macro
*mp
, *ep
;
115 if (db_read_token() != tIDENT
) {
116 db_printf("Bad macro name \"%s\"\n", db_tok_string
);
120 if ((mp
= db_lookup_macro(db_tok_string
)) == 0) {
121 if (db_macro_free
<= 0)
122 db_error("Too many macros\n");
124 ep
= &db_user_macro
[DB_NUSER_MACRO
];
125 for (mp
= db_user_macro
; mp
< ep
&& mp
->m_name
[0]; mp
++);
127 db_error("ddb: internal error(macro)\n");
130 strcpy(mp
->m_name
, db_tok_string
);
132 for (c
= db_read_char(); c
== ' ' || c
== '\t'; c
= db_read_char());
133 for (p
= mp
->m_lbuf
; c
> 0; c
= db_read_char())
136 mp
->m_size
= p
- mp
->m_lbuf
;
140 db_del_macro_cmd(void)
142 register struct db_user_macro
*mp
;
144 if (db_read_token() != tIDENT
145 || (mp
= db_lookup_macro(db_tok_string
)) == 0) {
146 db_printf("No such macro \"%s\"\n", db_tok_string
);
157 register struct db_user_macro
*mp
;
161 if ((t
= db_read_token()) == tIDENT
)
162 name
= db_tok_string
;
165 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
166 if (mp
->m_name
[0] == 0)
168 if (name
&& strcmp(mp
->m_name
, name
))
170 db_printf("%s: %s", mp
->m_name
, mp
->m_lbuf
);
175 db_exec_macro(char *name
)
177 register struct db_user_macro
*mp
;
180 if ((mp
= db_lookup_macro(name
)) == 0)
182 if (db_macro_level
+1 >= DB_MACRO_LEVEL
) {
184 db_error("Too many macro nest\n");
188 n
< DB_MACRO_NARGS
&&
189 db_expression(&db_macro_args
[db_macro_level
+1][n
]);
191 while (n
< DB_MACRO_NARGS
)
192 db_macro_args
[db_macro_level
+1][n
++] = 0;
194 db_exec_cmd_nest(mp
->m_lbuf
, mp
->m_size
);
201 struct db_variable
*vp
,
204 db_var_aux_param_t ap
)
210 if (flag
== DB_VAR_SHOW
) {
211 value
= db_macro_args
[ap
->hidden_level
][ap
->suffix
[0]-1];
212 db_printf("%#lln", (unsigned long long)value
);
213 db_find_xtrn_task_sym_and_offset(value
, &name
, &offset
, TASK_NULL
);
214 if (name
!= (char *)0 && offset
<= db_maxoff
&& offset
!= value
) {
215 db_printf("\t%s", name
);
217 db_printf("+%#llr", (unsigned long long)offset
);
222 if (ap
->level
!= 1 || ap
->suffix
[0] < 1 ||
223 ap
->suffix
[0] > DB_MACRO_NARGS
) {
224 db_error("Bad $arg variable\n");
227 if (flag
== DB_VAR_GET
)
228 *valuep
= db_macro_args
[db_macro_level
][ap
->suffix
[0]-1];
230 db_macro_args
[db_macro_level
][ap
->suffix
[0]-1] = *valuep
;