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