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