]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
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 | |
13 | * file. | |
14 | * | |
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 | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
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. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * @OSF_COPYRIGHT@ | |
27 | */ | |
28 | /* | |
29 | * HISTORY | |
30 | * | |
31 | * Revision 1.1.1.1 1998/09/22 21:05:47 wsanchez | |
32 | * Import of Mac OS X kernel (~semeria) | |
33 | * | |
34 | * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez | |
35 | * Import of OSF Mach kernel (~mburg) | |
36 | * | |
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 | |
39 | * condition given. | |
40 | * [1995/09/20 15:24:24 bolinger] | |
41 | * [97/02/25 barbou] | |
42 | * | |
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] | |
46 | * | |
47 | * Merged '64-bit safe' changes from DEC alpha port. | |
48 | * [1995/11/21 18:02:54 jfraser] | |
49 | * | |
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] | |
53 | * | |
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] | |
57 | * | |
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] | |
61 | * | |
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] | |
65 | * | |
66 | * Revision 1.2 1993/04/19 16:01:51 devrcs | |
67 | * Changes from mk78: | |
68 | * Changed errant call of db_error in db_cond_cmd() to db_printf/db_error. | |
69 | * [92/05/20 jfriedl] | |
70 | * [93/02/02 bruel] | |
71 | * | |
72 | * Revision 1.1 1992/09/30 02:00:58 robert | |
73 | * Initial revision | |
74 | * | |
75 | * $EndLog$ | |
76 | */ | |
77 | /* CMU_HIST */ | |
78 | /* | |
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. | |
82 | * [91/08/29 tak] | |
83 | * | |
84 | * Revision 2.1.3.1 91/10/05 13:05:38 jeffreyh | |
85 | * Created to support conditional break point and command execution. | |
86 | * [91/08/29 tak] | |
87 | * | |
88 | */ | |
89 | /* CMU_ENDHIST */ | |
90 | /* | |
91 | * Mach Operating System | |
92 | * Copyright (c) 1991,1990 Carnegie Mellon University | |
93 | * All Rights Reserved. | |
94 | * | |
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. | |
100 | * | |
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. | |
104 | * | |
105 | * Carnegie Mellon requests users of this software to return to | |
106 | * | |
107 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
108 | * School of Computer Science | |
109 | * Carnegie Mellon University | |
110 | * Pittsburgh PA 15213-3890 | |
111 | * | |
112 | * any improvements or extensions that they make and grant Carnegie Mellon | |
113 | * the rights to redistribute these changes. | |
114 | */ | |
115 | /* | |
116 | */ | |
117 | ||
118 | #include <machine/db_machdep.h> | |
119 | #include <machine/setjmp.h> | |
120 | #include <kern/misc_protos.h> | |
121 | ||
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() */ | |
128 | ||
129 | #define DB_MAX_COND 10 /* maximum conditions to be set */ | |
130 | ||
131 | int db_ncond_free = DB_MAX_COND; /* free condition */ | |
132 | struct db_cond { | |
133 | int c_size; /* size of cond */ | |
134 | char c_cond_cmd[DB_LEX_LINE_SIZE]; /* cond & cmd */ | |
135 | } db_cond[DB_MAX_COND]; | |
136 | ||
137 | void | |
138 | db_cond_free(db_thread_breakpoint_t bkpt) | |
139 | { | |
140 | if (bkpt->tb_cond > 0) { | |
141 | db_cond[bkpt->tb_cond-1].c_size = 0; | |
142 | db_ncond_free++; | |
143 | bkpt->tb_cond = 0; | |
144 | } | |
145 | } | |
146 | ||
147 | boolean_t | |
148 | db_cond_check(db_thread_breakpoint_t bkpt) | |
149 | { | |
150 | register struct db_cond *cp; | |
151 | db_expr_t value; | |
152 | int t; | |
153 | jmp_buf_t db_jmpbuf; | |
154 | extern jmp_buf_t *db_recover; | |
155 | ||
156 | if (bkpt->tb_cond <= 0) { /* no condition */ | |
157 | if (--(bkpt->tb_count) > 0) | |
158 | return(FALSE); | |
159 | bkpt->tb_count = bkpt->tb_init_count; | |
160 | return(TRUE); | |
161 | } | |
162 | db_dot = PC_REGS(DDB_REGS); | |
163 | db_prev = db_dot; | |
164 | db_next = db_dot; | |
165 | if (_setjmp(db_recover = &db_jmpbuf)) { | |
166 | /* | |
167 | * in case of error, return true to enter interactive mode | |
168 | */ | |
169 | return(TRUE); | |
170 | } | |
171 | ||
172 | /* | |
173 | * switch input, and evalutate condition | |
174 | */ | |
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"); | |
179 | return(TRUE); | |
180 | } | |
181 | if (value == 0 || --(bkpt->tb_count) > 0) | |
182 | return(FALSE); | |
183 | ||
184 | /* | |
185 | * execute a command list if exist | |
186 | */ | |
187 | bkpt->tb_count = bkpt->tb_init_count; | |
188 | if ((t = db_read_token()) != tEOL) { | |
189 | db_unread_token(t); | |
190 | return(db_exec_cmd_nest(0, 0)); | |
191 | } | |
192 | return(TRUE); | |
193 | } | |
194 | ||
195 | void | |
196 | db_cond_print(db_thread_breakpoint_t bkpt) | |
197 | { | |
198 | register char *p, *ep; | |
199 | register struct db_cond *cp; | |
200 | ||
201 | if (bkpt->tb_cond <= 0) | |
202 | return; | |
203 | cp = &db_cond[bkpt->tb_cond-1]; | |
204 | p = cp->c_cond_cmd; | |
205 | ep = p + cp->c_size; | |
206 | while (p < ep) { | |
207 | if (*p == '\n' || *p == 0) | |
208 | break; | |
209 | db_putchar(*p++); | |
210 | } | |
211 | } | |
212 | ||
213 | void | |
214 | db_cond_cmd(void) | |
215 | { | |
216 | register int c; | |
217 | register struct db_cond *cp; | |
218 | register char *p; | |
219 | db_expr_t value; | |
220 | db_thread_breakpoint_t bkpt; | |
221 | ||
222 | if (db_read_token() != tHASH || db_read_token() != tNUMBER) { | |
223 | db_printf("#<number> expected instead of \"%s\"\n", db_tok_string); | |
224 | db_error(0); | |
225 | return; | |
226 | } | |
227 | if ((bkpt = db_find_breakpoint_number(db_tok_number, 0)) == 0) { | |
228 | db_printf("No such break point #%d\n", db_tok_number); | |
229 | db_error(0); | |
230 | return; | |
231 | } | |
232 | /* | |
233 | * if the break point already has a condition, free it first | |
234 | */ | |
235 | if (bkpt->tb_cond > 0) { | |
236 | cp = &db_cond[bkpt->tb_cond - 1]; | |
237 | db_cond_free(bkpt); | |
238 | } else { | |
239 | if (db_ncond_free <= 0) { | |
240 | db_error("Too many conditions\n"); | |
241 | return; | |
242 | } | |
243 | for (cp = db_cond; cp < &db_cond[DB_MAX_COND]; cp++) | |
244 | if (cp->c_size == 0) | |
245 | break; | |
246 | if (cp >= &db_cond[DB_MAX_COND]) | |
247 | panic("bad db_cond_free"); | |
248 | } | |
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()) | |
251 | *p++ = c; | |
252 | /* | |
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. | |
259 | */ | |
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 */ | |
263 | db_flush_lex(); | |
264 | return; | |
265 | } | |
266 | db_flush_lex(); | |
267 | db_ncond_free--; | |
268 | cp->c_size = p - cp->c_cond_cmd; | |
269 | bkpt->tb_cond = (cp - db_cond) + 1; | |
270 | } |