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