]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_expr.c
dc49ab9bdb3b09ca1eac4628eae2325813756441
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.19.1 1997/03/27 18:46:35 barbou
38 * ri-osc CR1561: make operators "logical and", "logical or"
40 * [1995/09/20 15:26:38 bolinger]
43 * Revision 1.2.10.2 1995/01/06 19:10:13 devrcs
44 * mk6 CR668 - 1.3b26 merge
45 * * Revision 1.2.3.5 1994/05/06 18:39:16 tmt
46 * Merged osc1.3dec/shared with osc1.3b19
47 * Merge Alpha changes into osc1.312b source code.
50 * [1994/11/04 08:49:27 dwm]
52 * Revision 1.2.10.1 1994/09/23 01:19:06 ezf
53 * change marker to not FREE
54 * [1994/09/22 21:09:53 ezf]
56 * Revision 1.2.3.3 1993/07/27 18:27:15 elliston
57 * Add ANSI prototypes. CR #9523.
58 * [1993/07/27 18:11:36 elliston]
60 * Revision 1.2.3.2 1993/06/09 02:20:06 gm
61 * Added to OSF/1 R1.3 from NMK15.0.
62 * [1993/06/02 20:56:16 jeffc]
64 * Revision 1.2 1993/04/19 16:02:09 devrcs
65 * Allow unprefixed (0x) hexadecimal constants starting by a letter:
66 * unknown symbols are tentatively interpreted as hexadecimal constants,
67 * and ambiguities are reported.
71 * Removed unused variable from db_unary().
75 * Added string format arguments [barbou@gr.osf.org]
78 * Revision 1.1 1992/09/30 02:01:04 robert
85 * Revision 2.5 91/10/09 15:59:46 af
86 * Revision 2.4.3.1 91/10/05 13:06:04 jeffreyh
87 * Added relational expression etc. to support condition expression.
88 * Supported modifier after indirect expression to specify size,
89 * sign extention and non current task space indirection.
90 * Changed error messages to print more information.
93 * Revision 2.4.3.1 91/10/05 13:06:04 jeffreyh
94 * Added relational expression etc. to support condition expression.
95 * Supported modifier after indirect expression to specify size,
96 * sign extention and non current task space indirection.
97 * Changed error messages to print more information.
100 * Revision 2.4 91/05/14 15:33:45 mrt
101 * Correcting copyright
103 * Revision 2.3 91/02/05 17:06:25 mrt
104 * Changed to new Mach copyright
105 * [91/01/31 16:17:46 mrt]
107 * Revision 2.2 90/08/27 21:50:57 dbg
108 * Use '..' instead of '$$' for db_prev.
109 * Use '+' for db_next.
112 * Allow repeated unary operators.
115 * Reflected back rename of db_symbol_value->db_value_of_name
125 * Mach Operating System
126 * Copyright (c) 1991,1990 Carnegie Mellon University
127 * All Rights Reserved.
129 * Permission to use, copy, modify and distribute this software and its
130 * documentation is hereby granted, provided that both the copyright
131 * notice and this permission notice appear in all copies of the
132 * software, derivative works or modified versions, and any portions
133 * thereof, and that both notices appear in supporting documentation.
135 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
136 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
137 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
139 * Carnegie Mellon requests users of this software to return to
141 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
142 * School of Computer Science
143 * Carnegie Mellon University
144 * Pittsburgh PA 15213-3890
146 * any improvements or extensions that they make and grant Carnegie Mellon
147 * the rights to redistribute these changes.
152 * Author: David B. Golub, Carnegie Mellon University
156 #include <mach/boolean.h>
157 #include <machine/db_machdep.h>
158 #include <ddb/db_access.h>
159 #include <ddb/db_command.h>
160 #include <ddb/db_expr.h>
161 #include <ddb/db_lex.h>
162 #include <ddb/db_output.h> /* For db_printf() */
163 #include <ddb/db_sym.h>
164 #include <ddb/db_variables.h>
165 #include <kern/task.h>
169 /* Prototypes for functions local to this file. XXX -- should be static!
171 boolean_t
db_term(db_expr_t
*valuep
);
172 boolean_t
db_unary(db_expr_t
*valuep
);
173 boolean_t
db_mult_expr(db_expr_t
*valuep
);
174 boolean_t
db_add_expr(db_expr_t
*valuep
);
175 boolean_t
db_shift_expr(db_expr_t
*valuep
);
176 boolean_t
db_logical_relation_expr(db_expr_t
*valuep
);
177 boolean_t
db_logical_and_expr(db_expr_t
*valuep
);
178 boolean_t
db_logical_or_expr(db_expr_t
*valuep
);
181 /* try to interpret unknown symbols as hexadecimal constants */
182 int db_allow_unprefixed_hexa
= 1;
185 db_term(db_expr_t
*valuep
)
188 boolean_t valid_symbol
= FALSE
;
189 boolean_t valid_hexa
= FALSE
;
191 switch(t
= db_read_token()) {
193 if (db_value_of_name(db_tok_string
, valuep
)) {
196 if (db_allow_unprefixed_hexa
&& db_radix
== 16 &&
203 for (cp
= db_tok_string
; *cp
; cp
++) {
204 if (*cp
>= 'a' && *cp
<= 'f') {
205 value
= value
* 16 + 10 + (*cp
- 'a');
206 } else if (*cp
>= 'A' && *cp
<= 'F') {
207 value
= value
* 16 + 10 + (*cp
- 'A');
208 } else if (*cp
>= '0' && *cp
<= '9') {
209 value
= value
* 16 + (*cp
- '0');
217 db_printf("Ambiguous constant %x used as a symbol\n",
220 *valuep
= (db_expr_t
)value
;
224 if (!valid_symbol
&& !valid_hexa
) {
225 db_printf("Symbol \"%s\" not found\n", db_tok_string
);
231 *valuep
= /*(db_expr_t)*/db_tok_number
;
234 *valuep
= (db_expr_t
)db_dot
;
237 *valuep
= (db_expr_t
)db_prev
;
240 *valuep
= (db_expr_t
) db_next
;
243 *valuep
= (db_expr_t
)db_last_addr
;
246 if (!db_get_variable(valuep
))
250 if (!db_expression(valuep
)) {
251 db_error("Unmached ()s\n");
256 db_printf("')' expected at \"%s...\"\n", db_tok_string
);
263 static db_tok_offset
= 0;
266 sp
= (char *)db_tok_string
+ db_tok_offset
;
267 *valuep
= *(int *)sp
;
269 *cp
&& cp
< sp
+ sizeof (int);
271 if (cp
== sp
+ sizeof (int) && *cp
) {
272 db_tok_offset
+= sizeof (int);
292 int size
= sizeof(int);
296 for (p
= modif
; *p
; p
++) {
302 size
= sizeof(short);
319 db_unary(db_expr_t
*valuep
)
323 boolean_t u_opt
, t_opt
;
325 extern task_t db_default_task
;
329 if (!db_unary(valuep
)) {
330 db_error("Expression syntax error after '-'\n");
338 if (!db_unary(valuep
)) {
339 db_error("Expression syntax error after '*'\n");
343 size
= sizeof(db_addr_t
);
346 if (t
== tIDENT
&& db_tok_string
[0] == ':') {
347 size
= db_size_option(&db_tok_string
[1], &u_opt
, &t_opt
);
349 task
= db_default_task
;
352 *valuep
= db_get_task_value((db_addr_t
)*valuep
, size
, !u_opt
, task
);
356 if (!db_unary(valuep
)) {
357 db_error("Expression syntax error after '!'\n");
360 *valuep
= (!(*valuep
));
364 return (db_term(valuep
));
368 db_mult_expr(db_expr_t
*valuep
)
378 while (t
== tSTAR
|| t
== tSLASH
|| t
== tPCT
|| t
== tHASH
380 c
= db_tok_string
[0];
381 if (!db_term(&rhs
)) {
382 db_printf("Expression syntax error after '%c'\n", c
);
395 db_error("Divide by 0\n");
403 lhs
= ((lhs
+rhs
-1)/rhs
)*rhs
;
413 db_add_expr(db_expr_t
*valuep
)
419 if (!db_mult_expr(&lhs
))
423 while (t
== tPLUS
|| t
== tMINUS
|| t
== tBIT_OR
) {
424 c
= db_tok_string
[0];
425 if (!db_mult_expr(&rhs
)) {
426 db_printf("Expression syntax error after '%c'\n", c
);
432 else if (t
== tMINUS
)
444 db_shift_expr(db_expr_t
*valuep
)
449 if (!db_add_expr(&lhs
))
453 while (t
== tSHIFT_L
|| t
== tSHIFT_R
) {
454 if (!db_add_expr(&rhs
)) {
455 db_printf("Expression syntax error after \"%s\"\n",
456 (t
== tSHIFT_L
)? "<<": ">>");
461 db_error("Negative shift amount\n");
467 /* Shift right is unsigned */
468 lhs
= (natural_t
) lhs
>> rhs
;
478 db_logical_relation_expr(db_expr_t
*valuep
)
484 if (!db_shift_expr(&lhs
))
488 while (t
== tLOG_EQ
|| t
== tLOG_NOT_EQ
489 || t
== tGREATER
|| t
== tGREATER_EQ
490 || t
== tLESS
|| t
== tLESS_EQ
) {
491 op
[0] = db_tok_string
[0];
492 op
[1] = db_tok_string
[1];
494 if (!db_shift_expr(&rhs
)) {
495 db_printf("Expression syntax error after \"%s\"\n", op
);
527 db_logical_and_expr(db_expr_t
*valuep
)
532 if (!db_logical_relation_expr(&lhs
))
536 while (t
== tLOG_AND
) {
537 if (!db_logical_relation_expr(&rhs
)) {
538 db_error("Expression syntax error after \"&&\"\n");
550 db_logical_or_expr(db_expr_t
*valuep
)
555 if (!db_logical_and_expr(&lhs
))
559 while (t
== tLOG_OR
) {
560 if (!db_logical_and_expr(&rhs
)) {
561 db_error("Expression syntax error after \"||\"\n");
573 db_expression(db_expr_t
*valuep
)
575 return (db_logical_or_expr(valuep
));