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