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