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