Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Everything about breakpoints, for GDB. |
2f4973f8 | 2 | Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996 |
9f577285 | 3 | Free Software Foundation, Inc. |
bd5635a1 RP |
4 | |
5 | This file is part of GDB. | |
6 | ||
bdbd5f50 | 7 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 8 | it under the terms of the GNU General Public License as published by |
bdbd5f50 JG |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. | |
bd5635a1 | 11 | |
bdbd5f50 | 12 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
bdbd5f50 | 18 | along with this program; if not, write to the Free Software |
cd10c7e3 | 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
bd5635a1 | 20 | |
bd5635a1 | 21 | #include "defs.h" |
1eeba686 | 22 | #include <ctype.h> |
bd5635a1 RP |
23 | #include "symtab.h" |
24 | #include "frame.h" | |
25 | #include "breakpoint.h" | |
30875e1c | 26 | #include "gdbtypes.h" |
bd5635a1 RP |
27 | #include "expression.h" |
28 | #include "gdbcore.h" | |
29 | #include "gdbcmd.h" | |
30 | #include "value.h" | |
bd5635a1 RP |
31 | #include "command.h" |
32 | #include "inferior.h" | |
fdfa3315 | 33 | #include "gdbthread.h" |
bd5635a1 | 34 | #include "target.h" |
d3b9c0df | 35 | #include "language.h" |
2b576293 | 36 | #include "gdb_string.h" |
423e9664 | 37 | #include "demangle.h" |
9f577285 | 38 | #include "annotate.h" |
bd5635a1 | 39 | |
30875e1c SG |
40 | /* local function prototypes */ |
41 | ||
42 | static void | |
43 | catch_command_1 PARAMS ((char *, int, int)); | |
44 | ||
45 | static void | |
46 | enable_delete_command PARAMS ((char *, int)); | |
47 | ||
48 | static void | |
49 | enable_delete_breakpoint PARAMS ((struct breakpoint *)); | |
50 | ||
51 | static void | |
52 | enable_once_command PARAMS ((char *, int)); | |
53 | ||
54 | static void | |
55 | enable_once_breakpoint PARAMS ((struct breakpoint *)); | |
56 | ||
57 | static void | |
58 | disable_command PARAMS ((char *, int)); | |
59 | ||
30875e1c SG |
60 | static void |
61 | enable_command PARAMS ((char *, int)); | |
62 | ||
30875e1c SG |
63 | static void |
64 | map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *))); | |
65 | ||
66 | static void | |
67 | ignore_command PARAMS ((char *, int)); | |
68 | ||
69 | static int | |
70 | breakpoint_re_set_one PARAMS ((char *)); | |
71 | ||
72 | static void | |
73 | delete_command PARAMS ((char *, int)); | |
74 | ||
75 | static void | |
76 | clear_command PARAMS ((char *, int)); | |
77 | ||
78 | static void | |
79 | catch_command PARAMS ((char *, int)); | |
80 | ||
81 | static struct symtabs_and_lines | |
82 | get_catch_sals PARAMS ((int)); | |
83 | ||
84 | static void | |
85 | watch_command PARAMS ((char *, int)); | |
86 | ||
999dd04b | 87 | static int |
11054881 | 88 | can_use_hardware_watchpoint PARAMS ((struct value *)); |
999dd04b | 89 | |
30875e1c SG |
90 | static void |
91 | tbreak_command PARAMS ((char *, int)); | |
92 | ||
93 | static void | |
94 | break_command_1 PARAMS ((char *, int, int)); | |
95 | ||
96 | static void | |
97 | mention PARAMS ((struct breakpoint *)); | |
98 | ||
99 | static struct breakpoint * | |
100 | set_raw_breakpoint PARAMS ((struct symtab_and_line)); | |
101 | ||
102 | static void | |
103 | check_duplicates PARAMS ((CORE_ADDR)); | |
104 | ||
105 | static void | |
106 | describe_other_breakpoints PARAMS ((CORE_ADDR)); | |
107 | ||
30875e1c SG |
108 | static void |
109 | breakpoints_info PARAMS ((char *, int)); | |
110 | ||
111 | static void | |
423e9664 | 112 | breakpoint_1 PARAMS ((int, int)); |
30875e1c SG |
113 | |
114 | static bpstat | |
115 | bpstat_alloc PARAMS ((struct breakpoint *, bpstat)); | |
116 | ||
117 | static int | |
118 | breakpoint_cond_eval PARAMS ((char *)); | |
119 | ||
120 | static void | |
121 | cleanup_executing_breakpoints PARAMS ((int)); | |
122 | ||
123 | static void | |
124 | commands_command PARAMS ((char *, int)); | |
125 | ||
126 | static void | |
127 | condition_command PARAMS ((char *, int)); | |
128 | ||
129 | static int | |
130 | get_number PARAMS ((char **)); | |
131 | ||
132 | static void | |
133 | set_breakpoint_count PARAMS ((int)); | |
134 | ||
999dd04b JL |
135 | static int |
136 | remove_breakpoint PARAMS ((struct breakpoint *)); | |
30875e1c | 137 | |
bd5635a1 | 138 | extern int addressprint; /* Print machine addresses? */ |
bd5635a1 | 139 | |
bd5635a1 RP |
140 | /* Are we executing breakpoint commands? */ |
141 | static int executing_breakpoint_commands; | |
142 | ||
cba0d141 JG |
143 | /* Walk the following statement or block through all breakpoints. |
144 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
145 | breakpoint. */ | |
146 | ||
bd5635a1 RP |
147 | #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next) |
148 | ||
cba0d141 JG |
149 | #define ALL_BREAKPOINTS_SAFE(b,tmp) \ |
150 | for (b = breakpoint_chain; \ | |
151 | b? (tmp=b->next, 1): 0; \ | |
152 | b = tmp) | |
153 | ||
9f577285 SS |
154 | /* True if breakpoint hit counts should be displayed in breakpoint info. */ |
155 | ||
156 | int show_breakpoint_hit_counts = 1; | |
157 | ||
bd5635a1 RP |
158 | /* Chain of all breakpoints defined. */ |
159 | ||
e8bf33c4 | 160 | struct breakpoint *breakpoint_chain; |
bd5635a1 RP |
161 | |
162 | /* Number of last breakpoint made. */ | |
163 | ||
164 | static int breakpoint_count; | |
165 | ||
166 | /* Set breakpoint count to NUM. */ | |
9f577285 | 167 | |
bd5635a1 RP |
168 | static void |
169 | set_breakpoint_count (num) | |
170 | int num; | |
171 | { | |
172 | breakpoint_count = num; | |
173 | set_internalvar (lookup_internalvar ("bpnum"), | |
06b6c733 | 174 | value_from_longest (builtin_type_int, (LONGEST) num)); |
bd5635a1 RP |
175 | } |
176 | ||
9f577285 SS |
177 | /* Used in run_command to zero the hit count when a new run starts. */ |
178 | ||
179 | void | |
180 | clear_breakpoint_hit_counts () | |
181 | { | |
182 | struct breakpoint *b; | |
183 | ||
184 | ALL_BREAKPOINTS (b) | |
185 | b->hit_count = 0; | |
186 | } | |
187 | ||
bd5635a1 RP |
188 | /* Default address, symtab and line to put a breakpoint at |
189 | for "break" command with no arg. | |
190 | if default_breakpoint_valid is zero, the other three are | |
191 | not valid, and "break" with no arg is an error. | |
192 | ||
193 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
194 | ||
195 | int default_breakpoint_valid; | |
196 | CORE_ADDR default_breakpoint_address; | |
197 | struct symtab *default_breakpoint_symtab; | |
198 | int default_breakpoint_line; | |
bd5635a1 RP |
199 | \f |
200 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
201 | Advance *PP after the string and any trailing whitespace. | |
202 | ||
203 | Currently the string can either be a number or "$" followed by the name | |
204 | of a convenience variable. Making it an expression wouldn't work well | |
205 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */ | |
206 | static int | |
207 | get_number (pp) | |
208 | char **pp; | |
209 | { | |
210 | int retval; | |
211 | char *p = *pp; | |
212 | ||
213 | if (p == NULL) | |
214 | /* Empty line means refer to the last breakpoint. */ | |
215 | return breakpoint_count; | |
216 | else if (*p == '$') | |
217 | { | |
218 | /* Make a copy of the name, so we can null-terminate it | |
219 | to pass to lookup_internalvar(). */ | |
220 | char *varname; | |
221 | char *start = ++p; | |
82a2edfb | 222 | value_ptr val; |
bd5635a1 RP |
223 | |
224 | while (isalnum (*p) || *p == '_') | |
225 | p++; | |
226 | varname = (char *) alloca (p - start + 1); | |
227 | strncpy (varname, start, p - start); | |
228 | varname[p - start] = '\0'; | |
229 | val = value_of_internalvar (lookup_internalvar (varname)); | |
230 | if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT) | |
231 | error ( | |
232 | "Convenience variables used to specify breakpoints must have integer values." | |
233 | ); | |
234 | retval = (int) value_as_long (val); | |
235 | } | |
236 | else | |
237 | { | |
80ba48f5 SG |
238 | if (*p == '-') |
239 | ++p; | |
bd5635a1 RP |
240 | while (*p >= '0' && *p <= '9') |
241 | ++p; | |
242 | if (p == *pp) | |
243 | /* There is no number here. (e.g. "cond a == b"). */ | |
244 | error_no_arg ("breakpoint number"); | |
245 | retval = atoi (*pp); | |
246 | } | |
247 | if (!(isspace (*p) || *p == '\0')) | |
248 | error ("breakpoint number expected"); | |
249 | while (isspace (*p)) | |
250 | p++; | |
251 | *pp = p; | |
252 | return retval; | |
253 | } | |
254 | \f | |
255 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
256 | ||
257 | static void | |
258 | condition_command (arg, from_tty) | |
259 | char *arg; | |
260 | int from_tty; | |
261 | { | |
262 | register struct breakpoint *b; | |
263 | char *p; | |
264 | register int bnum; | |
265 | ||
266 | if (arg == 0) | |
267 | error_no_arg ("breakpoint number"); | |
268 | ||
269 | p = arg; | |
270 | bnum = get_number (&p); | |
271 | ||
272 | ALL_BREAKPOINTS (b) | |
273 | if (b->number == bnum) | |
274 | { | |
275 | if (b->cond) | |
276 | { | |
c8950965 | 277 | free ((PTR)b->cond); |
bd5635a1 RP |
278 | b->cond = 0; |
279 | } | |
280 | if (b->cond_string != NULL) | |
c8950965 | 281 | free ((PTR)b->cond_string); |
bd5635a1 RP |
282 | |
283 | if (*p == 0) | |
284 | { | |
285 | b->cond = 0; | |
286 | b->cond_string = NULL; | |
287 | if (from_tty) | |
423e9664 | 288 | printf_filtered ("Breakpoint %d now unconditional.\n", bnum); |
bd5635a1 RP |
289 | } |
290 | else | |
291 | { | |
292 | arg = p; | |
293 | /* I don't know if it matters whether this is the string the user | |
294 | typed in or the decompiled expression. */ | |
295 | b->cond_string = savestring (arg, strlen (arg)); | |
d3b9c0df | 296 | b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0); |
bd5635a1 RP |
297 | if (*arg) |
298 | error ("Junk at end of expression"); | |
299 | } | |
16726dd1 | 300 | breakpoints_changed (); |
bd5635a1 RP |
301 | return; |
302 | } | |
303 | ||
304 | error ("No breakpoint number %d.", bnum); | |
305 | } | |
306 | ||
bdbd5f50 | 307 | /* ARGSUSED */ |
bd5635a1 RP |
308 | static void |
309 | commands_command (arg, from_tty) | |
310 | char *arg; | |
311 | int from_tty; | |
312 | { | |
313 | register struct breakpoint *b; | |
314 | char *p; | |
315 | register int bnum; | |
316 | struct command_line *l; | |
317 | ||
318 | /* If we allowed this, we would have problems with when to | |
319 | free the storage, if we change the commands currently | |
320 | being read from. */ | |
321 | ||
322 | if (executing_breakpoint_commands) | |
323 | error ("Can't use the \"commands\" command among a breakpoint's commands."); | |
324 | ||
325 | p = arg; | |
326 | bnum = get_number (&p); | |
327 | if (p && *p) | |
328 | error ("Unexpected extra arguments following breakpoint number."); | |
329 | ||
330 | ALL_BREAKPOINTS (b) | |
331 | if (b->number == bnum) | |
332 | { | |
41756e56 FF |
333 | char tmpbuf[128]; |
334 | sprintf (tmpbuf, "Type commands for when breakpoint %d is hit, one per line.", bnum); | |
335 | l = read_command_lines (tmpbuf, from_tty); | |
bd5635a1 RP |
336 | free_command_lines (&b->commands); |
337 | b->commands = l; | |
6c803036 | 338 | breakpoints_changed (); |
bd5635a1 RP |
339 | return; |
340 | } | |
341 | error ("No breakpoint number %d.", bnum); | |
342 | } | |
343 | \f | |
31ef19fc JK |
344 | extern int memory_breakpoint_size; /* from mem-break.c */ |
345 | ||
346 | /* Like target_read_memory() but if breakpoints are inserted, return | |
30875e1c SG |
347 | the shadow contents instead of the breakpoints themselves. |
348 | ||
349 | Read "memory data" from whatever target or inferior we have. | |
350 | Returns zero if successful, errno value if not. EIO is used | |
351 | for address out of bounds. If breakpoints are inserted, returns | |
352 | shadow contents, not the breakpoints themselves. From breakpoint.c. */ | |
353 | ||
31ef19fc JK |
354 | int |
355 | read_memory_nobpt (memaddr, myaddr, len) | |
356 | CORE_ADDR memaddr; | |
357 | char *myaddr; | |
358 | unsigned len; | |
359 | { | |
360 | int status; | |
361 | struct breakpoint *b; | |
362 | ||
363 | if (memory_breakpoint_size < 0) | |
5af4f5f6 JK |
364 | /* No breakpoints on this machine. FIXME: This should be |
365 | dependent on the debugging target. Probably want | |
366 | target_insert_breakpoint to return a size, saying how many | |
367 | bytes of the shadow contents are used, or perhaps have | |
368 | something like target_xfer_shadow. */ | |
31ef19fc JK |
369 | return target_read_memory (memaddr, myaddr, len); |
370 | ||
371 | ALL_BREAKPOINTS (b) | |
372 | { | |
999dd04b JL |
373 | if (b->type == bp_watchpoint |
374 | || b->type == bp_hardware_watchpoint | |
11054881 KH |
375 | || b->type == bp_read_watchpoint |
376 | || b->type == bp_access_watchpoint | |
999dd04b | 377 | || !b->inserted) |
31ef19fc JK |
378 | continue; |
379 | else if (b->address + memory_breakpoint_size <= memaddr) | |
380 | /* The breakpoint is entirely before the chunk of memory | |
381 | we are reading. */ | |
382 | continue; | |
383 | else if (b->address >= memaddr + len) | |
384 | /* The breakpoint is entirely after the chunk of memory we | |
385 | are reading. */ | |
386 | continue; | |
387 | else | |
388 | { | |
389 | /* Copy the breakpoint from the shadow contents, and recurse | |
390 | for the things before and after. */ | |
391 | ||
392 | /* Addresses and length of the part of the breakpoint that | |
393 | we need to copy. */ | |
394 | CORE_ADDR membpt = b->address; | |
395 | unsigned int bptlen = memory_breakpoint_size; | |
396 | /* Offset within shadow_contents. */ | |
397 | int bptoffset = 0; | |
398 | ||
399 | if (membpt < memaddr) | |
400 | { | |
401 | /* Only copy the second part of the breakpoint. */ | |
402 | bptlen -= memaddr - membpt; | |
403 | bptoffset = memaddr - membpt; | |
404 | membpt = memaddr; | |
405 | } | |
406 | ||
407 | if (membpt + bptlen > memaddr + len) | |
408 | { | |
409 | /* Only copy the first part of the breakpoint. */ | |
410 | bptlen -= (membpt + bptlen) - (memaddr + len); | |
411 | } | |
412 | ||
4ed3a9ea FF |
413 | memcpy (myaddr + membpt - memaddr, |
414 | b->shadow_contents + bptoffset, bptlen); | |
31ef19fc JK |
415 | |
416 | if (membpt > memaddr) | |
417 | { | |
418 | /* Copy the section of memory before the breakpoint. */ | |
419 | status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr); | |
420 | if (status != 0) | |
421 | return status; | |
422 | } | |
423 | ||
424 | if (membpt + bptlen < memaddr + len) | |
425 | { | |
426 | /* Copy the section of memory after the breakpoint. */ | |
427 | status = read_memory_nobpt | |
428 | (membpt + bptlen, | |
429 | myaddr + membpt + bptlen - memaddr, | |
430 | memaddr + len - (membpt + bptlen)); | |
431 | if (status != 0) | |
432 | return status; | |
433 | } | |
434 | return 0; | |
435 | } | |
436 | } | |
437 | /* Nothing overlaps. Just call read_memory_noerr. */ | |
438 | return target_read_memory (memaddr, myaddr, len); | |
439 | } | |
440 | \f | |
bd5635a1 RP |
441 | /* insert_breakpoints is used when starting or continuing the program. |
442 | remove_breakpoints is used when the program stops. | |
443 | Both return zero if successful, | |
444 | or an `errno' value if could not write the inferior. */ | |
445 | ||
446 | int | |
447 | insert_breakpoints () | |
448 | { | |
fa3764e2 | 449 | register struct breakpoint *b, *temp; |
bd5635a1 RP |
450 | int val = 0; |
451 | int disabled_breaks = 0; | |
452 | ||
fa3764e2 | 453 | ALL_BREAKPOINTS_SAFE (b, temp) |
30875e1c | 454 | if (b->type != bp_watchpoint |
999dd04b | 455 | && b->type != bp_hardware_watchpoint |
11054881 KH |
456 | && b->type != bp_read_watchpoint |
457 | && b->type != bp_access_watchpoint | |
bd5635a1 | 458 | && b->enable != disabled |
fa3764e2 | 459 | && b->enable != shlib_disabled |
bd5635a1 RP |
460 | && ! b->inserted |
461 | && ! b->duplicate) | |
462 | { | |
11054881 KH |
463 | if (b->type == bp_hardware_breakpoint) |
464 | val = target_insert_hw_breakpoint(b->address, b->shadow_contents); | |
465 | else | |
466 | val = target_insert_breakpoint(b->address, b->shadow_contents); | |
bd5635a1 RP |
467 | if (val) |
468 | { | |
469 | /* Can't set the breakpoint. */ | |
470 | #if defined (DISABLE_UNSETTABLE_BREAK) | |
471 | if (DISABLE_UNSETTABLE_BREAK (b->address)) | |
472 | { | |
473 | val = 0; | |
fa3764e2 | 474 | b->enable = shlib_disabled; |
bd5635a1 RP |
475 | if (!disabled_breaks) |
476 | { | |
05052b63 | 477 | target_terminal_ours_for_output (); |
199b2450 | 478 | fprintf_unfiltered (gdb_stderr, |
2d313932 | 479 | "Cannot insert breakpoint %d:\n", b->number); |
fa3764e2 | 480 | printf_filtered ("Temporarily disabling shared library breakpoints:\n"); |
bd5635a1 RP |
481 | } |
482 | disabled_breaks = 1; | |
483 | printf_filtered ("%d ", b->number); | |
484 | } | |
485 | else | |
486 | #endif | |
487 | { | |
05052b63 | 488 | target_terminal_ours_for_output (); |
199b2450 | 489 | fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number); |
d3b9c0df | 490 | #ifdef ONE_PROCESS_WRITETEXT |
199b2450 | 491 | fprintf_unfiltered (gdb_stderr, |
2d313932 | 492 | "The same program may be running in another process.\n"); |
d3b9c0df | 493 | #endif |
bd5635a1 RP |
494 | memory_error (val, b->address); /* which bombs us out */ |
495 | } | |
496 | } | |
497 | else | |
498 | b->inserted = 1; | |
499 | } | |
11054881 KH |
500 | else if ((b->type == bp_hardware_watchpoint || |
501 | b->type == bp_read_watchpoint || | |
502 | b->type == bp_access_watchpoint) | |
999dd04b JL |
503 | && b->enable == enabled |
504 | && ! b->inserted | |
505 | && ! b->duplicate) | |
506 | { | |
706dc3ce | 507 | struct frame_info *saved_frame; |
999dd04b JL |
508 | int saved_level, within_current_scope; |
509 | value_ptr mark = value_mark (); | |
510 | value_ptr v; | |
511 | ||
512 | /* Save the current frame and level so we can restore it after | |
513 | evaluating the watchpoint expression on its own frame. */ | |
514 | saved_frame = selected_frame; | |
515 | saved_level = selected_frame_level; | |
516 | ||
517 | /* Determine if the watchpoint is within scope. */ | |
518 | if (b->exp_valid_block == NULL) | |
519 | within_current_scope = 1; | |
520 | else | |
521 | { | |
706dc3ce JL |
522 | struct frame_info *fi = |
523 | find_frame_addr_in_frame_chain (b->watchpoint_frame); | |
524 | within_current_scope = (fi != NULL); | |
999dd04b | 525 | if (within_current_scope) |
706dc3ce | 526 | select_frame (fi, -1); |
999dd04b JL |
527 | } |
528 | ||
529 | if (within_current_scope) | |
530 | { | |
531 | /* Evaluate the expression and cut the chain of values | |
532 | produced off from the value chain. */ | |
533 | v = evaluate_expression (b->exp); | |
534 | value_release_to_mark (mark); | |
535 | ||
536 | b->val_chain = v; | |
537 | b->inserted = 1; | |
538 | ||
539 | /* Look at each value on the value chain. */ | |
540 | for ( ; v; v=v->next) | |
541 | { | |
542 | /* If it's a memory location, then we must watch it. */ | |
543 | if (v->lval == lval_memory) | |
544 | { | |
11054881 | 545 | int addr, len, type; |
999dd04b JL |
546 | |
547 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
548 | len = TYPE_LENGTH (VALUE_TYPE (v)); | |
11054881 KH |
549 | type = 0; |
550 | if (b->type == bp_read_watchpoint) | |
551 | type = 1; | |
552 | else if (b->type == bp_access_watchpoint) | |
553 | type = 2; | |
554 | ||
555 | val = target_insert_watchpoint (addr, len, type); | |
999dd04b JL |
556 | if (val == -1) |
557 | { | |
558 | b->inserted = 0; | |
559 | break; | |
560 | } | |
561 | val = 0; | |
562 | } | |
563 | } | |
564 | /* Failure to insert a watchpoint on any memory value in the | |
565 | value chain brings us here. */ | |
566 | if (!b->inserted) | |
567 | warning ("Hardware watchpoint %d: Could not insert watchpoint\n", | |
568 | b->number); | |
569 | } | |
570 | else | |
571 | { | |
572 | printf_filtered ("\ | |
573 | Hardware watchpoint %d deleted because the program has left the block in\n\ | |
574 | which its expression is valid.\n", b->number); | |
575 | if (b->related_breakpoint) | |
e51481f9 JL |
576 | { |
577 | b->related_breakpoint->enable = disable; | |
578 | b->related_breakpoint->disposition = del_at_next_stop; | |
579 | } | |
580 | b->enable = disable; | |
581 | b->disposition = del_at_next_stop; | |
999dd04b JL |
582 | } |
583 | ||
584 | /* Restore the frame and level. */ | |
585 | select_frame (saved_frame, saved_level); | |
586 | } | |
bd5635a1 RP |
587 | if (disabled_breaks) |
588 | printf_filtered ("\n"); | |
589 | return val; | |
590 | } | |
591 | ||
999dd04b | 592 | |
bd5635a1 RP |
593 | int |
594 | remove_breakpoints () | |
595 | { | |
596 | register struct breakpoint *b; | |
597 | int val; | |
598 | ||
bd5635a1 | 599 | ALL_BREAKPOINTS (b) |
999dd04b JL |
600 | { |
601 | if (b->inserted) | |
602 | { | |
603 | val = remove_breakpoint (b); | |
604 | if (val != 0) | |
605 | return val; | |
606 | } | |
607 | } | |
608 | return 0; | |
609 | } | |
bd5635a1 | 610 | |
999dd04b JL |
611 | |
612 | static int | |
613 | remove_breakpoint (b) | |
614 | struct breakpoint *b; | |
615 | { | |
616 | int val; | |
617 | ||
618 | if (b->type != bp_watchpoint | |
11054881 KH |
619 | && b->type != bp_hardware_watchpoint |
620 | && b->type != bp_read_watchpoint | |
621 | && b->type != bp_access_watchpoint) | |
999dd04b | 622 | { |
11054881 KH |
623 | if (b->type == bp_hardware_breakpoint) |
624 | val = target_remove_hw_breakpoint(b->address, b->shadow_contents); | |
625 | else | |
626 | val = target_remove_breakpoint(b->address, b->shadow_contents); | |
999dd04b JL |
627 | if (val) |
628 | return val; | |
629 | b->inserted = 0; | |
630 | } | |
11054881 KH |
631 | else if ((b->type == bp_hardware_watchpoint || |
632 | b->type == bp_read_watchpoint || | |
633 | b->type == bp_access_watchpoint) | |
999dd04b JL |
634 | && b->enable == enabled |
635 | && ! b->duplicate) | |
636 | { | |
637 | value_ptr v, n; | |
638 | ||
639 | b->inserted = 0; | |
640 | /* Walk down the saved value chain. */ | |
641 | for (v = b->val_chain; v; v = v->next) | |
642 | { | |
643 | /* For each memory reference remove the watchpoint | |
644 | at that address. */ | |
645 | if (v->lval == lval_memory) | |
646 | { | |
647 | int addr, len; | |
648 | ||
649 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
650 | len = TYPE_LENGTH (VALUE_TYPE (v)); | |
11054881 | 651 | val = target_remove_watchpoint (addr, len, b->type); |
999dd04b JL |
652 | if (val == -1) |
653 | b->inserted = 1; | |
654 | val = 0; | |
655 | } | |
656 | } | |
657 | /* Failure to remove any of the hardware watchpoints comes here. */ | |
658 | if (b->inserted) | |
0fe1522a SG |
659 | warning ("Hardware watchpoint %d: Could not remove watchpoint\n", |
660 | b->number); | |
999dd04b JL |
661 | |
662 | /* Free the saved value chain. We will construct a new one | |
663 | the next time the watchpoint is inserted. */ | |
664 | for (v = b->val_chain; v; v = n) | |
665 | { | |
666 | n = v->next; | |
667 | value_free (v); | |
668 | } | |
669 | b->val_chain = NULL; | |
670 | } | |
bd5635a1 RP |
671 | return 0; |
672 | } | |
673 | ||
cf3e377e | 674 | /* Clear the "inserted" flag in all breakpoints. */ |
bd5635a1 RP |
675 | |
676 | void | |
677 | mark_breakpoints_out () | |
678 | { | |
679 | register struct breakpoint *b; | |
680 | ||
681 | ALL_BREAKPOINTS (b) | |
682 | b->inserted = 0; | |
683 | } | |
684 | ||
cf3e377e JK |
685 | /* Clear the "inserted" flag in all breakpoints and delete any breakpoints |
686 | which should go away between runs of the program. */ | |
687 | ||
688 | void | |
689 | breakpoint_init_inferior () | |
690 | { | |
691 | register struct breakpoint *b, *temp; | |
692 | ||
693 | ALL_BREAKPOINTS_SAFE (b, temp) | |
694 | { | |
695 | b->inserted = 0; | |
696 | ||
e51481f9 JL |
697 | switch (b->type) |
698 | { | |
699 | case bp_call_dummy: | |
700 | case bp_watchpoint_scope: | |
999dd04b | 701 | |
e51481f9 JL |
702 | /* If the call dummy breakpoint is at the entry point it will |
703 | cause problems when the inferior is rerun, so we better | |
704 | get rid of it. | |
999dd04b | 705 | |
e51481f9 JL |
706 | Also get rid of scope breakpoints. */ |
707 | delete_breakpoint (b); | |
708 | break; | |
709 | ||
710 | case bp_watchpoint: | |
711 | case bp_hardware_watchpoint: | |
712 | case bp_read_watchpoint: | |
713 | case bp_access_watchpoint: | |
714 | ||
715 | /* Likewise for watchpoints on local expressions. */ | |
716 | if (b->exp_valid_block != NULL) | |
717 | delete_breakpoint (b); | |
718 | break; | |
719 | ||
720 | default: | |
721 | break; | |
722 | } | |
cf3e377e JK |
723 | } |
724 | } | |
725 | ||
bd5635a1 RP |
726 | /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC. |
727 | When continuing from a location with a breakpoint, | |
728 | we actually single step once before calling insert_breakpoints. */ | |
729 | ||
730 | int | |
731 | breakpoint_here_p (pc) | |
732 | CORE_ADDR pc; | |
733 | { | |
734 | register struct breakpoint *b; | |
735 | ||
736 | ALL_BREAKPOINTS (b) | |
fa3764e2 JL |
737 | if (b->enable != disabled |
738 | && b->enable != shlib_disabled | |
739 | && b->address == pc) | |
bd5635a1 RP |
740 | return 1; |
741 | ||
742 | return 0; | |
743 | } | |
199b2450 | 744 | |
05052b63 JK |
745 | /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY |
746 | because figuring out the saved SP would take too much time, at least using | |
747 | get_saved_register on the 68k. This means that for this function to | |
748 | work right a port must use the bp_call_dummy breakpoint. */ | |
749 | ||
750 | int | |
751 | frame_in_dummy (frame) | |
706dc3ce | 752 | struct frame_info *frame; |
05052b63 JK |
753 | { |
754 | struct breakpoint *b; | |
755 | ||
d7e7e851 | 756 | #ifdef CALL_DUMMY |
05052b63 JK |
757 | ALL_BREAKPOINTS (b) |
758 | { | |
d7e7e851 JK |
759 | static unsigned LONGEST dummy[] = CALL_DUMMY; |
760 | ||
05052b63 | 761 | if (b->type == bp_call_dummy |
d7e7e851 JK |
762 | && b->frame == frame->frame |
763 | ||
764 | /* We need to check the PC as well as the frame on the sparc, | |
765 | for signals.exp in the testsuite. */ | |
766 | && (frame->pc | |
767 | >= (b->address | |
768 | - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE)) | |
769 | && frame->pc <= b->address) | |
05052b63 JK |
770 | return 1; |
771 | } | |
d7e7e851 | 772 | #endif /* CALL_DUMMY */ |
05052b63 JK |
773 | return 0; |
774 | } | |
775 | ||
199b2450 TL |
776 | /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC |
777 | is valid for process/thread PID. */ | |
778 | ||
779 | int | |
780 | breakpoint_thread_match (pc, pid) | |
781 | CORE_ADDR pc; | |
782 | int pid; | |
783 | { | |
784 | struct breakpoint *b; | |
785 | int thread; | |
786 | ||
787 | thread = pid_to_thread_id (pid); | |
788 | ||
789 | ALL_BREAKPOINTS (b) | |
790 | if (b->enable != disabled | |
fa3764e2 | 791 | && b->enable != shlib_disabled |
199b2450 TL |
792 | && b->address == pc |
793 | && (b->thread == -1 || b->thread == thread)) | |
794 | return 1; | |
795 | ||
796 | return 0; | |
797 | } | |
798 | ||
bd5635a1 RP |
799 | \f |
800 | /* bpstat stuff. External routines' interfaces are documented | |
801 | in breakpoint.h. */ | |
30875e1c SG |
802 | |
803 | /* Clear a bpstat so that it says we are not at any breakpoint. | |
804 | Also free any storage that is part of a bpstat. */ | |
805 | ||
bd5635a1 RP |
806 | void |
807 | bpstat_clear (bsp) | |
808 | bpstat *bsp; | |
809 | { | |
810 | bpstat p; | |
811 | bpstat q; | |
812 | ||
813 | if (bsp == 0) | |
814 | return; | |
815 | p = *bsp; | |
816 | while (p != NULL) | |
817 | { | |
818 | q = p->next; | |
819 | if (p->old_val != NULL) | |
820 | value_free (p->old_val); | |
c8950965 | 821 | free ((PTR)p); |
bd5635a1 RP |
822 | p = q; |
823 | } | |
824 | *bsp = NULL; | |
825 | } | |
826 | ||
30875e1c SG |
827 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
828 | is part of the bpstat is copied as well. */ | |
829 | ||
bd5635a1 RP |
830 | bpstat |
831 | bpstat_copy (bs) | |
832 | bpstat bs; | |
833 | { | |
834 | bpstat p = NULL; | |
835 | bpstat tmp; | |
fee933f1 | 836 | bpstat retval = NULL; |
bd5635a1 RP |
837 | |
838 | if (bs == NULL) | |
839 | return bs; | |
840 | ||
841 | for (; bs != NULL; bs = bs->next) | |
842 | { | |
843 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
4ed3a9ea | 844 | memcpy (tmp, bs, sizeof (*tmp)); |
bd5635a1 RP |
845 | if (p == NULL) |
846 | /* This is the first thing in the chain. */ | |
847 | retval = tmp; | |
848 | else | |
849 | p->next = tmp; | |
850 | p = tmp; | |
851 | } | |
852 | p->next = NULL; | |
853 | return retval; | |
854 | } | |
855 | ||
30875e1c SG |
856 | /* Find the bpstat associated with this breakpoint */ |
857 | ||
858 | bpstat | |
859 | bpstat_find_breakpoint(bsp, breakpoint) | |
860 | bpstat bsp; | |
861 | struct breakpoint *breakpoint; | |
862 | { | |
863 | if (bsp == NULL) return NULL; | |
864 | ||
865 | for (;bsp != NULL; bsp = bsp->next) { | |
866 | if (bsp->breakpoint_at == breakpoint) return bsp; | |
867 | } | |
868 | return NULL; | |
869 | } | |
870 | ||
871 | /* Return the breakpoint number of the first breakpoint we are stopped | |
872 | at. *BSP upon return is a bpstat which points to the remaining | |
873 | breakpoints stopped at (but which is not guaranteed to be good for | |
874 | anything but further calls to bpstat_num). | |
875 | Return 0 if passed a bpstat which does not indicate any breakpoints. */ | |
876 | ||
bd5635a1 RP |
877 | int |
878 | bpstat_num (bsp) | |
879 | bpstat *bsp; | |
880 | { | |
881 | struct breakpoint *b; | |
882 | ||
883 | if ((*bsp) == NULL) | |
884 | return 0; /* No more breakpoint values */ | |
885 | else | |
886 | { | |
887 | b = (*bsp)->breakpoint_at; | |
888 | *bsp = (*bsp)->next; | |
889 | if (b == NULL) | |
890 | return -1; /* breakpoint that's been deleted since */ | |
891 | else | |
892 | return b->number; /* We have its number */ | |
893 | } | |
894 | } | |
895 | ||
30875e1c SG |
896 | /* Modify BS so that the actions will not be performed. */ |
897 | ||
bd5635a1 RP |
898 | void |
899 | bpstat_clear_actions (bs) | |
900 | bpstat bs; | |
901 | { | |
902 | for (; bs != NULL; bs = bs->next) | |
903 | { | |
904 | bs->commands = NULL; | |
905 | if (bs->old_val != NULL) | |
906 | { | |
907 | value_free (bs->old_val); | |
908 | bs->old_val = NULL; | |
909 | } | |
910 | } | |
911 | } | |
912 | ||
bdbd5f50 JG |
913 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
914 | /* ARGSUSED */ | |
915 | static void | |
916 | cleanup_executing_breakpoints (ignore) | |
917 | int ignore; | |
918 | { | |
919 | executing_breakpoint_commands = 0; | |
920 | } | |
921 | ||
bd5635a1 RP |
922 | /* Execute all the commands associated with all the breakpoints at this |
923 | location. Any of these commands could cause the process to proceed | |
924 | beyond this point, etc. We look out for such changes by checking | |
925 | the global "breakpoint_proceeded" after each command. */ | |
30875e1c | 926 | |
bd5635a1 RP |
927 | void |
928 | bpstat_do_actions (bsp) | |
929 | bpstat *bsp; | |
930 | { | |
931 | bpstat bs; | |
bdbd5f50 | 932 | struct cleanup *old_chain; |
e8bf33c4 | 933 | struct command_line *cmd; |
bdbd5f50 | 934 | |
647e52ea SG |
935 | /* Avoid endless recursion if a `source' command is contained |
936 | in bs->commands. */ | |
937 | if (executing_breakpoint_commands) | |
938 | return; | |
939 | ||
bdbd5f50 JG |
940 | executing_breakpoint_commands = 1; |
941 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
bd5635a1 RP |
942 | |
943 | top: | |
944 | bs = *bsp; | |
945 | ||
bd5635a1 RP |
946 | breakpoint_proceeded = 0; |
947 | for (; bs != NULL; bs = bs->next) | |
948 | { | |
e8bf33c4 JK |
949 | cmd = bs->commands; |
950 | while (cmd != NULL) | |
bd5635a1 | 951 | { |
0f8cdd9b | 952 | execute_control_command (cmd); |
e8bf33c4 | 953 | cmd = cmd->next; |
bd5635a1 | 954 | } |
e8bf33c4 JK |
955 | if (breakpoint_proceeded) |
956 | /* The inferior is proceeded by the command; bomb out now. | |
957 | The bpstat chain has been blown away by wait_for_inferior. | |
958 | But since execution has stopped again, there is a new bpstat | |
959 | to look at, so start over. */ | |
960 | goto top; | |
961 | else | |
962 | bs->commands = NULL; | |
bd5635a1 | 963 | } |
bd5635a1 RP |
964 | |
965 | executing_breakpoint_commands = 0; | |
bdbd5f50 | 966 | discard_cleanups (old_chain); |
bd5635a1 RP |
967 | } |
968 | ||
8af68e4e JK |
969 | /* This is the normal print_it function for a bpstat. In the future, |
970 | much of this logic could (should?) be moved to bpstat_stop_status, | |
971 | by having it set different print_it functions. */ | |
30875e1c | 972 | |
8af68e4e JK |
973 | static int |
974 | print_it_normal (bs) | |
bd5635a1 RP |
975 | bpstat bs; |
976 | { | |
977 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint | |
978 | which has since been deleted. */ | |
8af68e4e | 979 | if (bs->breakpoint_at == NULL |
30875e1c | 980 | || (bs->breakpoint_at->type != bp_breakpoint |
11054881 | 981 | && bs->breakpoint_at->type != bp_hardware_breakpoint |
999dd04b | 982 | && bs->breakpoint_at->type != bp_watchpoint |
11054881 KH |
983 | && bs->breakpoint_at->type != bp_read_watchpoint |
984 | && bs->breakpoint_at->type != bp_access_watchpoint | |
999dd04b | 985 | && bs->breakpoint_at->type != bp_hardware_watchpoint)) |
bd5635a1 | 986 | return 0; |
bd5635a1 | 987 | |
11054881 KH |
988 | if (bs->breakpoint_at->type == bp_breakpoint || |
989 | bs->breakpoint_at->type == bp_hardware_breakpoint) | |
bd5635a1 RP |
990 | { |
991 | /* I think the user probably only wants to see one breakpoint | |
992 | number, not all of them. */ | |
f2d9c058 | 993 | annotate_breakpoint (bs->breakpoint_at->number); |
bd5635a1 RP |
994 | printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number); |
995 | return 0; | |
996 | } | |
11054881 KH |
997 | else if ((bs->old_val != NULL) && |
998 | (bs->breakpoint_at->type == bp_watchpoint || | |
999 | bs->breakpoint_at->type == bp_access_watchpoint || | |
1000 | bs->breakpoint_at->type == bp_hardware_watchpoint)) | |
bd5635a1 | 1001 | { |
f2d9c058 | 1002 | annotate_watchpoint (bs->breakpoint_at->number); |
11054881 | 1003 | mention (bs->breakpoint_at); |
bd5635a1 | 1004 | printf_filtered ("\nOld value = "); |
199b2450 | 1005 | value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default); |
bd5635a1 | 1006 | printf_filtered ("\nNew value = "); |
199b2450 | 1007 | value_print (bs->breakpoint_at->val, gdb_stdout, 0, |
bd5635a1 RP |
1008 | Val_pretty_default); |
1009 | printf_filtered ("\n"); | |
1010 | value_free (bs->old_val); | |
1011 | bs->old_val = NULL; | |
bd2f0c85 JL |
1012 | /* More than one watchpoint may have been triggered. */ |
1013 | return -1; | |
bd5635a1 | 1014 | } |
11054881 KH |
1015 | else if (bs->breakpoint_at->type == bp_access_watchpoint || |
1016 | bs->breakpoint_at->type == bp_read_watchpoint) | |
1017 | { | |
1018 | mention (bs->breakpoint_at); | |
1019 | printf_filtered ("\nValue = "); | |
1020 | value_print (bs->breakpoint_at->val, gdb_stdout, 0, | |
1021 | Val_pretty_default); | |
1022 | printf_filtered ("\n"); | |
1023 | return -1; | |
1024 | } | |
8af68e4e JK |
1025 | /* We can't deal with it. Maybe another member of the bpstat chain can. */ |
1026 | return -1; | |
1027 | } | |
1028 | ||
1029 | /* Print a message indicating what happened. Returns nonzero to | |
1030 | say that only the source line should be printed after this (zero | |
1031 | return means print the frame as well as the source line). */ | |
3f031adf | 1032 | /* Currently we always return zero. */ |
8af68e4e JK |
1033 | int |
1034 | bpstat_print (bs) | |
1035 | bpstat bs; | |
1036 | { | |
1037 | int val; | |
1038 | ||
1039 | if (bs == NULL) | |
1040 | return 0; | |
bd5635a1 | 1041 | |
8af68e4e JK |
1042 | val = (*bs->print_it) (bs); |
1043 | if (val >= 0) | |
1044 | return val; | |
1045 | ||
fcb887ff JK |
1046 | /* Maybe another breakpoint in the chain caused us to stop. |
1047 | (Currently all watchpoints go on the bpstat whether hit or | |
1048 | not. That probably could (should) be changed, provided care is taken | |
1049 | with respect to bpstat_explains_signal). */ | |
1050 | if (bs->next) | |
1051 | return bpstat_print (bs->next); | |
1052 | ||
cabd4da6 | 1053 | /* We reached the end of the chain without printing anything. */ |
bd5635a1 RP |
1054 | return 0; |
1055 | } | |
1056 | ||
1057 | /* Evaluate the expression EXP and return 1 if value is zero. | |
1058 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
bdbd5f50 | 1059 | The argument is a "struct expression *" that has been cast to char * to |
bd5635a1 RP |
1060 | make it pass through catch_errors. */ |
1061 | ||
1062 | static int | |
1063 | breakpoint_cond_eval (exp) | |
bdbd5f50 | 1064 | char *exp; |
bd5635a1 | 1065 | { |
11054881 KH |
1066 | value_ptr mark = value_mark (); |
1067 | int i = !value_true (evaluate_expression ((struct expression *)exp)); | |
1068 | value_free_to_mark (mark); | |
1069 | return i; | |
bd5635a1 RP |
1070 | } |
1071 | ||
1072 | /* Allocate a new bpstat and chain it to the current one. */ | |
1073 | ||
1074 | static bpstat | |
1075 | bpstat_alloc (b, cbs) | |
1076 | register struct breakpoint *b; | |
1077 | bpstat cbs; /* Current "bs" value */ | |
1078 | { | |
1079 | bpstat bs; | |
1080 | ||
1081 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
1082 | cbs->next = bs; | |
1083 | bs->breakpoint_at = b; | |
1084 | /* If the condition is false, etc., don't do the commands. */ | |
1085 | bs->commands = NULL; | |
bd5635a1 | 1086 | bs->old_val = NULL; |
8af68e4e | 1087 | bs->print_it = print_it_normal; |
bd5635a1 RP |
1088 | return bs; |
1089 | } | |
fa99ebe1 | 1090 | \f |
8af68e4e JK |
1091 | /* Possible return values for watchpoint_check (this can't be an enum |
1092 | because of check_errors). */ | |
999dd04b JL |
1093 | /* The watchpoint has been deleted. */ |
1094 | #define WP_DELETED 1 | |
8af68e4e JK |
1095 | /* The value has changed. */ |
1096 | #define WP_VALUE_CHANGED 2 | |
1097 | /* The value has not changed. */ | |
1098 | #define WP_VALUE_NOT_CHANGED 3 | |
1099 | ||
e8bf33c4 JK |
1100 | #define BP_TEMPFLAG 1 |
1101 | #define BP_HARDWAREFLAG 2 | |
1102 | ||
8af68e4e | 1103 | /* Check watchpoint condition. */ |
557f3a0e | 1104 | |
8af68e4e JK |
1105 | static int |
1106 | watchpoint_check (p) | |
fe675038 | 1107 | char *p; |
8af68e4e JK |
1108 | { |
1109 | bpstat bs = (bpstat) p; | |
11054881 | 1110 | struct breakpoint *b; |
2b576293 C |
1111 | struct frame_info *fr; |
1112 | int within_current_scope; | |
999dd04b | 1113 | |
557f3a0e SS |
1114 | b = bs->breakpoint_at; |
1115 | ||
1116 | if (b->exp_valid_block == NULL) | |
8af68e4e | 1117 | within_current_scope = 1; |
fa99ebe1 JK |
1118 | else |
1119 | { | |
706dc3ce JL |
1120 | /* There is no current frame at this moment. If we're going to have |
1121 | any chance of handling watchpoints on local variables, we'll need | |
1122 | the frame chain (so we can determine if we're in scope). */ | |
1123 | reinit_frame_cache(); | |
557f3a0e | 1124 | fr = find_frame_addr_in_frame_chain (b->watchpoint_frame); |
999dd04b | 1125 | within_current_scope = (fr != NULL); |
fa99ebe1 JK |
1126 | if (within_current_scope) |
1127 | /* If we end up stopping, the current frame will get selected | |
1128 | in normal_stop. So this call to select_frame won't affect | |
1129 | the user. */ | |
1130 | select_frame (fr, -1); | |
1131 | } | |
1132 | ||
8af68e4e JK |
1133 | if (within_current_scope) |
1134 | { | |
1135 | /* We use value_{,free_to_}mark because it could be a | |
1136 | *long* time before we return to the command level and | |
cef4c2e7 PS |
1137 | call free_all_values. We can't call free_all_values because |
1138 | we might be in the middle of evaluating a function call. */ | |
8af68e4e | 1139 | |
82a2edfb JK |
1140 | value_ptr mark = value_mark (); |
1141 | value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp); | |
557f3a0e | 1142 | if (!value_equal (b->val, new_val)) |
8af68e4e JK |
1143 | { |
1144 | release_value (new_val); | |
1145 | value_free_to_mark (mark); | |
557f3a0e SS |
1146 | bs->old_val = b->val; |
1147 | b->val = new_val; | |
8af68e4e JK |
1148 | /* We will stop here */ |
1149 | return WP_VALUE_CHANGED; | |
1150 | } | |
1151 | else | |
1152 | { | |
1153 | /* Nothing changed, don't do anything. */ | |
1154 | value_free_to_mark (mark); | |
1155 | /* We won't stop here */ | |
1156 | return WP_VALUE_NOT_CHANGED; | |
1157 | } | |
1158 | } | |
1159 | else | |
1160 | { | |
1161 | /* This seems like the only logical thing to do because | |
1162 | if we temporarily ignored the watchpoint, then when | |
1163 | we reenter the block in which it is valid it contains | |
1164 | garbage (in the case of a function, it may have two | |
1165 | garbage values, one before and one after the prologue). | |
1166 | So we can't even detect the first assignment to it and | |
1167 | watch after that (since the garbage may or may not equal | |
1168 | the first value assigned). */ | |
8af68e4e | 1169 | printf_filtered ("\ |
999dd04b | 1170 | Watchpoint %d deleted because the program has left the block in\n\ |
8af68e4e | 1171 | which its expression is valid.\n", bs->breakpoint_at->number); |
557f3a0e | 1172 | if (b->related_breakpoint) |
e51481f9 JL |
1173 | { |
1174 | b->related_breakpoint->enable = disable; | |
1175 | b->related_breakpoint->disposition = del_at_next_stop; | |
1176 | } | |
1177 | b->enable = disable; | |
1178 | b->disposition = del_at_next_stop; | |
999dd04b | 1179 | |
999dd04b | 1180 | return WP_DELETED; |
8af68e4e JK |
1181 | } |
1182 | } | |
1183 | ||
1184 | /* This is used when everything which needs to be printed has | |
1185 | already been printed. But we still want to print the frame. */ | |
1186 | static int | |
cabd4da6 | 1187 | print_it_done (bs) |
8af68e4e JK |
1188 | bpstat bs; |
1189 | { | |
1190 | return 0; | |
1191 | } | |
1192 | ||
cabd4da6 JK |
1193 | /* This is used when nothing should be printed for this bpstat entry. */ |
1194 | ||
1195 | static int | |
1196 | print_it_noop (bs) | |
1197 | bpstat bs; | |
1198 | { | |
1199 | return -1; | |
1200 | } | |
1201 | ||
cb6b0202 | 1202 | /* Get a bpstat associated with having just stopped at address *PC |
706dc3ce | 1203 | and frame address CORE_ADDRESS. Update *PC to point at the |
cb6b0202 JK |
1204 | breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero |
1205 | if this is known to not be a real breakpoint (it could still be a | |
1206 | watchpoint, though). */ | |
1207 | ||
bd5635a1 RP |
1208 | /* Determine whether we stopped at a breakpoint, etc, or whether we |
1209 | don't understand this stop. Result is a chain of bpstat's such that: | |
1210 | ||
1211 | if we don't understand the stop, the result is a null pointer. | |
1212 | ||
cb6b0202 | 1213 | if we understand why we stopped, the result is not null. |
bd5635a1 RP |
1214 | |
1215 | Each element of the chain refers to a particular breakpoint or | |
1216 | watchpoint at which we have stopped. (We may have stopped for | |
2d313932 | 1217 | several reasons concurrently.) |
bd5635a1 RP |
1218 | |
1219 | Each element of the chain has valid next, breakpoint_at, | |
1220 | commands, FIXME??? fields. | |
1221 | ||
1222 | */ | |
1223 | ||
bd5635a1 | 1224 | bpstat |
16726dd1 | 1225 | bpstat_stop_status (pc, not_a_breakpoint) |
bd5635a1 | 1226 | CORE_ADDR *pc; |
cb6b0202 | 1227 | int not_a_breakpoint; |
bd5635a1 | 1228 | { |
fa3764e2 | 1229 | register struct breakpoint *b, *temp; |
bd5635a1 | 1230 | CORE_ADDR bp_addr; |
bdbd5f50 | 1231 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
bd5635a1 RP |
1232 | /* True if we've hit a breakpoint (as opposed to a watchpoint). */ |
1233 | int real_breakpoint = 0; | |
bdbd5f50 | 1234 | #endif |
bd5635a1 | 1235 | /* Root of the chain of bpstat's */ |
e8bf33c4 | 1236 | struct bpstats root_bs[1]; |
bd5635a1 RP |
1237 | /* Pointer to the last thing in the chain currently. */ |
1238 | bpstat bs = root_bs; | |
11054881 KH |
1239 | static char message1[] = |
1240 | "Error evaluating expression for watchpoint %d\n"; | |
1241 | char message[sizeof (message1) + 30 /* slop */]; | |
bd5635a1 RP |
1242 | |
1243 | /* Get the address where the breakpoint would have been. */ | |
1244 | bp_addr = *pc - DECR_PC_AFTER_BREAK; | |
1245 | ||
fa3764e2 | 1246 | ALL_BREAKPOINTS_SAFE (b, temp) |
bd5635a1 | 1247 | { |
fa3764e2 JL |
1248 | if (b->enable == disabled |
1249 | || b->enable == shlib_disabled) | |
bd5635a1 | 1250 | continue; |
30875e1c | 1251 | |
999dd04b JL |
1252 | if (b->type != bp_watchpoint |
1253 | && b->type != bp_hardware_watchpoint | |
11054881 KH |
1254 | && b->type != bp_read_watchpoint |
1255 | && b->type != bp_access_watchpoint | |
1256 | && b->type != bp_hardware_breakpoint | |
999dd04b | 1257 | && b->address != bp_addr) |
bd5635a1 RP |
1258 | continue; |
1259 | ||
11054881 KH |
1260 | if (b->type == bp_hardware_breakpoint |
1261 | && b->address != (bp_addr - DECR_PC_AFTER_HW_BREAK)) | |
1262 | continue; | |
1263 | ||
999dd04b JL |
1264 | if (b->type != bp_watchpoint |
1265 | && b->type != bp_hardware_watchpoint | |
11054881 KH |
1266 | && b->type != bp_read_watchpoint |
1267 | && b->type != bp_access_watchpoint | |
999dd04b | 1268 | && not_a_breakpoint) |
cb6b0202 JK |
1269 | continue; |
1270 | ||
30875e1c SG |
1271 | /* Come here if it's a watchpoint, or if the break address matches */ |
1272 | ||
9f577285 SS |
1273 | ++(b->hit_count); |
1274 | ||
bd5635a1 RP |
1275 | bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ |
1276 | ||
cabd4da6 JK |
1277 | bs->stop = 1; |
1278 | bs->print = 1; | |
bd5635a1 | 1279 | |
11054881 | 1280 | sprintf (message, message1, b->number); |
999dd04b | 1281 | if (b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) |
bd5635a1 | 1282 | { |
fe675038 JK |
1283 | switch (catch_errors (watchpoint_check, (char *) bs, message, |
1284 | RETURN_MASK_ALL)) | |
bd5635a1 | 1285 | { |
999dd04b | 1286 | case WP_DELETED: |
8af68e4e | 1287 | /* We've already printed what needs to be printed. */ |
cabd4da6 | 1288 | bs->print_it = print_it_done; |
8af68e4e JK |
1289 | /* Stop. */ |
1290 | break; | |
1291 | case WP_VALUE_CHANGED: | |
1292 | /* Stop. */ | |
1293 | break; | |
1294 | case WP_VALUE_NOT_CHANGED: | |
1295 | /* Don't stop. */ | |
cabd4da6 JK |
1296 | bs->print_it = print_it_noop; |
1297 | bs->stop = 0; | |
bd5635a1 | 1298 | continue; |
8af68e4e JK |
1299 | default: |
1300 | /* Can't happen. */ | |
1301 | /* FALLTHROUGH */ | |
1302 | case 0: | |
1303 | /* Error from catch_errors. */ | |
999dd04b JL |
1304 | printf_filtered ("Watchpoint %d deleted.\n", b->number); |
1305 | if (b->related_breakpoint) | |
e51481f9 JL |
1306 | { |
1307 | b->related_breakpoint->enable = disable; | |
1308 | b->related_breakpoint->disposition = del_at_next_stop; | |
1309 | } | |
1310 | b->enable = disable; | |
1311 | b->disposition = del_at_next_stop; | |
8af68e4e | 1312 | /* We've already printed what needs to be printed. */ |
cabd4da6 | 1313 | bs->print_it = print_it_done; |
999dd04b | 1314 | |
8af68e4e JK |
1315 | /* Stop. */ |
1316 | break; | |
bd5635a1 RP |
1317 | } |
1318 | } | |
11054881 KH |
1319 | else if (b->type == bp_read_watchpoint || b->type == bp_access_watchpoint) |
1320 | { | |
1321 | CORE_ADDR addr; | |
1322 | value_ptr v; | |
1323 | int found = 0; | |
1324 | ||
1325 | addr = target_stopped_data_address(); | |
1326 | if (addr == 0) continue; | |
1327 | for (v = b->val_chain; v; v = v->next) | |
1328 | { | |
1329 | if (v->lval == lval_memory) | |
1330 | { | |
1331 | CORE_ADDR vaddr; | |
1332 | ||
1333 | vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); | |
1334 | if (addr == vaddr) | |
1335 | found = 1; | |
1336 | } | |
1337 | } | |
1338 | if (found) | |
1339 | switch (catch_errors (watchpoint_check, (char *) bs, message, | |
1340 | RETURN_MASK_ALL)) | |
1341 | { | |
1342 | case WP_DELETED: | |
1343 | /* We've already printed what needs to be printed. */ | |
1344 | bs->print_it = print_it_done; | |
1345 | /* Stop. */ | |
1346 | break; | |
1347 | case WP_VALUE_CHANGED: | |
1348 | case WP_VALUE_NOT_CHANGED: | |
1349 | /* Stop. */ | |
1350 | break; | |
1351 | default: | |
1352 | /* Can't happen. */ | |
1353 | case 0: | |
1354 | /* Error from catch_errors. */ | |
1355 | printf_filtered ("Watchpoint %d deleted.\n", b->number); | |
e51481f9 JL |
1356 | if (b->related_breakpoint) |
1357 | { | |
1358 | b->related_breakpoint->enable = disable; | |
1359 | b->related_breakpoint->disposition = del_at_next_stop; | |
1360 | } | |
1361 | b->enable = disable; | |
1362 | b->disposition = del_at_next_stop; | |
11054881 KH |
1363 | /* We've already printed what needs to be printed. */ |
1364 | bs->print_it = print_it_done; | |
1365 | break; | |
1366 | } | |
1367 | } | |
bdbd5f50 | 1368 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
bd5635a1 RP |
1369 | else |
1370 | real_breakpoint = 1; | |
bdbd5f50 | 1371 | #endif |
bd5635a1 | 1372 | |
706dc3ce | 1373 | if (b->frame && b->frame != (get_current_frame ())->frame) |
cabd4da6 | 1374 | bs->stop = 0; |
bd5635a1 RP |
1375 | else |
1376 | { | |
fee933f1 | 1377 | int value_is_zero = 0; |
bd5635a1 RP |
1378 | |
1379 | if (b->cond) | |
1380 | { | |
1381 | /* Need to select the frame, with all that implies | |
1382 | so that the conditions will have the right context. */ | |
1383 | select_frame (get_current_frame (), 0); | |
bdbd5f50 JG |
1384 | value_is_zero |
1385 | = catch_errors (breakpoint_cond_eval, (char *)(b->cond), | |
fe675038 JK |
1386 | "Error in testing breakpoint condition:\n", |
1387 | RETURN_MASK_ALL); | |
06b6c733 | 1388 | /* FIXME-someday, should give breakpoint # */ |
bd5635a1 RP |
1389 | free_all_values (); |
1390 | } | |
bdbd5f50 | 1391 | if (b->cond && value_is_zero) |
bd5635a1 | 1392 | { |
cabd4da6 | 1393 | bs->stop = 0; |
bd5635a1 RP |
1394 | } |
1395 | else if (b->ignore_count > 0) | |
1396 | { | |
1397 | b->ignore_count--; | |
cabd4da6 | 1398 | bs->stop = 0; |
bd5635a1 RP |
1399 | } |
1400 | else | |
1401 | { | |
1402 | /* We will stop here */ | |
30875e1c | 1403 | if (b->disposition == disable) |
bd5635a1 RP |
1404 | b->enable = disabled; |
1405 | bs->commands = b->commands; | |
1406 | if (b->silent) | |
cabd4da6 | 1407 | bs->print = 0; |
2d313932 | 1408 | if (bs->commands && STREQ ("silent", bs->commands->line)) |
bd5635a1 RP |
1409 | { |
1410 | bs->commands = bs->commands->next; | |
cabd4da6 | 1411 | bs->print = 0; |
bd5635a1 RP |
1412 | } |
1413 | } | |
1414 | } | |
cabd4da6 JK |
1415 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
1416 | if (bs->stop == 0 || bs->print == 0) | |
1417 | bs->print_it = print_it_noop; | |
bd5635a1 RP |
1418 | } |
1419 | ||
1420 | bs->next = NULL; /* Terminate the chain */ | |
1421 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
cabd4da6 | 1422 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
bd5635a1 RP |
1423 | if (bs) |
1424 | { | |
bd5635a1 RP |
1425 | if (real_breakpoint) |
1426 | { | |
1427 | *pc = bp_addr; | |
1428 | #if defined (SHIFT_INST_REGS) | |
817ac7f8 | 1429 | SHIFT_INST_REGS(); |
bd5635a1 RP |
1430 | #else /* No SHIFT_INST_REGS. */ |
1431 | write_pc (bp_addr); | |
1432 | #endif /* No SHIFT_INST_REGS. */ | |
1433 | } | |
bd5635a1 | 1434 | } |
cabd4da6 | 1435 | #endif /* DECR_PC_AFTER_BREAK != 0. */ |
999dd04b JL |
1436 | |
1437 | /* The value of a hardware watchpoint hasn't changed, but the | |
1438 | intermediate memory locations we are watching may have. */ | |
11054881 KH |
1439 | if (bs && ! bs->stop && |
1440 | (bs->breakpoint_at->type == bp_hardware_watchpoint || | |
1441 | bs->breakpoint_at->type == bp_read_watchpoint || | |
1442 | bs->breakpoint_at->type == bp_access_watchpoint)) | |
999dd04b JL |
1443 | { |
1444 | remove_breakpoints (); | |
1445 | insert_breakpoints (); | |
1446 | } | |
bd5635a1 RP |
1447 | return bs; |
1448 | } | |
cabd4da6 JK |
1449 | \f |
1450 | /* Tell what to do about this bpstat. */ | |
fe675038 | 1451 | struct bpstat_what |
cabd4da6 JK |
1452 | bpstat_what (bs) |
1453 | bpstat bs; | |
1454 | { | |
1455 | /* Classify each bpstat as one of the following. */ | |
1456 | enum class { | |
fe675038 JK |
1457 | /* This bpstat element has no effect on the main_action. */ |
1458 | no_effect = 0, | |
cabd4da6 JK |
1459 | |
1460 | /* There was a watchpoint, stop but don't print. */ | |
1461 | wp_silent, | |
1462 | ||
1463 | /* There was a watchpoint, stop and print. */ | |
1464 | wp_noisy, | |
1465 | ||
1466 | /* There was a breakpoint but we're not stopping. */ | |
1467 | bp_nostop, | |
1468 | ||
1469 | /* There was a breakpoint, stop but don't print. */ | |
1470 | bp_silent, | |
1471 | ||
1472 | /* There was a breakpoint, stop and print. */ | |
1473 | bp_noisy, | |
1474 | ||
1475 | /* We hit the longjmp breakpoint. */ | |
1476 | long_jump, | |
1477 | ||
1478 | /* We hit the longjmp_resume breakpoint. */ | |
1479 | long_resume, | |
1480 | ||
d7e7e851 JK |
1481 | /* We hit the step_resume breakpoint. */ |
1482 | step_resume, | |
1483 | ||
bcc37718 JK |
1484 | /* We hit the through_sigtramp breakpoint. */ |
1485 | through_sig, | |
1486 | ||
27b6a1fa JL |
1487 | /* We hit the shared library event breakpoint. */ |
1488 | shlib_event, | |
1489 | ||
cabd4da6 JK |
1490 | /* This is just used to count how many enums there are. */ |
1491 | class_last | |
1492 | }; | |
1493 | ||
1494 | /* Here is the table which drives this routine. So that we can | |
1495 | format it pretty, we define some abbreviations for the | |
1496 | enum bpstat_what codes. */ | |
27b6a1fa JL |
1497 | #define kc BPSTAT_WHAT_KEEP_CHECKING |
1498 | #define ss BPSTAT_WHAT_STOP_SILENT | |
1499 | #define sn BPSTAT_WHAT_STOP_NOISY | |
1500 | #define sgl BPSTAT_WHAT_SINGLE | |
1501 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
1502 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
1503 | #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE | |
d7e7e851 | 1504 | #define sr BPSTAT_WHAT_STEP_RESUME |
bcc37718 | 1505 | #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP |
27b6a1fa | 1506 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
d7e7e851 | 1507 | |
cabd4da6 JK |
1508 | /* "Can't happen." Might want to print an error message. |
1509 | abort() is not out of the question, but chances are GDB is just | |
1510 | a bit confused, not unusable. */ | |
1511 | #define err BPSTAT_WHAT_STOP_NOISY | |
1512 | ||
1513 | /* Given an old action and a class, come up with a new action. */ | |
84d59861 JK |
1514 | /* One interesting property of this table is that wp_silent is the same |
1515 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
1516 | after stopping, the check for whether to step over a breakpoint | |
1517 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
1518 | reference to how we stopped. We retain separate wp_silent and bp_silent | |
1519 | codes in case we want to change that someday. */ | |
d7e7e851 JK |
1520 | |
1521 | /* step_resume entries: a step resume breakpoint overrides another | |
1522 | breakpoint of signal handling (see comment in wait_for_inferior | |
1523 | at first IN_SIGTRAMP where we set the step_resume breakpoint). */ | |
bcc37718 JK |
1524 | /* We handle the through_sigtramp_breakpoint the same way; having both |
1525 | one of those and a step_resume_breakpoint is probably very rare (?). */ | |
d7e7e851 | 1526 | |
fe675038 | 1527 | static const enum bpstat_what_main_action |
cabd4da6 JK |
1528 | table[(int)class_last][(int)BPSTAT_WHAT_LAST] = |
1529 | { | |
1530 | /* old action */ | |
27b6a1fa | 1531 | /* kc ss sn sgl slr clr clrs sr ts shl |
bcc37718 | 1532 | */ |
27b6a1fa JL |
1533 | /*no_effect*/ {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl}, |
1534 | /*wp_silent*/ {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl}, | |
1535 | /*wp_noisy*/ {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl}, | |
1536 | /*bp_nostop*/ {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl}, | |
1537 | /*bp_silent*/ {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl}, | |
1538 | /*bp_noisy*/ {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl}, | |
1539 | /*long_jump*/ {slr, ss, sn, slr, err, err, err, sr, ts, shl}, | |
1540 | /*long_resume*/ {clr, ss, sn, clrs, err, err, err, sr, ts, shl}, | |
1541 | /*step_resume*/ {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl}, | |
1542 | /*through_sig*/ {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl}, | |
1543 | /*shlib*/ {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl} | |
cabd4da6 | 1544 | }; |
27b6a1fa JL |
1545 | #undef kc |
1546 | #undef ss | |
1547 | #undef sn | |
1548 | #undef sgl | |
1549 | #undef slr | |
1550 | #undef clr | |
1551 | #undef clrs | |
cabd4da6 | 1552 | #undef err |
bcc37718 JK |
1553 | #undef sr |
1554 | #undef ts | |
27b6a1fa | 1555 | #undef shl |
fe675038 | 1556 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
84d59861 | 1557 | struct bpstat_what retval; |
cabd4da6 | 1558 | |
cef4c2e7 | 1559 | retval.call_dummy = 0; |
cabd4da6 JK |
1560 | for (; bs != NULL; bs = bs->next) |
1561 | { | |
fee933f1 | 1562 | enum class bs_class = no_effect; |
cabd4da6 JK |
1563 | if (bs->breakpoint_at == NULL) |
1564 | /* I suspect this can happen if it was a momentary breakpoint | |
1565 | which has since been deleted. */ | |
1566 | continue; | |
1567 | switch (bs->breakpoint_at->type) | |
1568 | { | |
1569 | case bp_breakpoint: | |
11054881 | 1570 | case bp_hardware_breakpoint: |
cabd4da6 JK |
1571 | case bp_until: |
1572 | case bp_finish: | |
1573 | if (bs->stop) | |
1574 | { | |
1575 | if (bs->print) | |
1576 | bs_class = bp_noisy; | |
1577 | else | |
1578 | bs_class = bp_silent; | |
1579 | } | |
1580 | else | |
1581 | bs_class = bp_nostop; | |
1582 | break; | |
1583 | case bp_watchpoint: | |
999dd04b | 1584 | case bp_hardware_watchpoint: |
11054881 KH |
1585 | case bp_read_watchpoint: |
1586 | case bp_access_watchpoint: | |
cabd4da6 JK |
1587 | if (bs->stop) |
1588 | { | |
1589 | if (bs->print) | |
1590 | bs_class = wp_noisy; | |
1591 | else | |
1592 | bs_class = wp_silent; | |
1593 | } | |
1594 | else | |
fe675038 JK |
1595 | /* There was a watchpoint, but we're not stopping. This requires |
1596 | no further action. */ | |
1597 | bs_class = no_effect; | |
cabd4da6 JK |
1598 | break; |
1599 | case bp_longjmp: | |
1600 | bs_class = long_jump; | |
1601 | break; | |
1602 | case bp_longjmp_resume: | |
1603 | bs_class = long_resume; | |
1604 | break; | |
fe675038 | 1605 | case bp_step_resume: |
fe675038 JK |
1606 | if (bs->stop) |
1607 | { | |
d7e7e851 | 1608 | bs_class = step_resume; |
fe675038 JK |
1609 | } |
1610 | else | |
1611 | /* It is for the wrong frame. */ | |
1612 | bs_class = bp_nostop; | |
bcc37718 JK |
1613 | break; |
1614 | case bp_through_sigtramp: | |
1615 | bs_class = through_sig; | |
fe675038 | 1616 | break; |
999dd04b JL |
1617 | case bp_watchpoint_scope: |
1618 | bs_class = bp_nostop; | |
1619 | break; | |
27b6a1fa JL |
1620 | case bp_shlib_event: |
1621 | bs_class = shlib_event; | |
1622 | break; | |
84d59861 JK |
1623 | case bp_call_dummy: |
1624 | /* Make sure the action is stop (silent or noisy), so infrun.c | |
1625 | pops the dummy frame. */ | |
1626 | bs_class = bp_silent; | |
1627 | retval.call_dummy = 1; | |
bb7b3800 | 1628 | break; |
cabd4da6 JK |
1629 | } |
1630 | current_action = table[(int)bs_class][(int)current_action]; | |
1631 | } | |
84d59861 JK |
1632 | retval.main_action = current_action; |
1633 | return retval; | |
cabd4da6 | 1634 | } |
bd5635a1 | 1635 | |
30875e1c SG |
1636 | /* Nonzero if we should step constantly (e.g. watchpoints on machines |
1637 | without hardware support). This isn't related to a specific bpstat, | |
1638 | just to things like whether watchpoints are set. */ | |
1639 | ||
bd5635a1 RP |
1640 | int |
1641 | bpstat_should_step () | |
1642 | { | |
1643 | struct breakpoint *b; | |
1644 | ALL_BREAKPOINTS (b) | |
30875e1c | 1645 | if (b->enable == enabled && b->type == bp_watchpoint) |
bd5635a1 RP |
1646 | return 1; |
1647 | return 0; | |
1648 | } | |
1649 | \f | |
1650 | /* Print information on breakpoint number BNUM, or -1 if all. | |
1651 | If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS | |
1652 | is nonzero, process only watchpoints. */ | |
1653 | ||
1654 | static void | |
c8950965 | 1655 | breakpoint_1 (bnum, allflag) |
bd5635a1 | 1656 | int bnum; |
80ba48f5 | 1657 | int allflag; |
bd5635a1 RP |
1658 | { |
1659 | register struct breakpoint *b; | |
1660 | register struct command_line *l; | |
1661 | register struct symbol *sym; | |
1662 | CORE_ADDR last_addr = (CORE_ADDR)-1; | |
30875e1c | 1663 | int found_a_breakpoint = 0; |
11054881 KH |
1664 | static char *bptypes[] = {"breakpoint", "hw breakpoint", |
1665 | "until", "finish", "watchpoint", | |
1666 | "hw watchpoint", "read watchpoint", | |
1667 | "acc watchpoint", "longjmp", | |
999dd04b | 1668 | "longjmp resume", "step resume", |
27b6a1fa JL |
1669 | "sigtramp", |
1670 | "watchpoint scope", "call dummy", | |
1671 | "shlib events" }; | |
e51481f9 | 1672 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; |
647e52ea | 1673 | static char bpenables[] = "nyn"; |
0a62ff36 | 1674 | char wrap_indent[80]; |
30875e1c | 1675 | |
bd5635a1 | 1676 | ALL_BREAKPOINTS (b) |
30875e1c SG |
1677 | if (bnum == -1 |
1678 | || bnum == b->number) | |
bd5635a1 | 1679 | { |
80ba48f5 SG |
1680 | /* We only print out user settable breakpoints unless the allflag is set. */ |
1681 | if (!allflag | |
1682 | && b->type != bp_breakpoint | |
11054881 | 1683 | && b->type != bp_hardware_breakpoint |
999dd04b | 1684 | && b->type != bp_watchpoint |
11054881 KH |
1685 | && b->type != bp_read_watchpoint |
1686 | && b->type != bp_access_watchpoint | |
999dd04b | 1687 | && b->type != bp_hardware_watchpoint) |
80ba48f5 SG |
1688 | continue; |
1689 | ||
30875e1c | 1690 | if (!found_a_breakpoint++) |
47ebe8fd | 1691 | { |
f2d9c058 KH |
1692 | annotate_breakpoints_headers (); |
1693 | ||
1694 | annotate_field (0); | |
1695 | printf_filtered ("Num "); | |
1696 | annotate_field (1); | |
1697 | printf_filtered ("Type "); | |
1698 | annotate_field (2); | |
1699 | printf_filtered ("Disp "); | |
1700 | annotate_field (3); | |
1701 | printf_filtered ("Enb "); | |
1702 | if (addressprint) | |
1703 | { | |
1704 | annotate_field (4); | |
1705 | printf_filtered ("Address "); | |
1706 | } | |
1707 | annotate_field (5); | |
1708 | printf_filtered ("What\n"); | |
1709 | ||
1710 | annotate_breakpoints_table (); | |
1711 | } | |
1712 | ||
1713 | annotate_record (); | |
1714 | annotate_field (0); | |
1715 | printf_filtered ("%-3d ", b->number); | |
1716 | annotate_field (1); | |
1717 | printf_filtered ("%-14s ", bptypes[(int)b->type]); | |
1718 | annotate_field (2); | |
1719 | printf_filtered ("%-4s ", bpdisps[(int)b->disposition]); | |
1720 | annotate_field (3); | |
47ebe8fd JK |
1721 | printf_filtered ("%-3c ", bpenables[(int)b->enable]); |
1722 | ||
0a62ff36 JK |
1723 | strcpy (wrap_indent, " "); |
1724 | if (addressprint) | |
1725 | strcat (wrap_indent, " "); | |
30875e1c | 1726 | switch (b->type) |
bd5635a1 | 1727 | { |
30875e1c | 1728 | case bp_watchpoint: |
999dd04b | 1729 | case bp_hardware_watchpoint: |
11054881 KH |
1730 | case bp_read_watchpoint: |
1731 | case bp_access_watchpoint: | |
47ebe8fd JK |
1732 | /* Field 4, the address, is omitted (which makes the columns |
1733 | not line up too nicely with the headers, but the effect | |
1734 | is relatively readable). */ | |
9f577285 | 1735 | annotate_field (5); |
199b2450 | 1736 | print_expression (b->exp, gdb_stdout); |
30875e1c | 1737 | break; |
84d59861 | 1738 | |
30875e1c | 1739 | case bp_breakpoint: |
11054881 | 1740 | case bp_hardware_breakpoint: |
80ba48f5 SG |
1741 | case bp_until: |
1742 | case bp_finish: | |
1743 | case bp_longjmp: | |
1744 | case bp_longjmp_resume: | |
84d59861 | 1745 | case bp_step_resume: |
bcc37718 | 1746 | case bp_through_sigtramp: |
999dd04b | 1747 | case bp_watchpoint_scope: |
bb7b3800 | 1748 | case bp_call_dummy: |
27b6a1fa | 1749 | case bp_shlib_event: |
bd5635a1 | 1750 | if (addressprint) |
47ebe8fd | 1751 | { |
f2d9c058 | 1752 | annotate_field (4); |
47ebe8fd JK |
1753 | /* FIXME-32x64: need a print_address_numeric with |
1754 | field width */ | |
1755 | printf_filtered | |
1756 | ("%s ", | |
1757 | local_hex_string_custom | |
1758 | ((unsigned long) b->address, "08l")); | |
1759 | } | |
1760 | ||
f2d9c058 | 1761 | annotate_field (5); |
bd5635a1 RP |
1762 | |
1763 | last_addr = b->address; | |
d889f6b7 | 1764 | if (b->source_file) |
bd5635a1 RP |
1765 | { |
1766 | sym = find_pc_function (b->address); | |
1767 | if (sym) | |
1768 | { | |
199b2450 TL |
1769 | fputs_filtered ("in ", gdb_stdout); |
1770 | fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout); | |
0a62ff36 | 1771 | wrap_here (wrap_indent); |
199b2450 | 1772 | fputs_filtered (" at ", gdb_stdout); |
bd5635a1 | 1773 | } |
199b2450 | 1774 | fputs_filtered (b->source_file, gdb_stdout); |
bd5635a1 RP |
1775 | printf_filtered (":%d", b->line_number); |
1776 | } | |
1777 | else | |
199b2450 | 1778 | print_address_symbolic (b->address, gdb_stdout, demangle, " "); |
fee933f1 | 1779 | break; |
bd5635a1 RP |
1780 | } |
1781 | ||
1782 | printf_filtered ("\n"); | |
1783 | ||
1784 | if (b->frame) | |
833e0d94 | 1785 | { |
f2d9c058 | 1786 | annotate_field (6); |
47ebe8fd | 1787 | |
833e0d94 | 1788 | printf_filtered ("\tstop only in stack frame at "); |
d24c0599 | 1789 | print_address_numeric (b->frame, 1, gdb_stdout); |
833e0d94 | 1790 | printf_filtered ("\n"); |
bcc37718 | 1791 | } |
47ebe8fd | 1792 | |
bd5635a1 RP |
1793 | if (b->cond) |
1794 | { | |
f2d9c058 | 1795 | annotate_field (7); |
47ebe8fd | 1796 | |
bd5635a1 | 1797 | printf_filtered ("\tstop only if "); |
199b2450 | 1798 | print_expression (b->cond, gdb_stdout); |
bd5635a1 RP |
1799 | printf_filtered ("\n"); |
1800 | } | |
47ebe8fd | 1801 | |
647e52ea SG |
1802 | if (b->thread != -1) |
1803 | { | |
1804 | /* FIXME should make an annotation for this */ | |
1805 | printf_filtered ("\tstop only in thread %d\n", b->thread); | |
1806 | } | |
1807 | ||
9f577285 SS |
1808 | if (show_breakpoint_hit_counts && b->hit_count) |
1809 | { | |
1810 | /* FIXME should make an annotation for this */ | |
1811 | ||
16726dd1 JK |
1812 | printf_filtered ("\tbreakpoint already hit %d time%s\n", |
1813 | b->hit_count, (b->hit_count == 1 ? "" : "s")); | |
9f577285 SS |
1814 | } |
1815 | ||
bd5635a1 | 1816 | if (b->ignore_count) |
47ebe8fd | 1817 | { |
f2d9c058 | 1818 | annotate_field (8); |
47ebe8fd JK |
1819 | |
1820 | printf_filtered ("\tignore next %d hits\n", b->ignore_count); | |
1821 | } | |
1822 | ||
bd5635a1 | 1823 | if ((l = b->commands)) |
47ebe8fd | 1824 | { |
f2d9c058 | 1825 | annotate_field (9); |
47ebe8fd JK |
1826 | |
1827 | while (l) | |
1828 | { | |
0f8cdd9b | 1829 | print_command_line (l, 4); |
47ebe8fd JK |
1830 | l = l->next; |
1831 | } | |
1832 | } | |
bd5635a1 RP |
1833 | } |
1834 | ||
fee933f1 RP |
1835 | if (!found_a_breakpoint) |
1836 | { | |
1837 | if (bnum == -1) | |
1838 | printf_filtered ("No breakpoints or watchpoints.\n"); | |
1839 | else | |
1840 | printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum); | |
1841 | } | |
30875e1c SG |
1842 | else |
1843 | /* Compare against (CORE_ADDR)-1 in case some compiler decides | |
1844 | that a comparison of an unsigned with -1 is always false. */ | |
1845 | if (last_addr != (CORE_ADDR)-1) | |
1846 | set_next_address (last_addr); | |
47ebe8fd | 1847 | |
f2d9c058 | 1848 | annotate_breakpoints_table_end (); |
bd5635a1 RP |
1849 | } |
1850 | ||
bdbd5f50 | 1851 | /* ARGSUSED */ |
bd5635a1 RP |
1852 | static void |
1853 | breakpoints_info (bnum_exp, from_tty) | |
1854 | char *bnum_exp; | |
1855 | int from_tty; | |
1856 | { | |
1857 | int bnum = -1; | |
1858 | ||
1859 | if (bnum_exp) | |
1860 | bnum = parse_and_eval_address (bnum_exp); | |
1861 | ||
c8950965 | 1862 | breakpoint_1 (bnum, 0); |
80ba48f5 SG |
1863 | } |
1864 | ||
9b280a7f JG |
1865 | #if MAINTENANCE_CMDS |
1866 | ||
80ba48f5 SG |
1867 | /* ARGSUSED */ |
1868 | static void | |
9b280a7f | 1869 | maintenance_info_breakpoints (bnum_exp, from_tty) |
80ba48f5 SG |
1870 | char *bnum_exp; |
1871 | int from_tty; | |
1872 | { | |
1873 | int bnum = -1; | |
1874 | ||
1875 | if (bnum_exp) | |
1876 | bnum = parse_and_eval_address (bnum_exp); | |
1877 | ||
c8950965 | 1878 | breakpoint_1 (bnum, 1); |
bd5635a1 RP |
1879 | } |
1880 | ||
9b280a7f JG |
1881 | #endif |
1882 | ||
bd5635a1 RP |
1883 | /* Print a message describing any breakpoints set at PC. */ |
1884 | ||
1885 | static void | |
1886 | describe_other_breakpoints (pc) | |
1887 | register CORE_ADDR pc; | |
1888 | { | |
1889 | register int others = 0; | |
1890 | register struct breakpoint *b; | |
1891 | ||
1892 | ALL_BREAKPOINTS (b) | |
1893 | if (b->address == pc) | |
1894 | others++; | |
1895 | if (others > 0) | |
1896 | { | |
833e0d94 | 1897 | printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : ""); |
bd5635a1 RP |
1898 | ALL_BREAKPOINTS (b) |
1899 | if (b->address == pc) | |
1900 | { | |
1901 | others--; | |
833e0d94 JK |
1902 | printf_filtered |
1903 | ("%d%s%s ", | |
1904 | b->number, | |
fa3764e2 JL |
1905 | ((b->enable == disabled || b->enable == shlib_disabled) |
1906 | ? " (disabled)" : ""), | |
833e0d94 | 1907 | (others > 1) ? "," : ((others == 1) ? " and" : "")); |
bd5635a1 | 1908 | } |
833e0d94 | 1909 | printf_filtered ("also set at pc "); |
d24c0599 | 1910 | print_address_numeric (pc, 1, gdb_stdout); |
833e0d94 | 1911 | printf_filtered (".\n"); |
bd5635a1 RP |
1912 | } |
1913 | } | |
1914 | \f | |
1915 | /* Set the default place to put a breakpoint | |
1916 | for the `break' command with no arguments. */ | |
1917 | ||
1918 | void | |
1919 | set_default_breakpoint (valid, addr, symtab, line) | |
1920 | int valid; | |
1921 | CORE_ADDR addr; | |
1922 | struct symtab *symtab; | |
1923 | int line; | |
1924 | { | |
1925 | default_breakpoint_valid = valid; | |
1926 | default_breakpoint_address = addr; | |
1927 | default_breakpoint_symtab = symtab; | |
1928 | default_breakpoint_line = line; | |
1929 | } | |
1930 | ||
1931 | /* Rescan breakpoints at address ADDRESS, | |
1932 | marking the first one as "first" and any others as "duplicates". | |
1933 | This is so that the bpt instruction is only inserted once. */ | |
1934 | ||
1935 | static void | |
1936 | check_duplicates (address) | |
1937 | CORE_ADDR address; | |
1938 | { | |
1939 | register struct breakpoint *b; | |
1940 | register int count = 0; | |
1941 | ||
30875e1c | 1942 | if (address == 0) /* Watchpoints are uninteresting */ |
f266e564 JK |
1943 | return; |
1944 | ||
bd5635a1 | 1945 | ALL_BREAKPOINTS (b) |
fa3764e2 JL |
1946 | if (b->enable != disabled |
1947 | && b->enable != shlib_disabled | |
1948 | && b->address == address) | |
bd5635a1 RP |
1949 | { |
1950 | count++; | |
1951 | b->duplicate = count > 1; | |
1952 | } | |
1953 | } | |
1954 | ||
1955 | /* Low level routine to set a breakpoint. | |
1956 | Takes as args the three things that every breakpoint must have. | |
1957 | Returns the breakpoint object so caller can set other things. | |
1958 | Does not set the breakpoint number! | |
f266e564 JK |
1959 | Does not print anything. |
1960 | ||
1961 | ==> This routine should not be called if there is a chance of later | |
1962 | error(); otherwise it leaves a bogus breakpoint on the chain. Validate | |
1963 | your arguments BEFORE calling this routine! */ | |
bd5635a1 RP |
1964 | |
1965 | static struct breakpoint * | |
1966 | set_raw_breakpoint (sal) | |
1967 | struct symtab_and_line sal; | |
1968 | { | |
1969 | register struct breakpoint *b, *b1; | |
1970 | ||
1971 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4ed3a9ea | 1972 | memset (b, 0, sizeof (*b)); |
bd5635a1 | 1973 | b->address = sal.pc; |
d889f6b7 JK |
1974 | if (sal.symtab == NULL) |
1975 | b->source_file = NULL; | |
1976 | else | |
1977 | b->source_file = savestring (sal.symtab->filename, | |
1978 | strlen (sal.symtab->filename)); | |
706dc3ce JL |
1979 | b->language = current_language->la_language; |
1980 | b->input_radix = input_radix; | |
199b2450 | 1981 | b->thread = -1; |
bd5635a1 RP |
1982 | b->line_number = sal.line; |
1983 | b->enable = enabled; | |
1984 | b->next = 0; | |
1985 | b->silent = 0; | |
1986 | b->ignore_count = 0; | |
1987 | b->commands = NULL; | |
30875e1c | 1988 | b->frame = 0; |
bd5635a1 RP |
1989 | |
1990 | /* Add this breakpoint to the end of the chain | |
1991 | so that a list of breakpoints will come out in order | |
1992 | of increasing numbers. */ | |
1993 | ||
1994 | b1 = breakpoint_chain; | |
1995 | if (b1 == 0) | |
1996 | breakpoint_chain = b; | |
1997 | else | |
1998 | { | |
1999 | while (b1->next) | |
2000 | b1 = b1->next; | |
2001 | b1->next = b; | |
2002 | } | |
2003 | ||
2004 | check_duplicates (sal.pc); | |
6c803036 | 2005 | breakpoints_changed (); |
bd5635a1 RP |
2006 | |
2007 | return b; | |
2008 | } | |
2009 | ||
27b6a1fa JL |
2010 | static int internal_breakpoint_number = -1; |
2011 | ||
39ce6829 PS |
2012 | #ifdef GET_LONGJMP_TARGET |
2013 | ||
30875e1c | 2014 | static void |
cd10c7e3 | 2015 | create_longjmp_breakpoint (func_name) |
30875e1c | 2016 | char *func_name; |
30875e1c | 2017 | { |
30875e1c SG |
2018 | struct symtab_and_line sal; |
2019 | struct breakpoint *b; | |
2020 | ||
30875e1c SG |
2021 | if (func_name != NULL) |
2022 | { | |
2023 | struct minimal_symbol *m; | |
2024 | ||
e8bf33c4 | 2025 | m = lookup_minimal_symbol_text (func_name, NULL, (struct objfile *)NULL); |
30875e1c | 2026 | if (m) |
2d313932 | 2027 | sal.pc = SYMBOL_VALUE_ADDRESS (m); |
30875e1c SG |
2028 | else |
2029 | return; | |
2030 | } | |
2031 | else | |
2032 | sal.pc = 0; | |
2033 | ||
2034 | sal.symtab = NULL; | |
2035 | sal.line = 0; | |
30875e1c | 2036 | |
cd10c7e3 | 2037 | b = set_raw_breakpoint (sal); |
30875e1c SG |
2038 | if (!b) return; |
2039 | ||
80ba48f5 | 2040 | b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume; |
30875e1c SG |
2041 | b->disposition = donttouch; |
2042 | b->enable = disabled; | |
2043 | b->silent = 1; | |
80ba48f5 SG |
2044 | if (func_name) |
2045 | b->addr_string = strsave(func_name); | |
2046 | b->number = internal_breakpoint_number--; | |
30875e1c | 2047 | } |
30875e1c | 2048 | |
39ce6829 PS |
2049 | #endif /* #ifdef GET_LONGJMP_TARGET */ |
2050 | ||
30875e1c SG |
2051 | /* Call this routine when stepping and nexting to enable a breakpoint if we do |
2052 | a longjmp(). When we hit that breakpoint, call | |
2053 | set_longjmp_resume_breakpoint() to figure out where we are going. */ | |
2054 | ||
2055 | void | |
2056 | enable_longjmp_breakpoint() | |
2057 | { | |
80ba48f5 SG |
2058 | register struct breakpoint *b; |
2059 | ||
2060 | ALL_BREAKPOINTS (b) | |
2061 | if (b->type == bp_longjmp) | |
9b280a7f JG |
2062 | { |
2063 | b->enable = enabled; | |
2064 | check_duplicates (b->address); | |
2065 | } | |
30875e1c SG |
2066 | } |
2067 | ||
2068 | void | |
2069 | disable_longjmp_breakpoint() | |
2070 | { | |
80ba48f5 SG |
2071 | register struct breakpoint *b; |
2072 | ||
2073 | ALL_BREAKPOINTS (b) | |
9b280a7f | 2074 | if ( b->type == bp_longjmp |
80ba48f5 | 2075 | || b->type == bp_longjmp_resume) |
9b280a7f JG |
2076 | { |
2077 | b->enable = disabled; | |
2078 | check_duplicates (b->address); | |
2079 | } | |
30875e1c SG |
2080 | } |
2081 | ||
27b6a1fa JL |
2082 | #ifdef SOLIB_ADD |
2083 | void | |
2084 | remove_solib_event_breakpoints () | |
2085 | { | |
fa3764e2 | 2086 | register struct breakpoint *b, *temp; |
27b6a1fa | 2087 | |
fa3764e2 | 2088 | ALL_BREAKPOINTS_SAFE (b, temp) |
27b6a1fa JL |
2089 | if (b->type == bp_shlib_event) |
2090 | delete_breakpoint (b); | |
2091 | } | |
2092 | ||
2093 | void | |
2094 | create_solib_event_breakpoint (address) | |
2095 | CORE_ADDR address; | |
2096 | { | |
2097 | struct breakpoint *b; | |
2098 | struct symtab_and_line sal; | |
2099 | ||
2100 | sal.pc = address; | |
2101 | sal.symtab = NULL; | |
2102 | sal.line = 0; | |
2103 | b = set_raw_breakpoint (sal); | |
2104 | b->number = internal_breakpoint_number--; | |
2105 | b->disposition = donttouch; | |
2106 | b->type = bp_shlib_event; | |
2107 | } | |
fa3764e2 JL |
2108 | |
2109 | /* Try to reenable any breakpoints in shared libraries. */ | |
2110 | void | |
2111 | re_enable_breakpoints_in_shlibs () | |
2112 | { | |
2113 | struct breakpoint *b; | |
2114 | ||
2115 | ALL_BREAKPOINTS (b) | |
2116 | if (b->enable == shlib_disabled) | |
2117 | { | |
2118 | char buf[1]; | |
2119 | ||
2120 | /* Do not reenable the breakpoint if the shared library | |
2121 | is still not mapped in. */ | |
2122 | if (target_read_memory (b->address, buf, 1) == 0) | |
2123 | b->enable = enabled; | |
2124 | } | |
2125 | } | |
2126 | ||
27b6a1fa JL |
2127 | #endif |
2128 | ||
11054881 KH |
2129 | int |
2130 | hw_breakpoint_used_count() | |
2131 | { | |
2132 | register struct breakpoint *b; | |
2133 | int i = 0; | |
2134 | ||
2135 | ALL_BREAKPOINTS (b) | |
2136 | { | |
2137 | if (b->type == bp_hardware_breakpoint && b->enable == enabled) | |
2138 | i++; | |
2139 | } | |
2140 | ||
2141 | return i; | |
2142 | } | |
2143 | ||
2144 | int | |
2145 | hw_watchpoint_used_count(type, other_type_used) | |
2146 | enum bptype type; | |
2147 | int *other_type_used; | |
2148 | { | |
2149 | register struct breakpoint *b; | |
2150 | int i = 0; | |
2151 | ||
2152 | *other_type_used = 0; | |
2153 | ALL_BREAKPOINTS (b) | |
2154 | { | |
2155 | if (b->enable == enabled) | |
2156 | { | |
2157 | if (b->type == type) i++; | |
2158 | else if ((b->type == bp_hardware_watchpoint || | |
2159 | b->type == bp_read_watchpoint || | |
2160 | b->type == bp_access_watchpoint) | |
2161 | && b->enable == enabled) | |
2162 | *other_type_used = 1; | |
2163 | } | |
2164 | } | |
2165 | return i; | |
2166 | } | |
2167 | ||
30875e1c SG |
2168 | /* Call this after hitting the longjmp() breakpoint. Use this to set a new |
2169 | breakpoint at the target of the jmp_buf. | |
80ba48f5 SG |
2170 | |
2171 | FIXME - This ought to be done by setting a temporary breakpoint that gets | |
2172 | deleted automatically... | |
30875e1c SG |
2173 | */ |
2174 | ||
2175 | void | |
2176 | set_longjmp_resume_breakpoint(pc, frame) | |
2177 | CORE_ADDR pc; | |
706dc3ce | 2178 | struct frame_info *frame; |
30875e1c | 2179 | { |
80ba48f5 SG |
2180 | register struct breakpoint *b; |
2181 | ||
2182 | ALL_BREAKPOINTS (b) | |
2183 | if (b->type == bp_longjmp_resume) | |
2184 | { | |
2185 | b->address = pc; | |
2186 | b->enable = enabled; | |
2187 | if (frame != NULL) | |
706dc3ce | 2188 | b->frame = frame->frame; |
80ba48f5 SG |
2189 | else |
2190 | b->frame = 0; | |
9b280a7f | 2191 | check_duplicates (b->address); |
80ba48f5 SG |
2192 | return; |
2193 | } | |
30875e1c SG |
2194 | } |
2195 | ||
bd5635a1 RP |
2196 | /* Set a breakpoint that will evaporate an end of command |
2197 | at address specified by SAL. | |
2198 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
2199 | ||
30875e1c SG |
2200 | struct breakpoint * |
2201 | set_momentary_breakpoint (sal, frame, type) | |
bd5635a1 | 2202 | struct symtab_and_line sal; |
706dc3ce | 2203 | struct frame_info *frame; |
30875e1c | 2204 | enum bptype type; |
bd5635a1 RP |
2205 | { |
2206 | register struct breakpoint *b; | |
2207 | b = set_raw_breakpoint (sal); | |
30875e1c SG |
2208 | b->type = type; |
2209 | b->enable = enabled; | |
2210 | b->disposition = donttouch; | |
706dc3ce | 2211 | b->frame = (frame ? frame->frame : 0); |
2b576293 C |
2212 | |
2213 | /* If we're debugging a multi-threaded program, then we | |
2214 | want momentary breakpoints to be active in only a | |
2215 | single thread of control. */ | |
2216 | if (in_thread_list (inferior_pid)) | |
2217 | b->thread = pid_to_thread_id (inferior_pid); | |
2218 | ||
30875e1c | 2219 | return b; |
bd5635a1 RP |
2220 | } |
2221 | ||
bd5635a1 RP |
2222 | \f |
2223 | /* Tell the user we have just set a breakpoint B. */ | |
9f577285 | 2224 | |
bd5635a1 RP |
2225 | static void |
2226 | mention (b) | |
2227 | struct breakpoint *b; | |
2228 | { | |
9f577285 SS |
2229 | int say_where = 0; |
2230 | ||
d2a85f11 JMD |
2231 | /* FIXME: This is misplaced; mention() is called by things (like hitting a |
2232 | watchpoint) other than breakpoint creation. It should be possible to | |
2233 | clean this up and at the same time replace the random calls to | |
2234 | breakpoint_changed with this hook, as has already been done for | |
2235 | delete_breakpoint_hook and so on. */ | |
754e5da2 SG |
2236 | if (create_breakpoint_hook) |
2237 | create_breakpoint_hook (b); | |
2238 | ||
30875e1c | 2239 | switch (b->type) |
bd5635a1 | 2240 | { |
30875e1c | 2241 | case bp_watchpoint: |
bd5635a1 | 2242 | printf_filtered ("Watchpoint %d: ", b->number); |
199b2450 | 2243 | print_expression (b->exp, gdb_stdout); |
30875e1c | 2244 | break; |
999dd04b JL |
2245 | case bp_hardware_watchpoint: |
2246 | printf_filtered ("Hardware watchpoint %d: ", b->number); | |
2247 | print_expression (b->exp, gdb_stdout); | |
2248 | break; | |
11054881 KH |
2249 | case bp_read_watchpoint: |
2250 | printf_filtered ("Hardware read watchpoint %d: ", b->number); | |
2251 | print_expression (b->exp, gdb_stdout); | |
2252 | break; | |
2253 | case bp_access_watchpoint: | |
2254 | printf_filtered ("Hardware access(read/write) watchpoint %d: ",b->number); | |
2255 | print_expression (b->exp, gdb_stdout); | |
2256 | break; | |
30875e1c | 2257 | case bp_breakpoint: |
9f577285 SS |
2258 | printf_filtered ("Breakpoint %d", b->number); |
2259 | say_where = 1; | |
51b57ded | 2260 | break; |
11054881 | 2261 | case bp_hardware_breakpoint: |
9f577285 SS |
2262 | printf_filtered ("Hardware assisted breakpoint %d", b->number); |
2263 | say_where = 1; | |
11054881 | 2264 | break; |
51b57ded FF |
2265 | case bp_until: |
2266 | case bp_finish: | |
2267 | case bp_longjmp: | |
2268 | case bp_longjmp_resume: | |
fee933f1 | 2269 | case bp_step_resume: |
bcc37718 | 2270 | case bp_through_sigtramp: |
199b2450 | 2271 | case bp_call_dummy: |
999dd04b | 2272 | case bp_watchpoint_scope: |
fa3764e2 | 2273 | case bp_shlib_event: |
51b57ded | 2274 | break; |
bd5635a1 | 2275 | } |
9f577285 SS |
2276 | if (say_where) |
2277 | { | |
2278 | if (addressprint || b->source_file == NULL) | |
2279 | { | |
2280 | printf_filtered (" at "); | |
2281 | print_address_numeric (b->address, 1, gdb_stdout); | |
2282 | } | |
2283 | if (b->source_file) | |
2284 | printf_filtered (": file %s, line %d.", | |
2285 | b->source_file, b->line_number); | |
2286 | } | |
bd5635a1 RP |
2287 | printf_filtered ("\n"); |
2288 | } | |
2289 | ||
bd5635a1 RP |
2290 | \f |
2291 | /* Set a breakpoint according to ARG (function, linenum or *address) | |
11054881 KH |
2292 | flag: first bit : 0 non-temporary, 1 temporary. |
2293 | second bit : 0 normal breakpoint, 1 hardware breakpoint. */ | |
bd5635a1 RP |
2294 | |
2295 | static void | |
11054881 | 2296 | break_command_1 (arg, flag, from_tty) |
bd5635a1 | 2297 | char *arg; |
11054881 | 2298 | int flag, from_tty; |
bd5635a1 | 2299 | { |
11054881 | 2300 | int tempflag, hardwareflag; |
bd5635a1 RP |
2301 | struct symtabs_and_lines sals; |
2302 | struct symtab_and_line sal; | |
2303 | register struct expression *cond = 0; | |
2304 | register struct breakpoint *b; | |
2305 | ||
2306 | /* Pointers in arg to the start, and one past the end, of the condition. */ | |
2307 | char *cond_start = NULL; | |
fee933f1 | 2308 | char *cond_end = NULL; |
bd5635a1 RP |
2309 | /* Pointers in arg to the start, and one past the end, |
2310 | of the address part. */ | |
2311 | char *addr_start = NULL; | |
fee933f1 | 2312 | char *addr_end = NULL; |
d889f6b7 | 2313 | struct cleanup *old_chain; |
fee933f1 | 2314 | struct cleanup *canonical_strings_chain = NULL; |
d889f6b7 | 2315 | char **canonical = (char **)NULL; |
bd5635a1 | 2316 | int i; |
199b2450 | 2317 | int thread; |
bd5635a1 | 2318 | |
e8bf33c4 JK |
2319 | hardwareflag = flag & BP_HARDWAREFLAG; |
2320 | tempflag = flag & BP_TEMPFLAG; | |
11054881 | 2321 | |
bd5635a1 RP |
2322 | sals.sals = NULL; |
2323 | sals.nelts = 0; | |
2324 | ||
2325 | sal.line = sal.pc = sal.end = 0; | |
2326 | sal.symtab = 0; | |
2327 | ||
2328 | /* If no arg given, or if first arg is 'if ', use the default breakpoint. */ | |
2329 | ||
2330 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' | |
2331 | && (arg[2] == ' ' || arg[2] == '\t'))) | |
2332 | { | |
2333 | if (default_breakpoint_valid) | |
2334 | { | |
2335 | sals.sals = (struct symtab_and_line *) | |
2336 | xmalloc (sizeof (struct symtab_and_line)); | |
2337 | sal.pc = default_breakpoint_address; | |
2338 | sal.line = default_breakpoint_line; | |
2339 | sal.symtab = default_breakpoint_symtab; | |
2340 | sals.sals[0] = sal; | |
2341 | sals.nelts = 1; | |
2342 | } | |
2343 | else | |
2344 | error ("No default breakpoint address now."); | |
2345 | } | |
2346 | else | |
2347 | { | |
2348 | addr_start = arg; | |
2349 | ||
2350 | /* Force almost all breakpoints to be in terms of the | |
2351 | current_source_symtab (which is decode_line_1's default). This | |
2352 | should produce the results we want almost all of the time while | |
2353 | leaving default_breakpoint_* alone. */ | |
2354 | if (default_breakpoint_valid | |
2355 | && (!current_source_symtab | |
2356 | || (arg && (*arg == '+' || *arg == '-')))) | |
2357 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
d889f6b7 | 2358 | default_breakpoint_line, &canonical); |
bd5635a1 | 2359 | else |
d889f6b7 | 2360 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical); |
bd5635a1 RP |
2361 | |
2362 | addr_end = arg; | |
2363 | } | |
2364 | ||
2365 | if (! sals.nelts) | |
2366 | return; | |
2367 | ||
d889f6b7 JK |
2368 | /* Make sure that all storage allocated in decode_line_1 gets freed in case |
2369 | the following `for' loop errors out. */ | |
2370 | old_chain = make_cleanup (free, sals.sals); | |
2371 | if (canonical != (char **)NULL) | |
2372 | { | |
2373 | make_cleanup (free, canonical); | |
2374 | canonical_strings_chain = make_cleanup (null_cleanup, 0); | |
2375 | for (i = 0; i < sals.nelts; i++) | |
2376 | { | |
2377 | if (canonical[i] != NULL) | |
2378 | make_cleanup (free, canonical[i]); | |
2379 | } | |
2380 | } | |
2381 | ||
199b2450 TL |
2382 | thread = -1; /* No specific thread yet */ |
2383 | ||
30875e1c SG |
2384 | /* Resolve all line numbers to PC's, and verify that conditions |
2385 | can be parsed, before setting any breakpoints. */ | |
bd5635a1 RP |
2386 | for (i = 0; i < sals.nelts; i++) |
2387 | { | |
199b2450 TL |
2388 | char *tok, *end_tok; |
2389 | int toklen; | |
2390 | ||
30875e1c | 2391 | resolve_sal_pc (&sals.sals[i]); |
bd5635a1 | 2392 | |
199b2450 TL |
2393 | tok = arg; |
2394 | ||
2395 | while (tok && *tok) | |
bd5635a1 | 2396 | { |
199b2450 TL |
2397 | while (*tok == ' ' || *tok == '\t') |
2398 | tok++; | |
2399 | ||
2400 | end_tok = tok; | |
2401 | ||
2402 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
2403 | end_tok++; | |
2404 | ||
2405 | toklen = end_tok - tok; | |
2406 | ||
2407 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
2408 | { | |
2409 | tok = cond_start = end_tok + 1; | |
2410 | cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); | |
2411 | cond_end = tok; | |
2412 | } | |
2413 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
bd5635a1 | 2414 | { |
199b2450 TL |
2415 | char *tmptok; |
2416 | ||
2417 | tok = end_tok + 1; | |
2418 | tmptok = tok; | |
2419 | thread = strtol (tok, &tok, 0); | |
2420 | if (tok == tmptok) | |
2421 | error ("Junk after thread keyword."); | |
2422 | if (!valid_thread_id (thread)) | |
2423 | error ("Unknown thread %d\n", thread); | |
bd5635a1 RP |
2424 | } |
2425 | else | |
2426 | error ("Junk at end of arguments."); | |
2427 | } | |
bd5635a1 | 2428 | } |
11054881 KH |
2429 | if (hardwareflag) |
2430 | { | |
557f3a0e SS |
2431 | int i, target_resources_ok; |
2432 | ||
2433 | i = hw_breakpoint_used_count (); | |
2434 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT ( | |
2435 | bp_hardware_breakpoint, i + sals.nelts, 0); | |
11054881 KH |
2436 | if (target_resources_ok == 0) |
2437 | error ("No hardware breakpoint support in the target."); | |
2438 | else if (target_resources_ok < 0) | |
2439 | error ("Hardware breakpoints used exceeds limit."); | |
2440 | } | |
bd5635a1 | 2441 | |
d889f6b7 JK |
2442 | /* Remove the canonical strings from the cleanup, they are needed below. */ |
2443 | if (canonical != (char **)NULL) | |
2444 | discard_cleanups (canonical_strings_chain); | |
2445 | ||
30875e1c | 2446 | /* Now set all the breakpoints. */ |
bd5635a1 RP |
2447 | for (i = 0; i < sals.nelts; i++) |
2448 | { | |
2449 | sal = sals.sals[i]; | |
2450 | ||
2451 | if (from_tty) | |
2452 | describe_other_breakpoints (sal.pc); | |
2453 | ||
2454 | b = set_raw_breakpoint (sal); | |
2455 | set_breakpoint_count (breakpoint_count + 1); | |
2456 | b->number = breakpoint_count; | |
11054881 | 2457 | b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint; |
bd5635a1 | 2458 | b->cond = cond; |
199b2450 | 2459 | b->thread = thread; |
0a97f6c4 | 2460 | |
d889f6b7 JK |
2461 | /* If a canonical line spec is needed use that instead of the |
2462 | command string. */ | |
2463 | if (canonical != (char **)NULL && canonical[i] != NULL) | |
2464 | b->addr_string = canonical[i]; | |
2465 | else if (addr_start) | |
bd5635a1 RP |
2466 | b->addr_string = savestring (addr_start, addr_end - addr_start); |
2467 | if (cond_start) | |
2468 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
2469 | ||
30875e1c | 2470 | b->enable = enabled; |
e8bf33c4 | 2471 | b->disposition = tempflag ? del : donttouch; |
bd5635a1 RP |
2472 | |
2473 | mention (b); | |
2474 | } | |
2475 | ||
2476 | if (sals.nelts > 1) | |
2477 | { | |
833e0d94 JK |
2478 | printf_filtered ("Multiple breakpoints were set.\n"); |
2479 | printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n"); | |
bd5635a1 | 2480 | } |
d889f6b7 | 2481 | do_cleanups (old_chain); |
bd5635a1 RP |
2482 | } |
2483 | ||
30875e1c SG |
2484 | /* Helper function for break_command_1 and disassemble_command. */ |
2485 | ||
2486 | void | |
2487 | resolve_sal_pc (sal) | |
2488 | struct symtab_and_line *sal; | |
2489 | { | |
2490 | CORE_ADDR pc; | |
2491 | ||
2492 | if (sal->pc == 0 && sal->symtab != 0) | |
2493 | { | |
2494 | pc = find_line_pc (sal->symtab, sal->line); | |
2495 | if (pc == 0) | |
2496 | error ("No line %d in file \"%s\".", | |
2497 | sal->line, sal->symtab->filename); | |
2498 | sal->pc = pc; | |
2499 | } | |
2500 | } | |
2501 | ||
bd5635a1 RP |
2502 | void |
2503 | break_command (arg, from_tty) | |
2504 | char *arg; | |
2505 | int from_tty; | |
2506 | { | |
2507 | break_command_1 (arg, 0, from_tty); | |
2508 | } | |
2509 | ||
2510 | static void | |
2511 | tbreak_command (arg, from_tty) | |
2512 | char *arg; | |
2513 | int from_tty; | |
2514 | { | |
11054881 KH |
2515 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
2516 | } | |
2517 | ||
2518 | static void | |
2519 | hbreak_command (arg, from_tty) | |
2520 | char *arg; | |
2521 | int from_tty; | |
2522 | { | |
2523 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); | |
2524 | } | |
2525 | ||
2526 | static void | |
2527 | thbreak_command (arg, from_tty) | |
2528 | char *arg; | |
2529 | int from_tty; | |
2530 | { | |
2531 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); | |
bd5635a1 RP |
2532 | } |
2533 | ||
bdbd5f50 | 2534 | /* ARGSUSED */ |
11054881 KH |
2535 | /* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write) |
2536 | */ | |
bd5635a1 | 2537 | static void |
11054881 | 2538 | watch_command_1 (arg, accessflag, from_tty) |
bd5635a1 | 2539 | char *arg; |
11054881 | 2540 | int accessflag; |
bd5635a1 RP |
2541 | int from_tty; |
2542 | { | |
2543 | struct breakpoint *b; | |
2544 | struct symtab_and_line sal; | |
f266e564 JK |
2545 | struct expression *exp; |
2546 | struct block *exp_valid_block; | |
11054881 | 2547 | struct value *val, *mark; |
706dc3ce | 2548 | struct frame_info *frame, *prev_frame; |
11054881 KH |
2549 | char *exp_start = NULL; |
2550 | char *exp_end = NULL; | |
2551 | char *tok, *end_tok; | |
2552 | int toklen; | |
2553 | char *cond_start = NULL; | |
2554 | char *cond_end = NULL; | |
2555 | struct expression *cond = NULL; | |
2556 | int i, other_type_used, target_resources_ok; | |
2557 | enum bptype bp_type; | |
2558 | int mem_cnt = 0; | |
bd5635a1 | 2559 | |
30875e1c | 2560 | sal.pc = 0; |
bd5635a1 RP |
2561 | sal.symtab = NULL; |
2562 | sal.line = 0; | |
2563 | ||
f266e564 JK |
2564 | /* Parse arguments. */ |
2565 | innermost_block = NULL; | |
11054881 KH |
2566 | exp_start = arg; |
2567 | exp = parse_exp_1 (&arg, 0, 0); | |
2568 | exp_end = arg; | |
f266e564 | 2569 | exp_valid_block = innermost_block; |
11054881 | 2570 | mark = value_mark (); |
f266e564 JK |
2571 | val = evaluate_expression (exp); |
2572 | release_value (val); | |
2d313932 JK |
2573 | if (VALUE_LAZY (val)) |
2574 | value_fetch_lazy (val); | |
f266e564 | 2575 | |
11054881 KH |
2576 | tok = arg; |
2577 | while (*tok == ' ' || *tok == '\t') | |
2578 | tok++; | |
2579 | end_tok = tok; | |
2580 | ||
2581 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
2582 | end_tok++; | |
2583 | ||
2584 | toklen = end_tok - tok; | |
2585 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
2586 | { | |
2587 | tok = cond_start = end_tok + 1; | |
2588 | cond = parse_exp_1 (&tok, 0, 0); | |
2589 | cond_end = tok; | |
2590 | } | |
2591 | if (*tok) | |
2592 | error("Junk at end of command."); | |
2593 | ||
2594 | if (accessflag == 1) bp_type = bp_read_watchpoint; | |
2595 | else if (accessflag == 2) bp_type = bp_access_watchpoint; | |
2596 | else bp_type = bp_hardware_watchpoint; | |
2597 | ||
2598 | mem_cnt = can_use_hardware_watchpoint (val); | |
2599 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
2600 | error ("Expression cannot be implemented with read/access watchpoint."); | |
2601 | if (mem_cnt != 0) { | |
2602 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
2603 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( | |
2604 | bp_type, i + mem_cnt, other_type_used); | |
2605 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) | |
2606 | error ("Target does not have this type of hardware watchpoint support."); | |
2607 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) | |
2608 | error ("Target resources have been allocated for other types of watchpoints."); | |
2609 | } | |
2610 | ||
f266e564 | 2611 | /* Now set up the breakpoint. */ |
bd5635a1 RP |
2612 | b = set_raw_breakpoint (sal); |
2613 | set_breakpoint_count (breakpoint_count + 1); | |
2614 | b->number = breakpoint_count; | |
30875e1c | 2615 | b->disposition = donttouch; |
f266e564 JK |
2616 | b->exp = exp; |
2617 | b->exp_valid_block = exp_valid_block; | |
11054881 | 2618 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
f266e564 | 2619 | b->val = val; |
11054881 KH |
2620 | b->cond = cond; |
2621 | if (cond_start) | |
2622 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
2623 | else | |
2624 | b->cond_string = 0; | |
2625 | ||
999dd04b JL |
2626 | frame = block_innermost_frame (exp_valid_block); |
2627 | if (frame) | |
2628 | { | |
2629 | prev_frame = get_prev_frame (frame); | |
706dc3ce | 2630 | b->watchpoint_frame = frame->frame; |
999dd04b JL |
2631 | } |
2632 | else | |
9e8db445 | 2633 | b->watchpoint_frame = (CORE_ADDR)0; |
999dd04b | 2634 | |
11054881 KH |
2635 | if (mem_cnt && target_resources_ok > 0) |
2636 | b->type = bp_type; | |
999dd04b JL |
2637 | else |
2638 | b->type = bp_watchpoint; | |
2639 | ||
2640 | /* If the expression is "local", then set up a "watchpoint scope" | |
2641 | breakpoint at the point where we've left the scope of the watchpoint | |
2642 | expression. */ | |
2643 | if (innermost_block) | |
2644 | { | |
2645 | struct breakpoint *scope_breakpoint; | |
2646 | struct symtab_and_line scope_sal; | |
2647 | ||
2648 | if (prev_frame) | |
2649 | { | |
2650 | scope_sal.pc = get_frame_pc (prev_frame); | |
2651 | scope_sal.symtab = NULL; | |
2652 | scope_sal.line = 0; | |
2653 | ||
2654 | scope_breakpoint = set_raw_breakpoint (scope_sal); | |
2655 | set_breakpoint_count (breakpoint_count + 1); | |
2656 | scope_breakpoint->number = breakpoint_count; | |
2657 | ||
2658 | scope_breakpoint->type = bp_watchpoint_scope; | |
2659 | scope_breakpoint->enable = enabled; | |
2660 | ||
2661 | /* Automatically delete the breakpoint when it hits. */ | |
e8bf33c4 | 2662 | scope_breakpoint->disposition = del; |
999dd04b JL |
2663 | |
2664 | /* Only break in the proper frame (help with recursion). */ | |
2665 | scope_breakpoint->frame = prev_frame->frame; | |
2666 | ||
2667 | /* Set the address at which we will stop. */ | |
2668 | scope_breakpoint->address = get_frame_pc (prev_frame); | |
2669 | ||
2670 | /* The scope breakpoint is related to the watchpoint. We | |
2671 | will need to act on them together. */ | |
2672 | b->related_breakpoint = scope_breakpoint; | |
2673 | } | |
2674 | } | |
11054881 | 2675 | value_free_to_mark (mark); |
bd5635a1 RP |
2676 | mention (b); |
2677 | } | |
999dd04b | 2678 | |
11054881 KH |
2679 | /* Return count of locations need to be watched and can be handled |
2680 | in hardware. If the watchpoint can not be handled | |
999dd04b JL |
2681 | in hardware return zero. */ |
2682 | ||
2683 | static int | |
11054881 KH |
2684 | can_use_hardware_watchpoint (v) |
2685 | struct value *v; | |
999dd04b | 2686 | { |
11054881 | 2687 | int found_memory_cnt = 0; |
999dd04b JL |
2688 | |
2689 | /* Make sure all the intermediate values are in memory. Also make sure | |
2690 | we found at least one memory expression. Guards against watch 0x12345, | |
2691 | which is meaningless, but could cause errors if one tries to insert a | |
2692 | hardware watchpoint for the constant expression. */ | |
11054881 | 2693 | for ( ; v; v = v->next) |
999dd04b | 2694 | { |
11054881 KH |
2695 | if (v->lval == lval_memory) |
2696 | { | |
2697 | if (TYPE_LENGTH (VALUE_TYPE (v)) <= REGISTER_SIZE) | |
2698 | found_memory_cnt++; | |
2699 | } | |
2700 | else if (v->lval != not_lval && v->modifiable == 0) | |
999dd04b | 2701 | return 0; |
999dd04b JL |
2702 | } |
2703 | ||
2704 | /* The expression itself looks suitable for using a hardware | |
2705 | watchpoint, but give the target machine a chance to reject it. */ | |
11054881 KH |
2706 | return found_memory_cnt; |
2707 | } | |
2708 | ||
2709 | static void watch_command (arg, from_tty) | |
2710 | char *arg; | |
2711 | int from_tty; | |
2712 | { | |
2713 | watch_command_1 (arg, 0, from_tty); | |
2714 | } | |
2715 | ||
2716 | static void rwatch_command (arg, from_tty) | |
2717 | char *arg; | |
2718 | int from_tty; | |
2719 | { | |
2720 | watch_command_1 (arg, 1, from_tty); | |
2721 | } | |
2722 | ||
2723 | static void awatch_command (arg, from_tty) | |
2724 | char *arg; | |
2725 | int from_tty; | |
2726 | { | |
2727 | watch_command_1 (arg, 2, from_tty); | |
999dd04b JL |
2728 | } |
2729 | ||
bd5635a1 | 2730 | \f |
706dc3ce JL |
2731 | /* Helper routine for the until_command routine in infcmd.c. Here |
2732 | because it uses the mechanisms of breakpoints. */ | |
2733 | ||
bdbd5f50 | 2734 | /* ARGSUSED */ |
bd5635a1 RP |
2735 | void |
2736 | until_break_command (arg, from_tty) | |
2737 | char *arg; | |
2738 | int from_tty; | |
2739 | { | |
2740 | struct symtabs_and_lines sals; | |
2741 | struct symtab_and_line sal; | |
706dc3ce | 2742 | struct frame_info *prev_frame = get_prev_frame (selected_frame); |
30875e1c SG |
2743 | struct breakpoint *breakpoint; |
2744 | struct cleanup *old_chain; | |
bd5635a1 RP |
2745 | |
2746 | clear_proceed_status (); | |
2747 | ||
2748 | /* Set a breakpoint where the user wants it and at return from | |
2749 | this function */ | |
2750 | ||
2751 | if (default_breakpoint_valid) | |
2752 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
d889f6b7 | 2753 | default_breakpoint_line, (char ***)NULL); |
bd5635a1 | 2754 | else |
d889f6b7 | 2755 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL); |
bd5635a1 RP |
2756 | |
2757 | if (sals.nelts != 1) | |
2758 | error ("Couldn't get information on specified line."); | |
2759 | ||
2760 | sal = sals.sals[0]; | |
c8950965 | 2761 | free ((PTR)sals.sals); /* malloc'd, so freed */ |
bd5635a1 RP |
2762 | |
2763 | if (*arg) | |
2764 | error ("Junk at end of arguments."); | |
2765 | ||
30875e1c | 2766 | resolve_sal_pc (&sal); |
bd5635a1 | 2767 | |
30875e1c | 2768 | breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until); |
bd5635a1 | 2769 | |
30875e1c SG |
2770 | old_chain = make_cleanup(delete_breakpoint, breakpoint); |
2771 | ||
bd5635a1 RP |
2772 | /* Keep within the current frame */ |
2773 | ||
2774 | if (prev_frame) | |
2775 | { | |
706dc3ce JL |
2776 | sal = find_pc_line (prev_frame->pc, 0); |
2777 | sal.pc = prev_frame->pc; | |
30875e1c SG |
2778 | breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until); |
2779 | make_cleanup(delete_breakpoint, breakpoint); | |
bd5635a1 RP |
2780 | } |
2781 | ||
d7e7e851 | 2782 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
30875e1c | 2783 | do_cleanups(old_chain); |
bd5635a1 RP |
2784 | } |
2785 | \f | |
bdbd5f50 JG |
2786 | #if 0 |
2787 | /* These aren't used; I don't konw what they were for. */ | |
bd5635a1 RP |
2788 | /* Set a breakpoint at the catch clause for NAME. */ |
2789 | static int | |
2790 | catch_breakpoint (name) | |
2791 | char *name; | |
2792 | { | |
2793 | } | |
2794 | ||
2795 | static int | |
2796 | disable_catch_breakpoint () | |
2797 | { | |
2798 | } | |
2799 | ||
2800 | static int | |
2801 | delete_catch_breakpoint () | |
2802 | { | |
2803 | } | |
2804 | ||
2805 | static int | |
2806 | enable_catch_breakpoint () | |
2807 | { | |
2808 | } | |
bdbd5f50 | 2809 | #endif /* 0 */ |
bd5635a1 RP |
2810 | |
2811 | struct sal_chain | |
2812 | { | |
2813 | struct sal_chain *next; | |
2814 | struct symtab_and_line sal; | |
2815 | }; | |
2816 | ||
bdbd5f50 JG |
2817 | #if 0 |
2818 | /* This isn't used; I don't know what it was for. */ | |
bd5635a1 RP |
2819 | /* For each catch clause identified in ARGS, run FUNCTION |
2820 | with that clause as an argument. */ | |
2821 | static struct symtabs_and_lines | |
2822 | map_catch_names (args, function) | |
2823 | char *args; | |
2824 | int (*function)(); | |
2825 | { | |
2826 | register char *p = args; | |
2827 | register char *p1; | |
2828 | struct symtabs_and_lines sals; | |
bdbd5f50 | 2829 | #if 0 |
bd5635a1 | 2830 | struct sal_chain *sal_chain = 0; |
bdbd5f50 | 2831 | #endif |
bd5635a1 RP |
2832 | |
2833 | if (p == 0) | |
2834 | error_no_arg ("one or more catch names"); | |
2835 | ||
2836 | sals.nelts = 0; | |
2837 | sals.sals = NULL; | |
2838 | ||
2839 | while (*p) | |
2840 | { | |
2841 | p1 = p; | |
2842 | /* Don't swallow conditional part. */ | |
2843 | if (p1[0] == 'i' && p1[1] == 'f' | |
2844 | && (p1[2] == ' ' || p1[2] == '\t')) | |
2845 | break; | |
2846 | ||
2847 | if (isalpha (*p1)) | |
2848 | { | |
2849 | p1++; | |
2850 | while (isalnum (*p1) || *p1 == '_' || *p1 == '$') | |
2851 | p1++; | |
2852 | } | |
2853 | ||
2854 | if (*p1 && *p1 != ' ' && *p1 != '\t') | |
2855 | error ("Arguments must be catch names."); | |
2856 | ||
2857 | *p1 = 0; | |
2858 | #if 0 | |
2859 | if (function (p)) | |
2860 | { | |
2861 | struct sal_chain *next | |
2862 | = (struct sal_chain *)alloca (sizeof (struct sal_chain)); | |
2863 | next->next = sal_chain; | |
2864 | next->sal = get_catch_sal (p); | |
2865 | sal_chain = next; | |
2866 | goto win; | |
2867 | } | |
2868 | #endif | |
199b2450 | 2869 | printf_unfiltered ("No catch clause for exception %s.\n", p); |
bdbd5f50 | 2870 | #if 0 |
bd5635a1 | 2871 | win: |
bdbd5f50 | 2872 | #endif |
bd5635a1 RP |
2873 | p = p1; |
2874 | while (*p == ' ' || *p == '\t') p++; | |
2875 | } | |
2876 | } | |
bdbd5f50 | 2877 | #endif /* 0 */ |
bd5635a1 RP |
2878 | |
2879 | /* This shares a lot of code with `print_frame_label_vars' from stack.c. */ | |
2880 | ||
2881 | static struct symtabs_and_lines | |
2882 | get_catch_sals (this_level_only) | |
2883 | int this_level_only; | |
2884 | { | |
bd5635a1 | 2885 | register struct blockvector *bl; |
777bef06 | 2886 | register struct block *block; |
bd5635a1 | 2887 | int index, have_default = 0; |
777bef06 | 2888 | CORE_ADDR pc; |
bd5635a1 RP |
2889 | struct symtabs_and_lines sals; |
2890 | struct sal_chain *sal_chain = 0; | |
2891 | char *blocks_searched; | |
2892 | ||
777bef06 JK |
2893 | /* Not sure whether an error message is always the correct response, |
2894 | but it's better than a core dump. */ | |
2895 | if (selected_frame == NULL) | |
2896 | error ("No selected frame."); | |
2897 | block = get_frame_block (selected_frame); | |
706dc3ce | 2898 | pc = selected_frame->pc; |
777bef06 | 2899 | |
bd5635a1 RP |
2900 | sals.nelts = 0; |
2901 | sals.sals = NULL; | |
2902 | ||
2903 | if (block == 0) | |
2904 | error ("No symbol table info available.\n"); | |
2905 | ||
2906 | bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); | |
2907 | blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); | |
4ed3a9ea | 2908 | memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); |
bd5635a1 RP |
2909 | |
2910 | while (block != 0) | |
2911 | { | |
2912 | CORE_ADDR end = BLOCK_END (block) - 4; | |
2913 | int last_index; | |
2914 | ||
2915 | if (bl != blockvector_for_pc (end, &index)) | |
2916 | error ("blockvector blotch"); | |
2917 | if (BLOCKVECTOR_BLOCK (bl, index) != block) | |
2918 | error ("blockvector botch"); | |
2919 | last_index = BLOCKVECTOR_NBLOCKS (bl); | |
2920 | index += 1; | |
2921 | ||
2922 | /* Don't print out blocks that have gone by. */ | |
2923 | while (index < last_index | |
2924 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) | |
2925 | index++; | |
2926 | ||
2927 | while (index < last_index | |
2928 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) | |
2929 | { | |
2930 | if (blocks_searched[index] == 0) | |
2931 | { | |
2932 | struct block *b = BLOCKVECTOR_BLOCK (bl, index); | |
2933 | int nsyms; | |
2934 | register int i; | |
2935 | register struct symbol *sym; | |
2936 | ||
2937 | nsyms = BLOCK_NSYMS (b); | |
2938 | ||
2939 | for (i = 0; i < nsyms; i++) | |
2940 | { | |
2941 | sym = BLOCK_SYM (b, i); | |
2d313932 | 2942 | if (STREQ (SYMBOL_NAME (sym), "default")) |
bd5635a1 RP |
2943 | { |
2944 | if (have_default) | |
2945 | continue; | |
2946 | have_default = 1; | |
2947 | } | |
2948 | if (SYMBOL_CLASS (sym) == LOC_LABEL) | |
2949 | { | |
2950 | struct sal_chain *next = (struct sal_chain *) | |
2951 | alloca (sizeof (struct sal_chain)); | |
2952 | next->next = sal_chain; | |
2953 | next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); | |
2954 | sal_chain = next; | |
2955 | } | |
2956 | } | |
2957 | blocks_searched[index] = 1; | |
2958 | } | |
2959 | index++; | |
2960 | } | |
2961 | if (have_default) | |
2962 | break; | |
2963 | if (sal_chain && this_level_only) | |
2964 | break; | |
2965 | ||
2966 | /* After handling the function's top-level block, stop. | |
2967 | Don't continue to its superblock, the block of | |
2968 | per-file symbols. */ | |
2969 | if (BLOCK_FUNCTION (block)) | |
2970 | break; | |
2971 | block = BLOCK_SUPERBLOCK (block); | |
2972 | } | |
2973 | ||
2974 | if (sal_chain) | |
2975 | { | |
2976 | struct sal_chain *tmp_chain; | |
2977 | ||
2978 | /* Count the number of entries. */ | |
2979 | for (index = 0, tmp_chain = sal_chain; tmp_chain; | |
2980 | tmp_chain = tmp_chain->next) | |
2981 | index++; | |
2982 | ||
2983 | sals.nelts = index; | |
2984 | sals.sals = (struct symtab_and_line *) | |
2985 | xmalloc (index * sizeof (struct symtab_and_line)); | |
2986 | for (index = 0; sal_chain; sal_chain = sal_chain->next, index++) | |
2987 | sals.sals[index] = sal_chain->sal; | |
2988 | } | |
2989 | ||
2990 | return sals; | |
2991 | } | |
2992 | ||
2993 | /* Commands to deal with catching exceptions. */ | |
2994 | ||
30875e1c | 2995 | static void |
bd5635a1 RP |
2996 | catch_command_1 (arg, tempflag, from_tty) |
2997 | char *arg; | |
2998 | int tempflag; | |
2999 | int from_tty; | |
3000 | { | |
3001 | /* First, translate ARG into something we can deal with in terms | |
3002 | of breakpoints. */ | |
3003 | ||
3004 | struct symtabs_and_lines sals; | |
3005 | struct symtab_and_line sal; | |
3006 | register struct expression *cond = 0; | |
3007 | register struct breakpoint *b; | |
3008 | char *save_arg; | |
3009 | int i; | |
bd5635a1 RP |
3010 | |
3011 | sal.line = sal.pc = sal.end = 0; | |
3012 | sal.symtab = 0; | |
3013 | ||
3014 | /* If no arg given, or if first arg is 'if ', all active catch clauses | |
3015 | are breakpointed. */ | |
3016 | ||
3017 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' | |
3018 | && (arg[2] == ' ' || arg[2] == '\t'))) | |
3019 | { | |
3020 | /* Grab all active catch clauses. */ | |
3021 | sals = get_catch_sals (0); | |
3022 | } | |
3023 | else | |
3024 | { | |
3025 | /* Grab selected catch clauses. */ | |
fe675038 | 3026 | error ("catch NAME not implemented"); |
bdbd5f50 JG |
3027 | #if 0 |
3028 | /* This isn't used; I don't know what it was for. */ | |
bd5635a1 | 3029 | sals = map_catch_names (arg, catch_breakpoint); |
bdbd5f50 | 3030 | #endif |
bd5635a1 RP |
3031 | } |
3032 | ||
3033 | if (! sals.nelts) | |
3034 | return; | |
3035 | ||
3036 | save_arg = arg; | |
3037 | for (i = 0; i < sals.nelts; i++) | |
3038 | { | |
30875e1c | 3039 | resolve_sal_pc (&sals.sals[i]); |
bd5635a1 RP |
3040 | |
3041 | while (arg && *arg) | |
3042 | { | |
3043 | if (arg[0] == 'i' && arg[1] == 'f' | |
3044 | && (arg[2] == ' ' || arg[2] == '\t')) | |
30875e1c SG |
3045 | cond = parse_exp_1 ((arg += 2, &arg), |
3046 | block_for_pc (sals.sals[i].pc), 0); | |
bd5635a1 RP |
3047 | else |
3048 | error ("Junk at end of arguments."); | |
3049 | } | |
3050 | arg = save_arg; | |
bd5635a1 RP |
3051 | } |
3052 | ||
3053 | for (i = 0; i < sals.nelts; i++) | |
3054 | { | |
3055 | sal = sals.sals[i]; | |
3056 | ||
3057 | if (from_tty) | |
3058 | describe_other_breakpoints (sal.pc); | |
3059 | ||
3060 | b = set_raw_breakpoint (sal); | |
30875e1c SG |
3061 | set_breakpoint_count (breakpoint_count + 1); |
3062 | b->number = breakpoint_count; | |
3063 | b->type = bp_breakpoint; | |
bd5635a1 | 3064 | b->cond = cond; |
30875e1c | 3065 | b->enable = enabled; |
e8bf33c4 | 3066 | b->disposition = tempflag ? del : donttouch; |
bd5635a1 | 3067 | |
d889f6b7 | 3068 | mention (b); |
bd5635a1 RP |
3069 | } |
3070 | ||
3071 | if (sals.nelts > 1) | |
3072 | { | |
199b2450 TL |
3073 | printf_unfiltered ("Multiple breakpoints were set.\n"); |
3074 | printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n"); | |
bd5635a1 | 3075 | } |
c8950965 | 3076 | free ((PTR)sals.sals); |
bd5635a1 RP |
3077 | } |
3078 | ||
e8bf33c4 JK |
3079 | /* Used by the gui, could be made a worker for other things. */ |
3080 | ||
3081 | struct breakpoint * | |
3082 | set_breakpoint_sal (sal) | |
3083 | struct symtab_and_line sal; | |
3084 | { | |
3085 | struct breakpoint *b; | |
3086 | b = set_raw_breakpoint (sal); | |
3087 | set_breakpoint_count (breakpoint_count + 1); | |
3088 | b->number = breakpoint_count; | |
3089 | b->type = bp_breakpoint; | |
3090 | b->cond = 0; | |
3091 | b->thread = -1; | |
3092 | return b; | |
3093 | } | |
3094 | ||
bdbd5f50 JG |
3095 | #if 0 |
3096 | /* These aren't used; I don't know what they were for. */ | |
bd5635a1 RP |
3097 | /* Disable breakpoints on all catch clauses described in ARGS. */ |
3098 | static void | |
3099 | disable_catch (args) | |
3100 | char *args; | |
3101 | { | |
3102 | /* Map the disable command to catch clauses described in ARGS. */ | |
3103 | } | |
3104 | ||
3105 | /* Enable breakpoints on all catch clauses described in ARGS. */ | |
3106 | static void | |
3107 | enable_catch (args) | |
3108 | char *args; | |
3109 | { | |
3110 | /* Map the disable command to catch clauses described in ARGS. */ | |
3111 | } | |
3112 | ||
3113 | /* Delete breakpoints on all catch clauses in the active scope. */ | |
3114 | static void | |
3115 | delete_catch (args) | |
3116 | char *args; | |
3117 | { | |
3118 | /* Map the delete command to catch clauses described in ARGS. */ | |
3119 | } | |
bdbd5f50 | 3120 | #endif /* 0 */ |
bd5635a1 RP |
3121 | |
3122 | static void | |
3123 | catch_command (arg, from_tty) | |
3124 | char *arg; | |
3125 | int from_tty; | |
3126 | { | |
3127 | catch_command_1 (arg, 0, from_tty); | |
3128 | } | |
3129 | \f | |
3130 | static void | |
3131 | clear_command (arg, from_tty) | |
3132 | char *arg; | |
3133 | int from_tty; | |
3134 | { | |
3135 | register struct breakpoint *b, *b1; | |
3136 | struct symtabs_and_lines sals; | |
3137 | struct symtab_and_line sal; | |
3138 | register struct breakpoint *found; | |
3139 | int i; | |
3140 | ||
3141 | if (arg) | |
3142 | { | |
3143 | sals = decode_line_spec (arg, 1); | |
3144 | } | |
3145 | else | |
3146 | { | |
3147 | sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); | |
3148 | sal.line = default_breakpoint_line; | |
3149 | sal.symtab = default_breakpoint_symtab; | |
3150 | sal.pc = 0; | |
3151 | if (sal.symtab == 0) | |
3152 | error ("No source file specified."); | |
3153 | ||
3154 | sals.sals[0] = sal; | |
3155 | sals.nelts = 1; | |
3156 | } | |
3157 | ||
3158 | for (i = 0; i < sals.nelts; i++) | |
3159 | { | |
3160 | /* If exact pc given, clear bpts at that pc. | |
3161 | But if sal.pc is zero, clear all bpts on specified line. */ | |
3162 | sal = sals.sals[i]; | |
3163 | found = (struct breakpoint *) 0; | |
3164 | while (breakpoint_chain | |
d889f6b7 JK |
3165 | && (sal.pc |
3166 | ? breakpoint_chain->address == sal.pc | |
3167 | : (breakpoint_chain->source_file != NULL | |
3168 | && sal.symtab != NULL | |
3169 | && STREQ (breakpoint_chain->source_file, | |
3170 | sal.symtab->filename) | |
bd5635a1 RP |
3171 | && breakpoint_chain->line_number == sal.line))) |
3172 | { | |
3173 | b1 = breakpoint_chain; | |
3174 | breakpoint_chain = b1->next; | |
3175 | b1->next = found; | |
3176 | found = b1; | |
3177 | } | |
3178 | ||
3179 | ALL_BREAKPOINTS (b) | |
3180 | while (b->next | |
30875e1c | 3181 | && b->next->type != bp_watchpoint |
999dd04b | 3182 | && b->next->type != bp_hardware_watchpoint |
11054881 KH |
3183 | && b->next->type != bp_read_watchpoint |
3184 | && b->next->type != bp_access_watchpoint | |
d889f6b7 JK |
3185 | && (sal.pc |
3186 | ? b->next->address == sal.pc | |
3187 | : (b->next->source_file != NULL | |
3188 | && sal.symtab != NULL | |
3189 | && STREQ (b->next->source_file, sal.symtab->filename) | |
bd5635a1 RP |
3190 | && b->next->line_number == sal.line))) |
3191 | { | |
3192 | b1 = b->next; | |
3193 | b->next = b1->next; | |
3194 | b1->next = found; | |
3195 | found = b1; | |
3196 | } | |
3197 | ||
3198 | if (found == 0) | |
3199 | { | |
3200 | if (arg) | |
3201 | error ("No breakpoint at %s.", arg); | |
3202 | else | |
3203 | error ("No breakpoint at this line."); | |
3204 | } | |
3205 | ||
3206 | if (found->next) from_tty = 1; /* Always report if deleted more than one */ | |
199b2450 | 3207 | if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : ""); |
6c803036 | 3208 | breakpoints_changed (); |
bd5635a1 RP |
3209 | while (found) |
3210 | { | |
199b2450 | 3211 | if (from_tty) printf_unfiltered ("%d ", found->number); |
bd5635a1 RP |
3212 | b1 = found->next; |
3213 | delete_breakpoint (found); | |
3214 | found = b1; | |
3215 | } | |
199b2450 | 3216 | if (from_tty) putchar_unfiltered ('\n'); |
bd5635a1 | 3217 | } |
c8950965 | 3218 | free ((PTR)sals.sals); |
bd5635a1 RP |
3219 | } |
3220 | \f | |
e51481f9 JL |
3221 | /* Delete breakpoint in BS if they are `delete' breakpoints and |
3222 | all breakpoints that are marked for deletion, whether hit or not. | |
bd5635a1 RP |
3223 | This is called after any breakpoint is hit, or after errors. */ |
3224 | ||
3225 | void | |
3226 | breakpoint_auto_delete (bs) | |
3227 | bpstat bs; | |
3228 | { | |
e51481f9 JL |
3229 | struct breakpoint *b, *temp; |
3230 | ||
bd5635a1 | 3231 | for (; bs; bs = bs->next) |
e8bf33c4 | 3232 | if (bs->breakpoint_at && bs->breakpoint_at->disposition == del |
cef4c2e7 | 3233 | && bs->stop) |
bd5635a1 | 3234 | delete_breakpoint (bs->breakpoint_at); |
e51481f9 JL |
3235 | |
3236 | ALL_BREAKPOINTS_SAFE (b, temp) | |
3237 | { | |
3238 | if (b->disposition == del_at_next_stop) | |
3239 | delete_breakpoint (b); | |
3240 | } | |
bd5635a1 RP |
3241 | } |
3242 | ||
3243 | /* Delete a breakpoint and clean up all traces of it in the data structures. */ | |
3244 | ||
30875e1c | 3245 | void |
bd5635a1 RP |
3246 | delete_breakpoint (bpt) |
3247 | struct breakpoint *bpt; | |
3248 | { | |
3249 | register struct breakpoint *b; | |
3250 | register bpstat bs; | |
3251 | ||
754e5da2 SG |
3252 | if (delete_breakpoint_hook) |
3253 | delete_breakpoint_hook (bpt); | |
3254 | ||
bd5635a1 | 3255 | if (bpt->inserted) |
999dd04b JL |
3256 | remove_breakpoint (bpt); |
3257 | ||
bd5635a1 RP |
3258 | if (breakpoint_chain == bpt) |
3259 | breakpoint_chain = bpt->next; | |
3260 | ||
3261 | ALL_BREAKPOINTS (b) | |
3262 | if (b->next == bpt) | |
3263 | { | |
3264 | b->next = bpt->next; | |
3265 | break; | |
3266 | } | |
3267 | ||
3268 | check_duplicates (bpt->address); | |
fe675038 JK |
3269 | /* If this breakpoint was inserted, and there is another breakpoint |
3270 | at the same address, we need to insert the other breakpoint. */ | |
999dd04b | 3271 | if (bpt->inserted |
11054881 KH |
3272 | && bpt->type != bp_hardware_watchpoint |
3273 | && bpt->type != bp_read_watchpoint | |
3274 | && bpt->type != bp_access_watchpoint) | |
fe675038 JK |
3275 | { |
3276 | ALL_BREAKPOINTS (b) | |
ebad9e90 JK |
3277 | if (b->address == bpt->address |
3278 | && !b->duplicate | |
fa3764e2 JL |
3279 | && b->enable != disabled |
3280 | && b->enable != shlib_disabled) | |
fe675038 JK |
3281 | { |
3282 | int val; | |
3283 | val = target_insert_breakpoint (b->address, b->shadow_contents); | |
3284 | if (val != 0) | |
3285 | { | |
05052b63 | 3286 | target_terminal_ours_for_output (); |
199b2450 | 3287 | fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number); |
fe675038 JK |
3288 | memory_error (val, b->address); /* which bombs us out */ |
3289 | } | |
3290 | else | |
3291 | b->inserted = 1; | |
3292 | } | |
3293 | } | |
bd5635a1 RP |
3294 | |
3295 | free_command_lines (&bpt->commands); | |
3296 | if (bpt->cond) | |
d889f6b7 | 3297 | free (bpt->cond); |
bd5635a1 | 3298 | if (bpt->cond_string != NULL) |
d889f6b7 | 3299 | free (bpt->cond_string); |
bd5635a1 | 3300 | if (bpt->addr_string != NULL) |
d889f6b7 | 3301 | free (bpt->addr_string); |
39ce6829 PS |
3302 | if (bpt->exp != NULL) |
3303 | free (bpt->exp); | |
0eaaa46a | 3304 | if (bpt->exp_string != NULL) |
d889f6b7 | 3305 | free (bpt->exp_string); |
39ce6829 PS |
3306 | if (bpt->val != NULL) |
3307 | value_free (bpt->val); | |
d889f6b7 JK |
3308 | if (bpt->source_file != NULL) |
3309 | free (bpt->source_file); | |
bd5635a1 | 3310 | |
bd5635a1 | 3311 | /* Be sure no bpstat's are pointing at it after it's been freed. */ |
05052b63 JK |
3312 | /* FIXME, how can we find all bpstat's? |
3313 | We just check stop_bpstat for now. */ | |
bd5635a1 RP |
3314 | for (bs = stop_bpstat; bs; bs = bs->next) |
3315 | if (bs->breakpoint_at == bpt) | |
3316 | bs->breakpoint_at = NULL; | |
c8950965 | 3317 | free ((PTR)bpt); |
bd5635a1 RP |
3318 | } |
3319 | ||
bd5635a1 RP |
3320 | static void |
3321 | delete_command (arg, from_tty) | |
3322 | char *arg; | |
3323 | int from_tty; | |
3324 | { | |
3325 | ||
3326 | if (arg == 0) | |
3327 | { | |
3328 | /* Ask user only if there are some breakpoints to delete. */ | |
3329 | if (!from_tty | |
e8bf33c4 | 3330 | || (breakpoint_chain && query ("Delete all breakpoints? "))) |
bd5635a1 RP |
3331 | { |
3332 | /* No arg; clear all breakpoints. */ | |
3333 | while (breakpoint_chain) | |
3334 | delete_breakpoint (breakpoint_chain); | |
3335 | } | |
3336 | } | |
3337 | else | |
3338 | map_breakpoint_numbers (arg, delete_breakpoint); | |
3339 | } | |
3340 | ||
bdbd5f50 JG |
3341 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
3342 | The value we return ends up being the return value from catch_errors. | |
3343 | Unused in this case. */ | |
3344 | ||
3345 | static int | |
bd5635a1 | 3346 | breakpoint_re_set_one (bint) |
bdbd5f50 | 3347 | char *bint; |
bd5635a1 RP |
3348 | { |
3349 | struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */ | |
11054881 | 3350 | struct value *mark; |
bd5635a1 RP |
3351 | int i; |
3352 | struct symtabs_and_lines sals; | |
bd5635a1 | 3353 | char *s; |
30875e1c | 3354 | enum enable save_enable; |
bd5635a1 | 3355 | |
80ba48f5 | 3356 | switch (b->type) |
bd5635a1 | 3357 | { |
80ba48f5 | 3358 | case bp_breakpoint: |
11054881 | 3359 | case bp_hardware_breakpoint: |
80ba48f5 SG |
3360 | if (b->addr_string == NULL) |
3361 | { | |
3362 | /* Anything without a string can't be re-set. */ | |
3363 | delete_breakpoint (b); | |
3364 | return 0; | |
3365 | } | |
30875e1c SG |
3366 | /* In case we have a problem, disable this breakpoint. We'll restore |
3367 | its status if we succeed. */ | |
3368 | save_enable = b->enable; | |
3369 | b->enable = disabled; | |
3370 | ||
706dc3ce JL |
3371 | set_language (b->language); |
3372 | input_radix = b->input_radix; | |
bd5635a1 | 3373 | s = b->addr_string; |
d889f6b7 | 3374 | sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL); |
bd5635a1 RP |
3375 | for (i = 0; i < sals.nelts; i++) |
3376 | { | |
30875e1c | 3377 | resolve_sal_pc (&sals.sals[i]); |
fee933f1 RP |
3378 | |
3379 | /* Reparse conditions, they might contain references to the | |
3380 | old symtab. */ | |
3381 | if (b->cond_string != NULL) | |
3382 | { | |
3383 | s = b->cond_string; | |
3384 | if (b->cond) | |
3385 | free ((PTR)b->cond); | |
3386 | b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0); | |
3387 | } | |
3388 | ||
3389 | /* We need to re-set the breakpoint if the address changes...*/ | |
d889f6b7 | 3390 | if (b->address != sals.sals[i].pc |
fee933f1 RP |
3391 | /* ...or new and old breakpoints both have source files, and |
3392 | the source file name or the line number changes... */ | |
d889f6b7 JK |
3393 | || (b->source_file != NULL |
3394 | && sals.sals[i].symtab != NULL | |
3395 | && (!STREQ (b->source_file, sals.sals[i].symtab->filename) | |
3396 | || b->line_number != sals.sals[i].line) | |
fee933f1 RP |
3397 | ) |
3398 | /* ...or we switch between having a source file and not having | |
3399 | one. */ | |
3400 | || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL)) | |
3401 | ) | |
bd5635a1 | 3402 | { |
d889f6b7 JK |
3403 | if (b->source_file != NULL) |
3404 | free (b->source_file); | |
3405 | if (sals.sals[i].symtab == NULL) | |
3406 | b->source_file = NULL; | |
3407 | else | |
3408 | b->source_file = | |
3409 | savestring (sals.sals[i].symtab->filename, | |
3410 | strlen (sals.sals[i].symtab->filename)); | |
8537ba60 SG |
3411 | b->line_number = sals.sals[i].line; |
3412 | b->address = sals.sals[i].pc; | |
bd5635a1 | 3413 | |
8537ba60 | 3414 | check_duplicates (b->address); |
bd5635a1 | 3415 | |
8537ba60 | 3416 | mention (b); |
6c803036 JK |
3417 | |
3418 | /* Might be better to do this just once per breakpoint_re_set, | |
3419 | rather than once for every breakpoint. */ | |
3420 | breakpoints_changed (); | |
8537ba60 | 3421 | } |
30875e1c | 3422 | b->enable = save_enable; /* Restore it, this worked. */ |
bd5635a1 | 3423 | } |
c8950965 | 3424 | free ((PTR)sals.sals); |
80ba48f5 | 3425 | break; |
2d313932 | 3426 | |
80ba48f5 | 3427 | case bp_watchpoint: |
999dd04b | 3428 | case bp_hardware_watchpoint: |
11054881 KH |
3429 | case bp_read_watchpoint: |
3430 | case bp_access_watchpoint: | |
0eaaa46a | 3431 | innermost_block = NULL; |
0a97f6c4 JK |
3432 | /* The issue arises of what context to evaluate this in. The same |
3433 | one as when it was set, but what does that mean when symbols have | |
3434 | been re-read? We could save the filename and functionname, but | |
3435 | if the context is more local than that, the best we could do would | |
3436 | be something like how many levels deep and which index at that | |
3437 | particular level, but that's going to be less stable than filenames | |
3438 | or functionnames. */ | |
3439 | /* So for now, just use a global context. */ | |
39ce6829 PS |
3440 | if (b->exp) |
3441 | free ((PTR)b->exp); | |
0eaaa46a JK |
3442 | b->exp = parse_expression (b->exp_string); |
3443 | b->exp_valid_block = innermost_block; | |
11054881 | 3444 | mark = value_mark (); |
39ce6829 PS |
3445 | if (b->val) |
3446 | value_free (b->val); | |
0eaaa46a JK |
3447 | b->val = evaluate_expression (b->exp); |
3448 | release_value (b->val); | |
3449 | if (VALUE_LAZY (b->val)) | |
3450 | value_fetch_lazy (b->val); | |
3451 | ||
2d313932 JK |
3452 | if (b->cond_string != NULL) |
3453 | { | |
3454 | s = b->cond_string; | |
39ce6829 PS |
3455 | if (b->cond) |
3456 | free ((PTR)b->cond); | |
2d313932 JK |
3457 | b->cond = parse_exp_1 (&s, (struct block *)0, 0); |
3458 | } | |
cabd4da6 JK |
3459 | if (b->enable == enabled) |
3460 | mention (b); | |
11054881 | 3461 | value_free_to_mark (mark); |
80ba48f5 | 3462 | break; |
2d313932 | 3463 | |
80ba48f5 SG |
3464 | default: |
3465 | printf_filtered ("Deleting unknown breakpoint type %d\n", b->type); | |
2d313932 | 3466 | /* fall through */ |
fa3764e2 JL |
3467 | /* Delete longjmp breakpoints, they will be reset later by |
3468 | breakpoint_re_set. */ | |
80ba48f5 SG |
3469 | case bp_longjmp: |
3470 | case bp_longjmp_resume: | |
3471 | delete_breakpoint (b); | |
3472 | break; | |
27b6a1fa JL |
3473 | |
3474 | /* This breakpoint is special, it's set up when the inferior | |
3475 | starts and we really don't want to touch it. */ | |
3476 | case bp_shlib_event: | |
fa3764e2 JL |
3477 | |
3478 | /* Keep temporary breakpoints, which can be encountered when we step | |
3479 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
3480 | Otherwise these should have been blown away via the cleanup chain | |
3481 | or by breakpoint_init_inferior when we rerun the executable. */ | |
3482 | case bp_until: | |
3483 | case bp_finish: | |
3484 | case bp_watchpoint_scope: | |
3485 | case bp_call_dummy: | |
3486 | case bp_step_resume: | |
27b6a1fa | 3487 | break; |
bd5635a1 | 3488 | } |
80ba48f5 | 3489 | |
bdbd5f50 | 3490 | return 0; |
bd5635a1 RP |
3491 | } |
3492 | ||
3493 | /* Re-set all breakpoints after symbols have been re-loaded. */ | |
3494 | void | |
3495 | breakpoint_re_set () | |
3496 | { | |
cba0d141 | 3497 | struct breakpoint *b, *temp; |
706dc3ce JL |
3498 | enum language save_language; |
3499 | int save_input_radix; | |
30875e1c SG |
3500 | static char message1[] = "Error in re-setting breakpoint %d:\n"; |
3501 | char message[sizeof (message1) + 30 /* slop */]; | |
bd5635a1 | 3502 | |
706dc3ce JL |
3503 | save_language = current_language->la_language; |
3504 | save_input_radix = input_radix; | |
cba0d141 | 3505 | ALL_BREAKPOINTS_SAFE (b, temp) |
bd5635a1 | 3506 | { |
2d313932 | 3507 | sprintf (message, message1, b->number); /* Format possible error msg */ |
fe675038 JK |
3508 | catch_errors (breakpoint_re_set_one, (char *) b, message, |
3509 | RETURN_MASK_ALL); | |
bd5635a1 | 3510 | } |
706dc3ce JL |
3511 | set_language (save_language); |
3512 | input_radix = save_input_radix; | |
bd5635a1 | 3513 | |
cd10c7e3 SG |
3514 | #ifdef GET_LONGJMP_TARGET |
3515 | create_longjmp_breakpoint ("longjmp"); | |
3516 | create_longjmp_breakpoint ("_longjmp"); | |
3517 | create_longjmp_breakpoint ("siglongjmp"); | |
3518 | create_longjmp_breakpoint (NULL); | |
3519 | #endif | |
80ba48f5 | 3520 | |
1eeba686 | 3521 | #if 0 |
0fe1522a | 3522 | /* Took this out (temporarily at least), since it produces an extra |
1eeba686 | 3523 | blank line at startup. This messes up the gdbtests. -PB */ |
bd5635a1 RP |
3524 | /* Blank line to finish off all those mention() messages we just printed. */ |
3525 | printf_filtered ("\n"); | |
1eeba686 | 3526 | #endif |
bd5635a1 RP |
3527 | } |
3528 | \f | |
3529 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. | |
3530 | If from_tty is nonzero, it prints a message to that effect, | |
3531 | which ends with a period (no newline). */ | |
3532 | ||
3533 | void | |
3534 | set_ignore_count (bptnum, count, from_tty) | |
3535 | int bptnum, count, from_tty; | |
3536 | { | |
3537 | register struct breakpoint *b; | |
3538 | ||
3539 | if (count < 0) | |
3540 | count = 0; | |
3541 | ||
3542 | ALL_BREAKPOINTS (b) | |
3543 | if (b->number == bptnum) | |
3544 | { | |
3545 | b->ignore_count = count; | |
3546 | if (!from_tty) | |
3547 | return; | |
3548 | else if (count == 0) | |
423e9664 SG |
3549 | printf_filtered ("Will stop next time breakpoint %d is reached.", |
3550 | bptnum); | |
bd5635a1 | 3551 | else if (count == 1) |
423e9664 SG |
3552 | printf_filtered ("Will ignore next crossing of breakpoint %d.", |
3553 | bptnum); | |
bd5635a1 | 3554 | else |
423e9664 | 3555 | printf_filtered ("Will ignore next %d crossings of breakpoint %d.", |
bd5635a1 | 3556 | count, bptnum); |
6c803036 | 3557 | breakpoints_changed (); |
bd5635a1 RP |
3558 | return; |
3559 | } | |
3560 | ||
3561 | error ("No breakpoint number %d.", bptnum); | |
3562 | } | |
3563 | ||
3564 | /* Clear the ignore counts of all breakpoints. */ | |
3565 | void | |
3566 | breakpoint_clear_ignore_counts () | |
3567 | { | |
3568 | struct breakpoint *b; | |
3569 | ||
3570 | ALL_BREAKPOINTS (b) | |
3571 | b->ignore_count = 0; | |
3572 | } | |
3573 | ||
3574 | /* Command to set ignore-count of breakpoint N to COUNT. */ | |
3575 | ||
3576 | static void | |
3577 | ignore_command (args, from_tty) | |
3578 | char *args; | |
3579 | int from_tty; | |
3580 | { | |
3581 | char *p = args; | |
3582 | register int num; | |
3583 | ||
3584 | if (p == 0) | |
3585 | error_no_arg ("a breakpoint number"); | |
3586 | ||
3587 | num = get_number (&p); | |
3588 | ||
3589 | if (*p == 0) | |
3590 | error ("Second argument (specified ignore-count) is missing."); | |
3591 | ||
bdbd5f50 JG |
3592 | set_ignore_count (num, |
3593 | longest_to_int (value_as_long (parse_and_eval (p))), | |
3594 | from_tty); | |
423e9664 | 3595 | printf_filtered ("\n"); |
6c803036 | 3596 | breakpoints_changed (); |
bd5635a1 RP |
3597 | } |
3598 | \f | |
3599 | /* Call FUNCTION on each of the breakpoints | |
3600 | whose numbers are given in ARGS. */ | |
3601 | ||
3602 | static void | |
3603 | map_breakpoint_numbers (args, function) | |
3604 | char *args; | |
30875e1c | 3605 | void (*function) PARAMS ((struct breakpoint *)); |
bd5635a1 RP |
3606 | { |
3607 | register char *p = args; | |
3608 | char *p1; | |
3609 | register int num; | |
3610 | register struct breakpoint *b; | |
3611 | ||
3612 | if (p == 0) | |
3613 | error_no_arg ("one or more breakpoint numbers"); | |
3614 | ||
3615 | while (*p) | |
3616 | { | |
3617 | p1 = p; | |
3618 | ||
3619 | num = get_number (&p1); | |
3620 | ||
3621 | ALL_BREAKPOINTS (b) | |
3622 | if (b->number == num) | |
3623 | { | |
999dd04b | 3624 | struct breakpoint *related_breakpoint = b->related_breakpoint; |
bd5635a1 | 3625 | function (b); |
999dd04b JL |
3626 | if (related_breakpoint) |
3627 | function (related_breakpoint); | |
bd5635a1 RP |
3628 | goto win; |
3629 | } | |
199b2450 | 3630 | printf_unfiltered ("No breakpoint number %d.\n", num); |
bd5635a1 RP |
3631 | win: |
3632 | p = p1; | |
3633 | } | |
3634 | } | |
3635 | ||
e8bf33c4 | 3636 | void |
bd5635a1 RP |
3637 | disable_breakpoint (bpt) |
3638 | struct breakpoint *bpt; | |
3639 | { | |
999dd04b JL |
3640 | /* Never disable a watchpoint scope breakpoint; we want to |
3641 | hit them when we leave scope so we can delete both the | |
3642 | watchpoint and its scope breakpoint at that time. */ | |
3643 | if (bpt->type == bp_watchpoint_scope) | |
3644 | return; | |
3645 | ||
bd5635a1 RP |
3646 | bpt->enable = disabled; |
3647 | ||
bd5635a1 | 3648 | check_duplicates (bpt->address); |
e8bf33c4 JK |
3649 | |
3650 | if (modify_breakpoint_hook) | |
3651 | modify_breakpoint_hook (bpt); | |
bd5635a1 RP |
3652 | } |
3653 | ||
bdbd5f50 | 3654 | /* ARGSUSED */ |
bd5635a1 RP |
3655 | static void |
3656 | disable_command (args, from_tty) | |
3657 | char *args; | |
3658 | int from_tty; | |
3659 | { | |
3660 | register struct breakpoint *bpt; | |
3661 | if (args == 0) | |
3662 | ALL_BREAKPOINTS (bpt) | |
423e9664 SG |
3663 | switch (bpt->type) |
3664 | { | |
3665 | case bp_breakpoint: | |
11054881 KH |
3666 | case bp_hardware_breakpoint: |
3667 | case bp_watchpoint: | |
3668 | case bp_hardware_watchpoint: | |
3669 | case bp_read_watchpoint: | |
3670 | case bp_access_watchpoint: | |
423e9664 SG |
3671 | disable_breakpoint (bpt); |
3672 | default: | |
3673 | continue; | |
3674 | } | |
bd5635a1 RP |
3675 | else |
3676 | map_breakpoint_numbers (args, disable_breakpoint); | |
3677 | } | |
3678 | ||
3679 | static void | |
3f37b696 | 3680 | do_enable_breakpoint (bpt, disposition) |
bd5635a1 | 3681 | struct breakpoint *bpt; |
3f37b696 | 3682 | enum bpdisp disposition; |
bd5635a1 | 3683 | { |
706dc3ce | 3684 | struct frame_info *save_selected_frame = NULL; |
11054881 KH |
3685 | int save_selected_frame_level = -1; |
3686 | int target_resources_ok, other_type_used; | |
3687 | struct value *mark; | |
3688 | ||
3f37b696 FF |
3689 | if (bpt->type == bp_hardware_breakpoint) |
3690 | { | |
11054881 KH |
3691 | int i; |
3692 | i = hw_breakpoint_used_count(); | |
3693 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( | |
3694 | bp_hardware_breakpoint, i+1, 0); | |
3695 | if (target_resources_ok == 0) | |
3696 | error ("No hardware breakpoint support in the target."); | |
3697 | else if (target_resources_ok < 0) | |
3698 | error ("Hardware breakpoints used exceeds limit."); | |
3699 | } | |
3700 | ||
30875e1c | 3701 | bpt->enable = enabled; |
3f37b696 | 3702 | bpt->disposition = disposition; |
bd5635a1 | 3703 | check_duplicates (bpt->address); |
6c803036 | 3704 | breakpoints_changed (); |
11054881 KH |
3705 | |
3706 | if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint || | |
3707 | bpt->type == bp_read_watchpoint || bpt->type == bp_access_watchpoint) | |
3708 | { | |
3709 | if (bpt->exp_valid_block != NULL) | |
3710 | { | |
706dc3ce JL |
3711 | struct frame_info *fr = |
3712 | find_frame_addr_in_frame_chain (bpt->watchpoint_frame); | |
11054881 KH |
3713 | if (fr == NULL) |
3714 | { | |
3715 | printf_filtered ("\ | |
3716 | Cannot enable watchpoint %d because the block in which its expression\n\ | |
3717 | is valid is not currently in scope.\n", bpt->number); | |
3718 | bpt->enable = disabled; | |
3719 | return; | |
3720 | } | |
3721 | ||
3722 | save_selected_frame = selected_frame; | |
3723 | save_selected_frame_level = selected_frame_level; | |
3724 | select_frame (fr, -1); | |
3725 | } | |
3726 | ||
3727 | value_free (bpt->val); | |
3728 | mark = value_mark (); | |
3729 | bpt->val = evaluate_expression (bpt->exp); | |
3730 | release_value (bpt->val); | |
3731 | if (VALUE_LAZY (bpt->val)) | |
3732 | value_fetch_lazy (bpt->val); | |
3733 | ||
3734 | if (bpt->type == bp_hardware_watchpoint || | |
3735 | bpt->type == bp_read_watchpoint || | |
3736 | bpt->type == bp_access_watchpoint) | |
3737 | { | |
3738 | int i = hw_watchpoint_used_count (bpt->type, &other_type_used); | |
3f37b696 FF |
3739 | int mem_cnt = can_use_hardware_watchpoint (bpt->val); |
3740 | ||
11054881 | 3741 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( |
3f37b696 | 3742 | bpt->type, i + mem_cnt, other_type_used); |
11054881 KH |
3743 | /* we can consider of type is bp_hardware_watchpoint, convert to |
3744 | bp_watchpoint in the following condition */ | |
3745 | if (target_resources_ok < 0) | |
3746 | { | |
3747 | printf_filtered("\ | |
3748 | Cannot enable watchpoint %d because target watch resources\n\ | |
3749 | have been allocated for other watchpoints.\n", bpt->number); | |
3f37b696 FF |
3750 | bpt->enable = disabled; |
3751 | value_free_to_mark (mark); | |
3752 | return; | |
11054881 KH |
3753 | } |
3754 | } | |
3755 | ||
3756 | if (save_selected_frame_level >= 0) | |
3757 | select_frame (save_selected_frame, save_selected_frame_level); | |
3758 | value_free_to_mark (mark); | |
3759 | } | |
3f37b696 FF |
3760 | if (modify_breakpoint_hook) |
3761 | modify_breakpoint_hook (bpt); | |
3762 | } | |
3763 | ||
3764 | void | |
3765 | enable_breakpoint (bpt) | |
3766 | struct breakpoint *bpt; | |
3767 | { | |
3768 | do_enable_breakpoint (bpt, donttouch); | |
3769 | } | |
3770 | ||
3771 | /* The enable command enables the specified breakpoints (or all defined | |
3772 | breakpoints) so they once again become (or continue to be) effective | |
3773 | in stopping the inferior. */ | |
3774 | ||
3775 | /* ARGSUSED */ | |
3776 | static void | |
3777 | enable_command (args, from_tty) | |
3778 | char *args; | |
3779 | int from_tty; | |
3780 | { | |
3781 | register struct breakpoint *bpt; | |
3782 | if (args == 0) | |
3783 | ALL_BREAKPOINTS (bpt) | |
3784 | switch (bpt->type) | |
3785 | { | |
3786 | case bp_breakpoint: | |
3787 | case bp_hardware_breakpoint: | |
3788 | case bp_watchpoint: | |
3789 | case bp_hardware_watchpoint: | |
3790 | case bp_read_watchpoint: | |
3791 | case bp_access_watchpoint: | |
3792 | enable_breakpoint (bpt); | |
3793 | default: | |
3794 | continue; | |
3795 | } | |
3796 | else | |
3797 | map_breakpoint_numbers (args, enable_breakpoint); | |
3798 | } | |
3799 | ||
3800 | static void | |
3801 | enable_once_breakpoint (bpt) | |
3802 | struct breakpoint *bpt; | |
3803 | { | |
3804 | do_enable_breakpoint (bpt, disable); | |
bd5635a1 RP |
3805 | } |
3806 | ||
bdbd5f50 | 3807 | /* ARGSUSED */ |
bd5635a1 RP |
3808 | static void |
3809 | enable_once_command (args, from_tty) | |
3810 | char *args; | |
3811 | int from_tty; | |
3812 | { | |
3813 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
3814 | } | |
3815 | ||
3816 | static void | |
3817 | enable_delete_breakpoint (bpt) | |
3818 | struct breakpoint *bpt; | |
3819 | { | |
3f37b696 | 3820 | do_enable_breakpoint (bpt, del); |
bd5635a1 RP |
3821 | } |
3822 | ||
bdbd5f50 | 3823 | /* ARGSUSED */ |
bd5635a1 RP |
3824 | static void |
3825 | enable_delete_command (args, from_tty) | |
3826 | char *args; | |
3827 | int from_tty; | |
3828 | { | |
3829 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
3830 | } | |
3831 | \f | |
706dc3ce JL |
3832 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
3833 | ||
bd5635a1 RP |
3834 | struct symtabs_and_lines |
3835 | decode_line_spec_1 (string, funfirstline) | |
3836 | char *string; | |
3837 | int funfirstline; | |
3838 | { | |
3839 | struct symtabs_and_lines sals; | |
3840 | if (string == 0) | |
3841 | error ("Empty line specification."); | |
3842 | if (default_breakpoint_valid) | |
3843 | sals = decode_line_1 (&string, funfirstline, | |
d889f6b7 JK |
3844 | default_breakpoint_symtab, default_breakpoint_line, |
3845 | (char ***)NULL); | |
bd5635a1 | 3846 | else |
d889f6b7 JK |
3847 | sals = decode_line_1 (&string, funfirstline, |
3848 | (struct symtab *)NULL, 0, (char ***)NULL); | |
bd5635a1 RP |
3849 | if (*string) |
3850 | error ("Junk at end of line specification: %s", string); | |
3851 | return sals; | |
3852 | } | |
3853 | \f | |
bd5635a1 RP |
3854 | void |
3855 | _initialize_breakpoint () | |
3856 | { | |
3857 | breakpoint_chain = 0; | |
3858 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
3859 | before a breakpoint is set. */ | |
3860 | breakpoint_count = 0; | |
3861 | ||
3862 | add_com ("ignore", class_breakpoint, ignore_command, | |
557f3a0e SS |
3863 | "Set ignore-count of breakpoint number N to COUNT.\n\ |
3864 | Usage is `ignore N COUNT'."); | |
bd5635a1 RP |
3865 | |
3866 | add_com ("commands", class_breakpoint, commands_command, | |
3867 | "Set commands to be executed when a breakpoint is hit.\n\ | |
3868 | Give breakpoint number as argument after \"commands\".\n\ | |
3869 | With no argument, the targeted breakpoint is the last one set.\n\ | |
3870 | The commands themselves follow starting on the next line.\n\ | |
3871 | Type a line containing \"end\" to indicate the end of them.\n\ | |
3872 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
3873 | then no output is printed when it is hit, except what the commands print."); | |
3874 | ||
3875 | add_com ("condition", class_breakpoint, condition_command, | |
3876 | "Specify breakpoint number N to break only if COND is true.\n\ | |
557f3a0e SS |
3877 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
3878 | expression to be evaluated whenever breakpoint N is reached. "); | |
bd5635a1 RP |
3879 | |
3880 | add_com ("tbreak", class_breakpoint, tbreak_command, | |
3881 | "Set a temporary breakpoint. Args like \"break\" command.\n\ | |
c4de6b30 JK |
3882 | Like \"break\" except the breakpoint is only temporary,\n\ |
3883 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
3884 | by using \"enable delete\" on the breakpoint number."); | |
bd5635a1 | 3885 | |
11054881 KH |
3886 | add_com ("hbreak", class_breakpoint, hbreak_command, |
3887 | "Set a hardware assisted breakpoint. Args like \"break\" command.\n\ | |
3888 | Like \"break\" except the breakpoint requires hardware support,\n\ | |
3889 | some target hardware may not have this support."); | |
3890 | ||
3891 | add_com ("thbreak", class_breakpoint, thbreak_command, | |
3892 | "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\ | |
3893 | Like \"hbreak\" except the breakpoint is only temporary,\n\ | |
3894 | so it will be deleted when hit."); | |
3895 | ||
bd5635a1 RP |
3896 | add_prefix_cmd ("enable", class_breakpoint, enable_command, |
3897 | "Enable some breakpoints.\n\ | |
3898 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
3899 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
3900 | This is used to cancel the effect of the \"disable\" command.\n\ | |
3901 | With a subcommand you can enable temporarily.", | |
3902 | &enablelist, "enable ", 1, &cmdlist); | |
3903 | ||
3904 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, | |
3905 | "Enable some breakpoints.\n\ | |
3906 | Give breakpoint numbers (separated by spaces) as arguments.\n\ | |
3907 | This is used to cancel the effect of the \"disable\" command.\n\ | |
3908 | May be abbreviated to simply \"enable\".\n", | |
3909 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); | |
3910 | ||
3911 | add_cmd ("once", no_class, enable_once_command, | |
3912 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
bd2f0c85 | 3913 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", |
bd5635a1 RP |
3914 | &enablebreaklist); |
3915 | ||
3916 | add_cmd ("delete", no_class, enable_delete_command, | |
3917 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
3918 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
3919 | &enablebreaklist); | |
3920 | ||
3921 | add_cmd ("delete", no_class, enable_delete_command, | |
3922 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
3923 | If a breakpoint is hit while enabled in this fashion, it is deleted.", | |
3924 | &enablelist); | |
3925 | ||
3926 | add_cmd ("once", no_class, enable_once_command, | |
3927 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
bd2f0c85 | 3928 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", |
bd5635a1 RP |
3929 | &enablelist); |
3930 | ||
3931 | add_prefix_cmd ("disable", class_breakpoint, disable_command, | |
3932 | "Disable some breakpoints.\n\ | |
3933 | Arguments are breakpoint numbers with spaces in between.\n\ | |
3934 | To disable all breakpoints, give no argument.\n\ | |
3935 | A disabled breakpoint is not forgotten, but has no effect until reenabled.", | |
3936 | &disablelist, "disable ", 1, &cmdlist); | |
3937 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
3938 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
3939 | ||
3940 | add_cmd ("breakpoints", class_alias, disable_command, | |
3941 | "Disable some breakpoints.\n\ | |
3942 | Arguments are breakpoint numbers with spaces in between.\n\ | |
3943 | To disable all breakpoints, give no argument.\n\ | |
3944 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
3945 | This command may be abbreviated \"disable\".", | |
3946 | &disablelist); | |
3947 | ||
3948 | add_prefix_cmd ("delete", class_breakpoint, delete_command, | |
3949 | "Delete some breakpoints or auto-display expressions.\n\ | |
3950 | Arguments are breakpoint numbers with spaces in between.\n\ | |
3951 | To delete all breakpoints, give no argument.\n\ | |
3952 | \n\ | |
3953 | Also a prefix command for deletion of other GDB objects.\n\ | |
3954 | The \"unset\" command is also an alias for \"delete\".", | |
3955 | &deletelist, "delete ", 1, &cmdlist); | |
3956 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
bd5635a1 RP |
3957 | |
3958 | add_cmd ("breakpoints", class_alias, delete_command, | |
3959 | "Delete some breakpoints or auto-display expressions.\n\ | |
3960 | Arguments are breakpoint numbers with spaces in between.\n\ | |
3961 | To delete all breakpoints, give no argument.\n\ | |
3962 | This command may be abbreviated \"delete\".", | |
3963 | &deletelist); | |
3964 | ||
3965 | add_com ("clear", class_breakpoint, clear_command, | |
706dc3ce | 3966 | concat ("Clear breakpoint at specified line or function.\n\ |
bd5635a1 RP |
3967 | Argument may be line number, function name, or \"*\" and an address.\n\ |
3968 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
3969 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
706dc3ce JL |
3970 | If an address is specified, breakpoints at that address are cleared.\n\n", |
3971 | "With no argument, clears all breakpoints in the line that the selected frame\n\ | |
bd5635a1 RP |
3972 | is executing in.\n\ |
3973 | \n\ | |
706dc3ce | 3974 | See also the \"delete\" command which clears breakpoints by number.", NULL)); |
bd5635a1 RP |
3975 | |
3976 | add_com ("break", class_breakpoint, break_command, | |
706dc3ce | 3977 | concat ("Set breakpoint at specified line or function.\n\ |
bd5635a1 RP |
3978 | Argument may be line number, function name, or \"*\" and an address.\n\ |
3979 | If line number is specified, break at start of code for that line.\n\ | |
3980 | If function is specified, break at start of code for that function.\n\ | |
706dc3ce JL |
3981 | If an address is specified, break at that exact address.\n", |
3982 | "With no arg, uses current execution address of selected stack frame.\n\ | |
bd5635a1 RP |
3983 | This is useful for breaking on return to a stack frame.\n\ |
3984 | \n\ | |
3985 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
3986 | \n\ | |
706dc3ce | 3987 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)); |
bd5635a1 RP |
3988 | add_com_alias ("b", "break", class_run, 1); |
3989 | add_com_alias ("br", "break", class_run, 1); | |
3990 | add_com_alias ("bre", "break", class_run, 1); | |
3991 | add_com_alias ("brea", "break", class_run, 1); | |
3992 | ||
3993 | add_info ("breakpoints", breakpoints_info, | |
706dc3ce | 3994 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
80ba48f5 | 3995 | The \"Type\" column indicates one of:\n\ |
423e9664 SG |
3996 | \tbreakpoint - normal breakpoint\n\ |
3997 | \twatchpoint - watchpoint\n\ | |
80ba48f5 SG |
3998 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
3999 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
4000 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
706dc3ce JL |
4001 | address and file/line number respectively.\n\n", |
4002 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
80ba48f5 SG |
4003 | are set to the address of the last breakpoint listed.\n\n\ |
4004 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
706dc3ce | 4005 | breakpoint set.", NULL)); |
80ba48f5 | 4006 | |
9b280a7f JG |
4007 | #if MAINTENANCE_CMDS |
4008 | ||
4009 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, | |
706dc3ce | 4010 | concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\ |
80ba48f5 | 4011 | The \"Type\" column indicates one of:\n\ |
423e9664 SG |
4012 | \tbreakpoint - normal breakpoint\n\ |
4013 | \twatchpoint - watchpoint\n\ | |
4014 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
4015 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
4016 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
706dc3ce JL |
4017 | \tfinish - internal breakpoint used by the \"finish\" command\n", |
4018 | "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
80ba48f5 SG |
4019 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
4020 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
706dc3ce JL |
4021 | address and file/line number respectively.\n\n", |
4022 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
bd5635a1 RP |
4023 | are set to the address of the last breakpoint listed.\n\n\ |
4024 | Convenience variable \"$bpnum\" contains the number of the last\n\ | |
706dc3ce | 4025 | breakpoint set.", NULL), |
9b280a7f JG |
4026 | &maintenanceinfolist); |
4027 | ||
4028 | #endif /* MAINTENANCE_CMDS */ | |
bd5635a1 RP |
4029 | |
4030 | add_com ("catch", class_breakpoint, catch_command, | |
4031 | "Set breakpoints to catch exceptions that are raised.\n\ | |
4032 | Argument may be a single exception to catch, multiple exceptions\n\ | |
4033 | to catch, or the default exception \"default\". If no arguments\n\ | |
4034 | are given, breakpoints are set at all exception handlers catch clauses\n\ | |
4035 | within the current scope.\n\ | |
4036 | \n\ | |
4037 | A condition specified for the catch applies to all breakpoints set\n\ | |
4038 | with this command\n\ | |
4039 | \n\ | |
4040 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); | |
4041 | ||
4042 | add_com ("watch", class_breakpoint, watch_command, | |
4043 | "Set a watchpoint for an expression.\n\ | |
4044 | A watchpoint stops execution of your program whenever the value of\n\ | |
4045 | an expression changes."); | |
4046 | ||
11054881 KH |
4047 | add_com ("rwatch", class_breakpoint, rwatch_command, |
4048 | "Set a read watchpoint for an expression.\n\ | |
4049 | A watchpoint stops execution of your program whenever the value of\n\ | |
4050 | an expression is read."); | |
4051 | ||
4052 | add_com ("awatch", class_breakpoint, awatch_command, | |
4053 | "Set a watchpoint for an expression.\n\ | |
4054 | A watchpoint stops execution of your program whenever the value of\n\ | |
4055 | an expression is either read or written."); | |
4056 | ||
c8950965 JG |
4057 | add_info ("watchpoints", breakpoints_info, |
4058 | "Synonym for ``info breakpoints''."); | |
9f577285 | 4059 | |
bd5635a1 | 4060 | } |