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