119370Spst/* Everything about breakpoints, for GDB. 219370Spst 398944Sobrien Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 4130803Smarcel 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 5130803Smarcel Free Software Foundation, Inc. 619370Spst 798944Sobrien This file is part of GDB. 819370Spst 998944Sobrien This program is free software; you can redistribute it and/or modify 1098944Sobrien it under the terms of the GNU General Public License as published by 1198944Sobrien the Free Software Foundation; either version 2 of the License, or 1298944Sobrien (at your option) any later version. 1319370Spst 1498944Sobrien This program is distributed in the hope that it will be useful, 1598944Sobrien but WITHOUT ANY WARRANTY; without even the implied warranty of 1698944Sobrien MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1798944Sobrien GNU General Public License for more details. 1819370Spst 1998944Sobrien You should have received a copy of the GNU General Public License 2098944Sobrien along with this program; if not, write to the Free Software 2198944Sobrien Foundation, Inc., 59 Temple Place - Suite 330, 2298944Sobrien Boston, MA 02111-1307, USA. */ 2398944Sobrien 2419370Spst#include "defs.h" 2519370Spst#include <ctype.h> 2619370Spst#include "symtab.h" 2719370Spst#include "frame.h" 2819370Spst#include "breakpoint.h" 2919370Spst#include "gdbtypes.h" 3019370Spst#include "expression.h" 3119370Spst#include "gdbcore.h" 3219370Spst#include "gdbcmd.h" 3319370Spst#include "value.h" 3419370Spst#include "command.h" 3519370Spst#include "inferior.h" 3646283Sdfr#include "gdbthread.h" 3719370Spst#include "target.h" 3819370Spst#include "language.h" 3919370Spst#include "gdb_string.h" 4019370Spst#include "demangle.h" 4119370Spst#include "annotate.h" 4246283Sdfr#include "symfile.h" 4346283Sdfr#include "objfiles.h" 44130803Smarcel#include "source.h" 4598944Sobrien#include "linespec.h" 4698944Sobrien#include "completer.h" 4798944Sobrien#include "gdb.h" 4898944Sobrien#include "ui-out.h" 49130803Smarcel#include "cli/cli-script.h" 50130803Smarcel#include "gdb_assert.h" 51130803Smarcel#include "block.h" 5219370Spst 5398944Sobrien#include "gdb-events.h" 5498944Sobrien 5546283Sdfr/* Prototypes for local functions. */ 5619370Spst 5798944Sobrienstatic void until_break_command_continuation (struct continuation_arg *arg); 5819370Spst 5998944Sobrienstatic void catch_command_1 (char *, int, int); 6019370Spst 6198944Sobrienstatic void enable_delete_command (char *, int); 6219370Spst 6398944Sobrienstatic void enable_delete_breakpoint (struct breakpoint *); 6419370Spst 6598944Sobrienstatic void enable_once_command (char *, int); 6619370Spst 6798944Sobrienstatic void enable_once_breakpoint (struct breakpoint *); 6819370Spst 6998944Sobrienstatic void disable_command (char *, int); 7019370Spst 7198944Sobrienstatic void enable_command (char *, int); 7219370Spst 7398944Sobrienstatic void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); 7419370Spst 7598944Sobrienstatic void ignore_command (char *, int); 7619370Spst 77130803Smarcelstatic int breakpoint_re_set_one (void *); 7819370Spst 7998944Sobrienstatic void clear_command (char *, int); 8019370Spst 8198944Sobrienstatic void catch_command (char *, int); 8246283Sdfr 8398944Sobrienstatic void watch_command (char *, int); 8419370Spst 8598944Sobrienstatic int can_use_hardware_watchpoint (struct value *); 8619370Spst 8798944Sobrienextern void break_at_finish_command (char *, int); 8898944Sobrienextern void break_at_finish_at_depth_command (char *, int); 8919370Spst 9098944Sobrienextern void tbreak_at_finish_command (char *, int); 9119370Spst 92130803Smarcelstatic int break_command_1 (char *, int, int, struct breakpoint *); 9319370Spst 9498944Sobrienstatic void mention (struct breakpoint *); 9519370Spst 9698944Sobrienstruct breakpoint *set_raw_breakpoint (struct symtab_and_line, enum bptype); 9719370Spst 9898944Sobrienstatic void check_duplicates (struct breakpoint *); 9919370Spst 100130803Smarcelstatic void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); 101130803Smarcel 102130803Smarcelstatic CORE_ADDR adjust_breakpoint_address (CORE_ADDR bpaddr); 103130803Smarcel 10498944Sobrienstatic void describe_other_breakpoints (CORE_ADDR, asection *); 10519370Spst 10698944Sobrienstatic void breakpoints_info (char *, int); 10719370Spst 10898944Sobrienstatic void breakpoint_1 (int, int); 10919370Spst 11098944Sobrienstatic bpstat bpstat_alloc (struct breakpoint *, bpstat); 11119370Spst 112130803Smarcelstatic int breakpoint_cond_eval (void *); 11319370Spst 114130803Smarcelstatic void cleanup_executing_breakpoints (void *); 11519370Spst 11698944Sobrienstatic void commands_command (char *, int); 11719370Spst 11898944Sobrienstatic void condition_command (char *, int); 11919370Spst 12098944Sobrienstatic int get_number_trailer (char **, int); 12146283Sdfr 122130803Smarcelstatic int do_captured_parse_breakpoint (struct ui_out *, void *); 123130803Smarcel 12498944Sobrienvoid set_breakpoint_count (int); 12546283Sdfr 12698944Sobrientypedef enum 12798944Sobrien { 12898944Sobrien mark_inserted, 12998944Sobrien mark_uninserted 13098944Sobrien } 13198944Sobrieninsertion_state_t; 13219370Spst 133130803Smarcelstatic int remove_breakpoint (struct bp_location *, insertion_state_t); 13446283Sdfr 13598944Sobrienstatic enum print_stop_action print_it_typical (bpstat); 13646283Sdfr 13798944Sobrienstatic enum print_stop_action print_bp_stop_message (bpstat bs); 13846283Sdfr 13998944Sobrientypedef struct 14098944Sobrien { 14198944Sobrien enum exception_event_kind kind; 14298944Sobrien int enable_p; 14398944Sobrien } 14498944Sobrienargs_for_catchpoint_enable; 14546283Sdfr 146130803Smarcelstatic int watchpoint_check (void *); 14746283Sdfr 148130803Smarcelstatic int cover_target_enable_exception_callback (void *); 14946283Sdfr 15098944Sobrienstatic void maintenance_info_breakpoints (char *, int); 15146283Sdfr 15298944Sobrienstatic void create_longjmp_breakpoint (char *); 15346283Sdfr 15498944Sobrienstatic void create_overlay_event_breakpoint (char *); 15546283Sdfr 15698944Sobrienstatic int hw_breakpoint_used_count (void); 15746283Sdfr 15898944Sobrienstatic int hw_watchpoint_used_count (enum bptype, int *); 15946283Sdfr 16098944Sobrienstatic void hbreak_command (char *, int); 16146283Sdfr 16298944Sobrienstatic void thbreak_command (char *, int); 16346283Sdfr 16498944Sobrienstatic void watch_command_1 (char *, int, int); 16546283Sdfr 16698944Sobrienstatic void rwatch_command (char *, int); 16746283Sdfr 16898944Sobrienstatic void awatch_command (char *, int); 16946283Sdfr 17098944Sobrienstatic void do_enable_breakpoint (struct breakpoint *, enum bpdisp); 17146283Sdfr 17298944Sobrienstatic void solib_load_unload_1 (char *hookname, 17398944Sobrien int tempflag, 17498944Sobrien char *dll_pathname, 17598944Sobrien char *cond_string, enum bptype bp_kind); 17646283Sdfr 17798944Sobrienstatic void create_fork_vfork_event_catchpoint (int tempflag, 17898944Sobrien char *cond_string, 17998944Sobrien enum bptype bp_kind); 18046283Sdfr 18198944Sobrienstatic void break_at_finish_at_depth_command_1 (char *arg, 18298944Sobrien int flag, int from_tty); 18346283Sdfr 18498944Sobrienstatic void break_at_finish_command_1 (char *arg, int flag, int from_tty); 18546283Sdfr 18698944Sobrienstatic void stop_command (char *arg, int from_tty); 18746283Sdfr 18898944Sobrienstatic void stopin_command (char *arg, int from_tty); 18946283Sdfr 19098944Sobrienstatic void stopat_command (char *arg, int from_tty); 19119370Spst 19298944Sobrienstatic char *ep_find_event_name_end (char *arg); 19398944Sobrien 19498944Sobrienstatic char *ep_parse_optional_if_clause (char **arg); 19598944Sobrien 19698944Sobrienstatic char *ep_parse_optional_filename (char **arg); 19798944Sobrien 19898944Sobrienstatic void create_exception_catchpoint (int tempflag, char *cond_string, 19998944Sobrien enum exception_event_kind ex_event, 20098944Sobrien struct symtab_and_line *sal); 20198944Sobrien 20298944Sobrienstatic void catch_exception_command_1 (enum exception_event_kind ex_event, 20398944Sobrien char *arg, int tempflag, int from_tty); 20498944Sobrien 20598944Sobrienstatic void tcatch_command (char *arg, int from_tty); 20698944Sobrien 20798944Sobrienstatic void ep_skip_leading_whitespace (char **s); 20898944Sobrien 20998944Sobrien/* Prototypes for exported functions. */ 21098944Sobrien 21198944Sobrien/* If FALSE, gdb will not use hardware support for watchpoints, even 21298944Sobrien if such is available. */ 21398944Sobrienstatic int can_use_hw_watchpoints; 21498944Sobrien 215130803Smarcel/* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. 216130803Smarcel If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints 217130803Smarcel for unrecognized breakpoint locations. 218130803Smarcel If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ 219130803Smarcelstatic enum auto_boolean pending_break_support; 220130803Smarcel 22198944Sobrienvoid _initialize_breakpoint (void); 22298944Sobrien 22398944Sobrienextern int addressprint; /* Print machine addresses? */ 22498944Sobrien 22519370Spst/* Are we executing breakpoint commands? */ 22619370Spststatic int executing_breakpoint_commands; 22719370Spst 228130803Smarcel/* Are overlay event breakpoints enabled? */ 229130803Smarcelstatic int overlay_events_enabled; 230130803Smarcel 23119370Spst/* Walk the following statement or block through all breakpoints. 23219370Spst ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current 23319370Spst breakpoint. */ 23419370Spst 23598944Sobrien#define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) 23619370Spst 23798944Sobrien#define ALL_BREAKPOINTS_SAFE(B,TMP) \ 23898944Sobrien for (B = breakpoint_chain; \ 23998944Sobrien B ? (TMP=B->next, 1): 0; \ 24098944Sobrien B = TMP) 24119370Spst 242130803Smarcel/* Similar iterators for the low-level breakpoints. */ 24346283Sdfr 244130803Smarcel#define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->next) 24546283Sdfr 246130803Smarcel#define ALL_BP_LOCATIONS_SAFE(B,TMP) \ 247130803Smarcel for (B = bp_location_chain; \ 248130803Smarcel B ? (TMP=B->next, 1): 0; \ 249130803Smarcel B = TMP) 250130803Smarcel 25119370Spst/* True if breakpoint hit counts should be displayed in breakpoint info. */ 25219370Spst 25319370Spstint show_breakpoint_hit_counts = 1; 25419370Spst 255130803Smarcel/* Chains of all breakpoints defined. */ 25619370Spst 25719370Spststruct breakpoint *breakpoint_chain; 25819370Spst 259130803Smarcelstruct bp_location *bp_location_chain; 260130803Smarcel 26119370Spst/* Number of last breakpoint made. */ 26219370Spst 26346283Sdfrint breakpoint_count; 26419370Spst 26598944Sobrien/* Pointer to current exception event record */ 26698944Sobrienstatic struct exception_event_record *current_exception_event; 26746283Sdfr 26846283Sdfr/* Indicator of whether exception catchpoints should be nuked 26946283Sdfr between runs of a program */ 27046283Sdfrint exception_catchpoints_are_fragile = 0; 27198944Sobrien 27246283Sdfr/* Indicator of when exception catchpoints set-up should be 27346283Sdfr reinitialized -- e.g. when program is re-run */ 27446283Sdfrint exception_support_initialized = 0; 27546283Sdfr 27646283Sdfr/* This function returns a pointer to the string representation of the 27746283Sdfr pathname of the dynamically-linked library that has just been 27846283Sdfr loaded. 27946283Sdfr 28046283Sdfr This function must be used only when SOLIB_HAVE_LOAD_EVENT is TRUE, 28146283Sdfr or undefined results are guaranteed. 28246283Sdfr 28346283Sdfr This string's contents are only valid immediately after the 28446283Sdfr inferior has stopped in the dynamic linker hook, and becomes 28546283Sdfr invalid as soon as the inferior is continued. Clients should make 28646283Sdfr a copy of this string if they wish to continue the inferior and 28746283Sdfr then access the string. */ 28846283Sdfr 28946283Sdfr#ifndef SOLIB_LOADED_LIBRARY_PATHNAME 29046283Sdfr#define SOLIB_LOADED_LIBRARY_PATHNAME(pid) "" 29146283Sdfr#endif 29246283Sdfr 29346283Sdfr/* This function returns a pointer to the string representation of the 29446283Sdfr pathname of the dynamically-linked library that has just been 29546283Sdfr unloaded. 29646283Sdfr 29746283Sdfr This function must be used only when SOLIB_HAVE_UNLOAD_EVENT is 29846283Sdfr TRUE, or undefined results are guaranteed. 29946283Sdfr 30046283Sdfr This string's contents are only valid immediately after the 30146283Sdfr inferior has stopped in the dynamic linker hook, and becomes 30246283Sdfr invalid as soon as the inferior is continued. Clients should make 30346283Sdfr a copy of this string if they wish to continue the inferior and 30446283Sdfr then access the string. */ 30546283Sdfr 30646283Sdfr#ifndef SOLIB_UNLOADED_LIBRARY_PATHNAME 30746283Sdfr#define SOLIB_UNLOADED_LIBRARY_PATHNAME(pid) "" 30846283Sdfr#endif 30946283Sdfr 31046283Sdfr/* This function is called by the "catch load" command. It allows the 31146283Sdfr debugger to be notified by the dynamic linker when a specified 31246283Sdfr library file (or any library file, if filename is NULL) is loaded. */ 31346283Sdfr 31446283Sdfr#ifndef SOLIB_CREATE_CATCH_LOAD_HOOK 31546283Sdfr#define SOLIB_CREATE_CATCH_LOAD_HOOK(pid,tempflag,filename,cond_string) \ 31646283Sdfr error ("catch of library loads not yet implemented on this platform") 31746283Sdfr#endif 31846283Sdfr 31946283Sdfr/* This function is called by the "catch unload" command. It allows 32046283Sdfr the debugger to be notified by the dynamic linker when a specified 32146283Sdfr library file (or any library file, if filename is NULL) is 32246283Sdfr unloaded. */ 32346283Sdfr 32446283Sdfr#ifndef SOLIB_CREATE_CATCH_UNLOAD_HOOK 32546283Sdfr#define SOLIB_CREATE_CATCH_UNLOAD_HOOK(pid,tempflag,filename,cond_string) \ 32646283Sdfr error ("catch of library unloads not yet implemented on this platform") 32746283Sdfr#endif 32846283Sdfr 329130803Smarcel/* Return whether a breakpoint is an active enabled breakpoint. */ 330130803Smarcelstatic int 331130803Smarcelbreakpoint_enabled (struct breakpoint *b) 332130803Smarcel{ 333130803Smarcel return (b->enable_state == bp_enabled && !b->pending); 334130803Smarcel} 335130803Smarcel 33619370Spst/* Set breakpoint count to NUM. */ 33719370Spst 33846283Sdfrvoid 33998944Sobrienset_breakpoint_count (int num) 34019370Spst{ 34119370Spst breakpoint_count = num; 34219370Spst set_internalvar (lookup_internalvar ("bpnum"), 34319370Spst value_from_longest (builtin_type_int, (LONGEST) num)); 34419370Spst} 34519370Spst 34619370Spst/* Used in run_command to zero the hit count when a new run starts. */ 34719370Spst 34819370Spstvoid 34998944Sobrienclear_breakpoint_hit_counts (void) 35019370Spst{ 35119370Spst struct breakpoint *b; 35219370Spst 35319370Spst ALL_BREAKPOINTS (b) 35419370Spst b->hit_count = 0; 35519370Spst} 35619370Spst 35719370Spst/* Default address, symtab and line to put a breakpoint at 35819370Spst for "break" command with no arg. 35919370Spst if default_breakpoint_valid is zero, the other three are 36019370Spst not valid, and "break" with no arg is an error. 36119370Spst 36219370Spst This set by print_stack_frame, which calls set_default_breakpoint. */ 36319370Spst 36419370Spstint default_breakpoint_valid; 36519370SpstCORE_ADDR default_breakpoint_address; 36619370Spststruct symtab *default_breakpoint_symtab; 36719370Spstint default_breakpoint_line; 36819370Spst 36919370Spst/* *PP is a string denoting a breakpoint. Get the number of the breakpoint. 37019370Spst Advance *PP after the string and any trailing whitespace. 37119370Spst 37219370Spst Currently the string can either be a number or "$" followed by the name 37319370Spst of a convenience variable. Making it an expression wouldn't work well 37498944Sobrien for map_breakpoint_numbers (e.g. "4 + 5 + 6"). 37598944Sobrien 37698944Sobrien TRAILER is a character which can be found after the number; most 37798944Sobrien commonly this is `-'. If you don't want a trailer, use \0. */ 37819370Spststatic int 37998944Sobrienget_number_trailer (char **pp, int trailer) 38019370Spst{ 38198944Sobrien int retval = 0; /* default */ 38219370Spst char *p = *pp; 38319370Spst 38419370Spst if (p == NULL) 38519370Spst /* Empty line means refer to the last breakpoint. */ 38619370Spst return breakpoint_count; 38719370Spst else if (*p == '$') 38819370Spst { 38919370Spst /* Make a copy of the name, so we can null-terminate it 39098944Sobrien to pass to lookup_internalvar(). */ 39119370Spst char *varname; 39219370Spst char *start = ++p; 39398944Sobrien struct value *val; 39419370Spst 39519370Spst while (isalnum (*p) || *p == '_') 39619370Spst p++; 39719370Spst varname = (char *) alloca (p - start + 1); 39819370Spst strncpy (varname, start, p - start); 39919370Spst varname[p - start] = '\0'; 40019370Spst val = value_of_internalvar (lookup_internalvar (varname)); 40198944Sobrien if (TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_INT) 40298944Sobrien retval = (int) value_as_long (val); 40398944Sobrien else 40498944Sobrien { 40598944Sobrien printf_filtered ("Convenience variable must have integer value.\n"); 40698944Sobrien retval = 0; 40798944Sobrien } 40819370Spst } 40919370Spst else 41019370Spst { 41119370Spst if (*p == '-') 41219370Spst ++p; 41319370Spst while (*p >= '0' && *p <= '9') 41419370Spst ++p; 41519370Spst if (p == *pp) 41619370Spst /* There is no number here. (e.g. "cond a == b"). */ 41798944Sobrien { 41898944Sobrien /* Skip non-numeric token */ 41998944Sobrien while (*p && !isspace((int) *p)) 42098944Sobrien ++p; 42198944Sobrien /* Return zero, which caller must interpret as error. */ 42298944Sobrien retval = 0; 42398944Sobrien } 42498944Sobrien else 42598944Sobrien retval = atoi (*pp); 42619370Spst } 42798944Sobrien if (!(isspace (*p) || *p == '\0' || *p == trailer)) 42898944Sobrien { 42998944Sobrien /* Trailing junk: return 0 and let caller print error msg. */ 43098944Sobrien while (!(isspace (*p) || *p == '\0' || *p == trailer)) 43198944Sobrien ++p; 43298944Sobrien retval = 0; 43398944Sobrien } 43419370Spst while (isspace (*p)) 43519370Spst p++; 43619370Spst *pp = p; 43719370Spst return retval; 43819370Spst} 43998944Sobrien 44098944Sobrien 44198944Sobrien/* Like get_number_trailer, but don't allow a trailer. */ 44298944Sobrienint 44398944Sobrienget_number (char **pp) 44498944Sobrien{ 44598944Sobrien return get_number_trailer (pp, '\0'); 44698944Sobrien} 44798944Sobrien 44898944Sobrien/* Parse a number or a range. 44998944Sobrien * A number will be of the form handled by get_number. 45098944Sobrien * A range will be of the form <number1> - <number2>, and 45198944Sobrien * will represent all the integers between number1 and number2, 45298944Sobrien * inclusive. 45398944Sobrien * 45498944Sobrien * While processing a range, this fuction is called iteratively; 45598944Sobrien * At each call it will return the next value in the range. 45698944Sobrien * 45798944Sobrien * At the beginning of parsing a range, the char pointer PP will 45898944Sobrien * be advanced past <number1> and left pointing at the '-' token. 45998944Sobrien * Subsequent calls will not advance the pointer until the range 46098944Sobrien * is completed. The call that completes the range will advance 46198944Sobrien * pointer PP past <number2>. 46298944Sobrien */ 46398944Sobrien 46498944Sobrienint 46598944Sobrienget_number_or_range (char **pp) 46698944Sobrien{ 46798944Sobrien static int last_retval, end_value; 46898944Sobrien static char *end_ptr; 46998944Sobrien static int in_range = 0; 47098944Sobrien 47198944Sobrien if (**pp != '-') 47298944Sobrien { 47398944Sobrien /* Default case: pp is pointing either to a solo number, 47498944Sobrien or to the first number of a range. */ 47598944Sobrien last_retval = get_number_trailer (pp, '-'); 47698944Sobrien if (**pp == '-') 47798944Sobrien { 47898944Sobrien char **temp; 47998944Sobrien 48098944Sobrien /* This is the start of a range (<number1> - <number2>). 48198944Sobrien Skip the '-', parse and remember the second number, 48298944Sobrien and also remember the end of the final token. */ 48398944Sobrien 48498944Sobrien temp = &end_ptr; 48598944Sobrien end_ptr = *pp + 1; 48698944Sobrien while (isspace ((int) *end_ptr)) 48798944Sobrien end_ptr++; /* skip white space */ 48898944Sobrien end_value = get_number (temp); 48998944Sobrien if (end_value < last_retval) 49098944Sobrien { 49198944Sobrien error ("inverted range"); 49298944Sobrien } 49398944Sobrien else if (end_value == last_retval) 49498944Sobrien { 49598944Sobrien /* degenerate range (number1 == number2). Advance the 49698944Sobrien token pointer so that the range will be treated as a 49798944Sobrien single number. */ 49898944Sobrien *pp = end_ptr; 49998944Sobrien } 50098944Sobrien else 50198944Sobrien in_range = 1; 50298944Sobrien } 50398944Sobrien } 50498944Sobrien else if (! in_range) 50598944Sobrien error ("negative value"); 50698944Sobrien else 50798944Sobrien { 50898944Sobrien /* pp points to the '-' that betokens a range. All 50998944Sobrien number-parsing has already been done. Return the next 51098944Sobrien integer value (one greater than the saved previous value). 51198944Sobrien Do not advance the token pointer 'pp' until the end of range 51298944Sobrien is reached. */ 51398944Sobrien 51498944Sobrien if (++last_retval == end_value) 51598944Sobrien { 51698944Sobrien /* End of range reached; advance token pointer. */ 51798944Sobrien *pp = end_ptr; 51898944Sobrien in_range = 0; 51998944Sobrien } 52098944Sobrien } 52198944Sobrien return last_retval; 52298944Sobrien} 52398944Sobrien 52498944Sobrien 52519370Spst 52619370Spst/* condition N EXP -- set break condition of breakpoint N to EXP. */ 52719370Spst 52819370Spststatic void 52998944Sobriencondition_command (char *arg, int from_tty) 53019370Spst{ 531130803Smarcel struct breakpoint *b; 53219370Spst char *p; 533130803Smarcel int bnum; 53419370Spst 53519370Spst if (arg == 0) 53619370Spst error_no_arg ("breakpoint number"); 53719370Spst 53819370Spst p = arg; 53919370Spst bnum = get_number (&p); 54098944Sobrien if (bnum == 0) 54198944Sobrien error ("Bad breakpoint argument: '%s'", arg); 54219370Spst 54319370Spst ALL_BREAKPOINTS (b) 54419370Spst if (b->number == bnum) 54598944Sobrien { 54698944Sobrien if (b->cond) 54798944Sobrien { 54898944Sobrien xfree (b->cond); 54998944Sobrien b->cond = 0; 55098944Sobrien } 55198944Sobrien if (b->cond_string != NULL) 55298944Sobrien xfree (b->cond_string); 55319370Spst 55498944Sobrien if (*p == 0) 55598944Sobrien { 55698944Sobrien b->cond = 0; 55798944Sobrien b->cond_string = NULL; 55898944Sobrien if (from_tty) 55998944Sobrien printf_filtered ("Breakpoint %d now unconditional.\n", bnum); 56098944Sobrien } 56198944Sobrien else 56298944Sobrien { 56398944Sobrien arg = p; 56498944Sobrien /* I don't know if it matters whether this is the string the user 56598944Sobrien typed in or the decompiled expression. */ 56698944Sobrien b->cond_string = savestring (arg, strlen (arg)); 567130803Smarcel if (!b->pending) 568130803Smarcel { 569130803Smarcel b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0); 570130803Smarcel if (*arg) 571130803Smarcel error ("Junk at end of expression"); 572130803Smarcel } 57398944Sobrien } 57498944Sobrien breakpoints_changed (); 575130803Smarcel breakpoint_modify_event (b->number); 57698944Sobrien return; 57798944Sobrien } 57819370Spst 57919370Spst error ("No breakpoint number %d.", bnum); 58019370Spst} 58119370Spst 58219370Spststatic void 58398944Sobriencommands_command (char *arg, int from_tty) 58419370Spst{ 585130803Smarcel struct breakpoint *b; 58619370Spst char *p; 587130803Smarcel int bnum; 58819370Spst struct command_line *l; 58919370Spst 59019370Spst /* If we allowed this, we would have problems with when to 59119370Spst free the storage, if we change the commands currently 59219370Spst being read from. */ 59319370Spst 59419370Spst if (executing_breakpoint_commands) 59519370Spst error ("Can't use the \"commands\" command among a breakpoint's commands."); 59619370Spst 59719370Spst p = arg; 59819370Spst bnum = get_number (&p); 59998944Sobrien 60019370Spst if (p && *p) 60119370Spst error ("Unexpected extra arguments following breakpoint number."); 60298944Sobrien 60319370Spst ALL_BREAKPOINTS (b) 60419370Spst if (b->number == bnum) 605130803Smarcel { 606130803Smarcel char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", 607130803Smarcel bnum); 608130803Smarcel struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); 609130803Smarcel l = read_command_lines (tmpbuf, from_tty); 610130803Smarcel do_cleanups (cleanups); 611130803Smarcel free_command_lines (&b->commands); 612130803Smarcel b->commands = l; 613130803Smarcel breakpoints_changed (); 614130803Smarcel breakpoint_modify_event (b->number); 615130803Smarcel return; 61698944Sobrien } 61719370Spst error ("No breakpoint number %d.", bnum); 61819370Spst} 61919370Spst 62019370Spst/* Like target_read_memory() but if breakpoints are inserted, return 62119370Spst the shadow contents instead of the breakpoints themselves. 62219370Spst 62319370Spst Read "memory data" from whatever target or inferior we have. 62419370Spst Returns zero if successful, errno value if not. EIO is used 62519370Spst for address out of bounds. If breakpoints are inserted, returns 62619370Spst shadow contents, not the breakpoints themselves. From breakpoint.c. */ 62719370Spst 62819370Spstint 62998944Sobrienread_memory_nobpt (CORE_ADDR memaddr, char *myaddr, unsigned len) 63019370Spst{ 63119370Spst int status; 632130803Smarcel struct bp_location *b; 63346283Sdfr CORE_ADDR bp_addr = 0; 63446283Sdfr int bp_size = 0; 63519370Spst 63646283Sdfr if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL) 63746283Sdfr /* No breakpoints on this machine. */ 63819370Spst return target_read_memory (memaddr, myaddr, len); 63998944Sobrien 640130803Smarcel ALL_BP_LOCATIONS (b) 64198944Sobrien { 642130803Smarcel if (b->owner->type == bp_none) 643130803Smarcel warning ("reading through apparently deleted breakpoint #%d?", 644130803Smarcel b->owner->number); 64598944Sobrien 646130803Smarcel if (b->loc_type != bp_loc_software_breakpoint) 64798944Sobrien continue; 64898944Sobrien if (!b->inserted) 64998944Sobrien continue; 65098944Sobrien /* Addresses and length of the part of the breakpoint that 65198944Sobrien we need to copy. */ 65298944Sobrien /* XXXX The m68k, sh and h8300 have different local and remote 65398944Sobrien breakpoint values. BREAKPOINT_FROM_PC still manages to 65498944Sobrien correctly determine the breakpoints memory address and size 65598944Sobrien for these targets. */ 65698944Sobrien bp_addr = b->address; 65798944Sobrien bp_size = 0; 65898944Sobrien if (BREAKPOINT_FROM_PC (&bp_addr, &bp_size) == NULL) 65998944Sobrien continue; 66098944Sobrien if (bp_size == 0) 66198944Sobrien /* bp isn't valid */ 66298944Sobrien continue; 66398944Sobrien if (bp_addr + bp_size <= memaddr) 66498944Sobrien /* The breakpoint is entirely before the chunk of memory we 66598944Sobrien are reading. */ 66698944Sobrien continue; 66798944Sobrien if (bp_addr >= memaddr + len) 66898944Sobrien /* The breakpoint is entirely after the chunk of memory we are 66998944Sobrien reading. */ 67098944Sobrien continue; 67198944Sobrien /* Copy the breakpoint from the shadow contents, and recurse for 67298944Sobrien the things before and after. */ 67319370Spst { 67498944Sobrien /* Offset within shadow_contents. */ 67598944Sobrien int bptoffset = 0; 67646283Sdfr 67798944Sobrien if (bp_addr < memaddr) 67898944Sobrien { 67998944Sobrien /* Only copy the second part of the breakpoint. */ 68098944Sobrien bp_size -= memaddr - bp_addr; 68198944Sobrien bptoffset = memaddr - bp_addr; 68298944Sobrien bp_addr = memaddr; 68398944Sobrien } 68498944Sobrien 68598944Sobrien if (bp_addr + bp_size > memaddr + len) 68698944Sobrien { 68798944Sobrien /* Only copy the first part of the breakpoint. */ 68898944Sobrien bp_size -= (bp_addr + bp_size) - (memaddr + len); 68998944Sobrien } 69098944Sobrien 69198944Sobrien memcpy (myaddr + bp_addr - memaddr, 69298944Sobrien b->shadow_contents + bptoffset, bp_size); 69398944Sobrien 69498944Sobrien if (bp_addr > memaddr) 69598944Sobrien { 69698944Sobrien /* Copy the section of memory before the breakpoint. */ 69798944Sobrien status = read_memory_nobpt (memaddr, myaddr, bp_addr - memaddr); 69898944Sobrien if (status != 0) 69998944Sobrien return status; 70098944Sobrien } 70198944Sobrien 70298944Sobrien if (bp_addr + bp_size < memaddr + len) 70398944Sobrien { 70498944Sobrien /* Copy the section of memory after the breakpoint. */ 70598944Sobrien status = read_memory_nobpt (bp_addr + bp_size, 70698944Sobrien myaddr + bp_addr + bp_size - memaddr, 70798944Sobrien memaddr + len - (bp_addr + bp_size)); 70898944Sobrien if (status != 0) 70998944Sobrien return status; 71098944Sobrien } 71198944Sobrien return 0; 71219370Spst } 71398944Sobrien } 71419370Spst /* Nothing overlaps. Just call read_memory_noerr. */ 71519370Spst return target_read_memory (memaddr, myaddr, len); 71619370Spst} 71798944Sobrien 71846283Sdfr 719130803Smarcel/* A wrapper function for inserting catchpoints. */ 720130803Smarcelstatic int 721130803Smarcelinsert_catchpoint (struct ui_out *uo, void *args) 722130803Smarcel{ 723130803Smarcel struct breakpoint *b = (struct breakpoint *) args; 724130803Smarcel int val = -1; 72519370Spst 726130803Smarcel switch (b->type) 727130803Smarcel { 728130803Smarcel case bp_catch_fork: 729130803Smarcel val = target_insert_fork_catchpoint (PIDGET (inferior_ptid)); 730130803Smarcel break; 731130803Smarcel case bp_catch_vfork: 732130803Smarcel val = target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); 733130803Smarcel break; 734130803Smarcel case bp_catch_exec: 735130803Smarcel val = target_insert_exec_catchpoint (PIDGET (inferior_ptid)); 736130803Smarcel break; 737130803Smarcel default: 738130803Smarcel internal_error (__FILE__, __LINE__, "unknown breakpoint type"); 739130803Smarcel break; 740130803Smarcel } 741130803Smarcel 742130803Smarcel if (val < 0) 743130803Smarcel throw_exception (RETURN_ERROR); 744130803Smarcel 745130803Smarcel return 0; 746130803Smarcel} 747130803Smarcel 748130803Smarcel/* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. 749130803Smarcel Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, 750130803Smarcel PROCESS_WARNING, and HW_BREAKPOINT_ERROR are used to report problems. 751130803Smarcel 752130803Smarcel NOTE drow/2003-09-09: This routine could be broken down to an object-style 753130803Smarcel method for each breakpoint or catchpoint type. */ 754130803Smarcelstatic int 755130803Smarcelinsert_bp_location (struct bp_location *bpt, 756130803Smarcel struct ui_file *tmp_error_stream, 757130803Smarcel int *disabled_breaks, int *process_warning, 758130803Smarcel int *hw_breakpoint_error) 75919370Spst{ 76019370Spst int val = 0; 76119370Spst 762130803Smarcel /* Permanent breakpoints cannot be inserted or removed. Disabled 763130803Smarcel breakpoints should not be inserted. */ 764130803Smarcel if (!breakpoint_enabled (bpt->owner)) 765130803Smarcel return 0; 76646283Sdfr 767130803Smarcel if (bpt->inserted || bpt->duplicate) 768130803Smarcel return 0; 76946283Sdfr 770130803Smarcel if (bpt->loc_type == bp_loc_software_breakpoint 771130803Smarcel || bpt->loc_type == bp_loc_hardware_breakpoint) 772130803Smarcel { 773130803Smarcel /* First check to see if we have to handle an overlay. */ 774130803Smarcel if (overlay_debugging == ovly_off 775130803Smarcel || bpt->section == NULL 776130803Smarcel || !(section_is_overlay (bpt->section))) 777130803Smarcel { 778130803Smarcel /* No overlay handling: just set the breakpoint. */ 77946283Sdfr 780130803Smarcel if (bpt->loc_type == bp_loc_hardware_breakpoint) 781130803Smarcel val = target_insert_hw_breakpoint (bpt->address, 782130803Smarcel bpt->shadow_contents); 783130803Smarcel else 784130803Smarcel val = target_insert_breakpoint (bpt->address, 785130803Smarcel bpt->shadow_contents); 786130803Smarcel } 787130803Smarcel else 788130803Smarcel { 789130803Smarcel /* This breakpoint is in an overlay section. 790130803Smarcel Shall we set a breakpoint at the LMA? */ 791130803Smarcel if (!overlay_events_enabled) 792130803Smarcel { 793130803Smarcel /* Yes -- overlay event support is not active, 794130803Smarcel so we must try to set a breakpoint at the LMA. 795130803Smarcel This will not work for a hardware breakpoint. */ 796130803Smarcel if (bpt->loc_type == bp_loc_hardware_breakpoint) 797130803Smarcel warning ("hardware breakpoint %d not supported in overlay!\n", 798130803Smarcel bpt->owner->number); 799130803Smarcel else 800130803Smarcel { 801130803Smarcel CORE_ADDR addr = overlay_unmapped_address (bpt->address, 802130803Smarcel bpt->section); 803130803Smarcel /* Set a software (trap) breakpoint at the LMA. */ 804130803Smarcel val = target_insert_breakpoint (addr, bpt->shadow_contents); 805130803Smarcel if (val != 0) 806130803Smarcel fprintf_unfiltered (tmp_error_stream, 807130803Smarcel "Overlay breakpoint %d failed: in ROM?", 808130803Smarcel bpt->owner->number); 809130803Smarcel } 810130803Smarcel } 811130803Smarcel /* Shall we set a breakpoint at the VMA? */ 812130803Smarcel if (section_is_mapped (bpt->section)) 813130803Smarcel { 814130803Smarcel /* Yes. This overlay section is mapped into memory. */ 815130803Smarcel if (bpt->loc_type == bp_loc_hardware_breakpoint) 816130803Smarcel val = target_insert_hw_breakpoint (bpt->address, 817130803Smarcel bpt->shadow_contents); 818130803Smarcel else 819130803Smarcel val = target_insert_breakpoint (bpt->address, 820130803Smarcel bpt->shadow_contents); 821130803Smarcel } 822130803Smarcel else 823130803Smarcel { 824130803Smarcel /* No. This breakpoint will not be inserted. 825130803Smarcel No error, but do not mark the bp as 'inserted'. */ 826130803Smarcel return 0; 827130803Smarcel } 828130803Smarcel } 829130803Smarcel 830130803Smarcel if (val) 831130803Smarcel { 832130803Smarcel /* Can't set the breakpoint. */ 83346283Sdfr#if defined (DISABLE_UNSETTABLE_BREAK) 834130803Smarcel if (DISABLE_UNSETTABLE_BREAK (bpt->address)) 835130803Smarcel { 836130803Smarcel /* See also: disable_breakpoints_in_shlibs. */ 837130803Smarcel val = 0; 838130803Smarcel bpt->owner->enable_state = bp_shlib_disabled; 839130803Smarcel if (!*disabled_breaks) 840130803Smarcel { 841130803Smarcel fprintf_unfiltered (tmp_error_stream, 842130803Smarcel "Cannot insert breakpoint %d.\n", 843130803Smarcel bpt->owner->number); 844130803Smarcel fprintf_unfiltered (tmp_error_stream, 845130803Smarcel "Temporarily disabling shared library breakpoints:\n"); 846130803Smarcel } 847130803Smarcel *disabled_breaks = 1; 848130803Smarcel fprintf_unfiltered (tmp_error_stream, 849130803Smarcel "breakpoint #%d\n", bpt->owner->number); 850130803Smarcel } 851130803Smarcel else 85246283Sdfr#endif 853130803Smarcel { 85446283Sdfr#ifdef ONE_PROCESS_WRITETEXT 855130803Smarcel *process_warning = 1; 85646283Sdfr#endif 857130803Smarcel if (bpt->loc_type == bp_loc_hardware_breakpoint) 858130803Smarcel { 859130803Smarcel *hw_breakpoint_error = 1; 860130803Smarcel fprintf_unfiltered (tmp_error_stream, 861130803Smarcel "Cannot insert hardware breakpoint %d.\n", 862130803Smarcel bpt->owner->number); 863130803Smarcel } 864130803Smarcel else 865130803Smarcel { 866130803Smarcel fprintf_unfiltered (tmp_error_stream, 867130803Smarcel "Cannot insert breakpoint %d.\n", 868130803Smarcel bpt->owner->number); 869130803Smarcel fprintf_filtered (tmp_error_stream, 870130803Smarcel "Error accessing memory address "); 871130803Smarcel print_address_numeric (bpt->address, 1, tmp_error_stream); 872130803Smarcel fprintf_filtered (tmp_error_stream, ": %s.\n", 873130803Smarcel safe_strerror (val)); 874130803Smarcel } 87598944Sobrien 876130803Smarcel } 877130803Smarcel } 878130803Smarcel else 879130803Smarcel bpt->inserted = 1; 88046283Sdfr 881130803Smarcel return val; 882130803Smarcel } 88398944Sobrien 884130803Smarcel else if (bpt->loc_type == bp_loc_hardware_watchpoint 885130803Smarcel /* NOTE drow/2003-09-08: This state only exists for removing 886130803Smarcel watchpoints. It's not clear that it's necessary... */ 887130803Smarcel && bpt->owner->disposition != disp_del_at_next_stop) 888130803Smarcel { 889130803Smarcel /* FIXME drow/2003-09-08: This code sets multiple hardware watchpoints 890130803Smarcel based on the expression. Ideally this should happen at a higher level, 891130803Smarcel and there should be one bp_location for each computed address we 892130803Smarcel must watch. As soon as a many-to-one mapping is available I'll 893130803Smarcel convert this. */ 89498944Sobrien 895130803Smarcel struct frame_info *saved_frame; 896130803Smarcel int saved_level, within_current_scope; 897130803Smarcel struct value *mark = value_mark (); 898130803Smarcel struct value *v; 89919370Spst 900130803Smarcel /* Save the current frame and level so we can restore it after 901130803Smarcel evaluating the watchpoint expression on its own frame. */ 902130803Smarcel /* FIXME drow/2003-09-09: It would be nice if evaluate_expression 903130803Smarcel took a frame parameter, so that we didn't have to change the 904130803Smarcel selected frame. */ 905130803Smarcel saved_frame = deprecated_selected_frame; 906130803Smarcel saved_level = frame_relative_level (deprecated_selected_frame); 90719370Spst 908130803Smarcel /* Determine if the watchpoint is within scope. */ 909130803Smarcel if (bpt->owner->exp_valid_block == NULL) 910130803Smarcel within_current_scope = 1; 911130803Smarcel else 912130803Smarcel { 913130803Smarcel struct frame_info *fi; 914130803Smarcel fi = frame_find_by_id (bpt->owner->watchpoint_frame); 915130803Smarcel within_current_scope = (fi != NULL); 916130803Smarcel if (within_current_scope) 917130803Smarcel select_frame (fi); 918130803Smarcel } 91946283Sdfr 920130803Smarcel if (within_current_scope) 921130803Smarcel { 922130803Smarcel /* Evaluate the expression and cut the chain of values 923130803Smarcel produced off from the value chain. 92446283Sdfr 925130803Smarcel Make sure the value returned isn't lazy; we use 926130803Smarcel laziness to determine what memory GDB actually needed 927130803Smarcel in order to compute the value of the expression. */ 928130803Smarcel v = evaluate_expression (bpt->owner->exp); 929130803Smarcel VALUE_CONTENTS (v); 930130803Smarcel value_release_to_mark (mark); 93119370Spst 932130803Smarcel bpt->owner->val_chain = v; 933130803Smarcel bpt->inserted = 1; 93419370Spst 935130803Smarcel /* Look at each value on the value chain. */ 936130803Smarcel for (; v; v = v->next) 937130803Smarcel { 938130803Smarcel /* If it's a memory location, and GDB actually needed 939130803Smarcel its contents to evaluate the expression, then we 940130803Smarcel must watch it. */ 941130803Smarcel if (VALUE_LVAL (v) == lval_memory 942130803Smarcel && ! VALUE_LAZY (v)) 943130803Smarcel { 944130803Smarcel struct type *vtype = check_typedef (VALUE_TYPE (v)); 94598944Sobrien 946130803Smarcel /* We only watch structs and arrays if user asked 947130803Smarcel for it explicitly, never if they just happen to 948130803Smarcel appear in the middle of some value chain. */ 949130803Smarcel if (v == bpt->owner->val_chain 950130803Smarcel || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT 951130803Smarcel && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) 952130803Smarcel { 953130803Smarcel CORE_ADDR addr; 954130803Smarcel int len, type; 95598944Sobrien 956130803Smarcel addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); 957130803Smarcel len = TYPE_LENGTH (VALUE_TYPE (v)); 958130803Smarcel type = hw_write; 959130803Smarcel if (bpt->owner->type == bp_read_watchpoint) 960130803Smarcel type = hw_read; 961130803Smarcel else if (bpt->owner->type == bp_access_watchpoint) 962130803Smarcel type = hw_access; 96398944Sobrien 964130803Smarcel val = target_insert_watchpoint (addr, len, type); 965130803Smarcel if (val == -1) 966130803Smarcel { 967130803Smarcel /* Don't exit the loop, try to insert 968130803Smarcel every value on the value chain. That's 969130803Smarcel because we will be removing all the 970130803Smarcel watches below, and removing a 971130803Smarcel watchpoint we didn't insert could have 972130803Smarcel adverse effects. */ 973130803Smarcel bpt->inserted = 0; 974130803Smarcel } 975130803Smarcel val = 0; 976130803Smarcel } 977130803Smarcel } 978130803Smarcel } 979130803Smarcel /* Failure to insert a watchpoint on any memory value in the 980130803Smarcel value chain brings us here. */ 981130803Smarcel if (!bpt->inserted) 982130803Smarcel { 983130803Smarcel remove_breakpoint (bpt, mark_uninserted); 984130803Smarcel *hw_breakpoint_error = 1; 985130803Smarcel fprintf_unfiltered (tmp_error_stream, 986130803Smarcel "Could not insert hardware watchpoint %d.\n", 987130803Smarcel bpt->owner->number); 988130803Smarcel val = -1; 989130803Smarcel } 990130803Smarcel } 991130803Smarcel else 992130803Smarcel { 993130803Smarcel printf_filtered ("Hardware watchpoint %d deleted ", bpt->owner->number); 994130803Smarcel printf_filtered ("because the program has left the block \n"); 995130803Smarcel printf_filtered ("in which its expression is valid.\n"); 996130803Smarcel if (bpt->owner->related_breakpoint) 997130803Smarcel bpt->owner->related_breakpoint->disposition = disp_del_at_next_stop; 998130803Smarcel bpt->owner->disposition = disp_del_at_next_stop; 999130803Smarcel } 100098944Sobrien 1001130803Smarcel /* Restore the frame and level. */ 1002130803Smarcel if (saved_frame != deprecated_selected_frame 1003130803Smarcel || saved_level != frame_relative_level (deprecated_selected_frame)) 1004130803Smarcel select_frame (saved_frame); 100598944Sobrien 1006130803Smarcel return val; 1007130803Smarcel } 100819370Spst 1009130803Smarcel else if (ep_is_exception_catchpoint (bpt->owner)) 1010130803Smarcel { 1011130803Smarcel /* FIXME drow/2003-09-09: This code sets both a catchpoint and a 1012130803Smarcel breakpoint. Once again, it would be better if this was represented 1013130803Smarcel as two bp_locations. */ 101446283Sdfr 1015130803Smarcel /* If we get here, we must have a callback mechanism for exception 1016130803Smarcel events -- with g++ style embedded label support, we insert 1017130803Smarcel ordinary breakpoints and not catchpoints. */ 1018130803Smarcel val = target_insert_breakpoint (bpt->address, bpt->shadow_contents); 1019130803Smarcel if (val) 1020130803Smarcel { 1021130803Smarcel /* Couldn't set breakpoint for some reason */ 1022130803Smarcel fprintf_unfiltered (tmp_error_stream, 1023130803Smarcel "Cannot insert catchpoint %d; disabling it.\n", 1024130803Smarcel bpt->owner->number); 1025130803Smarcel fprintf_filtered (tmp_error_stream, 1026130803Smarcel "Error accessing memory address "); 1027130803Smarcel print_address_numeric (bpt->address, 1, tmp_error_stream); 1028130803Smarcel fprintf_filtered (tmp_error_stream, ": %s.\n", 1029130803Smarcel safe_strerror (val)); 1030130803Smarcel bpt->owner->enable_state = bp_disabled; 1031130803Smarcel } 1032130803Smarcel else 1033130803Smarcel { 1034130803Smarcel /* Bp set, now make sure callbacks are enabled */ 1035130803Smarcel /* Format possible error msg */ 1036130803Smarcel char *message = xstrprintf ("Error inserting catchpoint %d:\n", 1037130803Smarcel bpt->owner->number); 1038130803Smarcel struct cleanup *cleanups = make_cleanup (xfree, message); 1039130803Smarcel int val; 1040130803Smarcel args_for_catchpoint_enable args; 1041130803Smarcel args.kind = bpt->owner->type == bp_catch_catch ? 1042130803Smarcel EX_EVENT_CATCH : EX_EVENT_THROW; 1043130803Smarcel args.enable_p = 1; 1044130803Smarcel val = catch_errors (cover_target_enable_exception_callback, 1045130803Smarcel &args, message, RETURN_MASK_ALL); 1046130803Smarcel do_cleanups (cleanups); 1047130803Smarcel if (val != 0 && val != -1) 1048130803Smarcel bpt->inserted = 1; 104998944Sobrien 1050130803Smarcel /* Check if something went wrong; val == 0 can be ignored */ 1051130803Smarcel if (val == -1) 1052130803Smarcel { 1053130803Smarcel /* something went wrong */ 1054130803Smarcel fprintf_unfiltered (tmp_error_stream, 1055130803Smarcel "Cannot insert catchpoint %d; disabling it.\n", 1056130803Smarcel bpt->owner->number); 1057130803Smarcel bpt->owner->enable_state = bp_disabled; 1058130803Smarcel } 1059130803Smarcel } 106098944Sobrien 1061130803Smarcel return val; 1062130803Smarcel } 1063130803Smarcel 1064130803Smarcel else if (bpt->owner->type == bp_catch_fork 1065130803Smarcel || bpt->owner->type == bp_catch_vfork 1066130803Smarcel || bpt->owner->type == bp_catch_exec) 1067130803Smarcel { 1068130803Smarcel char *prefix = xstrprintf ("warning: inserting catchpoint %d: ", 1069130803Smarcel bpt->owner->number); 1070130803Smarcel struct cleanup *cleanups = make_cleanup (xfree, prefix); 1071130803Smarcel val = catch_exceptions (uiout, insert_catchpoint, bpt->owner, prefix, 1072130803Smarcel RETURN_MASK_ERROR); 1073130803Smarcel do_cleanups (cleanups); 1074130803Smarcel if (val < 0) 1075130803Smarcel bpt->owner->enable_state = bp_disabled; 1076130803Smarcel else 1077130803Smarcel bpt->inserted = 1; 1078130803Smarcel 1079130803Smarcel /* We've already printed an error message if there was a problem 1080130803Smarcel inserting this catchpoint, and we've disabled the catchpoint, 1081130803Smarcel so just return success. */ 1082130803Smarcel return 0; 1083130803Smarcel } 1084130803Smarcel 1085130803Smarcel return 0; 108619370Spst} 108719370Spst 1088130803Smarcel/* insert_breakpoints is used when starting or continuing the program. 1089130803Smarcel remove_breakpoints is used when the program stops. 1090130803Smarcel Both return zero if successful, 1091130803Smarcel or an `errno' value if could not write the inferior. */ 109219370Spst 109319370Spstint 1094130803Smarcelinsert_breakpoints (void) 1095130803Smarcel{ 1096130803Smarcel struct bp_location *b, *temp; 1097130803Smarcel int return_val = 0; /* return success code. */ 1098130803Smarcel int val = 0; 1099130803Smarcel int disabled_breaks = 0; 1100130803Smarcel int hw_breakpoint_error = 0; 1101130803Smarcel int process_warning = 0; 1102130803Smarcel 1103130803Smarcel struct ui_file *tmp_error_stream = mem_fileopen (); 1104130803Smarcel make_cleanup_ui_file_delete (tmp_error_stream); 1105130803Smarcel 1106130803Smarcel /* Explicitly mark the warning -- this will only be printed if 1107130803Smarcel there was an error. */ 1108130803Smarcel fprintf_unfiltered (tmp_error_stream, "Warning:\n"); 1109130803Smarcel 1110130803Smarcel ALL_BP_LOCATIONS_SAFE (b, temp) 1111130803Smarcel { 1112130803Smarcel /* Permanent breakpoints cannot be inserted or removed. Disabled 1113130803Smarcel breakpoints should not be inserted. */ 1114130803Smarcel if (!breakpoint_enabled (b->owner)) 1115130803Smarcel continue; 1116130803Smarcel 1117130803Smarcel /* FIXME drow/2003-10-07: This code should be pushed elsewhere when 1118130803Smarcel hardware watchpoints are split into multiple loc breakpoints. */ 1119130803Smarcel if ((b->loc_type == bp_loc_hardware_watchpoint 1120130803Smarcel || b->owner->type == bp_watchpoint) && !b->owner->val) 1121130803Smarcel { 1122130803Smarcel struct value *val; 1123130803Smarcel val = evaluate_expression (b->owner->exp); 1124130803Smarcel release_value (val); 1125130803Smarcel if (VALUE_LAZY (val)) 1126130803Smarcel value_fetch_lazy (val); 1127130803Smarcel b->owner->val = val; 1128130803Smarcel } 1129130803Smarcel 1130130803Smarcel val = insert_bp_location (b, tmp_error_stream, 1131130803Smarcel &disabled_breaks, &process_warning, 1132130803Smarcel &hw_breakpoint_error); 1133130803Smarcel if (val) 1134130803Smarcel return_val = val; 1135130803Smarcel } 1136130803Smarcel 1137130803Smarcel if (return_val) 1138130803Smarcel { 1139130803Smarcel /* If a hardware breakpoint or watchpoint was inserted, add a 1140130803Smarcel message about possibly exhausted resources. */ 1141130803Smarcel if (hw_breakpoint_error) 1142130803Smarcel { 1143130803Smarcel fprintf_unfiltered (tmp_error_stream, 1144130803Smarcel "Could not insert hardware breakpoints:\n\ 1145130803SmarcelYou may have requested too many hardware breakpoints/watchpoints.\n"); 1146130803Smarcel } 1147130803Smarcel#ifdef ONE_PROCESS_WRITETEXT 1148130803Smarcel if (process_warning) 1149130803Smarcel fprintf_unfiltered (tmp_error_stream, 1150130803Smarcel "The same program may be running in another process."); 1151130803Smarcel#endif 1152130803Smarcel target_terminal_ours_for_output (); 1153130803Smarcel error_stream (tmp_error_stream); 1154130803Smarcel } 1155130803Smarcel return return_val; 1156130803Smarcel} 1157130803Smarcel 1158130803Smarcelint 115998944Sobrienremove_breakpoints (void) 116019370Spst{ 1161130803Smarcel struct bp_location *b; 116219370Spst int val; 116319370Spst 1164130803Smarcel ALL_BP_LOCATIONS (b) 116598944Sobrien { 116698944Sobrien if (b->inserted) 116798944Sobrien { 116898944Sobrien val = remove_breakpoint (b, mark_uninserted); 116998944Sobrien if (val != 0) 117098944Sobrien return val; 117198944Sobrien } 117298944Sobrien } 117319370Spst return 0; 117419370Spst} 117519370Spst 117646283Sdfrint 117798944Sobrienremove_hw_watchpoints (void) 117846283Sdfr{ 1179130803Smarcel struct bp_location *b; 118046283Sdfr int val; 118119370Spst 1182130803Smarcel ALL_BP_LOCATIONS (b) 118398944Sobrien { 1184130803Smarcel if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) 118598944Sobrien { 118698944Sobrien val = remove_breakpoint (b, mark_uninserted); 118798944Sobrien if (val != 0) 118898944Sobrien return val; 118998944Sobrien } 119098944Sobrien } 119146283Sdfr return 0; 119246283Sdfr} 119346283Sdfr 119498944Sobrienint 119598944Sobrienreattach_breakpoints (int pid) 119698944Sobrien{ 1197130803Smarcel struct bp_location *b; 119898944Sobrien int val; 119998944Sobrien struct cleanup *old_chain = save_inferior_ptid (); 120098944Sobrien 120198944Sobrien /* Set inferior_ptid; remove_breakpoint uses this global. */ 120298944Sobrien inferior_ptid = pid_to_ptid (pid); 1203130803Smarcel ALL_BP_LOCATIONS (b) 120498944Sobrien { 120598944Sobrien if (b->inserted) 120698944Sobrien { 120798944Sobrien remove_breakpoint (b, mark_inserted); 1208130803Smarcel if (b->loc_type == bp_loc_hardware_breakpoint) 120998944Sobrien val = target_insert_hw_breakpoint (b->address, b->shadow_contents); 121098944Sobrien else 121198944Sobrien val = target_insert_breakpoint (b->address, b->shadow_contents); 1212130803Smarcel /* FIXME drow/2003-10-07: This doesn't handle any other kinds of 1213130803Smarcel breakpoints. It's wrong for watchpoints, for example. */ 121498944Sobrien if (val != 0) 121598944Sobrien { 121698944Sobrien do_cleanups (old_chain); 121798944Sobrien return val; 121898944Sobrien } 121998944Sobrien } 122098944Sobrien } 122198944Sobrien do_cleanups (old_chain); 122298944Sobrien return 0; 122398944Sobrien} 122498944Sobrien 122546283Sdfrvoid 122698944Sobrienupdate_breakpoints_after_exec (void) 122746283Sdfr{ 122898944Sobrien struct breakpoint *b; 122998944Sobrien struct breakpoint *temp; 123046283Sdfr 123146283Sdfr /* Doing this first prevents the badness of having delete_breakpoint() 123246283Sdfr write a breakpoint's current "shadow contents" to lift the bp. That 123346283Sdfr shadow is NOT valid after an exec()! */ 123446283Sdfr mark_breakpoints_out (); 123546283Sdfr 123646283Sdfr ALL_BREAKPOINTS_SAFE (b, temp) 123798944Sobrien { 123898944Sobrien /* Solib breakpoints must be explicitly reset after an exec(). */ 123998944Sobrien if (b->type == bp_shlib_event) 124098944Sobrien { 124198944Sobrien delete_breakpoint (b); 124298944Sobrien continue; 124398944Sobrien } 124446283Sdfr 124598944Sobrien /* Thread event breakpoints must be set anew after an exec(), 124698944Sobrien as must overlay event breakpoints. */ 124798944Sobrien if (b->type == bp_thread_event || b->type == bp_overlay_event) 124898944Sobrien { 124998944Sobrien delete_breakpoint (b); 125098944Sobrien continue; 125198944Sobrien } 125246283Sdfr 125398944Sobrien /* Step-resume breakpoints are meaningless after an exec(). */ 125498944Sobrien if (b->type == bp_step_resume) 125598944Sobrien { 125698944Sobrien delete_breakpoint (b); 125798944Sobrien continue; 125898944Sobrien } 125946283Sdfr 126098944Sobrien /* Ditto the sigtramp handler breakpoints. */ 126198944Sobrien if (b->type == bp_through_sigtramp) 126298944Sobrien { 126398944Sobrien delete_breakpoint (b); 126498944Sobrien continue; 126598944Sobrien } 126646283Sdfr 126798944Sobrien /* Ditto the exception-handling catchpoints. */ 126898944Sobrien if ((b->type == bp_catch_catch) || (b->type == bp_catch_throw)) 126998944Sobrien { 127098944Sobrien delete_breakpoint (b); 127198944Sobrien continue; 127298944Sobrien } 127346283Sdfr 127498944Sobrien /* Don't delete an exec catchpoint, because else the inferior 127598944Sobrien won't stop when it ought! 127646283Sdfr 127798944Sobrien Similarly, we probably ought to keep vfork catchpoints, 'cause 127898944Sobrien on this target, we may not be able to stop when the vfork is 127998944Sobrien seen, but only when the subsequent exec is seen. (And because 128098944Sobrien deleting fork catchpoints here but not vfork catchpoints will 128198944Sobrien seem mysterious to users, keep those too.) 128246283Sdfr 128398944Sobrien ??rehrauer: Let's hope that merely clearing out this catchpoint's 128498944Sobrien target address field, if any, is sufficient to have it be reset 128598944Sobrien automagically. Certainly on HP-UX that's true. 128646283Sdfr 128798944Sobrien Jim Blandy <jimb@redhat.com>: Actually, zero is a perfectly 1288130803Smarcel valid code address on some platforms (like the mn10300 1289130803Smarcel simulators). We shouldn't assign any special interpretation to 1290130803Smarcel a breakpoint with a zero address. And in fact, GDB doesn't --- 1291130803Smarcel I can't see what that comment above is talking about. As far 1292130803Smarcel as I can tell, setting the address of a 129398944Sobrien bp_catch_exec/bp_catch_vfork/bp_catch_fork breakpoint to zero 129498944Sobrien is meaningless, since those are implemented with HP-UX kernel 129598944Sobrien hackery, not by storing breakpoint instructions somewhere. */ 129698944Sobrien if ((b->type == bp_catch_exec) || 129798944Sobrien (b->type == bp_catch_vfork) || 129898944Sobrien (b->type == bp_catch_fork)) 129998944Sobrien { 1300130803Smarcel b->loc->address = (CORE_ADDR) NULL; 130198944Sobrien continue; 130298944Sobrien } 130346283Sdfr 130498944Sobrien /* bp_finish is a special case. The only way we ought to be able 130598944Sobrien to see one of these when an exec() has happened, is if the user 130698944Sobrien caught a vfork, and then said "finish". Ordinarily a finish just 130798944Sobrien carries them to the call-site of the current callee, by setting 130898944Sobrien a temporary bp there and resuming. But in this case, the finish 130998944Sobrien will carry them entirely through the vfork & exec. 131046283Sdfr 131198944Sobrien We don't want to allow a bp_finish to remain inserted now. But 131298944Sobrien we can't safely delete it, 'cause finish_command has a handle to 131398944Sobrien the bp on a bpstat, and will later want to delete it. There's a 131498944Sobrien chance (and I've seen it happen) that if we delete the bp_finish 131598944Sobrien here, that its storage will get reused by the time finish_command 131698944Sobrien gets 'round to deleting the "use to be a bp_finish" breakpoint. 131798944Sobrien We really must allow finish_command to delete a bp_finish. 131846283Sdfr 131998944Sobrien In the absense of a general solution for the "how do we know 132098944Sobrien it's safe to delete something others may have handles to?" 132198944Sobrien problem, what we'll do here is just uninsert the bp_finish, and 132298944Sobrien let finish_command delete it. 132346283Sdfr 132498944Sobrien (We know the bp_finish is "doomed" in the sense that it's 132598944Sobrien momentary, and will be deleted as soon as finish_command sees 132698944Sobrien the inferior stopped. So it doesn't matter that the bp's 132798944Sobrien address is probably bogus in the new a.out, unlike e.g., the 132898944Sobrien solib breakpoints.) */ 132998944Sobrien 133098944Sobrien if (b->type == bp_finish) 133198944Sobrien { 133298944Sobrien continue; 133398944Sobrien } 133498944Sobrien 133598944Sobrien /* Without a symbolic address, we have little hope of the 133698944Sobrien pre-exec() address meaning the same thing in the post-exec() 133798944Sobrien a.out. */ 133898944Sobrien if (b->addr_string == NULL) 133998944Sobrien { 134098944Sobrien delete_breakpoint (b); 134198944Sobrien continue; 134298944Sobrien } 134398944Sobrien 134498944Sobrien /* If this breakpoint has survived the above battery of checks, then 134598944Sobrien it must have a symbolic address. Be sure that it gets reevaluated 134698944Sobrien to a target address, rather than reusing the old evaluation. 134798944Sobrien 134898944Sobrien Jim Blandy <jimb@redhat.com>: As explained above in the comment 134998944Sobrien for bp_catch_exec and friends, I'm pretty sure this is entirely 135098944Sobrien unnecessary. A call to breakpoint_re_set_one always recomputes 135198944Sobrien the breakpoint's address from scratch, or deletes it if it can't. 135298944Sobrien So I think this assignment could be deleted without effect. */ 1353130803Smarcel b->loc->address = (CORE_ADDR) NULL; 135498944Sobrien } 135598944Sobrien /* FIXME what about longjmp breakpoints? Re-create them here? */ 135698944Sobrien create_overlay_event_breakpoint ("_ovly_debug_event"); 135746283Sdfr} 135846283Sdfr 135946283Sdfrint 136098944Sobriendetach_breakpoints (int pid) 136146283Sdfr{ 1362130803Smarcel struct bp_location *b; 136346283Sdfr int val; 136498944Sobrien struct cleanup *old_chain = save_inferior_ptid (); 136598944Sobrien 136698944Sobrien if (pid == PIDGET (inferior_ptid)) 136798944Sobrien error ("Cannot detach breakpoints of inferior_ptid"); 136898944Sobrien 136998944Sobrien /* Set inferior_ptid; remove_breakpoint uses this global. */ 137098944Sobrien inferior_ptid = pid_to_ptid (pid); 1371130803Smarcel ALL_BP_LOCATIONS (b) 137298944Sobrien { 137398944Sobrien if (b->inserted) 137498944Sobrien { 137598944Sobrien val = remove_breakpoint (b, mark_inserted); 137698944Sobrien if (val != 0) 137798944Sobrien { 137898944Sobrien do_cleanups (old_chain); 137998944Sobrien return val; 138098944Sobrien } 138198944Sobrien } 138298944Sobrien } 138398944Sobrien do_cleanups (old_chain); 138446283Sdfr return 0; 138546283Sdfr} 138646283Sdfr 138719370Spststatic int 1388130803Smarcelremove_breakpoint (struct bp_location *b, insertion_state_t is) 138919370Spst{ 139019370Spst int val; 139198944Sobrien 1392130803Smarcel if (b->owner->enable_state == bp_permanent) 139398944Sobrien /* Permanent breakpoints cannot be inserted or removed. */ 139498944Sobrien return 0; 139598944Sobrien 1396130803Smarcel if (b->owner->type == bp_none) 139798944Sobrien warning ("attempted to remove apparently deleted breakpoint #%d?", 1398130803Smarcel b->owner->number); 139946283Sdfr 1400130803Smarcel if (b->loc_type == bp_loc_software_breakpoint 1401130803Smarcel || b->loc_type == bp_loc_hardware_breakpoint) 140219370Spst { 1403130803Smarcel /* "Normal" instruction breakpoint: either the standard 1404130803Smarcel trap-instruction bp (bp_breakpoint), or a 1405130803Smarcel bp_hardware_breakpoint. */ 1406130803Smarcel 1407130803Smarcel /* First check to see if we have to handle an overlay. */ 1408130803Smarcel if (overlay_debugging == ovly_off 1409130803Smarcel || b->section == NULL 1410130803Smarcel || !(section_is_overlay (b->section))) 1411130803Smarcel { 1412130803Smarcel /* No overlay handling: just remove the breakpoint. */ 1413130803Smarcel 1414130803Smarcel if (b->loc_type == bp_loc_hardware_breakpoint) 1415130803Smarcel val = target_remove_hw_breakpoint (b->address, 1416130803Smarcel b->shadow_contents); 1417130803Smarcel else 1418130803Smarcel val = target_remove_breakpoint (b->address, b->shadow_contents); 1419130803Smarcel } 142019370Spst else 142146283Sdfr { 1422130803Smarcel /* This breakpoint is in an overlay section. 1423130803Smarcel Did we set a breakpoint at the LMA? */ 1424130803Smarcel if (!overlay_events_enabled) 1425130803Smarcel { 1426130803Smarcel /* Yes -- overlay event support is not active, so we 1427130803Smarcel should have set a breakpoint at the LMA. Remove it. 1428130803Smarcel */ 1429130803Smarcel CORE_ADDR addr = overlay_unmapped_address (b->address, 1430130803Smarcel b->section); 1431130803Smarcel /* Ignore any failures: if the LMA is in ROM, we will 1432130803Smarcel have already warned when we failed to insert it. */ 1433130803Smarcel if (b->loc_type == bp_loc_hardware_breakpoint) 1434130803Smarcel target_remove_hw_breakpoint (addr, b->shadow_contents); 1435130803Smarcel else 1436130803Smarcel target_remove_breakpoint (addr, b->shadow_contents); 1437130803Smarcel } 1438130803Smarcel /* Did we set a breakpoint at the VMA? 1439130803Smarcel If so, we will have marked the breakpoint 'inserted'. */ 1440130803Smarcel if (b->inserted) 144146283Sdfr { 1442130803Smarcel /* Yes -- remove it. Previously we did not bother to 1443130803Smarcel remove the breakpoint if the section had been 1444130803Smarcel unmapped, but let's not rely on that being safe. We 1445130803Smarcel don't know what the overlay manager might do. */ 1446130803Smarcel if (b->loc_type == bp_loc_hardware_breakpoint) 1447130803Smarcel val = target_remove_hw_breakpoint (b->address, 1448130803Smarcel b->shadow_contents); 1449130803Smarcel else 145098944Sobrien val = target_remove_breakpoint (b->address, 145146283Sdfr b->shadow_contents); 145246283Sdfr } 1453130803Smarcel else 1454130803Smarcel { 1455130803Smarcel /* No -- not inserted, so no need to remove. No error. */ 1456130803Smarcel val = 0; 1457130803Smarcel } 145846283Sdfr } 145919370Spst if (val) 146019370Spst return val; 146146283Sdfr b->inserted = (is == mark_inserted); 146219370Spst } 1463130803Smarcel else if (b->loc_type == bp_loc_hardware_watchpoint 1464130803Smarcel && breakpoint_enabled (b->owner) 146598944Sobrien && !b->duplicate) 146619370Spst { 146798944Sobrien struct value *v; 146898944Sobrien struct value *n; 146998944Sobrien 147046283Sdfr b->inserted = (is == mark_inserted); 147119370Spst /* Walk down the saved value chain. */ 1472130803Smarcel for (v = b->owner->val_chain; v; v = v->next) 147319370Spst { 147419370Spst /* For each memory reference remove the watchpoint 147519370Spst at that address. */ 147698944Sobrien if (VALUE_LVAL (v) == lval_memory 147798944Sobrien && ! VALUE_LAZY (v)) 147819370Spst { 147998944Sobrien struct type *vtype = check_typedef (VALUE_TYPE (v)); 148046283Sdfr 1481130803Smarcel if (v == b->owner->val_chain 148298944Sobrien || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT 148398944Sobrien && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) 148498944Sobrien { 148598944Sobrien CORE_ADDR addr; 148698944Sobrien int len, type; 148798944Sobrien 148898944Sobrien addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); 148998944Sobrien len = TYPE_LENGTH (VALUE_TYPE (v)); 149098944Sobrien type = hw_write; 1491130803Smarcel if (b->owner->type == bp_read_watchpoint) 149298944Sobrien type = hw_read; 1493130803Smarcel else if (b->owner->type == bp_access_watchpoint) 149498944Sobrien type = hw_access; 149598944Sobrien 149698944Sobrien val = target_remove_watchpoint (addr, len, type); 149798944Sobrien if (val == -1) 149898944Sobrien b->inserted = 1; 149998944Sobrien val = 0; 150098944Sobrien } 150119370Spst } 150219370Spst } 150319370Spst /* Failure to remove any of the hardware watchpoints comes here. */ 150446283Sdfr if ((is == mark_uninserted) && (b->inserted)) 150598944Sobrien warning ("Could not remove hardware watchpoint %d.", 1506130803Smarcel b->owner->number); 150798944Sobrien 150819370Spst /* Free the saved value chain. We will construct a new one 150998944Sobrien the next time the watchpoint is inserted. */ 1510130803Smarcel for (v = b->owner->val_chain; v; v = n) 151119370Spst { 151219370Spst n = v->next; 151319370Spst value_free (v); 151419370Spst } 1515130803Smarcel b->owner->val_chain = NULL; 151619370Spst } 1517130803Smarcel else if ((b->owner->type == bp_catch_fork || 1518130803Smarcel b->owner->type == bp_catch_vfork || 1519130803Smarcel b->owner->type == bp_catch_exec) 1520130803Smarcel && breakpoint_enabled (b->owner) 152198944Sobrien && !b->duplicate) 152246283Sdfr { 152346283Sdfr val = -1; 1524130803Smarcel switch (b->owner->type) 152598944Sobrien { 152698944Sobrien case bp_catch_fork: 152798944Sobrien val = target_remove_fork_catchpoint (PIDGET (inferior_ptid)); 152898944Sobrien break; 152998944Sobrien case bp_catch_vfork: 153098944Sobrien val = target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); 153198944Sobrien break; 153298944Sobrien case bp_catch_exec: 153398944Sobrien val = target_remove_exec_catchpoint (PIDGET (inferior_ptid)); 153498944Sobrien break; 153598944Sobrien default: 153698944Sobrien warning ("Internal error, %s line %d.", __FILE__, __LINE__); 153798944Sobrien break; 153898944Sobrien } 153946283Sdfr if (val) 154046283Sdfr return val; 154146283Sdfr b->inserted = (is == mark_inserted); 154246283Sdfr } 1543130803Smarcel else if ((b->owner->type == bp_catch_catch || 1544130803Smarcel b->owner->type == bp_catch_throw) 1545130803Smarcel && breakpoint_enabled (b->owner) 154698944Sobrien && !b->duplicate) 154746283Sdfr { 154846283Sdfr 154998944Sobrien val = target_remove_breakpoint (b->address, b->shadow_contents); 155046283Sdfr if (val) 155198944Sobrien return val; 155246283Sdfr b->inserted = (is == mark_inserted); 155346283Sdfr } 1554130803Smarcel else if (ep_is_exception_catchpoint (b->owner) 155598944Sobrien && b->inserted /* sometimes previous insert doesn't happen */ 1556130803Smarcel && breakpoint_enabled (b->owner) 155798944Sobrien && !b->duplicate) 155846283Sdfr { 155946283Sdfr 156098944Sobrien val = target_remove_breakpoint (b->address, b->shadow_contents); 156146283Sdfr if (val) 156298944Sobrien return val; 156398944Sobrien 156446283Sdfr b->inserted = (is == mark_inserted); 156546283Sdfr } 156646283Sdfr 156719370Spst return 0; 156819370Spst} 156919370Spst 157019370Spst/* Clear the "inserted" flag in all breakpoints. */ 157119370Spst 157219370Spstvoid 157398944Sobrienmark_breakpoints_out (void) 157419370Spst{ 1575130803Smarcel struct bp_location *bpt; 157619370Spst 1577130803Smarcel ALL_BP_LOCATIONS (bpt) 1578130803Smarcel bpt->inserted = 0; 157919370Spst} 158019370Spst 158198944Sobrien/* Clear the "inserted" flag in all breakpoints and delete any 158298944Sobrien breakpoints which should go away between runs of the program. 158319370Spst 158446283Sdfr Plus other such housekeeping that has to be done for breakpoints 158546283Sdfr between runs. 158646283Sdfr 158798944Sobrien Note: this function gets called at the end of a run (by 158898944Sobrien generic_mourn_inferior) and when a run begins (by 158998944Sobrien init_wait_for_inferior). */ 159046283Sdfr 159146283Sdfr 159246283Sdfr 159319370Spstvoid 159498944Sobrienbreakpoint_init_inferior (enum inf_context context) 159519370Spst{ 1596130803Smarcel struct breakpoint *b, *temp; 1597130803Smarcel struct bp_location *bpt; 159846283Sdfr static int warning_needed = 0; 159919370Spst 1600130803Smarcel ALL_BP_LOCATIONS (bpt) 1601130803Smarcel bpt->inserted = 0; 1602130803Smarcel 160319370Spst ALL_BREAKPOINTS_SAFE (b, temp) 160498944Sobrien { 160598944Sobrien switch (b->type) 160698944Sobrien { 160798944Sobrien case bp_call_dummy: 160898944Sobrien case bp_watchpoint_scope: 160919370Spst 161098944Sobrien /* If the call dummy breakpoint is at the entry point it will 161198944Sobrien cause problems when the inferior is rerun, so we better 161298944Sobrien get rid of it. 161319370Spst 161498944Sobrien Also get rid of scope breakpoints. */ 161598944Sobrien delete_breakpoint (b); 161698944Sobrien break; 161746283Sdfr 161898944Sobrien case bp_watchpoint: 161998944Sobrien case bp_hardware_watchpoint: 162098944Sobrien case bp_read_watchpoint: 162198944Sobrien case bp_access_watchpoint: 162246283Sdfr 162398944Sobrien /* Likewise for watchpoints on local expressions. */ 162498944Sobrien if (b->exp_valid_block != NULL) 162598944Sobrien delete_breakpoint (b); 1626130803Smarcel if (context == inf_starting) 1627130803Smarcel { 1628130803Smarcel /* Reset val field to force reread of starting value 1629130803Smarcel in insert_breakpoints. */ 1630130803Smarcel if (b->val) 1631130803Smarcel value_free (b->val); 1632130803Smarcel b->val = NULL; 1633130803Smarcel } 163498944Sobrien break; 163598944Sobrien default: 163698944Sobrien /* Likewise for exception catchpoints in dynamic-linked 163798944Sobrien executables where required */ 163898944Sobrien if (ep_is_exception_catchpoint (b) && 163998944Sobrien exception_catchpoints_are_fragile) 164098944Sobrien { 164198944Sobrien warning_needed = 1; 164246283Sdfr delete_breakpoint (b); 164398944Sobrien } 164498944Sobrien break; 164598944Sobrien } 164698944Sobrien } 164746283Sdfr 164846283Sdfr if (exception_catchpoints_are_fragile) 164946283Sdfr exception_support_initialized = 0; 165046283Sdfr 165198944Sobrien /* Don't issue the warning unless it's really needed... */ 165246283Sdfr if (warning_needed && (context != inf_exited)) 165346283Sdfr { 165498944Sobrien warning ("Exception catchpoints from last run were deleted."); 165598944Sobrien warning ("You must reinsert them explicitly."); 165646283Sdfr warning_needed = 0; 165798944Sobrien } 165819370Spst} 165919370Spst 166098944Sobrien/* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint 166198944Sobrien exists at PC. It returns ordinary_breakpoint_here if it's an 166298944Sobrien ordinary breakpoint, or permanent_breakpoint_here if it's a 166398944Sobrien permanent breakpoint. 166498944Sobrien - When continuing from a location with an ordinary breakpoint, we 166598944Sobrien actually single step once before calling insert_breakpoints. 166698944Sobrien - When continuing from a localion with a permanent breakpoint, we 166798944Sobrien need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by 166898944Sobrien the target, to advance the PC past the breakpoint. */ 166919370Spst 167098944Sobrienenum breakpoint_here 167198944Sobrienbreakpoint_here_p (CORE_ADDR pc) 167219370Spst{ 1673130803Smarcel struct bp_location *bpt; 167498944Sobrien int any_breakpoint_here = 0; 167519370Spst 1676130803Smarcel ALL_BP_LOCATIONS (bpt) 1677130803Smarcel { 1678130803Smarcel if (bpt->loc_type != bp_loc_software_breakpoint 1679130803Smarcel && bpt->loc_type != bp_loc_hardware_breakpoint) 1680130803Smarcel continue; 168119370Spst 1682130803Smarcel if ((breakpoint_enabled (bpt->owner) 1683130803Smarcel || bpt->owner->enable_state == bp_permanent) 1684130803Smarcel && bpt->address == pc) /* bp is enabled and matches pc */ 1685130803Smarcel { 1686130803Smarcel if (overlay_debugging 1687130803Smarcel && section_is_overlay (bpt->section) 1688130803Smarcel && !section_is_mapped (bpt->section)) 1689130803Smarcel continue; /* unmapped overlay -- can't be a match */ 1690130803Smarcel else if (bpt->owner->enable_state == bp_permanent) 1691130803Smarcel return permanent_breakpoint_here; 1692130803Smarcel else 1693130803Smarcel any_breakpoint_here = 1; 1694130803Smarcel } 1695130803Smarcel } 1696130803Smarcel 169798944Sobrien return any_breakpoint_here ? ordinary_breakpoint_here : 0; 169819370Spst} 169919370Spst 170046283Sdfr 170198944Sobrien/* breakpoint_inserted_here_p (PC) is just like breakpoint_here_p(), 170298944Sobrien but it only returns true if there is actually a breakpoint inserted 170398944Sobrien at PC. */ 170498944Sobrien 170546283Sdfrint 170698944Sobrienbreakpoint_inserted_here_p (CORE_ADDR pc) 170746283Sdfr{ 1708130803Smarcel struct bp_location *bpt; 170946283Sdfr 1710130803Smarcel ALL_BP_LOCATIONS (bpt) 171198944Sobrien { 1712130803Smarcel if (bpt->loc_type != bp_loc_software_breakpoint 1713130803Smarcel && bpt->loc_type != bp_loc_hardware_breakpoint) 1714130803Smarcel continue; 1715130803Smarcel 1716130803Smarcel if (bpt->inserted 1717130803Smarcel && bpt->address == pc) /* bp is inserted and matches pc */ 1718130803Smarcel { 1719130803Smarcel if (overlay_debugging 1720130803Smarcel && section_is_overlay (bpt->section) 1721130803Smarcel && !section_is_mapped (bpt->section)) 1722130803Smarcel continue; /* unmapped overlay -- can't be a match */ 1723130803Smarcel else 1724130803Smarcel return 1; 1725130803Smarcel } 172698944Sobrien } 172746283Sdfr 172846283Sdfr return 0; 172946283Sdfr} 173046283Sdfr 1731130803Smarcel/* This function returns non-zero iff there is a software breakpoint 1732130803Smarcel inserted at PC. */ 1733130803Smarcel 1734130803Smarcelint 1735130803Smarcelsoftware_breakpoint_inserted_here_p (CORE_ADDR pc) 1736130803Smarcel{ 1737130803Smarcel struct bp_location *bpt; 1738130803Smarcel int any_breakpoint_here = 0; 1739130803Smarcel 1740130803Smarcel ALL_BP_LOCATIONS (bpt) 1741130803Smarcel { 1742130803Smarcel if (bpt->loc_type != bp_loc_software_breakpoint) 1743130803Smarcel continue; 1744130803Smarcel 1745130803Smarcel if ((breakpoint_enabled (bpt->owner) 1746130803Smarcel || bpt->owner->enable_state == bp_permanent) 1747130803Smarcel && bpt->inserted 1748130803Smarcel && bpt->address == pc) /* bp is enabled and matches pc */ 1749130803Smarcel { 1750130803Smarcel if (overlay_debugging 1751130803Smarcel && section_is_overlay (bpt->section) 1752130803Smarcel && !section_is_mapped (bpt->section)) 1753130803Smarcel continue; /* unmapped overlay -- can't be a match */ 1754130803Smarcel else 1755130803Smarcel return 1; 1756130803Smarcel } 1757130803Smarcel } 1758130803Smarcel 1759130803Smarcel return 0; 1760130803Smarcel} 1761130803Smarcel 176298944Sobrien/* Return nonzero if FRAME is a dummy frame. We can't use 1763130803Smarcel DEPRECATED_PC_IN_CALL_DUMMY because figuring out the saved SP would 1764130803Smarcel take too much time, at least using frame_register() on the 68k. 1765130803Smarcel This means that for this function to work right a port must use the 176698944Sobrien bp_call_dummy breakpoint. */ 176719370Spst 176819370Spstint 1769130803Smarceldeprecated_frame_in_dummy (struct frame_info *frame) 177019370Spst{ 177119370Spst struct breakpoint *b; 177219370Spst 1773130803Smarcel /* This function is used by two files: get_frame_type(), after first 1774130803Smarcel checking that !DEPRECATED_USE_GENERIC_DUMMY_FRAMES; and 1775130803Smarcel sparc-tdep.c, which doesn't yet use generic dummy frames anyway. */ 1776130803Smarcel gdb_assert (!DEPRECATED_USE_GENERIC_DUMMY_FRAMES); 177719370Spst 177898944Sobrien ALL_BREAKPOINTS (b) 177998944Sobrien { 178098944Sobrien if (b->type == bp_call_dummy 1781130803Smarcel && frame_id_eq (b->frame_id, get_frame_id (frame)) 178298944Sobrien /* We need to check the PC as well as the frame on the sparc, 178398944Sobrien for signals.exp in the testsuite. */ 1784130803Smarcel && (get_frame_pc (frame) 1785130803Smarcel >= (b->loc->address 1786130803Smarcel - DEPRECATED_SIZEOF_CALL_DUMMY_WORDS / sizeof (LONGEST) * DEPRECATED_REGISTER_SIZE)) 1787130803Smarcel && get_frame_pc (frame) <= b->loc->address) 178898944Sobrien return 1; 178998944Sobrien } 179019370Spst return 0; 179119370Spst} 179219370Spst 1793130803Smarcel/* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at 1794130803Smarcel PC is valid for process/thread PTID. */ 179519370Spst 179619370Spstint 179798944Sobrienbreakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) 179819370Spst{ 1799130803Smarcel struct bp_location *bpt; 180019370Spst int thread; 180119370Spst 180298944Sobrien thread = pid_to_thread_id (ptid); 180319370Spst 1804130803Smarcel ALL_BP_LOCATIONS (bpt) 180598944Sobrien { 1806130803Smarcel if (bpt->loc_type != bp_loc_software_breakpoint 1807130803Smarcel && bpt->loc_type != bp_loc_hardware_breakpoint) 1808130803Smarcel continue; 1809130803Smarcel 1810130803Smarcel if ((breakpoint_enabled (bpt->owner) 1811130803Smarcel || bpt->owner->enable_state == bp_permanent) 1812130803Smarcel && bpt->address == pc 1813130803Smarcel && (bpt->owner->thread == -1 || bpt->owner->thread == thread)) 1814130803Smarcel { 1815130803Smarcel if (overlay_debugging 1816130803Smarcel && section_is_overlay (bpt->section) 1817130803Smarcel && !section_is_mapped (bpt->section)) 1818130803Smarcel continue; /* unmapped overlay -- can't be a match */ 1819130803Smarcel else 1820130803Smarcel return 1; 1821130803Smarcel } 182298944Sobrien } 182319370Spst 182419370Spst return 0; 182519370Spst} 182698944Sobrien 182719370Spst 182819370Spst/* bpstat stuff. External routines' interfaces are documented 182919370Spst in breakpoint.h. */ 183019370Spst 183146283Sdfrint 183298944Sobrienep_is_catchpoint (struct breakpoint *ep) 183346283Sdfr{ 183446283Sdfr return 183546283Sdfr (ep->type == bp_catch_load) 183646283Sdfr || (ep->type == bp_catch_unload) 183746283Sdfr || (ep->type == bp_catch_fork) 183846283Sdfr || (ep->type == bp_catch_vfork) 183946283Sdfr || (ep->type == bp_catch_exec) 184046283Sdfr || (ep->type == bp_catch_catch) 184198944Sobrien || (ep->type == bp_catch_throw); 184246283Sdfr 184398944Sobrien /* ??rehrauer: Add more kinds here, as are implemented... */ 184498944Sobrien} 184546283Sdfr 184646283Sdfrint 184798944Sobrienep_is_shlib_catchpoint (struct breakpoint *ep) 184846283Sdfr{ 184946283Sdfr return 185046283Sdfr (ep->type == bp_catch_load) 185198944Sobrien || (ep->type == bp_catch_unload); 185246283Sdfr} 185346283Sdfr 185446283Sdfrint 185598944Sobrienep_is_exception_catchpoint (struct breakpoint *ep) 185646283Sdfr{ 185746283Sdfr return 185846283Sdfr (ep->type == bp_catch_catch) 185998944Sobrien || (ep->type == bp_catch_throw); 186046283Sdfr} 186146283Sdfr 186219370Spst/* Clear a bpstat so that it says we are not at any breakpoint. 186319370Spst Also free any storage that is part of a bpstat. */ 186419370Spst 186519370Spstvoid 186698944Sobrienbpstat_clear (bpstat *bsp) 186719370Spst{ 186819370Spst bpstat p; 186919370Spst bpstat q; 187019370Spst 187119370Spst if (bsp == 0) 187219370Spst return; 187319370Spst p = *bsp; 187419370Spst while (p != NULL) 187519370Spst { 187619370Spst q = p->next; 187719370Spst if (p->old_val != NULL) 187819370Spst value_free (p->old_val); 1879130803Smarcel free_command_lines (&p->commands); 188098944Sobrien xfree (p); 188119370Spst p = q; 188219370Spst } 188319370Spst *bsp = NULL; 188419370Spst} 188519370Spst 188619370Spst/* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that 188719370Spst is part of the bpstat is copied as well. */ 188819370Spst 188919370Spstbpstat 189098944Sobrienbpstat_copy (bpstat bs) 189119370Spst{ 189219370Spst bpstat p = NULL; 189319370Spst bpstat tmp; 189419370Spst bpstat retval = NULL; 189519370Spst 189619370Spst if (bs == NULL) 189719370Spst return bs; 189819370Spst 189919370Spst for (; bs != NULL; bs = bs->next) 190019370Spst { 190119370Spst tmp = (bpstat) xmalloc (sizeof (*tmp)); 190219370Spst memcpy (tmp, bs, sizeof (*tmp)); 1903130803Smarcel if (bs->commands != NULL) 1904130803Smarcel tmp->commands = copy_command_lines (bs->commands); 1905130803Smarcel if (bs->old_val != NULL) 1906130803Smarcel tmp->old_val = value_copy (bs->old_val); 1907130803Smarcel 190819370Spst if (p == NULL) 190919370Spst /* This is the first thing in the chain. */ 191019370Spst retval = tmp; 191119370Spst else 191219370Spst p->next = tmp; 191319370Spst p = tmp; 191419370Spst } 191519370Spst p->next = NULL; 191619370Spst return retval; 191719370Spst} 191819370Spst 191919370Spst/* Find the bpstat associated with this breakpoint */ 192019370Spst 192119370Spstbpstat 192298944Sobrienbpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) 192319370Spst{ 192498944Sobrien if (bsp == NULL) 192598944Sobrien return NULL; 192619370Spst 192798944Sobrien for (; bsp != NULL; bsp = bsp->next) 192898944Sobrien { 192998944Sobrien if (bsp->breakpoint_at == breakpoint) 193098944Sobrien return bsp; 193198944Sobrien } 193219370Spst return NULL; 193319370Spst} 193419370Spst 193546283Sdfr/* Find a step_resume breakpoint associated with this bpstat. 193646283Sdfr (If there are multiple step_resume bp's on the list, this function 193746283Sdfr will arbitrarily pick one.) 193846283Sdfr 193946283Sdfr It is an error to use this function if BPSTAT doesn't contain a 194046283Sdfr step_resume breakpoint. 194146283Sdfr 194246283Sdfr See wait_for_inferior's use of this function. */ 194346283Sdfrstruct breakpoint * 194498944Sobrienbpstat_find_step_resume_breakpoint (bpstat bsp) 194546283Sdfr{ 194698944Sobrien int current_thread; 194798944Sobrien 194846283Sdfr if (bsp == NULL) 194946283Sdfr error ("Internal error (bpstat_find_step_resume_breakpoint)"); 195046283Sdfr 195198944Sobrien current_thread = pid_to_thread_id (inferior_ptid); 195298944Sobrien 195346283Sdfr for (; bsp != NULL; bsp = bsp->next) 195446283Sdfr { 195546283Sdfr if ((bsp->breakpoint_at != NULL) && 195698944Sobrien (bsp->breakpoint_at->type == bp_step_resume) && 195798944Sobrien (bsp->breakpoint_at->thread == current_thread || 195898944Sobrien bsp->breakpoint_at->thread == -1)) 195998944Sobrien return bsp->breakpoint_at; 196046283Sdfr } 196146283Sdfr 196246283Sdfr error ("Internal error (no step_resume breakpoint found)"); 196346283Sdfr} 196446283Sdfr 196546283Sdfr 196619370Spst/* Return the breakpoint number of the first breakpoint we are stopped 196719370Spst at. *BSP upon return is a bpstat which points to the remaining 196819370Spst breakpoints stopped at (but which is not guaranteed to be good for 196919370Spst anything but further calls to bpstat_num). 197019370Spst Return 0 if passed a bpstat which does not indicate any breakpoints. */ 197119370Spst 197219370Spstint 197398944Sobrienbpstat_num (bpstat *bsp) 197419370Spst{ 197519370Spst struct breakpoint *b; 197619370Spst 197719370Spst if ((*bsp) == NULL) 197819370Spst return 0; /* No more breakpoint values */ 197919370Spst else 198019370Spst { 198119370Spst b = (*bsp)->breakpoint_at; 198219370Spst *bsp = (*bsp)->next; 198319370Spst if (b == NULL) 198419370Spst return -1; /* breakpoint that's been deleted since */ 198519370Spst else 198698944Sobrien return b->number; /* We have its number */ 198719370Spst } 198819370Spst} 198919370Spst 199019370Spst/* Modify BS so that the actions will not be performed. */ 199119370Spst 199219370Spstvoid 199398944Sobrienbpstat_clear_actions (bpstat bs) 199419370Spst{ 199519370Spst for (; bs != NULL; bs = bs->next) 199619370Spst { 1997130803Smarcel free_command_lines (&bs->commands); 199819370Spst if (bs->old_val != NULL) 199919370Spst { 200019370Spst value_free (bs->old_val); 200119370Spst bs->old_val = NULL; 200219370Spst } 200319370Spst } 200419370Spst} 200519370Spst 200619370Spst/* Stub for cleaning up our state if we error-out of a breakpoint command */ 200719370Spststatic void 2008130803Smarcelcleanup_executing_breakpoints (void *ignore) 200919370Spst{ 201019370Spst executing_breakpoint_commands = 0; 201119370Spst} 201219370Spst 201319370Spst/* Execute all the commands associated with all the breakpoints at this 201419370Spst location. Any of these commands could cause the process to proceed 201519370Spst beyond this point, etc. We look out for such changes by checking 201619370Spst the global "breakpoint_proceeded" after each command. */ 201719370Spst 201819370Spstvoid 201998944Sobrienbpstat_do_actions (bpstat *bsp) 202019370Spst{ 202119370Spst bpstat bs; 202219370Spst struct cleanup *old_chain; 202319370Spst 202446283Sdfr /* Avoid endless recursion if a `source' command is contained 202546283Sdfr in bs->commands. */ 202646283Sdfr if (executing_breakpoint_commands) 202746283Sdfr return; 202846283Sdfr 202919370Spst executing_breakpoint_commands = 1; 203019370Spst old_chain = make_cleanup (cleanup_executing_breakpoints, 0); 203119370Spst 203219370Spsttop: 203346283Sdfr /* Note that (as of this writing), our callers all appear to 203446283Sdfr be passing us the address of global stop_bpstat. And, if 203546283Sdfr our calls to execute_control_command cause the inferior to 203646283Sdfr proceed, that global (and hence, *bsp) will change. 203746283Sdfr 203846283Sdfr We must be careful to not touch *bsp unless the inferior 203946283Sdfr has not proceeded. */ 204046283Sdfr 204146283Sdfr /* This pointer will iterate over the list of bpstat's. */ 204219370Spst bs = *bsp; 204319370Spst 204419370Spst breakpoint_proceeded = 0; 204519370Spst for (; bs != NULL; bs = bs->next) 204619370Spst { 2047130803Smarcel struct command_line *cmd; 2048130803Smarcel struct cleanup *this_cmd_tree_chain; 2049130803Smarcel 2050130803Smarcel /* Take ownership of the BSP's command tree, if it has one. 2051130803Smarcel 2052130803Smarcel The command tree could legitimately contain commands like 2053130803Smarcel 'step' and 'next', which call clear_proceed_status, which 2054130803Smarcel frees stop_bpstat's command tree. To make sure this doesn't 2055130803Smarcel free the tree we're executing out from under us, we need to 2056130803Smarcel take ownership of the tree ourselves. Since a given bpstat's 2057130803Smarcel commands are only executed once, we don't need to copy it; we 2058130803Smarcel can clear the pointer in the bpstat, and make sure we free 2059130803Smarcel the tree when we're done. */ 206019370Spst cmd = bs->commands; 2061130803Smarcel bs->commands = 0; 2062130803Smarcel this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); 2063130803Smarcel 206419370Spst while (cmd != NULL) 206519370Spst { 206619370Spst execute_control_command (cmd); 206746283Sdfr 206846283Sdfr if (breakpoint_proceeded) 206946283Sdfr break; 207046283Sdfr else 207146283Sdfr cmd = cmd->next; 207219370Spst } 2073130803Smarcel 2074130803Smarcel /* We can free this command tree now. */ 2075130803Smarcel do_cleanups (this_cmd_tree_chain); 2076130803Smarcel 207719370Spst if (breakpoint_proceeded) 207819370Spst /* The inferior is proceeded by the command; bomb out now. 207919370Spst The bpstat chain has been blown away by wait_for_inferior. 208019370Spst But since execution has stopped again, there is a new bpstat 208119370Spst to look at, so start over. */ 208219370Spst goto top; 208319370Spst } 2084130803Smarcel do_cleanups (old_chain); 208519370Spst} 208619370Spst 208798944Sobrien/* This is the normal print function for a bpstat. In the future, 208819370Spst much of this logic could (should?) be moved to bpstat_stop_status, 208998944Sobrien by having it set different print_it values. 209019370Spst 209198944Sobrien Current scheme: When we stop, bpstat_print() is called. It loops 209298944Sobrien through the bpstat list of things causing this stop, calling the 209398944Sobrien print_bp_stop_message function on each one. The behavior of the 209498944Sobrien print_bp_stop_message function depends on the print_it field of 209598944Sobrien bpstat. If such field so indicates, call this function here. 209646283Sdfr 209798944Sobrien Return values from this routine (ultimately used by bpstat_print() 209898944Sobrien and normal_stop() to decide what to do): 209998944Sobrien PRINT_NOTHING: Means we already printed all we needed to print, 210098944Sobrien don't print anything else. 210198944Sobrien PRINT_SRC_ONLY: Means we printed something, and we do *not* desire 210298944Sobrien that something to be followed by a location. 210398944Sobrien PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire 210498944Sobrien that something to be followed by a location. 210598944Sobrien PRINT_UNKNOWN: Means we printed nothing or we need to do some more 210698944Sobrien analysis. */ 210798944Sobrien 210898944Sobrienstatic enum print_stop_action 210998944Sobrienprint_it_typical (bpstat bs) 211019370Spst{ 2111130803Smarcel struct cleanup *old_chain, *ui_out_chain; 211298944Sobrien struct ui_stream *stb; 211398944Sobrien stb = ui_out_stream_new (uiout); 211498944Sobrien old_chain = make_cleanup_ui_out_stream_delete (stb); 211519370Spst /* bs->breakpoint_at can be NULL if it was a momentary breakpoint 211619370Spst which has since been deleted. */ 211798944Sobrien if (bs->breakpoint_at == NULL) 211898944Sobrien return PRINT_UNKNOWN; 211919370Spst 212098944Sobrien switch (bs->breakpoint_at->type) 212146283Sdfr { 212298944Sobrien case bp_breakpoint: 212398944Sobrien case bp_hardware_breakpoint: 2124130803Smarcel if (bs->breakpoint_at->loc->address != bs->breakpoint_at->loc->requested_address) 2125130803Smarcel breakpoint_adjustment_warning (bs->breakpoint_at->loc->requested_address, 2126130803Smarcel bs->breakpoint_at->loc->address, 2127130803Smarcel bs->breakpoint_at->number, 1); 212898944Sobrien annotate_breakpoint (bs->breakpoint_at->number); 212998944Sobrien ui_out_text (uiout, "\nBreakpoint "); 213098944Sobrien if (ui_out_is_mi_like_p (uiout)) 213198944Sobrien ui_out_field_string (uiout, "reason", "breakpoint-hit"); 213298944Sobrien ui_out_field_int (uiout, "bkptno", bs->breakpoint_at->number); 213398944Sobrien ui_out_text (uiout, ", "); 213498944Sobrien return PRINT_SRC_AND_LOC; 213598944Sobrien break; 213698944Sobrien 213798944Sobrien case bp_shlib_event: 213898944Sobrien /* Did we stop because the user set the stop_on_solib_events 213998944Sobrien variable? (If so, we report this as a generic, "Stopped due 214098944Sobrien to shlib event" message.) */ 214198944Sobrien printf_filtered ("Stopped due to shared library event\n"); 214298944Sobrien return PRINT_NOTHING; 214398944Sobrien break; 214498944Sobrien 214598944Sobrien case bp_thread_event: 214698944Sobrien /* Not sure how we will get here. 214798944Sobrien GDB should not stop for these breakpoints. */ 214898944Sobrien printf_filtered ("Thread Event Breakpoint: gdb should not stop!\n"); 214998944Sobrien return PRINT_NOTHING; 215098944Sobrien break; 215198944Sobrien 215298944Sobrien case bp_overlay_event: 215398944Sobrien /* By analogy with the thread event, GDB should not stop for these. */ 215498944Sobrien printf_filtered ("Overlay Event Breakpoint: gdb should not stop!\n"); 215598944Sobrien return PRINT_NOTHING; 215698944Sobrien break; 215798944Sobrien 215898944Sobrien case bp_catch_load: 215946283Sdfr annotate_catchpoint (bs->breakpoint_at->number); 216046283Sdfr printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); 216198944Sobrien printf_filtered ("loaded"); 216246283Sdfr printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname); 216398944Sobrien return PRINT_SRC_AND_LOC; 216498944Sobrien break; 216598944Sobrien 216698944Sobrien case bp_catch_unload: 216746283Sdfr annotate_catchpoint (bs->breakpoint_at->number); 216846283Sdfr printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); 216998944Sobrien printf_filtered ("unloaded"); 217098944Sobrien printf_filtered (" %s), ", bs->breakpoint_at->triggered_dll_pathname); 217198944Sobrien return PRINT_SRC_AND_LOC; 217298944Sobrien break; 217398944Sobrien 217498944Sobrien case bp_catch_fork: 217546283Sdfr annotate_catchpoint (bs->breakpoint_at->number); 217698944Sobrien printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); 217798944Sobrien printf_filtered ("forked"); 217898944Sobrien printf_filtered (" process %d), ", 217998944Sobrien bs->breakpoint_at->forked_inferior_pid); 218098944Sobrien return PRINT_SRC_AND_LOC; 218198944Sobrien break; 218298944Sobrien 218398944Sobrien case bp_catch_vfork: 218498944Sobrien annotate_catchpoint (bs->breakpoint_at->number); 218598944Sobrien printf_filtered ("\nCatchpoint %d (", bs->breakpoint_at->number); 218698944Sobrien printf_filtered ("vforked"); 218798944Sobrien printf_filtered (" process %d), ", 218898944Sobrien bs->breakpoint_at->forked_inferior_pid); 218998944Sobrien return PRINT_SRC_AND_LOC; 219098944Sobrien break; 219198944Sobrien 219298944Sobrien case bp_catch_exec: 219398944Sobrien annotate_catchpoint (bs->breakpoint_at->number); 219446283Sdfr printf_filtered ("\nCatchpoint %d (exec'd %s), ", 219598944Sobrien bs->breakpoint_at->number, 219698944Sobrien bs->breakpoint_at->exec_pathname); 219798944Sobrien return PRINT_SRC_AND_LOC; 219898944Sobrien break; 219998944Sobrien 220098944Sobrien case bp_catch_catch: 220198944Sobrien if (current_exception_event && 220298944Sobrien (CURRENT_EXCEPTION_KIND == EX_EVENT_CATCH)) 220398944Sobrien { 220498944Sobrien annotate_catchpoint (bs->breakpoint_at->number); 220598944Sobrien printf_filtered ("\nCatchpoint %d (exception caught), ", 220698944Sobrien bs->breakpoint_at->number); 220798944Sobrien printf_filtered ("throw location "); 220898944Sobrien if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE) 220998944Sobrien printf_filtered ("%s:%d", 221098944Sobrien CURRENT_EXCEPTION_THROW_FILE, 221198944Sobrien CURRENT_EXCEPTION_THROW_LINE); 221298944Sobrien else 221398944Sobrien printf_filtered ("unknown"); 221498944Sobrien 221598944Sobrien printf_filtered (", catch location "); 221698944Sobrien if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE) 221798944Sobrien printf_filtered ("%s:%d", 221898944Sobrien CURRENT_EXCEPTION_CATCH_FILE, 221998944Sobrien CURRENT_EXCEPTION_CATCH_LINE); 222098944Sobrien else 222198944Sobrien printf_filtered ("unknown"); 222298944Sobrien 222398944Sobrien printf_filtered ("\n"); 222498944Sobrien /* don't bother to print location frame info */ 222598944Sobrien return PRINT_SRC_ONLY; 222698944Sobrien } 222746283Sdfr else 222898944Sobrien { 222998944Sobrien /* really throw, some other bpstat will handle it */ 223098944Sobrien return PRINT_UNKNOWN; 223198944Sobrien } 223298944Sobrien break; 223398944Sobrien 223498944Sobrien case bp_catch_throw: 223598944Sobrien if (current_exception_event && 223698944Sobrien (CURRENT_EXCEPTION_KIND == EX_EVENT_THROW)) 223798944Sobrien { 223898944Sobrien annotate_catchpoint (bs->breakpoint_at->number); 223998944Sobrien printf_filtered ("\nCatchpoint %d (exception thrown), ", 224098944Sobrien bs->breakpoint_at->number); 224198944Sobrien printf_filtered ("throw location "); 224298944Sobrien if (CURRENT_EXCEPTION_THROW_PC && CURRENT_EXCEPTION_THROW_LINE) 224398944Sobrien printf_filtered ("%s:%d", 224498944Sobrien CURRENT_EXCEPTION_THROW_FILE, 224598944Sobrien CURRENT_EXCEPTION_THROW_LINE); 224698944Sobrien else 224798944Sobrien printf_filtered ("unknown"); 224898944Sobrien 224998944Sobrien printf_filtered (", catch location "); 225098944Sobrien if (CURRENT_EXCEPTION_CATCH_PC && CURRENT_EXCEPTION_CATCH_LINE) 225198944Sobrien printf_filtered ("%s:%d", 225298944Sobrien CURRENT_EXCEPTION_CATCH_FILE, 225398944Sobrien CURRENT_EXCEPTION_CATCH_LINE); 225498944Sobrien else 225598944Sobrien printf_filtered ("unknown"); 225698944Sobrien 225798944Sobrien printf_filtered ("\n"); 225898944Sobrien /* don't bother to print location frame info */ 225998944Sobrien return PRINT_SRC_ONLY; 226098944Sobrien } 226146283Sdfr else 226298944Sobrien { 226398944Sobrien /* really catch, some other bpstat will handle it */ 226498944Sobrien return PRINT_UNKNOWN; 226598944Sobrien } 226698944Sobrien break; 226746283Sdfr 226898944Sobrien case bp_watchpoint: 226998944Sobrien case bp_hardware_watchpoint: 227098944Sobrien if (bs->old_val != NULL) 227198944Sobrien { 227298944Sobrien annotate_watchpoint (bs->breakpoint_at->number); 227398944Sobrien if (ui_out_is_mi_like_p (uiout)) 227498944Sobrien ui_out_field_string (uiout, "reason", "watchpoint-trigger"); 227598944Sobrien mention (bs->breakpoint_at); 2276130803Smarcel ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 227798944Sobrien ui_out_text (uiout, "\nOld value = "); 227898944Sobrien value_print (bs->old_val, stb->stream, 0, Val_pretty_default); 227998944Sobrien ui_out_field_stream (uiout, "old", stb); 228098944Sobrien ui_out_text (uiout, "\nNew value = "); 228198944Sobrien value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default); 228298944Sobrien ui_out_field_stream (uiout, "new", stb); 2283130803Smarcel do_cleanups (ui_out_chain); 228498944Sobrien ui_out_text (uiout, "\n"); 228598944Sobrien value_free (bs->old_val); 228698944Sobrien bs->old_val = NULL; 228798944Sobrien } 228898944Sobrien /* More than one watchpoint may have been triggered. */ 228998944Sobrien return PRINT_UNKNOWN; 229098944Sobrien break; 229198944Sobrien 229298944Sobrien case bp_read_watchpoint: 229398944Sobrien if (ui_out_is_mi_like_p (uiout)) 229498944Sobrien ui_out_field_string (uiout, "reason", "read-watchpoint-trigger"); 229519370Spst mention (bs->breakpoint_at); 2296130803Smarcel ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 229798944Sobrien ui_out_text (uiout, "\nValue = "); 229898944Sobrien value_print (bs->breakpoint_at->val, stb->stream, 0, Val_pretty_default); 229998944Sobrien ui_out_field_stream (uiout, "value", stb); 2300130803Smarcel do_cleanups (ui_out_chain); 230198944Sobrien ui_out_text (uiout, "\n"); 230298944Sobrien return PRINT_UNKNOWN; 230398944Sobrien break; 230498944Sobrien 230598944Sobrien case bp_access_watchpoint: 230698944Sobrien if (bs->old_val != NULL) 230798944Sobrien { 230898944Sobrien annotate_watchpoint (bs->breakpoint_at->number); 230998944Sobrien if (ui_out_is_mi_like_p (uiout)) 231098944Sobrien ui_out_field_string (uiout, "reason", "access-watchpoint-trigger"); 231198944Sobrien mention (bs->breakpoint_at); 2312130803Smarcel ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 231398944Sobrien ui_out_text (uiout, "\nOld value = "); 231498944Sobrien value_print (bs->old_val, stb->stream, 0, Val_pretty_default); 231598944Sobrien ui_out_field_stream (uiout, "old", stb); 231698944Sobrien value_free (bs->old_val); 231798944Sobrien bs->old_val = NULL; 231898944Sobrien ui_out_text (uiout, "\nNew value = "); 231998944Sobrien } 232098944Sobrien else 232198944Sobrien { 232298944Sobrien mention (bs->breakpoint_at); 232398944Sobrien if (ui_out_is_mi_like_p (uiout)) 232498944Sobrien ui_out_field_string (uiout, "reason", "access-watchpoint-trigger"); 2325130803Smarcel ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 232698944Sobrien ui_out_text (uiout, "\nValue = "); 232798944Sobrien } 232898944Sobrien value_print (bs->breakpoint_at->val, stb->stream, 0,Val_pretty_default); 232998944Sobrien ui_out_field_stream (uiout, "new", stb); 2330130803Smarcel do_cleanups (ui_out_chain); 233198944Sobrien ui_out_text (uiout, "\n"); 233298944Sobrien return PRINT_UNKNOWN; 233398944Sobrien break; 233498944Sobrien 233598944Sobrien /* Fall through, we don't deal with these types of breakpoints 233698944Sobrien here. */ 233798944Sobrien 233898944Sobrien case bp_finish: 233998944Sobrien if (ui_out_is_mi_like_p (uiout)) 234098944Sobrien ui_out_field_string (uiout, "reason", "function-finished"); 234198944Sobrien return PRINT_UNKNOWN; 234298944Sobrien break; 234398944Sobrien 234498944Sobrien case bp_until: 234598944Sobrien if (ui_out_is_mi_like_p (uiout)) 234698944Sobrien ui_out_field_string (uiout, "reason", "location-reached"); 234798944Sobrien return PRINT_UNKNOWN; 234898944Sobrien break; 234998944Sobrien 235098944Sobrien case bp_none: 235198944Sobrien case bp_longjmp: 235298944Sobrien case bp_longjmp_resume: 235398944Sobrien case bp_step_resume: 235498944Sobrien case bp_through_sigtramp: 235598944Sobrien case bp_watchpoint_scope: 235698944Sobrien case bp_call_dummy: 235798944Sobrien default: 235898944Sobrien return PRINT_UNKNOWN; 235919370Spst } 236098944Sobrien} 236198944Sobrien 236298944Sobrien/* Generic routine for printing messages indicating why we 236398944Sobrien stopped. The behavior of this function depends on the value 236498944Sobrien 'print_it' in the bpstat structure. Under some circumstances we 236598944Sobrien may decide not to print anything here and delegate the task to 236698944Sobrien normal_stop(). */ 236798944Sobrien 236898944Sobrienstatic enum print_stop_action 236998944Sobrienprint_bp_stop_message (bpstat bs) 237098944Sobrien{ 237198944Sobrien switch (bs->print_it) 237219370Spst { 237398944Sobrien case print_it_noop: 237498944Sobrien /* Nothing should be printed for this bpstat entry. */ 237598944Sobrien return PRINT_UNKNOWN; 237698944Sobrien break; 237798944Sobrien 237898944Sobrien case print_it_done: 237998944Sobrien /* We still want to print the frame, but we already printed the 238098944Sobrien relevant messages. */ 238198944Sobrien return PRINT_SRC_AND_LOC; 238298944Sobrien break; 238398944Sobrien 238498944Sobrien case print_it_normal: 2385130803Smarcel /* Normal case. Call the breakpoint's print_it method, or 2386130803Smarcel print_it_typical. */ 2387130803Smarcel if (bs->breakpoint_at != NULL && bs->breakpoint_at->ops != NULL 2388130803Smarcel && bs->breakpoint_at->ops->print_it != NULL) 2389130803Smarcel return bs->breakpoint_at->ops->print_it (bs->breakpoint_at); 2390130803Smarcel else 2391130803Smarcel return print_it_typical (bs); 239298944Sobrien break; 2393130803Smarcel 239498944Sobrien default: 239598944Sobrien internal_error (__FILE__, __LINE__, 239698944Sobrien "print_bp_stop_message: unrecognized enum value"); 239798944Sobrien break; 239819370Spst } 239919370Spst} 240019370Spst 240198944Sobrien/* Print a message indicating what happened. This is called from 240298944Sobrien normal_stop(). The input to this routine is the head of the bpstat 240398944Sobrien list - a list of the eventpoints that caused this stop. This 240498944Sobrien routine calls the generic print routine for printing a message 240598944Sobrien about reasons for stopping. This will print (for example) the 240698944Sobrien "Breakpoint n," part of the output. The return value of this 240798944Sobrien routine is one of: 240846283Sdfr 240998944Sobrien PRINT_UNKNOWN: Means we printed nothing 241098944Sobrien PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent 241198944Sobrien code to print the location. An example is 241298944Sobrien "Breakpoint 1, " which should be followed by 241398944Sobrien the location. 241498944Sobrien PRINT_SRC_ONLY: Means we printed something, but there is no need 241598944Sobrien to also print the location part of the message. 241698944Sobrien An example is the catch/throw messages, which 241798944Sobrien don't require a location appended to the end. 241898944Sobrien PRINT_NOTHING: We have done some printing and we don't need any 241998944Sobrien further info to be printed.*/ 242046283Sdfr 242198944Sobrienenum print_stop_action 242298944Sobrienbpstat_print (bpstat bs) 242319370Spst{ 242419370Spst int val; 242519370Spst 242619370Spst /* Maybe another breakpoint in the chain caused us to stop. 242798944Sobrien (Currently all watchpoints go on the bpstat whether hit or not. 242898944Sobrien That probably could (should) be changed, provided care is taken 242919370Spst with respect to bpstat_explains_signal). */ 243098944Sobrien for (; bs; bs = bs->next) 243198944Sobrien { 243298944Sobrien val = print_bp_stop_message (bs); 243398944Sobrien if (val == PRINT_SRC_ONLY 243498944Sobrien || val == PRINT_SRC_AND_LOC 243598944Sobrien || val == PRINT_NOTHING) 243698944Sobrien return val; 243798944Sobrien } 243819370Spst 243998944Sobrien /* We reached the end of the chain, or we got a null BS to start 244098944Sobrien with and nothing was printed. */ 244198944Sobrien return PRINT_UNKNOWN; 244219370Spst} 244319370Spst 244419370Spst/* Evaluate the expression EXP and return 1 if value is zero. 244519370Spst This is used inside a catch_errors to evaluate the breakpoint condition. 244619370Spst The argument is a "struct expression *" that has been cast to char * to 244719370Spst make it pass through catch_errors. */ 244819370Spst 244919370Spststatic int 2450130803Smarcelbreakpoint_cond_eval (void *exp) 245119370Spst{ 245298944Sobrien struct value *mark = value_mark (); 245398944Sobrien int i = !value_true (evaluate_expression ((struct expression *) exp)); 245419370Spst value_free_to_mark (mark); 245519370Spst return i; 245619370Spst} 245719370Spst 245819370Spst/* Allocate a new bpstat and chain it to the current one. */ 245919370Spst 246019370Spststatic bpstat 246198944Sobrienbpstat_alloc (struct breakpoint *b, bpstat cbs /* Current "bs" value */ ) 246219370Spst{ 246319370Spst bpstat bs; 246419370Spst 246519370Spst bs = (bpstat) xmalloc (sizeof (*bs)); 246619370Spst cbs->next = bs; 246719370Spst bs->breakpoint_at = b; 246819370Spst /* If the condition is false, etc., don't do the commands. */ 246919370Spst bs->commands = NULL; 247019370Spst bs->old_val = NULL; 247119370Spst bs->print_it = print_it_normal; 247219370Spst return bs; 247319370Spst} 247419370Spst 247519370Spst/* Possible return values for watchpoint_check (this can't be an enum 247619370Spst because of check_errors). */ 247719370Spst/* The watchpoint has been deleted. */ 247819370Spst#define WP_DELETED 1 247919370Spst/* The value has changed. */ 248019370Spst#define WP_VALUE_CHANGED 2 248119370Spst/* The value has not changed. */ 248219370Spst#define WP_VALUE_NOT_CHANGED 3 248319370Spst 248419370Spst#define BP_TEMPFLAG 1 248519370Spst#define BP_HARDWAREFLAG 2 248619370Spst 248719370Spst/* Check watchpoint condition. */ 248819370Spst 248919370Spststatic int 2490130803Smarcelwatchpoint_check (void *p) 249119370Spst{ 249219370Spst bpstat bs = (bpstat) p; 249319370Spst struct breakpoint *b; 249419370Spst struct frame_info *fr; 249519370Spst int within_current_scope; 249619370Spst 249719370Spst b = bs->breakpoint_at; 249819370Spst 249919370Spst if (b->exp_valid_block == NULL) 250019370Spst within_current_scope = 1; 250119370Spst else 250219370Spst { 250319370Spst /* There is no current frame at this moment. If we're going to have 250498944Sobrien any chance of handling watchpoints on local variables, we'll need 250598944Sobrien the frame chain (so we can determine if we're in scope). */ 250698944Sobrien reinit_frame_cache (); 2507130803Smarcel fr = frame_find_by_id (b->watchpoint_frame); 250819370Spst within_current_scope = (fr != NULL); 250998944Sobrien /* in_function_epilogue_p() returns a non-zero value if we're still 251098944Sobrien in the function but the stack frame has already been invalidated. 251198944Sobrien Since we can't rely on the values of local variables after the 251298944Sobrien stack has been destroyed, we are treating the watchpoint in that 2513130803Smarcel state as `not changed' without further checking. 2514130803Smarcel 2515130803Smarcel vinschen/2003-09-04: The former implementation left out the case 2516130803Smarcel that the watchpoint frame couldn't be found by frame_find_by_id() 2517130803Smarcel because the current PC is currently in an epilogue. Calling 2518130803Smarcel gdbarch_in_function_epilogue_p() also when fr == NULL fixes that. */ 2519130803Smarcel if ((!within_current_scope || fr == get_current_frame ()) 252098944Sobrien && gdbarch_in_function_epilogue_p (current_gdbarch, read_pc ())) 252198944Sobrien return WP_VALUE_NOT_CHANGED; 2522130803Smarcel if (fr && within_current_scope) 252319370Spst /* If we end up stopping, the current frame will get selected 252419370Spst in normal_stop. So this call to select_frame won't affect 252519370Spst the user. */ 2526130803Smarcel select_frame (fr); 252719370Spst } 252898944Sobrien 252919370Spst if (within_current_scope) 253019370Spst { 253119370Spst /* We use value_{,free_to_}mark because it could be a 253219370Spst *long* time before we return to the command level and 253398944Sobrien call free_all_values. We can't call free_all_values because 253498944Sobrien we might be in the middle of evaluating a function call. */ 253519370Spst 253698944Sobrien struct value *mark = value_mark (); 253798944Sobrien struct value *new_val = evaluate_expression (bs->breakpoint_at->exp); 253819370Spst if (!value_equal (b->val, new_val)) 253919370Spst { 254019370Spst release_value (new_val); 254119370Spst value_free_to_mark (mark); 254219370Spst bs->old_val = b->val; 254319370Spst b->val = new_val; 254419370Spst /* We will stop here */ 254519370Spst return WP_VALUE_CHANGED; 254619370Spst } 254719370Spst else 254819370Spst { 254919370Spst /* Nothing changed, don't do anything. */ 255019370Spst value_free_to_mark (mark); 255119370Spst /* We won't stop here */ 255219370Spst return WP_VALUE_NOT_CHANGED; 255319370Spst } 255419370Spst } 255519370Spst else 255619370Spst { 255719370Spst /* This seems like the only logical thing to do because 255898944Sobrien if we temporarily ignored the watchpoint, then when 255998944Sobrien we reenter the block in which it is valid it contains 256098944Sobrien garbage (in the case of a function, it may have two 256198944Sobrien garbage values, one before and one after the prologue). 256298944Sobrien So we can't even detect the first assignment to it and 256398944Sobrien watch after that (since the garbage may or may not equal 256498944Sobrien the first value assigned). */ 256598944Sobrien /* We print all the stop information in print_it_typical(), but 256698944Sobrien in this case, by the time we call print_it_typical() this bp 256798944Sobrien will be deleted already. So we have no choice but print the 256898944Sobrien information here. */ 256998944Sobrien if (ui_out_is_mi_like_p (uiout)) 257098944Sobrien ui_out_field_string (uiout, "reason", "watchpoint-scope"); 257198944Sobrien ui_out_text (uiout, "\nWatchpoint "); 257298944Sobrien ui_out_field_int (uiout, "wpnum", bs->breakpoint_at->number); 257398944Sobrien ui_out_text (uiout, " deleted because the program has left the block in\n\ 257498944Sobrienwhich its expression is valid.\n"); 257598944Sobrien 257619370Spst if (b->related_breakpoint) 257798944Sobrien b->related_breakpoint->disposition = disp_del_at_next_stop; 257898944Sobrien b->disposition = disp_del_at_next_stop; 257919370Spst 258019370Spst return WP_DELETED; 258119370Spst } 258219370Spst} 258319370Spst 2584130803Smarcel/* Get a bpstat associated with having just stopped at address 2585130803Smarcel BP_ADDR. */ 258619370Spst 258719370Spst/* Determine whether we stopped at a breakpoint, etc, or whether we 258819370Spst don't understand this stop. Result is a chain of bpstat's such that: 258919370Spst 259098944Sobrien if we don't understand the stop, the result is a null pointer. 259119370Spst 259298944Sobrien if we understand why we stopped, the result is not null. 259319370Spst 259498944Sobrien Each element of the chain refers to a particular breakpoint or 259598944Sobrien watchpoint at which we have stopped. (We may have stopped for 259698944Sobrien several reasons concurrently.) 259719370Spst 259898944Sobrien Each element of the chain has valid next, breakpoint_at, 259998944Sobrien commands, FIXME??? fields. */ 260019370Spst 260119370Spstbpstat 2602130803Smarcelbpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid) 260319370Spst{ 2604130803Smarcel struct breakpoint *b, *temp; 260519370Spst /* True if we've hit a breakpoint (as opposed to a watchpoint). */ 260619370Spst int real_breakpoint = 0; 260719370Spst /* Root of the chain of bpstat's */ 260819370Spst struct bpstats root_bs[1]; 260919370Spst /* Pointer to the last thing in the chain currently. */ 261019370Spst bpstat bs = root_bs; 2611130803Smarcel int thread_id = pid_to_thread_id (ptid); 261219370Spst 261319370Spst ALL_BREAKPOINTS_SAFE (b, temp) 261498944Sobrien { 2615130803Smarcel if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) 261698944Sobrien continue; 261719370Spst 261898944Sobrien if (b->type != bp_watchpoint 261998944Sobrien && b->type != bp_hardware_watchpoint 262098944Sobrien && b->type != bp_read_watchpoint 262198944Sobrien && b->type != bp_access_watchpoint 262298944Sobrien && b->type != bp_hardware_breakpoint 262398944Sobrien && b->type != bp_catch_fork 262498944Sobrien && b->type != bp_catch_vfork 262598944Sobrien && b->type != bp_catch_exec 262698944Sobrien && b->type != bp_catch_catch 262798944Sobrien && b->type != bp_catch_throw) /* a non-watchpoint bp */ 262898944Sobrien { 2629130803Smarcel if (b->loc->address != bp_addr) /* address doesn't match */ 263046283Sdfr continue; 263198944Sobrien if (overlay_debugging /* unmapped overlay section */ 2632130803Smarcel && section_is_overlay (b->loc->section) 2633130803Smarcel && !section_is_mapped (b->loc->section)) 263498944Sobrien continue; 263598944Sobrien } 263619370Spst 2637130803Smarcel if (b->type == bp_hardware_breakpoint) 2638130803Smarcel { 2639130803Smarcel if (b->loc->address != bp_addr) 2640130803Smarcel continue; 2641130803Smarcel if (overlay_debugging /* unmapped overlay section */ 2642130803Smarcel && section_is_overlay (b->loc->section) 2643130803Smarcel && !section_is_mapped (b->loc->section)) 2644130803Smarcel continue; 2645130803Smarcel } 264619370Spst 264798944Sobrien /* Is this a catchpoint of a load or unload? If so, did we 264898944Sobrien get a load or unload of the specified library? If not, 264998944Sobrien ignore it. */ 265098944Sobrien if ((b->type == bp_catch_load) 265146283Sdfr#if defined(SOLIB_HAVE_LOAD_EVENT) 265298944Sobrien && (!SOLIB_HAVE_LOAD_EVENT (PIDGET (inferior_ptid)) 265398944Sobrien || ((b->dll_pathname != NULL) 265498944Sobrien && (strcmp (b->dll_pathname, 265598944Sobrien SOLIB_LOADED_LIBRARY_PATHNAME ( 265698944Sobrien PIDGET (inferior_ptid))) 265798944Sobrien != 0))) 265846283Sdfr#endif 265998944Sobrien ) 266098944Sobrien continue; 266198944Sobrien 266298944Sobrien if ((b->type == bp_catch_unload) 266346283Sdfr#if defined(SOLIB_HAVE_UNLOAD_EVENT) 266498944Sobrien && (!SOLIB_HAVE_UNLOAD_EVENT (PIDGET (inferior_ptid)) 266598944Sobrien || ((b->dll_pathname != NULL) 266698944Sobrien && (strcmp (b->dll_pathname, 266798944Sobrien SOLIB_UNLOADED_LIBRARY_PATHNAME ( 266898944Sobrien PIDGET (inferior_ptid))) 266998944Sobrien != 0))) 267046283Sdfr#endif 267198944Sobrien ) 267298944Sobrien continue; 267346283Sdfr 267498944Sobrien if ((b->type == bp_catch_fork) 2675130803Smarcel && !inferior_has_forked (PIDGET (inferior_ptid), 2676130803Smarcel &b->forked_inferior_pid)) 267798944Sobrien continue; 267846283Sdfr 267998944Sobrien if ((b->type == bp_catch_vfork) 2680130803Smarcel && !inferior_has_vforked (PIDGET (inferior_ptid), 2681130803Smarcel &b->forked_inferior_pid)) 268298944Sobrien continue; 268319370Spst 268498944Sobrien if ((b->type == bp_catch_exec) 2685130803Smarcel && !inferior_has_execd (PIDGET (inferior_ptid), &b->exec_pathname)) 268698944Sobrien continue; 268719370Spst 268898944Sobrien if (ep_is_exception_catchpoint (b) && 268998944Sobrien !(current_exception_event = target_get_current_exception_event ())) 269098944Sobrien continue; 269119370Spst 269298944Sobrien /* Come here if it's a watchpoint, or if the break address matches */ 269398944Sobrien 269498944Sobrien bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ 269598944Sobrien 269698944Sobrien /* Watchpoints may change this, if not found to have triggered. */ 269798944Sobrien bs->stop = 1; 269898944Sobrien bs->print = 1; 269998944Sobrien 270098944Sobrien if (b->type == bp_watchpoint || 270198944Sobrien b->type == bp_hardware_watchpoint) 270298944Sobrien { 2703130803Smarcel char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", 2704130803Smarcel b->number); 2705130803Smarcel struct cleanup *cleanups = make_cleanup (xfree, message); 2706130803Smarcel int e = catch_errors (watchpoint_check, bs, message, 2707130803Smarcel RETURN_MASK_ALL); 2708130803Smarcel do_cleanups (cleanups); 2709130803Smarcel switch (e) 271098944Sobrien { 271198944Sobrien case WP_DELETED: 271298944Sobrien /* We've already printed what needs to be printed. */ 271398944Sobrien /* Actually this is superfluous, because by the time we 271498944Sobrien call print_it_typical() the wp will be already deleted, 271598944Sobrien and the function will return immediately. */ 271698944Sobrien bs->print_it = print_it_done; 271798944Sobrien /* Stop. */ 271898944Sobrien break; 271998944Sobrien case WP_VALUE_CHANGED: 272098944Sobrien /* Stop. */ 272198944Sobrien ++(b->hit_count); 272298944Sobrien break; 272398944Sobrien case WP_VALUE_NOT_CHANGED: 272498944Sobrien /* Don't stop. */ 272598944Sobrien bs->print_it = print_it_noop; 272698944Sobrien bs->stop = 0; 272798944Sobrien continue; 272898944Sobrien default: 272998944Sobrien /* Can't happen. */ 273098944Sobrien /* FALLTHROUGH */ 273198944Sobrien case 0: 273298944Sobrien /* Error from catch_errors. */ 273398944Sobrien printf_filtered ("Watchpoint %d deleted.\n", b->number); 273498944Sobrien if (b->related_breakpoint) 273598944Sobrien b->related_breakpoint->disposition = disp_del_at_next_stop; 273698944Sobrien b->disposition = disp_del_at_next_stop; 273798944Sobrien /* We've already printed what needs to be printed. */ 273898944Sobrien bs->print_it = print_it_done; 273998944Sobrien 274098944Sobrien /* Stop. */ 274198944Sobrien break; 274298944Sobrien } 274398944Sobrien } 274498944Sobrien else if (b->type == bp_read_watchpoint || 274598944Sobrien b->type == bp_access_watchpoint) 274698944Sobrien { 274798944Sobrien CORE_ADDR addr; 274898944Sobrien struct value *v; 274998944Sobrien int found = 0; 275098944Sobrien 275198944Sobrien addr = target_stopped_data_address (); 275298944Sobrien if (addr == 0) 275398944Sobrien continue; 275498944Sobrien for (v = b->val_chain; v; v = v->next) 275598944Sobrien { 275698944Sobrien if (VALUE_LVAL (v) == lval_memory 275798944Sobrien && ! VALUE_LAZY (v)) 275898944Sobrien { 275998944Sobrien struct type *vtype = check_typedef (VALUE_TYPE (v)); 276098944Sobrien 276198944Sobrien if (v == b->val_chain 276298944Sobrien || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT 276398944Sobrien && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) 276498944Sobrien { 276598944Sobrien CORE_ADDR vaddr; 276698944Sobrien 276798944Sobrien vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); 276898944Sobrien /* Exact match not required. Within range is 276998944Sobrien sufficient. */ 277098944Sobrien if (addr >= vaddr && 277198944Sobrien addr < vaddr + TYPE_LENGTH (VALUE_TYPE (v))) 277298944Sobrien found = 1; 277398944Sobrien } 277498944Sobrien } 277598944Sobrien } 277698944Sobrien if (found) 2777130803Smarcel { 2778130803Smarcel char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", 2779130803Smarcel b->number); 2780130803Smarcel struct cleanup *cleanups = make_cleanup (xfree, message); 2781130803Smarcel int e = catch_errors (watchpoint_check, bs, message, 2782130803Smarcel RETURN_MASK_ALL); 2783130803Smarcel do_cleanups (cleanups); 2784130803Smarcel switch (e) 2785130803Smarcel { 2786130803Smarcel case WP_DELETED: 2787130803Smarcel /* We've already printed what needs to be printed. */ 2788130803Smarcel bs->print_it = print_it_done; 2789130803Smarcel /* Stop. */ 2790130803Smarcel break; 2791130803Smarcel case WP_VALUE_CHANGED: 2792130803Smarcel if (b->type == bp_read_watchpoint) 2793130803Smarcel { 2794130803Smarcel /* Don't stop: read watchpoints shouldn't fire if 2795130803Smarcel the value has changed. This is for targets 2796130803Smarcel which cannot set read-only watchpoints. */ 2797130803Smarcel bs->print_it = print_it_noop; 2798130803Smarcel bs->stop = 0; 2799130803Smarcel continue; 2800130803Smarcel } 2801130803Smarcel ++(b->hit_count); 2802130803Smarcel break; 2803130803Smarcel case WP_VALUE_NOT_CHANGED: 2804130803Smarcel /* Stop. */ 2805130803Smarcel ++(b->hit_count); 2806130803Smarcel break; 2807130803Smarcel default: 2808130803Smarcel /* Can't happen. */ 2809130803Smarcel case 0: 2810130803Smarcel /* Error from catch_errors. */ 2811130803Smarcel printf_filtered ("Watchpoint %d deleted.\n", b->number); 2812130803Smarcel if (b->related_breakpoint) 2813130803Smarcel b->related_breakpoint->disposition = disp_del_at_next_stop; 2814130803Smarcel b->disposition = disp_del_at_next_stop; 2815130803Smarcel /* We've already printed what needs to be printed. */ 2816130803Smarcel bs->print_it = print_it_done; 2817130803Smarcel break; 2818130803Smarcel } 2819130803Smarcel } 282098944Sobrien else /* found == 0 */ 282198944Sobrien { 282298944Sobrien /* This is a case where some watchpoint(s) triggered, 282398944Sobrien but not at the address of this watchpoint (FOUND 282498944Sobrien was left zero). So don't print anything for this 282598944Sobrien watchpoint. */ 282698944Sobrien bs->print_it = print_it_noop; 282798944Sobrien bs->stop = 0; 282898944Sobrien continue; 282998944Sobrien } 283098944Sobrien } 283198944Sobrien else 283298944Sobrien { 283398944Sobrien /* By definition, an encountered breakpoint is a triggered 283498944Sobrien breakpoint. */ 283598944Sobrien ++(b->hit_count); 283619370Spst 283798944Sobrien real_breakpoint = 1; 283898944Sobrien } 283919370Spst 2840130803Smarcel if (frame_id_p (b->frame_id) 2841130803Smarcel && !frame_id_eq (b->frame_id, get_frame_id (get_current_frame ()))) 284298944Sobrien bs->stop = 0; 284398944Sobrien else 284498944Sobrien { 284598944Sobrien int value_is_zero = 0; 284619370Spst 284798944Sobrien if (b->cond) 284898944Sobrien { 284998944Sobrien /* Need to select the frame, with all that implies 285098944Sobrien so that the conditions will have the right context. */ 2851130803Smarcel select_frame (get_current_frame ()); 285298944Sobrien value_is_zero 285398944Sobrien = catch_errors (breakpoint_cond_eval, (b->cond), 285498944Sobrien "Error in testing breakpoint condition:\n", 285598944Sobrien RETURN_MASK_ALL); 285698944Sobrien /* FIXME-someday, should give breakpoint # */ 285798944Sobrien free_all_values (); 285898944Sobrien } 285998944Sobrien if (b->cond && value_is_zero) 286098944Sobrien { 286198944Sobrien bs->stop = 0; 286298944Sobrien /* Don't consider this a hit. */ 286398944Sobrien --(b->hit_count); 286498944Sobrien } 2865130803Smarcel else if (b->thread != -1 && b->thread != thread_id) 2866130803Smarcel { 2867130803Smarcel bs->stop = 0; 2868130803Smarcel /* Don't consider this a hit. */ 2869130803Smarcel --(b->hit_count); 2870130803Smarcel } 287198944Sobrien else if (b->ignore_count > 0) 287298944Sobrien { 287398944Sobrien b->ignore_count--; 287498944Sobrien annotate_ignore_count_change (); 287598944Sobrien bs->stop = 0; 287698944Sobrien } 287798944Sobrien else 287898944Sobrien { 287998944Sobrien /* We will stop here */ 288098944Sobrien if (b->disposition == disp_disable) 288198944Sobrien b->enable_state = bp_disabled; 288298944Sobrien if (b->silent) 288398944Sobrien bs->print = 0; 2884130803Smarcel bs->commands = b->commands; 288598944Sobrien if (bs->commands && 2886130803Smarcel (strcmp ("silent", bs->commands->line) == 0 2887130803Smarcel || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) 288898944Sobrien { 288998944Sobrien bs->commands = bs->commands->next; 289019370Spst bs->print = 0; 289198944Sobrien } 2892130803Smarcel bs->commands = copy_command_lines (bs->commands); 289398944Sobrien } 289498944Sobrien } 289598944Sobrien /* Print nothing for this entry if we dont stop or if we dont print. */ 289698944Sobrien if (bs->stop == 0 || bs->print == 0) 289798944Sobrien bs->print_it = print_it_noop; 289898944Sobrien } 289919370Spst 290019370Spst bs->next = NULL; /* Terminate the chain */ 290119370Spst bs = root_bs->next; /* Re-grab the head of the chain */ 290246283Sdfr 290319370Spst /* The value of a hardware watchpoint hasn't changed, but the 290419370Spst intermediate memory locations we are watching may have. */ 290598944Sobrien if (bs && !bs->stop && 290619370Spst (bs->breakpoint_at->type == bp_hardware_watchpoint || 290719370Spst bs->breakpoint_at->type == bp_read_watchpoint || 290819370Spst bs->breakpoint_at->type == bp_access_watchpoint)) 290919370Spst { 291019370Spst remove_breakpoints (); 291119370Spst insert_breakpoints (); 291219370Spst } 291319370Spst return bs; 291419370Spst} 291519370Spst 291619370Spst/* Tell what to do about this bpstat. */ 291719370Spststruct bpstat_what 291898944Sobrienbpstat_what (bpstat bs) 291919370Spst{ 292019370Spst /* Classify each bpstat as one of the following. */ 292198944Sobrien enum class 292298944Sobrien { 292398944Sobrien /* This bpstat element has no effect on the main_action. */ 292498944Sobrien no_effect = 0, 292519370Spst 292698944Sobrien /* There was a watchpoint, stop but don't print. */ 292798944Sobrien wp_silent, 292819370Spst 292998944Sobrien /* There was a watchpoint, stop and print. */ 293098944Sobrien wp_noisy, 293119370Spst 293298944Sobrien /* There was a breakpoint but we're not stopping. */ 293398944Sobrien bp_nostop, 293419370Spst 293598944Sobrien /* There was a breakpoint, stop but don't print. */ 293698944Sobrien bp_silent, 293719370Spst 293898944Sobrien /* There was a breakpoint, stop and print. */ 293998944Sobrien bp_noisy, 294019370Spst 294198944Sobrien /* We hit the longjmp breakpoint. */ 294298944Sobrien long_jump, 294319370Spst 294498944Sobrien /* We hit the longjmp_resume breakpoint. */ 294598944Sobrien long_resume, 294619370Spst 294798944Sobrien /* We hit the step_resume breakpoint. */ 294898944Sobrien step_resume, 294919370Spst 295098944Sobrien /* We hit the through_sigtramp breakpoint. */ 295198944Sobrien through_sig, 295219370Spst 295398944Sobrien /* We hit the shared library event breakpoint. */ 295498944Sobrien shlib_event, 295519370Spst 295698944Sobrien /* We caught a shared library event. */ 295798944Sobrien catch_shlib_event, 295898944Sobrien 295998944Sobrien /* This is just used to count how many enums there are. */ 296098944Sobrien class_last 296119370Spst }; 296219370Spst 296319370Spst /* Here is the table which drives this routine. So that we can 296419370Spst format it pretty, we define some abbreviations for the 296519370Spst enum bpstat_what codes. */ 296619370Spst#define kc BPSTAT_WHAT_KEEP_CHECKING 296719370Spst#define ss BPSTAT_WHAT_STOP_SILENT 296819370Spst#define sn BPSTAT_WHAT_STOP_NOISY 296919370Spst#define sgl BPSTAT_WHAT_SINGLE 297019370Spst#define slr BPSTAT_WHAT_SET_LONGJMP_RESUME 297119370Spst#define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME 297219370Spst#define clrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE 297319370Spst#define sr BPSTAT_WHAT_STEP_RESUME 297419370Spst#define ts BPSTAT_WHAT_THROUGH_SIGTRAMP 297519370Spst#define shl BPSTAT_WHAT_CHECK_SHLIBS 297646283Sdfr#define shlr BPSTAT_WHAT_CHECK_SHLIBS_RESUME_FROM_HOOK 297719370Spst 297819370Spst/* "Can't happen." Might want to print an error message. 297919370Spst abort() is not out of the question, but chances are GDB is just 298019370Spst a bit confused, not unusable. */ 298119370Spst#define err BPSTAT_WHAT_STOP_NOISY 298219370Spst 298319370Spst /* Given an old action and a class, come up with a new action. */ 298419370Spst /* One interesting property of this table is that wp_silent is the same 298519370Spst as bp_silent and wp_noisy is the same as bp_noisy. That is because 298619370Spst after stopping, the check for whether to step over a breakpoint 298719370Spst (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without 298898944Sobrien reference to how we stopped. We retain separate wp_silent and 298998944Sobrien bp_silent codes in case we want to change that someday. 299019370Spst 299198944Sobrien Another possibly interesting property of this table is that 299298944Sobrien there's a partial ordering, priority-like, of the actions. Once 299398944Sobrien you've decided that some action is appropriate, you'll never go 299498944Sobrien back and decide something of a lower priority is better. The 299598944Sobrien ordering is: 299698944Sobrien 299798944Sobrien kc < clr sgl shl shlr slr sn sr ss ts 299898944Sobrien sgl < clrs shl shlr slr sn sr ss ts 299998944Sobrien slr < err shl shlr sn sr ss ts 300098944Sobrien clr < clrs err shl shlr sn sr ss ts 300198944Sobrien clrs < err shl shlr sn sr ss ts 300298944Sobrien ss < shl shlr sn sr ts 300398944Sobrien sn < shl shlr sr ts 300498944Sobrien sr < shl shlr ts 300598944Sobrien shl < shlr 300698944Sobrien ts < 300798944Sobrien shlr < 300898944Sobrien 300998944Sobrien What I think this means is that we don't need a damned table 301098944Sobrien here. If you just put the rows and columns in the right order, 301198944Sobrien it'd look awfully regular. We could simply walk the bpstat list 301298944Sobrien and choose the highest priority action we find, with a little 301398944Sobrien logic to handle the 'err' cases, and the CLEAR_LONGJMP_RESUME/ 301498944Sobrien CLEAR_LONGJMP_RESUME_SINGLE distinction (which breakpoint.h says 301598944Sobrien is messy anyway). */ 301698944Sobrien 301719370Spst /* step_resume entries: a step resume breakpoint overrides another 301819370Spst breakpoint of signal handling (see comment in wait_for_inferior 3019130803Smarcel at first PC_IN_SIGTRAMP where we set the step_resume breakpoint). */ 302019370Spst /* We handle the through_sigtramp_breakpoint the same way; having both 302119370Spst one of those and a step_resume_breakpoint is probably very rare (?). */ 302219370Spst 302319370Spst static const enum bpstat_what_main_action 302498944Sobrien table[(int) class_last][(int) BPSTAT_WHAT_LAST] = 302598944Sobrien { 302698944Sobrien /* old action */ 302798944Sobrien /* kc ss sn sgl slr clr clrs sr ts shl shlr 302898944Sobrien */ 302998944Sobrien/*no_effect */ 303098944Sobrien {kc, ss, sn, sgl, slr, clr, clrs, sr, ts, shl, shlr}, 303198944Sobrien/*wp_silent */ 303298944Sobrien {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr}, 303398944Sobrien/*wp_noisy */ 303498944Sobrien {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr}, 303598944Sobrien/*bp_nostop */ 303698944Sobrien {sgl, ss, sn, sgl, slr, clrs, clrs, sr, ts, shl, shlr}, 303798944Sobrien/*bp_silent */ 303898944Sobrien {ss, ss, sn, ss, ss, ss, ss, sr, ts, shl, shlr}, 303998944Sobrien/*bp_noisy */ 304098944Sobrien {sn, sn, sn, sn, sn, sn, sn, sr, ts, shl, shlr}, 304198944Sobrien/*long_jump */ 304298944Sobrien {slr, ss, sn, slr, slr, err, err, sr, ts, shl, shlr}, 304398944Sobrien/*long_resume */ 304498944Sobrien {clr, ss, sn, clrs, err, err, err, sr, ts, shl, shlr}, 304598944Sobrien/*step_resume */ 304698944Sobrien {sr, sr, sr, sr, sr, sr, sr, sr, ts, shl, shlr}, 304798944Sobrien/*through_sig */ 304898944Sobrien {ts, ts, ts, ts, ts, ts, ts, ts, ts, shl, shlr}, 304998944Sobrien/*shlib */ 305098944Sobrien {shl, shl, shl, shl, shl, shl, shl, shl, ts, shl, shlr}, 305198944Sobrien/*catch_shlib */ 305298944Sobrien {shlr, shlr, shlr, shlr, shlr, shlr, shlr, shlr, ts, shlr, shlr} 305398944Sobrien }; 305446283Sdfr 305519370Spst#undef kc 305619370Spst#undef ss 305719370Spst#undef sn 305819370Spst#undef sgl 305919370Spst#undef slr 306019370Spst#undef clr 306119370Spst#undef clrs 306219370Spst#undef err 306319370Spst#undef sr 306419370Spst#undef ts 306519370Spst#undef shl 306646283Sdfr#undef shlr 306719370Spst enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; 306819370Spst struct bpstat_what retval; 306919370Spst 307019370Spst retval.call_dummy = 0; 307119370Spst for (; bs != NULL; bs = bs->next) 307219370Spst { 307319370Spst enum class bs_class = no_effect; 307419370Spst if (bs->breakpoint_at == NULL) 307519370Spst /* I suspect this can happen if it was a momentary breakpoint 307619370Spst which has since been deleted. */ 307719370Spst continue; 307819370Spst switch (bs->breakpoint_at->type) 307919370Spst { 308046283Sdfr case bp_none: 308146283Sdfr continue; 308246283Sdfr 308319370Spst case bp_breakpoint: 308419370Spst case bp_hardware_breakpoint: 308519370Spst case bp_until: 308619370Spst case bp_finish: 308719370Spst if (bs->stop) 308819370Spst { 308919370Spst if (bs->print) 309019370Spst bs_class = bp_noisy; 309119370Spst else 309219370Spst bs_class = bp_silent; 309319370Spst } 309419370Spst else 309519370Spst bs_class = bp_nostop; 309619370Spst break; 309719370Spst case bp_watchpoint: 309819370Spst case bp_hardware_watchpoint: 309919370Spst case bp_read_watchpoint: 310019370Spst case bp_access_watchpoint: 310119370Spst if (bs->stop) 310219370Spst { 310319370Spst if (bs->print) 310419370Spst bs_class = wp_noisy; 310519370Spst else 310619370Spst bs_class = wp_silent; 310719370Spst } 310819370Spst else 310998944Sobrien /* There was a watchpoint, but we're not stopping. 311098944Sobrien This requires no further action. */ 311119370Spst bs_class = no_effect; 311219370Spst break; 311319370Spst case bp_longjmp: 311419370Spst bs_class = long_jump; 311519370Spst break; 311619370Spst case bp_longjmp_resume: 311719370Spst bs_class = long_resume; 311819370Spst break; 311919370Spst case bp_step_resume: 312019370Spst if (bs->stop) 312119370Spst { 312219370Spst bs_class = step_resume; 312319370Spst } 312419370Spst else 312519370Spst /* It is for the wrong frame. */ 312619370Spst bs_class = bp_nostop; 312719370Spst break; 312819370Spst case bp_through_sigtramp: 312919370Spst bs_class = through_sig; 313019370Spst break; 313119370Spst case bp_watchpoint_scope: 313219370Spst bs_class = bp_nostop; 313319370Spst break; 313419370Spst case bp_shlib_event: 313519370Spst bs_class = shlib_event; 313619370Spst break; 313798944Sobrien case bp_thread_event: 313898944Sobrien case bp_overlay_event: 313998944Sobrien bs_class = bp_nostop; 314098944Sobrien break; 314198944Sobrien case bp_catch_load: 314298944Sobrien case bp_catch_unload: 314398944Sobrien /* Only if this catchpoint triggered should we cause the 314498944Sobrien step-out-of-dld behaviour. Otherwise, we ignore this 314598944Sobrien catchpoint. */ 314698944Sobrien if (bs->stop) 314798944Sobrien bs_class = catch_shlib_event; 314898944Sobrien else 314998944Sobrien bs_class = no_effect; 315098944Sobrien break; 315198944Sobrien case bp_catch_fork: 315298944Sobrien case bp_catch_vfork: 315346283Sdfr case bp_catch_exec: 315498944Sobrien if (bs->stop) 315598944Sobrien { 315698944Sobrien if (bs->print) 315798944Sobrien bs_class = bp_noisy; 315898944Sobrien else 315998944Sobrien bs_class = bp_silent; 316098944Sobrien } 316198944Sobrien else 316298944Sobrien /* There was a catchpoint, but we're not stopping. 316398944Sobrien This requires no further action. */ 316498944Sobrien bs_class = no_effect; 316598944Sobrien break; 316698944Sobrien case bp_catch_catch: 316798944Sobrien if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_CATCH) 316898944Sobrien bs_class = bp_nostop; 316998944Sobrien else if (bs->stop) 317098944Sobrien bs_class = bs->print ? bp_noisy : bp_silent; 317198944Sobrien break; 317298944Sobrien case bp_catch_throw: 317398944Sobrien if (!bs->stop || CURRENT_EXCEPTION_KIND != EX_EVENT_THROW) 317498944Sobrien bs_class = bp_nostop; 317598944Sobrien else if (bs->stop) 317698944Sobrien bs_class = bs->print ? bp_noisy : bp_silent; 317798944Sobrien break; 317819370Spst case bp_call_dummy: 317998944Sobrien /* Make sure the action is stop (silent or noisy), 318098944Sobrien so infrun.c pops the dummy frame. */ 318119370Spst bs_class = bp_silent; 318219370Spst retval.call_dummy = 1; 318319370Spst break; 318419370Spst } 318598944Sobrien current_action = table[(int) bs_class][(int) current_action]; 318619370Spst } 318719370Spst retval.main_action = current_action; 318819370Spst return retval; 318919370Spst} 319019370Spst 319119370Spst/* Nonzero if we should step constantly (e.g. watchpoints on machines 319219370Spst without hardware support). This isn't related to a specific bpstat, 319319370Spst just to things like whether watchpoints are set. */ 319419370Spst 319598944Sobrienint 319698944Sobrienbpstat_should_step (void) 319719370Spst{ 319819370Spst struct breakpoint *b; 319919370Spst ALL_BREAKPOINTS (b) 3200130803Smarcel if (breakpoint_enabled (b) && b->type == bp_watchpoint) 320119370Spst return 1; 320219370Spst return 0; 320319370Spst} 320446283Sdfr 320546283Sdfr/* Nonzero if there are enabled hardware watchpoints. */ 320646283Sdfrint 320798944Sobrienbpstat_have_active_hw_watchpoints (void) 320846283Sdfr{ 3209130803Smarcel struct bp_location *bpt; 3210130803Smarcel ALL_BP_LOCATIONS (bpt) 3211130803Smarcel if (breakpoint_enabled (bpt->owner) 3212130803Smarcel && bpt->inserted 3213130803Smarcel && bpt->loc_type == bp_loc_hardware_watchpoint) 321446283Sdfr return 1; 321546283Sdfr return 0; 321646283Sdfr} 321798944Sobrien 321846283Sdfr 321946283Sdfr/* Given a bpstat that records zero or more triggered eventpoints, this 322046283Sdfr function returns another bpstat which contains only the catchpoints 322146283Sdfr on that first list, if any. */ 322246283Sdfrvoid 322398944Sobrienbpstat_get_triggered_catchpoints (bpstat ep_list, bpstat *cp_list) 322446283Sdfr{ 322598944Sobrien struct bpstats root_bs[1]; 322698944Sobrien bpstat bs = root_bs; 322798944Sobrien struct breakpoint *ep; 322898944Sobrien char *dll_pathname; 322998944Sobrien 323046283Sdfr bpstat_clear (cp_list); 323146283Sdfr root_bs->next = NULL; 323298944Sobrien 323398944Sobrien for (; ep_list != NULL; ep_list = ep_list->next) 323446283Sdfr { 323546283Sdfr /* Is this eventpoint a catchpoint? If not, ignore it. */ 323646283Sdfr ep = ep_list->breakpoint_at; 323746283Sdfr if (ep == NULL) 323898944Sobrien break; 323998944Sobrien if ((ep->type != bp_catch_load) && 324098944Sobrien (ep->type != bp_catch_unload) && 324198944Sobrien (ep->type != bp_catch_catch) && 324298944Sobrien (ep->type != bp_catch_throw)) 324398944Sobrien /* pai: (temp) ADD fork/vfork here!! */ 324498944Sobrien continue; 324598944Sobrien 324646283Sdfr /* Yes; add it to the list. */ 324746283Sdfr bs = bpstat_alloc (ep, bs); 324846283Sdfr *bs = *ep_list; 324946283Sdfr bs->next = NULL; 325046283Sdfr bs = root_bs->next; 325198944Sobrien 325246283Sdfr#if defined(SOLIB_ADD) 325346283Sdfr /* Also, for each triggered catchpoint, tag it with the name of 325446283Sdfr the library that caused this trigger. (We copy the name now, 325546283Sdfr because it's only guaranteed to be available NOW, when the 325646283Sdfr catchpoint triggers. Clients who may wish to know the name 325746283Sdfr later must get it from the catchpoint itself.) */ 325846283Sdfr if (ep->triggered_dll_pathname != NULL) 325998944Sobrien xfree (ep->triggered_dll_pathname); 326046283Sdfr if (ep->type == bp_catch_load) 326198944Sobrien dll_pathname = SOLIB_LOADED_LIBRARY_PATHNAME ( 326298944Sobrien PIDGET (inferior_ptid)); 326346283Sdfr else 326498944Sobrien dll_pathname = SOLIB_UNLOADED_LIBRARY_PATHNAME ( 326598944Sobrien PIDGET (inferior_ptid)); 326646283Sdfr#else 326746283Sdfr dll_pathname = NULL; 326846283Sdfr#endif 326946283Sdfr if (dll_pathname) 327046283Sdfr { 327198944Sobrien ep->triggered_dll_pathname = (char *) 327298944Sobrien xmalloc (strlen (dll_pathname) + 1); 327346283Sdfr strcpy (ep->triggered_dll_pathname, dll_pathname); 327446283Sdfr } 327546283Sdfr else 327646283Sdfr ep->triggered_dll_pathname = NULL; 327746283Sdfr } 327898944Sobrien 327946283Sdfr *cp_list = bs; 328046283Sdfr} 328146283Sdfr 328298944Sobrien/* Print B to gdb_stdout. */ 328319370Spststatic void 328498944Sobrienprint_one_breakpoint (struct breakpoint *b, 328598944Sobrien CORE_ADDR *last_addr) 328619370Spst{ 3287130803Smarcel struct command_line *l; 3288130803Smarcel struct symbol *sym; 328998944Sobrien struct ep_type_description 329098944Sobrien { 329198944Sobrien enum bptype type; 329298944Sobrien char *description; 329398944Sobrien }; 329498944Sobrien static struct ep_type_description bptypes[] = 329546283Sdfr { 329698944Sobrien {bp_none, "?deleted?"}, 329798944Sobrien {bp_breakpoint, "breakpoint"}, 329846283Sdfr {bp_hardware_breakpoint, "hw breakpoint"}, 329998944Sobrien {bp_until, "until"}, 330098944Sobrien {bp_finish, "finish"}, 330198944Sobrien {bp_watchpoint, "watchpoint"}, 330246283Sdfr {bp_hardware_watchpoint, "hw watchpoint"}, 330398944Sobrien {bp_read_watchpoint, "read watchpoint"}, 330498944Sobrien {bp_access_watchpoint, "acc watchpoint"}, 330598944Sobrien {bp_longjmp, "longjmp"}, 330698944Sobrien {bp_longjmp_resume, "longjmp resume"}, 330798944Sobrien {bp_step_resume, "step resume"}, 330898944Sobrien {bp_through_sigtramp, "sigtramp"}, 330998944Sobrien {bp_watchpoint_scope, "watchpoint scope"}, 331098944Sobrien {bp_call_dummy, "call dummy"}, 331198944Sobrien {bp_shlib_event, "shlib events"}, 331298944Sobrien {bp_thread_event, "thread events"}, 331398944Sobrien {bp_overlay_event, "overlay events"}, 331498944Sobrien {bp_catch_load, "catch load"}, 331598944Sobrien {bp_catch_unload, "catch unload"}, 331698944Sobrien {bp_catch_fork, "catch fork"}, 331798944Sobrien {bp_catch_vfork, "catch vfork"}, 331898944Sobrien {bp_catch_exec, "catch exec"}, 331998944Sobrien {bp_catch_catch, "catch catch"}, 332098944Sobrien {bp_catch_throw, "catch throw"} 332198944Sobrien }; 332298944Sobrien 332398944Sobrien static char *bpdisps[] = 332498944Sobrien {"del", "dstp", "dis", "keep"}; 332598944Sobrien static char bpenables[] = "nynny"; 332619370Spst char wrap_indent[80]; 332798944Sobrien struct ui_stream *stb = ui_out_stream_new (uiout); 332898944Sobrien struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); 3329130803Smarcel struct cleanup *bkpt_chain; 333019370Spst 333198944Sobrien annotate_record (); 3332130803Smarcel bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); 333319370Spst 333498944Sobrien /* 1 */ 333598944Sobrien annotate_field (0); 333698944Sobrien ui_out_field_int (uiout, "number", b->number); 333719370Spst 333898944Sobrien /* 2 */ 333998944Sobrien annotate_field (1); 334098944Sobrien if (((int) b->type > (sizeof (bptypes) / sizeof (bptypes[0]))) 334198944Sobrien || ((int) b->type != bptypes[(int) b->type].type)) 334298944Sobrien internal_error (__FILE__, __LINE__, 334398944Sobrien "bptypes table does not describe type #%d.", 334498944Sobrien (int) b->type); 334598944Sobrien ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); 334619370Spst 334798944Sobrien /* 3 */ 334898944Sobrien annotate_field (2); 334998944Sobrien ui_out_field_string (uiout, "disp", bpdisps[(int) b->disposition]); 335046283Sdfr 335198944Sobrien /* 4 */ 335298944Sobrien annotate_field (3); 335398944Sobrien ui_out_field_fmt (uiout, "enabled", "%c", bpenables[(int) b->enable_state]); 335498944Sobrien ui_out_spaces (uiout, 2); 335598944Sobrien 335698944Sobrien /* 5 and 6 */ 335798944Sobrien strcpy (wrap_indent, " "); 335898944Sobrien if (addressprint) 335998944Sobrien { 336098944Sobrien if (TARGET_ADDR_BIT <= 32) 336198944Sobrien strcat (wrap_indent, " "); 336298944Sobrien else 336398944Sobrien strcat (wrap_indent, " "); 336498944Sobrien } 336546283Sdfr 3366130803Smarcel if (b->ops != NULL && b->ops->print_one != NULL) 3367130803Smarcel b->ops->print_one (b, last_addr); 3368130803Smarcel else 3369130803Smarcel switch (b->type) 3370130803Smarcel { 3371130803Smarcel case bp_none: 3372130803Smarcel internal_error (__FILE__, __LINE__, 3373130803Smarcel "print_one_breakpoint: bp_none encountered\n"); 3374130803Smarcel break; 337519370Spst 3376130803Smarcel case bp_watchpoint: 3377130803Smarcel case bp_hardware_watchpoint: 3378130803Smarcel case bp_read_watchpoint: 3379130803Smarcel case bp_access_watchpoint: 3380130803Smarcel /* Field 4, the address, is omitted (which makes the columns 3381130803Smarcel not line up too nicely with the headers, but the effect 3382130803Smarcel is relatively readable). */ 3383130803Smarcel if (addressprint) 3384130803Smarcel ui_out_field_skip (uiout, "addr"); 3385130803Smarcel annotate_field (5); 3386130803Smarcel print_expression (b->exp, stb->stream); 3387130803Smarcel ui_out_field_stream (uiout, "what", stb); 3388130803Smarcel break; 338919370Spst 3390130803Smarcel case bp_catch_load: 3391130803Smarcel case bp_catch_unload: 3392130803Smarcel /* Field 4, the address, is omitted (which makes the columns 3393130803Smarcel not line up too nicely with the headers, but the effect 3394130803Smarcel is relatively readable). */ 3395130803Smarcel if (addressprint) 3396130803Smarcel ui_out_field_skip (uiout, "addr"); 3397130803Smarcel annotate_field (5); 3398130803Smarcel if (b->dll_pathname == NULL) 3399130803Smarcel { 3400130803Smarcel ui_out_field_string (uiout, "what", "<any library>"); 3401130803Smarcel ui_out_spaces (uiout, 1); 3402130803Smarcel } 3403130803Smarcel else 3404130803Smarcel { 3405130803Smarcel ui_out_text (uiout, "library \""); 3406130803Smarcel ui_out_field_string (uiout, "what", b->dll_pathname); 3407130803Smarcel ui_out_text (uiout, "\" "); 3408130803Smarcel } 3409130803Smarcel break; 3410130803Smarcel 3411130803Smarcel case bp_catch_fork: 3412130803Smarcel case bp_catch_vfork: 3413130803Smarcel /* Field 4, the address, is omitted (which makes the columns 3414130803Smarcel not line up too nicely with the headers, but the effect 3415130803Smarcel is relatively readable). */ 3416130803Smarcel if (addressprint) 3417130803Smarcel ui_out_field_skip (uiout, "addr"); 3418130803Smarcel annotate_field (5); 3419130803Smarcel if (b->forked_inferior_pid != 0) 3420130803Smarcel { 3421130803Smarcel ui_out_text (uiout, "process "); 3422130803Smarcel ui_out_field_int (uiout, "what", b->forked_inferior_pid); 3423130803Smarcel ui_out_spaces (uiout, 1); 3424130803Smarcel } 3425130803Smarcel 3426130803Smarcel case bp_catch_exec: 3427130803Smarcel /* Field 4, the address, is omitted (which makes the columns 3428130803Smarcel not line up too nicely with the headers, but the effect 3429130803Smarcel is relatively readable). */ 3430130803Smarcel if (addressprint) 3431130803Smarcel ui_out_field_skip (uiout, "addr"); 3432130803Smarcel annotate_field (5); 3433130803Smarcel if (b->exec_pathname != NULL) 3434130803Smarcel { 3435130803Smarcel ui_out_text (uiout, "program \""); 3436130803Smarcel ui_out_field_string (uiout, "what", b->exec_pathname); 3437130803Smarcel ui_out_text (uiout, "\" "); 3438130803Smarcel } 3439130803Smarcel break; 3440130803Smarcel 3441130803Smarcel case bp_catch_catch: 3442130803Smarcel /* Field 4, the address, is omitted (which makes the columns 3443130803Smarcel not line up too nicely with the headers, but the effect 3444130803Smarcel is relatively readable). */ 3445130803Smarcel if (addressprint) 3446130803Smarcel ui_out_field_skip (uiout, "addr"); 3447130803Smarcel annotate_field (5); 3448130803Smarcel ui_out_field_string (uiout, "what", "exception catch"); 3449130803Smarcel ui_out_spaces (uiout, 1); 3450130803Smarcel break; 3451130803Smarcel 3452130803Smarcel case bp_catch_throw: 3453130803Smarcel /* Field 4, the address, is omitted (which makes the columns 3454130803Smarcel not line up too nicely with the headers, but the effect 3455130803Smarcel is relatively readable). */ 3456130803Smarcel if (addressprint) 3457130803Smarcel ui_out_field_skip (uiout, "addr"); 3458130803Smarcel annotate_field (5); 3459130803Smarcel ui_out_field_string (uiout, "what", "exception throw"); 3460130803Smarcel ui_out_spaces (uiout, 1); 3461130803Smarcel break; 3462130803Smarcel 3463130803Smarcel case bp_breakpoint: 3464130803Smarcel case bp_hardware_breakpoint: 3465130803Smarcel case bp_until: 3466130803Smarcel case bp_finish: 3467130803Smarcel case bp_longjmp: 3468130803Smarcel case bp_longjmp_resume: 3469130803Smarcel case bp_step_resume: 3470130803Smarcel case bp_through_sigtramp: 3471130803Smarcel case bp_watchpoint_scope: 3472130803Smarcel case bp_call_dummy: 3473130803Smarcel case bp_shlib_event: 3474130803Smarcel case bp_thread_event: 3475130803Smarcel case bp_overlay_event: 3476130803Smarcel if (addressprint) 3477130803Smarcel { 3478130803Smarcel annotate_field (4); 3479130803Smarcel if (b->pending) 3480130803Smarcel ui_out_field_string (uiout, "addr", "<PENDING>"); 3481130803Smarcel else 3482130803Smarcel ui_out_field_core_addr (uiout, "addr", b->loc->address); 3483130803Smarcel } 3484130803Smarcel annotate_field (5); 3485130803Smarcel *last_addr = b->loc->address; 3486130803Smarcel if (b->source_file) 3487130803Smarcel { 3488130803Smarcel sym = find_pc_sect_function (b->loc->address, b->loc->section); 3489130803Smarcel if (sym) 3490130803Smarcel { 3491130803Smarcel ui_out_text (uiout, "in "); 3492130803Smarcel ui_out_field_string (uiout, "func", 3493130803Smarcel SYMBOL_PRINT_NAME (sym)); 3494130803Smarcel ui_out_wrap_hint (uiout, wrap_indent); 3495130803Smarcel ui_out_text (uiout, " at "); 3496130803Smarcel } 3497130803Smarcel ui_out_field_string (uiout, "file", b->source_file); 3498130803Smarcel ui_out_text (uiout, ":"); 3499130803Smarcel ui_out_field_int (uiout, "line", b->line_number); 3500130803Smarcel } 3501130803Smarcel else if (b->pending) 3502130803Smarcel { 3503130803Smarcel ui_out_field_string (uiout, "pending", b->addr_string); 3504130803Smarcel } 3505130803Smarcel else 3506130803Smarcel { 3507130803Smarcel print_address_symbolic (b->loc->address, stb->stream, demangle, ""); 3508130803Smarcel ui_out_field_stream (uiout, "at", stb); 3509130803Smarcel } 3510130803Smarcel break; 3511130803Smarcel } 3512130803Smarcel 351398944Sobrien if (b->thread != -1) 351498944Sobrien { 351598944Sobrien /* FIXME: This seems to be redundant and lost here; see the 351698944Sobrien "stop only in" line a little further down. */ 351798944Sobrien ui_out_text (uiout, " thread "); 351898944Sobrien ui_out_field_int (uiout, "thread", b->thread); 351998944Sobrien } 352098944Sobrien 352198944Sobrien ui_out_text (uiout, "\n"); 352298944Sobrien 3523130803Smarcel if (frame_id_p (b->frame_id)) 352498944Sobrien { 352598944Sobrien annotate_field (6); 352698944Sobrien ui_out_text (uiout, "\tstop only in stack frame at "); 3527130803Smarcel /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside 3528130803Smarcel the frame ID. */ 3529130803Smarcel ui_out_field_core_addr (uiout, "frame", b->frame_id.stack_addr); 353098944Sobrien ui_out_text (uiout, "\n"); 353198944Sobrien } 353298944Sobrien 353398944Sobrien if (b->cond) 353498944Sobrien { 353598944Sobrien annotate_field (7); 353698944Sobrien ui_out_text (uiout, "\tstop only if "); 353798944Sobrien print_expression (b->cond, stb->stream); 353898944Sobrien ui_out_field_stream (uiout, "cond", stb); 353998944Sobrien ui_out_text (uiout, "\n"); 354098944Sobrien } 3541130803Smarcel 3542130803Smarcel if (b->pending && b->cond_string) 3543130803Smarcel { 3544130803Smarcel annotate_field (7); 3545130803Smarcel ui_out_text (uiout, "\tstop only if "); 3546130803Smarcel ui_out_field_string (uiout, "cond", b->cond_string); 3547130803Smarcel ui_out_text (uiout, "\n"); 3548130803Smarcel } 3549130803Smarcel 355098944Sobrien if (b->thread != -1) 355198944Sobrien { 355298944Sobrien /* FIXME should make an annotation for this */ 355398944Sobrien ui_out_text (uiout, "\tstop only in thread "); 355498944Sobrien ui_out_field_int (uiout, "thread", b->thread); 355598944Sobrien ui_out_text (uiout, "\n"); 355698944Sobrien } 355798944Sobrien 355898944Sobrien if (show_breakpoint_hit_counts && b->hit_count) 355998944Sobrien { 356098944Sobrien /* FIXME should make an annotation for this */ 356198944Sobrien if (ep_is_catchpoint (b)) 356298944Sobrien ui_out_text (uiout, "\tcatchpoint"); 356398944Sobrien else 356498944Sobrien ui_out_text (uiout, "\tbreakpoint"); 356598944Sobrien ui_out_text (uiout, " already hit "); 356698944Sobrien ui_out_field_int (uiout, "times", b->hit_count); 356798944Sobrien if (b->hit_count == 1) 356898944Sobrien ui_out_text (uiout, " time\n"); 356998944Sobrien else 357098944Sobrien ui_out_text (uiout, " times\n"); 357198944Sobrien } 357298944Sobrien 357398944Sobrien /* Output the count also if it is zero, but only if this is 357498944Sobrien mi. FIXME: Should have a better test for this. */ 357598944Sobrien if (ui_out_is_mi_like_p (uiout)) 357698944Sobrien if (show_breakpoint_hit_counts && b->hit_count == 0) 357798944Sobrien ui_out_field_int (uiout, "times", b->hit_count); 357819370Spst 357998944Sobrien if (b->ignore_count) 358098944Sobrien { 358198944Sobrien annotate_field (8); 358298944Sobrien ui_out_text (uiout, "\tignore next "); 358398944Sobrien ui_out_field_int (uiout, "ignore", b->ignore_count); 358498944Sobrien ui_out_text (uiout, " hits\n"); 358598944Sobrien } 358698944Sobrien 358798944Sobrien if ((l = b->commands)) 358898944Sobrien { 3589130803Smarcel struct cleanup *script_chain; 3590130803Smarcel 359198944Sobrien annotate_field (9); 3592130803Smarcel script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); 359398944Sobrien print_command_lines (uiout, l, 4); 3594130803Smarcel do_cleanups (script_chain); 359598944Sobrien } 3596130803Smarcel do_cleanups (bkpt_chain); 359798944Sobrien do_cleanups (old_chain); 359898944Sobrien} 359946283Sdfr 360098944Sobrienstruct captured_breakpoint_query_args 360198944Sobrien { 360298944Sobrien int bnum; 360398944Sobrien }; 360419370Spst 360598944Sobrienstatic int 360698944Sobriendo_captured_breakpoint_query (struct ui_out *uiout, void *data) 360798944Sobrien{ 360898944Sobrien struct captured_breakpoint_query_args *args = data; 3609130803Smarcel struct breakpoint *b; 361098944Sobrien CORE_ADDR dummy_addr = 0; 361198944Sobrien ALL_BREAKPOINTS (b) 361298944Sobrien { 361398944Sobrien if (args->bnum == b->number) 361498944Sobrien { 361598944Sobrien print_one_breakpoint (b, &dummy_addr); 361698944Sobrien return GDB_RC_OK; 361798944Sobrien } 361898944Sobrien } 361998944Sobrien return GDB_RC_NONE; 362098944Sobrien} 362119370Spst 362298944Sobrienenum gdb_rc 362398944Sobriengdb_breakpoint_query (struct ui_out *uiout, int bnum) 362498944Sobrien{ 362598944Sobrien struct captured_breakpoint_query_args args; 362698944Sobrien args.bnum = bnum; 362798944Sobrien /* For the moment we don't trust print_one_breakpoint() to not throw 362898944Sobrien an error. */ 362998944Sobrien return catch_exceptions (uiout, do_captured_breakpoint_query, &args, 363098944Sobrien NULL, RETURN_MASK_ALL); 363198944Sobrien} 363219370Spst 363398944Sobrien/* Return non-zero if B is user settable (breakpoints, watchpoints, 363498944Sobrien catchpoints, et.al.). */ 363519370Spst 363698944Sobrienstatic int 363798944Sobrienuser_settable_breakpoint (const struct breakpoint *b) 363898944Sobrien{ 363998944Sobrien return (b->type == bp_breakpoint 364098944Sobrien || b->type == bp_catch_load 364198944Sobrien || b->type == bp_catch_unload 364298944Sobrien || b->type == bp_catch_fork 364398944Sobrien || b->type == bp_catch_vfork 364498944Sobrien || b->type == bp_catch_exec 364598944Sobrien || b->type == bp_catch_catch 364698944Sobrien || b->type == bp_catch_throw 364798944Sobrien || b->type == bp_hardware_breakpoint 364898944Sobrien || b->type == bp_watchpoint 364998944Sobrien || b->type == bp_read_watchpoint 365098944Sobrien || b->type == bp_access_watchpoint 365198944Sobrien || b->type == bp_hardware_watchpoint); 365298944Sobrien} 365398944Sobrien 365498944Sobrien/* Print information on user settable breakpoint (watchpoint, etc) 365598944Sobrien number BNUM. If BNUM is -1 print all user settable breakpoints. 365698944Sobrien If ALLFLAG is non-zero, include non- user settable breakpoints. */ 365719370Spst 365898944Sobrienstatic void 365998944Sobrienbreakpoint_1 (int bnum, int allflag) 366098944Sobrien{ 3661130803Smarcel struct breakpoint *b; 366298944Sobrien CORE_ADDR last_addr = (CORE_ADDR) -1; 366398944Sobrien int nr_printable_breakpoints; 3664130803Smarcel struct cleanup *bkpttbl_chain; 366598944Sobrien 366698944Sobrien /* Compute the number of rows in the table. */ 366798944Sobrien nr_printable_breakpoints = 0; 366898944Sobrien ALL_BREAKPOINTS (b) 366998944Sobrien if (bnum == -1 367098944Sobrien || bnum == b->number) 367198944Sobrien { 367298944Sobrien if (allflag || user_settable_breakpoint (b)) 367398944Sobrien nr_printable_breakpoints++; 367498944Sobrien } 367546283Sdfr 367698944Sobrien if (addressprint) 3677130803Smarcel bkpttbl_chain 3678130803Smarcel = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, 3679130803Smarcel "BreakpointTable"); 368098944Sobrien else 3681130803Smarcel bkpttbl_chain 3682130803Smarcel = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, 3683130803Smarcel "BreakpointTable"); 368419370Spst 368598944Sobrien if (nr_printable_breakpoints > 0) 368698944Sobrien annotate_breakpoints_headers (); 368798944Sobrien if (nr_printable_breakpoints > 0) 368898944Sobrien annotate_field (0); 368998944Sobrien ui_out_table_header (uiout, 3, ui_left, "number", "Num"); /* 1 */ 369098944Sobrien if (nr_printable_breakpoints > 0) 369198944Sobrien annotate_field (1); 369298944Sobrien ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ 369398944Sobrien if (nr_printable_breakpoints > 0) 369498944Sobrien annotate_field (2); 369598944Sobrien ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ 369698944Sobrien if (nr_printable_breakpoints > 0) 369798944Sobrien annotate_field (3); 369898944Sobrien ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ 369998944Sobrien if (addressprint) 370098944Sobrien { 370198944Sobrien if (nr_printable_breakpoints > 0) 370298944Sobrien annotate_field (4); 370398944Sobrien if (TARGET_ADDR_BIT <= 32) 370498944Sobrien ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ 370598944Sobrien else 370698944Sobrien ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ 370798944Sobrien } 370898944Sobrien if (nr_printable_breakpoints > 0) 370998944Sobrien annotate_field (5); 371098944Sobrien ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ 371198944Sobrien ui_out_table_body (uiout); 371298944Sobrien if (nr_printable_breakpoints > 0) 371398944Sobrien annotate_breakpoints_table (); 371419370Spst 371598944Sobrien ALL_BREAKPOINTS (b) 371698944Sobrien if (bnum == -1 371798944Sobrien || bnum == b->number) 371898944Sobrien { 371998944Sobrien /* We only print out user settable breakpoints unless the 372098944Sobrien allflag is set. */ 372198944Sobrien if (allflag || user_settable_breakpoint (b)) 372298944Sobrien print_one_breakpoint (b, &last_addr); 372319370Spst } 372498944Sobrien 3725130803Smarcel do_cleanups (bkpttbl_chain); 372619370Spst 372798944Sobrien if (nr_printable_breakpoints == 0) 372819370Spst { 372919370Spst if (bnum == -1) 373098944Sobrien ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); 373119370Spst else 373298944Sobrien ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", 373398944Sobrien bnum); 373419370Spst } 373519370Spst else 373698944Sobrien { 373798944Sobrien /* Compare against (CORE_ADDR)-1 in case some compiler decides 373898944Sobrien that a comparison of an unsigned with -1 is always false. */ 373998944Sobrien if (last_addr != (CORE_ADDR) -1) 374098944Sobrien set_next_address (last_addr); 374198944Sobrien } 374219370Spst 374398944Sobrien /* FIXME? Should this be moved up so that it is only called when 374498944Sobrien there have been breakpoints? */ 374519370Spst annotate_breakpoints_table_end (); 374619370Spst} 374719370Spst 374819370Spststatic void 374998944Sobrienbreakpoints_info (char *bnum_exp, int from_tty) 375019370Spst{ 375119370Spst int bnum = -1; 375219370Spst 375319370Spst if (bnum_exp) 375498944Sobrien bnum = parse_and_eval_long (bnum_exp); 375519370Spst 375619370Spst breakpoint_1 (bnum, 0); 375719370Spst} 375819370Spst 375998944Sobrienstatic void 376098944Sobrienmaintenance_info_breakpoints (char *bnum_exp, int from_tty) 376119370Spst{ 376219370Spst int bnum = -1; 376319370Spst 376419370Spst if (bnum_exp) 376598944Sobrien bnum = parse_and_eval_long (bnum_exp); 376619370Spst 376719370Spst breakpoint_1 (bnum, 1); 376819370Spst} 376919370Spst 377019370Spst/* Print a message describing any breakpoints set at PC. */ 377119370Spst 377219370Spststatic void 377398944Sobriendescribe_other_breakpoints (CORE_ADDR pc, asection *section) 377419370Spst{ 3775130803Smarcel int others = 0; 3776130803Smarcel struct breakpoint *b; 377719370Spst 377819370Spst ALL_BREAKPOINTS (b) 3779130803Smarcel if (b->loc->address == pc) /* address match / overlay match */ 3780130803Smarcel if (!b->pending && (!overlay_debugging || b->loc->section == section)) 378146283Sdfr others++; 378219370Spst if (others > 0) 378319370Spst { 378419370Spst printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : ""); 378519370Spst ALL_BREAKPOINTS (b) 3786130803Smarcel if (b->loc->address == pc) /* address match / overlay match */ 3787130803Smarcel if (!b->pending && (!overlay_debugging || b->loc->section == section)) 378846283Sdfr { 378946283Sdfr others--; 379098944Sobrien printf_filtered ("%d%s%s ", 379198944Sobrien b->number, 379298944Sobrien ((b->enable_state == bp_disabled || 379398944Sobrien b->enable_state == bp_shlib_disabled || 379498944Sobrien b->enable_state == bp_call_disabled) 379598944Sobrien ? " (disabled)" 379698944Sobrien : b->enable_state == bp_permanent 379798944Sobrien ? " (permanent)" 379898944Sobrien : ""), 379998944Sobrien (others > 1) ? "," 380098944Sobrien : ((others == 1) ? " and" : "")); 380146283Sdfr } 380219370Spst printf_filtered ("also set at pc "); 380319370Spst print_address_numeric (pc, 1, gdb_stdout); 380419370Spst printf_filtered (".\n"); 380519370Spst } 380619370Spst} 380719370Spst 380819370Spst/* Set the default place to put a breakpoint 380919370Spst for the `break' command with no arguments. */ 381019370Spst 381119370Spstvoid 381298944Sobrienset_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, 381398944Sobrien int line) 381419370Spst{ 381519370Spst default_breakpoint_valid = valid; 381619370Spst default_breakpoint_address = addr; 381719370Spst default_breakpoint_symtab = symtab; 381819370Spst default_breakpoint_line = line; 381919370Spst} 382019370Spst 382198944Sobrien/* Return true iff it is meaningful to use the address member of 382298944Sobrien BPT. For some breakpoint types, the address member is irrelevant 382398944Sobrien and it makes no sense to attempt to compare it to other addresses 382498944Sobrien (or use it for any other purpose either). 382598944Sobrien 382698944Sobrien More specifically, each of the following breakpoint types will always 382798944Sobrien have a zero valued address and we don't want check_duplicates() to mark 382898944Sobrien breakpoints of any of these types to be a duplicate of an actual 382998944Sobrien breakpoint at address zero: 383098944Sobrien 383198944Sobrien bp_watchpoint 383298944Sobrien bp_hardware_watchpoint 383398944Sobrien bp_read_watchpoint 383498944Sobrien bp_access_watchpoint 383598944Sobrien bp_catch_exec 383698944Sobrien bp_longjmp_resume 383798944Sobrien bp_catch_fork 383898944Sobrien bp_catch_vork */ 383998944Sobrien 384098944Sobrienstatic int 384198944Sobrienbreakpoint_address_is_meaningful (struct breakpoint *bpt) 384298944Sobrien{ 384398944Sobrien enum bptype type = bpt->type; 384498944Sobrien 384598944Sobrien return (type != bp_watchpoint 384698944Sobrien && type != bp_hardware_watchpoint 384798944Sobrien && type != bp_read_watchpoint 384898944Sobrien && type != bp_access_watchpoint 384998944Sobrien && type != bp_catch_exec 385098944Sobrien && type != bp_longjmp_resume 385198944Sobrien && type != bp_catch_fork 385298944Sobrien && type != bp_catch_vfork); 385398944Sobrien} 385498944Sobrien 385598944Sobrien/* Rescan breakpoints at the same address and section as BPT, 385619370Spst marking the first one as "first" and any others as "duplicates". 385798944Sobrien This is so that the bpt instruction is only inserted once. 385898944Sobrien If we have a permanent breakpoint at the same place as BPT, make 385998944Sobrien that one the official one, and the rest as duplicates. */ 386019370Spst 386119370Spststatic void 386298944Sobriencheck_duplicates (struct breakpoint *bpt) 386319370Spst{ 3864130803Smarcel struct bp_location *b; 3865130803Smarcel int count = 0; 3866130803Smarcel struct bp_location *perm_bp = 0; 3867130803Smarcel CORE_ADDR address = bpt->loc->address; 3868130803Smarcel asection *section = bpt->loc->section; 386919370Spst 387098944Sobrien if (! breakpoint_address_is_meaningful (bpt)) 387119370Spst return; 387219370Spst 3873130803Smarcel ALL_BP_LOCATIONS (b) 3874130803Smarcel if (b->owner->enable_state != bp_disabled 3875130803Smarcel && b->owner->enable_state != bp_shlib_disabled 3876130803Smarcel && !b->owner->pending 3877130803Smarcel && b->owner->enable_state != bp_call_disabled 387898944Sobrien && b->address == address /* address / overlay match */ 387998944Sobrien && (!overlay_debugging || b->section == section) 3880130803Smarcel && breakpoint_address_is_meaningful (b->owner)) 388198944Sobrien { 388298944Sobrien /* Have we found a permanent breakpoint? */ 3883130803Smarcel if (b->owner->enable_state == bp_permanent) 388498944Sobrien { 388598944Sobrien perm_bp = b; 388698944Sobrien break; 388798944Sobrien } 388898944Sobrien 388998944Sobrien count++; 389098944Sobrien b->duplicate = count > 1; 389198944Sobrien } 389298944Sobrien 389398944Sobrien /* If we found a permanent breakpoint at this address, go over the 389498944Sobrien list again and declare all the other breakpoints there to be the 389598944Sobrien duplicates. */ 389698944Sobrien if (perm_bp) 389798944Sobrien { 389898944Sobrien perm_bp->duplicate = 0; 389998944Sobrien 390098944Sobrien /* Permanent breakpoint should always be inserted. */ 390198944Sobrien if (! perm_bp->inserted) 390298944Sobrien internal_error (__FILE__, __LINE__, 390398944Sobrien "allegedly permanent breakpoint is not " 390498944Sobrien "actually inserted"); 390598944Sobrien 3906130803Smarcel ALL_BP_LOCATIONS (b) 390798944Sobrien if (b != perm_bp) 390898944Sobrien { 3909130803Smarcel if (b->owner->enable_state != bp_disabled 3910130803Smarcel && b->owner->enable_state != bp_shlib_disabled 3911130803Smarcel && !b->owner->pending 3912130803Smarcel && b->owner->enable_state != bp_call_disabled 391398944Sobrien && b->address == address /* address / overlay match */ 391498944Sobrien && (!overlay_debugging || b->section == section) 3915130803Smarcel && breakpoint_address_is_meaningful (b->owner)) 3916130803Smarcel { 3917130803Smarcel if (b->inserted) 3918130803Smarcel internal_error (__FILE__, __LINE__, 3919130803Smarcel "another breakpoint was inserted on top of " 3920130803Smarcel "a permanent breakpoint"); 3921130803Smarcel 3922130803Smarcel b->duplicate = 1; 3923130803Smarcel } 392498944Sobrien } 392598944Sobrien } 392619370Spst} 392719370Spst 3928130803Smarcelstatic void 3929130803Smarcelbreakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, 3930130803Smarcel int bnum, int have_bnum) 3931130803Smarcel{ 3932130803Smarcel char astr1[40]; 3933130803Smarcel char astr2[40]; 3934130803Smarcel 3935130803Smarcel strcpy (astr1, local_hex_string_custom ((unsigned long) from_addr, "08l")); 3936130803Smarcel strcpy (astr2, local_hex_string_custom ((unsigned long) to_addr, "08l")); 3937130803Smarcel if (have_bnum) 3938130803Smarcel warning ("Breakpoint %d address previously adjusted from %s to %s.", 3939130803Smarcel bnum, astr1, astr2); 3940130803Smarcel else 3941130803Smarcel warning ("Breakpoint address adjusted from %s to %s.", astr1, astr2); 3942130803Smarcel} 3943130803Smarcel 3944130803Smarcel/* Adjust a breakpoint's address to account for architectural constraints 3945130803Smarcel on breakpoint placement. Return the adjusted address. Note: Very 3946130803Smarcel few targets require this kind of adjustment. For most targets, 3947130803Smarcel this function is simply the identity function. */ 3948130803Smarcel 3949130803Smarcelstatic CORE_ADDR 3950130803Smarceladjust_breakpoint_address (CORE_ADDR bpaddr) 3951130803Smarcel{ 3952130803Smarcel if (!gdbarch_adjust_breakpoint_address_p (current_gdbarch)) 3953130803Smarcel { 3954130803Smarcel /* Very few targets need any kind of breakpoint adjustment. */ 3955130803Smarcel return bpaddr; 3956130803Smarcel } 3957130803Smarcel else 3958130803Smarcel { 3959130803Smarcel CORE_ADDR adjusted_bpaddr; 3960130803Smarcel 3961130803Smarcel /* Some targets have architectural constraints on the placement 3962130803Smarcel of breakpoint instructions. Obtain the adjusted address. */ 3963130803Smarcel adjusted_bpaddr = gdbarch_adjust_breakpoint_address (current_gdbarch, 3964130803Smarcel bpaddr); 3965130803Smarcel 3966130803Smarcel /* An adjusted breakpoint address can significantly alter 3967130803Smarcel a user's expectations. Print a warning if an adjustment 3968130803Smarcel is required. */ 3969130803Smarcel if (adjusted_bpaddr != bpaddr) 3970130803Smarcel breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); 3971130803Smarcel 3972130803Smarcel return adjusted_bpaddr; 3973130803Smarcel } 3974130803Smarcel} 3975130803Smarcel 3976130803Smarcel/* Allocate a struct bp_location. */ 3977130803Smarcel 3978130803Smarcelstatic struct bp_location * 3979130803Smarcelallocate_bp_location (struct breakpoint *bpt, enum bptype bp_type) 3980130803Smarcel{ 3981130803Smarcel struct bp_location *loc, *loc_p; 3982130803Smarcel 3983130803Smarcel loc = xmalloc (sizeof (struct bp_location)); 3984130803Smarcel memset (loc, 0, sizeof (*loc)); 3985130803Smarcel 3986130803Smarcel loc->owner = bpt; 3987130803Smarcel 3988130803Smarcel switch (bp_type) 3989130803Smarcel { 3990130803Smarcel case bp_breakpoint: 3991130803Smarcel case bp_until: 3992130803Smarcel case bp_finish: 3993130803Smarcel case bp_longjmp: 3994130803Smarcel case bp_longjmp_resume: 3995130803Smarcel case bp_step_resume: 3996130803Smarcel case bp_through_sigtramp: 3997130803Smarcel case bp_watchpoint_scope: 3998130803Smarcel case bp_call_dummy: 3999130803Smarcel case bp_shlib_event: 4000130803Smarcel case bp_thread_event: 4001130803Smarcel case bp_overlay_event: 4002130803Smarcel case bp_catch_load: 4003130803Smarcel case bp_catch_unload: 4004130803Smarcel loc->loc_type = bp_loc_software_breakpoint; 4005130803Smarcel break; 4006130803Smarcel case bp_hardware_breakpoint: 4007130803Smarcel loc->loc_type = bp_loc_hardware_breakpoint; 4008130803Smarcel break; 4009130803Smarcel case bp_hardware_watchpoint: 4010130803Smarcel case bp_read_watchpoint: 4011130803Smarcel case bp_access_watchpoint: 4012130803Smarcel loc->loc_type = bp_loc_hardware_watchpoint; 4013130803Smarcel break; 4014130803Smarcel case bp_watchpoint: 4015130803Smarcel case bp_catch_fork: 4016130803Smarcel case bp_catch_vfork: 4017130803Smarcel case bp_catch_exec: 4018130803Smarcel case bp_catch_catch: 4019130803Smarcel case bp_catch_throw: 4020130803Smarcel loc->loc_type = bp_loc_other; 4021130803Smarcel break; 4022130803Smarcel default: 4023130803Smarcel internal_error (__FILE__, __LINE__, "unknown breakpoint type"); 4024130803Smarcel } 4025130803Smarcel 4026130803Smarcel /* Add this breakpoint to the end of the chain. */ 4027130803Smarcel 4028130803Smarcel loc_p = bp_location_chain; 4029130803Smarcel if (loc_p == 0) 4030130803Smarcel bp_location_chain = loc; 4031130803Smarcel else 4032130803Smarcel { 4033130803Smarcel while (loc_p->next) 4034130803Smarcel loc_p = loc_p->next; 4035130803Smarcel loc_p->next = loc; 4036130803Smarcel } 4037130803Smarcel 4038130803Smarcel return loc; 4039130803Smarcel} 4040130803Smarcel 404198944Sobrien/* set_raw_breakpoint() is a low level routine for allocating and 404298944Sobrien partially initializing a breakpoint of type BPTYPE. The newly 404398944Sobrien created breakpoint's address, section, source file name, and line 404498944Sobrien number are provided by SAL. The newly created and partially 404598944Sobrien initialized breakpoint is added to the breakpoint chain and 404698944Sobrien is also returned as the value of this function. 404719370Spst 404898944Sobrien It is expected that the caller will complete the initialization of 404998944Sobrien the newly created breakpoint struct as well as output any status 405098944Sobrien information regarding the creation of a new breakpoint. In 405198944Sobrien particular, set_raw_breakpoint() does NOT set the breakpoint 405298944Sobrien number! Care should be taken to not allow an error() to occur 405398944Sobrien prior to completing the initialization of the breakpoint. If this 405498944Sobrien should happen, a bogus breakpoint will be left on the chain. */ 405519370Spst 405646283Sdfrstruct breakpoint * 405798944Sobrienset_raw_breakpoint (struct symtab_and_line sal, enum bptype bptype) 405819370Spst{ 4059130803Smarcel struct breakpoint *b, *b1; 406019370Spst 406119370Spst b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); 406219370Spst memset (b, 0, sizeof (*b)); 4063130803Smarcel b->loc = allocate_bp_location (b, bptype); 4064130803Smarcel b->loc->requested_address = sal.pc; 4065130803Smarcel b->loc->address = adjust_breakpoint_address (b->loc->requested_address); 406619370Spst if (sal.symtab == NULL) 406719370Spst b->source_file = NULL; 406819370Spst else 406919370Spst b->source_file = savestring (sal.symtab->filename, 407019370Spst strlen (sal.symtab->filename)); 4071130803Smarcel b->loc->section = sal.section; 407298944Sobrien b->type = bptype; 407319370Spst b->language = current_language->la_language; 407419370Spst b->input_radix = input_radix; 407519370Spst b->thread = -1; 407619370Spst b->line_number = sal.line; 407798944Sobrien b->enable_state = bp_enabled; 407819370Spst b->next = 0; 407919370Spst b->silent = 0; 408019370Spst b->ignore_count = 0; 408119370Spst b->commands = NULL; 4082130803Smarcel b->frame_id = null_frame_id; 408346283Sdfr b->dll_pathname = NULL; 408446283Sdfr b->triggered_dll_pathname = NULL; 408546283Sdfr b->forked_inferior_pid = 0; 408646283Sdfr b->exec_pathname = NULL; 4087130803Smarcel b->ops = NULL; 4088130803Smarcel b->pending = 0; 408919370Spst 409019370Spst /* Add this breakpoint to the end of the chain 409119370Spst so that a list of breakpoints will come out in order 409219370Spst of increasing numbers. */ 409319370Spst 409419370Spst b1 = breakpoint_chain; 409519370Spst if (b1 == 0) 409619370Spst breakpoint_chain = b; 409719370Spst else 409819370Spst { 409919370Spst while (b1->next) 410019370Spst b1 = b1->next; 410119370Spst b1->next = b; 410219370Spst } 410319370Spst 410498944Sobrien check_duplicates (b); 410519370Spst breakpoints_changed (); 410619370Spst 410719370Spst return b; 410819370Spst} 410919370Spst 411019370Spst 411198944Sobrien/* Note that the breakpoint object B describes a permanent breakpoint 411298944Sobrien instruction, hard-wired into the inferior's code. */ 411398944Sobrienvoid 411498944Sobrienmake_breakpoint_permanent (struct breakpoint *b) 411519370Spst{ 411698944Sobrien b->enable_state = bp_permanent; 411798944Sobrien 411898944Sobrien /* By definition, permanent breakpoints are already present in the code. */ 4119130803Smarcel b->loc->inserted = 1; 412098944Sobrien} 412198944Sobrien 412298944Sobrienstatic struct breakpoint * 412398944Sobriencreate_internal_breakpoint (CORE_ADDR address, enum bptype type) 412498944Sobrien{ 412598944Sobrien static int internal_breakpoint_number = -1; 412619370Spst struct symtab_and_line sal; 412719370Spst struct breakpoint *b; 412819370Spst 4129130803Smarcel init_sal (&sal); /* initialize to zeroes */ 413098944Sobrien 413198944Sobrien sal.pc = address; 413298944Sobrien sal.section = find_pc_overlay (sal.pc); 413398944Sobrien 413498944Sobrien b = set_raw_breakpoint (sal, type); 413598944Sobrien b->number = internal_breakpoint_number--; 413698944Sobrien b->disposition = disp_donttouch; 413798944Sobrien 413898944Sobrien return b; 413998944Sobrien} 414098944Sobrien 414198944Sobrien 414298944Sobrienstatic void 414398944Sobriencreate_longjmp_breakpoint (char *func_name) 414498944Sobrien{ 414598944Sobrien struct breakpoint *b; 414698944Sobrien struct minimal_symbol *m; 414798944Sobrien 414898944Sobrien if (func_name == NULL) 414998944Sobrien b = create_internal_breakpoint (0, bp_longjmp_resume); 415098944Sobrien else 415119370Spst { 4152130803Smarcel if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL) 415319370Spst return; 415498944Sobrien 415598944Sobrien b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), bp_longjmp); 415619370Spst } 415719370Spst 415898944Sobrien b->enable_state = bp_disabled; 415919370Spst b->silent = 1; 416019370Spst if (func_name) 416198944Sobrien b->addr_string = xstrdup (func_name); 416219370Spst} 416319370Spst 416498944Sobrien/* Call this routine when stepping and nexting to enable a breakpoint 416598944Sobrien if we do a longjmp(). When we hit that breakpoint, call 416619370Spst set_longjmp_resume_breakpoint() to figure out where we are going. */ 416719370Spst 416819370Spstvoid 416998944Sobrienenable_longjmp_breakpoint (void) 417019370Spst{ 4171130803Smarcel struct breakpoint *b; 417219370Spst 417319370Spst ALL_BREAKPOINTS (b) 417419370Spst if (b->type == bp_longjmp) 417598944Sobrien { 417698944Sobrien b->enable_state = bp_enabled; 417798944Sobrien check_duplicates (b); 417898944Sobrien } 417919370Spst} 418019370Spst 418119370Spstvoid 418298944Sobriendisable_longjmp_breakpoint (void) 418319370Spst{ 4184130803Smarcel struct breakpoint *b; 418519370Spst 418619370Spst ALL_BREAKPOINTS (b) 418798944Sobrien if (b->type == bp_longjmp 418819370Spst || b->type == bp_longjmp_resume) 418998944Sobrien { 419098944Sobrien b->enable_state = bp_disabled; 419198944Sobrien check_duplicates (b); 419298944Sobrien } 419319370Spst} 419419370Spst 419598944Sobrienstatic void 419698944Sobriencreate_overlay_event_breakpoint (char *func_name) 419798944Sobrien{ 419898944Sobrien struct breakpoint *b; 419998944Sobrien struct minimal_symbol *m; 420098944Sobrien 4201130803Smarcel if ((m = lookup_minimal_symbol_text (func_name, NULL)) == NULL) 420298944Sobrien return; 420398944Sobrien 420498944Sobrien b = create_internal_breakpoint (SYMBOL_VALUE_ADDRESS (m), 420598944Sobrien bp_overlay_event); 420698944Sobrien b->addr_string = xstrdup (func_name); 420798944Sobrien 420898944Sobrien if (overlay_debugging == ovly_auto) 4209130803Smarcel { 4210130803Smarcel b->enable_state = bp_enabled; 4211130803Smarcel overlay_events_enabled = 1; 4212130803Smarcel } 421398944Sobrien else 4214130803Smarcel { 4215130803Smarcel b->enable_state = bp_disabled; 4216130803Smarcel overlay_events_enabled = 0; 4217130803Smarcel } 421898944Sobrien} 421998944Sobrien 422098944Sobrienvoid 422198944Sobrienenable_overlay_breakpoints (void) 422298944Sobrien{ 4223130803Smarcel struct breakpoint *b; 422498944Sobrien 422598944Sobrien ALL_BREAKPOINTS (b) 422698944Sobrien if (b->type == bp_overlay_event) 422798944Sobrien { 422898944Sobrien b->enable_state = bp_enabled; 422998944Sobrien check_duplicates (b); 4230130803Smarcel overlay_events_enabled = 1; 423198944Sobrien } 423298944Sobrien} 423398944Sobrien 423498944Sobrienvoid 423598944Sobriendisable_overlay_breakpoints (void) 423698944Sobrien{ 4237130803Smarcel struct breakpoint *b; 423898944Sobrien 423998944Sobrien ALL_BREAKPOINTS (b) 424098944Sobrien if (b->type == bp_overlay_event) 424198944Sobrien { 424298944Sobrien b->enable_state = bp_disabled; 424398944Sobrien check_duplicates (b); 4244130803Smarcel overlay_events_enabled = 0; 424598944Sobrien } 424698944Sobrien} 424798944Sobrien 424898944Sobrienstruct breakpoint * 424998944Sobriencreate_thread_event_breakpoint (CORE_ADDR address) 425098944Sobrien{ 425198944Sobrien struct breakpoint *b; 425298944Sobrien 425398944Sobrien b = create_internal_breakpoint (address, bp_thread_event); 425498944Sobrien 425598944Sobrien b->enable_state = bp_enabled; 425698944Sobrien /* addr_string has to be used or breakpoint_re_set will delete me. */ 4257130803Smarcel xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address)); 425898944Sobrien 425998944Sobrien return b; 426098944Sobrien} 426198944Sobrien 426298944Sobrienvoid 426398944Sobrienremove_thread_event_breakpoints (void) 426498944Sobrien{ 426598944Sobrien struct breakpoint *b, *temp; 426698944Sobrien 426798944Sobrien ALL_BREAKPOINTS_SAFE (b, temp) 426898944Sobrien if (b->type == bp_thread_event) 426998944Sobrien delete_breakpoint (b); 427098944Sobrien} 427198944Sobrien 4272130803Smarcelstruct captured_parse_breakpoint_args 4273130803Smarcel { 4274130803Smarcel char **arg_p; 4275130803Smarcel struct symtabs_and_lines *sals_p; 4276130803Smarcel char ***addr_string_p; 4277130803Smarcel int *not_found_ptr; 4278130803Smarcel }; 4279130803Smarcel 4280130803Smarcelstruct lang_and_radix 4281130803Smarcel { 4282130803Smarcel enum language lang; 4283130803Smarcel int radix; 4284130803Smarcel }; 4285130803Smarcel 4286130803Smarcel/* Cleanup helper routine to restore the current language and 4287130803Smarcel input radix. */ 4288130803Smarcelstatic void 4289130803Smarceldo_restore_lang_radix_cleanup (void *old) 4290130803Smarcel{ 4291130803Smarcel struct lang_and_radix *p = old; 4292130803Smarcel set_language (p->lang); 4293130803Smarcel input_radix = p->radix; 4294130803Smarcel} 4295130803Smarcel 4296130803Smarcel/* Try and resolve a pending breakpoint. */ 4297130803Smarcelstatic int 4298130803Smarcelresolve_pending_breakpoint (struct breakpoint *b) 4299130803Smarcel{ 4300130803Smarcel /* Try and reparse the breakpoint in case the shared library 4301130803Smarcel is now loaded. */ 4302130803Smarcel struct symtabs_and_lines sals; 4303130803Smarcel struct symtab_and_line pending_sal; 4304130803Smarcel char **cond_string = (char **) NULL; 4305130803Smarcel char *copy_arg = b->addr_string; 4306130803Smarcel char **addr_string; 4307130803Smarcel char *errmsg; 4308130803Smarcel int rc; 4309130803Smarcel int not_found = 0; 4310130803Smarcel struct ui_file *old_gdb_stderr; 4311130803Smarcel struct lang_and_radix old_lr; 4312130803Smarcel struct cleanup *old_chain; 4313130803Smarcel 4314130803Smarcel /* Set language, input-radix, then reissue breakpoint command. 4315130803Smarcel Ensure the language and input-radix are restored afterwards. */ 4316130803Smarcel old_lr.lang = current_language->la_language; 4317130803Smarcel old_lr.radix = input_radix; 4318130803Smarcel old_chain = make_cleanup (do_restore_lang_radix_cleanup, &old_lr); 4319130803Smarcel 4320130803Smarcel set_language (b->language); 4321130803Smarcel input_radix = b->input_radix; 4322130803Smarcel rc = break_command_1 (b->addr_string, b->flag, b->from_tty, b); 4323130803Smarcel 4324130803Smarcel if (rc == GDB_RC_OK) 4325130803Smarcel /* Pending breakpoint has been resolved. */ 4326130803Smarcel printf_filtered ("Pending breakpoint \"%s\" resolved\n", b->addr_string); 4327130803Smarcel 4328130803Smarcel do_cleanups (old_chain); 4329130803Smarcel return rc; 4330130803Smarcel} 4331130803Smarcel 433219370Spst#ifdef SOLIB_ADD 433319370Spstvoid 433498944Sobrienremove_solib_event_breakpoints (void) 433519370Spst{ 4336130803Smarcel struct breakpoint *b, *temp; 433719370Spst 433819370Spst ALL_BREAKPOINTS_SAFE (b, temp) 433919370Spst if (b->type == bp_shlib_event) 434019370Spst delete_breakpoint (b); 434119370Spst} 434219370Spst 434398944Sobrienstruct breakpoint * 434498944Sobriencreate_solib_event_breakpoint (CORE_ADDR address) 434519370Spst{ 434619370Spst struct breakpoint *b; 434719370Spst 434898944Sobrien b = create_internal_breakpoint (address, bp_shlib_event); 434998944Sobrien return b; 435019370Spst} 435119370Spst 435298944Sobrien/* Disable any breakpoints that are on code in shared libraries. Only 435398944Sobrien apply to enabled breakpoints, disabled ones can just stay disabled. */ 435498944Sobrien 435546283Sdfrvoid 435698944Sobriendisable_breakpoints_in_shlibs (int silent) 435746283Sdfr{ 435898944Sobrien struct breakpoint *b; 435998944Sobrien int disabled_shlib_breaks = 0; 436046283Sdfr 436146283Sdfr /* See also: insert_breakpoints, under DISABLE_UNSETTABLE_BREAK. */ 436246283Sdfr ALL_BREAKPOINTS (b) 436398944Sobrien { 436446283Sdfr#if defined (PC_SOLIB) 436598944Sobrien if (((b->type == bp_breakpoint) || 436698944Sobrien (b->type == bp_hardware_breakpoint)) && 4367130803Smarcel breakpoint_enabled (b) && 4368130803Smarcel !b->loc->duplicate && 4369130803Smarcel PC_SOLIB (b->loc->address)) 437098944Sobrien { 437198944Sobrien b->enable_state = bp_shlib_disabled; 437298944Sobrien if (!silent) 437398944Sobrien { 437498944Sobrien if (!disabled_shlib_breaks) 437598944Sobrien { 437698944Sobrien target_terminal_ours_for_output (); 437798944Sobrien warning ("Temporarily disabling shared library breakpoints:"); 437898944Sobrien } 437998944Sobrien disabled_shlib_breaks = 1; 438098944Sobrien warning ("breakpoint #%d ", b->number); 438198944Sobrien } 438298944Sobrien } 438346283Sdfr#endif 438498944Sobrien } 438546283Sdfr} 438646283Sdfr 438719370Spst/* Try to reenable any breakpoints in shared libraries. */ 438819370Spstvoid 438998944Sobrienre_enable_breakpoints_in_shlibs (void) 439019370Spst{ 4391130803Smarcel struct breakpoint *b, *tmp; 439219370Spst 4393130803Smarcel ALL_BREAKPOINTS_SAFE (b, tmp) 4394130803Smarcel { 439598944Sobrien if (b->enable_state == bp_shlib_disabled) 4396130803Smarcel { 4397130803Smarcel char buf[1], *lib; 4398130803Smarcel 4399130803Smarcel /* Do not reenable the breakpoint if the shared library 4400130803Smarcel is still not mapped in. */ 4401130803Smarcel lib = PC_SOLIB (b->loc->address); 4402130803Smarcel if (lib != NULL && target_read_memory (b->loc->address, buf, 1) == 0) 4403130803Smarcel b->enable_state = bp_enabled; 4404130803Smarcel } 4405130803Smarcel else if (b->pending && (b->enable_state == bp_enabled)) 4406130803Smarcel { 4407130803Smarcel if (resolve_pending_breakpoint (b) == GDB_RC_OK) 4408130803Smarcel delete_breakpoint (b); 4409130803Smarcel } 4410130803Smarcel } 441119370Spst} 441219370Spst 441319370Spst#endif 441419370Spst 441546283Sdfrstatic void 441698944Sobriensolib_load_unload_1 (char *hookname, int tempflag, char *dll_pathname, 441798944Sobrien char *cond_string, enum bptype bp_kind) 441846283Sdfr{ 441998944Sobrien struct breakpoint *b; 442046283Sdfr struct symtabs_and_lines sals; 442198944Sobrien struct cleanup *old_chain; 442298944Sobrien struct cleanup *canonical_strings_chain = NULL; 442398944Sobrien char *addr_start = hookname; 442498944Sobrien char *addr_end = NULL; 442598944Sobrien char **canonical = (char **) NULL; 442698944Sobrien int thread = -1; /* All threads. */ 442798944Sobrien 442846283Sdfr /* Set a breakpoint on the specified hook. */ 4429130803Smarcel sals = decode_line_1 (&hookname, 1, (struct symtab *) NULL, 0, &canonical, NULL); 443046283Sdfr addr_end = hookname; 443198944Sobrien 443246283Sdfr if (sals.nelts == 0) 443346283Sdfr { 443446283Sdfr warning ("Unable to set a breakpoint on dynamic linker callback."); 443546283Sdfr warning ("Suggest linking with /opt/langtools/lib/end.o."); 443646283Sdfr warning ("GDB will be unable to track shl_load/shl_unload calls"); 443746283Sdfr return; 443846283Sdfr } 443946283Sdfr if (sals.nelts != 1) 444046283Sdfr { 444198944Sobrien warning ("Unable to set unique breakpoint on dynamic linker callback."); 444246283Sdfr warning ("GDB will be unable to track shl_load/shl_unload calls"); 444346283Sdfr return; 444446283Sdfr } 444546283Sdfr 444698944Sobrien /* Make sure that all storage allocated in decode_line_1 gets freed 444798944Sobrien in case the following errors out. */ 444898944Sobrien old_chain = make_cleanup (xfree, sals.sals); 444998944Sobrien if (canonical != (char **) NULL) 445046283Sdfr { 445198944Sobrien make_cleanup (xfree, canonical); 445246283Sdfr canonical_strings_chain = make_cleanup (null_cleanup, 0); 445346283Sdfr if (canonical[0] != NULL) 445498944Sobrien make_cleanup (xfree, canonical[0]); 445546283Sdfr } 445698944Sobrien 445746283Sdfr resolve_sal_pc (&sals.sals[0]); 445898944Sobrien 445946283Sdfr /* Remove the canonical strings from the cleanup, they are needed below. */ 446098944Sobrien if (canonical != (char **) NULL) 446146283Sdfr discard_cleanups (canonical_strings_chain); 446298944Sobrien 446398944Sobrien b = set_raw_breakpoint (sals.sals[0], bp_kind); 446446283Sdfr set_breakpoint_count (breakpoint_count + 1); 446546283Sdfr b->number = breakpoint_count; 446646283Sdfr b->cond = NULL; 446798944Sobrien b->cond_string = (cond_string == NULL) ? 446898944Sobrien NULL : savestring (cond_string, strlen (cond_string)); 446946283Sdfr b->thread = thread; 447098944Sobrien 447198944Sobrien if (canonical != (char **) NULL && canonical[0] != NULL) 447246283Sdfr b->addr_string = canonical[0]; 447346283Sdfr else if (addr_start) 447446283Sdfr b->addr_string = savestring (addr_start, addr_end - addr_start); 447598944Sobrien 447698944Sobrien b->enable_state = bp_enabled; 447798944Sobrien b->disposition = tempflag ? disp_del : disp_donttouch; 447898944Sobrien 447946283Sdfr if (dll_pathname == NULL) 448046283Sdfr b->dll_pathname = NULL; 448146283Sdfr else 448246283Sdfr { 448346283Sdfr b->dll_pathname = (char *) xmalloc (strlen (dll_pathname) + 1); 448446283Sdfr strcpy (b->dll_pathname, dll_pathname); 448546283Sdfr } 448698944Sobrien 448746283Sdfr mention (b); 448846283Sdfr do_cleanups (old_chain); 448946283Sdfr} 449046283Sdfr 449146283Sdfrvoid 449298944Sobriencreate_solib_load_event_breakpoint (char *hookname, int tempflag, 449398944Sobrien char *dll_pathname, char *cond_string) 449446283Sdfr{ 449598944Sobrien solib_load_unload_1 (hookname, tempflag, dll_pathname, 449698944Sobrien cond_string, bp_catch_load); 449746283Sdfr} 449846283Sdfr 449946283Sdfrvoid 450098944Sobriencreate_solib_unload_event_breakpoint (char *hookname, int tempflag, 450198944Sobrien char *dll_pathname, char *cond_string) 450246283Sdfr{ 450398944Sobrien solib_load_unload_1 (hookname,tempflag, dll_pathname, 450498944Sobrien cond_string, bp_catch_unload); 450546283Sdfr} 450646283Sdfr 450746283Sdfrstatic void 450898944Sobriencreate_fork_vfork_event_catchpoint (int tempflag, char *cond_string, 450998944Sobrien enum bptype bp_kind) 451046283Sdfr{ 451198944Sobrien struct symtab_and_line sal; 451298944Sobrien struct breakpoint *b; 451398944Sobrien int thread = -1; /* All threads. */ 451498944Sobrien 4515130803Smarcel init_sal (&sal); 451646283Sdfr sal.pc = 0; 451746283Sdfr sal.symtab = NULL; 451846283Sdfr sal.line = 0; 451998944Sobrien 452098944Sobrien b = set_raw_breakpoint (sal, bp_kind); 452146283Sdfr set_breakpoint_count (breakpoint_count + 1); 452246283Sdfr b->number = breakpoint_count; 452346283Sdfr b->cond = NULL; 452498944Sobrien b->cond_string = (cond_string == NULL) ? 452598944Sobrien NULL : savestring (cond_string, strlen (cond_string)); 452646283Sdfr b->thread = thread; 452746283Sdfr b->addr_string = NULL; 452898944Sobrien b->enable_state = bp_enabled; 452998944Sobrien b->disposition = tempflag ? disp_del : disp_donttouch; 453046283Sdfr b->forked_inferior_pid = 0; 453198944Sobrien 453246283Sdfr mention (b); 453346283Sdfr} 453446283Sdfr 453546283Sdfrvoid 453698944Sobriencreate_fork_event_catchpoint (int tempflag, char *cond_string) 453746283Sdfr{ 453846283Sdfr create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_fork); 453946283Sdfr} 454098944Sobrien 454146283Sdfrvoid 454298944Sobriencreate_vfork_event_catchpoint (int tempflag, char *cond_string) 454346283Sdfr{ 454446283Sdfr create_fork_vfork_event_catchpoint (tempflag, cond_string, bp_catch_vfork); 454546283Sdfr} 454646283Sdfr 454746283Sdfrvoid 454898944Sobriencreate_exec_event_catchpoint (int tempflag, char *cond_string) 454946283Sdfr{ 455098944Sobrien struct symtab_and_line sal; 455198944Sobrien struct breakpoint *b; 455298944Sobrien int thread = -1; /* All threads. */ 455346283Sdfr 4554130803Smarcel init_sal (&sal); 455546283Sdfr sal.pc = 0; 455646283Sdfr sal.symtab = NULL; 455746283Sdfr sal.line = 0; 455846283Sdfr 455998944Sobrien b = set_raw_breakpoint (sal, bp_catch_exec); 456046283Sdfr set_breakpoint_count (breakpoint_count + 1); 456146283Sdfr b->number = breakpoint_count; 456246283Sdfr b->cond = NULL; 456398944Sobrien b->cond_string = (cond_string == NULL) ? 456498944Sobrien NULL : savestring (cond_string, strlen (cond_string)); 456546283Sdfr b->thread = thread; 456646283Sdfr b->addr_string = NULL; 456798944Sobrien b->enable_state = bp_enabled; 456898944Sobrien b->disposition = tempflag ? disp_del : disp_donttouch; 456946283Sdfr 457046283Sdfr mention (b); 457146283Sdfr} 457246283Sdfr 457346283Sdfrstatic int 457498944Sobrienhw_breakpoint_used_count (void) 457519370Spst{ 4576130803Smarcel struct breakpoint *b; 457719370Spst int i = 0; 457819370Spst 457919370Spst ALL_BREAKPOINTS (b) 458098944Sobrien { 458198944Sobrien if (b->type == bp_hardware_breakpoint && b->enable_state == bp_enabled) 458298944Sobrien i++; 458398944Sobrien } 458419370Spst 458519370Spst return i; 458619370Spst} 458719370Spst 458846283Sdfrstatic int 458998944Sobrienhw_watchpoint_used_count (enum bptype type, int *other_type_used) 459019370Spst{ 4591130803Smarcel struct breakpoint *b; 459219370Spst int i = 0; 459319370Spst 459419370Spst *other_type_used = 0; 459519370Spst ALL_BREAKPOINTS (b) 459698944Sobrien { 4597130803Smarcel if (breakpoint_enabled (b)) 459898944Sobrien { 459998944Sobrien if (b->type == type) 460098944Sobrien i++; 460198944Sobrien else if ((b->type == bp_hardware_watchpoint || 460298944Sobrien b->type == bp_read_watchpoint || 4603130803Smarcel b->type == bp_access_watchpoint)) 460498944Sobrien *other_type_used = 1; 460598944Sobrien } 460698944Sobrien } 460719370Spst return i; 460819370Spst} 460919370Spst 461098944Sobrien/* Call this after hitting the longjmp() breakpoint. Use this to set 461198944Sobrien a new breakpoint at the target of the jmp_buf. 461219370Spst 461398944Sobrien FIXME - This ought to be done by setting a temporary breakpoint 461498944Sobrien that gets deleted automatically... */ 461519370Spst 461619370Spstvoid 4617130803Smarcelset_longjmp_resume_breakpoint (CORE_ADDR pc, struct frame_id frame_id) 461819370Spst{ 4619130803Smarcel struct breakpoint *b; 462019370Spst 462119370Spst ALL_BREAKPOINTS (b) 462219370Spst if (b->type == bp_longjmp_resume) 462398944Sobrien { 4624130803Smarcel b->loc->requested_address = pc; 4625130803Smarcel b->loc->address = adjust_breakpoint_address (b->loc->requested_address); 462698944Sobrien b->enable_state = bp_enabled; 4627130803Smarcel b->frame_id = frame_id; 462898944Sobrien check_duplicates (b); 462998944Sobrien return; 463098944Sobrien } 463119370Spst} 463219370Spst 463346283Sdfrvoid 463498944Sobriendisable_watchpoints_before_interactive_call_start (void) 463546283Sdfr{ 463698944Sobrien struct breakpoint *b; 463746283Sdfr 463846283Sdfr ALL_BREAKPOINTS (b) 463998944Sobrien { 464098944Sobrien if (((b->type == bp_watchpoint) 464198944Sobrien || (b->type == bp_hardware_watchpoint) 464298944Sobrien || (b->type == bp_read_watchpoint) 464398944Sobrien || (b->type == bp_access_watchpoint) 464498944Sobrien || ep_is_exception_catchpoint (b)) 4645130803Smarcel && breakpoint_enabled (b)) 464698944Sobrien { 464798944Sobrien b->enable_state = bp_call_disabled; 464898944Sobrien check_duplicates (b); 464998944Sobrien } 465098944Sobrien } 465146283Sdfr} 465246283Sdfr 465346283Sdfrvoid 465498944Sobrienenable_watchpoints_after_interactive_call_stop (void) 465546283Sdfr{ 465698944Sobrien struct breakpoint *b; 465746283Sdfr 465846283Sdfr ALL_BREAKPOINTS (b) 465998944Sobrien { 466098944Sobrien if (((b->type == bp_watchpoint) 466198944Sobrien || (b->type == bp_hardware_watchpoint) 466298944Sobrien || (b->type == bp_read_watchpoint) 466398944Sobrien || (b->type == bp_access_watchpoint) 466498944Sobrien || ep_is_exception_catchpoint (b)) 466598944Sobrien && (b->enable_state == bp_call_disabled)) 466698944Sobrien { 466798944Sobrien b->enable_state = bp_enabled; 466898944Sobrien check_duplicates (b); 466998944Sobrien } 467098944Sobrien } 467146283Sdfr} 467246283Sdfr 467346283Sdfr 467419370Spst/* Set a breakpoint that will evaporate an end of command 467519370Spst at address specified by SAL. 467619370Spst Restrict it to frame FRAME if FRAME is nonzero. */ 467719370Spst 467819370Spststruct breakpoint * 4679130803Smarcelset_momentary_breakpoint (struct symtab_and_line sal, struct frame_id frame_id, 468098944Sobrien enum bptype type) 468119370Spst{ 4682130803Smarcel struct breakpoint *b; 468398944Sobrien b = set_raw_breakpoint (sal, type); 468498944Sobrien b->enable_state = bp_enabled; 468598944Sobrien b->disposition = disp_donttouch; 4686130803Smarcel b->frame_id = frame_id; 468719370Spst 468819370Spst /* If we're debugging a multi-threaded program, then we 468919370Spst want momentary breakpoints to be active in only a 469019370Spst single thread of control. */ 469198944Sobrien if (in_thread_list (inferior_ptid)) 469298944Sobrien b->thread = pid_to_thread_id (inferior_ptid); 469319370Spst 469419370Spst return b; 469519370Spst} 469698944Sobrien 469719370Spst 469819370Spst/* Tell the user we have just set a breakpoint B. */ 469919370Spst 470019370Spststatic void 470198944Sobrienmention (struct breakpoint *b) 470219370Spst{ 470319370Spst int say_where = 0; 4704130803Smarcel struct cleanup *old_chain, *ui_out_chain; 470598944Sobrien struct ui_stream *stb; 470619370Spst 470798944Sobrien stb = ui_out_stream_new (uiout); 470898944Sobrien old_chain = make_cleanup_ui_out_stream_delete (stb); 470998944Sobrien 471019370Spst /* FIXME: This is misplaced; mention() is called by things (like hitting a 471119370Spst watchpoint) other than breakpoint creation. It should be possible to 471219370Spst clean this up and at the same time replace the random calls to 471319370Spst breakpoint_changed with this hook, as has already been done for 471419370Spst delete_breakpoint_hook and so on. */ 471519370Spst if (create_breakpoint_hook) 471619370Spst create_breakpoint_hook (b); 471798944Sobrien breakpoint_create_event (b->number); 471819370Spst 4719130803Smarcel if (b->ops != NULL && b->ops->print_mention != NULL) 4720130803Smarcel b->ops->print_mention (b); 4721130803Smarcel else 4722130803Smarcel switch (b->type) 4723130803Smarcel { 4724130803Smarcel case bp_none: 4725130803Smarcel printf_filtered ("(apparently deleted?) Eventpoint %d: ", b->number); 4726130803Smarcel break; 4727130803Smarcel case bp_watchpoint: 4728130803Smarcel ui_out_text (uiout, "Watchpoint "); 4729130803Smarcel ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); 4730130803Smarcel ui_out_field_int (uiout, "number", b->number); 4731130803Smarcel ui_out_text (uiout, ": "); 4732130803Smarcel print_expression (b->exp, stb->stream); 4733130803Smarcel ui_out_field_stream (uiout, "exp", stb); 4734130803Smarcel do_cleanups (ui_out_chain); 4735130803Smarcel break; 4736130803Smarcel case bp_hardware_watchpoint: 4737130803Smarcel ui_out_text (uiout, "Hardware watchpoint "); 4738130803Smarcel ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); 4739130803Smarcel ui_out_field_int (uiout, "number", b->number); 4740130803Smarcel ui_out_text (uiout, ": "); 4741130803Smarcel print_expression (b->exp, stb->stream); 4742130803Smarcel ui_out_field_stream (uiout, "exp", stb); 4743130803Smarcel do_cleanups (ui_out_chain); 4744130803Smarcel break; 4745130803Smarcel case bp_read_watchpoint: 4746130803Smarcel ui_out_text (uiout, "Hardware read watchpoint "); 4747130803Smarcel ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); 4748130803Smarcel ui_out_field_int (uiout, "number", b->number); 4749130803Smarcel ui_out_text (uiout, ": "); 4750130803Smarcel print_expression (b->exp, stb->stream); 4751130803Smarcel ui_out_field_stream (uiout, "exp", stb); 4752130803Smarcel do_cleanups (ui_out_chain); 4753130803Smarcel break; 4754130803Smarcel case bp_access_watchpoint: 4755130803Smarcel ui_out_text (uiout, "Hardware access (read/write) watchpoint "); 4756130803Smarcel ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); 4757130803Smarcel ui_out_field_int (uiout, "number", b->number); 4758130803Smarcel ui_out_text (uiout, ": "); 4759130803Smarcel print_expression (b->exp, stb->stream); 4760130803Smarcel ui_out_field_stream (uiout, "exp", stb); 4761130803Smarcel do_cleanups (ui_out_chain); 4762130803Smarcel break; 4763130803Smarcel case bp_breakpoint: 4764130803Smarcel if (ui_out_is_mi_like_p (uiout)) 4765130803Smarcel { 4766130803Smarcel say_where = 0; 4767130803Smarcel break; 4768130803Smarcel } 4769130803Smarcel printf_filtered ("Breakpoint %d", b->number); 4770130803Smarcel say_where = 1; 4771130803Smarcel break; 4772130803Smarcel case bp_hardware_breakpoint: 4773130803Smarcel if (ui_out_is_mi_like_p (uiout)) 4774130803Smarcel { 4775130803Smarcel say_where = 0; 4776130803Smarcel break; 4777130803Smarcel } 4778130803Smarcel printf_filtered ("Hardware assisted breakpoint %d", b->number); 4779130803Smarcel say_where = 1; 4780130803Smarcel break; 4781130803Smarcel case bp_catch_load: 4782130803Smarcel case bp_catch_unload: 4783130803Smarcel printf_filtered ("Catchpoint %d (%s %s)", 4784130803Smarcel b->number, 4785130803Smarcel (b->type == bp_catch_load) ? "load" : "unload", 4786130803Smarcel (b->dll_pathname != NULL) ? 4787130803Smarcel b->dll_pathname : "<any library>"); 4788130803Smarcel break; 4789130803Smarcel case bp_catch_fork: 4790130803Smarcel case bp_catch_vfork: 4791130803Smarcel printf_filtered ("Catchpoint %d (%s)", 4792130803Smarcel b->number, 4793130803Smarcel (b->type == bp_catch_fork) ? "fork" : "vfork"); 4794130803Smarcel break; 4795130803Smarcel case bp_catch_exec: 4796130803Smarcel printf_filtered ("Catchpoint %d (exec)", 4797130803Smarcel b->number); 4798130803Smarcel break; 4799130803Smarcel case bp_catch_catch: 4800130803Smarcel case bp_catch_throw: 4801130803Smarcel printf_filtered ("Catchpoint %d (%s)", 4802130803Smarcel b->number, 4803130803Smarcel (b->type == bp_catch_catch) ? "catch" : "throw"); 4804130803Smarcel break; 4805130803Smarcel 4806130803Smarcel case bp_until: 4807130803Smarcel case bp_finish: 4808130803Smarcel case bp_longjmp: 4809130803Smarcel case bp_longjmp_resume: 4810130803Smarcel case bp_step_resume: 4811130803Smarcel case bp_through_sigtramp: 4812130803Smarcel case bp_call_dummy: 4813130803Smarcel case bp_watchpoint_scope: 4814130803Smarcel case bp_shlib_event: 4815130803Smarcel case bp_thread_event: 4816130803Smarcel case bp_overlay_event: 4817130803Smarcel break; 4818130803Smarcel } 4819130803Smarcel 4820130803Smarcel if (say_where) 482119370Spst { 4822130803Smarcel if (b->pending) 482398944Sobrien { 4824130803Smarcel printf_filtered (" (%s) pending.", b->addr_string); 482598944Sobrien } 4826130803Smarcel else 482798944Sobrien { 4828130803Smarcel if (addressprint || b->source_file == NULL) 4829130803Smarcel { 4830130803Smarcel printf_filtered (" at "); 4831130803Smarcel print_address_numeric (b->loc->address, 1, gdb_stdout); 4832130803Smarcel } 4833130803Smarcel if (b->source_file) 4834130803Smarcel printf_filtered (": file %s, line %d.", 4835130803Smarcel b->source_file, b->line_number); 483698944Sobrien } 483719370Spst } 483898944Sobrien do_cleanups (old_chain); 483998944Sobrien if (ui_out_is_mi_like_p (uiout)) 484098944Sobrien return; 484119370Spst printf_filtered ("\n"); 484219370Spst} 484319370Spst 484419370Spst 484598944Sobrien/* Add SALS.nelts breakpoints to the breakpoint table. For each 484698944Sobrien SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i], 484798944Sobrien COND[i] and COND_STRING[i] values. 484898944Sobrien 4849130803Smarcel The parameter PENDING_BP points to a pending breakpoint that is 4850130803Smarcel the basis of the breakpoints currently being created. The pending 4851130803Smarcel breakpoint may contain a separate condition string or commands 4852130803Smarcel that were added after the initial pending breakpoint was created. 4853130803Smarcel 485498944Sobrien NOTE: If the function succeeds, the caller is expected to cleanup 485598944Sobrien the arrays ADDR_STRING, COND_STRING, COND and SALS (but not the 485698944Sobrien array contents). If the function fails (error() is called), the 485798944Sobrien caller is expected to cleanups both the ADDR_STRING, COND_STRING, 485898944Sobrien COND and SALS arrays and each of those arrays contents. */ 485998944Sobrien 486019370Spststatic void 486198944Sobriencreate_breakpoints (struct symtabs_and_lines sals, char **addr_string, 486298944Sobrien struct expression **cond, char **cond_string, 486398944Sobrien enum bptype type, enum bpdisp disposition, 4864130803Smarcel int thread, int ignore_count, int from_tty, 4865130803Smarcel struct breakpoint *pending_bp) 486619370Spst{ 486798944Sobrien if (type == bp_hardware_breakpoint) 486898944Sobrien { 486998944Sobrien int i = hw_breakpoint_used_count (); 487098944Sobrien int target_resources_ok = 487198944Sobrien TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, 487298944Sobrien i + sals.nelts, 0); 487398944Sobrien if (target_resources_ok == 0) 487498944Sobrien error ("No hardware breakpoint support in the target."); 487598944Sobrien else if (target_resources_ok < 0) 487698944Sobrien error ("Hardware breakpoints used exceeds limit."); 487798944Sobrien } 487819370Spst 487998944Sobrien /* Now set all the breakpoints. */ 488098944Sobrien { 488198944Sobrien int i; 488298944Sobrien for (i = 0; i < sals.nelts; i++) 488398944Sobrien { 488498944Sobrien struct breakpoint *b; 488598944Sobrien struct symtab_and_line sal = sals.sals[i]; 488619370Spst 488798944Sobrien if (from_tty) 488898944Sobrien describe_other_breakpoints (sal.pc, sal.section); 488998944Sobrien 489098944Sobrien b = set_raw_breakpoint (sal, type); 489198944Sobrien set_breakpoint_count (breakpoint_count + 1); 489298944Sobrien b->number = breakpoint_count; 489398944Sobrien b->cond = cond[i]; 489498944Sobrien b->thread = thread; 4895130803Smarcel if (addr_string[i]) 4896130803Smarcel b->addr_string = addr_string[i]; 4897130803Smarcel else 4898130803Smarcel /* addr_string has to be used or breakpoint_re_set will delete 4899130803Smarcel me. */ 4900130803Smarcel xasprintf (&b->addr_string, "*0x%s", paddr (b->loc->address)); 490198944Sobrien b->cond_string = cond_string[i]; 490298944Sobrien b->ignore_count = ignore_count; 490398944Sobrien b->enable_state = bp_enabled; 490498944Sobrien b->disposition = disposition; 4905130803Smarcel /* If resolving a pending breakpoint, a check must be made to see if 4906130803Smarcel the user has specified a new condition or commands for the 4907130803Smarcel breakpoint. A new condition will override any condition that was 4908130803Smarcel initially specified with the initial breakpoint command. */ 4909130803Smarcel if (pending_bp) 4910130803Smarcel { 4911130803Smarcel char *arg; 4912130803Smarcel if (pending_bp->cond_string) 4913130803Smarcel { 4914130803Smarcel arg = pending_bp->cond_string; 4915130803Smarcel b->cond_string = savestring (arg, strlen (arg)); 4916130803Smarcel b->cond = parse_exp_1 (&arg, block_for_pc (b->loc->address), 0); 4917130803Smarcel if (*arg) 4918130803Smarcel error ("Junk at end of pending breakpoint condition expression"); 4919130803Smarcel } 4920130803Smarcel /* If there are commands associated with the breakpoint, they should 4921130803Smarcel be copied too. */ 4922130803Smarcel if (pending_bp->commands) 4923130803Smarcel b->commands = copy_command_lines (pending_bp->commands); 4924130803Smarcel 4925130803Smarcel /* We have to copy over the ignore_count and thread as well. */ 4926130803Smarcel b->ignore_count = pending_bp->ignore_count; 4927130803Smarcel b->thread = pending_bp->thread; 4928130803Smarcel } 492998944Sobrien mention (b); 493098944Sobrien } 493198944Sobrien } 493298944Sobrien} 493319370Spst 493498944Sobrien/* Parse ARG which is assumed to be a SAL specification possibly 493598944Sobrien followed by conditionals. On return, SALS contains an array of SAL 493698944Sobrien addresses found. ADDR_STRING contains a vector of (canonical) 493798944Sobrien address strings. ARG points to the end of the SAL. */ 493819370Spst 4939130803Smarcelstatic void 494098944Sobrienparse_breakpoint_sals (char **address, 494198944Sobrien struct symtabs_and_lines *sals, 4942130803Smarcel char ***addr_string, 4943130803Smarcel int *not_found_ptr) 494498944Sobrien{ 494598944Sobrien char *addr_start = *address; 494698944Sobrien *addr_string = NULL; 494798944Sobrien /* If no arg given, or if first arg is 'if ', use the default 494898944Sobrien breakpoint. */ 494998944Sobrien if ((*address) == NULL 495098944Sobrien || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) 495119370Spst { 495219370Spst if (default_breakpoint_valid) 495319370Spst { 495498944Sobrien struct symtab_and_line sal; 4955130803Smarcel init_sal (&sal); /* initialize to zeroes */ 495698944Sobrien sals->sals = (struct symtab_and_line *) 495719370Spst xmalloc (sizeof (struct symtab_and_line)); 495819370Spst sal.pc = default_breakpoint_address; 495919370Spst sal.line = default_breakpoint_line; 496019370Spst sal.symtab = default_breakpoint_symtab; 496198944Sobrien sal.section = find_pc_overlay (sal.pc); 496298944Sobrien sals->sals[0] = sal; 496398944Sobrien sals->nelts = 1; 496419370Spst } 496519370Spst else 496619370Spst error ("No default breakpoint address now."); 496719370Spst } 496819370Spst else 496919370Spst { 497019370Spst /* Force almost all breakpoints to be in terms of the 497198944Sobrien current_source_symtab (which is decode_line_1's default). This 497298944Sobrien should produce the results we want almost all of the time while 4973130803Smarcel leaving default_breakpoint_* alone. 4974130803Smarcel ObjC: However, don't match an Objective-C method name which 4975130803Smarcel may have a '+' or '-' succeeded by a '[' */ 4976130803Smarcel 4977130803Smarcel struct symtab_and_line cursal = get_current_source_symtab_and_line (); 4978130803Smarcel 497919370Spst if (default_breakpoint_valid 4980130803Smarcel && (!cursal.symtab 4981130803Smarcel || ((strchr ("+-", (*address)[0]) != NULL) 4982130803Smarcel && ((*address)[1] != '[')))) 498398944Sobrien *sals = decode_line_1 (address, 1, default_breakpoint_symtab, 4984130803Smarcel default_breakpoint_line, addr_string, 4985130803Smarcel not_found_ptr); 498619370Spst else 4987130803Smarcel *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, 4988130803Smarcel addr_string, not_found_ptr); 498919370Spst } 499098944Sobrien /* For any SAL that didn't have a canonical string, fill one in. */ 499198944Sobrien if (sals->nelts > 0 && *addr_string == NULL) 499298944Sobrien *addr_string = xcalloc (sals->nelts, sizeof (char **)); 499398944Sobrien if (addr_start != (*address)) 499419370Spst { 499598944Sobrien int i; 499698944Sobrien for (i = 0; i < sals->nelts; i++) 499719370Spst { 499898944Sobrien /* Add the string if not present. */ 499998944Sobrien if ((*addr_string)[i] == NULL) 500098944Sobrien (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); 500119370Spst } 500219370Spst } 500398944Sobrien} 500419370Spst 500519370Spst 500698944Sobrien/* Convert each SAL into a real PC. Verify that the PC can be 500798944Sobrien inserted as a breakpoint. If it can't throw an error. */ 500898944Sobrien 5009130803Smarcelstatic void 501098944Sobrienbreakpoint_sals_to_pc (struct symtabs_and_lines *sals, 501198944Sobrien char *address) 501298944Sobrien{ 501398944Sobrien int i; 501498944Sobrien for (i = 0; i < sals->nelts; i++) 501519370Spst { 501698944Sobrien resolve_sal_pc (&sals->sals[i]); 501719370Spst 501846283Sdfr /* It's possible for the PC to be nonzero, but still an illegal 501946283Sdfr value on some targets. 502046283Sdfr 502146283Sdfr For example, on HP-UX if you start gdb, and before running the 502246283Sdfr inferior you try to set a breakpoint on a shared library function 502346283Sdfr "foo" where the inferior doesn't call "foo" directly but does 502446283Sdfr pass its address to another function call, then we do find a 502546283Sdfr minimal symbol for the "foo", but it's address is invalid. 502646283Sdfr (Appears to be an index into a table that the loader sets up 502746283Sdfr when the inferior is run.) 502846283Sdfr 502946283Sdfr Give the target a chance to bless sals.sals[i].pc before we 503046283Sdfr try to make a breakpoint for it. */ 503198944Sobrien if (PC_REQUIRES_RUN_BEFORE_USE (sals->sals[i].pc)) 503298944Sobrien { 503398944Sobrien if (address == NULL) 503498944Sobrien error ("Cannot break without a running program."); 503598944Sobrien else 503698944Sobrien error ("Cannot break on %s without a running program.", 503798944Sobrien address); 503898944Sobrien } 503998944Sobrien } 504098944Sobrien} 504119370Spst 5042130803Smarcelstatic int 5043130803Smarceldo_captured_parse_breakpoint (struct ui_out *ui, void *data) 5044130803Smarcel{ 5045130803Smarcel struct captured_parse_breakpoint_args *args = data; 5046130803Smarcel 5047130803Smarcel parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, 5048130803Smarcel args->not_found_ptr); 5049130803Smarcel 5050130803Smarcel return GDB_RC_OK; 5051130803Smarcel} 5052130803Smarcel 505398944Sobrien/* Set a breakpoint according to ARG (function, linenum or *address) 505498944Sobrien flag: first bit : 0 non-temporary, 1 temporary. 5055130803Smarcel second bit : 0 normal breakpoint, 1 hardware breakpoint. 505698944Sobrien 5057130803Smarcel PENDING_BP is non-NULL when this function is being called to resolve 5058130803Smarcel a pending breakpoint. */ 5059130803Smarcel 5060130803Smarcelstatic int 5061130803Smarcelbreak_command_1 (char *arg, int flag, int from_tty, struct breakpoint *pending_bp) 506298944Sobrien{ 506398944Sobrien int tempflag, hardwareflag; 506498944Sobrien struct symtabs_and_lines sals; 5065130803Smarcel struct expression **cond = 0; 5066130803Smarcel struct symtab_and_line pending_sal; 506798944Sobrien char **cond_string = (char **) NULL; 5068130803Smarcel char *copy_arg; 5069130803Smarcel char *err_msg; 507098944Sobrien char *addr_start = arg; 507198944Sobrien char **addr_string; 507298944Sobrien struct cleanup *old_chain; 507398944Sobrien struct cleanup *breakpoint_chain = NULL; 5074130803Smarcel struct captured_parse_breakpoint_args parse_args; 5075130803Smarcel int i, rc; 5076130803Smarcel int pending = 0; 507798944Sobrien int thread = -1; 507898944Sobrien int ignore_count = 0; 5079130803Smarcel int not_found = 0; 508098944Sobrien 508198944Sobrien hardwareflag = flag & BP_HARDWAREFLAG; 508298944Sobrien tempflag = flag & BP_TEMPFLAG; 508398944Sobrien 508498944Sobrien sals.sals = NULL; 508598944Sobrien sals.nelts = 0; 508698944Sobrien addr_string = NULL; 508798944Sobrien 5088130803Smarcel parse_args.arg_p = &arg; 5089130803Smarcel parse_args.sals_p = &sals; 5090130803Smarcel parse_args.addr_string_p = &addr_string; 5091130803Smarcel parse_args.not_found_ptr = ¬_found; 509298944Sobrien 5093130803Smarcel rc = catch_exceptions_with_msg (uiout, do_captured_parse_breakpoint, 5094130803Smarcel &parse_args, NULL, &err_msg, 5095130803Smarcel RETURN_MASK_ALL); 5096130803Smarcel 5097130803Smarcel /* If caller is interested in rc value from parse, set value. */ 5098130803Smarcel 5099130803Smarcel if (rc != GDB_RC_OK) 5100130803Smarcel { 5101130803Smarcel /* Check for file or function not found. */ 5102130803Smarcel if (not_found) 5103130803Smarcel { 5104130803Smarcel /* If called to resolve pending breakpoint, just return error code. */ 5105130803Smarcel if (pending_bp) 5106130803Smarcel return rc; 5107130803Smarcel 5108130803Smarcel error_output_message (NULL, err_msg); 5109130803Smarcel xfree (err_msg); 5110130803Smarcel 5111130803Smarcel /* If pending breakpoint support is turned off, throw error. */ 5112130803Smarcel 5113130803Smarcel if (pending_break_support == AUTO_BOOLEAN_FALSE) 5114130803Smarcel throw_exception (RETURN_ERROR); 5115130803Smarcel 5116130803Smarcel /* If pending breakpoint support is auto query and the user selects 5117130803Smarcel no, then simply return the error code. */ 5118130803Smarcel if (pending_break_support == AUTO_BOOLEAN_AUTO && 5119130803Smarcel !nquery ("Make breakpoint pending on future shared library load? ")) 5120130803Smarcel return rc; 5121130803Smarcel 5122130803Smarcel /* At this point, either the user was queried about setting a 5123130803Smarcel pending breakpoint and selected yes, or pending breakpoint 5124130803Smarcel behavior is on and thus a pending breakpoint is defaulted 5125130803Smarcel on behalf of the user. */ 5126130803Smarcel copy_arg = xstrdup (addr_start); 5127130803Smarcel addr_string = ©_arg; 5128130803Smarcel sals.nelts = 1; 5129130803Smarcel sals.sals = &pending_sal; 5130130803Smarcel pending_sal.pc = 0; 5131130803Smarcel pending = 1; 5132130803Smarcel } 5133130803Smarcel else 5134130803Smarcel return rc; 5135130803Smarcel } 5136130803Smarcel else if (!sals.nelts) 5137130803Smarcel return GDB_RC_FAIL; 5138130803Smarcel 513998944Sobrien /* Create a chain of things that always need to be cleaned up. */ 514098944Sobrien old_chain = make_cleanup (null_cleanup, 0); 514198944Sobrien 5142130803Smarcel if (!pending) 5143130803Smarcel { 5144130803Smarcel /* Make sure that all storage allocated to SALS gets freed. */ 5145130803Smarcel make_cleanup (xfree, sals.sals); 5146130803Smarcel 5147130803Smarcel /* Cleanup the addr_string array but not its contents. */ 5148130803Smarcel make_cleanup (xfree, addr_string); 5149130803Smarcel } 515098944Sobrien 515198944Sobrien /* Allocate space for all the cond expressions. */ 515298944Sobrien cond = xcalloc (sals.nelts, sizeof (struct expression *)); 515398944Sobrien make_cleanup (xfree, cond); 515498944Sobrien 515598944Sobrien /* Allocate space for all the cond strings. */ 515698944Sobrien cond_string = xcalloc (sals.nelts, sizeof (char **)); 515798944Sobrien make_cleanup (xfree, cond_string); 515898944Sobrien 515998944Sobrien /* ----------------------------- SNIP ----------------------------- 516098944Sobrien Anything added to the cleanup chain beyond this point is assumed 516198944Sobrien to be part of a breakpoint. If the breakpoint create succeeds 516298944Sobrien then the memory is not reclaimed. */ 516398944Sobrien breakpoint_chain = make_cleanup (null_cleanup, 0); 516498944Sobrien 516598944Sobrien /* Mark the contents of the addr_string for cleanup. These go on 516698944Sobrien the breakpoint_chain and only occure if the breakpoint create 516798944Sobrien fails. */ 516898944Sobrien for (i = 0; i < sals.nelts; i++) 516998944Sobrien { 517098944Sobrien if (addr_string[i] != NULL) 517198944Sobrien make_cleanup (xfree, addr_string[i]); 517298944Sobrien } 517398944Sobrien 517498944Sobrien /* Resolve all line numbers to PC's and verify that the addresses 517598944Sobrien are ok for the target. */ 5176130803Smarcel if (!pending) 5177130803Smarcel breakpoint_sals_to_pc (&sals, addr_start); 517898944Sobrien 517998944Sobrien /* Verify that condition can be parsed, before setting any 518098944Sobrien breakpoints. Allocate a separate condition expression for each 518198944Sobrien breakpoint. */ 518298944Sobrien thread = -1; /* No specific thread yet */ 5183130803Smarcel if (!pending) 518498944Sobrien { 5185130803Smarcel for (i = 0; i < sals.nelts; i++) 518619370Spst { 5187130803Smarcel char *tok = arg; 5188130803Smarcel while (tok && *tok) 518919370Spst { 5190130803Smarcel char *end_tok; 5191130803Smarcel int toklen; 5192130803Smarcel char *cond_start = NULL; 5193130803Smarcel char *cond_end = NULL; 5194130803Smarcel while (*tok == ' ' || *tok == '\t') 5195130803Smarcel tok++; 5196130803Smarcel 5197130803Smarcel end_tok = tok; 5198130803Smarcel 5199130803Smarcel while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') 5200130803Smarcel end_tok++; 5201130803Smarcel 5202130803Smarcel toklen = end_tok - tok; 5203130803Smarcel 5204130803Smarcel if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) 5205130803Smarcel { 5206130803Smarcel tok = cond_start = end_tok + 1; 5207130803Smarcel cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 5208130803Smarcel 0); 5209130803Smarcel make_cleanup (xfree, cond[i]); 5210130803Smarcel cond_end = tok; 5211130803Smarcel cond_string[i] = savestring (cond_start, 5212130803Smarcel cond_end - cond_start); 5213130803Smarcel make_cleanup (xfree, cond_string[i]); 5214130803Smarcel } 5215130803Smarcel else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) 5216130803Smarcel { 5217130803Smarcel char *tmptok; 5218130803Smarcel 5219130803Smarcel tok = end_tok + 1; 5220130803Smarcel tmptok = tok; 5221130803Smarcel thread = strtol (tok, &tok, 0); 5222130803Smarcel if (tok == tmptok) 5223130803Smarcel error ("Junk after thread keyword."); 5224130803Smarcel if (!valid_thread_id (thread)) 5225130803Smarcel error ("Unknown thread %d\n", thread); 5226130803Smarcel } 5227130803Smarcel else 5228130803Smarcel error ("Junk at end of arguments."); 522919370Spst } 523019370Spst } 5231130803Smarcel create_breakpoints (sals, addr_string, cond, cond_string, 5232130803Smarcel hardwareflag ? bp_hardware_breakpoint 5233130803Smarcel : bp_breakpoint, 5234130803Smarcel tempflag ? disp_del : disp_donttouch, 5235130803Smarcel thread, ignore_count, from_tty, 5236130803Smarcel pending_bp); 523719370Spst } 5238130803Smarcel else 5239130803Smarcel { 5240130803Smarcel struct symtab_and_line sal; 5241130803Smarcel struct breakpoint *b; 524298944Sobrien 5243130803Smarcel sal.symtab = NULL; 5244130803Smarcel sal.pc = 0; 524598944Sobrien 5246130803Smarcel make_cleanup (xfree, copy_arg); 5247130803Smarcel 5248130803Smarcel b = set_raw_breakpoint (sal, hardwareflag ? bp_hardware_breakpoint 5249130803Smarcel : bp_breakpoint); 5250130803Smarcel set_breakpoint_count (breakpoint_count + 1); 5251130803Smarcel b->number = breakpoint_count; 5252130803Smarcel b->cond = *cond; 5253130803Smarcel b->thread = thread; 5254130803Smarcel b->addr_string = *addr_string; 5255130803Smarcel b->cond_string = *cond_string; 5256130803Smarcel b->ignore_count = ignore_count; 5257130803Smarcel b->pending = 1; 5258130803Smarcel b->disposition = tempflag ? disp_del : disp_donttouch; 5259130803Smarcel b->from_tty = from_tty; 5260130803Smarcel b->flag = flag; 5261130803Smarcel mention (b); 5262130803Smarcel } 5263130803Smarcel 526498944Sobrien if (sals.nelts > 1) 526519370Spst { 526698944Sobrien warning ("Multiple breakpoints were set."); 526798944Sobrien warning ("Use the \"delete\" command to delete unwanted breakpoints."); 526819370Spst } 526998944Sobrien /* That's it. Discard the cleanups for data inserted into the 527098944Sobrien breakpoint. */ 527198944Sobrien discard_cleanups (breakpoint_chain); 527298944Sobrien /* But cleanup everything else. */ 527398944Sobrien do_cleanups (old_chain); 5274130803Smarcel 5275130803Smarcel return GDB_RC_OK; 527698944Sobrien} 527719370Spst 527898944Sobrien/* Set a breakpoint of TYPE/DISPOSITION according to ARG (function, 527998944Sobrien linenum or *address) with COND and IGNORE_COUNT. */ 528019370Spst 528198944Sobrienstruct captured_breakpoint_args 528298944Sobrien { 528398944Sobrien char *address; 528498944Sobrien char *condition; 528598944Sobrien int hardwareflag; 528698944Sobrien int tempflag; 528798944Sobrien int thread; 528898944Sobrien int ignore_count; 528998944Sobrien }; 529098944Sobrien 529198944Sobrienstatic int 529298944Sobriendo_captured_breakpoint (void *data) 529398944Sobrien{ 529498944Sobrien struct captured_breakpoint_args *args = data; 529598944Sobrien struct symtabs_and_lines sals; 5296130803Smarcel struct expression **cond; 529798944Sobrien struct cleanup *old_chain; 529898944Sobrien struct cleanup *breakpoint_chain = NULL; 529998944Sobrien int i; 530098944Sobrien char **addr_string; 530198944Sobrien char **cond_string; 530298944Sobrien 530398944Sobrien char *address_end; 530498944Sobrien 530598944Sobrien /* Parse the source and lines spec. Delay check that the expression 530698944Sobrien didn't contain trailing garbage until after cleanups are in 530798944Sobrien place. */ 530898944Sobrien sals.sals = NULL; 530998944Sobrien sals.nelts = 0; 531098944Sobrien address_end = args->address; 531198944Sobrien addr_string = NULL; 5312130803Smarcel parse_breakpoint_sals (&address_end, &sals, &addr_string, 0); 531398944Sobrien 531498944Sobrien if (!sals.nelts) 531598944Sobrien return GDB_RC_NONE; 531698944Sobrien 531798944Sobrien /* Create a chain of things at always need to be cleaned up. */ 531898944Sobrien old_chain = make_cleanup (null_cleanup, 0); 531998944Sobrien 532098944Sobrien /* Always have a addr_string array, even if it is empty. */ 532198944Sobrien make_cleanup (xfree, addr_string); 532298944Sobrien 532398944Sobrien /* Make sure that all storage allocated to SALS gets freed. */ 532498944Sobrien make_cleanup (xfree, sals.sals); 532598944Sobrien 532698944Sobrien /* Allocate space for all the cond expressions. */ 532798944Sobrien cond = xcalloc (sals.nelts, sizeof (struct expression *)); 532898944Sobrien make_cleanup (xfree, cond); 532998944Sobrien 533098944Sobrien /* Allocate space for all the cond strings. */ 533198944Sobrien cond_string = xcalloc (sals.nelts, sizeof (char **)); 533298944Sobrien make_cleanup (xfree, cond_string); 533398944Sobrien 533498944Sobrien /* ----------------------------- SNIP ----------------------------- 533598944Sobrien Anything added to the cleanup chain beyond this point is assumed 533698944Sobrien to be part of a breakpoint. If the breakpoint create goes 533798944Sobrien through then that memory is not cleaned up. */ 533898944Sobrien breakpoint_chain = make_cleanup (null_cleanup, 0); 533998944Sobrien 534098944Sobrien /* Mark the contents of the addr_string for cleanup. These go on 534198944Sobrien the breakpoint_chain and only occure if the breakpoint create 534298944Sobrien fails. */ 534319370Spst for (i = 0; i < sals.nelts; i++) 534419370Spst { 534598944Sobrien if (addr_string[i] != NULL) 534698944Sobrien make_cleanup (xfree, addr_string[i]); 534798944Sobrien } 534819370Spst 534998944Sobrien /* Wait until now before checking for garbage at the end of the 535098944Sobrien address. That way cleanups can take care of freeing any 535198944Sobrien memory. */ 535298944Sobrien if (*address_end != '\0') 535398944Sobrien error ("Garbage %s following breakpoint address", address_end); 535419370Spst 535598944Sobrien /* Resolve all line numbers to PC's. */ 535698944Sobrien breakpoint_sals_to_pc (&sals, args->address); 535719370Spst 535898944Sobrien /* Verify that conditions can be parsed, before setting any 535998944Sobrien breakpoints. */ 536098944Sobrien for (i = 0; i < sals.nelts; i++) 536198944Sobrien { 536298944Sobrien if (args->condition != NULL) 536398944Sobrien { 536498944Sobrien char *tok = args->condition; 536598944Sobrien cond[i] = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); 536698944Sobrien if (*tok != '\0') 536798944Sobrien error ("Garbage %s follows condition", tok); 536898944Sobrien make_cleanup (xfree, cond[i]); 536998944Sobrien cond_string[i] = xstrdup (args->condition); 537098944Sobrien } 537119370Spst } 537219370Spst 537398944Sobrien create_breakpoints (sals, addr_string, cond, cond_string, 537498944Sobrien args->hardwareflag ? bp_hardware_breakpoint : bp_breakpoint, 537598944Sobrien args->tempflag ? disp_del : disp_donttouch, 5376130803Smarcel args->thread, args->ignore_count, 0/*from-tty*/, 5377130803Smarcel NULL/*pending_bp*/); 537898944Sobrien 537998944Sobrien /* That's it. Discard the cleanups for data inserted into the 538098944Sobrien breakpoint. */ 538198944Sobrien discard_cleanups (breakpoint_chain); 538298944Sobrien /* But cleanup everything else. */ 538319370Spst do_cleanups (old_chain); 538498944Sobrien return GDB_RC_OK; 538519370Spst} 538619370Spst 538798944Sobrienenum gdb_rc 538898944Sobriengdb_breakpoint (char *address, char *condition, 538998944Sobrien int hardwareflag, int tempflag, 539098944Sobrien int thread, int ignore_count) 539198944Sobrien{ 539298944Sobrien struct captured_breakpoint_args args; 539398944Sobrien args.address = address; 539498944Sobrien args.condition = condition; 539598944Sobrien args.hardwareflag = hardwareflag; 539698944Sobrien args.tempflag = tempflag; 539798944Sobrien args.thread = thread; 539898944Sobrien args.ignore_count = ignore_count; 539998944Sobrien return catch_errors (do_captured_breakpoint, &args, 540098944Sobrien NULL, RETURN_MASK_ALL); 540198944Sobrien} 540298944Sobrien 540398944Sobrien 540446283Sdfrstatic void 540598944Sobrienbreak_at_finish_at_depth_command_1 (char *arg, int flag, int from_tty) 540646283Sdfr{ 540746283Sdfr struct frame_info *frame; 540846283Sdfr CORE_ADDR low, high, selected_pc = 0; 540998944Sobrien char *extra_args = NULL; 541098944Sobrien char *level_arg; 541146283Sdfr int extra_args_len = 0, if_arg = 0; 541246283Sdfr 541346283Sdfr if (!arg || 541446283Sdfr (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t'))) 541546283Sdfr { 541646283Sdfr 541746283Sdfr if (default_breakpoint_valid) 541846283Sdfr { 5419130803Smarcel if (deprecated_selected_frame) 542046283Sdfr { 5421130803Smarcel selected_pc = get_frame_pc (deprecated_selected_frame); 542246283Sdfr if (arg) 542346283Sdfr if_arg = 1; 542446283Sdfr } 542546283Sdfr else 542646283Sdfr error ("No selected frame."); 542746283Sdfr } 542846283Sdfr else 542946283Sdfr error ("No default breakpoint address now."); 543046283Sdfr } 543146283Sdfr else 543246283Sdfr { 543346283Sdfr extra_args = strchr (arg, ' '); 543446283Sdfr if (extra_args) 543546283Sdfr { 543646283Sdfr extra_args++; 543746283Sdfr extra_args_len = strlen (extra_args); 543846283Sdfr level_arg = (char *) xmalloc (extra_args - arg); 543946283Sdfr strncpy (level_arg, arg, extra_args - arg - 1); 544046283Sdfr level_arg[extra_args - arg - 1] = '\0'; 544146283Sdfr } 544246283Sdfr else 544346283Sdfr { 544446283Sdfr level_arg = (char *) xmalloc (strlen (arg) + 1); 544546283Sdfr strcpy (level_arg, arg); 544646283Sdfr } 544746283Sdfr 544846283Sdfr frame = parse_frame_specification (level_arg); 544946283Sdfr if (frame) 5450130803Smarcel selected_pc = get_frame_pc (frame); 545146283Sdfr else 545246283Sdfr selected_pc = 0; 545346283Sdfr } 545446283Sdfr if (if_arg) 545546283Sdfr { 545646283Sdfr extra_args = arg; 545798944Sobrien extra_args_len = strlen (arg); 545846283Sdfr } 545946283Sdfr 546046283Sdfr if (selected_pc) 546146283Sdfr { 546298944Sobrien if (find_pc_partial_function (selected_pc, (char **) NULL, &low, &high)) 546346283Sdfr { 5464130803Smarcel char *addr_string; 546546283Sdfr if (extra_args_len) 5466130803Smarcel addr_string = xstrprintf ("*0x%s %s", paddr_nz (high), extra_args); 546746283Sdfr else 5468130803Smarcel addr_string = xstrprintf ("*0x%s", paddr_nz (high)); 5469130803Smarcel break_command_1 (addr_string, flag, from_tty, NULL); 547098944Sobrien xfree (addr_string); 547146283Sdfr } 547246283Sdfr else 547346283Sdfr error ("No function contains the specified address"); 547446283Sdfr } 547546283Sdfr else 547646283Sdfr error ("Unable to set breakpoint at procedure exit"); 547746283Sdfr} 547846283Sdfr 547946283Sdfr 548046283Sdfrstatic void 548198944Sobrienbreak_at_finish_command_1 (char *arg, int flag, int from_tty) 548246283Sdfr{ 548346283Sdfr char *addr_string, *break_string, *beg_addr_string; 548446283Sdfr CORE_ADDR low, high; 548546283Sdfr struct symtabs_and_lines sals; 548646283Sdfr struct symtab_and_line sal; 548746283Sdfr struct cleanup *old_chain; 548898944Sobrien char *extra_args = NULL; 548946283Sdfr int extra_args_len = 0; 549046283Sdfr int i, if_arg = 0; 549146283Sdfr 549246283Sdfr if (!arg || 549346283Sdfr (arg[0] == 'i' && arg[1] == 'f' && (arg[2] == ' ' || arg[2] == '\t'))) 549446283Sdfr { 549546283Sdfr if (default_breakpoint_valid) 549646283Sdfr { 5497130803Smarcel if (deprecated_selected_frame) 549846283Sdfr { 5499130803Smarcel addr_string = xstrprintf ("*0x%s", 5500130803Smarcel paddr_nz (get_frame_pc (deprecated_selected_frame))); 550146283Sdfr if (arg) 550246283Sdfr if_arg = 1; 550346283Sdfr } 550446283Sdfr else 550546283Sdfr error ("No selected frame."); 550646283Sdfr } 550746283Sdfr else 550846283Sdfr error ("No default breakpoint address now."); 550946283Sdfr } 551046283Sdfr else 551146283Sdfr { 551246283Sdfr addr_string = (char *) xmalloc (strlen (arg) + 1); 551346283Sdfr strcpy (addr_string, arg); 551446283Sdfr } 551546283Sdfr 551646283Sdfr if (if_arg) 551746283Sdfr { 551846283Sdfr extra_args = arg; 551998944Sobrien extra_args_len = strlen (arg); 552046283Sdfr } 552198944Sobrien else if (arg) 552298944Sobrien { 552398944Sobrien /* get the stuff after the function name or address */ 552498944Sobrien extra_args = strchr (arg, ' '); 552598944Sobrien if (extra_args) 552698944Sobrien { 552798944Sobrien extra_args++; 552898944Sobrien extra_args_len = strlen (extra_args); 552998944Sobrien } 553098944Sobrien } 553146283Sdfr 553246283Sdfr sals.sals = NULL; 553346283Sdfr sals.nelts = 0; 553446283Sdfr 553598944Sobrien beg_addr_string = addr_string; 553698944Sobrien sals = decode_line_1 (&addr_string, 1, (struct symtab *) NULL, 0, 5537130803Smarcel (char ***) NULL, NULL); 553846283Sdfr 553998944Sobrien xfree (beg_addr_string); 554098944Sobrien old_chain = make_cleanup (xfree, sals.sals); 554146283Sdfr for (i = 0; (i < sals.nelts); i++) 554246283Sdfr { 554346283Sdfr sal = sals.sals[i]; 554498944Sobrien if (find_pc_partial_function (sal.pc, (char **) NULL, &low, &high)) 554546283Sdfr { 5546130803Smarcel break_string; 554746283Sdfr if (extra_args_len) 5548130803Smarcel break_string = xstrprintf ("*0x%s %s", paddr_nz (high), 5549130803Smarcel extra_args); 555046283Sdfr else 5551130803Smarcel break_string = xstrprintf ("*0x%s", paddr_nz (high)); 5552130803Smarcel break_command_1 (break_string, flag, from_tty, NULL); 555398944Sobrien xfree (break_string); 555446283Sdfr } 555546283Sdfr else 555646283Sdfr error ("No function contains the specified address"); 555746283Sdfr } 555846283Sdfr if (sals.nelts > 1) 555946283Sdfr { 556098944Sobrien warning ("Multiple breakpoints were set.\n"); 556198944Sobrien warning ("Use the \"delete\" command to delete unwanted breakpoints."); 556246283Sdfr } 556398944Sobrien do_cleanups (old_chain); 556446283Sdfr} 556546283Sdfr 556646283Sdfr 556719370Spst/* Helper function for break_command_1 and disassemble_command. */ 556819370Spst 556919370Spstvoid 557098944Sobrienresolve_sal_pc (struct symtab_and_line *sal) 557119370Spst{ 557219370Spst CORE_ADDR pc; 557319370Spst 557446283Sdfr if (sal->pc == 0 && sal->symtab != NULL) 557519370Spst { 557646283Sdfr if (!find_line_pc (sal->symtab, sal->line, &pc)) 557719370Spst error ("No line %d in file \"%s\".", 557819370Spst sal->line, sal->symtab->filename); 557919370Spst sal->pc = pc; 558019370Spst } 558146283Sdfr 558246283Sdfr if (sal->section == 0 && sal->symtab != NULL) 558346283Sdfr { 558446283Sdfr struct blockvector *bv; 558598944Sobrien struct block *b; 558698944Sobrien struct symbol *sym; 558798944Sobrien int index; 558846283Sdfr 558998944Sobrien bv = blockvector_for_pc_sect (sal->pc, 0, &index, sal->symtab); 559046283Sdfr if (bv != NULL) 559146283Sdfr { 559298944Sobrien b = BLOCKVECTOR_BLOCK (bv, index); 559346283Sdfr sym = block_function (b); 559446283Sdfr if (sym != NULL) 559546283Sdfr { 559646283Sdfr fixup_symbol_section (sym, sal->symtab->objfile); 559746283Sdfr sal->section = SYMBOL_BFD_SECTION (sym); 559846283Sdfr } 559946283Sdfr else 560046283Sdfr { 560146283Sdfr /* It really is worthwhile to have the section, so we'll just 560298944Sobrien have to look harder. This case can be executed if we have 560398944Sobrien line numbers but no functions (as can happen in assembly 560498944Sobrien source). */ 560546283Sdfr 560698944Sobrien struct minimal_symbol *msym; 560746283Sdfr 560846283Sdfr msym = lookup_minimal_symbol_by_pc (sal->pc); 560946283Sdfr if (msym) 561046283Sdfr sal->section = SYMBOL_BFD_SECTION (msym); 561146283Sdfr } 561246283Sdfr } 561346283Sdfr } 561419370Spst} 561519370Spst 561619370Spstvoid 561798944Sobrienbreak_command (char *arg, int from_tty) 561819370Spst{ 5619130803Smarcel break_command_1 (arg, 0, from_tty, NULL); 562019370Spst} 562119370Spst 562246283Sdfrvoid 562398944Sobrienbreak_at_finish_command (char *arg, int from_tty) 562446283Sdfr{ 562546283Sdfr break_at_finish_command_1 (arg, 0, from_tty); 562646283Sdfr} 562746283Sdfr 562846283Sdfrvoid 562998944Sobrienbreak_at_finish_at_depth_command (char *arg, int from_tty) 563046283Sdfr{ 563146283Sdfr break_at_finish_at_depth_command_1 (arg, 0, from_tty); 563246283Sdfr} 563346283Sdfr 563446283Sdfrvoid 563598944Sobrientbreak_command (char *arg, int from_tty) 563619370Spst{ 5637130803Smarcel break_command_1 (arg, BP_TEMPFLAG, from_tty, NULL); 563819370Spst} 563919370Spst 564046283Sdfrvoid 564198944Sobrientbreak_at_finish_command (char *arg, int from_tty) 564246283Sdfr{ 564346283Sdfr break_at_finish_command_1 (arg, BP_TEMPFLAG, from_tty); 564446283Sdfr} 564546283Sdfr 564619370Spststatic void 564798944Sobrienhbreak_command (char *arg, int from_tty) 564819370Spst{ 5649130803Smarcel break_command_1 (arg, BP_HARDWAREFLAG, from_tty, NULL); 565019370Spst} 565119370Spst 565219370Spststatic void 565398944Sobrienthbreak_command (char *arg, int from_tty) 565419370Spst{ 5655130803Smarcel break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty, NULL); 565619370Spst} 565719370Spst 565846283Sdfrstatic void 565998944Sobrienstop_command (char *arg, int from_tty) 566046283Sdfr{ 566146283Sdfr printf_filtered ("Specify the type of breakpoint to set.\n\ 566246283SdfrUsage: stop in <function | address>\n\ 566346283Sdfr stop at <line>\n"); 566446283Sdfr} 566546283Sdfr 566646283Sdfrstatic void 566798944Sobrienstopin_command (char *arg, int from_tty) 566846283Sdfr{ 566946283Sdfr int badInput = 0; 567046283Sdfr 567198944Sobrien if (arg == (char *) NULL) 567246283Sdfr badInput = 1; 567346283Sdfr else if (*arg != '*') 567446283Sdfr { 567546283Sdfr char *argptr = arg; 567646283Sdfr int hasColon = 0; 567746283Sdfr 567898944Sobrien /* look for a ':'. If this is a line number specification, then 567998944Sobrien say it is bad, otherwise, it should be an address or 568098944Sobrien function/method name */ 568146283Sdfr while (*argptr && !hasColon) 568298944Sobrien { 568398944Sobrien hasColon = (*argptr == ':'); 568498944Sobrien argptr++; 568598944Sobrien } 568646283Sdfr 568746283Sdfr if (hasColon) 568898944Sobrien badInput = (*argptr != ':'); /* Not a class::method */ 568946283Sdfr else 569098944Sobrien badInput = isdigit (*arg); /* a simple line number */ 569146283Sdfr } 569246283Sdfr 569346283Sdfr if (badInput) 569498944Sobrien printf_filtered ("Usage: stop in <function | address>\n"); 569546283Sdfr else 5696130803Smarcel break_command_1 (arg, 0, from_tty, NULL); 569746283Sdfr} 569846283Sdfr 569946283Sdfrstatic void 570098944Sobrienstopat_command (char *arg, int from_tty) 570146283Sdfr{ 570246283Sdfr int badInput = 0; 570346283Sdfr 570498944Sobrien if (arg == (char *) NULL || *arg == '*') /* no line number */ 570546283Sdfr badInput = 1; 570646283Sdfr else 570746283Sdfr { 570846283Sdfr char *argptr = arg; 570946283Sdfr int hasColon = 0; 571046283Sdfr 571146283Sdfr /* look for a ':'. If there is a '::' then get out, otherwise 571298944Sobrien it is probably a line number. */ 571346283Sdfr while (*argptr && !hasColon) 571498944Sobrien { 571598944Sobrien hasColon = (*argptr == ':'); 571698944Sobrien argptr++; 571798944Sobrien } 571846283Sdfr 571946283Sdfr if (hasColon) 572098944Sobrien badInput = (*argptr == ':'); /* we have class::method */ 572146283Sdfr else 572298944Sobrien badInput = !isdigit (*arg); /* not a line number */ 572346283Sdfr } 572446283Sdfr 572546283Sdfr if (badInput) 572698944Sobrien printf_filtered ("Usage: stop at <line>\n"); 572746283Sdfr else 5728130803Smarcel break_command_1 (arg, 0, from_tty, NULL); 572946283Sdfr} 573046283Sdfr 573198944Sobrien/* accessflag: hw_write: watch write, 573298944Sobrien hw_read: watch read, 573398944Sobrien hw_access: watch access (read or write) */ 573419370Spststatic void 573598944Sobrienwatch_command_1 (char *arg, int accessflag, int from_tty) 573619370Spst{ 573719370Spst struct breakpoint *b; 573819370Spst struct symtab_and_line sal; 573919370Spst struct expression *exp; 574019370Spst struct block *exp_valid_block; 574119370Spst struct value *val, *mark; 574246283Sdfr struct frame_info *frame; 574346283Sdfr struct frame_info *prev_frame = NULL; 574419370Spst char *exp_start = NULL; 574519370Spst char *exp_end = NULL; 574619370Spst char *tok, *end_tok; 574719370Spst int toklen; 574819370Spst char *cond_start = NULL; 574919370Spst char *cond_end = NULL; 575019370Spst struct expression *cond = NULL; 575146283Sdfr int i, other_type_used, target_resources_ok = 0; 575219370Spst enum bptype bp_type; 575319370Spst int mem_cnt = 0; 575419370Spst 5755130803Smarcel init_sal (&sal); /* initialize to zeroes */ 575698944Sobrien 575719370Spst /* Parse arguments. */ 575819370Spst innermost_block = NULL; 575919370Spst exp_start = arg; 576019370Spst exp = parse_exp_1 (&arg, 0, 0); 576119370Spst exp_end = arg; 576219370Spst exp_valid_block = innermost_block; 576319370Spst mark = value_mark (); 576419370Spst val = evaluate_expression (exp); 576519370Spst release_value (val); 576619370Spst if (VALUE_LAZY (val)) 576719370Spst value_fetch_lazy (val); 576819370Spst 576919370Spst tok = arg; 577019370Spst while (*tok == ' ' || *tok == '\t') 577119370Spst tok++; 577219370Spst end_tok = tok; 577319370Spst 577419370Spst while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') 577519370Spst end_tok++; 577619370Spst 577719370Spst toklen = end_tok - tok; 577819370Spst if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) 577919370Spst { 578019370Spst tok = cond_start = end_tok + 1; 578119370Spst cond = parse_exp_1 (&tok, 0, 0); 578219370Spst cond_end = tok; 578319370Spst } 578419370Spst if (*tok) 578598944Sobrien error ("Junk at end of command."); 578619370Spst 578798944Sobrien if (accessflag == hw_read) 578898944Sobrien bp_type = bp_read_watchpoint; 578998944Sobrien else if (accessflag == hw_access) 579098944Sobrien bp_type = bp_access_watchpoint; 579198944Sobrien else 579298944Sobrien bp_type = bp_hardware_watchpoint; 579319370Spst 579419370Spst mem_cnt = can_use_hardware_watchpoint (val); 579519370Spst if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) 579619370Spst error ("Expression cannot be implemented with read/access watchpoint."); 579798944Sobrien if (mem_cnt != 0) 579898944Sobrien { 579998944Sobrien i = hw_watchpoint_used_count (bp_type, &other_type_used); 580098944Sobrien target_resources_ok = 580198944Sobrien TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_type, i + mem_cnt, 580298944Sobrien other_type_used); 580398944Sobrien if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) 580498944Sobrien error ("Target does not support this type of hardware watchpoint."); 580546283Sdfr 580698944Sobrien if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) 580798944Sobrien error ("Target can only support one kind of HW watchpoint at a time."); 580898944Sobrien } 580998944Sobrien 581046283Sdfr#if defined(HPUXHPPA) 581198944Sobrien /* On HP-UX if you set a h/w 581246283Sdfr watchpoint before the "run" command, the inferior dies with a e.g., 581346283Sdfr SIGILL once you start it. I initially believed this was due to a 581446283Sdfr bad interaction between page protection traps and the initial 581546283Sdfr startup sequence by the dynamic linker. 581646283Sdfr 581746283Sdfr However, I tried avoiding that by having HP-UX's implementation of 581898944Sobrien TARGET_CAN_USE_HW_WATCHPOINT return FALSE if there was no inferior_ptid 581946283Sdfr yet, which forced slow watches before a "run" or "attach", and it 582046283Sdfr still fails somewhere in the startup code. 582146283Sdfr 582246283Sdfr Until I figure out what's happening, I'm disallowing watches altogether 582346283Sdfr before the "run" or "attach" command. We'll tell the user they must 582446283Sdfr set watches after getting the program started. */ 582598944Sobrien if (!target_has_execution) 582646283Sdfr { 582746283Sdfr warning ("can't do that without a running program; try \"break main\", \"run\" first"); 582846283Sdfr return; 582946283Sdfr } 583046283Sdfr#endif /* HPUXHPPA */ 583198944Sobrien 583298944Sobrien /* Change the type of breakpoint to an ordinary watchpoint if a hardware 583398944Sobrien watchpoint could not be set. */ 583498944Sobrien if (!mem_cnt || target_resources_ok <= 0) 583598944Sobrien bp_type = bp_watchpoint; 583698944Sobrien 583719370Spst /* Now set up the breakpoint. */ 583898944Sobrien b = set_raw_breakpoint (sal, bp_type); 583919370Spst set_breakpoint_count (breakpoint_count + 1); 584019370Spst b->number = breakpoint_count; 584198944Sobrien b->disposition = disp_donttouch; 584219370Spst b->exp = exp; 584319370Spst b->exp_valid_block = exp_valid_block; 584419370Spst b->exp_string = savestring (exp_start, exp_end - exp_start); 584519370Spst b->val = val; 584619370Spst b->cond = cond; 584719370Spst if (cond_start) 584819370Spst b->cond_string = savestring (cond_start, cond_end - cond_start); 584919370Spst else 585019370Spst b->cond_string = 0; 585198944Sobrien 585219370Spst frame = block_innermost_frame (exp_valid_block); 585319370Spst if (frame) 585419370Spst { 585519370Spst prev_frame = get_prev_frame (frame); 5856130803Smarcel b->watchpoint_frame = get_frame_id (frame); 585719370Spst } 585819370Spst else 5859130803Smarcel { 5860130803Smarcel memset (&b->watchpoint_frame, 0, sizeof (b->watchpoint_frame)); 5861130803Smarcel } 586219370Spst 586319370Spst /* If the expression is "local", then set up a "watchpoint scope" 586419370Spst breakpoint at the point where we've left the scope of the watchpoint 586519370Spst expression. */ 586619370Spst if (innermost_block) 586719370Spst { 586819370Spst if (prev_frame) 586919370Spst { 587046283Sdfr struct breakpoint *scope_breakpoint; 5871130803Smarcel scope_breakpoint = create_internal_breakpoint (get_frame_pc (prev_frame), 5872130803Smarcel bp_watchpoint_scope); 587346283Sdfr 587498944Sobrien scope_breakpoint->enable_state = bp_enabled; 587519370Spst 587619370Spst /* Automatically delete the breakpoint when it hits. */ 587798944Sobrien scope_breakpoint->disposition = disp_del; 587819370Spst 587919370Spst /* Only break in the proper frame (help with recursion). */ 5880130803Smarcel scope_breakpoint->frame_id = get_frame_id (prev_frame); 588119370Spst 588219370Spst /* Set the address at which we will stop. */ 5883130803Smarcel scope_breakpoint->loc->requested_address 5884130803Smarcel = get_frame_pc (prev_frame); 5885130803Smarcel scope_breakpoint->loc->address 5886130803Smarcel = adjust_breakpoint_address (scope_breakpoint->loc->requested_address); 588719370Spst 588819370Spst /* The scope breakpoint is related to the watchpoint. We 588919370Spst will need to act on them together. */ 589019370Spst b->related_breakpoint = scope_breakpoint; 589119370Spst } 589219370Spst } 589319370Spst value_free_to_mark (mark); 589419370Spst mention (b); 589519370Spst} 589619370Spst 589719370Spst/* Return count of locations need to be watched and can be handled 589819370Spst in hardware. If the watchpoint can not be handled 589919370Spst in hardware return zero. */ 590019370Spst 590146283Sdfr#if !defined(TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT) 590298944Sobrien#define TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(BYTE_SIZE) \ 5903130803Smarcel ((BYTE_SIZE) <= (DEPRECATED_REGISTER_SIZE)) 590446283Sdfr#endif 590546283Sdfr 590698944Sobrien#if !defined(TARGET_REGION_OK_FOR_HW_WATCHPOINT) 590798944Sobrien#define TARGET_REGION_OK_FOR_HW_WATCHPOINT(ADDR,LEN) \ 590898944Sobrien (TARGET_REGION_SIZE_OK_FOR_HW_WATCHPOINT(LEN)) 590998944Sobrien#endif 591098944Sobrien 591119370Spststatic int 591298944Sobriencan_use_hardware_watchpoint (struct value *v) 591319370Spst{ 591419370Spst int found_memory_cnt = 0; 591598944Sobrien struct value *head = v; 591646283Sdfr 591746283Sdfr /* Did the user specifically forbid us to use hardware watchpoints? */ 591898944Sobrien if (!can_use_hw_watchpoints) 591946283Sdfr return 0; 592098944Sobrien 592198944Sobrien /* Make sure that the value of the expression depends only upon 592298944Sobrien memory contents, and values computed from them within GDB. If we 592398944Sobrien find any register references or function calls, we can't use a 592498944Sobrien hardware watchpoint. 592598944Sobrien 592698944Sobrien The idea here is that evaluating an expression generates a series 592798944Sobrien of values, one holding the value of every subexpression. (The 592898944Sobrien expression a*b+c has five subexpressions: a, b, a*b, c, and 592998944Sobrien a*b+c.) GDB's values hold almost enough information to establish 593098944Sobrien the criteria given above --- they identify memory lvalues, 593198944Sobrien register lvalues, computed values, etcetera. So we can evaluate 593298944Sobrien the expression, and then scan the chain of values that leaves 593398944Sobrien behind to decide whether we can detect any possible change to the 593498944Sobrien expression's final value using only hardware watchpoints. 593598944Sobrien 593698944Sobrien However, I don't think that the values returned by inferior 593798944Sobrien function calls are special in any way. So this function may not 593898944Sobrien notice that an expression involving an inferior function call 593998944Sobrien can't be watched with hardware watchpoints. FIXME. */ 594098944Sobrien for (; v; v = v->next) 594119370Spst { 594298944Sobrien if (VALUE_LVAL (v) == lval_memory) 594319370Spst { 594498944Sobrien if (VALUE_LAZY (v)) 594598944Sobrien /* A lazy memory lvalue is one that GDB never needed to fetch; 594698944Sobrien we either just used its address (e.g., `a' in `a.b') or 594798944Sobrien we never needed it at all (e.g., `a' in `a,b'). */ 594898944Sobrien ; 594998944Sobrien else 595098944Sobrien { 595198944Sobrien /* Ahh, memory we actually used! Check if we can cover 595298944Sobrien it with hardware watchpoints. */ 595398944Sobrien struct type *vtype = check_typedef (VALUE_TYPE (v)); 595498944Sobrien 595598944Sobrien /* We only watch structs and arrays if user asked for it 595698944Sobrien explicitly, never if they just happen to appear in a 595798944Sobrien middle of some value chain. */ 595898944Sobrien if (v == head 595998944Sobrien || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT 596098944Sobrien && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) 596198944Sobrien { 596298944Sobrien CORE_ADDR vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); 596398944Sobrien int len = TYPE_LENGTH (VALUE_TYPE (v)); 596498944Sobrien 596598944Sobrien if (!TARGET_REGION_OK_FOR_HW_WATCHPOINT (vaddr, len)) 596698944Sobrien return 0; 596798944Sobrien else 596898944Sobrien found_memory_cnt++; 596998944Sobrien } 597098944Sobrien } 597198944Sobrien } 597219370Spst else if (v->lval != not_lval && v->modifiable == 0) 597398944Sobrien return 0; /* ??? What does this represent? */ 597498944Sobrien else if (v->lval == lval_register) 597598944Sobrien return 0; /* cannot watch a register with a HW watchpoint */ 597619370Spst } 597719370Spst 597819370Spst /* The expression itself looks suitable for using a hardware 597919370Spst watchpoint, but give the target machine a chance to reject it. */ 598019370Spst return found_memory_cnt; 598119370Spst} 598219370Spst 598398944Sobrienvoid 598498944Sobrienwatch_command_wrapper (char *arg, int from_tty) 598519370Spst{ 598698944Sobrien watch_command (arg, from_tty); 598719370Spst} 598819370Spst 598998944Sobrienstatic void 599098944Sobrienwatch_command (char *arg, int from_tty) 599119370Spst{ 599298944Sobrien watch_command_1 (arg, hw_write, from_tty); 599319370Spst} 599419370Spst 599598944Sobrienvoid 599698944Sobrienrwatch_command_wrapper (char *arg, int from_tty) 599719370Spst{ 599898944Sobrien rwatch_command (arg, from_tty); 599919370Spst} 600019370Spst 600198944Sobrienstatic void 600298944Sobrienrwatch_command (char *arg, int from_tty) 600398944Sobrien{ 600498944Sobrien watch_command_1 (arg, hw_read, from_tty); 600598944Sobrien} 600698944Sobrien 600798944Sobrienvoid 600898944Sobrienawatch_command_wrapper (char *arg, int from_tty) 600998944Sobrien{ 601098944Sobrien awatch_command (arg, from_tty); 601198944Sobrien} 601298944Sobrien 601398944Sobrienstatic void 601498944Sobrienawatch_command (char *arg, int from_tty) 601598944Sobrien{ 601698944Sobrien watch_command_1 (arg, hw_access, from_tty); 601798944Sobrien} 601819370Spst 601998944Sobrien 602098944Sobrien/* Helper routines for the until_command routine in infcmd.c. Here 602119370Spst because it uses the mechanisms of breakpoints. */ 602219370Spst 602398944Sobrien/* This function is called by fetch_inferior_event via the 602498944Sobrien cmd_continuation pointer, to complete the until command. It takes 602598944Sobrien care of cleaning up the temporary breakpoints set up by the until 602698944Sobrien command. */ 602798944Sobrienstatic void 602898944Sobrienuntil_break_command_continuation (struct continuation_arg *arg) 602998944Sobrien{ 603098944Sobrien struct cleanup *cleanups; 603198944Sobrien 603298944Sobrien cleanups = (struct cleanup *) arg->data.pointer; 603398944Sobrien do_exec_cleanups (cleanups); 603498944Sobrien} 603598944Sobrien 603619370Spstvoid 6037130803Smarceluntil_break_command (char *arg, int from_tty, int anywhere) 603819370Spst{ 603919370Spst struct symtabs_and_lines sals; 604019370Spst struct symtab_and_line sal; 6041130803Smarcel struct frame_info *prev_frame = get_prev_frame (deprecated_selected_frame); 604219370Spst struct breakpoint *breakpoint; 604319370Spst struct cleanup *old_chain; 604498944Sobrien struct continuation_arg *arg1; 604519370Spst 604698944Sobrien 604719370Spst clear_proceed_status (); 604819370Spst 604919370Spst /* Set a breakpoint where the user wants it and at return from 605019370Spst this function */ 605198944Sobrien 605219370Spst if (default_breakpoint_valid) 605319370Spst sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, 6054130803Smarcel default_breakpoint_line, (char ***) NULL, NULL); 605519370Spst else 605698944Sobrien sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 6057130803Smarcel 0, (char ***) NULL, NULL); 605898944Sobrien 605919370Spst if (sals.nelts != 1) 606019370Spst error ("Couldn't get information on specified line."); 606198944Sobrien 606219370Spst sal = sals.sals[0]; 606398944Sobrien xfree (sals.sals); /* malloc'd, so freed */ 606498944Sobrien 606519370Spst if (*arg) 606619370Spst error ("Junk at end of arguments."); 606798944Sobrien 606819370Spst resolve_sal_pc (&sal); 606998944Sobrien 6070130803Smarcel if (anywhere) 6071130803Smarcel /* If the user told us to continue until a specified location, 6072130803Smarcel we don't specify a frame at which we need to stop. */ 6073130803Smarcel breakpoint = set_momentary_breakpoint (sal, null_frame_id, bp_until); 6074130803Smarcel else 6075130803Smarcel /* Otherwise, specify the current frame, because we want to stop only 6076130803Smarcel at the very same frame. */ 6077130803Smarcel breakpoint = set_momentary_breakpoint (sal, 6078130803Smarcel get_frame_id (deprecated_selected_frame), 6079130803Smarcel bp_until); 608019370Spst 608198944Sobrien if (!event_loop_p || !target_can_async_p ()) 608298944Sobrien old_chain = make_cleanup_delete_breakpoint (breakpoint); 608398944Sobrien else 608498944Sobrien old_chain = make_exec_cleanup_delete_breakpoint (breakpoint); 608598944Sobrien 608698944Sobrien /* If we are running asynchronously, and the target supports async 608798944Sobrien execution, we are not waiting for the target to stop, in the call 608898944Sobrien tp proceed, below. This means that we cannot delete the 608998944Sobrien brekpoints until the target has actually stopped. The only place 609098944Sobrien where we get a chance to do that is in fetch_inferior_event, so 609198944Sobrien we must set things up for that. */ 609298944Sobrien 609398944Sobrien if (event_loop_p && target_can_async_p ()) 609498944Sobrien { 609598944Sobrien /* In this case the arg for the continuation is just the point 609698944Sobrien in the exec_cleanups chain from where to start doing 609798944Sobrien cleanups, because all the continuation does is the cleanups in 609898944Sobrien the exec_cleanup_chain. */ 609998944Sobrien arg1 = 610098944Sobrien (struct continuation_arg *) xmalloc (sizeof (struct continuation_arg)); 610198944Sobrien arg1->next = NULL; 610298944Sobrien arg1->data.pointer = old_chain; 610398944Sobrien 610498944Sobrien add_continuation (until_break_command_continuation, arg1); 610598944Sobrien } 610698944Sobrien 6107130803Smarcel /* Keep within the current frame, or in frames called by the current 6108130803Smarcel one. */ 610919370Spst if (prev_frame) 611019370Spst { 6111130803Smarcel sal = find_pc_line (get_frame_pc (prev_frame), 0); 6112130803Smarcel sal.pc = get_frame_pc (prev_frame); 6113130803Smarcel breakpoint = set_momentary_breakpoint (sal, get_frame_id (prev_frame), 6114130803Smarcel bp_until); 611598944Sobrien if (!event_loop_p || !target_can_async_p ()) 611698944Sobrien make_cleanup_delete_breakpoint (breakpoint); 611798944Sobrien else 611898944Sobrien make_exec_cleanup_delete_breakpoint (breakpoint); 611919370Spst } 612098944Sobrien 612119370Spst proceed (-1, TARGET_SIGNAL_DEFAULT, 0); 612298944Sobrien /* Do the cleanups now, anly if we are not running asynchronously, 612398944Sobrien of if we are, but the target is still synchronous. */ 612498944Sobrien if (!event_loop_p || !target_can_async_p ()) 612598944Sobrien do_cleanups (old_chain); 612619370Spst} 612719370Spst 612846283Sdfrstatic void 612998944Sobrienep_skip_leading_whitespace (char **s) 613046283Sdfr{ 613198944Sobrien if ((s == NULL) || (*s == NULL)) 613298944Sobrien return; 613398944Sobrien while (isspace (**s)) 613498944Sobrien *s += 1; 613546283Sdfr} 613698944Sobrien 613746283Sdfr/* This function examines a string, and attempts to find a token 613846283Sdfr that might be an event name in the leading characters. If a 613946283Sdfr possible match is found, a pointer to the last character of 614046283Sdfr the token is returned. Else, NULL is returned. */ 614198944Sobrien 614246283Sdfrstatic char * 614398944Sobrienep_find_event_name_end (char *arg) 614446283Sdfr{ 614598944Sobrien char *s = arg; 614698944Sobrien char *event_name_end = NULL; 614798944Sobrien 614846283Sdfr /* If we could depend upon the presense of strrpbrk, we'd use that... */ 614946283Sdfr if (arg == NULL) 615046283Sdfr return NULL; 615198944Sobrien 615246283Sdfr /* We break out of the loop when we find a token delimiter. 615398944Sobrien Basically, we're looking for alphanumerics and underscores; 615498944Sobrien anything else delimites the token. */ 615546283Sdfr while (*s != '\0') 615646283Sdfr { 615798944Sobrien if (!isalnum (*s) && (*s != '_')) 615898944Sobrien break; 615946283Sdfr event_name_end = s; 616046283Sdfr s++; 616146283Sdfr } 616298944Sobrien 616346283Sdfr return event_name_end; 616446283Sdfr} 616546283Sdfr 616698944Sobrien 616746283Sdfr/* This function attempts to parse an optional "if <cond>" clause 616846283Sdfr from the arg string. If one is not found, it returns NULL. 616998944Sobrien 617046283Sdfr Else, it returns a pointer to the condition string. (It does not 617146283Sdfr attempt to evaluate the string against a particular block.) And, 617246283Sdfr it updates arg to point to the first character following the parsed 617346283Sdfr if clause in the arg string. */ 617498944Sobrien 617546283Sdfrstatic char * 617698944Sobrienep_parse_optional_if_clause (char **arg) 617746283Sdfr{ 617898944Sobrien char *cond_string; 617998944Sobrien 618098944Sobrien if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) 618146283Sdfr return NULL; 618298944Sobrien 618346283Sdfr /* Skip the "if" keyword. */ 618446283Sdfr (*arg) += 2; 618598944Sobrien 618646283Sdfr /* Skip any extra leading whitespace, and record the start of the 618746283Sdfr condition string. */ 618846283Sdfr ep_skip_leading_whitespace (arg); 618946283Sdfr cond_string = *arg; 619098944Sobrien 619146283Sdfr /* Assume that the condition occupies the remainder of the arg string. */ 619246283Sdfr (*arg) += strlen (cond_string); 619398944Sobrien 619446283Sdfr return cond_string; 619546283Sdfr} 619698944Sobrien 619746283Sdfr/* This function attempts to parse an optional filename from the arg 619846283Sdfr string. If one is not found, it returns NULL. 619998944Sobrien 620046283Sdfr Else, it returns a pointer to the parsed filename. (This function 620146283Sdfr makes no attempt to verify that a file of that name exists, or is 620246283Sdfr accessible.) And, it updates arg to point to the first character 620346283Sdfr following the parsed filename in the arg string. 620498944Sobrien 620546283Sdfr Note that clients needing to preserve the returned filename for 620646283Sdfr future access should copy it to their own buffers. */ 620746283Sdfrstatic char * 620898944Sobrienep_parse_optional_filename (char **arg) 620946283Sdfr{ 621098944Sobrien static char filename[1024]; 621198944Sobrien char *arg_p = *arg; 621298944Sobrien int i; 621398944Sobrien char c; 621498944Sobrien 621546283Sdfr if ((*arg_p == '\0') || isspace (*arg_p)) 621646283Sdfr return NULL; 621798944Sobrien 621898944Sobrien for (i = 0;; i++) 621946283Sdfr { 622046283Sdfr c = *arg_p; 622146283Sdfr if (isspace (c)) 622298944Sobrien c = '\0'; 622346283Sdfr filename[i] = c; 622446283Sdfr if (c == '\0') 622598944Sobrien break; 622646283Sdfr arg_p++; 622746283Sdfr } 622846283Sdfr *arg = arg_p; 622998944Sobrien 623046283Sdfr return filename; 623146283Sdfr} 623298944Sobrien 623346283Sdfr/* Commands to deal with catching events, such as signals, exceptions, 623446283Sdfr process start/exit, etc. */ 623598944Sobrien 623698944Sobrientypedef enum 623798944Sobrien{ 623898944Sobrien catch_fork, catch_vfork 623998944Sobrien} 624098944Sobriencatch_fork_kind; 624198944Sobrien 624246283Sdfrstatic void 624398944Sobriencatch_fork_command_1 (catch_fork_kind fork_kind, char *arg, int tempflag, 624498944Sobrien int from_tty) 624546283Sdfr{ 624698944Sobrien char *cond_string = NULL; 624798944Sobrien 624846283Sdfr ep_skip_leading_whitespace (&arg); 624998944Sobrien 625046283Sdfr /* The allowed syntax is: 625198944Sobrien catch [v]fork 625298944Sobrien catch [v]fork if <cond> 625398944Sobrien 625446283Sdfr First, check if there's an if clause. */ 625546283Sdfr cond_string = ep_parse_optional_if_clause (&arg); 625698944Sobrien 625746283Sdfr if ((*arg != '\0') && !isspace (*arg)) 625846283Sdfr error ("Junk at end of arguments."); 625998944Sobrien 626046283Sdfr /* If this target supports it, create a fork or vfork catchpoint 626146283Sdfr and enable reporting of such events. */ 626298944Sobrien switch (fork_kind) 626398944Sobrien { 626498944Sobrien case catch_fork: 626546283Sdfr create_fork_event_catchpoint (tempflag, cond_string); 626646283Sdfr break; 626798944Sobrien case catch_vfork: 626846283Sdfr create_vfork_event_catchpoint (tempflag, cond_string); 626946283Sdfr break; 627098944Sobrien default: 627146283Sdfr error ("unsupported or unknown fork kind; cannot catch it"); 627246283Sdfr break; 627398944Sobrien } 627446283Sdfr} 627546283Sdfr 627646283Sdfrstatic void 627798944Sobriencatch_exec_command_1 (char *arg, int tempflag, int from_tty) 627846283Sdfr{ 627998944Sobrien char *cond_string = NULL; 628046283Sdfr 628146283Sdfr ep_skip_leading_whitespace (&arg); 628246283Sdfr 628346283Sdfr /* The allowed syntax is: 628498944Sobrien catch exec 628598944Sobrien catch exec if <cond> 628646283Sdfr 628746283Sdfr First, check if there's an if clause. */ 628846283Sdfr cond_string = ep_parse_optional_if_clause (&arg); 628946283Sdfr 629046283Sdfr if ((*arg != '\0') && !isspace (*arg)) 629146283Sdfr error ("Junk at end of arguments."); 629246283Sdfr 629346283Sdfr /* If this target supports it, create an exec catchpoint 629446283Sdfr and enable reporting of such events. */ 629546283Sdfr create_exec_event_catchpoint (tempflag, cond_string); 629646283Sdfr} 629798944Sobrien 629846283Sdfrstatic void 629998944Sobriencatch_load_command_1 (char *arg, int tempflag, int from_tty) 630046283Sdfr{ 630198944Sobrien char *dll_pathname = NULL; 630298944Sobrien char *cond_string = NULL; 630398944Sobrien 630446283Sdfr ep_skip_leading_whitespace (&arg); 630598944Sobrien 630646283Sdfr /* The allowed syntax is: 630798944Sobrien catch load 630898944Sobrien catch load if <cond> 630998944Sobrien catch load <filename> 631098944Sobrien catch load <filename> if <cond> 631198944Sobrien 631246283Sdfr The user is not allowed to specify the <filename> after an 631346283Sdfr if clause. 631498944Sobrien 631546283Sdfr We'll ignore the pathological case of a file named "if". 631698944Sobrien 631746283Sdfr First, check if there's an if clause. If so, then there 631846283Sdfr cannot be a filename. */ 631946283Sdfr cond_string = ep_parse_optional_if_clause (&arg); 632098944Sobrien 632146283Sdfr /* If there was an if clause, then there cannot be a filename. 632246283Sdfr Else, there might be a filename and an if clause. */ 632346283Sdfr if (cond_string == NULL) 632446283Sdfr { 632546283Sdfr dll_pathname = ep_parse_optional_filename (&arg); 632646283Sdfr ep_skip_leading_whitespace (&arg); 632746283Sdfr cond_string = ep_parse_optional_if_clause (&arg); 632846283Sdfr } 632998944Sobrien 633046283Sdfr if ((*arg != '\0') && !isspace (*arg)) 633146283Sdfr error ("Junk at end of arguments."); 633298944Sobrien 633346283Sdfr /* Create a load breakpoint that only triggers when a load of 633446283Sdfr the specified dll (or any dll, if no pathname was specified) 633546283Sdfr occurs. */ 633698944Sobrien SOLIB_CREATE_CATCH_LOAD_HOOK (PIDGET (inferior_ptid), tempflag, 633798944Sobrien dll_pathname, cond_string); 633846283Sdfr} 633998944Sobrien 634046283Sdfrstatic void 634198944Sobriencatch_unload_command_1 (char *arg, int tempflag, int from_tty) 634246283Sdfr{ 634398944Sobrien char *dll_pathname = NULL; 634498944Sobrien char *cond_string = NULL; 634598944Sobrien 634646283Sdfr ep_skip_leading_whitespace (&arg); 634798944Sobrien 634846283Sdfr /* The allowed syntax is: 634998944Sobrien catch unload 635098944Sobrien catch unload if <cond> 635198944Sobrien catch unload <filename> 635298944Sobrien catch unload <filename> if <cond> 635398944Sobrien 635446283Sdfr The user is not allowed to specify the <filename> after an 635546283Sdfr if clause. 635698944Sobrien 635746283Sdfr We'll ignore the pathological case of a file named "if". 635898944Sobrien 635946283Sdfr First, check if there's an if clause. If so, then there 636046283Sdfr cannot be a filename. */ 636146283Sdfr cond_string = ep_parse_optional_if_clause (&arg); 636298944Sobrien 636346283Sdfr /* If there was an if clause, then there cannot be a filename. 636446283Sdfr Else, there might be a filename and an if clause. */ 636546283Sdfr if (cond_string == NULL) 636646283Sdfr { 636746283Sdfr dll_pathname = ep_parse_optional_filename (&arg); 636846283Sdfr ep_skip_leading_whitespace (&arg); 636946283Sdfr cond_string = ep_parse_optional_if_clause (&arg); 637046283Sdfr } 637198944Sobrien 637246283Sdfr if ((*arg != '\0') && !isspace (*arg)) 637346283Sdfr error ("Junk at end of arguments."); 637498944Sobrien 637546283Sdfr /* Create an unload breakpoint that only triggers when an unload of 637646283Sdfr the specified dll (or any dll, if no pathname was specified) 637746283Sdfr occurs. */ 637898944Sobrien SOLIB_CREATE_CATCH_UNLOAD_HOOK (PIDGET (inferior_ptid), tempflag, 637998944Sobrien dll_pathname, cond_string); 638046283Sdfr} 638146283Sdfr 638219370Spst/* Commands to deal with catching exceptions. */ 638319370Spst 638446283Sdfr/* Set a breakpoint at the specified callback routine for an 638598944Sobrien exception event callback */ 638646283Sdfr 638719370Spststatic void 638898944Sobriencreate_exception_catchpoint (int tempflag, char *cond_string, 638998944Sobrien enum exception_event_kind ex_event, 639098944Sobrien struct symtab_and_line *sal) 639146283Sdfr{ 639298944Sobrien struct breakpoint *b; 639398944Sobrien int thread = -1; /* All threads. */ 639498944Sobrien enum bptype bptype; 639546283Sdfr 639698944Sobrien if (!sal) /* no exception support? */ 639746283Sdfr return; 639846283Sdfr 639998944Sobrien switch (ex_event) 640098944Sobrien { 640198944Sobrien case EX_EVENT_THROW: 640298944Sobrien bptype = bp_catch_throw; 640398944Sobrien break; 640498944Sobrien case EX_EVENT_CATCH: 640598944Sobrien bptype = bp_catch_catch; 640698944Sobrien break; 640798944Sobrien default: /* error condition */ 640898944Sobrien error ("Internal error -- invalid catchpoint kind"); 640998944Sobrien } 641098944Sobrien 641198944Sobrien b = set_raw_breakpoint (*sal, bptype); 641246283Sdfr set_breakpoint_count (breakpoint_count + 1); 641346283Sdfr b->number = breakpoint_count; 641446283Sdfr b->cond = NULL; 641598944Sobrien b->cond_string = (cond_string == NULL) ? 641698944Sobrien NULL : savestring (cond_string, strlen (cond_string)); 641746283Sdfr b->thread = thread; 641846283Sdfr b->addr_string = NULL; 641998944Sobrien b->enable_state = bp_enabled; 642098944Sobrien b->disposition = tempflag ? disp_del : disp_donttouch; 642146283Sdfr mention (b); 642246283Sdfr} 642346283Sdfr 6424130803Smarcelstatic enum print_stop_action 6425130803Smarcelprint_exception_catchpoint (struct breakpoint *b) 6426130803Smarcel{ 6427130803Smarcel annotate_catchpoint (b->number); 6428130803Smarcel 6429130803Smarcel if (strstr (b->addr_string, "throw") != NULL) 6430130803Smarcel printf_filtered ("\nCatchpoint %d (exception thrown)\n", 6431130803Smarcel b->number); 6432130803Smarcel else 6433130803Smarcel printf_filtered ("\nCatchpoint %d (exception caught)\n", 6434130803Smarcel b->number); 6435130803Smarcel 6436130803Smarcel return PRINT_SRC_AND_LOC; 6437130803Smarcel} 6438130803Smarcel 6439130803Smarcelstatic void 6440130803Smarcelprint_one_exception_catchpoint (struct breakpoint *b, CORE_ADDR *last_addr) 6441130803Smarcel{ 6442130803Smarcel if (addressprint) 6443130803Smarcel { 6444130803Smarcel annotate_field (4); 6445130803Smarcel ui_out_field_core_addr (uiout, "addr", b->loc->address); 6446130803Smarcel } 6447130803Smarcel annotate_field (5); 6448130803Smarcel *last_addr = b->loc->address; 6449130803Smarcel if (strstr (b->addr_string, "throw") != NULL) 6450130803Smarcel ui_out_field_string (uiout, "what", "exception throw"); 6451130803Smarcel else 6452130803Smarcel ui_out_field_string (uiout, "what", "exception catch"); 6453130803Smarcel} 6454130803Smarcel 6455130803Smarcelstatic void 6456130803Smarcelprint_mention_exception_catchpoint (struct breakpoint *b) 6457130803Smarcel{ 6458130803Smarcel if (strstr (b->addr_string, "throw") != NULL) 6459130803Smarcel printf_filtered ("Catchpoint %d (throw)", b->number); 6460130803Smarcel else 6461130803Smarcel printf_filtered ("Catchpoint %d (catch)", b->number); 6462130803Smarcel} 6463130803Smarcel 6464130803Smarcelstatic struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { 6465130803Smarcel print_exception_catchpoint, 6466130803Smarcel print_one_exception_catchpoint, 6467130803Smarcel print_mention_exception_catchpoint 6468130803Smarcel}; 6469130803Smarcel 6470130803Smarcelstatic int 6471130803Smarcelhandle_gnu_v3_exceptions (int tempflag, char *cond_string, 6472130803Smarcel enum exception_event_kind ex_event, int from_tty) 6473130803Smarcel{ 6474130803Smarcel char *trigger_func_name, *nameptr; 6475130803Smarcel struct symtabs_and_lines sals; 6476130803Smarcel struct breakpoint *b; 6477130803Smarcel 6478130803Smarcel if (ex_event == EX_EVENT_CATCH) 6479130803Smarcel trigger_func_name = xstrdup ("__cxa_begin_catch"); 6480130803Smarcel else 6481130803Smarcel trigger_func_name = xstrdup ("__cxa_throw"); 6482130803Smarcel 6483130803Smarcel nameptr = trigger_func_name; 6484130803Smarcel sals = decode_line_1 (&nameptr, 1, NULL, 0, NULL, NULL); 6485130803Smarcel if (sals.nelts == 0) 6486130803Smarcel { 6487130803Smarcel xfree (trigger_func_name); 6488130803Smarcel return 0; 6489130803Smarcel } 6490130803Smarcel 6491130803Smarcel b = set_raw_breakpoint (sals.sals[0], bp_breakpoint); 6492130803Smarcel set_breakpoint_count (breakpoint_count + 1); 6493130803Smarcel b->number = breakpoint_count; 6494130803Smarcel b->cond = NULL; 6495130803Smarcel b->cond_string = (cond_string == NULL) ? 6496130803Smarcel NULL : savestring (cond_string, strlen (cond_string)); 6497130803Smarcel b->thread = -1; 6498130803Smarcel b->addr_string = trigger_func_name; 6499130803Smarcel b->enable_state = bp_enabled; 6500130803Smarcel b->disposition = tempflag ? disp_del : disp_donttouch; 6501130803Smarcel b->ops = &gnu_v3_exception_catchpoint_ops; 6502130803Smarcel 6503130803Smarcel xfree (sals.sals); 6504130803Smarcel mention (b); 6505130803Smarcel return 1; 6506130803Smarcel} 6507130803Smarcel 650898944Sobrien/* Deal with "catch catch" and "catch throw" commands */ 650946283Sdfr 651046283Sdfrstatic void 651198944Sobriencatch_exception_command_1 (enum exception_event_kind ex_event, char *arg, 651298944Sobrien int tempflag, int from_tty) 651346283Sdfr{ 651498944Sobrien char *cond_string = NULL; 651598944Sobrien struct symtab_and_line *sal = NULL; 651698944Sobrien 651746283Sdfr ep_skip_leading_whitespace (&arg); 651898944Sobrien 651946283Sdfr cond_string = ep_parse_optional_if_clause (&arg); 652046283Sdfr 652146283Sdfr if ((*arg != '\0') && !isspace (*arg)) 652246283Sdfr error ("Junk at end of arguments."); 652346283Sdfr 652446283Sdfr if ((ex_event != EX_EVENT_THROW) && 652546283Sdfr (ex_event != EX_EVENT_CATCH)) 652646283Sdfr error ("Unsupported or unknown exception event; cannot catch it"); 652746283Sdfr 6528130803Smarcel if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) 6529130803Smarcel return; 6530130803Smarcel 653146283Sdfr /* See if we can find a callback routine */ 653246283Sdfr sal = target_enable_exception_callback (ex_event, 1); 653346283Sdfr 653498944Sobrien if (sal) 653546283Sdfr { 653646283Sdfr /* We have callbacks from the runtime system for exceptions. 653798944Sobrien Set a breakpoint on the sal found, if no errors */ 653846283Sdfr if (sal != (struct symtab_and_line *) -1) 653998944Sobrien create_exception_catchpoint (tempflag, cond_string, ex_event, sal); 654046283Sdfr else 654198944Sobrien return; /* something went wrong with setting up callbacks */ 654246283Sdfr } 654398944Sobrien 6544130803Smarcel warning ("Unsupported with this platform/compiler combination."); 654546283Sdfr} 654646283Sdfr 654746283Sdfr/* Cover routine to allow wrapping target_enable_exception_catchpoints 654846283Sdfr inside a catch_errors */ 654946283Sdfr 655046283Sdfrstatic int 6551130803Smarcelcover_target_enable_exception_callback (void *arg) 655246283Sdfr{ 655346283Sdfr args_for_catchpoint_enable *args = arg; 655446283Sdfr struct symtab_and_line *sal; 655598944Sobrien sal = target_enable_exception_callback (args->kind, args->enable_p); 655646283Sdfr if (sal == NULL) 655746283Sdfr return 0; 655846283Sdfr else if (sal == (struct symtab_and_line *) -1) 655946283Sdfr return -1; 656046283Sdfr else 656198944Sobrien return 1; /*is valid */ 656246283Sdfr} 656346283Sdfr 656446283Sdfrstatic void 656598944Sobriencatch_command_1 (char *arg, int tempflag, int from_tty) 656646283Sdfr{ 656746283Sdfr 656846283Sdfr /* The first argument may be an event name, such as "start" or "load". 656946283Sdfr If so, then handle it as such. If it doesn't match an event name, 657046283Sdfr then attempt to interpret it as an exception name. (This latter is 657146283Sdfr the v4.16-and-earlier GDB meaning of the "catch" command.) 657298944Sobrien 657346283Sdfr First, try to find the bounds of what might be an event name. */ 657498944Sobrien char *arg1_start = arg; 657598944Sobrien char *arg1_end; 657698944Sobrien int arg1_length; 657798944Sobrien 657846283Sdfr if (arg1_start == NULL) 657946283Sdfr { 658098944Sobrien /* Old behaviour was to use pre-v-4.16 syntax */ 658146283Sdfr /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */ 658246283Sdfr /* return; */ 658398944Sobrien /* Now, this is not allowed */ 658446283Sdfr error ("Catch requires an event name."); 658546283Sdfr 658646283Sdfr } 658746283Sdfr arg1_end = ep_find_event_name_end (arg1_start); 658846283Sdfr if (arg1_end == NULL) 658946283Sdfr error ("catch requires an event"); 659046283Sdfr arg1_length = arg1_end + 1 - arg1_start; 659198944Sobrien 659246283Sdfr /* Try to match what we found against known event names. */ 659346283Sdfr if (strncmp (arg1_start, "signal", arg1_length) == 0) 659446283Sdfr { 659546283Sdfr error ("Catch of signal not yet implemented"); 659646283Sdfr } 659746283Sdfr else if (strncmp (arg1_start, "catch", arg1_length) == 0) 659846283Sdfr { 659998944Sobrien catch_exception_command_1 (EX_EVENT_CATCH, arg1_end + 1, 660098944Sobrien tempflag, from_tty); 660146283Sdfr } 660246283Sdfr else if (strncmp (arg1_start, "throw", arg1_length) == 0) 660346283Sdfr { 660498944Sobrien catch_exception_command_1 (EX_EVENT_THROW, arg1_end + 1, 660598944Sobrien tempflag, from_tty); 660646283Sdfr } 660746283Sdfr else if (strncmp (arg1_start, "thread_start", arg1_length) == 0) 660846283Sdfr { 660946283Sdfr error ("Catch of thread_start not yet implemented"); 661046283Sdfr } 661146283Sdfr else if (strncmp (arg1_start, "thread_exit", arg1_length) == 0) 661246283Sdfr { 661346283Sdfr error ("Catch of thread_exit not yet implemented"); 661446283Sdfr } 661546283Sdfr else if (strncmp (arg1_start, "thread_join", arg1_length) == 0) 661646283Sdfr { 661746283Sdfr error ("Catch of thread_join not yet implemented"); 661846283Sdfr } 661946283Sdfr else if (strncmp (arg1_start, "start", arg1_length) == 0) 662046283Sdfr { 662146283Sdfr error ("Catch of start not yet implemented"); 662246283Sdfr } 662346283Sdfr else if (strncmp (arg1_start, "exit", arg1_length) == 0) 662446283Sdfr { 662546283Sdfr error ("Catch of exit not yet implemented"); 662646283Sdfr } 662746283Sdfr else if (strncmp (arg1_start, "fork", arg1_length) == 0) 662846283Sdfr { 662998944Sobrien catch_fork_command_1 (catch_fork, arg1_end + 1, tempflag, from_tty); 663046283Sdfr } 663146283Sdfr else if (strncmp (arg1_start, "vfork", arg1_length) == 0) 663246283Sdfr { 663398944Sobrien catch_fork_command_1 (catch_vfork, arg1_end + 1, tempflag, from_tty); 663446283Sdfr } 663546283Sdfr else if (strncmp (arg1_start, "exec", arg1_length) == 0) 663646283Sdfr { 663798944Sobrien catch_exec_command_1 (arg1_end + 1, tempflag, from_tty); 663846283Sdfr } 663946283Sdfr else if (strncmp (arg1_start, "load", arg1_length) == 0) 664046283Sdfr { 664198944Sobrien catch_load_command_1 (arg1_end + 1, tempflag, from_tty); 664246283Sdfr } 664346283Sdfr else if (strncmp (arg1_start, "unload", arg1_length) == 0) 664446283Sdfr { 664598944Sobrien catch_unload_command_1 (arg1_end + 1, tempflag, from_tty); 664646283Sdfr } 664746283Sdfr else if (strncmp (arg1_start, "stop", arg1_length) == 0) 664846283Sdfr { 664946283Sdfr error ("Catch of stop not yet implemented"); 665046283Sdfr } 665198944Sobrien 665246283Sdfr /* This doesn't appear to be an event name */ 665346283Sdfr 665446283Sdfr else 665546283Sdfr { 665646283Sdfr /* Pre-v.4.16 behaviour was to treat the argument 665798944Sobrien as the name of an exception */ 665846283Sdfr /* catch_throw_command_1 (arg1_start, tempflag, from_tty); */ 665998944Sobrien /* Now this is not allowed */ 666046283Sdfr error ("Unknown event kind specified for catch"); 666146283Sdfr 666246283Sdfr } 666346283Sdfr} 666446283Sdfr 666519370Spst/* Used by the gui, could be made a worker for other things. */ 666619370Spst 666719370Spststruct breakpoint * 666898944Sobrienset_breakpoint_sal (struct symtab_and_line sal) 666919370Spst{ 667019370Spst struct breakpoint *b; 667198944Sobrien b = set_raw_breakpoint (sal, bp_breakpoint); 667219370Spst set_breakpoint_count (breakpoint_count + 1); 667319370Spst b->number = breakpoint_count; 667419370Spst b->cond = 0; 667519370Spst b->thread = -1; 667619370Spst return b; 667719370Spst} 667819370Spst 667919370Spststatic void 668098944Sobriencatch_command (char *arg, int from_tty) 668119370Spst{ 668219370Spst catch_command_1 (arg, 0, from_tty); 668319370Spst} 668419370Spst 668546283Sdfr 668619370Spststatic void 668798944Sobrientcatch_command (char *arg, int from_tty) 668846283Sdfr{ 668946283Sdfr catch_command_1 (arg, 1, from_tty); 669046283Sdfr} 669146283Sdfr 6692130803Smarcel/* Delete breakpoints by address or line. */ 669346283Sdfr 669446283Sdfrstatic void 669598944Sobrienclear_command (char *arg, int from_tty) 669619370Spst{ 6697130803Smarcel struct breakpoint *b, *tmp, *prev, *found; 669846283Sdfr int default_match; 669919370Spst struct symtabs_and_lines sals; 670019370Spst struct symtab_and_line sal; 670119370Spst int i; 670219370Spst 670319370Spst if (arg) 670419370Spst { 670519370Spst sals = decode_line_spec (arg, 1); 670646283Sdfr default_match = 0; 670719370Spst } 670819370Spst else 670919370Spst { 671098944Sobrien sals.sals = (struct symtab_and_line *) 671146283Sdfr xmalloc (sizeof (struct symtab_and_line)); 6712130803Smarcel make_cleanup (xfree, sals.sals); 6713130803Smarcel init_sal (&sal); /* initialize to zeroes */ 671419370Spst sal.line = default_breakpoint_line; 671519370Spst sal.symtab = default_breakpoint_symtab; 671646283Sdfr sal.pc = default_breakpoint_address; 671719370Spst if (sal.symtab == 0) 671819370Spst error ("No source file specified."); 671919370Spst 672019370Spst sals.sals[0] = sal; 672119370Spst sals.nelts = 1; 672246283Sdfr 672346283Sdfr default_match = 1; 672419370Spst } 672519370Spst 672646283Sdfr /* For each line spec given, delete bps which correspond 6727130803Smarcel to it. Do it in two passes, solely to preserve the current 6728130803Smarcel behavior that from_tty is forced true if we delete more than 6729130803Smarcel one breakpoint. */ 673046283Sdfr 6731130803Smarcel found = NULL; 673219370Spst for (i = 0; i < sals.nelts; i++) 673319370Spst { 673419370Spst /* If exact pc given, clear bpts at that pc. 673598944Sobrien If line given (pc == 0), clear all bpts on specified line. 673698944Sobrien If defaulting, clear all bpts on default line 673746283Sdfr or at default pc. 673846283Sdfr 673998944Sobrien defaulting sal.pc != 0 tests to do 674098944Sobrien 674198944Sobrien 0 1 pc 674298944Sobrien 1 1 pc _and_ line 674398944Sobrien 0 0 line 674498944Sobrien 1 0 <can't happen> */ 674598944Sobrien 674619370Spst sal = sals.sals[i]; 6747130803Smarcel prev = NULL; 674846283Sdfr 6749130803Smarcel /* Find all matching breakpoints, remove them from the 6750130803Smarcel breakpoint chain, and add them to the 'found' chain. */ 6751130803Smarcel ALL_BREAKPOINTS_SAFE (b, tmp) 675219370Spst { 6753130803Smarcel /* Are we going to delete b? */ 6754130803Smarcel if (b->type != bp_none 6755130803Smarcel && b->type != bp_watchpoint 6756130803Smarcel && b->type != bp_hardware_watchpoint 6757130803Smarcel && b->type != bp_read_watchpoint 6758130803Smarcel && b->type != bp_access_watchpoint 6759130803Smarcel /* Not if b is a watchpoint of any sort... */ 6760130803Smarcel && (((sal.pc && (b->loc->address == sal.pc)) 6761130803Smarcel && (!section_is_overlay (b->loc->section) 6762130803Smarcel || b->loc->section == sal.section)) 6763130803Smarcel /* Yes, if sal.pc matches b (modulo overlays). */ 6764130803Smarcel || ((default_match || (0 == sal.pc)) 6765130803Smarcel && b->source_file != NULL 6766130803Smarcel && sal.symtab != NULL 6767130803Smarcel && strcmp (b->source_file, sal.symtab->filename) == 0 6768130803Smarcel && b->line_number == sal.line))) 6769130803Smarcel /* Yes, if sal source file and line matches b. */ 6770130803Smarcel { 6771130803Smarcel /* Remove it from breakpoint_chain... */ 6772130803Smarcel if (b == breakpoint_chain) 6773130803Smarcel { 6774130803Smarcel /* b is at the head of the list */ 6775130803Smarcel breakpoint_chain = b->next; 6776130803Smarcel } 6777130803Smarcel else 6778130803Smarcel { 6779130803Smarcel prev->next = b->next; 6780130803Smarcel } 6781130803Smarcel /* And add it to 'found' chain. */ 6782130803Smarcel b->next = found; 6783130803Smarcel found = b; 6784130803Smarcel } 678519370Spst else 6786130803Smarcel { 6787130803Smarcel /* Keep b, and keep a pointer to it. */ 6788130803Smarcel prev = b; 6789130803Smarcel } 679019370Spst } 6791130803Smarcel } 6792130803Smarcel /* Now go thru the 'found' chain and delete them. */ 6793130803Smarcel if (found == 0) 6794130803Smarcel { 6795130803Smarcel if (arg) 6796130803Smarcel error ("No breakpoint at %s.", arg); 6797130803Smarcel else 6798130803Smarcel error ("No breakpoint at this line."); 6799130803Smarcel } 680019370Spst 6801130803Smarcel if (found->next) 6802130803Smarcel from_tty = 1; /* Always report if deleted more than one */ 6803130803Smarcel if (from_tty) 6804130803Smarcel printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : ""); 6805130803Smarcel breakpoints_changed (); 6806130803Smarcel while (found) 6807130803Smarcel { 680898944Sobrien if (from_tty) 6809130803Smarcel printf_unfiltered ("%d ", found->number); 6810130803Smarcel tmp = found->next; 6811130803Smarcel delete_breakpoint (found); 6812130803Smarcel found = tmp; 681319370Spst } 6814130803Smarcel if (from_tty) 6815130803Smarcel putchar_unfiltered ('\n'); 681619370Spst} 681719370Spst 681846283Sdfr/* Delete breakpoint in BS if they are `delete' breakpoints and 681946283Sdfr all breakpoints that are marked for deletion, whether hit or not. 682019370Spst This is called after any breakpoint is hit, or after errors. */ 682119370Spst 682219370Spstvoid 682398944Sobrienbreakpoint_auto_delete (bpstat bs) 682419370Spst{ 682546283Sdfr struct breakpoint *b, *temp; 682646283Sdfr 682719370Spst for (; bs; bs = bs->next) 682898944Sobrien if (bs->breakpoint_at && bs->breakpoint_at->disposition == disp_del 682919370Spst && bs->stop) 683019370Spst delete_breakpoint (bs->breakpoint_at); 683146283Sdfr 683246283Sdfr ALL_BREAKPOINTS_SAFE (b, temp) 683398944Sobrien { 683498944Sobrien if (b->disposition == disp_del_at_next_stop) 683598944Sobrien delete_breakpoint (b); 683698944Sobrien } 683719370Spst} 683819370Spst 683998944Sobrien/* Delete a breakpoint and clean up all traces of it in the data 684098944Sobrien structures. */ 684119370Spst 684219370Spstvoid 684398944Sobriendelete_breakpoint (struct breakpoint *bpt) 684419370Spst{ 6845130803Smarcel struct breakpoint *b; 6846130803Smarcel bpstat bs; 6847130803Smarcel struct bp_location *loc; 684819370Spst 684946283Sdfr if (bpt == NULL) 685046283Sdfr error ("Internal error (attempted to delete a NULL breakpoint)"); 685146283Sdfr 685246283Sdfr 685346283Sdfr /* Has this bp already been deleted? This can happen because multiple 685446283Sdfr lists can hold pointers to bp's. bpstat lists are especial culprits. 685546283Sdfr 685646283Sdfr One example of this happening is a watchpoint's scope bp. When the 685746283Sdfr scope bp triggers, we notice that the watchpoint is out of scope, and 685846283Sdfr delete it. We also delete its scope bp. But the scope bp is marked 685946283Sdfr "auto-deleting", and is already on a bpstat. That bpstat is then 686046283Sdfr checked for auto-deleting bp's, which are deleted. 686146283Sdfr 686246283Sdfr A real solution to this problem might involve reference counts in bp's, 686346283Sdfr and/or giving them pointers back to their referencing bpstat's, and 686446283Sdfr teaching delete_breakpoint to only free a bp's storage when no more 686546283Sdfr references were extent. A cheaper bandaid was chosen. */ 686646283Sdfr if (bpt->type == bp_none) 686746283Sdfr return; 686846283Sdfr 686919370Spst if (delete_breakpoint_hook) 687019370Spst delete_breakpoint_hook (bpt); 687198944Sobrien breakpoint_delete_event (bpt->number); 687219370Spst 6873130803Smarcel if (bpt->loc->inserted) 6874130803Smarcel remove_breakpoint (bpt->loc, mark_inserted); 687598944Sobrien 687619370Spst if (breakpoint_chain == bpt) 687719370Spst breakpoint_chain = bpt->next; 687819370Spst 6879130803Smarcel if (bp_location_chain == bpt->loc) 6880130803Smarcel bp_location_chain = bpt->loc->next; 6881130803Smarcel 688246283Sdfr /* If we have callback-style exception catchpoints, don't go through 688346283Sdfr the adjustments to the C++ runtime library etc. if the inferior 688446283Sdfr isn't actually running. target_enable_exception_callback for a 688546283Sdfr null target ops vector gives an undesirable error message, so we 688646283Sdfr check here and avoid it. Since currently (1997-09-17) only HP-UX aCC's 688798944Sobrien exceptions are supported in this way, it's OK for now. FIXME */ 688846283Sdfr if (ep_is_exception_catchpoint (bpt) && target_has_execution) 688946283Sdfr { 6890130803Smarcel /* Format possible error msg */ 6891130803Smarcel char *message = xstrprintf ("Error in deleting catchpoint %d:\n", 6892130803Smarcel bpt->number); 6893130803Smarcel struct cleanup *cleanups = make_cleanup (xfree, message); 689446283Sdfr args_for_catchpoint_enable args; 689598944Sobrien args.kind = bpt->type == bp_catch_catch ? 689698944Sobrien EX_EVENT_CATCH : EX_EVENT_THROW; 689798944Sobrien args.enable_p = 0; 689846283Sdfr catch_errors (cover_target_enable_exception_callback, &args, 689946283Sdfr message, RETURN_MASK_ALL); 6900130803Smarcel do_cleanups (cleanups); 690146283Sdfr } 690246283Sdfr 690346283Sdfr 690419370Spst ALL_BREAKPOINTS (b) 690519370Spst if (b->next == bpt) 690646283Sdfr { 690798944Sobrien b->next = bpt->next; 690898944Sobrien break; 690946283Sdfr } 691046283Sdfr 6911130803Smarcel ALL_BP_LOCATIONS (loc) 6912130803Smarcel if (loc->next == bpt->loc) 6913130803Smarcel { 6914130803Smarcel loc->next = bpt->loc->next; 6915130803Smarcel break; 6916130803Smarcel } 6917130803Smarcel 691898944Sobrien check_duplicates (bpt); 691919370Spst /* If this breakpoint was inserted, and there is another breakpoint 692019370Spst at the same address, we need to insert the other breakpoint. */ 6921130803Smarcel if (bpt->loc->inserted 692219370Spst && bpt->type != bp_hardware_watchpoint 692319370Spst && bpt->type != bp_read_watchpoint 692446283Sdfr && bpt->type != bp_access_watchpoint 692546283Sdfr && bpt->type != bp_catch_fork 692646283Sdfr && bpt->type != bp_catch_vfork 692746283Sdfr && bpt->type != bp_catch_exec) 692819370Spst { 692919370Spst ALL_BREAKPOINTS (b) 6930130803Smarcel if (b->loc->address == bpt->loc->address 6931130803Smarcel && b->loc->section == bpt->loc->section 6932130803Smarcel && !b->loc->duplicate 693398944Sobrien && b->enable_state != bp_disabled 693498944Sobrien && b->enable_state != bp_shlib_disabled 6935130803Smarcel && !b->pending 693698944Sobrien && b->enable_state != bp_call_disabled) 693798944Sobrien { 693898944Sobrien int val; 693998944Sobrien 694098944Sobrien /* We should never reach this point if there is a permanent 694198944Sobrien breakpoint at the same address as the one being deleted. 694298944Sobrien If there is a permanent breakpoint somewhere, it should 694398944Sobrien always be the only one inserted. */ 694498944Sobrien if (b->enable_state == bp_permanent) 694598944Sobrien internal_error (__FILE__, __LINE__, 694698944Sobrien "another breakpoint was inserted on top of " 694798944Sobrien "a permanent breakpoint"); 694898944Sobrien 694998944Sobrien if (b->type == bp_hardware_breakpoint) 6950130803Smarcel val = target_insert_hw_breakpoint (b->loc->address, b->loc->shadow_contents); 695198944Sobrien else 6952130803Smarcel val = target_insert_breakpoint (b->loc->address, b->loc->shadow_contents); 695398944Sobrien 6954130803Smarcel /* If there was an error in the insert, print a message, then stop execution. */ 695598944Sobrien if (val != 0) 695698944Sobrien { 6957130803Smarcel struct ui_file *tmp_error_stream = mem_fileopen (); 6958130803Smarcel make_cleanup_ui_file_delete (tmp_error_stream); 6959130803Smarcel 6960130803Smarcel 6961130803Smarcel if (b->type == bp_hardware_breakpoint) 6962130803Smarcel { 6963130803Smarcel fprintf_unfiltered (tmp_error_stream, 6964130803Smarcel "Cannot insert hardware breakpoint %d.\n" 6965130803Smarcel "You may have requested too many hardware breakpoints.\n", 6966130803Smarcel b->number); 6967130803Smarcel } 6968130803Smarcel else 6969130803Smarcel { 6970130803Smarcel fprintf_unfiltered (tmp_error_stream, "Cannot insert breakpoint %d.\n", b->number); 6971130803Smarcel fprintf_filtered (tmp_error_stream, "Error accessing memory address "); 6972130803Smarcel print_address_numeric (b->loc->address, 1, tmp_error_stream); 6973130803Smarcel fprintf_filtered (tmp_error_stream, ": %s.\n", 6974130803Smarcel safe_strerror (val)); 6975130803Smarcel } 6976130803Smarcel 6977130803Smarcel fprintf_unfiltered (tmp_error_stream,"The same program may be running in another process."); 697898944Sobrien target_terminal_ours_for_output (); 6979130803Smarcel error_stream(tmp_error_stream); 698098944Sobrien } 698198944Sobrien else 6982130803Smarcel b->loc->inserted = 1; 698398944Sobrien } 698419370Spst } 698519370Spst 698619370Spst free_command_lines (&bpt->commands); 698719370Spst if (bpt->cond) 698898944Sobrien xfree (bpt->cond); 698919370Spst if (bpt->cond_string != NULL) 699098944Sobrien xfree (bpt->cond_string); 699119370Spst if (bpt->addr_string != NULL) 699298944Sobrien xfree (bpt->addr_string); 699346283Sdfr if (bpt->exp != NULL) 699498944Sobrien xfree (bpt->exp); 699519370Spst if (bpt->exp_string != NULL) 699698944Sobrien xfree (bpt->exp_string); 699746283Sdfr if (bpt->val != NULL) 699846283Sdfr value_free (bpt->val); 699919370Spst if (bpt->source_file != NULL) 700098944Sobrien xfree (bpt->source_file); 700146283Sdfr if (bpt->dll_pathname != NULL) 700298944Sobrien xfree (bpt->dll_pathname); 700346283Sdfr if (bpt->triggered_dll_pathname != NULL) 700498944Sobrien xfree (bpt->triggered_dll_pathname); 700546283Sdfr if (bpt->exec_pathname != NULL) 700698944Sobrien xfree (bpt->exec_pathname); 700719370Spst 700819370Spst /* Be sure no bpstat's are pointing at it after it's been freed. */ 700919370Spst /* FIXME, how can we find all bpstat's? 701019370Spst We just check stop_bpstat for now. */ 701119370Spst for (bs = stop_bpstat; bs; bs = bs->next) 701219370Spst if (bs->breakpoint_at == bpt) 701346283Sdfr { 701446283Sdfr bs->breakpoint_at = NULL; 701546283Sdfr bs->old_val = NULL; 7016130803Smarcel /* bs->commands will be freed later. */ 701746283Sdfr } 701846283Sdfr /* On the chance that someone will soon try again to delete this same 701946283Sdfr bp, we mark it as deleted before freeing its storage. */ 702046283Sdfr bpt->type = bp_none; 702146283Sdfr 7022130803Smarcel xfree (bpt->loc); 702398944Sobrien xfree (bpt); 702419370Spst} 702519370Spst 702698944Sobrienstatic void 702798944Sobriendo_delete_breakpoint_cleanup (void *b) 702898944Sobrien{ 702998944Sobrien delete_breakpoint (b); 703098944Sobrien} 703198944Sobrien 703298944Sobrienstruct cleanup * 703398944Sobrienmake_cleanup_delete_breakpoint (struct breakpoint *b) 703498944Sobrien{ 703598944Sobrien return make_cleanup (do_delete_breakpoint_cleanup, b); 703698944Sobrien} 703798944Sobrien 703898944Sobrienstruct cleanup * 703998944Sobrienmake_exec_cleanup_delete_breakpoint (struct breakpoint *b) 704098944Sobrien{ 704198944Sobrien return make_exec_cleanup (do_delete_breakpoint_cleanup, b); 704298944Sobrien} 704398944Sobrien 704446283Sdfrvoid 704598944Sobriendelete_command (char *arg, int from_tty) 704619370Spst{ 704746283Sdfr struct breakpoint *b, *temp; 704819370Spst 7049130803Smarcel dont_repeat (); 7050130803Smarcel 705119370Spst if (arg == 0) 705219370Spst { 705346283Sdfr int breaks_to_delete = 0; 705446283Sdfr 705546283Sdfr /* Delete all breakpoints if no argument. 705698944Sobrien Do not delete internal or call-dummy breakpoints, these 705798944Sobrien have to be deleted with an explicit breakpoint number argument. */ 705898944Sobrien ALL_BREAKPOINTS (b) 705998944Sobrien { 706098944Sobrien if (b->type != bp_call_dummy && 706198944Sobrien b->type != bp_shlib_event && 706298944Sobrien b->type != bp_thread_event && 706398944Sobrien b->type != bp_overlay_event && 706498944Sobrien b->number >= 0) 706598944Sobrien breaks_to_delete = 1; 706698944Sobrien } 706746283Sdfr 706819370Spst /* Ask user only if there are some breakpoints to delete. */ 706919370Spst if (!from_tty 707046283Sdfr || (breaks_to_delete && query ("Delete all breakpoints? "))) 707119370Spst { 707298944Sobrien ALL_BREAKPOINTS_SAFE (b, temp) 707398944Sobrien { 707498944Sobrien if (b->type != bp_call_dummy && 707598944Sobrien b->type != bp_shlib_event && 707698944Sobrien b->type != bp_thread_event && 707798944Sobrien b->type != bp_overlay_event && 707898944Sobrien b->number >= 0) 707998944Sobrien delete_breakpoint (b); 708098944Sobrien } 708119370Spst } 708219370Spst } 708319370Spst else 708419370Spst map_breakpoint_numbers (arg, delete_breakpoint); 708519370Spst} 708619370Spst 708719370Spst/* Reset a breakpoint given it's struct breakpoint * BINT. 708819370Spst The value we return ends up being the return value from catch_errors. 708919370Spst Unused in this case. */ 709019370Spst 709119370Spststatic int 7092130803Smarcelbreakpoint_re_set_one (void *bint) 709319370Spst{ 709498944Sobrien /* get past catch_errs */ 709598944Sobrien struct breakpoint *b = (struct breakpoint *) bint; 709619370Spst struct value *mark; 709719370Spst int i; 709819370Spst struct symtabs_and_lines sals; 709919370Spst char *s; 710098944Sobrien enum enable_state save_enable; 710119370Spst 710219370Spst switch (b->type) 710319370Spst { 710446283Sdfr case bp_none: 710598944Sobrien warning ("attempted to reset apparently deleted breakpoint #%d?", 710698944Sobrien b->number); 710746283Sdfr return 0; 710819370Spst case bp_breakpoint: 710919370Spst case bp_hardware_breakpoint: 711046283Sdfr case bp_catch_load: 711146283Sdfr case bp_catch_unload: 711219370Spst if (b->addr_string == NULL) 711319370Spst { 711419370Spst /* Anything without a string can't be re-set. */ 711519370Spst delete_breakpoint (b); 711619370Spst return 0; 711719370Spst } 711898944Sobrien /* HACK: cagney/2001-11-11: kettenis/2001-11-11: MarkK wrote: 711919370Spst 712098944Sobrien ``And a hack it is, although Apple's Darwin version of GDB 712198944Sobrien contains an almost identical hack to implement a "future 712298944Sobrien break" command. It seems to work in many real world cases, 712398944Sobrien but it is easy to come up with a test case where the patch 712498944Sobrien doesn't help at all.'' 712598944Sobrien 712698944Sobrien ``It seems that the way GDB implements breakpoints - in - 712798944Sobrien shared - libraries was designed for a.out shared library 712898944Sobrien systems (SunOS 4) where shared libraries were loaded at a 712998944Sobrien fixed address in memory. Since ELF shared libraries can (and 713098944Sobrien will) be loaded at any address in memory, things break. 713198944Sobrien Fixing this is not trivial. Therefore, I'm not sure whether 713298944Sobrien we should add this hack to the branch only. I cannot 713398944Sobrien guarantee that things will be fixed on the trunk in the near 713498944Sobrien future.'' 713598944Sobrien 713698944Sobrien In case we have a problem, disable this breakpoint. We'll 713798944Sobrien restore its status if we succeed. Don't disable a 713898944Sobrien shlib_disabled breakpoint though. There's a fair chance we 713998944Sobrien can't re-set it if the shared library it's in hasn't been 714098944Sobrien loaded yet. */ 7141130803Smarcel 7142130803Smarcel if (b->pending) 7143130803Smarcel break; 7144130803Smarcel 714598944Sobrien save_enable = b->enable_state; 714698944Sobrien if (b->enable_state != bp_shlib_disabled) 714798944Sobrien b->enable_state = bp_disabled; 714898944Sobrien 714919370Spst set_language (b->language); 715019370Spst input_radix = b->input_radix; 715119370Spst s = b->addr_string; 7152130803Smarcel sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, NULL); 715319370Spst for (i = 0; i < sals.nelts; i++) 715419370Spst { 715519370Spst resolve_sal_pc (&sals.sals[i]); 715619370Spst 715719370Spst /* Reparse conditions, they might contain references to the 715819370Spst old symtab. */ 715919370Spst if (b->cond_string != NULL) 716019370Spst { 716119370Spst s = b->cond_string; 716219370Spst if (b->cond) 7163130803Smarcel { 7164130803Smarcel xfree (b->cond); 7165130803Smarcel /* Avoid re-freeing b->exp if an error during the call 7166130803Smarcel to parse_exp_1. */ 7167130803Smarcel b->cond = NULL; 7168130803Smarcel } 716919370Spst b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0); 717019370Spst } 717119370Spst 717298944Sobrien /* We need to re-set the breakpoint if the address changes... */ 7173130803Smarcel if (b->loc->address != sals.sals[i].pc 717498944Sobrien /* ...or new and old breakpoints both have source files, and 717598944Sobrien the source file name or the line number changes... */ 717619370Spst || (b->source_file != NULL 717719370Spst && sals.sals[i].symtab != NULL 7178130803Smarcel && (strcmp (b->source_file, sals.sals[i].symtab->filename) != 0 717919370Spst || b->line_number != sals.sals[i].line) 718098944Sobrien ) 718198944Sobrien /* ...or we switch between having a source file and not having 718298944Sobrien one. */ 718319370Spst || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL)) 718498944Sobrien ) 718519370Spst { 718619370Spst if (b->source_file != NULL) 718798944Sobrien xfree (b->source_file); 718819370Spst if (sals.sals[i].symtab == NULL) 718919370Spst b->source_file = NULL; 719019370Spst else 719119370Spst b->source_file = 719219370Spst savestring (sals.sals[i].symtab->filename, 719319370Spst strlen (sals.sals[i].symtab->filename)); 719419370Spst b->line_number = sals.sals[i].line; 7195130803Smarcel b->loc->requested_address = sals.sals[i].pc; 7196130803Smarcel b->loc->address 7197130803Smarcel = adjust_breakpoint_address (b->loc->requested_address); 719819370Spst 719998944Sobrien /* Used to check for duplicates here, but that can 720098944Sobrien cause trouble, as it doesn't check for disabled 720198944Sobrien breakpoints. */ 720246283Sdfr 720319370Spst mention (b); 720419370Spst 720519370Spst /* Might be better to do this just once per breakpoint_re_set, 720698944Sobrien rather than once for every breakpoint. */ 720719370Spst breakpoints_changed (); 720819370Spst } 7209130803Smarcel b->loc->section = sals.sals[i].section; 721098944Sobrien b->enable_state = save_enable; /* Restore it, this worked. */ 721146283Sdfr 721246283Sdfr 721398944Sobrien /* Now that this is re-enabled, check_duplicates 721446283Sdfr can be used. */ 721598944Sobrien check_duplicates (b); 721646283Sdfr 721719370Spst } 721898944Sobrien xfree (sals.sals); 721919370Spst break; 722019370Spst 722119370Spst case bp_watchpoint: 722219370Spst case bp_hardware_watchpoint: 722319370Spst case bp_read_watchpoint: 722419370Spst case bp_access_watchpoint: 722519370Spst innermost_block = NULL; 722698944Sobrien /* The issue arises of what context to evaluate this in. The 722798944Sobrien same one as when it was set, but what does that mean when 722898944Sobrien symbols have been re-read? We could save the filename and 722998944Sobrien functionname, but if the context is more local than that, the 723098944Sobrien best we could do would be something like how many levels deep 723198944Sobrien and which index at that particular level, but that's going to 723298944Sobrien be less stable than filenames or function names. */ 723398944Sobrien 723419370Spst /* So for now, just use a global context. */ 723546283Sdfr if (b->exp) 7236130803Smarcel { 7237130803Smarcel xfree (b->exp); 7238130803Smarcel /* Avoid re-freeing b->exp if an error during the call to 7239130803Smarcel parse_expression. */ 7240130803Smarcel b->exp = NULL; 7241130803Smarcel } 724219370Spst b->exp = parse_expression (b->exp_string); 724319370Spst b->exp_valid_block = innermost_block; 724419370Spst mark = value_mark (); 724546283Sdfr if (b->val) 7246130803Smarcel { 7247130803Smarcel value_free (b->val); 7248130803Smarcel /* Avoid re-freeing b->val if an error during the call to 7249130803Smarcel evaluate_expression. */ 7250130803Smarcel b->val = NULL; 7251130803Smarcel } 725219370Spst b->val = evaluate_expression (b->exp); 725319370Spst release_value (b->val); 7254130803Smarcel if (VALUE_LAZY (b->val) && breakpoint_enabled (b)) 725519370Spst value_fetch_lazy (b->val); 725619370Spst 725719370Spst if (b->cond_string != NULL) 725819370Spst { 725919370Spst s = b->cond_string; 726046283Sdfr if (b->cond) 7261130803Smarcel { 7262130803Smarcel xfree (b->cond); 7263130803Smarcel /* Avoid re-freeing b->exp if an error during the call 7264130803Smarcel to parse_exp_1. */ 7265130803Smarcel b->cond = NULL; 7266130803Smarcel } 726798944Sobrien b->cond = parse_exp_1 (&s, (struct block *) 0, 0); 726819370Spst } 7269130803Smarcel if (breakpoint_enabled (b)) 727019370Spst mention (b); 727119370Spst value_free_to_mark (mark); 727219370Spst break; 727398944Sobrien case bp_catch_catch: 727498944Sobrien case bp_catch_throw: 727546283Sdfr break; 727698944Sobrien /* We needn't really do anything to reset these, since the mask 727798944Sobrien that requests them is unaffected by e.g., new libraries being 727898944Sobrien loaded. */ 727946283Sdfr case bp_catch_fork: 728046283Sdfr case bp_catch_vfork: 728146283Sdfr case bp_catch_exec: 728246283Sdfr break; 728398944Sobrien 728419370Spst default: 728519370Spst printf_filtered ("Deleting unknown breakpoint type %d\n", b->type); 728619370Spst /* fall through */ 728798944Sobrien /* Delete longjmp and overlay event breakpoints; they will be 728898944Sobrien reset later by breakpoint_re_set. */ 728919370Spst case bp_longjmp: 729019370Spst case bp_longjmp_resume: 729198944Sobrien case bp_overlay_event: 729219370Spst delete_breakpoint (b); 729319370Spst break; 729419370Spst 729598944Sobrien /* This breakpoint is special, it's set up when the inferior 729698944Sobrien starts and we really don't want to touch it. */ 729719370Spst case bp_shlib_event: 729819370Spst 729998944Sobrien /* Like bp_shlib_event, this breakpoint type is special. 730098944Sobrien Once it is set up, we do not want to touch it. */ 730198944Sobrien case bp_thread_event: 730298944Sobrien 730398944Sobrien /* Keep temporary breakpoints, which can be encountered when we step 730498944Sobrien over a dlopen call and SOLIB_ADD is resetting the breakpoints. 730598944Sobrien Otherwise these should have been blown away via the cleanup chain 730698944Sobrien or by breakpoint_init_inferior when we rerun the executable. */ 730719370Spst case bp_until: 730819370Spst case bp_finish: 730919370Spst case bp_watchpoint_scope: 731019370Spst case bp_call_dummy: 731119370Spst case bp_step_resume: 731219370Spst break; 731319370Spst } 731419370Spst 731519370Spst return 0; 731619370Spst} 731719370Spst 731819370Spst/* Re-set all breakpoints after symbols have been re-loaded. */ 731919370Spstvoid 732098944Sobrienbreakpoint_re_set (void) 732119370Spst{ 732219370Spst struct breakpoint *b, *temp; 732319370Spst enum language save_language; 732419370Spst int save_input_radix; 732598944Sobrien 732619370Spst save_language = current_language->la_language; 732719370Spst save_input_radix = input_radix; 732819370Spst ALL_BREAKPOINTS_SAFE (b, temp) 732998944Sobrien { 733098944Sobrien /* Format possible error msg */ 7331130803Smarcel char *message = xstrprintf ("Error in re-setting breakpoint %d:\n", 7332130803Smarcel b->number); 7333130803Smarcel struct cleanup *cleanups = make_cleanup (xfree, message); 733498944Sobrien catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); 7335130803Smarcel do_cleanups (cleanups); 733698944Sobrien } 733719370Spst set_language (save_language); 733819370Spst input_radix = save_input_radix; 733919370Spst 734098944Sobrien if (GET_LONGJMP_TARGET_P ()) 734198944Sobrien { 734298944Sobrien create_longjmp_breakpoint ("longjmp"); 734398944Sobrien create_longjmp_breakpoint ("_longjmp"); 734498944Sobrien create_longjmp_breakpoint ("siglongjmp"); 734598944Sobrien create_longjmp_breakpoint ("_siglongjmp"); 734698944Sobrien create_longjmp_breakpoint (NULL); 734798944Sobrien } 734898944Sobrien 734998944Sobrien create_overlay_event_breakpoint ("_ovly_debug_event"); 735019370Spst} 735119370Spst 735246283Sdfr/* Reset the thread number of this breakpoint: 735346283Sdfr 735446283Sdfr - If the breakpoint is for all threads, leave it as-is. 735598944Sobrien - Else, reset it to the current thread for inferior_ptid. */ 735619370Spstvoid 735798944Sobrienbreakpoint_re_set_thread (struct breakpoint *b) 735846283Sdfr{ 735946283Sdfr if (b->thread != -1) 736046283Sdfr { 736198944Sobrien if (in_thread_list (inferior_ptid)) 736298944Sobrien b->thread = pid_to_thread_id (inferior_ptid); 736346283Sdfr } 736446283Sdfr} 736546283Sdfr 736698944Sobrien/* Set ignore-count of breakpoint number BPTNUM to COUNT. 736798944Sobrien If from_tty is nonzero, it prints a message to that effect, 736898944Sobrien which ends with a period (no newline). */ 736998944Sobrien 737046283Sdfrvoid 737198944Sobrienset_ignore_count (int bptnum, int count, int from_tty) 737219370Spst{ 7373130803Smarcel struct breakpoint *b; 737419370Spst 737519370Spst if (count < 0) 737619370Spst count = 0; 737719370Spst 737819370Spst ALL_BREAKPOINTS (b) 737919370Spst if (b->number == bptnum) 738098944Sobrien { 738198944Sobrien b->ignore_count = count; 7382130803Smarcel if (from_tty) 7383130803Smarcel { 7384130803Smarcel if (count == 0) 7385130803Smarcel printf_filtered ("Will stop next time breakpoint %d is reached.", 7386130803Smarcel bptnum); 7387130803Smarcel else if (count == 1) 7388130803Smarcel printf_filtered ("Will ignore next crossing of breakpoint %d.", 7389130803Smarcel bptnum); 7390130803Smarcel else 7391130803Smarcel printf_filtered ("Will ignore next %d crossings of breakpoint %d.", 7392130803Smarcel count, bptnum); 7393130803Smarcel } 739498944Sobrien breakpoints_changed (); 7395130803Smarcel breakpoint_modify_event (b->number); 739698944Sobrien return; 739798944Sobrien } 739819370Spst 739919370Spst error ("No breakpoint number %d.", bptnum); 740019370Spst} 740119370Spst 740219370Spst/* Clear the ignore counts of all breakpoints. */ 740319370Spstvoid 740498944Sobrienbreakpoint_clear_ignore_counts (void) 740519370Spst{ 740619370Spst struct breakpoint *b; 740719370Spst 740819370Spst ALL_BREAKPOINTS (b) 740919370Spst b->ignore_count = 0; 741019370Spst} 741119370Spst 741219370Spst/* Command to set ignore-count of breakpoint N to COUNT. */ 741319370Spst 741419370Spststatic void 741598944Sobrienignore_command (char *args, int from_tty) 741619370Spst{ 741719370Spst char *p = args; 7418130803Smarcel int num; 741919370Spst 742019370Spst if (p == 0) 742119370Spst error_no_arg ("a breakpoint number"); 742298944Sobrien 742319370Spst num = get_number (&p); 742498944Sobrien if (num == 0) 742598944Sobrien error ("bad breakpoint number: '%s'", args); 742619370Spst if (*p == 0) 742719370Spst error ("Second argument (specified ignore-count) is missing."); 742819370Spst 742919370Spst set_ignore_count (num, 743019370Spst longest_to_int (value_as_long (parse_and_eval (p))), 743119370Spst from_tty); 7432130803Smarcel if (from_tty) 7433130803Smarcel printf_filtered ("\n"); 743419370Spst} 743519370Spst 743619370Spst/* Call FUNCTION on each of the breakpoints 743719370Spst whose numbers are given in ARGS. */ 743819370Spst 743919370Spststatic void 744098944Sobrienmap_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) 744119370Spst{ 7442130803Smarcel char *p = args; 744319370Spst char *p1; 7444130803Smarcel int num; 7445130803Smarcel struct breakpoint *b, *tmp; 744698944Sobrien int match; 744719370Spst 744819370Spst if (p == 0) 744919370Spst error_no_arg ("one or more breakpoint numbers"); 745019370Spst 745119370Spst while (*p) 745219370Spst { 745398944Sobrien match = 0; 745419370Spst p1 = p; 745519370Spst 745698944Sobrien num = get_number_or_range (&p1); 745798944Sobrien if (num == 0) 745898944Sobrien { 745998944Sobrien warning ("bad breakpoint number at or near '%s'", p); 746098944Sobrien } 746198944Sobrien else 746298944Sobrien { 746398944Sobrien ALL_BREAKPOINTS_SAFE (b, tmp) 746498944Sobrien if (b->number == num) 746598944Sobrien { 746698944Sobrien struct breakpoint *related_breakpoint = b->related_breakpoint; 746798944Sobrien match = 1; 746898944Sobrien function (b); 746998944Sobrien if (related_breakpoint) 747098944Sobrien function (related_breakpoint); 747198944Sobrien break; 747298944Sobrien } 747398944Sobrien if (match == 0) 747498944Sobrien printf_unfiltered ("No breakpoint number %d.\n", num); 747598944Sobrien } 747619370Spst p = p1; 747719370Spst } 747819370Spst} 747919370Spst 748098944Sobrien/* Set ignore-count of breakpoint number BPTNUM to COUNT. 748198944Sobrien If from_tty is nonzero, it prints a message to that effect, 748298944Sobrien which ends with a period (no newline). */ 748398944Sobrien 748419370Spstvoid 748598944Sobriendisable_breakpoint (struct breakpoint *bpt) 748619370Spst{ 748719370Spst /* Never disable a watchpoint scope breakpoint; we want to 748819370Spst hit them when we leave scope so we can delete both the 748919370Spst watchpoint and its scope breakpoint at that time. */ 749019370Spst if (bpt->type == bp_watchpoint_scope) 749119370Spst return; 749219370Spst 749398944Sobrien /* You can't disable permanent breakpoints. */ 749498944Sobrien if (bpt->enable_state == bp_permanent) 749598944Sobrien return; 749619370Spst 749798944Sobrien bpt->enable_state = bp_disabled; 749819370Spst 749998944Sobrien check_duplicates (bpt); 750098944Sobrien 750119370Spst if (modify_breakpoint_hook) 750219370Spst modify_breakpoint_hook (bpt); 750398944Sobrien breakpoint_modify_event (bpt->number); 750419370Spst} 750519370Spst 750619370Spststatic void 750798944Sobriendisable_command (char *args, int from_tty) 750819370Spst{ 7509130803Smarcel struct breakpoint *bpt; 751019370Spst if (args == 0) 751119370Spst ALL_BREAKPOINTS (bpt) 751219370Spst switch (bpt->type) 751398944Sobrien { 751498944Sobrien case bp_none: 751598944Sobrien warning ("attempted to disable apparently deleted breakpoint #%d?", 751698944Sobrien bpt->number); 751798944Sobrien continue; 751898944Sobrien case bp_breakpoint: 751998944Sobrien case bp_catch_load: 752098944Sobrien case bp_catch_unload: 752198944Sobrien case bp_catch_fork: 752298944Sobrien case bp_catch_vfork: 752398944Sobrien case bp_catch_exec: 752498944Sobrien case bp_catch_catch: 752598944Sobrien case bp_catch_throw: 752698944Sobrien case bp_hardware_breakpoint: 752798944Sobrien case bp_watchpoint: 752898944Sobrien case bp_hardware_watchpoint: 752998944Sobrien case bp_read_watchpoint: 753098944Sobrien case bp_access_watchpoint: 753198944Sobrien disable_breakpoint (bpt); 753298944Sobrien default: 753398944Sobrien continue; 753498944Sobrien } 753519370Spst else 753619370Spst map_breakpoint_numbers (args, disable_breakpoint); 753719370Spst} 753819370Spst 753919370Spststatic void 754098944Sobriendo_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) 754119370Spst{ 754219370Spst struct frame_info *save_selected_frame = NULL; 754319370Spst int save_selected_frame_level = -1; 754419370Spst int target_resources_ok, other_type_used; 754519370Spst struct value *mark; 754619370Spst 754746283Sdfr if (bpt->type == bp_hardware_breakpoint) 754846283Sdfr { 754919370Spst int i; 755098944Sobrien i = hw_breakpoint_used_count (); 755198944Sobrien target_resources_ok = 755298944Sobrien TARGET_CAN_USE_HARDWARE_WATCHPOINT (bp_hardware_breakpoint, 755398944Sobrien i + 1, 0); 755419370Spst if (target_resources_ok == 0) 755598944Sobrien error ("No hardware breakpoint support in the target."); 755619370Spst else if (target_resources_ok < 0) 755798944Sobrien error ("Hardware breakpoints used exceeds limit."); 755819370Spst } 755919370Spst 7560130803Smarcel if (bpt->pending) 756119370Spst { 7562130803Smarcel if (bpt->enable_state != bp_enabled) 756319370Spst { 7564130803Smarcel /* When enabling a pending breakpoint, we need to check if the breakpoint 7565130803Smarcel is resolvable since shared libraries could have been loaded 7566130803Smarcel after the breakpoint was disabled. */ 7567130803Smarcel breakpoints_changed (); 7568130803Smarcel if (resolve_pending_breakpoint (bpt) == GDB_RC_OK) 756919370Spst { 7570130803Smarcel delete_breakpoint (bpt); 757119370Spst return; 757219370Spst } 7573130803Smarcel bpt->enable_state = bp_enabled; 7574130803Smarcel bpt->disposition = disposition; 757519370Spst } 7576130803Smarcel } 7577130803Smarcel else /* Not a pending breakpoint. */ 7578130803Smarcel { 7579130803Smarcel if (bpt->enable_state != bp_permanent) 7580130803Smarcel bpt->enable_state = bp_enabled; 7581130803Smarcel bpt->disposition = disposition; 7582130803Smarcel check_duplicates (bpt); 7583130803Smarcel breakpoints_changed (); 7584130803Smarcel 7585130803Smarcel if (bpt->type == bp_watchpoint || 7586130803Smarcel bpt->type == bp_hardware_watchpoint || 7587130803Smarcel bpt->type == bp_read_watchpoint || 758898944Sobrien bpt->type == bp_access_watchpoint) 758998944Sobrien { 7590130803Smarcel if (bpt->exp_valid_block != NULL) 759198944Sobrien { 7592130803Smarcel struct frame_info *fr = 7593130803Smarcel fr = frame_find_by_id (bpt->watchpoint_frame); 7594130803Smarcel if (fr == NULL) 7595130803Smarcel { 7596130803Smarcel printf_filtered ("\ 7597130803SmarcelCannot enable watchpoint %d because the block in which its expression\n\ 7598130803Smarcelis valid is not currently in scope.\n", bpt->number); 7599130803Smarcel bpt->enable_state = bp_disabled; 7600130803Smarcel return; 7601130803Smarcel } 7602130803Smarcel 7603130803Smarcel save_selected_frame = deprecated_selected_frame; 7604130803Smarcel save_selected_frame_level = frame_relative_level (deprecated_selected_frame); 7605130803Smarcel select_frame (fr); 7606130803Smarcel } 7607130803Smarcel 7608130803Smarcel value_free (bpt->val); 7609130803Smarcel mark = value_mark (); 7610130803Smarcel bpt->val = evaluate_expression (bpt->exp); 7611130803Smarcel release_value (bpt->val); 7612130803Smarcel if (VALUE_LAZY (bpt->val)) 7613130803Smarcel value_fetch_lazy (bpt->val); 7614130803Smarcel 7615130803Smarcel if (bpt->type == bp_hardware_watchpoint || 7616130803Smarcel bpt->type == bp_read_watchpoint || 7617130803Smarcel bpt->type == bp_access_watchpoint) 7618130803Smarcel { 7619130803Smarcel int i = hw_watchpoint_used_count (bpt->type, &other_type_used); 7620130803Smarcel int mem_cnt = can_use_hardware_watchpoint (bpt->val); 7621130803Smarcel 7622130803Smarcel /* Hack around 'unused var' error for some targets here */ 7623130803Smarcel (void) mem_cnt, i; 7624130803Smarcel target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT ( 7625130803Smarcel bpt->type, i + mem_cnt, other_type_used); 7626130803Smarcel /* we can consider of type is bp_hardware_watchpoint, convert to 7627130803Smarcel bp_watchpoint in the following condition */ 7628130803Smarcel if (target_resources_ok < 0) 7629130803Smarcel { 7630130803Smarcel printf_filtered ("\ 763119370SpstCannot enable watchpoint %d because target watch resources\n\ 763219370Spsthave been allocated for other watchpoints.\n", bpt->number); 7633130803Smarcel bpt->enable_state = bp_disabled; 7634130803Smarcel value_free_to_mark (mark); 7635130803Smarcel return; 7636130803Smarcel } 763798944Sobrien } 7638130803Smarcel 7639130803Smarcel if (save_selected_frame_level >= 0) 7640130803Smarcel select_frame (save_selected_frame); 7641130803Smarcel value_free_to_mark (mark); 764298944Sobrien } 7643130803Smarcel } 764419370Spst 764546283Sdfr if (modify_breakpoint_hook) 764646283Sdfr modify_breakpoint_hook (bpt); 764798944Sobrien breakpoint_modify_event (bpt->number); 764819370Spst} 764919370Spst 765046283Sdfrvoid 765198944Sobrienenable_breakpoint (struct breakpoint *bpt) 765246283Sdfr{ 765346283Sdfr do_enable_breakpoint (bpt, bpt->disposition); 765446283Sdfr} 765546283Sdfr 765646283Sdfr/* The enable command enables the specified breakpoints (or all defined 765746283Sdfr breakpoints) so they once again become (or continue to be) effective 765846283Sdfr in stopping the inferior. */ 765946283Sdfr 766019370Spststatic void 766198944Sobrienenable_command (char *args, int from_tty) 766246283Sdfr{ 7663130803Smarcel struct breakpoint *bpt; 766446283Sdfr if (args == 0) 766546283Sdfr ALL_BREAKPOINTS (bpt) 766646283Sdfr switch (bpt->type) 766798944Sobrien { 766898944Sobrien case bp_none: 766998944Sobrien warning ("attempted to enable apparently deleted breakpoint #%d?", 767098944Sobrien bpt->number); 767198944Sobrien continue; 767298944Sobrien case bp_breakpoint: 767398944Sobrien case bp_catch_load: 767498944Sobrien case bp_catch_unload: 767598944Sobrien case bp_catch_fork: 767698944Sobrien case bp_catch_vfork: 767798944Sobrien case bp_catch_exec: 767898944Sobrien case bp_catch_catch: 767998944Sobrien case bp_catch_throw: 768098944Sobrien case bp_hardware_breakpoint: 768198944Sobrien case bp_watchpoint: 768298944Sobrien case bp_hardware_watchpoint: 768398944Sobrien case bp_read_watchpoint: 768498944Sobrien case bp_access_watchpoint: 768598944Sobrien enable_breakpoint (bpt); 768698944Sobrien default: 768798944Sobrien continue; 768898944Sobrien } 768946283Sdfr else 769046283Sdfr map_breakpoint_numbers (args, enable_breakpoint); 769146283Sdfr} 769246283Sdfr 769346283Sdfrstatic void 769498944Sobrienenable_once_breakpoint (struct breakpoint *bpt) 769546283Sdfr{ 769698944Sobrien do_enable_breakpoint (bpt, disp_disable); 769746283Sdfr} 769846283Sdfr 769946283Sdfrstatic void 770098944Sobrienenable_once_command (char *args, int from_tty) 770119370Spst{ 770219370Spst map_breakpoint_numbers (args, enable_once_breakpoint); 770319370Spst} 770419370Spst 770519370Spststatic void 770698944Sobrienenable_delete_breakpoint (struct breakpoint *bpt) 770719370Spst{ 770898944Sobrien do_enable_breakpoint (bpt, disp_del); 770919370Spst} 771019370Spst 771119370Spststatic void 771298944Sobrienenable_delete_command (char *args, int from_tty) 771319370Spst{ 771419370Spst map_breakpoint_numbers (args, enable_delete_breakpoint); 771519370Spst} 771619370Spst 7717130803Smarcelstatic void 7718130803Smarcelset_breakpoint_cmd (char *args, int from_tty) 7719130803Smarcel{ 7720130803Smarcel} 7721130803Smarcel 7722130803Smarcelstatic void 7723130803Smarcelshow_breakpoint_cmd (char *args, int from_tty) 7724130803Smarcel{ 7725130803Smarcel} 7726130803Smarcel 772719370Spst/* Use default_breakpoint_'s, or nothing if they aren't valid. */ 772819370Spst 772919370Spststruct symtabs_and_lines 773098944Sobriendecode_line_spec_1 (char *string, int funfirstline) 773119370Spst{ 773219370Spst struct symtabs_and_lines sals; 773319370Spst if (string == 0) 773419370Spst error ("Empty line specification."); 773519370Spst if (default_breakpoint_valid) 773619370Spst sals = decode_line_1 (&string, funfirstline, 773798944Sobrien default_breakpoint_symtab, 773898944Sobrien default_breakpoint_line, 7739130803Smarcel (char ***) NULL, NULL); 774019370Spst else 774119370Spst sals = decode_line_1 (&string, funfirstline, 7742130803Smarcel (struct symtab *) NULL, 0, (char ***) NULL, NULL); 774319370Spst if (*string) 774419370Spst error ("Junk at end of line specification: %s", string); 774519370Spst return sals; 774619370Spst} 774719370Spst 774819370Spstvoid 774998944Sobrien_initialize_breakpoint (void) 775019370Spst{ 7751130803Smarcel static struct cmd_list_element *breakpoint_set_cmdlist; 7752130803Smarcel static struct cmd_list_element *breakpoint_show_cmdlist; 775346283Sdfr struct cmd_list_element *c; 775446283Sdfr 775519370Spst breakpoint_chain = 0; 775619370Spst /* Don't bother to call set_breakpoint_count. $bpnum isn't useful 775719370Spst before a breakpoint is set. */ 775819370Spst breakpoint_count = 0; 775919370Spst 776019370Spst add_com ("ignore", class_breakpoint, ignore_command, 776119370Spst "Set ignore-count of breakpoint number N to COUNT.\n\ 776219370SpstUsage is `ignore N COUNT'."); 776346283Sdfr if (xdb_commands) 776498944Sobrien add_com_alias ("bc", "ignore", class_breakpoint, 1); 776519370Spst 776619370Spst add_com ("commands", class_breakpoint, commands_command, 776719370Spst "Set commands to be executed when a breakpoint is hit.\n\ 776819370SpstGive breakpoint number as argument after \"commands\".\n\ 776919370SpstWith no argument, the targeted breakpoint is the last one set.\n\ 777019370SpstThe commands themselves follow starting on the next line.\n\ 777119370SpstType a line containing \"end\" to indicate the end of them.\n\ 777219370SpstGive \"silent\" as the first line to make the breakpoint silent;\n\ 777319370Spstthen no output is printed when it is hit, except what the commands print."); 777419370Spst 777519370Spst add_com ("condition", class_breakpoint, condition_command, 777619370Spst "Specify breakpoint number N to break only if COND is true.\n\ 777719370SpstUsage is `condition N COND', where N is an integer and COND is an\n\ 7778130803Smarcelexpression to be evaluated whenever breakpoint N is reached."); 777919370Spst 778098944Sobrien c = add_com ("tbreak", class_breakpoint, tbreak_command, 778198944Sobrien "Set a temporary breakpoint. Args like \"break\" command.\n\ 778219370SpstLike \"break\" except the breakpoint is only temporary,\n\ 778319370Spstso it will be deleted when hit. Equivalent to \"break\" followed\n\ 778419370Spstby using \"enable delete\" on the breakpoint number."); 7785130803Smarcel set_cmd_completer (c, location_completer); 778619370Spst 778798944Sobrien c = add_com ("hbreak", class_breakpoint, hbreak_command, 778898944Sobrien "Set a hardware assisted breakpoint. Args like \"break\" command.\n\ 778919370SpstLike \"break\" except the breakpoint requires hardware support,\n\ 779019370Spstsome target hardware may not have this support."); 7791130803Smarcel set_cmd_completer (c, location_completer); 779219370Spst 779398944Sobrien c = add_com ("thbreak", class_breakpoint, thbreak_command, 779498944Sobrien "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\ 779519370SpstLike \"hbreak\" except the breakpoint is only temporary,\n\ 779619370Spstso it will be deleted when hit."); 7797130803Smarcel set_cmd_completer (c, location_completer); 779819370Spst 779919370Spst add_prefix_cmd ("enable", class_breakpoint, enable_command, 780019370Spst "Enable some breakpoints.\n\ 780119370SpstGive breakpoint numbers (separated by spaces) as arguments.\n\ 780219370SpstWith no subcommand, breakpoints are enabled until you command otherwise.\n\ 780319370SpstThis is used to cancel the effect of the \"disable\" command.\n\ 780419370SpstWith a subcommand you can enable temporarily.", 780519370Spst &enablelist, "enable ", 1, &cmdlist); 780646283Sdfr if (xdb_commands) 780798944Sobrien add_com ("ab", class_breakpoint, enable_command, 780898944Sobrien "Enable some breakpoints.\n\ 780946283SdfrGive breakpoint numbers (separated by spaces) as arguments.\n\ 781046283SdfrWith no subcommand, breakpoints are enabled until you command otherwise.\n\ 781146283SdfrThis is used to cancel the effect of the \"disable\" command.\n\ 781246283SdfrWith a subcommand you can enable temporarily."); 781319370Spst 781446283Sdfr add_com_alias ("en", "enable", class_breakpoint, 1); 781546283Sdfr 781619370Spst add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, 781798944Sobrien "Enable some breakpoints.\n\ 781819370SpstGive breakpoint numbers (separated by spaces) as arguments.\n\ 781919370SpstThis is used to cancel the effect of the \"disable\" command.\n\ 782019370SpstMay be abbreviated to simply \"enable\".\n", 782198944Sobrien &enablebreaklist, "enable breakpoints ", 1, &enablelist); 782219370Spst 782319370Spst add_cmd ("once", no_class, enable_once_command, 782419370Spst "Enable breakpoints for one hit. Give breakpoint numbers.\n\ 782519370SpstIf a breakpoint is hit while enabled in this fashion, it becomes disabled.", 782619370Spst &enablebreaklist); 782719370Spst 782819370Spst add_cmd ("delete", no_class, enable_delete_command, 782919370Spst "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ 783019370SpstIf a breakpoint is hit while enabled in this fashion, it is deleted.", 783119370Spst &enablebreaklist); 783219370Spst 783319370Spst add_cmd ("delete", no_class, enable_delete_command, 783419370Spst "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ 783519370SpstIf a breakpoint is hit while enabled in this fashion, it is deleted.", 783619370Spst &enablelist); 783719370Spst 783819370Spst add_cmd ("once", no_class, enable_once_command, 783919370Spst "Enable breakpoints for one hit. Give breakpoint numbers.\n\ 784019370SpstIf a breakpoint is hit while enabled in this fashion, it becomes disabled.", 784119370Spst &enablelist); 784219370Spst 784319370Spst add_prefix_cmd ("disable", class_breakpoint, disable_command, 784498944Sobrien "Disable some breakpoints.\n\ 784519370SpstArguments are breakpoint numbers with spaces in between.\n\ 784619370SpstTo disable all breakpoints, give no argument.\n\ 784719370SpstA disabled breakpoint is not forgotten, but has no effect until reenabled.", 784819370Spst &disablelist, "disable ", 1, &cmdlist); 784919370Spst add_com_alias ("dis", "disable", class_breakpoint, 1); 785019370Spst add_com_alias ("disa", "disable", class_breakpoint, 1); 785146283Sdfr if (xdb_commands) 785298944Sobrien add_com ("sb", class_breakpoint, disable_command, 785398944Sobrien "Disable some breakpoints.\n\ 785446283SdfrArguments are breakpoint numbers with spaces in between.\n\ 785546283SdfrTo disable all breakpoints, give no argument.\n\ 785646283SdfrA disabled breakpoint is not forgotten, but has no effect until reenabled."); 785719370Spst 785819370Spst add_cmd ("breakpoints", class_alias, disable_command, 785919370Spst "Disable some breakpoints.\n\ 786019370SpstArguments are breakpoint numbers with spaces in between.\n\ 786119370SpstTo disable all breakpoints, give no argument.\n\ 786219370SpstA disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ 786319370SpstThis command may be abbreviated \"disable\".", 786419370Spst &disablelist); 786519370Spst 786619370Spst add_prefix_cmd ("delete", class_breakpoint, delete_command, 786798944Sobrien "Delete some breakpoints or auto-display expressions.\n\ 786819370SpstArguments are breakpoint numbers with spaces in between.\n\ 786919370SpstTo delete all breakpoints, give no argument.\n\ 787019370Spst\n\ 787119370SpstAlso a prefix command for deletion of other GDB objects.\n\ 787219370SpstThe \"unset\" command is also an alias for \"delete\".", 787319370Spst &deletelist, "delete ", 1, &cmdlist); 787419370Spst add_com_alias ("d", "delete", class_breakpoint, 1); 787546283Sdfr if (xdb_commands) 787646283Sdfr add_com ("db", class_breakpoint, delete_command, 787798944Sobrien "Delete some breakpoints.\n\ 787846283SdfrArguments are breakpoint numbers with spaces in between.\n\ 787946283SdfrTo delete all breakpoints, give no argument.\n"); 788019370Spst 788119370Spst add_cmd ("breakpoints", class_alias, delete_command, 788219370Spst "Delete some breakpoints or auto-display expressions.\n\ 788319370SpstArguments are breakpoint numbers with spaces in between.\n\ 788419370SpstTo delete all breakpoints, give no argument.\n\ 788519370SpstThis command may be abbreviated \"delete\".", 788619370Spst &deletelist); 788719370Spst 788819370Spst add_com ("clear", class_breakpoint, clear_command, 788919370Spst concat ("Clear breakpoint at specified line or function.\n\ 789019370SpstArgument may be line number, function name, or \"*\" and an address.\n\ 789119370SpstIf line number is specified, all breakpoints in that line are cleared.\n\ 789219370SpstIf function is specified, breakpoints at beginning of function are cleared.\n\ 789319370SpstIf an address is specified, breakpoints at that address are cleared.\n\n", 789498944Sobrien "With no argument, clears all breakpoints in the line that the selected frame\n\ 789519370Spstis executing in.\n\ 789619370Spst\n\ 789719370SpstSee also the \"delete\" command which clears breakpoints by number.", NULL)); 789819370Spst 789998944Sobrien c = add_com ("break", class_breakpoint, break_command, 790098944Sobrien concat ("Set breakpoint at specified line or function.\n\ 790119370SpstArgument may be line number, function name, or \"*\" and an address.\n\ 790219370SpstIf line number is specified, break at start of code for that line.\n\ 790319370SpstIf function is specified, break at start of code for that function.\n\ 790419370SpstIf an address is specified, break at that exact address.\n", 790598944Sobrien "With no arg, uses current execution address of selected stack frame.\n\ 790619370SpstThis is useful for breaking on return to a stack frame.\n\ 790719370Spst\n\ 790819370SpstMultiple breakpoints at one place are permitted, and useful if conditional.\n\ 790919370Spst\n\ 791019370SpstDo \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)); 7911130803Smarcel set_cmd_completer (c, location_completer); 791298944Sobrien 791319370Spst add_com_alias ("b", "break", class_run, 1); 791419370Spst add_com_alias ("br", "break", class_run, 1); 791519370Spst add_com_alias ("bre", "break", class_run, 1); 791619370Spst add_com_alias ("brea", "break", class_run, 1); 791719370Spst 791898944Sobrien if (xdb_commands) 791946283Sdfr { 792046283Sdfr add_com_alias ("ba", "break", class_breakpoint, 1); 792146283Sdfr add_com_alias ("bu", "ubreak", class_breakpoint, 1); 792246283Sdfr } 792346283Sdfr 792446283Sdfr if (dbx_commands) 792546283Sdfr { 792698944Sobrien add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, 792798944Sobrien "Break in function/address or break at a line in the current file.", 792898944Sobrien &stoplist, "stop ", 1, &cmdlist); 792998944Sobrien add_cmd ("in", class_breakpoint, stopin_command, 793098944Sobrien "Break in function or address.\n", &stoplist); 793198944Sobrien add_cmd ("at", class_breakpoint, stopat_command, 793298944Sobrien "Break at a line in the current file.\n", &stoplist); 793398944Sobrien add_com ("status", class_info, breakpoints_info, 793498944Sobrien concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ 793546283SdfrThe \"Type\" column indicates one of:\n\ 793646283Sdfr\tbreakpoint - normal breakpoint\n\ 793746283Sdfr\twatchpoint - watchpoint\n\ 793846283SdfrThe \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 793946283Sdfrthe disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 794046283Sdfrbreakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 794146283Sdfraddress and file/line number respectively.\n\n", 794298944Sobrien "Convenience variable \"$_\" and default examine address for \"x\"\n\ 794346283Sdfrare set to the address of the last breakpoint listed.\n\n\ 794446283SdfrConvenience variable \"$bpnum\" contains the number of the last\n\ 794546283Sdfrbreakpoint set.", NULL)); 794646283Sdfr } 794746283Sdfr 794819370Spst add_info ("breakpoints", breakpoints_info, 794919370Spst concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ 795019370SpstThe \"Type\" column indicates one of:\n\ 795119370Spst\tbreakpoint - normal breakpoint\n\ 795219370Spst\twatchpoint - watchpoint\n\ 795319370SpstThe \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 795419370Spstthe disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 795519370Spstbreakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 795619370Spstaddress and file/line number respectively.\n\n", 795798944Sobrien "Convenience variable \"$_\" and default examine address for \"x\"\n\ 795819370Spstare set to the address of the last breakpoint listed.\n\n\ 795919370SpstConvenience variable \"$bpnum\" contains the number of the last\n\ 796019370Spstbreakpoint set.", NULL)); 796119370Spst 796246283Sdfr if (xdb_commands) 796398944Sobrien add_com ("lb", class_breakpoint, breakpoints_info, 796498944Sobrien concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ 796546283SdfrThe \"Type\" column indicates one of:\n\ 796646283Sdfr\tbreakpoint - normal breakpoint\n\ 796746283Sdfr\twatchpoint - watchpoint\n\ 796846283SdfrThe \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 796946283Sdfrthe disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 797046283Sdfrbreakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 797146283Sdfraddress and file/line number respectively.\n\n", 797298944Sobrien "Convenience variable \"$_\" and default examine address for \"x\"\n\ 797346283Sdfrare set to the address of the last breakpoint listed.\n\n\ 797446283SdfrConvenience variable \"$bpnum\" contains the number of the last\n\ 797546283Sdfrbreakpoint set.", NULL)); 797646283Sdfr 797719370Spst add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, 797898944Sobrien concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\ 797919370SpstThe \"Type\" column indicates one of:\n\ 798019370Spst\tbreakpoint - normal breakpoint\n\ 798119370Spst\twatchpoint - watchpoint\n\ 798219370Spst\tlongjmp - internal breakpoint used to step through longjmp()\n\ 798319370Spst\tlongjmp resume - internal breakpoint at the target of longjmp()\n\ 798419370Spst\tuntil - internal breakpoint used by the \"until\" command\n\ 798519370Spst\tfinish - internal breakpoint used by the \"finish\" command\n", 798698944Sobrien "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 798719370Spstthe disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 798819370Spstbreakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 798919370Spstaddress and file/line number respectively.\n\n", 799098944Sobrien "Convenience variable \"$_\" and default examine address for \"x\"\n\ 799119370Spstare set to the address of the last breakpoint listed.\n\n\ 799219370SpstConvenience variable \"$bpnum\" contains the number of the last\n\ 799319370Spstbreakpoint set.", NULL), 799419370Spst &maintenanceinfolist); 799519370Spst 799619370Spst add_com ("catch", class_breakpoint, catch_command, 799798944Sobrien "Set catchpoints to catch events.\n\ 799846283SdfrRaised signals may be caught:\n\ 799946283Sdfr\tcatch signal - all signals\n\ 800046283Sdfr\tcatch signal <signame> - a particular signal\n\ 800146283SdfrRaised exceptions may be caught:\n\ 800246283Sdfr\tcatch throw - all exceptions, when thrown\n\ 800346283Sdfr\tcatch throw <exceptname> - a particular exception, when thrown\n\ 800446283Sdfr\tcatch catch - all exceptions, when caught\n\ 800546283Sdfr\tcatch catch <exceptname> - a particular exception, when caught\n\ 800646283SdfrThread or process events may be caught:\n\ 800746283Sdfr\tcatch thread_start - any threads, just after creation\n\ 800846283Sdfr\tcatch thread_exit - any threads, just before expiration\n\ 800946283Sdfr\tcatch thread_join - any threads, just after joins\n\ 801046283SdfrProcess events may be caught:\n\ 801146283Sdfr\tcatch start - any processes, just after creation\n\ 801246283Sdfr\tcatch exit - any processes, just before expiration\n\ 801346283Sdfr\tcatch fork - calls to fork()\n\ 801446283Sdfr\tcatch vfork - calls to vfork()\n\ 801546283Sdfr\tcatch exec - calls to exec()\n\ 801646283SdfrDynamically-linked library events may be caught:\n\ 801746283Sdfr\tcatch load - loads of any library\n\ 801846283Sdfr\tcatch load <libname> - loads of a particular library\n\ 801946283Sdfr\tcatch unload - unloads of any library\n\ 802046283Sdfr\tcatch unload <libname> - unloads of a particular library\n\ 802146283SdfrThe act of your program's execution stopping may also be caught:\n\ 802246283Sdfr\tcatch stop\n\n\ 802346283SdfrC++ exceptions may be caught:\n\ 802446283Sdfr\tcatch throw - all exceptions, when thrown\n\ 802546283Sdfr\tcatch catch - all exceptions, when caught\n\ 802619370Spst\n\ 802746283SdfrDo \"help set follow-fork-mode\" for info on debugging your program\n\ 802846283Sdfrafter a fork or vfork is caught.\n\n\ 802919370SpstDo \"help breakpoints\" for info on other commands dealing with breakpoints."); 803098944Sobrien 803146283Sdfr add_com ("tcatch", class_breakpoint, tcatch_command, 803298944Sobrien "Set temporary catchpoints to catch events.\n\ 803346283SdfrArgs like \"catch\" command.\n\ 803446283SdfrLike \"catch\" except the catchpoint is only temporary,\n\ 803546283Sdfrso it will be deleted when hit. Equivalent to \"catch\" followed\n\ 803646283Sdfrby using \"enable delete\" on the catchpoint number."); 803719370Spst 803898944Sobrien c = add_com ("watch", class_breakpoint, watch_command, 803998944Sobrien "Set a watchpoint for an expression.\n\ 804019370SpstA watchpoint stops execution of your program whenever the value of\n\ 804119370Spstan expression changes."); 8042130803Smarcel set_cmd_completer (c, location_completer); 804319370Spst 804498944Sobrien c = add_com ("rwatch", class_breakpoint, rwatch_command, 804598944Sobrien "Set a read watchpoint for an expression.\n\ 804619370SpstA watchpoint stops execution of your program whenever the value of\n\ 804719370Spstan expression is read."); 8048130803Smarcel set_cmd_completer (c, location_completer); 804919370Spst 805098944Sobrien c = add_com ("awatch", class_breakpoint, awatch_command, 805198944Sobrien "Set a watchpoint for an expression.\n\ 805219370SpstA watchpoint stops execution of your program whenever the value of\n\ 805319370Spstan expression is either read or written."); 8054130803Smarcel set_cmd_completer (c, location_completer); 805519370Spst 805619370Spst add_info ("watchpoints", breakpoints_info, 805719370Spst "Synonym for ``info breakpoints''."); 805819370Spst 805946283Sdfr 806046283Sdfr c = add_set_cmd ("can-use-hw-watchpoints", class_support, var_zinteger, 806198944Sobrien (char *) &can_use_hw_watchpoints, 806298944Sobrien "Set debugger's willingness to use watchpoint hardware.\n\ 806346283SdfrIf zero, gdb will not use hardware for new watchpoints, even if\n\ 806446283Sdfrsuch is available. (However, any hardware watchpoints that were\n\ 806546283Sdfrcreated before setting this to nonzero, will continue to use watchpoint\n\ 806646283Sdfrhardware.)", 806798944Sobrien &setlist); 806846283Sdfr add_show_from_set (c, &showlist); 806946283Sdfr 807046283Sdfr can_use_hw_watchpoints = 1; 8071130803Smarcel 8072130803Smarcel add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, "\ 8073130803SmarcelBreakpoint specific settings\n\ 8074130803SmarcelConfigure various breakpoint-specific variables such as\n\ 8075130803Smarcelpending breakpoint behavior", 8076130803Smarcel &breakpoint_set_cmdlist, "set breakpoint ", 8077130803Smarcel 0/*allow-unknown*/, &setlist); 8078130803Smarcel add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, "\ 8079130803SmarcelBreakpoint specific settings\n\ 8080130803SmarcelConfigure various breakpoint-specific variables such as\n\ 8081130803Smarcelpending breakpoint behavior", 8082130803Smarcel &breakpoint_show_cmdlist, "show breakpoint ", 8083130803Smarcel 0/*allow-unknown*/, &showlist); 8084130803Smarcel 8085130803Smarcel add_setshow_auto_boolean_cmd ("pending", no_class, &pending_break_support, "\ 8086130803SmarcelSet debugger's behavior regarding pending breakpoints.\n\ 8087130803SmarcelIf on, an unrecognized breakpoint location will cause gdb to create a\n\ 8088130803Smarcelpending breakpoint. If off, an unrecognized breakpoint location results in\n\ 8089130803Smarcelan error. If auto, an unrecognized breakpoint location results in a\n\ 8090130803Smarceluser-query to see if a pending breakpoint should be created.","\ 8091130803SmarcelShow debugger's behavior regarding pending breakpoints.\n\ 8092130803SmarcelIf on, an unrecognized breakpoint location will cause gdb to create a\n\ 8093130803Smarcelpending breakpoint. If off, an unrecognized breakpoint location results in\n\ 8094130803Smarcelan error. If auto, an unrecognized breakpoint location results in a\n\ 8095130803Smarceluser-query to see if a pending breakpoint should be created.", 8096130803Smarcel NULL, NULL, 8097130803Smarcel &breakpoint_set_cmdlist, 8098130803Smarcel &breakpoint_show_cmdlist); 8099130803Smarcel 8100130803Smarcel pending_break_support = AUTO_BOOLEAN_AUTO; 810119370Spst} 8102