Changeset 641ef00 in rtems


Ignore:
Timestamp:
Sep 18, 2008, 3:51:34 AM (11 years ago)
Author:
Ralf Corsepius <ralf.corsepius@…>
Branches:
4.10, 4.11, master
Children:
ec9e8a9
Parents:
61852aa0
Message:

Remove *.orig files having crept into patch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • contrib/crossrpms/patches/gdb-6.8-rtems4.10-20080917.diff

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