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