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