2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
28 * Revision 1.1.1.1 1998/09/22 21:05:47 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
32 * Import of OSF Mach kernel (~mburg)
34 * Revision 1.2.18.1 1997/03/27 18:46:29 barbou
35 * ri-osc CR1558: enable use of breakpoint counts even when no
37 * [1995/09/20 15:24:24 bolinger]
40 * Revision 1.2.6.2 1996/01/09 19:15:34 devrcs
41 * Change 'register c' to 'register int c'.
42 * [1995/12/01 21:42:00 jfraser]
44 * Merged '64-bit safe' changes from DEC alpha port.
45 * [1995/11/21 18:02:54 jfraser]
47 * Revision 1.2.6.1 1994/09/23 01:18:27 ezf
48 * change marker to not FREE
49 * [1994/09/22 21:09:37 ezf]
51 * Revision 1.2.2.4 1993/08/11 20:37:33 elliston
52 * Add ANSI Prototypes. CR #9523.
53 * [1993/08/11 03:32:57 elliston]
55 * Revision 1.2.2.3 1993/07/27 18:26:59 elliston
56 * Add ANSI prototypes. CR #9523.
57 * [1993/07/27 18:11:12 elliston]
59 * Revision 1.2.2.2 1993/06/09 02:19:53 gm
60 * Added to OSF/1 R1.3 from NMK15.0.
61 * [1993/06/02 20:56:04 jeffc]
63 * Revision 1.2 1993/04/19 16:01:51 devrcs
65 * Changed errant call of db_error in db_cond_cmd() to db_printf/db_error.
69 * Revision 1.1 1992/09/30 02:00:58 robert
76 * Revision 2.2 91/10/09 15:59:09 af
77 * Revision 2.1.3.1 91/10/05 13:05:38 jeffreyh
78 * Created to support conditional break point and command execution.
81 * Revision 2.1.3.1 91/10/05 13:05:38 jeffreyh
82 * Created to support conditional break point and command execution.
88 * Mach Operating System
89 * Copyright (c) 1991,1990 Carnegie Mellon University
90 * All Rights Reserved.
92 * Permission to use, copy, modify and distribute this software and its
93 * documentation is hereby granted, provided that both the copyright
94 * notice and this permission notice appear in all copies of the
95 * software, derivative works or modified versions, and any portions
96 * thereof, and that both notices appear in supporting documentation.
98 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
99 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
100 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
102 * Carnegie Mellon requests users of this software to return to
104 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
105 * School of Computer Science
106 * Carnegie Mellon University
107 * Pittsburgh PA 15213-3890
109 * any improvements or extensions that they make and grant Carnegie Mellon
110 * the rights to redistribute these changes.
115 #include <machine/db_machdep.h>
116 #include <machine/setjmp.h>
117 #include <kern/misc_protos.h>
119 #include <ddb/db_lex.h>
120 #include <ddb/db_break.h>
121 #include <ddb/db_command.h>
122 #include <ddb/db_cond.h>
123 #include <ddb/db_expr.h>
124 #include <ddb/db_output.h> /* For db_printf() */
126 #define DB_MAX_COND 10 /* maximum conditions to be set */
128 int db_ncond_free
= DB_MAX_COND
; /* free condition */
130 int c_size
; /* size of cond */
131 char c_cond_cmd
[DB_LEX_LINE_SIZE
]; /* cond & cmd */
132 } db_cond
[DB_MAX_COND
];
135 db_cond_free(db_thread_breakpoint_t bkpt
)
137 if (bkpt
->tb_cond
> 0) {
138 db_cond
[bkpt
->tb_cond
-1].c_size
= 0;
145 db_cond_check(db_thread_breakpoint_t bkpt
)
147 register struct db_cond
*cp
;
151 extern jmp_buf_t
*db_recover
;
153 if (bkpt
->tb_cond
<= 0) { /* no condition */
154 if (--(bkpt
->tb_count
) > 0)
156 bkpt
->tb_count
= bkpt
->tb_init_count
;
159 db_dot
= PC_REGS(DDB_REGS
);
162 if (_setjmp(db_recover
= &db_jmpbuf
)) {
164 * in case of error, return true to enter interactive mode
170 * switch input, and evalutate condition
172 cp
= &db_cond
[bkpt
->tb_cond
- 1];
173 db_switch_input(cp
->c_cond_cmd
, cp
->c_size
);
174 if (!db_expression(&value
)) {
175 db_printf("error: condition evaluation error\n");
178 if (value
== 0 || --(bkpt
->tb_count
) > 0)
182 * execute a command list if exist
184 bkpt
->tb_count
= bkpt
->tb_init_count
;
185 if ((t
= db_read_token()) != tEOL
) {
187 return(db_exec_cmd_nest(0, 0));
193 db_cond_print(db_thread_breakpoint_t bkpt
)
195 register char *p
, *ep
;
196 register struct db_cond
*cp
;
198 if (bkpt
->tb_cond
<= 0)
200 cp
= &db_cond
[bkpt
->tb_cond
-1];
204 if (*p
== '\n' || *p
== 0)
214 register struct db_cond
*cp
;
217 db_thread_breakpoint_t bkpt
;
219 if (db_read_token() != tHASH
|| db_read_token() != tNUMBER
) {
220 db_printf("#<number> expected instead of \"%s\"\n", db_tok_string
);
224 if ((bkpt
= db_find_breakpoint_number(db_tok_number
, 0)) == 0) {
225 db_printf("No such break point #%d\n", db_tok_number
);
230 * if the break point already has a condition, free it first
232 if (bkpt
->tb_cond
> 0) {
233 cp
= &db_cond
[bkpt
->tb_cond
- 1];
236 if (db_ncond_free
<= 0) {
237 db_error("Too many conditions\n");
240 for (cp
= db_cond
; cp
< &db_cond
[DB_MAX_COND
]; cp
++)
243 if (cp
>= &db_cond
[DB_MAX_COND
])
244 panic("bad db_cond_free");
246 for (c
= db_read_char(); c
== ' ' || c
== '\t'; c
= db_read_char());
247 for (p
= cp
->c_cond_cmd
; c
>= 0; c
= db_read_char())
250 * switch to saved data and call db_expression to check the condition.
251 * If no condition is supplied, db_expression will return false.
252 * In this case, clear previous condition of the break point.
253 * If condition is supplied, set the condition to the permanent area.
254 * Note: db_expression will not return here, if the condition
255 * expression is wrong.
257 db_switch_input(cp
->c_cond_cmd
, p
- cp
->c_cond_cmd
);
258 if (!db_expression(&value
)) {
259 /* since condition is already freed, do nothing */
265 cp
->c_size
= p
- cp
->c_cond_cmd
;
266 bkpt
->tb_cond
= (cp
- db_cond
) + 1;