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