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