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