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