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