GDB (API)
|
00001 /* Everything about breakpoints, for GDB. 00002 00003 Copyright (C) 1986-2013 Free Software Foundation, Inc. 00004 00005 This file is part of GDB. 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 3 of the License, or 00010 (at your option) any later version. 00011 00012 This program is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 00019 00020 #include "defs.h" 00021 #include "arch-utils.h" 00022 #include <ctype.h> 00023 #include "hashtab.h" 00024 #include "symtab.h" 00025 #include "frame.h" 00026 #include "breakpoint.h" 00027 #include "tracepoint.h" 00028 #include "gdbtypes.h" 00029 #include "expression.h" 00030 #include "gdbcore.h" 00031 #include "gdbcmd.h" 00032 #include "value.h" 00033 #include "command.h" 00034 #include "inferior.h" 00035 #include "gdbthread.h" 00036 #include "target.h" 00037 #include "language.h" 00038 #include "gdb_string.h" 00039 #include "gdb-demangle.h" 00040 #include "filenames.h" 00041 #include "annotate.h" 00042 #include "symfile.h" 00043 #include "objfiles.h" 00044 #include "source.h" 00045 #include "linespec.h" 00046 #include "completer.h" 00047 #include "gdb.h" 00048 #include "ui-out.h" 00049 #include "cli/cli-script.h" 00050 #include "gdb_assert.h" 00051 #include "block.h" 00052 #include "solib.h" 00053 #include "solist.h" 00054 #include "observer.h" 00055 #include "exceptions.h" 00056 #include "memattr.h" 00057 #include "ada-lang.h" 00058 #include "top.h" 00059 #include "valprint.h" 00060 #include "jit.h" 00061 #include "xml-syscall.h" 00062 #include "parser-defs.h" 00063 #include "gdb_regex.h" 00064 #include "probe.h" 00065 #include "cli/cli-utils.h" 00066 #include "continuations.h" 00067 #include "stack.h" 00068 #include "skip.h" 00069 #include "gdb_regex.h" 00070 #include "ax-gdb.h" 00071 #include "dummy-frame.h" 00072 00073 #include "format.h" 00074 00075 /* readline include files */ 00076 #include "readline/readline.h" 00077 #include "readline/history.h" 00078 00079 /* readline defines this. */ 00080 #undef savestring 00081 00082 #include "mi/mi-common.h" 00083 #include "python/python.h" 00084 00085 /* Enums for exception-handling support. */ 00086 enum exception_event_kind 00087 { 00088 EX_EVENT_THROW, 00089 EX_EVENT_RETHROW, 00090 EX_EVENT_CATCH 00091 }; 00092 00093 /* Prototypes for local functions. */ 00094 00095 static void enable_delete_command (char *, int); 00096 00097 static void enable_once_command (char *, int); 00098 00099 static void enable_count_command (char *, int); 00100 00101 static void disable_command (char *, int); 00102 00103 static void enable_command (char *, int); 00104 00105 static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, 00106 void *), 00107 void *); 00108 00109 static void ignore_command (char *, int); 00110 00111 static int breakpoint_re_set_one (void *); 00112 00113 static void breakpoint_re_set_default (struct breakpoint *); 00114 00115 static void create_sals_from_address_default (char **, 00116 struct linespec_result *, 00117 enum bptype, char *, 00118 char **); 00119 00120 static void create_breakpoints_sal_default (struct gdbarch *, 00121 struct linespec_result *, 00122 char *, char *, enum bptype, 00123 enum bpdisp, int, int, 00124 int, 00125 const struct breakpoint_ops *, 00126 int, int, int, unsigned); 00127 00128 static void decode_linespec_default (struct breakpoint *, char **, 00129 struct symtabs_and_lines *); 00130 00131 static void clear_command (char *, int); 00132 00133 static void catch_command (char *, int); 00134 00135 static int can_use_hardware_watchpoint (struct value *); 00136 00137 static void break_command_1 (char *, int, int); 00138 00139 static void mention (struct breakpoint *); 00140 00141 static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, 00142 enum bptype, 00143 const struct breakpoint_ops *); 00144 static struct bp_location *add_location_to_breakpoint (struct breakpoint *, 00145 const struct symtab_and_line *); 00146 00147 /* This function is used in gdbtk sources and thus can not be made 00148 static. */ 00149 struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, 00150 struct symtab_and_line, 00151 enum bptype, 00152 const struct breakpoint_ops *); 00153 00154 static struct breakpoint * 00155 momentary_breakpoint_from_master (struct breakpoint *orig, 00156 enum bptype type, 00157 const struct breakpoint_ops *ops); 00158 00159 static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); 00160 00161 static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, 00162 CORE_ADDR bpaddr, 00163 enum bptype bptype); 00164 00165 static void describe_other_breakpoints (struct gdbarch *, 00166 struct program_space *, CORE_ADDR, 00167 struct obj_section *, int); 00168 00169 static int breakpoint_address_match (struct address_space *aspace1, 00170 CORE_ADDR addr1, 00171 struct address_space *aspace2, 00172 CORE_ADDR addr2); 00173 00174 static int watchpoint_locations_match (struct bp_location *loc1, 00175 struct bp_location *loc2); 00176 00177 static int breakpoint_location_address_match (struct bp_location *bl, 00178 struct address_space *aspace, 00179 CORE_ADDR addr); 00180 00181 static void breakpoints_info (char *, int); 00182 00183 static void watchpoints_info (char *, int); 00184 00185 static int breakpoint_1 (char *, int, 00186 int (*) (const struct breakpoint *)); 00187 00188 static int breakpoint_cond_eval (void *); 00189 00190 static void cleanup_executing_breakpoints (void *); 00191 00192 static void commands_command (char *, int); 00193 00194 static void condition_command (char *, int); 00195 00196 typedef enum 00197 { 00198 mark_inserted, 00199 mark_uninserted 00200 } 00201 insertion_state_t; 00202 00203 static int remove_breakpoint (struct bp_location *, insertion_state_t); 00204 static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); 00205 00206 static enum print_stop_action print_bp_stop_message (bpstat bs); 00207 00208 static int watchpoint_check (void *); 00209 00210 static void maintenance_info_breakpoints (char *, int); 00211 00212 static int hw_breakpoint_used_count (void); 00213 00214 static int hw_watchpoint_use_count (struct breakpoint *); 00215 00216 static int hw_watchpoint_used_count_others (struct breakpoint *except, 00217 enum bptype type, 00218 int *other_type_used); 00219 00220 static void hbreak_command (char *, int); 00221 00222 static void thbreak_command (char *, int); 00223 00224 static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, 00225 int count); 00226 00227 static void stop_command (char *arg, int from_tty); 00228 00229 static void stopin_command (char *arg, int from_tty); 00230 00231 static void stopat_command (char *arg, int from_tty); 00232 00233 static void tcatch_command (char *arg, int from_tty); 00234 00235 static void detach_single_step_breakpoints (void); 00236 00237 static int single_step_breakpoint_inserted_here_p (struct address_space *, 00238 CORE_ADDR pc); 00239 00240 static void free_bp_location (struct bp_location *loc); 00241 static void incref_bp_location (struct bp_location *loc); 00242 static void decref_bp_location (struct bp_location **loc); 00243 00244 static struct bp_location *allocate_bp_location (struct breakpoint *bpt); 00245 00246 static void update_global_location_list (int); 00247 00248 static void update_global_location_list_nothrow (int); 00249 00250 static int is_hardware_watchpoint (const struct breakpoint *bpt); 00251 00252 static void insert_breakpoint_locations (void); 00253 00254 static int syscall_catchpoint_p (struct breakpoint *b); 00255 00256 static void tracepoints_info (char *, int); 00257 00258 static void delete_trace_command (char *, int); 00259 00260 static void enable_trace_command (char *, int); 00261 00262 static void disable_trace_command (char *, int); 00263 00264 static void trace_pass_command (char *, int); 00265 00266 static void set_tracepoint_count (int num); 00267 00268 static int is_masked_watchpoint (const struct breakpoint *b); 00269 00270 static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); 00271 00272 /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero 00273 otherwise. */ 00274 00275 static int strace_marker_p (struct breakpoint *b); 00276 00277 /* The abstract base class all breakpoint_ops structures inherit 00278 from. */ 00279 struct breakpoint_ops base_breakpoint_ops; 00280 00281 /* The breakpoint_ops structure to be inherited by all breakpoint_ops 00282 that are implemented on top of software or hardware breakpoints 00283 (user breakpoints, internal and momentary breakpoints, etc.). */ 00284 static struct breakpoint_ops bkpt_base_breakpoint_ops; 00285 00286 /* Internal breakpoints class type. */ 00287 static struct breakpoint_ops internal_breakpoint_ops; 00288 00289 /* Momentary breakpoints class type. */ 00290 static struct breakpoint_ops momentary_breakpoint_ops; 00291 00292 /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ 00293 static struct breakpoint_ops longjmp_breakpoint_ops; 00294 00295 /* The breakpoint_ops structure to be used in regular user created 00296 breakpoints. */ 00297 struct breakpoint_ops bkpt_breakpoint_ops; 00298 00299 /* Breakpoints set on probes. */ 00300 static struct breakpoint_ops bkpt_probe_breakpoint_ops; 00301 00302 /* Dynamic printf class type. */ 00303 struct breakpoint_ops dprintf_breakpoint_ops; 00304 00305 /* The style in which to perform a dynamic printf. This is a user 00306 option because different output options have different tradeoffs; 00307 if GDB does the printing, there is better error handling if there 00308 is a problem with any of the arguments, but using an inferior 00309 function lets you have special-purpose printers and sending of 00310 output to the same place as compiled-in print functions. */ 00311 00312 static const char dprintf_style_gdb[] = "gdb"; 00313 static const char dprintf_style_call[] = "call"; 00314 static const char dprintf_style_agent[] = "agent"; 00315 static const char *const dprintf_style_enums[] = { 00316 dprintf_style_gdb, 00317 dprintf_style_call, 00318 dprintf_style_agent, 00319 NULL 00320 }; 00321 static const char *dprintf_style = dprintf_style_gdb; 00322 00323 /* The function to use for dynamic printf if the preferred style is to 00324 call into the inferior. The value is simply a string that is 00325 copied into the command, so it can be anything that GDB can 00326 evaluate to a callable address, not necessarily a function name. */ 00327 00328 static char *dprintf_function = ""; 00329 00330 /* The channel to use for dynamic printf if the preferred style is to 00331 call into the inferior; if a nonempty string, it will be passed to 00332 the call as the first argument, with the format string as the 00333 second. As with the dprintf function, this can be anything that 00334 GDB knows how to evaluate, so in addition to common choices like 00335 "stderr", this could be an app-specific expression like 00336 "mystreams[curlogger]". */ 00337 00338 static char *dprintf_channel = ""; 00339 00340 /* True if dprintf commands should continue to operate even if GDB 00341 has disconnected. */ 00342 static int disconnected_dprintf = 1; 00343 00344 /* A reference-counted struct command_line. This lets multiple 00345 breakpoints share a single command list. */ 00346 struct counted_command_line 00347 { 00348 /* The reference count. */ 00349 int refc; 00350 00351 /* The command list. */ 00352 struct command_line *commands; 00353 }; 00354 00355 struct command_line * 00356 breakpoint_commands (struct breakpoint *b) 00357 { 00358 return b->commands ? b->commands->commands : NULL; 00359 } 00360 00361 /* Flag indicating that a command has proceeded the inferior past the 00362 current breakpoint. */ 00363 00364 static int breakpoint_proceeded; 00365 00366 const char * 00367 bpdisp_text (enum bpdisp disp) 00368 { 00369 /* NOTE: the following values are a part of MI protocol and 00370 represent values of 'disp' field returned when inferior stops at 00371 a breakpoint. */ 00372 static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; 00373 00374 return bpdisps[(int) disp]; 00375 } 00376 00377 /* Prototypes for exported functions. */ 00378 /* If FALSE, gdb will not use hardware support for watchpoints, even 00379 if such is available. */ 00380 static int can_use_hw_watchpoints; 00381 00382 static void 00383 show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, 00384 struct cmd_list_element *c, 00385 const char *value) 00386 { 00387 fprintf_filtered (file, 00388 _("Debugger's willingness to use " 00389 "watchpoint hardware is %s.\n"), 00390 value); 00391 } 00392 00393 /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. 00394 If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints 00395 for unrecognized breakpoint locations. 00396 If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ 00397 static enum auto_boolean pending_break_support; 00398 static void 00399 show_pending_break_support (struct ui_file *file, int from_tty, 00400 struct cmd_list_element *c, 00401 const char *value) 00402 { 00403 fprintf_filtered (file, 00404 _("Debugger's behavior regarding " 00405 "pending breakpoints is %s.\n"), 00406 value); 00407 } 00408 00409 /* If 1, gdb will automatically use hardware breakpoints for breakpoints 00410 set with "break" but falling in read-only memory. 00411 If 0, gdb will warn about such breakpoints, but won't automatically 00412 use hardware breakpoints. */ 00413 static int automatic_hardware_breakpoints; 00414 static void 00415 show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, 00416 struct cmd_list_element *c, 00417 const char *value) 00418 { 00419 fprintf_filtered (file, 00420 _("Automatic usage of hardware breakpoints is %s.\n"), 00421 value); 00422 } 00423 00424 /* If on, gdb will keep breakpoints inserted even as inferior is 00425 stopped, and immediately insert any new breakpoints. If off, gdb 00426 will insert breakpoints into inferior only when resuming it, and 00427 will remove breakpoints upon stop. If auto, GDB will behave as ON 00428 if in non-stop mode, and as OFF if all-stop mode.*/ 00429 00430 static enum auto_boolean always_inserted_mode = AUTO_BOOLEAN_AUTO; 00431 00432 static void 00433 show_always_inserted_mode (struct ui_file *file, int from_tty, 00434 struct cmd_list_element *c, const char *value) 00435 { 00436 if (always_inserted_mode == AUTO_BOOLEAN_AUTO) 00437 fprintf_filtered (file, 00438 _("Always inserted breakpoint " 00439 "mode is %s (currently %s).\n"), 00440 value, 00441 breakpoints_always_inserted_mode () ? "on" : "off"); 00442 else 00443 fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), 00444 value); 00445 } 00446 00447 int 00448 breakpoints_always_inserted_mode (void) 00449 { 00450 return (always_inserted_mode == AUTO_BOOLEAN_TRUE 00451 || (always_inserted_mode == AUTO_BOOLEAN_AUTO && non_stop)); 00452 } 00453 00454 static const char condition_evaluation_both[] = "host or target"; 00455 00456 /* Modes for breakpoint condition evaluation. */ 00457 static const char condition_evaluation_auto[] = "auto"; 00458 static const char condition_evaluation_host[] = "host"; 00459 static const char condition_evaluation_target[] = "target"; 00460 static const char *const condition_evaluation_enums[] = { 00461 condition_evaluation_auto, 00462 condition_evaluation_host, 00463 condition_evaluation_target, 00464 NULL 00465 }; 00466 00467 /* Global that holds the current mode for breakpoint condition evaluation. */ 00468 static const char *condition_evaluation_mode_1 = condition_evaluation_auto; 00469 00470 /* Global that we use to display information to the user (gets its value from 00471 condition_evaluation_mode_1. */ 00472 static const char *condition_evaluation_mode = condition_evaluation_auto; 00473 00474 /* Translate a condition evaluation mode MODE into either "host" 00475 or "target". This is used mostly to translate from "auto" to the 00476 real setting that is being used. It returns the translated 00477 evaluation mode. */ 00478 00479 static const char * 00480 translate_condition_evaluation_mode (const char *mode) 00481 { 00482 if (mode == condition_evaluation_auto) 00483 { 00484 if (target_supports_evaluation_of_breakpoint_conditions ()) 00485 return condition_evaluation_target; 00486 else 00487 return condition_evaluation_host; 00488 } 00489 else 00490 return mode; 00491 } 00492 00493 /* Discovers what condition_evaluation_auto translates to. */ 00494 00495 static const char * 00496 breakpoint_condition_evaluation_mode (void) 00497 { 00498 return translate_condition_evaluation_mode (condition_evaluation_mode); 00499 } 00500 00501 /* Return true if GDB should evaluate breakpoint conditions or false 00502 otherwise. */ 00503 00504 static int 00505 gdb_evaluates_breakpoint_condition_p (void) 00506 { 00507 const char *mode = breakpoint_condition_evaluation_mode (); 00508 00509 return (mode == condition_evaluation_host); 00510 } 00511 00512 void _initialize_breakpoint (void); 00513 00514 /* Are we executing breakpoint commands? */ 00515 static int executing_breakpoint_commands; 00516 00517 /* Are overlay event breakpoints enabled? */ 00518 static int overlay_events_enabled; 00519 00520 /* See description in breakpoint.h. */ 00521 int target_exact_watchpoints = 0; 00522 00523 /* Walk the following statement or block through all breakpoints. 00524 ALL_BREAKPOINTS_SAFE does so even if the statement deletes the 00525 current breakpoint. */ 00526 00527 #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) 00528 00529 #define ALL_BREAKPOINTS_SAFE(B,TMP) \ 00530 for (B = breakpoint_chain; \ 00531 B ? (TMP=B->next, 1): 0; \ 00532 B = TMP) 00533 00534 /* Similar iterator for the low-level breakpoints. SAFE variant is 00535 not provided so update_global_location_list must not be called 00536 while executing the block of ALL_BP_LOCATIONS. */ 00537 00538 #define ALL_BP_LOCATIONS(B,BP_TMP) \ 00539 for (BP_TMP = bp_location; \ 00540 BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ 00541 BP_TMP++) 00542 00543 /* Iterates through locations with address ADDRESS for the currently selected 00544 program space. BP_LOCP_TMP points to each object. BP_LOCP_START points 00545 to where the loop should start from. 00546 If BP_LOCP_START is a NULL pointer, the macro automatically seeks the 00547 appropriate location to start with. */ 00548 00549 #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ 00550 for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ 00551 BP_LOCP_TMP = BP_LOCP_START; \ 00552 BP_LOCP_START \ 00553 && (BP_LOCP_TMP < bp_location + bp_location_count \ 00554 && (*BP_LOCP_TMP)->address == ADDRESS); \ 00555 BP_LOCP_TMP++) 00556 00557 /* Iterator for tracepoints only. */ 00558 00559 #define ALL_TRACEPOINTS(B) \ 00560 for (B = breakpoint_chain; B; B = B->next) \ 00561 if (is_tracepoint (B)) 00562 00563 /* Chains of all breakpoints defined. */ 00564 00565 struct breakpoint *breakpoint_chain; 00566 00567 /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ 00568 00569 static struct bp_location **bp_location; 00570 00571 /* Number of elements of BP_LOCATION. */ 00572 00573 static unsigned bp_location_count; 00574 00575 /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and 00576 ADDRESS for the current elements of BP_LOCATION which get a valid 00577 result from bp_location_has_shadow. You can use it for roughly 00578 limiting the subrange of BP_LOCATION to scan for shadow bytes for 00579 an address you need to read. */ 00580 00581 static CORE_ADDR bp_location_placed_address_before_address_max; 00582 00583 /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS 00584 + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of 00585 BP_LOCATION which get a valid result from bp_location_has_shadow. 00586 You can use it for roughly limiting the subrange of BP_LOCATION to 00587 scan for shadow bytes for an address you need to read. */ 00588 00589 static CORE_ADDR bp_location_shadow_len_after_address_max; 00590 00591 /* The locations that no longer correspond to any breakpoint, unlinked 00592 from bp_location array, but for which a hit may still be reported 00593 by a target. */ 00594 VEC(bp_location_p) *moribund_locations = NULL; 00595 00596 /* Number of last breakpoint made. */ 00597 00598 static int breakpoint_count; 00599 00600 /* The value of `breakpoint_count' before the last command that 00601 created breakpoints. If the last (break-like) command created more 00602 than one breakpoint, then the difference between BREAKPOINT_COUNT 00603 and PREV_BREAKPOINT_COUNT is more than one. */ 00604 static int prev_breakpoint_count; 00605 00606 /* Number of last tracepoint made. */ 00607 00608 static int tracepoint_count; 00609 00610 static struct cmd_list_element *breakpoint_set_cmdlist; 00611 static struct cmd_list_element *breakpoint_show_cmdlist; 00612 struct cmd_list_element *save_cmdlist; 00613 00614 /* Return whether a breakpoint is an active enabled breakpoint. */ 00615 static int 00616 breakpoint_enabled (struct breakpoint *b) 00617 { 00618 return (b->enable_state == bp_enabled); 00619 } 00620 00621 /* Set breakpoint count to NUM. */ 00622 00623 static void 00624 set_breakpoint_count (int num) 00625 { 00626 prev_breakpoint_count = breakpoint_count; 00627 breakpoint_count = num; 00628 set_internalvar_integer (lookup_internalvar ("bpnum"), num); 00629 } 00630 00631 /* Used by `start_rbreak_breakpoints' below, to record the current 00632 breakpoint count before "rbreak" creates any breakpoint. */ 00633 static int rbreak_start_breakpoint_count; 00634 00635 /* Called at the start an "rbreak" command to record the first 00636 breakpoint made. */ 00637 00638 void 00639 start_rbreak_breakpoints (void) 00640 { 00641 rbreak_start_breakpoint_count = breakpoint_count; 00642 } 00643 00644 /* Called at the end of an "rbreak" command to record the last 00645 breakpoint made. */ 00646 00647 void 00648 end_rbreak_breakpoints (void) 00649 { 00650 prev_breakpoint_count = rbreak_start_breakpoint_count; 00651 } 00652 00653 /* Used in run_command to zero the hit count when a new run starts. */ 00654 00655 void 00656 clear_breakpoint_hit_counts (void) 00657 { 00658 struct breakpoint *b; 00659 00660 ALL_BREAKPOINTS (b) 00661 b->hit_count = 0; 00662 } 00663 00664 /* Allocate a new counted_command_line with reference count of 1. 00665 The new structure owns COMMANDS. */ 00666 00667 static struct counted_command_line * 00668 alloc_counted_command_line (struct command_line *commands) 00669 { 00670 struct counted_command_line *result 00671 = xmalloc (sizeof (struct counted_command_line)); 00672 00673 result->refc = 1; 00674 result->commands = commands; 00675 return result; 00676 } 00677 00678 /* Increment reference count. This does nothing if CMD is NULL. */ 00679 00680 static void 00681 incref_counted_command_line (struct counted_command_line *cmd) 00682 { 00683 if (cmd) 00684 ++cmd->refc; 00685 } 00686 00687 /* Decrement reference count. If the reference count reaches 0, 00688 destroy the counted_command_line. Sets *CMDP to NULL. This does 00689 nothing if *CMDP is NULL. */ 00690 00691 static void 00692 decref_counted_command_line (struct counted_command_line **cmdp) 00693 { 00694 if (*cmdp) 00695 { 00696 if (--(*cmdp)->refc == 0) 00697 { 00698 free_command_lines (&(*cmdp)->commands); 00699 xfree (*cmdp); 00700 } 00701 *cmdp = NULL; 00702 } 00703 } 00704 00705 /* A cleanup function that calls decref_counted_command_line. */ 00706 00707 static void 00708 do_cleanup_counted_command_line (void *arg) 00709 { 00710 decref_counted_command_line (arg); 00711 } 00712 00713 /* Create a cleanup that calls decref_counted_command_line on the 00714 argument. */ 00715 00716 static struct cleanup * 00717 make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) 00718 { 00719 return make_cleanup (do_cleanup_counted_command_line, cmdp); 00720 } 00721 00722 00723 /* Return the breakpoint with the specified number, or NULL 00724 if the number does not refer to an existing breakpoint. */ 00725 00726 struct breakpoint * 00727 get_breakpoint (int num) 00728 { 00729 struct breakpoint *b; 00730 00731 ALL_BREAKPOINTS (b) 00732 if (b->number == num) 00733 return b; 00734 00735 return NULL; 00736 } 00737 00738 00739 00740 /* Mark locations as "conditions have changed" in case the target supports 00741 evaluating conditions on its side. */ 00742 00743 static void 00744 mark_breakpoint_modified (struct breakpoint *b) 00745 { 00746 struct bp_location *loc; 00747 00748 /* This is only meaningful if the target is 00749 evaluating conditions and if the user has 00750 opted for condition evaluation on the target's 00751 side. */ 00752 if (gdb_evaluates_breakpoint_condition_p () 00753 || !target_supports_evaluation_of_breakpoint_conditions ()) 00754 return; 00755 00756 if (!is_breakpoint (b)) 00757 return; 00758 00759 for (loc = b->loc; loc; loc = loc->next) 00760 loc->condition_changed = condition_modified; 00761 } 00762 00763 /* Mark location as "conditions have changed" in case the target supports 00764 evaluating conditions on its side. */ 00765 00766 static void 00767 mark_breakpoint_location_modified (struct bp_location *loc) 00768 { 00769 /* This is only meaningful if the target is 00770 evaluating conditions and if the user has 00771 opted for condition evaluation on the target's 00772 side. */ 00773 if (gdb_evaluates_breakpoint_condition_p () 00774 || !target_supports_evaluation_of_breakpoint_conditions ()) 00775 00776 return; 00777 00778 if (!is_breakpoint (loc->owner)) 00779 return; 00780 00781 loc->condition_changed = condition_modified; 00782 } 00783 00784 /* Sets the condition-evaluation mode using the static global 00785 condition_evaluation_mode. */ 00786 00787 static void 00788 set_condition_evaluation_mode (char *args, int from_tty, 00789 struct cmd_list_element *c) 00790 { 00791 const char *old_mode, *new_mode; 00792 00793 if ((condition_evaluation_mode_1 == condition_evaluation_target) 00794 && !target_supports_evaluation_of_breakpoint_conditions ()) 00795 { 00796 condition_evaluation_mode_1 = condition_evaluation_mode; 00797 warning (_("Target does not support breakpoint condition evaluation.\n" 00798 "Using host evaluation mode instead.")); 00799 return; 00800 } 00801 00802 new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); 00803 old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); 00804 00805 /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the 00806 settings was "auto". */ 00807 condition_evaluation_mode = condition_evaluation_mode_1; 00808 00809 /* Only update the mode if the user picked a different one. */ 00810 if (new_mode != old_mode) 00811 { 00812 struct bp_location *loc, **loc_tmp; 00813 /* If the user switched to a different evaluation mode, we 00814 need to synch the changes with the target as follows: 00815 00816 "host" -> "target": Send all (valid) conditions to the target. 00817 "target" -> "host": Remove all the conditions from the target. 00818 */ 00819 00820 if (new_mode == condition_evaluation_target) 00821 { 00822 /* Mark everything modified and synch conditions with the 00823 target. */ 00824 ALL_BP_LOCATIONS (loc, loc_tmp) 00825 mark_breakpoint_location_modified (loc); 00826 } 00827 else 00828 { 00829 /* Manually mark non-duplicate locations to synch conditions 00830 with the target. We do this to remove all the conditions the 00831 target knows about. */ 00832 ALL_BP_LOCATIONS (loc, loc_tmp) 00833 if (is_breakpoint (loc->owner) && loc->inserted) 00834 loc->needs_update = 1; 00835 } 00836 00837 /* Do the update. */ 00838 update_global_location_list (1); 00839 } 00840 00841 return; 00842 } 00843 00844 /* Shows the current mode of breakpoint condition evaluation. Explicitly shows 00845 what "auto" is translating to. */ 00846 00847 static void 00848 show_condition_evaluation_mode (struct ui_file *file, int from_tty, 00849 struct cmd_list_element *c, const char *value) 00850 { 00851 if (condition_evaluation_mode == condition_evaluation_auto) 00852 fprintf_filtered (file, 00853 _("Breakpoint condition evaluation " 00854 "mode is %s (currently %s).\n"), 00855 value, 00856 breakpoint_condition_evaluation_mode ()); 00857 else 00858 fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), 00859 value); 00860 } 00861 00862 /* A comparison function for bp_location AP and BP that is used by 00863 bsearch. This comparison function only cares about addresses, unlike 00864 the more general bp_location_compare function. */ 00865 00866 static int 00867 bp_location_compare_addrs (const void *ap, const void *bp) 00868 { 00869 struct bp_location *a = *(void **) ap; 00870 struct bp_location *b = *(void **) bp; 00871 00872 if (a->address == b->address) 00873 return 0; 00874 else 00875 return ((a->address > b->address) - (a->address < b->address)); 00876 } 00877 00878 /* Helper function to skip all bp_locations with addresses 00879 less than ADDRESS. It returns the first bp_location that 00880 is greater than or equal to ADDRESS. If none is found, just 00881 return NULL. */ 00882 00883 static struct bp_location ** 00884 get_first_locp_gte_addr (CORE_ADDR address) 00885 { 00886 struct bp_location dummy_loc; 00887 struct bp_location *dummy_locp = &dummy_loc; 00888 struct bp_location **locp_found = NULL; 00889 00890 /* Initialize the dummy location's address field. */ 00891 memset (&dummy_loc, 0, sizeof (struct bp_location)); 00892 dummy_loc.address = address; 00893 00894 /* Find a close match to the first location at ADDRESS. */ 00895 locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, 00896 sizeof (struct bp_location **), 00897 bp_location_compare_addrs); 00898 00899 /* Nothing was found, nothing left to do. */ 00900 if (locp_found == NULL) 00901 return NULL; 00902 00903 /* We may have found a location that is at ADDRESS but is not the first in the 00904 location's list. Go backwards (if possible) and locate the first one. */ 00905 while ((locp_found - 1) >= bp_location 00906 && (*(locp_found - 1))->address == address) 00907 locp_found--; 00908 00909 return locp_found; 00910 } 00911 00912 void 00913 set_breakpoint_condition (struct breakpoint *b, char *exp, 00914 int from_tty) 00915 { 00916 xfree (b->cond_string); 00917 b->cond_string = NULL; 00918 00919 if (is_watchpoint (b)) 00920 { 00921 struct watchpoint *w = (struct watchpoint *) b; 00922 00923 xfree (w->cond_exp); 00924 w->cond_exp = NULL; 00925 } 00926 else 00927 { 00928 struct bp_location *loc; 00929 00930 for (loc = b->loc; loc; loc = loc->next) 00931 { 00932 xfree (loc->cond); 00933 loc->cond = NULL; 00934 00935 /* No need to free the condition agent expression 00936 bytecode (if we have one). We will handle this 00937 when we go through update_global_location_list. */ 00938 } 00939 } 00940 00941 if (*exp == 0) 00942 { 00943 if (from_tty) 00944 printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); 00945 } 00946 else 00947 { 00948 const char *arg = exp; 00949 00950 /* I don't know if it matters whether this is the string the user 00951 typed in or the decompiled expression. */ 00952 b->cond_string = xstrdup (arg); 00953 b->condition_not_parsed = 0; 00954 00955 if (is_watchpoint (b)) 00956 { 00957 struct watchpoint *w = (struct watchpoint *) b; 00958 00959 innermost_block = NULL; 00960 arg = exp; 00961 w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); 00962 if (*arg) 00963 error (_("Junk at end of expression")); 00964 w->cond_exp_valid_block = innermost_block; 00965 } 00966 else 00967 { 00968 struct bp_location *loc; 00969 00970 for (loc = b->loc; loc; loc = loc->next) 00971 { 00972 arg = exp; 00973 loc->cond = 00974 parse_exp_1 (&arg, loc->address, 00975 block_for_pc (loc->address), 0); 00976 if (*arg) 00977 error (_("Junk at end of expression")); 00978 } 00979 } 00980 } 00981 mark_breakpoint_modified (b); 00982 00983 observer_notify_breakpoint_modified (b); 00984 } 00985 00986 /* Completion for the "condition" command. */ 00987 00988 static VEC (char_ptr) * 00989 condition_completer (struct cmd_list_element *cmd, 00990 const char *text, const char *word) 00991 { 00992 const char *space; 00993 00994 text = skip_spaces_const (text); 00995 space = skip_to_space_const (text); 00996 if (*space == '\0') 00997 { 00998 int len; 00999 struct breakpoint *b; 01000 VEC (char_ptr) *result = NULL; 01001 01002 if (text[0] == '$') 01003 { 01004 /* We don't support completion of history indices. */ 01005 if (isdigit (text[1])) 01006 return NULL; 01007 return complete_internalvar (&text[1]); 01008 } 01009 01010 /* We're completing the breakpoint number. */ 01011 len = strlen (text); 01012 01013 ALL_BREAKPOINTS (b) 01014 { 01015 char number[50]; 01016 01017 xsnprintf (number, sizeof (number), "%d", b->number); 01018 01019 if (strncmp (number, text, len) == 0) 01020 VEC_safe_push (char_ptr, result, xstrdup (number)); 01021 } 01022 01023 return result; 01024 } 01025 01026 /* We're completing the expression part. */ 01027 text = skip_spaces_const (space); 01028 return expression_completer (cmd, text, word); 01029 } 01030 01031 /* condition N EXP -- set break condition of breakpoint N to EXP. */ 01032 01033 static void 01034 condition_command (char *arg, int from_tty) 01035 { 01036 struct breakpoint *b; 01037 char *p; 01038 int bnum; 01039 01040 if (arg == 0) 01041 error_no_arg (_("breakpoint number")); 01042 01043 p = arg; 01044 bnum = get_number (&p); 01045 if (bnum == 0) 01046 error (_("Bad breakpoint argument: '%s'"), arg); 01047 01048 ALL_BREAKPOINTS (b) 01049 if (b->number == bnum) 01050 { 01051 /* Check if this breakpoint has a Python object assigned to 01052 it, and if it has a definition of the "stop" 01053 method. This method and conditions entered into GDB from 01054 the CLI are mutually exclusive. */ 01055 if (b->py_bp_object 01056 && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) 01057 error (_("Cannot set a condition where a Python 'stop' " 01058 "method has been defined in the breakpoint.")); 01059 set_breakpoint_condition (b, p, from_tty); 01060 01061 if (is_breakpoint (b)) 01062 update_global_location_list (1); 01063 01064 return; 01065 } 01066 01067 error (_("No breakpoint number %d."), bnum); 01068 } 01069 01070 /* Check that COMMAND do not contain commands that are suitable 01071 only for tracepoints and not suitable for ordinary breakpoints. 01072 Throw if any such commands is found. */ 01073 01074 static void 01075 check_no_tracepoint_commands (struct command_line *commands) 01076 { 01077 struct command_line *c; 01078 01079 for (c = commands; c; c = c->next) 01080 { 01081 int i; 01082 01083 if (c->control_type == while_stepping_control) 01084 error (_("The 'while-stepping' command can " 01085 "only be used for tracepoints")); 01086 01087 for (i = 0; i < c->body_count; ++i) 01088 check_no_tracepoint_commands ((c->body_list)[i]); 01089 01090 /* Not that command parsing removes leading whitespace and comment 01091 lines and also empty lines. So, we only need to check for 01092 command directly. */ 01093 if (strstr (c->line, "collect ") == c->line) 01094 error (_("The 'collect' command can only be used for tracepoints")); 01095 01096 if (strstr (c->line, "teval ") == c->line) 01097 error (_("The 'teval' command can only be used for tracepoints")); 01098 } 01099 } 01100 01101 /* Encapsulate tests for different types of tracepoints. */ 01102 01103 static int 01104 is_tracepoint_type (enum bptype type) 01105 { 01106 return (type == bp_tracepoint 01107 || type == bp_fast_tracepoint 01108 || type == bp_static_tracepoint); 01109 } 01110 01111 int 01112 is_tracepoint (const struct breakpoint *b) 01113 { 01114 return is_tracepoint_type (b->type); 01115 } 01116 01117 /* A helper function that validates that COMMANDS are valid for a 01118 breakpoint. This function will throw an exception if a problem is 01119 found. */ 01120 01121 static void 01122 validate_commands_for_breakpoint (struct breakpoint *b, 01123 struct command_line *commands) 01124 { 01125 if (is_tracepoint (b)) 01126 { 01127 struct tracepoint *t = (struct tracepoint *) b; 01128 struct command_line *c; 01129 struct command_line *while_stepping = 0; 01130 01131 /* Reset the while-stepping step count. The previous commands 01132 might have included a while-stepping action, while the new 01133 ones might not. */ 01134 t->step_count = 0; 01135 01136 /* We need to verify that each top-level element of commands is 01137 valid for tracepoints, that there's at most one 01138 while-stepping element, and that the while-stepping's body 01139 has valid tracing commands excluding nested while-stepping. 01140 We also need to validate the tracepoint action line in the 01141 context of the tracepoint --- validate_actionline actually 01142 has side effects, like setting the tracepoint's 01143 while-stepping STEP_COUNT, in addition to checking if the 01144 collect/teval actions parse and make sense in the 01145 tracepoint's context. */ 01146 for (c = commands; c; c = c->next) 01147 { 01148 if (c->control_type == while_stepping_control) 01149 { 01150 if (b->type == bp_fast_tracepoint) 01151 error (_("The 'while-stepping' command " 01152 "cannot be used for fast tracepoint")); 01153 else if (b->type == bp_static_tracepoint) 01154 error (_("The 'while-stepping' command " 01155 "cannot be used for static tracepoint")); 01156 01157 if (while_stepping) 01158 error (_("The 'while-stepping' command " 01159 "can be used only once")); 01160 else 01161 while_stepping = c; 01162 } 01163 01164 validate_actionline (c->line, b); 01165 } 01166 if (while_stepping) 01167 { 01168 struct command_line *c2; 01169 01170 gdb_assert (while_stepping->body_count == 1); 01171 c2 = while_stepping->body_list[0]; 01172 for (; c2; c2 = c2->next) 01173 { 01174 if (c2->control_type == while_stepping_control) 01175 error (_("The 'while-stepping' command cannot be nested")); 01176 } 01177 } 01178 } 01179 else 01180 { 01181 check_no_tracepoint_commands (commands); 01182 } 01183 } 01184 01185 /* Return a vector of all the static tracepoints set at ADDR. The 01186 caller is responsible for releasing the vector. */ 01187 01188 VEC(breakpoint_p) * 01189 static_tracepoints_here (CORE_ADDR addr) 01190 { 01191 struct breakpoint *b; 01192 VEC(breakpoint_p) *found = 0; 01193 struct bp_location *loc; 01194 01195 ALL_BREAKPOINTS (b) 01196 if (b->type == bp_static_tracepoint) 01197 { 01198 for (loc = b->loc; loc; loc = loc->next) 01199 if (loc->address == addr) 01200 VEC_safe_push(breakpoint_p, found, b); 01201 } 01202 01203 return found; 01204 } 01205 01206 /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, 01207 validate that only allowed commands are included. */ 01208 01209 void 01210 breakpoint_set_commands (struct breakpoint *b, 01211 struct command_line *commands) 01212 { 01213 validate_commands_for_breakpoint (b, commands); 01214 01215 decref_counted_command_line (&b->commands); 01216 b->commands = alloc_counted_command_line (commands); 01217 observer_notify_breakpoint_modified (b); 01218 } 01219 01220 /* Set the internal `silent' flag on the breakpoint. Note that this 01221 is not the same as the "silent" that may appear in the breakpoint's 01222 commands. */ 01223 01224 void 01225 breakpoint_set_silent (struct breakpoint *b, int silent) 01226 { 01227 int old_silent = b->silent; 01228 01229 b->silent = silent; 01230 if (old_silent != silent) 01231 observer_notify_breakpoint_modified (b); 01232 } 01233 01234 /* Set the thread for this breakpoint. If THREAD is -1, make the 01235 breakpoint work for any thread. */ 01236 01237 void 01238 breakpoint_set_thread (struct breakpoint *b, int thread) 01239 { 01240 int old_thread = b->thread; 01241 01242 b->thread = thread; 01243 if (old_thread != thread) 01244 observer_notify_breakpoint_modified (b); 01245 } 01246 01247 /* Set the task for this breakpoint. If TASK is 0, make the 01248 breakpoint work for any task. */ 01249 01250 void 01251 breakpoint_set_task (struct breakpoint *b, int task) 01252 { 01253 int old_task = b->task; 01254 01255 b->task = task; 01256 if (old_task != task) 01257 observer_notify_breakpoint_modified (b); 01258 } 01259 01260 void 01261 check_tracepoint_command (char *line, void *closure) 01262 { 01263 struct breakpoint *b = closure; 01264 01265 validate_actionline (line, b); 01266 } 01267 01268 /* A structure used to pass information through 01269 map_breakpoint_numbers. */ 01270 01271 struct commands_info 01272 { 01273 /* True if the command was typed at a tty. */ 01274 int from_tty; 01275 01276 /* The breakpoint range spec. */ 01277 char *arg; 01278 01279 /* Non-NULL if the body of the commands are being read from this 01280 already-parsed command. */ 01281 struct command_line *control; 01282 01283 /* The command lines read from the user, or NULL if they have not 01284 yet been read. */ 01285 struct counted_command_line *cmd; 01286 }; 01287 01288 /* A callback for map_breakpoint_numbers that sets the commands for 01289 commands_command. */ 01290 01291 static void 01292 do_map_commands_command (struct breakpoint *b, void *data) 01293 { 01294 struct commands_info *info = data; 01295 01296 if (info->cmd == NULL) 01297 { 01298 struct command_line *l; 01299 01300 if (info->control != NULL) 01301 l = copy_command_lines (info->control->body_list[0]); 01302 else 01303 { 01304 struct cleanup *old_chain; 01305 char *str; 01306 01307 str = xstrprintf (_("Type commands for breakpoint(s) " 01308 "%s, one per line."), 01309 info->arg); 01310 01311 old_chain = make_cleanup (xfree, str); 01312 01313 l = read_command_lines (str, 01314 info->from_tty, 1, 01315 (is_tracepoint (b) 01316 ? check_tracepoint_command : 0), 01317 b); 01318 01319 do_cleanups (old_chain); 01320 } 01321 01322 info->cmd = alloc_counted_command_line (l); 01323 } 01324 01325 /* If a breakpoint was on the list more than once, we don't need to 01326 do anything. */ 01327 if (b->commands != info->cmd) 01328 { 01329 validate_commands_for_breakpoint (b, info->cmd->commands); 01330 incref_counted_command_line (info->cmd); 01331 decref_counted_command_line (&b->commands); 01332 b->commands = info->cmd; 01333 observer_notify_breakpoint_modified (b); 01334 } 01335 } 01336 01337 static void 01338 commands_command_1 (char *arg, int from_tty, 01339 struct command_line *control) 01340 { 01341 struct cleanup *cleanups; 01342 struct commands_info info; 01343 01344 info.from_tty = from_tty; 01345 info.control = control; 01346 info.cmd = NULL; 01347 /* If we read command lines from the user, then `info' will hold an 01348 extra reference to the commands that we must clean up. */ 01349 cleanups = make_cleanup_decref_counted_command_line (&info.cmd); 01350 01351 if (arg == NULL || !*arg) 01352 { 01353 if (breakpoint_count - prev_breakpoint_count > 1) 01354 arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, 01355 breakpoint_count); 01356 else if (breakpoint_count > 0) 01357 arg = xstrprintf ("%d", breakpoint_count); 01358 else 01359 { 01360 /* So that we don't try to free the incoming non-NULL 01361 argument in the cleanup below. Mapping breakpoint 01362 numbers will fail in this case. */ 01363 arg = NULL; 01364 } 01365 } 01366 else 01367 /* The command loop has some static state, so we need to preserve 01368 our argument. */ 01369 arg = xstrdup (arg); 01370 01371 if (arg != NULL) 01372 make_cleanup (xfree, arg); 01373 01374 info.arg = arg; 01375 01376 map_breakpoint_numbers (arg, do_map_commands_command, &info); 01377 01378 if (info.cmd == NULL) 01379 error (_("No breakpoints specified.")); 01380 01381 do_cleanups (cleanups); 01382 } 01383 01384 static void 01385 commands_command (char *arg, int from_tty) 01386 { 01387 commands_command_1 (arg, from_tty, NULL); 01388 } 01389 01390 /* Like commands_command, but instead of reading the commands from 01391 input stream, takes them from an already parsed command structure. 01392 01393 This is used by cli-script.c to DTRT with breakpoint commands 01394 that are part of if and while bodies. */ 01395 enum command_control_type 01396 commands_from_control_command (char *arg, struct command_line *cmd) 01397 { 01398 commands_command_1 (arg, 0, cmd); 01399 return simple_control; 01400 } 01401 01402 /* Return non-zero if BL->TARGET_INFO contains valid information. */ 01403 01404 static int 01405 bp_location_has_shadow (struct bp_location *bl) 01406 { 01407 if (bl->loc_type != bp_loc_software_breakpoint) 01408 return 0; 01409 if (!bl->inserted) 01410 return 0; 01411 if (bl->target_info.shadow_len == 0) 01412 /* BL isn't valid, or doesn't shadow memory. */ 01413 return 0; 01414 return 1; 01415 } 01416 01417 /* Update BUF, which is LEN bytes read from the target address MEMADDR, 01418 by replacing any memory breakpoints with their shadowed contents. 01419 01420 If READBUF is not NULL, this buffer must not overlap with any of 01421 the breakpoint location's shadow_contents buffers. Otherwise, 01422 a failed assertion internal error will be raised. 01423 01424 The range of shadowed area by each bp_location is: 01425 bl->address - bp_location_placed_address_before_address_max 01426 up to bl->address + bp_location_shadow_len_after_address_max 01427 The range we were requested to resolve shadows for is: 01428 memaddr ... memaddr + len 01429 Thus the safe cutoff boundaries for performance optimization are 01430 memaddr + len <= (bl->address 01431 - bp_location_placed_address_before_address_max) 01432 and: 01433 bl->address + bp_location_shadow_len_after_address_max <= memaddr */ 01434 01435 void 01436 breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, 01437 const gdb_byte *writebuf_org, 01438 ULONGEST memaddr, LONGEST len) 01439 { 01440 /* Left boundary, right boundary and median element of our binary 01441 search. */ 01442 unsigned bc_l, bc_r, bc; 01443 01444 /* Find BC_L which is a leftmost element which may affect BUF 01445 content. It is safe to report lower value but a failure to 01446 report higher one. */ 01447 01448 bc_l = 0; 01449 bc_r = bp_location_count; 01450 while (bc_l + 1 < bc_r) 01451 { 01452 struct bp_location *bl; 01453 01454 bc = (bc_l + bc_r) / 2; 01455 bl = bp_location[bc]; 01456 01457 /* Check first BL->ADDRESS will not overflow due to the added 01458 constant. Then advance the left boundary only if we are sure 01459 the BC element can in no way affect the BUF content (MEMADDR 01460 to MEMADDR + LEN range). 01461 01462 Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety 01463 offset so that we cannot miss a breakpoint with its shadow 01464 range tail still reaching MEMADDR. */ 01465 01466 if ((bl->address + bp_location_shadow_len_after_address_max 01467 >= bl->address) 01468 && (bl->address + bp_location_shadow_len_after_address_max 01469 <= memaddr)) 01470 bc_l = bc; 01471 else 01472 bc_r = bc; 01473 } 01474 01475 /* Due to the binary search above, we need to make sure we pick the 01476 first location that's at BC_L's address. E.g., if there are 01477 multiple locations at the same address, BC_L may end up pointing 01478 at a duplicate location, and miss the "master"/"inserted" 01479 location. Say, given locations L1, L2 and L3 at addresses A and 01480 B: 01481 01482 L1@A, L2@A, L3@B, ... 01483 01484 BC_L could end up pointing at location L2, while the "master" 01485 location could be L1. Since the `loc->inserted' flag is only set 01486 on "master" locations, we'd forget to restore the shadow of L1 01487 and L2. */ 01488 while (bc_l > 0 01489 && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) 01490 bc_l--; 01491 01492 /* Now do full processing of the found relevant range of elements. */ 01493 01494 for (bc = bc_l; bc < bp_location_count; bc++) 01495 { 01496 struct bp_location *bl = bp_location[bc]; 01497 CORE_ADDR bp_addr = 0; 01498 int bp_size = 0; 01499 int bptoffset = 0; 01500 01501 /* bp_location array has BL->OWNER always non-NULL. */ 01502 if (bl->owner->type == bp_none) 01503 warning (_("reading through apparently deleted breakpoint #%d?"), 01504 bl->owner->number); 01505 01506 /* Performance optimization: any further element can no longer affect BUF 01507 content. */ 01508 01509 if (bl->address >= bp_location_placed_address_before_address_max 01510 && memaddr + len <= (bl->address 01511 - bp_location_placed_address_before_address_max)) 01512 break; 01513 01514 if (!bp_location_has_shadow (bl)) 01515 continue; 01516 if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, 01517 current_program_space->aspace, 0)) 01518 continue; 01519 01520 /* Addresses and length of the part of the breakpoint that 01521 we need to copy. */ 01522 bp_addr = bl->target_info.placed_address; 01523 bp_size = bl->target_info.shadow_len; 01524 01525 if (bp_addr + bp_size <= memaddr) 01526 /* The breakpoint is entirely before the chunk of memory we 01527 are reading. */ 01528 continue; 01529 01530 if (bp_addr >= memaddr + len) 01531 /* The breakpoint is entirely after the chunk of memory we are 01532 reading. */ 01533 continue; 01534 01535 /* Offset within shadow_contents. */ 01536 if (bp_addr < memaddr) 01537 { 01538 /* Only copy the second part of the breakpoint. */ 01539 bp_size -= memaddr - bp_addr; 01540 bptoffset = memaddr - bp_addr; 01541 bp_addr = memaddr; 01542 } 01543 01544 if (bp_addr + bp_size > memaddr + len) 01545 { 01546 /* Only copy the first part of the breakpoint. */ 01547 bp_size -= (bp_addr + bp_size) - (memaddr + len); 01548 } 01549 01550 if (readbuf != NULL) 01551 { 01552 /* Verify that the readbuf buffer does not overlap with 01553 the shadow_contents buffer. */ 01554 gdb_assert (bl->target_info.shadow_contents >= readbuf + len 01555 || readbuf >= (bl->target_info.shadow_contents 01556 + bl->target_info.shadow_len)); 01557 01558 /* Update the read buffer with this inserted breakpoint's 01559 shadow. */ 01560 memcpy (readbuf + bp_addr - memaddr, 01561 bl->target_info.shadow_contents + bptoffset, bp_size); 01562 } 01563 else 01564 { 01565 struct gdbarch *gdbarch = bl->gdbarch; 01566 const unsigned char *bp; 01567 CORE_ADDR placed_address = bl->target_info.placed_address; 01568 int placed_size = bl->target_info.placed_size; 01569 01570 /* Update the shadow with what we want to write to memory. */ 01571 memcpy (bl->target_info.shadow_contents + bptoffset, 01572 writebuf_org + bp_addr - memaddr, bp_size); 01573 01574 /* Determine appropriate breakpoint contents and size for this 01575 address. */ 01576 bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); 01577 01578 /* Update the final write buffer with this inserted 01579 breakpoint's INSN. */ 01580 memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); 01581 } 01582 } 01583 } 01584 01585 01586 /* Return true if BPT is either a software breakpoint or a hardware 01587 breakpoint. */ 01588 01589 int 01590 is_breakpoint (const struct breakpoint *bpt) 01591 { 01592 return (bpt->type == bp_breakpoint 01593 || bpt->type == bp_hardware_breakpoint 01594 || bpt->type == bp_dprintf); 01595 } 01596 01597 /* Return true if BPT is of any hardware watchpoint kind. */ 01598 01599 static int 01600 is_hardware_watchpoint (const struct breakpoint *bpt) 01601 { 01602 return (bpt->type == bp_hardware_watchpoint 01603 || bpt->type == bp_read_watchpoint 01604 || bpt->type == bp_access_watchpoint); 01605 } 01606 01607 /* Return true if BPT is of any watchpoint kind, hardware or 01608 software. */ 01609 01610 int 01611 is_watchpoint (const struct breakpoint *bpt) 01612 { 01613 return (is_hardware_watchpoint (bpt) 01614 || bpt->type == bp_watchpoint); 01615 } 01616 01617 /* Returns true if the current thread and its running state are safe 01618 to evaluate or update watchpoint B. Watchpoints on local 01619 expressions need to be evaluated in the context of the thread that 01620 was current when the watchpoint was created, and, that thread needs 01621 to be stopped to be able to select the correct frame context. 01622 Watchpoints on global expressions can be evaluated on any thread, 01623 and in any state. It is presently left to the target allowing 01624 memory accesses when threads are running. */ 01625 01626 static int 01627 watchpoint_in_thread_scope (struct watchpoint *b) 01628 { 01629 return (b->base.pspace == current_program_space 01630 && (ptid_equal (b->watchpoint_thread, null_ptid) 01631 || (ptid_equal (inferior_ptid, b->watchpoint_thread) 01632 && !is_executing (inferior_ptid)))); 01633 } 01634 01635 /* Set watchpoint B to disp_del_at_next_stop, even including its possible 01636 associated bp_watchpoint_scope breakpoint. */ 01637 01638 static void 01639 watchpoint_del_at_next_stop (struct watchpoint *w) 01640 { 01641 struct breakpoint *b = &w->base; 01642 01643 if (b->related_breakpoint != b) 01644 { 01645 gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); 01646 gdb_assert (b->related_breakpoint->related_breakpoint == b); 01647 b->related_breakpoint->disposition = disp_del_at_next_stop; 01648 b->related_breakpoint->related_breakpoint = b->related_breakpoint; 01649 b->related_breakpoint = b; 01650 } 01651 b->disposition = disp_del_at_next_stop; 01652 } 01653 01654 /* Assuming that B is a watchpoint: 01655 - Reparse watchpoint expression, if REPARSE is non-zero 01656 - Evaluate expression and store the result in B->val 01657 - Evaluate the condition if there is one, and store the result 01658 in b->loc->cond. 01659 - Update the list of values that must be watched in B->loc. 01660 01661 If the watchpoint disposition is disp_del_at_next_stop, then do 01662 nothing. If this is local watchpoint that is out of scope, delete 01663 it. 01664 01665 Even with `set breakpoint always-inserted on' the watchpoints are 01666 removed + inserted on each stop here. Normal breakpoints must 01667 never be removed because they might be missed by a running thread 01668 when debugging in non-stop mode. On the other hand, hardware 01669 watchpoints (is_hardware_watchpoint; processed here) are specific 01670 to each LWP since they are stored in each LWP's hardware debug 01671 registers. Therefore, such LWP must be stopped first in order to 01672 be able to modify its hardware watchpoints. 01673 01674 Hardware watchpoints must be reset exactly once after being 01675 presented to the user. It cannot be done sooner, because it would 01676 reset the data used to present the watchpoint hit to the user. And 01677 it must not be done later because it could display the same single 01678 watchpoint hit during multiple GDB stops. Note that the latter is 01679 relevant only to the hardware watchpoint types bp_read_watchpoint 01680 and bp_access_watchpoint. False hit by bp_hardware_watchpoint is 01681 not user-visible - its hit is suppressed if the memory content has 01682 not changed. 01683 01684 The following constraints influence the location where we can reset 01685 hardware watchpoints: 01686 01687 * target_stopped_by_watchpoint and target_stopped_data_address are 01688 called several times when GDB stops. 01689 01690 [linux] 01691 * Multiple hardware watchpoints can be hit at the same time, 01692 causing GDB to stop. GDB only presents one hardware watchpoint 01693 hit at a time as the reason for stopping, and all the other hits 01694 are presented later, one after the other, each time the user 01695 requests the execution to be resumed. Execution is not resumed 01696 for the threads still having pending hit event stored in 01697 LWP_INFO->STATUS. While the watchpoint is already removed from 01698 the inferior on the first stop the thread hit event is kept being 01699 reported from its cached value by linux_nat_stopped_data_address 01700 until the real thread resume happens after the watchpoint gets 01701 presented and thus its LWP_INFO->STATUS gets reset. 01702 01703 Therefore the hardware watchpoint hit can get safely reset on the 01704 watchpoint removal from inferior. */ 01705 01706 static void 01707 update_watchpoint (struct watchpoint *b, int reparse) 01708 { 01709 int within_current_scope; 01710 struct frame_id saved_frame_id; 01711 int frame_saved; 01712 01713 /* If this is a local watchpoint, we only want to check if the 01714 watchpoint frame is in scope if the current thread is the thread 01715 that was used to create the watchpoint. */ 01716 if (!watchpoint_in_thread_scope (b)) 01717 return; 01718 01719 if (b->base.disposition == disp_del_at_next_stop) 01720 return; 01721 01722 frame_saved = 0; 01723 01724 /* Determine if the watchpoint is within scope. */ 01725 if (b->exp_valid_block == NULL) 01726 within_current_scope = 1; 01727 else 01728 { 01729 struct frame_info *fi = get_current_frame (); 01730 struct gdbarch *frame_arch = get_frame_arch (fi); 01731 CORE_ADDR frame_pc = get_frame_pc (fi); 01732 01733 /* If we're in a function epilogue, unwinding may not work 01734 properly, so do not attempt to recreate locations at this 01735 point. See similar comments in watchpoint_check. */ 01736 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) 01737 return; 01738 01739 /* Save the current frame's ID so we can restore it after 01740 evaluating the watchpoint expression on its own frame. */ 01741 /* FIXME drow/2003-09-09: It would be nice if evaluate_expression 01742 took a frame parameter, so that we didn't have to change the 01743 selected frame. */ 01744 frame_saved = 1; 01745 saved_frame_id = get_frame_id (get_selected_frame (NULL)); 01746 01747 fi = frame_find_by_id (b->watchpoint_frame); 01748 within_current_scope = (fi != NULL); 01749 if (within_current_scope) 01750 select_frame (fi); 01751 } 01752 01753 /* We don't free locations. They are stored in the bp_location array 01754 and update_global_location_list will eventually delete them and 01755 remove breakpoints if needed. */ 01756 b->base.loc = NULL; 01757 01758 if (within_current_scope && reparse) 01759 { 01760 const char *s; 01761 01762 if (b->exp) 01763 { 01764 xfree (b->exp); 01765 b->exp = NULL; 01766 } 01767 s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; 01768 b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); 01769 /* If the meaning of expression itself changed, the old value is 01770 no longer relevant. We don't want to report a watchpoint hit 01771 to the user when the old value and the new value may actually 01772 be completely different objects. */ 01773 value_free (b->val); 01774 b->val = NULL; 01775 b->val_valid = 0; 01776 01777 /* Note that unlike with breakpoints, the watchpoint's condition 01778 expression is stored in the breakpoint object, not in the 01779 locations (re)created below. */ 01780 if (b->base.cond_string != NULL) 01781 { 01782 if (b->cond_exp != NULL) 01783 { 01784 xfree (b->cond_exp); 01785 b->cond_exp = NULL; 01786 } 01787 01788 s = b->base.cond_string; 01789 b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); 01790 } 01791 } 01792 01793 /* If we failed to parse the expression, for example because 01794 it refers to a global variable in a not-yet-loaded shared library, 01795 don't try to insert watchpoint. We don't automatically delete 01796 such watchpoint, though, since failure to parse expression 01797 is different from out-of-scope watchpoint. */ 01798 if ( !target_has_execution) 01799 { 01800 /* Without execution, memory can't change. No use to try and 01801 set watchpoint locations. The watchpoint will be reset when 01802 the target gains execution, through breakpoint_re_set. */ 01803 } 01804 else if (within_current_scope && b->exp) 01805 { 01806 int pc = 0; 01807 struct value *val_chain, *v, *result, *next; 01808 struct program_space *frame_pspace; 01809 01810 fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); 01811 01812 /* Avoid setting b->val if it's already set. The meaning of 01813 b->val is 'the last value' user saw, and we should update 01814 it only if we reported that last value to user. As it 01815 happens, the code that reports it updates b->val directly. 01816 We don't keep track of the memory value for masked 01817 watchpoints. */ 01818 if (!b->val_valid && !is_masked_watchpoint (&b->base)) 01819 { 01820 b->val = v; 01821 b->val_valid = 1; 01822 } 01823 01824 frame_pspace = get_frame_program_space (get_selected_frame (NULL)); 01825 01826 /* Look at each value on the value chain. */ 01827 for (v = val_chain; v; v = value_next (v)) 01828 { 01829 /* If it's a memory location, and GDB actually needed 01830 its contents to evaluate the expression, then we 01831 must watch it. If the first value returned is 01832 still lazy, that means an error occurred reading it; 01833 watch it anyway in case it becomes readable. */ 01834 if (VALUE_LVAL (v) == lval_memory 01835 && (v == val_chain || ! value_lazy (v))) 01836 { 01837 struct type *vtype = check_typedef (value_type (v)); 01838 01839 /* We only watch structs and arrays if user asked 01840 for it explicitly, never if they just happen to 01841 appear in the middle of some value chain. */ 01842 if (v == result 01843 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT 01844 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) 01845 { 01846 CORE_ADDR addr; 01847 int type; 01848 struct bp_location *loc, **tmp; 01849 01850 addr = value_address (v); 01851 type = hw_write; 01852 if (b->base.type == bp_read_watchpoint) 01853 type = hw_read; 01854 else if (b->base.type == bp_access_watchpoint) 01855 type = hw_access; 01856 01857 loc = allocate_bp_location (&b->base); 01858 for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) 01859 ; 01860 *tmp = loc; 01861 loc->gdbarch = get_type_arch (value_type (v)); 01862 01863 loc->pspace = frame_pspace; 01864 loc->address = addr; 01865 loc->length = TYPE_LENGTH (value_type (v)); 01866 loc->watchpoint_type = type; 01867 } 01868 } 01869 } 01870 01871 /* Change the type of breakpoint between hardware assisted or 01872 an ordinary watchpoint depending on the hardware support 01873 and free hardware slots. REPARSE is set when the inferior 01874 is started. */ 01875 if (reparse) 01876 { 01877 int reg_cnt; 01878 enum bp_loc_type loc_type; 01879 struct bp_location *bl; 01880 01881 reg_cnt = can_use_hardware_watchpoint (val_chain); 01882 01883 if (reg_cnt) 01884 { 01885 int i, target_resources_ok, other_type_used; 01886 enum bptype type; 01887 01888 /* Use an exact watchpoint when there's only one memory region to be 01889 watched, and only one debug register is needed to watch it. */ 01890 b->exact = target_exact_watchpoints && reg_cnt == 1; 01891 01892 /* We need to determine how many resources are already 01893 used for all other hardware watchpoints plus this one 01894 to see if we still have enough resources to also fit 01895 this watchpoint in as well. */ 01896 01897 /* If this is a software watchpoint, we try to turn it 01898 to a hardware one -- count resources as if B was of 01899 hardware watchpoint type. */ 01900 type = b->base.type; 01901 if (type == bp_watchpoint) 01902 type = bp_hardware_watchpoint; 01903 01904 /* This watchpoint may or may not have been placed on 01905 the list yet at this point (it won't be in the list 01906 if we're trying to create it for the first time, 01907 through watch_command), so always account for it 01908 manually. */ 01909 01910 /* Count resources used by all watchpoints except B. */ 01911 i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); 01912 01913 /* Add in the resources needed for B. */ 01914 i += hw_watchpoint_use_count (&b->base); 01915 01916 target_resources_ok 01917 = target_can_use_hardware_watchpoint (type, i, other_type_used); 01918 if (target_resources_ok <= 0) 01919 { 01920 int sw_mode = b->base.ops->works_in_software_mode (&b->base); 01921 01922 if (target_resources_ok == 0 && !sw_mode) 01923 error (_("Target does not support this type of " 01924 "hardware watchpoint.")); 01925 else if (target_resources_ok < 0 && !sw_mode) 01926 error (_("There are not enough available hardware " 01927 "resources for this watchpoint.")); 01928 01929 /* Downgrade to software watchpoint. */ 01930 b->base.type = bp_watchpoint; 01931 } 01932 else 01933 { 01934 /* If this was a software watchpoint, we've just 01935 found we have enough resources to turn it to a 01936 hardware watchpoint. Otherwise, this is a 01937 nop. */ 01938 b->base.type = type; 01939 } 01940 } 01941 else if (!b->base.ops->works_in_software_mode (&b->base)) 01942 error (_("Expression cannot be implemented with " 01943 "read/access watchpoint.")); 01944 else 01945 b->base.type = bp_watchpoint; 01946 01947 loc_type = (b->base.type == bp_watchpoint? bp_loc_other 01948 : bp_loc_hardware_watchpoint); 01949 for (bl = b->base.loc; bl; bl = bl->next) 01950 bl->loc_type = loc_type; 01951 } 01952 01953 for (v = val_chain; v; v = next) 01954 { 01955 next = value_next (v); 01956 if (v != b->val) 01957 value_free (v); 01958 } 01959 01960 /* If a software watchpoint is not watching any memory, then the 01961 above left it without any location set up. But, 01962 bpstat_stop_status requires a location to be able to report 01963 stops, so make sure there's at least a dummy one. */ 01964 if (b->base.type == bp_watchpoint && b->base.loc == NULL) 01965 { 01966 struct breakpoint *base = &b->base; 01967 base->loc = allocate_bp_location (base); 01968 base->loc->pspace = frame_pspace; 01969 base->loc->address = -1; 01970 base->loc->length = -1; 01971 base->loc->watchpoint_type = -1; 01972 } 01973 } 01974 else if (!within_current_scope) 01975 { 01976 printf_filtered (_("\ 01977 Watchpoint %d deleted because the program has left the block\n\ 01978 in which its expression is valid.\n"), 01979 b->base.number); 01980 watchpoint_del_at_next_stop (b); 01981 } 01982 01983 /* Restore the selected frame. */ 01984 if (frame_saved) 01985 select_frame (frame_find_by_id (saved_frame_id)); 01986 } 01987 01988 01989 /* Returns 1 iff breakpoint location should be 01990 inserted in the inferior. We don't differentiate the type of BL's owner 01991 (breakpoint vs. tracepoint), although insert_location in tracepoint's 01992 breakpoint_ops is not defined, because in insert_bp_location, 01993 tracepoint's insert_location will not be called. */ 01994 static int 01995 should_be_inserted (struct bp_location *bl) 01996 { 01997 if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) 01998 return 0; 01999 02000 if (bl->owner->disposition == disp_del_at_next_stop) 02001 return 0; 02002 02003 if (!bl->enabled || bl->shlib_disabled || bl->duplicate) 02004 return 0; 02005 02006 if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) 02007 return 0; 02008 02009 /* This is set for example, when we're attached to the parent of a 02010 vfork, and have detached from the child. The child is running 02011 free, and we expect it to do an exec or exit, at which point the 02012 OS makes the parent schedulable again (and the target reports 02013 that the vfork is done). Until the child is done with the shared 02014 memory region, do not insert breakpoints in the parent, otherwise 02015 the child could still trip on the parent's breakpoints. Since 02016 the parent is blocked anyway, it won't miss any breakpoint. */ 02017 if (bl->pspace->breakpoints_not_allowed) 02018 return 0; 02019 02020 return 1; 02021 } 02022 02023 /* Same as should_be_inserted but does the check assuming 02024 that the location is not duplicated. */ 02025 02026 static int 02027 unduplicated_should_be_inserted (struct bp_location *bl) 02028 { 02029 int result; 02030 const int save_duplicate = bl->duplicate; 02031 02032 bl->duplicate = 0; 02033 result = should_be_inserted (bl); 02034 bl->duplicate = save_duplicate; 02035 return result; 02036 } 02037 02038 /* Parses a conditional described by an expression COND into an 02039 agent expression bytecode suitable for evaluation 02040 by the bytecode interpreter. Return NULL if there was 02041 any error during parsing. */ 02042 02043 static struct agent_expr * 02044 parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) 02045 { 02046 struct agent_expr *aexpr = NULL; 02047 volatile struct gdb_exception ex; 02048 02049 if (!cond) 02050 return NULL; 02051 02052 /* We don't want to stop processing, so catch any errors 02053 that may show up. */ 02054 TRY_CATCH (ex, RETURN_MASK_ERROR) 02055 { 02056 aexpr = gen_eval_for_expr (scope, cond); 02057 } 02058 02059 if (ex.reason < 0) 02060 { 02061 /* If we got here, it means the condition could not be parsed to a valid 02062 bytecode expression and thus can't be evaluated on the target's side. 02063 It's no use iterating through the conditions. */ 02064 return NULL; 02065 } 02066 02067 /* We have a valid agent expression. */ 02068 return aexpr; 02069 } 02070 02071 /* Based on location BL, create a list of breakpoint conditions to be 02072 passed on to the target. If we have duplicated locations with different 02073 conditions, we will add such conditions to the list. The idea is that the 02074 target will evaluate the list of conditions and will only notify GDB when 02075 one of them is true. */ 02076 02077 static void 02078 build_target_condition_list (struct bp_location *bl) 02079 { 02080 struct bp_location **locp = NULL, **loc2p; 02081 int null_condition_or_parse_error = 0; 02082 int modified = bl->needs_update; 02083 struct bp_location *loc; 02084 02085 /* This is only meaningful if the target is 02086 evaluating conditions and if the user has 02087 opted for condition evaluation on the target's 02088 side. */ 02089 if (gdb_evaluates_breakpoint_condition_p () 02090 || !target_supports_evaluation_of_breakpoint_conditions ()) 02091 return; 02092 02093 /* Do a first pass to check for locations with no assigned 02094 conditions or conditions that fail to parse to a valid agent expression 02095 bytecode. If any of these happen, then it's no use to send conditions 02096 to the target since this location will always trigger and generate a 02097 response back to GDB. */ 02098 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) 02099 { 02100 loc = (*loc2p); 02101 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) 02102 { 02103 if (modified) 02104 { 02105 struct agent_expr *aexpr; 02106 02107 /* Re-parse the conditions since something changed. In that 02108 case we already freed the condition bytecodes (see 02109 force_breakpoint_reinsertion). We just 02110 need to parse the condition to bytecodes again. */ 02111 aexpr = parse_cond_to_aexpr (bl->address, loc->cond); 02112 loc->cond_bytecode = aexpr; 02113 02114 /* Check if we managed to parse the conditional expression 02115 correctly. If not, we will not send this condition 02116 to the target. */ 02117 if (aexpr) 02118 continue; 02119 } 02120 02121 /* If we have a NULL bytecode expression, it means something 02122 went wrong or we have a null condition expression. */ 02123 if (!loc->cond_bytecode) 02124 { 02125 null_condition_or_parse_error = 1; 02126 break; 02127 } 02128 } 02129 } 02130 02131 /* If any of these happened, it means we will have to evaluate the conditions 02132 for the location's address on gdb's side. It is no use keeping bytecodes 02133 for all the other duplicate locations, thus we free all of them here. 02134 02135 This is so we have a finer control over which locations' conditions are 02136 being evaluated by GDB or the remote stub. */ 02137 if (null_condition_or_parse_error) 02138 { 02139 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) 02140 { 02141 loc = (*loc2p); 02142 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) 02143 { 02144 /* Only go as far as the first NULL bytecode is 02145 located. */ 02146 if (!loc->cond_bytecode) 02147 return; 02148 02149 free_agent_expr (loc->cond_bytecode); 02150 loc->cond_bytecode = NULL; 02151 } 02152 } 02153 } 02154 02155 /* No NULL conditions or failed bytecode generation. Build a condition list 02156 for this location's address. */ 02157 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) 02158 { 02159 loc = (*loc2p); 02160 if (loc->cond 02161 && is_breakpoint (loc->owner) 02162 && loc->pspace->num == bl->pspace->num 02163 && loc->owner->enable_state == bp_enabled 02164 && loc->enabled) 02165 /* Add the condition to the vector. This will be used later to send the 02166 conditions to the target. */ 02167 VEC_safe_push (agent_expr_p, bl->target_info.conditions, 02168 loc->cond_bytecode); 02169 } 02170 02171 return; 02172 } 02173 02174 /* Parses a command described by string CMD into an agent expression 02175 bytecode suitable for evaluation by the bytecode interpreter. 02176 Return NULL if there was any error during parsing. */ 02177 02178 static struct agent_expr * 02179 parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) 02180 { 02181 struct cleanup *old_cleanups = 0; 02182 struct expression *expr, **argvec; 02183 struct agent_expr *aexpr = NULL; 02184 volatile struct gdb_exception ex; 02185 const char *cmdrest; 02186 const char *format_start, *format_end; 02187 struct format_piece *fpieces; 02188 int nargs; 02189 struct gdbarch *gdbarch = get_current_arch (); 02190 02191 if (!cmd) 02192 return NULL; 02193 02194 cmdrest = cmd; 02195 02196 if (*cmdrest == ',') 02197 ++cmdrest; 02198 cmdrest = skip_spaces_const (cmdrest); 02199 02200 if (*cmdrest++ != '"') 02201 error (_("No format string following the location")); 02202 02203 format_start = cmdrest; 02204 02205 fpieces = parse_format_string (&cmdrest); 02206 02207 old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); 02208 02209 format_end = cmdrest; 02210 02211 if (*cmdrest++ != '"') 02212 error (_("Bad format string, non-terminated '\"'.")); 02213 02214 cmdrest = skip_spaces_const (cmdrest); 02215 02216 if (!(*cmdrest == ',' || *cmdrest == '\0')) 02217 error (_("Invalid argument syntax")); 02218 02219 if (*cmdrest == ',') 02220 cmdrest++; 02221 cmdrest = skip_spaces_const (cmdrest); 02222 02223 /* For each argument, make an expression. */ 02224 02225 argvec = (struct expression **) alloca (strlen (cmd) 02226 * sizeof (struct expression *)); 02227 02228 nargs = 0; 02229 while (*cmdrest != '\0') 02230 { 02231 const char *cmd1; 02232 02233 cmd1 = cmdrest; 02234 expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); 02235 argvec[nargs++] = expr; 02236 cmdrest = cmd1; 02237 if (*cmdrest == ',') 02238 ++cmdrest; 02239 } 02240 02241 /* We don't want to stop processing, so catch any errors 02242 that may show up. */ 02243 TRY_CATCH (ex, RETURN_MASK_ERROR) 02244 { 02245 aexpr = gen_printf (scope, gdbarch, 0, 0, 02246 format_start, format_end - format_start, 02247 fpieces, nargs, argvec); 02248 } 02249 02250 do_cleanups (old_cleanups); 02251 02252 if (ex.reason < 0) 02253 { 02254 /* If we got here, it means the command could not be parsed to a valid 02255 bytecode expression and thus can't be evaluated on the target's side. 02256 It's no use iterating through the other commands. */ 02257 return NULL; 02258 } 02259 02260 /* We have a valid agent expression, return it. */ 02261 return aexpr; 02262 } 02263 02264 /* Based on location BL, create a list of breakpoint commands to be 02265 passed on to the target. If we have duplicated locations with 02266 different commands, we will add any such to the list. */ 02267 02268 static void 02269 build_target_command_list (struct bp_location *bl) 02270 { 02271 struct bp_location **locp = NULL, **loc2p; 02272 int null_command_or_parse_error = 0; 02273 int modified = bl->needs_update; 02274 struct bp_location *loc; 02275 02276 /* For now, limit to agent-style dprintf breakpoints. */ 02277 if (bl->owner->type != bp_dprintf 02278 || strcmp (dprintf_style, dprintf_style_agent) != 0) 02279 return; 02280 02281 if (!target_can_run_breakpoint_commands ()) 02282 return; 02283 02284 /* Do a first pass to check for locations with no assigned 02285 conditions or conditions that fail to parse to a valid agent expression 02286 bytecode. If any of these happen, then it's no use to send conditions 02287 to the target since this location will always trigger and generate a 02288 response back to GDB. */ 02289 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) 02290 { 02291 loc = (*loc2p); 02292 if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) 02293 { 02294 if (modified) 02295 { 02296 struct agent_expr *aexpr; 02297 02298 /* Re-parse the commands since something changed. In that 02299 case we already freed the command bytecodes (see 02300 force_breakpoint_reinsertion). We just 02301 need to parse the command to bytecodes again. */ 02302 aexpr = parse_cmd_to_aexpr (bl->address, 02303 loc->owner->extra_string); 02304 loc->cmd_bytecode = aexpr; 02305 02306 if (!aexpr) 02307 continue; 02308 } 02309 02310 /* If we have a NULL bytecode expression, it means something 02311 went wrong or we have a null command expression. */ 02312 if (!loc->cmd_bytecode) 02313 { 02314 null_command_or_parse_error = 1; 02315 break; 02316 } 02317 } 02318 } 02319 02320 /* If anything failed, then we're not doing target-side commands, 02321 and so clean up. */ 02322 if (null_command_or_parse_error) 02323 { 02324 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) 02325 { 02326 loc = (*loc2p); 02327 if (is_breakpoint (loc->owner) 02328 && loc->pspace->num == bl->pspace->num) 02329 { 02330 /* Only go as far as the first NULL bytecode is 02331 located. */ 02332 if (loc->cmd_bytecode == NULL) 02333 return; 02334 02335 free_agent_expr (loc->cmd_bytecode); 02336 loc->cmd_bytecode = NULL; 02337 } 02338 } 02339 } 02340 02341 /* No NULL commands or failed bytecode generation. Build a command list 02342 for this location's address. */ 02343 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) 02344 { 02345 loc = (*loc2p); 02346 if (loc->owner->extra_string 02347 && is_breakpoint (loc->owner) 02348 && loc->pspace->num == bl->pspace->num 02349 && loc->owner->enable_state == bp_enabled 02350 && loc->enabled) 02351 /* Add the command to the vector. This will be used later 02352 to send the commands to the target. */ 02353 VEC_safe_push (agent_expr_p, bl->target_info.tcommands, 02354 loc->cmd_bytecode); 02355 } 02356 02357 bl->target_info.persist = 0; 02358 /* Maybe flag this location as persistent. */ 02359 if (bl->owner->type == bp_dprintf && disconnected_dprintf) 02360 bl->target_info.persist = 1; 02361 } 02362 02363 /* Insert a low-level "breakpoint" of some type. BL is the breakpoint 02364 location. Any error messages are printed to TMP_ERROR_STREAM; and 02365 DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. 02366 Returns 0 for success, 1 if the bp_location type is not supported or 02367 -1 for failure. 02368 02369 NOTE drow/2003-09-09: This routine could be broken down to an 02370 object-style method for each breakpoint or catchpoint type. */ 02371 static int 02372 insert_bp_location (struct bp_location *bl, 02373 struct ui_file *tmp_error_stream, 02374 int *disabled_breaks, 02375 int *hw_breakpoint_error, 02376 int *hw_bp_error_explained_already) 02377 { 02378 int val = 0; 02379 char *hw_bp_err_string = NULL; 02380 struct gdb_exception e; 02381 02382 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) 02383 return 0; 02384 02385 /* Note we don't initialize bl->target_info, as that wipes out 02386 the breakpoint location's shadow_contents if the breakpoint 02387 is still inserted at that location. This in turn breaks 02388 target_read_memory which depends on these buffers when 02389 a memory read is requested at the breakpoint location: 02390 Once the target_info has been wiped, we fail to see that 02391 we have a breakpoint inserted at that address and thus 02392 read the breakpoint instead of returning the data saved in 02393 the breakpoint location's shadow contents. */ 02394 bl->target_info.placed_address = bl->address; 02395 bl->target_info.placed_address_space = bl->pspace->aspace; 02396 bl->target_info.length = bl->length; 02397 02398 /* When working with target-side conditions, we must pass all the conditions 02399 for the same breakpoint address down to the target since GDB will not 02400 insert those locations. With a list of breakpoint conditions, the target 02401 can decide when to stop and notify GDB. */ 02402 02403 if (is_breakpoint (bl->owner)) 02404 { 02405 build_target_condition_list (bl); 02406 build_target_command_list (bl); 02407 /* Reset the modification marker. */ 02408 bl->needs_update = 0; 02409 } 02410 02411 if (bl->loc_type == bp_loc_software_breakpoint 02412 || bl->loc_type == bp_loc_hardware_breakpoint) 02413 { 02414 if (bl->owner->type != bp_hardware_breakpoint) 02415 { 02416 /* If the explicitly specified breakpoint type 02417 is not hardware breakpoint, check the memory map to see 02418 if the breakpoint address is in read only memory or not. 02419 02420 Two important cases are: 02421 - location type is not hardware breakpoint, memory 02422 is readonly. We change the type of the location to 02423 hardware breakpoint. 02424 - location type is hardware breakpoint, memory is 02425 read-write. This means we've previously made the 02426 location hardware one, but then the memory map changed, 02427 so we undo. 02428 02429 When breakpoints are removed, remove_breakpoints will use 02430 location types we've just set here, the only possible 02431 problem is that memory map has changed during running 02432 program, but it's not going to work anyway with current 02433 gdb. */ 02434 struct mem_region *mr 02435 = lookup_mem_region (bl->target_info.placed_address); 02436 02437 if (mr) 02438 { 02439 if (automatic_hardware_breakpoints) 02440 { 02441 enum bp_loc_type new_type; 02442 02443 if (mr->attrib.mode != MEM_RW) 02444 new_type = bp_loc_hardware_breakpoint; 02445 else 02446 new_type = bp_loc_software_breakpoint; 02447 02448 if (new_type != bl->loc_type) 02449 { 02450 static int said = 0; 02451 02452 bl->loc_type = new_type; 02453 if (!said) 02454 { 02455 fprintf_filtered (gdb_stdout, 02456 _("Note: automatically using " 02457 "hardware breakpoints for " 02458 "read-only addresses.\n")); 02459 said = 1; 02460 } 02461 } 02462 } 02463 else if (bl->loc_type == bp_loc_software_breakpoint 02464 && mr->attrib.mode != MEM_RW) 02465 warning (_("cannot set software breakpoint " 02466 "at readonly address %s"), 02467 paddress (bl->gdbarch, bl->address)); 02468 } 02469 } 02470 02471 /* First check to see if we have to handle an overlay. */ 02472 if (overlay_debugging == ovly_off 02473 || bl->section == NULL 02474 || !(section_is_overlay (bl->section))) 02475 { 02476 /* No overlay handling: just set the breakpoint. */ 02477 TRY_CATCH (e, RETURN_MASK_ALL) 02478 { 02479 val = bl->owner->ops->insert_location (bl); 02480 } 02481 if (e.reason < 0) 02482 { 02483 val = 1; 02484 hw_bp_err_string = (char *) e.message; 02485 } 02486 } 02487 else 02488 { 02489 /* This breakpoint is in an overlay section. 02490 Shall we set a breakpoint at the LMA? */ 02491 if (!overlay_events_enabled) 02492 { 02493 /* Yes -- overlay event support is not active, 02494 so we must try to set a breakpoint at the LMA. 02495 This will not work for a hardware breakpoint. */ 02496 if (bl->loc_type == bp_loc_hardware_breakpoint) 02497 warning (_("hardware breakpoint %d not supported in overlay!"), 02498 bl->owner->number); 02499 else 02500 { 02501 CORE_ADDR addr = overlay_unmapped_address (bl->address, 02502 bl->section); 02503 /* Set a software (trap) breakpoint at the LMA. */ 02504 bl->overlay_target_info = bl->target_info; 02505 bl->overlay_target_info.placed_address = addr; 02506 val = target_insert_breakpoint (bl->gdbarch, 02507 &bl->overlay_target_info); 02508 if (val != 0) 02509 fprintf_unfiltered (tmp_error_stream, 02510 "Overlay breakpoint %d " 02511 "failed: in ROM?\n", 02512 bl->owner->number); 02513 } 02514 } 02515 /* Shall we set a breakpoint at the VMA? */ 02516 if (section_is_mapped (bl->section)) 02517 { 02518 /* Yes. This overlay section is mapped into memory. */ 02519 TRY_CATCH (e, RETURN_MASK_ALL) 02520 { 02521 val = bl->owner->ops->insert_location (bl); 02522 } 02523 if (e.reason < 0) 02524 { 02525 val = 1; 02526 hw_bp_err_string = (char *) e.message; 02527 } 02528 } 02529 else 02530 { 02531 /* No. This breakpoint will not be inserted. 02532 No error, but do not mark the bp as 'inserted'. */ 02533 return 0; 02534 } 02535 } 02536 02537 if (val) 02538 { 02539 /* Can't set the breakpoint. */ 02540 if (solib_name_from_address (bl->pspace, bl->address)) 02541 { 02542 /* See also: disable_breakpoints_in_shlibs. */ 02543 val = 0; 02544 bl->shlib_disabled = 1; 02545 observer_notify_breakpoint_modified (bl->owner); 02546 if (!*disabled_breaks) 02547 { 02548 fprintf_unfiltered (tmp_error_stream, 02549 "Cannot insert breakpoint %d.\n", 02550 bl->owner->number); 02551 fprintf_unfiltered (tmp_error_stream, 02552 "Temporarily disabling shared " 02553 "library breakpoints:\n"); 02554 } 02555 *disabled_breaks = 1; 02556 fprintf_unfiltered (tmp_error_stream, 02557 "breakpoint #%d\n", bl->owner->number); 02558 } 02559 else 02560 { 02561 if (bl->loc_type == bp_loc_hardware_breakpoint) 02562 { 02563 *hw_breakpoint_error = 1; 02564 *hw_bp_error_explained_already = hw_bp_err_string != NULL; 02565 fprintf_unfiltered (tmp_error_stream, 02566 "Cannot insert hardware breakpoint %d%s", 02567 bl->owner->number, hw_bp_err_string ? ":" : ".\n"); 02568 if (hw_bp_err_string) 02569 fprintf_unfiltered (tmp_error_stream, "%s.\n", hw_bp_err_string); 02570 } 02571 else 02572 { 02573 char *message = memory_error_message (TARGET_XFER_E_IO, 02574 bl->gdbarch, bl->address); 02575 struct cleanup *old_chain = make_cleanup (xfree, message); 02576 02577 fprintf_unfiltered (tmp_error_stream, 02578 "Cannot insert breakpoint %d.\n" 02579 "%s\n", 02580 bl->owner->number, message); 02581 02582 do_cleanups (old_chain); 02583 } 02584 02585 } 02586 } 02587 else 02588 bl->inserted = 1; 02589 02590 return val; 02591 } 02592 02593 else if (bl->loc_type == bp_loc_hardware_watchpoint 02594 /* NOTE drow/2003-09-08: This state only exists for removing 02595 watchpoints. It's not clear that it's necessary... */ 02596 && bl->owner->disposition != disp_del_at_next_stop) 02597 { 02598 gdb_assert (bl->owner->ops != NULL 02599 && bl->owner->ops->insert_location != NULL); 02600 02601 val = bl->owner->ops->insert_location (bl); 02602 02603 /* If trying to set a read-watchpoint, and it turns out it's not 02604 supported, try emulating one with an access watchpoint. */ 02605 if (val == 1 && bl->watchpoint_type == hw_read) 02606 { 02607 struct bp_location *loc, **loc_temp; 02608 02609 /* But don't try to insert it, if there's already another 02610 hw_access location that would be considered a duplicate 02611 of this one. */ 02612 ALL_BP_LOCATIONS (loc, loc_temp) 02613 if (loc != bl 02614 && loc->watchpoint_type == hw_access 02615 && watchpoint_locations_match (bl, loc)) 02616 { 02617 bl->duplicate = 1; 02618 bl->inserted = 1; 02619 bl->target_info = loc->target_info; 02620 bl->watchpoint_type = hw_access; 02621 val = 0; 02622 break; 02623 } 02624 02625 if (val == 1) 02626 { 02627 bl->watchpoint_type = hw_access; 02628 val = bl->owner->ops->insert_location (bl); 02629 02630 if (val) 02631 /* Back to the original value. */ 02632 bl->watchpoint_type = hw_read; 02633 } 02634 } 02635 02636 bl->inserted = (val == 0); 02637 } 02638 02639 else if (bl->owner->type == bp_catchpoint) 02640 { 02641 gdb_assert (bl->owner->ops != NULL 02642 && bl->owner->ops->insert_location != NULL); 02643 02644 val = bl->owner->ops->insert_location (bl); 02645 if (val) 02646 { 02647 bl->owner->enable_state = bp_disabled; 02648 02649 if (val == 1) 02650 warning (_("\ 02651 Error inserting catchpoint %d: Your system does not support this type\n\ 02652 of catchpoint."), bl->owner->number); 02653 else 02654 warning (_("Error inserting catchpoint %d."), bl->owner->number); 02655 } 02656 02657 bl->inserted = (val == 0); 02658 02659 /* We've already printed an error message if there was a problem 02660 inserting this catchpoint, and we've disabled the catchpoint, 02661 so just return success. */ 02662 return 0; 02663 } 02664 02665 return 0; 02666 } 02667 02668 /* This function is called when program space PSPACE is about to be 02669 deleted. It takes care of updating breakpoints to not reference 02670 PSPACE anymore. */ 02671 02672 void 02673 breakpoint_program_space_exit (struct program_space *pspace) 02674 { 02675 struct breakpoint *b, *b_temp; 02676 struct bp_location *loc, **loc_temp; 02677 02678 /* Remove any breakpoint that was set through this program space. */ 02679 ALL_BREAKPOINTS_SAFE (b, b_temp) 02680 { 02681 if (b->pspace == pspace) 02682 delete_breakpoint (b); 02683 } 02684 02685 /* Breakpoints set through other program spaces could have locations 02686 bound to PSPACE as well. Remove those. */ 02687 ALL_BP_LOCATIONS (loc, loc_temp) 02688 { 02689 struct bp_location *tmp; 02690 02691 if (loc->pspace == pspace) 02692 { 02693 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ 02694 if (loc->owner->loc == loc) 02695 loc->owner->loc = loc->next; 02696 else 02697 for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) 02698 if (tmp->next == loc) 02699 { 02700 tmp->next = loc->next; 02701 break; 02702 } 02703 } 02704 } 02705 02706 /* Now update the global location list to permanently delete the 02707 removed locations above. */ 02708 update_global_location_list (0); 02709 } 02710 02711 /* Make sure all breakpoints are inserted in inferior. 02712 Throws exception on any error. 02713 A breakpoint that is already inserted won't be inserted 02714 again, so calling this function twice is safe. */ 02715 void 02716 insert_breakpoints (void) 02717 { 02718 struct breakpoint *bpt; 02719 02720 ALL_BREAKPOINTS (bpt) 02721 if (is_hardware_watchpoint (bpt)) 02722 { 02723 struct watchpoint *w = (struct watchpoint *) bpt; 02724 02725 update_watchpoint (w, 0 /* don't reparse. */); 02726 } 02727 02728 update_global_location_list (1); 02729 02730 /* update_global_location_list does not insert breakpoints when 02731 always_inserted_mode is not enabled. Explicitly insert them 02732 now. */ 02733 if (!breakpoints_always_inserted_mode ()) 02734 insert_breakpoint_locations (); 02735 } 02736 02737 /* Invoke CALLBACK for each of bp_location. */ 02738 02739 void 02740 iterate_over_bp_locations (walk_bp_location_callback callback) 02741 { 02742 struct bp_location *loc, **loc_tmp; 02743 02744 ALL_BP_LOCATIONS (loc, loc_tmp) 02745 { 02746 callback (loc, NULL); 02747 } 02748 } 02749 02750 /* This is used when we need to synch breakpoint conditions between GDB and the 02751 target. It is the case with deleting and disabling of breakpoints when using 02752 always-inserted mode. */ 02753 02754 static void 02755 update_inserted_breakpoint_locations (void) 02756 { 02757 struct bp_location *bl, **blp_tmp; 02758 int error_flag = 0; 02759 int val = 0; 02760 int disabled_breaks = 0; 02761 int hw_breakpoint_error = 0; 02762 int hw_bp_details_reported = 0; 02763 02764 struct ui_file *tmp_error_stream = mem_fileopen (); 02765 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); 02766 02767 /* Explicitly mark the warning -- this will only be printed if 02768 there was an error. */ 02769 fprintf_unfiltered (tmp_error_stream, "Warning:\n"); 02770 02771 save_current_space_and_thread (); 02772 02773 ALL_BP_LOCATIONS (bl, blp_tmp) 02774 { 02775 /* We only want to update software breakpoints and hardware 02776 breakpoints. */ 02777 if (!is_breakpoint (bl->owner)) 02778 continue; 02779 02780 /* We only want to update locations that are already inserted 02781 and need updating. This is to avoid unwanted insertion during 02782 deletion of breakpoints. */ 02783 if (!bl->inserted || (bl->inserted && !bl->needs_update)) 02784 continue; 02785 02786 switch_to_program_space_and_thread (bl->pspace); 02787 02788 /* For targets that support global breakpoints, there's no need 02789 to select an inferior to insert breakpoint to. In fact, even 02790 if we aren't attached to any process yet, we should still 02791 insert breakpoints. */ 02792 if (!gdbarch_has_global_breakpoints (target_gdbarch ()) 02793 && ptid_equal (inferior_ptid, null_ptid)) 02794 continue; 02795 02796 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, 02797 &hw_breakpoint_error, &hw_bp_details_reported); 02798 if (val) 02799 error_flag = val; 02800 } 02801 02802 if (error_flag) 02803 { 02804 target_terminal_ours_for_output (); 02805 error_stream (tmp_error_stream); 02806 } 02807 02808 do_cleanups (cleanups); 02809 } 02810 02811 /* Used when starting or continuing the program. */ 02812 02813 static void 02814 insert_breakpoint_locations (void) 02815 { 02816 struct breakpoint *bpt; 02817 struct bp_location *bl, **blp_tmp; 02818 int error_flag = 0; 02819 int val = 0; 02820 int disabled_breaks = 0; 02821 int hw_breakpoint_error = 0; 02822 int hw_bp_error_explained_already = 0; 02823 02824 struct ui_file *tmp_error_stream = mem_fileopen (); 02825 struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); 02826 02827 /* Explicitly mark the warning -- this will only be printed if 02828 there was an error. */ 02829 fprintf_unfiltered (tmp_error_stream, "Warning:\n"); 02830 02831 save_current_space_and_thread (); 02832 02833 ALL_BP_LOCATIONS (bl, blp_tmp) 02834 { 02835 if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) 02836 continue; 02837 02838 /* There is no point inserting thread-specific breakpoints if 02839 the thread no longer exists. ALL_BP_LOCATIONS bp_location 02840 has BL->OWNER always non-NULL. */ 02841 if (bl->owner->thread != -1 02842 && !valid_thread_id (bl->owner->thread)) 02843 continue; 02844 02845 switch_to_program_space_and_thread (bl->pspace); 02846 02847 /* For targets that support global breakpoints, there's no need 02848 to select an inferior to insert breakpoint to. In fact, even 02849 if we aren't attached to any process yet, we should still 02850 insert breakpoints. */ 02851 if (!gdbarch_has_global_breakpoints (target_gdbarch ()) 02852 && ptid_equal (inferior_ptid, null_ptid)) 02853 continue; 02854 02855 val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, 02856 &hw_breakpoint_error, &hw_bp_error_explained_already); 02857 if (val) 02858 error_flag = val; 02859 } 02860 02861 /* If we failed to insert all locations of a watchpoint, remove 02862 them, as half-inserted watchpoint is of limited use. */ 02863 ALL_BREAKPOINTS (bpt) 02864 { 02865 int some_failed = 0; 02866 struct bp_location *loc; 02867 02868 if (!is_hardware_watchpoint (bpt)) 02869 continue; 02870 02871 if (!breakpoint_enabled (bpt)) 02872 continue; 02873 02874 if (bpt->disposition == disp_del_at_next_stop) 02875 continue; 02876 02877 for (loc = bpt->loc; loc; loc = loc->next) 02878 if (!loc->inserted && should_be_inserted (loc)) 02879 { 02880 some_failed = 1; 02881 break; 02882 } 02883 if (some_failed) 02884 { 02885 for (loc = bpt->loc; loc; loc = loc->next) 02886 if (loc->inserted) 02887 remove_breakpoint (loc, mark_uninserted); 02888 02889 hw_breakpoint_error = 1; 02890 fprintf_unfiltered (tmp_error_stream, 02891 "Could not insert hardware watchpoint %d.\n", 02892 bpt->number); 02893 error_flag = -1; 02894 } 02895 } 02896 02897 if (error_flag) 02898 { 02899 /* If a hardware breakpoint or watchpoint was inserted, add a 02900 message about possibly exhausted resources. */ 02901 if (hw_breakpoint_error && !hw_bp_error_explained_already) 02902 { 02903 fprintf_unfiltered (tmp_error_stream, 02904 "Could not insert hardware breakpoints:\n\ 02905 You may have requested too many hardware breakpoints/watchpoints.\n"); 02906 } 02907 target_terminal_ours_for_output (); 02908 error_stream (tmp_error_stream); 02909 } 02910 02911 do_cleanups (cleanups); 02912 } 02913 02914 /* Used when the program stops. 02915 Returns zero if successful, or non-zero if there was a problem 02916 removing a breakpoint location. */ 02917 02918 int 02919 remove_breakpoints (void) 02920 { 02921 struct bp_location *bl, **blp_tmp; 02922 int val = 0; 02923 02924 ALL_BP_LOCATIONS (bl, blp_tmp) 02925 { 02926 if (bl->inserted && !is_tracepoint (bl->owner)) 02927 val |= remove_breakpoint (bl, mark_uninserted); 02928 } 02929 return val; 02930 } 02931 02932 /* When a thread exits, remove breakpoints that are related to 02933 that thread. */ 02934 02935 static void 02936 remove_threaded_breakpoints (struct thread_info *tp, int silent) 02937 { 02938 struct breakpoint *b, *b_tmp; 02939 02940 ALL_BREAKPOINTS_SAFE (b, b_tmp) 02941 { 02942 if (b->thread == tp->num && user_breakpoint_p (b)) 02943 { 02944 b->disposition = disp_del_at_next_stop; 02945 02946 printf_filtered (_("\ 02947 Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), 02948 b->number, tp->num); 02949 02950 /* Hide it from the user. */ 02951 b->number = 0; 02952 } 02953 } 02954 } 02955 02956 /* Remove breakpoints of process PID. */ 02957 02958 int 02959 remove_breakpoints_pid (int pid) 02960 { 02961 struct bp_location *bl, **blp_tmp; 02962 int val; 02963 struct inferior *inf = find_inferior_pid (pid); 02964 02965 ALL_BP_LOCATIONS (bl, blp_tmp) 02966 { 02967 if (bl->pspace != inf->pspace) 02968 continue; 02969 02970 if (bl->owner->type == bp_dprintf) 02971 continue; 02972 02973 if (bl->inserted) 02974 { 02975 val = remove_breakpoint (bl, mark_uninserted); 02976 if (val != 0) 02977 return val; 02978 } 02979 } 02980 return 0; 02981 } 02982 02983 int 02984 reattach_breakpoints (int pid) 02985 { 02986 struct cleanup *old_chain; 02987 struct bp_location *bl, **blp_tmp; 02988 int val; 02989 struct ui_file *tmp_error_stream; 02990 int dummy1 = 0, dummy2 = 0, dummy3 = 0; 02991 struct inferior *inf; 02992 struct thread_info *tp; 02993 02994 tp = any_live_thread_of_process (pid); 02995 if (tp == NULL) 02996 return 1; 02997 02998 inf = find_inferior_pid (pid); 02999 old_chain = save_inferior_ptid (); 03000 03001 inferior_ptid = tp->ptid; 03002 03003 tmp_error_stream = mem_fileopen (); 03004 make_cleanup_ui_file_delete (tmp_error_stream); 03005 03006 ALL_BP_LOCATIONS (bl, blp_tmp) 03007 { 03008 if (bl->pspace != inf->pspace) 03009 continue; 03010 03011 if (bl->inserted) 03012 { 03013 bl->inserted = 0; 03014 val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); 03015 if (val != 0) 03016 { 03017 do_cleanups (old_chain); 03018 return val; 03019 } 03020 } 03021 } 03022 do_cleanups (old_chain); 03023 return 0; 03024 } 03025 03026 static int internal_breakpoint_number = -1; 03027 03028 /* Set the breakpoint number of B, depending on the value of INTERNAL. 03029 If INTERNAL is non-zero, the breakpoint number will be populated 03030 from internal_breakpoint_number and that variable decremented. 03031 Otherwise the breakpoint number will be populated from 03032 breakpoint_count and that value incremented. Internal breakpoints 03033 do not set the internal var bpnum. */ 03034 static void 03035 set_breakpoint_number (int internal, struct breakpoint *b) 03036 { 03037 if (internal) 03038 b->number = internal_breakpoint_number--; 03039 else 03040 { 03041 set_breakpoint_count (breakpoint_count + 1); 03042 b->number = breakpoint_count; 03043 } 03044 } 03045 03046 static struct breakpoint * 03047 create_internal_breakpoint (struct gdbarch *gdbarch, 03048 CORE_ADDR address, enum bptype type, 03049 const struct breakpoint_ops *ops) 03050 { 03051 struct symtab_and_line sal; 03052 struct breakpoint *b; 03053 03054 init_sal (&sal); /* Initialize to zeroes. */ 03055 03056 sal.pc = address; 03057 sal.section = find_pc_overlay (sal.pc); 03058 sal.pspace = current_program_space; 03059 03060 b = set_raw_breakpoint (gdbarch, sal, type, ops); 03061 b->number = internal_breakpoint_number--; 03062 b->disposition = disp_donttouch; 03063 03064 return b; 03065 } 03066 03067 static const char *const longjmp_names[] = 03068 { 03069 "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" 03070 }; 03071 #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) 03072 03073 /* Per-objfile data private to breakpoint.c. */ 03074 struct breakpoint_objfile_data 03075 { 03076 /* Minimal symbol for "_ovly_debug_event" (if any). */ 03077 struct minimal_symbol *overlay_msym; 03078 03079 /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ 03080 struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; 03081 03082 /* True if we have looked for longjmp probes. */ 03083 int longjmp_searched; 03084 03085 /* SystemTap probe points for longjmp (if any). */ 03086 VEC (probe_p) *longjmp_probes; 03087 03088 /* Minimal symbol for "std::terminate()" (if any). */ 03089 struct minimal_symbol *terminate_msym; 03090 03091 /* Minimal symbol for "_Unwind_DebugHook" (if any). */ 03092 struct minimal_symbol *exception_msym; 03093 03094 /* True if we have looked for exception probes. */ 03095 int exception_searched; 03096 03097 /* SystemTap probe points for unwinding (if any). */ 03098 VEC (probe_p) *exception_probes; 03099 }; 03100 03101 static const struct objfile_data *breakpoint_objfile_key; 03102 03103 /* Minimal symbol not found sentinel. */ 03104 static struct minimal_symbol msym_not_found; 03105 03106 /* Returns TRUE if MSYM point to the "not found" sentinel. */ 03107 03108 static int 03109 msym_not_found_p (const struct minimal_symbol *msym) 03110 { 03111 return msym == &msym_not_found; 03112 } 03113 03114 /* Return per-objfile data needed by breakpoint.c. 03115 Allocate the data if necessary. */ 03116 03117 static struct breakpoint_objfile_data * 03118 get_breakpoint_objfile_data (struct objfile *objfile) 03119 { 03120 struct breakpoint_objfile_data *bp_objfile_data; 03121 03122 bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); 03123 if (bp_objfile_data == NULL) 03124 { 03125 bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, 03126 sizeof (*bp_objfile_data)); 03127 03128 memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); 03129 set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); 03130 } 03131 return bp_objfile_data; 03132 } 03133 03134 static void 03135 free_breakpoint_probes (struct objfile *obj, void *data) 03136 { 03137 struct breakpoint_objfile_data *bp_objfile_data = data; 03138 03139 VEC_free (probe_p, bp_objfile_data->longjmp_probes); 03140 VEC_free (probe_p, bp_objfile_data->exception_probes); 03141 } 03142 03143 static void 03144 create_overlay_event_breakpoint (void) 03145 { 03146 struct objfile *objfile; 03147 const char *const func_name = "_ovly_debug_event"; 03148 03149 ALL_OBJFILES (objfile) 03150 { 03151 struct breakpoint *b; 03152 struct breakpoint_objfile_data *bp_objfile_data; 03153 CORE_ADDR addr; 03154 03155 bp_objfile_data = get_breakpoint_objfile_data (objfile); 03156 03157 if (msym_not_found_p (bp_objfile_data->overlay_msym)) 03158 continue; 03159 03160 if (bp_objfile_data->overlay_msym == NULL) 03161 { 03162 struct minimal_symbol *m; 03163 03164 m = lookup_minimal_symbol_text (func_name, objfile); 03165 if (m == NULL) 03166 { 03167 /* Avoid future lookups in this objfile. */ 03168 bp_objfile_data->overlay_msym = &msym_not_found; 03169 continue; 03170 } 03171 bp_objfile_data->overlay_msym = m; 03172 } 03173 03174 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); 03175 b = create_internal_breakpoint (get_objfile_arch (objfile), addr, 03176 bp_overlay_event, 03177 &internal_breakpoint_ops); 03178 b->addr_string = xstrdup (func_name); 03179 03180 if (overlay_debugging == ovly_auto) 03181 { 03182 b->enable_state = bp_enabled; 03183 overlay_events_enabled = 1; 03184 } 03185 else 03186 { 03187 b->enable_state = bp_disabled; 03188 overlay_events_enabled = 0; 03189 } 03190 } 03191 update_global_location_list (1); 03192 } 03193 03194 static void 03195 create_longjmp_master_breakpoint (void) 03196 { 03197 struct program_space *pspace; 03198 struct cleanup *old_chain; 03199 03200 old_chain = save_current_program_space (); 03201 03202 ALL_PSPACES (pspace) 03203 { 03204 struct objfile *objfile; 03205 03206 set_current_program_space (pspace); 03207 03208 ALL_OBJFILES (objfile) 03209 { 03210 int i; 03211 struct gdbarch *gdbarch; 03212 struct breakpoint_objfile_data *bp_objfile_data; 03213 03214 gdbarch = get_objfile_arch (objfile); 03215 if (!gdbarch_get_longjmp_target_p (gdbarch)) 03216 continue; 03217 03218 bp_objfile_data = get_breakpoint_objfile_data (objfile); 03219 03220 if (!bp_objfile_data->longjmp_searched) 03221 { 03222 VEC (probe_p) *ret; 03223 03224 ret = find_probes_in_objfile (objfile, "libc", "longjmp"); 03225 if (ret != NULL) 03226 { 03227 /* We are only interested in checking one element. */ 03228 struct probe *p = VEC_index (probe_p, ret, 0); 03229 03230 if (!can_evaluate_probe_arguments (p)) 03231 { 03232 /* We cannot use the probe interface here, because it does 03233 not know how to evaluate arguments. */ 03234 VEC_free (probe_p, ret); 03235 ret = NULL; 03236 } 03237 } 03238 bp_objfile_data->longjmp_probes = ret; 03239 bp_objfile_data->longjmp_searched = 1; 03240 } 03241 03242 if (bp_objfile_data->longjmp_probes != NULL) 03243 { 03244 int i; 03245 struct probe *probe; 03246 struct gdbarch *gdbarch = get_objfile_arch (objfile); 03247 03248 for (i = 0; 03249 VEC_iterate (probe_p, 03250 bp_objfile_data->longjmp_probes, 03251 i, probe); 03252 ++i) 03253 { 03254 struct breakpoint *b; 03255 03256 b = create_internal_breakpoint (gdbarch, probe->address, 03257 bp_longjmp_master, 03258 &internal_breakpoint_ops); 03259 b->addr_string = xstrdup ("-probe-stap libc:longjmp"); 03260 b->enable_state = bp_disabled; 03261 } 03262 03263 continue; 03264 } 03265 03266 for (i = 0; i < NUM_LONGJMP_NAMES; i++) 03267 { 03268 struct breakpoint *b; 03269 const char *func_name; 03270 CORE_ADDR addr; 03271 03272 if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) 03273 continue; 03274 03275 func_name = longjmp_names[i]; 03276 if (bp_objfile_data->longjmp_msym[i] == NULL) 03277 { 03278 struct minimal_symbol *m; 03279 03280 m = lookup_minimal_symbol_text (func_name, objfile); 03281 if (m == NULL) 03282 { 03283 /* Prevent future lookups in this objfile. */ 03284 bp_objfile_data->longjmp_msym[i] = &msym_not_found; 03285 continue; 03286 } 03287 bp_objfile_data->longjmp_msym[i] = m; 03288 } 03289 03290 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); 03291 b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, 03292 &internal_breakpoint_ops); 03293 b->addr_string = xstrdup (func_name); 03294 b->enable_state = bp_disabled; 03295 } 03296 } 03297 } 03298 update_global_location_list (1); 03299 03300 do_cleanups (old_chain); 03301 } 03302 03303 /* Create a master std::terminate breakpoint. */ 03304 static void 03305 create_std_terminate_master_breakpoint (void) 03306 { 03307 struct program_space *pspace; 03308 struct cleanup *old_chain; 03309 const char *const func_name = "std::terminate()"; 03310 03311 old_chain = save_current_program_space (); 03312 03313 ALL_PSPACES (pspace) 03314 { 03315 struct objfile *objfile; 03316 CORE_ADDR addr; 03317 03318 set_current_program_space (pspace); 03319 03320 ALL_OBJFILES (objfile) 03321 { 03322 struct breakpoint *b; 03323 struct breakpoint_objfile_data *bp_objfile_data; 03324 03325 bp_objfile_data = get_breakpoint_objfile_data (objfile); 03326 03327 if (msym_not_found_p (bp_objfile_data->terminate_msym)) 03328 continue; 03329 03330 if (bp_objfile_data->terminate_msym == NULL) 03331 { 03332 struct minimal_symbol *m; 03333 03334 m = lookup_minimal_symbol (func_name, NULL, objfile); 03335 if (m == NULL || (MSYMBOL_TYPE (m) != mst_text 03336 && MSYMBOL_TYPE (m) != mst_file_text)) 03337 { 03338 /* Prevent future lookups in this objfile. */ 03339 bp_objfile_data->terminate_msym = &msym_not_found; 03340 continue; 03341 } 03342 bp_objfile_data->terminate_msym = m; 03343 } 03344 03345 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); 03346 b = create_internal_breakpoint (get_objfile_arch (objfile), addr, 03347 bp_std_terminate_master, 03348 &internal_breakpoint_ops); 03349 b->addr_string = xstrdup (func_name); 03350 b->enable_state = bp_disabled; 03351 } 03352 } 03353 03354 update_global_location_list (1); 03355 03356 do_cleanups (old_chain); 03357 } 03358 03359 /* Install a master breakpoint on the unwinder's debug hook. */ 03360 03361 static void 03362 create_exception_master_breakpoint (void) 03363 { 03364 struct objfile *objfile; 03365 const char *const func_name = "_Unwind_DebugHook"; 03366 03367 ALL_OBJFILES (objfile) 03368 { 03369 struct breakpoint *b; 03370 struct gdbarch *gdbarch; 03371 struct breakpoint_objfile_data *bp_objfile_data; 03372 CORE_ADDR addr; 03373 03374 bp_objfile_data = get_breakpoint_objfile_data (objfile); 03375 03376 /* We prefer the SystemTap probe point if it exists. */ 03377 if (!bp_objfile_data->exception_searched) 03378 { 03379 VEC (probe_p) *ret; 03380 03381 ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); 03382 03383 if (ret != NULL) 03384 { 03385 /* We are only interested in checking one element. */ 03386 struct probe *p = VEC_index (probe_p, ret, 0); 03387 03388 if (!can_evaluate_probe_arguments (p)) 03389 { 03390 /* We cannot use the probe interface here, because it does 03391 not know how to evaluate arguments. */ 03392 VEC_free (probe_p, ret); 03393 ret = NULL; 03394 } 03395 } 03396 bp_objfile_data->exception_probes = ret; 03397 bp_objfile_data->exception_searched = 1; 03398 } 03399 03400 if (bp_objfile_data->exception_probes != NULL) 03401 { 03402 struct gdbarch *gdbarch = get_objfile_arch (objfile); 03403 int i; 03404 struct probe *probe; 03405 03406 for (i = 0; 03407 VEC_iterate (probe_p, 03408 bp_objfile_data->exception_probes, 03409 i, probe); 03410 ++i) 03411 { 03412 struct breakpoint *b; 03413 03414 b = create_internal_breakpoint (gdbarch, probe->address, 03415 bp_exception_master, 03416 &internal_breakpoint_ops); 03417 b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); 03418 b->enable_state = bp_disabled; 03419 } 03420 03421 continue; 03422 } 03423 03424 /* Otherwise, try the hook function. */ 03425 03426 if (msym_not_found_p (bp_objfile_data->exception_msym)) 03427 continue; 03428 03429 gdbarch = get_objfile_arch (objfile); 03430 03431 if (bp_objfile_data->exception_msym == NULL) 03432 { 03433 struct minimal_symbol *debug_hook; 03434 03435 debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); 03436 if (debug_hook == NULL) 03437 { 03438 bp_objfile_data->exception_msym = &msym_not_found; 03439 continue; 03440 } 03441 03442 bp_objfile_data->exception_msym = debug_hook; 03443 } 03444 03445 addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); 03446 addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, 03447 ¤t_target); 03448 b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, 03449 &internal_breakpoint_ops); 03450 b->addr_string = xstrdup (func_name); 03451 b->enable_state = bp_disabled; 03452 } 03453 03454 update_global_location_list (1); 03455 } 03456 03457 void 03458 update_breakpoints_after_exec (void) 03459 { 03460 struct breakpoint *b, *b_tmp; 03461 struct bp_location *bploc, **bplocp_tmp; 03462 03463 /* We're about to delete breakpoints from GDB's lists. If the 03464 INSERTED flag is true, GDB will try to lift the breakpoints by 03465 writing the breakpoints' "shadow contents" back into memory. The 03466 "shadow contents" are NOT valid after an exec, so GDB should not 03467 do that. Instead, the target is responsible from marking 03468 breakpoints out as soon as it detects an exec. We don't do that 03469 here instead, because there may be other attempts to delete 03470 breakpoints after detecting an exec and before reaching here. */ 03471 ALL_BP_LOCATIONS (bploc, bplocp_tmp) 03472 if (bploc->pspace == current_program_space) 03473 gdb_assert (!bploc->inserted); 03474 03475 ALL_BREAKPOINTS_SAFE (b, b_tmp) 03476 { 03477 if (b->pspace != current_program_space) 03478 continue; 03479 03480 /* Solib breakpoints must be explicitly reset after an exec(). */ 03481 if (b->type == bp_shlib_event) 03482 { 03483 delete_breakpoint (b); 03484 continue; 03485 } 03486 03487 /* JIT breakpoints must be explicitly reset after an exec(). */ 03488 if (b->type == bp_jit_event) 03489 { 03490 delete_breakpoint (b); 03491 continue; 03492 } 03493 03494 /* Thread event breakpoints must be set anew after an exec(), 03495 as must overlay event and longjmp master breakpoints. */ 03496 if (b->type == bp_thread_event || b->type == bp_overlay_event 03497 || b->type == bp_longjmp_master || b->type == bp_std_terminate_master 03498 || b->type == bp_exception_master) 03499 { 03500 delete_breakpoint (b); 03501 continue; 03502 } 03503 03504 /* Step-resume breakpoints are meaningless after an exec(). */ 03505 if (b->type == bp_step_resume || b->type == bp_hp_step_resume) 03506 { 03507 delete_breakpoint (b); 03508 continue; 03509 } 03510 03511 /* Longjmp and longjmp-resume breakpoints are also meaningless 03512 after an exec. */ 03513 if (b->type == bp_longjmp || b->type == bp_longjmp_resume 03514 || b->type == bp_longjmp_call_dummy 03515 || b->type == bp_exception || b->type == bp_exception_resume) 03516 { 03517 delete_breakpoint (b); 03518 continue; 03519 } 03520 03521 if (b->type == bp_catchpoint) 03522 { 03523 /* For now, none of the bp_catchpoint breakpoints need to 03524 do anything at this point. In the future, if some of 03525 the catchpoints need to something, we will need to add 03526 a new method, and call this method from here. */ 03527 continue; 03528 } 03529 03530 /* bp_finish is a special case. The only way we ought to be able 03531 to see one of these when an exec() has happened, is if the user 03532 caught a vfork, and then said "finish". Ordinarily a finish just 03533 carries them to the call-site of the current callee, by setting 03534 a temporary bp there and resuming. But in this case, the finish 03535 will carry them entirely through the vfork & exec. 03536 03537 We don't want to allow a bp_finish to remain inserted now. But 03538 we can't safely delete it, 'cause finish_command has a handle to 03539 the bp on a bpstat, and will later want to delete it. There's a 03540 chance (and I've seen it happen) that if we delete the bp_finish 03541 here, that its storage will get reused by the time finish_command 03542 gets 'round to deleting the "use to be a bp_finish" breakpoint. 03543 We really must allow finish_command to delete a bp_finish. 03544 03545 In the absence of a general solution for the "how do we know 03546 it's safe to delete something others may have handles to?" 03547 problem, what we'll do here is just uninsert the bp_finish, and 03548 let finish_command delete it. 03549 03550 (We know the bp_finish is "doomed" in the sense that it's 03551 momentary, and will be deleted as soon as finish_command sees 03552 the inferior stopped. So it doesn't matter that the bp's 03553 address is probably bogus in the new a.out, unlike e.g., the 03554 solib breakpoints.) */ 03555 03556 if (b->type == bp_finish) 03557 { 03558 continue; 03559 } 03560 03561 /* Without a symbolic address, we have little hope of the 03562 pre-exec() address meaning the same thing in the post-exec() 03563 a.out. */ 03564 if (b->addr_string == NULL) 03565 { 03566 delete_breakpoint (b); 03567 continue; 03568 } 03569 } 03570 /* FIXME what about longjmp breakpoints? Re-create them here? */ 03571 create_overlay_event_breakpoint (); 03572 create_longjmp_master_breakpoint (); 03573 create_std_terminate_master_breakpoint (); 03574 create_exception_master_breakpoint (); 03575 } 03576 03577 int 03578 detach_breakpoints (ptid_t ptid) 03579 { 03580 struct bp_location *bl, **blp_tmp; 03581 int val = 0; 03582 struct cleanup *old_chain = save_inferior_ptid (); 03583 struct inferior *inf = current_inferior (); 03584 03585 if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) 03586 error (_("Cannot detach breakpoints of inferior_ptid")); 03587 03588 /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ 03589 inferior_ptid = ptid; 03590 ALL_BP_LOCATIONS (bl, blp_tmp) 03591 { 03592 if (bl->pspace != inf->pspace) 03593 continue; 03594 03595 /* This function must physically remove breakpoints locations 03596 from the specified ptid, without modifying the breakpoint 03597 package's state. Locations of type bp_loc_other are only 03598 maintained at GDB side. So, there is no need to remove 03599 these bp_loc_other locations. Moreover, removing these 03600 would modify the breakpoint package's state. */ 03601 if (bl->loc_type == bp_loc_other) 03602 continue; 03603 03604 if (bl->inserted) 03605 val |= remove_breakpoint_1 (bl, mark_inserted); 03606 } 03607 03608 /* Detach single-step breakpoints as well. */ 03609 detach_single_step_breakpoints (); 03610 03611 do_cleanups (old_chain); 03612 return val; 03613 } 03614 03615 /* Remove the breakpoint location BL from the current address space. 03616 Note that this is used to detach breakpoints from a child fork. 03617 When we get here, the child isn't in the inferior list, and neither 03618 do we have objects to represent its address space --- we should 03619 *not* look at bl->pspace->aspace here. */ 03620 03621 static int 03622 remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) 03623 { 03624 int val; 03625 03626 /* BL is never in moribund_locations by our callers. */ 03627 gdb_assert (bl->owner != NULL); 03628 03629 if (bl->owner->enable_state == bp_permanent) 03630 /* Permanent breakpoints cannot be inserted or removed. */ 03631 return 0; 03632 03633 /* The type of none suggests that owner is actually deleted. 03634 This should not ever happen. */ 03635 gdb_assert (bl->owner->type != bp_none); 03636 03637 if (bl->loc_type == bp_loc_software_breakpoint 03638 || bl->loc_type == bp_loc_hardware_breakpoint) 03639 { 03640 /* "Normal" instruction breakpoint: either the standard 03641 trap-instruction bp (bp_breakpoint), or a 03642 bp_hardware_breakpoint. */ 03643 03644 /* First check to see if we have to handle an overlay. */ 03645 if (overlay_debugging == ovly_off 03646 || bl->section == NULL 03647 || !(section_is_overlay (bl->section))) 03648 { 03649 /* No overlay handling: just remove the breakpoint. */ 03650 val = bl->owner->ops->remove_location (bl); 03651 } 03652 else 03653 { 03654 /* This breakpoint is in an overlay section. 03655 Did we set a breakpoint at the LMA? */ 03656 if (!overlay_events_enabled) 03657 { 03658 /* Yes -- overlay event support is not active, so we 03659 should have set a breakpoint at the LMA. Remove it. 03660 */ 03661 /* Ignore any failures: if the LMA is in ROM, we will 03662 have already warned when we failed to insert it. */ 03663 if (bl->loc_type == bp_loc_hardware_breakpoint) 03664 target_remove_hw_breakpoint (bl->gdbarch, 03665 &bl->overlay_target_info); 03666 else 03667 target_remove_breakpoint (bl->gdbarch, 03668 &bl->overlay_target_info); 03669 } 03670 /* Did we set a breakpoint at the VMA? 03671 If so, we will have marked the breakpoint 'inserted'. */ 03672 if (bl->inserted) 03673 { 03674 /* Yes -- remove it. Previously we did not bother to 03675 remove the breakpoint if the section had been 03676 unmapped, but let's not rely on that being safe. We 03677 don't know what the overlay manager might do. */ 03678 03679 /* However, we should remove *software* breakpoints only 03680 if the section is still mapped, or else we overwrite 03681 wrong code with the saved shadow contents. */ 03682 if (bl->loc_type == bp_loc_hardware_breakpoint 03683 || section_is_mapped (bl->section)) 03684 val = bl->owner->ops->remove_location (bl); 03685 else 03686 val = 0; 03687 } 03688 else 03689 { 03690 /* No -- not inserted, so no need to remove. No error. */ 03691 val = 0; 03692 } 03693 } 03694 03695 /* In some cases, we might not be able to remove a breakpoint 03696 in a shared library that has already been removed, but we 03697 have not yet processed the shlib unload event. */ 03698 if (val && solib_name_from_address (bl->pspace, bl->address)) 03699 val = 0; 03700 03701 if (val) 03702 return val; 03703 bl->inserted = (is == mark_inserted); 03704 } 03705 else if (bl->loc_type == bp_loc_hardware_watchpoint) 03706 { 03707 gdb_assert (bl->owner->ops != NULL 03708 && bl->owner->ops->remove_location != NULL); 03709 03710 bl->inserted = (is == mark_inserted); 03711 bl->owner->ops->remove_location (bl); 03712 03713 /* Failure to remove any of the hardware watchpoints comes here. */ 03714 if ((is == mark_uninserted) && (bl->inserted)) 03715 warning (_("Could not remove hardware watchpoint %d."), 03716 bl->owner->number); 03717 } 03718 else if (bl->owner->type == bp_catchpoint 03719 && breakpoint_enabled (bl->owner) 03720 && !bl->duplicate) 03721 { 03722 gdb_assert (bl->owner->ops != NULL 03723 && bl->owner->ops->remove_location != NULL); 03724 03725 val = bl->owner->ops->remove_location (bl); 03726 if (val) 03727 return val; 03728 03729 bl->inserted = (is == mark_inserted); 03730 } 03731 03732 return 0; 03733 } 03734 03735 static int 03736 remove_breakpoint (struct bp_location *bl, insertion_state_t is) 03737 { 03738 int ret; 03739 struct cleanup *old_chain; 03740 03741 /* BL is never in moribund_locations by our callers. */ 03742 gdb_assert (bl->owner != NULL); 03743 03744 if (bl->owner->enable_state == bp_permanent) 03745 /* Permanent breakpoints cannot be inserted or removed. */ 03746 return 0; 03747 03748 /* The type of none suggests that owner is actually deleted. 03749 This should not ever happen. */ 03750 gdb_assert (bl->owner->type != bp_none); 03751 03752 old_chain = save_current_space_and_thread (); 03753 03754 switch_to_program_space_and_thread (bl->pspace); 03755 03756 ret = remove_breakpoint_1 (bl, is); 03757 03758 do_cleanups (old_chain); 03759 return ret; 03760 } 03761 03762 /* Clear the "inserted" flag in all breakpoints. */ 03763 03764 void 03765 mark_breakpoints_out (void) 03766 { 03767 struct bp_location *bl, **blp_tmp; 03768 03769 ALL_BP_LOCATIONS (bl, blp_tmp) 03770 if (bl->pspace == current_program_space) 03771 bl->inserted = 0; 03772 } 03773 03774 /* Clear the "inserted" flag in all breakpoints and delete any 03775 breakpoints which should go away between runs of the program. 03776 03777 Plus other such housekeeping that has to be done for breakpoints 03778 between runs. 03779 03780 Note: this function gets called at the end of a run (by 03781 generic_mourn_inferior) and when a run begins (by 03782 init_wait_for_inferior). */ 03783 03784 03785 03786 void 03787 breakpoint_init_inferior (enum inf_context context) 03788 { 03789 struct breakpoint *b, *b_tmp; 03790 struct bp_location *bl, **blp_tmp; 03791 int ix; 03792 struct program_space *pspace = current_program_space; 03793 03794 /* If breakpoint locations are shared across processes, then there's 03795 nothing to do. */ 03796 if (gdbarch_has_global_breakpoints (target_gdbarch ())) 03797 return; 03798 03799 ALL_BP_LOCATIONS (bl, blp_tmp) 03800 { 03801 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ 03802 if (bl->pspace == pspace 03803 && bl->owner->enable_state != bp_permanent) 03804 bl->inserted = 0; 03805 } 03806 03807 ALL_BREAKPOINTS_SAFE (b, b_tmp) 03808 { 03809 if (b->loc && b->loc->pspace != pspace) 03810 continue; 03811 03812 switch (b->type) 03813 { 03814 case bp_call_dummy: 03815 case bp_longjmp_call_dummy: 03816 03817 /* If the call dummy breakpoint is at the entry point it will 03818 cause problems when the inferior is rerun, so we better get 03819 rid of it. */ 03820 03821 case bp_watchpoint_scope: 03822 03823 /* Also get rid of scope breakpoints. */ 03824 03825 case bp_shlib_event: 03826 03827 /* Also remove solib event breakpoints. Their addresses may 03828 have changed since the last time we ran the program. 03829 Actually we may now be debugging against different target; 03830 and so the solib backend that installed this breakpoint may 03831 not be used in by the target. E.g., 03832 03833 (gdb) file prog-linux 03834 (gdb) run # native linux target 03835 ... 03836 (gdb) kill 03837 (gdb) file prog-win.exe 03838 (gdb) tar rem :9999 # remote Windows gdbserver. 03839 */ 03840 03841 case bp_step_resume: 03842 03843 /* Also remove step-resume breakpoints. */ 03844 03845 delete_breakpoint (b); 03846 break; 03847 03848 case bp_watchpoint: 03849 case bp_hardware_watchpoint: 03850 case bp_read_watchpoint: 03851 case bp_access_watchpoint: 03852 { 03853 struct watchpoint *w = (struct watchpoint *) b; 03854 03855 /* Likewise for watchpoints on local expressions. */ 03856 if (w->exp_valid_block != NULL) 03857 delete_breakpoint (b); 03858 else if (context == inf_starting) 03859 { 03860 /* Reset val field to force reread of starting value in 03861 insert_breakpoints. */ 03862 if (w->val) 03863 value_free (w->val); 03864 w->val = NULL; 03865 w->val_valid = 0; 03866 } 03867 } 03868 break; 03869 default: 03870 break; 03871 } 03872 } 03873 03874 /* Get rid of the moribund locations. */ 03875 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) 03876 decref_bp_location (&bl); 03877 VEC_free (bp_location_p, moribund_locations); 03878 } 03879 03880 /* These functions concern about actual breakpoints inserted in the 03881 target --- to e.g. check if we need to do decr_pc adjustment or if 03882 we need to hop over the bkpt --- so we check for address space 03883 match, not program space. */ 03884 03885 /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint 03886 exists at PC. It returns ordinary_breakpoint_here if it's an 03887 ordinary breakpoint, or permanent_breakpoint_here if it's a 03888 permanent breakpoint. 03889 - When continuing from a location with an ordinary breakpoint, we 03890 actually single step once before calling insert_breakpoints. 03891 - When continuing from a location with a permanent breakpoint, we 03892 need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by 03893 the target, to advance the PC past the breakpoint. */ 03894 03895 enum breakpoint_here 03896 breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) 03897 { 03898 struct bp_location *bl, **blp_tmp; 03899 int any_breakpoint_here = 0; 03900 03901 ALL_BP_LOCATIONS (bl, blp_tmp) 03902 { 03903 if (bl->loc_type != bp_loc_software_breakpoint 03904 && bl->loc_type != bp_loc_hardware_breakpoint) 03905 continue; 03906 03907 /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ 03908 if ((breakpoint_enabled (bl->owner) 03909 || bl->owner->enable_state == bp_permanent) 03910 && breakpoint_location_address_match (bl, aspace, pc)) 03911 { 03912 if (overlay_debugging 03913 && section_is_overlay (bl->section) 03914 && !section_is_mapped (bl->section)) 03915 continue; /* unmapped overlay -- can't be a match */ 03916 else if (bl->owner->enable_state == bp_permanent) 03917 return permanent_breakpoint_here; 03918 else 03919 any_breakpoint_here = 1; 03920 } 03921 } 03922 03923 return any_breakpoint_here ? ordinary_breakpoint_here : 0; 03924 } 03925 03926 /* Return true if there's a moribund breakpoint at PC. */ 03927 03928 int 03929 moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) 03930 { 03931 struct bp_location *loc; 03932 int ix; 03933 03934 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) 03935 if (breakpoint_location_address_match (loc, aspace, pc)) 03936 return 1; 03937 03938 return 0; 03939 } 03940 03941 /* Returns non-zero if there's a breakpoint inserted at PC, which is 03942 inserted using regular breakpoint_chain / bp_location array 03943 mechanism. This does not check for single-step breakpoints, which 03944 are inserted and removed using direct target manipulation. */ 03945 03946 int 03947 regular_breakpoint_inserted_here_p (struct address_space *aspace, 03948 CORE_ADDR pc) 03949 { 03950 struct bp_location *bl, **blp_tmp; 03951 03952 ALL_BP_LOCATIONS (bl, blp_tmp) 03953 { 03954 if (bl->loc_type != bp_loc_software_breakpoint 03955 && bl->loc_type != bp_loc_hardware_breakpoint) 03956 continue; 03957 03958 if (bl->inserted 03959 && breakpoint_location_address_match (bl, aspace, pc)) 03960 { 03961 if (overlay_debugging 03962 && section_is_overlay (bl->section) 03963 && !section_is_mapped (bl->section)) 03964 continue; /* unmapped overlay -- can't be a match */ 03965 else 03966 return 1; 03967 } 03968 } 03969 return 0; 03970 } 03971 03972 /* Returns non-zero iff there's either regular breakpoint 03973 or a single step breakpoint inserted at PC. */ 03974 03975 int 03976 breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) 03977 { 03978 if (regular_breakpoint_inserted_here_p (aspace, pc)) 03979 return 1; 03980 03981 if (single_step_breakpoint_inserted_here_p (aspace, pc)) 03982 return 1; 03983 03984 return 0; 03985 } 03986 03987 /* This function returns non-zero iff there is a software breakpoint 03988 inserted at PC. */ 03989 03990 int 03991 software_breakpoint_inserted_here_p (struct address_space *aspace, 03992 CORE_ADDR pc) 03993 { 03994 struct bp_location *bl, **blp_tmp; 03995 03996 ALL_BP_LOCATIONS (bl, blp_tmp) 03997 { 03998 if (bl->loc_type != bp_loc_software_breakpoint) 03999 continue; 04000 04001 if (bl->inserted 04002 && breakpoint_address_match (bl->pspace->aspace, bl->address, 04003 aspace, pc)) 04004 { 04005 if (overlay_debugging 04006 && section_is_overlay (bl->section) 04007 && !section_is_mapped (bl->section)) 04008 continue; /* unmapped overlay -- can't be a match */ 04009 else 04010 return 1; 04011 } 04012 } 04013 04014 /* Also check for software single-step breakpoints. */ 04015 if (single_step_breakpoint_inserted_here_p (aspace, pc)) 04016 return 1; 04017 04018 return 0; 04019 } 04020 04021 int 04022 hardware_watchpoint_inserted_in_range (struct address_space *aspace, 04023 CORE_ADDR addr, ULONGEST len) 04024 { 04025 struct breakpoint *bpt; 04026 04027 ALL_BREAKPOINTS (bpt) 04028 { 04029 struct bp_location *loc; 04030 04031 if (bpt->type != bp_hardware_watchpoint 04032 && bpt->type != bp_access_watchpoint) 04033 continue; 04034 04035 if (!breakpoint_enabled (bpt)) 04036 continue; 04037 04038 for (loc = bpt->loc; loc; loc = loc->next) 04039 if (loc->pspace->aspace == aspace && loc->inserted) 04040 { 04041 CORE_ADDR l, h; 04042 04043 /* Check for intersection. */ 04044 l = max (loc->address, addr); 04045 h = min (loc->address + loc->length, addr + len); 04046 if (l < h) 04047 return 1; 04048 } 04049 } 04050 return 0; 04051 } 04052 04053 /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at 04054 PC is valid for process/thread PTID. */ 04055 04056 int 04057 breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, 04058 ptid_t ptid) 04059 { 04060 struct bp_location *bl, **blp_tmp; 04061 /* The thread and task IDs associated to PTID, computed lazily. */ 04062 int thread = -1; 04063 int task = 0; 04064 04065 ALL_BP_LOCATIONS (bl, blp_tmp) 04066 { 04067 if (bl->loc_type != bp_loc_software_breakpoint 04068 && bl->loc_type != bp_loc_hardware_breakpoint) 04069 continue; 04070 04071 /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ 04072 if (!breakpoint_enabled (bl->owner) 04073 && bl->owner->enable_state != bp_permanent) 04074 continue; 04075 04076 if (!breakpoint_location_address_match (bl, aspace, pc)) 04077 continue; 04078 04079 if (bl->owner->thread != -1) 04080 { 04081 /* This is a thread-specific breakpoint. Check that ptid 04082 matches that thread. If thread hasn't been computed yet, 04083 it is now time to do so. */ 04084 if (thread == -1) 04085 thread = pid_to_thread_id (ptid); 04086 if (bl->owner->thread != thread) 04087 continue; 04088 } 04089 04090 if (bl->owner->task != 0) 04091 { 04092 /* This is a task-specific breakpoint. Check that ptid 04093 matches that task. If task hasn't been computed yet, 04094 it is now time to do so. */ 04095 if (task == 0) 04096 task = ada_get_task_number (ptid); 04097 if (bl->owner->task != task) 04098 continue; 04099 } 04100 04101 if (overlay_debugging 04102 && section_is_overlay (bl->section) 04103 && !section_is_mapped (bl->section)) 04104 continue; /* unmapped overlay -- can't be a match */ 04105 04106 return 1; 04107 } 04108 04109 return 0; 04110 } 04111 04112 04113 /* bpstat stuff. External routines' interfaces are documented 04114 in breakpoint.h. */ 04115 04116 int 04117 is_catchpoint (struct breakpoint *ep) 04118 { 04119 return (ep->type == bp_catchpoint); 04120 } 04121 04122 /* Frees any storage that is part of a bpstat. Does not walk the 04123 'next' chain. */ 04124 04125 static void 04126 bpstat_free (bpstat bs) 04127 { 04128 if (bs->old_val != NULL) 04129 value_free (bs->old_val); 04130 decref_counted_command_line (&bs->commands); 04131 decref_bp_location (&bs->bp_location_at); 04132 xfree (bs); 04133 } 04134 04135 /* Clear a bpstat so that it says we are not at any breakpoint. 04136 Also free any storage that is part of a bpstat. */ 04137 04138 void 04139 bpstat_clear (bpstat *bsp) 04140 { 04141 bpstat p; 04142 bpstat q; 04143 04144 if (bsp == 0) 04145 return; 04146 p = *bsp; 04147 while (p != NULL) 04148 { 04149 q = p->next; 04150 bpstat_free (p); 04151 p = q; 04152 } 04153 *bsp = NULL; 04154 } 04155 04156 /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that 04157 is part of the bpstat is copied as well. */ 04158 04159 bpstat 04160 bpstat_copy (bpstat bs) 04161 { 04162 bpstat p = NULL; 04163 bpstat tmp; 04164 bpstat retval = NULL; 04165 04166 if (bs == NULL) 04167 return bs; 04168 04169 for (; bs != NULL; bs = bs->next) 04170 { 04171 tmp = (bpstat) xmalloc (sizeof (*tmp)); 04172 memcpy (tmp, bs, sizeof (*tmp)); 04173 incref_counted_command_line (tmp->commands); 04174 incref_bp_location (tmp->bp_location_at); 04175 if (bs->old_val != NULL) 04176 { 04177 tmp->old_val = value_copy (bs->old_val); 04178 release_value (tmp->old_val); 04179 } 04180 04181 if (p == NULL) 04182 /* This is the first thing in the chain. */ 04183 retval = tmp; 04184 else 04185 p->next = tmp; 04186 p = tmp; 04187 } 04188 p->next = NULL; 04189 return retval; 04190 } 04191 04192 /* Find the bpstat associated with this breakpoint. */ 04193 04194 bpstat 04195 bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) 04196 { 04197 if (bsp == NULL) 04198 return NULL; 04199 04200 for (; bsp != NULL; bsp = bsp->next) 04201 { 04202 if (bsp->breakpoint_at == breakpoint) 04203 return bsp; 04204 } 04205 return NULL; 04206 } 04207 04208 /* See breakpoint.h. */ 04209 04210 enum bpstat_signal_value 04211 bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) 04212 { 04213 enum bpstat_signal_value result = BPSTAT_SIGNAL_NO; 04214 04215 for (; bsp != NULL; bsp = bsp->next) 04216 { 04217 /* Ensure that, if we ever entered this loop, then we at least 04218 return BPSTAT_SIGNAL_HIDE. */ 04219 enum bpstat_signal_value newval; 04220 04221 if (bsp->breakpoint_at == NULL) 04222 { 04223 /* A moribund location can never explain a signal other than 04224 GDB_SIGNAL_TRAP. */ 04225 if (sig == GDB_SIGNAL_TRAP) 04226 newval = BPSTAT_SIGNAL_HIDE; 04227 else 04228 newval = BPSTAT_SIGNAL_NO; 04229 } 04230 else 04231 newval = bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, 04232 sig); 04233 04234 if (newval > result) 04235 result = newval; 04236 } 04237 04238 return result; 04239 } 04240 04241 /* Put in *NUM the breakpoint number of the first breakpoint we are 04242 stopped at. *BSP upon return is a bpstat which points to the 04243 remaining breakpoints stopped at (but which is not guaranteed to be 04244 good for anything but further calls to bpstat_num). 04245 04246 Return 0 if passed a bpstat which does not indicate any breakpoints. 04247 Return -1 if stopped at a breakpoint that has been deleted since 04248 we set it. 04249 Return 1 otherwise. */ 04250 04251 int 04252 bpstat_num (bpstat *bsp, int *num) 04253 { 04254 struct breakpoint *b; 04255 04256 if ((*bsp) == NULL) 04257 return 0; /* No more breakpoint values */ 04258 04259 /* We assume we'll never have several bpstats that correspond to a 04260 single breakpoint -- otherwise, this function might return the 04261 same number more than once and this will look ugly. */ 04262 b = (*bsp)->breakpoint_at; 04263 *bsp = (*bsp)->next; 04264 if (b == NULL) 04265 return -1; /* breakpoint that's been deleted since */ 04266 04267 *num = b->number; /* We have its number */ 04268 return 1; 04269 } 04270 04271 /* See breakpoint.h. */ 04272 04273 void 04274 bpstat_clear_actions (void) 04275 { 04276 struct thread_info *tp; 04277 bpstat bs; 04278 04279 if (ptid_equal (inferior_ptid, null_ptid)) 04280 return; 04281 04282 tp = find_thread_ptid (inferior_ptid); 04283 if (tp == NULL) 04284 return; 04285 04286 for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) 04287 { 04288 decref_counted_command_line (&bs->commands); 04289 04290 if (bs->old_val != NULL) 04291 { 04292 value_free (bs->old_val); 04293 bs->old_val = NULL; 04294 } 04295 } 04296 } 04297 04298 /* Called when a command is about to proceed the inferior. */ 04299 04300 static void 04301 breakpoint_about_to_proceed (void) 04302 { 04303 if (!ptid_equal (inferior_ptid, null_ptid)) 04304 { 04305 struct thread_info *tp = inferior_thread (); 04306 04307 /* Allow inferior function calls in breakpoint commands to not 04308 interrupt the command list. When the call finishes 04309 successfully, the inferior will be standing at the same 04310 breakpoint as if nothing happened. */ 04311 if (tp->control.in_infcall) 04312 return; 04313 } 04314 04315 breakpoint_proceeded = 1; 04316 } 04317 04318 /* Stub for cleaning up our state if we error-out of a breakpoint 04319 command. */ 04320 static void 04321 cleanup_executing_breakpoints (void *ignore) 04322 { 04323 executing_breakpoint_commands = 0; 04324 } 04325 04326 /* Return non-zero iff CMD as the first line of a command sequence is `silent' 04327 or its equivalent. */ 04328 04329 static int 04330 command_line_is_silent (struct command_line *cmd) 04331 { 04332 return cmd && (strcmp ("silent", cmd->line) == 0 04333 || (xdb_commands && strcmp ("Q", cmd->line) == 0)); 04334 } 04335 04336 /* Execute all the commands associated with all the breakpoints at 04337 this location. Any of these commands could cause the process to 04338 proceed beyond this point, etc. We look out for such changes by 04339 checking the global "breakpoint_proceeded" after each command. 04340 04341 Returns true if a breakpoint command resumed the inferior. In that 04342 case, it is the caller's responsibility to recall it again with the 04343 bpstat of the current thread. */ 04344 04345 static int 04346 bpstat_do_actions_1 (bpstat *bsp) 04347 { 04348 bpstat bs; 04349 struct cleanup *old_chain; 04350 int again = 0; 04351 04352 /* Avoid endless recursion if a `source' command is contained 04353 in bs->commands. */ 04354 if (executing_breakpoint_commands) 04355 return 0; 04356 04357 executing_breakpoint_commands = 1; 04358 old_chain = make_cleanup (cleanup_executing_breakpoints, 0); 04359 04360 prevent_dont_repeat (); 04361 04362 /* This pointer will iterate over the list of bpstat's. */ 04363 bs = *bsp; 04364 04365 breakpoint_proceeded = 0; 04366 for (; bs != NULL; bs = bs->next) 04367 { 04368 struct counted_command_line *ccmd; 04369 struct command_line *cmd; 04370 struct cleanup *this_cmd_tree_chain; 04371 04372 /* Take ownership of the BSP's command tree, if it has one. 04373 04374 The command tree could legitimately contain commands like 04375 'step' and 'next', which call clear_proceed_status, which 04376 frees stop_bpstat's command tree. To make sure this doesn't 04377 free the tree we're executing out from under us, we need to 04378 take ownership of the tree ourselves. Since a given bpstat's 04379 commands are only executed once, we don't need to copy it; we 04380 can clear the pointer in the bpstat, and make sure we free 04381 the tree when we're done. */ 04382 ccmd = bs->commands; 04383 bs->commands = NULL; 04384 this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); 04385 cmd = ccmd ? ccmd->commands : NULL; 04386 if (command_line_is_silent (cmd)) 04387 { 04388 /* The action has been already done by bpstat_stop_status. */ 04389 cmd = cmd->next; 04390 } 04391 04392 while (cmd != NULL) 04393 { 04394 execute_control_command (cmd); 04395 04396 if (breakpoint_proceeded) 04397 break; 04398 else 04399 cmd = cmd->next; 04400 } 04401 04402 /* We can free this command tree now. */ 04403 do_cleanups (this_cmd_tree_chain); 04404 04405 if (breakpoint_proceeded) 04406 { 04407 if (target_can_async_p ()) 04408 /* If we are in async mode, then the target might be still 04409 running, not stopped at any breakpoint, so nothing for 04410 us to do here -- just return to the event loop. */ 04411 ; 04412 else 04413 /* In sync mode, when execute_control_command returns 04414 we're already standing on the next breakpoint. 04415 Breakpoint commands for that stop were not run, since 04416 execute_command does not run breakpoint commands -- 04417 only command_line_handler does, but that one is not 04418 involved in execution of breakpoint commands. So, we 04419 can now execute breakpoint commands. It should be 04420 noted that making execute_command do bpstat actions is 04421 not an option -- in this case we'll have recursive 04422 invocation of bpstat for each breakpoint with a 04423 command, and can easily blow up GDB stack. Instead, we 04424 return true, which will trigger the caller to recall us 04425 with the new stop_bpstat. */ 04426 again = 1; 04427 break; 04428 } 04429 } 04430 do_cleanups (old_chain); 04431 return again; 04432 } 04433 04434 void 04435 bpstat_do_actions (void) 04436 { 04437 struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); 04438 04439 /* Do any commands attached to breakpoint we are stopped at. */ 04440 while (!ptid_equal (inferior_ptid, null_ptid) 04441 && target_has_execution 04442 && !is_exited (inferior_ptid) 04443 && !is_executing (inferior_ptid)) 04444 /* Since in sync mode, bpstat_do_actions may resume the inferior, 04445 and only return when it is stopped at the next breakpoint, we 04446 keep doing breakpoint actions until it returns false to 04447 indicate the inferior was not resumed. */ 04448 if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) 04449 break; 04450 04451 discard_cleanups (cleanup_if_error); 04452 } 04453 04454 /* Print out the (old or new) value associated with a watchpoint. */ 04455 04456 static void 04457 watchpoint_value_print (struct value *val, struct ui_file *stream) 04458 { 04459 if (val == NULL) 04460 fprintf_unfiltered (stream, _("<unreadable>")); 04461 else 04462 { 04463 struct value_print_options opts; 04464 get_user_print_options (&opts); 04465 value_print (val, stream, &opts); 04466 } 04467 } 04468 04469 /* Generic routine for printing messages indicating why we 04470 stopped. The behavior of this function depends on the value 04471 'print_it' in the bpstat structure. Under some circumstances we 04472 may decide not to print anything here and delegate the task to 04473 normal_stop(). */ 04474 04475 static enum print_stop_action 04476 print_bp_stop_message (bpstat bs) 04477 { 04478 switch (bs->print_it) 04479 { 04480 case print_it_noop: 04481 /* Nothing should be printed for this bpstat entry. */ 04482 return PRINT_UNKNOWN; 04483 break; 04484 04485 case print_it_done: 04486 /* We still want to print the frame, but we already printed the 04487 relevant messages. */ 04488 return PRINT_SRC_AND_LOC; 04489 break; 04490 04491 case print_it_normal: 04492 { 04493 struct breakpoint *b = bs->breakpoint_at; 04494 04495 /* bs->breakpoint_at can be NULL if it was a momentary breakpoint 04496 which has since been deleted. */ 04497 if (b == NULL) 04498 return PRINT_UNKNOWN; 04499 04500 /* Normal case. Call the breakpoint's print_it method. */ 04501 return b->ops->print_it (bs); 04502 } 04503 break; 04504 04505 default: 04506 internal_error (__FILE__, __LINE__, 04507 _("print_bp_stop_message: unrecognized enum value")); 04508 break; 04509 } 04510 } 04511 04512 /* A helper function that prints a shared library stopped event. */ 04513 04514 static void 04515 print_solib_event (int is_catchpoint) 04516 { 04517 int any_deleted 04518 = !VEC_empty (char_ptr, current_program_space->deleted_solibs); 04519 int any_added 04520 = !VEC_empty (so_list_ptr, current_program_space->added_solibs); 04521 04522 if (!is_catchpoint) 04523 { 04524 if (any_added || any_deleted) 04525 ui_out_text (current_uiout, 04526 _("Stopped due to shared library event:\n")); 04527 else 04528 ui_out_text (current_uiout, 04529 _("Stopped due to shared library event (no " 04530 "libraries added or removed)\n")); 04531 } 04532 04533 if (ui_out_is_mi_like_p (current_uiout)) 04534 ui_out_field_string (current_uiout, "reason", 04535 async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); 04536 04537 if (any_deleted) 04538 { 04539 struct cleanup *cleanup; 04540 char *name; 04541 int ix; 04542 04543 ui_out_text (current_uiout, _(" Inferior unloaded ")); 04544 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, 04545 "removed"); 04546 for (ix = 0; 04547 VEC_iterate (char_ptr, current_program_space->deleted_solibs, 04548 ix, name); 04549 ++ix) 04550 { 04551 if (ix > 0) 04552 ui_out_text (current_uiout, " "); 04553 ui_out_field_string (current_uiout, "library", name); 04554 ui_out_text (current_uiout, "\n"); 04555 } 04556 04557 do_cleanups (cleanup); 04558 } 04559 04560 if (any_added) 04561 { 04562 struct so_list *iter; 04563 int ix; 04564 struct cleanup *cleanup; 04565 04566 ui_out_text (current_uiout, _(" Inferior loaded ")); 04567 cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, 04568 "added"); 04569 for (ix = 0; 04570 VEC_iterate (so_list_ptr, current_program_space->added_solibs, 04571 ix, iter); 04572 ++ix) 04573 { 04574 if (ix > 0) 04575 ui_out_text (current_uiout, " "); 04576 ui_out_field_string (current_uiout, "library", iter->so_name); 04577 ui_out_text (current_uiout, "\n"); 04578 } 04579 04580 do_cleanups (cleanup); 04581 } 04582 } 04583 04584 /* Print a message indicating what happened. This is called from 04585 normal_stop(). The input to this routine is the head of the bpstat 04586 list - a list of the eventpoints that caused this stop. KIND is 04587 the target_waitkind for the stopping event. This 04588 routine calls the generic print routine for printing a message 04589 about reasons for stopping. This will print (for example) the 04590 "Breakpoint n," part of the output. The return value of this 04591 routine is one of: 04592 04593 PRINT_UNKNOWN: Means we printed nothing. 04594 PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent 04595 code to print the location. An example is 04596 "Breakpoint 1, " which should be followed by 04597 the location. 04598 PRINT_SRC_ONLY: Means we printed something, but there is no need 04599 to also print the location part of the message. 04600 An example is the catch/throw messages, which 04601 don't require a location appended to the end. 04602 PRINT_NOTHING: We have done some printing and we don't need any 04603 further info to be printed. */ 04604 04605 enum print_stop_action 04606 bpstat_print (bpstat bs, int kind) 04607 { 04608 int val; 04609 04610 /* Maybe another breakpoint in the chain caused us to stop. 04611 (Currently all watchpoints go on the bpstat whether hit or not. 04612 That probably could (should) be changed, provided care is taken 04613 with respect to bpstat_explains_signal). */ 04614 for (; bs; bs = bs->next) 04615 { 04616 val = print_bp_stop_message (bs); 04617 if (val == PRINT_SRC_ONLY 04618 || val == PRINT_SRC_AND_LOC 04619 || val == PRINT_NOTHING) 04620 return val; 04621 } 04622 04623 /* If we had hit a shared library event breakpoint, 04624 print_bp_stop_message would print out this message. If we hit an 04625 OS-level shared library event, do the same thing. */ 04626 if (kind == TARGET_WAITKIND_LOADED) 04627 { 04628 print_solib_event (0); 04629 return PRINT_NOTHING; 04630 } 04631 04632 /* We reached the end of the chain, or we got a null BS to start 04633 with and nothing was printed. */ 04634 return PRINT_UNKNOWN; 04635 } 04636 04637 /* Evaluate the expression EXP and return 1 if value is zero. This is 04638 used inside a catch_errors to evaluate the breakpoint condition. 04639 The argument is a "struct expression *" that has been cast to a 04640 "char *" to make it pass through catch_errors. */ 04641 04642 static int 04643 breakpoint_cond_eval (void *exp) 04644 { 04645 struct value *mark = value_mark (); 04646 int i = !value_true (evaluate_expression ((struct expression *) exp)); 04647 04648 value_free_to_mark (mark); 04649 return i; 04650 } 04651 04652 /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ 04653 04654 static bpstat 04655 bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) 04656 { 04657 bpstat bs; 04658 04659 bs = (bpstat) xmalloc (sizeof (*bs)); 04660 bs->next = NULL; 04661 **bs_link_pointer = bs; 04662 *bs_link_pointer = &bs->next; 04663 bs->breakpoint_at = bl->owner; 04664 bs->bp_location_at = bl; 04665 incref_bp_location (bl); 04666 /* If the condition is false, etc., don't do the commands. */ 04667 bs->commands = NULL; 04668 bs->old_val = NULL; 04669 bs->print_it = print_it_normal; 04670 return bs; 04671 } 04672 04673 /* The target has stopped with waitstatus WS. Check if any hardware 04674 watchpoints have triggered, according to the target. */ 04675 04676 int 04677 watchpoints_triggered (struct target_waitstatus *ws) 04678 { 04679 int stopped_by_watchpoint = target_stopped_by_watchpoint (); 04680 CORE_ADDR addr; 04681 struct breakpoint *b; 04682 04683 if (!stopped_by_watchpoint) 04684 { 04685 /* We were not stopped by a watchpoint. Mark all watchpoints 04686 as not triggered. */ 04687 ALL_BREAKPOINTS (b) 04688 if (is_hardware_watchpoint (b)) 04689 { 04690 struct watchpoint *w = (struct watchpoint *) b; 04691 04692 w->watchpoint_triggered = watch_triggered_no; 04693 } 04694 04695 return 0; 04696 } 04697 04698 if (!target_stopped_data_address (¤t_target, &addr)) 04699 { 04700 /* We were stopped by a watchpoint, but we don't know where. 04701 Mark all watchpoints as unknown. */ 04702 ALL_BREAKPOINTS (b) 04703 if (is_hardware_watchpoint (b)) 04704 { 04705 struct watchpoint *w = (struct watchpoint *) b; 04706 04707 w->watchpoint_triggered = watch_triggered_unknown; 04708 } 04709 04710 return stopped_by_watchpoint; 04711 } 04712 04713 /* The target could report the data address. Mark watchpoints 04714 affected by this data address as triggered, and all others as not 04715 triggered. */ 04716 04717 ALL_BREAKPOINTS (b) 04718 if (is_hardware_watchpoint (b)) 04719 { 04720 struct watchpoint *w = (struct watchpoint *) b; 04721 struct bp_location *loc; 04722 04723 w->watchpoint_triggered = watch_triggered_no; 04724 for (loc = b->loc; loc; loc = loc->next) 04725 { 04726 if (is_masked_watchpoint (b)) 04727 { 04728 CORE_ADDR newaddr = addr & w->hw_wp_mask; 04729 CORE_ADDR start = loc->address & w->hw_wp_mask; 04730 04731 if (newaddr == start) 04732 { 04733 w->watchpoint_triggered = watch_triggered_yes; 04734 break; 04735 } 04736 } 04737 /* Exact match not required. Within range is sufficient. */ 04738 else if (target_watchpoint_addr_within_range (¤t_target, 04739 addr, loc->address, 04740 loc->length)) 04741 { 04742 w->watchpoint_triggered = watch_triggered_yes; 04743 break; 04744 } 04745 } 04746 } 04747 04748 return 1; 04749 } 04750 04751 /* Possible return values for watchpoint_check (this can't be an enum 04752 because of check_errors). */ 04753 /* The watchpoint has been deleted. */ 04754 #define WP_DELETED 1 04755 /* The value has changed. */ 04756 #define WP_VALUE_CHANGED 2 04757 /* The value has not changed. */ 04758 #define WP_VALUE_NOT_CHANGED 3 04759 /* Ignore this watchpoint, no matter if the value changed or not. */ 04760 #define WP_IGNORE 4 04761 04762 #define BP_TEMPFLAG 1 04763 #define BP_HARDWAREFLAG 2 04764 04765 /* Evaluate watchpoint condition expression and check if its value 04766 changed. 04767 04768 P should be a pointer to struct bpstat, but is defined as a void * 04769 in order for this function to be usable with catch_errors. */ 04770 04771 static int 04772 watchpoint_check (void *p) 04773 { 04774 bpstat bs = (bpstat) p; 04775 struct watchpoint *b; 04776 struct frame_info *fr; 04777 int within_current_scope; 04778 04779 /* BS is built from an existing struct breakpoint. */ 04780 gdb_assert (bs->breakpoint_at != NULL); 04781 b = (struct watchpoint *) bs->breakpoint_at; 04782 04783 /* If this is a local watchpoint, we only want to check if the 04784 watchpoint frame is in scope if the current thread is the thread 04785 that was used to create the watchpoint. */ 04786 if (!watchpoint_in_thread_scope (b)) 04787 return WP_IGNORE; 04788 04789 if (b->exp_valid_block == NULL) 04790 within_current_scope = 1; 04791 else 04792 { 04793 struct frame_info *frame = get_current_frame (); 04794 struct gdbarch *frame_arch = get_frame_arch (frame); 04795 CORE_ADDR frame_pc = get_frame_pc (frame); 04796 04797 /* in_function_epilogue_p() returns a non-zero value if we're 04798 still in the function but the stack frame has already been 04799 invalidated. Since we can't rely on the values of local 04800 variables after the stack has been destroyed, we are treating 04801 the watchpoint in that state as `not changed' without further 04802 checking. Don't mark watchpoints as changed if the current 04803 frame is in an epilogue - even if they are in some other 04804 frame, our view of the stack is likely to be wrong and 04805 frame_find_by_id could error out. */ 04806 if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) 04807 return WP_IGNORE; 04808 04809 fr = frame_find_by_id (b->watchpoint_frame); 04810 within_current_scope = (fr != NULL); 04811 04812 /* If we've gotten confused in the unwinder, we might have 04813 returned a frame that can't describe this variable. */ 04814 if (within_current_scope) 04815 { 04816 struct symbol *function; 04817 04818 function = get_frame_function (fr); 04819 if (function == NULL 04820 || !contained_in (b->exp_valid_block, 04821 SYMBOL_BLOCK_VALUE (function))) 04822 within_current_scope = 0; 04823 } 04824 04825 if (within_current_scope) 04826 /* If we end up stopping, the current frame will get selected 04827 in normal_stop. So this call to select_frame won't affect 04828 the user. */ 04829 select_frame (fr); 04830 } 04831 04832 if (within_current_scope) 04833 { 04834 /* We use value_{,free_to_}mark because it could be a *long* 04835 time before we return to the command level and call 04836 free_all_values. We can't call free_all_values because we 04837 might be in the middle of evaluating a function call. */ 04838 04839 int pc = 0; 04840 struct value *mark; 04841 struct value *new_val; 04842 04843 if (is_masked_watchpoint (&b->base)) 04844 /* Since we don't know the exact trigger address (from 04845 stopped_data_address), just tell the user we've triggered 04846 a mask watchpoint. */ 04847 return WP_VALUE_CHANGED; 04848 04849 mark = value_mark (); 04850 fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); 04851 04852 /* We use value_equal_contents instead of value_equal because 04853 the latter coerces an array to a pointer, thus comparing just 04854 the address of the array instead of its contents. This is 04855 not what we want. */ 04856 if ((b->val != NULL) != (new_val != NULL) 04857 || (b->val != NULL && !value_equal_contents (b->val, new_val))) 04858 { 04859 if (new_val != NULL) 04860 { 04861 release_value (new_val); 04862 value_free_to_mark (mark); 04863 } 04864 bs->old_val = b->val; 04865 b->val = new_val; 04866 b->val_valid = 1; 04867 return WP_VALUE_CHANGED; 04868 } 04869 else 04870 { 04871 /* Nothing changed. */ 04872 value_free_to_mark (mark); 04873 return WP_VALUE_NOT_CHANGED; 04874 } 04875 } 04876 else 04877 { 04878 struct ui_out *uiout = current_uiout; 04879 04880 /* This seems like the only logical thing to do because 04881 if we temporarily ignored the watchpoint, then when 04882 we reenter the block in which it is valid it contains 04883 garbage (in the case of a function, it may have two 04884 garbage values, one before and one after the prologue). 04885 So we can't even detect the first assignment to it and 04886 watch after that (since the garbage may or may not equal 04887 the first value assigned). */ 04888 /* We print all the stop information in 04889 breakpoint_ops->print_it, but in this case, by the time we 04890 call breakpoint_ops->print_it this bp will be deleted 04891 already. So we have no choice but print the information 04892 here. */ 04893 if (ui_out_is_mi_like_p (uiout)) 04894 ui_out_field_string 04895 (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); 04896 ui_out_text (uiout, "\nWatchpoint "); 04897 ui_out_field_int (uiout, "wpnum", b->base.number); 04898 ui_out_text (uiout, 04899 " deleted because the program has left the block in\n\ 04900 which its expression is valid.\n"); 04901 04902 /* Make sure the watchpoint's commands aren't executed. */ 04903 decref_counted_command_line (&b->base.commands); 04904 watchpoint_del_at_next_stop (b); 04905 04906 return WP_DELETED; 04907 } 04908 } 04909 04910 /* Return true if it looks like target has stopped due to hitting 04911 breakpoint location BL. This function does not check if we should 04912 stop, only if BL explains the stop. */ 04913 04914 static int 04915 bpstat_check_location (const struct bp_location *bl, 04916 struct address_space *aspace, CORE_ADDR bp_addr, 04917 const struct target_waitstatus *ws) 04918 { 04919 struct breakpoint *b = bl->owner; 04920 04921 /* BL is from an existing breakpoint. */ 04922 gdb_assert (b != NULL); 04923 04924 return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); 04925 } 04926 04927 /* Determine if the watched values have actually changed, and we 04928 should stop. If not, set BS->stop to 0. */ 04929 04930 static void 04931 bpstat_check_watchpoint (bpstat bs) 04932 { 04933 const struct bp_location *bl; 04934 struct watchpoint *b; 04935 04936 /* BS is built for existing struct breakpoint. */ 04937 bl = bs->bp_location_at; 04938 gdb_assert (bl != NULL); 04939 b = (struct watchpoint *) bs->breakpoint_at; 04940 gdb_assert (b != NULL); 04941 04942 { 04943 int must_check_value = 0; 04944 04945 if (b->base.type == bp_watchpoint) 04946 /* For a software watchpoint, we must always check the 04947 watched value. */ 04948 must_check_value = 1; 04949 else if (b->watchpoint_triggered == watch_triggered_yes) 04950 /* We have a hardware watchpoint (read, write, or access) 04951 and the target earlier reported an address watched by 04952 this watchpoint. */ 04953 must_check_value = 1; 04954 else if (b->watchpoint_triggered == watch_triggered_unknown 04955 && b->base.type == bp_hardware_watchpoint) 04956 /* We were stopped by a hardware watchpoint, but the target could 04957 not report the data address. We must check the watchpoint's 04958 value. Access and read watchpoints are out of luck; without 04959 a data address, we can't figure it out. */ 04960 must_check_value = 1; 04961 04962 if (must_check_value) 04963 { 04964 char *message 04965 = xstrprintf ("Error evaluating expression for watchpoint %d\n", 04966 b->base.number); 04967 struct cleanup *cleanups = make_cleanup (xfree, message); 04968 int e = catch_errors (watchpoint_check, bs, message, 04969 RETURN_MASK_ALL); 04970 do_cleanups (cleanups); 04971 switch (e) 04972 { 04973 case WP_DELETED: 04974 /* We've already printed what needs to be printed. */ 04975 bs->print_it = print_it_done; 04976 /* Stop. */ 04977 break; 04978 case WP_IGNORE: 04979 bs->print_it = print_it_noop; 04980 bs->stop = 0; 04981 break; 04982 case WP_VALUE_CHANGED: 04983 if (b->base.type == bp_read_watchpoint) 04984 { 04985 /* There are two cases to consider here: 04986 04987 1. We're watching the triggered memory for reads. 04988 In that case, trust the target, and always report 04989 the watchpoint hit to the user. Even though 04990 reads don't cause value changes, the value may 04991 have changed since the last time it was read, and 04992 since we're not trapping writes, we will not see 04993 those, and as such we should ignore our notion of 04994 old value. 04995 04996 2. We're watching the triggered memory for both 04997 reads and writes. There are two ways this may 04998 happen: 04999 05000 2.1. This is a target that can't break on data 05001 reads only, but can break on accesses (reads or 05002 writes), such as e.g., x86. We detect this case 05003 at the time we try to insert read watchpoints. 05004 05005 2.2. Otherwise, the target supports read 05006 watchpoints, but, the user set an access or write 05007 watchpoint watching the same memory as this read 05008 watchpoint. 05009 05010 If we're watching memory writes as well as reads, 05011 ignore watchpoint hits when we find that the 05012 value hasn't changed, as reads don't cause 05013 changes. This still gives false positives when 05014 the program writes the same value to memory as 05015 what there was already in memory (we will confuse 05016 it for a read), but it's much better than 05017 nothing. */ 05018 05019 int other_write_watchpoint = 0; 05020 05021 if (bl->watchpoint_type == hw_read) 05022 { 05023 struct breakpoint *other_b; 05024 05025 ALL_BREAKPOINTS (other_b) 05026 if (other_b->type == bp_hardware_watchpoint 05027 || other_b->type == bp_access_watchpoint) 05028 { 05029 struct watchpoint *other_w = 05030 (struct watchpoint *) other_b; 05031 05032 if (other_w->watchpoint_triggered 05033 == watch_triggered_yes) 05034 { 05035 other_write_watchpoint = 1; 05036 break; 05037 } 05038 } 05039 } 05040 05041 if (other_write_watchpoint 05042 || bl->watchpoint_type == hw_access) 05043 { 05044 /* We're watching the same memory for writes, 05045 and the value changed since the last time we 05046 updated it, so this trap must be for a write. 05047 Ignore it. */ 05048 bs->print_it = print_it_noop; 05049 bs->stop = 0; 05050 } 05051 } 05052 break; 05053 case WP_VALUE_NOT_CHANGED: 05054 if (b->base.type == bp_hardware_watchpoint 05055 || b->base.type == bp_watchpoint) 05056 { 05057 /* Don't stop: write watchpoints shouldn't fire if 05058 the value hasn't changed. */ 05059 bs->print_it = print_it_noop; 05060 bs->stop = 0; 05061 } 05062 /* Stop. */ 05063 break; 05064 default: 05065 /* Can't happen. */ 05066 case 0: 05067 /* Error from catch_errors. */ 05068 printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); 05069 watchpoint_del_at_next_stop (b); 05070 /* We've already printed what needs to be printed. */ 05071 bs->print_it = print_it_done; 05072 break; 05073 } 05074 } 05075 else /* must_check_value == 0 */ 05076 { 05077 /* This is a case where some watchpoint(s) triggered, but 05078 not at the address of this watchpoint, or else no 05079 watchpoint triggered after all. So don't print 05080 anything for this watchpoint. */ 05081 bs->print_it = print_it_noop; 05082 bs->stop = 0; 05083 } 05084 } 05085 } 05086 05087 05088 /* Check conditions (condition proper, frame, thread and ignore count) 05089 of breakpoint referred to by BS. If we should not stop for this 05090 breakpoint, set BS->stop to 0. */ 05091 05092 static void 05093 bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) 05094 { 05095 int thread_id = pid_to_thread_id (ptid); 05096 const struct bp_location *bl; 05097 struct breakpoint *b; 05098 05099 /* BS is built for existing struct breakpoint. */ 05100 bl = bs->bp_location_at; 05101 gdb_assert (bl != NULL); 05102 b = bs->breakpoint_at; 05103 gdb_assert (b != NULL); 05104 05105 /* Even if the target evaluated the condition on its end and notified GDB, we 05106 need to do so again since GDB does not know if we stopped due to a 05107 breakpoint or a single step breakpoint. */ 05108 05109 if (frame_id_p (b->frame_id) 05110 && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) 05111 bs->stop = 0; 05112 else if (bs->stop) 05113 { 05114 int value_is_zero = 0; 05115 struct expression *cond; 05116 05117 /* Evaluate Python breakpoints that have a "stop" 05118 method implemented. */ 05119 if (b->py_bp_object) 05120 bs->stop = gdbpy_should_stop (b->py_bp_object); 05121 05122 if (is_watchpoint (b)) 05123 { 05124 struct watchpoint *w = (struct watchpoint *) b; 05125 05126 cond = w->cond_exp; 05127 } 05128 else 05129 cond = bl->cond; 05130 05131 if (cond && b->disposition != disp_del_at_next_stop) 05132 { 05133 int within_current_scope = 1; 05134 struct watchpoint * w; 05135 05136 /* We use value_mark and value_free_to_mark because it could 05137 be a long time before we return to the command level and 05138 call free_all_values. We can't call free_all_values 05139 because we might be in the middle of evaluating a 05140 function call. */ 05141 struct value *mark = value_mark (); 05142 05143 if (is_watchpoint (b)) 05144 w = (struct watchpoint *) b; 05145 else 05146 w = NULL; 05147 05148 /* Need to select the frame, with all that implies so that 05149 the conditions will have the right context. Because we 05150 use the frame, we will not see an inlined function's 05151 variables when we arrive at a breakpoint at the start 05152 of the inlined function; the current frame will be the 05153 call site. */ 05154 if (w == NULL || w->cond_exp_valid_block == NULL) 05155 select_frame (get_current_frame ()); 05156 else 05157 { 05158 struct frame_info *frame; 05159 05160 /* For local watchpoint expressions, which particular 05161 instance of a local is being watched matters, so we 05162 keep track of the frame to evaluate the expression 05163 in. To evaluate the condition however, it doesn't 05164 really matter which instantiation of the function 05165 where the condition makes sense triggers the 05166 watchpoint. This allows an expression like "watch 05167 global if q > 10" set in `func', catch writes to 05168 global on all threads that call `func', or catch 05169 writes on all recursive calls of `func' by a single 05170 thread. We simply always evaluate the condition in 05171 the innermost frame that's executing where it makes 05172 sense to evaluate the condition. It seems 05173 intuitive. */ 05174 frame = block_innermost_frame (w->cond_exp_valid_block); 05175 if (frame != NULL) 05176 select_frame (frame); 05177 else 05178 within_current_scope = 0; 05179 } 05180 if (within_current_scope) 05181 value_is_zero 05182 = catch_errors (breakpoint_cond_eval, cond, 05183 "Error in testing breakpoint condition:\n", 05184 RETURN_MASK_ALL); 05185 else 05186 { 05187 warning (_("Watchpoint condition cannot be tested " 05188 "in the current scope")); 05189 /* If we failed to set the right context for this 05190 watchpoint, unconditionally report it. */ 05191 value_is_zero = 0; 05192 } 05193 /* FIXME-someday, should give breakpoint #. */ 05194 value_free_to_mark (mark); 05195 } 05196 05197 if (cond && value_is_zero) 05198 { 05199 bs->stop = 0; 05200 } 05201 else if (b->thread != -1 && b->thread != thread_id) 05202 { 05203 bs->stop = 0; 05204 } 05205 else if (b->ignore_count > 0) 05206 { 05207 b->ignore_count--; 05208 bs->stop = 0; 05209 /* Increase the hit count even though we don't stop. */ 05210 ++(b->hit_count); 05211 observer_notify_breakpoint_modified (b); 05212 } 05213 } 05214 } 05215 05216 05217 /* Get a bpstat associated with having just stopped at address 05218 BP_ADDR in thread PTID. 05219 05220 Determine whether we stopped at a breakpoint, etc, or whether we 05221 don't understand this stop. Result is a chain of bpstat's such 05222 that: 05223 05224 if we don't understand the stop, the result is a null pointer. 05225 05226 if we understand why we stopped, the result is not null. 05227 05228 Each element of the chain refers to a particular breakpoint or 05229 watchpoint at which we have stopped. (We may have stopped for 05230 several reasons concurrently.) 05231 05232 Each element of the chain has valid next, breakpoint_at, 05233 commands, FIXME??? fields. */ 05234 05235 bpstat 05236 bpstat_stop_status (struct address_space *aspace, 05237 CORE_ADDR bp_addr, ptid_t ptid, 05238 const struct target_waitstatus *ws) 05239 { 05240 struct breakpoint *b = NULL; 05241 struct bp_location *bl; 05242 struct bp_location *loc; 05243 /* First item of allocated bpstat's. */ 05244 bpstat bs_head = NULL, *bs_link = &bs_head; 05245 /* Pointer to the last thing in the chain currently. */ 05246 bpstat bs; 05247 int ix; 05248 int need_remove_insert; 05249 int removed_any; 05250 05251 /* First, build the bpstat chain with locations that explain a 05252 target stop, while being careful to not set the target running, 05253 as that may invalidate locations (in particular watchpoint 05254 locations are recreated). Resuming will happen here with 05255 breakpoint conditions or watchpoint expressions that include 05256 inferior function calls. */ 05257 05258 ALL_BREAKPOINTS (b) 05259 { 05260 if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) 05261 continue; 05262 05263 for (bl = b->loc; bl != NULL; bl = bl->next) 05264 { 05265 /* For hardware watchpoints, we look only at the first 05266 location. The watchpoint_check function will work on the 05267 entire expression, not the individual locations. For 05268 read watchpoints, the watchpoints_triggered function has 05269 checked all locations already. */ 05270 if (b->type == bp_hardware_watchpoint && bl != b->loc) 05271 break; 05272 05273 if (!bl->enabled || bl->shlib_disabled) 05274 continue; 05275 05276 if (!bpstat_check_location (bl, aspace, bp_addr, ws)) 05277 continue; 05278 05279 /* Come here if it's a watchpoint, or if the break address 05280 matches. */ 05281 05282 bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to 05283 explain stop. */ 05284 05285 /* Assume we stop. Should we find a watchpoint that is not 05286 actually triggered, or if the condition of the breakpoint 05287 evaluates as false, we'll reset 'stop' to 0. */ 05288 bs->stop = 1; 05289 bs->print = 1; 05290 05291 /* If this is a scope breakpoint, mark the associated 05292 watchpoint as triggered so that we will handle the 05293 out-of-scope event. We'll get to the watchpoint next 05294 iteration. */ 05295 if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) 05296 { 05297 struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; 05298 05299 w->watchpoint_triggered = watch_triggered_yes; 05300 } 05301 } 05302 } 05303 05304 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) 05305 { 05306 if (breakpoint_location_address_match (loc, aspace, bp_addr)) 05307 { 05308 bs = bpstat_alloc (loc, &bs_link); 05309 /* For hits of moribund locations, we should just proceed. */ 05310 bs->stop = 0; 05311 bs->print = 0; 05312 bs->print_it = print_it_noop; 05313 } 05314 } 05315 05316 /* A bit of special processing for shlib breakpoints. We need to 05317 process solib loading here, so that the lists of loaded and 05318 unloaded libraries are correct before we handle "catch load" and 05319 "catch unload". */ 05320 for (bs = bs_head; bs != NULL; bs = bs->next) 05321 { 05322 if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) 05323 { 05324 handle_solib_event (); 05325 break; 05326 } 05327 } 05328 05329 /* Now go through the locations that caused the target to stop, and 05330 check whether we're interested in reporting this stop to higher 05331 layers, or whether we should resume the target transparently. */ 05332 05333 removed_any = 0; 05334 05335 for (bs = bs_head; bs != NULL; bs = bs->next) 05336 { 05337 if (!bs->stop) 05338 continue; 05339 05340 b = bs->breakpoint_at; 05341 b->ops->check_status (bs); 05342 if (bs->stop) 05343 { 05344 bpstat_check_breakpoint_conditions (bs, ptid); 05345 05346 if (bs->stop) 05347 { 05348 ++(b->hit_count); 05349 observer_notify_breakpoint_modified (b); 05350 05351 /* We will stop here. */ 05352 if (b->disposition == disp_disable) 05353 { 05354 --(b->enable_count); 05355 if (b->enable_count <= 0 05356 && b->enable_state != bp_permanent) 05357 b->enable_state = bp_disabled; 05358 removed_any = 1; 05359 } 05360 if (b->silent) 05361 bs->print = 0; 05362 bs->commands = b->commands; 05363 incref_counted_command_line (bs->commands); 05364 if (command_line_is_silent (bs->commands 05365 ? bs->commands->commands : NULL)) 05366 bs->print = 0; 05367 05368 b->ops->after_condition_true (bs); 05369 } 05370 05371 } 05372 05373 /* Print nothing for this entry if we don't stop or don't 05374 print. */ 05375 if (!bs->stop || !bs->print) 05376 bs->print_it = print_it_noop; 05377 } 05378 05379 /* If we aren't stopping, the value of some hardware watchpoint may 05380 not have changed, but the intermediate memory locations we are 05381 watching may have. Don't bother if we're stopping; this will get 05382 done later. */ 05383 need_remove_insert = 0; 05384 if (! bpstat_causes_stop (bs_head)) 05385 for (bs = bs_head; bs != NULL; bs = bs->next) 05386 if (!bs->stop 05387 && bs->breakpoint_at 05388 && is_hardware_watchpoint (bs->breakpoint_at)) 05389 { 05390 struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; 05391 05392 update_watchpoint (w, 0 /* don't reparse. */); 05393 need_remove_insert = 1; 05394 } 05395 05396 if (need_remove_insert) 05397 update_global_location_list (1); 05398 else if (removed_any) 05399 update_global_location_list (0); 05400 05401 return bs_head; 05402 } 05403 05404 static void 05405 handle_jit_event (void) 05406 { 05407 struct frame_info *frame; 05408 struct gdbarch *gdbarch; 05409 05410 /* Switch terminal for any messages produced by 05411 breakpoint_re_set. */ 05412 target_terminal_ours_for_output (); 05413 05414 frame = get_current_frame (); 05415 gdbarch = get_frame_arch (frame); 05416 05417 jit_event_handler (gdbarch); 05418 05419 target_terminal_inferior (); 05420 } 05421 05422 /* Prepare WHAT final decision for infrun. */ 05423 05424 /* Decide what infrun needs to do with this bpstat. */ 05425 05426 struct bpstat_what 05427 bpstat_what (bpstat bs_head) 05428 { 05429 struct bpstat_what retval; 05430 int jit_event = 0; 05431 bpstat bs; 05432 05433 retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; 05434 retval.call_dummy = STOP_NONE; 05435 retval.is_longjmp = 0; 05436 05437 for (bs = bs_head; bs != NULL; bs = bs->next) 05438 { 05439 /* Extract this BS's action. After processing each BS, we check 05440 if its action overrides all we've seem so far. */ 05441 enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; 05442 enum bptype bptype; 05443 05444 if (bs->breakpoint_at == NULL) 05445 { 05446 /* I suspect this can happen if it was a momentary 05447 breakpoint which has since been deleted. */ 05448 bptype = bp_none; 05449 } 05450 else 05451 bptype = bs->breakpoint_at->type; 05452 05453 switch (bptype) 05454 { 05455 case bp_none: 05456 break; 05457 case bp_breakpoint: 05458 case bp_hardware_breakpoint: 05459 case bp_until: 05460 case bp_finish: 05461 case bp_shlib_event: 05462 if (bs->stop) 05463 { 05464 if (bs->print) 05465 this_action = BPSTAT_WHAT_STOP_NOISY; 05466 else 05467 this_action = BPSTAT_WHAT_STOP_SILENT; 05468 } 05469 else 05470 this_action = BPSTAT_WHAT_SINGLE; 05471 break; 05472 case bp_watchpoint: 05473 case bp_hardware_watchpoint: 05474 case bp_read_watchpoint: 05475 case bp_access_watchpoint: 05476 if (bs->stop) 05477 { 05478 if (bs->print) 05479 this_action = BPSTAT_WHAT_STOP_NOISY; 05480 else 05481 this_action = BPSTAT_WHAT_STOP_SILENT; 05482 } 05483 else 05484 { 05485 /* There was a watchpoint, but we're not stopping. 05486 This requires no further action. */ 05487 } 05488 break; 05489 case bp_longjmp: 05490 case bp_longjmp_call_dummy: 05491 case bp_exception: 05492 this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; 05493 retval.is_longjmp = bptype != bp_exception; 05494 break; 05495 case bp_longjmp_resume: 05496 case bp_exception_resume: 05497 this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; 05498 retval.is_longjmp = bptype == bp_longjmp_resume; 05499 break; 05500 case bp_step_resume: 05501 if (bs->stop) 05502 this_action = BPSTAT_WHAT_STEP_RESUME; 05503 else 05504 { 05505 /* It is for the wrong frame. */ 05506 this_action = BPSTAT_WHAT_SINGLE; 05507 } 05508 break; 05509 case bp_hp_step_resume: 05510 if (bs->stop) 05511 this_action = BPSTAT_WHAT_HP_STEP_RESUME; 05512 else 05513 { 05514 /* It is for the wrong frame. */ 05515 this_action = BPSTAT_WHAT_SINGLE; 05516 } 05517 break; 05518 case bp_watchpoint_scope: 05519 case bp_thread_event: 05520 case bp_overlay_event: 05521 case bp_longjmp_master: 05522 case bp_std_terminate_master: 05523 case bp_exception_master: 05524 this_action = BPSTAT_WHAT_SINGLE; 05525 break; 05526 case bp_catchpoint: 05527 if (bs->stop) 05528 { 05529 if (bs->print) 05530 this_action = BPSTAT_WHAT_STOP_NOISY; 05531 else 05532 this_action = BPSTAT_WHAT_STOP_SILENT; 05533 } 05534 else 05535 { 05536 /* There was a catchpoint, but we're not stopping. 05537 This requires no further action. */ 05538 } 05539 break; 05540 case bp_jit_event: 05541 jit_event = 1; 05542 this_action = BPSTAT_WHAT_SINGLE; 05543 break; 05544 case bp_call_dummy: 05545 /* Make sure the action is stop (silent or noisy), 05546 so infrun.c pops the dummy frame. */ 05547 retval.call_dummy = STOP_STACK_DUMMY; 05548 this_action = BPSTAT_WHAT_STOP_SILENT; 05549 break; 05550 case bp_std_terminate: 05551 /* Make sure the action is stop (silent or noisy), 05552 so infrun.c pops the dummy frame. */ 05553 retval.call_dummy = STOP_STD_TERMINATE; 05554 this_action = BPSTAT_WHAT_STOP_SILENT; 05555 break; 05556 case bp_tracepoint: 05557 case bp_fast_tracepoint: 05558 case bp_static_tracepoint: 05559 /* Tracepoint hits should not be reported back to GDB, and 05560 if one got through somehow, it should have been filtered 05561 out already. */ 05562 internal_error (__FILE__, __LINE__, 05563 _("bpstat_what: tracepoint encountered")); 05564 break; 05565 case bp_gnu_ifunc_resolver: 05566 /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ 05567 this_action = BPSTAT_WHAT_SINGLE; 05568 break; 05569 case bp_gnu_ifunc_resolver_return: 05570 /* The breakpoint will be removed, execution will restart from the 05571 PC of the former breakpoint. */ 05572 this_action = BPSTAT_WHAT_KEEP_CHECKING; 05573 break; 05574 05575 case bp_dprintf: 05576 if (bs->stop) 05577 this_action = BPSTAT_WHAT_STOP_SILENT; 05578 else 05579 this_action = BPSTAT_WHAT_SINGLE; 05580 break; 05581 05582 default: 05583 internal_error (__FILE__, __LINE__, 05584 _("bpstat_what: unhandled bptype %d"), (int) bptype); 05585 } 05586 05587 retval.main_action = max (retval.main_action, this_action); 05588 } 05589 05590 /* These operations may affect the bs->breakpoint_at state so they are 05591 delayed after MAIN_ACTION is decided above. */ 05592 05593 if (jit_event) 05594 { 05595 if (debug_infrun) 05596 fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); 05597 05598 handle_jit_event (); 05599 } 05600 05601 for (bs = bs_head; bs != NULL; bs = bs->next) 05602 { 05603 struct breakpoint *b = bs->breakpoint_at; 05604 05605 if (b == NULL) 05606 continue; 05607 switch (b->type) 05608 { 05609 case bp_gnu_ifunc_resolver: 05610 gnu_ifunc_resolver_stop (b); 05611 break; 05612 case bp_gnu_ifunc_resolver_return: 05613 gnu_ifunc_resolver_return_stop (b); 05614 break; 05615 } 05616 } 05617 05618 return retval; 05619 } 05620 05621 /* Nonzero if we should step constantly (e.g. watchpoints on machines 05622 without hardware support). This isn't related to a specific bpstat, 05623 just to things like whether watchpoints are set. */ 05624 05625 int 05626 bpstat_should_step (void) 05627 { 05628 struct breakpoint *b; 05629 05630 ALL_BREAKPOINTS (b) 05631 if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) 05632 return 1; 05633 return 0; 05634 } 05635 05636 int 05637 bpstat_causes_stop (bpstat bs) 05638 { 05639 for (; bs != NULL; bs = bs->next) 05640 if (bs->stop) 05641 return 1; 05642 05643 return 0; 05644 } 05645 05646 05647 05648 /* Compute a string of spaces suitable to indent the next line 05649 so it starts at the position corresponding to the table column 05650 named COL_NAME in the currently active table of UIOUT. */ 05651 05652 static char * 05653 wrap_indent_at_field (struct ui_out *uiout, const char *col_name) 05654 { 05655 static char wrap_indent[80]; 05656 int i, total_width, width, align; 05657 char *text; 05658 05659 total_width = 0; 05660 for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) 05661 { 05662 if (strcmp (text, col_name) == 0) 05663 { 05664 gdb_assert (total_width < sizeof wrap_indent); 05665 memset (wrap_indent, ' ', total_width); 05666 wrap_indent[total_width] = 0; 05667 05668 return wrap_indent; 05669 } 05670 05671 total_width += width + 1; 05672 } 05673 05674 return NULL; 05675 } 05676 05677 /* Determine if the locations of this breakpoint will have their conditions 05678 evaluated by the target, host or a mix of both. Returns the following: 05679 05680 "host": Host evals condition. 05681 "host or target": Host or Target evals condition. 05682 "target": Target evals condition. 05683 */ 05684 05685 static const char * 05686 bp_condition_evaluator (struct breakpoint *b) 05687 { 05688 struct bp_location *bl; 05689 char host_evals = 0; 05690 char target_evals = 0; 05691 05692 if (!b) 05693 return NULL; 05694 05695 if (!is_breakpoint (b)) 05696 return NULL; 05697 05698 if (gdb_evaluates_breakpoint_condition_p () 05699 || !target_supports_evaluation_of_breakpoint_conditions ()) 05700 return condition_evaluation_host; 05701 05702 for (bl = b->loc; bl; bl = bl->next) 05703 { 05704 if (bl->cond_bytecode) 05705 target_evals++; 05706 else 05707 host_evals++; 05708 } 05709 05710 if (host_evals && target_evals) 05711 return condition_evaluation_both; 05712 else if (target_evals) 05713 return condition_evaluation_target; 05714 else 05715 return condition_evaluation_host; 05716 } 05717 05718 /* Determine the breakpoint location's condition evaluator. This is 05719 similar to bp_condition_evaluator, but for locations. */ 05720 05721 static const char * 05722 bp_location_condition_evaluator (struct bp_location *bl) 05723 { 05724 if (bl && !is_breakpoint (bl->owner)) 05725 return NULL; 05726 05727 if (gdb_evaluates_breakpoint_condition_p () 05728 || !target_supports_evaluation_of_breakpoint_conditions ()) 05729 return condition_evaluation_host; 05730 05731 if (bl && bl->cond_bytecode) 05732 return condition_evaluation_target; 05733 else 05734 return condition_evaluation_host; 05735 } 05736 05737 /* Print the LOC location out of the list of B->LOC locations. */ 05738 05739 static void 05740 print_breakpoint_location (struct breakpoint *b, 05741 struct bp_location *loc) 05742 { 05743 struct ui_out *uiout = current_uiout; 05744 struct cleanup *old_chain = save_current_program_space (); 05745 05746 if (loc != NULL && loc->shlib_disabled) 05747 loc = NULL; 05748 05749 if (loc != NULL) 05750 set_current_program_space (loc->pspace); 05751 05752 if (b->display_canonical) 05753 ui_out_field_string (uiout, "what", b->addr_string); 05754 else if (loc && loc->symtab) 05755 { 05756 struct symbol *sym 05757 = find_pc_sect_function (loc->address, loc->section); 05758 if (sym) 05759 { 05760 ui_out_text (uiout, "in "); 05761 ui_out_field_string (uiout, "func", 05762 SYMBOL_PRINT_NAME (sym)); 05763 ui_out_text (uiout, " "); 05764 ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); 05765 ui_out_text (uiout, "at "); 05766 } 05767 ui_out_field_string (uiout, "file", 05768 symtab_to_filename_for_display (loc->symtab)); 05769 ui_out_text (uiout, ":"); 05770 05771 if (ui_out_is_mi_like_p (uiout)) 05772 ui_out_field_string (uiout, "fullname", 05773 symtab_to_fullname (loc->symtab)); 05774 05775 ui_out_field_int (uiout, "line", loc->line_number); 05776 } 05777 else if (loc) 05778 { 05779 struct ui_file *stb = mem_fileopen (); 05780 struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); 05781 05782 print_address_symbolic (loc->gdbarch, loc->address, stb, 05783 demangle, ""); 05784 ui_out_field_stream (uiout, "at", stb); 05785 05786 do_cleanups (stb_chain); 05787 } 05788 else 05789 ui_out_field_string (uiout, "pending", b->addr_string); 05790 05791 if (loc && is_breakpoint (b) 05792 && breakpoint_condition_evaluation_mode () == condition_evaluation_target 05793 && bp_condition_evaluator (b) == condition_evaluation_both) 05794 { 05795 ui_out_text (uiout, " ("); 05796 ui_out_field_string (uiout, "evaluated-by", 05797 bp_location_condition_evaluator (loc)); 05798 ui_out_text (uiout, ")"); 05799 } 05800 05801 do_cleanups (old_chain); 05802 } 05803 05804 static const char * 05805 bptype_string (enum bptype type) 05806 { 05807 struct ep_type_description 05808 { 05809 enum bptype type; 05810 char *description; 05811 }; 05812 static struct ep_type_description bptypes[] = 05813 { 05814 {bp_none, "?deleted?"}, 05815 {bp_breakpoint, "breakpoint"}, 05816 {bp_hardware_breakpoint, "hw breakpoint"}, 05817 {bp_until, "until"}, 05818 {bp_finish, "finish"}, 05819 {bp_watchpoint, "watchpoint"}, 05820 {bp_hardware_watchpoint, "hw watchpoint"}, 05821 {bp_read_watchpoint, "read watchpoint"}, 05822 {bp_access_watchpoint, "acc watchpoint"}, 05823 {bp_longjmp, "longjmp"}, 05824 {bp_longjmp_resume, "longjmp resume"}, 05825 {bp_longjmp_call_dummy, "longjmp for call dummy"}, 05826 {bp_exception, "exception"}, 05827 {bp_exception_resume, "exception resume"}, 05828 {bp_step_resume, "step resume"}, 05829 {bp_hp_step_resume, "high-priority step resume"}, 05830 {bp_watchpoint_scope, "watchpoint scope"}, 05831 {bp_call_dummy, "call dummy"}, 05832 {bp_std_terminate, "std::terminate"}, 05833 {bp_shlib_event, "shlib events"}, 05834 {bp_thread_event, "thread events"}, 05835 {bp_overlay_event, "overlay events"}, 05836 {bp_longjmp_master, "longjmp master"}, 05837 {bp_std_terminate_master, "std::terminate master"}, 05838 {bp_exception_master, "exception master"}, 05839 {bp_catchpoint, "catchpoint"}, 05840 {bp_tracepoint, "tracepoint"}, 05841 {bp_fast_tracepoint, "fast tracepoint"}, 05842 {bp_static_tracepoint, "static tracepoint"}, 05843 {bp_dprintf, "dprintf"}, 05844 {bp_jit_event, "jit events"}, 05845 {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, 05846 {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, 05847 }; 05848 05849 if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) 05850 || ((int) type != bptypes[(int) type].type)) 05851 internal_error (__FILE__, __LINE__, 05852 _("bptypes table does not describe type #%d."), 05853 (int) type); 05854 05855 return bptypes[(int) type].description; 05856 } 05857 05858 /* For MI, output a field named 'thread-groups' with a list as the value. 05859 For CLI, prefix the list with the string 'inf'. */ 05860 05861 static void 05862 output_thread_groups (struct ui_out *uiout, 05863 const char *field_name, 05864 VEC(int) *inf_num, 05865 int mi_only) 05866 { 05867 struct cleanup *back_to; 05868 int is_mi = ui_out_is_mi_like_p (uiout); 05869 int inf; 05870 int i; 05871 05872 /* For backward compatibility, don't display inferiors in CLI unless 05873 there are several. Always display them for MI. */ 05874 if (!is_mi && mi_only) 05875 return; 05876 05877 back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); 05878 05879 for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) 05880 { 05881 if (is_mi) 05882 { 05883 char mi_group[10]; 05884 05885 xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); 05886 ui_out_field_string (uiout, NULL, mi_group); 05887 } 05888 else 05889 { 05890 if (i == 0) 05891 ui_out_text (uiout, " inf "); 05892 else 05893 ui_out_text (uiout, ", "); 05894 05895 ui_out_text (uiout, plongest (inf)); 05896 } 05897 } 05898 05899 do_cleanups (back_to); 05900 } 05901 05902 /* Print B to gdb_stdout. */ 05903 05904 static void 05905 print_one_breakpoint_location (struct breakpoint *b, 05906 struct bp_location *loc, 05907 int loc_number, 05908 struct bp_location **last_loc, 05909 int allflag) 05910 { 05911 struct command_line *l; 05912 static char bpenables[] = "nynny"; 05913 05914 struct ui_out *uiout = current_uiout; 05915 int header_of_multiple = 0; 05916 int part_of_multiple = (loc != NULL); 05917 struct value_print_options opts; 05918 05919 get_user_print_options (&opts); 05920 05921 gdb_assert (!loc || loc_number != 0); 05922 /* See comment in print_one_breakpoint concerning treatment of 05923 breakpoints with single disabled location. */ 05924 if (loc == NULL 05925 && (b->loc != NULL 05926 && (b->loc->next != NULL || !b->loc->enabled))) 05927 header_of_multiple = 1; 05928 if (loc == NULL) 05929 loc = b->loc; 05930 05931 annotate_record (); 05932 05933 /* 1 */ 05934 annotate_field (0); 05935 if (part_of_multiple) 05936 { 05937 char *formatted; 05938 formatted = xstrprintf ("%d.%d", b->number, loc_number); 05939 ui_out_field_string (uiout, "number", formatted); 05940 xfree (formatted); 05941 } 05942 else 05943 { 05944 ui_out_field_int (uiout, "number", b->number); 05945 } 05946 05947 /* 2 */ 05948 annotate_field (1); 05949 if (part_of_multiple) 05950 ui_out_field_skip (uiout, "type"); 05951 else 05952 ui_out_field_string (uiout, "type", bptype_string (b->type)); 05953 05954 /* 3 */ 05955 annotate_field (2); 05956 if (part_of_multiple) 05957 ui_out_field_skip (uiout, "disp"); 05958 else 05959 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 05960 05961 05962 /* 4 */ 05963 annotate_field (3); 05964 if (part_of_multiple) 05965 ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); 05966 else 05967 ui_out_field_fmt (uiout, "enabled", "%c", 05968 bpenables[(int) b->enable_state]); 05969 ui_out_spaces (uiout, 2); 05970 05971 05972 /* 5 and 6 */ 05973 if (b->ops != NULL && b->ops->print_one != NULL) 05974 { 05975 /* Although the print_one can possibly print all locations, 05976 calling it here is not likely to get any nice result. So, 05977 make sure there's just one location. */ 05978 gdb_assert (b->loc == NULL || b->loc->next == NULL); 05979 b->ops->print_one (b, last_loc); 05980 } 05981 else 05982 switch (b->type) 05983 { 05984 case bp_none: 05985 internal_error (__FILE__, __LINE__, 05986 _("print_one_breakpoint: bp_none encountered\n")); 05987 break; 05988 05989 case bp_watchpoint: 05990 case bp_hardware_watchpoint: 05991 case bp_read_watchpoint: 05992 case bp_access_watchpoint: 05993 { 05994 struct watchpoint *w = (struct watchpoint *) b; 05995 05996 /* Field 4, the address, is omitted (which makes the columns 05997 not line up too nicely with the headers, but the effect 05998 is relatively readable). */ 05999 if (opts.addressprint) 06000 ui_out_field_skip (uiout, "addr"); 06001 annotate_field (5); 06002 ui_out_field_string (uiout, "what", w->exp_string); 06003 } 06004 break; 06005 06006 case bp_breakpoint: 06007 case bp_hardware_breakpoint: 06008 case bp_until: 06009 case bp_finish: 06010 case bp_longjmp: 06011 case bp_longjmp_resume: 06012 case bp_longjmp_call_dummy: 06013 case bp_exception: 06014 case bp_exception_resume: 06015 case bp_step_resume: 06016 case bp_hp_step_resume: 06017 case bp_watchpoint_scope: 06018 case bp_call_dummy: 06019 case bp_std_terminate: 06020 case bp_shlib_event: 06021 case bp_thread_event: 06022 case bp_overlay_event: 06023 case bp_longjmp_master: 06024 case bp_std_terminate_master: 06025 case bp_exception_master: 06026 case bp_tracepoint: 06027 case bp_fast_tracepoint: 06028 case bp_static_tracepoint: 06029 case bp_dprintf: 06030 case bp_jit_event: 06031 case bp_gnu_ifunc_resolver: 06032 case bp_gnu_ifunc_resolver_return: 06033 if (opts.addressprint) 06034 { 06035 annotate_field (4); 06036 if (header_of_multiple) 06037 ui_out_field_string (uiout, "addr", "<MULTIPLE>"); 06038 else if (b->loc == NULL || loc->shlib_disabled) 06039 ui_out_field_string (uiout, "addr", "<PENDING>"); 06040 else 06041 ui_out_field_core_addr (uiout, "addr", 06042 loc->gdbarch, loc->address); 06043 } 06044 annotate_field (5); 06045 if (!header_of_multiple) 06046 print_breakpoint_location (b, loc); 06047 if (b->loc) 06048 *last_loc = b->loc; 06049 break; 06050 } 06051 06052 06053 if (loc != NULL && !header_of_multiple) 06054 { 06055 struct inferior *inf; 06056 VEC(int) *inf_num = NULL; 06057 int mi_only = 1; 06058 06059 ALL_INFERIORS (inf) 06060 { 06061 if (inf->pspace == loc->pspace) 06062 VEC_safe_push (int, inf_num, inf->num); 06063 } 06064 06065 /* For backward compatibility, don't display inferiors in CLI unless 06066 there are several. Always display for MI. */ 06067 if (allflag 06068 || (!gdbarch_has_global_breakpoints (target_gdbarch ()) 06069 && (number_of_program_spaces () > 1 06070 || number_of_inferiors () > 1) 06071 /* LOC is for existing B, it cannot be in 06072 moribund_locations and thus having NULL OWNER. */ 06073 && loc->owner->type != bp_catchpoint)) 06074 mi_only = 0; 06075 output_thread_groups (uiout, "thread-groups", inf_num, mi_only); 06076 VEC_free (int, inf_num); 06077 } 06078 06079 if (!part_of_multiple) 06080 { 06081 if (b->thread != -1) 06082 { 06083 /* FIXME: This seems to be redundant and lost here; see the 06084 "stop only in" line a little further down. */ 06085 ui_out_text (uiout, " thread "); 06086 ui_out_field_int (uiout, "thread", b->thread); 06087 } 06088 else if (b->task != 0) 06089 { 06090 ui_out_text (uiout, " task "); 06091 ui_out_field_int (uiout, "task", b->task); 06092 } 06093 } 06094 06095 ui_out_text (uiout, "\n"); 06096 06097 if (!part_of_multiple) 06098 b->ops->print_one_detail (b, uiout); 06099 06100 if (part_of_multiple && frame_id_p (b->frame_id)) 06101 { 06102 annotate_field (6); 06103 ui_out_text (uiout, "\tstop only in stack frame at "); 06104 /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside 06105 the frame ID. */ 06106 ui_out_field_core_addr (uiout, "frame", 06107 b->gdbarch, b->frame_id.stack_addr); 06108 ui_out_text (uiout, "\n"); 06109 } 06110 06111 if (!part_of_multiple && b->cond_string) 06112 { 06113 annotate_field (7); 06114 if (is_tracepoint (b)) 06115 ui_out_text (uiout, "\ttrace only if "); 06116 else 06117 ui_out_text (uiout, "\tstop only if "); 06118 ui_out_field_string (uiout, "cond", b->cond_string); 06119 06120 /* Print whether the target is doing the breakpoint's condition 06121 evaluation. If GDB is doing the evaluation, don't print anything. */ 06122 if (is_breakpoint (b) 06123 && breakpoint_condition_evaluation_mode () 06124 == condition_evaluation_target) 06125 { 06126 ui_out_text (uiout, " ("); 06127 ui_out_field_string (uiout, "evaluated-by", 06128 bp_condition_evaluator (b)); 06129 ui_out_text (uiout, " evals)"); 06130 } 06131 ui_out_text (uiout, "\n"); 06132 } 06133 06134 if (!part_of_multiple && b->thread != -1) 06135 { 06136 /* FIXME should make an annotation for this. */ 06137 ui_out_text (uiout, "\tstop only in thread "); 06138 ui_out_field_int (uiout, "thread", b->thread); 06139 ui_out_text (uiout, "\n"); 06140 } 06141 06142 if (!part_of_multiple) 06143 { 06144 if (b->hit_count) 06145 { 06146 /* FIXME should make an annotation for this. */ 06147 if (is_catchpoint (b)) 06148 ui_out_text (uiout, "\tcatchpoint"); 06149 else if (is_tracepoint (b)) 06150 ui_out_text (uiout, "\ttracepoint"); 06151 else 06152 ui_out_text (uiout, "\tbreakpoint"); 06153 ui_out_text (uiout, " already hit "); 06154 ui_out_field_int (uiout, "times", b->hit_count); 06155 if (b->hit_count == 1) 06156 ui_out_text (uiout, " time\n"); 06157 else 06158 ui_out_text (uiout, " times\n"); 06159 } 06160 else 06161 { 06162 /* Output the count also if it is zero, but only if this is mi. */ 06163 if (ui_out_is_mi_like_p (uiout)) 06164 ui_out_field_int (uiout, "times", b->hit_count); 06165 } 06166 } 06167 06168 if (!part_of_multiple && b->ignore_count) 06169 { 06170 annotate_field (8); 06171 ui_out_text (uiout, "\tignore next "); 06172 ui_out_field_int (uiout, "ignore", b->ignore_count); 06173 ui_out_text (uiout, " hits\n"); 06174 } 06175 06176 /* Note that an enable count of 1 corresponds to "enable once" 06177 behavior, which is reported by the combination of enablement and 06178 disposition, so we don't need to mention it here. */ 06179 if (!part_of_multiple && b->enable_count > 1) 06180 { 06181 annotate_field (8); 06182 ui_out_text (uiout, "\tdisable after "); 06183 /* Tweak the wording to clarify that ignore and enable counts 06184 are distinct, and have additive effect. */ 06185 if (b->ignore_count) 06186 ui_out_text (uiout, "additional "); 06187 else 06188 ui_out_text (uiout, "next "); 06189 ui_out_field_int (uiout, "enable", b->enable_count); 06190 ui_out_text (uiout, " hits\n"); 06191 } 06192 06193 if (!part_of_multiple && is_tracepoint (b)) 06194 { 06195 struct tracepoint *tp = (struct tracepoint *) b; 06196 06197 if (tp->traceframe_usage) 06198 { 06199 ui_out_text (uiout, "\ttrace buffer usage "); 06200 ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); 06201 ui_out_text (uiout, " bytes\n"); 06202 } 06203 } 06204 06205 l = b->commands ? b->commands->commands : NULL; 06206 if (!part_of_multiple && l) 06207 { 06208 struct cleanup *script_chain; 06209 06210 annotate_field (9); 06211 script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); 06212 print_command_lines (uiout, l, 4); 06213 do_cleanups (script_chain); 06214 } 06215 06216 if (is_tracepoint (b)) 06217 { 06218 struct tracepoint *t = (struct tracepoint *) b; 06219 06220 if (!part_of_multiple && t->pass_count) 06221 { 06222 annotate_field (10); 06223 ui_out_text (uiout, "\tpass count "); 06224 ui_out_field_int (uiout, "pass", t->pass_count); 06225 ui_out_text (uiout, " \n"); 06226 } 06227 06228 /* Don't display it when tracepoint or tracepoint location is 06229 pending. */ 06230 if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) 06231 { 06232 annotate_field (11); 06233 06234 if (ui_out_is_mi_like_p (uiout)) 06235 ui_out_field_string (uiout, "installed", 06236 loc->inserted ? "y" : "n"); 06237 else 06238 { 06239 if (loc->inserted) 06240 ui_out_text (uiout, "\t"); 06241 else 06242 ui_out_text (uiout, "\tnot "); 06243 ui_out_text (uiout, "installed on target\n"); 06244 } 06245 } 06246 } 06247 06248 if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) 06249 { 06250 if (is_watchpoint (b)) 06251 { 06252 struct watchpoint *w = (struct watchpoint *) b; 06253 06254 ui_out_field_string (uiout, "original-location", w->exp_string); 06255 } 06256 else if (b->addr_string) 06257 ui_out_field_string (uiout, "original-location", b->addr_string); 06258 } 06259 } 06260 06261 static void 06262 print_one_breakpoint (struct breakpoint *b, 06263 struct bp_location **last_loc, 06264 int allflag) 06265 { 06266 struct cleanup *bkpt_chain; 06267 struct ui_out *uiout = current_uiout; 06268 06269 bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); 06270 06271 print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); 06272 do_cleanups (bkpt_chain); 06273 06274 /* If this breakpoint has custom print function, 06275 it's already printed. Otherwise, print individual 06276 locations, if any. */ 06277 if (b->ops == NULL || b->ops->print_one == NULL) 06278 { 06279 /* If breakpoint has a single location that is disabled, we 06280 print it as if it had several locations, since otherwise it's 06281 hard to represent "breakpoint enabled, location disabled" 06282 situation. 06283 06284 Note that while hardware watchpoints have several locations 06285 internally, that's not a property exposed to user. */ 06286 if (b->loc 06287 && !is_hardware_watchpoint (b) 06288 && (b->loc->next || !b->loc->enabled)) 06289 { 06290 struct bp_location *loc; 06291 int n = 1; 06292 06293 for (loc = b->loc; loc; loc = loc->next, ++n) 06294 { 06295 struct cleanup *inner2 = 06296 make_cleanup_ui_out_tuple_begin_end (uiout, NULL); 06297 print_one_breakpoint_location (b, loc, n, last_loc, allflag); 06298 do_cleanups (inner2); 06299 } 06300 } 06301 } 06302 } 06303 06304 static int 06305 breakpoint_address_bits (struct breakpoint *b) 06306 { 06307 int print_address_bits = 0; 06308 struct bp_location *loc; 06309 06310 for (loc = b->loc; loc; loc = loc->next) 06311 { 06312 int addr_bit; 06313 06314 /* Software watchpoints that aren't watching memory don't have 06315 an address to print. */ 06316 if (b->type == bp_watchpoint && loc->watchpoint_type == -1) 06317 continue; 06318 06319 addr_bit = gdbarch_addr_bit (loc->gdbarch); 06320 if (addr_bit > print_address_bits) 06321 print_address_bits = addr_bit; 06322 } 06323 06324 return print_address_bits; 06325 } 06326 06327 struct captured_breakpoint_query_args 06328 { 06329 int bnum; 06330 }; 06331 06332 static int 06333 do_captured_breakpoint_query (struct ui_out *uiout, void *data) 06334 { 06335 struct captured_breakpoint_query_args *args = data; 06336 struct breakpoint *b; 06337 struct bp_location *dummy_loc = NULL; 06338 06339 ALL_BREAKPOINTS (b) 06340 { 06341 if (args->bnum == b->number) 06342 { 06343 print_one_breakpoint (b, &dummy_loc, 0); 06344 return GDB_RC_OK; 06345 } 06346 } 06347 return GDB_RC_NONE; 06348 } 06349 06350 enum gdb_rc 06351 gdb_breakpoint_query (struct ui_out *uiout, int bnum, 06352 char **error_message) 06353 { 06354 struct captured_breakpoint_query_args args; 06355 06356 args.bnum = bnum; 06357 /* For the moment we don't trust print_one_breakpoint() to not throw 06358 an error. */ 06359 if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, 06360 error_message, RETURN_MASK_ALL) < 0) 06361 return GDB_RC_FAIL; 06362 else 06363 return GDB_RC_OK; 06364 } 06365 06366 /* Return true if this breakpoint was set by the user, false if it is 06367 internal or momentary. */ 06368 06369 int 06370 user_breakpoint_p (struct breakpoint *b) 06371 { 06372 return b->number > 0; 06373 } 06374 06375 /* Print information on user settable breakpoint (watchpoint, etc) 06376 number BNUM. If BNUM is -1 print all user-settable breakpoints. 06377 If ALLFLAG is non-zero, include non-user-settable breakpoints. If 06378 FILTER is non-NULL, call it on each breakpoint and only include the 06379 ones for which it returns non-zero. Return the total number of 06380 breakpoints listed. */ 06381 06382 static int 06383 breakpoint_1 (char *args, int allflag, 06384 int (*filter) (const struct breakpoint *)) 06385 { 06386 struct breakpoint *b; 06387 struct bp_location *last_loc = NULL; 06388 int nr_printable_breakpoints; 06389 struct cleanup *bkpttbl_chain; 06390 struct value_print_options opts; 06391 int print_address_bits = 0; 06392 int print_type_col_width = 14; 06393 struct ui_out *uiout = current_uiout; 06394 06395 get_user_print_options (&opts); 06396 06397 /* Compute the number of rows in the table, as well as the size 06398 required for address fields. */ 06399 nr_printable_breakpoints = 0; 06400 ALL_BREAKPOINTS (b) 06401 { 06402 /* If we have a filter, only list the breakpoints it accepts. */ 06403 if (filter && !filter (b)) 06404 continue; 06405 06406 /* If we have an "args" string, it is a list of breakpoints to 06407 accept. Skip the others. */ 06408 if (args != NULL && *args != '\0') 06409 { 06410 if (allflag && parse_and_eval_long (args) != b->number) 06411 continue; 06412 if (!allflag && !number_is_in_list (args, b->number)) 06413 continue; 06414 } 06415 06416 if (allflag || user_breakpoint_p (b)) 06417 { 06418 int addr_bit, type_len; 06419 06420 addr_bit = breakpoint_address_bits (b); 06421 if (addr_bit > print_address_bits) 06422 print_address_bits = addr_bit; 06423 06424 type_len = strlen (bptype_string (b->type)); 06425 if (type_len > print_type_col_width) 06426 print_type_col_width = type_len; 06427 06428 nr_printable_breakpoints++; 06429 } 06430 } 06431 06432 if (opts.addressprint) 06433 bkpttbl_chain 06434 = make_cleanup_ui_out_table_begin_end (uiout, 6, 06435 nr_printable_breakpoints, 06436 "BreakpointTable"); 06437 else 06438 bkpttbl_chain 06439 = make_cleanup_ui_out_table_begin_end (uiout, 5, 06440 nr_printable_breakpoints, 06441 "BreakpointTable"); 06442 06443 if (nr_printable_breakpoints > 0) 06444 annotate_breakpoints_headers (); 06445 if (nr_printable_breakpoints > 0) 06446 annotate_field (0); 06447 ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ 06448 if (nr_printable_breakpoints > 0) 06449 annotate_field (1); 06450 ui_out_table_header (uiout, print_type_col_width, ui_left, 06451 "type", "Type"); /* 2 */ 06452 if (nr_printable_breakpoints > 0) 06453 annotate_field (2); 06454 ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ 06455 if (nr_printable_breakpoints > 0) 06456 annotate_field (3); 06457 ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ 06458 if (opts.addressprint) 06459 { 06460 if (nr_printable_breakpoints > 0) 06461 annotate_field (4); 06462 if (print_address_bits <= 32) 06463 ui_out_table_header (uiout, 10, ui_left, 06464 "addr", "Address"); /* 5 */ 06465 else 06466 ui_out_table_header (uiout, 18, ui_left, 06467 "addr", "Address"); /* 5 */ 06468 } 06469 if (nr_printable_breakpoints > 0) 06470 annotate_field (5); 06471 ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ 06472 ui_out_table_body (uiout); 06473 if (nr_printable_breakpoints > 0) 06474 annotate_breakpoints_table (); 06475 06476 ALL_BREAKPOINTS (b) 06477 { 06478 QUIT; 06479 /* If we have a filter, only list the breakpoints it accepts. */ 06480 if (filter && !filter (b)) 06481 continue; 06482 06483 /* If we have an "args" string, it is a list of breakpoints to 06484 accept. Skip the others. */ 06485 06486 if (args != NULL && *args != '\0') 06487 { 06488 if (allflag) /* maintenance info breakpoint */ 06489 { 06490 if (parse_and_eval_long (args) != b->number) 06491 continue; 06492 } 06493 else /* all others */ 06494 { 06495 if (!number_is_in_list (args, b->number)) 06496 continue; 06497 } 06498 } 06499 /* We only print out user settable breakpoints unless the 06500 allflag is set. */ 06501 if (allflag || user_breakpoint_p (b)) 06502 print_one_breakpoint (b, &last_loc, allflag); 06503 } 06504 06505 do_cleanups (bkpttbl_chain); 06506 06507 if (nr_printable_breakpoints == 0) 06508 { 06509 /* If there's a filter, let the caller decide how to report 06510 empty list. */ 06511 if (!filter) 06512 { 06513 if (args == NULL || *args == '\0') 06514 ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); 06515 else 06516 ui_out_message (uiout, 0, 06517 "No breakpoint or watchpoint matching '%s'.\n", 06518 args); 06519 } 06520 } 06521 else 06522 { 06523 if (last_loc && !server_command) 06524 set_next_address (last_loc->gdbarch, last_loc->address); 06525 } 06526 06527 /* FIXME? Should this be moved up so that it is only called when 06528 there have been breakpoints? */ 06529 annotate_breakpoints_table_end (); 06530 06531 return nr_printable_breakpoints; 06532 } 06533 06534 /* Display the value of default-collect in a way that is generally 06535 compatible with the breakpoint list. */ 06536 06537 static void 06538 default_collect_info (void) 06539 { 06540 struct ui_out *uiout = current_uiout; 06541 06542 /* If it has no value (which is frequently the case), say nothing; a 06543 message like "No default-collect." gets in user's face when it's 06544 not wanted. */ 06545 if (!*default_collect) 06546 return; 06547 06548 /* The following phrase lines up nicely with per-tracepoint collect 06549 actions. */ 06550 ui_out_text (uiout, "default collect "); 06551 ui_out_field_string (uiout, "default-collect", default_collect); 06552 ui_out_text (uiout, " \n"); 06553 } 06554 06555 static void 06556 breakpoints_info (char *args, int from_tty) 06557 { 06558 breakpoint_1 (args, 0, NULL); 06559 06560 default_collect_info (); 06561 } 06562 06563 static void 06564 watchpoints_info (char *args, int from_tty) 06565 { 06566 int num_printed = breakpoint_1 (args, 0, is_watchpoint); 06567 struct ui_out *uiout = current_uiout; 06568 06569 if (num_printed == 0) 06570 { 06571 if (args == NULL || *args == '\0') 06572 ui_out_message (uiout, 0, "No watchpoints.\n"); 06573 else 06574 ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); 06575 } 06576 } 06577 06578 static void 06579 maintenance_info_breakpoints (char *args, int from_tty) 06580 { 06581 breakpoint_1 (args, 1, NULL); 06582 06583 default_collect_info (); 06584 } 06585 06586 static int 06587 breakpoint_has_pc (struct breakpoint *b, 06588 struct program_space *pspace, 06589 CORE_ADDR pc, struct obj_section *section) 06590 { 06591 struct bp_location *bl = b->loc; 06592 06593 for (; bl; bl = bl->next) 06594 { 06595 if (bl->pspace == pspace 06596 && bl->address == pc 06597 && (!overlay_debugging || bl->section == section)) 06598 return 1; 06599 } 06600 return 0; 06601 } 06602 06603 /* Print a message describing any user-breakpoints set at PC. This 06604 concerns with logical breakpoints, so we match program spaces, not 06605 address spaces. */ 06606 06607 static void 06608 describe_other_breakpoints (struct gdbarch *gdbarch, 06609 struct program_space *pspace, CORE_ADDR pc, 06610 struct obj_section *section, int thread) 06611 { 06612 int others = 0; 06613 struct breakpoint *b; 06614 06615 ALL_BREAKPOINTS (b) 06616 others += (user_breakpoint_p (b) 06617 && breakpoint_has_pc (b, pspace, pc, section)); 06618 if (others > 0) 06619 { 06620 if (others == 1) 06621 printf_filtered (_("Note: breakpoint ")); 06622 else /* if (others == ???) */ 06623 printf_filtered (_("Note: breakpoints ")); 06624 ALL_BREAKPOINTS (b) 06625 if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) 06626 { 06627 others--; 06628 printf_filtered ("%d", b->number); 06629 if (b->thread == -1 && thread != -1) 06630 printf_filtered (" (all threads)"); 06631 else if (b->thread != -1) 06632 printf_filtered (" (thread %d)", b->thread); 06633 printf_filtered ("%s%s ", 06634 ((b->enable_state == bp_disabled 06635 || b->enable_state == bp_call_disabled) 06636 ? " (disabled)" 06637 : b->enable_state == bp_permanent 06638 ? " (permanent)" 06639 : ""), 06640 (others > 1) ? "," 06641 : ((others == 1) ? " and" : "")); 06642 } 06643 printf_filtered (_("also set at pc ")); 06644 fputs_filtered (paddress (gdbarch, pc), gdb_stdout); 06645 printf_filtered (".\n"); 06646 } 06647 } 06648 06649 06650 /* Return true iff it is meaningful to use the address member of 06651 BPT. For some breakpoint types, the address member is irrelevant 06652 and it makes no sense to attempt to compare it to other addresses 06653 (or use it for any other purpose either). 06654 06655 More specifically, each of the following breakpoint types will 06656 always have a zero valued address and we don't want to mark 06657 breakpoints of any of these types to be a duplicate of an actual 06658 breakpoint at address zero: 06659 06660 bp_watchpoint 06661 bp_catchpoint 06662 06663 */ 06664 06665 static int 06666 breakpoint_address_is_meaningful (struct breakpoint *bpt) 06667 { 06668 enum bptype type = bpt->type; 06669 06670 return (type != bp_watchpoint && type != bp_catchpoint); 06671 } 06672 06673 /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns 06674 true if LOC1 and LOC2 represent the same watchpoint location. */ 06675 06676 static int 06677 watchpoint_locations_match (struct bp_location *loc1, 06678 struct bp_location *loc2) 06679 { 06680 struct watchpoint *w1 = (struct watchpoint *) loc1->owner; 06681 struct watchpoint *w2 = (struct watchpoint *) loc2->owner; 06682 06683 /* Both of them must exist. */ 06684 gdb_assert (w1 != NULL); 06685 gdb_assert (w2 != NULL); 06686 06687 /* If the target can evaluate the condition expression in hardware, 06688 then we we need to insert both watchpoints even if they are at 06689 the same place. Otherwise the watchpoint will only trigger when 06690 the condition of whichever watchpoint was inserted evaluates to 06691 true, not giving a chance for GDB to check the condition of the 06692 other watchpoint. */ 06693 if ((w1->cond_exp 06694 && target_can_accel_watchpoint_condition (loc1->address, 06695 loc1->length, 06696 loc1->watchpoint_type, 06697 w1->cond_exp)) 06698 || (w2->cond_exp 06699 && target_can_accel_watchpoint_condition (loc2->address, 06700 loc2->length, 06701 loc2->watchpoint_type, 06702 w2->cond_exp))) 06703 return 0; 06704 06705 /* Note that this checks the owner's type, not the location's. In 06706 case the target does not support read watchpoints, but does 06707 support access watchpoints, we'll have bp_read_watchpoint 06708 watchpoints with hw_access locations. Those should be considered 06709 duplicates of hw_read locations. The hw_read locations will 06710 become hw_access locations later. */ 06711 return (loc1->owner->type == loc2->owner->type 06712 && loc1->pspace->aspace == loc2->pspace->aspace 06713 && loc1->address == loc2->address 06714 && loc1->length == loc2->length); 06715 } 06716 06717 /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the 06718 same breakpoint location. In most targets, this can only be true 06719 if ASPACE1 matches ASPACE2. On targets that have global 06720 breakpoints, the address space doesn't really matter. */ 06721 06722 static int 06723 breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, 06724 struct address_space *aspace2, CORE_ADDR addr2) 06725 { 06726 return ((gdbarch_has_global_breakpoints (target_gdbarch ()) 06727 || aspace1 == aspace2) 06728 && addr1 == addr2); 06729 } 06730 06731 /* Returns true if {ASPACE2,ADDR2} falls within the range determined by 06732 {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 06733 matches ASPACE2. On targets that have global breakpoints, the address 06734 space doesn't really matter. */ 06735 06736 static int 06737 breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, 06738 int len1, struct address_space *aspace2, 06739 CORE_ADDR addr2) 06740 { 06741 return ((gdbarch_has_global_breakpoints (target_gdbarch ()) 06742 || aspace1 == aspace2) 06743 && addr2 >= addr1 && addr2 < addr1 + len1); 06744 } 06745 06746 /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be 06747 a ranged breakpoint. In most targets, a match happens only if ASPACE 06748 matches the breakpoint's address space. On targets that have global 06749 breakpoints, the address space doesn't really matter. */ 06750 06751 static int 06752 breakpoint_location_address_match (struct bp_location *bl, 06753 struct address_space *aspace, 06754 CORE_ADDR addr) 06755 { 06756 return (breakpoint_address_match (bl->pspace->aspace, bl->address, 06757 aspace, addr) 06758 || (bl->length 06759 && breakpoint_address_match_range (bl->pspace->aspace, 06760 bl->address, bl->length, 06761 aspace, addr))); 06762 } 06763 06764 /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. 06765 Then, if LOC1 and LOC2 represent the same tracepoint location, returns 06766 true, otherwise returns false. */ 06767 06768 static int 06769 tracepoint_locations_match (struct bp_location *loc1, 06770 struct bp_location *loc2) 06771 { 06772 if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) 06773 /* Since tracepoint locations are never duplicated with others', tracepoint 06774 locations at the same address of different tracepoints are regarded as 06775 different locations. */ 06776 return (loc1->address == loc2->address && loc1->owner == loc2->owner); 06777 else 06778 return 0; 06779 } 06780 06781 /* Assuming LOC1 and LOC2's types' have meaningful target addresses 06782 (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 06783 represent the same location. */ 06784 06785 static int 06786 breakpoint_locations_match (struct bp_location *loc1, 06787 struct bp_location *loc2) 06788 { 06789 int hw_point1, hw_point2; 06790 06791 /* Both of them must not be in moribund_locations. */ 06792 gdb_assert (loc1->owner != NULL); 06793 gdb_assert (loc2->owner != NULL); 06794 06795 hw_point1 = is_hardware_watchpoint (loc1->owner); 06796 hw_point2 = is_hardware_watchpoint (loc2->owner); 06797 06798 if (hw_point1 != hw_point2) 06799 return 0; 06800 else if (hw_point1) 06801 return watchpoint_locations_match (loc1, loc2); 06802 else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) 06803 return tracepoint_locations_match (loc1, loc2); 06804 else 06805 /* We compare bp_location.length in order to cover ranged breakpoints. */ 06806 return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, 06807 loc2->pspace->aspace, loc2->address) 06808 && loc1->length == loc2->length); 06809 } 06810 06811 static void 06812 breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, 06813 int bnum, int have_bnum) 06814 { 06815 /* The longest string possibly returned by hex_string_custom 06816 is 50 chars. These must be at least that big for safety. */ 06817 char astr1[64]; 06818 char astr2[64]; 06819 06820 strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); 06821 strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); 06822 if (have_bnum) 06823 warning (_("Breakpoint %d address previously adjusted from %s to %s."), 06824 bnum, astr1, astr2); 06825 else 06826 warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); 06827 } 06828 06829 /* Adjust a breakpoint's address to account for architectural 06830 constraints on breakpoint placement. Return the adjusted address. 06831 Note: Very few targets require this kind of adjustment. For most 06832 targets, this function is simply the identity function. */ 06833 06834 static CORE_ADDR 06835 adjust_breakpoint_address (struct gdbarch *gdbarch, 06836 CORE_ADDR bpaddr, enum bptype bptype) 06837 { 06838 if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) 06839 { 06840 /* Very few targets need any kind of breakpoint adjustment. */ 06841 return bpaddr; 06842 } 06843 else if (bptype == bp_watchpoint 06844 || bptype == bp_hardware_watchpoint 06845 || bptype == bp_read_watchpoint 06846 || bptype == bp_access_watchpoint 06847 || bptype == bp_catchpoint) 06848 { 06849 /* Watchpoints and the various bp_catch_* eventpoints should not 06850 have their addresses modified. */ 06851 return bpaddr; 06852 } 06853 else 06854 { 06855 CORE_ADDR adjusted_bpaddr; 06856 06857 /* Some targets have architectural constraints on the placement 06858 of breakpoint instructions. Obtain the adjusted address. */ 06859 adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); 06860 06861 /* An adjusted breakpoint address can significantly alter 06862 a user's expectations. Print a warning if an adjustment 06863 is required. */ 06864 if (adjusted_bpaddr != bpaddr) 06865 breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); 06866 06867 return adjusted_bpaddr; 06868 } 06869 } 06870 06871 void 06872 init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, 06873 struct breakpoint *owner) 06874 { 06875 memset (loc, 0, sizeof (*loc)); 06876 06877 gdb_assert (ops != NULL); 06878 06879 loc->ops = ops; 06880 loc->owner = owner; 06881 loc->cond = NULL; 06882 loc->cond_bytecode = NULL; 06883 loc->shlib_disabled = 0; 06884 loc->enabled = 1; 06885 06886 switch (owner->type) 06887 { 06888 case bp_breakpoint: 06889 case bp_until: 06890 case bp_finish: 06891 case bp_longjmp: 06892 case bp_longjmp_resume: 06893 case bp_longjmp_call_dummy: 06894 case bp_exception: 06895 case bp_exception_resume: 06896 case bp_step_resume: 06897 case bp_hp_step_resume: 06898 case bp_watchpoint_scope: 06899 case bp_call_dummy: 06900 case bp_std_terminate: 06901 case bp_shlib_event: 06902 case bp_thread_event: 06903 case bp_overlay_event: 06904 case bp_jit_event: 06905 case bp_longjmp_master: 06906 case bp_std_terminate_master: 06907 case bp_exception_master: 06908 case bp_gnu_ifunc_resolver: 06909 case bp_gnu_ifunc_resolver_return: 06910 case bp_dprintf: 06911 loc->loc_type = bp_loc_software_breakpoint; 06912 mark_breakpoint_location_modified (loc); 06913 break; 06914 case bp_hardware_breakpoint: 06915 loc->loc_type = bp_loc_hardware_breakpoint; 06916 mark_breakpoint_location_modified (loc); 06917 break; 06918 case bp_hardware_watchpoint: 06919 case bp_read_watchpoint: 06920 case bp_access_watchpoint: 06921 loc->loc_type = bp_loc_hardware_watchpoint; 06922 break; 06923 case bp_watchpoint: 06924 case bp_catchpoint: 06925 case bp_tracepoint: 06926 case bp_fast_tracepoint: 06927 case bp_static_tracepoint: 06928 loc->loc_type = bp_loc_other; 06929 break; 06930 default: 06931 internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); 06932 } 06933 06934 loc->refc = 1; 06935 } 06936 06937 /* Allocate a struct bp_location. */ 06938 06939 static struct bp_location * 06940 allocate_bp_location (struct breakpoint *bpt) 06941 { 06942 return bpt->ops->allocate_location (bpt); 06943 } 06944 06945 static void 06946 free_bp_location (struct bp_location *loc) 06947 { 06948 loc->ops->dtor (loc); 06949 xfree (loc); 06950 } 06951 06952 /* Increment reference count. */ 06953 06954 static void 06955 incref_bp_location (struct bp_location *bl) 06956 { 06957 ++bl->refc; 06958 } 06959 06960 /* Decrement reference count. If the reference count reaches 0, 06961 destroy the bp_location. Sets *BLP to NULL. */ 06962 06963 static void 06964 decref_bp_location (struct bp_location **blp) 06965 { 06966 gdb_assert ((*blp)->refc > 0); 06967 06968 if (--(*blp)->refc == 0) 06969 free_bp_location (*blp); 06970 *blp = NULL; 06971 } 06972 06973 /* Add breakpoint B at the end of the global breakpoint chain. */ 06974 06975 static void 06976 add_to_breakpoint_chain (struct breakpoint *b) 06977 { 06978 struct breakpoint *b1; 06979 06980 /* Add this breakpoint to the end of the chain so that a list of 06981 breakpoints will come out in order of increasing numbers. */ 06982 06983 b1 = breakpoint_chain; 06984 if (b1 == 0) 06985 breakpoint_chain = b; 06986 else 06987 { 06988 while (b1->next) 06989 b1 = b1->next; 06990 b1->next = b; 06991 } 06992 } 06993 06994 /* Initializes breakpoint B with type BPTYPE and no locations yet. */ 06995 06996 static void 06997 init_raw_breakpoint_without_location (struct breakpoint *b, 06998 struct gdbarch *gdbarch, 06999 enum bptype bptype, 07000 const struct breakpoint_ops *ops) 07001 { 07002 memset (b, 0, sizeof (*b)); 07003 07004 gdb_assert (ops != NULL); 07005 07006 b->ops = ops; 07007 b->type = bptype; 07008 b->gdbarch = gdbarch; 07009 b->language = current_language->la_language; 07010 b->input_radix = input_radix; 07011 b->thread = -1; 07012 b->enable_state = bp_enabled; 07013 b->next = 0; 07014 b->silent = 0; 07015 b->ignore_count = 0; 07016 b->commands = NULL; 07017 b->frame_id = null_frame_id; 07018 b->condition_not_parsed = 0; 07019 b->py_bp_object = NULL; 07020 b->related_breakpoint = b; 07021 } 07022 07023 /* Helper to set_raw_breakpoint below. Creates a breakpoint 07024 that has type BPTYPE and has no locations as yet. */ 07025 07026 static struct breakpoint * 07027 set_raw_breakpoint_without_location (struct gdbarch *gdbarch, 07028 enum bptype bptype, 07029 const struct breakpoint_ops *ops) 07030 { 07031 struct breakpoint *b = XNEW (struct breakpoint); 07032 07033 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); 07034 add_to_breakpoint_chain (b); 07035 return b; 07036 } 07037 07038 /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function 07039 resolutions should be made as the user specified the location explicitly 07040 enough. */ 07041 07042 static void 07043 set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) 07044 { 07045 gdb_assert (loc->owner != NULL); 07046 07047 if (loc->owner->type == bp_breakpoint 07048 || loc->owner->type == bp_hardware_breakpoint 07049 || is_tracepoint (loc->owner)) 07050 { 07051 int is_gnu_ifunc; 07052 const char *function_name; 07053 CORE_ADDR func_addr; 07054 07055 find_pc_partial_function_gnu_ifunc (loc->address, &function_name, 07056 &func_addr, NULL, &is_gnu_ifunc); 07057 07058 if (is_gnu_ifunc && !explicit_loc) 07059 { 07060 struct breakpoint *b = loc->owner; 07061 07062 gdb_assert (loc->pspace == current_program_space); 07063 if (gnu_ifunc_resolve_name (function_name, 07064 &loc->requested_address)) 07065 { 07066 /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ 07067 loc->address = adjust_breakpoint_address (loc->gdbarch, 07068 loc->requested_address, 07069 b->type); 07070 } 07071 else if (b->type == bp_breakpoint && b->loc == loc 07072 && loc->next == NULL && b->related_breakpoint == b) 07073 { 07074 /* Create only the whole new breakpoint of this type but do not 07075 mess more complicated breakpoints with multiple locations. */ 07076 b->type = bp_gnu_ifunc_resolver; 07077 /* Remember the resolver's address for use by the return 07078 breakpoint. */ 07079 loc->related_address = func_addr; 07080 } 07081 } 07082 07083 if (function_name) 07084 loc->function_name = xstrdup (function_name); 07085 } 07086 } 07087 07088 /* Attempt to determine architecture of location identified by SAL. */ 07089 struct gdbarch * 07090 get_sal_arch (struct symtab_and_line sal) 07091 { 07092 if (sal.section) 07093 return get_objfile_arch (sal.section->objfile); 07094 if (sal.symtab) 07095 return get_objfile_arch (sal.symtab->objfile); 07096 07097 return NULL; 07098 } 07099 07100 /* Low level routine for partially initializing a breakpoint of type 07101 BPTYPE. The newly created breakpoint's address, section, source 07102 file name, and line number are provided by SAL. 07103 07104 It is expected that the caller will complete the initialization of 07105 the newly created breakpoint struct as well as output any status 07106 information regarding the creation of a new breakpoint. */ 07107 07108 static void 07109 init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, 07110 struct symtab_and_line sal, enum bptype bptype, 07111 const struct breakpoint_ops *ops) 07112 { 07113 init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); 07114 07115 add_location_to_breakpoint (b, &sal); 07116 07117 if (bptype != bp_catchpoint) 07118 gdb_assert (sal.pspace != NULL); 07119 07120 /* Store the program space that was used to set the breakpoint, 07121 except for ordinary breakpoints, which are independent of the 07122 program space. */ 07123 if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) 07124 b->pspace = sal.pspace; 07125 } 07126 07127 /* set_raw_breakpoint is a low level routine for allocating and 07128 partially initializing a breakpoint of type BPTYPE. The newly 07129 created breakpoint's address, section, source file name, and line 07130 number are provided by SAL. The newly created and partially 07131 initialized breakpoint is added to the breakpoint chain and 07132 is also returned as the value of this function. 07133 07134 It is expected that the caller will complete the initialization of 07135 the newly created breakpoint struct as well as output any status 07136 information regarding the creation of a new breakpoint. In 07137 particular, set_raw_breakpoint does NOT set the breakpoint 07138 number! Care should be taken to not allow an error to occur 07139 prior to completing the initialization of the breakpoint. If this 07140 should happen, a bogus breakpoint will be left on the chain. */ 07141 07142 struct breakpoint * 07143 set_raw_breakpoint (struct gdbarch *gdbarch, 07144 struct symtab_and_line sal, enum bptype bptype, 07145 const struct breakpoint_ops *ops) 07146 { 07147 struct breakpoint *b = XNEW (struct breakpoint); 07148 07149 init_raw_breakpoint (b, gdbarch, sal, bptype, ops); 07150 add_to_breakpoint_chain (b); 07151 return b; 07152 } 07153 07154 07155 /* Note that the breakpoint object B describes a permanent breakpoint 07156 instruction, hard-wired into the inferior's code. */ 07157 void 07158 make_breakpoint_permanent (struct breakpoint *b) 07159 { 07160 struct bp_location *bl; 07161 07162 b->enable_state = bp_permanent; 07163 07164 /* By definition, permanent breakpoints are already present in the 07165 code. Mark all locations as inserted. For now, 07166 make_breakpoint_permanent is called in just one place, so it's 07167 hard to say if it's reasonable to have permanent breakpoint with 07168 multiple locations or not, but it's easy to implement. */ 07169 for (bl = b->loc; bl; bl = bl->next) 07170 bl->inserted = 1; 07171 } 07172 07173 /* Call this routine when stepping and nexting to enable a breakpoint 07174 if we do a longjmp() or 'throw' in TP. FRAME is the frame which 07175 initiated the operation. */ 07176 07177 void 07178 set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) 07179 { 07180 struct breakpoint *b, *b_tmp; 07181 int thread = tp->num; 07182 07183 /* To avoid having to rescan all objfile symbols at every step, 07184 we maintain a list of continually-inserted but always disabled 07185 longjmp "master" breakpoints. Here, we simply create momentary 07186 clones of those and enable them for the requested thread. */ 07187 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07188 if (b->pspace == current_program_space 07189 && (b->type == bp_longjmp_master 07190 || b->type == bp_exception_master)) 07191 { 07192 enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; 07193 struct breakpoint *clone; 07194 07195 /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again 07196 after their removal. */ 07197 clone = momentary_breakpoint_from_master (b, type, 07198 &longjmp_breakpoint_ops); 07199 clone->thread = thread; 07200 } 07201 07202 tp->initiating_frame = frame; 07203 } 07204 07205 /* Delete all longjmp breakpoints from THREAD. */ 07206 void 07207 delete_longjmp_breakpoint (int thread) 07208 { 07209 struct breakpoint *b, *b_tmp; 07210 07211 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07212 if (b->type == bp_longjmp || b->type == bp_exception) 07213 { 07214 if (b->thread == thread) 07215 delete_breakpoint (b); 07216 } 07217 } 07218 07219 void 07220 delete_longjmp_breakpoint_at_next_stop (int thread) 07221 { 07222 struct breakpoint *b, *b_tmp; 07223 07224 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07225 if (b->type == bp_longjmp || b->type == bp_exception) 07226 { 07227 if (b->thread == thread) 07228 b->disposition = disp_del_at_next_stop; 07229 } 07230 } 07231 07232 /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for 07233 INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return 07234 pointer to any of them. Return NULL if this system cannot place longjmp 07235 breakpoints. */ 07236 07237 struct breakpoint * 07238 set_longjmp_breakpoint_for_call_dummy (void) 07239 { 07240 struct breakpoint *b, *retval = NULL; 07241 07242 ALL_BREAKPOINTS (b) 07243 if (b->pspace == current_program_space && b->type == bp_longjmp_master) 07244 { 07245 struct breakpoint *new_b; 07246 07247 new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, 07248 &momentary_breakpoint_ops); 07249 new_b->thread = pid_to_thread_id (inferior_ptid); 07250 07251 /* Link NEW_B into the chain of RETVAL breakpoints. */ 07252 07253 gdb_assert (new_b->related_breakpoint == new_b); 07254 if (retval == NULL) 07255 retval = new_b; 07256 new_b->related_breakpoint = retval; 07257 while (retval->related_breakpoint != new_b->related_breakpoint) 07258 retval = retval->related_breakpoint; 07259 retval->related_breakpoint = new_b; 07260 } 07261 07262 return retval; 07263 } 07264 07265 /* Verify all existing dummy frames and their associated breakpoints for 07266 THREAD. Remove those which can no longer be found in the current frame 07267 stack. 07268 07269 You should call this function only at places where it is safe to currently 07270 unwind the whole stack. Failed stack unwind would discard live dummy 07271 frames. */ 07272 07273 void 07274 check_longjmp_breakpoint_for_call_dummy (int thread) 07275 { 07276 struct breakpoint *b, *b_tmp; 07277 07278 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07279 if (b->type == bp_longjmp_call_dummy && b->thread == thread) 07280 { 07281 struct breakpoint *dummy_b = b->related_breakpoint; 07282 07283 while (dummy_b != b && dummy_b->type != bp_call_dummy) 07284 dummy_b = dummy_b->related_breakpoint; 07285 if (dummy_b->type != bp_call_dummy 07286 || frame_find_by_id (dummy_b->frame_id) != NULL) 07287 continue; 07288 07289 dummy_frame_discard (dummy_b->frame_id); 07290 07291 while (b->related_breakpoint != b) 07292 { 07293 if (b_tmp == b->related_breakpoint) 07294 b_tmp = b->related_breakpoint->next; 07295 delete_breakpoint (b->related_breakpoint); 07296 } 07297 delete_breakpoint (b); 07298 } 07299 } 07300 07301 void 07302 enable_overlay_breakpoints (void) 07303 { 07304 struct breakpoint *b; 07305 07306 ALL_BREAKPOINTS (b) 07307 if (b->type == bp_overlay_event) 07308 { 07309 b->enable_state = bp_enabled; 07310 update_global_location_list (1); 07311 overlay_events_enabled = 1; 07312 } 07313 } 07314 07315 void 07316 disable_overlay_breakpoints (void) 07317 { 07318 struct breakpoint *b; 07319 07320 ALL_BREAKPOINTS (b) 07321 if (b->type == bp_overlay_event) 07322 { 07323 b->enable_state = bp_disabled; 07324 update_global_location_list (0); 07325 overlay_events_enabled = 0; 07326 } 07327 } 07328 07329 /* Set an active std::terminate breakpoint for each std::terminate 07330 master breakpoint. */ 07331 void 07332 set_std_terminate_breakpoint (void) 07333 { 07334 struct breakpoint *b, *b_tmp; 07335 07336 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07337 if (b->pspace == current_program_space 07338 && b->type == bp_std_terminate_master) 07339 { 07340 momentary_breakpoint_from_master (b, bp_std_terminate, 07341 &momentary_breakpoint_ops); 07342 } 07343 } 07344 07345 /* Delete all the std::terminate breakpoints. */ 07346 void 07347 delete_std_terminate_breakpoint (void) 07348 { 07349 struct breakpoint *b, *b_tmp; 07350 07351 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07352 if (b->type == bp_std_terminate) 07353 delete_breakpoint (b); 07354 } 07355 07356 struct breakpoint * 07357 create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) 07358 { 07359 struct breakpoint *b; 07360 07361 b = create_internal_breakpoint (gdbarch, address, bp_thread_event, 07362 &internal_breakpoint_ops); 07363 07364 b->enable_state = bp_enabled; 07365 /* addr_string has to be used or breakpoint_re_set will delete me. */ 07366 b->addr_string 07367 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); 07368 07369 update_global_location_list_nothrow (1); 07370 07371 return b; 07372 } 07373 07374 void 07375 remove_thread_event_breakpoints (void) 07376 { 07377 struct breakpoint *b, *b_tmp; 07378 07379 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07380 if (b->type == bp_thread_event 07381 && b->loc->pspace == current_program_space) 07382 delete_breakpoint (b); 07383 } 07384 07385 struct lang_and_radix 07386 { 07387 enum language lang; 07388 int radix; 07389 }; 07390 07391 /* Create a breakpoint for JIT code registration and unregistration. */ 07392 07393 struct breakpoint * 07394 create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) 07395 { 07396 struct breakpoint *b; 07397 07398 b = create_internal_breakpoint (gdbarch, address, bp_jit_event, 07399 &internal_breakpoint_ops); 07400 update_global_location_list_nothrow (1); 07401 return b; 07402 } 07403 07404 /* Remove JIT code registration and unregistration breakpoint(s). */ 07405 07406 void 07407 remove_jit_event_breakpoints (void) 07408 { 07409 struct breakpoint *b, *b_tmp; 07410 07411 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07412 if (b->type == bp_jit_event 07413 && b->loc->pspace == current_program_space) 07414 delete_breakpoint (b); 07415 } 07416 07417 void 07418 remove_solib_event_breakpoints (void) 07419 { 07420 struct breakpoint *b, *b_tmp; 07421 07422 ALL_BREAKPOINTS_SAFE (b, b_tmp) 07423 if (b->type == bp_shlib_event 07424 && b->loc->pspace == current_program_space) 07425 delete_breakpoint (b); 07426 } 07427 07428 struct breakpoint * 07429 create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) 07430 { 07431 struct breakpoint *b; 07432 07433 b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, 07434 &internal_breakpoint_ops); 07435 update_global_location_list_nothrow (1); 07436 return b; 07437 } 07438 07439 /* Disable any breakpoints that are on code in shared libraries. Only 07440 apply to enabled breakpoints, disabled ones can just stay disabled. */ 07441 07442 void 07443 disable_breakpoints_in_shlibs (void) 07444 { 07445 struct bp_location *loc, **locp_tmp; 07446 07447 ALL_BP_LOCATIONS (loc, locp_tmp) 07448 { 07449 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ 07450 struct breakpoint *b = loc->owner; 07451 07452 /* We apply the check to all breakpoints, including disabled for 07453 those with loc->duplicate set. This is so that when breakpoint 07454 becomes enabled, or the duplicate is removed, gdb will try to 07455 insert all breakpoints. If we don't set shlib_disabled here, 07456 we'll try to insert those breakpoints and fail. */ 07457 if (((b->type == bp_breakpoint) 07458 || (b->type == bp_jit_event) 07459 || (b->type == bp_hardware_breakpoint) 07460 || (is_tracepoint (b))) 07461 && loc->pspace == current_program_space 07462 && !loc->shlib_disabled 07463 && solib_name_from_address (loc->pspace, loc->address) 07464 ) 07465 { 07466 loc->shlib_disabled = 1; 07467 } 07468 } 07469 } 07470 07471 /* Disable any breakpoints and tracepoints that are in an unloaded shared 07472 library. Only apply to enabled breakpoints, disabled ones can just stay 07473 disabled. */ 07474 07475 static void 07476 disable_breakpoints_in_unloaded_shlib (struct so_list *solib) 07477 { 07478 struct bp_location *loc, **locp_tmp; 07479 int disabled_shlib_breaks = 0; 07480 07481 /* SunOS a.out shared libraries are always mapped, so do not 07482 disable breakpoints; they will only be reported as unloaded 07483 through clear_solib when GDB discards its shared library 07484 list. See clear_solib for more information. */ 07485 if (exec_bfd != NULL 07486 && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) 07487 return; 07488 07489 ALL_BP_LOCATIONS (loc, locp_tmp) 07490 { 07491 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ 07492 struct breakpoint *b = loc->owner; 07493 07494 if (solib->pspace == loc->pspace 07495 && !loc->shlib_disabled 07496 && (((b->type == bp_breakpoint 07497 || b->type == bp_jit_event 07498 || b->type == bp_hardware_breakpoint) 07499 && (loc->loc_type == bp_loc_hardware_breakpoint 07500 || loc->loc_type == bp_loc_software_breakpoint)) 07501 || is_tracepoint (b)) 07502 && solib_contains_address_p (solib, loc->address)) 07503 { 07504 loc->shlib_disabled = 1; 07505 /* At this point, we cannot rely on remove_breakpoint 07506 succeeding so we must mark the breakpoint as not inserted 07507 to prevent future errors occurring in remove_breakpoints. */ 07508 loc->inserted = 0; 07509 07510 /* This may cause duplicate notifications for the same breakpoint. */ 07511 observer_notify_breakpoint_modified (b); 07512 07513 if (!disabled_shlib_breaks) 07514 { 07515 target_terminal_ours_for_output (); 07516 warning (_("Temporarily disabling breakpoints " 07517 "for unloaded shared library \"%s\""), 07518 solib->so_name); 07519 } 07520 disabled_shlib_breaks = 1; 07521 } 07522 } 07523 } 07524 07525 /* FORK & VFORK catchpoints. */ 07526 07527 /* An instance of this type is used to represent a fork or vfork 07528 catchpoint. It includes a "struct breakpoint" as a kind of base 07529 class; users downcast to "struct breakpoint *" when needed. A 07530 breakpoint is really of this type iff its ops pointer points to 07531 CATCH_FORK_BREAKPOINT_OPS. */ 07532 07533 struct fork_catchpoint 07534 { 07535 /* The base class. */ 07536 struct breakpoint base; 07537 07538 /* Process id of a child process whose forking triggered this 07539 catchpoint. This field is only valid immediately after this 07540 catchpoint has triggered. */ 07541 ptid_t forked_inferior_pid; 07542 }; 07543 07544 /* Implement the "insert" breakpoint_ops method for fork 07545 catchpoints. */ 07546 07547 static int 07548 insert_catch_fork (struct bp_location *bl) 07549 { 07550 return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); 07551 } 07552 07553 /* Implement the "remove" breakpoint_ops method for fork 07554 catchpoints. */ 07555 07556 static int 07557 remove_catch_fork (struct bp_location *bl) 07558 { 07559 return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); 07560 } 07561 07562 /* Implement the "breakpoint_hit" breakpoint_ops method for fork 07563 catchpoints. */ 07564 07565 static int 07566 breakpoint_hit_catch_fork (const struct bp_location *bl, 07567 struct address_space *aspace, CORE_ADDR bp_addr, 07568 const struct target_waitstatus *ws) 07569 { 07570 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; 07571 07572 if (ws->kind != TARGET_WAITKIND_FORKED) 07573 return 0; 07574 07575 c->forked_inferior_pid = ws->value.related_pid; 07576 return 1; 07577 } 07578 07579 /* Implement the "print_it" breakpoint_ops method for fork 07580 catchpoints. */ 07581 07582 static enum print_stop_action 07583 print_it_catch_fork (bpstat bs) 07584 { 07585 struct ui_out *uiout = current_uiout; 07586 struct breakpoint *b = bs->breakpoint_at; 07587 struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; 07588 07589 annotate_catchpoint (b->number); 07590 if (b->disposition == disp_del) 07591 ui_out_text (uiout, "\nTemporary catchpoint "); 07592 else 07593 ui_out_text (uiout, "\nCatchpoint "); 07594 if (ui_out_is_mi_like_p (uiout)) 07595 { 07596 ui_out_field_string (uiout, "reason", 07597 async_reason_lookup (EXEC_ASYNC_FORK)); 07598 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 07599 } 07600 ui_out_field_int (uiout, "bkptno", b->number); 07601 ui_out_text (uiout, " (forked process "); 07602 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); 07603 ui_out_text (uiout, "), "); 07604 return PRINT_SRC_AND_LOC; 07605 } 07606 07607 /* Implement the "print_one" breakpoint_ops method for fork 07608 catchpoints. */ 07609 07610 static void 07611 print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) 07612 { 07613 struct fork_catchpoint *c = (struct fork_catchpoint *) b; 07614 struct value_print_options opts; 07615 struct ui_out *uiout = current_uiout; 07616 07617 get_user_print_options (&opts); 07618 07619 /* Field 4, the address, is omitted (which makes the columns not 07620 line up too nicely with the headers, but the effect is relatively 07621 readable). */ 07622 if (opts.addressprint) 07623 ui_out_field_skip (uiout, "addr"); 07624 annotate_field (5); 07625 ui_out_text (uiout, "fork"); 07626 if (!ptid_equal (c->forked_inferior_pid, null_ptid)) 07627 { 07628 ui_out_text (uiout, ", process "); 07629 ui_out_field_int (uiout, "what", 07630 ptid_get_pid (c->forked_inferior_pid)); 07631 ui_out_spaces (uiout, 1); 07632 } 07633 07634 if (ui_out_is_mi_like_p (uiout)) 07635 ui_out_field_string (uiout, "catch-type", "fork"); 07636 } 07637 07638 /* Implement the "print_mention" breakpoint_ops method for fork 07639 catchpoints. */ 07640 07641 static void 07642 print_mention_catch_fork (struct breakpoint *b) 07643 { 07644 printf_filtered (_("Catchpoint %d (fork)"), b->number); 07645 } 07646 07647 /* Implement the "print_recreate" breakpoint_ops method for fork 07648 catchpoints. */ 07649 07650 static void 07651 print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) 07652 { 07653 fprintf_unfiltered (fp, "catch fork"); 07654 print_recreate_thread (b, fp); 07655 } 07656 07657 /* The breakpoint_ops structure to be used in fork catchpoints. */ 07658 07659 static struct breakpoint_ops catch_fork_breakpoint_ops; 07660 07661 /* Implement the "insert" breakpoint_ops method for vfork 07662 catchpoints. */ 07663 07664 static int 07665 insert_catch_vfork (struct bp_location *bl) 07666 { 07667 return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); 07668 } 07669 07670 /* Implement the "remove" breakpoint_ops method for vfork 07671 catchpoints. */ 07672 07673 static int 07674 remove_catch_vfork (struct bp_location *bl) 07675 { 07676 return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); 07677 } 07678 07679 /* Implement the "breakpoint_hit" breakpoint_ops method for vfork 07680 catchpoints. */ 07681 07682 static int 07683 breakpoint_hit_catch_vfork (const struct bp_location *bl, 07684 struct address_space *aspace, CORE_ADDR bp_addr, 07685 const struct target_waitstatus *ws) 07686 { 07687 struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; 07688 07689 if (ws->kind != TARGET_WAITKIND_VFORKED) 07690 return 0; 07691 07692 c->forked_inferior_pid = ws->value.related_pid; 07693 return 1; 07694 } 07695 07696 /* Implement the "print_it" breakpoint_ops method for vfork 07697 catchpoints. */ 07698 07699 static enum print_stop_action 07700 print_it_catch_vfork (bpstat bs) 07701 { 07702 struct ui_out *uiout = current_uiout; 07703 struct breakpoint *b = bs->breakpoint_at; 07704 struct fork_catchpoint *c = (struct fork_catchpoint *) b; 07705 07706 annotate_catchpoint (b->number); 07707 if (b->disposition == disp_del) 07708 ui_out_text (uiout, "\nTemporary catchpoint "); 07709 else 07710 ui_out_text (uiout, "\nCatchpoint "); 07711 if (ui_out_is_mi_like_p (uiout)) 07712 { 07713 ui_out_field_string (uiout, "reason", 07714 async_reason_lookup (EXEC_ASYNC_VFORK)); 07715 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 07716 } 07717 ui_out_field_int (uiout, "bkptno", b->number); 07718 ui_out_text (uiout, " (vforked process "); 07719 ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); 07720 ui_out_text (uiout, "), "); 07721 return PRINT_SRC_AND_LOC; 07722 } 07723 07724 /* Implement the "print_one" breakpoint_ops method for vfork 07725 catchpoints. */ 07726 07727 static void 07728 print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) 07729 { 07730 struct fork_catchpoint *c = (struct fork_catchpoint *) b; 07731 struct value_print_options opts; 07732 struct ui_out *uiout = current_uiout; 07733 07734 get_user_print_options (&opts); 07735 /* Field 4, the address, is omitted (which makes the columns not 07736 line up too nicely with the headers, but the effect is relatively 07737 readable). */ 07738 if (opts.addressprint) 07739 ui_out_field_skip (uiout, "addr"); 07740 annotate_field (5); 07741 ui_out_text (uiout, "vfork"); 07742 if (!ptid_equal (c->forked_inferior_pid, null_ptid)) 07743 { 07744 ui_out_text (uiout, ", process "); 07745 ui_out_field_int (uiout, "what", 07746 ptid_get_pid (c->forked_inferior_pid)); 07747 ui_out_spaces (uiout, 1); 07748 } 07749 07750 if (ui_out_is_mi_like_p (uiout)) 07751 ui_out_field_string (uiout, "catch-type", "vfork"); 07752 } 07753 07754 /* Implement the "print_mention" breakpoint_ops method for vfork 07755 catchpoints. */ 07756 07757 static void 07758 print_mention_catch_vfork (struct breakpoint *b) 07759 { 07760 printf_filtered (_("Catchpoint %d (vfork)"), b->number); 07761 } 07762 07763 /* Implement the "print_recreate" breakpoint_ops method for vfork 07764 catchpoints. */ 07765 07766 static void 07767 print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) 07768 { 07769 fprintf_unfiltered (fp, "catch vfork"); 07770 print_recreate_thread (b, fp); 07771 } 07772 07773 /* The breakpoint_ops structure to be used in vfork catchpoints. */ 07774 07775 static struct breakpoint_ops catch_vfork_breakpoint_ops; 07776 07777 /* An instance of this type is used to represent an solib catchpoint. 07778 It includes a "struct breakpoint" as a kind of base class; users 07779 downcast to "struct breakpoint *" when needed. A breakpoint is 07780 really of this type iff its ops pointer points to 07781 CATCH_SOLIB_BREAKPOINT_OPS. */ 07782 07783 struct solib_catchpoint 07784 { 07785 /* The base class. */ 07786 struct breakpoint base; 07787 07788 /* True for "catch load", false for "catch unload". */ 07789 unsigned char is_load; 07790 07791 /* Regular expression to match, if any. COMPILED is only valid when 07792 REGEX is non-NULL. */ 07793 char *regex; 07794 regex_t compiled; 07795 }; 07796 07797 static void 07798 dtor_catch_solib (struct breakpoint *b) 07799 { 07800 struct solib_catchpoint *self = (struct solib_catchpoint *) b; 07801 07802 if (self->regex) 07803 regfree (&self->compiled); 07804 xfree (self->regex); 07805 07806 base_breakpoint_ops.dtor (b); 07807 } 07808 07809 static int 07810 insert_catch_solib (struct bp_location *ignore) 07811 { 07812 return 0; 07813 } 07814 07815 static int 07816 remove_catch_solib (struct bp_location *ignore) 07817 { 07818 return 0; 07819 } 07820 07821 static int 07822 breakpoint_hit_catch_solib (const struct bp_location *bl, 07823 struct address_space *aspace, 07824 CORE_ADDR bp_addr, 07825 const struct target_waitstatus *ws) 07826 { 07827 struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; 07828 struct breakpoint *other; 07829 07830 if (ws->kind == TARGET_WAITKIND_LOADED) 07831 return 1; 07832 07833 ALL_BREAKPOINTS (other) 07834 { 07835 struct bp_location *other_bl; 07836 07837 if (other == bl->owner) 07838 continue; 07839 07840 if (other->type != bp_shlib_event) 07841 continue; 07842 07843 if (self->base.pspace != NULL && other->pspace != self->base.pspace) 07844 continue; 07845 07846 for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) 07847 { 07848 if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) 07849 return 1; 07850 } 07851 } 07852 07853 return 0; 07854 } 07855 07856 static void 07857 check_status_catch_solib (struct bpstats *bs) 07858 { 07859 struct solib_catchpoint *self 07860 = (struct solib_catchpoint *) bs->breakpoint_at; 07861 int ix; 07862 07863 if (self->is_load) 07864 { 07865 struct so_list *iter; 07866 07867 for (ix = 0; 07868 VEC_iterate (so_list_ptr, current_program_space->added_solibs, 07869 ix, iter); 07870 ++ix) 07871 { 07872 if (!self->regex 07873 || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) 07874 return; 07875 } 07876 } 07877 else 07878 { 07879 char *iter; 07880 07881 for (ix = 0; 07882 VEC_iterate (char_ptr, current_program_space->deleted_solibs, 07883 ix, iter); 07884 ++ix) 07885 { 07886 if (!self->regex 07887 || regexec (&self->compiled, iter, 0, NULL, 0) == 0) 07888 return; 07889 } 07890 } 07891 07892 bs->stop = 0; 07893 bs->print_it = print_it_noop; 07894 } 07895 07896 static enum print_stop_action 07897 print_it_catch_solib (bpstat bs) 07898 { 07899 struct breakpoint *b = bs->breakpoint_at; 07900 struct ui_out *uiout = current_uiout; 07901 07902 annotate_catchpoint (b->number); 07903 if (b->disposition == disp_del) 07904 ui_out_text (uiout, "\nTemporary catchpoint "); 07905 else 07906 ui_out_text (uiout, "\nCatchpoint "); 07907 ui_out_field_int (uiout, "bkptno", b->number); 07908 ui_out_text (uiout, "\n"); 07909 if (ui_out_is_mi_like_p (uiout)) 07910 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 07911 print_solib_event (1); 07912 return PRINT_SRC_AND_LOC; 07913 } 07914 07915 static void 07916 print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) 07917 { 07918 struct solib_catchpoint *self = (struct solib_catchpoint *) b; 07919 struct value_print_options opts; 07920 struct ui_out *uiout = current_uiout; 07921 char *msg; 07922 07923 get_user_print_options (&opts); 07924 /* Field 4, the address, is omitted (which makes the columns not 07925 line up too nicely with the headers, but the effect is relatively 07926 readable). */ 07927 if (opts.addressprint) 07928 { 07929 annotate_field (4); 07930 ui_out_field_skip (uiout, "addr"); 07931 } 07932 07933 annotate_field (5); 07934 if (self->is_load) 07935 { 07936 if (self->regex) 07937 msg = xstrprintf (_("load of library matching %s"), self->regex); 07938 else 07939 msg = xstrdup (_("load of library")); 07940 } 07941 else 07942 { 07943 if (self->regex) 07944 msg = xstrprintf (_("unload of library matching %s"), self->regex); 07945 else 07946 msg = xstrdup (_("unload of library")); 07947 } 07948 ui_out_field_string (uiout, "what", msg); 07949 xfree (msg); 07950 07951 if (ui_out_is_mi_like_p (uiout)) 07952 ui_out_field_string (uiout, "catch-type", 07953 self->is_load ? "load" : "unload"); 07954 } 07955 07956 static void 07957 print_mention_catch_solib (struct breakpoint *b) 07958 { 07959 struct solib_catchpoint *self = (struct solib_catchpoint *) b; 07960 07961 printf_filtered (_("Catchpoint %d (%s)"), b->number, 07962 self->is_load ? "load" : "unload"); 07963 } 07964 07965 static void 07966 print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) 07967 { 07968 struct solib_catchpoint *self = (struct solib_catchpoint *) b; 07969 07970 fprintf_unfiltered (fp, "%s %s", 07971 b->disposition == disp_del ? "tcatch" : "catch", 07972 self->is_load ? "load" : "unload"); 07973 if (self->regex) 07974 fprintf_unfiltered (fp, " %s", self->regex); 07975 fprintf_unfiltered (fp, "\n"); 07976 } 07977 07978 static struct breakpoint_ops catch_solib_breakpoint_ops; 07979 07980 /* Shared helper function (MI and CLI) for creating and installing 07981 a shared object event catchpoint. If IS_LOAD is non-zero then 07982 the events to be caught are load events, otherwise they are 07983 unload events. If IS_TEMP is non-zero the catchpoint is a 07984 temporary one. If ENABLED is non-zero the catchpoint is 07985 created in an enabled state. */ 07986 07987 void 07988 add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) 07989 { 07990 struct solib_catchpoint *c; 07991 struct gdbarch *gdbarch = get_current_arch (); 07992 struct cleanup *cleanup; 07993 07994 if (!arg) 07995 arg = ""; 07996 arg = skip_spaces (arg); 07997 07998 c = XCNEW (struct solib_catchpoint); 07999 cleanup = make_cleanup (xfree, c); 08000 08001 if (*arg != '\0') 08002 { 08003 int errcode; 08004 08005 errcode = regcomp (&c->compiled, arg, REG_NOSUB); 08006 if (errcode != 0) 08007 { 08008 char *err = get_regcomp_error (errcode, &c->compiled); 08009 08010 make_cleanup (xfree, err); 08011 error (_("Invalid regexp (%s): %s"), err, arg); 08012 } 08013 c->regex = xstrdup (arg); 08014 } 08015 08016 c->is_load = is_load; 08017 init_catchpoint (&c->base, gdbarch, is_temp, NULL, 08018 &catch_solib_breakpoint_ops); 08019 08020 c->base.enable_state = enabled ? bp_enabled : bp_disabled; 08021 08022 discard_cleanups (cleanup); 08023 install_breakpoint (0, &c->base, 1); 08024 } 08025 08026 /* A helper function that does all the work for "catch load" and 08027 "catch unload". */ 08028 08029 static void 08030 catch_load_or_unload (char *arg, int from_tty, int is_load, 08031 struct cmd_list_element *command) 08032 { 08033 int tempflag; 08034 const int enabled = 1; 08035 08036 tempflag = get_cmd_context (command) == CATCH_TEMPORARY; 08037 08038 add_solib_catchpoint (arg, is_load, tempflag, enabled); 08039 } 08040 08041 static void 08042 catch_load_command_1 (char *arg, int from_tty, 08043 struct cmd_list_element *command) 08044 { 08045 catch_load_or_unload (arg, from_tty, 1, command); 08046 } 08047 08048 static void 08049 catch_unload_command_1 (char *arg, int from_tty, 08050 struct cmd_list_element *command) 08051 { 08052 catch_load_or_unload (arg, from_tty, 0, command); 08053 } 08054 08055 /* An instance of this type is used to represent a syscall catchpoint. 08056 It includes a "struct breakpoint" as a kind of base class; users 08057 downcast to "struct breakpoint *" when needed. A breakpoint is 08058 really of this type iff its ops pointer points to 08059 CATCH_SYSCALL_BREAKPOINT_OPS. */ 08060 08061 struct syscall_catchpoint 08062 { 08063 /* The base class. */ 08064 struct breakpoint base; 08065 08066 /* Syscall numbers used for the 'catch syscall' feature. If no 08067 syscall has been specified for filtering, its value is NULL. 08068 Otherwise, it holds a list of all syscalls to be caught. The 08069 list elements are allocated with xmalloc. */ 08070 VEC(int) *syscalls_to_be_caught; 08071 }; 08072 08073 /* Implement the "dtor" breakpoint_ops method for syscall 08074 catchpoints. */ 08075 08076 static void 08077 dtor_catch_syscall (struct breakpoint *b) 08078 { 08079 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; 08080 08081 VEC_free (int, c->syscalls_to_be_caught); 08082 08083 base_breakpoint_ops.dtor (b); 08084 } 08085 08086 static const struct inferior_data *catch_syscall_inferior_data = NULL; 08087 08088 struct catch_syscall_inferior_data 08089 { 08090 /* We keep a count of the number of times the user has requested a 08091 particular syscall to be tracked, and pass this information to the 08092 target. This lets capable targets implement filtering directly. */ 08093 08094 /* Number of times that "any" syscall is requested. */ 08095 int any_syscall_count; 08096 08097 /* Count of each system call. */ 08098 VEC(int) *syscalls_counts; 08099 08100 /* This counts all syscall catch requests, so we can readily determine 08101 if any catching is necessary. */ 08102 int total_syscalls_count; 08103 }; 08104 08105 static struct catch_syscall_inferior_data* 08106 get_catch_syscall_inferior_data (struct inferior *inf) 08107 { 08108 struct catch_syscall_inferior_data *inf_data; 08109 08110 inf_data = inferior_data (inf, catch_syscall_inferior_data); 08111 if (inf_data == NULL) 08112 { 08113 inf_data = XZALLOC (struct catch_syscall_inferior_data); 08114 set_inferior_data (inf, catch_syscall_inferior_data, inf_data); 08115 } 08116 08117 return inf_data; 08118 } 08119 08120 static void 08121 catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) 08122 { 08123 xfree (arg); 08124 } 08125 08126 08127 /* Implement the "insert" breakpoint_ops method for syscall 08128 catchpoints. */ 08129 08130 static int 08131 insert_catch_syscall (struct bp_location *bl) 08132 { 08133 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; 08134 struct inferior *inf = current_inferior (); 08135 struct catch_syscall_inferior_data *inf_data 08136 = get_catch_syscall_inferior_data (inf); 08137 08138 ++inf_data->total_syscalls_count; 08139 if (!c->syscalls_to_be_caught) 08140 ++inf_data->any_syscall_count; 08141 else 08142 { 08143 int i, iter; 08144 08145 for (i = 0; 08146 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 08147 i++) 08148 { 08149 int elem; 08150 08151 if (iter >= VEC_length (int, inf_data->syscalls_counts)) 08152 { 08153 int old_size = VEC_length (int, inf_data->syscalls_counts); 08154 uintptr_t vec_addr_offset 08155 = old_size * ((uintptr_t) sizeof (int)); 08156 uintptr_t vec_addr; 08157 VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); 08158 vec_addr = ((uintptr_t) VEC_address (int, 08159 inf_data->syscalls_counts) 08160 + vec_addr_offset); 08161 memset ((void *) vec_addr, 0, 08162 (iter + 1 - old_size) * sizeof (int)); 08163 } 08164 elem = VEC_index (int, inf_data->syscalls_counts, iter); 08165 VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); 08166 } 08167 } 08168 08169 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), 08170 inf_data->total_syscalls_count != 0, 08171 inf_data->any_syscall_count, 08172 VEC_length (int, 08173 inf_data->syscalls_counts), 08174 VEC_address (int, 08175 inf_data->syscalls_counts)); 08176 } 08177 08178 /* Implement the "remove" breakpoint_ops method for syscall 08179 catchpoints. */ 08180 08181 static int 08182 remove_catch_syscall (struct bp_location *bl) 08183 { 08184 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; 08185 struct inferior *inf = current_inferior (); 08186 struct catch_syscall_inferior_data *inf_data 08187 = get_catch_syscall_inferior_data (inf); 08188 08189 --inf_data->total_syscalls_count; 08190 if (!c->syscalls_to_be_caught) 08191 --inf_data->any_syscall_count; 08192 else 08193 { 08194 int i, iter; 08195 08196 for (i = 0; 08197 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 08198 i++) 08199 { 08200 int elem; 08201 if (iter >= VEC_length (int, inf_data->syscalls_counts)) 08202 /* Shouldn't happen. */ 08203 continue; 08204 elem = VEC_index (int, inf_data->syscalls_counts, iter); 08205 VEC_replace (int, inf_data->syscalls_counts, iter, --elem); 08206 } 08207 } 08208 08209 return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), 08210 inf_data->total_syscalls_count != 0, 08211 inf_data->any_syscall_count, 08212 VEC_length (int, 08213 inf_data->syscalls_counts), 08214 VEC_address (int, 08215 inf_data->syscalls_counts)); 08216 } 08217 08218 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall 08219 catchpoints. */ 08220 08221 static int 08222 breakpoint_hit_catch_syscall (const struct bp_location *bl, 08223 struct address_space *aspace, CORE_ADDR bp_addr, 08224 const struct target_waitstatus *ws) 08225 { 08226 /* We must check if we are catching specific syscalls in this 08227 breakpoint. If we are, then we must guarantee that the called 08228 syscall is the same syscall we are catching. */ 08229 int syscall_number = 0; 08230 const struct syscall_catchpoint *c 08231 = (const struct syscall_catchpoint *) bl->owner; 08232 08233 if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY 08234 && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) 08235 return 0; 08236 08237 syscall_number = ws->value.syscall_number; 08238 08239 /* Now, checking if the syscall is the same. */ 08240 if (c->syscalls_to_be_caught) 08241 { 08242 int i, iter; 08243 08244 for (i = 0; 08245 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 08246 i++) 08247 if (syscall_number == iter) 08248 break; 08249 /* Not the same. */ 08250 if (!iter) 08251 return 0; 08252 } 08253 08254 return 1; 08255 } 08256 08257 /* Implement the "print_it" breakpoint_ops method for syscall 08258 catchpoints. */ 08259 08260 static enum print_stop_action 08261 print_it_catch_syscall (bpstat bs) 08262 { 08263 struct ui_out *uiout = current_uiout; 08264 struct breakpoint *b = bs->breakpoint_at; 08265 /* These are needed because we want to know in which state a 08266 syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY 08267 or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we 08268 must print "called syscall" or "returned from syscall". */ 08269 ptid_t ptid; 08270 struct target_waitstatus last; 08271 struct syscall s; 08272 08273 get_last_target_status (&ptid, &last); 08274 08275 get_syscall_by_number (last.value.syscall_number, &s); 08276 08277 annotate_catchpoint (b->number); 08278 08279 if (b->disposition == disp_del) 08280 ui_out_text (uiout, "\nTemporary catchpoint "); 08281 else 08282 ui_out_text (uiout, "\nCatchpoint "); 08283 if (ui_out_is_mi_like_p (uiout)) 08284 { 08285 ui_out_field_string (uiout, "reason", 08286 async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY 08287 ? EXEC_ASYNC_SYSCALL_ENTRY 08288 : EXEC_ASYNC_SYSCALL_RETURN)); 08289 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 08290 } 08291 ui_out_field_int (uiout, "bkptno", b->number); 08292 08293 if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) 08294 ui_out_text (uiout, " (call to syscall "); 08295 else 08296 ui_out_text (uiout, " (returned from syscall "); 08297 08298 if (s.name == NULL || ui_out_is_mi_like_p (uiout)) 08299 ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); 08300 if (s.name != NULL) 08301 ui_out_field_string (uiout, "syscall-name", s.name); 08302 08303 ui_out_text (uiout, "), "); 08304 08305 return PRINT_SRC_AND_LOC; 08306 } 08307 08308 /* Implement the "print_one" breakpoint_ops method for syscall 08309 catchpoints. */ 08310 08311 static void 08312 print_one_catch_syscall (struct breakpoint *b, 08313 struct bp_location **last_loc) 08314 { 08315 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; 08316 struct value_print_options opts; 08317 struct ui_out *uiout = current_uiout; 08318 08319 get_user_print_options (&opts); 08320 /* Field 4, the address, is omitted (which makes the columns not 08321 line up too nicely with the headers, but the effect is relatively 08322 readable). */ 08323 if (opts.addressprint) 08324 ui_out_field_skip (uiout, "addr"); 08325 annotate_field (5); 08326 08327 if (c->syscalls_to_be_caught 08328 && VEC_length (int, c->syscalls_to_be_caught) > 1) 08329 ui_out_text (uiout, "syscalls \""); 08330 else 08331 ui_out_text (uiout, "syscall \""); 08332 08333 if (c->syscalls_to_be_caught) 08334 { 08335 int i, iter; 08336 char *text = xstrprintf ("%s", ""); 08337 08338 for (i = 0; 08339 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 08340 i++) 08341 { 08342 char *x = text; 08343 struct syscall s; 08344 get_syscall_by_number (iter, &s); 08345 08346 if (s.name != NULL) 08347 text = xstrprintf ("%s%s, ", text, s.name); 08348 else 08349 text = xstrprintf ("%s%d, ", text, iter); 08350 08351 /* We have to xfree the last 'text' (now stored at 'x') 08352 because xstrprintf dynamically allocates new space for it 08353 on every call. */ 08354 xfree (x); 08355 } 08356 /* Remove the last comma. */ 08357 text[strlen (text) - 2] = '\0'; 08358 ui_out_field_string (uiout, "what", text); 08359 } 08360 else 08361 ui_out_field_string (uiout, "what", "<any syscall>"); 08362 ui_out_text (uiout, "\" "); 08363 08364 if (ui_out_is_mi_like_p (uiout)) 08365 ui_out_field_string (uiout, "catch-type", "syscall"); 08366 } 08367 08368 /* Implement the "print_mention" breakpoint_ops method for syscall 08369 catchpoints. */ 08370 08371 static void 08372 print_mention_catch_syscall (struct breakpoint *b) 08373 { 08374 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; 08375 08376 if (c->syscalls_to_be_caught) 08377 { 08378 int i, iter; 08379 08380 if (VEC_length (int, c->syscalls_to_be_caught) > 1) 08381 printf_filtered (_("Catchpoint %d (syscalls"), b->number); 08382 else 08383 printf_filtered (_("Catchpoint %d (syscall"), b->number); 08384 08385 for (i = 0; 08386 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 08387 i++) 08388 { 08389 struct syscall s; 08390 get_syscall_by_number (iter, &s); 08391 08392 if (s.name) 08393 printf_filtered (" '%s' [%d]", s.name, s.number); 08394 else 08395 printf_filtered (" %d", s.number); 08396 } 08397 printf_filtered (")"); 08398 } 08399 else 08400 printf_filtered (_("Catchpoint %d (any syscall)"), 08401 b->number); 08402 } 08403 08404 /* Implement the "print_recreate" breakpoint_ops method for syscall 08405 catchpoints. */ 08406 08407 static void 08408 print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) 08409 { 08410 struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; 08411 08412 fprintf_unfiltered (fp, "catch syscall"); 08413 08414 if (c->syscalls_to_be_caught) 08415 { 08416 int i, iter; 08417 08418 for (i = 0; 08419 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 08420 i++) 08421 { 08422 struct syscall s; 08423 08424 get_syscall_by_number (iter, &s); 08425 if (s.name) 08426 fprintf_unfiltered (fp, " %s", s.name); 08427 else 08428 fprintf_unfiltered (fp, " %d", s.number); 08429 } 08430 } 08431 print_recreate_thread (b, fp); 08432 } 08433 08434 /* The breakpoint_ops structure to be used in syscall catchpoints. */ 08435 08436 static struct breakpoint_ops catch_syscall_breakpoint_ops; 08437 08438 /* Returns non-zero if 'b' is a syscall catchpoint. */ 08439 08440 static int 08441 syscall_catchpoint_p (struct breakpoint *b) 08442 { 08443 return (b->ops == &catch_syscall_breakpoint_ops); 08444 } 08445 08446 /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG 08447 is non-zero, then make the breakpoint temporary. If COND_STRING is 08448 not NULL, then store it in the breakpoint. OPS, if not NULL, is 08449 the breakpoint_ops structure associated to the catchpoint. */ 08450 08451 void 08452 init_catchpoint (struct breakpoint *b, 08453 struct gdbarch *gdbarch, int tempflag, 08454 char *cond_string, 08455 const struct breakpoint_ops *ops) 08456 { 08457 struct symtab_and_line sal; 08458 08459 init_sal (&sal); 08460 sal.pspace = current_program_space; 08461 08462 init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); 08463 08464 b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); 08465 b->disposition = tempflag ? disp_del : disp_donttouch; 08466 } 08467 08468 void 08469 install_breakpoint (int internal, struct breakpoint *b, int update_gll) 08470 { 08471 add_to_breakpoint_chain (b); 08472 set_breakpoint_number (internal, b); 08473 if (is_tracepoint (b)) 08474 set_tracepoint_count (breakpoint_count); 08475 if (!internal) 08476 mention (b); 08477 observer_notify_breakpoint_created (b); 08478 08479 if (update_gll) 08480 update_global_location_list (1); 08481 } 08482 08483 static void 08484 create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, 08485 int tempflag, char *cond_string, 08486 const struct breakpoint_ops *ops) 08487 { 08488 struct fork_catchpoint *c = XNEW (struct fork_catchpoint); 08489 08490 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); 08491 08492 c->forked_inferior_pid = null_ptid; 08493 08494 install_breakpoint (0, &c->base, 1); 08495 } 08496 08497 /* Exec catchpoints. */ 08498 08499 /* An instance of this type is used to represent an exec catchpoint. 08500 It includes a "struct breakpoint" as a kind of base class; users 08501 downcast to "struct breakpoint *" when needed. A breakpoint is 08502 really of this type iff its ops pointer points to 08503 CATCH_EXEC_BREAKPOINT_OPS. */ 08504 08505 struct exec_catchpoint 08506 { 08507 /* The base class. */ 08508 struct breakpoint base; 08509 08510 /* Filename of a program whose exec triggered this catchpoint. 08511 This field is only valid immediately after this catchpoint has 08512 triggered. */ 08513 char *exec_pathname; 08514 }; 08515 08516 /* Implement the "dtor" breakpoint_ops method for exec 08517 catchpoints. */ 08518 08519 static void 08520 dtor_catch_exec (struct breakpoint *b) 08521 { 08522 struct exec_catchpoint *c = (struct exec_catchpoint *) b; 08523 08524 xfree (c->exec_pathname); 08525 08526 base_breakpoint_ops.dtor (b); 08527 } 08528 08529 static int 08530 insert_catch_exec (struct bp_location *bl) 08531 { 08532 return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); 08533 } 08534 08535 static int 08536 remove_catch_exec (struct bp_location *bl) 08537 { 08538 return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); 08539 } 08540 08541 static int 08542 breakpoint_hit_catch_exec (const struct bp_location *bl, 08543 struct address_space *aspace, CORE_ADDR bp_addr, 08544 const struct target_waitstatus *ws) 08545 { 08546 struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; 08547 08548 if (ws->kind != TARGET_WAITKIND_EXECD) 08549 return 0; 08550 08551 c->exec_pathname = xstrdup (ws->value.execd_pathname); 08552 return 1; 08553 } 08554 08555 static enum print_stop_action 08556 print_it_catch_exec (bpstat bs) 08557 { 08558 struct ui_out *uiout = current_uiout; 08559 struct breakpoint *b = bs->breakpoint_at; 08560 struct exec_catchpoint *c = (struct exec_catchpoint *) b; 08561 08562 annotate_catchpoint (b->number); 08563 if (b->disposition == disp_del) 08564 ui_out_text (uiout, "\nTemporary catchpoint "); 08565 else 08566 ui_out_text (uiout, "\nCatchpoint "); 08567 if (ui_out_is_mi_like_p (uiout)) 08568 { 08569 ui_out_field_string (uiout, "reason", 08570 async_reason_lookup (EXEC_ASYNC_EXEC)); 08571 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 08572 } 08573 ui_out_field_int (uiout, "bkptno", b->number); 08574 ui_out_text (uiout, " (exec'd "); 08575 ui_out_field_string (uiout, "new-exec", c->exec_pathname); 08576 ui_out_text (uiout, "), "); 08577 08578 return PRINT_SRC_AND_LOC; 08579 } 08580 08581 static void 08582 print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) 08583 { 08584 struct exec_catchpoint *c = (struct exec_catchpoint *) b; 08585 struct value_print_options opts; 08586 struct ui_out *uiout = current_uiout; 08587 08588 get_user_print_options (&opts); 08589 08590 /* Field 4, the address, is omitted (which makes the columns 08591 not line up too nicely with the headers, but the effect 08592 is relatively readable). */ 08593 if (opts.addressprint) 08594 ui_out_field_skip (uiout, "addr"); 08595 annotate_field (5); 08596 ui_out_text (uiout, "exec"); 08597 if (c->exec_pathname != NULL) 08598 { 08599 ui_out_text (uiout, ", program \""); 08600 ui_out_field_string (uiout, "what", c->exec_pathname); 08601 ui_out_text (uiout, "\" "); 08602 } 08603 08604 if (ui_out_is_mi_like_p (uiout)) 08605 ui_out_field_string (uiout, "catch-type", "exec"); 08606 } 08607 08608 static void 08609 print_mention_catch_exec (struct breakpoint *b) 08610 { 08611 printf_filtered (_("Catchpoint %d (exec)"), b->number); 08612 } 08613 08614 /* Implement the "print_recreate" breakpoint_ops method for exec 08615 catchpoints. */ 08616 08617 static void 08618 print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) 08619 { 08620 fprintf_unfiltered (fp, "catch exec"); 08621 print_recreate_thread (b, fp); 08622 } 08623 08624 static struct breakpoint_ops catch_exec_breakpoint_ops; 08625 08626 static void 08627 create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, 08628 const struct breakpoint_ops *ops) 08629 { 08630 struct syscall_catchpoint *c; 08631 struct gdbarch *gdbarch = get_current_arch (); 08632 08633 c = XNEW (struct syscall_catchpoint); 08634 init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); 08635 c->syscalls_to_be_caught = filter; 08636 08637 install_breakpoint (0, &c->base, 1); 08638 } 08639 08640 static int 08641 hw_breakpoint_used_count (void) 08642 { 08643 int i = 0; 08644 struct breakpoint *b; 08645 struct bp_location *bl; 08646 08647 ALL_BREAKPOINTS (b) 08648 { 08649 if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) 08650 for (bl = b->loc; bl; bl = bl->next) 08651 { 08652 /* Special types of hardware breakpoints may use more than 08653 one register. */ 08654 i += b->ops->resources_needed (bl); 08655 } 08656 } 08657 08658 return i; 08659 } 08660 08661 /* Returns the resources B would use if it were a hardware 08662 watchpoint. */ 08663 08664 static int 08665 hw_watchpoint_use_count (struct breakpoint *b) 08666 { 08667 int i = 0; 08668 struct bp_location *bl; 08669 08670 if (!breakpoint_enabled (b)) 08671 return 0; 08672 08673 for (bl = b->loc; bl; bl = bl->next) 08674 { 08675 /* Special types of hardware watchpoints may use more than 08676 one register. */ 08677 i += b->ops->resources_needed (bl); 08678 } 08679 08680 return i; 08681 } 08682 08683 /* Returns the sum the used resources of all hardware watchpoints of 08684 type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED 08685 the sum of the used resources of all hardware watchpoints of other 08686 types _not_ TYPE. */ 08687 08688 static int 08689 hw_watchpoint_used_count_others (struct breakpoint *except, 08690 enum bptype type, int *other_type_used) 08691 { 08692 int i = 0; 08693 struct breakpoint *b; 08694 08695 *other_type_used = 0; 08696 ALL_BREAKPOINTS (b) 08697 { 08698 if (b == except) 08699 continue; 08700 if (!breakpoint_enabled (b)) 08701 continue; 08702 08703 if (b->type == type) 08704 i += hw_watchpoint_use_count (b); 08705 else if (is_hardware_watchpoint (b)) 08706 *other_type_used = 1; 08707 } 08708 08709 return i; 08710 } 08711 08712 void 08713 disable_watchpoints_before_interactive_call_start (void) 08714 { 08715 struct breakpoint *b; 08716 08717 ALL_BREAKPOINTS (b) 08718 { 08719 if (is_watchpoint (b) && breakpoint_enabled (b)) 08720 { 08721 b->enable_state = bp_call_disabled; 08722 update_global_location_list (0); 08723 } 08724 } 08725 } 08726 08727 void 08728 enable_watchpoints_after_interactive_call_stop (void) 08729 { 08730 struct breakpoint *b; 08731 08732 ALL_BREAKPOINTS (b) 08733 { 08734 if (is_watchpoint (b) && b->enable_state == bp_call_disabled) 08735 { 08736 b->enable_state = bp_enabled; 08737 update_global_location_list (1); 08738 } 08739 } 08740 } 08741 08742 void 08743 disable_breakpoints_before_startup (void) 08744 { 08745 current_program_space->executing_startup = 1; 08746 update_global_location_list (0); 08747 } 08748 08749 void 08750 enable_breakpoints_after_startup (void) 08751 { 08752 current_program_space->executing_startup = 0; 08753 breakpoint_re_set (); 08754 } 08755 08756 08757 /* Set a breakpoint that will evaporate an end of command 08758 at address specified by SAL. 08759 Restrict it to frame FRAME if FRAME is nonzero. */ 08760 08761 struct breakpoint * 08762 set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, 08763 struct frame_id frame_id, enum bptype type) 08764 { 08765 struct breakpoint *b; 08766 08767 /* If FRAME_ID is valid, it should be a real frame, not an inlined or 08768 tail-called one. */ 08769 gdb_assert (!frame_id_artificial_p (frame_id)); 08770 08771 b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); 08772 b->enable_state = bp_enabled; 08773 b->disposition = disp_donttouch; 08774 b->frame_id = frame_id; 08775 08776 /* If we're debugging a multi-threaded program, then we want 08777 momentary breakpoints to be active in only a single thread of 08778 control. */ 08779 if (in_thread_list (inferior_ptid)) 08780 b->thread = pid_to_thread_id (inferior_ptid); 08781 08782 update_global_location_list_nothrow (1); 08783 08784 return b; 08785 } 08786 08787 /* Make a momentary breakpoint based on the master breakpoint ORIG. 08788 The new breakpoint will have type TYPE, and use OPS as it 08789 breakpoint_ops. */ 08790 08791 static struct breakpoint * 08792 momentary_breakpoint_from_master (struct breakpoint *orig, 08793 enum bptype type, 08794 const struct breakpoint_ops *ops) 08795 { 08796 struct breakpoint *copy; 08797 08798 copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); 08799 copy->loc = allocate_bp_location (copy); 08800 set_breakpoint_location_function (copy->loc, 1); 08801 08802 copy->loc->gdbarch = orig->loc->gdbarch; 08803 copy->loc->requested_address = orig->loc->requested_address; 08804 copy->loc->address = orig->loc->address; 08805 copy->loc->section = orig->loc->section; 08806 copy->loc->pspace = orig->loc->pspace; 08807 copy->loc->probe = orig->loc->probe; 08808 copy->loc->line_number = orig->loc->line_number; 08809 copy->loc->symtab = orig->loc->symtab; 08810 copy->frame_id = orig->frame_id; 08811 copy->thread = orig->thread; 08812 copy->pspace = orig->pspace; 08813 08814 copy->enable_state = bp_enabled; 08815 copy->disposition = disp_donttouch; 08816 copy->number = internal_breakpoint_number--; 08817 08818 update_global_location_list_nothrow (0); 08819 return copy; 08820 } 08821 08822 /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if 08823 ORIG is NULL. */ 08824 08825 struct breakpoint * 08826 clone_momentary_breakpoint (struct breakpoint *orig) 08827 { 08828 /* If there's nothing to clone, then return nothing. */ 08829 if (orig == NULL) 08830 return NULL; 08831 08832 return momentary_breakpoint_from_master (orig, orig->type, orig->ops); 08833 } 08834 08835 struct breakpoint * 08836 set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, 08837 enum bptype type) 08838 { 08839 struct symtab_and_line sal; 08840 08841 sal = find_pc_line (pc, 0); 08842 sal.pc = pc; 08843 sal.section = find_pc_overlay (pc); 08844 sal.explicit_pc = 1; 08845 08846 return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); 08847 } 08848 08849 08850 /* Tell the user we have just set a breakpoint B. */ 08851 08852 static void 08853 mention (struct breakpoint *b) 08854 { 08855 b->ops->print_mention (b); 08856 if (ui_out_is_mi_like_p (current_uiout)) 08857 return; 08858 printf_filtered ("\n"); 08859 } 08860 08861 08862 static struct bp_location * 08863 add_location_to_breakpoint (struct breakpoint *b, 08864 const struct symtab_and_line *sal) 08865 { 08866 struct bp_location *loc, **tmp; 08867 CORE_ADDR adjusted_address; 08868 struct gdbarch *loc_gdbarch = get_sal_arch (*sal); 08869 08870 if (loc_gdbarch == NULL) 08871 loc_gdbarch = b->gdbarch; 08872 08873 /* Adjust the breakpoint's address prior to allocating a location. 08874 Once we call allocate_bp_location(), that mostly uninitialized 08875 location will be placed on the location chain. Adjustment of the 08876 breakpoint may cause target_read_memory() to be called and we do 08877 not want its scan of the location chain to find a breakpoint and 08878 location that's only been partially initialized. */ 08879 adjusted_address = adjust_breakpoint_address (loc_gdbarch, 08880 sal->pc, b->type); 08881 08882 /* Sort the locations by their ADDRESS. */ 08883 loc = allocate_bp_location (b); 08884 for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; 08885 tmp = &((*tmp)->next)) 08886 ; 08887 loc->next = *tmp; 08888 *tmp = loc; 08889 08890 loc->requested_address = sal->pc; 08891 loc->address = adjusted_address; 08892 loc->pspace = sal->pspace; 08893 loc->probe = sal->probe; 08894 gdb_assert (loc->pspace != NULL); 08895 loc->section = sal->section; 08896 loc->gdbarch = loc_gdbarch; 08897 loc->line_number = sal->line; 08898 loc->symtab = sal->symtab; 08899 08900 set_breakpoint_location_function (loc, 08901 sal->explicit_pc || sal->explicit_line); 08902 return loc; 08903 } 08904 08905 08906 /* Return 1 if LOC is pointing to a permanent breakpoint, 08907 return 0 otherwise. */ 08908 08909 static int 08910 bp_loc_is_permanent (struct bp_location *loc) 08911 { 08912 int len; 08913 CORE_ADDR addr; 08914 const gdb_byte *bpoint; 08915 gdb_byte *target_mem; 08916 struct cleanup *cleanup; 08917 int retval = 0; 08918 08919 gdb_assert (loc != NULL); 08920 08921 addr = loc->address; 08922 bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); 08923 08924 /* Software breakpoints unsupported? */ 08925 if (bpoint == NULL) 08926 return 0; 08927 08928 target_mem = alloca (len); 08929 08930 /* Enable the automatic memory restoration from breakpoints while 08931 we read the memory. Otherwise we could say about our temporary 08932 breakpoints they are permanent. */ 08933 cleanup = save_current_space_and_thread (); 08934 08935 switch_to_program_space_and_thread (loc->pspace); 08936 make_show_memory_breakpoints_cleanup (0); 08937 08938 if (target_read_memory (loc->address, target_mem, len) == 0 08939 && memcmp (target_mem, bpoint, len) == 0) 08940 retval = 1; 08941 08942 do_cleanups (cleanup); 08943 08944 return retval; 08945 } 08946 08947 /* Build a command list for the dprintf corresponding to the current 08948 settings of the dprintf style options. */ 08949 08950 static void 08951 update_dprintf_command_list (struct breakpoint *b) 08952 { 08953 char *dprintf_args = b->extra_string; 08954 char *printf_line = NULL; 08955 08956 if (!dprintf_args) 08957 return; 08958 08959 dprintf_args = skip_spaces (dprintf_args); 08960 08961 /* Allow a comma, as it may have terminated a location, but don't 08962 insist on it. */ 08963 if (*dprintf_args == ',') 08964 ++dprintf_args; 08965 dprintf_args = skip_spaces (dprintf_args); 08966 08967 if (*dprintf_args != '"') 08968 error (_("Bad format string, missing '\"'.")); 08969 08970 if (strcmp (dprintf_style, dprintf_style_gdb) == 0) 08971 printf_line = xstrprintf ("printf %s", dprintf_args); 08972 else if (strcmp (dprintf_style, dprintf_style_call) == 0) 08973 { 08974 if (!dprintf_function) 08975 error (_("No function supplied for dprintf call")); 08976 08977 if (dprintf_channel && strlen (dprintf_channel) > 0) 08978 printf_line = xstrprintf ("call (void) %s (%s,%s)", 08979 dprintf_function, 08980 dprintf_channel, 08981 dprintf_args); 08982 else 08983 printf_line = xstrprintf ("call (void) %s (%s)", 08984 dprintf_function, 08985 dprintf_args); 08986 } 08987 else if (strcmp (dprintf_style, dprintf_style_agent) == 0) 08988 { 08989 if (target_can_run_breakpoint_commands ()) 08990 printf_line = xstrprintf ("agent-printf %s", dprintf_args); 08991 else 08992 { 08993 warning (_("Target cannot run dprintf commands, falling back to GDB printf")); 08994 printf_line = xstrprintf ("printf %s", dprintf_args); 08995 } 08996 } 08997 else 08998 internal_error (__FILE__, __LINE__, 08999 _("Invalid dprintf style.")); 09000 09001 gdb_assert (printf_line != NULL); 09002 /* Manufacture a printf sequence. */ 09003 { 09004 struct command_line *printf_cmd_line 09005 = xmalloc (sizeof (struct command_line)); 09006 09007 printf_cmd_line = xmalloc (sizeof (struct command_line)); 09008 printf_cmd_line->control_type = simple_control; 09009 printf_cmd_line->body_count = 0; 09010 printf_cmd_line->body_list = NULL; 09011 printf_cmd_line->next = NULL; 09012 printf_cmd_line->line = printf_line; 09013 09014 breakpoint_set_commands (b, printf_cmd_line); 09015 } 09016 } 09017 09018 /* Update all dprintf commands, making their command lists reflect 09019 current style settings. */ 09020 09021 static void 09022 update_dprintf_commands (char *args, int from_tty, 09023 struct cmd_list_element *c) 09024 { 09025 struct breakpoint *b; 09026 09027 ALL_BREAKPOINTS (b) 09028 { 09029 if (b->type == bp_dprintf) 09030 update_dprintf_command_list (b); 09031 } 09032 } 09033 09034 /* Create a breakpoint with SAL as location. Use ADDR_STRING 09035 as textual description of the location, and COND_STRING 09036 as condition expression. */ 09037 09038 static void 09039 init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, 09040 struct symtabs_and_lines sals, char *addr_string, 09041 char *filter, char *cond_string, 09042 char *extra_string, 09043 enum bptype type, enum bpdisp disposition, 09044 int thread, int task, int ignore_count, 09045 const struct breakpoint_ops *ops, int from_tty, 09046 int enabled, int internal, unsigned flags, 09047 int display_canonical) 09048 { 09049 int i; 09050 09051 if (type == bp_hardware_breakpoint) 09052 { 09053 int target_resources_ok; 09054 09055 i = hw_breakpoint_used_count (); 09056 target_resources_ok = 09057 target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 09058 i + 1, 0); 09059 if (target_resources_ok == 0) 09060 error (_("No hardware breakpoint support in the target.")); 09061 else if (target_resources_ok < 0) 09062 error (_("Hardware breakpoints used exceeds limit.")); 09063 } 09064 09065 gdb_assert (sals.nelts > 0); 09066 09067 for (i = 0; i < sals.nelts; ++i) 09068 { 09069 struct symtab_and_line sal = sals.sals[i]; 09070 struct bp_location *loc; 09071 09072 if (from_tty) 09073 { 09074 struct gdbarch *loc_gdbarch = get_sal_arch (sal); 09075 if (!loc_gdbarch) 09076 loc_gdbarch = gdbarch; 09077 09078 describe_other_breakpoints (loc_gdbarch, 09079 sal.pspace, sal.pc, sal.section, thread); 09080 } 09081 09082 if (i == 0) 09083 { 09084 init_raw_breakpoint (b, gdbarch, sal, type, ops); 09085 b->thread = thread; 09086 b->task = task; 09087 09088 b->cond_string = cond_string; 09089 b->extra_string = extra_string; 09090 b->ignore_count = ignore_count; 09091 b->enable_state = enabled ? bp_enabled : bp_disabled; 09092 b->disposition = disposition; 09093 09094 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) 09095 b->loc->inserted = 1; 09096 09097 if (type == bp_static_tracepoint) 09098 { 09099 struct tracepoint *t = (struct tracepoint *) b; 09100 struct static_tracepoint_marker marker; 09101 09102 if (strace_marker_p (b)) 09103 { 09104 /* We already know the marker exists, otherwise, we 09105 wouldn't see a sal for it. */ 09106 char *p = &addr_string[3]; 09107 char *endp; 09108 char *marker_str; 09109 09110 p = skip_spaces (p); 09111 09112 endp = skip_to_space (p); 09113 09114 marker_str = savestring (p, endp - p); 09115 t->static_trace_marker_id = marker_str; 09116 09117 printf_filtered (_("Probed static tracepoint " 09118 "marker \"%s\"\n"), 09119 t->static_trace_marker_id); 09120 } 09121 else if (target_static_tracepoint_marker_at (sal.pc, &marker)) 09122 { 09123 t->static_trace_marker_id = xstrdup (marker.str_id); 09124 release_static_tracepoint_marker (&marker); 09125 09126 printf_filtered (_("Probed static tracepoint " 09127 "marker \"%s\"\n"), 09128 t->static_trace_marker_id); 09129 } 09130 else 09131 warning (_("Couldn't determine the static " 09132 "tracepoint marker to probe")); 09133 } 09134 09135 loc = b->loc; 09136 } 09137 else 09138 { 09139 loc = add_location_to_breakpoint (b, &sal); 09140 if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) 09141 loc->inserted = 1; 09142 } 09143 09144 if (bp_loc_is_permanent (loc)) 09145 make_breakpoint_permanent (b); 09146 09147 if (b->cond_string) 09148 { 09149 const char *arg = b->cond_string; 09150 09151 loc->cond = parse_exp_1 (&arg, loc->address, 09152 block_for_pc (loc->address), 0); 09153 if (*arg) 09154 error (_("Garbage '%s' follows condition"), arg); 09155 } 09156 09157 /* Dynamic printf requires and uses additional arguments on the 09158 command line, otherwise it's an error. */ 09159 if (type == bp_dprintf) 09160 { 09161 if (b->extra_string) 09162 update_dprintf_command_list (b); 09163 else 09164 error (_("Format string required")); 09165 } 09166 else if (b->extra_string) 09167 error (_("Garbage '%s' at end of command"), b->extra_string); 09168 } 09169 09170 b->display_canonical = display_canonical; 09171 if (addr_string) 09172 b->addr_string = addr_string; 09173 else 09174 /* addr_string has to be used or breakpoint_re_set will delete 09175 me. */ 09176 b->addr_string 09177 = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); 09178 b->filter = filter; 09179 } 09180 09181 static void 09182 create_breakpoint_sal (struct gdbarch *gdbarch, 09183 struct symtabs_and_lines sals, char *addr_string, 09184 char *filter, char *cond_string, 09185 char *extra_string, 09186 enum bptype type, enum bpdisp disposition, 09187 int thread, int task, int ignore_count, 09188 const struct breakpoint_ops *ops, int from_tty, 09189 int enabled, int internal, unsigned flags, 09190 int display_canonical) 09191 { 09192 struct breakpoint *b; 09193 struct cleanup *old_chain; 09194 09195 if (is_tracepoint_type (type)) 09196 { 09197 struct tracepoint *t; 09198 09199 t = XCNEW (struct tracepoint); 09200 b = &t->base; 09201 } 09202 else 09203 b = XNEW (struct breakpoint); 09204 09205 old_chain = make_cleanup (xfree, b); 09206 09207 init_breakpoint_sal (b, gdbarch, 09208 sals, addr_string, 09209 filter, cond_string, extra_string, 09210 type, disposition, 09211 thread, task, ignore_count, 09212 ops, from_tty, 09213 enabled, internal, flags, 09214 display_canonical); 09215 discard_cleanups (old_chain); 09216 09217 install_breakpoint (internal, b, 0); 09218 } 09219 09220 /* Add SALS.nelts breakpoints to the breakpoint table. For each 09221 SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] 09222 value. COND_STRING, if not NULL, specified the condition to be 09223 used for all breakpoints. Essentially the only case where 09224 SALS.nelts is not 1 is when we set a breakpoint on an overloaded 09225 function. In that case, it's still not possible to specify 09226 separate conditions for different overloaded functions, so 09227 we take just a single condition string. 09228 09229 NOTE: If the function succeeds, the caller is expected to cleanup 09230 the arrays ADDR_STRING, COND_STRING, and SALS (but not the 09231 array contents). If the function fails (error() is called), the 09232 caller is expected to cleanups both the ADDR_STRING, COND_STRING, 09233 COND and SALS arrays and each of those arrays contents. */ 09234 09235 static void 09236 create_breakpoints_sal (struct gdbarch *gdbarch, 09237 struct linespec_result *canonical, 09238 char *cond_string, char *extra_string, 09239 enum bptype type, enum bpdisp disposition, 09240 int thread, int task, int ignore_count, 09241 const struct breakpoint_ops *ops, int from_tty, 09242 int enabled, int internal, unsigned flags) 09243 { 09244 int i; 09245 struct linespec_sals *lsal; 09246 09247 if (canonical->pre_expanded) 09248 gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); 09249 09250 for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) 09251 { 09252 /* Note that 'addr_string' can be NULL in the case of a plain 09253 'break', without arguments. */ 09254 char *addr_string = (canonical->addr_string 09255 ? xstrdup (canonical->addr_string) 09256 : NULL); 09257 char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; 09258 struct cleanup *inner = make_cleanup (xfree, addr_string); 09259 09260 make_cleanup (xfree, filter_string); 09261 create_breakpoint_sal (gdbarch, lsal->sals, 09262 addr_string, 09263 filter_string, 09264 cond_string, extra_string, 09265 type, disposition, 09266 thread, task, ignore_count, ops, 09267 from_tty, enabled, internal, flags, 09268 canonical->special_display); 09269 discard_cleanups (inner); 09270 } 09271 } 09272 09273 /* Parse ADDRESS which is assumed to be a SAL specification possibly 09274 followed by conditionals. On return, SALS contains an array of SAL 09275 addresses found. ADDR_STRING contains a vector of (canonical) 09276 address strings. ADDRESS points to the end of the SAL. 09277 09278 The array and the line spec strings are allocated on the heap, it is 09279 the caller's responsibility to free them. */ 09280 09281 static void 09282 parse_breakpoint_sals (char **address, 09283 struct linespec_result *canonical) 09284 { 09285 /* If no arg given, or if first arg is 'if ', use the default 09286 breakpoint. */ 09287 if ((*address) == NULL 09288 || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) 09289 { 09290 /* The last displayed codepoint, if it's valid, is our default breakpoint 09291 address. */ 09292 if (last_displayed_sal_is_valid ()) 09293 { 09294 struct linespec_sals lsal; 09295 struct symtab_and_line sal; 09296 CORE_ADDR pc; 09297 09298 init_sal (&sal); /* Initialize to zeroes. */ 09299 lsal.sals.sals = (struct symtab_and_line *) 09300 xmalloc (sizeof (struct symtab_and_line)); 09301 09302 /* Set sal's pspace, pc, symtab, and line to the values 09303 corresponding to the last call to print_frame_info. 09304 Be sure to reinitialize LINE with NOTCURRENT == 0 09305 as the breakpoint line number is inappropriate otherwise. 09306 find_pc_line would adjust PC, re-set it back. */ 09307 get_last_displayed_sal (&sal); 09308 pc = sal.pc; 09309 sal = find_pc_line (pc, 0); 09310 09311 /* "break" without arguments is equivalent to "break *PC" 09312 where PC is the last displayed codepoint's address. So 09313 make sure to set sal.explicit_pc to prevent GDB from 09314 trying to expand the list of sals to include all other 09315 instances with the same symtab and line. */ 09316 sal.pc = pc; 09317 sal.explicit_pc = 1; 09318 09319 lsal.sals.sals[0] = sal; 09320 lsal.sals.nelts = 1; 09321 lsal.canonical = NULL; 09322 09323 VEC_safe_push (linespec_sals, canonical->sals, &lsal); 09324 } 09325 else 09326 error (_("No default breakpoint address now.")); 09327 } 09328 else 09329 { 09330 struct symtab_and_line cursal = get_current_source_symtab_and_line (); 09331 09332 /* Force almost all breakpoints to be in terms of the 09333 current_source_symtab (which is decode_line_1's default). 09334 This should produce the results we want almost all of the 09335 time while leaving default_breakpoint_* alone. 09336 09337 ObjC: However, don't match an Objective-C method name which 09338 may have a '+' or '-' succeeded by a '['. */ 09339 if (last_displayed_sal_is_valid () 09340 && (!cursal.symtab 09341 || ((strchr ("+-", (*address)[0]) != NULL) 09342 && ((*address)[1] != '[')))) 09343 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, 09344 get_last_displayed_symtab (), 09345 get_last_displayed_line (), 09346 canonical, NULL, NULL); 09347 else 09348 decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, 09349 cursal.symtab, cursal.line, canonical, NULL, NULL); 09350 } 09351 } 09352 09353 09354 /* Convert each SAL into a real PC. Verify that the PC can be 09355 inserted as a breakpoint. If it can't throw an error. */ 09356 09357 static void 09358 breakpoint_sals_to_pc (struct symtabs_and_lines *sals) 09359 { 09360 int i; 09361 09362 for (i = 0; i < sals->nelts; i++) 09363 resolve_sal_pc (&sals->sals[i]); 09364 } 09365 09366 /* Fast tracepoints may have restrictions on valid locations. For 09367 instance, a fast tracepoint using a jump instead of a trap will 09368 likely have to overwrite more bytes than a trap would, and so can 09369 only be placed where the instruction is longer than the jump, or a 09370 multi-instruction sequence does not have a jump into the middle of 09371 it, etc. */ 09372 09373 static void 09374 check_fast_tracepoint_sals (struct gdbarch *gdbarch, 09375 struct symtabs_and_lines *sals) 09376 { 09377 int i, rslt; 09378 struct symtab_and_line *sal; 09379 char *msg; 09380 struct cleanup *old_chain; 09381 09382 for (i = 0; i < sals->nelts; i++) 09383 { 09384 struct gdbarch *sarch; 09385 09386 sal = &sals->sals[i]; 09387 09388 sarch = get_sal_arch (*sal); 09389 /* We fall back to GDBARCH if there is no architecture 09390 associated with SAL. */ 09391 if (sarch == NULL) 09392 sarch = gdbarch; 09393 rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, 09394 NULL, &msg); 09395 old_chain = make_cleanup (xfree, msg); 09396 09397 if (!rslt) 09398 error (_("May not have a fast tracepoint at 0x%s%s"), 09399 paddress (sarch, sal->pc), (msg ? msg : "")); 09400 09401 do_cleanups (old_chain); 09402 } 09403 } 09404 09405 /* Issue an invalid thread ID error. */ 09406 09407 static void ATTRIBUTE_NORETURN 09408 invalid_thread_id_error (int id) 09409 { 09410 error (_("Unknown thread %d."), id); 09411 } 09412 09413 /* Given TOK, a string specification of condition and thread, as 09414 accepted by the 'break' command, extract the condition 09415 string and thread number and set *COND_STRING and *THREAD. 09416 PC identifies the context at which the condition should be parsed. 09417 If no condition is found, *COND_STRING is set to NULL. 09418 If no thread is found, *THREAD is set to -1. */ 09419 09420 static void 09421 find_condition_and_thread (const char *tok, CORE_ADDR pc, 09422 char **cond_string, int *thread, int *task, 09423 char **rest) 09424 { 09425 *cond_string = NULL; 09426 *thread = -1; 09427 *task = 0; 09428 *rest = NULL; 09429 09430 while (tok && *tok) 09431 { 09432 const char *end_tok; 09433 int toklen; 09434 const char *cond_start = NULL; 09435 const char *cond_end = NULL; 09436 09437 tok = skip_spaces_const (tok); 09438 09439 if ((*tok == '"' || *tok == ',') && rest) 09440 { 09441 *rest = savestring (tok, strlen (tok)); 09442 return; 09443 } 09444 09445 end_tok = skip_to_space_const (tok); 09446 09447 toklen = end_tok - tok; 09448 09449 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) 09450 { 09451 struct expression *expr; 09452 09453 tok = cond_start = end_tok + 1; 09454 expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); 09455 xfree (expr); 09456 cond_end = tok; 09457 *cond_string = savestring (cond_start, cond_end - cond_start); 09458 } 09459 else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) 09460 { 09461 char *tmptok; 09462 09463 tok = end_tok + 1; 09464 *thread = strtol (tok, &tmptok, 0); 09465 if (tok == tmptok) 09466 error (_("Junk after thread keyword.")); 09467 if (!valid_thread_id (*thread)) 09468 invalid_thread_id_error (*thread); 09469 tok = tmptok; 09470 } 09471 else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) 09472 { 09473 char *tmptok; 09474 09475 tok = end_tok + 1; 09476 *task = strtol (tok, &tmptok, 0); 09477 if (tok == tmptok) 09478 error (_("Junk after task keyword.")); 09479 if (!valid_task_id (*task)) 09480 error (_("Unknown task %d."), *task); 09481 tok = tmptok; 09482 } 09483 else if (rest) 09484 { 09485 *rest = savestring (tok, strlen (tok)); 09486 return; 09487 } 09488 else 09489 error (_("Junk at end of arguments.")); 09490 } 09491 } 09492 09493 /* Decode a static tracepoint marker spec. */ 09494 09495 static struct symtabs_and_lines 09496 decode_static_tracepoint_spec (char **arg_p) 09497 { 09498 VEC(static_tracepoint_marker_p) *markers = NULL; 09499 struct symtabs_and_lines sals; 09500 struct cleanup *old_chain; 09501 char *p = &(*arg_p)[3]; 09502 char *endp; 09503 char *marker_str; 09504 int i; 09505 09506 p = skip_spaces (p); 09507 09508 endp = skip_to_space (p); 09509 09510 marker_str = savestring (p, endp - p); 09511 old_chain = make_cleanup (xfree, marker_str); 09512 09513 markers = target_static_tracepoint_markers_by_strid (marker_str); 09514 if (VEC_empty(static_tracepoint_marker_p, markers)) 09515 error (_("No known static tracepoint marker named %s"), marker_str); 09516 09517 sals.nelts = VEC_length(static_tracepoint_marker_p, markers); 09518 sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); 09519 09520 for (i = 0; i < sals.nelts; i++) 09521 { 09522 struct static_tracepoint_marker *marker; 09523 09524 marker = VEC_index (static_tracepoint_marker_p, markers, i); 09525 09526 init_sal (&sals.sals[i]); 09527 09528 sals.sals[i] = find_pc_line (marker->address, 0); 09529 sals.sals[i].pc = marker->address; 09530 09531 release_static_tracepoint_marker (marker); 09532 } 09533 09534 do_cleanups (old_chain); 09535 09536 *arg_p = endp; 09537 return sals; 09538 } 09539 09540 /* Set a breakpoint. This function is shared between CLI and MI 09541 functions for setting a breakpoint. This function has two major 09542 modes of operations, selected by the PARSE_ARG parameter. If 09543 non-zero, the function will parse ARG, extracting location, 09544 condition, thread and extra string. Otherwise, ARG is just the 09545 breakpoint's location, with condition, thread, and extra string 09546 specified by the COND_STRING, THREAD and EXTRA_STRING parameters. 09547 If INTERNAL is non-zero, the breakpoint number will be allocated 09548 from the internal breakpoint count. Returns true if any breakpoint 09549 was created; false otherwise. */ 09550 09551 int 09552 create_breakpoint (struct gdbarch *gdbarch, 09553 char *arg, char *cond_string, 09554 int thread, char *extra_string, 09555 int parse_arg, 09556 int tempflag, enum bptype type_wanted, 09557 int ignore_count, 09558 enum auto_boolean pending_break_support, 09559 const struct breakpoint_ops *ops, 09560 int from_tty, int enabled, int internal, 09561 unsigned flags) 09562 { 09563 volatile struct gdb_exception e; 09564 char *copy_arg = NULL; 09565 char *addr_start = arg; 09566 struct linespec_result canonical; 09567 struct cleanup *old_chain; 09568 struct cleanup *bkpt_chain = NULL; 09569 int pending = 0; 09570 int task = 0; 09571 int prev_bkpt_count = breakpoint_count; 09572 09573 gdb_assert (ops != NULL); 09574 09575 init_linespec_result (&canonical); 09576 09577 TRY_CATCH (e, RETURN_MASK_ALL) 09578 { 09579 ops->create_sals_from_address (&arg, &canonical, type_wanted, 09580 addr_start, ©_arg); 09581 } 09582 09583 /* If caller is interested in rc value from parse, set value. */ 09584 switch (e.reason) 09585 { 09586 case GDB_NO_ERROR: 09587 if (VEC_empty (linespec_sals, canonical.sals)) 09588 return 0; 09589 break; 09590 case RETURN_ERROR: 09591 switch (e.error) 09592 { 09593 case NOT_FOUND_ERROR: 09594 09595 /* If pending breakpoint support is turned off, throw 09596 error. */ 09597 09598 if (pending_break_support == AUTO_BOOLEAN_FALSE) 09599 throw_exception (e); 09600 09601 exception_print (gdb_stderr, e); 09602 09603 /* If pending breakpoint support is auto query and the user 09604 selects no, then simply return the error code. */ 09605 if (pending_break_support == AUTO_BOOLEAN_AUTO 09606 && !nquery (_("Make %s pending on future shared library load? "), 09607 bptype_string (type_wanted))) 09608 return 0; 09609 09610 /* At this point, either the user was queried about setting 09611 a pending breakpoint and selected yes, or pending 09612 breakpoint behavior is on and thus a pending breakpoint 09613 is defaulted on behalf of the user. */ 09614 { 09615 struct linespec_sals lsal; 09616 09617 copy_arg = xstrdup (addr_start); 09618 lsal.canonical = xstrdup (copy_arg); 09619 lsal.sals.nelts = 1; 09620 lsal.sals.sals = XNEW (struct symtab_and_line); 09621 init_sal (&lsal.sals.sals[0]); 09622 pending = 1; 09623 VEC_safe_push (linespec_sals, canonical.sals, &lsal); 09624 } 09625 break; 09626 default: 09627 throw_exception (e); 09628 } 09629 break; 09630 default: 09631 throw_exception (e); 09632 } 09633 09634 /* Create a chain of things that always need to be cleaned up. */ 09635 old_chain = make_cleanup_destroy_linespec_result (&canonical); 09636 09637 /* ----------------------------- SNIP ----------------------------- 09638 Anything added to the cleanup chain beyond this point is assumed 09639 to be part of a breakpoint. If the breakpoint create succeeds 09640 then the memory is not reclaimed. */ 09641 bkpt_chain = make_cleanup (null_cleanup, 0); 09642 09643 /* Resolve all line numbers to PC's and verify that the addresses 09644 are ok for the target. */ 09645 if (!pending) 09646 { 09647 int ix; 09648 struct linespec_sals *iter; 09649 09650 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) 09651 breakpoint_sals_to_pc (&iter->sals); 09652 } 09653 09654 /* Fast tracepoints may have additional restrictions on location. */ 09655 if (!pending && type_wanted == bp_fast_tracepoint) 09656 { 09657 int ix; 09658 struct linespec_sals *iter; 09659 09660 for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) 09661 check_fast_tracepoint_sals (gdbarch, &iter->sals); 09662 } 09663 09664 /* Verify that condition can be parsed, before setting any 09665 breakpoints. Allocate a separate condition expression for each 09666 breakpoint. */ 09667 if (!pending) 09668 { 09669 if (parse_arg) 09670 { 09671 char *rest; 09672 struct linespec_sals *lsal; 09673 09674 lsal = VEC_index (linespec_sals, canonical.sals, 0); 09675 09676 /* Here we only parse 'arg' to separate condition 09677 from thread number, so parsing in context of first 09678 sal is OK. When setting the breakpoint we'll 09679 re-parse it in context of each sal. */ 09680 09681 find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, 09682 &thread, &task, &rest); 09683 if (cond_string) 09684 make_cleanup (xfree, cond_string); 09685 if (rest) 09686 make_cleanup (xfree, rest); 09687 if (rest) 09688 extra_string = rest; 09689 } 09690 else 09691 { 09692 if (*arg != '\0') 09693 error (_("Garbage '%s' at end of location"), arg); 09694 09695 /* Create a private copy of condition string. */ 09696 if (cond_string) 09697 { 09698 cond_string = xstrdup (cond_string); 09699 make_cleanup (xfree, cond_string); 09700 } 09701 /* Create a private copy of any extra string. */ 09702 if (extra_string) 09703 { 09704 extra_string = xstrdup (extra_string); 09705 make_cleanup (xfree, extra_string); 09706 } 09707 } 09708 09709 ops->create_breakpoints_sal (gdbarch, &canonical, 09710 cond_string, extra_string, type_wanted, 09711 tempflag ? disp_del : disp_donttouch, 09712 thread, task, ignore_count, ops, 09713 from_tty, enabled, internal, flags); 09714 } 09715 else 09716 { 09717 struct breakpoint *b; 09718 09719 make_cleanup (xfree, copy_arg); 09720 09721 if (is_tracepoint_type (type_wanted)) 09722 { 09723 struct tracepoint *t; 09724 09725 t = XCNEW (struct tracepoint); 09726 b = &t->base; 09727 } 09728 else 09729 b = XNEW (struct breakpoint); 09730 09731 init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); 09732 09733 b->addr_string = copy_arg; 09734 if (parse_arg) 09735 b->cond_string = NULL; 09736 else 09737 { 09738 /* Create a private copy of condition string. */ 09739 if (cond_string) 09740 { 09741 cond_string = xstrdup (cond_string); 09742 make_cleanup (xfree, cond_string); 09743 } 09744 b->cond_string = cond_string; 09745 } 09746 b->extra_string = NULL; 09747 b->ignore_count = ignore_count; 09748 b->disposition = tempflag ? disp_del : disp_donttouch; 09749 b->condition_not_parsed = 1; 09750 b->enable_state = enabled ? bp_enabled : bp_disabled; 09751 if ((type_wanted != bp_breakpoint 09752 && type_wanted != bp_hardware_breakpoint) || thread != -1) 09753 b->pspace = current_program_space; 09754 09755 install_breakpoint (internal, b, 0); 09756 } 09757 09758 if (VEC_length (linespec_sals, canonical.sals) > 1) 09759 { 09760 warning (_("Multiple breakpoints were set.\nUse the " 09761 "\"delete\" command to delete unwanted breakpoints.")); 09762 prev_breakpoint_count = prev_bkpt_count; 09763 } 09764 09765 /* That's it. Discard the cleanups for data inserted into the 09766 breakpoint. */ 09767 discard_cleanups (bkpt_chain); 09768 /* But cleanup everything else. */ 09769 do_cleanups (old_chain); 09770 09771 /* error call may happen here - have BKPT_CHAIN already discarded. */ 09772 update_global_location_list (1); 09773 09774 return 1; 09775 } 09776 09777 /* Set a breakpoint. 09778 ARG is a string describing breakpoint address, 09779 condition, and thread. 09780 FLAG specifies if a breakpoint is hardware on, 09781 and if breakpoint is temporary, using BP_HARDWARE_FLAG 09782 and BP_TEMPFLAG. */ 09783 09784 static void 09785 break_command_1 (char *arg, int flag, int from_tty) 09786 { 09787 int tempflag = flag & BP_TEMPFLAG; 09788 enum bptype type_wanted = (flag & BP_HARDWAREFLAG 09789 ? bp_hardware_breakpoint 09790 : bp_breakpoint); 09791 struct breakpoint_ops *ops; 09792 const char *arg_cp = arg; 09793 09794 /* Matching breakpoints on probes. */ 09795 if (arg && probe_linespec_to_ops (&arg_cp) != NULL) 09796 ops = &bkpt_probe_breakpoint_ops; 09797 else 09798 ops = &bkpt_breakpoint_ops; 09799 09800 create_breakpoint (get_current_arch (), 09801 arg, 09802 NULL, 0, NULL, 1 /* parse arg */, 09803 tempflag, type_wanted, 09804 0 /* Ignore count */, 09805 pending_break_support, 09806 ops, 09807 from_tty, 09808 1 /* enabled */, 09809 0 /* internal */, 09810 0); 09811 } 09812 09813 /* Helper function for break_command_1 and disassemble_command. */ 09814 09815 void 09816 resolve_sal_pc (struct symtab_and_line *sal) 09817 { 09818 CORE_ADDR pc; 09819 09820 if (sal->pc == 0 && sal->symtab != NULL) 09821 { 09822 if (!find_line_pc (sal->symtab, sal->line, &pc)) 09823 error (_("No line %d in file \"%s\"."), 09824 sal->line, symtab_to_filename_for_display (sal->symtab)); 09825 sal->pc = pc; 09826 09827 /* If this SAL corresponds to a breakpoint inserted using a line 09828 number, then skip the function prologue if necessary. */ 09829 if (sal->explicit_line) 09830 skip_prologue_sal (sal); 09831 } 09832 09833 if (sal->section == 0 && sal->symtab != NULL) 09834 { 09835 struct blockvector *bv; 09836 struct block *b; 09837 struct symbol *sym; 09838 09839 bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); 09840 if (bv != NULL) 09841 { 09842 sym = block_linkage_function (b); 09843 if (sym != NULL) 09844 { 09845 fixup_symbol_section (sym, sal->symtab->objfile); 09846 sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); 09847 } 09848 else 09849 { 09850 /* It really is worthwhile to have the section, so we'll 09851 just have to look harder. This case can be executed 09852 if we have line numbers but no functions (as can 09853 happen in assembly source). */ 09854 09855 struct bound_minimal_symbol msym; 09856 struct cleanup *old_chain = save_current_space_and_thread (); 09857 09858 switch_to_program_space_and_thread (sal->pspace); 09859 09860 msym = lookup_minimal_symbol_by_pc (sal->pc); 09861 if (msym.minsym) 09862 sal->section = SYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); 09863 09864 do_cleanups (old_chain); 09865 } 09866 } 09867 } 09868 } 09869 09870 void 09871 break_command (char *arg, int from_tty) 09872 { 09873 break_command_1 (arg, 0, from_tty); 09874 } 09875 09876 void 09877 tbreak_command (char *arg, int from_tty) 09878 { 09879 break_command_1 (arg, BP_TEMPFLAG, from_tty); 09880 } 09881 09882 static void 09883 hbreak_command (char *arg, int from_tty) 09884 { 09885 break_command_1 (arg, BP_HARDWAREFLAG, from_tty); 09886 } 09887 09888 static void 09889 thbreak_command (char *arg, int from_tty) 09890 { 09891 break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); 09892 } 09893 09894 static void 09895 stop_command (char *arg, int from_tty) 09896 { 09897 printf_filtered (_("Specify the type of breakpoint to set.\n\ 09898 Usage: stop in <function | address>\n\ 09899 stop at <line>\n")); 09900 } 09901 09902 static void 09903 stopin_command (char *arg, int from_tty) 09904 { 09905 int badInput = 0; 09906 09907 if (arg == (char *) NULL) 09908 badInput = 1; 09909 else if (*arg != '*') 09910 { 09911 char *argptr = arg; 09912 int hasColon = 0; 09913 09914 /* Look for a ':'. If this is a line number specification, then 09915 say it is bad, otherwise, it should be an address or 09916 function/method name. */ 09917 while (*argptr && !hasColon) 09918 { 09919 hasColon = (*argptr == ':'); 09920 argptr++; 09921 } 09922 09923 if (hasColon) 09924 badInput = (*argptr != ':'); /* Not a class::method */ 09925 else 09926 badInput = isdigit (*arg); /* a simple line number */ 09927 } 09928 09929 if (badInput) 09930 printf_filtered (_("Usage: stop in <function | address>\n")); 09931 else 09932 break_command_1 (arg, 0, from_tty); 09933 } 09934 09935 static void 09936 stopat_command (char *arg, int from_tty) 09937 { 09938 int badInput = 0; 09939 09940 if (arg == (char *) NULL || *arg == '*') /* no line number */ 09941 badInput = 1; 09942 else 09943 { 09944 char *argptr = arg; 09945 int hasColon = 0; 09946 09947 /* Look for a ':'. If there is a '::' then get out, otherwise 09948 it is probably a line number. */ 09949 while (*argptr && !hasColon) 09950 { 09951 hasColon = (*argptr == ':'); 09952 argptr++; 09953 } 09954 09955 if (hasColon) 09956 badInput = (*argptr == ':'); /* we have class::method */ 09957 else 09958 badInput = !isdigit (*arg); /* not a line number */ 09959 } 09960 09961 if (badInput) 09962 printf_filtered (_("Usage: stop at <line>\n")); 09963 else 09964 break_command_1 (arg, 0, from_tty); 09965 } 09966 09967 /* The dynamic printf command is mostly like a regular breakpoint, but 09968 with a prewired command list consisting of a single output command, 09969 built from extra arguments supplied on the dprintf command 09970 line. */ 09971 09972 static void 09973 dprintf_command (char *arg, int from_tty) 09974 { 09975 create_breakpoint (get_current_arch (), 09976 arg, 09977 NULL, 0, NULL, 1 /* parse arg */, 09978 0, bp_dprintf, 09979 0 /* Ignore count */, 09980 pending_break_support, 09981 &dprintf_breakpoint_ops, 09982 from_tty, 09983 1 /* enabled */, 09984 0 /* internal */, 09985 0); 09986 } 09987 09988 static void 09989 agent_printf_command (char *arg, int from_tty) 09990 { 09991 error (_("May only run agent-printf on the target")); 09992 } 09993 09994 /* Implement the "breakpoint_hit" breakpoint_ops method for 09995 ranged breakpoints. */ 09996 09997 static int 09998 breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, 09999 struct address_space *aspace, 10000 CORE_ADDR bp_addr, 10001 const struct target_waitstatus *ws) 10002 { 10003 if (ws->kind != TARGET_WAITKIND_STOPPED 10004 || ws->value.sig != GDB_SIGNAL_TRAP) 10005 return 0; 10006 10007 return breakpoint_address_match_range (bl->pspace->aspace, bl->address, 10008 bl->length, aspace, bp_addr); 10009 } 10010 10011 /* Implement the "resources_needed" breakpoint_ops method for 10012 ranged breakpoints. */ 10013 10014 static int 10015 resources_needed_ranged_breakpoint (const struct bp_location *bl) 10016 { 10017 return target_ranged_break_num_registers (); 10018 } 10019 10020 /* Implement the "print_it" breakpoint_ops method for 10021 ranged breakpoints. */ 10022 10023 static enum print_stop_action 10024 print_it_ranged_breakpoint (bpstat bs) 10025 { 10026 struct breakpoint *b = bs->breakpoint_at; 10027 struct bp_location *bl = b->loc; 10028 struct ui_out *uiout = current_uiout; 10029 10030 gdb_assert (b->type == bp_hardware_breakpoint); 10031 10032 /* Ranged breakpoints have only one location. */ 10033 gdb_assert (bl && bl->next == NULL); 10034 10035 annotate_breakpoint (b->number); 10036 if (b->disposition == disp_del) 10037 ui_out_text (uiout, "\nTemporary ranged breakpoint "); 10038 else 10039 ui_out_text (uiout, "\nRanged breakpoint "); 10040 if (ui_out_is_mi_like_p (uiout)) 10041 { 10042 ui_out_field_string (uiout, "reason", 10043 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); 10044 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 10045 } 10046 ui_out_field_int (uiout, "bkptno", b->number); 10047 ui_out_text (uiout, ", "); 10048 10049 return PRINT_SRC_AND_LOC; 10050 } 10051 10052 /* Implement the "print_one" breakpoint_ops method for 10053 ranged breakpoints. */ 10054 10055 static void 10056 print_one_ranged_breakpoint (struct breakpoint *b, 10057 struct bp_location **last_loc) 10058 { 10059 struct bp_location *bl = b->loc; 10060 struct value_print_options opts; 10061 struct ui_out *uiout = current_uiout; 10062 10063 /* Ranged breakpoints have only one location. */ 10064 gdb_assert (bl && bl->next == NULL); 10065 10066 get_user_print_options (&opts); 10067 10068 if (opts.addressprint) 10069 /* We don't print the address range here, it will be printed later 10070 by print_one_detail_ranged_breakpoint. */ 10071 ui_out_field_skip (uiout, "addr"); 10072 annotate_field (5); 10073 print_breakpoint_location (b, bl); 10074 *last_loc = bl; 10075 } 10076 10077 /* Implement the "print_one_detail" breakpoint_ops method for 10078 ranged breakpoints. */ 10079 10080 static void 10081 print_one_detail_ranged_breakpoint (const struct breakpoint *b, 10082 struct ui_out *uiout) 10083 { 10084 CORE_ADDR address_start, address_end; 10085 struct bp_location *bl = b->loc; 10086 struct ui_file *stb = mem_fileopen (); 10087 struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); 10088 10089 gdb_assert (bl); 10090 10091 address_start = bl->address; 10092 address_end = address_start + bl->length - 1; 10093 10094 ui_out_text (uiout, "\taddress range: "); 10095 fprintf_unfiltered (stb, "[%s, %s]", 10096 print_core_address (bl->gdbarch, address_start), 10097 print_core_address (bl->gdbarch, address_end)); 10098 ui_out_field_stream (uiout, "addr", stb); 10099 ui_out_text (uiout, "\n"); 10100 10101 do_cleanups (cleanup); 10102 } 10103 10104 /* Implement the "print_mention" breakpoint_ops method for 10105 ranged breakpoints. */ 10106 10107 static void 10108 print_mention_ranged_breakpoint (struct breakpoint *b) 10109 { 10110 struct bp_location *bl = b->loc; 10111 struct ui_out *uiout = current_uiout; 10112 10113 gdb_assert (bl); 10114 gdb_assert (b->type == bp_hardware_breakpoint); 10115 10116 if (ui_out_is_mi_like_p (uiout)) 10117 return; 10118 10119 printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), 10120 b->number, paddress (bl->gdbarch, bl->address), 10121 paddress (bl->gdbarch, bl->address + bl->length - 1)); 10122 } 10123 10124 /* Implement the "print_recreate" breakpoint_ops method for 10125 ranged breakpoints. */ 10126 10127 static void 10128 print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) 10129 { 10130 fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, 10131 b->addr_string_range_end); 10132 print_recreate_thread (b, fp); 10133 } 10134 10135 /* The breakpoint_ops structure to be used in ranged breakpoints. */ 10136 10137 static struct breakpoint_ops ranged_breakpoint_ops; 10138 10139 /* Find the address where the end of the breakpoint range should be 10140 placed, given the SAL of the end of the range. This is so that if 10141 the user provides a line number, the end of the range is set to the 10142 last instruction of the given line. */ 10143 10144 static CORE_ADDR 10145 find_breakpoint_range_end (struct symtab_and_line sal) 10146 { 10147 CORE_ADDR end; 10148 10149 /* If the user provided a PC value, use it. Otherwise, 10150 find the address of the end of the given location. */ 10151 if (sal.explicit_pc) 10152 end = sal.pc; 10153 else 10154 { 10155 int ret; 10156 CORE_ADDR start; 10157 10158 ret = find_line_pc_range (sal, &start, &end); 10159 if (!ret) 10160 error (_("Could not find location of the end of the range.")); 10161 10162 /* find_line_pc_range returns the start of the next line. */ 10163 end--; 10164 } 10165 10166 return end; 10167 } 10168 10169 /* Implement the "break-range" CLI command. */ 10170 10171 static void 10172 break_range_command (char *arg, int from_tty) 10173 { 10174 char *arg_start, *addr_string_start, *addr_string_end; 10175 struct linespec_result canonical_start, canonical_end; 10176 int bp_count, can_use_bp, length; 10177 CORE_ADDR end; 10178 struct breakpoint *b; 10179 struct symtab_and_line sal_start, sal_end; 10180 struct cleanup *cleanup_bkpt; 10181 struct linespec_sals *lsal_start, *lsal_end; 10182 10183 /* We don't support software ranged breakpoints. */ 10184 if (target_ranged_break_num_registers () < 0) 10185 error (_("This target does not support hardware ranged breakpoints.")); 10186 10187 bp_count = hw_breakpoint_used_count (); 10188 bp_count += target_ranged_break_num_registers (); 10189 can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 10190 bp_count, 0); 10191 if (can_use_bp < 0) 10192 error (_("Hardware breakpoints used exceeds limit.")); 10193 10194 arg = skip_spaces (arg); 10195 if (arg == NULL || arg[0] == '\0') 10196 error(_("No address range specified.")); 10197 10198 init_linespec_result (&canonical_start); 10199 10200 arg_start = arg; 10201 parse_breakpoint_sals (&arg, &canonical_start); 10202 10203 cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); 10204 10205 if (arg[0] != ',') 10206 error (_("Too few arguments.")); 10207 else if (VEC_empty (linespec_sals, canonical_start.sals)) 10208 error (_("Could not find location of the beginning of the range.")); 10209 10210 lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); 10211 10212 if (VEC_length (linespec_sals, canonical_start.sals) > 1 10213 || lsal_start->sals.nelts != 1) 10214 error (_("Cannot create a ranged breakpoint with multiple locations.")); 10215 10216 sal_start = lsal_start->sals.sals[0]; 10217 addr_string_start = savestring (arg_start, arg - arg_start); 10218 make_cleanup (xfree, addr_string_start); 10219 10220 arg++; /* Skip the comma. */ 10221 arg = skip_spaces (arg); 10222 10223 /* Parse the end location. */ 10224 10225 init_linespec_result (&canonical_end); 10226 arg_start = arg; 10227 10228 /* We call decode_line_full directly here instead of using 10229 parse_breakpoint_sals because we need to specify the start location's 10230 symtab and line as the default symtab and line for the end of the 10231 range. This makes it possible to have ranges like "foo.c:27, +14", 10232 where +14 means 14 lines from the start location. */ 10233 decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, 10234 sal_start.symtab, sal_start.line, 10235 &canonical_end, NULL, NULL); 10236 10237 make_cleanup_destroy_linespec_result (&canonical_end); 10238 10239 if (VEC_empty (linespec_sals, canonical_end.sals)) 10240 error (_("Could not find location of the end of the range.")); 10241 10242 lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); 10243 if (VEC_length (linespec_sals, canonical_end.sals) > 1 10244 || lsal_end->sals.nelts != 1) 10245 error (_("Cannot create a ranged breakpoint with multiple locations.")); 10246 10247 sal_end = lsal_end->sals.sals[0]; 10248 addr_string_end = savestring (arg_start, arg - arg_start); 10249 make_cleanup (xfree, addr_string_end); 10250 10251 end = find_breakpoint_range_end (sal_end); 10252 if (sal_start.pc > end) 10253 error (_("Invalid address range, end precedes start.")); 10254 10255 length = end - sal_start.pc + 1; 10256 if (length < 0) 10257 /* Length overflowed. */ 10258 error (_("Address range too large.")); 10259 else if (length == 1) 10260 { 10261 /* This range is simple enough to be handled by 10262 the `hbreak' command. */ 10263 hbreak_command (addr_string_start, 1); 10264 10265 do_cleanups (cleanup_bkpt); 10266 10267 return; 10268 } 10269 10270 /* Now set up the breakpoint. */ 10271 b = set_raw_breakpoint (get_current_arch (), sal_start, 10272 bp_hardware_breakpoint, &ranged_breakpoint_ops); 10273 set_breakpoint_count (breakpoint_count + 1); 10274 b->number = breakpoint_count; 10275 b->disposition = disp_donttouch; 10276 b->addr_string = xstrdup (addr_string_start); 10277 b->addr_string_range_end = xstrdup (addr_string_end); 10278 b->loc->length = length; 10279 10280 do_cleanups (cleanup_bkpt); 10281 10282 mention (b); 10283 observer_notify_breakpoint_created (b); 10284 update_global_location_list (1); 10285 } 10286 10287 /* Return non-zero if EXP is verified as constant. Returned zero 10288 means EXP is variable. Also the constant detection may fail for 10289 some constant expressions and in such case still falsely return 10290 zero. */ 10291 10292 static int 10293 watchpoint_exp_is_const (const struct expression *exp) 10294 { 10295 int i = exp->nelts; 10296 10297 while (i > 0) 10298 { 10299 int oplenp, argsp; 10300 10301 /* We are only interested in the descriptor of each element. */ 10302 operator_length (exp, i, &oplenp, &argsp); 10303 i -= oplenp; 10304 10305 switch (exp->elts[i].opcode) 10306 { 10307 case BINOP_ADD: 10308 case BINOP_SUB: 10309 case BINOP_MUL: 10310 case BINOP_DIV: 10311 case BINOP_REM: 10312 case BINOP_MOD: 10313 case BINOP_LSH: 10314 case BINOP_RSH: 10315 case BINOP_LOGICAL_AND: 10316 case BINOP_LOGICAL_OR: 10317 case BINOP_BITWISE_AND: 10318 case BINOP_BITWISE_IOR: 10319 case BINOP_BITWISE_XOR: 10320 case BINOP_EQUAL: 10321 case BINOP_NOTEQUAL: 10322 case BINOP_LESS: 10323 case BINOP_GTR: 10324 case BINOP_LEQ: 10325 case BINOP_GEQ: 10326 case BINOP_REPEAT: 10327 case BINOP_COMMA: 10328 case BINOP_EXP: 10329 case BINOP_MIN: 10330 case BINOP_MAX: 10331 case BINOP_INTDIV: 10332 case BINOP_CONCAT: 10333 case BINOP_IN: 10334 case BINOP_RANGE: 10335 case TERNOP_COND: 10336 case TERNOP_SLICE: 10337 10338 case OP_LONG: 10339 case OP_DOUBLE: 10340 case OP_DECFLOAT: 10341 case OP_LAST: 10342 case OP_COMPLEX: 10343 case OP_STRING: 10344 case OP_ARRAY: 10345 case OP_TYPE: 10346 case OP_TYPEOF: 10347 case OP_DECLTYPE: 10348 case OP_TYPEID: 10349 case OP_NAME: 10350 case OP_OBJC_NSSTRING: 10351 10352 case UNOP_NEG: 10353 case UNOP_LOGICAL_NOT: 10354 case UNOP_COMPLEMENT: 10355 case UNOP_ADDR: 10356 case UNOP_HIGH: 10357 case UNOP_CAST: 10358 10359 case UNOP_CAST_TYPE: 10360 case UNOP_REINTERPRET_CAST: 10361 case UNOP_DYNAMIC_CAST: 10362 /* Unary, binary and ternary operators: We have to check 10363 their operands. If they are constant, then so is the 10364 result of that operation. For instance, if A and B are 10365 determined to be constants, then so is "A + B". 10366 10367 UNOP_IND is one exception to the rule above, because the 10368 value of *ADDR is not necessarily a constant, even when 10369 ADDR is. */ 10370 break; 10371 10372 case OP_VAR_VALUE: 10373 /* Check whether the associated symbol is a constant. 10374 10375 We use SYMBOL_CLASS rather than TYPE_CONST because it's 10376 possible that a buggy compiler could mark a variable as 10377 constant even when it is not, and TYPE_CONST would return 10378 true in this case, while SYMBOL_CLASS wouldn't. 10379 10380 We also have to check for function symbols because they 10381 are always constant. */ 10382 { 10383 struct symbol *s = exp->elts[i + 2].symbol; 10384 10385 if (SYMBOL_CLASS (s) != LOC_BLOCK 10386 && SYMBOL_CLASS (s) != LOC_CONST 10387 && SYMBOL_CLASS (s) != LOC_CONST_BYTES) 10388 return 0; 10389 break; 10390 } 10391 10392 /* The default action is to return 0 because we are using 10393 the optimistic approach here: If we don't know something, 10394 then it is not a constant. */ 10395 default: 10396 return 0; 10397 } 10398 } 10399 10400 return 1; 10401 } 10402 10403 /* Implement the "dtor" breakpoint_ops method for watchpoints. */ 10404 10405 static void 10406 dtor_watchpoint (struct breakpoint *self) 10407 { 10408 struct watchpoint *w = (struct watchpoint *) self; 10409 10410 xfree (w->cond_exp); 10411 xfree (w->exp); 10412 xfree (w->exp_string); 10413 xfree (w->exp_string_reparse); 10414 value_free (w->val); 10415 10416 base_breakpoint_ops.dtor (self); 10417 } 10418 10419 /* Implement the "re_set" breakpoint_ops method for watchpoints. */ 10420 10421 static void 10422 re_set_watchpoint (struct breakpoint *b) 10423 { 10424 struct watchpoint *w = (struct watchpoint *) b; 10425 10426 /* Watchpoint can be either on expression using entirely global 10427 variables, or it can be on local variables. 10428 10429 Watchpoints of the first kind are never auto-deleted, and even 10430 persist across program restarts. Since they can use variables 10431 from shared libraries, we need to reparse expression as libraries 10432 are loaded and unloaded. 10433 10434 Watchpoints on local variables can also change meaning as result 10435 of solib event. For example, if a watchpoint uses both a local 10436 and a global variables in expression, it's a local watchpoint, 10437 but unloading of a shared library will make the expression 10438 invalid. This is not a very common use case, but we still 10439 re-evaluate expression, to avoid surprises to the user. 10440 10441 Note that for local watchpoints, we re-evaluate it only if 10442 watchpoints frame id is still valid. If it's not, it means the 10443 watchpoint is out of scope and will be deleted soon. In fact, 10444 I'm not sure we'll ever be called in this case. 10445 10446 If a local watchpoint's frame id is still valid, then 10447 w->exp_valid_block is likewise valid, and we can safely use it. 10448 10449 Don't do anything about disabled watchpoints, since they will be 10450 reevaluated again when enabled. */ 10451 update_watchpoint (w, 1 /* reparse */); 10452 } 10453 10454 /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ 10455 10456 static int 10457 insert_watchpoint (struct bp_location *bl) 10458 { 10459 struct watchpoint *w = (struct watchpoint *) bl->owner; 10460 int length = w->exact ? 1 : bl->length; 10461 10462 return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, 10463 w->cond_exp); 10464 } 10465 10466 /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ 10467 10468 static int 10469 remove_watchpoint (struct bp_location *bl) 10470 { 10471 struct watchpoint *w = (struct watchpoint *) bl->owner; 10472 int length = w->exact ? 1 : bl->length; 10473 10474 return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, 10475 w->cond_exp); 10476 } 10477 10478 static int 10479 breakpoint_hit_watchpoint (const struct bp_location *bl, 10480 struct address_space *aspace, CORE_ADDR bp_addr, 10481 const struct target_waitstatus *ws) 10482 { 10483 struct breakpoint *b = bl->owner; 10484 struct watchpoint *w = (struct watchpoint *) b; 10485 10486 /* Continuable hardware watchpoints are treated as non-existent if the 10487 reason we stopped wasn't a hardware watchpoint (we didn't stop on 10488 some data address). Otherwise gdb won't stop on a break instruction 10489 in the code (not from a breakpoint) when a hardware watchpoint has 10490 been defined. Also skip watchpoints which we know did not trigger 10491 (did not match the data address). */ 10492 if (is_hardware_watchpoint (b) 10493 && w->watchpoint_triggered == watch_triggered_no) 10494 return 0; 10495 10496 return 1; 10497 } 10498 10499 static void 10500 check_status_watchpoint (bpstat bs) 10501 { 10502 gdb_assert (is_watchpoint (bs->breakpoint_at)); 10503 10504 bpstat_check_watchpoint (bs); 10505 } 10506 10507 /* Implement the "resources_needed" breakpoint_ops method for 10508 hardware watchpoints. */ 10509 10510 static int 10511 resources_needed_watchpoint (const struct bp_location *bl) 10512 { 10513 struct watchpoint *w = (struct watchpoint *) bl->owner; 10514 int length = w->exact? 1 : bl->length; 10515 10516 return target_region_ok_for_hw_watchpoint (bl->address, length); 10517 } 10518 10519 /* Implement the "works_in_software_mode" breakpoint_ops method for 10520 hardware watchpoints. */ 10521 10522 static int 10523 works_in_software_mode_watchpoint (const struct breakpoint *b) 10524 { 10525 /* Read and access watchpoints only work with hardware support. */ 10526 return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; 10527 } 10528 10529 static enum print_stop_action 10530 print_it_watchpoint (bpstat bs) 10531 { 10532 struct cleanup *old_chain; 10533 struct breakpoint *b; 10534 struct ui_file *stb; 10535 enum print_stop_action result; 10536 struct watchpoint *w; 10537 struct ui_out *uiout = current_uiout; 10538 10539 gdb_assert (bs->bp_location_at != NULL); 10540 10541 b = bs->breakpoint_at; 10542 w = (struct watchpoint *) b; 10543 10544 stb = mem_fileopen (); 10545 old_chain = make_cleanup_ui_file_delete (stb); 10546 10547 switch (b->type) 10548 { 10549 case bp_watchpoint: 10550 case bp_hardware_watchpoint: 10551 annotate_watchpoint (b->number); 10552 if (ui_out_is_mi_like_p (uiout)) 10553 ui_out_field_string 10554 (uiout, "reason", 10555 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); 10556 mention (b); 10557 make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 10558 ui_out_text (uiout, "\nOld value = "); 10559 watchpoint_value_print (bs->old_val, stb); 10560 ui_out_field_stream (uiout, "old", stb); 10561 ui_out_text (uiout, "\nNew value = "); 10562 watchpoint_value_print (w->val, stb); 10563 ui_out_field_stream (uiout, "new", stb); 10564 ui_out_text (uiout, "\n"); 10565 /* More than one watchpoint may have been triggered. */ 10566 result = PRINT_UNKNOWN; 10567 break; 10568 10569 case bp_read_watchpoint: 10570 if (ui_out_is_mi_like_p (uiout)) 10571 ui_out_field_string 10572 (uiout, "reason", 10573 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); 10574 mention (b); 10575 make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 10576 ui_out_text (uiout, "\nValue = "); 10577 watchpoint_value_print (w->val, stb); 10578 ui_out_field_stream (uiout, "value", stb); 10579 ui_out_text (uiout, "\n"); 10580 result = PRINT_UNKNOWN; 10581 break; 10582 10583 case bp_access_watchpoint: 10584 if (bs->old_val != NULL) 10585 { 10586 annotate_watchpoint (b->number); 10587 if (ui_out_is_mi_like_p (uiout)) 10588 ui_out_field_string 10589 (uiout, "reason", 10590 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); 10591 mention (b); 10592 make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 10593 ui_out_text (uiout, "\nOld value = "); 10594 watchpoint_value_print (bs->old_val, stb); 10595 ui_out_field_stream (uiout, "old", stb); 10596 ui_out_text (uiout, "\nNew value = "); 10597 } 10598 else 10599 { 10600 mention (b); 10601 if (ui_out_is_mi_like_p (uiout)) 10602 ui_out_field_string 10603 (uiout, "reason", 10604 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); 10605 make_cleanup_ui_out_tuple_begin_end (uiout, "value"); 10606 ui_out_text (uiout, "\nValue = "); 10607 } 10608 watchpoint_value_print (w->val, stb); 10609 ui_out_field_stream (uiout, "new", stb); 10610 ui_out_text (uiout, "\n"); 10611 result = PRINT_UNKNOWN; 10612 break; 10613 default: 10614 result = PRINT_UNKNOWN; 10615 } 10616 10617 do_cleanups (old_chain); 10618 return result; 10619 } 10620 10621 /* Implement the "print_mention" breakpoint_ops method for hardware 10622 watchpoints. */ 10623 10624 static void 10625 print_mention_watchpoint (struct breakpoint *b) 10626 { 10627 struct cleanup *ui_out_chain; 10628 struct watchpoint *w = (struct watchpoint *) b; 10629 struct ui_out *uiout = current_uiout; 10630 10631 switch (b->type) 10632 { 10633 case bp_watchpoint: 10634 ui_out_text (uiout, "Watchpoint "); 10635 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); 10636 break; 10637 case bp_hardware_watchpoint: 10638 ui_out_text (uiout, "Hardware watchpoint "); 10639 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); 10640 break; 10641 case bp_read_watchpoint: 10642 ui_out_text (uiout, "Hardware read watchpoint "); 10643 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); 10644 break; 10645 case bp_access_watchpoint: 10646 ui_out_text (uiout, "Hardware access (read/write) watchpoint "); 10647 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); 10648 break; 10649 default: 10650 internal_error (__FILE__, __LINE__, 10651 _("Invalid hardware watchpoint type.")); 10652 } 10653 10654 ui_out_field_int (uiout, "number", b->number); 10655 ui_out_text (uiout, ": "); 10656 ui_out_field_string (uiout, "exp", w->exp_string); 10657 do_cleanups (ui_out_chain); 10658 } 10659 10660 /* Implement the "print_recreate" breakpoint_ops method for 10661 watchpoints. */ 10662 10663 static void 10664 print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) 10665 { 10666 struct watchpoint *w = (struct watchpoint *) b; 10667 10668 switch (b->type) 10669 { 10670 case bp_watchpoint: 10671 case bp_hardware_watchpoint: 10672 fprintf_unfiltered (fp, "watch"); 10673 break; 10674 case bp_read_watchpoint: 10675 fprintf_unfiltered (fp, "rwatch"); 10676 break; 10677 case bp_access_watchpoint: 10678 fprintf_unfiltered (fp, "awatch"); 10679 break; 10680 default: 10681 internal_error (__FILE__, __LINE__, 10682 _("Invalid watchpoint type.")); 10683 } 10684 10685 fprintf_unfiltered (fp, " %s", w->exp_string); 10686 print_recreate_thread (b, fp); 10687 } 10688 10689 /* Implement the "explains_signal" breakpoint_ops method for 10690 watchpoints. */ 10691 10692 static enum bpstat_signal_value 10693 explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) 10694 { 10695 /* A software watchpoint cannot cause a signal other than 10696 GDB_SIGNAL_TRAP. */ 10697 if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) 10698 return BPSTAT_SIGNAL_NO; 10699 10700 return BPSTAT_SIGNAL_HIDE; 10701 } 10702 10703 /* The breakpoint_ops structure to be used in hardware watchpoints. */ 10704 10705 static struct breakpoint_ops watchpoint_breakpoint_ops; 10706 10707 /* Implement the "insert" breakpoint_ops method for 10708 masked hardware watchpoints. */ 10709 10710 static int 10711 insert_masked_watchpoint (struct bp_location *bl) 10712 { 10713 struct watchpoint *w = (struct watchpoint *) bl->owner; 10714 10715 return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, 10716 bl->watchpoint_type); 10717 } 10718 10719 /* Implement the "remove" breakpoint_ops method for 10720 masked hardware watchpoints. */ 10721 10722 static int 10723 remove_masked_watchpoint (struct bp_location *bl) 10724 { 10725 struct watchpoint *w = (struct watchpoint *) bl->owner; 10726 10727 return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, 10728 bl->watchpoint_type); 10729 } 10730 10731 /* Implement the "resources_needed" breakpoint_ops method for 10732 masked hardware watchpoints. */ 10733 10734 static int 10735 resources_needed_masked_watchpoint (const struct bp_location *bl) 10736 { 10737 struct watchpoint *w = (struct watchpoint *) bl->owner; 10738 10739 return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); 10740 } 10741 10742 /* Implement the "works_in_software_mode" breakpoint_ops method for 10743 masked hardware watchpoints. */ 10744 10745 static int 10746 works_in_software_mode_masked_watchpoint (const struct breakpoint *b) 10747 { 10748 return 0; 10749 } 10750 10751 /* Implement the "print_it" breakpoint_ops method for 10752 masked hardware watchpoints. */ 10753 10754 static enum print_stop_action 10755 print_it_masked_watchpoint (bpstat bs) 10756 { 10757 struct breakpoint *b = bs->breakpoint_at; 10758 struct ui_out *uiout = current_uiout; 10759 10760 /* Masked watchpoints have only one location. */ 10761 gdb_assert (b->loc && b->loc->next == NULL); 10762 10763 switch (b->type) 10764 { 10765 case bp_hardware_watchpoint: 10766 annotate_watchpoint (b->number); 10767 if (ui_out_is_mi_like_p (uiout)) 10768 ui_out_field_string 10769 (uiout, "reason", 10770 async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); 10771 break; 10772 10773 case bp_read_watchpoint: 10774 if (ui_out_is_mi_like_p (uiout)) 10775 ui_out_field_string 10776 (uiout, "reason", 10777 async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); 10778 break; 10779 10780 case bp_access_watchpoint: 10781 if (ui_out_is_mi_like_p (uiout)) 10782 ui_out_field_string 10783 (uiout, "reason", 10784 async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); 10785 break; 10786 default: 10787 internal_error (__FILE__, __LINE__, 10788 _("Invalid hardware watchpoint type.")); 10789 } 10790 10791 mention (b); 10792 ui_out_text (uiout, _("\n\ 10793 Check the underlying instruction at PC for the memory\n\ 10794 address and value which triggered this watchpoint.\n")); 10795 ui_out_text (uiout, "\n"); 10796 10797 /* More than one watchpoint may have been triggered. */ 10798 return PRINT_UNKNOWN; 10799 } 10800 10801 /* Implement the "print_one_detail" breakpoint_ops method for 10802 masked hardware watchpoints. */ 10803 10804 static void 10805 print_one_detail_masked_watchpoint (const struct breakpoint *b, 10806 struct ui_out *uiout) 10807 { 10808 struct watchpoint *w = (struct watchpoint *) b; 10809 10810 /* Masked watchpoints have only one location. */ 10811 gdb_assert (b->loc && b->loc->next == NULL); 10812 10813 ui_out_text (uiout, "\tmask "); 10814 ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); 10815 ui_out_text (uiout, "\n"); 10816 } 10817 10818 /* Implement the "print_mention" breakpoint_ops method for 10819 masked hardware watchpoints. */ 10820 10821 static void 10822 print_mention_masked_watchpoint (struct breakpoint *b) 10823 { 10824 struct watchpoint *w = (struct watchpoint *) b; 10825 struct ui_out *uiout = current_uiout; 10826 struct cleanup *ui_out_chain; 10827 10828 switch (b->type) 10829 { 10830 case bp_hardware_watchpoint: 10831 ui_out_text (uiout, "Masked hardware watchpoint "); 10832 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); 10833 break; 10834 case bp_read_watchpoint: 10835 ui_out_text (uiout, "Masked hardware read watchpoint "); 10836 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); 10837 break; 10838 case bp_access_watchpoint: 10839 ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); 10840 ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); 10841 break; 10842 default: 10843 internal_error (__FILE__, __LINE__, 10844 _("Invalid hardware watchpoint type.")); 10845 } 10846 10847 ui_out_field_int (uiout, "number", b->number); 10848 ui_out_text (uiout, ": "); 10849 ui_out_field_string (uiout, "exp", w->exp_string); 10850 do_cleanups (ui_out_chain); 10851 } 10852 10853 /* Implement the "print_recreate" breakpoint_ops method for 10854 masked hardware watchpoints. */ 10855 10856 static void 10857 print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) 10858 { 10859 struct watchpoint *w = (struct watchpoint *) b; 10860 char tmp[40]; 10861 10862 switch (b->type) 10863 { 10864 case bp_hardware_watchpoint: 10865 fprintf_unfiltered (fp, "watch"); 10866 break; 10867 case bp_read_watchpoint: 10868 fprintf_unfiltered (fp, "rwatch"); 10869 break; 10870 case bp_access_watchpoint: 10871 fprintf_unfiltered (fp, "awatch"); 10872 break; 10873 default: 10874 internal_error (__FILE__, __LINE__, 10875 _("Invalid hardware watchpoint type.")); 10876 } 10877 10878 sprintf_vma (tmp, w->hw_wp_mask); 10879 fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); 10880 print_recreate_thread (b, fp); 10881 } 10882 10883 /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ 10884 10885 static struct breakpoint_ops masked_watchpoint_breakpoint_ops; 10886 10887 /* Tell whether the given watchpoint is a masked hardware watchpoint. */ 10888 10889 static int 10890 is_masked_watchpoint (const struct breakpoint *b) 10891 { 10892 return b->ops == &masked_watchpoint_breakpoint_ops; 10893 } 10894 10895 /* accessflag: hw_write: watch write, 10896 hw_read: watch read, 10897 hw_access: watch access (read or write) */ 10898 static void 10899 watch_command_1 (const char *arg, int accessflag, int from_tty, 10900 int just_location, int internal) 10901 { 10902 volatile struct gdb_exception e; 10903 struct breakpoint *b, *scope_breakpoint = NULL; 10904 struct expression *exp; 10905 const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; 10906 struct value *val, *mark, *result; 10907 struct frame_info *frame; 10908 const char *exp_start = NULL; 10909 const char *exp_end = NULL; 10910 const char *tok, *end_tok; 10911 int toklen = -1; 10912 const char *cond_start = NULL; 10913 const char *cond_end = NULL; 10914 enum bptype bp_type; 10915 int thread = -1; 10916 int pc = 0; 10917 /* Flag to indicate whether we are going to use masks for 10918 the hardware watchpoint. */ 10919 int use_mask = 0; 10920 CORE_ADDR mask = 0; 10921 struct watchpoint *w; 10922 char *expression; 10923 struct cleanup *back_to; 10924 10925 /* Make sure that we actually have parameters to parse. */ 10926 if (arg != NULL && arg[0] != '\0') 10927 { 10928 const char *value_start; 10929 10930 exp_end = arg + strlen (arg); 10931 10932 /* Look for "parameter value" pairs at the end 10933 of the arguments string. */ 10934 for (tok = exp_end - 1; tok > arg; tok--) 10935 { 10936 /* Skip whitespace at the end of the argument list. */ 10937 while (tok > arg && (*tok == ' ' || *tok == '\t')) 10938 tok--; 10939 10940 /* Find the beginning of the last token. 10941 This is the value of the parameter. */ 10942 while (tok > arg && (*tok != ' ' && *tok != '\t')) 10943 tok--; 10944 value_start = tok + 1; 10945 10946 /* Skip whitespace. */ 10947 while (tok > arg && (*tok == ' ' || *tok == '\t')) 10948 tok--; 10949 10950 end_tok = tok; 10951 10952 /* Find the beginning of the second to last token. 10953 This is the parameter itself. */ 10954 while (tok > arg && (*tok != ' ' && *tok != '\t')) 10955 tok--; 10956 tok++; 10957 toklen = end_tok - tok + 1; 10958 10959 if (toklen == 6 && !strncmp (tok, "thread", 6)) 10960 { 10961 /* At this point we've found a "thread" token, which means 10962 the user is trying to set a watchpoint that triggers 10963 only in a specific thread. */ 10964 char *endp; 10965 10966 if (thread != -1) 10967 error(_("You can specify only one thread.")); 10968 10969 /* Extract the thread ID from the next token. */ 10970 thread = strtol (value_start, &endp, 0); 10971 10972 /* Check if the user provided a valid numeric value for the 10973 thread ID. */ 10974 if (*endp != ' ' && *endp != '\t' && *endp != '\0') 10975 error (_("Invalid thread ID specification %s."), value_start); 10976 10977 /* Check if the thread actually exists. */ 10978 if (!valid_thread_id (thread)) 10979 invalid_thread_id_error (thread); 10980 } 10981 else if (toklen == 4 && !strncmp (tok, "mask", 4)) 10982 { 10983 /* We've found a "mask" token, which means the user wants to 10984 create a hardware watchpoint that is going to have the mask 10985 facility. */ 10986 struct value *mask_value, *mark; 10987 10988 if (use_mask) 10989 error(_("You can specify only one mask.")); 10990 10991 use_mask = just_location = 1; 10992 10993 mark = value_mark (); 10994 mask_value = parse_to_comma_and_eval (&value_start); 10995 mask = value_as_address (mask_value); 10996 value_free_to_mark (mark); 10997 } 10998 else 10999 /* We didn't recognize what we found. We should stop here. */ 11000 break; 11001 11002 /* Truncate the string and get rid of the "parameter value" pair before 11003 the arguments string is parsed by the parse_exp_1 function. */ 11004 exp_end = tok; 11005 } 11006 } 11007 else 11008 exp_end = arg; 11009 11010 /* Parse the rest of the arguments. From here on out, everything 11011 is in terms of a newly allocated string instead of the original 11012 ARG. */ 11013 innermost_block = NULL; 11014 expression = savestring (arg, exp_end - arg); 11015 back_to = make_cleanup (xfree, expression); 11016 exp_start = arg = expression; 11017 exp = parse_exp_1 (&arg, 0, 0, 0); 11018 exp_end = arg; 11019 /* Remove trailing whitespace from the expression before saving it. 11020 This makes the eventual display of the expression string a bit 11021 prettier. */ 11022 while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) 11023 --exp_end; 11024 11025 /* Checking if the expression is not constant. */ 11026 if (watchpoint_exp_is_const (exp)) 11027 { 11028 int len; 11029 11030 len = exp_end - exp_start; 11031 while (len > 0 && isspace (exp_start[len - 1])) 11032 len--; 11033 error (_("Cannot watch constant value `%.*s'."), len, exp_start); 11034 } 11035 11036 exp_valid_block = innermost_block; 11037 mark = value_mark (); 11038 fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); 11039 11040 if (just_location) 11041 { 11042 int ret; 11043 11044 exp_valid_block = NULL; 11045 val = value_addr (result); 11046 release_value (val); 11047 value_free_to_mark (mark); 11048 11049 if (use_mask) 11050 { 11051 ret = target_masked_watch_num_registers (value_as_address (val), 11052 mask); 11053 if (ret == -1) 11054 error (_("This target does not support masked watchpoints.")); 11055 else if (ret == -2) 11056 error (_("Invalid mask or memory region.")); 11057 } 11058 } 11059 else if (val != NULL) 11060 release_value (val); 11061 11062 tok = skip_spaces_const (arg); 11063 end_tok = skip_to_space_const (tok); 11064 11065 toklen = end_tok - tok; 11066 if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) 11067 { 11068 struct expression *cond; 11069 11070 innermost_block = NULL; 11071 tok = cond_start = end_tok + 1; 11072 cond = parse_exp_1 (&tok, 0, 0, 0); 11073 11074 /* The watchpoint expression may not be local, but the condition 11075 may still be. E.g.: `watch global if local > 0'. */ 11076 cond_exp_valid_block = innermost_block; 11077 11078 xfree (cond); 11079 cond_end = tok; 11080 } 11081 if (*tok) 11082 error (_("Junk at end of command.")); 11083 11084 if (accessflag == hw_read) 11085 bp_type = bp_read_watchpoint; 11086 else if (accessflag == hw_access) 11087 bp_type = bp_access_watchpoint; 11088 else 11089 bp_type = bp_hardware_watchpoint; 11090 11091 frame = block_innermost_frame (exp_valid_block); 11092 11093 /* If the expression is "local", then set up a "watchpoint scope" 11094 breakpoint at the point where we've left the scope of the watchpoint 11095 expression. Create the scope breakpoint before the watchpoint, so 11096 that we will encounter it first in bpstat_stop_status. */ 11097 if (exp_valid_block && frame) 11098 { 11099 if (frame_id_p (frame_unwind_caller_id (frame))) 11100 { 11101 scope_breakpoint 11102 = create_internal_breakpoint (frame_unwind_caller_arch (frame), 11103 frame_unwind_caller_pc (frame), 11104 bp_watchpoint_scope, 11105 &momentary_breakpoint_ops); 11106 11107 scope_breakpoint->enable_state = bp_enabled; 11108 11109 /* Automatically delete the breakpoint when it hits. */ 11110 scope_breakpoint->disposition = disp_del; 11111 11112 /* Only break in the proper frame (help with recursion). */ 11113 scope_breakpoint->frame_id = frame_unwind_caller_id (frame); 11114 11115 /* Set the address at which we will stop. */ 11116 scope_breakpoint->loc->gdbarch 11117 = frame_unwind_caller_arch (frame); 11118 scope_breakpoint->loc->requested_address 11119 = frame_unwind_caller_pc (frame); 11120 scope_breakpoint->loc->address 11121 = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, 11122 scope_breakpoint->loc->requested_address, 11123 scope_breakpoint->type); 11124 } 11125 } 11126 11127 /* Now set up the breakpoint. */ 11128 11129 w = XCNEW (struct watchpoint); 11130 b = &w->base; 11131 if (use_mask) 11132 init_raw_breakpoint_without_location (b, NULL, bp_type, 11133 &masked_watchpoint_breakpoint_ops); 11134 else 11135 init_raw_breakpoint_without_location (b, NULL, bp_type, 11136 &watchpoint_breakpoint_ops); 11137 b->thread = thread; 11138 b->disposition = disp_donttouch; 11139 b->pspace = current_program_space; 11140 w->exp = exp; 11141 w->exp_valid_block = exp_valid_block; 11142 w->cond_exp_valid_block = cond_exp_valid_block; 11143 if (just_location) 11144 { 11145 struct type *t = value_type (val); 11146 CORE_ADDR addr = value_as_address (val); 11147 char *name; 11148 11149 t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); 11150 name = type_to_string (t); 11151 11152 w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, 11153 core_addr_to_string (addr)); 11154 xfree (name); 11155 11156 w->exp_string = xstrprintf ("-location %.*s", 11157 (int) (exp_end - exp_start), exp_start); 11158 11159 /* The above expression is in C. */ 11160 b->language = language_c; 11161 } 11162 else 11163 w->exp_string = savestring (exp_start, exp_end - exp_start); 11164 11165 if (use_mask) 11166 { 11167 w->hw_wp_mask = mask; 11168 } 11169 else 11170 { 11171 w->val = val; 11172 w->val_valid = 1; 11173 } 11174 11175 if (cond_start) 11176 b->cond_string = savestring (cond_start, cond_end - cond_start); 11177 else 11178 b->cond_string = 0; 11179 11180 if (frame) 11181 { 11182 w->watchpoint_frame = get_frame_id (frame); 11183 w->watchpoint_thread = inferior_ptid; 11184 } 11185 else 11186 { 11187 w->watchpoint_frame = null_frame_id; 11188 w->watchpoint_thread = null_ptid; 11189 } 11190 11191 if (scope_breakpoint != NULL) 11192 { 11193 /* The scope breakpoint is related to the watchpoint. We will 11194 need to act on them together. */ 11195 b->related_breakpoint = scope_breakpoint; 11196 scope_breakpoint->related_breakpoint = b; 11197 } 11198 11199 if (!just_location) 11200 value_free_to_mark (mark); 11201 11202 TRY_CATCH (e, RETURN_MASK_ALL) 11203 { 11204 /* Finally update the new watchpoint. This creates the locations 11205 that should be inserted. */ 11206 update_watchpoint (w, 1); 11207 } 11208 if (e.reason < 0) 11209 { 11210 delete_breakpoint (b); 11211 throw_exception (e); 11212 } 11213 11214 install_breakpoint (internal, b, 1); 11215 do_cleanups (back_to); 11216 } 11217 11218 /* Return count of debug registers needed to watch the given expression. 11219 If the watchpoint cannot be handled in hardware return zero. */ 11220 11221 static int 11222 can_use_hardware_watchpoint (struct value *v) 11223 { 11224 int found_memory_cnt = 0; 11225 struct value *head = v; 11226 11227 /* Did the user specifically forbid us to use hardware watchpoints? */ 11228 if (!can_use_hw_watchpoints) 11229 return 0; 11230 11231 /* Make sure that the value of the expression depends only upon 11232 memory contents, and values computed from them within GDB. If we 11233 find any register references or function calls, we can't use a 11234 hardware watchpoint. 11235 11236 The idea here is that evaluating an expression generates a series 11237 of values, one holding the value of every subexpression. (The 11238 expression a*b+c has five subexpressions: a, b, a*b, c, and 11239 a*b+c.) GDB's values hold almost enough information to establish 11240 the criteria given above --- they identify memory lvalues, 11241 register lvalues, computed values, etcetera. So we can evaluate 11242 the expression, and then scan the chain of values that leaves 11243 behind to decide whether we can detect any possible change to the 11244 expression's final value using only hardware watchpoints. 11245 11246 However, I don't think that the values returned by inferior 11247 function calls are special in any way. So this function may not 11248 notice that an expression involving an inferior function call 11249 can't be watched with hardware watchpoints. FIXME. */ 11250 for (; v; v = value_next (v)) 11251 { 11252 if (VALUE_LVAL (v) == lval_memory) 11253 { 11254 if (v != head && value_lazy (v)) 11255 /* A lazy memory lvalue in the chain is one that GDB never 11256 needed to fetch; we either just used its address (e.g., 11257 `a' in `a.b') or we never needed it at all (e.g., `a' 11258 in `a,b'). This doesn't apply to HEAD; if that is 11259 lazy then it was not readable, but watch it anyway. */ 11260 ; 11261 else 11262 { 11263 /* Ahh, memory we actually used! Check if we can cover 11264 it with hardware watchpoints. */ 11265 struct type *vtype = check_typedef (value_type (v)); 11266 11267 /* We only watch structs and arrays if user asked for it 11268 explicitly, never if they just happen to appear in a 11269 middle of some value chain. */ 11270 if (v == head 11271 || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT 11272 && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) 11273 { 11274 CORE_ADDR vaddr = value_address (v); 11275 int len; 11276 int num_regs; 11277 11278 len = (target_exact_watchpoints 11279 && is_scalar_type_recursive (vtype))? 11280 1 : TYPE_LENGTH (value_type (v)); 11281 11282 num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); 11283 if (!num_regs) 11284 return 0; 11285 else 11286 found_memory_cnt += num_regs; 11287 } 11288 } 11289 } 11290 else if (VALUE_LVAL (v) != not_lval 11291 && deprecated_value_modifiable (v) == 0) 11292 return 0; /* These are values from the history (e.g., $1). */ 11293 else if (VALUE_LVAL (v) == lval_register) 11294 return 0; /* Cannot watch a register with a HW watchpoint. */ 11295 } 11296 11297 /* The expression itself looks suitable for using a hardware 11298 watchpoint, but give the target machine a chance to reject it. */ 11299 return found_memory_cnt; 11300 } 11301 11302 void 11303 watch_command_wrapper (char *arg, int from_tty, int internal) 11304 { 11305 watch_command_1 (arg, hw_write, from_tty, 0, internal); 11306 } 11307 11308 /* A helper function that looks for the "-location" argument and then 11309 calls watch_command_1. */ 11310 11311 static void 11312 watch_maybe_just_location (char *arg, int accessflag, int from_tty) 11313 { 11314 int just_location = 0; 11315 11316 if (arg 11317 && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) 11318 || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) 11319 { 11320 arg = skip_spaces (arg); 11321 just_location = 1; 11322 } 11323 11324 watch_command_1 (arg, accessflag, from_tty, just_location, 0); 11325 } 11326 11327 static void 11328 watch_command (char *arg, int from_tty) 11329 { 11330 watch_maybe_just_location (arg, hw_write, from_tty); 11331 } 11332 11333 void 11334 rwatch_command_wrapper (char *arg, int from_tty, int internal) 11335 { 11336 watch_command_1 (arg, hw_read, from_tty, 0, internal); 11337 } 11338 11339 static void 11340 rwatch_command (char *arg, int from_tty) 11341 { 11342 watch_maybe_just_location (arg, hw_read, from_tty); 11343 } 11344 11345 void 11346 awatch_command_wrapper (char *arg, int from_tty, int internal) 11347 { 11348 watch_command_1 (arg, hw_access, from_tty, 0, internal); 11349 } 11350 11351 static void 11352 awatch_command (char *arg, int from_tty) 11353 { 11354 watch_maybe_just_location (arg, hw_access, from_tty); 11355 } 11356 11357 11358 /* Helper routines for the until_command routine in infcmd.c. Here 11359 because it uses the mechanisms of breakpoints. */ 11360 11361 struct until_break_command_continuation_args 11362 { 11363 struct breakpoint *breakpoint; 11364 struct breakpoint *breakpoint2; 11365 int thread_num; 11366 }; 11367 11368 /* This function is called by fetch_inferior_event via the 11369 cmd_continuation pointer, to complete the until command. It takes 11370 care of cleaning up the temporary breakpoints set up by the until 11371 command. */ 11372 static void 11373 until_break_command_continuation (void *arg, int err) 11374 { 11375 struct until_break_command_continuation_args *a = arg; 11376 11377 delete_breakpoint (a->breakpoint); 11378 if (a->breakpoint2) 11379 delete_breakpoint (a->breakpoint2); 11380 delete_longjmp_breakpoint (a->thread_num); 11381 } 11382 11383 void 11384 until_break_command (char *arg, int from_tty, int anywhere) 11385 { 11386 struct symtabs_and_lines sals; 11387 struct symtab_and_line sal; 11388 struct frame_info *frame; 11389 struct gdbarch *frame_gdbarch; 11390 struct frame_id stack_frame_id; 11391 struct frame_id caller_frame_id; 11392 struct breakpoint *breakpoint; 11393 struct breakpoint *breakpoint2 = NULL; 11394 struct cleanup *old_chain; 11395 int thread; 11396 struct thread_info *tp; 11397 11398 clear_proceed_status (); 11399 11400 /* Set a breakpoint where the user wants it and at return from 11401 this function. */ 11402 11403 if (last_displayed_sal_is_valid ()) 11404 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, 11405 get_last_displayed_symtab (), 11406 get_last_displayed_line ()); 11407 else 11408 sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, 11409 (struct symtab *) NULL, 0); 11410 11411 if (sals.nelts != 1) 11412 error (_("Couldn't get information on specified line.")); 11413 11414 sal = sals.sals[0]; 11415 xfree (sals.sals); /* malloc'd, so freed. */ 11416 11417 if (*arg) 11418 error (_("Junk at end of arguments.")); 11419 11420 resolve_sal_pc (&sal); 11421 11422 tp = inferior_thread (); 11423 thread = tp->num; 11424 11425 old_chain = make_cleanup (null_cleanup, NULL); 11426 11427 /* Note linespec handling above invalidates the frame chain. 11428 Installing a breakpoint also invalidates the frame chain (as it 11429 may need to switch threads), so do any frame handling before 11430 that. */ 11431 11432 frame = get_selected_frame (NULL); 11433 frame_gdbarch = get_frame_arch (frame); 11434 stack_frame_id = get_stack_frame_id (frame); 11435 caller_frame_id = frame_unwind_caller_id (frame); 11436 11437 /* Keep within the current frame, or in frames called by the current 11438 one. */ 11439 11440 if (frame_id_p (caller_frame_id)) 11441 { 11442 struct symtab_and_line sal2; 11443 11444 sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); 11445 sal2.pc = frame_unwind_caller_pc (frame); 11446 breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), 11447 sal2, 11448 caller_frame_id, 11449 bp_until); 11450 make_cleanup_delete_breakpoint (breakpoint2); 11451 11452 set_longjmp_breakpoint (tp, caller_frame_id); 11453 make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); 11454 } 11455 11456 /* set_momentary_breakpoint could invalidate FRAME. */ 11457 frame = NULL; 11458 11459 if (anywhere) 11460 /* If the user told us to continue until a specified location, 11461 we don't specify a frame at which we need to stop. */ 11462 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, 11463 null_frame_id, bp_until); 11464 else 11465 /* Otherwise, specify the selected frame, because we want to stop 11466 only at the very same frame. */ 11467 breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, 11468 stack_frame_id, bp_until); 11469 make_cleanup_delete_breakpoint (breakpoint); 11470 11471 proceed (-1, GDB_SIGNAL_DEFAULT, 0); 11472 11473 /* If we are running asynchronously, and proceed call above has 11474 actually managed to start the target, arrange for breakpoints to 11475 be deleted when the target stops. Otherwise, we're already 11476 stopped and delete breakpoints via cleanup chain. */ 11477 11478 if (target_can_async_p () && is_running (inferior_ptid)) 11479 { 11480 struct until_break_command_continuation_args *args; 11481 args = xmalloc (sizeof (*args)); 11482 11483 args->breakpoint = breakpoint; 11484 args->breakpoint2 = breakpoint2; 11485 args->thread_num = thread; 11486 11487 discard_cleanups (old_chain); 11488 add_continuation (inferior_thread (), 11489 until_break_command_continuation, args, 11490 xfree); 11491 } 11492 else 11493 do_cleanups (old_chain); 11494 } 11495 11496 /* This function attempts to parse an optional "if <cond>" clause 11497 from the arg string. If one is not found, it returns NULL. 11498 11499 Else, it returns a pointer to the condition string. (It does not 11500 attempt to evaluate the string against a particular block.) And, 11501 it updates arg to point to the first character following the parsed 11502 if clause in the arg string. */ 11503 11504 char * 11505 ep_parse_optional_if_clause (char **arg) 11506 { 11507 char *cond_string; 11508 11509 if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) 11510 return NULL; 11511 11512 /* Skip the "if" keyword. */ 11513 (*arg) += 2; 11514 11515 /* Skip any extra leading whitespace, and record the start of the 11516 condition string. */ 11517 *arg = skip_spaces (*arg); 11518 cond_string = *arg; 11519 11520 /* Assume that the condition occupies the remainder of the arg 11521 string. */ 11522 (*arg) += strlen (cond_string); 11523 11524 return cond_string; 11525 } 11526 11527 /* Commands to deal with catching events, such as signals, exceptions, 11528 process start/exit, etc. */ 11529 11530 typedef enum 11531 { 11532 catch_fork_temporary, catch_vfork_temporary, 11533 catch_fork_permanent, catch_vfork_permanent 11534 } 11535 catch_fork_kind; 11536 11537 static void 11538 catch_fork_command_1 (char *arg, int from_tty, 11539 struct cmd_list_element *command) 11540 { 11541 struct gdbarch *gdbarch = get_current_arch (); 11542 char *cond_string = NULL; 11543 catch_fork_kind fork_kind; 11544 int tempflag; 11545 11546 fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); 11547 tempflag = (fork_kind == catch_fork_temporary 11548 || fork_kind == catch_vfork_temporary); 11549 11550 if (!arg) 11551 arg = ""; 11552 arg = skip_spaces (arg); 11553 11554 /* The allowed syntax is: 11555 catch [v]fork 11556 catch [v]fork if <cond> 11557 11558 First, check if there's an if clause. */ 11559 cond_string = ep_parse_optional_if_clause (&arg); 11560 11561 if ((*arg != '\0') && !isspace (*arg)) 11562 error (_("Junk at end of arguments.")); 11563 11564 /* If this target supports it, create a fork or vfork catchpoint 11565 and enable reporting of such events. */ 11566 switch (fork_kind) 11567 { 11568 case catch_fork_temporary: 11569 case catch_fork_permanent: 11570 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, 11571 &catch_fork_breakpoint_ops); 11572 break; 11573 case catch_vfork_temporary: 11574 case catch_vfork_permanent: 11575 create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, 11576 &catch_vfork_breakpoint_ops); 11577 break; 11578 default: 11579 error (_("unsupported or unknown fork kind; cannot catch it")); 11580 break; 11581 } 11582 } 11583 11584 static void 11585 catch_exec_command_1 (char *arg, int from_tty, 11586 struct cmd_list_element *command) 11587 { 11588 struct exec_catchpoint *c; 11589 struct gdbarch *gdbarch = get_current_arch (); 11590 int tempflag; 11591 char *cond_string = NULL; 11592 11593 tempflag = get_cmd_context (command) == CATCH_TEMPORARY; 11594 11595 if (!arg) 11596 arg = ""; 11597 arg = skip_spaces (arg); 11598 11599 /* The allowed syntax is: 11600 catch exec 11601 catch exec if <cond> 11602 11603 First, check if there's an if clause. */ 11604 cond_string = ep_parse_optional_if_clause (&arg); 11605 11606 if ((*arg != '\0') && !isspace (*arg)) 11607 error (_("Junk at end of arguments.")); 11608 11609 c = XNEW (struct exec_catchpoint); 11610 init_catchpoint (&c->base, gdbarch, tempflag, cond_string, 11611 &catch_exec_breakpoint_ops); 11612 c->exec_pathname = NULL; 11613 11614 install_breakpoint (0, &c->base, 1); 11615 } 11616 11617 void 11618 init_ada_exception_breakpoint (struct breakpoint *b, 11619 struct gdbarch *gdbarch, 11620 struct symtab_and_line sal, 11621 char *addr_string, 11622 const struct breakpoint_ops *ops, 11623 int tempflag, 11624 int enabled, 11625 int from_tty) 11626 { 11627 if (from_tty) 11628 { 11629 struct gdbarch *loc_gdbarch = get_sal_arch (sal); 11630 if (!loc_gdbarch) 11631 loc_gdbarch = gdbarch; 11632 11633 describe_other_breakpoints (loc_gdbarch, 11634 sal.pspace, sal.pc, sal.section, -1); 11635 /* FIXME: brobecker/2006-12-28: Actually, re-implement a special 11636 version for exception catchpoints, because two catchpoints 11637 used for different exception names will use the same address. 11638 In this case, a "breakpoint ... also set at..." warning is 11639 unproductive. Besides, the warning phrasing is also a bit 11640 inappropriate, we should use the word catchpoint, and tell 11641 the user what type of catchpoint it is. The above is good 11642 enough for now, though. */ 11643 } 11644 11645 init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); 11646 11647 b->enable_state = enabled ? bp_enabled : bp_disabled; 11648 b->disposition = tempflag ? disp_del : disp_donttouch; 11649 b->addr_string = addr_string; 11650 b->language = language_ada; 11651 } 11652 11653 /* Splits the argument using space as delimiter. Returns an xmalloc'd 11654 filter list, or NULL if no filtering is required. */ 11655 static VEC(int) * 11656 catch_syscall_split_args (char *arg) 11657 { 11658 VEC(int) *result = NULL; 11659 struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); 11660 11661 while (*arg != '\0') 11662 { 11663 int i, syscall_number; 11664 char *endptr; 11665 char cur_name[128]; 11666 struct syscall s; 11667 11668 /* Skip whitespace. */ 11669 arg = skip_spaces (arg); 11670 11671 for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) 11672 cur_name[i] = arg[i]; 11673 cur_name[i] = '\0'; 11674 arg += i; 11675 11676 /* Check if the user provided a syscall name or a number. */ 11677 syscall_number = (int) strtol (cur_name, &endptr, 0); 11678 if (*endptr == '\0') 11679 get_syscall_by_number (syscall_number, &s); 11680 else 11681 { 11682 /* We have a name. Let's check if it's valid and convert it 11683 to a number. */ 11684 get_syscall_by_name (cur_name, &s); 11685 11686 if (s.number == UNKNOWN_SYSCALL) 11687 /* Here we have to issue an error instead of a warning, 11688 because GDB cannot do anything useful if there's no 11689 syscall number to be caught. */ 11690 error (_("Unknown syscall name '%s'."), cur_name); 11691 } 11692 11693 /* Ok, it's valid. */ 11694 VEC_safe_push (int, result, s.number); 11695 } 11696 11697 discard_cleanups (cleanup); 11698 return result; 11699 } 11700 11701 /* Implement the "catch syscall" command. */ 11702 11703 static void 11704 catch_syscall_command_1 (char *arg, int from_tty, 11705 struct cmd_list_element *command) 11706 { 11707 int tempflag; 11708 VEC(int) *filter; 11709 struct syscall s; 11710 struct gdbarch *gdbarch = get_current_arch (); 11711 11712 /* Checking if the feature if supported. */ 11713 if (gdbarch_get_syscall_number_p (gdbarch) == 0) 11714 error (_("The feature 'catch syscall' is not supported on \ 11715 this architecture yet.")); 11716 11717 tempflag = get_cmd_context (command) == CATCH_TEMPORARY; 11718 11719 arg = skip_spaces (arg); 11720 11721 /* We need to do this first "dummy" translation in order 11722 to get the syscall XML file loaded or, most important, 11723 to display a warning to the user if there's no XML file 11724 for his/her architecture. */ 11725 get_syscall_by_number (0, &s); 11726 11727 /* The allowed syntax is: 11728 catch syscall 11729 catch syscall <name | number> [<name | number> ... <name | number>] 11730 11731 Let's check if there's a syscall name. */ 11732 11733 if (arg != NULL) 11734 filter = catch_syscall_split_args (arg); 11735 else 11736 filter = NULL; 11737 11738 create_syscall_event_catchpoint (tempflag, filter, 11739 &catch_syscall_breakpoint_ops); 11740 } 11741 11742 static void 11743 catch_command (char *arg, int from_tty) 11744 { 11745 error (_("Catch requires an event name.")); 11746 } 11747 11748 11749 static void 11750 tcatch_command (char *arg, int from_tty) 11751 { 11752 error (_("Catch requires an event name.")); 11753 } 11754 11755 /* A qsort comparison function that sorts breakpoints in order. */ 11756 11757 static int 11758 compare_breakpoints (const void *a, const void *b) 11759 { 11760 const breakpoint_p *ba = a; 11761 uintptr_t ua = (uintptr_t) *ba; 11762 const breakpoint_p *bb = b; 11763 uintptr_t ub = (uintptr_t) *bb; 11764 11765 if ((*ba)->number < (*bb)->number) 11766 return -1; 11767 else if ((*ba)->number > (*bb)->number) 11768 return 1; 11769 11770 /* Now sort by address, in case we see, e..g, two breakpoints with 11771 the number 0. */ 11772 if (ua < ub) 11773 return -1; 11774 return ua > ub ? 1 : 0; 11775 } 11776 11777 /* Delete breakpoints by address or line. */ 11778 11779 static void 11780 clear_command (char *arg, int from_tty) 11781 { 11782 struct breakpoint *b, *prev; 11783 VEC(breakpoint_p) *found = 0; 11784 int ix; 11785 int default_match; 11786 struct symtabs_and_lines sals; 11787 struct symtab_and_line sal; 11788 int i; 11789 struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); 11790 11791 if (arg) 11792 { 11793 sals = decode_line_with_current_source (arg, 11794 (DECODE_LINE_FUNFIRSTLINE 11795 | DECODE_LINE_LIST_MODE)); 11796 make_cleanup (xfree, sals.sals); 11797 default_match = 0; 11798 } 11799 else 11800 { 11801 sals.sals = (struct symtab_and_line *) 11802 xmalloc (sizeof (struct symtab_and_line)); 11803 make_cleanup (xfree, sals.sals); 11804 init_sal (&sal); /* Initialize to zeroes. */ 11805 11806 /* Set sal's line, symtab, pc, and pspace to the values 11807 corresponding to the last call to print_frame_info. If the 11808 codepoint is not valid, this will set all the fields to 0. */ 11809 get_last_displayed_sal (&sal); 11810 if (sal.symtab == 0) 11811 error (_("No source file specified.")); 11812 11813 sals.sals[0] = sal; 11814 sals.nelts = 1; 11815 11816 default_match = 1; 11817 } 11818 11819 /* We don't call resolve_sal_pc here. That's not as bad as it 11820 seems, because all existing breakpoints typically have both 11821 file/line and pc set. So, if clear is given file/line, we can 11822 match this to existing breakpoint without obtaining pc at all. 11823 11824 We only support clearing given the address explicitly 11825 present in breakpoint table. Say, we've set breakpoint 11826 at file:line. There were several PC values for that file:line, 11827 due to optimization, all in one block. 11828 11829 We've picked one PC value. If "clear" is issued with another 11830 PC corresponding to the same file:line, the breakpoint won't 11831 be cleared. We probably can still clear the breakpoint, but 11832 since the other PC value is never presented to user, user 11833 can only find it by guessing, and it does not seem important 11834 to support that. */ 11835 11836 /* For each line spec given, delete bps which correspond to it. Do 11837 it in two passes, solely to preserve the current behavior that 11838 from_tty is forced true if we delete more than one 11839 breakpoint. */ 11840 11841 found = NULL; 11842 make_cleanup (VEC_cleanup (breakpoint_p), &found); 11843 for (i = 0; i < sals.nelts; i++) 11844 { 11845 const char *sal_fullname; 11846 11847 /* If exact pc given, clear bpts at that pc. 11848 If line given (pc == 0), clear all bpts on specified line. 11849 If defaulting, clear all bpts on default line 11850 or at default pc. 11851 11852 defaulting sal.pc != 0 tests to do 11853 11854 0 1 pc 11855 1 1 pc _and_ line 11856 0 0 line 11857 1 0 <can't happen> */ 11858 11859 sal = sals.sals[i]; 11860 sal_fullname = (sal.symtab == NULL 11861 ? NULL : symtab_to_fullname (sal.symtab)); 11862 11863 /* Find all matching breakpoints and add them to 'found'. */ 11864 ALL_BREAKPOINTS (b) 11865 { 11866 int match = 0; 11867 /* Are we going to delete b? */ 11868 if (b->type != bp_none && !is_watchpoint (b)) 11869 { 11870 struct bp_location *loc = b->loc; 11871 for (; loc; loc = loc->next) 11872 { 11873 /* If the user specified file:line, don't allow a PC 11874 match. This matches historical gdb behavior. */ 11875 int pc_match = (!sal.explicit_line 11876 && sal.pc 11877 && (loc->pspace == sal.pspace) 11878 && (loc->address == sal.pc) 11879 && (!section_is_overlay (loc->section) 11880 || loc->section == sal.section)); 11881 int line_match = 0; 11882 11883 if ((default_match || sal.explicit_line) 11884 && loc->symtab != NULL 11885 && sal_fullname != NULL 11886 && sal.pspace == loc->pspace 11887 && loc->line_number == sal.line 11888 && filename_cmp (symtab_to_fullname (loc->symtab), 11889 sal_fullname) == 0) 11890 line_match = 1; 11891 11892 if (pc_match || line_match) 11893 { 11894 match = 1; 11895 break; 11896 } 11897 } 11898 } 11899 11900 if (match) 11901 VEC_safe_push(breakpoint_p, found, b); 11902 } 11903 } 11904 11905 /* Now go thru the 'found' chain and delete them. */ 11906 if (VEC_empty(breakpoint_p, found)) 11907 { 11908 if (arg) 11909 error (_("No breakpoint at %s."), arg); 11910 else 11911 error (_("No breakpoint at this line.")); 11912 } 11913 11914 /* Remove duplicates from the vec. */ 11915 qsort (VEC_address (breakpoint_p, found), 11916 VEC_length (breakpoint_p, found), 11917 sizeof (breakpoint_p), 11918 compare_breakpoints); 11919 prev = VEC_index (breakpoint_p, found, 0); 11920 for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) 11921 { 11922 if (b == prev) 11923 { 11924 VEC_ordered_remove (breakpoint_p, found, ix); 11925 --ix; 11926 } 11927 } 11928 11929 if (VEC_length(breakpoint_p, found) > 1) 11930 from_tty = 1; /* Always report if deleted more than one. */ 11931 if (from_tty) 11932 { 11933 if (VEC_length(breakpoint_p, found) == 1) 11934 printf_unfiltered (_("Deleted breakpoint ")); 11935 else 11936 printf_unfiltered (_("Deleted breakpoints ")); 11937 } 11938 11939 for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) 11940 { 11941 if (from_tty) 11942 printf_unfiltered ("%d ", b->number); 11943 delete_breakpoint (b); 11944 } 11945 if (from_tty) 11946 putchar_unfiltered ('\n'); 11947 11948 do_cleanups (cleanups); 11949 } 11950 11951 /* Delete breakpoint in BS if they are `delete' breakpoints and 11952 all breakpoints that are marked for deletion, whether hit or not. 11953 This is called after any breakpoint is hit, or after errors. */ 11954 11955 void 11956 breakpoint_auto_delete (bpstat bs) 11957 { 11958 struct breakpoint *b, *b_tmp; 11959 11960 for (; bs; bs = bs->next) 11961 if (bs->breakpoint_at 11962 && bs->breakpoint_at->disposition == disp_del 11963 && bs->stop) 11964 delete_breakpoint (bs->breakpoint_at); 11965 11966 ALL_BREAKPOINTS_SAFE (b, b_tmp) 11967 { 11968 if (b->disposition == disp_del_at_next_stop) 11969 delete_breakpoint (b); 11970 } 11971 } 11972 11973 /* A comparison function for bp_location AP and BP being interfaced to 11974 qsort. Sort elements primarily by their ADDRESS (no matter what 11975 does breakpoint_address_is_meaningful say for its OWNER), 11976 secondarily by ordering first bp_permanent OWNERed elements and 11977 terciarily just ensuring the array is sorted stable way despite 11978 qsort being an unstable algorithm. */ 11979 11980 static int 11981 bp_location_compare (const void *ap, const void *bp) 11982 { 11983 struct bp_location *a = *(void **) ap; 11984 struct bp_location *b = *(void **) bp; 11985 /* A and B come from existing breakpoints having non-NULL OWNER. */ 11986 int a_perm = a->owner->enable_state == bp_permanent; 11987 int b_perm = b->owner->enable_state == bp_permanent; 11988 11989 if (a->address != b->address) 11990 return (a->address > b->address) - (a->address < b->address); 11991 11992 /* Sort locations at the same address by their pspace number, keeping 11993 locations of the same inferior (in a multi-inferior environment) 11994 grouped. */ 11995 11996 if (a->pspace->num != b->pspace->num) 11997 return ((a->pspace->num > b->pspace->num) 11998 - (a->pspace->num < b->pspace->num)); 11999 12000 /* Sort permanent breakpoints first. */ 12001 if (a_perm != b_perm) 12002 return (a_perm < b_perm) - (a_perm > b_perm); 12003 12004 /* Make the internal GDB representation stable across GDB runs 12005 where A and B memory inside GDB can differ. Breakpoint locations of 12006 the same type at the same address can be sorted in arbitrary order. */ 12007 12008 if (a->owner->number != b->owner->number) 12009 return ((a->owner->number > b->owner->number) 12010 - (a->owner->number < b->owner->number)); 12011 12012 return (a > b) - (a < b); 12013 } 12014 12015 /* Set bp_location_placed_address_before_address_max and 12016 bp_location_shadow_len_after_address_max according to the current 12017 content of the bp_location array. */ 12018 12019 static void 12020 bp_location_target_extensions_update (void) 12021 { 12022 struct bp_location *bl, **blp_tmp; 12023 12024 bp_location_placed_address_before_address_max = 0; 12025 bp_location_shadow_len_after_address_max = 0; 12026 12027 ALL_BP_LOCATIONS (bl, blp_tmp) 12028 { 12029 CORE_ADDR start, end, addr; 12030 12031 if (!bp_location_has_shadow (bl)) 12032 continue; 12033 12034 start = bl->target_info.placed_address; 12035 end = start + bl->target_info.shadow_len; 12036 12037 gdb_assert (bl->address >= start); 12038 addr = bl->address - start; 12039 if (addr > bp_location_placed_address_before_address_max) 12040 bp_location_placed_address_before_address_max = addr; 12041 12042 /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ 12043 12044 gdb_assert (bl->address < end); 12045 addr = end - bl->address; 12046 if (addr > bp_location_shadow_len_after_address_max) 12047 bp_location_shadow_len_after_address_max = addr; 12048 } 12049 } 12050 12051 /* Download tracepoint locations if they haven't been. */ 12052 12053 static void 12054 download_tracepoint_locations (void) 12055 { 12056 struct breakpoint *b; 12057 struct cleanup *old_chain; 12058 12059 if (!target_can_download_tracepoint ()) 12060 return; 12061 12062 old_chain = save_current_space_and_thread (); 12063 12064 ALL_TRACEPOINTS (b) 12065 { 12066 struct bp_location *bl; 12067 struct tracepoint *t; 12068 int bp_location_downloaded = 0; 12069 12070 if ((b->type == bp_fast_tracepoint 12071 ? !may_insert_fast_tracepoints 12072 : !may_insert_tracepoints)) 12073 continue; 12074 12075 for (bl = b->loc; bl; bl = bl->next) 12076 { 12077 /* In tracepoint, locations are _never_ duplicated, so 12078 should_be_inserted is equivalent to 12079 unduplicated_should_be_inserted. */ 12080 if (!should_be_inserted (bl) || bl->inserted) 12081 continue; 12082 12083 switch_to_program_space_and_thread (bl->pspace); 12084 12085 target_download_tracepoint (bl); 12086 12087 bl->inserted = 1; 12088 bp_location_downloaded = 1; 12089 } 12090 t = (struct tracepoint *) b; 12091 t->number_on_target = b->number; 12092 if (bp_location_downloaded) 12093 observer_notify_breakpoint_modified (b); 12094 } 12095 12096 do_cleanups (old_chain); 12097 } 12098 12099 /* Swap the insertion/duplication state between two locations. */ 12100 12101 static void 12102 swap_insertion (struct bp_location *left, struct bp_location *right) 12103 { 12104 const int left_inserted = left->inserted; 12105 const int left_duplicate = left->duplicate; 12106 const int left_needs_update = left->needs_update; 12107 const struct bp_target_info left_target_info = left->target_info; 12108 12109 /* Locations of tracepoints can never be duplicated. */ 12110 if (is_tracepoint (left->owner)) 12111 gdb_assert (!left->duplicate); 12112 if (is_tracepoint (right->owner)) 12113 gdb_assert (!right->duplicate); 12114 12115 left->inserted = right->inserted; 12116 left->duplicate = right->duplicate; 12117 left->needs_update = right->needs_update; 12118 left->target_info = right->target_info; 12119 right->inserted = left_inserted; 12120 right->duplicate = left_duplicate; 12121 right->needs_update = left_needs_update; 12122 right->target_info = left_target_info; 12123 } 12124 12125 /* Force the re-insertion of the locations at ADDRESS. This is called 12126 once a new/deleted/modified duplicate location is found and we are evaluating 12127 conditions on the target's side. Such conditions need to be updated on 12128 the target. */ 12129 12130 static void 12131 force_breakpoint_reinsertion (struct bp_location *bl) 12132 { 12133 struct bp_location **locp = NULL, **loc2p; 12134 struct bp_location *loc; 12135 CORE_ADDR address = 0; 12136 int pspace_num; 12137 12138 address = bl->address; 12139 pspace_num = bl->pspace->num; 12140 12141 /* This is only meaningful if the target is 12142 evaluating conditions and if the user has 12143 opted for condition evaluation on the target's 12144 side. */ 12145 if (gdb_evaluates_breakpoint_condition_p () 12146 || !target_supports_evaluation_of_breakpoint_conditions ()) 12147 return; 12148 12149 /* Flag all breakpoint locations with this address and 12150 the same program space as the location 12151 as "its condition has changed". We need to 12152 update the conditions on the target's side. */ 12153 ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) 12154 { 12155 loc = *loc2p; 12156 12157 if (!is_breakpoint (loc->owner) 12158 || pspace_num != loc->pspace->num) 12159 continue; 12160 12161 /* Flag the location appropriately. We use a different state to 12162 let everyone know that we already updated the set of locations 12163 with addr bl->address and program space bl->pspace. This is so 12164 we don't have to keep calling these functions just to mark locations 12165 that have already been marked. */ 12166 loc->condition_changed = condition_updated; 12167 12168 /* Free the agent expression bytecode as well. We will compute 12169 it later on. */ 12170 if (loc->cond_bytecode) 12171 { 12172 free_agent_expr (loc->cond_bytecode); 12173 loc->cond_bytecode = NULL; 12174 } 12175 } 12176 } 12177 12178 /* If SHOULD_INSERT is false, do not insert any breakpoint locations 12179 into the inferior, only remove already-inserted locations that no 12180 longer should be inserted. Functions that delete a breakpoint or 12181 breakpoints should pass false, so that deleting a breakpoint 12182 doesn't have the side effect of inserting the locations of other 12183 breakpoints that are marked not-inserted, but should_be_inserted 12184 returns true on them. 12185 12186 This behaviour is useful is situations close to tear-down -- e.g., 12187 after an exec, while the target still has execution, but breakpoint 12188 shadows of the previous executable image should *NOT* be restored 12189 to the new image; or before detaching, where the target still has 12190 execution and wants to delete breakpoints from GDB's lists, and all 12191 breakpoints had already been removed from the inferior. */ 12192 12193 static void 12194 update_global_location_list (int should_insert) 12195 { 12196 struct breakpoint *b; 12197 struct bp_location **locp, *loc; 12198 struct cleanup *cleanups; 12199 /* Last breakpoint location address that was marked for update. */ 12200 CORE_ADDR last_addr = 0; 12201 /* Last breakpoint location program space that was marked for update. */ 12202 int last_pspace_num = -1; 12203 12204 /* Used in the duplicates detection below. When iterating over all 12205 bp_locations, points to the first bp_location of a given address. 12206 Breakpoints and watchpoints of different types are never 12207 duplicates of each other. Keep one pointer for each type of 12208 breakpoint/watchpoint, so we only need to loop over all locations 12209 once. */ 12210 struct bp_location *bp_loc_first; /* breakpoint */ 12211 struct bp_location *wp_loc_first; /* hardware watchpoint */ 12212 struct bp_location *awp_loc_first; /* access watchpoint */ 12213 struct bp_location *rwp_loc_first; /* read watchpoint */ 12214 12215 /* Saved former bp_location array which we compare against the newly 12216 built bp_location from the current state of ALL_BREAKPOINTS. */ 12217 struct bp_location **old_location, **old_locp; 12218 unsigned old_location_count; 12219 12220 old_location = bp_location; 12221 old_location_count = bp_location_count; 12222 bp_location = NULL; 12223 bp_location_count = 0; 12224 cleanups = make_cleanup (xfree, old_location); 12225 12226 ALL_BREAKPOINTS (b) 12227 for (loc = b->loc; loc; loc = loc->next) 12228 bp_location_count++; 12229 12230 bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); 12231 locp = bp_location; 12232 ALL_BREAKPOINTS (b) 12233 for (loc = b->loc; loc; loc = loc->next) 12234 *locp++ = loc; 12235 qsort (bp_location, bp_location_count, sizeof (*bp_location), 12236 bp_location_compare); 12237 12238 bp_location_target_extensions_update (); 12239 12240 /* Identify bp_location instances that are no longer present in the 12241 new list, and therefore should be freed. Note that it's not 12242 necessary that those locations should be removed from inferior -- 12243 if there's another location at the same address (previously 12244 marked as duplicate), we don't need to remove/insert the 12245 location. 12246 12247 LOCP is kept in sync with OLD_LOCP, each pointing to the current 12248 and former bp_location array state respectively. */ 12249 12250 locp = bp_location; 12251 for (old_locp = old_location; old_locp < old_location + old_location_count; 12252 old_locp++) 12253 { 12254 struct bp_location *old_loc = *old_locp; 12255 struct bp_location **loc2p; 12256 12257 /* Tells if 'old_loc' is found among the new locations. If 12258 not, we have to free it. */ 12259 int found_object = 0; 12260 /* Tells if the location should remain inserted in the target. */ 12261 int keep_in_target = 0; 12262 int removed = 0; 12263 12264 /* Skip LOCP entries which will definitely never be needed. 12265 Stop either at or being the one matching OLD_LOC. */ 12266 while (locp < bp_location + bp_location_count 12267 && (*locp)->address < old_loc->address) 12268 locp++; 12269 12270 for (loc2p = locp; 12271 (loc2p < bp_location + bp_location_count 12272 && (*loc2p)->address == old_loc->address); 12273 loc2p++) 12274 { 12275 /* Check if this is a new/duplicated location or a duplicated 12276 location that had its condition modified. If so, we want to send 12277 its condition to the target if evaluation of conditions is taking 12278 place there. */ 12279 if ((*loc2p)->condition_changed == condition_modified 12280 && (last_addr != old_loc->address 12281 || last_pspace_num != old_loc->pspace->num)) 12282 { 12283 force_breakpoint_reinsertion (*loc2p); 12284 last_pspace_num = old_loc->pspace->num; 12285 } 12286 12287 if (*loc2p == old_loc) 12288 found_object = 1; 12289 } 12290 12291 /* We have already handled this address, update it so that we don't 12292 have to go through updates again. */ 12293 last_addr = old_loc->address; 12294 12295 /* Target-side condition evaluation: Handle deleted locations. */ 12296 if (!found_object) 12297 force_breakpoint_reinsertion (old_loc); 12298 12299 /* If this location is no longer present, and inserted, look if 12300 there's maybe a new location at the same address. If so, 12301 mark that one inserted, and don't remove this one. This is 12302 needed so that we don't have a time window where a breakpoint 12303 at certain location is not inserted. */ 12304 12305 if (old_loc->inserted) 12306 { 12307 /* If the location is inserted now, we might have to remove 12308 it. */ 12309 12310 if (found_object && should_be_inserted (old_loc)) 12311 { 12312 /* The location is still present in the location list, 12313 and still should be inserted. Don't do anything. */ 12314 keep_in_target = 1; 12315 } 12316 else 12317 { 12318 /* This location still exists, but it won't be kept in the 12319 target since it may have been disabled. We proceed to 12320 remove its target-side condition. */ 12321 12322 /* The location is either no longer present, or got 12323 disabled. See if there's another location at the 12324 same address, in which case we don't need to remove 12325 this one from the target. */ 12326 12327 /* OLD_LOC comes from existing struct breakpoint. */ 12328 if (breakpoint_address_is_meaningful (old_loc->owner)) 12329 { 12330 for (loc2p = locp; 12331 (loc2p < bp_location + bp_location_count 12332 && (*loc2p)->address == old_loc->address); 12333 loc2p++) 12334 { 12335 struct bp_location *loc2 = *loc2p; 12336 12337 if (breakpoint_locations_match (loc2, old_loc)) 12338 { 12339 /* Read watchpoint locations are switched to 12340 access watchpoints, if the former are not 12341 supported, but the latter are. */ 12342 if (is_hardware_watchpoint (old_loc->owner)) 12343 { 12344 gdb_assert (is_hardware_watchpoint (loc2->owner)); 12345 loc2->watchpoint_type = old_loc->watchpoint_type; 12346 } 12347 12348 /* loc2 is a duplicated location. We need to check 12349 if it should be inserted in case it will be 12350 unduplicated. */ 12351 if (loc2 != old_loc 12352 && unduplicated_should_be_inserted (loc2)) 12353 { 12354 swap_insertion (old_loc, loc2); 12355 keep_in_target = 1; 12356 break; 12357 } 12358 } 12359 } 12360 } 12361 } 12362 12363 if (!keep_in_target) 12364 { 12365 if (remove_breakpoint (old_loc, mark_uninserted)) 12366 { 12367 /* This is just about all we can do. We could keep 12368 this location on the global list, and try to 12369 remove it next time, but there's no particular 12370 reason why we will succeed next time. 12371 12372 Note that at this point, old_loc->owner is still 12373 valid, as delete_breakpoint frees the breakpoint 12374 only after calling us. */ 12375 printf_filtered (_("warning: Error removing " 12376 "breakpoint %d\n"), 12377 old_loc->owner->number); 12378 } 12379 removed = 1; 12380 } 12381 } 12382 12383 if (!found_object) 12384 { 12385 if (removed && non_stop 12386 && breakpoint_address_is_meaningful (old_loc->owner) 12387 && !is_hardware_watchpoint (old_loc->owner)) 12388 { 12389 /* This location was removed from the target. In 12390 non-stop mode, a race condition is possible where 12391 we've removed a breakpoint, but stop events for that 12392 breakpoint are already queued and will arrive later. 12393 We apply an heuristic to be able to distinguish such 12394 SIGTRAPs from other random SIGTRAPs: we keep this 12395 breakpoint location for a bit, and will retire it 12396 after we see some number of events. The theory here 12397 is that reporting of events should, "on the average", 12398 be fair, so after a while we'll see events from all 12399 threads that have anything of interest, and no longer 12400 need to keep this breakpoint location around. We 12401 don't hold locations forever so to reduce chances of 12402 mistaking a non-breakpoint SIGTRAP for a breakpoint 12403 SIGTRAP. 12404 12405 The heuristic failing can be disastrous on 12406 decr_pc_after_break targets. 12407 12408 On decr_pc_after_break targets, like e.g., x86-linux, 12409 if we fail to recognize a late breakpoint SIGTRAP, 12410 because events_till_retirement has reached 0 too 12411 soon, we'll fail to do the PC adjustment, and report 12412 a random SIGTRAP to the user. When the user resumes 12413 the inferior, it will most likely immediately crash 12414 with SIGILL/SIGBUS/SIGSEGV, or worse, get silently 12415 corrupted, because of being resumed e.g., in the 12416 middle of a multi-byte instruction, or skipped a 12417 one-byte instruction. This was actually seen happen 12418 on native x86-linux, and should be less rare on 12419 targets that do not support new thread events, like 12420 remote, due to the heuristic depending on 12421 thread_count. 12422 12423 Mistaking a random SIGTRAP for a breakpoint trap 12424 causes similar symptoms (PC adjustment applied when 12425 it shouldn't), but then again, playing with SIGTRAPs 12426 behind the debugger's back is asking for trouble. 12427 12428 Since hardware watchpoint traps are always 12429 distinguishable from other traps, so we don't need to 12430 apply keep hardware watchpoint moribund locations 12431 around. We simply always ignore hardware watchpoint 12432 traps we can no longer explain. */ 12433 12434 old_loc->events_till_retirement = 3 * (thread_count () + 1); 12435 old_loc->owner = NULL; 12436 12437 VEC_safe_push (bp_location_p, moribund_locations, old_loc); 12438 } 12439 else 12440 { 12441 old_loc->owner = NULL; 12442 decref_bp_location (&old_loc); 12443 } 12444 } 12445 } 12446 12447 /* Rescan breakpoints at the same address and section, marking the 12448 first one as "first" and any others as "duplicates". This is so 12449 that the bpt instruction is only inserted once. If we have a 12450 permanent breakpoint at the same place as BPT, make that one the 12451 official one, and the rest as duplicates. Permanent breakpoints 12452 are sorted first for the same address. 12453 12454 Do the same for hardware watchpoints, but also considering the 12455 watchpoint's type (regular/access/read) and length. */ 12456 12457 bp_loc_first = NULL; 12458 wp_loc_first = NULL; 12459 awp_loc_first = NULL; 12460 rwp_loc_first = NULL; 12461 ALL_BP_LOCATIONS (loc, locp) 12462 { 12463 /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always 12464 non-NULL. */ 12465 struct bp_location **loc_first_p; 12466 b = loc->owner; 12467 12468 if (!unduplicated_should_be_inserted (loc) 12469 || !breakpoint_address_is_meaningful (b) 12470 /* Don't detect duplicate for tracepoint locations because they are 12471 never duplicated. See the comments in field `duplicate' of 12472 `struct bp_location'. */ 12473 || is_tracepoint (b)) 12474 { 12475 /* Clear the condition modification flag. */ 12476 loc->condition_changed = condition_unchanged; 12477 continue; 12478 } 12479 12480 /* Permanent breakpoint should always be inserted. */ 12481 if (b->enable_state == bp_permanent && ! loc->inserted) 12482 internal_error (__FILE__, __LINE__, 12483 _("allegedly permanent breakpoint is not " 12484 "actually inserted")); 12485 12486 if (b->type == bp_hardware_watchpoint) 12487 loc_first_p = &wp_loc_first; 12488 else if (b->type == bp_read_watchpoint) 12489 loc_first_p = &rwp_loc_first; 12490 else if (b->type == bp_access_watchpoint) 12491 loc_first_p = &awp_loc_first; 12492 else 12493 loc_first_p = &bp_loc_first; 12494 12495 if (*loc_first_p == NULL 12496 || (overlay_debugging && loc->section != (*loc_first_p)->section) 12497 || !breakpoint_locations_match (loc, *loc_first_p)) 12498 { 12499 *loc_first_p = loc; 12500 loc->duplicate = 0; 12501 12502 if (is_breakpoint (loc->owner) && loc->condition_changed) 12503 { 12504 loc->needs_update = 1; 12505 /* Clear the condition modification flag. */ 12506 loc->condition_changed = condition_unchanged; 12507 } 12508 continue; 12509 } 12510 12511 12512 /* This and the above ensure the invariant that the first location 12513 is not duplicated, and is the inserted one. 12514 All following are marked as duplicated, and are not inserted. */ 12515 if (loc->inserted) 12516 swap_insertion (loc, *loc_first_p); 12517 loc->duplicate = 1; 12518 12519 /* Clear the condition modification flag. */ 12520 loc->condition_changed = condition_unchanged; 12521 12522 if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted 12523 && b->enable_state != bp_permanent) 12524 internal_error (__FILE__, __LINE__, 12525 _("another breakpoint was inserted on top of " 12526 "a permanent breakpoint")); 12527 } 12528 12529 if (breakpoints_always_inserted_mode () 12530 && (have_live_inferiors () 12531 || (gdbarch_has_global_breakpoints (target_gdbarch ())))) 12532 { 12533 if (should_insert) 12534 insert_breakpoint_locations (); 12535 else 12536 { 12537 /* Though should_insert is false, we may need to update conditions 12538 on the target's side if it is evaluating such conditions. We 12539 only update conditions for locations that are marked 12540 "needs_update". */ 12541 update_inserted_breakpoint_locations (); 12542 } 12543 } 12544 12545 if (should_insert) 12546 download_tracepoint_locations (); 12547 12548 do_cleanups (cleanups); 12549 } 12550 12551 void 12552 breakpoint_retire_moribund (void) 12553 { 12554 struct bp_location *loc; 12555 int ix; 12556 12557 for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) 12558 if (--(loc->events_till_retirement) == 0) 12559 { 12560 decref_bp_location (&loc); 12561 VEC_unordered_remove (bp_location_p, moribund_locations, ix); 12562 --ix; 12563 } 12564 } 12565 12566 static void 12567 update_global_location_list_nothrow (int inserting) 12568 { 12569 volatile struct gdb_exception e; 12570 12571 TRY_CATCH (e, RETURN_MASK_ERROR) 12572 update_global_location_list (inserting); 12573 } 12574 12575 /* Clear BKP from a BPS. */ 12576 12577 static void 12578 bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) 12579 { 12580 bpstat bs; 12581 12582 for (bs = bps; bs; bs = bs->next) 12583 if (bs->breakpoint_at == bpt) 12584 { 12585 bs->breakpoint_at = NULL; 12586 bs->old_val = NULL; 12587 /* bs->commands will be freed later. */ 12588 } 12589 } 12590 12591 /* Callback for iterate_over_threads. */ 12592 static int 12593 bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) 12594 { 12595 struct breakpoint *bpt = data; 12596 12597 bpstat_remove_bp_location (th->control.stop_bpstat, bpt); 12598 return 0; 12599 } 12600 12601 /* Helper for breakpoint and tracepoint breakpoint_ops->mention 12602 callbacks. */ 12603 12604 static void 12605 say_where (struct breakpoint *b) 12606 { 12607 struct value_print_options opts; 12608 12609 get_user_print_options (&opts); 12610 12611 /* i18n: cagney/2005-02-11: Below needs to be merged into a 12612 single string. */ 12613 if (b->loc == NULL) 12614 { 12615 printf_filtered (_(" (%s) pending."), b->addr_string); 12616 } 12617 else 12618 { 12619 if (opts.addressprint || b->loc->symtab == NULL) 12620 { 12621 printf_filtered (" at "); 12622 fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), 12623 gdb_stdout); 12624 } 12625 if (b->loc->symtab != NULL) 12626 { 12627 /* If there is a single location, we can print the location 12628 more nicely. */ 12629 if (b->loc->next == NULL) 12630 printf_filtered (": file %s, line %d.", 12631 symtab_to_filename_for_display (b->loc->symtab), 12632 b->loc->line_number); 12633 else 12634 /* This is not ideal, but each location may have a 12635 different file name, and this at least reflects the 12636 real situation somewhat. */ 12637 printf_filtered (": %s.", b->addr_string); 12638 } 12639 12640 if (b->loc->next) 12641 { 12642 struct bp_location *loc = b->loc; 12643 int n = 0; 12644 for (; loc; loc = loc->next) 12645 ++n; 12646 printf_filtered (" (%d locations)", n); 12647 } 12648 } 12649 } 12650 12651 /* Default bp_location_ops methods. */ 12652 12653 static void 12654 bp_location_dtor (struct bp_location *self) 12655 { 12656 xfree (self->cond); 12657 if (self->cond_bytecode) 12658 free_agent_expr (self->cond_bytecode); 12659 xfree (self->function_name); 12660 } 12661 12662 static const struct bp_location_ops bp_location_ops = 12663 { 12664 bp_location_dtor 12665 }; 12666 12667 /* Default breakpoint_ops methods all breakpoint_ops ultimately 12668 inherit from. */ 12669 12670 static void 12671 base_breakpoint_dtor (struct breakpoint *self) 12672 { 12673 decref_counted_command_line (&self->commands); 12674 xfree (self->cond_string); 12675 xfree (self->extra_string); 12676 xfree (self->addr_string); 12677 xfree (self->filter); 12678 xfree (self->addr_string_range_end); 12679 } 12680 12681 static struct bp_location * 12682 base_breakpoint_allocate_location (struct breakpoint *self) 12683 { 12684 struct bp_location *loc; 12685 12686 loc = XNEW (struct bp_location); 12687 init_bp_location (loc, &bp_location_ops, self); 12688 return loc; 12689 } 12690 12691 static void 12692 base_breakpoint_re_set (struct breakpoint *b) 12693 { 12694 /* Nothing to re-set. */ 12695 } 12696 12697 #define internal_error_pure_virtual_called() \ 12698 gdb_assert_not_reached ("pure virtual function called") 12699 12700 static int 12701 base_breakpoint_insert_location (struct bp_location *bl) 12702 { 12703 internal_error_pure_virtual_called (); 12704 } 12705 12706 static int 12707 base_breakpoint_remove_location (struct bp_location *bl) 12708 { 12709 internal_error_pure_virtual_called (); 12710 } 12711 12712 static int 12713 base_breakpoint_breakpoint_hit (const struct bp_location *bl, 12714 struct address_space *aspace, 12715 CORE_ADDR bp_addr, 12716 const struct target_waitstatus *ws) 12717 { 12718 internal_error_pure_virtual_called (); 12719 } 12720 12721 static void 12722 base_breakpoint_check_status (bpstat bs) 12723 { 12724 /* Always stop. */ 12725 } 12726 12727 /* A "works_in_software_mode" breakpoint_ops method that just internal 12728 errors. */ 12729 12730 static int 12731 base_breakpoint_works_in_software_mode (const struct breakpoint *b) 12732 { 12733 internal_error_pure_virtual_called (); 12734 } 12735 12736 /* A "resources_needed" breakpoint_ops method that just internal 12737 errors. */ 12738 12739 static int 12740 base_breakpoint_resources_needed (const struct bp_location *bl) 12741 { 12742 internal_error_pure_virtual_called (); 12743 } 12744 12745 static enum print_stop_action 12746 base_breakpoint_print_it (bpstat bs) 12747 { 12748 internal_error_pure_virtual_called (); 12749 } 12750 12751 static void 12752 base_breakpoint_print_one_detail (const struct breakpoint *self, 12753 struct ui_out *uiout) 12754 { 12755 /* nothing */ 12756 } 12757 12758 static void 12759 base_breakpoint_print_mention (struct breakpoint *b) 12760 { 12761 internal_error_pure_virtual_called (); 12762 } 12763 12764 static void 12765 base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) 12766 { 12767 internal_error_pure_virtual_called (); 12768 } 12769 12770 static void 12771 base_breakpoint_create_sals_from_address (char **arg, 12772 struct linespec_result *canonical, 12773 enum bptype type_wanted, 12774 char *addr_start, 12775 char **copy_arg) 12776 { 12777 internal_error_pure_virtual_called (); 12778 } 12779 12780 static void 12781 base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, 12782 struct linespec_result *c, 12783 char *cond_string, 12784 char *extra_string, 12785 enum bptype type_wanted, 12786 enum bpdisp disposition, 12787 int thread, 12788 int task, int ignore_count, 12789 const struct breakpoint_ops *o, 12790 int from_tty, int enabled, 12791 int internal, unsigned flags) 12792 { 12793 internal_error_pure_virtual_called (); 12794 } 12795 12796 static void 12797 base_breakpoint_decode_linespec (struct breakpoint *b, char **s, 12798 struct symtabs_and_lines *sals) 12799 { 12800 internal_error_pure_virtual_called (); 12801 } 12802 12803 /* The default 'explains_signal' method. */ 12804 12805 static enum bpstat_signal_value 12806 base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) 12807 { 12808 return BPSTAT_SIGNAL_HIDE; 12809 } 12810 12811 /* The default "after_condition_true" method. */ 12812 12813 static void 12814 base_breakpoint_after_condition_true (struct bpstats *bs) 12815 { 12816 /* Nothing to do. */ 12817 } 12818 12819 struct breakpoint_ops base_breakpoint_ops = 12820 { 12821 base_breakpoint_dtor, 12822 base_breakpoint_allocate_location, 12823 base_breakpoint_re_set, 12824 base_breakpoint_insert_location, 12825 base_breakpoint_remove_location, 12826 base_breakpoint_breakpoint_hit, 12827 base_breakpoint_check_status, 12828 base_breakpoint_resources_needed, 12829 base_breakpoint_works_in_software_mode, 12830 base_breakpoint_print_it, 12831 NULL, 12832 base_breakpoint_print_one_detail, 12833 base_breakpoint_print_mention, 12834 base_breakpoint_print_recreate, 12835 base_breakpoint_create_sals_from_address, 12836 base_breakpoint_create_breakpoints_sal, 12837 base_breakpoint_decode_linespec, 12838 base_breakpoint_explains_signal, 12839 base_breakpoint_after_condition_true, 12840 }; 12841 12842 /* Default breakpoint_ops methods. */ 12843 12844 static void 12845 bkpt_re_set (struct breakpoint *b) 12846 { 12847 /* FIXME: is this still reachable? */ 12848 if (b->addr_string == NULL) 12849 { 12850 /* Anything without a string can't be re-set. */ 12851 delete_breakpoint (b); 12852 return; 12853 } 12854 12855 breakpoint_re_set_default (b); 12856 } 12857 12858 static int 12859 bkpt_insert_location (struct bp_location *bl) 12860 { 12861 if (bl->loc_type == bp_loc_hardware_breakpoint) 12862 return target_insert_hw_breakpoint (bl->gdbarch, 12863 &bl->target_info); 12864 else 12865 return target_insert_breakpoint (bl->gdbarch, 12866 &bl->target_info); 12867 } 12868 12869 static int 12870 bkpt_remove_location (struct bp_location *bl) 12871 { 12872 if (bl->loc_type == bp_loc_hardware_breakpoint) 12873 return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); 12874 else 12875 return target_remove_breakpoint (bl->gdbarch, &bl->target_info); 12876 } 12877 12878 static int 12879 bkpt_breakpoint_hit (const struct bp_location *bl, 12880 struct address_space *aspace, CORE_ADDR bp_addr, 12881 const struct target_waitstatus *ws) 12882 { 12883 if (ws->kind != TARGET_WAITKIND_STOPPED 12884 || ws->value.sig != GDB_SIGNAL_TRAP) 12885 return 0; 12886 12887 if (!breakpoint_address_match (bl->pspace->aspace, bl->address, 12888 aspace, bp_addr)) 12889 return 0; 12890 12891 if (overlay_debugging /* unmapped overlay section */ 12892 && section_is_overlay (bl->section) 12893 && !section_is_mapped (bl->section)) 12894 return 0; 12895 12896 return 1; 12897 } 12898 12899 static int 12900 bkpt_resources_needed (const struct bp_location *bl) 12901 { 12902 gdb_assert (bl->owner->type == bp_hardware_breakpoint); 12903 12904 return 1; 12905 } 12906 12907 static enum print_stop_action 12908 bkpt_print_it (bpstat bs) 12909 { 12910 struct breakpoint *b; 12911 const struct bp_location *bl; 12912 int bp_temp; 12913 struct ui_out *uiout = current_uiout; 12914 12915 gdb_assert (bs->bp_location_at != NULL); 12916 12917 bl = bs->bp_location_at; 12918 b = bs->breakpoint_at; 12919 12920 bp_temp = b->disposition == disp_del; 12921 if (bl->address != bl->requested_address) 12922 breakpoint_adjustment_warning (bl->requested_address, 12923 bl->address, 12924 b->number, 1); 12925 annotate_breakpoint (b->number); 12926 if (bp_temp) 12927 ui_out_text (uiout, "\nTemporary breakpoint "); 12928 else 12929 ui_out_text (uiout, "\nBreakpoint "); 12930 if (ui_out_is_mi_like_p (uiout)) 12931 { 12932 ui_out_field_string (uiout, "reason", 12933 async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); 12934 ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); 12935 } 12936 ui_out_field_int (uiout, "bkptno", b->number); 12937 ui_out_text (uiout, ", "); 12938 12939 return PRINT_SRC_AND_LOC; 12940 } 12941 12942 static void 12943 bkpt_print_mention (struct breakpoint *b) 12944 { 12945 if (ui_out_is_mi_like_p (current_uiout)) 12946 return; 12947 12948 switch (b->type) 12949 { 12950 case bp_breakpoint: 12951 case bp_gnu_ifunc_resolver: 12952 if (b->disposition == disp_del) 12953 printf_filtered (_("Temporary breakpoint")); 12954 else 12955 printf_filtered (_("Breakpoint")); 12956 printf_filtered (_(" %d"), b->number); 12957 if (b->type == bp_gnu_ifunc_resolver) 12958 printf_filtered (_(" at gnu-indirect-function resolver")); 12959 break; 12960 case bp_hardware_breakpoint: 12961 printf_filtered (_("Hardware assisted breakpoint %d"), b->number); 12962 break; 12963 case bp_dprintf: 12964 printf_filtered (_("Dprintf %d"), b->number); 12965 break; 12966 } 12967 12968 say_where (b); 12969 } 12970 12971 static void 12972 bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) 12973 { 12974 if (tp->type == bp_breakpoint && tp->disposition == disp_del) 12975 fprintf_unfiltered (fp, "tbreak"); 12976 else if (tp->type == bp_breakpoint) 12977 fprintf_unfiltered (fp, "break"); 12978 else if (tp->type == bp_hardware_breakpoint 12979 && tp->disposition == disp_del) 12980 fprintf_unfiltered (fp, "thbreak"); 12981 else if (tp->type == bp_hardware_breakpoint) 12982 fprintf_unfiltered (fp, "hbreak"); 12983 else 12984 internal_error (__FILE__, __LINE__, 12985 _("unhandled breakpoint type %d"), (int) tp->type); 12986 12987 fprintf_unfiltered (fp, " %s", tp->addr_string); 12988 print_recreate_thread (tp, fp); 12989 } 12990 12991 static void 12992 bkpt_create_sals_from_address (char **arg, 12993 struct linespec_result *canonical, 12994 enum bptype type_wanted, 12995 char *addr_start, char **copy_arg) 12996 { 12997 create_sals_from_address_default (arg, canonical, type_wanted, 12998 addr_start, copy_arg); 12999 } 13000 13001 static void 13002 bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, 13003 struct linespec_result *canonical, 13004 char *cond_string, 13005 char *extra_string, 13006 enum bptype type_wanted, 13007 enum bpdisp disposition, 13008 int thread, 13009 int task, int ignore_count, 13010 const struct breakpoint_ops *ops, 13011 int from_tty, int enabled, 13012 int internal, unsigned flags) 13013 { 13014 create_breakpoints_sal_default (gdbarch, canonical, 13015 cond_string, extra_string, 13016 type_wanted, 13017 disposition, thread, task, 13018 ignore_count, ops, from_tty, 13019 enabled, internal, flags); 13020 } 13021 13022 static void 13023 bkpt_decode_linespec (struct breakpoint *b, char **s, 13024 struct symtabs_and_lines *sals) 13025 { 13026 decode_linespec_default (b, s, sals); 13027 } 13028 13029 /* Virtual table for internal breakpoints. */ 13030 13031 static void 13032 internal_bkpt_re_set (struct breakpoint *b) 13033 { 13034 switch (b->type) 13035 { 13036 /* Delete overlay event and longjmp master breakpoints; they 13037 will be reset later by breakpoint_re_set. */ 13038 case bp_overlay_event: 13039 case bp_longjmp_master: 13040 case bp_std_terminate_master: 13041 case bp_exception_master: 13042 delete_breakpoint (b); 13043 break; 13044 13045 /* This breakpoint is special, it's set up when the inferior 13046 starts and we really don't want to touch it. */ 13047 case bp_shlib_event: 13048 13049 /* Like bp_shlib_event, this breakpoint type is special. Once 13050 it is set up, we do not want to touch it. */ 13051 case bp_thread_event: 13052 break; 13053 } 13054 } 13055 13056 static void 13057 internal_bkpt_check_status (bpstat bs) 13058 { 13059 if (bs->breakpoint_at->type == bp_shlib_event) 13060 { 13061 /* If requested, stop when the dynamic linker notifies GDB of 13062 events. This allows the user to get control and place 13063 breakpoints in initializer routines for dynamically loaded 13064 objects (among other things). */ 13065 bs->stop = stop_on_solib_events; 13066 bs->print = stop_on_solib_events; 13067 } 13068 else 13069 bs->stop = 0; 13070 } 13071 13072 static enum print_stop_action 13073 internal_bkpt_print_it (bpstat bs) 13074 { 13075 struct breakpoint *b; 13076 13077 b = bs->breakpoint_at; 13078 13079 switch (b->type) 13080 { 13081 case bp_shlib_event: 13082 /* Did we stop because the user set the stop_on_solib_events 13083 variable? (If so, we report this as a generic, "Stopped due 13084 to shlib event" message.) */ 13085 print_solib_event (0); 13086 break; 13087 13088 case bp_thread_event: 13089 /* Not sure how we will get here. 13090 GDB should not stop for these breakpoints. */ 13091 printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); 13092 break; 13093 13094 case bp_overlay_event: 13095 /* By analogy with the thread event, GDB should not stop for these. */ 13096 printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); 13097 break; 13098 13099 case bp_longjmp_master: 13100 /* These should never be enabled. */ 13101 printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); 13102 break; 13103 13104 case bp_std_terminate_master: 13105 /* These should never be enabled. */ 13106 printf_filtered (_("std::terminate Master Breakpoint: " 13107 "gdb should not stop!\n")); 13108 break; 13109 13110 case bp_exception_master: 13111 /* These should never be enabled. */ 13112 printf_filtered (_("Exception Master Breakpoint: " 13113 "gdb should not stop!\n")); 13114 break; 13115 } 13116 13117 return PRINT_NOTHING; 13118 } 13119 13120 static void 13121 internal_bkpt_print_mention (struct breakpoint *b) 13122 { 13123 /* Nothing to mention. These breakpoints are internal. */ 13124 } 13125 13126 /* Virtual table for momentary breakpoints */ 13127 13128 static void 13129 momentary_bkpt_re_set (struct breakpoint *b) 13130 { 13131 /* Keep temporary breakpoints, which can be encountered when we step 13132 over a dlopen call and solib_add is resetting the breakpoints. 13133 Otherwise these should have been blown away via the cleanup chain 13134 or by breakpoint_init_inferior when we rerun the executable. */ 13135 } 13136 13137 static void 13138 momentary_bkpt_check_status (bpstat bs) 13139 { 13140 /* Nothing. The point of these breakpoints is causing a stop. */ 13141 } 13142 13143 static enum print_stop_action 13144 momentary_bkpt_print_it (bpstat bs) 13145 { 13146 struct ui_out *uiout = current_uiout; 13147 13148 if (ui_out_is_mi_like_p (uiout)) 13149 { 13150 struct breakpoint *b = bs->breakpoint_at; 13151 13152 switch (b->type) 13153 { 13154 case bp_finish: 13155 ui_out_field_string 13156 (uiout, "reason", 13157 async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); 13158 break; 13159 13160 case bp_until: 13161 ui_out_field_string 13162 (uiout, "reason", 13163 async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); 13164 break; 13165 } 13166 } 13167 13168 return PRINT_UNKNOWN; 13169 } 13170 13171 static void 13172 momentary_bkpt_print_mention (struct breakpoint *b) 13173 { 13174 /* Nothing to mention. These breakpoints are internal. */ 13175 } 13176 13177 /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. 13178 13179 It gets cleared already on the removal of the first one of such placed 13180 breakpoints. This is OK as they get all removed altogether. */ 13181 13182 static void 13183 longjmp_bkpt_dtor (struct breakpoint *self) 13184 { 13185 struct thread_info *tp = find_thread_id (self->thread); 13186 13187 if (tp) 13188 tp->initiating_frame = null_frame_id; 13189 13190 momentary_breakpoint_ops.dtor (self); 13191 } 13192 13193 /* Specific methods for probe breakpoints. */ 13194 13195 static int 13196 bkpt_probe_insert_location (struct bp_location *bl) 13197 { 13198 int v = bkpt_insert_location (bl); 13199 13200 if (v == 0) 13201 { 13202 /* The insertion was successful, now let's set the probe's semaphore 13203 if needed. */ 13204 bl->probe->pops->set_semaphore (bl->probe, bl->gdbarch); 13205 } 13206 13207 return v; 13208 } 13209 13210 static int 13211 bkpt_probe_remove_location (struct bp_location *bl) 13212 { 13213 /* Let's clear the semaphore before removing the location. */ 13214 bl->probe->pops->clear_semaphore (bl->probe, bl->gdbarch); 13215 13216 return bkpt_remove_location (bl); 13217 } 13218 13219 static void 13220 bkpt_probe_create_sals_from_address (char **arg, 13221 struct linespec_result *canonical, 13222 enum bptype type_wanted, 13223 char *addr_start, char **copy_arg) 13224 { 13225 struct linespec_sals lsal; 13226 13227 lsal.sals = parse_probes (arg, canonical); 13228 13229 *copy_arg = xstrdup (canonical->addr_string); 13230 lsal.canonical = xstrdup (*copy_arg); 13231 13232 VEC_safe_push (linespec_sals, canonical->sals, &lsal); 13233 } 13234 13235 static void 13236 bkpt_probe_decode_linespec (struct breakpoint *b, char **s, 13237 struct symtabs_and_lines *sals) 13238 { 13239 *sals = parse_probes (s, NULL); 13240 if (!sals->sals) 13241 error (_("probe not found")); 13242 } 13243 13244 /* The breakpoint_ops structure to be used in tracepoints. */ 13245 13246 static void 13247 tracepoint_re_set (struct breakpoint *b) 13248 { 13249 breakpoint_re_set_default (b); 13250 } 13251 13252 static int 13253 tracepoint_breakpoint_hit (const struct bp_location *bl, 13254 struct address_space *aspace, CORE_ADDR bp_addr, 13255 const struct target_waitstatus *ws) 13256 { 13257 /* By definition, the inferior does not report stops at 13258 tracepoints. */ 13259 return 0; 13260 } 13261 13262 static void 13263 tracepoint_print_one_detail (const struct breakpoint *self, 13264 struct ui_out *uiout) 13265 { 13266 struct tracepoint *tp = (struct tracepoint *) self; 13267 if (tp->static_trace_marker_id) 13268 { 13269 gdb_assert (self->type == bp_static_tracepoint); 13270 13271 ui_out_text (uiout, "\tmarker id is "); 13272 ui_out_field_string (uiout, "static-tracepoint-marker-string-id", 13273 tp->static_trace_marker_id); 13274 ui_out_text (uiout, "\n"); 13275 } 13276 } 13277 13278 static void 13279 tracepoint_print_mention (struct breakpoint *b) 13280 { 13281 if (ui_out_is_mi_like_p (current_uiout)) 13282 return; 13283 13284 switch (b->type) 13285 { 13286 case bp_tracepoint: 13287 printf_filtered (_("Tracepoint")); 13288 printf_filtered (_(" %d"), b->number); 13289 break; 13290 case bp_fast_tracepoint: 13291 printf_filtered (_("Fast tracepoint")); 13292 printf_filtered (_(" %d"), b->number); 13293 break; 13294 case bp_static_tracepoint: 13295 printf_filtered (_("Static tracepoint")); 13296 printf_filtered (_(" %d"), b->number); 13297 break; 13298 default: 13299 internal_error (__FILE__, __LINE__, 13300 _("unhandled tracepoint type %d"), (int) b->type); 13301 } 13302 13303 say_where (b); 13304 } 13305 13306 static void 13307 tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) 13308 { 13309 struct tracepoint *tp = (struct tracepoint *) self; 13310 13311 if (self->type == bp_fast_tracepoint) 13312 fprintf_unfiltered (fp, "ftrace"); 13313 if (self->type == bp_static_tracepoint) 13314 fprintf_unfiltered (fp, "strace"); 13315 else if (self->type == bp_tracepoint) 13316 fprintf_unfiltered (fp, "trace"); 13317 else 13318 internal_error (__FILE__, __LINE__, 13319 _("unhandled tracepoint type %d"), (int) self->type); 13320 13321 fprintf_unfiltered (fp, " %s", self->addr_string); 13322 print_recreate_thread (self, fp); 13323 13324 if (tp->pass_count) 13325 fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); 13326 } 13327 13328 static void 13329 tracepoint_create_sals_from_address (char **arg, 13330 struct linespec_result *canonical, 13331 enum bptype type_wanted, 13332 char *addr_start, char **copy_arg) 13333 { 13334 create_sals_from_address_default (arg, canonical, type_wanted, 13335 addr_start, copy_arg); 13336 } 13337 13338 static void 13339 tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, 13340 struct linespec_result *canonical, 13341 char *cond_string, 13342 char *extra_string, 13343 enum bptype type_wanted, 13344 enum bpdisp disposition, 13345 int thread, 13346 int task, int ignore_count, 13347 const struct breakpoint_ops *ops, 13348 int from_tty, int enabled, 13349 int internal, unsigned flags) 13350 { 13351 create_breakpoints_sal_default (gdbarch, canonical, 13352 cond_string, extra_string, 13353 type_wanted, 13354 disposition, thread, task, 13355 ignore_count, ops, from_tty, 13356 enabled, internal, flags); 13357 } 13358 13359 static void 13360 tracepoint_decode_linespec (struct breakpoint *b, char **s, 13361 struct symtabs_and_lines *sals) 13362 { 13363 decode_linespec_default (b, s, sals); 13364 } 13365 13366 struct breakpoint_ops tracepoint_breakpoint_ops; 13367 13368 /* The breakpoint_ops structure to be use on tracepoints placed in a 13369 static probe. */ 13370 13371 static void 13372 tracepoint_probe_create_sals_from_address (char **arg, 13373 struct linespec_result *canonical, 13374 enum bptype type_wanted, 13375 char *addr_start, char **copy_arg) 13376 { 13377 /* We use the same method for breakpoint on probes. */ 13378 bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, 13379 addr_start, copy_arg); 13380 } 13381 13382 static void 13383 tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, 13384 struct symtabs_and_lines *sals) 13385 { 13386 /* We use the same method for breakpoint on probes. */ 13387 bkpt_probe_decode_linespec (b, s, sals); 13388 } 13389 13390 static struct breakpoint_ops tracepoint_probe_breakpoint_ops; 13391 13392 /* Dprintf breakpoint_ops methods. */ 13393 13394 static void 13395 dprintf_re_set (struct breakpoint *b) 13396 { 13397 breakpoint_re_set_default (b); 13398 13399 /* This breakpoint could have been pending, and be resolved now, and 13400 if so, we should now have the extra string. If we don't, the 13401 dprintf was malformed when created, but we couldn't tell because 13402 we can't extract the extra string until the location is 13403 resolved. */ 13404 if (b->loc != NULL && b->extra_string == NULL) 13405 error (_("Format string required")); 13406 13407 /* 1 - connect to target 1, that can run breakpoint commands. 13408 2 - create a dprintf, which resolves fine. 13409 3 - disconnect from target 1 13410 4 - connect to target 2, that can NOT run breakpoint commands. 13411 13412 After steps #3/#4, you'll want the dprintf command list to 13413 be updated, because target 1 and 2 may well return different 13414 answers for target_can_run_breakpoint_commands(). 13415 Given absence of finer grained resetting, we get to do 13416 it all the time. */ 13417 if (b->extra_string != NULL) 13418 update_dprintf_command_list (b); 13419 } 13420 13421 /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ 13422 13423 static void 13424 dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) 13425 { 13426 fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, 13427 tp->extra_string); 13428 print_recreate_thread (tp, fp); 13429 } 13430 13431 /* Implement the "after_condition_true" breakpoint_ops method for 13432 dprintf. 13433 13434 dprintf's are implemented with regular commands in their command 13435 list, but we run the commands here instead of before presenting the 13436 stop to the user, as dprintf's don't actually cause a stop. This 13437 also makes it so that the commands of multiple dprintfs at the same 13438 address are all handled. */ 13439 13440 static void 13441 dprintf_after_condition_true (struct bpstats *bs) 13442 { 13443 struct cleanup *old_chain; 13444 struct bpstats tmp_bs = { NULL }; 13445 struct bpstats *tmp_bs_p = &tmp_bs; 13446 13447 /* dprintf's never cause a stop. This wasn't set in the 13448 check_status hook instead because that would make the dprintf's 13449 condition not be evaluated. */ 13450 bs->stop = 0; 13451 13452 /* Run the command list here. Take ownership of it instead of 13453 copying. We never want these commands to run later in 13454 bpstat_do_actions, if a breakpoint that causes a stop happens to 13455 be set at same address as this dprintf, or even if running the 13456 commands here throws. */ 13457 tmp_bs.commands = bs->commands; 13458 bs->commands = NULL; 13459 old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); 13460 13461 bpstat_do_actions_1 (&tmp_bs_p); 13462 13463 /* 'tmp_bs.commands' will usually be NULL by now, but 13464 bpstat_do_actions_1 may return early without processing the whole 13465 list. */ 13466 do_cleanups (old_chain); 13467 } 13468 13469 /* The breakpoint_ops structure to be used on static tracepoints with 13470 markers (`-m'). */ 13471 13472 static void 13473 strace_marker_create_sals_from_address (char **arg, 13474 struct linespec_result *canonical, 13475 enum bptype type_wanted, 13476 char *addr_start, char **copy_arg) 13477 { 13478 struct linespec_sals lsal; 13479 13480 lsal.sals = decode_static_tracepoint_spec (arg); 13481 13482 *copy_arg = savestring (addr_start, *arg - addr_start); 13483 13484 canonical->addr_string = xstrdup (*copy_arg); 13485 lsal.canonical = xstrdup (*copy_arg); 13486 VEC_safe_push (linespec_sals, canonical->sals, &lsal); 13487 } 13488 13489 static void 13490 strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, 13491 struct linespec_result *canonical, 13492 char *cond_string, 13493 char *extra_string, 13494 enum bptype type_wanted, 13495 enum bpdisp disposition, 13496 int thread, 13497 int task, int ignore_count, 13498 const struct breakpoint_ops *ops, 13499 int from_tty, int enabled, 13500 int internal, unsigned flags) 13501 { 13502 int i; 13503 struct linespec_sals *lsal = VEC_index (linespec_sals, 13504 canonical->sals, 0); 13505 13506 /* If the user is creating a static tracepoint by marker id 13507 (strace -m MARKER_ID), then store the sals index, so that 13508 breakpoint_re_set can try to match up which of the newly 13509 found markers corresponds to this one, and, don't try to 13510 expand multiple locations for each sal, given than SALS 13511 already should contain all sals for MARKER_ID. */ 13512 13513 for (i = 0; i < lsal->sals.nelts; ++i) 13514 { 13515 struct symtabs_and_lines expanded; 13516 struct tracepoint *tp; 13517 struct cleanup *old_chain; 13518 char *addr_string; 13519 13520 expanded.nelts = 1; 13521 expanded.sals = &lsal->sals.sals[i]; 13522 13523 addr_string = xstrdup (canonical->addr_string); 13524 old_chain = make_cleanup (xfree, addr_string); 13525 13526 tp = XCNEW (struct tracepoint); 13527 init_breakpoint_sal (&tp->base, gdbarch, expanded, 13528 addr_string, NULL, 13529 cond_string, extra_string, 13530 type_wanted, disposition, 13531 thread, task, ignore_count, ops, 13532 from_tty, enabled, internal, flags, 13533 canonical->special_display); 13534 /* Given that its possible to have multiple markers with 13535 the same string id, if the user is creating a static 13536 tracepoint by marker id ("strace -m MARKER_ID"), then 13537 store the sals index, so that breakpoint_re_set can 13538 try to match up which of the newly found markers 13539 corresponds to this one */ 13540 tp->static_trace_marker_id_idx = i; 13541 13542 install_breakpoint (internal, &tp->base, 0); 13543 13544 discard_cleanups (old_chain); 13545 } 13546 } 13547 13548 static void 13549 strace_marker_decode_linespec (struct breakpoint *b, char **s, 13550 struct symtabs_and_lines *sals) 13551 { 13552 struct tracepoint *tp = (struct tracepoint *) b; 13553 13554 *sals = decode_static_tracepoint_spec (s); 13555 if (sals->nelts > tp->static_trace_marker_id_idx) 13556 { 13557 sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; 13558 sals->nelts = 1; 13559 } 13560 else 13561 error (_("marker %s not found"), tp->static_trace_marker_id); 13562 } 13563 13564 static struct breakpoint_ops strace_marker_breakpoint_ops; 13565 13566 static int 13567 strace_marker_p (struct breakpoint *b) 13568 { 13569 return b->ops == &strace_marker_breakpoint_ops; 13570 } 13571 13572 /* Delete a breakpoint and clean up all traces of it in the data 13573 structures. */ 13574 13575 void 13576 delete_breakpoint (struct breakpoint *bpt) 13577 { 13578 struct breakpoint *b; 13579 13580 gdb_assert (bpt != NULL); 13581 13582 /* Has this bp already been deleted? This can happen because 13583 multiple lists can hold pointers to bp's. bpstat lists are 13584 especial culprits. 13585 13586 One example of this happening is a watchpoint's scope bp. When 13587 the scope bp triggers, we notice that the watchpoint is out of 13588 scope, and delete it. We also delete its scope bp. But the 13589 scope bp is marked "auto-deleting", and is already on a bpstat. 13590 That bpstat is then checked for auto-deleting bp's, which are 13591 deleted. 13592 13593 A real solution to this problem might involve reference counts in 13594 bp's, and/or giving them pointers back to their referencing 13595 bpstat's, and teaching delete_breakpoint to only free a bp's 13596 storage when no more references were extent. A cheaper bandaid 13597 was chosen. */ 13598 if (bpt->type == bp_none) 13599 return; 13600 13601 /* At least avoid this stale reference until the reference counting 13602 of breakpoints gets resolved. */ 13603 if (bpt->related_breakpoint != bpt) 13604 { 13605 struct breakpoint *related; 13606 struct watchpoint *w; 13607 13608 if (bpt->type == bp_watchpoint_scope) 13609 w = (struct watchpoint *) bpt->related_breakpoint; 13610 else if (bpt->related_breakpoint->type == bp_watchpoint_scope) 13611 w = (struct watchpoint *) bpt; 13612 else 13613 w = NULL; 13614 if (w != NULL) 13615 watchpoint_del_at_next_stop (w); 13616 13617 /* Unlink bpt from the bpt->related_breakpoint ring. */ 13618 for (related = bpt; related->related_breakpoint != bpt; 13619 related = related->related_breakpoint); 13620 related->related_breakpoint = bpt->related_breakpoint; 13621 bpt->related_breakpoint = bpt; 13622 } 13623 13624 /* watch_command_1 creates a watchpoint but only sets its number if 13625 update_watchpoint succeeds in creating its bp_locations. If there's 13626 a problem in that process, we'll be asked to delete the half-created 13627 watchpoint. In that case, don't announce the deletion. */ 13628 if (bpt->number) 13629 observer_notify_breakpoint_deleted (bpt); 13630 13631 if (breakpoint_chain == bpt) 13632 breakpoint_chain = bpt->next; 13633 13634 ALL_BREAKPOINTS (b) 13635 if (b->next == bpt) 13636 { 13637 b->next = bpt->next; 13638 break; 13639 } 13640 13641 /* Be sure no bpstat's are pointing at the breakpoint after it's 13642 been freed. */ 13643 /* FIXME, how can we find all bpstat's? We just check stop_bpstat 13644 in all threads for now. Note that we cannot just remove bpstats 13645 pointing at bpt from the stop_bpstat list entirely, as breakpoint 13646 commands are associated with the bpstat; if we remove it here, 13647 then the later call to bpstat_do_actions (&stop_bpstat); in 13648 event-top.c won't do anything, and temporary breakpoints with 13649 commands won't work. */ 13650 13651 iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); 13652 13653 /* Now that breakpoint is removed from breakpoint list, update the 13654 global location list. This will remove locations that used to 13655 belong to this breakpoint. Do this before freeing the breakpoint 13656 itself, since remove_breakpoint looks at location's owner. It 13657 might be better design to have location completely 13658 self-contained, but it's not the case now. */ 13659 update_global_location_list (0); 13660 13661 bpt->ops->dtor (bpt); 13662 /* On the chance that someone will soon try again to delete this 13663 same bp, we mark it as deleted before freeing its storage. */ 13664 bpt->type = bp_none; 13665 xfree (bpt); 13666 } 13667 13668 static void 13669 do_delete_breakpoint_cleanup (void *b) 13670 { 13671 delete_breakpoint (b); 13672 } 13673 13674 struct cleanup * 13675 make_cleanup_delete_breakpoint (struct breakpoint *b) 13676 { 13677 return make_cleanup (do_delete_breakpoint_cleanup, b); 13678 } 13679 13680 /* Iterator function to call a user-provided callback function once 13681 for each of B and its related breakpoints. */ 13682 13683 static void 13684 iterate_over_related_breakpoints (struct breakpoint *b, 13685 void (*function) (struct breakpoint *, 13686 void *), 13687 void *data) 13688 { 13689 struct breakpoint *related; 13690 13691 related = b; 13692 do 13693 { 13694 struct breakpoint *next; 13695 13696 /* FUNCTION may delete RELATED. */ 13697 next = related->related_breakpoint; 13698 13699 if (next == related) 13700 { 13701 /* RELATED is the last ring entry. */ 13702 function (related, data); 13703 13704 /* FUNCTION may have deleted it, so we'd never reach back to 13705 B. There's nothing left to do anyway, so just break 13706 out. */ 13707 break; 13708 } 13709 else 13710 function (related, data); 13711 13712 related = next; 13713 } 13714 while (related != b); 13715 } 13716 13717 static void 13718 do_delete_breakpoint (struct breakpoint *b, void *ignore) 13719 { 13720 delete_breakpoint (b); 13721 } 13722 13723 /* A callback for map_breakpoint_numbers that calls 13724 delete_breakpoint. */ 13725 13726 static void 13727 do_map_delete_breakpoint (struct breakpoint *b, void *ignore) 13728 { 13729 iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); 13730 } 13731 13732 void 13733 delete_command (char *arg, int from_tty) 13734 { 13735 struct breakpoint *b, *b_tmp; 13736 13737 dont_repeat (); 13738 13739 if (arg == 0) 13740 { 13741 int breaks_to_delete = 0; 13742 13743 /* Delete all breakpoints if no argument. Do not delete 13744 internal breakpoints, these have to be deleted with an 13745 explicit breakpoint number argument. */ 13746 ALL_BREAKPOINTS (b) 13747 if (user_breakpoint_p (b)) 13748 { 13749 breaks_to_delete = 1; 13750 break; 13751 } 13752 13753 /* Ask user only if there are some breakpoints to delete. */ 13754 if (!from_tty 13755 || (breaks_to_delete && query (_("Delete all breakpoints? ")))) 13756 { 13757 ALL_BREAKPOINTS_SAFE (b, b_tmp) 13758 if (user_breakpoint_p (b)) 13759 delete_breakpoint (b); 13760 } 13761 } 13762 else 13763 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); 13764 } 13765 13766 static int 13767 all_locations_are_pending (struct bp_location *loc) 13768 { 13769 for (; loc; loc = loc->next) 13770 if (!loc->shlib_disabled 13771 && !loc->pspace->executing_startup) 13772 return 0; 13773 return 1; 13774 } 13775 13776 /* Subroutine of update_breakpoint_locations to simplify it. 13777 Return non-zero if multiple fns in list LOC have the same name. 13778 Null names are ignored. */ 13779 13780 static int 13781 ambiguous_names_p (struct bp_location *loc) 13782 { 13783 struct bp_location *l; 13784 htab_t htab = htab_create_alloc (13, htab_hash_string, 13785 (int (*) (const void *, 13786 const void *)) streq, 13787 NULL, xcalloc, xfree); 13788 13789 for (l = loc; l != NULL; l = l->next) 13790 { 13791 const char **slot; 13792 const char *name = l->function_name; 13793 13794 /* Allow for some names to be NULL, ignore them. */ 13795 if (name == NULL) 13796 continue; 13797 13798 slot = (const char **) htab_find_slot (htab, (const void *) name, 13799 INSERT); 13800 /* NOTE: We can assume slot != NULL here because xcalloc never 13801 returns NULL. */ 13802 if (*slot != NULL) 13803 { 13804 htab_delete (htab); 13805 return 1; 13806 } 13807 *slot = name; 13808 } 13809 13810 htab_delete (htab); 13811 return 0; 13812 } 13813 13814 /* When symbols change, it probably means the sources changed as well, 13815 and it might mean the static tracepoint markers are no longer at 13816 the same address or line numbers they used to be at last we 13817 checked. Losing your static tracepoints whenever you rebuild is 13818 undesirable. This function tries to resync/rematch gdb static 13819 tracepoints with the markers on the target, for static tracepoints 13820 that have not been set by marker id. Static tracepoint that have 13821 been set by marker id are reset by marker id in breakpoint_re_set. 13822 The heuristic is: 13823 13824 1) For a tracepoint set at a specific address, look for a marker at 13825 the old PC. If one is found there, assume to be the same marker. 13826 If the name / string id of the marker found is different from the 13827 previous known name, assume that means the user renamed the marker 13828 in the sources, and output a warning. 13829 13830 2) For a tracepoint set at a given line number, look for a marker 13831 at the new address of the old line number. If one is found there, 13832 assume to be the same marker. If the name / string id of the 13833 marker found is different from the previous known name, assume that 13834 means the user renamed the marker in the sources, and output a 13835 warning. 13836 13837 3) If a marker is no longer found at the same address or line, it 13838 may mean the marker no longer exists. But it may also just mean 13839 the code changed a bit. Maybe the user added a few lines of code 13840 that made the marker move up or down (in line number terms). Ask 13841 the target for info about the marker with the string id as we knew 13842 it. If found, update line number and address in the matching 13843 static tracepoint. This will get confused if there's more than one 13844 marker with the same ID (possible in UST, although unadvised 13845 precisely because it confuses tools). */ 13846 13847 static struct symtab_and_line 13848 update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) 13849 { 13850 struct tracepoint *tp = (struct tracepoint *) b; 13851 struct static_tracepoint_marker marker; 13852 CORE_ADDR pc; 13853 13854 pc = sal.pc; 13855 if (sal.line) 13856 find_line_pc (sal.symtab, sal.line, &pc); 13857 13858 if (target_static_tracepoint_marker_at (pc, &marker)) 13859 { 13860 if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) 13861 warning (_("static tracepoint %d changed probed marker from %s to %s"), 13862 b->number, 13863 tp->static_trace_marker_id, marker.str_id); 13864 13865 xfree (tp->static_trace_marker_id); 13866 tp->static_trace_marker_id = xstrdup (marker.str_id); 13867 release_static_tracepoint_marker (&marker); 13868 13869 return sal; 13870 } 13871 13872 /* Old marker wasn't found on target at lineno. Try looking it up 13873 by string ID. */ 13874 if (!sal.explicit_pc 13875 && sal.line != 0 13876 && sal.symtab != NULL 13877 && tp->static_trace_marker_id != NULL) 13878 { 13879 VEC(static_tracepoint_marker_p) *markers; 13880 13881 markers 13882 = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); 13883 13884 if (!VEC_empty(static_tracepoint_marker_p, markers)) 13885 { 13886 struct symtab_and_line sal2; 13887 struct symbol *sym; 13888 struct static_tracepoint_marker *tpmarker; 13889 struct ui_out *uiout = current_uiout; 13890 13891 tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); 13892 13893 xfree (tp->static_trace_marker_id); 13894 tp->static_trace_marker_id = xstrdup (tpmarker->str_id); 13895 13896 warning (_("marker for static tracepoint %d (%s) not " 13897 "found at previous line number"), 13898 b->number, tp->static_trace_marker_id); 13899 13900 init_sal (&sal2); 13901 13902 sal2.pc = tpmarker->address; 13903 13904 sal2 = find_pc_line (tpmarker->address, 0); 13905 sym = find_pc_sect_function (tpmarker->address, NULL); 13906 ui_out_text (uiout, "Now in "); 13907 if (sym) 13908 { 13909 ui_out_field_string (uiout, "func", 13910 SYMBOL_PRINT_NAME (sym)); 13911 ui_out_text (uiout, " at "); 13912 } 13913 ui_out_field_string (uiout, "file", 13914 symtab_to_filename_for_display (sal2.symtab)); 13915 ui_out_text (uiout, ":"); 13916 13917 if (ui_out_is_mi_like_p (uiout)) 13918 { 13919 const char *fullname = symtab_to_fullname (sal2.symtab); 13920 13921 ui_out_field_string (uiout, "fullname", fullname); 13922 } 13923 13924 ui_out_field_int (uiout, "line", sal2.line); 13925 ui_out_text (uiout, "\n"); 13926 13927 b->loc->line_number = sal2.line; 13928 b->loc->symtab = sym != NULL ? sal2.symtab : NULL; 13929 13930 xfree (b->addr_string); 13931 b->addr_string = xstrprintf ("%s:%d", 13932 symtab_to_filename_for_display (sal2.symtab), 13933 b->loc->line_number); 13934 13935 /* Might be nice to check if function changed, and warn if 13936 so. */ 13937 13938 release_static_tracepoint_marker (tpmarker); 13939 } 13940 } 13941 return sal; 13942 } 13943 13944 /* Returns 1 iff locations A and B are sufficiently same that 13945 we don't need to report breakpoint as changed. */ 13946 13947 static int 13948 locations_are_equal (struct bp_location *a, struct bp_location *b) 13949 { 13950 while (a && b) 13951 { 13952 if (a->address != b->address) 13953 return 0; 13954 13955 if (a->shlib_disabled != b->shlib_disabled) 13956 return 0; 13957 13958 if (a->enabled != b->enabled) 13959 return 0; 13960 13961 a = a->next; 13962 b = b->next; 13963 } 13964 13965 if ((a == NULL) != (b == NULL)) 13966 return 0; 13967 13968 return 1; 13969 } 13970 13971 /* Create new breakpoint locations for B (a hardware or software breakpoint) 13972 based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is 13973 a ranged breakpoint. */ 13974 13975 void 13976 update_breakpoint_locations (struct breakpoint *b, 13977 struct symtabs_and_lines sals, 13978 struct symtabs_and_lines sals_end) 13979 { 13980 int i; 13981 struct bp_location *existing_locations = b->loc; 13982 13983 if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) 13984 { 13985 /* Ranged breakpoints have only one start location and one end 13986 location. */ 13987 b->enable_state = bp_disabled; 13988 update_global_location_list (1); 13989 printf_unfiltered (_("Could not reset ranged breakpoint %d: " 13990 "multiple locations found\n"), 13991 b->number); 13992 return; 13993 } 13994 13995 /* If there's no new locations, and all existing locations are 13996 pending, don't do anything. This optimizes the common case where 13997 all locations are in the same shared library, that was unloaded. 13998 We'd like to retain the location, so that when the library is 13999 loaded again, we don't loose the enabled/disabled status of the 14000 individual locations. */ 14001 if (all_locations_are_pending (existing_locations) && sals.nelts == 0) 14002 return; 14003 14004 b->loc = NULL; 14005 14006 for (i = 0; i < sals.nelts; ++i) 14007 { 14008 struct bp_location *new_loc; 14009 14010 switch_to_program_space_and_thread (sals.sals[i].pspace); 14011 14012 new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); 14013 14014 /* Reparse conditions, they might contain references to the 14015 old symtab. */ 14016 if (b->cond_string != NULL) 14017 { 14018 const char *s; 14019 volatile struct gdb_exception e; 14020 14021 s = b->cond_string; 14022 TRY_CATCH (e, RETURN_MASK_ERROR) 14023 { 14024 new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, 14025 block_for_pc (sals.sals[i].pc), 14026 0); 14027 } 14028 if (e.reason < 0) 14029 { 14030 warning (_("failed to reevaluate condition " 14031 "for breakpoint %d: %s"), 14032 b->number, e.message); 14033 new_loc->enabled = 0; 14034 } 14035 } 14036 14037 if (sals_end.nelts) 14038 { 14039 CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); 14040 14041 new_loc->length = end - sals.sals[0].pc + 1; 14042 } 14043 } 14044 14045 /* Update locations of permanent breakpoints. */ 14046 if (b->enable_state == bp_permanent) 14047 make_breakpoint_permanent (b); 14048 14049 /* If possible, carry over 'disable' status from existing 14050 breakpoints. */ 14051 { 14052 struct bp_location *e = existing_locations; 14053 /* If there are multiple breakpoints with the same function name, 14054 e.g. for inline functions, comparing function names won't work. 14055 Instead compare pc addresses; this is just a heuristic as things 14056 may have moved, but in practice it gives the correct answer 14057 often enough until a better solution is found. */ 14058 int have_ambiguous_names = ambiguous_names_p (b->loc); 14059 14060 for (; e; e = e->next) 14061 { 14062 if (!e->enabled && e->function_name) 14063 { 14064 struct bp_location *l = b->loc; 14065 if (have_ambiguous_names) 14066 { 14067 for (; l; l = l->next) 14068 if (breakpoint_locations_match (e, l)) 14069 { 14070 l->enabled = 0; 14071 break; 14072 } 14073 } 14074 else 14075 { 14076 for (; l; l = l->next) 14077 if (l->function_name 14078 && strcmp (e->function_name, l->function_name) == 0) 14079 { 14080 l->enabled = 0; 14081 break; 14082 } 14083 } 14084 } 14085 } 14086 } 14087 14088 if (!locations_are_equal (existing_locations, b->loc)) 14089 observer_notify_breakpoint_modified (b); 14090 14091 update_global_location_list (1); 14092 } 14093 14094 /* Find the SaL locations corresponding to the given ADDR_STRING. 14095 On return, FOUND will be 1 if any SaL was found, zero otherwise. */ 14096 14097 static struct symtabs_and_lines 14098 addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) 14099 { 14100 char *s; 14101 struct symtabs_and_lines sals = {0}; 14102 volatile struct gdb_exception e; 14103 14104 gdb_assert (b->ops != NULL); 14105 s = addr_string; 14106 14107 TRY_CATCH (e, RETURN_MASK_ERROR) 14108 { 14109 b->ops->decode_linespec (b, &s, &sals); 14110 } 14111 if (e.reason < 0) 14112 { 14113 int not_found_and_ok = 0; 14114 /* For pending breakpoints, it's expected that parsing will 14115 fail until the right shared library is loaded. User has 14116 already told to create pending breakpoints and don't need 14117 extra messages. If breakpoint is in bp_shlib_disabled 14118 state, then user already saw the message about that 14119 breakpoint being disabled, and don't want to see more 14120 errors. */ 14121 if (e.error == NOT_FOUND_ERROR 14122 && (b->condition_not_parsed 14123 || (b->loc && b->loc->shlib_disabled) 14124 || (b->loc && b->loc->pspace->executing_startup) 14125 || b->enable_state == bp_disabled)) 14126 not_found_and_ok = 1; 14127 14128 if (!not_found_and_ok) 14129 { 14130 /* We surely don't want to warn about the same breakpoint 14131 10 times. One solution, implemented here, is disable 14132 the breakpoint on error. Another solution would be to 14133 have separate 'warning emitted' flag. Since this 14134 happens only when a binary has changed, I don't know 14135 which approach is better. */ 14136 b->enable_state = bp_disabled; 14137 throw_exception (e); 14138 } 14139 } 14140 14141 if (e.reason == 0 || e.error != NOT_FOUND_ERROR) 14142 { 14143 int i; 14144 14145 for (i = 0; i < sals.nelts; ++i) 14146 resolve_sal_pc (&sals.sals[i]); 14147 if (b->condition_not_parsed && s && s[0]) 14148 { 14149 char *cond_string, *extra_string; 14150 int thread, task; 14151 14152 find_condition_and_thread (s, sals.sals[0].pc, 14153 &cond_string, &thread, &task, 14154 &extra_string); 14155 if (cond_string) 14156 b->cond_string = cond_string; 14157 b->thread = thread; 14158 b->task = task; 14159 if (extra_string) 14160 b->extra_string = extra_string; 14161 b->condition_not_parsed = 0; 14162 } 14163 14164 if (b->type == bp_static_tracepoint && !strace_marker_p (b)) 14165 sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); 14166 14167 *found = 1; 14168 } 14169 else 14170 *found = 0; 14171 14172 return sals; 14173 } 14174 14175 /* The default re_set method, for typical hardware or software 14176 breakpoints. Reevaluate the breakpoint and recreate its 14177 locations. */ 14178 14179 static void 14180 breakpoint_re_set_default (struct breakpoint *b) 14181 { 14182 int found; 14183 struct symtabs_and_lines sals, sals_end; 14184 struct symtabs_and_lines expanded = {0}; 14185 struct symtabs_and_lines expanded_end = {0}; 14186 14187 sals = addr_string_to_sals (b, b->addr_string, &found); 14188 if (found) 14189 { 14190 make_cleanup (xfree, sals.sals); 14191 expanded = sals; 14192 } 14193 14194 if (b->addr_string_range_end) 14195 { 14196 sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); 14197 if (found) 14198 { 14199 make_cleanup (xfree, sals_end.sals); 14200 expanded_end = sals_end; 14201 } 14202 } 14203 14204 update_breakpoint_locations (b, expanded, expanded_end); 14205 } 14206 14207 /* Default method for creating SALs from an address string. It basically 14208 calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ 14209 14210 static void 14211 create_sals_from_address_default (char **arg, 14212 struct linespec_result *canonical, 14213 enum bptype type_wanted, 14214 char *addr_start, char **copy_arg) 14215 { 14216 parse_breakpoint_sals (arg, canonical); 14217 } 14218 14219 /* Call create_breakpoints_sal for the given arguments. This is the default 14220 function for the `create_breakpoints_sal' method of 14221 breakpoint_ops. */ 14222 14223 static void 14224 create_breakpoints_sal_default (struct gdbarch *gdbarch, 14225 struct linespec_result *canonical, 14226 char *cond_string, 14227 char *extra_string, 14228 enum bptype type_wanted, 14229 enum bpdisp disposition, 14230 int thread, 14231 int task, int ignore_count, 14232 const struct breakpoint_ops *ops, 14233 int from_tty, int enabled, 14234 int internal, unsigned flags) 14235 { 14236 create_breakpoints_sal (gdbarch, canonical, cond_string, 14237 extra_string, 14238 type_wanted, disposition, 14239 thread, task, ignore_count, ops, from_tty, 14240 enabled, internal, flags); 14241 } 14242 14243 /* Decode the line represented by S by calling decode_line_full. This is the 14244 default function for the `decode_linespec' method of breakpoint_ops. */ 14245 14246 static void 14247 decode_linespec_default (struct breakpoint *b, char **s, 14248 struct symtabs_and_lines *sals) 14249 { 14250 struct linespec_result canonical; 14251 14252 init_linespec_result (&canonical); 14253 decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, 14254 (struct symtab *) NULL, 0, 14255 &canonical, multiple_symbols_all, 14256 b->filter); 14257 14258 /* We should get 0 or 1 resulting SALs. */ 14259 gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); 14260 14261 if (VEC_length (linespec_sals, canonical.sals) > 0) 14262 { 14263 struct linespec_sals *lsal; 14264 14265 lsal = VEC_index (linespec_sals, canonical.sals, 0); 14266 *sals = lsal->sals; 14267 /* Arrange it so the destructor does not free the 14268 contents. */ 14269 lsal->sals.sals = NULL; 14270 } 14271 14272 destroy_linespec_result (&canonical); 14273 } 14274 14275 /* Prepare the global context for a re-set of breakpoint B. */ 14276 14277 static struct cleanup * 14278 prepare_re_set_context (struct breakpoint *b) 14279 { 14280 struct cleanup *cleanups; 14281 14282 input_radix = b->input_radix; 14283 cleanups = save_current_space_and_thread (); 14284 if (b->pspace != NULL) 14285 switch_to_program_space_and_thread (b->pspace); 14286 set_language (b->language); 14287 14288 return cleanups; 14289 } 14290 14291 /* Reset a breakpoint given it's struct breakpoint * BINT. 14292 The value we return ends up being the return value from catch_errors. 14293 Unused in this case. */ 14294 14295 static int 14296 breakpoint_re_set_one (void *bint) 14297 { 14298 /* Get past catch_errs. */ 14299 struct breakpoint *b = (struct breakpoint *) bint; 14300 struct cleanup *cleanups; 14301 14302 cleanups = prepare_re_set_context (b); 14303 b->ops->re_set (b); 14304 do_cleanups (cleanups); 14305 return 0; 14306 } 14307 14308 /* Re-set all breakpoints after symbols have been re-loaded. */ 14309 void 14310 breakpoint_re_set (void) 14311 { 14312 struct breakpoint *b, *b_tmp; 14313 enum language save_language; 14314 int save_input_radix; 14315 struct cleanup *old_chain; 14316 14317 save_language = current_language->la_language; 14318 save_input_radix = input_radix; 14319 old_chain = save_current_program_space (); 14320 14321 ALL_BREAKPOINTS_SAFE (b, b_tmp) 14322 { 14323 /* Format possible error msg. */ 14324 char *message = xstrprintf ("Error in re-setting breakpoint %d: ", 14325 b->number); 14326 struct cleanup *cleanups = make_cleanup (xfree, message); 14327 catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); 14328 do_cleanups (cleanups); 14329 } 14330 set_language (save_language); 14331 input_radix = save_input_radix; 14332 14333 jit_breakpoint_re_set (); 14334 14335 do_cleanups (old_chain); 14336 14337 create_overlay_event_breakpoint (); 14338 create_longjmp_master_breakpoint (); 14339 create_std_terminate_master_breakpoint (); 14340 create_exception_master_breakpoint (); 14341 } 14342 14343 /* Reset the thread number of this breakpoint: 14344 14345 - If the breakpoint is for all threads, leave it as-is. 14346 - Else, reset it to the current thread for inferior_ptid. */ 14347 void 14348 breakpoint_re_set_thread (struct breakpoint *b) 14349 { 14350 if (b->thread != -1) 14351 { 14352 if (in_thread_list (inferior_ptid)) 14353 b->thread = pid_to_thread_id (inferior_ptid); 14354 14355 /* We're being called after following a fork. The new fork is 14356 selected as current, and unless this was a vfork will have a 14357 different program space from the original thread. Reset that 14358 as well. */ 14359 b->loc->pspace = current_program_space; 14360 } 14361 } 14362 14363 /* Set ignore-count of breakpoint number BPTNUM to COUNT. 14364 If from_tty is nonzero, it prints a message to that effect, 14365 which ends with a period (no newline). */ 14366 14367 void 14368 set_ignore_count (int bptnum, int count, int from_tty) 14369 { 14370 struct breakpoint *b; 14371 14372 if (count < 0) 14373 count = 0; 14374 14375 ALL_BREAKPOINTS (b) 14376 if (b->number == bptnum) 14377 { 14378 if (is_tracepoint (b)) 14379 { 14380 if (from_tty && count != 0) 14381 printf_filtered (_("Ignore count ignored for tracepoint %d."), 14382 bptnum); 14383 return; 14384 } 14385 14386 b->ignore_count = count; 14387 if (from_tty) 14388 { 14389 if (count == 0) 14390 printf_filtered (_("Will stop next time " 14391 "breakpoint %d is reached."), 14392 bptnum); 14393 else if (count == 1) 14394 printf_filtered (_("Will ignore next crossing of breakpoint %d."), 14395 bptnum); 14396 else 14397 printf_filtered (_("Will ignore next %d " 14398 "crossings of breakpoint %d."), 14399 count, bptnum); 14400 } 14401 observer_notify_breakpoint_modified (b); 14402 return; 14403 } 14404 14405 error (_("No breakpoint number %d."), bptnum); 14406 } 14407 14408 /* Command to set ignore-count of breakpoint N to COUNT. */ 14409 14410 static void 14411 ignore_command (char *args, int from_tty) 14412 { 14413 char *p = args; 14414 int num; 14415 14416 if (p == 0) 14417 error_no_arg (_("a breakpoint number")); 14418 14419 num = get_number (&p); 14420 if (num == 0) 14421 error (_("bad breakpoint number: '%s'"), args); 14422 if (*p == 0) 14423 error (_("Second argument (specified ignore-count) is missing.")); 14424 14425 set_ignore_count (num, 14426 longest_to_int (value_as_long (parse_and_eval (p))), 14427 from_tty); 14428 if (from_tty) 14429 printf_filtered ("\n"); 14430 } 14431 14432 /* Call FUNCTION on each of the breakpoints 14433 whose numbers are given in ARGS. */ 14434 14435 static void 14436 map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, 14437 void *), 14438 void *data) 14439 { 14440 int num; 14441 struct breakpoint *b, *tmp; 14442 int match; 14443 struct get_number_or_range_state state; 14444 14445 if (args == 0) 14446 error_no_arg (_("one or more breakpoint numbers")); 14447 14448 init_number_or_range (&state, args); 14449 14450 while (!state.finished) 14451 { 14452 char *p = state.string; 14453 14454 match = 0; 14455 14456 num = get_number_or_range (&state); 14457 if (num == 0) 14458 { 14459 warning (_("bad breakpoint number at or near '%s'"), p); 14460 } 14461 else 14462 { 14463 ALL_BREAKPOINTS_SAFE (b, tmp) 14464 if (b->number == num) 14465 { 14466 match = 1; 14467 function (b, data); 14468 break; 14469 } 14470 if (match == 0) 14471 printf_unfiltered (_("No breakpoint number %d.\n"), num); 14472 } 14473 } 14474 } 14475 14476 static struct bp_location * 14477 find_location_by_number (char *number) 14478 { 14479 char *dot = strchr (number, '.'); 14480 char *p1; 14481 int bp_num; 14482 int loc_num; 14483 struct breakpoint *b; 14484 struct bp_location *loc; 14485 14486 *dot = '\0'; 14487 14488 p1 = number; 14489 bp_num = get_number (&p1); 14490 if (bp_num == 0) 14491 error (_("Bad breakpoint number '%s'"), number); 14492 14493 ALL_BREAKPOINTS (b) 14494 if (b->number == bp_num) 14495 { 14496 break; 14497 } 14498 14499 if (!b || b->number != bp_num) 14500 error (_("Bad breakpoint number '%s'"), number); 14501 14502 p1 = dot+1; 14503 loc_num = get_number (&p1); 14504 if (loc_num == 0) 14505 error (_("Bad breakpoint location number '%s'"), number); 14506 14507 --loc_num; 14508 loc = b->loc; 14509 for (;loc_num && loc; --loc_num, loc = loc->next) 14510 ; 14511 if (!loc) 14512 error (_("Bad breakpoint location number '%s'"), dot+1); 14513 14514 return loc; 14515 } 14516 14517 14518 /* Set ignore-count of breakpoint number BPTNUM to COUNT. 14519 If from_tty is nonzero, it prints a message to that effect, 14520 which ends with a period (no newline). */ 14521 14522 void 14523 disable_breakpoint (struct breakpoint *bpt) 14524 { 14525 /* Never disable a watchpoint scope breakpoint; we want to 14526 hit them when we leave scope so we can delete both the 14527 watchpoint and its scope breakpoint at that time. */ 14528 if (bpt->type == bp_watchpoint_scope) 14529 return; 14530 14531 /* You can't disable permanent breakpoints. */ 14532 if (bpt->enable_state == bp_permanent) 14533 return; 14534 14535 bpt->enable_state = bp_disabled; 14536 14537 /* Mark breakpoint locations modified. */ 14538 mark_breakpoint_modified (bpt); 14539 14540 if (target_supports_enable_disable_tracepoint () 14541 && current_trace_status ()->running && is_tracepoint (bpt)) 14542 { 14543 struct bp_location *location; 14544 14545 for (location = bpt->loc; location; location = location->next) 14546 target_disable_tracepoint (location); 14547 } 14548 14549 update_global_location_list (0); 14550 14551 observer_notify_breakpoint_modified (bpt); 14552 } 14553 14554 /* A callback for iterate_over_related_breakpoints. */ 14555 14556 static void 14557 do_disable_breakpoint (struct breakpoint *b, void *ignore) 14558 { 14559 disable_breakpoint (b); 14560 } 14561 14562 /* A callback for map_breakpoint_numbers that calls 14563 disable_breakpoint. */ 14564 14565 static void 14566 do_map_disable_breakpoint (struct breakpoint *b, void *ignore) 14567 { 14568 iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); 14569 } 14570 14571 static void 14572 disable_command (char *args, int from_tty) 14573 { 14574 if (args == 0) 14575 { 14576 struct breakpoint *bpt; 14577 14578 ALL_BREAKPOINTS (bpt) 14579 if (user_breakpoint_p (bpt)) 14580 disable_breakpoint (bpt); 14581 } 14582 else 14583 { 14584 char *num = extract_arg (&args); 14585 14586 while (num) 14587 { 14588 if (strchr (num, '.')) 14589 { 14590 struct bp_location *loc = find_location_by_number (num); 14591 14592 if (loc) 14593 { 14594 if (loc->enabled) 14595 { 14596 loc->enabled = 0; 14597 mark_breakpoint_location_modified (loc); 14598 } 14599 if (target_supports_enable_disable_tracepoint () 14600 && current_trace_status ()->running && loc->owner 14601 && is_tracepoint (loc->owner)) 14602 target_disable_tracepoint (loc); 14603 } 14604 update_global_location_list (0); 14605 } 14606 else 14607 map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); 14608 num = extract_arg (&args); 14609 } 14610 } 14611 } 14612 14613 static void 14614 enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, 14615 int count) 14616 { 14617 int target_resources_ok; 14618 14619 if (bpt->type == bp_hardware_breakpoint) 14620 { 14621 int i; 14622 i = hw_breakpoint_used_count (); 14623 target_resources_ok = 14624 target_can_use_hardware_watchpoint (bp_hardware_breakpoint, 14625 i + 1, 0); 14626 if (target_resources_ok == 0) 14627 error (_("No hardware breakpoint support in the target.")); 14628 else if (target_resources_ok < 0) 14629 error (_("Hardware breakpoints used exceeds limit.")); 14630 } 14631 14632 if (is_watchpoint (bpt)) 14633 { 14634 /* Initialize it just to avoid a GCC false warning. */ 14635 enum enable_state orig_enable_state = 0; 14636 volatile struct gdb_exception e; 14637 14638 TRY_CATCH (e, RETURN_MASK_ALL) 14639 { 14640 struct watchpoint *w = (struct watchpoint *) bpt; 14641 14642 orig_enable_state = bpt->enable_state; 14643 bpt->enable_state = bp_enabled; 14644 update_watchpoint (w, 1 /* reparse */); 14645 } 14646 if (e.reason < 0) 14647 { 14648 bpt->enable_state = orig_enable_state; 14649 exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), 14650 bpt->number); 14651 return; 14652 } 14653 } 14654 14655 if (bpt->enable_state != bp_permanent) 14656 bpt->enable_state = bp_enabled; 14657 14658 bpt->enable_state = bp_enabled; 14659 14660 /* Mark breakpoint locations modified. */ 14661 mark_breakpoint_modified (bpt); 14662 14663 if (target_supports_enable_disable_tracepoint () 14664 && current_trace_status ()->running && is_tracepoint (bpt)) 14665 { 14666 struct bp_location *location; 14667 14668 for (location = bpt->loc; location; location = location->next) 14669 target_enable_tracepoint (location); 14670 } 14671 14672 bpt->disposition = disposition; 14673 bpt->enable_count = count; 14674 update_global_location_list (1); 14675 14676 observer_notify_breakpoint_modified (bpt); 14677 } 14678 14679 14680 void 14681 enable_breakpoint (struct breakpoint *bpt) 14682 { 14683 enable_breakpoint_disp (bpt, bpt->disposition, 0); 14684 } 14685 14686 static void 14687 do_enable_breakpoint (struct breakpoint *bpt, void *arg) 14688 { 14689 enable_breakpoint (bpt); 14690 } 14691 14692 /* A callback for map_breakpoint_numbers that calls 14693 enable_breakpoint. */ 14694 14695 static void 14696 do_map_enable_breakpoint (struct breakpoint *b, void *ignore) 14697 { 14698 iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); 14699 } 14700 14701 /* The enable command enables the specified breakpoints (or all defined 14702 breakpoints) so they once again become (or continue to be) effective 14703 in stopping the inferior. */ 14704 14705 static void 14706 enable_command (char *args, int from_tty) 14707 { 14708 if (args == 0) 14709 { 14710 struct breakpoint *bpt; 14711 14712 ALL_BREAKPOINTS (bpt) 14713 if (user_breakpoint_p (bpt)) 14714 enable_breakpoint (bpt); 14715 } 14716 else 14717 { 14718 char *num = extract_arg (&args); 14719 14720 while (num) 14721 { 14722 if (strchr (num, '.')) 14723 { 14724 struct bp_location *loc = find_location_by_number (num); 14725 14726 if (loc) 14727 { 14728 if (!loc->enabled) 14729 { 14730 loc->enabled = 1; 14731 mark_breakpoint_location_modified (loc); 14732 } 14733 if (target_supports_enable_disable_tracepoint () 14734 && current_trace_status ()->running && loc->owner 14735 && is_tracepoint (loc->owner)) 14736 target_enable_tracepoint (loc); 14737 } 14738 update_global_location_list (1); 14739 } 14740 else 14741 map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); 14742 num = extract_arg (&args); 14743 } 14744 } 14745 } 14746 14747 /* This struct packages up disposition data for application to multiple 14748 breakpoints. */ 14749 14750 struct disp_data 14751 { 14752 enum bpdisp disp; 14753 int count; 14754 }; 14755 14756 static void 14757 do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) 14758 { 14759 struct disp_data disp_data = *(struct disp_data *) arg; 14760 14761 enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); 14762 } 14763 14764 static void 14765 do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) 14766 { 14767 struct disp_data disp = { disp_disable, 1 }; 14768 14769 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); 14770 } 14771 14772 static void 14773 enable_once_command (char *args, int from_tty) 14774 { 14775 map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); 14776 } 14777 14778 static void 14779 do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) 14780 { 14781 struct disp_data disp = { disp_disable, *(int *) countptr }; 14782 14783 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); 14784 } 14785 14786 static void 14787 enable_count_command (char *args, int from_tty) 14788 { 14789 int count = get_number (&args); 14790 14791 map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); 14792 } 14793 14794 static void 14795 do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) 14796 { 14797 struct disp_data disp = { disp_del, 1 }; 14798 14799 iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); 14800 } 14801 14802 static void 14803 enable_delete_command (char *args, int from_tty) 14804 { 14805 map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); 14806 } 14807 14808 static void 14809 set_breakpoint_cmd (char *args, int from_tty) 14810 { 14811 } 14812 14813 static void 14814 show_breakpoint_cmd (char *args, int from_tty) 14815 { 14816 } 14817 14818 /* Invalidate last known value of any hardware watchpoint if 14819 the memory which that value represents has been written to by 14820 GDB itself. */ 14821 14822 static void 14823 invalidate_bp_value_on_memory_change (struct inferior *inferior, 14824 CORE_ADDR addr, ssize_t len, 14825 const bfd_byte *data) 14826 { 14827 struct breakpoint *bp; 14828 14829 ALL_BREAKPOINTS (bp) 14830 if (bp->enable_state == bp_enabled 14831 && bp->type == bp_hardware_watchpoint) 14832 { 14833 struct watchpoint *wp = (struct watchpoint *) bp; 14834 14835 if (wp->val_valid && wp->val) 14836 { 14837 struct bp_location *loc; 14838 14839 for (loc = bp->loc; loc != NULL; loc = loc->next) 14840 if (loc->loc_type == bp_loc_hardware_watchpoint 14841 && loc->address + loc->length > addr 14842 && addr + len > loc->address) 14843 { 14844 value_free (wp->val); 14845 wp->val = NULL; 14846 wp->val_valid = 0; 14847 } 14848 } 14849 } 14850 } 14851 14852 /* Create and insert a raw software breakpoint at PC. Return an 14853 identifier, which should be used to remove the breakpoint later. 14854 In general, places which call this should be using something on the 14855 breakpoint chain instead; this function should be eliminated 14856 someday. */ 14857 14858 void * 14859 deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, 14860 struct address_space *aspace, CORE_ADDR pc) 14861 { 14862 struct bp_target_info *bp_tgt; 14863 14864 bp_tgt = XZALLOC (struct bp_target_info); 14865 14866 bp_tgt->placed_address_space = aspace; 14867 bp_tgt->placed_address = pc; 14868 14869 if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) 14870 { 14871 /* Could not insert the breakpoint. */ 14872 xfree (bp_tgt); 14873 return NULL; 14874 } 14875 14876 return bp_tgt; 14877 } 14878 14879 /* Remove a breakpoint BP inserted by 14880 deprecated_insert_raw_breakpoint. */ 14881 14882 int 14883 deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) 14884 { 14885 struct bp_target_info *bp_tgt = bp; 14886 int ret; 14887 14888 ret = target_remove_breakpoint (gdbarch, bp_tgt); 14889 xfree (bp_tgt); 14890 14891 return ret; 14892 } 14893 14894 /* One (or perhaps two) breakpoints used for software single 14895 stepping. */ 14896 14897 static void *single_step_breakpoints[2]; 14898 static struct gdbarch *single_step_gdbarch[2]; 14899 14900 /* Create and insert a breakpoint for software single step. */ 14901 14902 void 14903 insert_single_step_breakpoint (struct gdbarch *gdbarch, 14904 struct address_space *aspace, 14905 CORE_ADDR next_pc) 14906 { 14907 void **bpt_p; 14908 14909 if (single_step_breakpoints[0] == NULL) 14910 { 14911 bpt_p = &single_step_breakpoints[0]; 14912 single_step_gdbarch[0] = gdbarch; 14913 } 14914 else 14915 { 14916 gdb_assert (single_step_breakpoints[1] == NULL); 14917 bpt_p = &single_step_breakpoints[1]; 14918 single_step_gdbarch[1] = gdbarch; 14919 } 14920 14921 /* NOTE drow/2006-04-11: A future improvement to this function would 14922 be to only create the breakpoints once, and actually put them on 14923 the breakpoint chain. That would let us use set_raw_breakpoint. 14924 We could adjust the addresses each time they were needed. Doing 14925 this requires corresponding changes elsewhere where single step 14926 breakpoints are handled, however. So, for now, we use this. */ 14927 14928 *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); 14929 if (*bpt_p == NULL) 14930 error (_("Could not insert single-step breakpoint at %s"), 14931 paddress (gdbarch, next_pc)); 14932 } 14933 14934 /* Check if the breakpoints used for software single stepping 14935 were inserted or not. */ 14936 14937 int 14938 single_step_breakpoints_inserted (void) 14939 { 14940 return (single_step_breakpoints[0] != NULL 14941 || single_step_breakpoints[1] != NULL); 14942 } 14943 14944 /* Remove and delete any breakpoints used for software single step. */ 14945 14946 void 14947 remove_single_step_breakpoints (void) 14948 { 14949 gdb_assert (single_step_breakpoints[0] != NULL); 14950 14951 /* See insert_single_step_breakpoint for more about this deprecated 14952 call. */ 14953 deprecated_remove_raw_breakpoint (single_step_gdbarch[0], 14954 single_step_breakpoints[0]); 14955 single_step_gdbarch[0] = NULL; 14956 single_step_breakpoints[0] = NULL; 14957 14958 if (single_step_breakpoints[1] != NULL) 14959 { 14960 deprecated_remove_raw_breakpoint (single_step_gdbarch[1], 14961 single_step_breakpoints[1]); 14962 single_step_gdbarch[1] = NULL; 14963 single_step_breakpoints[1] = NULL; 14964 } 14965 } 14966 14967 /* Delete software single step breakpoints without removing them from 14968 the inferior. This is intended to be used if the inferior's address 14969 space where they were inserted is already gone, e.g. after exit or 14970 exec. */ 14971 14972 void 14973 cancel_single_step_breakpoints (void) 14974 { 14975 int i; 14976 14977 for (i = 0; i < 2; i++) 14978 if (single_step_breakpoints[i]) 14979 { 14980 xfree (single_step_breakpoints[i]); 14981 single_step_breakpoints[i] = NULL; 14982 single_step_gdbarch[i] = NULL; 14983 } 14984 } 14985 14986 /* Detach software single-step breakpoints from INFERIOR_PTID without 14987 removing them. */ 14988 14989 static void 14990 detach_single_step_breakpoints (void) 14991 { 14992 int i; 14993 14994 for (i = 0; i < 2; i++) 14995 if (single_step_breakpoints[i]) 14996 target_remove_breakpoint (single_step_gdbarch[i], 14997 single_step_breakpoints[i]); 14998 } 14999 15000 /* Check whether a software single-step breakpoint is inserted at 15001 PC. */ 15002 15003 static int 15004 single_step_breakpoint_inserted_here_p (struct address_space *aspace, 15005 CORE_ADDR pc) 15006 { 15007 int i; 15008 15009 for (i = 0; i < 2; i++) 15010 { 15011 struct bp_target_info *bp_tgt = single_step_breakpoints[i]; 15012 if (bp_tgt 15013 && breakpoint_address_match (bp_tgt->placed_address_space, 15014 bp_tgt->placed_address, 15015 aspace, pc)) 15016 return 1; 15017 } 15018 15019 return 0; 15020 } 15021 15022 /* Returns 0 if 'bp' is NOT a syscall catchpoint, 15023 non-zero otherwise. */ 15024 static int 15025 is_syscall_catchpoint_enabled (struct breakpoint *bp) 15026 { 15027 if (syscall_catchpoint_p (bp) 15028 && bp->enable_state != bp_disabled 15029 && bp->enable_state != bp_call_disabled) 15030 return 1; 15031 else 15032 return 0; 15033 } 15034 15035 int 15036 catch_syscall_enabled (void) 15037 { 15038 struct catch_syscall_inferior_data *inf_data 15039 = get_catch_syscall_inferior_data (current_inferior ()); 15040 15041 return inf_data->total_syscalls_count != 0; 15042 } 15043 15044 int 15045 catching_syscall_number (int syscall_number) 15046 { 15047 struct breakpoint *bp; 15048 15049 ALL_BREAKPOINTS (bp) 15050 if (is_syscall_catchpoint_enabled (bp)) 15051 { 15052 struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; 15053 15054 if (c->syscalls_to_be_caught) 15055 { 15056 int i, iter; 15057 for (i = 0; 15058 VEC_iterate (int, c->syscalls_to_be_caught, i, iter); 15059 i++) 15060 if (syscall_number == iter) 15061 return 1; 15062 } 15063 else 15064 return 1; 15065 } 15066 15067 return 0; 15068 } 15069 15070 /* Complete syscall names. Used by "catch syscall". */ 15071 static VEC (char_ptr) * 15072 catch_syscall_completer (struct cmd_list_element *cmd, 15073 const char *text, const char *word) 15074 { 15075 const char **list = get_syscall_names (); 15076 VEC (char_ptr) *retlist 15077 = (list == NULL) ? NULL : complete_on_enum (list, word, word); 15078 15079 xfree (list); 15080 return retlist; 15081 } 15082 15083 /* Tracepoint-specific operations. */ 15084 15085 /* Set tracepoint count to NUM. */ 15086 static void 15087 set_tracepoint_count (int num) 15088 { 15089 tracepoint_count = num; 15090 set_internalvar_integer (lookup_internalvar ("tpnum"), num); 15091 } 15092 15093 static void 15094 trace_command (char *arg, int from_tty) 15095 { 15096 struct breakpoint_ops *ops; 15097 const char *arg_cp = arg; 15098 15099 if (arg && probe_linespec_to_ops (&arg_cp)) 15100 ops = &tracepoint_probe_breakpoint_ops; 15101 else 15102 ops = &tracepoint_breakpoint_ops; 15103 15104 create_breakpoint (get_current_arch (), 15105 arg, 15106 NULL, 0, NULL, 1 /* parse arg */, 15107 0 /* tempflag */, 15108 bp_tracepoint /* type_wanted */, 15109 0 /* Ignore count */, 15110 pending_break_support, 15111 ops, 15112 from_tty, 15113 1 /* enabled */, 15114 0 /* internal */, 0); 15115 } 15116 15117 static void 15118 ftrace_command (char *arg, int from_tty) 15119 { 15120 create_breakpoint (get_current_arch (), 15121 arg, 15122 NULL, 0, NULL, 1 /* parse arg */, 15123 0 /* tempflag */, 15124 bp_fast_tracepoint /* type_wanted */, 15125 0 /* Ignore count */, 15126 pending_break_support, 15127 &tracepoint_breakpoint_ops, 15128 from_tty, 15129 1 /* enabled */, 15130 0 /* internal */, 0); 15131 } 15132 15133 /* strace command implementation. Creates a static tracepoint. */ 15134 15135 static void 15136 strace_command (char *arg, int from_tty) 15137 { 15138 struct breakpoint_ops *ops; 15139 15140 /* Decide if we are dealing with a static tracepoint marker (`-m'), 15141 or with a normal static tracepoint. */ 15142 if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) 15143 ops = &strace_marker_breakpoint_ops; 15144 else 15145 ops = &tracepoint_breakpoint_ops; 15146 15147 create_breakpoint (get_current_arch (), 15148 arg, 15149 NULL, 0, NULL, 1 /* parse arg */, 15150 0 /* tempflag */, 15151 bp_static_tracepoint /* type_wanted */, 15152 0 /* Ignore count */, 15153 pending_break_support, 15154 ops, 15155 from_tty, 15156 1 /* enabled */, 15157 0 /* internal */, 0); 15158 } 15159 15160 /* Set up a fake reader function that gets command lines from a linked 15161 list that was acquired during tracepoint uploading. */ 15162 15163 static struct uploaded_tp *this_utp; 15164 static int next_cmd; 15165 15166 static char * 15167 read_uploaded_action (void) 15168 { 15169 char *rslt; 15170 15171 VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); 15172 15173 next_cmd++; 15174 15175 return rslt; 15176 } 15177 15178 /* Given information about a tracepoint as recorded on a target (which 15179 can be either a live system or a trace file), attempt to create an 15180 equivalent GDB tracepoint. This is not a reliable process, since 15181 the target does not necessarily have all the information used when 15182 the tracepoint was originally defined. */ 15183 15184 struct tracepoint * 15185 create_tracepoint_from_upload (struct uploaded_tp *utp) 15186 { 15187 char *addr_str, small_buf[100]; 15188 struct tracepoint *tp; 15189 15190 if (utp->at_string) 15191 addr_str = utp->at_string; 15192 else 15193 { 15194 /* In the absence of a source location, fall back to raw 15195 address. Since there is no way to confirm that the address 15196 means the same thing as when the trace was started, warn the 15197 user. */ 15198 warning (_("Uploaded tracepoint %d has no " 15199 "source location, using raw address"), 15200 utp->number); 15201 xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); 15202 addr_str = small_buf; 15203 } 15204 15205 /* There's not much we can do with a sequence of bytecodes. */ 15206 if (utp->cond && !utp->cond_string) 15207 warning (_("Uploaded tracepoint %d condition " 15208 "has no source form, ignoring it"), 15209 utp->number); 15210 15211 if (!create_breakpoint (get_current_arch (), 15212 addr_str, 15213 utp->cond_string, -1, NULL, 15214 0 /* parse cond/thread */, 15215 0 /* tempflag */, 15216 utp->type /* type_wanted */, 15217 0 /* Ignore count */, 15218 pending_break_support, 15219 &tracepoint_breakpoint_ops, 15220 0 /* from_tty */, 15221 utp->enabled /* enabled */, 15222 0 /* internal */, 15223 CREATE_BREAKPOINT_FLAGS_INSERTED)) 15224 return NULL; 15225 15226 /* Get the tracepoint we just created. */ 15227 tp = get_tracepoint (tracepoint_count); 15228 gdb_assert (tp != NULL); 15229 15230 if (utp->pass > 0) 15231 { 15232 xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, 15233 tp->base.number); 15234 15235 trace_pass_command (small_buf, 0); 15236 } 15237 15238 /* If we have uploaded versions of the original commands, set up a 15239 special-purpose "reader" function and call the usual command line 15240 reader, then pass the result to the breakpoint command-setting 15241 function. */ 15242 if (!VEC_empty (char_ptr, utp->cmd_strings)) 15243 { 15244 struct command_line *cmd_list; 15245 15246 this_utp = utp; 15247 next_cmd = 0; 15248 15249 cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); 15250 15251 breakpoint_set_commands (&tp->base, cmd_list); 15252 } 15253 else if (!VEC_empty (char_ptr, utp->actions) 15254 || !VEC_empty (char_ptr, utp->step_actions)) 15255 warning (_("Uploaded tracepoint %d actions " 15256 "have no source form, ignoring them"), 15257 utp->number); 15258 15259 /* Copy any status information that might be available. */ 15260 tp->base.hit_count = utp->hit_count; 15261 tp->traceframe_usage = utp->traceframe_usage; 15262 15263 return tp; 15264 } 15265 15266 /* Print information on tracepoint number TPNUM_EXP, or all if 15267 omitted. */ 15268 15269 static void 15270 tracepoints_info (char *args, int from_tty) 15271 { 15272 struct ui_out *uiout = current_uiout; 15273 int num_printed; 15274 15275 num_printed = breakpoint_1 (args, 0, is_tracepoint); 15276 15277 if (num_printed == 0) 15278 { 15279 if (args == NULL || *args == '\0') 15280 ui_out_message (uiout, 0, "No tracepoints.\n"); 15281 else 15282 ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); 15283 } 15284 15285 default_collect_info (); 15286 } 15287 15288 /* The 'enable trace' command enables tracepoints. 15289 Not supported by all targets. */ 15290 static void 15291 enable_trace_command (char *args, int from_tty) 15292 { 15293 enable_command (args, from_tty); 15294 } 15295 15296 /* The 'disable trace' command disables tracepoints. 15297 Not supported by all targets. */ 15298 static void 15299 disable_trace_command (char *args, int from_tty) 15300 { 15301 disable_command (args, from_tty); 15302 } 15303 15304 /* Remove a tracepoint (or all if no argument). */ 15305 static void 15306 delete_trace_command (char *arg, int from_tty) 15307 { 15308 struct breakpoint *b, *b_tmp; 15309 15310 dont_repeat (); 15311 15312 if (arg == 0) 15313 { 15314 int breaks_to_delete = 0; 15315 15316 /* Delete all breakpoints if no argument. 15317 Do not delete internal or call-dummy breakpoints, these 15318 have to be deleted with an explicit breakpoint number 15319 argument. */ 15320 ALL_TRACEPOINTS (b) 15321 if (is_tracepoint (b) && user_breakpoint_p (b)) 15322 { 15323 breaks_to_delete = 1; 15324 break; 15325 } 15326 15327 /* Ask user only if there are some breakpoints to delete. */ 15328 if (!from_tty 15329 || (breaks_to_delete && query (_("Delete all tracepoints? ")))) 15330 { 15331 ALL_BREAKPOINTS_SAFE (b, b_tmp) 15332 if (is_tracepoint (b) && user_breakpoint_p (b)) 15333 delete_breakpoint (b); 15334 } 15335 } 15336 else 15337 map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); 15338 } 15339 15340 /* Helper function for trace_pass_command. */ 15341 15342 static void 15343 trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) 15344 { 15345 tp->pass_count = count; 15346 observer_notify_breakpoint_modified (&tp->base); 15347 if (from_tty) 15348 printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), 15349 tp->base.number, count); 15350 } 15351 15352 /* Set passcount for tracepoint. 15353 15354 First command argument is passcount, second is tracepoint number. 15355 If tracepoint number omitted, apply to most recently defined. 15356 Also accepts special argument "all". */ 15357 15358 static void 15359 trace_pass_command (char *args, int from_tty) 15360 { 15361 struct tracepoint *t1; 15362 unsigned int count; 15363 15364 if (args == 0 || *args == 0) 15365 error (_("passcount command requires an " 15366 "argument (count + optional TP num)")); 15367 15368 count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ 15369 15370 args = skip_spaces (args); 15371 if (*args && strncasecmp (args, "all", 3) == 0) 15372 { 15373 struct breakpoint *b; 15374 15375 args += 3; /* Skip special argument "all". */ 15376 if (*args) 15377 error (_("Junk at end of arguments.")); 15378 15379 ALL_TRACEPOINTS (b) 15380 { 15381 t1 = (struct tracepoint *) b; 15382 trace_pass_set_count (t1, count, from_tty); 15383 } 15384 } 15385 else if (*args == '\0') 15386 { 15387 t1 = get_tracepoint_by_number (&args, NULL, 1); 15388 if (t1) 15389 trace_pass_set_count (t1, count, from_tty); 15390 } 15391 else 15392 { 15393 struct get_number_or_range_state state; 15394 15395 init_number_or_range (&state, args); 15396 while (!state.finished) 15397 { 15398 t1 = get_tracepoint_by_number (&args, &state, 1); 15399 if (t1) 15400 trace_pass_set_count (t1, count, from_tty); 15401 } 15402 } 15403 } 15404 15405 struct tracepoint * 15406 get_tracepoint (int num) 15407 { 15408 struct breakpoint *t; 15409 15410 ALL_TRACEPOINTS (t) 15411 if (t->number == num) 15412 return (struct tracepoint *) t; 15413 15414 return NULL; 15415 } 15416 15417 /* Find the tracepoint with the given target-side number (which may be 15418 different from the tracepoint number after disconnecting and 15419 reconnecting). */ 15420 15421 struct tracepoint * 15422 get_tracepoint_by_number_on_target (int num) 15423 { 15424 struct breakpoint *b; 15425 15426 ALL_TRACEPOINTS (b) 15427 { 15428 struct tracepoint *t = (struct tracepoint *) b; 15429 15430 if (t->number_on_target == num) 15431 return t; 15432 } 15433 15434 return NULL; 15435 } 15436 15437 /* Utility: parse a tracepoint number and look it up in the list. 15438 If STATE is not NULL, use, get_number_or_range_state and ignore ARG. 15439 If OPTIONAL_P is true, then if the argument is missing, the most 15440 recent tracepoint (tracepoint_count) is returned. */ 15441 struct tracepoint * 15442 get_tracepoint_by_number (char **arg, 15443 struct get_number_or_range_state *state, 15444 int optional_p) 15445 { 15446 struct breakpoint *t; 15447 int tpnum; 15448 char *instring = arg == NULL ? NULL : *arg; 15449 15450 if (state) 15451 { 15452 gdb_assert (!state->finished); 15453 tpnum = get_number_or_range (state); 15454 } 15455 else if (arg == NULL || *arg == NULL || ! **arg) 15456 { 15457 if (optional_p) 15458 tpnum = tracepoint_count; 15459 else 15460 error_no_arg (_("tracepoint number")); 15461 } 15462 else 15463 tpnum = get_number (arg); 15464 15465 if (tpnum <= 0) 15466 { 15467 if (instring && *instring) 15468 printf_filtered (_("bad tracepoint number at or near '%s'\n"), 15469 instring); 15470 else 15471 printf_filtered (_("Tracepoint argument missing " 15472 "and no previous tracepoint\n")); 15473 return NULL; 15474 } 15475 15476 ALL_TRACEPOINTS (t) 15477 if (t->number == tpnum) 15478 { 15479 return (struct tracepoint *) t; 15480 } 15481 15482 printf_unfiltered ("No tracepoint number %d.\n", tpnum); 15483 return NULL; 15484 } 15485 15486 void 15487 print_recreate_thread (struct breakpoint *b, struct ui_file *fp) 15488 { 15489 if (b->thread != -1) 15490 fprintf_unfiltered (fp, " thread %d", b->thread); 15491 15492 if (b->task != 0) 15493 fprintf_unfiltered (fp, " task %d", b->task); 15494 15495 fprintf_unfiltered (fp, "\n"); 15496 } 15497 15498 /* Save information on user settable breakpoints (watchpoints, etc) to 15499 a new script file named FILENAME. If FILTER is non-NULL, call it 15500 on each breakpoint and only include the ones for which it returns 15501 non-zero. */ 15502 15503 static void 15504 save_breakpoints (char *filename, int from_tty, 15505 int (*filter) (const struct breakpoint *)) 15506 { 15507 struct breakpoint *tp; 15508 int any = 0; 15509 struct cleanup *cleanup; 15510 struct ui_file *fp; 15511 int extra_trace_bits = 0; 15512 15513 if (filename == 0 || *filename == 0) 15514 error (_("Argument required (file name in which to save)")); 15515 15516 /* See if we have anything to save. */ 15517 ALL_BREAKPOINTS (tp) 15518 { 15519 /* Skip internal and momentary breakpoints. */ 15520 if (!user_breakpoint_p (tp)) 15521 continue; 15522 15523 /* If we have a filter, only save the breakpoints it accepts. */ 15524 if (filter && !filter (tp)) 15525 continue; 15526 15527 any = 1; 15528 15529 if (is_tracepoint (tp)) 15530 { 15531 extra_trace_bits = 1; 15532 15533 /* We can stop searching. */ 15534 break; 15535 } 15536 } 15537 15538 if (!any) 15539 { 15540 warning (_("Nothing to save.")); 15541 return; 15542 } 15543 15544 filename = tilde_expand (filename); 15545 cleanup = make_cleanup (xfree, filename); 15546 fp = gdb_fopen (filename, "w"); 15547 if (!fp) 15548 error (_("Unable to open file '%s' for saving (%s)"), 15549 filename, safe_strerror (errno)); 15550 make_cleanup_ui_file_delete (fp); 15551 15552 if (extra_trace_bits) 15553 save_trace_state_variables (fp); 15554 15555 ALL_BREAKPOINTS (tp) 15556 { 15557 /* Skip internal and momentary breakpoints. */ 15558 if (!user_breakpoint_p (tp)) 15559 continue; 15560 15561 /* If we have a filter, only save the breakpoints it accepts. */ 15562 if (filter && !filter (tp)) 15563 continue; 15564 15565 tp->ops->print_recreate (tp, fp); 15566 15567 /* Note, we can't rely on tp->number for anything, as we can't 15568 assume the recreated breakpoint numbers will match. Use $bpnum 15569 instead. */ 15570 15571 if (tp->cond_string) 15572 fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); 15573 15574 if (tp->ignore_count) 15575 fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); 15576 15577 if (tp->type != bp_dprintf && tp->commands) 15578 { 15579 volatile struct gdb_exception ex; 15580 15581 fprintf_unfiltered (fp, " commands\n"); 15582 15583 ui_out_redirect (current_uiout, fp); 15584 TRY_CATCH (ex, RETURN_MASK_ALL) 15585 { 15586 print_command_lines (current_uiout, tp->commands->commands, 2); 15587 } 15588 ui_out_redirect (current_uiout, NULL); 15589 15590 if (ex.reason < 0) 15591 throw_exception (ex); 15592 15593 fprintf_unfiltered (fp, " end\n"); 15594 } 15595 15596 if (tp->enable_state == bp_disabled) 15597 fprintf_unfiltered (fp, "disable\n"); 15598 15599 /* If this is a multi-location breakpoint, check if the locations 15600 should be individually disabled. Watchpoint locations are 15601 special, and not user visible. */ 15602 if (!is_watchpoint (tp) && tp->loc && tp->loc->next) 15603 { 15604 struct bp_location *loc; 15605 int n = 1; 15606 15607 for (loc = tp->loc; loc != NULL; loc = loc->next, n++) 15608 if (!loc->enabled) 15609 fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); 15610 } 15611 } 15612 15613 if (extra_trace_bits && *default_collect) 15614 fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); 15615 15616 if (from_tty) 15617 printf_filtered (_("Saved to file '%s'.\n"), filename); 15618 do_cleanups (cleanup); 15619 } 15620 15621 /* The `save breakpoints' command. */ 15622 15623 static void 15624 save_breakpoints_command (char *args, int from_tty) 15625 { 15626 save_breakpoints (args, from_tty, NULL); 15627 } 15628 15629 /* The `save tracepoints' command. */ 15630 15631 static void 15632 save_tracepoints_command (char *args, int from_tty) 15633 { 15634 save_breakpoints (args, from_tty, is_tracepoint); 15635 } 15636 15637 /* Create a vector of all tracepoints. */ 15638 15639 VEC(breakpoint_p) * 15640 all_tracepoints (void) 15641 { 15642 VEC(breakpoint_p) *tp_vec = 0; 15643 struct breakpoint *tp; 15644 15645 ALL_TRACEPOINTS (tp) 15646 { 15647 VEC_safe_push (breakpoint_p, tp_vec, tp); 15648 } 15649 15650 return tp_vec; 15651 } 15652 15653 15654 /* This help string is used for the break, hbreak, tbreak and thbreak 15655 commands. It is defined as a macro to prevent duplication. 15656 COMMAND should be a string constant containing the name of the 15657 command. */ 15658 #define BREAK_ARGS_HELP(command) \ 15659 command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ 15660 PROBE_MODIFIER shall be present if the command is to be placed in a\n\ 15661 probe point. Accepted values are `-probe' (for a generic, automatically\n\ 15662 guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ 15663 LOCATION may be a line number, function name, or \"*\" and an address.\n\ 15664 If a line number is specified, break at start of code for that line.\n\ 15665 If a function is specified, break at start of code for that function.\n\ 15666 If an address is specified, break at that exact address.\n\ 15667 With no LOCATION, uses current execution address of the selected\n\ 15668 stack frame. This is useful for breaking on return to a stack frame.\n\ 15669 \n\ 15670 THREADNUM is the number from \"info threads\".\n\ 15671 CONDITION is a boolean expression.\n\ 15672 \n\ 15673 Multiple breakpoints at one place are permitted, and useful if their\n\ 15674 conditions are different.\n\ 15675 \n\ 15676 Do \"help breakpoints\" for info on other commands dealing with breakpoints." 15677 15678 /* List of subcommands for "catch". */ 15679 static struct cmd_list_element *catch_cmdlist; 15680 15681 /* List of subcommands for "tcatch". */ 15682 static struct cmd_list_element *tcatch_cmdlist; 15683 15684 void 15685 add_catch_command (char *name, char *docstring, 15686 void (*sfunc) (char *args, int from_tty, 15687 struct cmd_list_element *command), 15688 completer_ftype *completer, 15689 void *user_data_catch, 15690 void *user_data_tcatch) 15691 { 15692 struct cmd_list_element *command; 15693 15694 command = add_cmd (name, class_breakpoint, NULL, docstring, 15695 &catch_cmdlist); 15696 set_cmd_sfunc (command, sfunc); 15697 set_cmd_context (command, user_data_catch); 15698 set_cmd_completer (command, completer); 15699 15700 command = add_cmd (name, class_breakpoint, NULL, docstring, 15701 &tcatch_cmdlist); 15702 set_cmd_sfunc (command, sfunc); 15703 set_cmd_context (command, user_data_tcatch); 15704 set_cmd_completer (command, completer); 15705 } 15706 15707 static void 15708 clear_syscall_counts (struct inferior *inf) 15709 { 15710 struct catch_syscall_inferior_data *inf_data 15711 = get_catch_syscall_inferior_data (inf); 15712 15713 inf_data->total_syscalls_count = 0; 15714 inf_data->any_syscall_count = 0; 15715 VEC_free (int, inf_data->syscalls_counts); 15716 } 15717 15718 static void 15719 save_command (char *arg, int from_tty) 15720 { 15721 printf_unfiltered (_("\"save\" must be followed by " 15722 "the name of a save subcommand.\n")); 15723 help_list (save_cmdlist, "save ", -1, gdb_stdout); 15724 } 15725 15726 struct breakpoint * 15727 iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), 15728 void *data) 15729 { 15730 struct breakpoint *b, *b_tmp; 15731 15732 ALL_BREAKPOINTS_SAFE (b, b_tmp) 15733 { 15734 if ((*callback) (b, data)) 15735 return b; 15736 } 15737 15738 return NULL; 15739 } 15740 15741 /* Zero if any of the breakpoint's locations could be a location where 15742 functions have been inlined, nonzero otherwise. */ 15743 15744 static int 15745 is_non_inline_function (struct breakpoint *b) 15746 { 15747 /* The shared library event breakpoint is set on the address of a 15748 non-inline function. */ 15749 if (b->type == bp_shlib_event) 15750 return 1; 15751 15752 return 0; 15753 } 15754 15755 /* Nonzero if the specified PC cannot be a location where functions 15756 have been inlined. */ 15757 15758 int 15759 pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, 15760 const struct target_waitstatus *ws) 15761 { 15762 struct breakpoint *b; 15763 struct bp_location *bl; 15764 15765 ALL_BREAKPOINTS (b) 15766 { 15767 if (!is_non_inline_function (b)) 15768 continue; 15769 15770 for (bl = b->loc; bl != NULL; bl = bl->next) 15771 { 15772 if (!bl->shlib_disabled 15773 && bpstat_check_location (bl, aspace, pc, ws)) 15774 return 1; 15775 } 15776 } 15777 15778 return 0; 15779 } 15780 15781 /* Remove any references to OBJFILE which is going to be freed. */ 15782 15783 void 15784 breakpoint_free_objfile (struct objfile *objfile) 15785 { 15786 struct bp_location **locp, *loc; 15787 15788 ALL_BP_LOCATIONS (loc, locp) 15789 if (loc->symtab != NULL && loc->symtab->objfile == objfile) 15790 loc->symtab = NULL; 15791 } 15792 15793 void 15794 initialize_breakpoint_ops (void) 15795 { 15796 static int initialized = 0; 15797 15798 struct breakpoint_ops *ops; 15799 15800 if (initialized) 15801 return; 15802 initialized = 1; 15803 15804 /* The breakpoint_ops structure to be inherit by all kinds of 15805 breakpoints (real breakpoints, i.e., user "break" breakpoints, 15806 internal and momentary breakpoints, etc.). */ 15807 ops = &bkpt_base_breakpoint_ops; 15808 *ops = base_breakpoint_ops; 15809 ops->re_set = bkpt_re_set; 15810 ops->insert_location = bkpt_insert_location; 15811 ops->remove_location = bkpt_remove_location; 15812 ops->breakpoint_hit = bkpt_breakpoint_hit; 15813 ops->create_sals_from_address = bkpt_create_sals_from_address; 15814 ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; 15815 ops->decode_linespec = bkpt_decode_linespec; 15816 15817 /* The breakpoint_ops structure to be used in regular breakpoints. */ 15818 ops = &bkpt_breakpoint_ops; 15819 *ops = bkpt_base_breakpoint_ops; 15820 ops->re_set = bkpt_re_set; 15821 ops->resources_needed = bkpt_resources_needed; 15822 ops->print_it = bkpt_print_it; 15823 ops->print_mention = bkpt_print_mention; 15824 ops->print_recreate = bkpt_print_recreate; 15825 15826 /* Ranged breakpoints. */ 15827 ops = &ranged_breakpoint_ops; 15828 *ops = bkpt_breakpoint_ops; 15829 ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; 15830 ops->resources_needed = resources_needed_ranged_breakpoint; 15831 ops->print_it = print_it_ranged_breakpoint; 15832 ops->print_one = print_one_ranged_breakpoint; 15833 ops->print_one_detail = print_one_detail_ranged_breakpoint; 15834 ops->print_mention = print_mention_ranged_breakpoint; 15835 ops->print_recreate = print_recreate_ranged_breakpoint; 15836 15837 /* Internal breakpoints. */ 15838 ops = &internal_breakpoint_ops; 15839 *ops = bkpt_base_breakpoint_ops; 15840 ops->re_set = internal_bkpt_re_set; 15841 ops->check_status = internal_bkpt_check_status; 15842 ops->print_it = internal_bkpt_print_it; 15843 ops->print_mention = internal_bkpt_print_mention; 15844 15845 /* Momentary breakpoints. */ 15846 ops = &momentary_breakpoint_ops; 15847 *ops = bkpt_base_breakpoint_ops; 15848 ops->re_set = momentary_bkpt_re_set; 15849 ops->check_status = momentary_bkpt_check_status; 15850 ops->print_it = momentary_bkpt_print_it; 15851 ops->print_mention = momentary_bkpt_print_mention; 15852 15853 /* Momentary breakpoints for bp_longjmp and bp_exception. */ 15854 ops = &longjmp_breakpoint_ops; 15855 *ops = momentary_breakpoint_ops; 15856 ops->dtor = longjmp_bkpt_dtor; 15857 15858 /* Probe breakpoints. */ 15859 ops = &bkpt_probe_breakpoint_ops; 15860 *ops = bkpt_breakpoint_ops; 15861 ops->insert_location = bkpt_probe_insert_location; 15862 ops->remove_location = bkpt_probe_remove_location; 15863 ops->create_sals_from_address = bkpt_probe_create_sals_from_address; 15864 ops->decode_linespec = bkpt_probe_decode_linespec; 15865 15866 /* Watchpoints. */ 15867 ops = &watchpoint_breakpoint_ops; 15868 *ops = base_breakpoint_ops; 15869 ops->dtor = dtor_watchpoint; 15870 ops->re_set = re_set_watchpoint; 15871 ops->insert_location = insert_watchpoint; 15872 ops->remove_location = remove_watchpoint; 15873 ops->breakpoint_hit = breakpoint_hit_watchpoint; 15874 ops->check_status = check_status_watchpoint; 15875 ops->resources_needed = resources_needed_watchpoint; 15876 ops->works_in_software_mode = works_in_software_mode_watchpoint; 15877 ops->print_it = print_it_watchpoint; 15878 ops->print_mention = print_mention_watchpoint; 15879 ops->print_recreate = print_recreate_watchpoint; 15880 ops->explains_signal = explains_signal_watchpoint; 15881 15882 /* Masked watchpoints. */ 15883 ops = &masked_watchpoint_breakpoint_ops; 15884 *ops = watchpoint_breakpoint_ops; 15885 ops->insert_location = insert_masked_watchpoint; 15886 ops->remove_location = remove_masked_watchpoint; 15887 ops->resources_needed = resources_needed_masked_watchpoint; 15888 ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; 15889 ops->print_it = print_it_masked_watchpoint; 15890 ops->print_one_detail = print_one_detail_masked_watchpoint; 15891 ops->print_mention = print_mention_masked_watchpoint; 15892 ops->print_recreate = print_recreate_masked_watchpoint; 15893 15894 /* Tracepoints. */ 15895 ops = &tracepoint_breakpoint_ops; 15896 *ops = base_breakpoint_ops; 15897 ops->re_set = tracepoint_re_set; 15898 ops->breakpoint_hit = tracepoint_breakpoint_hit; 15899 ops->print_one_detail = tracepoint_print_one_detail; 15900 ops->print_mention = tracepoint_print_mention; 15901 ops->print_recreate = tracepoint_print_recreate; 15902 ops->create_sals_from_address = tracepoint_create_sals_from_address; 15903 ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; 15904 ops->decode_linespec = tracepoint_decode_linespec; 15905 15906 /* Probe tracepoints. */ 15907 ops = &tracepoint_probe_breakpoint_ops; 15908 *ops = tracepoint_breakpoint_ops; 15909 ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; 15910 ops->decode_linespec = tracepoint_probe_decode_linespec; 15911 15912 /* Static tracepoints with marker (`-m'). */ 15913 ops = &strace_marker_breakpoint_ops; 15914 *ops = tracepoint_breakpoint_ops; 15915 ops->create_sals_from_address = strace_marker_create_sals_from_address; 15916 ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; 15917 ops->decode_linespec = strace_marker_decode_linespec; 15918 15919 /* Fork catchpoints. */ 15920 ops = &catch_fork_breakpoint_ops; 15921 *ops = base_breakpoint_ops; 15922 ops->insert_location = insert_catch_fork; 15923 ops->remove_location = remove_catch_fork; 15924 ops->breakpoint_hit = breakpoint_hit_catch_fork; 15925 ops->print_it = print_it_catch_fork; 15926 ops->print_one = print_one_catch_fork; 15927 ops->print_mention = print_mention_catch_fork; 15928 ops->print_recreate = print_recreate_catch_fork; 15929 15930 /* Vfork catchpoints. */ 15931 ops = &catch_vfork_breakpoint_ops; 15932 *ops = base_breakpoint_ops; 15933 ops->insert_location = insert_catch_vfork; 15934 ops->remove_location = remove_catch_vfork; 15935 ops->breakpoint_hit = breakpoint_hit_catch_vfork; 15936 ops->print_it = print_it_catch_vfork; 15937 ops->print_one = print_one_catch_vfork; 15938 ops->print_mention = print_mention_catch_vfork; 15939 ops->print_recreate = print_recreate_catch_vfork; 15940 15941 /* Exec catchpoints. */ 15942 ops = &catch_exec_breakpoint_ops; 15943 *ops = base_breakpoint_ops; 15944 ops->dtor = dtor_catch_exec; 15945 ops->insert_location = insert_catch_exec; 15946 ops->remove_location = remove_catch_exec; 15947 ops->breakpoint_hit = breakpoint_hit_catch_exec; 15948 ops->print_it = print_it_catch_exec; 15949 ops->print_one = print_one_catch_exec; 15950 ops->print_mention = print_mention_catch_exec; 15951 ops->print_recreate = print_recreate_catch_exec; 15952 15953 /* Syscall catchpoints. */ 15954 ops = &catch_syscall_breakpoint_ops; 15955 *ops = base_breakpoint_ops; 15956 ops->dtor = dtor_catch_syscall; 15957 ops->insert_location = insert_catch_syscall; 15958 ops->remove_location = remove_catch_syscall; 15959 ops->breakpoint_hit = breakpoint_hit_catch_syscall; 15960 ops->print_it = print_it_catch_syscall; 15961 ops->print_one = print_one_catch_syscall; 15962 ops->print_mention = print_mention_catch_syscall; 15963 ops->print_recreate = print_recreate_catch_syscall; 15964 15965 /* Solib-related catchpoints. */ 15966 ops = &catch_solib_breakpoint_ops; 15967 *ops = base_breakpoint_ops; 15968 ops->dtor = dtor_catch_solib; 15969 ops->insert_location = insert_catch_solib; 15970 ops->remove_location = remove_catch_solib; 15971 ops->breakpoint_hit = breakpoint_hit_catch_solib; 15972 ops->check_status = check_status_catch_solib; 15973 ops->print_it = print_it_catch_solib; 15974 ops->print_one = print_one_catch_solib; 15975 ops->print_mention = print_mention_catch_solib; 15976 ops->print_recreate = print_recreate_catch_solib; 15977 15978 ops = &dprintf_breakpoint_ops; 15979 *ops = bkpt_base_breakpoint_ops; 15980 ops->re_set = dprintf_re_set; 15981 ops->resources_needed = bkpt_resources_needed; 15982 ops->print_it = bkpt_print_it; 15983 ops->print_mention = bkpt_print_mention; 15984 ops->print_recreate = dprintf_print_recreate; 15985 ops->after_condition_true = dprintf_after_condition_true; 15986 } 15987 15988 /* Chain containing all defined "enable breakpoint" subcommands. */ 15989 15990 static struct cmd_list_element *enablebreaklist = NULL; 15991 15992 void 15993 _initialize_breakpoint (void) 15994 { 15995 struct cmd_list_element *c; 15996 15997 initialize_breakpoint_ops (); 15998 15999 observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); 16000 observer_attach_inferior_exit (clear_syscall_counts); 16001 observer_attach_memory_changed (invalidate_bp_value_on_memory_change); 16002 16003 breakpoint_objfile_key 16004 = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); 16005 16006 catch_syscall_inferior_data 16007 = register_inferior_data_with_cleanup (NULL, 16008 catch_syscall_inferior_data_cleanup); 16009 16010 breakpoint_chain = 0; 16011 /* Don't bother to call set_breakpoint_count. $bpnum isn't useful 16012 before a breakpoint is set. */ 16013 breakpoint_count = 0; 16014 16015 tracepoint_count = 0; 16016 16017 add_com ("ignore", class_breakpoint, ignore_command, _("\ 16018 Set ignore-count of breakpoint number N to COUNT.\n\ 16019 Usage is `ignore N COUNT'.")); 16020 if (xdb_commands) 16021 add_com_alias ("bc", "ignore", class_breakpoint, 1); 16022 16023 add_com ("commands", class_breakpoint, commands_command, _("\ 16024 Set commands to be executed when a breakpoint is hit.\n\ 16025 Give breakpoint number as argument after \"commands\".\n\ 16026 With no argument, the targeted breakpoint is the last one set.\n\ 16027 The commands themselves follow starting on the next line.\n\ 16028 Type a line containing \"end\" to indicate the end of them.\n\ 16029 Give \"silent\" as the first line to make the breakpoint silent;\n\ 16030 then no output is printed when it is hit, except what the commands print.")); 16031 16032 c = add_com ("condition", class_breakpoint, condition_command, _("\ 16033 Specify breakpoint number N to break only if COND is true.\n\ 16034 Usage is `condition N COND', where N is an integer and COND is an\n\ 16035 expression to be evaluated whenever breakpoint N is reached.")); 16036 set_cmd_completer (c, condition_completer); 16037 16038 c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ 16039 Set a temporary breakpoint.\n\ 16040 Like \"break\" except the breakpoint is only temporary,\n\ 16041 so it will be deleted when hit. Equivalent to \"break\" followed\n\ 16042 by using \"enable delete\" on the breakpoint number.\n\ 16043 \n" 16044 BREAK_ARGS_HELP ("tbreak"))); 16045 set_cmd_completer (c, location_completer); 16046 16047 c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ 16048 Set a hardware assisted breakpoint.\n\ 16049 Like \"break\" except the breakpoint requires hardware support,\n\ 16050 some target hardware may not have this support.\n\ 16051 \n" 16052 BREAK_ARGS_HELP ("hbreak"))); 16053 set_cmd_completer (c, location_completer); 16054 16055 c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ 16056 Set a temporary hardware assisted breakpoint.\n\ 16057 Like \"hbreak\" except the breakpoint is only temporary,\n\ 16058 so it will be deleted when hit.\n\ 16059 \n" 16060 BREAK_ARGS_HELP ("thbreak"))); 16061 set_cmd_completer (c, location_completer); 16062 16063 add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ 16064 Enable some breakpoints.\n\ 16065 Give breakpoint numbers (separated by spaces) as arguments.\n\ 16066 With no subcommand, breakpoints are enabled until you command otherwise.\n\ 16067 This is used to cancel the effect of the \"disable\" command.\n\ 16068 With a subcommand you can enable temporarily."), 16069 &enablelist, "enable ", 1, &cmdlist); 16070 if (xdb_commands) 16071 add_com ("ab", class_breakpoint, enable_command, _("\ 16072 Enable some breakpoints.\n\ 16073 Give breakpoint numbers (separated by spaces) as arguments.\n\ 16074 With no subcommand, breakpoints are enabled until you command otherwise.\n\ 16075 This is used to cancel the effect of the \"disable\" command.\n\ 16076 With a subcommand you can enable temporarily.")); 16077 16078 add_com_alias ("en", "enable", class_breakpoint, 1); 16079 16080 add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ 16081 Enable some breakpoints.\n\ 16082 Give breakpoint numbers (separated by spaces) as arguments.\n\ 16083 This is used to cancel the effect of the \"disable\" command.\n\ 16084 May be abbreviated to simply \"enable\".\n"), 16085 &enablebreaklist, "enable breakpoints ", 1, &enablelist); 16086 16087 add_cmd ("once", no_class, enable_once_command, _("\ 16088 Enable breakpoints for one hit. Give breakpoint numbers.\n\ 16089 If a breakpoint is hit while enabled in this fashion, it becomes disabled."), 16090 &enablebreaklist); 16091 16092 add_cmd ("delete", no_class, enable_delete_command, _("\ 16093 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ 16094 If a breakpoint is hit while enabled in this fashion, it is deleted."), 16095 &enablebreaklist); 16096 16097 add_cmd ("count", no_class, enable_count_command, _("\ 16098 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ 16099 If a breakpoint is hit while enabled in this fashion,\n\ 16100 the count is decremented; when it reaches zero, the breakpoint is disabled."), 16101 &enablebreaklist); 16102 16103 add_cmd ("delete", no_class, enable_delete_command, _("\ 16104 Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ 16105 If a breakpoint is hit while enabled in this fashion, it is deleted."), 16106 &enablelist); 16107 16108 add_cmd ("once", no_class, enable_once_command, _("\ 16109 Enable breakpoints for one hit. Give breakpoint numbers.\n\ 16110 If a breakpoint is hit while enabled in this fashion, it becomes disabled."), 16111 &enablelist); 16112 16113 add_cmd ("count", no_class, enable_count_command, _("\ 16114 Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ 16115 If a breakpoint is hit while enabled in this fashion,\n\ 16116 the count is decremented; when it reaches zero, the breakpoint is disabled."), 16117 &enablelist); 16118 16119 add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ 16120 Disable some breakpoints.\n\ 16121 Arguments are breakpoint numbers with spaces in between.\n\ 16122 To disable all breakpoints, give no argument.\n\ 16123 A disabled breakpoint is not forgotten, but has no effect until re-enabled."), 16124 &disablelist, "disable ", 1, &cmdlist); 16125 add_com_alias ("dis", "disable", class_breakpoint, 1); 16126 add_com_alias ("disa", "disable", class_breakpoint, 1); 16127 if (xdb_commands) 16128 add_com ("sb", class_breakpoint, disable_command, _("\ 16129 Disable some breakpoints.\n\ 16130 Arguments are breakpoint numbers with spaces in between.\n\ 16131 To disable all breakpoints, give no argument.\n\ 16132 A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); 16133 16134 add_cmd ("breakpoints", class_alias, disable_command, _("\ 16135 Disable some breakpoints.\n\ 16136 Arguments are breakpoint numbers with spaces in between.\n\ 16137 To disable all breakpoints, give no argument.\n\ 16138 A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ 16139 This command may be abbreviated \"disable\"."), 16140 &disablelist); 16141 16142 add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ 16143 Delete some breakpoints or auto-display expressions.\n\ 16144 Arguments are breakpoint numbers with spaces in between.\n\ 16145 To delete all breakpoints, give no argument.\n\ 16146 \n\ 16147 Also a prefix command for deletion of other GDB objects.\n\ 16148 The \"unset\" command is also an alias for \"delete\"."), 16149 &deletelist, "delete ", 1, &cmdlist); 16150 add_com_alias ("d", "delete", class_breakpoint, 1); 16151 add_com_alias ("del", "delete", class_breakpoint, 1); 16152 if (xdb_commands) 16153 add_com ("db", class_breakpoint, delete_command, _("\ 16154 Delete some breakpoints.\n\ 16155 Arguments are breakpoint numbers with spaces in between.\n\ 16156 To delete all breakpoints, give no argument.\n")); 16157 16158 add_cmd ("breakpoints", class_alias, delete_command, _("\ 16159 Delete some breakpoints or auto-display expressions.\n\ 16160 Arguments are breakpoint numbers with spaces in between.\n\ 16161 To delete all breakpoints, give no argument.\n\ 16162 This command may be abbreviated \"delete\"."), 16163 &deletelist); 16164 16165 add_com ("clear", class_breakpoint, clear_command, _("\ 16166 Clear breakpoint at specified line or function.\n\ 16167 Argument may be line number, function name, or \"*\" and an address.\n\ 16168 If line number is specified, all breakpoints in that line are cleared.\n\ 16169 If function is specified, breakpoints at beginning of function are cleared.\n\ 16170 If an address is specified, breakpoints at that address are cleared.\n\ 16171 \n\ 16172 With no argument, clears all breakpoints in the line that the selected frame\n\ 16173 is executing in.\n\ 16174 \n\ 16175 See also the \"delete\" command which clears breakpoints by number.")); 16176 add_com_alias ("cl", "clear", class_breakpoint, 1); 16177 16178 c = add_com ("break", class_breakpoint, break_command, _("\ 16179 Set breakpoint at specified line or function.\n" 16180 BREAK_ARGS_HELP ("break"))); 16181 set_cmd_completer (c, location_completer); 16182 16183 add_com_alias ("b", "break", class_run, 1); 16184 add_com_alias ("br", "break", class_run, 1); 16185 add_com_alias ("bre", "break", class_run, 1); 16186 add_com_alias ("brea", "break", class_run, 1); 16187 16188 if (xdb_commands) 16189 add_com_alias ("ba", "break", class_breakpoint, 1); 16190 16191 if (dbx_commands) 16192 { 16193 add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ 16194 Break in function/address or break at a line in the current file."), 16195 &stoplist, "stop ", 1, &cmdlist); 16196 add_cmd ("in", class_breakpoint, stopin_command, 16197 _("Break in function or address."), &stoplist); 16198 add_cmd ("at", class_breakpoint, stopat_command, 16199 _("Break at a line in the current file."), &stoplist); 16200 add_com ("status", class_info, breakpoints_info, _("\ 16201 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ 16202 The \"Type\" column indicates one of:\n\ 16203 \tbreakpoint - normal breakpoint\n\ 16204 \twatchpoint - watchpoint\n\ 16205 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 16206 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 16207 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 16208 address and file/line number respectively.\n\ 16209 \n\ 16210 Convenience variable \"$_\" and default examine address for \"x\"\n\ 16211 are set to the address of the last breakpoint listed unless the command\n\ 16212 is prefixed with \"server \".\n\n\ 16213 Convenience variable \"$bpnum\" contains the number of the last\n\ 16214 breakpoint set.")); 16215 } 16216 16217 add_info ("breakpoints", breakpoints_info, _("\ 16218 Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ 16219 The \"Type\" column indicates one of:\n\ 16220 \tbreakpoint - normal breakpoint\n\ 16221 \twatchpoint - watchpoint\n\ 16222 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 16223 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 16224 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 16225 address and file/line number respectively.\n\ 16226 \n\ 16227 Convenience variable \"$_\" and default examine address for \"x\"\n\ 16228 are set to the address of the last breakpoint listed unless the command\n\ 16229 is prefixed with \"server \".\n\n\ 16230 Convenience variable \"$bpnum\" contains the number of the last\n\ 16231 breakpoint set.")); 16232 16233 add_info_alias ("b", "breakpoints", 1); 16234 16235 if (xdb_commands) 16236 add_com ("lb", class_breakpoint, breakpoints_info, _("\ 16237 Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ 16238 The \"Type\" column indicates one of:\n\ 16239 \tbreakpoint - normal breakpoint\n\ 16240 \twatchpoint - watchpoint\n\ 16241 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 16242 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 16243 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 16244 address and file/line number respectively.\n\ 16245 \n\ 16246 Convenience variable \"$_\" and default examine address for \"x\"\n\ 16247 are set to the address of the last breakpoint listed unless the command\n\ 16248 is prefixed with \"server \".\n\n\ 16249 Convenience variable \"$bpnum\" contains the number of the last\n\ 16250 breakpoint set.")); 16251 16252 add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ 16253 Status of all breakpoints, or breakpoint number NUMBER.\n\ 16254 The \"Type\" column indicates one of:\n\ 16255 \tbreakpoint - normal breakpoint\n\ 16256 \twatchpoint - watchpoint\n\ 16257 \tlongjmp - internal breakpoint used to step through longjmp()\n\ 16258 \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ 16259 \tuntil - internal breakpoint used by the \"until\" command\n\ 16260 \tfinish - internal breakpoint used by the \"finish\" command\n\ 16261 The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ 16262 the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ 16263 breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ 16264 address and file/line number respectively.\n\ 16265 \n\ 16266 Convenience variable \"$_\" and default examine address for \"x\"\n\ 16267 are set to the address of the last breakpoint listed unless the command\n\ 16268 is prefixed with \"server \".\n\n\ 16269 Convenience variable \"$bpnum\" contains the number of the last\n\ 16270 breakpoint set."), 16271 &maintenanceinfolist); 16272 16273 add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ 16274 Set catchpoints to catch events."), 16275 &catch_cmdlist, "catch ", 16276 0/*allow-unknown*/, &cmdlist); 16277 16278 add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ 16279 Set temporary catchpoints to catch events."), 16280 &tcatch_cmdlist, "tcatch ", 16281 0/*allow-unknown*/, &cmdlist); 16282 16283 add_catch_command ("fork", _("Catch calls to fork."), 16284 catch_fork_command_1, 16285 NULL, 16286 (void *) (uintptr_t) catch_fork_permanent, 16287 (void *) (uintptr_t) catch_fork_temporary); 16288 add_catch_command ("vfork", _("Catch calls to vfork."), 16289 catch_fork_command_1, 16290 NULL, 16291 (void *) (uintptr_t) catch_vfork_permanent, 16292 (void *) (uintptr_t) catch_vfork_temporary); 16293 add_catch_command ("exec", _("Catch calls to exec."), 16294 catch_exec_command_1, 16295 NULL, 16296 CATCH_PERMANENT, 16297 CATCH_TEMPORARY); 16298 add_catch_command ("load", _("Catch loads of shared libraries.\n\ 16299 Usage: catch load [REGEX]\n\ 16300 If REGEX is given, only stop for libraries matching the regular expression."), 16301 catch_load_command_1, 16302 NULL, 16303 CATCH_PERMANENT, 16304 CATCH_TEMPORARY); 16305 add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ 16306 Usage: catch unload [REGEX]\n\ 16307 If REGEX is given, only stop for libraries matching the regular expression."), 16308 catch_unload_command_1, 16309 NULL, 16310 CATCH_PERMANENT, 16311 CATCH_TEMPORARY); 16312 add_catch_command ("syscall", _("\ 16313 Catch system calls by their names and/or numbers.\n\ 16314 Arguments say which system calls to catch. If no arguments\n\ 16315 are given, every system call will be caught.\n\ 16316 Arguments, if given, should be one or more system call names\n\ 16317 (if your system supports that), or system call numbers."), 16318 catch_syscall_command_1, 16319 catch_syscall_completer, 16320 CATCH_PERMANENT, 16321 CATCH_TEMPORARY); 16322 16323 c = add_com ("watch", class_breakpoint, watch_command, _("\ 16324 Set a watchpoint for an expression.\n\ 16325 Usage: watch [-l|-location] EXPRESSION\n\ 16326 A watchpoint stops execution of your program whenever the value of\n\ 16327 an expression changes.\n\ 16328 If -l or -location is given, this evaluates EXPRESSION and watches\n\ 16329 the memory to which it refers.")); 16330 set_cmd_completer (c, expression_completer); 16331 16332 c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ 16333 Set a read watchpoint for an expression.\n\ 16334 Usage: rwatch [-l|-location] EXPRESSION\n\ 16335 A watchpoint stops execution of your program whenever the value of\n\ 16336 an expression is read.\n\ 16337 If -l or -location is given, this evaluates EXPRESSION and watches\n\ 16338 the memory to which it refers.")); 16339 set_cmd_completer (c, expression_completer); 16340 16341 c = add_com ("awatch", class_breakpoint, awatch_command, _("\ 16342 Set a watchpoint for an expression.\n\ 16343 Usage: awatch [-l|-location] EXPRESSION\n\ 16344 A watchpoint stops execution of your program whenever the value of\n\ 16345 an expression is either read or written.\n\ 16346 If -l or -location is given, this evaluates EXPRESSION and watches\n\ 16347 the memory to which it refers.")); 16348 set_cmd_completer (c, expression_completer); 16349 16350 add_info ("watchpoints", watchpoints_info, _("\ 16351 Status of specified watchpoints (all watchpoints if no argument).")); 16352 16353 /* XXX: cagney/2005-02-23: This should be a boolean, and should 16354 respond to changes - contrary to the description. */ 16355 add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, 16356 &can_use_hw_watchpoints, _("\ 16357 Set debugger's willingness to use watchpoint hardware."), _("\ 16358 Show debugger's willingness to use watchpoint hardware."), _("\ 16359 If zero, gdb will not use hardware for new watchpoints, even if\n\ 16360 such is available. (However, any hardware watchpoints that were\n\ 16361 created before setting this to nonzero, will continue to use watchpoint\n\ 16362 hardware.)"), 16363 NULL, 16364 show_can_use_hw_watchpoints, 16365 &setlist, &showlist); 16366 16367 can_use_hw_watchpoints = 1; 16368 16369 /* Tracepoint manipulation commands. */ 16370 16371 c = add_com ("trace", class_breakpoint, trace_command, _("\ 16372 Set a tracepoint at specified line or function.\n\ 16373 \n" 16374 BREAK_ARGS_HELP ("trace") "\n\ 16375 Do \"help tracepoints\" for info on other tracepoint commands.")); 16376 set_cmd_completer (c, location_completer); 16377 16378 add_com_alias ("tp", "trace", class_alias, 0); 16379 add_com_alias ("tr", "trace", class_alias, 1); 16380 add_com_alias ("tra", "trace", class_alias, 1); 16381 add_com_alias ("trac", "trace", class_alias, 1); 16382 16383 c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ 16384 Set a fast tracepoint at specified line or function.\n\ 16385 \n" 16386 BREAK_ARGS_HELP ("ftrace") "\n\ 16387 Do \"help tracepoints\" for info on other tracepoint commands.")); 16388 set_cmd_completer (c, location_completer); 16389 16390 c = add_com ("strace", class_breakpoint, strace_command, _("\ 16391 Set a static tracepoint at specified line, function or marker.\n\ 16392 \n\ 16393 strace [LOCATION] [if CONDITION]\n\ 16394 LOCATION may be a line number, function name, \"*\" and an address,\n\ 16395 or -m MARKER_ID.\n\ 16396 If a line number is specified, probe the marker at start of code\n\ 16397 for that line. If a function is specified, probe the marker at start\n\ 16398 of code for that function. If an address is specified, probe the marker\n\ 16399 at that exact address. If a marker id is specified, probe the marker\n\ 16400 with that name. With no LOCATION, uses current execution address of\n\ 16401 the selected stack frame.\n\ 16402 Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ 16403 This collects arbitrary user data passed in the probe point call to the\n\ 16404 tracing library. You can inspect it when analyzing the trace buffer,\n\ 16405 by printing the $_sdata variable like any other convenience variable.\n\ 16406 \n\ 16407 CONDITION is a boolean expression.\n\ 16408 \n\ 16409 Multiple tracepoints at one place are permitted, and useful if their\n\ 16410 conditions are different.\n\ 16411 \n\ 16412 Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ 16413 Do \"help tracepoints\" for info on other tracepoint commands.")); 16414 set_cmd_completer (c, location_completer); 16415 16416 add_info ("tracepoints", tracepoints_info, _("\ 16417 Status of specified tracepoints (all tracepoints if no argument).\n\ 16418 Convenience variable \"$tpnum\" contains the number of the\n\ 16419 last tracepoint set.")); 16420 16421 add_info_alias ("tp", "tracepoints", 1); 16422 16423 add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ 16424 Delete specified tracepoints.\n\ 16425 Arguments are tracepoint numbers, separated by spaces.\n\ 16426 No argument means delete all tracepoints."), 16427 &deletelist); 16428 add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); 16429 16430 c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ 16431 Disable specified tracepoints.\n\ 16432 Arguments are tracepoint numbers, separated by spaces.\n\ 16433 No argument means disable all tracepoints."), 16434 &disablelist); 16435 deprecate_cmd (c, "disable"); 16436 16437 c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ 16438 Enable specified tracepoints.\n\ 16439 Arguments are tracepoint numbers, separated by spaces.\n\ 16440 No argument means enable all tracepoints."), 16441 &enablelist); 16442 deprecate_cmd (c, "enable"); 16443 16444 add_com ("passcount", class_trace, trace_pass_command, _("\ 16445 Set the passcount for a tracepoint.\n\ 16446 The trace will end when the tracepoint has been passed 'count' times.\n\ 16447 Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ 16448 if TPNUM is omitted, passcount refers to the last tracepoint defined.")); 16449 16450 add_prefix_cmd ("save", class_breakpoint, save_command, 16451 _("Save breakpoint definitions as a script."), 16452 &save_cmdlist, "save ", 16453 0/*allow-unknown*/, &cmdlist); 16454 16455 c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ 16456 Save current breakpoint definitions as a script.\n\ 16457 This includes all types of breakpoints (breakpoints, watchpoints,\n\ 16458 catchpoints, tracepoints). Use the 'source' command in another debug\n\ 16459 session to restore them."), 16460 &save_cmdlist); 16461 set_cmd_completer (c, filename_completer); 16462 16463 c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ 16464 Save current tracepoint definitions as a script.\n\ 16465 Use the 'source' command in another debug session to restore them."), 16466 &save_cmdlist); 16467 set_cmd_completer (c, filename_completer); 16468 16469 c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); 16470 deprecate_cmd (c, "save tracepoints"); 16471 16472 add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ 16473 Breakpoint specific settings\n\ 16474 Configure various breakpoint-specific variables such as\n\ 16475 pending breakpoint behavior"), 16476 &breakpoint_set_cmdlist, "set breakpoint ", 16477 0/*allow-unknown*/, &setlist); 16478 add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ 16479 Breakpoint specific settings\n\ 16480 Configure various breakpoint-specific variables such as\n\ 16481 pending breakpoint behavior"), 16482 &breakpoint_show_cmdlist, "show breakpoint ", 16483 0/*allow-unknown*/, &showlist); 16484 16485 add_setshow_auto_boolean_cmd ("pending", no_class, 16486 &pending_break_support, _("\ 16487 Set debugger's behavior regarding pending breakpoints."), _("\ 16488 Show debugger's behavior regarding pending breakpoints."), _("\ 16489 If on, an unrecognized breakpoint location will cause gdb to create a\n\ 16490 pending breakpoint. If off, an unrecognized breakpoint location results in\n\ 16491 an error. If auto, an unrecognized breakpoint location results in a\n\ 16492 user-query to see if a pending breakpoint should be created."), 16493 NULL, 16494 show_pending_break_support, 16495 &breakpoint_set_cmdlist, 16496 &breakpoint_show_cmdlist); 16497 16498 pending_break_support = AUTO_BOOLEAN_AUTO; 16499 16500 add_setshow_boolean_cmd ("auto-hw", no_class, 16501 &automatic_hardware_breakpoints, _("\ 16502 Set automatic usage of hardware breakpoints."), _("\ 16503 Show automatic usage of hardware breakpoints."), _("\ 16504 If set, the debugger will automatically use hardware breakpoints for\n\ 16505 breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ 16506 a warning will be emitted for such breakpoints."), 16507 NULL, 16508 show_automatic_hardware_breakpoints, 16509 &breakpoint_set_cmdlist, 16510 &breakpoint_show_cmdlist); 16511 16512 add_setshow_auto_boolean_cmd ("always-inserted", class_support, 16513 &always_inserted_mode, _("\ 16514 Set mode for inserting breakpoints."), _("\ 16515 Show mode for inserting breakpoints."), _("\ 16516 When this mode is off, breakpoints are inserted in inferior when it is\n\ 16517 resumed, and removed when execution stops. When this mode is on,\n\ 16518 breakpoints are inserted immediately and removed only when the user\n\ 16519 deletes the breakpoint. When this mode is auto (which is the default),\n\ 16520 the behaviour depends on the non-stop setting (see help set non-stop).\n\ 16521 In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ 16522 behaves as if always-inserted mode is on; if gdb is controlling the\n\ 16523 inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), 16524 NULL, 16525 &show_always_inserted_mode, 16526 &breakpoint_set_cmdlist, 16527 &breakpoint_show_cmdlist); 16528 16529 add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, 16530 condition_evaluation_enums, 16531 &condition_evaluation_mode_1, _("\ 16532 Set mode of breakpoint condition evaluation."), _("\ 16533 Show mode of breakpoint condition evaluation."), _("\ 16534 When this is set to \"host\", breakpoint conditions will be\n\ 16535 evaluated on the host's side by GDB. When it is set to \"target\",\n\ 16536 breakpoint conditions will be downloaded to the target (if the target\n\ 16537 supports such feature) and conditions will be evaluated on the target's side.\n\ 16538 If this is set to \"auto\" (default), this will be automatically set to\n\ 16539 \"target\" if it supports condition evaluation, otherwise it will\n\ 16540 be set to \"gdb\""), 16541 &set_condition_evaluation_mode, 16542 &show_condition_evaluation_mode, 16543 &breakpoint_set_cmdlist, 16544 &breakpoint_show_cmdlist); 16545 16546 add_com ("break-range", class_breakpoint, break_range_command, _("\ 16547 Set a breakpoint for an address range.\n\ 16548 break-range START-LOCATION, END-LOCATION\n\ 16549 where START-LOCATION and END-LOCATION can be one of the following:\n\ 16550 LINENUM, for that line in the current file,\n\ 16551 FILE:LINENUM, for that line in that file,\n\ 16552 +OFFSET, for that number of lines after the current line\n\ 16553 or the start of the range\n\ 16554 FUNCTION, for the first line in that function,\n\ 16555 FILE:FUNCTION, to distinguish among like-named static functions.\n\ 16556 *ADDRESS, for the instruction at that address.\n\ 16557 \n\ 16558 The breakpoint will stop execution of the inferior whenever it executes\n\ 16559 an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ 16560 range (including START-LOCATION and END-LOCATION).")); 16561 16562 c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ 16563 Set a dynamic printf at specified line or function.\n\ 16564 dprintf location,format string,arg1,arg2,...\n\ 16565 location may be a line number, function name, or \"*\" and an address.\n\ 16566 If a line number is specified, break at start of code for that line.\n\ 16567 If a function is specified, break at start of code for that function.")); 16568 set_cmd_completer (c, location_completer); 16569 16570 add_setshow_enum_cmd ("dprintf-style", class_support, 16571 dprintf_style_enums, &dprintf_style, _("\ 16572 Set the style of usage for dynamic printf."), _("\ 16573 Show the style of usage for dynamic printf."), _("\ 16574 This setting chooses how GDB will do a dynamic printf.\n\ 16575 If the value is \"gdb\", then the printing is done by GDB to its own\n\ 16576 console, as with the \"printf\" command.\n\ 16577 If the value is \"call\", the print is done by calling a function in your\n\ 16578 program; by default printf(), but you can choose a different function or\n\ 16579 output stream by setting dprintf-function and dprintf-channel."), 16580 update_dprintf_commands, NULL, 16581 &setlist, &showlist); 16582 16583 dprintf_function = xstrdup ("printf"); 16584 add_setshow_string_cmd ("dprintf-function", class_support, 16585 &dprintf_function, _("\ 16586 Set the function to use for dynamic printf"), _("\ 16587 Show the function to use for dynamic printf"), NULL, 16588 update_dprintf_commands, NULL, 16589 &setlist, &showlist); 16590 16591 dprintf_channel = xstrdup (""); 16592 add_setshow_string_cmd ("dprintf-channel", class_support, 16593 &dprintf_channel, _("\ 16594 Set the channel to use for dynamic printf"), _("\ 16595 Show the channel to use for dynamic printf"), NULL, 16596 update_dprintf_commands, NULL, 16597 &setlist, &showlist); 16598 16599 add_setshow_boolean_cmd ("disconnected-dprintf", no_class, 16600 &disconnected_dprintf, _("\ 16601 Set whether dprintf continues after GDB disconnects."), _("\ 16602 Show whether dprintf continues after GDB disconnects."), _("\ 16603 Use this to let dprintf commands continue to hit and produce output\n\ 16604 even if GDB disconnects or detaches from the target."), 16605 NULL, 16606 NULL, 16607 &setlist, &showlist); 16608 16609 add_com ("agent-printf", class_vars, agent_printf_command, _("\ 16610 agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ 16611 (target agent only) This is useful for formatted output in user-defined commands.")); 16612 16613 automatic_hardware_breakpoints = 1; 16614 16615 observer_attach_about_to_proceed (breakpoint_about_to_proceed); 16616 observer_attach_thread_exit (remove_threaded_breakpoints); 16617 }