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