2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34 * Revision 1.1.1.1 1998/09/22 21:05:47 wsanchez
35 * Import of Mac OS X kernel (~semeria)
37 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
38 * Import of OSF Mach kernel (~mburg)
40 * Revision 1.2.18.1 1997/03/27 18:46:29 barbou
41 * ri-osc CR1558: enable use of breakpoint counts even when no
43 * [1995/09/20 15:24:24 bolinger]
46 * Revision 1.2.6.2 1996/01/09 19:15:34 devrcs
47 * Change 'register c' to 'register int c'.
48 * [1995/12/01 21:42:00 jfraser]
50 * Merged '64-bit safe' changes from DEC alpha port.
51 * [1995/11/21 18:02:54 jfraser]
53 * Revision 1.2.6.1 1994/09/23 01:18:27 ezf
54 * change marker to not FREE
55 * [1994/09/22 21:09:37 ezf]
57 * Revision 1.2.2.4 1993/08/11 20:37:33 elliston
58 * Add ANSI Prototypes. CR #9523.
59 * [1993/08/11 03:32:57 elliston]
61 * Revision 1.2.2.3 1993/07/27 18:26:59 elliston
62 * Add ANSI prototypes. CR #9523.
63 * [1993/07/27 18:11:12 elliston]
65 * Revision 1.2.2.2 1993/06/09 02:19:53 gm
66 * Added to OSF/1 R1.3 from NMK15.0.
67 * [1993/06/02 20:56:04 jeffc]
69 * Revision 1.2 1993/04/19 16:01:51 devrcs
71 * Changed errant call of db_error in db_cond_cmd() to db_printf/db_error.
75 * Revision 1.1 1992/09/30 02:00:58 robert
82 * Revision 2.2 91/10/09 15:59:09 af
83 * Revision 2.1.3.1 91/10/05 13:05:38 jeffreyh
84 * Created to support conditional break point and command execution.
87 * Revision 2.1.3.1 91/10/05 13:05:38 jeffreyh
88 * Created to support conditional break point and command execution.
94 * Mach Operating System
95 * Copyright (c) 1991,1990 Carnegie Mellon University
96 * All Rights Reserved.
98 * Permission to use, copy, modify and distribute this software and its
99 * documentation is hereby granted, provided that both the copyright
100 * notice and this permission notice appear in all copies of the
101 * software, derivative works or modified versions, and any portions
102 * thereof, and that both notices appear in supporting documentation.
104 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
105 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
106 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
108 * Carnegie Mellon requests users of this software to return to
110 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
111 * School of Computer Science
112 * Carnegie Mellon University
113 * Pittsburgh PA 15213-3890
115 * any improvements or extensions that they make and grant Carnegie Mellon
116 * the rights to redistribute these changes.
121 #include <machine/db_machdep.h>
122 #include <machine/setjmp.h>
123 #include <kern/misc_protos.h>
125 #include <ddb/db_lex.h>
126 #include <ddb/db_break.h>
127 #include <ddb/db_command.h>
128 #include <ddb/db_cond.h>
129 #include <ddb/db_expr.h>
130 #include <ddb/db_output.h> /* For db_printf() */
132 #define DB_MAX_COND 10 /* maximum conditions to be set */
134 int db_ncond_free
= DB_MAX_COND
; /* free condition */
136 int c_size
; /* size of cond */
137 char c_cond_cmd
[DB_LEX_LINE_SIZE
]; /* cond & cmd */
138 } db_cond
[DB_MAX_COND
];
141 db_cond_free(db_thread_breakpoint_t bkpt
)
143 if (bkpt
->tb_cond
> 0) {
144 db_cond
[bkpt
->tb_cond
-1].c_size
= 0;
150 extern jmp_buf_t
*db_recover
;
153 db_cond_check(db_thread_breakpoint_t bkpt
)
155 register struct db_cond
*cp
;
160 if (bkpt
->tb_cond
<= 0) { /* no condition */
161 if (--(bkpt
->tb_count
) > 0)
163 bkpt
->tb_count
= bkpt
->tb_init_count
;
166 db_dot
= PC_REGS(DDB_REGS
);
169 if (_setjmp(db_recover
= &db_jmpbuf
)) {
171 * in case of error, return true to enter interactive mode
177 * switch input, and evalutate condition
179 cp
= &db_cond
[bkpt
->tb_cond
- 1];
180 db_switch_input(cp
->c_cond_cmd
, cp
->c_size
);
181 if (!db_expression(&value
)) {
182 db_printf("error: condition evaluation error\n");
185 if (value
== 0 || --(bkpt
->tb_count
) > 0)
189 * execute a command list if exist
191 bkpt
->tb_count
= bkpt
->tb_init_count
;
192 if ((t
= db_read_token()) != tEOL
) {
194 return(db_exec_cmd_nest(0, 0));
200 db_cond_print(db_thread_breakpoint_t bkpt
)
202 register char *p
, *ep
;
203 register struct db_cond
*cp
;
205 if (bkpt
->tb_cond
<= 0)
207 cp
= &db_cond
[bkpt
->tb_cond
-1];
211 if (*p
== '\n' || *p
== 0)
221 register struct db_cond
*cp
;
224 db_thread_breakpoint_t bkpt
;
226 if (db_read_token() != tHASH
|| db_read_token() != tNUMBER
) {
227 db_printf("#<number> expected instead of \"%s\"\n", db_tok_string
);
231 if ((bkpt
= db_find_breakpoint_number(db_tok_number
, 0)) == 0) {
232 db_printf("No such break point #%d\n", db_tok_number
);
237 * if the break point already has a condition, free it first
239 if (bkpt
->tb_cond
> 0) {
240 cp
= &db_cond
[bkpt
->tb_cond
- 1];
243 if (db_ncond_free
<= 0) {
244 db_error("Too many conditions\n");
247 for (cp
= db_cond
; cp
< &db_cond
[DB_MAX_COND
]; cp
++)
250 if (cp
>= &db_cond
[DB_MAX_COND
])
251 panic("bad db_cond_free");
253 for (c
= db_read_char(); c
== ' ' || c
== '\t'; c
= db_read_char());
254 for (p
= cp
->c_cond_cmd
; c
>= 0; c
= db_read_char())
257 * switch to saved data and call db_expression to check the condition.
258 * If no condition is supplied, db_expression will return false.
259 * In this case, clear previous condition of the break point.
260 * If condition is supplied, set the condition to the permanent area.
261 * Note: db_expression will not return here, if the condition
262 * expression is wrong.
264 db_switch_input(cp
->c_cond_cmd
, p
- cp
->c_cond_cmd
);
265 if (!db_expression(&value
)) {
266 /* since condition is already freed, do nothing */
272 cp
->c_size
= p
- cp
->c_cond_cmd
;
273 bkpt
->tb_cond
= (cp
- db_cond
) + 1;