]>
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 * 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@
29 * Mach Operating System
30 * Copyright (c) 1991,1990 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
55 #include <kern/thread.h>
56 #include <string.h> /* For strcmp(), strcpy() */
58 #include <machine/db_machdep.h>
59 #include <ddb/db_command.h>
60 #include <ddb/db_expr.h>
61 #include <ddb/db_lex.h>
62 #include <ddb/db_macro.h>
63 #include <ddb/db_output.h> /* For db_printf() */
64 #include <ddb/db_sym.h>
65 #include <ddb/db_variables.h>
68 * debugger macro support
71 #define DB_NUSER_MACRO 10 /* max user macros */
73 int db_macro_free
= DB_NUSER_MACRO
;
74 struct db_user_macro
{
75 char m_name
[TOK_STRING_SIZE
];
76 char m_lbuf
[DB_LEX_LINE_SIZE
];
78 } db_user_macro
[DB_NUSER_MACRO
];
80 int db_macro_level
= -1;
81 db_expr_t db_macro_args
[DB_MACRO_LEVEL
][DB_MACRO_NARGS
];
84 /* Prototypes for functions local to this file.
86 static struct db_user_macro
*db_lookup_macro(char *name
);
89 static struct db_user_macro
*
90 db_lookup_macro(char *name
)
92 register struct db_user_macro
*mp
;
94 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
95 if (mp
->m_name
[0] == 0)
97 if (strcmp(mp
->m_name
, name
) == 0)
104 db_def_macro_cmd(void)
108 register struct db_user_macro
*mp
, *ep
;
110 if (db_read_token() != tIDENT
) {
111 db_printf("Bad macro name \"%s\"\n", db_tok_string
);
115 if ((mp
= db_lookup_macro(db_tok_string
)) == 0) {
116 if (db_macro_free
<= 0)
117 db_error("Too many macros\n");
119 ep
= &db_user_macro
[DB_NUSER_MACRO
];
120 for (mp
= db_user_macro
; mp
< ep
&& mp
->m_name
[0]; mp
++);
122 db_error("ddb: internal error(macro)\n");
125 strcpy(mp
->m_name
, db_tok_string
);
127 for (c
= db_read_char(); c
== ' ' || c
== '\t'; c
= db_read_char());
128 for (p
= mp
->m_lbuf
; c
> 0; c
= db_read_char())
131 mp
->m_size
= p
- mp
->m_lbuf
;
135 db_del_macro_cmd(void)
137 register struct db_user_macro
*mp
;
139 if (db_read_token() != tIDENT
140 || (mp
= db_lookup_macro(db_tok_string
)) == 0) {
141 db_printf("No such macro \"%s\"\n", db_tok_string
);
152 register struct db_user_macro
*mp
;
156 if ((t
= db_read_token()) == tIDENT
)
157 name
= db_tok_string
;
160 for (mp
= db_user_macro
; mp
< &db_user_macro
[DB_NUSER_MACRO
]; mp
++) {
161 if (mp
->m_name
[0] == 0)
163 if (name
&& strcmp(mp
->m_name
, name
))
165 db_printf("%s: %s", mp
->m_name
, mp
->m_lbuf
);
170 db_exec_macro(char *name
)
172 register struct db_user_macro
*mp
;
175 if ((mp
= db_lookup_macro(name
)) == 0)
177 if (db_macro_level
+1 >= DB_MACRO_LEVEL
) {
179 db_error("Too many macro nest\n");
183 n
< DB_MACRO_NARGS
&&
184 db_expression(&db_macro_args
[db_macro_level
+1][n
]);
186 while (n
< DB_MACRO_NARGS
)
187 db_macro_args
[db_macro_level
+1][n
++] = 0;
189 db_exec_cmd_nest(mp
->m_lbuf
, mp
->m_size
);
196 struct db_variable
*vp
,
199 db_var_aux_param_t ap
)
205 if (flag
== DB_VAR_SHOW
) {
206 value
= db_macro_args
[ap
->hidden_level
][ap
->suffix
[0]-1];
207 db_printf("%#lln", value
);
208 db_find_xtrn_task_sym_and_offset(value
, &name
, &offset
, TASK_NULL
);
209 if (name
!= (char *)0 && offset
<= db_maxoff
&& offset
!= value
) {
210 db_printf("\t%s", name
);
212 db_printf("+%#r", offset
);
217 if (ap
->level
!= 1 || ap
->suffix
[0] < 1 ||
218 ap
->suffix
[0] > DB_MACRO_NARGS
) {
219 db_error("Bad $arg variable\n");
222 if (flag
== DB_VAR_GET
)
223 *valuep
= db_macro_args
[db_macro_level
][ap
->suffix
[0]-1];
225 db_macro_args
[db_macro_level
][ap
->suffix
[0]-1] = *valuep
;