* blockframe.c (inside_main_func): No longer use symbol_lookup()
[deliverable/binutils-gdb.git] / gdb / breakpoint.c
1 /* Everything about breakpoints, for GDB.
2
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Free Software
5 Foundation, Inc.
6
7 This file is part of GDB.
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
23
24 #include "defs.h"
25 #include <ctype.h>
26 #include "symtab.h"
27 #include "frame.h"
28 #include "breakpoint.h"
29 #include "gdbtypes.h"
30 #include "expression.h"
31 #include "gdbcore.h"
32 #include "gdbcmd.h"
33 #include "value.h"
34 #include "command.h"
35 #include "inferior.h"
36 #include "gdbthread.h"
37 #include "target.h"
38 #include "language.h"
39 #include "gdb_string.h"
40 #include "demangle.h"
41 #include "annotate.h"
42 #include "symfile.h"
43 #include "objfiles.h"
44 #include "source.h"
45 #include "linespec.h"
46 #include "completer.h"
47 #include "gdb.h"
48 #include "ui-out.h"
49 #include "cli/cli-script.h"
50 #include "gdb_assert.h"
51 #include "block.h"
52
53 #include "gdb-events.h"
54
55 /* Prototypes for local functions. */
56
57 static void until_break_command_continuation (struct continuation_arg *arg);
58
59 static void catch_command_1 (char *, int, int);
60
61 static void enable_delete_command (char *, int);
62
63 static void enable_delete_breakpoint (struct breakpoint *);
64
65 static void enable_once_command (char *, int);
66
67 static void enable_once_breakpoint (struct breakpoint *);
68
69 static void disable_command (char *, int);
70
71 static void enable_command (char *, int);
72
73 static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *));
74
75 static void ignore_command (char *, int);
76
77 static int breakpoint_re_set_one (void *);
78
79 static void clear_command (char *, int);
80
81 static void catch_command (char *, int);
82
83 static void watch_command (char *, int);
84
85 static int can_use_hardware_watchpoint (struct value *);
86
87 extern void break_at_finish_command (char *, int);
88 extern void break_at_finish_at_depth_command (char *, int);
89
90 extern void tbreak_at_finish_command (char *, int);
91
92 static void break_command_1 (char *, int, int);
93
94 static void mention (struct breakpoint *);
95
96 struct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype);
97
98 static void check_duplicates (struct breakpoint *);
99
100 static void describe_other_breakpoints (CORE_ADDR, asection *);
101
102 static void breakpoints_info (char *, int);
103
104 static void breakpoint_1 (int, int);
105
106 static bpstat bpstat_alloc (struct breakpoint *, bpstat);
107
108 static int breakpoint_cond_eval (void *);
109
110 static void cleanup_executing_breakpoints (void *);
111
112 static void commands_command (char *, int);
113
114 static void condition_command (char *, int);
115
116 static int get_number_trailer (char **, int);
117
118 void set_breakpoint_count (int);
119
120 typedef enum
121 {
122 mark_inserted,
123 mark_uninserted
124 }
125 insertion_state_t;
126
127 static int remove_breakpoint (struct breakpoint *, insertion_state_t);
128
129 static enum print_stop_action print_it_typical (bpstat);
130
131 static enum print_stop_action print_bp_stop_message (bpstat bs);
132
133 typedef struct
134 {
135 enum exception_event_kind kind;
136 int enable_p;
137 }
138 args_for_catchpoint_enable;
139
140 static int watchpoint_check (void *);
141
142 static int cover_target_enable_exception_callback (void *);
143
144 static void maintenance_info_breakpoints (char *, int);
145
146 static void create_longjmp_breakpoint (char *);
147
148 static void create_overlay_event_breakpoint (char *);
149
150 static int hw_breakpoint_used_count (void);
151
152 static int hw_watchpoint_used_count (enum bptype, int *);
153
154 static void hbreak_command (char *, int);
155
156 static void thbreak_command (char *, int);
157
158 static void watch_command_1 (char *, int, int);
159
160 static void rwatch_command (char *, int);
161
162 static void awatch_command (char *, int);
163
164 static void do_enable_breakpoint (struct breakpoint *, enum bpdisp);
165
166 static void solib_load_unload_1 (char *hookname,
167 int tempflag,
168 char *dll_pathname,
169 char *cond_string, enum bptype bp_kind);
170
171 static void create_fork_vfork_event_catchpoint (int tempflag,
172 char *cond_string,
173 enum bptype bp_kind);
174
175 static void break_at_finish_at_depth_command_1 (char *arg,
176 int flag, int from_tty);
177
178 static void break_at_finish_command_1 (char *arg, int flag, int from_tty);
179
180 static void stop_command (char *arg, int from_tty);
181
182 static void stopin_command (char *arg, int from_tty);
183
184 static void stopat_command (char *arg, int from_tty);
185
186 static char *ep_find_event_name_end (char *arg);
187
188 static char *ep_parse_optional_if_clause (char **arg);
189
190 static char *ep_parse_optional_filename (char **arg);
191
192 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
193 static void catch_exec_command_1 (char *arg, int tempflag, int from_tty);
194 #endif
195
196 static void create_exception_catchpoint (int tempflag, char *cond_string,
197 enum exception_event_kind ex_event,
198 struct symtab_and_line *sal);
199
200 static void catch_exception_command_1 (enum exception_event_kind ex_event,
201 char *arg, int tempflag, int from_tty);
202
203 static void tcatch_command (char *arg, int from_tty);
204
205 static void ep_skip_leading_whitespace (char **s);
206
207 /* Prototypes for exported functions. */
208
209 /* If FALSE, gdb will not use hardware support for watchpoints, even
210 if such is available. */
211 static int can_use_hw_watchpoints;
212
213 void _initialize_breakpoint (void);
214
215 extern int addressprint; /* Print machine addresses? */
216
217 /* Are we executing breakpoint commands? */
218 static int executing_breakpoint_commands;
219
220 /* Are overlay event breakpoints enabled? */
221 static int overlay_events_enabled;
222
223 /* Walk the following statement or block through all breakpoints.
224 ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current
225 breakpoint. */
226
227 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next)
228
229 #define ALL_BREAKPOINTS_SAFE(B,TMP) \
230 for (B = breakpoint_chain; \
231 B ? (TMP=B->next, 1): 0; \
232 B = TMP)
233
234 /* True if SHIFT_INST_REGS defined, false otherwise. */
235
236 int must_shift_inst_regs =
237 #if defined(SHIFT_INST_REGS)
238 1
239 #else
240 0
241 #endif
242 ;
243
244 /* True if breakpoint hit counts should be displayed in breakpoint info. */
245
246 int show_breakpoint_hit_counts = 1;
247
248 /* Chain of all breakpoints defined. */
249
250 struct breakpoint *breakpoint_chain;
251
252 /* Number of last breakpoint made. */
253
254 int breakpoint_count;
255
256 /* Pointer to current exception event record */
257 static struct exception_event_record *current_exception_event;
258
259 /* Indicator of whether exception catchpoints should be nuked
260 between runs of a program */
261 int exception_catchpoints_are_fragile = 0;
262
263 /* Indicator of when exception catchpoints set-up should be
264 reinitialized -- e.g. when program is re-run */
265 int exception_support_initialized = 0;
266
267 /* This function returns a pointer to the string representation of the
268 pathname of the dynamically-linked library that has just been
269 loaded.
270
271 This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE,
272 or undefined results are guaranteed.
273
274 This string's contents are only valid immediately after the
275 inferior has stopped in the dynamic linker hook, and becomes
276 invalid as soon as the inferior is continued. Clients should make
277 a copy of this string if they wish to continue the inferior and
278 then access the string. */
279
280 #ifndef SOLIB_LOADED_LIBRARY_PATHNAME
281 #define SOLIB_LOADED_LIBRARY_PATHNAME(pid) ""
282 #endif
283
284 /* This function returns a pointer to the string representation of the
285 pathname of the dynamically-linked library that has just been
286 unloaded.
287
288 This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is
289 TRUE, or undefined results are guaranteed.
290
291 This string's contents are only valid immediately after the
292 inferior has stopped in the dynamic linker hook, and becomes
293 invalid as soon as the inferior is continued. Clients should make
294 a copy of this string if they wish to continue the inferior and
295 then access the string. */
296
297 #ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME
298 #define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) ""
299 #endif
300
301 /* This function is called by the "catch load" command. It allows the
302 debugger to be notified by the dynamic linker when a specified
303 library file (or any library file, if filename is NULL) is loaded. */
304
305 #ifndef SOLIB_CREATE_CATCH_LOAD_HOOK
306 #define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \
307 error ("catch of library loads not yet implemented on this platform")
308 #endif
309
310 /* This function is called by the "catch unload" command. It allows
311 the debugger to be notified by the dynamic linker when a specified
312 library file (or any library file, if filename is NULL) is
313 unloaded. */
314
315 #ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK
316 #define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \
317 error ("catch of library unloads not yet implemented on this platform")
318 #endif
319
320 /* Set breakpoint count to NUM. */
321
322 void
323 set_breakpoint_count (int num)
324 {
325 breakpoint_count = num;
326 set_internalvar (lookup_internalvar ("bpnum"),
327 value_from_longest (builtin_type_int, (LONGEST) num));
328 }
329
330 /* Used in run_command to zero the hit count when a new run starts. */
331
332 void
333 clear_breakpoint_hit_counts (void)
334 {
335 struct breakpoint *b;
336
337 ALL_BREAKPOINTS (b)
338 b->hit_count = 0;
339 }
340
341 /* Default address, symtab and line to put a breakpoint at
342 for "break" command with no arg.
343 if default_breakpoint_valid is zero, the other three are
344 not valid, and "break" with no arg is an error.
345
346 This set by print_stack_frame, which calls set_default_breakpoint. */
347
348 int default_breakpoint_valid;
349 CORE_ADDR default_breakpoint_address;
350 struct symtab *default_breakpoint_symtab;
351 int default_breakpoint_line;
352 \f
353 /* *PP is a string denoting a breakpoint. Get the number of the breakpoint.
354 Advance *PP after the string and any trailing whitespace.
355
356 Currently the string can either be a number or "$" followed by the name
357 of a convenience variable. Making it an expression wouldn't work well
358 for map_breakpoint_numbers (e.g. "4 + 5 + 6").
359
360 TRAILER is a character which can be found after the number; most
361 commonly this is `-'. If you don't want a trailer, use \0. */
362 static int
363 get_number_trailer (char **pp, int trailer)
364 {
365 int retval = 0; /* default */
366 char *p = *pp;
367
368 if (p == NULL)
369 /* Empty line means refer to the last breakpoint. */
370 return breakpoint_count;
371 else if (*p == '$')
372 {
373 /* Make a copy of the name, so we can null-terminate it
374 to pass to lookup_internalvar(). */
375 char *varname;
376 char *start = ++p;
377 struct value *val;
378
379 while (isalnum (*p) || *p == '_')
380 p++;
381 varname = (char *) alloca (p - start + 1);
382 strncpy (varname, start, p - start);
383 varname[p - start] = '\0';
384 val = value_of_internalvar (lookup_internalvar (varname));
385 if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT)
386 retval = (int) value_as_long (val);
387 else
388 {
389 printf_filtered ("Convenience variable must have integer value.\n");
390 retval = 0;
391 }
392 }
393 else
394 {
395 if (*p == '-')
396 ++p;
397 while (*p >= '0' && *p <= '9')
398 ++p;
399 if (p == *pp)
400 /* There is no number here. (e.g. "cond a == b"). */
401 {
402 /* Skip non-numeric token */
403 while (*p && !isspace((int) *p))
404 ++p;
405 /* Return zero, which caller must interpret as error. */
406 retval = 0;
407 }
408 else
409 retval = atoi (*pp);
410 }
411 if (!(isspace (*p) || *p == '\0' || *p == trailer))
412 {
413 /* Trailing junk: return 0 and let caller print error msg. */
414 while (!(isspace (*p) || *p == '\0' || *p == trailer))
415 ++p;
416 retval = 0;
417 }
418 while (isspace (*p))
419 p++;
420 *pp = p;
421 return retval;
422 }
423
424
425 /* Like get_number_trailer, but don't allow a trailer. */
426 int
427 get_number (char **pp)
428 {
429 return get_number_trailer (pp, '\0');
430 }
431
432 /* Parse a number or a range.
433 * A number will be of the form handled by get_number.
434 * A range will be of the form <number1> - <number2>, and
435 * will represent all the integers between number1 and number2,
436 * inclusive.
437 *
438 * While processing a range, this fuction is called iteratively;
439 * At each call it will return the next value in the range.
440 *
441 * At the beginning of parsing a range, the char pointer PP will
442 * be advanced past <number1> and left pointing at the '-' token.
443 * Subsequent calls will not advance the pointer until the range
444 * is completed. The call that completes the range will advance
445 * pointer PP past <number2>.
446 */
447
448 int
449 get_number_or_range (char **pp)
450 {
451 static int last_retval, end_value;
452 static char *end_ptr;
453 static int in_range = 0;
454
455 if (**pp != '-')
456 {
457 /* Default case: pp is pointing either to a solo number,
458 or to the first number of a range. */
459 last_retval = get_number_trailer (pp, '-');
460 if (**pp == '-')
461 {
462 char **temp;
463
464 /* This is the start of a range (<number1> - <number2>).
465 Skip the '-', parse and remember the second number,
466 and also remember the end of the final token. */
467
468 temp = &end_ptr;
469 end_ptr = *pp + 1;
470 while (isspace ((int) *end_ptr))
471 end_ptr++; /* skip white space */
472 end_value = get_number (temp);
473 if (end_value < last_retval)
474 {
475 error ("inverted range");
476 }
477 else if (end_value == last_retval)
478 {
479 /* degenerate range (number1 == number2). Advance the
480 token pointer so that the range will be treated as a
481 single number. */
482 *pp = end_ptr;
483 }
484 else
485 in_range = 1;
486 }
487 }
488 else if (! in_range)
489 error ("negative value");
490 else
491 {
492 /* pp points to the '-' that betokens a range. All
493 number-parsing has already been done. Return the next
494 integer value (one greater than the saved previous value).
495 Do not advance the token pointer 'pp' until the end of range
496 is reached. */
497
498 if (++last_retval == end_value)
499 {
500 /* End of range reached; advance token pointer. */
501 *pp = end_ptr;
502 in_range = 0;
503 }
504 }
505 return last_retval;
506 }
507
508
509 \f
510 /* condition N EXP -- set break condition of breakpoint N to EXP. */
511
512 static void
513 condition_command (char *arg, int from_tty)
514 {
515 struct breakpoint *b;
516 char *p;
517 int bnum;
518
519 if (arg == 0)
520 error_no_arg ("breakpoint number");
521
522 p = arg;
523 bnum = get_number (&p);
524 if (bnum == 0)
525 error ("Bad breakpoint argument: '%s'", arg);
526
527 ALL_BREAKPOINTS (b)
528 if (b->number == bnum)
529 {
530 if (b->cond)
531 {
532 xfree (b->cond);
533 b->cond = 0;
534 }
535 if (b->cond_string != NULL)
536 xfree (b->cond_string);
537
538 if (*p == 0)
539 {
540 b->cond = 0;
541 b->cond_string = NULL;
542 if (from_tty)
543 printf_filtered ("Breakpoint %d now unconditional.\n", bnum);
544 }
545 else
546 {
547 arg = p;
548 /* I don't know if it matters whether this is the string the user
549 typed in or the decompiled expression. */
550 b->cond_string = savestring (arg, strlen (arg));
551 b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
552 if (*arg)
553 error ("Junk at end of expression");
554 }
555 breakpoints_changed ();
556 breakpoint_modify_event (b->number);
557 return;
558 }
559
560 error ("No breakpoint number %d.", bnum);
561 }
562
563 static void
564 commands_command (char *arg, int from_tty)
565 {
566 struct breakpoint *b;
567 char *p;
568 int bnum;
569 struct command_line *l;
570
571 /* If we allowed this, we would have problems with when to
572 free the storage, if we change the commands currently
573 being read from. */
574
575 if (executing_breakpoint_commands)
576 error ("Can't use the \"commands\" command among a breakpoint's commands.");
577
578 p = arg;
579 bnum = get_number (&p);
580
581 if (p && *p)
582 error ("Unexpected extra arguments following breakpoint number.");
583
584 ALL_BREAKPOINTS (b)
585 if (b->number == bnum)
586 {
587 char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.",
588 bnum);
589 struct cleanup *cleanups = make_cleanup (xfree, tmpbuf);
590 l = read_command_lines (tmpbuf, from_tty);
591 do_cleanups (cleanups);
592 free_command_lines (&b->commands);
593 b->commands = l;
594 breakpoints_changed ();
595 breakpoint_modify_event (b->number);
596 return;
597 }
598 error ("No breakpoint number %d.", bnum);
599 }
600 \f
601 /* Like target_read_memory() but if breakpoints are inserted, return
602 the shadow contents instead of the breakpoints themselves.
603
604 Read "memory data" from whatever target or inferior we have.
605 Returns zero if successful, errno value if not. EIO is used
606 for address out of bounds. If breakpoints are inserted, returns
607 shadow contents, not the breakpoints themselves. From breakpoint.c. */
608
609 int
610 read_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len)
611 {
612 int status;
613 struct breakpoint *b;
614 CORE_ADDR bp_addr = 0;
615 int bp_size = 0;
616
617 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
618 /* No breakpoints on this machine. */
619 return target_read_memory (memaddr, myaddr, len);
620
621 ALL_BREAKPOINTS (b)
622 {
623 if (b->type == bp_none)
624 warning ("reading through apparently deleted breakpoint #%d?",
625 b->number);
626
627 /* memory breakpoint? */
628 if (b->type == bp_watchpoint
629 || b->type == bp_hardware_watchpoint
630 || b->type == bp_read_watchpoint
631 || b->type == bp_access_watchpoint)
632 continue;
633 /* bp in memory? */
634 if (!b->inserted)
635 continue;
636 /* Addresses and length of the part of the breakpoint that
637 we need to copy. */
638 /* XXXX The m68k, sh and h8300 have different local and remote
639 breakpoint values. BREAKPOINT_FROM_PC still manages to
640 correctly determine the breakpoints memory address and size
641 for these targets. */
642 bp_addr = b->address;
643 bp_size = 0;
644 if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL)
645 continue;
646 if (bp_size == 0)
647 /* bp isn't valid */
648 continue;
649 if (bp_addr + bp_size <= memaddr)
650 /* The breakpoint is entirely before the chunk of memory we
651 are reading. */
652 continue;
653 if (bp_addr >= memaddr + len)
654 /* The breakpoint is entirely after the chunk of memory we are
655 reading. */
656 continue;
657 /* Copy the breakpoint from the shadow contents, and recurse for
658 the things before and after. */
659 {
660 /* Offset within shadow_contents. */
661 int bptoffset = 0;
662
663 if (bp_addr < memaddr)
664 {
665 /* Only copy the second part of the breakpoint. */
666 bp_size -= memaddr - bp_addr;
667 bptoffset = memaddr - bp_addr;
668 bp_addr = memaddr;
669 }
670
671 if (bp_addr + bp_size > memaddr + len)
672 {
673 /* Only copy the first part of the breakpoint. */
674 bp_size -= (bp_addr + bp_size) - (memaddr + len);
675 }
676
677 memcpy (myaddr + bp_addr - memaddr,
678 b->shadow_contents + bptoffset, bp_size);
679
680 if (bp_addr > memaddr)
681 {
682 /* Copy the section of memory before the breakpoint. */
683 status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr);
684 if (status != 0)
685 return status;
686 }
687
688 if (bp_addr + bp_size < memaddr + len)
689 {
690 /* Copy the section of memory after the breakpoint. */
691 status = read_memory_nobpt (bp_addr + bp_size,
692 myaddr + bp_addr + bp_size - memaddr,
693 memaddr + len - (bp_addr + bp_size));
694 if (status != 0)
695 return status;
696 }
697 return 0;
698 }
699 }
700 /* Nothing overlaps. Just call read_memory_noerr. */
701 return target_read_memory (memaddr, myaddr, len);
702 }
703 \f
704
705 /* A wrapper function for inserting catchpoints. */
706 static int
707 insert_catchpoint (struct ui_out *uo, void *args)
708 {
709 struct breakpoint *b = (struct breakpoint *) args;
710 int val = -1;
711
712 switch (b->type)
713 {
714 case bp_catch_fork:
715 val = target_insert_fork_catchpoint (PIDGET (inferior_ptid));
716 break;
717 case bp_catch_vfork:
718 val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid));
719 break;
720 case bp_catch_exec:
721 val = target_insert_exec_catchpoint (PIDGET (inferior_ptid));
722 break;
723 default:
724 internal_error (__FILE__, __LINE__, "unknown breakpoint type");
725 break;
726 }
727
728 if (val < 0)
729 throw_exception (RETURN_ERROR);
730
731 return 0;
732 }
733
734 /* insert_breakpoints is used when starting or continuing the program.
735 remove_breakpoints is used when the program stops.
736 Both return zero if successful,
737 or an `errno' value if could not write the inferior. */
738
739 int
740 insert_breakpoints (void)
741 {
742 struct breakpoint *b, *temp;
743 int return_val = 0; /* return success code. */
744 int val = 0;
745 int disabled_breaks = 0;
746 int hw_breakpoint_error = 0;
747 #ifdef ONE_PROCESS_WRITETEXT
748 int process_warning = 0;
749 #endif
750
751 struct ui_file *tmp_error_stream = mem_fileopen ();
752 make_cleanup_ui_file_delete (tmp_error_stream);
753
754 /* Explicitly mark the warning -- this will only be printed if
755 there was an error. */
756 fprintf_unfiltered (tmp_error_stream, "Warning:\n");
757
758 ALL_BREAKPOINTS_SAFE (b, temp)
759 {
760 /* Permanent breakpoints cannot be inserted or removed. Disabled
761 breakpoints should not be inserted. */
762 if (b->enable_state != bp_enabled)
763 continue;
764
765 if ((b->type == bp_watchpoint
766 || b->type == bp_hardware_watchpoint
767 || b->type == bp_read_watchpoint
768 || b->type == bp_access_watchpoint) && (!b->val))
769 {
770 struct value *val;
771 val = evaluate_expression (b->exp);
772 release_value (val);
773 if (VALUE_LAZY (val))
774 value_fetch_lazy (val);
775 b->val = val;
776 }
777 if (b->type != bp_watchpoint
778 && b->type != bp_hardware_watchpoint
779 && b->type != bp_read_watchpoint
780 && b->type != bp_access_watchpoint
781 && b->type != bp_catch_fork
782 && b->type != bp_catch_vfork
783 && b->type != bp_catch_exec
784 && b->type != bp_catch_throw
785 && b->type != bp_catch_catch
786 && !b->inserted
787 && !b->duplicate)
788 {
789 /* "Normal" instruction breakpoint: either the standard
790 trap-instruction bp (bp_breakpoint), or a
791 bp_hardware_breakpoint. */
792
793 /* First check to see if we have to handle an overlay. */
794 if (overlay_debugging == ovly_off
795 || b->section == NULL
796 || !(section_is_overlay (b->section)))
797 {
798 /* No overlay handling: just set the breakpoint. */
799
800 if (b->type == bp_hardware_breakpoint)
801 val = target_insert_hw_breakpoint (b->address,
802 b->shadow_contents);
803 else
804 val = target_insert_breakpoint (b->address, b->shadow_contents);
805 }
806 else
807 {
808 /* This breakpoint is in an overlay section.
809 Shall we set a breakpoint at the LMA? */
810 if (!overlay_events_enabled)
811 {
812 /* Yes -- overlay event support is not active,
813 so we must try to set a breakpoint at the LMA.
814 This will not work for a hardware breakpoint. */
815 if (b->type == bp_hardware_breakpoint)
816 warning ("hardware breakpoint %d not supported in overlay!\n",
817 b->number);
818 else
819 {
820 CORE_ADDR addr = overlay_unmapped_address (b->address,
821 b->section);
822 /* Set a software (trap) breakpoint at the LMA. */
823 val = target_insert_breakpoint (addr, b->shadow_contents);
824 if (val != 0)
825 fprintf_unfiltered (tmp_error_stream,
826 "Overlay breakpoint %d failed: in ROM?",
827 b->number);
828 }
829 }
830 /* Shall we set a breakpoint at the VMA? */
831 if (section_is_mapped (b->section))
832 {
833 /* Yes. This overlay section is mapped into memory. */
834 if (b->type == bp_hardware_breakpoint)
835 val = target_insert_hw_breakpoint (b->address,
836 b->shadow_contents);
837 else
838 val = target_insert_breakpoint (b->address,
839 b->shadow_contents);
840 }
841 else
842 {
843 /* No. This breakpoint will not be inserted.
844 No error, but do not mark the bp as 'inserted'. */
845 continue;
846 }
847 }
848
849 if (val)
850 {
851 /* Can't set the breakpoint. */
852 #if defined (DISABLE_UNSETTABLE_BREAK)
853 if (DISABLE_UNSETTABLE_BREAK (b->address))
854 {
855 /* See also: disable_breakpoints_in_shlibs. */
856 val = 0;
857 b->enable_state = bp_shlib_disabled;
858 if (!disabled_breaks)
859 {
860 fprintf_unfiltered (tmp_error_stream,
861 "Cannot insert breakpoint %d.\n",
862 b->number);
863 fprintf_unfiltered (tmp_error_stream,
864 "Temporarily disabling shared library breakpoints:\n");
865 }
866 disabled_breaks = 1;
867 fprintf_unfiltered (tmp_error_stream,
868 "breakpoint #%d\n", b->number);
869 }
870 else
871 #endif
872 {
873 #ifdef ONE_PROCESS_WRITETEXT
874 process_warning = 1;
875 #endif
876 if (b->type == bp_hardware_breakpoint)
877 {
878 hw_breakpoint_error = 1;
879 fprintf_unfiltered (tmp_error_stream,
880 "Cannot insert hardware breakpoint %d.\n",
881 b->number);
882 }
883 else
884 {
885 fprintf_unfiltered (tmp_error_stream,
886 "Cannot insert breakpoint %d.\n",
887 b->number);
888 fprintf_filtered (tmp_error_stream,
889 "Error accessing memory address ");
890 print_address_numeric (b->address, 1, tmp_error_stream);
891 fprintf_filtered (tmp_error_stream, ": %s.\n",
892 safe_strerror (val));
893 }
894
895 }
896 }
897 else
898 b->inserted = 1;
899
900 if (val)
901 return_val = val; /* remember failure */
902 }
903 else if (ep_is_exception_catchpoint (b)
904 && !b->inserted
905 && !b->duplicate)
906
907 {
908 /* If we get here, we must have a callback mechanism for exception
909 events -- with g++ style embedded label support, we insert
910 ordinary breakpoints and not catchpoints. */
911 val = target_insert_breakpoint (b->address, b->shadow_contents);
912 if (val)
913 {
914 /* Couldn't set breakpoint for some reason */
915 fprintf_unfiltered (tmp_error_stream,
916 "Cannot insert catchpoint %d; disabling it.\n",
917 b->number);
918 fprintf_filtered (tmp_error_stream,
919 "Error accessing memory address ");
920 print_address_numeric (b->address, 1, tmp_error_stream);
921 fprintf_filtered (tmp_error_stream, ": %s.\n",
922 safe_strerror (val));
923 b->enable_state = bp_disabled;
924 }
925 else
926 {
927 /* Bp set, now make sure callbacks are enabled */
928 /* Format possible error msg */
929 char *message = xstrprintf ("Error inserting catchpoint %d:\n",
930 b->number);
931 struct cleanup *cleanups = make_cleanup (xfree, message);
932 int val;
933 args_for_catchpoint_enable args;
934 args.kind = b->type == bp_catch_catch ?
935 EX_EVENT_CATCH : EX_EVENT_THROW;
936 args.enable_p = 1;
937 val = catch_errors (cover_target_enable_exception_callback,
938 &args, message, RETURN_MASK_ALL);
939 do_cleanups (cleanups);
940 if (val != 0 && val != -1)
941 {
942 b->inserted = 1;
943 }
944 /* Check if something went wrong; val == 0 can be ignored */
945 if (val == -1)
946 {
947 /* something went wrong */
948 fprintf_unfiltered (tmp_error_stream,
949 "Cannot insert catchpoint %d; disabling it.\n",
950 b->number);
951 b->enable_state = bp_disabled;
952 }
953 }
954
955 if (val)
956 return_val = val; /* remember failure */
957 }
958
959 else if ((b->type == bp_hardware_watchpoint ||
960 b->type == bp_read_watchpoint ||
961 b->type == bp_access_watchpoint)
962 && b->disposition != disp_del_at_next_stop
963 && !b->inserted
964 && !b->duplicate)
965 {
966 struct frame_info *saved_frame;
967 int saved_level, within_current_scope;
968 struct value *mark = value_mark ();
969 struct value *v;
970
971 /* Save the current frame and level so we can restore it after
972 evaluating the watchpoint expression on its own frame. */
973 saved_frame = deprecated_selected_frame;
974 saved_level = frame_relative_level (deprecated_selected_frame);
975
976 /* Determine if the watchpoint is within scope. */
977 if (b->exp_valid_block == NULL)
978 within_current_scope = 1;
979 else
980 {
981 struct frame_info *fi;
982 fi = frame_find_by_id (b->watchpoint_frame);
983 within_current_scope = (fi != NULL);
984 if (within_current_scope)
985 select_frame (fi);
986 }
987
988 if (within_current_scope)
989 {
990 /* Evaluate the expression and cut the chain of values
991 produced off from the value chain.
992
993 Make sure the value returned isn't lazy; we use
994 laziness to determine what memory GDB actually needed
995 in order to compute the value of the expression. */
996 v = evaluate_expression (b->exp);
997 VALUE_CONTENTS(v);
998 value_release_to_mark (mark);
999
1000 b->val_chain = v;
1001 b->inserted = 1;
1002
1003 /* Look at each value on the value chain. */
1004 for (; v; v = v->next)
1005 {
1006 /* If it's a memory location, and GDB actually needed
1007 its contents to evaluate the expression, then we
1008 must watch it. */
1009 if (VALUE_LVAL (v) == lval_memory
1010 && ! VALUE_LAZY (v))
1011 {
1012 struct type *vtype = check_typedef (VALUE_TYPE (v));
1013
1014 /* We only watch structs and arrays if user asked
1015 for it explicitly, never if they just happen to
1016 appear in the middle of some value chain. */
1017 if (v == b->val_chain
1018 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1019 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1020 {
1021 CORE_ADDR addr;
1022 int len, type;
1023
1024 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1025 len = TYPE_LENGTH (VALUE_TYPE (v));
1026 type = hw_write;
1027 if (b->type == bp_read_watchpoint)
1028 type = hw_read;
1029 else if (b->type == bp_access_watchpoint)
1030 type = hw_access;
1031
1032 val = target_insert_watchpoint (addr, len, type);
1033 if (val == -1)
1034 {
1035 /* Don't exit the loop, try to insert
1036 every value on the value chain. That's
1037 because we will be removing all the
1038 watches below, and removing a
1039 watchpoint we didn't insert could have
1040 adverse effects. */
1041 b->inserted = 0;
1042 }
1043 val = 0;
1044 }
1045 }
1046 }
1047 /* Failure to insert a watchpoint on any memory value in the
1048 value chain brings us here. */
1049 if (!b->inserted)
1050 {
1051 remove_breakpoint (b, mark_uninserted);
1052 hw_breakpoint_error = 1;
1053 fprintf_unfiltered (tmp_error_stream,
1054 "Could not insert hardware watchpoint %d.\n",
1055 b->number);
1056 val = -1;
1057 }
1058 }
1059 else
1060 {
1061 printf_filtered ("Hardware watchpoint %d deleted ", b->number);
1062 printf_filtered ("because the program has left the block \n");
1063 printf_filtered ("in which its expression is valid.\n");
1064 if (b->related_breakpoint)
1065 b->related_breakpoint->disposition = disp_del_at_next_stop;
1066 b->disposition = disp_del_at_next_stop;
1067 }
1068
1069 /* Restore the frame and level. */
1070 if ((saved_frame != deprecated_selected_frame) ||
1071 (saved_level != frame_relative_level (deprecated_selected_frame)))
1072 select_frame (saved_frame);
1073
1074 if (val)
1075 return_val = val; /* remember failure */
1076 }
1077 else if ((b->type == bp_catch_fork
1078 || b->type == bp_catch_vfork
1079 || b->type == bp_catch_exec)
1080 && !b->inserted
1081 && !b->duplicate)
1082 {
1083 char *prefix = xstrprintf ("warning: inserting catchpoint %d: ",
1084 b->number);
1085 struct cleanup *cleanups = make_cleanup (xfree, prefix);
1086 val = catch_exceptions (uiout, insert_catchpoint, b, prefix,
1087 RETURN_MASK_ERROR);
1088 do_cleanups (cleanups);
1089 if (val < 0)
1090 b->enable_state = bp_disabled;
1091 else
1092 b->inserted = 1;
1093 }
1094 }
1095
1096 if (return_val)
1097 {
1098 /* If a hardware breakpoint or watchpoint was inserted, add a
1099 message about possibly exhausted resources. */
1100 if (hw_breakpoint_error)
1101 {
1102 fprintf_unfiltered (tmp_error_stream,
1103 "Could not insert hardware breakpoints:\n\
1104 You may have requested too many hardware breakpoints/watchpoints.\n");
1105 }
1106 #ifdef ONE_PROCESS_WRITETEXT
1107 if (process_warning)
1108 fprintf_unfiltered (tmp_error_stream,
1109 "The same program may be running in another process.");
1110 #endif
1111 target_terminal_ours_for_output ();
1112 error_stream (tmp_error_stream);
1113 }
1114 return return_val;
1115 }
1116
1117 int
1118 remove_breakpoints (void)
1119 {
1120 struct breakpoint *b;
1121 int val;
1122
1123 ALL_BREAKPOINTS (b)
1124 {
1125 if (b->inserted)
1126 {
1127 val = remove_breakpoint (b, mark_uninserted);
1128 if (val != 0)
1129 return val;
1130 }
1131 }
1132 return 0;
1133 }
1134
1135 int
1136 remove_hw_watchpoints (void)
1137 {
1138 struct breakpoint *b;
1139 int val;
1140
1141 ALL_BREAKPOINTS (b)
1142 {
1143 if (b->inserted
1144 && (b->type == bp_hardware_watchpoint
1145 || b->type == bp_read_watchpoint
1146 || b->type == bp_access_watchpoint))
1147 {
1148 val = remove_breakpoint (b, mark_uninserted);
1149 if (val != 0)
1150 return val;
1151 }
1152 }
1153 return 0;
1154 }
1155
1156 int
1157 reattach_breakpoints (int pid)
1158 {
1159 struct breakpoint *b;
1160 int val;
1161 struct cleanup *old_chain = save_inferior_ptid ();
1162
1163 /* Set inferior_ptid; remove_breakpoint uses this global. */
1164 inferior_ptid = pid_to_ptid (pid);
1165 ALL_BREAKPOINTS (b)
1166 {
1167 if (b->inserted)
1168 {
1169 remove_breakpoint (b, mark_inserted);
1170 if (b->type == bp_hardware_breakpoint)
1171 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
1172 else
1173 val = target_insert_breakpoint (b->address, b->shadow_contents);
1174 if (val != 0)
1175 {
1176 do_cleanups (old_chain);
1177 return val;
1178 }
1179 }
1180 }
1181 do_cleanups (old_chain);
1182 return 0;
1183 }
1184
1185 void
1186 update_breakpoints_after_exec (void)
1187 {
1188 struct breakpoint *b;
1189 struct breakpoint *temp;
1190
1191 /* Doing this first prevents the badness of having delete_breakpoint()
1192 write a breakpoint's current "shadow contents" to lift the bp. That
1193 shadow is NOT valid after an exec()! */
1194 mark_breakpoints_out ();
1195
1196 ALL_BREAKPOINTS_SAFE (b, temp)
1197 {
1198 /* Solib breakpoints must be explicitly reset after an exec(). */
1199 if (b->type == bp_shlib_event)
1200 {
1201 delete_breakpoint (b);
1202 continue;
1203 }
1204
1205 /* Thread event breakpoints must be set anew after an exec(),
1206 as must overlay event breakpoints. */
1207 if (b->type == bp_thread_event || b->type == bp_overlay_event)
1208 {
1209 delete_breakpoint (b);
1210 continue;
1211 }
1212
1213 /* Step-resume breakpoints are meaningless after an exec(). */
1214 if (b->type == bp_step_resume)
1215 {
1216 delete_breakpoint (b);
1217 continue;
1218 }
1219
1220 /* Ditto the sigtramp handler breakpoints. */
1221 if (b->type == bp_through_sigtramp)
1222 {
1223 delete_breakpoint (b);
1224 continue;
1225 }
1226
1227 /* Ditto the exception-handling catchpoints. */
1228 if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw))
1229 {
1230 delete_breakpoint (b);
1231 continue;
1232 }
1233
1234 /* Don't delete an exec catchpoint, because else the inferior
1235 won't stop when it ought!
1236
1237 Similarly, we probably ought to keep vfork catchpoints, 'cause
1238 on this target, we may not be able to stop when the vfork is
1239 seen, but only when the subsequent exec is seen. (And because
1240 deleting fork catchpoints here but not vfork catchpoints will
1241 seem mysterious to users, keep those too.)
1242
1243 ??rehrauer: Let's hope that merely clearing out this catchpoint's
1244 target address field, if any, is sufficient to have it be reset
1245 automagically. Certainly on HP-UX that's true.
1246
1247 Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly
1248 valid code address on some platforms (like the mn10300
1249 simulators). We shouldn't assign any special interpretation to
1250 a breakpoint with a zero address. And in fact, GDB doesn't ---
1251 I can't see what that comment above is talking about. As far
1252 as I can tell, setting the address of a
1253 bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero
1254 is meaningless, since those are implemented with HP-UX kernel
1255 hackery, not by storing breakpoint instructions somewhere. */
1256 if ((b->type == bp_catch_exec) ||
1257 (b->type == bp_catch_vfork) ||
1258 (b->type == bp_catch_fork))
1259 {
1260 b->address = (CORE_ADDR) NULL;
1261 continue;
1262 }
1263
1264 /* bp_finish is a special case. The only way we ought to be able
1265 to see one of these when an exec() has happened, is if the user
1266 caught a vfork, and then said "finish". Ordinarily a finish just
1267 carries them to the call-site of the current callee, by setting
1268 a temporary bp there and resuming. But in this case, the finish
1269 will carry them entirely through the vfork & exec.
1270
1271 We don't want to allow a bp_finish to remain inserted now. But
1272 we can't safely delete it, 'cause finish_command has a handle to
1273 the bp on a bpstat, and will later want to delete it. There's a
1274 chance (and I've seen it happen) that if we delete the bp_finish
1275 here, that its storage will get reused by the time finish_command
1276 gets 'round to deleting the "use to be a bp_finish" breakpoint.
1277 We really must allow finish_command to delete a bp_finish.
1278
1279 In the absense of a general solution for the "how do we know
1280 it's safe to delete something others may have handles to?"
1281 problem, what we'll do here is just uninsert the bp_finish, and
1282 let finish_command delete it.
1283
1284 (We know the bp_finish is "doomed" in the sense that it's
1285 momentary, and will be deleted as soon as finish_command sees
1286 the inferior stopped. So it doesn't matter that the bp's
1287 address is probably bogus in the new a.out, unlike e.g., the
1288 solib breakpoints.) */
1289
1290 if (b->type == bp_finish)
1291 {
1292 continue;
1293 }
1294
1295 /* Without a symbolic address, we have little hope of the
1296 pre-exec() address meaning the same thing in the post-exec()
1297 a.out. */
1298 if (b->addr_string == NULL)
1299 {
1300 delete_breakpoint (b);
1301 continue;
1302 }
1303
1304 /* If this breakpoint has survived the above battery of checks, then
1305 it must have a symbolic address. Be sure that it gets reevaluated
1306 to a target address, rather than reusing the old evaluation.
1307
1308 Jim Blandy <jimb@redhat.com>: As explained above in the comment
1309 for bp_catch_exec and friends, I'm pretty sure this is entirely
1310 unnecessary. A call to breakpoint_re_set_one always recomputes
1311 the breakpoint's address from scratch, or deletes it if it can't.
1312 So I think this assignment could be deleted without effect. */
1313 b->address = (CORE_ADDR) NULL;
1314 }
1315 /* FIXME what about longjmp breakpoints? Re-create them here? */
1316 create_overlay_event_breakpoint ("_ovly_debug_event");
1317 }
1318
1319 int
1320 detach_breakpoints (int pid)
1321 {
1322 struct breakpoint *b;
1323 int val;
1324 struct cleanup *old_chain = save_inferior_ptid ();
1325
1326 if (pid == PIDGET (inferior_ptid))
1327 error ("Cannot detach breakpoints of inferior_ptid");
1328
1329 /* Set inferior_ptid; remove_breakpoint uses this global. */
1330 inferior_ptid = pid_to_ptid (pid);
1331 ALL_BREAKPOINTS (b)
1332 {
1333 if (b->inserted)
1334 {
1335 val = remove_breakpoint (b, mark_inserted);
1336 if (val != 0)
1337 {
1338 do_cleanups (old_chain);
1339 return val;
1340 }
1341 }
1342 }
1343 do_cleanups (old_chain);
1344 return 0;
1345 }
1346
1347 static int
1348 remove_breakpoint (struct breakpoint *b, insertion_state_t is)
1349 {
1350 int val;
1351
1352 if (b->enable_state == bp_permanent)
1353 /* Permanent breakpoints cannot be inserted or removed. */
1354 return 0;
1355
1356 if (b->type == bp_none)
1357 warning ("attempted to remove apparently deleted breakpoint #%d?",
1358 b->number);
1359
1360 if (b->type != bp_watchpoint
1361 && b->type != bp_hardware_watchpoint
1362 && b->type != bp_read_watchpoint
1363 && b->type != bp_access_watchpoint
1364 && b->type != bp_catch_fork
1365 && b->type != bp_catch_vfork
1366 && b->type != bp_catch_exec
1367 && b->type != bp_catch_catch
1368 && b->type != bp_catch_throw)
1369 {
1370 /* "Normal" instruction breakpoint: either the standard
1371 trap-instruction bp (bp_breakpoint), or a
1372 bp_hardware_breakpoint. */
1373
1374 /* First check to see if we have to handle an overlay. */
1375 if (overlay_debugging == ovly_off
1376 || b->section == NULL
1377 || !(section_is_overlay (b->section)))
1378 {
1379 /* No overlay handling: just remove the breakpoint. */
1380
1381 if (b->type == bp_hardware_breakpoint)
1382 val = target_remove_hw_breakpoint (b->address,
1383 b->shadow_contents);
1384 else
1385 val = target_remove_breakpoint (b->address, b->shadow_contents);
1386 }
1387 else
1388 {
1389 /* This breakpoint is in an overlay section.
1390 Did we set a breakpoint at the LMA? */
1391 if (!overlay_events_enabled)
1392 {
1393 /* Yes -- overlay event support is not active, so we
1394 should have set a breakpoint at the LMA. Remove it.
1395 */
1396 CORE_ADDR addr = overlay_unmapped_address (b->address,
1397 b->section);
1398 /* Ignore any failures: if the LMA is in ROM, we will
1399 have already warned when we failed to insert it. */
1400 if (b->type != bp_hardware_breakpoint)
1401 target_remove_hw_breakpoint (addr, b->shadow_contents);
1402 else
1403 target_remove_breakpoint (addr, b->shadow_contents);
1404 }
1405 /* Did we set a breakpoint at the VMA?
1406 If so, we will have marked the breakpoint 'inserted'. */
1407 if (b->inserted)
1408 {
1409 /* Yes -- remove it. Previously we did not bother to
1410 remove the breakpoint if the section had been
1411 unmapped, but let's not rely on that being safe. We
1412 don't know what the overlay manager might do. */
1413 if (b->type == bp_hardware_breakpoint)
1414 val = target_remove_hw_breakpoint (b->address,
1415 b->shadow_contents);
1416 else
1417 val = target_remove_breakpoint (b->address,
1418 b->shadow_contents);
1419 }
1420 else
1421 {
1422 /* No -- not inserted, so no need to remove. No error. */
1423 val = 0;
1424 }
1425 }
1426 if (val)
1427 return val;
1428 b->inserted = (is == mark_inserted);
1429 }
1430 else if ((b->type == bp_hardware_watchpoint ||
1431 b->type == bp_read_watchpoint ||
1432 b->type == bp_access_watchpoint)
1433 && b->enable_state == bp_enabled
1434 && !b->duplicate)
1435 {
1436 struct value *v;
1437 struct value *n;
1438
1439 b->inserted = (is == mark_inserted);
1440 /* Walk down the saved value chain. */
1441 for (v = b->val_chain; v; v = v->next)
1442 {
1443 /* For each memory reference remove the watchpoint
1444 at that address. */
1445 if (VALUE_LVAL (v) == lval_memory
1446 && ! VALUE_LAZY (v))
1447 {
1448 struct type *vtype = check_typedef (VALUE_TYPE (v));
1449
1450 if (v == b->val_chain
1451 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
1452 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
1453 {
1454 CORE_ADDR addr;
1455 int len, type;
1456
1457 addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
1458 len = TYPE_LENGTH (VALUE_TYPE (v));
1459 type = hw_write;
1460 if (b->type == bp_read_watchpoint)
1461 type = hw_read;
1462 else if (b->type == bp_access_watchpoint)
1463 type = hw_access;
1464
1465 val = target_remove_watchpoint (addr, len, type);
1466 if (val == -1)
1467 b->inserted = 1;
1468 val = 0;
1469 }
1470 }
1471 }
1472 /* Failure to remove any of the hardware watchpoints comes here. */
1473 if ((is == mark_uninserted) && (b->inserted))
1474 warning ("Could not remove hardware watchpoint %d.",
1475 b->number);
1476
1477 /* Free the saved value chain. We will construct a new one
1478 the next time the watchpoint is inserted. */
1479 for (v = b->val_chain; v; v = n)
1480 {
1481 n = v->next;
1482 value_free (v);
1483 }
1484 b->val_chain = NULL;
1485 }
1486 else if ((b->type == bp_catch_fork ||
1487 b->type == bp_catch_vfork ||
1488 b->type == bp_catch_exec)
1489 && b->enable_state == bp_enabled
1490 && !b->duplicate)
1491 {
1492 val = -1;
1493 switch (b->type)
1494 {
1495 case bp_catch_fork:
1496 val = target_remove_fork_catchpoint (PIDGET (inferior_ptid));
1497 break;
1498 case bp_catch_vfork:
1499 val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid));
1500 break;
1501 case bp_catch_exec:
1502 val = target_remove_exec_catchpoint (PIDGET (inferior_ptid));
1503 break;
1504 default:
1505 warning ("Internal error, %s line %d.", __FILE__, __LINE__);
1506 break;
1507 }
1508 if (val)
1509 return val;
1510 b->inserted = (is == mark_inserted);
1511 }
1512 else if ((b->type == bp_catch_catch ||
1513 b->type == bp_catch_throw)
1514 && b->enable_state == bp_enabled
1515 && !b->duplicate)
1516 {
1517
1518 val = target_remove_breakpoint (b->address, b->shadow_contents);
1519 if (val)
1520 return val;
1521 b->inserted = (is == mark_inserted);
1522 }
1523 else if (ep_is_exception_catchpoint (b)
1524 && b->inserted /* sometimes previous insert doesn't happen */
1525 && b->enable_state == bp_enabled
1526 && !b->duplicate)
1527 {
1528
1529 val = target_remove_breakpoint (b->address, b->shadow_contents);
1530 if (val)
1531 return val;
1532
1533 b->inserted = (is == mark_inserted);
1534 }
1535
1536 return 0;
1537 }
1538
1539 /* Clear the "inserted" flag in all breakpoints. */
1540
1541 void
1542 mark_breakpoints_out (void)
1543 {
1544 struct breakpoint *b;
1545
1546 ALL_BREAKPOINTS (b)
1547 b->inserted = 0;
1548 }
1549
1550 /* Clear the "inserted" flag in all breakpoints and delete any
1551 breakpoints which should go away between runs of the program.
1552
1553 Plus other such housekeeping that has to be done for breakpoints
1554 between runs.
1555
1556 Note: this function gets called at the end of a run (by
1557 generic_mourn_inferior) and when a run begins (by
1558 init_wait_for_inferior). */
1559
1560
1561
1562 void
1563 breakpoint_init_inferior (enum inf_context context)
1564 {
1565 struct breakpoint *b, *temp;
1566 static int warning_needed = 0;
1567
1568 ALL_BREAKPOINTS_SAFE (b, temp)
1569 {
1570 b->inserted = 0;
1571
1572 switch (b->type)
1573 {
1574 case bp_call_dummy:
1575 case bp_watchpoint_scope:
1576
1577 /* If the call dummy breakpoint is at the entry point it will
1578 cause problems when the inferior is rerun, so we better
1579 get rid of it.
1580
1581 Also get rid of scope breakpoints. */
1582 delete_breakpoint (b);
1583 break;
1584
1585 case bp_watchpoint:
1586 case bp_hardware_watchpoint:
1587 case bp_read_watchpoint:
1588 case bp_access_watchpoint:
1589
1590 /* Likewise for watchpoints on local expressions. */
1591 if (b->exp_valid_block != NULL)
1592 delete_breakpoint (b);
1593 if (context == inf_starting)
1594 {
1595 /* Reset val field to force reread of starting value
1596 in insert_breakpoints. */
1597 if (b->val)
1598 value_free (b->val);
1599 b->val = NULL;
1600 }
1601 break;
1602 default:
1603 /* Likewise for exception catchpoints in dynamic-linked
1604 executables where required */
1605 if (ep_is_exception_catchpoint (b) &&
1606 exception_catchpoints_are_fragile)
1607 {
1608 warning_needed = 1;
1609 delete_breakpoint (b);
1610 }
1611 break;
1612 }
1613 }
1614
1615 if (exception_catchpoints_are_fragile)
1616 exception_support_initialized = 0;
1617
1618 /* Don't issue the warning unless it's really needed... */
1619 if (warning_needed && (context != inf_exited))
1620 {
1621 warning ("Exception catchpoints from last run were deleted.");
1622 warning ("You must reinsert them explicitly.");
1623 warning_needed = 0;
1624 }
1625 }
1626
1627 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint
1628 exists at PC. It returns ordinary_breakpoint_here if it's an
1629 ordinary breakpoint, or permanent_breakpoint_here if it's a
1630 permanent breakpoint.
1631 - When continuing from a location with an ordinary breakpoint, we
1632 actually single step once before calling insert_breakpoints.
1633 - When continuing from a localion with a permanent breakpoint, we
1634 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by
1635 the target, to advance the PC past the breakpoint. */
1636
1637 enum breakpoint_here
1638 breakpoint_here_p (CORE_ADDR pc)
1639 {
1640 struct breakpoint *b;
1641 int any_breakpoint_here = 0;
1642
1643 ALL_BREAKPOINTS (b)
1644 if ((b->enable_state == bp_enabled
1645 || b->enable_state == bp_permanent)
1646 && b->address == pc) /* bp is enabled and matches pc */
1647 {
1648 if (overlay_debugging
1649 && section_is_overlay (b->section)
1650 && !section_is_mapped (b->section))
1651 continue; /* unmapped overlay -- can't be a match */
1652 else if (b->enable_state == bp_permanent)
1653 return permanent_breakpoint_here;
1654 else
1655 any_breakpoint_here = 1;
1656 }
1657
1658 return any_breakpoint_here ? ordinary_breakpoint_here : 0;
1659 }
1660
1661
1662 /* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(),
1663 but it only returns true if there is actually a breakpoint inserted
1664 at PC. */
1665
1666 int
1667 breakpoint_inserted_here_p (CORE_ADDR pc)
1668 {
1669 struct breakpoint *b;
1670
1671 ALL_BREAKPOINTS (b)
1672 if (b->inserted
1673 && b->address == pc) /* bp is inserted and matches pc */
1674 {
1675 if (overlay_debugging
1676 && section_is_overlay (b->section)
1677 && !section_is_mapped (b->section))
1678 continue; /* unmapped overlay -- can't be a match */
1679 else
1680 return 1;
1681 }
1682
1683 return 0;
1684 }
1685
1686 /* Return nonzero if FRAME is a dummy frame. We can't use
1687 DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would
1688 take too much time, at least using frame_register() on the 68k.
1689 This means that for this function to work right a port must use the
1690 bp_call_dummy breakpoint. */
1691
1692 int
1693 deprecated_frame_in_dummy (struct frame_info *frame)
1694 {
1695 struct breakpoint *b;
1696
1697 /* This function is used by two files: get_frame_type(), after first
1698 checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and
1699 sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */
1700 gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES);
1701
1702 ALL_BREAKPOINTS (b)
1703 {
1704 if (b->type == bp_call_dummy
1705 && frame_id_eq (b->frame_id, get_frame_id (frame))
1706 /* We need to check the PC as well as the frame on the sparc,
1707 for signals.exp in the testsuite. */
1708 && (get_frame_pc (frame)
1709 >= (b->address
1710 - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE))
1711 && get_frame_pc (frame) <= b->address)
1712 return 1;
1713 }
1714 return 0;
1715 }
1716
1717 /* breakpoint_thread_match (PC, PID) returns true if the breakpoint at
1718 PC is valid for process/thread PID. */
1719
1720 int
1721 breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid)
1722 {
1723 struct breakpoint *b;
1724 int thread;
1725
1726 thread = pid_to_thread_id (ptid);
1727
1728 ALL_BREAKPOINTS (b)
1729 if (b->enable_state != bp_disabled
1730 && b->enable_state != bp_shlib_disabled
1731 && b->enable_state != bp_call_disabled
1732 && b->address == pc
1733 && (b->thread == -1 || b->thread == thread))
1734 {
1735 if (overlay_debugging
1736 && section_is_overlay (b->section)
1737 && !section_is_mapped (b->section))
1738 continue; /* unmapped overlay -- can't be a match */
1739 else
1740 return 1;
1741 }
1742
1743 return 0;
1744 }
1745 \f
1746
1747 /* bpstat stuff. External routines' interfaces are documented
1748 in breakpoint.h. */
1749
1750 int
1751 ep_is_catchpoint (struct breakpoint *ep)
1752 {
1753 return
1754 (ep->type == bp_catch_load)
1755 || (ep->type == bp_catch_unload)
1756 || (ep->type == bp_catch_fork)
1757 || (ep->type == bp_catch_vfork)
1758 || (ep->type == bp_catch_exec)
1759 || (ep->type == bp_catch_catch)
1760 || (ep->type == bp_catch_throw);
1761
1762 /* ??rehrauer: Add more kinds here, as are implemented... */
1763 }
1764
1765 int
1766 ep_is_shlib_catchpoint (struct breakpoint *ep)
1767 {
1768 return
1769 (ep->type == bp_catch_load)
1770 || (ep->type == bp_catch_unload);
1771 }
1772
1773 int
1774 ep_is_exception_catchpoint (struct breakpoint *ep)
1775 {
1776 return
1777 (ep->type == bp_catch_catch)
1778 || (ep->type == bp_catch_throw);
1779 }
1780
1781 /* Clear a bpstat so that it says we are not at any breakpoint.
1782 Also free any storage that is part of a bpstat. */
1783
1784 void
1785 bpstat_clear (bpstat *bsp)
1786 {
1787 bpstat p;
1788 bpstat q;
1789
1790 if (bsp == 0)
1791 return;
1792 p = *bsp;
1793 while (p != NULL)
1794 {
1795 q = p->next;
1796 if (p->old_val != NULL)
1797 value_free (p->old_val);
1798 free_command_lines (&p->commands);
1799 xfree (p);
1800 p = q;
1801 }
1802 *bsp = NULL;
1803 }
1804
1805 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that
1806 is part of the bpstat is copied as well. */
1807
1808 bpstat
1809 bpstat_copy (bpstat bs)
1810 {
1811 bpstat p = NULL;
1812 bpstat tmp;
1813 bpstat retval = NULL;
1814
1815 if (bs == NULL)
1816 return bs;
1817
1818 for (; bs != NULL; bs = bs->next)
1819 {
1820 tmp = (bpstat) xmalloc (sizeof (*tmp));
1821 memcpy (tmp, bs, sizeof (*tmp));
1822 if (bs->commands != NULL)
1823 tmp->commands = copy_command_lines (bs->commands);
1824 if (bs->old_val != NULL)
1825 tmp->old_val = value_copy (bs->old_val);
1826
1827 if (p == NULL)
1828 /* This is the first thing in the chain. */
1829 retval = tmp;
1830 else
1831 p->next = tmp;
1832 p = tmp;
1833 }
1834 p->next = NULL;
1835 return retval;
1836 }
1837
1838 /* Find the bpstat associated with this breakpoint */
1839
1840 bpstat
1841 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint)
1842 {
1843 if (bsp == NULL)
1844 return NULL;
1845
1846 for (; bsp != NULL; bsp = bsp->next)
1847 {
1848 if (bsp->breakpoint_at == breakpoint)
1849 return bsp;
1850 }
1851 return NULL;
1852 }
1853
1854 /* Find a step_resume breakpoint associated with this bpstat.
1855 (If there are multiple step_resume bp's on the list, this function
1856 will arbitrarily pick one.)
1857
1858 It is an error to use this function if BPSTAT doesn't contain a
1859 step_resume breakpoint.
1860
1861 See wait_for_inferior's use of this function. */
1862 struct breakpoint *
1863 bpstat_find_step_resume_breakpoint (bpstat bsp)
1864 {
1865 int current_thread;
1866
1867 if (bsp == NULL)
1868 error ("Internal error (bpstat_find_step_resume_breakpoint)");
1869
1870 current_thread = pid_to_thread_id (inferior_ptid);
1871
1872 for (; bsp != NULL; bsp = bsp->next)
1873 {
1874 if ((bsp->breakpoint_at != NULL) &&
1875 (bsp->breakpoint_at->type == bp_step_resume) &&
1876 (bsp->breakpoint_at->thread == current_thread ||
1877 bsp->breakpoint_at->thread == -1))
1878 return bsp->breakpoint_at;
1879 }
1880
1881 error ("Internal error (no step_resume breakpoint found)");
1882 }
1883
1884
1885 /* Return the breakpoint number of the first breakpoint we are stopped
1886 at. *BSP upon return is a bpstat which points to the remaining
1887 breakpoints stopped at (but which is not guaranteed to be good for
1888 anything but further calls to bpstat_num).
1889 Return 0 if passed a bpstat which does not indicate any breakpoints. */
1890
1891 int
1892 bpstat_num (bpstat *bsp)
1893 {
1894 struct breakpoint *b;
1895
1896 if ((*bsp) == NULL)
1897 return 0; /* No more breakpoint values */
1898 else
1899 {
1900 b = (*bsp)->breakpoint_at;
1901 *bsp = (*bsp)->next;
1902 if (b == NULL)
1903 return -1; /* breakpoint that's been deleted since */
1904 else
1905 return b->number; /* We have its number */
1906 }
1907 }
1908
1909 /* Modify BS so that the actions will not be performed. */
1910
1911 void
1912 bpstat_clear_actions (bpstat bs)
1913 {
1914 for (; bs != NULL; bs = bs->next)
1915 {
1916 free_command_lines (&bs->commands);
1917 if (bs->old_val != NULL)
1918 {
1919 value_free (bs->old_val);
1920 bs->old_val = NULL;
1921 }
1922 }
1923 }
1924
1925 /* Stub for cleaning up our state if we error-out of a breakpoint command */
1926 static void
1927 cleanup_executing_breakpoints (void *ignore)
1928 {
1929 executing_breakpoint_commands = 0;
1930 }
1931
1932 /* Execute all the commands associated with all the breakpoints at this
1933 location. Any of these commands could cause the process to proceed
1934 beyond this point, etc. We look out for such changes by checking
1935 the global "breakpoint_proceeded" after each command. */
1936
1937 void
1938 bpstat_do_actions (bpstat *bsp)
1939 {
1940 bpstat bs;
1941 struct cleanup *old_chain;
1942 struct command_line *cmd;
1943
1944 /* Avoid endless recursion if a `source' command is contained
1945 in bs->commands. */
1946 if (executing_breakpoint_commands)
1947 return;
1948
1949 executing_breakpoint_commands = 1;
1950 old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
1951
1952 top:
1953 /* Note that (as of this writing), our callers all appear to
1954 be passing us the address of global stop_bpstat. And, if
1955 our calls to execute_control_command cause the inferior to
1956 proceed, that global (and hence, *bsp) will change.
1957
1958 We must be careful to not touch *bsp unless the inferior
1959 has not proceeded. */
1960
1961 /* This pointer will iterate over the list of bpstat's. */
1962 bs = *bsp;
1963
1964 breakpoint_proceeded = 0;
1965 for (; bs != NULL; bs = bs->next)
1966 {
1967 cmd = bs->commands;
1968 while (cmd != NULL)
1969 {
1970 execute_control_command (cmd);
1971
1972 if (breakpoint_proceeded)
1973 break;
1974 else
1975 cmd = cmd->next;
1976 }
1977 if (breakpoint_proceeded)
1978 /* The inferior is proceeded by the command; bomb out now.
1979 The bpstat chain has been blown away by wait_for_inferior.
1980 But since execution has stopped again, there is a new bpstat
1981 to look at, so start over. */
1982 goto top;
1983 else
1984 free_command_lines (&bs->commands);
1985 }
1986 do_cleanups (old_chain);
1987 }
1988
1989 /* This is the normal print function for a bpstat. In the future,
1990 much of this logic could (should?) be moved to bpstat_stop_status,
1991 by having it set different print_it values.
1992
1993 Current scheme: When we stop, bpstat_print() is called. It loops
1994 through the bpstat list of things causing this stop, calling the
1995 print_bp_stop_message function on each one. The behavior of the
1996 print_bp_stop_message function depends on the print_it field of
1997 bpstat. If such field so indicates, call this function here.
1998
1999 Return values from this routine (ultimately used by bpstat_print()
2000 and normal_stop() to decide what to do):
2001 PRINT_NOTHING: Means we already printed all we needed to print,
2002 don't print anything else.
2003 PRINT_SRC_ONLY: Means we printed something, and we do *not* desire
2004 that something to be followed by a location.
2005 PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire
2006 that something to be followed by a location.
2007 PRINT_UNKNOWN: Means we printed nothing or we need to do some more
2008 analysis. */
2009
2010 static enum print_stop_action
2011 print_it_typical (bpstat bs)
2012 {
2013 struct cleanup *old_chain, *ui_out_chain;
2014 struct ui_stream *stb;
2015 stb = ui_out_stream_new (uiout);
2016 old_chain = make_cleanup_ui_out_stream_delete (stb);
2017 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
2018 which has since been deleted. */
2019 if (bs->breakpoint_at == NULL)
2020 return PRINT_UNKNOWN;
2021
2022 switch (bs->breakpoint_at->type)
2023 {
2024 case bp_breakpoint:
2025 case bp_hardware_breakpoint:
2026 annotate_breakpoint (bs->breakpoint_at->number);
2027 ui_out_text (uiout, "\nBreakpoint ");
2028 if (ui_out_is_mi_like_p (uiout))
2029 ui_out_field_string (uiout, "reason", "breakpoint-hit");
2030 ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number);
2031 ui_out_text (uiout, ", ");
2032 return PRINT_SRC_AND_LOC;
2033 break;
2034
2035 case bp_shlib_event:
2036 /* Did we stop because the user set the stop_on_solib_events
2037 variable? (If so, we report this as a generic, "Stopped due
2038 to shlib event" message.) */
2039 printf_filtered ("Stopped due to shared library event\n");
2040 return PRINT_NOTHING;
2041 break;
2042
2043 case bp_thread_event:
2044 /* Not sure how we will get here.
2045 GDB should not stop for these breakpoints. */
2046 printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n");
2047 return PRINT_NOTHING;
2048 break;
2049
2050 case bp_overlay_event:
2051 /* By analogy with the thread event, GDB should not stop for these. */
2052 printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n");
2053 return PRINT_NOTHING;
2054 break;
2055
2056 case bp_catch_load:
2057 annotate_catchpoint (bs->breakpoint_at->number);
2058 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2059 printf_filtered ("loaded");
2060 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2061 return PRINT_SRC_AND_LOC;
2062 break;
2063
2064 case bp_catch_unload:
2065 annotate_catchpoint (bs->breakpoint_at->number);
2066 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2067 printf_filtered ("unloaded");
2068 printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname);
2069 return PRINT_SRC_AND_LOC;
2070 break;
2071
2072 case bp_catch_fork:
2073 annotate_catchpoint (bs->breakpoint_at->number);
2074 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2075 printf_filtered ("forked");
2076 printf_filtered (" process %d), ",
2077 bs->breakpoint_at->forked_inferior_pid);
2078 return PRINT_SRC_AND_LOC;
2079 break;
2080
2081 case bp_catch_vfork:
2082 annotate_catchpoint (bs->breakpoint_at->number);
2083 printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number);
2084 printf_filtered ("vforked");
2085 printf_filtered (" process %d), ",
2086 bs->breakpoint_at->forked_inferior_pid);
2087 return PRINT_SRC_AND_LOC;
2088 break;
2089
2090 case bp_catch_exec:
2091 annotate_catchpoint (bs->breakpoint_at->number);
2092 printf_filtered ("\nCatchpoint %d (exec'd %s), ",
2093 bs->breakpoint_at->number,
2094 bs->breakpoint_at->exec_pathname);
2095 return PRINT_SRC_AND_LOC;
2096 break;
2097
2098 case bp_catch_catch:
2099 if (current_exception_event &&
2100 (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH))
2101 {
2102 annotate_catchpoint (bs->breakpoint_at->number);
2103 printf_filtered ("\nCatchpoint %d (exception caught), ",
2104 bs->breakpoint_at->number);
2105 printf_filtered ("throw location ");
2106 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2107 printf_filtered ("%s:%d",
2108 CURRENT_EXCEPTION_THROW_FILE,
2109 CURRENT_EXCEPTION_THROW_LINE);
2110 else
2111 printf_filtered ("unknown");
2112
2113 printf_filtered (", catch location ");
2114 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2115 printf_filtered ("%s:%d",
2116 CURRENT_EXCEPTION_CATCH_FILE,
2117 CURRENT_EXCEPTION_CATCH_LINE);
2118 else
2119 printf_filtered ("unknown");
2120
2121 printf_filtered ("\n");
2122 /* don't bother to print location frame info */
2123 return PRINT_SRC_ONLY;
2124 }
2125 else
2126 {
2127 /* really throw, some other bpstat will handle it */
2128 return PRINT_UNKNOWN;
2129 }
2130 break;
2131
2132 case bp_catch_throw:
2133 if (current_exception_event &&
2134 (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW))
2135 {
2136 annotate_catchpoint (bs->breakpoint_at->number);
2137 printf_filtered ("\nCatchpoint %d (exception thrown), ",
2138 bs->breakpoint_at->number);
2139 printf_filtered ("throw location ");
2140 if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE)
2141 printf_filtered ("%s:%d",
2142 CURRENT_EXCEPTION_THROW_FILE,
2143 CURRENT_EXCEPTION_THROW_LINE);
2144 else
2145 printf_filtered ("unknown");
2146
2147 printf_filtered (", catch location ");
2148 if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE)
2149 printf_filtered ("%s:%d",
2150 CURRENT_EXCEPTION_CATCH_FILE,
2151 CURRENT_EXCEPTION_CATCH_LINE);
2152 else
2153 printf_filtered ("unknown");
2154
2155 printf_filtered ("\n");
2156 /* don't bother to print location frame info */
2157 return PRINT_SRC_ONLY;
2158 }
2159 else
2160 {
2161 /* really catch, some other bpstat will handle it */
2162 return PRINT_UNKNOWN;
2163 }
2164 break;
2165
2166 case bp_watchpoint:
2167 case bp_hardware_watchpoint:
2168 if (bs->old_val != NULL)
2169 {
2170 annotate_watchpoint (bs->breakpoint_at->number);
2171 if (ui_out_is_mi_like_p (uiout))
2172 ui_out_field_string (uiout, "reason", "watchpoint-trigger");
2173 mention (bs->breakpoint_at);
2174 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2175 ui_out_text (uiout, "\nOld value = ");
2176 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2177 ui_out_field_stream (uiout, "old", stb);
2178 ui_out_text (uiout, "\nNew value = ");
2179 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2180 ui_out_field_stream (uiout, "new", stb);
2181 do_cleanups (ui_out_chain);
2182 ui_out_text (uiout, "\n");
2183 value_free (bs->old_val);
2184 bs->old_val = NULL;
2185 }
2186 /* More than one watchpoint may have been triggered. */
2187 return PRINT_UNKNOWN;
2188 break;
2189
2190 case bp_read_watchpoint:
2191 if (ui_out_is_mi_like_p (uiout))
2192 ui_out_field_string (uiout, "reason", "read-watchpoint-trigger");
2193 mention (bs->breakpoint_at);
2194 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2195 ui_out_text (uiout, "\nValue = ");
2196 value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default);
2197 ui_out_field_stream (uiout, "value", stb);
2198 do_cleanups (ui_out_chain);
2199 ui_out_text (uiout, "\n");
2200 return PRINT_UNKNOWN;
2201 break;
2202
2203 case bp_access_watchpoint:
2204 if (bs->old_val != NULL)
2205 {
2206 annotate_watchpoint (bs->breakpoint_at->number);
2207 if (ui_out_is_mi_like_p (uiout))
2208 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2209 mention (bs->breakpoint_at);
2210 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2211 ui_out_text (uiout, "\nOld value = ");
2212 value_print (bs->old_val, stb->stream, 0, Val_pretty_default);
2213 ui_out_field_stream (uiout, "old", stb);
2214 value_free (bs->old_val);
2215 bs->old_val = NULL;
2216 ui_out_text (uiout, "\nNew value = ");
2217 }
2218 else
2219 {
2220 mention (bs->breakpoint_at);
2221 if (ui_out_is_mi_like_p (uiout))
2222 ui_out_field_string (uiout, "reason", "access-watchpoint-trigger");
2223 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value");
2224 ui_out_text (uiout, "\nValue = ");
2225 }
2226 value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default);
2227 ui_out_field_stream (uiout, "new", stb);
2228 do_cleanups (ui_out_chain);
2229 ui_out_text (uiout, "\n");
2230 return PRINT_UNKNOWN;
2231 break;
2232
2233 /* Fall through, we don't deal with these types of breakpoints
2234 here. */
2235
2236 case bp_finish:
2237 if (ui_out_is_mi_like_p (uiout))
2238 ui_out_field_string (uiout, "reason", "function-finished");
2239 return PRINT_UNKNOWN;
2240 break;
2241
2242 case bp_until:
2243 if (ui_out_is_mi_like_p (uiout))
2244 ui_out_field_string (uiout, "reason", "location-reached");
2245 return PRINT_UNKNOWN;
2246 break;
2247
2248 case bp_none:
2249 case bp_longjmp:
2250 case bp_longjmp_resume:
2251 case bp_step_resume:
2252 case bp_through_sigtramp:
2253 case bp_watchpoint_scope:
2254 case bp_call_dummy:
2255 default:
2256 return PRINT_UNKNOWN;
2257 }
2258 }
2259
2260 /* Generic routine for printing messages indicating why we
2261 stopped. The behavior of this function depends on the value
2262 'print_it' in the bpstat structure. Under some circumstances we
2263 may decide not to print anything here and delegate the task to
2264 normal_stop(). */
2265
2266 static enum print_stop_action
2267 print_bp_stop_message (bpstat bs)
2268 {
2269 switch (bs->print_it)
2270 {
2271 case print_it_noop:
2272 /* Nothing should be printed for this bpstat entry. */
2273 return PRINT_UNKNOWN;
2274 break;
2275
2276 case print_it_done:
2277 /* We still want to print the frame, but we already printed the
2278 relevant messages. */
2279 return PRINT_SRC_AND_LOC;
2280 break;
2281
2282 case print_it_normal:
2283 /* Normal case. Call the breakpoint's print_it method, or
2284 print_it_typical. */
2285 if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL
2286 && bs->breakpoint_at->ops->print_it != NULL)
2287 return bs->breakpoint_at->ops->print_it (bs->breakpoint_at);
2288 else
2289 return print_it_typical (bs);
2290 break;
2291
2292 default:
2293 internal_error (__FILE__, __LINE__,
2294 "print_bp_stop_message: unrecognized enum value");
2295 break;
2296 }
2297 }
2298
2299 /* Print a message indicating what happened. This is called from
2300 normal_stop(). The input to this routine is the head of the bpstat
2301 list - a list of the eventpoints that caused this stop. This
2302 routine calls the generic print routine for printing a message
2303 about reasons for stopping. This will print (for example) the
2304 "Breakpoint n," part of the output. The return value of this
2305 routine is one of:
2306
2307 PRINT_UNKNOWN: Means we printed nothing
2308 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent
2309 code to print the location. An example is
2310 "Breakpoint 1, " which should be followed by
2311 the location.
2312 PRINT_SRC_ONLY: Means we printed something, but there is no need
2313 to also print the location part of the message.
2314 An example is the catch/throw messages, which
2315 don't require a location appended to the end.
2316 PRINT_NOTHING: We have done some printing and we don't need any
2317 further info to be printed.*/
2318
2319 enum print_stop_action
2320 bpstat_print (bpstat bs)
2321 {
2322 int val;
2323
2324 /* Maybe another breakpoint in the chain caused us to stop.
2325 (Currently all watchpoints go on the bpstat whether hit or not.
2326 That probably could (should) be changed, provided care is taken
2327 with respect to bpstat_explains_signal). */
2328 for (; bs; bs = bs->next)
2329 {
2330 val = print_bp_stop_message (bs);
2331 if (val == PRINT_SRC_ONLY
2332 || val == PRINT_SRC_AND_LOC
2333 || val == PRINT_NOTHING)
2334 return val;
2335 }
2336
2337 /* We reached the end of the chain, or we got a null BS to start
2338 with and nothing was printed. */
2339 return PRINT_UNKNOWN;
2340 }
2341
2342 /* Evaluate the expression EXP and return 1 if value is zero.
2343 This is used inside a catch_errors to evaluate the breakpoint condition.
2344 The argument is a "struct expression *" that has been cast to char * to
2345 make it pass through catch_errors. */
2346
2347 static int
2348 breakpoint_cond_eval (void *exp)
2349 {
2350 struct value *mark = value_mark ();
2351 int i = !value_true (evaluate_expression ((struct expression *) exp));
2352 value_free_to_mark (mark);
2353 return i;
2354 }
2355
2356 /* Allocate a new bpstat and chain it to the current one. */
2357
2358 static bpstat
2359 bpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ )
2360 {
2361 bpstat bs;
2362
2363 bs = (bpstat) xmalloc (sizeof (*bs));
2364 cbs->next = bs;
2365 bs->breakpoint_at = b;
2366 /* If the condition is false, etc., don't do the commands. */
2367 bs->commands = NULL;
2368 bs->old_val = NULL;
2369 bs->print_it = print_it_normal;
2370 return bs;
2371 }
2372 \f
2373 /* Possible return values for watchpoint_check (this can't be an enum
2374 because of check_errors). */
2375 /* The watchpoint has been deleted. */
2376 #define WP_DELETED 1
2377 /* The value has changed. */
2378 #define WP_VALUE_CHANGED 2
2379 /* The value has not changed. */
2380 #define WP_VALUE_NOT_CHANGED 3
2381
2382 #define BP_TEMPFLAG 1
2383 #define BP_HARDWAREFLAG 2
2384
2385 /* Check watchpoint condition. */
2386
2387 static int
2388 watchpoint_check (void *p)
2389 {
2390 bpstat bs = (bpstat) p;
2391 struct breakpoint *b;
2392 struct frame_info *fr;
2393 int within_current_scope;
2394 #if 0
2395 struct frame_id current_frame_id;
2396 #endif
2397
2398 b = bs->breakpoint_at;
2399
2400 if (b->exp_valid_block == NULL)
2401 within_current_scope = 1;
2402 else
2403 {
2404 /* There is no current frame at this moment. If we're going to have
2405 any chance of handling watchpoints on local variables, we'll need
2406 the frame chain (so we can determine if we're in scope). */
2407 reinit_frame_cache ();
2408 fr = frame_find_by_id (b->watchpoint_frame);
2409 within_current_scope = (fr != NULL);
2410 /* in_function_epilogue_p() returns a non-zero value if we're still
2411 in the function but the stack frame has already been invalidated.
2412 Since we can't rely on the values of local variables after the
2413 stack has been destroyed, we are treating the watchpoint in that
2414 state as `not changed' without further checking.
2415
2416 vinschen/2003-09-04: The former implementation left out the case
2417 that the watchpoint frame couldn't be found by frame_find_by_id()
2418 because the current PC is currently in an epilogue. Calling
2419 gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */
2420 if ((!within_current_scope || fr == get_current_frame ())
2421 && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ()))
2422 return WP_VALUE_NOT_CHANGED;
2423 if (fr && within_current_scope)
2424 /* If we end up stopping, the current frame will get selected
2425 in normal_stop. So this call to select_frame won't affect
2426 the user. */
2427 select_frame (fr);
2428 }
2429
2430 if (within_current_scope)
2431 {
2432 /* We use value_{,free_to_}mark because it could be a
2433 *long* time before we return to the command level and
2434 call free_all_values. We can't call free_all_values because
2435 we might be in the middle of evaluating a function call. */
2436
2437 struct value *mark = value_mark ();
2438 struct value *new_val = evaluate_expression (bs->breakpoint_at->exp);
2439 if (!value_equal (b->val, new_val))
2440 {
2441 release_value (new_val);
2442 value_free_to_mark (mark);
2443 bs->old_val = b->val;
2444 b->val = new_val;
2445 /* We will stop here */
2446 return WP_VALUE_CHANGED;
2447 }
2448 else
2449 {
2450 /* Nothing changed, don't do anything. */
2451 value_free_to_mark (mark);
2452 /* We won't stop here */
2453 return WP_VALUE_NOT_CHANGED;
2454 }
2455 }
2456 else
2457 {
2458 /* This seems like the only logical thing to do because
2459 if we temporarily ignored the watchpoint, then when
2460 we reenter the block in which it is valid it contains
2461 garbage (in the case of a function, it may have two
2462 garbage values, one before and one after the prologue).
2463 So we can't even detect the first assignment to it and
2464 watch after that (since the garbage may or may not equal
2465 the first value assigned). */
2466 /* We print all the stop information in print_it_typical(), but
2467 in this case, by the time we call print_it_typical() this bp
2468 will be deleted already. So we have no choice but print the
2469 information here. */
2470 if (ui_out_is_mi_like_p (uiout))
2471 ui_out_field_string (uiout, "reason", "watchpoint-scope");
2472 ui_out_text (uiout, "\nWatchpoint ");
2473 ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number);
2474 ui_out_text (uiout, " deleted because the program has left the block in\n\
2475 which its expression is valid.\n");
2476
2477 if (b->related_breakpoint)
2478 b->related_breakpoint->disposition = disp_del_at_next_stop;
2479 b->disposition = disp_del_at_next_stop;
2480
2481 return WP_DELETED;
2482 }
2483 }
2484
2485 /* Get a bpstat associated with having just stopped at address *PC
2486 and frame address CORE_ADDRESS. Update *PC to point at the
2487 breakpoint (if we hit a breakpoint). NOT_A_SW_BREAKPOINT is nonzero
2488 if this is known to not be a real breakpoint (it could still be a
2489 watchpoint, though). */
2490
2491 /* Determine whether we stopped at a breakpoint, etc, or whether we
2492 don't understand this stop. Result is a chain of bpstat's such that:
2493
2494 if we don't understand the stop, the result is a null pointer.
2495
2496 if we understand why we stopped, the result is not null.
2497
2498 Each element of the chain refers to a particular breakpoint or
2499 watchpoint at which we have stopped. (We may have stopped for
2500 several reasons concurrently.)
2501
2502 Each element of the chain has valid next, breakpoint_at,
2503 commands, FIXME??? fields. */
2504
2505 bpstat
2506 bpstat_stop_status (CORE_ADDR *pc, int not_a_sw_breakpoint)
2507 {
2508 struct breakpoint *b, *temp;
2509 CORE_ADDR bp_addr;
2510 /* True if we've hit a breakpoint (as opposed to a watchpoint). */
2511 int real_breakpoint = 0;
2512 /* Root of the chain of bpstat's */
2513 struct bpstats root_bs[1];
2514 /* Pointer to the last thing in the chain currently. */
2515 bpstat bs = root_bs;
2516
2517 /* Get the address where the breakpoint would have been. The
2518 "not_a_sw_breakpoint" argument is meant to distinguish between a
2519 breakpoint trap event and a trace/singlestep trap event. For a
2520 trace/singlestep trap event, we would not want to subtract
2521 DECR_PC_AFTER_BREAK from the PC. */
2522
2523 bp_addr = *pc - (not_a_sw_breakpoint ? 0 : DECR_PC_AFTER_BREAK);
2524
2525 ALL_BREAKPOINTS_SAFE (b, temp)
2526 {
2527 if (b->enable_state == bp_disabled
2528 || b->enable_state == bp_shlib_disabled
2529 || b->enable_state == bp_call_disabled)
2530 continue;
2531
2532 if (b->type != bp_watchpoint
2533 && b->type != bp_hardware_watchpoint
2534 && b->type != bp_read_watchpoint
2535 && b->type != bp_access_watchpoint
2536 && b->type != bp_hardware_breakpoint
2537 && b->type != bp_catch_fork
2538 && b->type != bp_catch_vfork
2539 && b->type != bp_catch_exec
2540 && b->type != bp_catch_catch
2541 && b->type != bp_catch_throw) /* a non-watchpoint bp */
2542 {
2543 if (b->address != bp_addr) /* address doesn't match */
2544 continue;
2545 if (overlay_debugging /* unmapped overlay section */
2546 && section_is_overlay (b->section)
2547 && !section_is_mapped (b->section))
2548 continue;
2549 }
2550
2551 if (b->type == bp_hardware_breakpoint)
2552 {
2553 if (b->address != (*pc - DECR_PC_AFTER_HW_BREAK))
2554 continue;
2555 if (overlay_debugging /* unmapped overlay section */
2556 && section_is_overlay (b->section)
2557 && !section_is_mapped (b->section))
2558 continue;
2559 }
2560
2561 /* Is this a catchpoint of a load or unload? If so, did we
2562 get a load or unload of the specified library? If not,
2563 ignore it. */
2564 if ((b->type == bp_catch_load)
2565 #if defined(SOLIB_HAVE_LOAD_EVENT)
2566 && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid))
2567 || ((b->dll_pathname != NULL)
2568 && (strcmp (b->dll_pathname,
2569 SOLIB_LOADED_LIBRARY_PATHNAME (
2570 PIDGET (inferior_ptid)))
2571 != 0)))
2572 #endif
2573 )
2574 continue;
2575
2576 if ((b->type == bp_catch_unload)
2577 #if defined(SOLIB_HAVE_UNLOAD_EVENT)
2578 && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid))
2579 || ((b->dll_pathname != NULL)
2580 && (strcmp (b->dll_pathname,
2581 SOLIB_UNLOADED_LIBRARY_PATHNAME (
2582 PIDGET (inferior_ptid)))
2583 != 0)))
2584 #endif
2585 )
2586 continue;
2587
2588 if ((b->type == bp_catch_fork)
2589 && !inferior_has_forked (PIDGET (inferior_ptid),
2590 &b->forked_inferior_pid))
2591 continue;
2592
2593 if ((b->type == bp_catch_vfork)
2594 && !inferior_has_vforked (PIDGET (inferior_ptid),
2595 &b->forked_inferior_pid))
2596 continue;
2597
2598 if ((b->type == bp_catch_exec)
2599 && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname))
2600 continue;
2601
2602 if (ep_is_exception_catchpoint (b) &&
2603 !(current_exception_event = target_get_current_exception_event ()))
2604 continue;
2605
2606 /* Come here if it's a watchpoint, or if the break address matches */
2607
2608 bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */
2609
2610 /* Watchpoints may change this, if not found to have triggered. */
2611 bs->stop = 1;
2612 bs->print = 1;
2613
2614 if (b->type == bp_watchpoint ||
2615 b->type == bp_hardware_watchpoint)
2616 {
2617 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2618 b->number);
2619 struct cleanup *cleanups = make_cleanup (xfree, message);
2620 int e = catch_errors (watchpoint_check, bs, message,
2621 RETURN_MASK_ALL);
2622 do_cleanups (cleanups);
2623 switch (e)
2624 {
2625 case WP_DELETED:
2626 /* We've already printed what needs to be printed. */
2627 /* Actually this is superfluous, because by the time we
2628 call print_it_typical() the wp will be already deleted,
2629 and the function will return immediately. */
2630 bs->print_it = print_it_done;
2631 /* Stop. */
2632 break;
2633 case WP_VALUE_CHANGED:
2634 /* Stop. */
2635 ++(b->hit_count);
2636 break;
2637 case WP_VALUE_NOT_CHANGED:
2638 /* Don't stop. */
2639 bs->print_it = print_it_noop;
2640 bs->stop = 0;
2641 continue;
2642 default:
2643 /* Can't happen. */
2644 /* FALLTHROUGH */
2645 case 0:
2646 /* Error from catch_errors. */
2647 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2648 if (b->related_breakpoint)
2649 b->related_breakpoint->disposition = disp_del_at_next_stop;
2650 b->disposition = disp_del_at_next_stop;
2651 /* We've already printed what needs to be printed. */
2652 bs->print_it = print_it_done;
2653
2654 /* Stop. */
2655 break;
2656 }
2657 }
2658 else if (b->type == bp_read_watchpoint ||
2659 b->type == bp_access_watchpoint)
2660 {
2661 CORE_ADDR addr;
2662 struct value *v;
2663 int found = 0;
2664
2665 addr = target_stopped_data_address ();
2666 if (addr == 0)
2667 continue;
2668 for (v = b->val_chain; v; v = v->next)
2669 {
2670 if (VALUE_LVAL (v) == lval_memory
2671 && ! VALUE_LAZY (v))
2672 {
2673 struct type *vtype = check_typedef (VALUE_TYPE (v));
2674
2675 if (v == b->val_chain
2676 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
2677 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
2678 {
2679 CORE_ADDR vaddr;
2680
2681 vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
2682 /* Exact match not required. Within range is
2683 sufficient. */
2684 if (addr >= vaddr &&
2685 addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v)))
2686 found = 1;
2687 }
2688 }
2689 }
2690 if (found)
2691 {
2692 char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n",
2693 b->number);
2694 struct cleanup *cleanups = make_cleanup (xfree, message);
2695 int e = catch_errors (watchpoint_check, bs, message,
2696 RETURN_MASK_ALL);
2697 do_cleanups (cleanups);
2698 switch (e)
2699 {
2700 case WP_DELETED:
2701 /* We've already printed what needs to be printed. */
2702 bs->print_it = print_it_done;
2703 /* Stop. */
2704 break;
2705 case WP_VALUE_CHANGED:
2706 if (b->type == bp_read_watchpoint)
2707 {
2708 /* Don't stop: read watchpoints shouldn't fire if
2709 the value has changed. This is for targets
2710 which cannot set read-only watchpoints. */
2711 bs->print_it = print_it_noop;
2712 bs->stop = 0;
2713 continue;
2714 }
2715 ++(b->hit_count);
2716 break;
2717 case WP_VALUE_NOT_CHANGED:
2718 /* Stop. */
2719 ++(b->hit_count);
2720 break;
2721 default:
2722 /* Can't happen. */
2723 case 0:
2724 /* Error from catch_errors. */
2725 printf_filtered ("Watchpoint %d deleted.\n", b->number);
2726 if (b->related_breakpoint)
2727 b->related_breakpoint->disposition = disp_del_at_next_stop;
2728 b->disposition = disp_del_at_next_stop;
2729 /* We've already printed what needs to be printed. */
2730 bs->print_it = print_it_done;
2731 break;
2732 }
2733 }
2734 else /* found == 0 */
2735 {
2736 /* This is a case where some watchpoint(s) triggered,
2737 but not at the address of this watchpoint (FOUND
2738 was left zero). So don't print anything for this
2739 watchpoint. */
2740 bs->print_it = print_it_noop;
2741 bs->stop = 0;
2742 continue;
2743 }
2744 }
2745 else
2746 {
2747 /* By definition, an encountered breakpoint is a triggered
2748 breakpoint. */
2749 ++(b->hit_count);
2750
2751 real_breakpoint = 1;
2752 }
2753
2754 if (frame_id_p (b->frame_id)
2755 && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ())))
2756 bs->stop = 0;
2757 else
2758 {
2759 int value_is_zero = 0;
2760
2761 if (b->cond)
2762 {
2763 /* Need to select the frame, with all that implies
2764 so that the conditions will have the right context. */
2765 select_frame (get_current_frame ());
2766 value_is_zero
2767 = catch_errors (breakpoint_cond_eval, (b->cond),
2768 "Error in testing breakpoint condition:\n",
2769 RETURN_MASK_ALL);
2770 /* FIXME-someday, should give breakpoint # */
2771 free_all_values ();
2772 }
2773 if (b->cond && value_is_zero)
2774 {
2775 bs->stop = 0;
2776 /* Don't consider this a hit. */
2777 --(b->hit_count);
2778 }
2779 else if (b->ignore_count > 0)
2780 {
2781 b->ignore_count--;
2782 annotate_ignore_count_change ();
2783 bs->stop = 0;
2784 }
2785 else
2786 {
2787 /* We will stop here */
2788 if (b->disposition == disp_disable)
2789 b->enable_state = bp_disabled;
2790 if (b->silent)
2791 bs->print = 0;
2792 bs->commands = b->commands;
2793 if (bs->commands &&
2794 (STREQ ("silent", bs->commands->line) ||
2795 (xdb_commands && STREQ ("Q", bs->commands->line))))
2796 {
2797 bs->commands = bs->commands->next;
2798 bs->print = 0;
2799 }
2800 bs->commands = copy_command_lines (bs->commands);
2801 }
2802 }
2803 /* Print nothing for this entry if we dont stop or if we dont print. */
2804 if (bs->stop == 0 || bs->print == 0)
2805 bs->print_it = print_it_noop;
2806 }
2807
2808 bs->next = NULL; /* Terminate the chain */
2809 bs = root_bs->next; /* Re-grab the head of the chain */
2810
2811 if (real_breakpoint && bs)
2812 {
2813 if (bs->breakpoint_at->type == bp_hardware_breakpoint)
2814 {
2815 if (DECR_PC_AFTER_HW_BREAK != 0)
2816 {
2817 *pc = *pc - DECR_PC_AFTER_HW_BREAK;
2818 write_pc (*pc);
2819 }
2820 }
2821 else
2822 {
2823 if (DECR_PC_AFTER_BREAK != 0 || must_shift_inst_regs)
2824 {
2825 *pc = bp_addr;
2826 #if defined (SHIFT_INST_REGS)
2827 SHIFT_INST_REGS ();
2828 #else /* No SHIFT_INST_REGS. */
2829 write_pc (bp_addr);
2830 #endif /* No SHIFT_INST_REGS. */
2831 }
2832 }
2833 }
2834
2835 /* The value of a hardware watchpoint hasn't changed, but the
2836 intermediate memory locations we are watching may have. */
2837 if (bs && !bs->stop &&
2838 (bs->breakpoint_at->type == bp_hardware_watchpoint ||
2839 bs->breakpoint_at->type == bp_read_watchpoint ||
2840 bs->breakpoint_at->type == bp_access_watchpoint))
2841 {
2842 remove_breakpoints ();
2843 insert_breakpoints ();
2844 }
2845 return bs;
2846 }
2847 \f
2848 /* Tell what to do about this bpstat. */
2849 struct bpstat_what
2850 bpstat_what (bpstat bs)
2851 {
2852 /* Classify each bpstat as one of the following. */
2853 enum class
2854 {
2855 /* This bpstat element has no effect on the main_action. */
2856 no_effect = 0,
2857
2858 /* There was a watchpoint, stop but don't print. */
2859 wp_silent,
2860
2861 /* There was a watchpoint, stop and print. */
2862 wp_noisy,
2863
2864 /* There was a breakpoint but we're not stopping. */
2865 bp_nostop,
2866
2867 /* There was a breakpoint, stop but don't print. */
2868 bp_silent,
2869
2870 /* There was a breakpoint, stop and print. */
2871 bp_noisy,
2872
2873 /* We hit the longjmp breakpoint. */
2874 long_jump,
2875
2876 /* We hit the longjmp_resume breakpoint. */
2877 long_resume,
2878
2879 /* We hit the step_resume breakpoint. */
2880 step_resume,
2881
2882 /* We hit the through_sigtramp breakpoint. */
2883 through_sig,
2884
2885 /* We hit the shared library event breakpoint. */
2886 shlib_event,
2887
2888 /* We caught a shared library event. */
2889 catch_shlib_event,
2890
2891 /* This is just used to count how many enums there are. */
2892 class_last
2893 };
2894
2895 /* Here is the table which drives this routine. So that we can
2896 format it pretty, we define some abbreviations for the
2897 enum bpstat_what codes. */
2898 #define kc BPSTAT_WHAT_KEEP_CHECKING
2899 #define ss BPSTAT_WHAT_STOP_SILENT
2900 #define sn BPSTAT_WHAT_STOP_NOISY
2901 #define sgl BPSTAT_WHAT_SINGLE
2902 #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME
2903 #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME
2904 #define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE
2905 #define sr BPSTAT_WHAT_STEP_RESUME
2906 #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP
2907 #define shl BPSTAT_WHAT_CHECK_SHLIBS
2908 #define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK
2909
2910 /* "Can't happen." Might want to print an error message.
2911 abort() is not out of the question, but chances are GDB is just
2912 a bit confused, not unusable. */
2913 #define err BPSTAT_WHAT_STOP_NOISY
2914
2915 /* Given an old action and a class, come up with a new action. */
2916 /* One interesting property of this table is that wp_silent is the same
2917 as bp_silent and wp_noisy is the same as bp_noisy. That is because
2918 after stopping, the check for whether to step over a breakpoint
2919 (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without
2920 reference to how we stopped. We retain separate wp_silent and
2921 bp_silent codes in case we want to change that someday.
2922
2923 Another possibly interesting property of this table is that
2924 there's a partial ordering, priority-like, of the actions. Once
2925 you've decided that some action is appropriate, you'll never go
2926 back and decide something of a lower priority is better. The
2927 ordering is:
2928
2929 kc < clr sgl shl shlr slr sn sr ss ts
2930 sgl < clrs shl shlr slr sn sr ss ts
2931 slr < err shl shlr sn sr ss ts
2932 clr < clrs err shl shlr sn sr ss ts
2933 clrs < err shl shlr sn sr ss ts
2934 ss < shl shlr sn sr ts
2935 sn < shl shlr sr ts
2936 sr < shl shlr ts
2937 shl < shlr
2938 ts <
2939 shlr <
2940
2941 What I think this means is that we don't need a damned table
2942 here. If you just put the rows and columns in the right order,
2943 it'd look awfully regular. We could simply walk the bpstat list
2944 and choose the highest priority action we find, with a little
2945 logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/
2946 CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says
2947 is messy anyway). */
2948
2949 /* step_resume entries: a step resume breakpoint overrides another
2950 breakpoint of signal handling (see comment in wait_for_inferior
2951 at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */
2952 /* We handle the through_sigtramp_breakpoint the same way; having both
2953 one of those and a step_resume_breakpoint is probably very rare (?). */
2954
2955 static const enum bpstat_what_main_action
2956 table[(int) class_last][(int) BPSTAT_WHAT_LAST] =
2957 {
2958 /* old action */
2959 /* kc ss sn sgl slr clr clrs sr ts shl shlr
2960 */
2961 /*no_effect */
2962 {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr},
2963 /*wp_silent */
2964 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2965 /*wp_noisy */
2966 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2967 /*bp_nostop */
2968 {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr},
2969 /*bp_silent */
2970 {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr},
2971 /*bp_noisy */
2972 {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr},
2973 /*long_jump */
2974 {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr},
2975 /*long_resume */
2976 {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr},
2977 /*step_resume */
2978 {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr},
2979 /*through_sig */
2980 {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr},
2981 /*shlib */
2982 {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr},
2983 /*catch_shlib */
2984 {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr}
2985 };
2986
2987 #undef kc
2988 #undef ss
2989 #undef sn
2990 #undef sgl
2991 #undef slr
2992 #undef clr
2993 #undef clrs
2994 #undef err
2995 #undef sr
2996 #undef ts
2997 #undef shl
2998 #undef shlr
2999 enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING;
3000 struct bpstat_what retval;
3001
3002 retval.call_dummy = 0;
3003 for (; bs != NULL; bs = bs->next)
3004 {
3005 enum class bs_class = no_effect;
3006 if (bs->breakpoint_at == NULL)
3007 /* I suspect this can happen if it was a momentary breakpoint
3008 which has since been deleted. */
3009 continue;
3010 switch (bs->breakpoint_at->type)
3011 {
3012 case bp_none:
3013 continue;
3014
3015 case bp_breakpoint:
3016 case bp_hardware_breakpoint:
3017 case bp_until:
3018 case bp_finish:
3019 if (bs->stop)
3020 {
3021 if (bs->print)
3022 bs_class = bp_noisy;
3023 else
3024 bs_class = bp_silent;
3025 }
3026 else
3027 bs_class = bp_nostop;
3028 break;
3029 case bp_watchpoint:
3030 case bp_hardware_watchpoint:
3031 case bp_read_watchpoint:
3032 case bp_access_watchpoint:
3033 if (bs->stop)
3034 {
3035 if (bs->print)
3036 bs_class = wp_noisy;
3037 else
3038 bs_class = wp_silent;
3039 }
3040 else
3041 /* There was a watchpoint, but we're not stopping.
3042 This requires no further action. */
3043 bs_class = no_effect;
3044 break;
3045 case bp_longjmp:
3046 bs_class = long_jump;
3047 break;
3048 case bp_longjmp_resume:
3049 bs_class = long_resume;
3050 break;
3051 case bp_step_resume:
3052 if (bs->stop)
3053 {
3054 bs_class = step_resume;
3055 }
3056 else
3057 /* It is for the wrong frame. */
3058 bs_class = bp_nostop;
3059 break;
3060 case bp_through_sigtramp:
3061 bs_class = through_sig;
3062 break;
3063 case bp_watchpoint_scope:
3064 bs_class = bp_nostop;
3065 break;
3066 case bp_shlib_event:
3067 bs_class = shlib_event;
3068 break;
3069 case bp_thread_event:
3070 case bp_overlay_event:
3071 bs_class = bp_nostop;
3072 break;
3073 case bp_catch_load:
3074 case bp_catch_unload:
3075 /* Only if this catchpoint triggered should we cause the
3076 step-out-of-dld behaviour. Otherwise, we ignore this
3077 catchpoint. */
3078 if (bs->stop)
3079 bs_class = catch_shlib_event;
3080 else
3081 bs_class = no_effect;
3082 break;
3083 case bp_catch_fork:
3084 case bp_catch_vfork:
3085 case bp_catch_exec:
3086 if (bs->stop)
3087 {
3088 if (bs->print)
3089 bs_class = bp_noisy;
3090 else
3091 bs_class = bp_silent;
3092 }
3093 else
3094 /* There was a catchpoint, but we're not stopping.
3095 This requires no further action. */
3096 bs_class = no_effect;
3097 break;
3098 case bp_catch_catch:
3099 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH)
3100 bs_class = bp_nostop;
3101 else if (bs->stop)
3102 bs_class = bs->print ? bp_noisy : bp_silent;
3103 break;
3104 case bp_catch_throw:
3105 if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW)
3106 bs_class = bp_nostop;
3107 else if (bs->stop)
3108 bs_class = bs->print ? bp_noisy : bp_silent;
3109 break;
3110 case bp_call_dummy:
3111 /* Make sure the action is stop (silent or noisy),
3112 so infrun.c pops the dummy frame. */
3113 bs_class = bp_silent;
3114 retval.call_dummy = 1;
3115 break;
3116 }
3117 current_action = table[(int) bs_class][(int) current_action];
3118 }
3119 retval.main_action = current_action;
3120 return retval;
3121 }
3122
3123 /* Nonzero if we should step constantly (e.g. watchpoints on machines
3124 without hardware support). This isn't related to a specific bpstat,
3125 just to things like whether watchpoints are set. */
3126
3127 int
3128 bpstat_should_step (void)
3129 {
3130 struct breakpoint *b;
3131 ALL_BREAKPOINTS (b)
3132 if (b->enable_state == bp_enabled && b->type == bp_watchpoint)
3133 return 1;
3134 return 0;
3135 }
3136
3137 /* Nonzero if there are enabled hardware watchpoints. */
3138 int
3139 bpstat_have_active_hw_watchpoints (void)
3140 {
3141 struct breakpoint *b;
3142 ALL_BREAKPOINTS (b)
3143 if ((b->enable_state == bp_enabled) &&
3144 (b->inserted) &&
3145 ((b->type == bp_hardware_watchpoint) ||
3146 (b->type == bp_read_watchpoint) ||
3147 (b->type == bp_access_watchpoint)))
3148 return 1;
3149 return 0;
3150 }
3151 \f
3152
3153 /* Given a bpstat that records zero or more triggered eventpoints, this
3154 function returns another bpstat which contains only the catchpoints
3155 on that first list, if any. */
3156 void
3157 bpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list)
3158 {
3159 struct bpstats root_bs[1];
3160 bpstat bs = root_bs;
3161 struct breakpoint *ep;
3162 char *dll_pathname;
3163
3164 bpstat_clear (cp_list);
3165 root_bs->next = NULL;
3166
3167 for (; ep_list != NULL; ep_list = ep_list->next)
3168 {
3169 /* Is this eventpoint a catchpoint? If not, ignore it. */
3170 ep = ep_list->breakpoint_at;
3171 if (ep == NULL)
3172 break;
3173 if ((ep->type != bp_catch_load) &&
3174 (ep->type != bp_catch_unload) &&
3175 (ep->type != bp_catch_catch) &&
3176 (ep->type != bp_catch_throw))
3177 /* pai: (temp) ADD fork/vfork here!! */
3178 continue;
3179
3180 /* Yes; add it to the list. */
3181 bs = bpstat_alloc (ep, bs);
3182 *bs = *ep_list;
3183 bs->next = NULL;
3184 bs = root_bs->next;
3185
3186 #if defined(SOLIB_ADD)
3187 /* Also, for each triggered catchpoint, tag it with the name of
3188 the library that caused this trigger. (We copy the name now,
3189 because it's only guaranteed to be available NOW, when the
3190 catchpoint triggers. Clients who may wish to know the name
3191 later must get it from the catchpoint itself.) */
3192 if (ep->triggered_dll_pathname != NULL)
3193 xfree (ep->triggered_dll_pathname);
3194 if (ep->type == bp_catch_load)
3195 dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME (
3196 PIDGET (inferior_ptid));
3197 else
3198 dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME (
3199 PIDGET (inferior_ptid));
3200 #else
3201 dll_pathname = NULL;
3202 #endif
3203 if (dll_pathname)
3204 {
3205 ep->triggered_dll_pathname = (char *)
3206 xmalloc (strlen (dll_pathname) + 1);
3207 strcpy (ep->triggered_dll_pathname, dll_pathname);
3208 }
3209 else
3210 ep->triggered_dll_pathname = NULL;
3211 }
3212
3213 *cp_list = bs;
3214 }
3215
3216 /* Print B to gdb_stdout. */
3217 static void
3218 print_one_breakpoint (struct breakpoint *b,
3219 CORE_ADDR *last_addr)
3220 {
3221 struct command_line *l;
3222 struct symbol *sym;
3223 struct ep_type_description
3224 {
3225 enum bptype type;
3226 char *description;
3227 };
3228 static struct ep_type_description bptypes[] =
3229 {
3230 {bp_none, "?deleted?"},
3231 {bp_breakpoint, "breakpoint"},
3232 {bp_hardware_breakpoint, "hw breakpoint"},
3233 {bp_until, "until"},
3234 {bp_finish, "finish"},
3235 {bp_watchpoint, "watchpoint"},
3236 {bp_hardware_watchpoint, "hw watchpoint"},
3237 {bp_read_watchpoint, "read watchpoint"},
3238 {bp_access_watchpoint, "acc watchpoint"},
3239 {bp_longjmp, "longjmp"},
3240 {bp_longjmp_resume, "longjmp resume"},
3241 {bp_step_resume, "step resume"},
3242 {bp_through_sigtramp, "sigtramp"},
3243 {bp_watchpoint_scope, "watchpoint scope"},
3244 {bp_call_dummy, "call dummy"},
3245 {bp_shlib_event, "shlib events"},
3246 {bp_thread_event, "thread events"},
3247 {bp_overlay_event, "overlay events"},
3248 {bp_catch_load, "catch load"},
3249 {bp_catch_unload, "catch unload"},
3250 {bp_catch_fork, "catch fork"},
3251 {bp_catch_vfork, "catch vfork"},
3252 {bp_catch_exec, "catch exec"},
3253 {bp_catch_catch, "catch catch"},
3254 {bp_catch_throw, "catch throw"}
3255 };
3256
3257 static char *bpdisps[] =
3258 {"del", "dstp", "dis", "keep"};
3259 static char bpenables[] = "nynny";
3260 char wrap_indent[80];
3261 struct ui_stream *stb = ui_out_stream_new (uiout);
3262 struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb);
3263 struct cleanup *bkpt_chain;
3264
3265 annotate_record ();
3266 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt");
3267
3268 /* 1 */
3269 annotate_field (0);
3270 ui_out_field_int (uiout, "number", b->number);
3271
3272 /* 2 */
3273 annotate_field (1);
3274 if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0])))
3275 || ((int) b->type != bptypes[(int) b->type].type))
3276 internal_error (__FILE__, __LINE__,
3277 "bptypes table does not describe type #%d.",
3278 (int) b->type);
3279 ui_out_field_string (uiout, "type", bptypes[(int) b->type].description);
3280
3281 /* 3 */
3282 annotate_field (2);
3283 ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]);
3284
3285 /* 4 */
3286 annotate_field (3);
3287 ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]);
3288 ui_out_spaces (uiout, 2);
3289
3290 /* 5 and 6 */
3291 strcpy (wrap_indent, " ");
3292 if (addressprint)
3293 {
3294 if (TARGET_ADDR_BIT <= 32)
3295 strcat (wrap_indent, " ");
3296 else
3297 strcat (wrap_indent, " ");
3298 }
3299
3300 if (b->ops != NULL && b->ops->print_one != NULL)
3301 b->ops->print_one (b, last_addr);
3302 else
3303 switch (b->type)
3304 {
3305 case bp_none:
3306 internal_error (__FILE__, __LINE__,
3307 "print_one_breakpoint: bp_none encountered\n");
3308 break;
3309
3310 case bp_watchpoint:
3311 case bp_hardware_watchpoint:
3312 case bp_read_watchpoint:
3313 case bp_access_watchpoint:
3314 /* Field 4, the address, is omitted (which makes the columns
3315 not line up too nicely with the headers, but the effect
3316 is relatively readable). */
3317 if (addressprint)
3318 ui_out_field_skip (uiout, "addr");
3319 annotate_field (5);
3320 print_expression (b->exp, stb->stream);
3321 ui_out_field_stream (uiout, "what", stb);
3322 break;
3323
3324 case bp_catch_load:
3325 case bp_catch_unload:
3326 /* Field 4, the address, is omitted (which makes the columns
3327 not line up too nicely with the headers, but the effect
3328 is relatively readable). */
3329 if (addressprint)
3330 ui_out_field_skip (uiout, "addr");
3331 annotate_field (5);
3332 if (b->dll_pathname == NULL)
3333 {
3334 ui_out_field_string (uiout, "what", "<any library>");
3335 ui_out_spaces (uiout, 1);
3336 }
3337 else
3338 {
3339 ui_out_text (uiout, "library \"");
3340 ui_out_field_string (uiout, "what", b->dll_pathname);
3341 ui_out_text (uiout, "\" ");
3342 }
3343 break;
3344
3345 case bp_catch_fork:
3346 case bp_catch_vfork:
3347 /* Field 4, the address, is omitted (which makes the columns
3348 not line up too nicely with the headers, but the effect
3349 is relatively readable). */
3350 if (addressprint)
3351 ui_out_field_skip (uiout, "addr");
3352 annotate_field (5);
3353 if (b->forked_inferior_pid != 0)
3354 {
3355 ui_out_text (uiout, "process ");
3356 ui_out_field_int (uiout, "what", b->forked_inferior_pid);
3357 ui_out_spaces (uiout, 1);
3358 }
3359
3360 case bp_catch_exec:
3361 /* Field 4, the address, is omitted (which makes the columns
3362 not line up too nicely with the headers, but the effect
3363 is relatively readable). */
3364 if (addressprint)
3365 ui_out_field_skip (uiout, "addr");
3366 annotate_field (5);
3367 if (b->exec_pathname != NULL)
3368 {
3369 ui_out_text (uiout, "program \"");
3370 ui_out_field_string (uiout, "what", b->exec_pathname);
3371 ui_out_text (uiout, "\" ");
3372 }
3373 break;
3374
3375 case bp_catch_catch:
3376 /* Field 4, the address, is omitted (which makes the columns
3377 not line up too nicely with the headers, but the effect
3378 is relatively readable). */
3379 if (addressprint)
3380 ui_out_field_skip (uiout, "addr");
3381 annotate_field (5);
3382 ui_out_field_string (uiout, "what", "exception catch");
3383 ui_out_spaces (uiout, 1);
3384 break;
3385
3386 case bp_catch_throw:
3387 /* Field 4, the address, is omitted (which makes the columns
3388 not line up too nicely with the headers, but the effect
3389 is relatively readable). */
3390 if (addressprint)
3391 ui_out_field_skip (uiout, "addr");
3392 annotate_field (5);
3393 ui_out_field_string (uiout, "what", "exception throw");
3394 ui_out_spaces (uiout, 1);
3395 break;
3396
3397 case bp_breakpoint:
3398 case bp_hardware_breakpoint:
3399 case bp_until:
3400 case bp_finish:
3401 case bp_longjmp:
3402 case bp_longjmp_resume:
3403 case bp_step_resume:
3404 case bp_through_sigtramp:
3405 case bp_watchpoint_scope:
3406 case bp_call_dummy:
3407 case bp_shlib_event:
3408 case bp_thread_event:
3409 case bp_overlay_event:
3410 if (addressprint)
3411 {
3412 annotate_field (4);
3413 ui_out_field_core_addr (uiout, "addr", b->address);
3414 }
3415 annotate_field (5);
3416 *last_addr = b->address;
3417 if (b->source_file)
3418 {
3419 sym = find_pc_sect_function (b->address, b->section);
3420 if (sym)
3421 {
3422 ui_out_text (uiout, "in ");
3423 ui_out_field_string (uiout, "func",
3424 SYMBOL_PRINT_NAME (sym));
3425 ui_out_wrap_hint (uiout, wrap_indent);
3426 ui_out_text (uiout, " at ");
3427 }
3428 ui_out_field_string (uiout, "file", b->source_file);
3429 ui_out_text (uiout, ":");
3430 ui_out_field_int (uiout, "line", b->line_number);
3431 }
3432 else
3433 {
3434 print_address_symbolic (b->address, stb->stream, demangle, "");
3435 ui_out_field_stream (uiout, "at", stb);
3436 }
3437 break;
3438 }
3439
3440 if (b->thread != -1)
3441 {
3442 /* FIXME: This seems to be redundant and lost here; see the
3443 "stop only in" line a little further down. */
3444 ui_out_text (uiout, " thread ");
3445 ui_out_field_int (uiout, "thread", b->thread);
3446 }
3447
3448 ui_out_text (uiout, "\n");
3449
3450 if (frame_id_p (b->frame_id))
3451 {
3452 annotate_field (6);
3453 ui_out_text (uiout, "\tstop only in stack frame at ");
3454 /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside
3455 the frame ID. */
3456 ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr);
3457 ui_out_text (uiout, "\n");
3458 }
3459
3460 if (b->cond)
3461 {
3462 annotate_field (7);
3463 ui_out_text (uiout, "\tstop only if ");
3464 print_expression (b->cond, stb->stream);
3465 ui_out_field_stream (uiout, "cond", stb);
3466 ui_out_text (uiout, "\n");
3467 }
3468
3469 if (b->thread != -1)
3470 {
3471 /* FIXME should make an annotation for this */
3472 ui_out_text (uiout, "\tstop only in thread ");
3473 ui_out_field_int (uiout, "thread", b->thread);
3474 ui_out_text (uiout, "\n");
3475 }
3476
3477 if (show_breakpoint_hit_counts && b->hit_count)
3478 {
3479 /* FIXME should make an annotation for this */
3480 if (ep_is_catchpoint (b))
3481 ui_out_text (uiout, "\tcatchpoint");
3482 else
3483 ui_out_text (uiout, "\tbreakpoint");
3484 ui_out_text (uiout, " already hit ");
3485 ui_out_field_int (uiout, "times", b->hit_count);
3486 if (b->hit_count == 1)
3487 ui_out_text (uiout, " time\n");
3488 else
3489 ui_out_text (uiout, " times\n");
3490 }
3491
3492 /* Output the count also if it is zero, but only if this is
3493 mi. FIXME: Should have a better test for this. */
3494 if (ui_out_is_mi_like_p (uiout))
3495 if (show_breakpoint_hit_counts && b->hit_count == 0)
3496 ui_out_field_int (uiout, "times", b->hit_count);
3497
3498 if (b->ignore_count)
3499 {
3500 annotate_field (8);
3501 ui_out_text (uiout, "\tignore next ");
3502 ui_out_field_int (uiout, "ignore", b->ignore_count);
3503 ui_out_text (uiout, " hits\n");
3504 }
3505
3506 if ((l = b->commands))
3507 {
3508 struct cleanup *script_chain;
3509
3510 annotate_field (9);
3511 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script");
3512 print_command_lines (uiout, l, 4);
3513 do_cleanups (script_chain);
3514 }
3515 do_cleanups (bkpt_chain);
3516 do_cleanups (old_chain);
3517 }
3518
3519 struct captured_breakpoint_query_args
3520 {
3521 int bnum;
3522 };
3523
3524 static int
3525 do_captured_breakpoint_query (struct ui_out *uiout, void *data)
3526 {
3527 struct captured_breakpoint_query_args *args = data;
3528 struct breakpoint *b;
3529 CORE_ADDR dummy_addr = 0;
3530 ALL_BREAKPOINTS (b)
3531 {
3532 if (args->bnum == b->number)
3533 {
3534 print_one_breakpoint (b, &dummy_addr);
3535 return GDB_RC_OK;
3536 }
3537 }
3538 return GDB_RC_NONE;
3539 }
3540
3541 enum gdb_rc
3542 gdb_breakpoint_query (struct ui_out *uiout, int bnum)
3543 {
3544 struct captured_breakpoint_query_args args;
3545 args.bnum = bnum;
3546 /* For the moment we don't trust print_one_breakpoint() to not throw
3547 an error. */
3548 return catch_exceptions (uiout, do_captured_breakpoint_query, &args,
3549 NULL, RETURN_MASK_ALL);
3550 }
3551
3552 /* Return non-zero if B is user settable (breakpoints, watchpoints,
3553 catchpoints, et.al.). */
3554
3555 static int
3556 user_settable_breakpoint (const struct breakpoint *b)
3557 {
3558 return (b->type == bp_breakpoint
3559 || b->type == bp_catch_load
3560 || b->type == bp_catch_unload
3561 || b->type == bp_catch_fork
3562 || b->type == bp_catch_vfork
3563 || b->type == bp_catch_exec
3564 || b->type == bp_catch_catch
3565 || b->type == bp_catch_throw
3566 || b->type == bp_hardware_breakpoint
3567 || b->type == bp_watchpoint
3568 || b->type == bp_read_watchpoint
3569 || b->type == bp_access_watchpoint
3570 || b->type == bp_hardware_watchpoint);
3571 }
3572
3573 /* Print information on user settable breakpoint (watchpoint, etc)
3574 number BNUM. If BNUM is -1 print all user settable breakpoints.
3575 If ALLFLAG is non-zero, include non- user settable breakpoints. */
3576
3577 static void
3578 breakpoint_1 (int bnum, int allflag)
3579 {
3580 struct breakpoint *b;
3581 CORE_ADDR last_addr = (CORE_ADDR) -1;
3582 int nr_printable_breakpoints;
3583 struct cleanup *bkpttbl_chain;
3584
3585 /* Compute the number of rows in the table. */
3586 nr_printable_breakpoints = 0;
3587 ALL_BREAKPOINTS (b)
3588 if (bnum == -1
3589 || bnum == b->number)
3590 {
3591 if (allflag || user_settable_breakpoint (b))
3592 nr_printable_breakpoints++;
3593 }
3594
3595 if (addressprint)
3596 bkpttbl_chain
3597 = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints,
3598 "BreakpointTable");
3599 else
3600 bkpttbl_chain
3601 = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints,
3602 "BreakpointTable");
3603
3604 if (nr_printable_breakpoints > 0)
3605 annotate_breakpoints_headers ();
3606 if (nr_printable_breakpoints > 0)
3607 annotate_field (0);
3608 ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */
3609 if (nr_printable_breakpoints > 0)
3610 annotate_field (1);
3611 ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */
3612 if (nr_printable_breakpoints > 0)
3613 annotate_field (2);
3614 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */
3615 if (nr_printable_breakpoints > 0)
3616 annotate_field (3);
3617 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */
3618 if (addressprint)
3619 {
3620 if (nr_printable_breakpoints > 0)
3621 annotate_field (4);
3622 if (TARGET_ADDR_BIT <= 32)
3623 ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */
3624 else
3625 ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */
3626 }
3627 if (nr_printable_breakpoints > 0)
3628 annotate_field (5);
3629 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */
3630 ui_out_table_body (uiout);
3631 if (nr_printable_breakpoints > 0)
3632 annotate_breakpoints_table ();
3633
3634 ALL_BREAKPOINTS (b)
3635 if (bnum == -1
3636 || bnum == b->number)
3637 {
3638 /* We only print out user settable breakpoints unless the
3639 allflag is set. */
3640 if (allflag || user_settable_breakpoint (b))
3641 print_one_breakpoint (b, &last_addr);
3642 }
3643
3644 do_cleanups (bkpttbl_chain);
3645
3646 if (nr_printable_breakpoints == 0)
3647 {
3648 if (bnum == -1)
3649 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n");
3650 else
3651 ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n",
3652 bnum);
3653 }
3654 else
3655 {
3656 /* Compare against (CORE_ADDR)-1 in case some compiler decides
3657 that a comparison of an unsigned with -1 is always false. */
3658 if (last_addr != (CORE_ADDR) -1)
3659 set_next_address (last_addr);
3660 }
3661
3662 /* FIXME? Should this be moved up so that it is only called when
3663 there have been breakpoints? */
3664 annotate_breakpoints_table_end ();
3665 }
3666
3667 static void
3668 breakpoints_info (char *bnum_exp, int from_tty)
3669 {
3670 int bnum = -1;
3671
3672 if (bnum_exp)
3673 bnum = parse_and_eval_long (bnum_exp);
3674
3675 breakpoint_1 (bnum, 0);
3676 }
3677
3678 static void
3679 maintenance_info_breakpoints (char *bnum_exp, int from_tty)
3680 {
3681 int bnum = -1;
3682
3683 if (bnum_exp)
3684 bnum = parse_and_eval_long (bnum_exp);
3685
3686 breakpoint_1 (bnum, 1);
3687 }
3688
3689 /* Print a message describing any breakpoints set at PC. */
3690
3691 static void
3692 describe_other_breakpoints (CORE_ADDR pc, asection *section)
3693 {
3694 int others = 0;
3695 struct breakpoint *b;
3696
3697 ALL_BREAKPOINTS (b)
3698 if (b->address == pc) /* address match / overlay match */
3699 if (!overlay_debugging || b->section == section)
3700 others++;
3701 if (others > 0)
3702 {
3703 printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : "");
3704 ALL_BREAKPOINTS (b)
3705 if (b->address == pc) /* address match / overlay match */
3706 if (!overlay_debugging || b->section == section)
3707 {
3708 others--;
3709 printf_filtered ("%d%s%s ",
3710 b->number,
3711 ((b->enable_state == bp_disabled ||
3712 b->enable_state == bp_shlib_disabled ||
3713 b->enable_state == bp_call_disabled)
3714 ? " (disabled)"
3715 : b->enable_state == bp_permanent
3716 ? " (permanent)"
3717 : ""),
3718 (others > 1) ? ","
3719 : ((others == 1) ? " and" : ""));
3720 }
3721 printf_filtered ("also set at pc ");
3722 print_address_numeric (pc, 1, gdb_stdout);
3723 printf_filtered (".\n");
3724 }
3725 }
3726 \f
3727 /* Set the default place to put a breakpoint
3728 for the `break' command with no arguments. */
3729
3730 void
3731 set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab,
3732 int line)
3733 {
3734 default_breakpoint_valid = valid;
3735 default_breakpoint_address = addr;
3736 default_breakpoint_symtab = symtab;
3737 default_breakpoint_line = line;
3738 }
3739
3740 /* Return true iff it is meaningful to use the address member of
3741 BPT. For some breakpoint types, the address member is irrelevant
3742 and it makes no sense to attempt to compare it to other addresses
3743 (or use it for any other purpose either).
3744
3745 More specifically, each of the following breakpoint types will always
3746 have a zero valued address and we don't want check_duplicates() to mark
3747 breakpoints of any of these types to be a duplicate of an actual
3748 breakpoint at address zero:
3749
3750 bp_watchpoint
3751 bp_hardware_watchpoint
3752 bp_read_watchpoint
3753 bp_access_watchpoint
3754 bp_catch_exec
3755 bp_longjmp_resume
3756 bp_catch_fork
3757 bp_catch_vork */
3758
3759 static int
3760 breakpoint_address_is_meaningful (struct breakpoint *bpt)
3761 {
3762 enum bptype type = bpt->type;
3763
3764 return (type != bp_watchpoint
3765 && type != bp_hardware_watchpoint
3766 && type != bp_read_watchpoint
3767 && type != bp_access_watchpoint
3768 && type != bp_catch_exec
3769 && type != bp_longjmp_resume
3770 && type != bp_catch_fork
3771 && type != bp_catch_vfork);
3772 }
3773
3774 /* Rescan breakpoints at the same address and section as BPT,
3775 marking the first one as "first" and any others as "duplicates".
3776 This is so that the bpt instruction is only inserted once.
3777 If we have a permanent breakpoint at the same place as BPT, make
3778 that one the official one, and the rest as duplicates. */
3779
3780 static void
3781 check_duplicates (struct breakpoint *bpt)
3782 {
3783 struct breakpoint *b;
3784 int count = 0;
3785 struct breakpoint *perm_bp = 0;
3786 CORE_ADDR address = bpt->address;
3787 asection *section = bpt->section;
3788
3789 if (! breakpoint_address_is_meaningful (bpt))
3790 return;
3791
3792 ALL_BREAKPOINTS (b)
3793 if (b->enable_state != bp_disabled
3794 && b->enable_state != bp_shlib_disabled
3795 && b->enable_state != bp_call_disabled
3796 && b->address == address /* address / overlay match */
3797 && (!overlay_debugging || b->section == section)
3798 && breakpoint_address_is_meaningful (b))
3799 {
3800 /* Have we found a permanent breakpoint? */
3801 if (b->enable_state == bp_permanent)
3802 {
3803 perm_bp = b;
3804 break;
3805 }
3806
3807 count++;
3808 b->duplicate = count > 1;
3809 }
3810
3811 /* If we found a permanent breakpoint at this address, go over the
3812 list again and declare all the other breakpoints there to be the
3813 duplicates. */
3814 if (perm_bp)
3815 {
3816 perm_bp->duplicate = 0;
3817
3818 /* Permanent breakpoint should always be inserted. */
3819 if (! perm_bp->inserted)
3820 internal_error (__FILE__, __LINE__,
3821 "allegedly permanent breakpoint is not "
3822 "actually inserted");
3823
3824 ALL_BREAKPOINTS (b)
3825 if (b != perm_bp)
3826 {
3827 if (b->inserted)
3828 internal_error (__FILE__, __LINE__,
3829 "another breakpoint was inserted on top of "
3830 "a permanent breakpoint");
3831
3832 if (b->enable_state != bp_disabled
3833 && b->enable_state != bp_shlib_disabled
3834 && b->enable_state != bp_call_disabled
3835 && b->address == address /* address / overlay match */
3836 && (!overlay_debugging || b->section == section)
3837 && breakpoint_address_is_meaningful (b))
3838 b->duplicate = 1;
3839 }
3840 }
3841 }
3842
3843 /* set_raw_breakpoint() is a low level routine for allocating and
3844 partially initializing a breakpoint of type BPTYPE. The newly
3845 created breakpoint's address, section, source file name, and line
3846 number are provided by SAL. The newly created and partially
3847 initialized breakpoint is added to the breakpoint chain and
3848 is also returned as the value of this function.
3849
3850 It is expected that the caller will complete the initialization of
3851 the newly created breakpoint struct as well as output any status
3852 information regarding the creation of a new breakpoint. In
3853 particular, set_raw_breakpoint() does NOT set the breakpoint
3854 number! Care should be taken to not allow an error() to occur
3855 prior to completing the initialization of the breakpoint. If this
3856 should happen, a bogus breakpoint will be left on the chain. */
3857
3858 struct breakpoint *
3859 set_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype)
3860 {
3861 struct breakpoint *b, *b1;
3862
3863 b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
3864 memset (b, 0, sizeof (*b));
3865 b->address = sal.pc;
3866 if (sal.symtab == NULL)
3867 b->source_file = NULL;
3868 else
3869 b->source_file = savestring (sal.symtab->filename,
3870 strlen (sal.symtab->filename));
3871 b->section = sal.section;
3872 b->type = bptype;
3873 b->language = current_language->la_language;
3874 b->input_radix = input_radix;
3875 b->thread = -1;
3876 b->line_number = sal.line;
3877 b->enable_state = bp_enabled;
3878 b->next = 0;
3879 b->silent = 0;
3880 b->ignore_count = 0;
3881 b->commands = NULL;
3882 b->frame_id = null_frame_id;
3883 b->dll_pathname = NULL;
3884 b->triggered_dll_pathname = NULL;
3885 b->forked_inferior_pid = 0;
3886 b->exec_pathname = NULL;
3887 b->ops = NULL;
3888
3889 /* Add this breakpoint to the end of the chain
3890 so that a list of breakpoints will come out in order
3891 of increasing numbers. */
3892
3893 b1 = breakpoint_chain;
3894 if (b1 == 0)
3895 breakpoint_chain = b;
3896 else
3897 {
3898 while (b1->next)
3899 b1 = b1->next;
3900 b1->next = b;
3901 }
3902
3903 check_duplicates (b);
3904 breakpoints_changed ();
3905
3906 return b;
3907 }
3908
3909
3910 /* Note that the breakpoint object B describes a permanent breakpoint
3911 instruction, hard-wired into the inferior's code. */
3912 void
3913 make_breakpoint_permanent (struct breakpoint *b)
3914 {
3915 b->enable_state = bp_permanent;
3916
3917 /* By definition, permanent breakpoints are already present in the code. */
3918 b->inserted = 1;
3919 }
3920
3921 static struct breakpoint *
3922 create_internal_breakpoint (CORE_ADDR address, enum bptype type)
3923 {
3924 static int internal_breakpoint_number = -1;
3925 struct symtab_and_line sal;
3926 struct breakpoint *b;
3927
3928 init_sal (&sal); /* initialize to zeroes */
3929
3930 sal.pc = address;
3931 sal.section = find_pc_overlay (sal.pc);
3932
3933 b = set_raw_breakpoint (sal, type);
3934 b->number = internal_breakpoint_number--;
3935 b->disposition = disp_donttouch;
3936
3937 return b;
3938 }
3939
3940
3941 static void
3942 create_longjmp_breakpoint (char *func_name)
3943 {
3944 struct breakpoint *b;
3945 struct minimal_symbol *m;
3946
3947 if (func_name == NULL)
3948 b = create_internal_breakpoint (0, bp_longjmp_resume);
3949 else
3950 {
3951 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
3952 return;
3953
3954 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp);
3955 }
3956
3957 b->enable_state = bp_disabled;
3958 b->silent = 1;
3959 if (func_name)
3960 b->addr_string = xstrdup (func_name);
3961 }
3962
3963 /* Call this routine when stepping and nexting to enable a breakpoint
3964 if we do a longjmp(). When we hit that breakpoint, call
3965 set_longjmp_resume_breakpoint() to figure out where we are going. */
3966
3967 void
3968 enable_longjmp_breakpoint (void)
3969 {
3970 struct breakpoint *b;
3971
3972 ALL_BREAKPOINTS (b)
3973 if (b->type == bp_longjmp)
3974 {
3975 b->enable_state = bp_enabled;
3976 check_duplicates (b);
3977 }
3978 }
3979
3980 void
3981 disable_longjmp_breakpoint (void)
3982 {
3983 struct breakpoint *b;
3984
3985 ALL_BREAKPOINTS (b)
3986 if (b->type == bp_longjmp
3987 || b->type == bp_longjmp_resume)
3988 {
3989 b->enable_state = bp_disabled;
3990 check_duplicates (b);
3991 }
3992 }
3993
3994 static void
3995 create_overlay_event_breakpoint (char *func_name)
3996 {
3997 struct breakpoint *b;
3998 struct minimal_symbol *m;
3999
4000 if ((m = lookup_minimal_symbol_text (func_name, NULL, NULL)) == NULL)
4001 return;
4002
4003 b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m),
4004 bp_overlay_event);
4005 b->addr_string = xstrdup (func_name);
4006
4007 if (overlay_debugging == ovly_auto)
4008 {
4009 b->enable_state = bp_enabled;
4010 overlay_events_enabled = 1;
4011 }
4012 else
4013 {
4014 b->enable_state = bp_disabled;
4015 overlay_events_enabled = 0;
4016 }
4017 }
4018
4019 void
4020 enable_overlay_breakpoints (void)
4021 {
4022 struct breakpoint *b;
4023
4024 ALL_BREAKPOINTS (b)
4025 if (b->type == bp_overlay_event)
4026 {
4027 b->enable_state = bp_enabled;
4028 check_duplicates (b);
4029 overlay_events_enabled = 1;
4030 }
4031 }
4032
4033 void
4034 disable_overlay_breakpoints (void)
4035 {
4036 struct breakpoint *b;
4037
4038 ALL_BREAKPOINTS (b)
4039 if (b->type == bp_overlay_event)
4040 {
4041 b->enable_state = bp_disabled;
4042 check_duplicates (b);
4043 overlay_events_enabled = 0;
4044 }
4045 }
4046
4047 struct breakpoint *
4048 create_thread_event_breakpoint (CORE_ADDR address)
4049 {
4050 struct breakpoint *b;
4051
4052 b = create_internal_breakpoint (address, bp_thread_event);
4053
4054 b->enable_state = bp_enabled;
4055 /* addr_string has to be used or breakpoint_re_set will delete me. */
4056 xasprintf (&b->addr_string, "*0x%s", paddr (b->address));
4057
4058 return b;
4059 }
4060
4061 void
4062 remove_thread_event_breakpoints (void)
4063 {
4064 struct breakpoint *b, *temp;
4065
4066 ALL_BREAKPOINTS_SAFE (b, temp)
4067 if (b->type == bp_thread_event)
4068 delete_breakpoint (b);
4069 }
4070
4071 #ifdef SOLIB_ADD
4072 void
4073 remove_solib_event_breakpoints (void)
4074 {
4075 struct breakpoint *b, *temp;
4076
4077 ALL_BREAKPOINTS_SAFE (b, temp)
4078 if (b->type == bp_shlib_event)
4079 delete_breakpoint (b);
4080 }
4081
4082 struct breakpoint *
4083 create_solib_event_breakpoint (CORE_ADDR address)
4084 {
4085 struct breakpoint *b;
4086
4087 b = create_internal_breakpoint (address, bp_shlib_event);
4088 return b;
4089 }
4090
4091 /* Disable any breakpoints that are on code in shared libraries. Only
4092 apply to enabled breakpoints, disabled ones can just stay disabled. */
4093
4094 void
4095 disable_breakpoints_in_shlibs (int silent)
4096 {
4097 struct breakpoint *b;
4098 int disabled_shlib_breaks = 0;
4099
4100 /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */
4101 ALL_BREAKPOINTS (b)
4102 {
4103 #if defined (PC_SOLIB)
4104 if (((b->type == bp_breakpoint) ||
4105 (b->type == bp_hardware_breakpoint)) &&
4106 b->enable_state == bp_enabled &&
4107 !b->duplicate &&
4108 PC_SOLIB (b->address))
4109 {
4110 b->enable_state = bp_shlib_disabled;
4111 if (!silent)
4112 {
4113 if (!disabled_shlib_breaks)
4114 {
4115 target_terminal_ours_for_output ();
4116 warning ("Temporarily disabling shared library breakpoints:");
4117 }
4118 disabled_shlib_breaks = 1;
4119 warning ("breakpoint #%d ", b->number);
4120 }
4121 }
4122 #endif
4123 }
4124 }
4125
4126 /* Try to reenable any breakpoints in shared libraries. */
4127 void
4128 re_enable_breakpoints_in_shlibs (void)
4129 {
4130 struct breakpoint *b;
4131
4132 ALL_BREAKPOINTS (b)
4133 if (b->enable_state == bp_shlib_disabled)
4134 {
4135 char buf[1];
4136
4137 /* Do not reenable the breakpoint if the shared library
4138 is still not mapped in. */
4139 if (target_read_memory (b->address, buf, 1) == 0)
4140 b->enable_state = bp_enabled;
4141 }
4142 }
4143
4144 #endif
4145
4146 static void
4147 solib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname,
4148 char *cond_string, enum bptype bp_kind)
4149 {
4150 struct breakpoint *b;
4151 struct symtabs_and_lines sals;
4152 struct cleanup *old_chain;
4153 struct cleanup *canonical_strings_chain = NULL;
4154 char *addr_start = hookname;
4155 char *addr_end = NULL;
4156 char **canonical = (char **) NULL;
4157 int thread = -1; /* All threads. */
4158
4159 /* Set a breakpoint on the specified hook. */
4160 sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical);
4161 addr_end = hookname;
4162
4163 if (sals.nelts == 0)
4164 {
4165 warning ("Unable to set a breakpoint on dynamic linker callback.");
4166 warning ("Suggest linking with /opt/langtools/lib/end.o.");
4167 warning ("GDB will be unable to track shl_load/shl_unload calls");
4168 return;
4169 }
4170 if (sals.nelts != 1)
4171 {
4172 warning ("Unable to set unique breakpoint on dynamic linker callback.");
4173 warning ("GDB will be unable to track shl_load/shl_unload calls");
4174 return;
4175 }
4176
4177 /* Make sure that all storage allocated in decode_line_1 gets freed
4178 in case the following errors out. */
4179 old_chain = make_cleanup (xfree, sals.sals);
4180 if (canonical != (char **) NULL)
4181 {
4182 make_cleanup (xfree, canonical);
4183 canonical_strings_chain = make_cleanup (null_cleanup, 0);
4184 if (canonical[0] != NULL)
4185 make_cleanup (xfree, canonical[0]);
4186 }
4187
4188 resolve_sal_pc (&sals.sals[0]);
4189
4190 /* Remove the canonical strings from the cleanup, they are needed below. */
4191 if (canonical != (char **) NULL)
4192 discard_cleanups (canonical_strings_chain);
4193
4194 b = set_raw_breakpoint (sals.sals[0], bp_kind);
4195 set_breakpoint_count (breakpoint_count + 1);
4196 b->number = breakpoint_count;
4197 b->cond = NULL;
4198 b->cond_string = (cond_string == NULL) ?
4199 NULL : savestring (cond_string, strlen (cond_string));
4200 b->thread = thread;
4201
4202 if (canonical != (char **) NULL && canonical[0] != NULL)
4203 b->addr_string = canonical[0];
4204 else if (addr_start)
4205 b->addr_string = savestring (addr_start, addr_end - addr_start);
4206
4207 b->enable_state = bp_enabled;
4208 b->disposition = tempflag ? disp_del : disp_donttouch;
4209
4210 if (dll_pathname == NULL)
4211 b->dll_pathname = NULL;
4212 else
4213 {
4214 b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1);
4215 strcpy (b->dll_pathname, dll_pathname);
4216 }
4217
4218 mention (b);
4219 do_cleanups (old_chain);
4220 }
4221
4222 void
4223 create_solib_load_event_breakpoint (char *hookname, int tempflag,
4224 char *dll_pathname, char *cond_string)
4225 {
4226 solib_load_unload_1 (hookname, tempflag, dll_pathname,
4227 cond_string, bp_catch_load);
4228 }
4229
4230 void
4231 create_solib_unload_event_breakpoint (char *hookname, int tempflag,
4232 char *dll_pathname, char *cond_string)
4233 {
4234 solib_load_unload_1 (hookname,tempflag, dll_pathname,
4235 cond_string, bp_catch_unload);
4236 }
4237
4238 static void
4239 create_fork_vfork_event_catchpoint (int tempflag, char *cond_string,
4240 enum bptype bp_kind)
4241 {
4242 struct symtab_and_line sal;
4243 struct breakpoint *b;
4244 int thread = -1; /* All threads. */
4245
4246 init_sal (&sal);
4247 sal.pc = 0;
4248 sal.symtab = NULL;
4249 sal.line = 0;
4250
4251 b = set_raw_breakpoint (sal, bp_kind);
4252 set_breakpoint_count (breakpoint_count + 1);
4253 b->number = breakpoint_count;
4254 b->cond = NULL;
4255 b->cond_string = (cond_string == NULL) ?
4256 NULL : savestring (cond_string, strlen (cond_string));
4257 b->thread = thread;
4258 b->addr_string = NULL;
4259 b->enable_state = bp_enabled;
4260 b->disposition = tempflag ? disp_del : disp_donttouch;
4261 b->forked_inferior_pid = 0;
4262
4263 mention (b);
4264 }
4265
4266 void
4267 create_fork_event_catchpoint (int tempflag, char *cond_string)
4268 {
4269 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork);
4270 }
4271
4272 void
4273 create_vfork_event_catchpoint (int tempflag, char *cond_string)
4274 {
4275 create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork);
4276 }
4277
4278 void
4279 create_exec_event_catchpoint (int tempflag, char *cond_string)
4280 {
4281 struct symtab_and_line sal;
4282 struct breakpoint *b;
4283 int thread = -1; /* All threads. */
4284
4285 init_sal (&sal);
4286 sal.pc = 0;
4287 sal.symtab = NULL;
4288 sal.line = 0;
4289
4290 b = set_raw_breakpoint (sal, bp_catch_exec);
4291 set_breakpoint_count (breakpoint_count + 1);
4292 b->number = breakpoint_count;
4293 b->cond = NULL;
4294 b->cond_string = (cond_string == NULL) ?
4295 NULL : savestring (cond_string, strlen (cond_string));
4296 b->thread = thread;
4297 b->addr_string = NULL;
4298 b->enable_state = bp_enabled;
4299 b->disposition = tempflag ? disp_del : disp_donttouch;
4300
4301 mention (b);
4302 }
4303
4304 static int
4305 hw_breakpoint_used_count (void)
4306 {
4307 struct breakpoint *b;
4308 int i = 0;
4309
4310 ALL_BREAKPOINTS (b)
4311 {
4312 if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled)
4313 i++;
4314 }
4315
4316 return i;
4317 }
4318
4319 static int
4320 hw_watchpoint_used_count (enum bptype type, int *other_type_used)
4321 {
4322 struct breakpoint *b;
4323 int i = 0;
4324
4325 *other_type_used = 0;
4326 ALL_BREAKPOINTS (b)
4327 {
4328 if (b->enable_state == bp_enabled)
4329 {
4330 if (b->type == type)
4331 i++;
4332 else if ((b->type == bp_hardware_watchpoint ||
4333 b->type == bp_read_watchpoint ||
4334 b->type == bp_access_watchpoint)
4335 && b->enable_state == bp_enabled)
4336 *other_type_used = 1;
4337 }
4338 }
4339 return i;
4340 }
4341
4342 /* Call this after hitting the longjmp() breakpoint. Use this to set
4343 a new breakpoint at the target of the jmp_buf.
4344
4345 FIXME - This ought to be done by setting a temporary breakpoint
4346 that gets deleted automatically... */
4347
4348 void
4349 set_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id)
4350 {
4351 struct breakpoint *b;
4352
4353 ALL_BREAKPOINTS (b)
4354 if (b->type == bp_longjmp_resume)
4355 {
4356 b->address = pc;
4357 b->enable_state = bp_enabled;
4358 b->frame_id = frame_id;
4359 check_duplicates (b);
4360 return;
4361 }
4362 }
4363
4364 void
4365 disable_watchpoints_before_interactive_call_start (void)
4366 {
4367 struct breakpoint *b;
4368
4369 ALL_BREAKPOINTS (b)
4370 {
4371 if (((b->type == bp_watchpoint)
4372 || (b->type == bp_hardware_watchpoint)
4373 || (b->type == bp_read_watchpoint)
4374 || (b->type == bp_access_watchpoint)
4375 || ep_is_exception_catchpoint (b))
4376 && (b->enable_state == bp_enabled))
4377 {
4378 b->enable_state = bp_call_disabled;
4379 check_duplicates (b);
4380 }
4381 }
4382 }
4383
4384 void
4385 enable_watchpoints_after_interactive_call_stop (void)
4386 {
4387 struct breakpoint *b;
4388
4389 ALL_BREAKPOINTS (b)
4390 {
4391 if (((b->type == bp_watchpoint)
4392 || (b->type == bp_hardware_watchpoint)
4393 || (b->type == bp_read_watchpoint)
4394 || (b->type == bp_access_watchpoint)
4395 || ep_is_exception_catchpoint (b))
4396 && (b->enable_state == bp_call_disabled))
4397 {
4398 b->enable_state = bp_enabled;
4399 check_duplicates (b);
4400 }
4401 }
4402 }
4403
4404
4405 /* Set a breakpoint that will evaporate an end of command
4406 at address specified by SAL.
4407 Restrict it to frame FRAME if FRAME is nonzero. */
4408
4409 struct breakpoint *
4410 set_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id,
4411 enum bptype type)
4412 {
4413 struct breakpoint *b;
4414 b = set_raw_breakpoint (sal, type);
4415 b->enable_state = bp_enabled;
4416 b->disposition = disp_donttouch;
4417 b->frame_id = frame_id;
4418
4419 /* If we're debugging a multi-threaded program, then we
4420 want momentary breakpoints to be active in only a
4421 single thread of control. */
4422 if (in_thread_list (inferior_ptid))
4423 b->thread = pid_to_thread_id (inferior_ptid);
4424
4425 return b;
4426 }
4427 \f
4428
4429 /* Tell the user we have just set a breakpoint B. */
4430
4431 static void
4432 mention (struct breakpoint *b)
4433 {
4434 int say_where = 0;
4435 struct cleanup *old_chain, *ui_out_chain;
4436 struct ui_stream *stb;
4437
4438 stb = ui_out_stream_new (uiout);
4439 old_chain = make_cleanup_ui_out_stream_delete (stb);
4440
4441 /* FIXME: This is misplaced; mention() is called by things (like hitting a
4442 watchpoint) other than breakpoint creation. It should be possible to
4443 clean this up and at the same time replace the random calls to
4444 breakpoint_changed with this hook, as has already been done for
4445 delete_breakpoint_hook and so on. */
4446 if (create_breakpoint_hook)
4447 create_breakpoint_hook (b);
4448 breakpoint_create_event (b->number);
4449
4450 if (b->ops != NULL && b->ops->print_mention != NULL)
4451 b->ops->print_mention (b);
4452 else
4453 switch (b->type)
4454 {
4455 case bp_none:
4456 printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number);
4457 break;
4458 case bp_watchpoint:
4459 ui_out_text (uiout, "Watchpoint ");
4460 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4461 ui_out_field_int (uiout, "number", b->number);
4462 ui_out_text (uiout, ": ");
4463 print_expression (b->exp, stb->stream);
4464 ui_out_field_stream (uiout, "exp", stb);
4465 do_cleanups (ui_out_chain);
4466 break;
4467 case bp_hardware_watchpoint:
4468 ui_out_text (uiout, "Hardware watchpoint ");
4469 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt");
4470 ui_out_field_int (uiout, "number", b->number);
4471 ui_out_text (uiout, ": ");
4472 print_expression (b->exp, stb->stream);
4473 ui_out_field_stream (uiout, "exp", stb);
4474 do_cleanups (ui_out_chain);
4475 break;
4476 case bp_read_watchpoint:
4477 ui_out_text (uiout, "Hardware read watchpoint ");
4478 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt");
4479 ui_out_field_int (uiout, "number", b->number);
4480 ui_out_text (uiout, ": ");
4481 print_expression (b->exp, stb->stream);
4482 ui_out_field_stream (uiout, "exp", stb);
4483 do_cleanups (ui_out_chain);
4484 break;
4485 case bp_access_watchpoint:
4486 ui_out_text (uiout, "Hardware access (read/write) watchpoint ");
4487 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt");
4488 ui_out_field_int (uiout, "number", b->number);
4489 ui_out_text (uiout, ": ");
4490 print_expression (b->exp, stb->stream);
4491 ui_out_field_stream (uiout, "exp", stb);
4492 do_cleanups (ui_out_chain);
4493 break;
4494 case bp_breakpoint:
4495 if (ui_out_is_mi_like_p (uiout))
4496 {
4497 say_where = 0;
4498 break;
4499 }
4500 printf_filtered ("Breakpoint %d", b->number);
4501 say_where = 1;
4502 break;
4503 case bp_hardware_breakpoint:
4504 if (ui_out_is_mi_like_p (uiout))
4505 {
4506 say_where = 0;
4507 break;
4508 }
4509 printf_filtered ("Hardware assisted breakpoint %d", b->number);
4510 say_where = 1;
4511 break;
4512 case bp_catch_load:
4513 case bp_catch_unload:
4514 printf_filtered ("Catchpoint %d (%s %s)",
4515 b->number,
4516 (b->type == bp_catch_load) ? "load" : "unload",
4517 (b->dll_pathname != NULL) ?
4518 b->dll_pathname : "<any library>");
4519 break;
4520 case bp_catch_fork:
4521 case bp_catch_vfork:
4522 printf_filtered ("Catchpoint %d (%s)",
4523 b->number,
4524 (b->type == bp_catch_fork) ? "fork" : "vfork");
4525 break;
4526 case bp_catch_exec:
4527 printf_filtered ("Catchpoint %d (exec)",
4528 b->number);
4529 break;
4530 case bp_catch_catch:
4531 case bp_catch_throw:
4532 printf_filtered ("Catchpoint %d (%s)",
4533 b->number,
4534 (b->type == bp_catch_catch) ? "catch" : "throw");
4535 break;
4536
4537 case bp_until:
4538 case bp_finish:
4539 case bp_longjmp:
4540 case bp_longjmp_resume:
4541 case bp_step_resume:
4542 case bp_through_sigtramp:
4543 case bp_call_dummy:
4544 case bp_watchpoint_scope:
4545 case bp_shlib_event:
4546 case bp_thread_event:
4547 case bp_overlay_event:
4548 break;
4549 }
4550
4551 if (say_where)
4552 {
4553 if (addressprint || b->source_file == NULL)
4554 {
4555 printf_filtered (" at ");
4556 print_address_numeric (b->address, 1, gdb_stdout);
4557 }
4558 if (b->source_file)
4559 printf_filtered (": file %s, line %d.",
4560 b->source_file, b->line_number);
4561 }
4562 do_cleanups (old_chain);
4563 if (ui_out_is_mi_like_p (uiout))
4564 return;
4565 printf_filtered ("\n");
4566 }
4567 \f
4568
4569 /* Add SALS.nelts breakpoints to the breakpoint table. For each
4570 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i],
4571 COND[i] and COND_STRING[i] values.
4572
4573 NOTE: If the function succeeds, the caller is expected to cleanup
4574 the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the
4575 array contents). If the function fails (error() is called), the
4576 caller is expected to cleanups both the ADDR_STRING, COND_STRING,
4577 COND and SALS arrays and each of those arrays contents. */
4578
4579 static void
4580 create_breakpoints (struct symtabs_and_lines sals, char **addr_string,
4581 struct expression **cond, char **cond_string,
4582 enum bptype type, enum bpdisp disposition,
4583 int thread, int ignore_count, int from_tty)
4584 {
4585 if (type == bp_hardware_breakpoint)
4586 {
4587 int i = hw_breakpoint_used_count ();
4588 int target_resources_ok =
4589 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
4590 i + sals.nelts, 0);
4591 if (target_resources_ok == 0)
4592 error ("No hardware breakpoint support in the target.");
4593 else if (target_resources_ok < 0)
4594 error ("Hardware breakpoints used exceeds limit.");
4595 }
4596
4597 /* Now set all the breakpoints. */
4598 {
4599 int i;
4600 for (i = 0; i < sals.nelts; i++)
4601 {
4602 struct breakpoint *b;
4603 struct symtab_and_line sal = sals.sals[i];
4604
4605 if (from_tty)
4606 describe_other_breakpoints (sal.pc, sal.section);
4607
4608 b = set_raw_breakpoint (sal, type);
4609 set_breakpoint_count (breakpoint_count + 1);
4610 b->number = breakpoint_count;
4611 b->cond = cond[i];
4612 b->thread = thread;
4613 if (addr_string[i])
4614 b->addr_string = addr_string[i];
4615 else
4616 /* addr_string has to be used or breakpoint_re_set will delete
4617 me. */
4618 xasprintf (&b->addr_string, "*0x%s", paddr (b->address));
4619 b->cond_string = cond_string[i];
4620 b->ignore_count = ignore_count;
4621 b->enable_state = bp_enabled;
4622 b->disposition = disposition;
4623 mention (b);
4624 }
4625 }
4626 }
4627
4628 /* Parse ARG which is assumed to be a SAL specification possibly
4629 followed by conditionals. On return, SALS contains an array of SAL
4630 addresses found. ADDR_STRING contains a vector of (canonical)
4631 address strings. ARG points to the end of the SAL. */
4632
4633 static void
4634 parse_breakpoint_sals (char **address,
4635 struct symtabs_and_lines *sals,
4636 char ***addr_string)
4637 {
4638 char *addr_start = *address;
4639 *addr_string = NULL;
4640 /* If no arg given, or if first arg is 'if ', use the default
4641 breakpoint. */
4642 if ((*address) == NULL
4643 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2])))
4644 {
4645 if (default_breakpoint_valid)
4646 {
4647 struct symtab_and_line sal;
4648 init_sal (&sal); /* initialize to zeroes */
4649 sals->sals = (struct symtab_and_line *)
4650 xmalloc (sizeof (struct symtab_and_line));
4651 sal.pc = default_breakpoint_address;
4652 sal.line = default_breakpoint_line;
4653 sal.symtab = default_breakpoint_symtab;
4654 sal.section = find_pc_overlay (sal.pc);
4655 sals->sals[0] = sal;
4656 sals->nelts = 1;
4657 }
4658 else
4659 error ("No default breakpoint address now.");
4660 }
4661 else
4662 {
4663 /* Force almost all breakpoints to be in terms of the
4664 current_source_symtab (which is decode_line_1's default). This
4665 should produce the results we want almost all of the time while
4666 leaving default_breakpoint_* alone.
4667 ObjC: However, don't match an Objective-C method name which
4668 may have a '+' or '-' succeeded by a '[' */
4669
4670 struct symtab_and_line cursal = get_current_source_symtab_and_line ();
4671
4672 if (default_breakpoint_valid
4673 && (!cursal.symtab
4674 || ((strchr ("+-", (*address)[0]) != NULL)
4675 && ((*address)[1] != '['))))
4676 *sals = decode_line_1 (address, 1, default_breakpoint_symtab,
4677 default_breakpoint_line, addr_string);
4678 else
4679 *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, addr_string);
4680 }
4681 /* For any SAL that didn't have a canonical string, fill one in. */
4682 if (sals->nelts > 0 && *addr_string == NULL)
4683 *addr_string = xcalloc (sals->nelts, sizeof (char **));
4684 if (addr_start != (*address))
4685 {
4686 int i;
4687 for (i = 0; i < sals->nelts; i++)
4688 {
4689 /* Add the string if not present. */
4690 if ((*addr_string)[i] == NULL)
4691 (*addr_string)[i] = savestring (addr_start, (*address) - addr_start);
4692 }
4693 }
4694 }
4695
4696
4697 /* Convert each SAL into a real PC. Verify that the PC can be
4698 inserted as a breakpoint. If it can't throw an error. */
4699
4700 static void
4701 breakpoint_sals_to_pc (struct symtabs_and_lines *sals,
4702 char *address)
4703 {
4704 int i;
4705 for (i = 0; i < sals->nelts; i++)
4706 {
4707 resolve_sal_pc (&sals->sals[i]);
4708
4709 /* It's possible for the PC to be nonzero, but still an illegal
4710 value on some targets.
4711
4712 For example, on HP-UX if you start gdb, and before running the
4713 inferior you try to set a breakpoint on a shared library function
4714 "foo" where the inferior doesn't call "foo" directly but does
4715 pass its address to another function call, then we do find a
4716 minimal symbol for the "foo", but it's address is invalid.
4717 (Appears to be an index into a table that the loader sets up
4718 when the inferior is run.)
4719
4720 Give the target a chance to bless sals.sals[i].pc before we
4721 try to make a breakpoint for it. */
4722 if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc))
4723 {
4724 if (address == NULL)
4725 error ("Cannot break without a running program.");
4726 else
4727 error ("Cannot break on %s without a running program.",
4728 address);
4729 }
4730 }
4731 }
4732
4733 /* Set a breakpoint according to ARG (function, linenum or *address)
4734 flag: first bit : 0 non-temporary, 1 temporary.
4735 second bit : 0 normal breakpoint, 1 hardware breakpoint. */
4736
4737 static void
4738 break_command_1 (char *arg, int flag, int from_tty)
4739 {
4740 int tempflag, hardwareflag;
4741 struct symtabs_and_lines sals;
4742 struct expression **cond = 0;
4743 /* Pointers in arg to the start, and one past the end, of the
4744 condition. */
4745 char **cond_string = (char **) NULL;
4746 char *addr_start = arg;
4747 char **addr_string;
4748 struct cleanup *old_chain;
4749 struct cleanup *breakpoint_chain = NULL;
4750 int i;
4751 int thread = -1;
4752 int ignore_count = 0;
4753
4754 hardwareflag = flag & BP_HARDWAREFLAG;
4755 tempflag = flag & BP_TEMPFLAG;
4756
4757 sals.sals = NULL;
4758 sals.nelts = 0;
4759 addr_string = NULL;
4760 parse_breakpoint_sals (&arg, &sals, &addr_string);
4761
4762 if (!sals.nelts)
4763 return;
4764
4765 /* Create a chain of things that always need to be cleaned up. */
4766 old_chain = make_cleanup (null_cleanup, 0);
4767
4768 /* Make sure that all storage allocated to SALS gets freed. */
4769 make_cleanup (xfree, sals.sals);
4770
4771 /* Cleanup the addr_string array but not its contents. */
4772 make_cleanup (xfree, addr_string);
4773
4774 /* Allocate space for all the cond expressions. */
4775 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4776 make_cleanup (xfree, cond);
4777
4778 /* Allocate space for all the cond strings. */
4779 cond_string = xcalloc (sals.nelts, sizeof (char **));
4780 make_cleanup (xfree, cond_string);
4781
4782 /* ----------------------------- SNIP -----------------------------
4783 Anything added to the cleanup chain beyond this point is assumed
4784 to be part of a breakpoint. If the breakpoint create succeeds
4785 then the memory is not reclaimed. */
4786 breakpoint_chain = make_cleanup (null_cleanup, 0);
4787
4788 /* Mark the contents of the addr_string for cleanup. These go on
4789 the breakpoint_chain and only occure if the breakpoint create
4790 fails. */
4791 for (i = 0; i < sals.nelts; i++)
4792 {
4793 if (addr_string[i] != NULL)
4794 make_cleanup (xfree, addr_string[i]);
4795 }
4796
4797 /* Resolve all line numbers to PC's and verify that the addresses
4798 are ok for the target. */
4799 breakpoint_sals_to_pc (&sals, addr_start);
4800
4801 /* Verify that condition can be parsed, before setting any
4802 breakpoints. Allocate a separate condition expression for each
4803 breakpoint. */
4804 thread = -1; /* No specific thread yet */
4805 for (i = 0; i < sals.nelts; i++)
4806 {
4807 char *tok = arg;
4808 while (tok && *tok)
4809 {
4810 char *end_tok;
4811 int toklen;
4812 char *cond_start = NULL;
4813 char *cond_end = NULL;
4814 while (*tok == ' ' || *tok == '\t')
4815 tok++;
4816
4817 end_tok = tok;
4818
4819 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
4820 end_tok++;
4821
4822 toklen = end_tok - tok;
4823
4824 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
4825 {
4826 tok = cond_start = end_tok + 1;
4827 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4828 make_cleanup (xfree, cond[i]);
4829 cond_end = tok;
4830 cond_string[i] = savestring (cond_start, cond_end - cond_start);
4831 make_cleanup (xfree, cond_string[i]);
4832 }
4833 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0)
4834 {
4835 char *tmptok;
4836
4837 tok = end_tok + 1;
4838 tmptok = tok;
4839 thread = strtol (tok, &tok, 0);
4840 if (tok == tmptok)
4841 error ("Junk after thread keyword.");
4842 if (!valid_thread_id (thread))
4843 error ("Unknown thread %d\n", thread);
4844 }
4845 else
4846 error ("Junk at end of arguments.");
4847 }
4848 }
4849
4850 create_breakpoints (sals, addr_string, cond, cond_string,
4851 hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4852 tempflag ? disp_del : disp_donttouch,
4853 thread, ignore_count, from_tty);
4854
4855 if (sals.nelts > 1)
4856 {
4857 warning ("Multiple breakpoints were set.");
4858 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
4859 }
4860 /* That's it. Discard the cleanups for data inserted into the
4861 breakpoint. */
4862 discard_cleanups (breakpoint_chain);
4863 /* But cleanup everything else. */
4864 do_cleanups (old_chain);
4865 }
4866
4867 /* Set a breakpoint of TYPE/DISPOSITION according to ARG (function,
4868 linenum or *address) with COND and IGNORE_COUNT. */
4869
4870 struct captured_breakpoint_args
4871 {
4872 char *address;
4873 char *condition;
4874 int hardwareflag;
4875 int tempflag;
4876 int thread;
4877 int ignore_count;
4878 };
4879
4880 static int
4881 do_captured_breakpoint (void *data)
4882 {
4883 struct captured_breakpoint_args *args = data;
4884 struct symtabs_and_lines sals;
4885 struct expression **cond;
4886 struct cleanup *old_chain;
4887 struct cleanup *breakpoint_chain = NULL;
4888 int i;
4889 char **addr_string;
4890 char **cond_string;
4891
4892 char *address_end;
4893
4894 /* Parse the source and lines spec. Delay check that the expression
4895 didn't contain trailing garbage until after cleanups are in
4896 place. */
4897 sals.sals = NULL;
4898 sals.nelts = 0;
4899 address_end = args->address;
4900 addr_string = NULL;
4901 parse_breakpoint_sals (&address_end, &sals, &addr_string);
4902
4903 if (!sals.nelts)
4904 return GDB_RC_NONE;
4905
4906 /* Create a chain of things at always need to be cleaned up. */
4907 old_chain = make_cleanup (null_cleanup, 0);
4908
4909 /* Always have a addr_string array, even if it is empty. */
4910 make_cleanup (xfree, addr_string);
4911
4912 /* Make sure that all storage allocated to SALS gets freed. */
4913 make_cleanup (xfree, sals.sals);
4914
4915 /* Allocate space for all the cond expressions. */
4916 cond = xcalloc (sals.nelts, sizeof (struct expression *));
4917 make_cleanup (xfree, cond);
4918
4919 /* Allocate space for all the cond strings. */
4920 cond_string = xcalloc (sals.nelts, sizeof (char **));
4921 make_cleanup (xfree, cond_string);
4922
4923 /* ----------------------------- SNIP -----------------------------
4924 Anything added to the cleanup chain beyond this point is assumed
4925 to be part of a breakpoint. If the breakpoint create goes
4926 through then that memory is not cleaned up. */
4927 breakpoint_chain = make_cleanup (null_cleanup, 0);
4928
4929 /* Mark the contents of the addr_string for cleanup. These go on
4930 the breakpoint_chain and only occure if the breakpoint create
4931 fails. */
4932 for (i = 0; i < sals.nelts; i++)
4933 {
4934 if (addr_string[i] != NULL)
4935 make_cleanup (xfree, addr_string[i]);
4936 }
4937
4938 /* Wait until now before checking for garbage at the end of the
4939 address. That way cleanups can take care of freeing any
4940 memory. */
4941 if (*address_end != '\0')
4942 error ("Garbage %s following breakpoint address", address_end);
4943
4944 /* Resolve all line numbers to PC's. */
4945 breakpoint_sals_to_pc (&sals, args->address);
4946
4947 /* Verify that conditions can be parsed, before setting any
4948 breakpoints. */
4949 for (i = 0; i < sals.nelts; i++)
4950 {
4951 if (args->condition != NULL)
4952 {
4953 char *tok = args->condition;
4954 cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0);
4955 if (*tok != '\0')
4956 error ("Garbage %s follows condition", tok);
4957 make_cleanup (xfree, cond[i]);
4958 cond_string[i] = xstrdup (args->condition);
4959 }
4960 }
4961
4962 create_breakpoints (sals, addr_string, cond, cond_string,
4963 args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint,
4964 args->tempflag ? disp_del : disp_donttouch,
4965 args->thread, args->ignore_count, 0/*from-tty*/);
4966
4967 /* That's it. Discard the cleanups for data inserted into the
4968 breakpoint. */
4969 discard_cleanups (breakpoint_chain);
4970 /* But cleanup everything else. */
4971 do_cleanups (old_chain);
4972 return GDB_RC_OK;
4973 }
4974
4975 enum gdb_rc
4976 gdb_breakpoint (char *address, char *condition,
4977 int hardwareflag, int tempflag,
4978 int thread, int ignore_count)
4979 {
4980 struct captured_breakpoint_args args;
4981 args.address = address;
4982 args.condition = condition;
4983 args.hardwareflag = hardwareflag;
4984 args.tempflag = tempflag;
4985 args.thread = thread;
4986 args.ignore_count = ignore_count;
4987 return catch_errors (do_captured_breakpoint, &args,
4988 NULL, RETURN_MASK_ALL);
4989 }
4990
4991
4992 static void
4993 break_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty)
4994 {
4995 struct frame_info *frame;
4996 CORE_ADDR low, high, selected_pc = 0;
4997 char *extra_args = NULL;
4998 char *level_arg;
4999 int extra_args_len = 0, if_arg = 0;
5000
5001 if (!arg ||
5002 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5003 {
5004
5005 if (default_breakpoint_valid)
5006 {
5007 if (deprecated_selected_frame)
5008 {
5009 selected_pc = get_frame_pc (deprecated_selected_frame);
5010 if (arg)
5011 if_arg = 1;
5012 }
5013 else
5014 error ("No selected frame.");
5015 }
5016 else
5017 error ("No default breakpoint address now.");
5018 }
5019 else
5020 {
5021 extra_args = strchr (arg, ' ');
5022 if (extra_args)
5023 {
5024 extra_args++;
5025 extra_args_len = strlen (extra_args);
5026 level_arg = (char *) xmalloc (extra_args - arg);
5027 strncpy (level_arg, arg, extra_args - arg - 1);
5028 level_arg[extra_args - arg - 1] = '\0';
5029 }
5030 else
5031 {
5032 level_arg = (char *) xmalloc (strlen (arg) + 1);
5033 strcpy (level_arg, arg);
5034 }
5035
5036 frame = parse_frame_specification (level_arg);
5037 if (frame)
5038 selected_pc = get_frame_pc (frame);
5039 else
5040 selected_pc = 0;
5041 }
5042 if (if_arg)
5043 {
5044 extra_args = arg;
5045 extra_args_len = strlen (arg);
5046 }
5047
5048 if (selected_pc)
5049 {
5050 if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high))
5051 {
5052 char *addr_string;
5053 if (extra_args_len)
5054 addr_string = xstrprintf ("*0x%s %s", paddr_nz (high), extra_args);
5055 else
5056 addr_string = xstrprintf ("*0x%s", paddr_nz (high));
5057 break_command_1 (addr_string, flag, from_tty);
5058 xfree (addr_string);
5059 }
5060 else
5061 error ("No function contains the specified address");
5062 }
5063 else
5064 error ("Unable to set breakpoint at procedure exit");
5065 }
5066
5067
5068 static void
5069 break_at_finish_command_1 (char *arg, int flag, int from_tty)
5070 {
5071 char *addr_string, *break_string, *beg_addr_string;
5072 CORE_ADDR low, high;
5073 struct symtabs_and_lines sals;
5074 struct symtab_and_line sal;
5075 struct cleanup *old_chain;
5076 char *extra_args = NULL;
5077 int extra_args_len = 0;
5078 int i, if_arg = 0;
5079
5080 if (!arg ||
5081 (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t')))
5082 {
5083 if (default_breakpoint_valid)
5084 {
5085 if (deprecated_selected_frame)
5086 {
5087 addr_string = xstrprintf ("*0x%s",
5088 paddr_nz (get_frame_pc (deprecated_selected_frame)));
5089 if (arg)
5090 if_arg = 1;
5091 }
5092 else
5093 error ("No selected frame.");
5094 }
5095 else
5096 error ("No default breakpoint address now.");
5097 }
5098 else
5099 {
5100 addr_string = (char *) xmalloc (strlen (arg) + 1);
5101 strcpy (addr_string, arg);
5102 }
5103
5104 if (if_arg)
5105 {
5106 extra_args = arg;
5107 extra_args_len = strlen (arg);
5108 }
5109 else if (arg)
5110 {
5111 /* get the stuff after the function name or address */
5112 extra_args = strchr (arg, ' ');
5113 if (extra_args)
5114 {
5115 extra_args++;
5116 extra_args_len = strlen (extra_args);
5117 }
5118 }
5119
5120 sals.sals = NULL;
5121 sals.nelts = 0;
5122
5123 beg_addr_string = addr_string;
5124 sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0,
5125 (char ***) NULL);
5126
5127 xfree (beg_addr_string);
5128 old_chain = make_cleanup (xfree, sals.sals);
5129 for (i = 0; (i < sals.nelts); i++)
5130 {
5131 sal = sals.sals[i];
5132 if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high))
5133 {
5134 break_string;
5135 if (extra_args_len)
5136 break_string = xstrprintf ("*0x%s %s", paddr_nz (high),
5137 extra_args);
5138 else
5139 break_string = xstrprintf ("*0x%s", paddr_nz (high));
5140 break_command_1 (break_string, flag, from_tty);
5141 xfree (break_string);
5142 }
5143 else
5144 error ("No function contains the specified address");
5145 }
5146 if (sals.nelts > 1)
5147 {
5148 warning ("Multiple breakpoints were set.\n");
5149 warning ("Use the \"delete\" command to delete unwanted breakpoints.");
5150 }
5151 do_cleanups (old_chain);
5152 }
5153
5154
5155 /* Helper function for break_command_1 and disassemble_command. */
5156
5157 void
5158 resolve_sal_pc (struct symtab_and_line *sal)
5159 {
5160 CORE_ADDR pc;
5161
5162 if (sal->pc == 0 && sal->symtab != NULL)
5163 {
5164 if (!find_line_pc (sal->symtab, sal->line, &pc))
5165 error ("No line %d in file \"%s\".",
5166 sal->line, sal->symtab->filename);
5167 sal->pc = pc;
5168 }
5169
5170 if (sal->section == 0 && sal->symtab != NULL)
5171 {
5172 struct blockvector *bv;
5173 struct block *b;
5174 struct symbol *sym;
5175 int index;
5176
5177 bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab);
5178 if (bv != NULL)
5179 {
5180 b = BLOCKVECTOR_BLOCK (bv, index);
5181 sym = block_function (b);
5182 if (sym != NULL)
5183 {
5184 fixup_symbol_section (sym, sal->symtab->objfile);
5185 sal->section = SYMBOL_BFD_SECTION (sym);
5186 }
5187 else
5188 {
5189 /* It really is worthwhile to have the section, so we'll just
5190 have to look harder. This case can be executed if we have
5191 line numbers but no functions (as can happen in assembly
5192 source). */
5193
5194 struct minimal_symbol *msym;
5195
5196 msym = lookup_minimal_symbol_by_pc (sal->pc);
5197 if (msym)
5198 sal->section = SYMBOL_BFD_SECTION (msym);
5199 }
5200 }
5201 }
5202 }
5203
5204 void
5205 break_command (char *arg, int from_tty)
5206 {
5207 break_command_1 (arg, 0, from_tty);
5208 }
5209
5210 void
5211 break_at_finish_command (char *arg, int from_tty)
5212 {
5213 break_at_finish_command_1 (arg, 0, from_tty);
5214 }
5215
5216 void
5217 break_at_finish_at_depth_command (char *arg, int from_tty)
5218 {
5219 break_at_finish_at_depth_command_1 (arg, 0, from_tty);
5220 }
5221
5222 void
5223 tbreak_command (char *arg, int from_tty)
5224 {
5225 break_command_1 (arg, BP_TEMPFLAG, from_tty);
5226 }
5227
5228 void
5229 tbreak_at_finish_command (char *arg, int from_tty)
5230 {
5231 break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty);
5232 }
5233
5234 static void
5235 hbreak_command (char *arg, int from_tty)
5236 {
5237 break_command_1 (arg, BP_HARDWAREFLAG, from_tty);
5238 }
5239
5240 static void
5241 thbreak_command (char *arg, int from_tty)
5242 {
5243 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty);
5244 }
5245
5246 static void
5247 stop_command (char *arg, int from_tty)
5248 {
5249 printf_filtered ("Specify the type of breakpoint to set.\n\
5250 Usage: stop in <function | address>\n\
5251 stop at <line>\n");
5252 }
5253
5254 static void
5255 stopin_command (char *arg, int from_tty)
5256 {
5257 int badInput = 0;
5258
5259 if (arg == (char *) NULL)
5260 badInput = 1;
5261 else if (*arg != '*')
5262 {
5263 char *argptr = arg;
5264 int hasColon = 0;
5265
5266 /* look for a ':'. If this is a line number specification, then
5267 say it is bad, otherwise, it should be an address or
5268 function/method name */
5269 while (*argptr && !hasColon)
5270 {
5271 hasColon = (*argptr == ':');
5272 argptr++;
5273 }
5274
5275 if (hasColon)
5276 badInput = (*argptr != ':'); /* Not a class::method */
5277 else
5278 badInput = isdigit (*arg); /* a simple line number */
5279 }
5280
5281 if (badInput)
5282 printf_filtered ("Usage: stop in <function | address>\n");
5283 else
5284 break_command_1 (arg, 0, from_tty);
5285 }
5286
5287 static void
5288 stopat_command (char *arg, int from_tty)
5289 {
5290 int badInput = 0;
5291
5292 if (arg == (char *) NULL || *arg == '*') /* no line number */
5293 badInput = 1;
5294 else
5295 {
5296 char *argptr = arg;
5297 int hasColon = 0;
5298
5299 /* look for a ':'. If there is a '::' then get out, otherwise
5300 it is probably a line number. */
5301 while (*argptr && !hasColon)
5302 {
5303 hasColon = (*argptr == ':');
5304 argptr++;
5305 }
5306
5307 if (hasColon)
5308 badInput = (*argptr == ':'); /* we have class::method */
5309 else
5310 badInput = !isdigit (*arg); /* not a line number */
5311 }
5312
5313 if (badInput)
5314 printf_filtered ("Usage: stop at <line>\n");
5315 else
5316 break_command_1 (arg, 0, from_tty);
5317 }
5318
5319 /* accessflag: hw_write: watch write,
5320 hw_read: watch read,
5321 hw_access: watch access (read or write) */
5322 static void
5323 watch_command_1 (char *arg, int accessflag, int from_tty)
5324 {
5325 struct breakpoint *b;
5326 struct symtab_and_line sal;
5327 struct expression *exp;
5328 struct block *exp_valid_block;
5329 struct value *val, *mark;
5330 struct frame_info *frame;
5331 struct frame_info *prev_frame = NULL;
5332 char *exp_start = NULL;
5333 char *exp_end = NULL;
5334 char *tok, *end_tok;
5335 int toklen;
5336 char *cond_start = NULL;
5337 char *cond_end = NULL;
5338 struct expression *cond = NULL;
5339 int i, other_type_used, target_resources_ok = 0;
5340 enum bptype bp_type;
5341 int mem_cnt = 0;
5342
5343 init_sal (&sal); /* initialize to zeroes */
5344
5345 /* Parse arguments. */
5346 innermost_block = NULL;
5347 exp_start = arg;
5348 exp = parse_exp_1 (&arg, 0, 0);
5349 exp_end = arg;
5350 exp_valid_block = innermost_block;
5351 mark = value_mark ();
5352 val = evaluate_expression (exp);
5353 release_value (val);
5354 if (VALUE_LAZY (val))
5355 value_fetch_lazy (val);
5356
5357 tok = arg;
5358 while (*tok == ' ' || *tok == '\t')
5359 tok++;
5360 end_tok = tok;
5361
5362 while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000')
5363 end_tok++;
5364
5365 toklen = end_tok - tok;
5366 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0)
5367 {
5368 tok = cond_start = end_tok + 1;
5369 cond = parse_exp_1 (&tok, 0, 0);
5370 cond_end = tok;
5371 }
5372 if (*tok)
5373 error ("Junk at end of command.");
5374
5375 if (accessflag == hw_read)
5376 bp_type = bp_read_watchpoint;
5377 else if (accessflag == hw_access)
5378 bp_type = bp_access_watchpoint;
5379 else
5380 bp_type = bp_hardware_watchpoint;
5381
5382 mem_cnt = can_use_hardware_watchpoint (val);
5383 if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint)
5384 error ("Expression cannot be implemented with read/access watchpoint.");
5385 if (mem_cnt != 0)
5386 {
5387 i = hw_watchpoint_used_count (bp_type, &other_type_used);
5388 target_resources_ok =
5389 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt,
5390 other_type_used);
5391 if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint)
5392 error ("Target does not support this type of hardware watchpoint.");
5393
5394 if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint)
5395 error ("Target can only support one kind of HW watchpoint at a time.");
5396 }
5397
5398 #if defined(HPUXHPPA)
5399 /* On HP-UX if you set a h/w
5400 watchpoint before the "run" command, the inferior dies with a e.g.,
5401 SIGILL once you start it. I initially believed this was due to a
5402 bad interaction between page protection traps and the initial
5403 startup sequence by the dynamic linker.
5404
5405 However, I tried avoiding that by having HP-UX's implementation of
5406 TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid
5407 yet, which forced slow watches before a "run" or "attach", and it
5408 still fails somewhere in the startup code.
5409
5410 Until I figure out what's happening, I'm disallowing watches altogether
5411 before the "run" or "attach" command. We'll tell the user they must
5412 set watches after getting the program started. */
5413 if (!target_has_execution)
5414 {
5415 warning ("can't do that without a running program; try \"break main\", \"run\" first");
5416 return;
5417 }
5418 #endif /* HPUXHPPA */
5419
5420 /* Change the type of breakpoint to an ordinary watchpoint if a hardware
5421 watchpoint could not be set. */
5422 if (!mem_cnt || target_resources_ok <= 0)
5423 bp_type = bp_watchpoint;
5424
5425 /* Now set up the breakpoint. */
5426 b = set_raw_breakpoint (sal, bp_type);
5427 set_breakpoint_count (breakpoint_count + 1);
5428 b->number = breakpoint_count;
5429 b->disposition = disp_donttouch;
5430 b->exp = exp;
5431 b->exp_valid_block = exp_valid_block;
5432 b->exp_string = savestring (exp_start, exp_end - exp_start);
5433 b->val = val;
5434 b->cond = cond;
5435 if (cond_start)
5436 b->cond_string = savestring (cond_start, cond_end - cond_start);
5437 else
5438 b->cond_string = 0;
5439
5440 frame = block_innermost_frame (exp_valid_block);
5441 if (frame)
5442 {
5443 prev_frame = get_prev_frame (frame);
5444 b->watchpoint_frame = get_frame_id (frame);
5445 }
5446 else
5447 {
5448 memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame));
5449 }
5450
5451 /* If the expression is "local", then set up a "watchpoint scope"
5452 breakpoint at the point where we've left the scope of the watchpoint
5453 expression. */
5454 if (innermost_block)
5455 {
5456 if (prev_frame)
5457 {
5458 struct breakpoint *scope_breakpoint;
5459 scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame),
5460 bp_watchpoint_scope);
5461
5462 scope_breakpoint->enable_state = bp_enabled;
5463
5464 /* Automatically delete the breakpoint when it hits. */
5465 scope_breakpoint->disposition = disp_del;
5466
5467 /* Only break in the proper frame (help with recursion). */
5468 scope_breakpoint->frame_id = get_frame_id (prev_frame);
5469
5470 /* Set the address at which we will stop. */
5471 scope_breakpoint->address = get_frame_pc (prev_frame);
5472
5473 /* The scope breakpoint is related to the watchpoint. We
5474 will need to act on them together. */
5475 b->related_breakpoint = scope_breakpoint;
5476 }
5477 }
5478 value_free_to_mark (mark);
5479 mention (b);
5480 }
5481
5482 /* Return count of locations need to be watched and can be handled
5483 in hardware. If the watchpoint can not be handled
5484 in hardware return zero. */
5485
5486 #if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT)
5487 #define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \
5488 ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE))
5489 #endif
5490
5491 #if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT)
5492 #define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \
5493 (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN))
5494 #endif
5495
5496 static int
5497 can_use_hardware_watchpoint (struct value *v)
5498 {
5499 int found_memory_cnt = 0;
5500 struct value *head = v;
5501
5502 /* Did the user specifically forbid us to use hardware watchpoints? */
5503 if (!can_use_hw_watchpoints)
5504 return 0;
5505
5506 /* Make sure that the value of the expression depends only upon
5507 memory contents, and values computed from them within GDB. If we
5508 find any register references or function calls, we can't use a
5509 hardware watchpoint.
5510
5511 The idea here is that evaluating an expression generates a series
5512 of values, one holding the value of every subexpression. (The
5513 expression a*b+c has five subexpressions: a, b, a*b, c, and
5514 a*b+c.) GDB's values hold almost enough information to establish
5515 the criteria given above --- they identify memory lvalues,
5516 register lvalues, computed values, etcetera. So we can evaluate
5517 the expression, and then scan the chain of values that leaves
5518 behind to decide whether we can detect any possible change to the
5519 expression's final value using only hardware watchpoints.
5520
5521 However, I don't think that the values returned by inferior
5522 function calls are special in any way. So this function may not
5523 notice that an expression involving an inferior function call
5524 can't be watched with hardware watchpoints. FIXME. */
5525 for (; v; v = v->next)
5526 {
5527 if (VALUE_LVAL (v) == lval_memory)
5528 {
5529 if (VALUE_LAZY (v))
5530 /* A lazy memory lvalue is one that GDB never needed to fetch;
5531 we either just used its address (e.g., `a' in `a.b') or
5532 we never needed it at all (e.g., `a' in `a,b'). */
5533 ;
5534 else
5535 {
5536 /* Ahh, memory we actually used! Check if we can cover
5537 it with hardware watchpoints. */
5538 struct type *vtype = check_typedef (VALUE_TYPE (v));
5539
5540 /* We only watch structs and arrays if user asked for it
5541 explicitly, never if they just happen to appear in a
5542 middle of some value chain. */
5543 if (v == head
5544 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT
5545 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY))
5546 {
5547 CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v);
5548 int len = TYPE_LENGTH (VALUE_TYPE (v));
5549
5550 if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len))
5551 return 0;
5552 else
5553 found_memory_cnt++;
5554 }
5555 }
5556 }
5557 else if (v->lval != not_lval && v->modifiable == 0)
5558 return 0; /* ??? What does this represent? */
5559 else if (v->lval == lval_register)
5560 return 0; /* cannot watch a register with a HW watchpoint */
5561 }
5562
5563 /* The expression itself looks suitable for using a hardware
5564 watchpoint, but give the target machine a chance to reject it. */
5565 return found_memory_cnt;
5566 }
5567
5568 void
5569 watch_command_wrapper (char *arg, int from_tty)
5570 {
5571 watch_command (arg, from_tty);
5572 }
5573
5574 static void
5575 watch_command (char *arg, int from_tty)
5576 {
5577 watch_command_1 (arg, hw_write, from_tty);
5578 }
5579
5580 void
5581 rwatch_command_wrapper (char *arg, int from_tty)
5582 {
5583 rwatch_command (arg, from_tty);
5584 }
5585
5586 static void
5587 rwatch_command (char *arg, int from_tty)
5588 {
5589 watch_command_1 (arg, hw_read, from_tty);
5590 }
5591
5592 void
5593 awatch_command_wrapper (char *arg, int from_tty)
5594 {
5595 awatch_command (arg, from_tty);
5596 }
5597
5598 static void
5599 awatch_command (char *arg, int from_tty)
5600 {
5601 watch_command_1 (arg, hw_access, from_tty);
5602 }
5603 \f
5604
5605 /* Helper routines for the until_command routine in infcmd.c. Here
5606 because it uses the mechanisms of breakpoints. */
5607
5608 /* This function is called by fetch_inferior_event via the
5609 cmd_continuation pointer, to complete the until command. It takes
5610 care of cleaning up the temporary breakpoints set up by the until
5611 command. */
5612 static void
5613 until_break_command_continuation (struct continuation_arg *arg)
5614 {
5615 struct cleanup *cleanups;
5616
5617 cleanups = (struct cleanup *) arg->data.pointer;
5618 do_exec_cleanups (cleanups);
5619 }
5620
5621 void
5622 until_break_command (char *arg, int from_tty, int anywhere)
5623 {
5624 struct symtabs_and_lines sals;
5625 struct symtab_and_line sal;
5626 struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame);
5627 struct breakpoint *breakpoint;
5628 struct cleanup *old_chain;
5629 struct continuation_arg *arg1;
5630
5631
5632 clear_proceed_status ();
5633
5634 /* Set a breakpoint where the user wants it and at return from
5635 this function */
5636
5637 if (default_breakpoint_valid)
5638 sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
5639 default_breakpoint_line, (char ***) NULL);
5640 else
5641 sals = decode_line_1 (&arg, 1, (struct symtab *) NULL,
5642 0, (char ***) NULL);
5643
5644 if (sals.nelts != 1)
5645 error ("Couldn't get information on specified line.");
5646
5647 sal = sals.sals[0];
5648 xfree (sals.sals); /* malloc'd, so freed */
5649
5650 if (*arg)
5651 error ("Junk at end of arguments.");
5652
5653 resolve_sal_pc (&sal);
5654
5655 if (anywhere)
5656 /* If the user told us to continue until a specified location,
5657 we don't specify a frame at which we need to stop. */
5658 breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until);
5659 else
5660 /* Otherwise, specify the current frame, because we want to stop only
5661 at the very same frame. */
5662 breakpoint = set_momentary_breakpoint (sal,
5663 get_frame_id (deprecated_selected_frame),
5664 bp_until);
5665
5666 if (!event_loop_p || !target_can_async_p ())
5667 old_chain = make_cleanup_delete_breakpoint (breakpoint);
5668 else
5669 old_chain = make_exec_cleanup_delete_breakpoint (breakpoint);
5670
5671 /* If we are running asynchronously, and the target supports async
5672 execution, we are not waiting for the target to stop, in the call
5673 tp proceed, below. This means that we cannot delete the
5674 brekpoints until the target has actually stopped. The only place
5675 where we get a chance to do that is in fetch_inferior_event, so
5676 we must set things up for that. */
5677
5678 if (event_loop_p && target_can_async_p ())
5679 {
5680 /* In this case the arg for the continuation is just the point
5681 in the exec_cleanups chain from where to start doing
5682 cleanups, because all the continuation does is the cleanups in
5683 the exec_cleanup_chain. */
5684 arg1 =
5685 (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg));
5686 arg1->next = NULL;
5687 arg1->data.pointer = old_chain;
5688
5689 add_continuation (until_break_command_continuation, arg1);
5690 }
5691
5692 /* Keep within the current frame, or in frames called by the current
5693 one. */
5694 if (prev_frame)
5695 {
5696 sal = find_pc_line (get_frame_pc (prev_frame), 0);
5697 sal.pc = get_frame_pc (prev_frame);
5698 breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame),
5699 bp_until);
5700 if (!event_loop_p || !target_can_async_p ())
5701 make_cleanup_delete_breakpoint (breakpoint);
5702 else
5703 make_exec_cleanup_delete_breakpoint (breakpoint);
5704 }
5705
5706 proceed (-1, TARGET_SIGNAL_DEFAULT, 0);
5707 /* Do the cleanups now, anly if we are not running asynchronously,
5708 of if we are, but the target is still synchronous. */
5709 if (!event_loop_p || !target_can_async_p ())
5710 do_cleanups (old_chain);
5711 }
5712
5713 #if 0
5714 /* These aren't used; I don't konw what they were for. */
5715 /* Set a breakpoint at the catch clause for NAME. */
5716 static int
5717 catch_breakpoint (char *name)
5718 {
5719 }
5720
5721 static int
5722 disable_catch_breakpoint (void)
5723 {
5724 }
5725
5726 static int
5727 delete_catch_breakpoint (void)
5728 {
5729 }
5730
5731 static int
5732 enable_catch_breakpoint (void)
5733 {
5734 }
5735 #endif /* 0 */
5736
5737 static void
5738 ep_skip_leading_whitespace (char **s)
5739 {
5740 if ((s == NULL) || (*s == NULL))
5741 return;
5742 while (isspace (**s))
5743 *s += 1;
5744 }
5745
5746 /* This function examines a string, and attempts to find a token
5747 that might be an event name in the leading characters. If a
5748 possible match is found, a pointer to the last character of
5749 the token is returned. Else, NULL is returned. */
5750
5751 static char *
5752 ep_find_event_name_end (char *arg)
5753 {
5754 char *s = arg;
5755 char *event_name_end = NULL;
5756
5757 /* If we could depend upon the presense of strrpbrk, we'd use that... */
5758 if (arg == NULL)
5759 return NULL;
5760
5761 /* We break out of the loop when we find a token delimiter.
5762 Basically, we're looking for alphanumerics and underscores;
5763 anything else delimites the token. */
5764 while (*s != '\0')
5765 {
5766 if (!isalnum (*s) && (*s != '_'))
5767 break;
5768 event_name_end = s;
5769 s++;
5770 }
5771
5772 return event_name_end;
5773 }
5774
5775
5776 /* This function attempts to parse an optional "if <cond>" clause
5777 from the arg string. If one is not found, it returns NULL.
5778
5779 Else, it returns a pointer to the condition string. (It does not
5780 attempt to evaluate the string against a particular block.) And,
5781 it updates arg to point to the first character following the parsed
5782 if clause in the arg string. */
5783
5784 static char *
5785 ep_parse_optional_if_clause (char **arg)
5786 {
5787 char *cond_string;
5788
5789 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2]))
5790 return NULL;
5791
5792 /* Skip the "if" keyword. */
5793 (*arg) += 2;
5794
5795 /* Skip any extra leading whitespace, and record the start of the
5796 condition string. */
5797 ep_skip_leading_whitespace (arg);
5798 cond_string = *arg;
5799
5800 /* Assume that the condition occupies the remainder of the arg string. */
5801 (*arg) += strlen (cond_string);
5802
5803 return cond_string;
5804 }
5805
5806 /* This function attempts to parse an optional filename from the arg
5807 string. If one is not found, it returns NULL.
5808
5809 Else, it returns a pointer to the parsed filename. (This function
5810 makes no attempt to verify that a file of that name exists, or is
5811 accessible.) And, it updates arg to point to the first character
5812 following the parsed filename in the arg string.
5813
5814 Note that clients needing to preserve the returned filename for
5815 future access should copy it to their own buffers. */
5816 static char *
5817 ep_parse_optional_filename (char **arg)
5818 {
5819 static char filename[1024];
5820 char *arg_p = *arg;
5821 int i;
5822 char c;
5823
5824 if ((*arg_p == '\0') || isspace (*arg_p))
5825 return NULL;
5826
5827 for (i = 0;; i++)
5828 {
5829 c = *arg_p;
5830 if (isspace (c))
5831 c = '\0';
5832 filename[i] = c;
5833 if (c == '\0')
5834 break;
5835 arg_p++;
5836 }
5837 *arg = arg_p;
5838
5839 return filename;
5840 }
5841
5842 /* Commands to deal with catching events, such as signals, exceptions,
5843 process start/exit, etc. */
5844
5845 typedef enum
5846 {
5847 catch_fork, catch_vfork
5848 }
5849 catch_fork_kind;
5850
5851 #if defined(CHILD_INSERT_FORK_CATCHPOINT) || defined(CHILD_INSERT_VFORK_CATCHPOINT)
5852 static void catch_fork_command_1 (catch_fork_kind fork_kind,
5853 char *arg, int tempflag, int from_tty);
5854
5855 static void
5856 catch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag,
5857 int from_tty)
5858 {
5859 char *cond_string = NULL;
5860
5861 ep_skip_leading_whitespace (&arg);
5862
5863 /* The allowed syntax is:
5864 catch [v]fork
5865 catch [v]fork if <cond>
5866
5867 First, check if there's an if clause. */
5868 cond_string = ep_parse_optional_if_clause (&arg);
5869
5870 if ((*arg != '\0') && !isspace (*arg))
5871 error ("Junk at end of arguments.");
5872
5873 /* If this target supports it, create a fork or vfork catchpoint
5874 and enable reporting of such events. */
5875 switch (fork_kind)
5876 {
5877 case catch_fork:
5878 create_fork_event_catchpoint (tempflag, cond_string);
5879 break;
5880 case catch_vfork:
5881 create_vfork_event_catchpoint (tempflag, cond_string);
5882 break;
5883 default:
5884 error ("unsupported or unknown fork kind; cannot catch it");
5885 break;
5886 }
5887 }
5888 #endif
5889
5890 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
5891 static void
5892 catch_exec_command_1 (char *arg, int tempflag, int from_tty)
5893 {
5894 char *cond_string = NULL;
5895
5896 ep_skip_leading_whitespace (&arg);
5897
5898 /* The allowed syntax is:
5899 catch exec
5900 catch exec if <cond>
5901
5902 First, check if there's an if clause. */
5903 cond_string = ep_parse_optional_if_clause (&arg);
5904
5905 if ((*arg != '\0') && !isspace (*arg))
5906 error ("Junk at end of arguments.");
5907
5908 /* If this target supports it, create an exec catchpoint
5909 and enable reporting of such events. */
5910 create_exec_event_catchpoint (tempflag, cond_string);
5911 }
5912 #endif
5913
5914 #if defined(SOLIB_ADD)
5915 static void
5916 catch_load_command_1 (char *arg, int tempflag, int from_tty)
5917 {
5918 char *dll_pathname = NULL;
5919 char *cond_string = NULL;
5920
5921 ep_skip_leading_whitespace (&arg);
5922
5923 /* The allowed syntax is:
5924 catch load
5925 catch load if <cond>
5926 catch load <filename>
5927 catch load <filename> if <cond>
5928
5929 The user is not allowed to specify the <filename> after an
5930 if clause.
5931
5932 We'll ignore the pathological case of a file named "if".
5933
5934 First, check if there's an if clause. If so, then there
5935 cannot be a filename. */
5936 cond_string = ep_parse_optional_if_clause (&arg);
5937
5938 /* If there was an if clause, then there cannot be a filename.
5939 Else, there might be a filename and an if clause. */
5940 if (cond_string == NULL)
5941 {
5942 dll_pathname = ep_parse_optional_filename (&arg);
5943 ep_skip_leading_whitespace (&arg);
5944 cond_string = ep_parse_optional_if_clause (&arg);
5945 }
5946
5947 if ((*arg != '\0') && !isspace (*arg))
5948 error ("Junk at end of arguments.");
5949
5950 /* Create a load breakpoint that only triggers when a load of
5951 the specified dll (or any dll, if no pathname was specified)
5952 occurs. */
5953 SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag,
5954 dll_pathname, cond_string);
5955 }
5956
5957 static void
5958 catch_unload_command_1 (char *arg, int tempflag, int from_tty)
5959 {
5960 char *dll_pathname = NULL;
5961 char *cond_string = NULL;
5962
5963 ep_skip_leading_whitespace (&arg);
5964
5965 /* The allowed syntax is:
5966 catch unload
5967 catch unload if <cond>
5968 catch unload <filename>
5969 catch unload <filename> if <cond>
5970
5971 The user is not allowed to specify the <filename> after an
5972 if clause.
5973
5974 We'll ignore the pathological case of a file named "if".
5975
5976 First, check if there's an if clause. If so, then there
5977 cannot be a filename. */
5978 cond_string = ep_parse_optional_if_clause (&arg);
5979
5980 /* If there was an if clause, then there cannot be a filename.
5981 Else, there might be a filename and an if clause. */
5982 if (cond_string == NULL)
5983 {
5984 dll_pathname = ep_parse_optional_filename (&arg);
5985 ep_skip_leading_whitespace (&arg);
5986 cond_string = ep_parse_optional_if_clause (&arg);
5987 }
5988
5989 if ((*arg != '\0') && !isspace (*arg))
5990 error ("Junk at end of arguments.");
5991
5992 /* Create an unload breakpoint that only triggers when an unload of
5993 the specified dll (or any dll, if no pathname was specified)
5994 occurs. */
5995 SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag,
5996 dll_pathname, cond_string);
5997 }
5998 #endif /* SOLIB_ADD */
5999
6000 /* Commands to deal with catching exceptions. */
6001
6002 /* Set a breakpoint at the specified callback routine for an
6003 exception event callback */
6004
6005 static void
6006 create_exception_catchpoint (int tempflag, char *cond_string,
6007 enum exception_event_kind ex_event,
6008 struct symtab_and_line *sal)
6009 {
6010 struct breakpoint *b;
6011 int thread = -1; /* All threads. */
6012 enum bptype bptype;
6013
6014 if (!sal) /* no exception support? */
6015 return;
6016
6017 switch (ex_event)
6018 {
6019 case EX_EVENT_THROW:
6020 bptype = bp_catch_throw;
6021 break;
6022 case EX_EVENT_CATCH:
6023 bptype = bp_catch_catch;
6024 break;
6025 default: /* error condition */
6026 error ("Internal error -- invalid catchpoint kind");
6027 }
6028
6029 b = set_raw_breakpoint (*sal, bptype);
6030 set_breakpoint_count (breakpoint_count + 1);
6031 b->number = breakpoint_count;
6032 b->cond = NULL;
6033 b->cond_string = (cond_string == NULL) ?
6034 NULL : savestring (cond_string, strlen (cond_string));
6035 b->thread = thread;
6036 b->addr_string = NULL;
6037 b->enable_state = bp_enabled;
6038 b->disposition = tempflag ? disp_del : disp_donttouch;
6039 mention (b);
6040 }
6041
6042 static enum print_stop_action
6043 print_exception_catchpoint (struct breakpoint *b)
6044 {
6045 annotate_catchpoint (b->number);
6046
6047 if (strstr (b->addr_string, "throw") != NULL)
6048 printf_filtered ("\nCatchpoint %d (exception thrown)\n",
6049 b->number);
6050 else
6051 printf_filtered ("\nCatchpoint %d (exception caught)\n",
6052 b->number);
6053
6054 return PRINT_SRC_AND_LOC;
6055 }
6056
6057 static void
6058 print_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr)
6059 {
6060 if (addressprint)
6061 {
6062 annotate_field (4);
6063 ui_out_field_core_addr (uiout, "addr", b->address);
6064 }
6065 annotate_field (5);
6066 *last_addr = b->address;
6067 if (strstr (b->addr_string, "throw") != NULL)
6068 ui_out_field_string (uiout, "what", "exception throw");
6069 else
6070 ui_out_field_string (uiout, "what", "exception catch");
6071 }
6072
6073 static void
6074 print_mention_exception_catchpoint (struct breakpoint *b)
6075 {
6076 if (strstr (b->addr_string, "throw") != NULL)
6077 printf_filtered ("Catchpoint %d (throw)", b->number);
6078 else
6079 printf_filtered ("Catchpoint %d (catch)", b->number);
6080 }
6081
6082 static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = {
6083 print_exception_catchpoint,
6084 print_one_exception_catchpoint,
6085 print_mention_exception_catchpoint
6086 };
6087
6088 static int
6089 handle_gnu_v3_exceptions (int tempflag, char *cond_string,
6090 enum exception_event_kind ex_event, int from_tty)
6091 {
6092 char *trigger_func_name, *nameptr;
6093 struct symtabs_and_lines sals;
6094 struct breakpoint *b;
6095
6096 if (ex_event == EX_EVENT_CATCH)
6097 trigger_func_name = xstrdup ("__cxa_begin_catch");
6098 else
6099 trigger_func_name = xstrdup ("__cxa_throw");
6100
6101 nameptr = trigger_func_name;
6102 sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL);
6103 if (sals.nelts == 0)
6104 {
6105 xfree (trigger_func_name);
6106 return 0;
6107 }
6108
6109 b = set_raw_breakpoint (sals.sals[0], bp_breakpoint);
6110 set_breakpoint_count (breakpoint_count + 1);
6111 b->number = breakpoint_count;
6112 b->cond = NULL;
6113 b->cond_string = (cond_string == NULL) ?
6114 NULL : savestring (cond_string, strlen (cond_string));
6115 b->thread = -1;
6116 b->addr_string = trigger_func_name;
6117 b->enable_state = bp_enabled;
6118 b->disposition = tempflag ? disp_del : disp_donttouch;
6119 b->ops = &gnu_v3_exception_catchpoint_ops;
6120
6121 xfree (sals.sals);
6122 mention (b);
6123 return 1;
6124 }
6125
6126 /* Deal with "catch catch" and "catch throw" commands */
6127
6128 static void
6129 catch_exception_command_1 (enum exception_event_kind ex_event, char *arg,
6130 int tempflag, int from_tty)
6131 {
6132 char *cond_string = NULL;
6133 struct symtab_and_line *sal = NULL;
6134
6135 ep_skip_leading_whitespace (&arg);
6136
6137 cond_string = ep_parse_optional_if_clause (&arg);
6138
6139 if ((*arg != '\0') && !isspace (*arg))
6140 error ("Junk at end of arguments.");
6141
6142 if ((ex_event != EX_EVENT_THROW) &&
6143 (ex_event != EX_EVENT_CATCH))
6144 error ("Unsupported or unknown exception event; cannot catch it");
6145
6146 if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty))
6147 return;
6148
6149 /* See if we can find a callback routine */
6150 sal = target_enable_exception_callback (ex_event, 1);
6151
6152 if (sal)
6153 {
6154 /* We have callbacks from the runtime system for exceptions.
6155 Set a breakpoint on the sal found, if no errors */
6156 if (sal != (struct symtab_and_line *) -1)
6157 create_exception_catchpoint (tempflag, cond_string, ex_event, sal);
6158 else
6159 return; /* something went wrong with setting up callbacks */
6160 }
6161
6162 warning ("Unsupported with this platform/compiler combination.");
6163 }
6164
6165 /* Cover routine to allow wrapping target_enable_exception_catchpoints
6166 inside a catch_errors */
6167
6168 static int
6169 cover_target_enable_exception_callback (void *arg)
6170 {
6171 args_for_catchpoint_enable *args = arg;
6172 struct symtab_and_line *sal;
6173 sal = target_enable_exception_callback (args->kind, args->enable_p);
6174 if (sal == NULL)
6175 return 0;
6176 else if (sal == (struct symtab_and_line *) -1)
6177 return -1;
6178 else
6179 return 1; /*is valid */
6180 }
6181
6182 static void
6183 catch_command_1 (char *arg, int tempflag, int from_tty)
6184 {
6185
6186 /* The first argument may be an event name, such as "start" or "load".
6187 If so, then handle it as such. If it doesn't match an event name,
6188 then attempt to interpret it as an exception name. (This latter is
6189 the v4.16-and-earlier GDB meaning of the "catch" command.)
6190
6191 First, try to find the bounds of what might be an event name. */
6192 char *arg1_start = arg;
6193 char *arg1_end;
6194 int arg1_length;
6195
6196 if (arg1_start == NULL)
6197 {
6198 /* Old behaviour was to use pre-v-4.16 syntax */
6199 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6200 /* return; */
6201 /* Now, this is not allowed */
6202 error ("Catch requires an event name.");
6203
6204 }
6205 arg1_end = ep_find_event_name_end (arg1_start);
6206 if (arg1_end == NULL)
6207 error ("catch requires an event");
6208 arg1_length = arg1_end + 1 - arg1_start;
6209
6210 /* Try to match what we found against known event names. */
6211 if (strncmp (arg1_start, "signal", arg1_length) == 0)
6212 {
6213 error ("Catch of signal not yet implemented");
6214 }
6215 else if (strncmp (arg1_start, "catch", arg1_length) == 0)
6216 {
6217 catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1,
6218 tempflag, from_tty);
6219 }
6220 else if (strncmp (arg1_start, "throw", arg1_length) == 0)
6221 {
6222 catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1,
6223 tempflag, from_tty);
6224 }
6225 else if (strncmp (arg1_start, "thread_start", arg1_length) == 0)
6226 {
6227 error ("Catch of thread_start not yet implemented");
6228 }
6229 else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0)
6230 {
6231 error ("Catch of thread_exit not yet implemented");
6232 }
6233 else if (strncmp (arg1_start, "thread_join", arg1_length) == 0)
6234 {
6235 error ("Catch of thread_join not yet implemented");
6236 }
6237 else if (strncmp (arg1_start, "start", arg1_length) == 0)
6238 {
6239 error ("Catch of start not yet implemented");
6240 }
6241 else if (strncmp (arg1_start, "exit", arg1_length) == 0)
6242 {
6243 error ("Catch of exit not yet implemented");
6244 }
6245 else if (strncmp (arg1_start, "fork", arg1_length) == 0)
6246 {
6247 #if defined(CHILD_INSERT_FORK_CATCHPOINT)
6248 catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty);
6249 #else
6250 error ("Catch of fork not yet implemented");
6251 #endif
6252 }
6253 else if (strncmp (arg1_start, "vfork", arg1_length) == 0)
6254 {
6255 #if defined(CHILD_INSERT_VFORK_CATCHPOINT)
6256 catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty);
6257 #else
6258 error ("Catch of vfork not yet implemented");
6259 #endif
6260 }
6261 else if (strncmp (arg1_start, "exec", arg1_length) == 0)
6262 {
6263 #if defined(CHILD_INSERT_EXEC_CATCHPOINT)
6264 catch_exec_command_1 (arg1_end + 1, tempflag, from_tty);
6265 #else
6266 error ("Catch of exec not yet implemented");
6267 #endif
6268 }
6269 else if (strncmp (arg1_start, "load", arg1_length) == 0)
6270 {
6271 #if defined(SOLIB_ADD)
6272 catch_load_command_1 (arg1_end + 1, tempflag, from_tty);
6273 #else
6274 error ("Catch of load not implemented");
6275 #endif
6276 }
6277 else if (strncmp (arg1_start, "unload", arg1_length) == 0)
6278 {
6279 #if defined(SOLIB_ADD)
6280 catch_unload_command_1 (arg1_end + 1, tempflag, from_tty);
6281 #else
6282 error ("Catch of load not implemented");
6283 #endif
6284 }
6285 else if (strncmp (arg1_start, "stop", arg1_length) == 0)
6286 {
6287 error ("Catch of stop not yet implemented");
6288 }
6289
6290 /* This doesn't appear to be an event name */
6291
6292 else
6293 {
6294 /* Pre-v.4.16 behaviour was to treat the argument
6295 as the name of an exception */
6296 /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */
6297 /* Now this is not allowed */
6298 error ("Unknown event kind specified for catch");
6299
6300 }
6301 }
6302
6303 /* Used by the gui, could be made a worker for other things. */
6304
6305 struct breakpoint *
6306 set_breakpoint_sal (struct symtab_and_line sal)
6307 {
6308 struct breakpoint *b;
6309 b = set_raw_breakpoint (sal, bp_breakpoint);
6310 set_breakpoint_count (breakpoint_count + 1);
6311 b->number = breakpoint_count;
6312 b->cond = 0;
6313 b->thread = -1;
6314 return b;
6315 }
6316
6317 #if 0
6318 /* These aren't used; I don't know what they were for. */
6319 /* Disable breakpoints on all catch clauses described in ARGS. */
6320 static void
6321 disable_catch (char *args)
6322 {
6323 /* Map the disable command to catch clauses described in ARGS. */
6324 }
6325
6326 /* Enable breakpoints on all catch clauses described in ARGS. */
6327 static void
6328 enable_catch (char *args)
6329 {
6330 /* Map the disable command to catch clauses described in ARGS. */
6331 }
6332
6333 /* Delete breakpoints on all catch clauses in the active scope. */
6334 static void
6335 delete_catch (char *args)
6336 {
6337 /* Map the delete command to catch clauses described in ARGS. */
6338 }
6339 #endif /* 0 */
6340
6341 static void
6342 catch_command (char *arg, int from_tty)
6343 {
6344 catch_command_1 (arg, 0, from_tty);
6345 }
6346 \f
6347
6348 static void
6349 tcatch_command (char *arg, int from_tty)
6350 {
6351 catch_command_1 (arg, 1, from_tty);
6352 }
6353
6354 /* Delete breakpoints by address or line. */
6355
6356 static void
6357 clear_command (char *arg, int from_tty)
6358 {
6359 struct breakpoint *b, *tmp, *prev, *found;
6360 int default_match;
6361 struct symtabs_and_lines sals;
6362 struct symtab_and_line sal;
6363 int i;
6364
6365 if (arg)
6366 {
6367 sals = decode_line_spec (arg, 1);
6368 default_match = 0;
6369 }
6370 else
6371 {
6372 sals.sals = (struct symtab_and_line *)
6373 xmalloc (sizeof (struct symtab_and_line));
6374 make_cleanup (xfree, sals.sals);
6375 init_sal (&sal); /* initialize to zeroes */
6376 sal.line = default_breakpoint_line;
6377 sal.symtab = default_breakpoint_symtab;
6378 sal.pc = default_breakpoint_address;
6379 if (sal.symtab == 0)
6380 error ("No source file specified.");
6381
6382 sals.sals[0] = sal;
6383 sals.nelts = 1;
6384
6385 default_match = 1;
6386 }
6387
6388 /* For each line spec given, delete bps which correspond
6389 to it. Do it in two passes, solely to preserve the current
6390 behavior that from_tty is forced true if we delete more than
6391 one breakpoint. */
6392
6393 found = NULL;
6394 for (i = 0; i < sals.nelts; i++)
6395 {
6396 /* If exact pc given, clear bpts at that pc.
6397 If line given (pc == 0), clear all bpts on specified line.
6398 If defaulting, clear all bpts on default line
6399 or at default pc.
6400
6401 defaulting sal.pc != 0 tests to do
6402
6403 0 1 pc
6404 1 1 pc _and_ line
6405 0 0 line
6406 1 0 <can't happen> */
6407
6408 sal = sals.sals[i];
6409 prev = NULL;
6410
6411 /* Find all matching breakpoints, remove them from the
6412 breakpoint chain, and add them to the 'found' chain. */
6413 ALL_BREAKPOINTS_SAFE (b, tmp)
6414 {
6415 /* Are we going to delete b? */
6416 if (b->type != bp_none
6417 && b->type != bp_watchpoint
6418 && b->type != bp_hardware_watchpoint
6419 && b->type != bp_read_watchpoint
6420 && b->type != bp_access_watchpoint
6421 /* Not if b is a watchpoint of any sort... */
6422 && (((sal.pc && (b->address == sal.pc))
6423 && (!section_is_overlay (b->section)
6424 || b->section == sal.section))
6425 /* Yes, if sal.pc matches b (modulo overlays). */
6426 || ((default_match || (0 == sal.pc))
6427 && b->source_file != NULL
6428 && sal.symtab != NULL
6429 && STREQ (b->source_file, sal.symtab->filename)
6430 && b->line_number == sal.line)))
6431 /* Yes, if sal source file and line matches b. */
6432 {
6433 /* Remove it from breakpoint_chain... */
6434 if (b == breakpoint_chain)
6435 {
6436 /* b is at the head of the list */
6437 breakpoint_chain = b->next;
6438 }
6439 else
6440 {
6441 prev->next = b->next;
6442 }
6443 /* And add it to 'found' chain. */
6444 b->next = found;
6445 found = b;
6446 }
6447 else
6448 {
6449 /* Keep b, and keep a pointer to it. */
6450 prev = b;
6451 }
6452 }
6453 }
6454 /* Now go thru the 'found' chain and delete them. */
6455 if (found == 0)
6456 {
6457 if (arg)
6458 error ("No breakpoint at %s.", arg);
6459 else
6460 error ("No breakpoint at this line.");
6461 }
6462
6463 if (found->next)
6464 from_tty = 1; /* Always report if deleted more than one */
6465 if (from_tty)
6466 printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : "");
6467 breakpoints_changed ();
6468 while (found)
6469 {
6470 if (from_tty)
6471 printf_unfiltered ("%d ", found->number);
6472 tmp = found->next;
6473 delete_breakpoint (found);
6474 found = tmp;
6475 }
6476 if (from_tty)
6477 putchar_unfiltered ('\n');
6478 }
6479 \f
6480 /* Delete breakpoint in BS if they are `delete' breakpoints and
6481 all breakpoints that are marked for deletion, whether hit or not.
6482 This is called after any breakpoint is hit, or after errors. */
6483
6484 void
6485 breakpoint_auto_delete (bpstat bs)
6486 {
6487 struct breakpoint *b, *temp;
6488
6489 for (; bs; bs = bs->next)
6490 if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del
6491 && bs->stop)
6492 delete_breakpoint (bs->breakpoint_at);
6493
6494 ALL_BREAKPOINTS_SAFE (b, temp)
6495 {
6496 if (b->disposition == disp_del_at_next_stop)
6497 delete_breakpoint (b);
6498 }
6499 }
6500
6501 /* Delete a breakpoint and clean up all traces of it in the data
6502 structures. */
6503
6504 void
6505 delete_breakpoint (struct breakpoint *bpt)
6506 {
6507 struct breakpoint *b;
6508 bpstat bs;
6509
6510 if (bpt == NULL)
6511 error ("Internal error (attempted to delete a NULL breakpoint)");
6512
6513
6514 /* Has this bp already been deleted? This can happen because multiple
6515 lists can hold pointers to bp's. bpstat lists are especial culprits.
6516
6517 One example of this happening is a watchpoint's scope bp. When the
6518 scope bp triggers, we notice that the watchpoint is out of scope, and
6519 delete it. We also delete its scope bp. But the scope bp is marked
6520 "auto-deleting", and is already on a bpstat. That bpstat is then
6521 checked for auto-deleting bp's, which are deleted.
6522
6523 A real solution to this problem might involve reference counts in bp's,
6524 and/or giving them pointers back to their referencing bpstat's, and
6525 teaching delete_breakpoint to only free a bp's storage when no more
6526 references were extent. A cheaper bandaid was chosen. */
6527 if (bpt->type == bp_none)
6528 return;
6529
6530 if (delete_breakpoint_hook)
6531 delete_breakpoint_hook (bpt);
6532 breakpoint_delete_event (bpt->number);
6533
6534 if (bpt->inserted)
6535 remove_breakpoint (bpt, mark_inserted);
6536
6537 if (breakpoint_chain == bpt)
6538 breakpoint_chain = bpt->next;
6539
6540 /* If we have callback-style exception catchpoints, don't go through
6541 the adjustments to the C++ runtime library etc. if the inferior
6542 isn't actually running. target_enable_exception_callback for a
6543 null target ops vector gives an undesirable error message, so we
6544 check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's
6545 exceptions are supported in this way, it's OK for now. FIXME */
6546 if (ep_is_exception_catchpoint (bpt) && target_has_execution)
6547 {
6548 /* Format possible error msg */
6549 char *message = xstrprintf ("Error in deleting catchpoint %d:\n",
6550 bpt->number);
6551 struct cleanup *cleanups = make_cleanup (xfree, message);
6552 args_for_catchpoint_enable args;
6553 args.kind = bpt->type == bp_catch_catch ?
6554 EX_EVENT_CATCH : EX_EVENT_THROW;
6555 args.enable_p = 0;
6556 catch_errors (cover_target_enable_exception_callback, &args,
6557 message, RETURN_MASK_ALL);
6558 do_cleanups (cleanups);
6559 }
6560
6561
6562 ALL_BREAKPOINTS (b)
6563 if (b->next == bpt)
6564 {
6565 b->next = bpt->next;
6566 break;
6567 }
6568
6569 check_duplicates (bpt);
6570 /* If this breakpoint was inserted, and there is another breakpoint
6571 at the same address, we need to insert the other breakpoint. */
6572 if (bpt->inserted
6573 && bpt->type != bp_hardware_watchpoint
6574 && bpt->type != bp_read_watchpoint
6575 && bpt->type != bp_access_watchpoint
6576 && bpt->type != bp_catch_fork
6577 && bpt->type != bp_catch_vfork
6578 && bpt->type != bp_catch_exec)
6579 {
6580 ALL_BREAKPOINTS (b)
6581 if (b->address == bpt->address
6582 && b->section == bpt->section
6583 && !b->duplicate
6584 && b->enable_state != bp_disabled
6585 && b->enable_state != bp_shlib_disabled
6586 && b->enable_state != bp_call_disabled)
6587 {
6588 int val;
6589
6590 /* We should never reach this point if there is a permanent
6591 breakpoint at the same address as the one being deleted.
6592 If there is a permanent breakpoint somewhere, it should
6593 always be the only one inserted. */
6594 if (b->enable_state == bp_permanent)
6595 internal_error (__FILE__, __LINE__,
6596 "another breakpoint was inserted on top of "
6597 "a permanent breakpoint");
6598
6599 if (b->type == bp_hardware_breakpoint)
6600 val = target_insert_hw_breakpoint (b->address, b->shadow_contents);
6601 else
6602 val = target_insert_breakpoint (b->address, b->shadow_contents);
6603
6604 /* If there was an error in the insert, print a message, then stop execution. */
6605 if (val != 0)
6606 {
6607 struct ui_file *tmp_error_stream = mem_fileopen ();
6608 make_cleanup_ui_file_delete (tmp_error_stream);
6609
6610
6611 if (b->type == bp_hardware_breakpoint)
6612 {
6613 fprintf_unfiltered (tmp_error_stream,
6614 "Cannot insert hardware breakpoint %d.\n"
6615 "You may have requested too many hardware breakpoints.\n",
6616 b->number);
6617 }
6618 else
6619 {
6620 fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number);
6621 fprintf_filtered (tmp_error_stream, "Error accessing memory address ");
6622 print_address_numeric (b->address, 1, tmp_error_stream);
6623 fprintf_filtered (tmp_error_stream, ": %s.\n",
6624 safe_strerror (val));
6625 }
6626
6627 fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process.");
6628 target_terminal_ours_for_output ();
6629 error_stream(tmp_error_stream);
6630 }
6631 else
6632 b->inserted = 1;
6633 }
6634 }
6635
6636 free_command_lines (&bpt->commands);
6637 if (bpt->cond)
6638 xfree (bpt->cond);
6639 if (bpt->cond_string != NULL)
6640 xfree (bpt->cond_string);
6641 if (bpt->addr_string != NULL)
6642 xfree (bpt->addr_string);
6643 if (bpt->exp != NULL)
6644 xfree (bpt->exp);
6645 if (bpt->exp_string != NULL)
6646 xfree (bpt->exp_string);
6647 if (bpt->val != NULL)
6648 value_free (bpt->val);
6649 if (bpt->source_file != NULL)
6650 xfree (bpt->source_file);
6651 if (bpt->dll_pathname != NULL)
6652 xfree (bpt->dll_pathname);
6653 if (bpt->triggered_dll_pathname != NULL)
6654 xfree (bpt->triggered_dll_pathname);
6655 if (bpt->exec_pathname != NULL)
6656 xfree (bpt->exec_pathname);
6657
6658 /* Be sure no bpstat's are pointing at it after it's been freed. */
6659 /* FIXME, how can we find all bpstat's?
6660 We just check stop_bpstat for now. */
6661 for (bs = stop_bpstat; bs; bs = bs->next)
6662 if (bs->breakpoint_at == bpt)
6663 {
6664 bs->breakpoint_at = NULL;
6665 bs->old_val = NULL;
6666 /* bs->commands will be freed later. */
6667 }
6668 /* On the chance that someone will soon try again to delete this same
6669 bp, we mark it as deleted before freeing its storage. */
6670 bpt->type = bp_none;
6671
6672 xfree (bpt);
6673 }
6674
6675 static void
6676 do_delete_breakpoint_cleanup (void *b)
6677 {
6678 delete_breakpoint (b);
6679 }
6680
6681 struct cleanup *
6682 make_cleanup_delete_breakpoint (struct breakpoint *b)
6683 {
6684 return make_cleanup (do_delete_breakpoint_cleanup, b);
6685 }
6686
6687 struct cleanup *
6688 make_exec_cleanup_delete_breakpoint (struct breakpoint *b)
6689 {
6690 return make_exec_cleanup (do_delete_breakpoint_cleanup, b);
6691 }
6692
6693 void
6694 delete_command (char *arg, int from_tty)
6695 {
6696 struct breakpoint *b, *temp;
6697
6698 dont_repeat ();
6699
6700 if (arg == 0)
6701 {
6702 int breaks_to_delete = 0;
6703
6704 /* Delete all breakpoints if no argument.
6705 Do not delete internal or call-dummy breakpoints, these
6706 have to be deleted with an explicit breakpoint number argument. */
6707 ALL_BREAKPOINTS (b)
6708 {
6709 if (b->type != bp_call_dummy &&
6710 b->type != bp_shlib_event &&
6711 b->type != bp_thread_event &&
6712 b->type != bp_overlay_event &&
6713 b->number >= 0)
6714 breaks_to_delete = 1;
6715 }
6716
6717 /* Ask user only if there are some breakpoints to delete. */
6718 if (!from_tty
6719 || (breaks_to_delete && query ("Delete all breakpoints? ")))
6720 {
6721 ALL_BREAKPOINTS_SAFE (b, temp)
6722 {
6723 if (b->type != bp_call_dummy &&
6724 b->type != bp_shlib_event &&
6725 b->type != bp_thread_event &&
6726 b->type != bp_overlay_event &&
6727 b->number >= 0)
6728 delete_breakpoint (b);
6729 }
6730 }
6731 }
6732 else
6733 map_breakpoint_numbers (arg, delete_breakpoint);
6734 }
6735
6736 /* Reset a breakpoint given it's struct breakpoint * BINT.
6737 The value we return ends up being the return value from catch_errors.
6738 Unused in this case. */
6739
6740 static int
6741 breakpoint_re_set_one (void *bint)
6742 {
6743 /* get past catch_errs */
6744 struct breakpoint *b = (struct breakpoint *) bint;
6745 struct value *mark;
6746 int i;
6747 struct symtabs_and_lines sals;
6748 char *s;
6749 enum enable_state save_enable;
6750
6751 switch (b->type)
6752 {
6753 case bp_none:
6754 warning ("attempted to reset apparently deleted breakpoint #%d?",
6755 b->number);
6756 return 0;
6757 case bp_breakpoint:
6758 case bp_hardware_breakpoint:
6759 case bp_catch_load:
6760 case bp_catch_unload:
6761 if (b->addr_string == NULL)
6762 {
6763 /* Anything without a string can't be re-set. */
6764 delete_breakpoint (b);
6765 return 0;
6766 }
6767 /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote:
6768
6769 ``And a hack it is, although Apple's Darwin version of GDB
6770 contains an almost identical hack to implement a "future
6771 break" command. It seems to work in many real world cases,
6772 but it is easy to come up with a test case where the patch
6773 doesn't help at all.''
6774
6775 ``It seems that the way GDB implements breakpoints - in -
6776 shared - libraries was designed for a.out shared library
6777 systems (SunOS 4) where shared libraries were loaded at a
6778 fixed address in memory. Since ELF shared libraries can (and
6779 will) be loaded at any address in memory, things break.
6780 Fixing this is not trivial. Therefore, I'm not sure whether
6781 we should add this hack to the branch only. I cannot
6782 guarantee that things will be fixed on the trunk in the near
6783 future.''
6784
6785 In case we have a problem, disable this breakpoint. We'll
6786 restore its status if we succeed. Don't disable a
6787 shlib_disabled breakpoint though. There's a fair chance we
6788 can't re-set it if the shared library it's in hasn't been
6789 loaded yet. */
6790 save_enable = b->enable_state;
6791 if (b->enable_state != bp_shlib_disabled)
6792 b->enable_state = bp_disabled;
6793
6794 set_language (b->language);
6795 input_radix = b->input_radix;
6796 s = b->addr_string;
6797 sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL);
6798 for (i = 0; i < sals.nelts; i++)
6799 {
6800 resolve_sal_pc (&sals.sals[i]);
6801
6802 /* Reparse conditions, they might contain references to the
6803 old symtab. */
6804 if (b->cond_string != NULL)
6805 {
6806 s = b->cond_string;
6807 if (b->cond)
6808 xfree (b->cond);
6809 b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0);
6810 }
6811
6812 /* We need to re-set the breakpoint if the address changes... */
6813 if (b->address != sals.sals[i].pc
6814 /* ...or new and old breakpoints both have source files, and
6815 the source file name or the line number changes... */
6816 || (b->source_file != NULL
6817 && sals.sals[i].symtab != NULL
6818 && (!STREQ (b->source_file, sals.sals[i].symtab->filename)
6819 || b->line_number != sals.sals[i].line)
6820 )
6821 /* ...or we switch between having a source file and not having
6822 one. */
6823 || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL))
6824 )
6825 {
6826 if (b->source_file != NULL)
6827 xfree (b->source_file);
6828 if (sals.sals[i].symtab == NULL)
6829 b->source_file = NULL;
6830 else
6831 b->source_file =
6832 savestring (sals.sals[i].symtab->filename,
6833 strlen (sals.sals[i].symtab->filename));
6834 b->line_number = sals.sals[i].line;
6835 b->address = sals.sals[i].pc;
6836
6837 /* Used to check for duplicates here, but that can
6838 cause trouble, as it doesn't check for disabled
6839 breakpoints. */
6840
6841 mention (b);
6842
6843 /* Might be better to do this just once per breakpoint_re_set,
6844 rather than once for every breakpoint. */
6845 breakpoints_changed ();
6846 }
6847 b->section = sals.sals[i].section;
6848 b->enable_state = save_enable; /* Restore it, this worked. */
6849
6850
6851 /* Now that this is re-enabled, check_duplicates
6852 can be used. */
6853 check_duplicates (b);
6854
6855 }
6856 xfree (sals.sals);
6857 break;
6858
6859 case bp_watchpoint:
6860 case bp_hardware_watchpoint:
6861 case bp_read_watchpoint:
6862 case bp_access_watchpoint:
6863 innermost_block = NULL;
6864 /* The issue arises of what context to evaluate this in. The
6865 same one as when it was set, but what does that mean when
6866 symbols have been re-read? We could save the filename and
6867 functionname, but if the context is more local than that, the
6868 best we could do would be something like how many levels deep
6869 and which index at that particular level, but that's going to
6870 be less stable than filenames or function names. */
6871
6872 /* So for now, just use a global context. */
6873 if (b->exp)
6874 xfree (b->exp);
6875 b->exp = parse_expression (b->exp_string);
6876 b->exp_valid_block = innermost_block;
6877 mark = value_mark ();
6878 if (b->val)
6879 value_free (b->val);
6880 b->val = evaluate_expression (b->exp);
6881 release_value (b->val);
6882 if (VALUE_LAZY (b->val) && b->enable_state == bp_enabled)
6883 value_fetch_lazy (b->val);
6884
6885 if (b->cond_string != NULL)
6886 {
6887 s = b->cond_string;
6888 if (b->cond)
6889 xfree (b->cond);
6890 b->cond = parse_exp_1 (&s, (struct block *) 0, 0);
6891 }
6892 if (b->enable_state == bp_enabled)
6893 mention (b);
6894 value_free_to_mark (mark);
6895 break;
6896 case bp_catch_catch:
6897 case bp_catch_throw:
6898 break;
6899 /* We needn't really do anything to reset these, since the mask
6900 that requests them is unaffected by e.g., new libraries being
6901 loaded. */
6902 case bp_catch_fork:
6903 case bp_catch_vfork:
6904 case bp_catch_exec:
6905 break;
6906
6907 default:
6908 printf_filtered ("Deleting unknown breakpoint type %d\n", b->type);
6909 /* fall through */
6910 /* Delete longjmp and overlay event breakpoints; they will be
6911 reset later by breakpoint_re_set. */
6912 case bp_longjmp:
6913 case bp_longjmp_resume:
6914 case bp_overlay_event:
6915 delete_breakpoint (b);
6916 break;
6917
6918 /* This breakpoint is special, it's set up when the inferior
6919 starts and we really don't want to touch it. */
6920 case bp_shlib_event:
6921
6922 /* Like bp_shlib_event, this breakpoint type is special.
6923 Once it is set up, we do not want to touch it. */
6924 case bp_thread_event:
6925
6926 /* Keep temporary breakpoints, which can be encountered when we step
6927 over a dlopen call and SOLIB_ADD is resetting the breakpoints.
6928 Otherwise these should have been blown away via the cleanup chain
6929 or by breakpoint_init_inferior when we rerun the executable. */
6930 case bp_until:
6931 case bp_finish:
6932 case bp_watchpoint_scope:
6933 case bp_call_dummy:
6934 case bp_step_resume:
6935 break;
6936 }
6937
6938 return 0;
6939 }
6940
6941 /* Re-set all breakpoints after symbols have been re-loaded. */
6942 void
6943 breakpoint_re_set (void)
6944 {
6945 struct breakpoint *b, *temp;
6946 enum language save_language;
6947 int save_input_radix;
6948
6949 save_language = current_language->la_language;
6950 save_input_radix = input_radix;
6951 ALL_BREAKPOINTS_SAFE (b, temp)
6952 {
6953 /* Format possible error msg */
6954 char *message = xstrprintf ("Error in re-setting breakpoint %d:\n",
6955 b->number);
6956 struct cleanup *cleanups = make_cleanup (xfree, message);
6957 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL);
6958 do_cleanups (cleanups);
6959 }
6960 set_language (save_language);
6961 input_radix = save_input_radix;
6962
6963 if (GET_LONGJMP_TARGET_P ())
6964 {
6965 create_longjmp_breakpoint ("longjmp");
6966 create_longjmp_breakpoint ("_longjmp");
6967 create_longjmp_breakpoint ("siglongjmp");
6968 create_longjmp_breakpoint ("_siglongjmp");
6969 create_longjmp_breakpoint (NULL);
6970 }
6971
6972 create_overlay_event_breakpoint ("_ovly_debug_event");
6973 }
6974 \f
6975 /* Reset the thread number of this breakpoint:
6976
6977 - If the breakpoint is for all threads, leave it as-is.
6978 - Else, reset it to the current thread for inferior_ptid. */
6979 void
6980 breakpoint_re_set_thread (struct breakpoint *b)
6981 {
6982 if (b->thread != -1)
6983 {
6984 if (in_thread_list (inferior_ptid))
6985 b->thread = pid_to_thread_id (inferior_ptid);
6986 }
6987 }
6988
6989 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
6990 If from_tty is nonzero, it prints a message to that effect,
6991 which ends with a period (no newline). */
6992
6993 void
6994 set_ignore_count (int bptnum, int count, int from_tty)
6995 {
6996 struct breakpoint *b;
6997
6998 if (count < 0)
6999 count = 0;
7000
7001 ALL_BREAKPOINTS (b)
7002 if (b->number == bptnum)
7003 {
7004 b->ignore_count = count;
7005 if (from_tty)
7006 {
7007 if (count == 0)
7008 printf_filtered ("Will stop next time breakpoint %d is reached.",
7009 bptnum);
7010 else if (count == 1)
7011 printf_filtered ("Will ignore next crossing of breakpoint %d.",
7012 bptnum);
7013 else
7014 printf_filtered ("Will ignore next %d crossings of breakpoint %d.",
7015 count, bptnum);
7016 }
7017 breakpoints_changed ();
7018 breakpoint_modify_event (b->number);
7019 return;
7020 }
7021
7022 error ("No breakpoint number %d.", bptnum);
7023 }
7024
7025 /* Clear the ignore counts of all breakpoints. */
7026 void
7027 breakpoint_clear_ignore_counts (void)
7028 {
7029 struct breakpoint *b;
7030
7031 ALL_BREAKPOINTS (b)
7032 b->ignore_count = 0;
7033 }
7034
7035 /* Command to set ignore-count of breakpoint N to COUNT. */
7036
7037 static void
7038 ignore_command (char *args, int from_tty)
7039 {
7040 char *p = args;
7041 int num;
7042
7043 if (p == 0)
7044 error_no_arg ("a breakpoint number");
7045
7046 num = get_number (&p);
7047 if (num == 0)
7048 error ("bad breakpoint number: '%s'", args);
7049 if (*p == 0)
7050 error ("Second argument (specified ignore-count) is missing.");
7051
7052 set_ignore_count (num,
7053 longest_to_int (value_as_long (parse_and_eval (p))),
7054 from_tty);
7055 if (from_tty)
7056 printf_filtered ("\n");
7057 }
7058 \f
7059 /* Call FUNCTION on each of the breakpoints
7060 whose numbers are given in ARGS. */
7061
7062 static void
7063 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *))
7064 {
7065 char *p = args;
7066 char *p1;
7067 int num;
7068 struct breakpoint *b, *tmp;
7069 int match;
7070
7071 if (p == 0)
7072 error_no_arg ("one or more breakpoint numbers");
7073
7074 while (*p)
7075 {
7076 match = 0;
7077 p1 = p;
7078
7079 num = get_number_or_range (&p1);
7080 if (num == 0)
7081 {
7082 warning ("bad breakpoint number at or near '%s'", p);
7083 }
7084 else
7085 {
7086 ALL_BREAKPOINTS_SAFE (b, tmp)
7087 if (b->number == num)
7088 {
7089 struct breakpoint *related_breakpoint = b->related_breakpoint;
7090 match = 1;
7091 function (b);
7092 if (related_breakpoint)
7093 function (related_breakpoint);
7094 break;
7095 }
7096 if (match == 0)
7097 printf_unfiltered ("No breakpoint number %d.\n", num);
7098 }
7099 p = p1;
7100 }
7101 }
7102
7103 /* Set ignore-count of breakpoint number BPTNUM to COUNT.
7104 If from_tty is nonzero, it prints a message to that effect,
7105 which ends with a period (no newline). */
7106
7107 void
7108 disable_breakpoint (struct breakpoint *bpt)
7109 {
7110 /* Never disable a watchpoint scope breakpoint; we want to
7111 hit them when we leave scope so we can delete both the
7112 watchpoint and its scope breakpoint at that time. */
7113 if (bpt->type == bp_watchpoint_scope)
7114 return;
7115
7116 /* You can't disable permanent breakpoints. */
7117 if (bpt->enable_state == bp_permanent)
7118 return;
7119
7120 bpt->enable_state = bp_disabled;
7121
7122 check_duplicates (bpt);
7123
7124 if (modify_breakpoint_hook)
7125 modify_breakpoint_hook (bpt);
7126 breakpoint_modify_event (bpt->number);
7127 }
7128
7129 static void
7130 disable_command (char *args, int from_tty)
7131 {
7132 struct breakpoint *bpt;
7133 if (args == 0)
7134 ALL_BREAKPOINTS (bpt)
7135 switch (bpt->type)
7136 {
7137 case bp_none:
7138 warning ("attempted to disable apparently deleted breakpoint #%d?",
7139 bpt->number);
7140 continue;
7141 case bp_breakpoint:
7142 case bp_catch_load:
7143 case bp_catch_unload:
7144 case bp_catch_fork:
7145 case bp_catch_vfork:
7146 case bp_catch_exec:
7147 case bp_catch_catch:
7148 case bp_catch_throw:
7149 case bp_hardware_breakpoint:
7150 case bp_watchpoint:
7151 case bp_hardware_watchpoint:
7152 case bp_read_watchpoint:
7153 case bp_access_watchpoint:
7154 disable_breakpoint (bpt);
7155 default:
7156 continue;
7157 }
7158 else
7159 map_breakpoint_numbers (args, disable_breakpoint);
7160 }
7161
7162 static void
7163 do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition)
7164 {
7165 struct frame_info *save_selected_frame = NULL;
7166 int save_selected_frame_level = -1;
7167 int target_resources_ok, other_type_used;
7168 struct value *mark;
7169
7170 if (bpt->type == bp_hardware_breakpoint)
7171 {
7172 int i;
7173 i = hw_breakpoint_used_count ();
7174 target_resources_ok =
7175 TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint,
7176 i + 1, 0);
7177 if (target_resources_ok == 0)
7178 error ("No hardware breakpoint support in the target.");
7179 else if (target_resources_ok < 0)
7180 error ("Hardware breakpoints used exceeds limit.");
7181 }
7182
7183 if (bpt->enable_state != bp_permanent)
7184 bpt->enable_state = bp_enabled;
7185 bpt->disposition = disposition;
7186 check_duplicates (bpt);
7187 breakpoints_changed ();
7188
7189 if (bpt->type == bp_watchpoint ||
7190 bpt->type == bp_hardware_watchpoint ||
7191 bpt->type == bp_read_watchpoint ||
7192 bpt->type == bp_access_watchpoint)
7193 {
7194 if (bpt->exp_valid_block != NULL)
7195 {
7196 struct frame_info *fr =
7197 fr = frame_find_by_id (bpt->watchpoint_frame);
7198 if (fr == NULL)
7199 {
7200 printf_filtered ("\
7201 Cannot enable watchpoint %d because the block in which its expression\n\
7202 is valid is not currently in scope.\n", bpt->number);
7203 bpt->enable_state = bp_disabled;
7204 return;
7205 }
7206
7207 save_selected_frame = deprecated_selected_frame;
7208 save_selected_frame_level = frame_relative_level (deprecated_selected_frame);
7209 select_frame (fr);
7210 }
7211
7212 value_free (bpt->val);
7213 mark = value_mark ();
7214 bpt->val = evaluate_expression (bpt->exp);
7215 release_value (bpt->val);
7216 if (VALUE_LAZY (bpt->val))
7217 value_fetch_lazy (bpt->val);
7218
7219 if (bpt->type == bp_hardware_watchpoint ||
7220 bpt->type == bp_read_watchpoint ||
7221 bpt->type == bp_access_watchpoint)
7222 {
7223 int i = hw_watchpoint_used_count (bpt->type, &other_type_used);
7224 int mem_cnt = can_use_hardware_watchpoint (bpt->val);
7225
7226 /* Hack around 'unused var' error for some targets here */
7227 (void) mem_cnt, i;
7228 target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT (
7229 bpt->type, i + mem_cnt, other_type_used);
7230 /* we can consider of type is bp_hardware_watchpoint, convert to
7231 bp_watchpoint in the following condition */
7232 if (target_resources_ok < 0)
7233 {
7234 printf_filtered ("\
7235 Cannot enable watchpoint %d because target watch resources\n\
7236 have been allocated for other watchpoints.\n", bpt->number);
7237 bpt->enable_state = bp_disabled;
7238 value_free_to_mark (mark);
7239 return;
7240 }
7241 }
7242
7243 if (save_selected_frame_level >= 0)
7244 select_frame (save_selected_frame);
7245 value_free_to_mark (mark);
7246 }
7247 if (modify_breakpoint_hook)
7248 modify_breakpoint_hook (bpt);
7249 breakpoint_modify_event (bpt->number);
7250 }
7251
7252 void
7253 enable_breakpoint (struct breakpoint *bpt)
7254 {
7255 do_enable_breakpoint (bpt, bpt->disposition);
7256 }
7257
7258 /* The enable command enables the specified breakpoints (or all defined
7259 breakpoints) so they once again become (or continue to be) effective
7260 in stopping the inferior. */
7261
7262 static void
7263 enable_command (char *args, int from_tty)
7264 {
7265 struct breakpoint *bpt;
7266 if (args == 0)
7267 ALL_BREAKPOINTS (bpt)
7268 switch (bpt->type)
7269 {
7270 case bp_none:
7271 warning ("attempted to enable apparently deleted breakpoint #%d?",
7272 bpt->number);
7273 continue;
7274 case bp_breakpoint:
7275 case bp_catch_load:
7276 case bp_catch_unload:
7277 case bp_catch_fork:
7278 case bp_catch_vfork:
7279 case bp_catch_exec:
7280 case bp_catch_catch:
7281 case bp_catch_throw:
7282 case bp_hardware_breakpoint:
7283 case bp_watchpoint:
7284 case bp_hardware_watchpoint:
7285 case bp_read_watchpoint:
7286 case bp_access_watchpoint:
7287 enable_breakpoint (bpt);
7288 default:
7289 continue;
7290 }
7291 else
7292 map_breakpoint_numbers (args, enable_breakpoint);
7293 }
7294
7295 static void
7296 enable_once_breakpoint (struct breakpoint *bpt)
7297 {
7298 do_enable_breakpoint (bpt, disp_disable);
7299 }
7300
7301 static void
7302 enable_once_command (char *args, int from_tty)
7303 {
7304 map_breakpoint_numbers (args, enable_once_breakpoint);
7305 }
7306
7307 static void
7308 enable_delete_breakpoint (struct breakpoint *bpt)
7309 {
7310 do_enable_breakpoint (bpt, disp_del);
7311 }
7312
7313 static void
7314 enable_delete_command (char *args, int from_tty)
7315 {
7316 map_breakpoint_numbers (args, enable_delete_breakpoint);
7317 }
7318 \f
7319 /* Use default_breakpoint_'s, or nothing if they aren't valid. */
7320
7321 struct symtabs_and_lines
7322 decode_line_spec_1 (char *string, int funfirstline)
7323 {
7324 struct symtabs_and_lines sals;
7325 if (string == 0)
7326 error ("Empty line specification.");
7327 if (default_breakpoint_valid)
7328 sals = decode_line_1 (&string, funfirstline,
7329 default_breakpoint_symtab,
7330 default_breakpoint_line,
7331 (char ***) NULL);
7332 else
7333 sals = decode_line_1 (&string, funfirstline,
7334 (struct symtab *) NULL, 0, (char ***) NULL);
7335 if (*string)
7336 error ("Junk at end of line specification: %s", string);
7337 return sals;
7338 }
7339 \f
7340 void
7341 _initialize_breakpoint (void)
7342 {
7343 struct cmd_list_element *c;
7344
7345 breakpoint_chain = 0;
7346 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful
7347 before a breakpoint is set. */
7348 breakpoint_count = 0;
7349
7350 add_com ("ignore", class_breakpoint, ignore_command,
7351 "Set ignore-count of breakpoint number N to COUNT.\n\
7352 Usage is `ignore N COUNT'.");
7353 if (xdb_commands)
7354 add_com_alias ("bc", "ignore", class_breakpoint, 1);
7355
7356 add_com ("commands", class_breakpoint, commands_command,
7357 "Set commands to be executed when a breakpoint is hit.\n\
7358 Give breakpoint number as argument after \"commands\".\n\
7359 With no argument, the targeted breakpoint is the last one set.\n\
7360 The commands themselves follow starting on the next line.\n\
7361 Type a line containing \"end\" to indicate the end of them.\n\
7362 Give \"silent\" as the first line to make the breakpoint silent;\n\
7363 then no output is printed when it is hit, except what the commands print.");
7364
7365 add_com ("condition", class_breakpoint, condition_command,
7366 "Specify breakpoint number N to break only if COND is true.\n\
7367 Usage is `condition N COND', where N is an integer and COND is an\n\
7368 expression to be evaluated whenever breakpoint N is reached.");
7369
7370 c = add_com ("tbreak", class_breakpoint, tbreak_command,
7371 "Set a temporary breakpoint. Args like \"break\" command.\n\
7372 Like \"break\" except the breakpoint is only temporary,\n\
7373 so it will be deleted when hit. Equivalent to \"break\" followed\n\
7374 by using \"enable delete\" on the breakpoint number.");
7375 set_cmd_completer (c, location_completer);
7376
7377 c = add_com ("hbreak", class_breakpoint, hbreak_command,
7378 "Set a hardware assisted breakpoint. Args like \"break\" command.\n\
7379 Like \"break\" except the breakpoint requires hardware support,\n\
7380 some target hardware may not have this support.");
7381 set_cmd_completer (c, location_completer);
7382
7383 c = add_com ("thbreak", class_breakpoint, thbreak_command,
7384 "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\
7385 Like \"hbreak\" except the breakpoint is only temporary,\n\
7386 so it will be deleted when hit.");
7387 set_cmd_completer (c, location_completer);
7388
7389 add_prefix_cmd ("enable", class_breakpoint, enable_command,
7390 "Enable some breakpoints.\n\
7391 Give breakpoint numbers (separated by spaces) as arguments.\n\
7392 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7393 This is used to cancel the effect of the \"disable\" command.\n\
7394 With a subcommand you can enable temporarily.",
7395 &enablelist, "enable ", 1, &cmdlist);
7396 if (xdb_commands)
7397 add_com ("ab", class_breakpoint, enable_command,
7398 "Enable some breakpoints.\n\
7399 Give breakpoint numbers (separated by spaces) as arguments.\n\
7400 With no subcommand, breakpoints are enabled until you command otherwise.\n\
7401 This is used to cancel the effect of the \"disable\" command.\n\
7402 With a subcommand you can enable temporarily.");
7403
7404 add_com_alias ("en", "enable", class_breakpoint, 1);
7405
7406 add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
7407 "Enable some breakpoints.\n\
7408 Give breakpoint numbers (separated by spaces) as arguments.\n\
7409 This is used to cancel the effect of the \"disable\" command.\n\
7410 May be abbreviated to simply \"enable\".\n",
7411 &enablebreaklist, "enable breakpoints ", 1, &enablelist);
7412
7413 add_cmd ("once", no_class, enable_once_command,
7414 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7415 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7416 &enablebreaklist);
7417
7418 add_cmd ("delete", no_class, enable_delete_command,
7419 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7420 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7421 &enablebreaklist);
7422
7423 add_cmd ("delete", no_class, enable_delete_command,
7424 "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\
7425 If a breakpoint is hit while enabled in this fashion, it is deleted.",
7426 &enablelist);
7427
7428 add_cmd ("once", no_class, enable_once_command,
7429 "Enable breakpoints for one hit. Give breakpoint numbers.\n\
7430 If a breakpoint is hit while enabled in this fashion, it becomes disabled.",
7431 &enablelist);
7432
7433 add_prefix_cmd ("disable", class_breakpoint, disable_command,
7434 "Disable some breakpoints.\n\
7435 Arguments are breakpoint numbers with spaces in between.\n\
7436 To disable all breakpoints, give no argument.\n\
7437 A disabled breakpoint is not forgotten, but has no effect until reenabled.",
7438 &disablelist, "disable ", 1, &cmdlist);
7439 add_com_alias ("dis", "disable", class_breakpoint, 1);
7440 add_com_alias ("disa", "disable", class_breakpoint, 1);
7441 if (xdb_commands)
7442 add_com ("sb", class_breakpoint, disable_command,
7443 "Disable some breakpoints.\n\
7444 Arguments are breakpoint numbers with spaces in between.\n\
7445 To disable all breakpoints, give no argument.\n\
7446 A disabled breakpoint is not forgotten, but has no effect until reenabled.");
7447
7448 add_cmd ("breakpoints", class_alias, disable_command,
7449 "Disable some breakpoints.\n\
7450 Arguments are breakpoint numbers with spaces in between.\n\
7451 To disable all breakpoints, give no argument.\n\
7452 A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
7453 This command may be abbreviated \"disable\".",
7454 &disablelist);
7455
7456 add_prefix_cmd ("delete", class_breakpoint, delete_command,
7457 "Delete some breakpoints or auto-display expressions.\n\
7458 Arguments are breakpoint numbers with spaces in between.\n\
7459 To delete all breakpoints, give no argument.\n\
7460 \n\
7461 Also a prefix command for deletion of other GDB objects.\n\
7462 The \"unset\" command is also an alias for \"delete\".",
7463 &deletelist, "delete ", 1, &cmdlist);
7464 add_com_alias ("d", "delete", class_breakpoint, 1);
7465 if (xdb_commands)
7466 add_com ("db", class_breakpoint, delete_command,
7467 "Delete some breakpoints.\n\
7468 Arguments are breakpoint numbers with spaces in between.\n\
7469 To delete all breakpoints, give no argument.\n");
7470
7471 add_cmd ("breakpoints", class_alias, delete_command,
7472 "Delete some breakpoints or auto-display expressions.\n\
7473 Arguments are breakpoint numbers with spaces in between.\n\
7474 To delete all breakpoints, give no argument.\n\
7475 This command may be abbreviated \"delete\".",
7476 &deletelist);
7477
7478 add_com ("clear", class_breakpoint, clear_command,
7479 concat ("Clear breakpoint at specified line or function.\n\
7480 Argument may be line number, function name, or \"*\" and an address.\n\
7481 If line number is specified, all breakpoints in that line are cleared.\n\
7482 If function is specified, breakpoints at beginning of function are cleared.\n\
7483 If an address is specified, breakpoints at that address are cleared.\n\n",
7484 "With no argument, clears all breakpoints in the line that the selected frame\n\
7485 is executing in.\n\
7486 \n\
7487 See also the \"delete\" command which clears breakpoints by number.", NULL));
7488
7489 c = add_com ("break", class_breakpoint, break_command,
7490 concat ("Set breakpoint at specified line or function.\n\
7491 Argument may be line number, function name, or \"*\" and an address.\n\
7492 If line number is specified, break at start of code for that line.\n\
7493 If function is specified, break at start of code for that function.\n\
7494 If an address is specified, break at that exact address.\n",
7495 "With no arg, uses current execution address of selected stack frame.\n\
7496 This is useful for breaking on return to a stack frame.\n\
7497 \n\
7498 Multiple breakpoints at one place are permitted, and useful if conditional.\n\
7499 \n\
7500 Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL));
7501 set_cmd_completer (c, location_completer);
7502
7503 add_com_alias ("b", "break", class_run, 1);
7504 add_com_alias ("br", "break", class_run, 1);
7505 add_com_alias ("bre", "break", class_run, 1);
7506 add_com_alias ("brea", "break", class_run, 1);
7507
7508 if (xdb_commands)
7509 {
7510 add_com_alias ("ba", "break", class_breakpoint, 1);
7511 add_com_alias ("bu", "ubreak", class_breakpoint, 1);
7512 }
7513
7514 if (dbx_commands)
7515 {
7516 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command,
7517 "Break in function/address or break at a line in the current file.",
7518 &stoplist, "stop ", 1, &cmdlist);
7519 add_cmd ("in", class_breakpoint, stopin_command,
7520 "Break in function or address.\n", &stoplist);
7521 add_cmd ("at", class_breakpoint, stopat_command,
7522 "Break at a line in the current file.\n", &stoplist);
7523 add_com ("status", class_info, breakpoints_info,
7524 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7525 The \"Type\" column indicates one of:\n\
7526 \tbreakpoint - normal breakpoint\n\
7527 \twatchpoint - watchpoint\n\
7528 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7529 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7530 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7531 address and file/line number respectively.\n\n",
7532 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7533 are set to the address of the last breakpoint listed.\n\n\
7534 Convenience variable \"$bpnum\" contains the number of the last\n\
7535 breakpoint set.", NULL));
7536 }
7537
7538 add_info ("breakpoints", breakpoints_info,
7539 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7540 The \"Type\" column indicates one of:\n\
7541 \tbreakpoint - normal breakpoint\n\
7542 \twatchpoint - watchpoint\n\
7543 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7544 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7545 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7546 address and file/line number respectively.\n\n",
7547 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7548 are set to the address of the last breakpoint listed.\n\n\
7549 Convenience variable \"$bpnum\" contains the number of the last\n\
7550 breakpoint set.", NULL));
7551
7552 if (xdb_commands)
7553 add_com ("lb", class_breakpoint, breakpoints_info,
7554 concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\
7555 The \"Type\" column indicates one of:\n\
7556 \tbreakpoint - normal breakpoint\n\
7557 \twatchpoint - watchpoint\n\
7558 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7559 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7560 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7561 address and file/line number respectively.\n\n",
7562 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7563 are set to the address of the last breakpoint listed.\n\n\
7564 Convenience variable \"$bpnum\" contains the number of the last\n\
7565 breakpoint set.", NULL));
7566
7567 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints,
7568 concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\
7569 The \"Type\" column indicates one of:\n\
7570 \tbreakpoint - normal breakpoint\n\
7571 \twatchpoint - watchpoint\n\
7572 \tlongjmp - internal breakpoint used to step through longjmp()\n\
7573 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\
7574 \tuntil - internal breakpoint used by the \"until\" command\n\
7575 \tfinish - internal breakpoint used by the \"finish\" command\n",
7576 "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\
7577 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\
7578 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\
7579 address and file/line number respectively.\n\n",
7580 "Convenience variable \"$_\" and default examine address for \"x\"\n\
7581 are set to the address of the last breakpoint listed.\n\n\
7582 Convenience variable \"$bpnum\" contains the number of the last\n\
7583 breakpoint set.", NULL),
7584 &maintenanceinfolist);
7585
7586 add_com ("catch", class_breakpoint, catch_command,
7587 "Set catchpoints to catch events.\n\
7588 Raised signals may be caught:\n\
7589 \tcatch signal - all signals\n\
7590 \tcatch signal <signame> - a particular signal\n\
7591 Raised exceptions may be caught:\n\
7592 \tcatch throw - all exceptions, when thrown\n\
7593 \tcatch throw <exceptname> - a particular exception, when thrown\n\
7594 \tcatch catch - all exceptions, when caught\n\
7595 \tcatch catch <exceptname> - a particular exception, when caught\n\
7596 Thread or process events may be caught:\n\
7597 \tcatch thread_start - any threads, just after creation\n\
7598 \tcatch thread_exit - any threads, just before expiration\n\
7599 \tcatch thread_join - any threads, just after joins\n\
7600 Process events may be caught:\n\
7601 \tcatch start - any processes, just after creation\n\
7602 \tcatch exit - any processes, just before expiration\n\
7603 \tcatch fork - calls to fork()\n\
7604 \tcatch vfork - calls to vfork()\n\
7605 \tcatch exec - calls to exec()\n\
7606 Dynamically-linked library events may be caught:\n\
7607 \tcatch load - loads of any library\n\
7608 \tcatch load <libname> - loads of a particular library\n\
7609 \tcatch unload - unloads of any library\n\
7610 \tcatch unload <libname> - unloads of a particular library\n\
7611 The act of your program's execution stopping may also be caught:\n\
7612 \tcatch stop\n\n\
7613 C++ exceptions may be caught:\n\
7614 \tcatch throw - all exceptions, when thrown\n\
7615 \tcatch catch - all exceptions, when caught\n\
7616 \n\
7617 Do \"help set follow-fork-mode\" for info on debugging your program\n\
7618 after a fork or vfork is caught.\n\n\
7619 Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
7620
7621 add_com ("tcatch", class_breakpoint, tcatch_command,
7622 "Set temporary catchpoints to catch events.\n\
7623 Args like \"catch\" command.\n\
7624 Like \"catch\" except the catchpoint is only temporary,\n\
7625 so it will be deleted when hit. Equivalent to \"catch\" followed\n\
7626 by using \"enable delete\" on the catchpoint number.");
7627
7628 c = add_com ("watch", class_breakpoint, watch_command,
7629 "Set a watchpoint for an expression.\n\
7630 A watchpoint stops execution of your program whenever the value of\n\
7631 an expression changes.");
7632 set_cmd_completer (c, location_completer);
7633
7634 c = add_com ("rwatch", class_breakpoint, rwatch_command,
7635 "Set a read watchpoint for an expression.\n\
7636 A watchpoint stops execution of your program whenever the value of\n\
7637 an expression is read.");
7638 set_cmd_completer (c, location_completer);
7639
7640 c = add_com ("awatch", class_breakpoint, awatch_command,
7641 "Set a watchpoint for an expression.\n\
7642 A watchpoint stops execution of your program whenever the value of\n\
7643 an expression is either read or written.");
7644 set_cmd_completer (c, location_completer);
7645
7646 add_info ("watchpoints", breakpoints_info,
7647 "Synonym for ``info breakpoints''.");
7648
7649
7650 c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger,
7651 (char *) &can_use_hw_watchpoints,
7652 "Set debugger's willingness to use watchpoint hardware.\n\
7653 If zero, gdb will not use hardware for new watchpoints, even if\n\
7654 such is available. (However, any hardware watchpoints that were\n\
7655 created before setting this to nonzero, will continue to use watchpoint\n\
7656 hardware.)",
7657 &setlist);
7658 add_show_from_set (c, &showlist);
7659
7660 can_use_hw_watchpoints = 1;
7661 }
This page took 0.192789 seconds and 4 git commands to generate.