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:47 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.18.1 1997/03/27 18:46:29 barbou
38 * ri-osc CR1558: enable use of breakpoint counts even when no
40 * [1995/09/20 15:24:24 bolinger]
43 * Revision 1.2.6.2 1996/01/09 19:15:34 devrcs
44 * Change 'register c' to 'register int c'.
45 * [1995/12/01 21:42:00 jfraser]
47 * Merged '64-bit safe' changes from DEC alpha port.
48 * [1995/11/21 18:02:54 jfraser]
50 * Revision 1.2.6.1 1994/09/23 01:18:27 ezf
51 * change marker to not FREE
52 * [1994/09/22 21:09:37 ezf]
54 * Revision 1.2.2.4 1993/08/11 20:37:33 elliston
55 * Add ANSI Prototypes. CR #9523.
56 * [1993/08/11 03:32:57 elliston]
58 * Revision 1.2.2.3 1993/07/27 18:26:59 elliston
59 * Add ANSI prototypes. CR #9523.
60 * [1993/07/27 18:11:12 elliston]
62 * Revision 1.2.2.2 1993/06/09 02:19:53 gm
63 * Added to OSF/1 R1.3 from NMK15.0.
64 * [1993/06/02 20:56:04 jeffc]
66 * Revision 1.2 1993/04/19 16:01:51 devrcs
68 * Changed errant call of db_error in db_cond_cmd() to db_printf/db_error.
72 * Revision 1.1 1992/09/30 02:00:58 robert
79 * Revision 2.2 91/10/09 15:59:09 af
80 * Revision 2.1.3.1 91/10/05 13:05:38 jeffreyh
81 * Created to support conditional break point and command execution.
84 * Revision 2.1.3.1 91/10/05 13:05:38 jeffreyh
85 * Created to support conditional break point and command execution.
91 * Mach Operating System
92 * Copyright (c) 1991,1990 Carnegie Mellon University
93 * All Rights Reserved.
95 * Permission to use, copy, modify and distribute this software and its
96 * documentation is hereby granted, provided that both the copyright
97 * notice and this permission notice appear in all copies of the
98 * software, derivative works or modified versions, and any portions
99 * thereof, and that both notices appear in supporting documentation.
101 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
102 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
103 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
105 * Carnegie Mellon requests users of this software to return to
107 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
108 * School of Computer Science
109 * Carnegie Mellon University
110 * Pittsburgh PA 15213-3890
112 * any improvements or extensions that they make and grant Carnegie Mellon
113 * the rights to redistribute these changes.
118 #include <machine/db_machdep.h>
119 #include <machine/setjmp.h>
120 #include <kern/misc_protos.h>
122 #include <ddb/db_lex.h>
123 #include <ddb/db_break.h>
124 #include <ddb/db_command.h>
125 #include <ddb/db_cond.h>
126 #include <ddb/db_expr.h>
127 #include <ddb/db_output.h> /* For db_printf() */
129 #define DB_MAX_COND 10 /* maximum conditions to be set */
131 int db_ncond_free
= DB_MAX_COND
; /* free condition */
133 int c_size
; /* size of cond */
134 char c_cond_cmd
[DB_LEX_LINE_SIZE
]; /* cond & cmd */
135 } db_cond
[DB_MAX_COND
];
138 db_cond_free(db_thread_breakpoint_t bkpt
)
140 if (bkpt
->tb_cond
> 0) {
141 db_cond
[bkpt
->tb_cond
-1].c_size
= 0;
148 db_cond_check(db_thread_breakpoint_t bkpt
)
150 register struct db_cond
*cp
;
154 extern jmp_buf_t
*db_recover
;
156 if (bkpt
->tb_cond
<= 0) { /* no condition */
157 if (--(bkpt
->tb_count
) > 0)
159 bkpt
->tb_count
= bkpt
->tb_init_count
;
162 db_dot
= PC_REGS(DDB_REGS
);
165 if (_setjmp(db_recover
= &db_jmpbuf
)) {
167 * in case of error, return true to enter interactive mode
173 * switch input, and evalutate condition
175 cp
= &db_cond
[bkpt
->tb_cond
- 1];
176 db_switch_input(cp
->c_cond_cmd
, cp
->c_size
);
177 if (!db_expression(&value
)) {
178 db_printf("error: condition evaluation error\n");
181 if (value
== 0 || --(bkpt
->tb_count
) > 0)
185 * execute a command list if exist
187 bkpt
->tb_count
= bkpt
->tb_init_count
;
188 if ((t
= db_read_token()) != tEOL
) {
190 return(db_exec_cmd_nest(0, 0));
196 db_cond_print(db_thread_breakpoint_t bkpt
)
198 register char *p
, *ep
;
199 register struct db_cond
*cp
;
201 if (bkpt
->tb_cond
<= 0)
203 cp
= &db_cond
[bkpt
->tb_cond
-1];
207 if (*p
== '\n' || *p
== 0)
217 register struct db_cond
*cp
;
220 db_thread_breakpoint_t bkpt
;
222 if (db_read_token() != tHASH
|| db_read_token() != tNUMBER
) {
223 db_printf("#<number> expected instead of \"%s\"\n", db_tok_string
);
227 if ((bkpt
= db_find_breakpoint_number(db_tok_number
, 0)) == 0) {
228 db_printf("No such break point #%d\n", db_tok_number
);
233 * if the break point already has a condition, free it first
235 if (bkpt
->tb_cond
> 0) {
236 cp
= &db_cond
[bkpt
->tb_cond
- 1];
239 if (db_ncond_free
<= 0) {
240 db_error("Too many conditions\n");
243 for (cp
= db_cond
; cp
< &db_cond
[DB_MAX_COND
]; cp
++)
246 if (cp
>= &db_cond
[DB_MAX_COND
])
247 panic("bad db_cond_free");
249 for (c
= db_read_char(); c
== ' ' || c
== '\t'; c
= db_read_char());
250 for (p
= cp
->c_cond_cmd
; c
>= 0; c
= db_read_char())
253 * switch to saved data and call db_expression to check the condition.
254 * If no condition is supplied, db_expression will return false.
255 * In this case, clear previous condition of the break point.
256 * If condition is supplied, set the condition to the permanent area.
257 * Note: db_expression will not return here, if the condition
258 * expression is wrong.
260 db_switch_input(cp
->c_cond_cmd
, p
- cp
->c_cond_cmd
);
261 if (!db_expression(&value
)) {
262 /* since condition is already freed, do nothing */
268 cp
->c_size
= p
- cp
->c_cond_cmd
;
269 bkpt
->tb_cond
= (cp
- db_cond
) + 1;