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