| 1 | /* Everything about breakpoints, for GDB. |
| 2 | |
| 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
| 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
| 5 | 2008, 2009 Free Software Foundation, Inc. |
| 6 | |
| 7 | This file is part of GDB. |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 3 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 21 | |
| 22 | #include "defs.h" |
| 23 | #include "arch-utils.h" |
| 24 | #include <ctype.h> |
| 25 | #include "hashtab.h" |
| 26 | #include "symtab.h" |
| 27 | #include "frame.h" |
| 28 | #include "breakpoint.h" |
| 29 | #include "tracepoint.h" |
| 30 | #include "gdbtypes.h" |
| 31 | #include "expression.h" |
| 32 | #include "gdbcore.h" |
| 33 | #include "gdbcmd.h" |
| 34 | #include "value.h" |
| 35 | #include "command.h" |
| 36 | #include "inferior.h" |
| 37 | #include "gdbthread.h" |
| 38 | #include "target.h" |
| 39 | #include "language.h" |
| 40 | #include "gdb_string.h" |
| 41 | #include "demangle.h" |
| 42 | #include "annotate.h" |
| 43 | #include "symfile.h" |
| 44 | #include "objfiles.h" |
| 45 | #include "source.h" |
| 46 | #include "linespec.h" |
| 47 | #include "completer.h" |
| 48 | #include "gdb.h" |
| 49 | #include "ui-out.h" |
| 50 | #include "cli/cli-script.h" |
| 51 | #include "gdb_assert.h" |
| 52 | #include "block.h" |
| 53 | #include "solib.h" |
| 54 | #include "solist.h" |
| 55 | #include "observer.h" |
| 56 | #include "exceptions.h" |
| 57 | #include "memattr.h" |
| 58 | #include "ada-lang.h" |
| 59 | #include "top.h" |
| 60 | #include "wrapper.h" |
| 61 | #include "valprint.h" |
| 62 | #include "jit.h" |
| 63 | |
| 64 | /* readline include files */ |
| 65 | #include "readline/readline.h" |
| 66 | #include "readline/history.h" |
| 67 | |
| 68 | /* readline defines this. */ |
| 69 | #undef savestring |
| 70 | |
| 71 | #include "mi/mi-common.h" |
| 72 | |
| 73 | /* Arguments to pass as context to some catch command handlers. */ |
| 74 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) |
| 75 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) |
| 76 | |
| 77 | /* Prototypes for local functions. */ |
| 78 | |
| 79 | static void enable_delete_command (char *, int); |
| 80 | |
| 81 | static void enable_delete_breakpoint (struct breakpoint *); |
| 82 | |
| 83 | static void enable_once_command (char *, int); |
| 84 | |
| 85 | static void enable_once_breakpoint (struct breakpoint *); |
| 86 | |
| 87 | static void disable_command (char *, int); |
| 88 | |
| 89 | static void enable_command (char *, int); |
| 90 | |
| 91 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
| 92 | |
| 93 | static void ignore_command (char *, int); |
| 94 | |
| 95 | static int breakpoint_re_set_one (void *); |
| 96 | |
| 97 | static void clear_command (char *, int); |
| 98 | |
| 99 | static void catch_command (char *, int); |
| 100 | |
| 101 | static void watch_command (char *, int); |
| 102 | |
| 103 | static int can_use_hardware_watchpoint (struct value *); |
| 104 | |
| 105 | static void break_command_1 (char *, int, int); |
| 106 | |
| 107 | static void mention (struct breakpoint *); |
| 108 | |
| 109 | /* This function is used in gdbtk sources and thus can not be made static. */ |
| 110 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
| 111 | struct symtab_and_line, |
| 112 | enum bptype); |
| 113 | |
| 114 | static void check_duplicates (struct breakpoint *); |
| 115 | |
| 116 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
| 117 | |
| 118 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 119 | CORE_ADDR bpaddr, |
| 120 | enum bptype bptype); |
| 121 | |
| 122 | static void describe_other_breakpoints (struct gdbarch *, CORE_ADDR, |
| 123 | struct obj_section *, int); |
| 124 | |
| 125 | static void breakpoints_info (char *, int); |
| 126 | |
| 127 | static void breakpoint_1 (int, int); |
| 128 | |
| 129 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
| 130 | |
| 131 | static int breakpoint_cond_eval (void *); |
| 132 | |
| 133 | static void cleanup_executing_breakpoints (void *); |
| 134 | |
| 135 | static void commands_command (char *, int); |
| 136 | |
| 137 | static void condition_command (char *, int); |
| 138 | |
| 139 | static int get_number_trailer (char **, int); |
| 140 | |
| 141 | void set_breakpoint_count (int); |
| 142 | |
| 143 | typedef enum |
| 144 | { |
| 145 | mark_inserted, |
| 146 | mark_uninserted |
| 147 | } |
| 148 | insertion_state_t; |
| 149 | |
| 150 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
| 151 | |
| 152 | static enum print_stop_action print_it_typical (bpstat); |
| 153 | |
| 154 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
| 155 | |
| 156 | static int watchpoint_check (void *); |
| 157 | |
| 158 | static void maintenance_info_breakpoints (char *, int); |
| 159 | |
| 160 | static int hw_breakpoint_used_count (void); |
| 161 | |
| 162 | static int hw_watchpoint_used_count (enum bptype, int *); |
| 163 | |
| 164 | static void hbreak_command (char *, int); |
| 165 | |
| 166 | static void thbreak_command (char *, int); |
| 167 | |
| 168 | static void watch_command_1 (char *, int, int); |
| 169 | |
| 170 | static void rwatch_command (char *, int); |
| 171 | |
| 172 | static void awatch_command (char *, int); |
| 173 | |
| 174 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
| 175 | |
| 176 | static void stop_command (char *arg, int from_tty); |
| 177 | |
| 178 | static void stopin_command (char *arg, int from_tty); |
| 179 | |
| 180 | static void stopat_command (char *arg, int from_tty); |
| 181 | |
| 182 | static char *ep_parse_optional_if_clause (char **arg); |
| 183 | |
| 184 | static char *ep_parse_optional_filename (char **arg); |
| 185 | |
| 186 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
| 187 | char *arg, int tempflag, int from_tty); |
| 188 | |
| 189 | static void tcatch_command (char *arg, int from_tty); |
| 190 | |
| 191 | static void ep_skip_leading_whitespace (char **s); |
| 192 | |
| 193 | static int single_step_breakpoint_inserted_here_p (CORE_ADDR pc); |
| 194 | |
| 195 | static void free_bp_location (struct bp_location *loc); |
| 196 | |
| 197 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
| 198 | |
| 199 | static void update_global_location_list (int); |
| 200 | |
| 201 | static void update_global_location_list_nothrow (int); |
| 202 | |
| 203 | static int is_hardware_watchpoint (struct breakpoint *bpt); |
| 204 | |
| 205 | static void insert_breakpoint_locations (void); |
| 206 | |
| 207 | static void tracepoints_info (char *, int); |
| 208 | |
| 209 | static void delete_trace_command (char *, int); |
| 210 | |
| 211 | static void enable_trace_command (char *, int); |
| 212 | |
| 213 | static void disable_trace_command (char *, int); |
| 214 | |
| 215 | static void trace_pass_command (char *, int); |
| 216 | |
| 217 | static void skip_prologue_sal (struct symtab_and_line *sal); |
| 218 | |
| 219 | |
| 220 | /* Flag indicating that a command has proceeded the inferior past the |
| 221 | current breakpoint. */ |
| 222 | |
| 223 | static int breakpoint_proceeded; |
| 224 | |
| 225 | static const char * |
| 226 | bpdisp_text (enum bpdisp disp) |
| 227 | { |
| 228 | /* NOTE: the following values are a part of MI protocol and represent |
| 229 | values of 'disp' field returned when inferior stops at a breakpoint. */ |
| 230 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; |
| 231 | return bpdisps[(int) disp]; |
| 232 | } |
| 233 | |
| 234 | /* Prototypes for exported functions. */ |
| 235 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
| 236 | if such is available. */ |
| 237 | static int can_use_hw_watchpoints; |
| 238 | |
| 239 | static void |
| 240 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, |
| 241 | struct cmd_list_element *c, |
| 242 | const char *value) |
| 243 | { |
| 244 | fprintf_filtered (file, _("\ |
| 245 | Debugger's willingness to use watchpoint hardware is %s.\n"), |
| 246 | value); |
| 247 | } |
| 248 | |
| 249 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
| 250 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints |
| 251 | for unrecognized breakpoint locations. |
| 252 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
| 253 | static enum auto_boolean pending_break_support; |
| 254 | static void |
| 255 | show_pending_break_support (struct ui_file *file, int from_tty, |
| 256 | struct cmd_list_element *c, |
| 257 | const char *value) |
| 258 | { |
| 259 | fprintf_filtered (file, _("\ |
| 260 | Debugger's behavior regarding pending breakpoints is %s.\n"), |
| 261 | value); |
| 262 | } |
| 263 | |
| 264 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
| 265 | set with "break" but falling in read-only memory. |
| 266 | If 0, gdb will warn about such breakpoints, but won't automatically |
| 267 | use hardware breakpoints. */ |
| 268 | static int automatic_hardware_breakpoints; |
| 269 | static void |
| 270 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, |
| 271 | struct cmd_list_element *c, |
| 272 | const char *value) |
| 273 | { |
| 274 | fprintf_filtered (file, _("\ |
| 275 | Automatic usage of hardware breakpoints is %s.\n"), |
| 276 | value); |
| 277 | } |
| 278 | |
| 279 | /* If on, gdb will keep breakpoints inserted even as inferior is |
| 280 | stopped, and immediately insert any new breakpoints. If off, gdb |
| 281 | will insert breakpoints into inferior only when resuming it, and |
| 282 | will remove breakpoints upon stop. If auto, GDB will behave as ON |
| 283 | if in non-stop mode, and as OFF if all-stop mode.*/ |
| 284 | |
| 285 | static const char always_inserted_auto[] = "auto"; |
| 286 | static const char always_inserted_on[] = "on"; |
| 287 | static const char always_inserted_off[] = "off"; |
| 288 | static const char *always_inserted_enums[] = { |
| 289 | always_inserted_auto, |
| 290 | always_inserted_off, |
| 291 | always_inserted_on, |
| 292 | NULL |
| 293 | }; |
| 294 | static const char *always_inserted_mode = always_inserted_auto; |
| 295 | static void |
| 296 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
| 297 | struct cmd_list_element *c, const char *value) |
| 298 | { |
| 299 | if (always_inserted_mode == always_inserted_auto) |
| 300 | fprintf_filtered (file, _("\ |
| 301 | Always inserted breakpoint mode is %s (currently %s).\n"), |
| 302 | value, |
| 303 | breakpoints_always_inserted_mode () ? "on" : "off"); |
| 304 | else |
| 305 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); |
| 306 | } |
| 307 | |
| 308 | int |
| 309 | breakpoints_always_inserted_mode (void) |
| 310 | { |
| 311 | return (always_inserted_mode == always_inserted_on |
| 312 | || (always_inserted_mode == always_inserted_auto && non_stop)); |
| 313 | } |
| 314 | |
| 315 | void _initialize_breakpoint (void); |
| 316 | |
| 317 | /* Are we executing breakpoint commands? */ |
| 318 | static int executing_breakpoint_commands; |
| 319 | |
| 320 | /* Are overlay event breakpoints enabled? */ |
| 321 | static int overlay_events_enabled; |
| 322 | |
| 323 | /* Are we executing startup code? */ |
| 324 | static int executing_startup; |
| 325 | |
| 326 | /* Walk the following statement or block through all breakpoints. |
| 327 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current |
| 328 | breakpoint. */ |
| 329 | |
| 330 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
| 331 | |
| 332 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
| 333 | for (B = breakpoint_chain; \ |
| 334 | B ? (TMP=B->next, 1): 0; \ |
| 335 | B = TMP) |
| 336 | |
| 337 | /* Similar iterators for the low-level breakpoints. */ |
| 338 | |
| 339 | #define ALL_BP_LOCATIONS(B) for (B = bp_location_chain; B; B = B->global_next) |
| 340 | |
| 341 | #define ALL_BP_LOCATIONS_SAFE(B,TMP) \ |
| 342 | for (B = bp_location_chain; \ |
| 343 | B ? (TMP=B->global_next, 1): 0; \ |
| 344 | B = TMP) |
| 345 | |
| 346 | /* Iterator for tracepoints only. */ |
| 347 | |
| 348 | #define ALL_TRACEPOINTS(B) \ |
| 349 | for (B = breakpoint_chain; B; B = B->next) \ |
| 350 | if ((B)->type == bp_tracepoint) |
| 351 | |
| 352 | /* Chains of all breakpoints defined. */ |
| 353 | |
| 354 | struct breakpoint *breakpoint_chain; |
| 355 | |
| 356 | struct bp_location *bp_location_chain; |
| 357 | |
| 358 | /* The locations that no longer correspond to any breakpoint, |
| 359 | unlinked from bp_location_chain, but for which a hit |
| 360 | may still be reported by a target. */ |
| 361 | VEC(bp_location_p) *moribund_locations = NULL; |
| 362 | |
| 363 | /* Number of last breakpoint made. */ |
| 364 | |
| 365 | int breakpoint_count; |
| 366 | |
| 367 | /* Number of last tracepoint made. */ |
| 368 | |
| 369 | int tracepoint_count; |
| 370 | |
| 371 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
| 372 | static int |
| 373 | breakpoint_enabled (struct breakpoint *b) |
| 374 | { |
| 375 | return (b->enable_state == bp_enabled); |
| 376 | } |
| 377 | |
| 378 | /* Set breakpoint count to NUM. */ |
| 379 | |
| 380 | void |
| 381 | set_breakpoint_count (int num) |
| 382 | { |
| 383 | breakpoint_count = num; |
| 384 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
| 385 | } |
| 386 | |
| 387 | /* Used in run_command to zero the hit count when a new run starts. */ |
| 388 | |
| 389 | void |
| 390 | clear_breakpoint_hit_counts (void) |
| 391 | { |
| 392 | struct breakpoint *b; |
| 393 | |
| 394 | ALL_BREAKPOINTS (b) |
| 395 | b->hit_count = 0; |
| 396 | } |
| 397 | |
| 398 | /* Default address, symtab and line to put a breakpoint at |
| 399 | for "break" command with no arg. |
| 400 | if default_breakpoint_valid is zero, the other three are |
| 401 | not valid, and "break" with no arg is an error. |
| 402 | |
| 403 | This set by print_stack_frame, which calls set_default_breakpoint. */ |
| 404 | |
| 405 | int default_breakpoint_valid; |
| 406 | CORE_ADDR default_breakpoint_address; |
| 407 | struct symtab *default_breakpoint_symtab; |
| 408 | int default_breakpoint_line; |
| 409 | \f |
| 410 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. |
| 411 | Advance *PP after the string and any trailing whitespace. |
| 412 | |
| 413 | Currently the string can either be a number or "$" followed by the name |
| 414 | of a convenience variable. Making it an expression wouldn't work well |
| 415 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
| 416 | |
| 417 | If the string is a NULL pointer, that denotes the last breakpoint. |
| 418 | |
| 419 | TRAILER is a character which can be found after the number; most |
| 420 | commonly this is `-'. If you don't want a trailer, use \0. */ |
| 421 | static int |
| 422 | get_number_trailer (char **pp, int trailer) |
| 423 | { |
| 424 | int retval = 0; /* default */ |
| 425 | char *p = *pp; |
| 426 | |
| 427 | if (p == NULL) |
| 428 | /* Empty line means refer to the last breakpoint. */ |
| 429 | return breakpoint_count; |
| 430 | else if (*p == '$') |
| 431 | { |
| 432 | /* Make a copy of the name, so we can null-terminate it |
| 433 | to pass to lookup_internalvar(). */ |
| 434 | char *varname; |
| 435 | char *start = ++p; |
| 436 | LONGEST val; |
| 437 | |
| 438 | while (isalnum (*p) || *p == '_') |
| 439 | p++; |
| 440 | varname = (char *) alloca (p - start + 1); |
| 441 | strncpy (varname, start, p - start); |
| 442 | varname[p - start] = '\0'; |
| 443 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
| 444 | retval = (int) val; |
| 445 | else |
| 446 | { |
| 447 | printf_filtered (_("Convenience variable must have integer value.\n")); |
| 448 | retval = 0; |
| 449 | } |
| 450 | } |
| 451 | else |
| 452 | { |
| 453 | if (*p == '-') |
| 454 | ++p; |
| 455 | while (*p >= '0' && *p <= '9') |
| 456 | ++p; |
| 457 | if (p == *pp) |
| 458 | /* There is no number here. (e.g. "cond a == b"). */ |
| 459 | { |
| 460 | /* Skip non-numeric token */ |
| 461 | while (*p && !isspace((int) *p)) |
| 462 | ++p; |
| 463 | /* Return zero, which caller must interpret as error. */ |
| 464 | retval = 0; |
| 465 | } |
| 466 | else |
| 467 | retval = atoi (*pp); |
| 468 | } |
| 469 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) |
| 470 | { |
| 471 | /* Trailing junk: return 0 and let caller print error msg. */ |
| 472 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) |
| 473 | ++p; |
| 474 | retval = 0; |
| 475 | } |
| 476 | while (isspace (*p)) |
| 477 | p++; |
| 478 | *pp = p; |
| 479 | return retval; |
| 480 | } |
| 481 | |
| 482 | |
| 483 | /* Like get_number_trailer, but don't allow a trailer. */ |
| 484 | int |
| 485 | get_number (char **pp) |
| 486 | { |
| 487 | return get_number_trailer (pp, '\0'); |
| 488 | } |
| 489 | |
| 490 | /* Parse a number or a range. |
| 491 | * A number will be of the form handled by get_number. |
| 492 | * A range will be of the form <number1> - <number2>, and |
| 493 | * will represent all the integers between number1 and number2, |
| 494 | * inclusive. |
| 495 | * |
| 496 | * While processing a range, this fuction is called iteratively; |
| 497 | * At each call it will return the next value in the range. |
| 498 | * |
| 499 | * At the beginning of parsing a range, the char pointer PP will |
| 500 | * be advanced past <number1> and left pointing at the '-' token. |
| 501 | * Subsequent calls will not advance the pointer until the range |
| 502 | * is completed. The call that completes the range will advance |
| 503 | * pointer PP past <number2>. |
| 504 | */ |
| 505 | |
| 506 | int |
| 507 | get_number_or_range (char **pp) |
| 508 | { |
| 509 | static int last_retval, end_value; |
| 510 | static char *end_ptr; |
| 511 | static int in_range = 0; |
| 512 | |
| 513 | if (**pp != '-') |
| 514 | { |
| 515 | /* Default case: pp is pointing either to a solo number, |
| 516 | or to the first number of a range. */ |
| 517 | last_retval = get_number_trailer (pp, '-'); |
| 518 | if (**pp == '-') |
| 519 | { |
| 520 | char **temp; |
| 521 | |
| 522 | /* This is the start of a range (<number1> - <number2>). |
| 523 | Skip the '-', parse and remember the second number, |
| 524 | and also remember the end of the final token. */ |
| 525 | |
| 526 | temp = &end_ptr; |
| 527 | end_ptr = *pp + 1; |
| 528 | while (isspace ((int) *end_ptr)) |
| 529 | end_ptr++; /* skip white space */ |
| 530 | end_value = get_number (temp); |
| 531 | if (end_value < last_retval) |
| 532 | { |
| 533 | error (_("inverted range")); |
| 534 | } |
| 535 | else if (end_value == last_retval) |
| 536 | { |
| 537 | /* degenerate range (number1 == number2). Advance the |
| 538 | token pointer so that the range will be treated as a |
| 539 | single number. */ |
| 540 | *pp = end_ptr; |
| 541 | } |
| 542 | else |
| 543 | in_range = 1; |
| 544 | } |
| 545 | } |
| 546 | else if (! in_range) |
| 547 | error (_("negative value")); |
| 548 | else |
| 549 | { |
| 550 | /* pp points to the '-' that betokens a range. All |
| 551 | number-parsing has already been done. Return the next |
| 552 | integer value (one greater than the saved previous value). |
| 553 | Do not advance the token pointer 'pp' until the end of range |
| 554 | is reached. */ |
| 555 | |
| 556 | if (++last_retval == end_value) |
| 557 | { |
| 558 | /* End of range reached; advance token pointer. */ |
| 559 | *pp = end_ptr; |
| 560 | in_range = 0; |
| 561 | } |
| 562 | } |
| 563 | return last_retval; |
| 564 | } |
| 565 | |
| 566 | /* Return the breakpoint with the specified number, or NULL |
| 567 | if the number does not refer to an existing breakpoint. */ |
| 568 | |
| 569 | struct breakpoint * |
| 570 | get_breakpoint (int num) |
| 571 | { |
| 572 | struct breakpoint *b; |
| 573 | |
| 574 | ALL_BREAKPOINTS (b) |
| 575 | if (b->number == num) |
| 576 | return b; |
| 577 | |
| 578 | return NULL; |
| 579 | } |
| 580 | |
| 581 | \f |
| 582 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
| 583 | |
| 584 | static void |
| 585 | condition_command (char *arg, int from_tty) |
| 586 | { |
| 587 | struct breakpoint *b; |
| 588 | char *p; |
| 589 | int bnum; |
| 590 | |
| 591 | if (arg == 0) |
| 592 | error_no_arg (_("breakpoint number")); |
| 593 | |
| 594 | p = arg; |
| 595 | bnum = get_number (&p); |
| 596 | if (bnum == 0) |
| 597 | error (_("Bad breakpoint argument: '%s'"), arg); |
| 598 | |
| 599 | ALL_BREAKPOINTS (b) |
| 600 | if (b->number == bnum) |
| 601 | { |
| 602 | struct bp_location *loc = b->loc; |
| 603 | for (; loc; loc = loc->next) |
| 604 | { |
| 605 | if (loc->cond) |
| 606 | { |
| 607 | xfree (loc->cond); |
| 608 | loc->cond = 0; |
| 609 | } |
| 610 | } |
| 611 | if (b->cond_string != NULL) |
| 612 | xfree (b->cond_string); |
| 613 | |
| 614 | if (*p == 0) |
| 615 | { |
| 616 | b->cond_string = NULL; |
| 617 | if (from_tty) |
| 618 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); |
| 619 | } |
| 620 | else |
| 621 | { |
| 622 | arg = p; |
| 623 | /* I don't know if it matters whether this is the string the user |
| 624 | typed in or the decompiled expression. */ |
| 625 | b->cond_string = xstrdup (arg); |
| 626 | b->condition_not_parsed = 0; |
| 627 | for (loc = b->loc; loc; loc = loc->next) |
| 628 | { |
| 629 | arg = p; |
| 630 | loc->cond = |
| 631 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
| 632 | if (*arg) |
| 633 | error (_("Junk at end of expression")); |
| 634 | } |
| 635 | } |
| 636 | breakpoints_changed (); |
| 637 | observer_notify_breakpoint_modified (b->number); |
| 638 | return; |
| 639 | } |
| 640 | |
| 641 | error (_("No breakpoint number %d."), bnum); |
| 642 | } |
| 643 | |
| 644 | /* Set the command list of B to COMMANDS. */ |
| 645 | |
| 646 | void |
| 647 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) |
| 648 | { |
| 649 | free_command_lines (&b->commands); |
| 650 | b->commands = commands; |
| 651 | breakpoints_changed (); |
| 652 | observer_notify_breakpoint_modified (b->number); |
| 653 | } |
| 654 | |
| 655 | static void |
| 656 | commands_command (char *arg, int from_tty) |
| 657 | { |
| 658 | struct breakpoint *b; |
| 659 | char *p; |
| 660 | int bnum; |
| 661 | struct command_line *l; |
| 662 | |
| 663 | /* If we allowed this, we would have problems with when to |
| 664 | free the storage, if we change the commands currently |
| 665 | being read from. */ |
| 666 | |
| 667 | if (executing_breakpoint_commands) |
| 668 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
| 669 | |
| 670 | p = arg; |
| 671 | bnum = get_number (&p); |
| 672 | |
| 673 | if (p && *p) |
| 674 | error (_("Unexpected extra arguments following breakpoint number.")); |
| 675 | |
| 676 | ALL_BREAKPOINTS (b) |
| 677 | if (b->number == bnum) |
| 678 | { |
| 679 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", |
| 680 | bnum); |
| 681 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); |
| 682 | l = read_command_lines (tmpbuf, from_tty, 1); |
| 683 | do_cleanups (cleanups); |
| 684 | breakpoint_set_commands (b, l); |
| 685 | return; |
| 686 | } |
| 687 | error (_("No breakpoint number %d."), bnum); |
| 688 | } |
| 689 | |
| 690 | /* Like commands_command, but instead of reading the commands from |
| 691 | input stream, takes them from an already parsed command structure. |
| 692 | |
| 693 | This is used by cli-script.c to DTRT with breakpoint commands |
| 694 | that are part of if and while bodies. */ |
| 695 | enum command_control_type |
| 696 | commands_from_control_command (char *arg, struct command_line *cmd) |
| 697 | { |
| 698 | struct breakpoint *b; |
| 699 | char *p; |
| 700 | int bnum; |
| 701 | |
| 702 | /* If we allowed this, we would have problems with when to |
| 703 | free the storage, if we change the commands currently |
| 704 | being read from. */ |
| 705 | |
| 706 | if (executing_breakpoint_commands) |
| 707 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
| 708 | |
| 709 | /* An empty string for the breakpoint number means the last |
| 710 | breakpoint, but get_number expects a NULL pointer. */ |
| 711 | if (arg && !*arg) |
| 712 | p = NULL; |
| 713 | else |
| 714 | p = arg; |
| 715 | bnum = get_number (&p); |
| 716 | |
| 717 | if (p && *p) |
| 718 | error (_("Unexpected extra arguments following breakpoint number.")); |
| 719 | |
| 720 | ALL_BREAKPOINTS (b) |
| 721 | if (b->number == bnum) |
| 722 | { |
| 723 | free_command_lines (&b->commands); |
| 724 | if (cmd->body_count != 1) |
| 725 | error (_("Invalid \"commands\" block structure.")); |
| 726 | /* We need to copy the commands because if/while will free the |
| 727 | list after it finishes execution. */ |
| 728 | b->commands = copy_command_lines (cmd->body_list[0]); |
| 729 | breakpoints_changed (); |
| 730 | observer_notify_breakpoint_modified (b->number); |
| 731 | return simple_control; |
| 732 | } |
| 733 | error (_("No breakpoint number %d."), bnum); |
| 734 | } |
| 735 | \f |
| 736 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
| 737 | by replacing any memory breakpoints with their shadowed contents. */ |
| 738 | |
| 739 | void |
| 740 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) |
| 741 | { |
| 742 | struct bp_location *b; |
| 743 | CORE_ADDR bp_addr = 0; |
| 744 | int bp_size = 0; |
| 745 | int bptoffset = 0; |
| 746 | |
| 747 | ALL_BP_LOCATIONS (b) |
| 748 | { |
| 749 | if (b->owner->type == bp_none) |
| 750 | warning (_("reading through apparently deleted breakpoint #%d?"), |
| 751 | b->owner->number); |
| 752 | |
| 753 | if (b->loc_type != bp_loc_software_breakpoint) |
| 754 | continue; |
| 755 | if (!b->inserted) |
| 756 | continue; |
| 757 | /* Addresses and length of the part of the breakpoint that |
| 758 | we need to copy. */ |
| 759 | bp_addr = b->target_info.placed_address; |
| 760 | bp_size = b->target_info.shadow_len; |
| 761 | if (bp_size == 0) |
| 762 | /* bp isn't valid, or doesn't shadow memory. */ |
| 763 | continue; |
| 764 | |
| 765 | if (bp_addr + bp_size <= memaddr) |
| 766 | /* The breakpoint is entirely before the chunk of memory we |
| 767 | are reading. */ |
| 768 | continue; |
| 769 | |
| 770 | if (bp_addr >= memaddr + len) |
| 771 | /* The breakpoint is entirely after the chunk of memory we are |
| 772 | reading. */ |
| 773 | continue; |
| 774 | |
| 775 | /* Offset within shadow_contents. */ |
| 776 | if (bp_addr < memaddr) |
| 777 | { |
| 778 | /* Only copy the second part of the breakpoint. */ |
| 779 | bp_size -= memaddr - bp_addr; |
| 780 | bptoffset = memaddr - bp_addr; |
| 781 | bp_addr = memaddr; |
| 782 | } |
| 783 | |
| 784 | if (bp_addr + bp_size > memaddr + len) |
| 785 | { |
| 786 | /* Only copy the first part of the breakpoint. */ |
| 787 | bp_size -= (bp_addr + bp_size) - (memaddr + len); |
| 788 | } |
| 789 | |
| 790 | memcpy (buf + bp_addr - memaddr, |
| 791 | b->target_info.shadow_contents + bptoffset, bp_size); |
| 792 | } |
| 793 | } |
| 794 | \f |
| 795 | |
| 796 | /* A wrapper function for inserting catchpoints. */ |
| 797 | static void |
| 798 | insert_catchpoint (struct ui_out *uo, void *args) |
| 799 | { |
| 800 | struct breakpoint *b = (struct breakpoint *) args; |
| 801 | int val = -1; |
| 802 | |
| 803 | gdb_assert (b->type == bp_catchpoint); |
| 804 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); |
| 805 | |
| 806 | b->ops->insert (b); |
| 807 | } |
| 808 | |
| 809 | static int |
| 810 | is_hardware_watchpoint (struct breakpoint *bpt) |
| 811 | { |
| 812 | return (bpt->type == bp_hardware_watchpoint |
| 813 | || bpt->type == bp_read_watchpoint |
| 814 | || bpt->type == bp_access_watchpoint); |
| 815 | } |
| 816 | |
| 817 | /* Find the current value of a watchpoint on EXP. Return the value in |
| 818 | *VALP and *RESULTP and the chain of intermediate and final values |
| 819 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does |
| 820 | not need them. |
| 821 | |
| 822 | If a memory error occurs while evaluating the expression, *RESULTP will |
| 823 | be set to NULL. *RESULTP may be a lazy value, if the result could |
| 824 | not be read from memory. It is used to determine whether a value |
| 825 | is user-specified (we should watch the whole value) or intermediate |
| 826 | (we should watch only the bit used to locate the final value). |
| 827 | |
| 828 | If the final value, or any intermediate value, could not be read |
| 829 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be |
| 830 | set to any referenced values. *VALP will never be a lazy value. |
| 831 | This is the value which we store in struct breakpoint. |
| 832 | |
| 833 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the |
| 834 | value chain. The caller must free the values individually. If |
| 835 | VAL_CHAIN is NULL, all generated values will be left on the value |
| 836 | chain. */ |
| 837 | |
| 838 | static void |
| 839 | fetch_watchpoint_value (struct expression *exp, struct value **valp, |
| 840 | struct value **resultp, struct value **val_chain) |
| 841 | { |
| 842 | struct value *mark, *new_mark, *result; |
| 843 | volatile struct gdb_exception ex; |
| 844 | |
| 845 | *valp = NULL; |
| 846 | if (resultp) |
| 847 | *resultp = NULL; |
| 848 | if (val_chain) |
| 849 | *val_chain = NULL; |
| 850 | |
| 851 | /* Evaluate the expression. */ |
| 852 | mark = value_mark (); |
| 853 | result = NULL; |
| 854 | |
| 855 | TRY_CATCH (ex, RETURN_MASK_ALL) |
| 856 | { |
| 857 | result = evaluate_expression (exp); |
| 858 | } |
| 859 | if (ex.reason < 0) |
| 860 | { |
| 861 | /* Ignore memory errors, we want watchpoints pointing at |
| 862 | inaccessible memory to still be created; otherwise, throw the |
| 863 | error to some higher catcher. */ |
| 864 | switch (ex.error) |
| 865 | { |
| 866 | case MEMORY_ERROR: |
| 867 | break; |
| 868 | default: |
| 869 | throw_exception (ex); |
| 870 | break; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | new_mark = value_mark (); |
| 875 | if (mark == new_mark) |
| 876 | return; |
| 877 | if (resultp) |
| 878 | *resultp = result; |
| 879 | |
| 880 | /* Make sure it's not lazy, so that after the target stops again we |
| 881 | have a non-lazy previous value to compare with. */ |
| 882 | if (result != NULL |
| 883 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) |
| 884 | *valp = result; |
| 885 | |
| 886 | if (val_chain) |
| 887 | { |
| 888 | /* Return the chain of intermediate values. We use this to |
| 889 | decide which addresses to watch. */ |
| 890 | *val_chain = new_mark; |
| 891 | value_release_to_mark (mark); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | /* Assuming that B is a watchpoint: |
| 896 | - Reparse watchpoint expression, if REPARSE is non-zero |
| 897 | - Evaluate expression and store the result in B->val |
| 898 | - Evaluate the condition if there is one, and store the result |
| 899 | in b->loc->cond. |
| 900 | - Update the list of values that must be watched in B->loc. |
| 901 | |
| 902 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
| 903 | If this is local watchpoint that is out of scope, delete it. */ |
| 904 | static void |
| 905 | update_watchpoint (struct breakpoint *b, int reparse) |
| 906 | { |
| 907 | int within_current_scope; |
| 908 | struct frame_id saved_frame_id; |
| 909 | struct bp_location *loc; |
| 910 | bpstat bs; |
| 911 | |
| 912 | /* We don't free locations. They are stored in bp_location_chain and |
| 913 | update_global_locations will eventually delete them and remove |
| 914 | breakpoints if needed. */ |
| 915 | b->loc = NULL; |
| 916 | |
| 917 | if (b->disposition == disp_del_at_next_stop) |
| 918 | return; |
| 919 | |
| 920 | /* Save the current frame's ID so we can restore it after |
| 921 | evaluating the watchpoint expression on its own frame. */ |
| 922 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
| 923 | took a frame parameter, so that we didn't have to change the |
| 924 | selected frame. */ |
| 925 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); |
| 926 | |
| 927 | /* Determine if the watchpoint is within scope. */ |
| 928 | if (b->exp_valid_block == NULL) |
| 929 | within_current_scope = 1; |
| 930 | else |
| 931 | { |
| 932 | struct frame_info *fi; |
| 933 | fi = frame_find_by_id (b->watchpoint_frame); |
| 934 | within_current_scope = (fi != NULL); |
| 935 | if (within_current_scope) |
| 936 | select_frame (fi); |
| 937 | } |
| 938 | |
| 939 | if (within_current_scope && reparse) |
| 940 | { |
| 941 | char *s; |
| 942 | if (b->exp) |
| 943 | { |
| 944 | xfree (b->exp); |
| 945 | b->exp = NULL; |
| 946 | } |
| 947 | s = b->exp_string; |
| 948 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
| 949 | /* If the meaning of expression itself changed, the old value is |
| 950 | no longer relevant. We don't want to report a watchpoint hit |
| 951 | to the user when the old value and the new value may actually |
| 952 | be completely different objects. */ |
| 953 | value_free (b->val); |
| 954 | b->val = NULL; |
| 955 | b->val_valid = 0; |
| 956 | } |
| 957 | |
| 958 | /* If we failed to parse the expression, for example because |
| 959 | it refers to a global variable in a not-yet-loaded shared library, |
| 960 | don't try to insert watchpoint. We don't automatically delete |
| 961 | such watchpoint, though, since failure to parse expression |
| 962 | is different from out-of-scope watchpoint. */ |
| 963 | if (within_current_scope && b->exp) |
| 964 | { |
| 965 | struct value *val_chain, *v, *result, *next; |
| 966 | |
| 967 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
| 968 | |
| 969 | /* Avoid setting b->val if it's already set. The meaning of |
| 970 | b->val is 'the last value' user saw, and we should update |
| 971 | it only if we reported that last value to user. As it |
| 972 | happens, the code that reports it updates b->val directly. */ |
| 973 | if (!b->val_valid) |
| 974 | { |
| 975 | b->val = v; |
| 976 | b->val_valid = 1; |
| 977 | } |
| 978 | |
| 979 | /* Change the type of breakpoint between hardware assisted or an |
| 980 | ordinary watchpoint depending on the hardware support and free |
| 981 | hardware slots. REPARSE is set when the inferior is started. */ |
| 982 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) |
| 983 | && reparse) |
| 984 | { |
| 985 | int i, mem_cnt, other_type_used; |
| 986 | |
| 987 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
| 988 | &other_type_used); |
| 989 | mem_cnt = can_use_hardware_watchpoint (val_chain); |
| 990 | |
| 991 | if (!mem_cnt) |
| 992 | b->type = bp_watchpoint; |
| 993 | else |
| 994 | { |
| 995 | int target_resources_ok = target_can_use_hardware_watchpoint |
| 996 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
| 997 | if (target_resources_ok <= 0) |
| 998 | b->type = bp_watchpoint; |
| 999 | else |
| 1000 | b->type = bp_hardware_watchpoint; |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | /* Look at each value on the value chain. */ |
| 1005 | for (v = val_chain; v; v = next) |
| 1006 | { |
| 1007 | /* If it's a memory location, and GDB actually needed |
| 1008 | its contents to evaluate the expression, then we |
| 1009 | must watch it. If the first value returned is |
| 1010 | still lazy, that means an error occurred reading it; |
| 1011 | watch it anyway in case it becomes readable. */ |
| 1012 | if (VALUE_LVAL (v) == lval_memory |
| 1013 | && (v == val_chain || ! value_lazy (v))) |
| 1014 | { |
| 1015 | struct type *vtype = check_typedef (value_type (v)); |
| 1016 | |
| 1017 | /* We only watch structs and arrays if user asked |
| 1018 | for it explicitly, never if they just happen to |
| 1019 | appear in the middle of some value chain. */ |
| 1020 | if (v == result |
| 1021 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 1022 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 1023 | { |
| 1024 | CORE_ADDR addr; |
| 1025 | int len, type; |
| 1026 | struct bp_location *loc, **tmp; |
| 1027 | |
| 1028 | addr = value_address (v); |
| 1029 | len = TYPE_LENGTH (value_type (v)); |
| 1030 | type = hw_write; |
| 1031 | if (b->type == bp_read_watchpoint) |
| 1032 | type = hw_read; |
| 1033 | else if (b->type == bp_access_watchpoint) |
| 1034 | type = hw_access; |
| 1035 | |
| 1036 | loc = allocate_bp_location (b); |
| 1037 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
| 1038 | ; |
| 1039 | *tmp = loc; |
| 1040 | loc->gdbarch = get_type_arch (value_type (v)); |
| 1041 | loc->address = addr; |
| 1042 | loc->length = len; |
| 1043 | loc->watchpoint_type = type; |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | next = value_next (v); |
| 1048 | if (v != b->val) |
| 1049 | value_free (v); |
| 1050 | } |
| 1051 | |
| 1052 | /* We just regenerated the list of breakpoint locations. |
| 1053 | The new location does not have its condition field set to anything |
| 1054 | and therefore, we must always reparse the cond_string, independently |
| 1055 | of the value of the reparse flag. */ |
| 1056 | if (b->cond_string != NULL) |
| 1057 | { |
| 1058 | char *s = b->cond_string; |
| 1059 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
| 1060 | } |
| 1061 | } |
| 1062 | else if (!within_current_scope) |
| 1063 | { |
| 1064 | printf_filtered (_("\ |
| 1065 | Watchpoint %d deleted because the program has left the block \n\ |
| 1066 | in which its expression is valid.\n"), |
| 1067 | b->number); |
| 1068 | if (b->related_breakpoint) |
| 1069 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
| 1070 | b->disposition = disp_del_at_next_stop; |
| 1071 | } |
| 1072 | |
| 1073 | /* Restore the selected frame. */ |
| 1074 | select_frame (frame_find_by_id (saved_frame_id)); |
| 1075 | } |
| 1076 | |
| 1077 | |
| 1078 | /* Returns 1 iff breakpoint location should be |
| 1079 | inserted in the inferior. */ |
| 1080 | static int |
| 1081 | should_be_inserted (struct bp_location *bpt) |
| 1082 | { |
| 1083 | if (!breakpoint_enabled (bpt->owner)) |
| 1084 | return 0; |
| 1085 | |
| 1086 | if (bpt->owner->disposition == disp_del_at_next_stop) |
| 1087 | return 0; |
| 1088 | |
| 1089 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) |
| 1090 | return 0; |
| 1091 | |
| 1092 | /* Tracepoints are inserted by the target at a time of its choosing, |
| 1093 | not by us. */ |
| 1094 | if (bpt->owner->type == bp_tracepoint) |
| 1095 | return 0; |
| 1096 | |
| 1097 | return 1; |
| 1098 | } |
| 1099 | |
| 1100 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
| 1101 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, |
| 1102 | and HW_BREAKPOINT_ERROR are used to report problems. |
| 1103 | |
| 1104 | NOTE drow/2003-09-09: This routine could be broken down to an object-style |
| 1105 | method for each breakpoint or catchpoint type. */ |
| 1106 | static int |
| 1107 | insert_bp_location (struct bp_location *bpt, |
| 1108 | struct ui_file *tmp_error_stream, |
| 1109 | int *disabled_breaks, |
| 1110 | int *hw_breakpoint_error) |
| 1111 | { |
| 1112 | int val = 0; |
| 1113 | |
| 1114 | if (!should_be_inserted (bpt) || bpt->inserted) |
| 1115 | return 0; |
| 1116 | |
| 1117 | /* Initialize the target-specific information. */ |
| 1118 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); |
| 1119 | bpt->target_info.placed_address = bpt->address; |
| 1120 | |
| 1121 | if (bpt->loc_type == bp_loc_software_breakpoint |
| 1122 | || bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1123 | { |
| 1124 | if (bpt->owner->type != bp_hardware_breakpoint) |
| 1125 | { |
| 1126 | /* If the explicitly specified breakpoint type |
| 1127 | is not hardware breakpoint, check the memory map to see |
| 1128 | if the breakpoint address is in read only memory or not. |
| 1129 | Two important cases are: |
| 1130 | - location type is not hardware breakpoint, memory |
| 1131 | is readonly. We change the type of the location to |
| 1132 | hardware breakpoint. |
| 1133 | - location type is hardware breakpoint, memory is read-write. |
| 1134 | This means we've previously made the location hardware one, but |
| 1135 | then the memory map changed, so we undo. |
| 1136 | |
| 1137 | When breakpoints are removed, remove_breakpoints will |
| 1138 | use location types we've just set here, the only possible |
| 1139 | problem is that memory map has changed during running program, |
| 1140 | but it's not going to work anyway with current gdb. */ |
| 1141 | struct mem_region *mr |
| 1142 | = lookup_mem_region (bpt->target_info.placed_address); |
| 1143 | |
| 1144 | if (mr) |
| 1145 | { |
| 1146 | if (automatic_hardware_breakpoints) |
| 1147 | { |
| 1148 | int changed = 0; |
| 1149 | enum bp_loc_type new_type; |
| 1150 | |
| 1151 | if (mr->attrib.mode != MEM_RW) |
| 1152 | new_type = bp_loc_hardware_breakpoint; |
| 1153 | else |
| 1154 | new_type = bp_loc_software_breakpoint; |
| 1155 | |
| 1156 | if (new_type != bpt->loc_type) |
| 1157 | { |
| 1158 | static int said = 0; |
| 1159 | bpt->loc_type = new_type; |
| 1160 | if (!said) |
| 1161 | { |
| 1162 | fprintf_filtered (gdb_stdout, _("\ |
| 1163 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
| 1164 | said = 1; |
| 1165 | } |
| 1166 | } |
| 1167 | } |
| 1168 | else if (bpt->loc_type == bp_loc_software_breakpoint |
| 1169 | && mr->attrib.mode != MEM_RW) |
| 1170 | warning (_("cannot set software breakpoint at readonly address %s"), |
| 1171 | paddress (bpt->gdbarch, bpt->address)); |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | /* First check to see if we have to handle an overlay. */ |
| 1176 | if (overlay_debugging == ovly_off |
| 1177 | || bpt->section == NULL |
| 1178 | || !(section_is_overlay (bpt->section))) |
| 1179 | { |
| 1180 | /* No overlay handling: just set the breakpoint. */ |
| 1181 | |
| 1182 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1183 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
| 1184 | &bpt->target_info); |
| 1185 | else |
| 1186 | val = target_insert_breakpoint (bpt->gdbarch, |
| 1187 | &bpt->target_info); |
| 1188 | } |
| 1189 | else |
| 1190 | { |
| 1191 | /* This breakpoint is in an overlay section. |
| 1192 | Shall we set a breakpoint at the LMA? */ |
| 1193 | if (!overlay_events_enabled) |
| 1194 | { |
| 1195 | /* Yes -- overlay event support is not active, |
| 1196 | so we must try to set a breakpoint at the LMA. |
| 1197 | This will not work for a hardware breakpoint. */ |
| 1198 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1199 | warning (_("hardware breakpoint %d not supported in overlay!"), |
| 1200 | bpt->owner->number); |
| 1201 | else |
| 1202 | { |
| 1203 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, |
| 1204 | bpt->section); |
| 1205 | /* Set a software (trap) breakpoint at the LMA. */ |
| 1206 | bpt->overlay_target_info = bpt->target_info; |
| 1207 | bpt->overlay_target_info.placed_address = addr; |
| 1208 | val = target_insert_breakpoint (bpt->gdbarch, |
| 1209 | &bpt->overlay_target_info); |
| 1210 | if (val != 0) |
| 1211 | fprintf_unfiltered (tmp_error_stream, |
| 1212 | "Overlay breakpoint %d failed: in ROM?\n", |
| 1213 | bpt->owner->number); |
| 1214 | } |
| 1215 | } |
| 1216 | /* Shall we set a breakpoint at the VMA? */ |
| 1217 | if (section_is_mapped (bpt->section)) |
| 1218 | { |
| 1219 | /* Yes. This overlay section is mapped into memory. */ |
| 1220 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1221 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
| 1222 | &bpt->target_info); |
| 1223 | else |
| 1224 | val = target_insert_breakpoint (bpt->gdbarch, |
| 1225 | &bpt->target_info); |
| 1226 | } |
| 1227 | else |
| 1228 | { |
| 1229 | /* No. This breakpoint will not be inserted. |
| 1230 | No error, but do not mark the bp as 'inserted'. */ |
| 1231 | return 0; |
| 1232 | } |
| 1233 | } |
| 1234 | |
| 1235 | if (val) |
| 1236 | { |
| 1237 | /* Can't set the breakpoint. */ |
| 1238 | if (solib_name_from_address (bpt->address)) |
| 1239 | { |
| 1240 | /* See also: disable_breakpoints_in_shlibs. */ |
| 1241 | val = 0; |
| 1242 | bpt->shlib_disabled = 1; |
| 1243 | if (!*disabled_breaks) |
| 1244 | { |
| 1245 | fprintf_unfiltered (tmp_error_stream, |
| 1246 | "Cannot insert breakpoint %d.\n", |
| 1247 | bpt->owner->number); |
| 1248 | fprintf_unfiltered (tmp_error_stream, |
| 1249 | "Temporarily disabling shared library breakpoints:\n"); |
| 1250 | } |
| 1251 | *disabled_breaks = 1; |
| 1252 | fprintf_unfiltered (tmp_error_stream, |
| 1253 | "breakpoint #%d\n", bpt->owner->number); |
| 1254 | } |
| 1255 | else |
| 1256 | { |
| 1257 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
| 1258 | { |
| 1259 | *hw_breakpoint_error = 1; |
| 1260 | fprintf_unfiltered (tmp_error_stream, |
| 1261 | "Cannot insert hardware breakpoint %d.\n", |
| 1262 | bpt->owner->number); |
| 1263 | } |
| 1264 | else |
| 1265 | { |
| 1266 | fprintf_unfiltered (tmp_error_stream, |
| 1267 | "Cannot insert breakpoint %d.\n", |
| 1268 | bpt->owner->number); |
| 1269 | fprintf_filtered (tmp_error_stream, |
| 1270 | "Error accessing memory address "); |
| 1271 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
| 1272 | tmp_error_stream); |
| 1273 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
| 1274 | safe_strerror (val)); |
| 1275 | } |
| 1276 | |
| 1277 | } |
| 1278 | } |
| 1279 | else |
| 1280 | bpt->inserted = 1; |
| 1281 | |
| 1282 | return val; |
| 1283 | } |
| 1284 | |
| 1285 | else if (bpt->loc_type == bp_loc_hardware_watchpoint |
| 1286 | /* NOTE drow/2003-09-08: This state only exists for removing |
| 1287 | watchpoints. It's not clear that it's necessary... */ |
| 1288 | && bpt->owner->disposition != disp_del_at_next_stop) |
| 1289 | { |
| 1290 | val = target_insert_watchpoint (bpt->address, |
| 1291 | bpt->length, |
| 1292 | bpt->watchpoint_type); |
| 1293 | bpt->inserted = (val != -1); |
| 1294 | } |
| 1295 | |
| 1296 | else if (bpt->owner->type == bp_catchpoint) |
| 1297 | { |
| 1298 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
| 1299 | bpt->owner, RETURN_MASK_ERROR); |
| 1300 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
| 1301 | bpt->owner->number); |
| 1302 | if (e.reason < 0) |
| 1303 | bpt->owner->enable_state = bp_disabled; |
| 1304 | else |
| 1305 | bpt->inserted = 1; |
| 1306 | |
| 1307 | /* We've already printed an error message if there was a problem |
| 1308 | inserting this catchpoint, and we've disabled the catchpoint, |
| 1309 | so just return success. */ |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
| 1313 | return 0; |
| 1314 | } |
| 1315 | |
| 1316 | /* Make sure all breakpoints are inserted in inferior. |
| 1317 | Throws exception on any error. |
| 1318 | A breakpoint that is already inserted won't be inserted |
| 1319 | again, so calling this function twice is safe. */ |
| 1320 | void |
| 1321 | insert_breakpoints (void) |
| 1322 | { |
| 1323 | struct breakpoint *bpt; |
| 1324 | |
| 1325 | ALL_BREAKPOINTS (bpt) |
| 1326 | if (is_hardware_watchpoint (bpt)) |
| 1327 | update_watchpoint (bpt, 0 /* don't reparse. */); |
| 1328 | |
| 1329 | update_global_location_list (1); |
| 1330 | |
| 1331 | /* update_global_location_list does not insert breakpoints when |
| 1332 | always_inserted_mode is not enabled. Explicitly insert them |
| 1333 | now. */ |
| 1334 | if (!breakpoints_always_inserted_mode ()) |
| 1335 | insert_breakpoint_locations (); |
| 1336 | } |
| 1337 | |
| 1338 | /* insert_breakpoints is used when starting or continuing the program. |
| 1339 | remove_breakpoints is used when the program stops. |
| 1340 | Both return zero if successful, |
| 1341 | or an `errno' value if could not write the inferior. */ |
| 1342 | |
| 1343 | static void |
| 1344 | insert_breakpoint_locations (void) |
| 1345 | { |
| 1346 | struct breakpoint *bpt; |
| 1347 | struct bp_location *b, *temp; |
| 1348 | int error = 0; |
| 1349 | int val = 0; |
| 1350 | int disabled_breaks = 0; |
| 1351 | int hw_breakpoint_error = 0; |
| 1352 | |
| 1353 | struct ui_file *tmp_error_stream = mem_fileopen (); |
| 1354 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
| 1355 | |
| 1356 | /* Explicitly mark the warning -- this will only be printed if |
| 1357 | there was an error. */ |
| 1358 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); |
| 1359 | |
| 1360 | ALL_BP_LOCATIONS_SAFE (b, temp) |
| 1361 | { |
| 1362 | if (!should_be_inserted (b) || b->inserted) |
| 1363 | continue; |
| 1364 | |
| 1365 | /* There is no point inserting thread-specific breakpoints if the |
| 1366 | thread no longer exists. */ |
| 1367 | if (b->owner->thread != -1 |
| 1368 | && !valid_thread_id (b->owner->thread)) |
| 1369 | continue; |
| 1370 | |
| 1371 | val = insert_bp_location (b, tmp_error_stream, |
| 1372 | &disabled_breaks, |
| 1373 | &hw_breakpoint_error); |
| 1374 | if (val) |
| 1375 | error = val; |
| 1376 | } |
| 1377 | |
| 1378 | /* If we failed to insert all locations of a watchpoint, |
| 1379 | remove them, as half-inserted watchpoint is of limited use. */ |
| 1380 | ALL_BREAKPOINTS (bpt) |
| 1381 | { |
| 1382 | int some_failed = 0; |
| 1383 | struct bp_location *loc; |
| 1384 | |
| 1385 | if (!is_hardware_watchpoint (bpt)) |
| 1386 | continue; |
| 1387 | |
| 1388 | if (!breakpoint_enabled (bpt)) |
| 1389 | continue; |
| 1390 | |
| 1391 | if (bpt->disposition == disp_del_at_next_stop) |
| 1392 | continue; |
| 1393 | |
| 1394 | for (loc = bpt->loc; loc; loc = loc->next) |
| 1395 | if (!loc->inserted) |
| 1396 | { |
| 1397 | some_failed = 1; |
| 1398 | break; |
| 1399 | } |
| 1400 | if (some_failed) |
| 1401 | { |
| 1402 | for (loc = bpt->loc; loc; loc = loc->next) |
| 1403 | if (loc->inserted) |
| 1404 | remove_breakpoint (loc, mark_uninserted); |
| 1405 | |
| 1406 | hw_breakpoint_error = 1; |
| 1407 | fprintf_unfiltered (tmp_error_stream, |
| 1408 | "Could not insert hardware watchpoint %d.\n", |
| 1409 | bpt->number); |
| 1410 | error = -1; |
| 1411 | } |
| 1412 | } |
| 1413 | |
| 1414 | if (error) |
| 1415 | { |
| 1416 | /* If a hardware breakpoint or watchpoint was inserted, add a |
| 1417 | message about possibly exhausted resources. */ |
| 1418 | if (hw_breakpoint_error) |
| 1419 | { |
| 1420 | fprintf_unfiltered (tmp_error_stream, |
| 1421 | "Could not insert hardware breakpoints:\n\ |
| 1422 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
| 1423 | } |
| 1424 | target_terminal_ours_for_output (); |
| 1425 | error_stream (tmp_error_stream); |
| 1426 | } |
| 1427 | |
| 1428 | do_cleanups (cleanups); |
| 1429 | } |
| 1430 | |
| 1431 | int |
| 1432 | remove_breakpoints (void) |
| 1433 | { |
| 1434 | struct bp_location *b; |
| 1435 | int val = 0; |
| 1436 | |
| 1437 | ALL_BP_LOCATIONS (b) |
| 1438 | { |
| 1439 | if (b->inserted) |
| 1440 | val |= remove_breakpoint (b, mark_uninserted); |
| 1441 | } |
| 1442 | return val; |
| 1443 | } |
| 1444 | |
| 1445 | int |
| 1446 | remove_hw_watchpoints (void) |
| 1447 | { |
| 1448 | struct bp_location *b; |
| 1449 | int val = 0; |
| 1450 | |
| 1451 | ALL_BP_LOCATIONS (b) |
| 1452 | { |
| 1453 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
| 1454 | val |= remove_breakpoint (b, mark_uninserted); |
| 1455 | } |
| 1456 | return val; |
| 1457 | } |
| 1458 | |
| 1459 | int |
| 1460 | reattach_breakpoints (int pid) |
| 1461 | { |
| 1462 | struct bp_location *b; |
| 1463 | int val; |
| 1464 | struct cleanup *old_chain = save_inferior_ptid (); |
| 1465 | struct ui_file *tmp_error_stream = mem_fileopen (); |
| 1466 | int dummy1 = 0, dummy2 = 0; |
| 1467 | |
| 1468 | make_cleanup_ui_file_delete (tmp_error_stream); |
| 1469 | |
| 1470 | inferior_ptid = pid_to_ptid (pid); |
| 1471 | ALL_BP_LOCATIONS (b) |
| 1472 | { |
| 1473 | if (b->inserted) |
| 1474 | { |
| 1475 | b->inserted = 0; |
| 1476 | val = insert_bp_location (b, tmp_error_stream, |
| 1477 | &dummy1, &dummy2); |
| 1478 | if (val != 0) |
| 1479 | { |
| 1480 | do_cleanups (old_chain); |
| 1481 | return val; |
| 1482 | } |
| 1483 | } |
| 1484 | } |
| 1485 | do_cleanups (old_chain); |
| 1486 | return 0; |
| 1487 | } |
| 1488 | |
| 1489 | static int internal_breakpoint_number = -1; |
| 1490 | |
| 1491 | static struct breakpoint * |
| 1492 | create_internal_breakpoint (struct gdbarch *gdbarch, |
| 1493 | CORE_ADDR address, enum bptype type) |
| 1494 | { |
| 1495 | struct symtab_and_line sal; |
| 1496 | struct breakpoint *b; |
| 1497 | |
| 1498 | init_sal (&sal); /* initialize to zeroes */ |
| 1499 | |
| 1500 | sal.pc = address; |
| 1501 | sal.section = find_pc_overlay (sal.pc); |
| 1502 | |
| 1503 | b = set_raw_breakpoint (gdbarch, sal, type); |
| 1504 | b->number = internal_breakpoint_number--; |
| 1505 | b->disposition = disp_donttouch; |
| 1506 | |
| 1507 | return b; |
| 1508 | } |
| 1509 | |
| 1510 | static void |
| 1511 | create_overlay_event_breakpoint (char *func_name) |
| 1512 | { |
| 1513 | struct objfile *objfile; |
| 1514 | |
| 1515 | ALL_OBJFILES (objfile) |
| 1516 | { |
| 1517 | struct breakpoint *b; |
| 1518 | struct minimal_symbol *m; |
| 1519 | |
| 1520 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 1521 | if (m == NULL) |
| 1522 | continue; |
| 1523 | |
| 1524 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
| 1525 | SYMBOL_VALUE_ADDRESS (m), |
| 1526 | bp_overlay_event); |
| 1527 | b->addr_string = xstrdup (func_name); |
| 1528 | |
| 1529 | if (overlay_debugging == ovly_auto) |
| 1530 | { |
| 1531 | b->enable_state = bp_enabled; |
| 1532 | overlay_events_enabled = 1; |
| 1533 | } |
| 1534 | else |
| 1535 | { |
| 1536 | b->enable_state = bp_disabled; |
| 1537 | overlay_events_enabled = 0; |
| 1538 | } |
| 1539 | } |
| 1540 | update_global_location_list (1); |
| 1541 | } |
| 1542 | |
| 1543 | static void |
| 1544 | create_longjmp_master_breakpoint (char *func_name) |
| 1545 | { |
| 1546 | struct objfile *objfile; |
| 1547 | |
| 1548 | ALL_OBJFILES (objfile) |
| 1549 | { |
| 1550 | struct breakpoint *b; |
| 1551 | struct minimal_symbol *m; |
| 1552 | |
| 1553 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) |
| 1554 | continue; |
| 1555 | |
| 1556 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 1557 | if (m == NULL) |
| 1558 | continue; |
| 1559 | |
| 1560 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
| 1561 | SYMBOL_VALUE_ADDRESS (m), |
| 1562 | bp_longjmp_master); |
| 1563 | b->addr_string = xstrdup (func_name); |
| 1564 | b->enable_state = bp_disabled; |
| 1565 | } |
| 1566 | update_global_location_list (1); |
| 1567 | } |
| 1568 | |
| 1569 | void |
| 1570 | update_breakpoints_after_exec (void) |
| 1571 | { |
| 1572 | struct breakpoint *b; |
| 1573 | struct breakpoint *temp; |
| 1574 | struct bp_location *bploc; |
| 1575 | |
| 1576 | /* We're about to delete breakpoints from GDB's lists. If the |
| 1577 | INSERTED flag is true, GDB will try to lift the breakpoints by |
| 1578 | writing the breakpoints' "shadow contents" back into memory. The |
| 1579 | "shadow contents" are NOT valid after an exec, so GDB should not |
| 1580 | do that. Instead, the target is responsible from marking |
| 1581 | breakpoints out as soon as it detects an exec. We don't do that |
| 1582 | here instead, because there may be other attempts to delete |
| 1583 | breakpoints after detecting an exec and before reaching here. */ |
| 1584 | ALL_BP_LOCATIONS (bploc) |
| 1585 | gdb_assert (!bploc->inserted); |
| 1586 | |
| 1587 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 1588 | { |
| 1589 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
| 1590 | if (b->type == bp_shlib_event) |
| 1591 | { |
| 1592 | delete_breakpoint (b); |
| 1593 | continue; |
| 1594 | } |
| 1595 | |
| 1596 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
| 1597 | if (b->type == bp_jit_event) |
| 1598 | { |
| 1599 | delete_breakpoint (b); |
| 1600 | continue; |
| 1601 | } |
| 1602 | |
| 1603 | /* Thread event breakpoints must be set anew after an exec(), |
| 1604 | as must overlay event and longjmp master breakpoints. */ |
| 1605 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
| 1606 | || b->type == bp_longjmp_master) |
| 1607 | { |
| 1608 | delete_breakpoint (b); |
| 1609 | continue; |
| 1610 | } |
| 1611 | |
| 1612 | /* Step-resume breakpoints are meaningless after an exec(). */ |
| 1613 | if (b->type == bp_step_resume) |
| 1614 | { |
| 1615 | delete_breakpoint (b); |
| 1616 | continue; |
| 1617 | } |
| 1618 | |
| 1619 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
| 1620 | after an exec. */ |
| 1621 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) |
| 1622 | { |
| 1623 | delete_breakpoint (b); |
| 1624 | continue; |
| 1625 | } |
| 1626 | |
| 1627 | if (b->type == bp_catchpoint) |
| 1628 | { |
| 1629 | /* For now, none of the bp_catchpoint breakpoints need to |
| 1630 | do anything at this point. In the future, if some of |
| 1631 | the catchpoints need to something, we will need to add |
| 1632 | a new method, and call this method from here. */ |
| 1633 | continue; |
| 1634 | } |
| 1635 | |
| 1636 | /* bp_finish is a special case. The only way we ought to be able |
| 1637 | to see one of these when an exec() has happened, is if the user |
| 1638 | caught a vfork, and then said "finish". Ordinarily a finish just |
| 1639 | carries them to the call-site of the current callee, by setting |
| 1640 | a temporary bp there and resuming. But in this case, the finish |
| 1641 | will carry them entirely through the vfork & exec. |
| 1642 | |
| 1643 | We don't want to allow a bp_finish to remain inserted now. But |
| 1644 | we can't safely delete it, 'cause finish_command has a handle to |
| 1645 | the bp on a bpstat, and will later want to delete it. There's a |
| 1646 | chance (and I've seen it happen) that if we delete the bp_finish |
| 1647 | here, that its storage will get reused by the time finish_command |
| 1648 | gets 'round to deleting the "use to be a bp_finish" breakpoint. |
| 1649 | We really must allow finish_command to delete a bp_finish. |
| 1650 | |
| 1651 | In the absense of a general solution for the "how do we know |
| 1652 | it's safe to delete something others may have handles to?" |
| 1653 | problem, what we'll do here is just uninsert the bp_finish, and |
| 1654 | let finish_command delete it. |
| 1655 | |
| 1656 | (We know the bp_finish is "doomed" in the sense that it's |
| 1657 | momentary, and will be deleted as soon as finish_command sees |
| 1658 | the inferior stopped. So it doesn't matter that the bp's |
| 1659 | address is probably bogus in the new a.out, unlike e.g., the |
| 1660 | solib breakpoints.) */ |
| 1661 | |
| 1662 | if (b->type == bp_finish) |
| 1663 | { |
| 1664 | continue; |
| 1665 | } |
| 1666 | |
| 1667 | /* Without a symbolic address, we have little hope of the |
| 1668 | pre-exec() address meaning the same thing in the post-exec() |
| 1669 | a.out. */ |
| 1670 | if (b->addr_string == NULL) |
| 1671 | { |
| 1672 | delete_breakpoint (b); |
| 1673 | continue; |
| 1674 | } |
| 1675 | } |
| 1676 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
| 1677 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
| 1678 | create_longjmp_master_breakpoint ("longjmp"); |
| 1679 | create_longjmp_master_breakpoint ("_longjmp"); |
| 1680 | create_longjmp_master_breakpoint ("siglongjmp"); |
| 1681 | create_longjmp_master_breakpoint ("_siglongjmp"); |
| 1682 | } |
| 1683 | |
| 1684 | int |
| 1685 | detach_breakpoints (int pid) |
| 1686 | { |
| 1687 | struct bp_location *b; |
| 1688 | int val = 0; |
| 1689 | struct cleanup *old_chain = save_inferior_ptid (); |
| 1690 | |
| 1691 | if (pid == PIDGET (inferior_ptid)) |
| 1692 | error (_("Cannot detach breakpoints of inferior_ptid")); |
| 1693 | |
| 1694 | /* Set inferior_ptid; remove_breakpoint uses this global. */ |
| 1695 | inferior_ptid = pid_to_ptid (pid); |
| 1696 | ALL_BP_LOCATIONS (b) |
| 1697 | { |
| 1698 | if (b->inserted) |
| 1699 | val |= remove_breakpoint (b, mark_inserted); |
| 1700 | } |
| 1701 | do_cleanups (old_chain); |
| 1702 | return val; |
| 1703 | } |
| 1704 | |
| 1705 | static int |
| 1706 | remove_breakpoint (struct bp_location *b, insertion_state_t is) |
| 1707 | { |
| 1708 | int val; |
| 1709 | |
| 1710 | if (b->owner->enable_state == bp_permanent) |
| 1711 | /* Permanent breakpoints cannot be inserted or removed. */ |
| 1712 | return 0; |
| 1713 | |
| 1714 | /* The type of none suggests that owner is actually deleted. |
| 1715 | This should not ever happen. */ |
| 1716 | gdb_assert (b->owner->type != bp_none); |
| 1717 | |
| 1718 | if (b->loc_type == bp_loc_software_breakpoint |
| 1719 | || b->loc_type == bp_loc_hardware_breakpoint) |
| 1720 | { |
| 1721 | /* "Normal" instruction breakpoint: either the standard |
| 1722 | trap-instruction bp (bp_breakpoint), or a |
| 1723 | bp_hardware_breakpoint. */ |
| 1724 | |
| 1725 | /* First check to see if we have to handle an overlay. */ |
| 1726 | if (overlay_debugging == ovly_off |
| 1727 | || b->section == NULL |
| 1728 | || !(section_is_overlay (b->section))) |
| 1729 | { |
| 1730 | /* No overlay handling: just remove the breakpoint. */ |
| 1731 | |
| 1732 | if (b->loc_type == bp_loc_hardware_breakpoint) |
| 1733 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
| 1734 | else |
| 1735 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
| 1736 | } |
| 1737 | else |
| 1738 | { |
| 1739 | /* This breakpoint is in an overlay section. |
| 1740 | Did we set a breakpoint at the LMA? */ |
| 1741 | if (!overlay_events_enabled) |
| 1742 | { |
| 1743 | /* Yes -- overlay event support is not active, so we |
| 1744 | should have set a breakpoint at the LMA. Remove it. |
| 1745 | */ |
| 1746 | /* Ignore any failures: if the LMA is in ROM, we will |
| 1747 | have already warned when we failed to insert it. */ |
| 1748 | if (b->loc_type == bp_loc_hardware_breakpoint) |
| 1749 | target_remove_hw_breakpoint (b->gdbarch, |
| 1750 | &b->overlay_target_info); |
| 1751 | else |
| 1752 | target_remove_breakpoint (b->gdbarch, |
| 1753 | &b->overlay_target_info); |
| 1754 | } |
| 1755 | /* Did we set a breakpoint at the VMA? |
| 1756 | If so, we will have marked the breakpoint 'inserted'. */ |
| 1757 | if (b->inserted) |
| 1758 | { |
| 1759 | /* Yes -- remove it. Previously we did not bother to |
| 1760 | remove the breakpoint if the section had been |
| 1761 | unmapped, but let's not rely on that being safe. We |
| 1762 | don't know what the overlay manager might do. */ |
| 1763 | if (b->loc_type == bp_loc_hardware_breakpoint) |
| 1764 | val = target_remove_hw_breakpoint (b->gdbarch, |
| 1765 | &b->target_info); |
| 1766 | |
| 1767 | /* However, we should remove *software* breakpoints only |
| 1768 | if the section is still mapped, or else we overwrite |
| 1769 | wrong code with the saved shadow contents. */ |
| 1770 | else if (section_is_mapped (b->section)) |
| 1771 | val = target_remove_breakpoint (b->gdbarch, |
| 1772 | &b->target_info); |
| 1773 | else |
| 1774 | val = 0; |
| 1775 | } |
| 1776 | else |
| 1777 | { |
| 1778 | /* No -- not inserted, so no need to remove. No error. */ |
| 1779 | val = 0; |
| 1780 | } |
| 1781 | } |
| 1782 | |
| 1783 | /* In some cases, we might not be able to remove a breakpoint |
| 1784 | in a shared library that has already been removed, but we |
| 1785 | have not yet processed the shlib unload event. */ |
| 1786 | if (val && solib_name_from_address (b->address)) |
| 1787 | val = 0; |
| 1788 | |
| 1789 | if (val) |
| 1790 | return val; |
| 1791 | b->inserted = (is == mark_inserted); |
| 1792 | } |
| 1793 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
| 1794 | { |
| 1795 | struct value *v; |
| 1796 | struct value *n; |
| 1797 | |
| 1798 | b->inserted = (is == mark_inserted); |
| 1799 | val = target_remove_watchpoint (b->address, b->length, |
| 1800 | b->watchpoint_type); |
| 1801 | |
| 1802 | /* Failure to remove any of the hardware watchpoints comes here. */ |
| 1803 | if ((is == mark_uninserted) && (b->inserted)) |
| 1804 | warning (_("Could not remove hardware watchpoint %d."), |
| 1805 | b->owner->number); |
| 1806 | } |
| 1807 | else if (b->owner->type == bp_catchpoint |
| 1808 | && breakpoint_enabled (b->owner) |
| 1809 | && !b->duplicate) |
| 1810 | { |
| 1811 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); |
| 1812 | |
| 1813 | val = b->owner->ops->remove (b->owner); |
| 1814 | if (val) |
| 1815 | return val; |
| 1816 | b->inserted = (is == mark_inserted); |
| 1817 | } |
| 1818 | |
| 1819 | return 0; |
| 1820 | } |
| 1821 | |
| 1822 | /* Clear the "inserted" flag in all breakpoints. */ |
| 1823 | |
| 1824 | void |
| 1825 | mark_breakpoints_out (void) |
| 1826 | { |
| 1827 | struct bp_location *bpt; |
| 1828 | |
| 1829 | ALL_BP_LOCATIONS (bpt) |
| 1830 | bpt->inserted = 0; |
| 1831 | } |
| 1832 | |
| 1833 | /* Clear the "inserted" flag in all breakpoints and delete any |
| 1834 | breakpoints which should go away between runs of the program. |
| 1835 | |
| 1836 | Plus other such housekeeping that has to be done for breakpoints |
| 1837 | between runs. |
| 1838 | |
| 1839 | Note: this function gets called at the end of a run (by |
| 1840 | generic_mourn_inferior) and when a run begins (by |
| 1841 | init_wait_for_inferior). */ |
| 1842 | |
| 1843 | |
| 1844 | |
| 1845 | void |
| 1846 | breakpoint_init_inferior (enum inf_context context) |
| 1847 | { |
| 1848 | struct breakpoint *b, *temp; |
| 1849 | struct bp_location *bpt; |
| 1850 | int ix; |
| 1851 | |
| 1852 | /* If breakpoint locations are shared across processes, then there's |
| 1853 | nothing to do. */ |
| 1854 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
| 1855 | return; |
| 1856 | |
| 1857 | ALL_BP_LOCATIONS (bpt) |
| 1858 | if (bpt->owner->enable_state != bp_permanent) |
| 1859 | bpt->inserted = 0; |
| 1860 | |
| 1861 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 1862 | { |
| 1863 | switch (b->type) |
| 1864 | { |
| 1865 | case bp_call_dummy: |
| 1866 | case bp_watchpoint_scope: |
| 1867 | |
| 1868 | /* If the call dummy breakpoint is at the entry point it will |
| 1869 | cause problems when the inferior is rerun, so we better |
| 1870 | get rid of it. |
| 1871 | |
| 1872 | Also get rid of scope breakpoints. */ |
| 1873 | delete_breakpoint (b); |
| 1874 | break; |
| 1875 | |
| 1876 | case bp_watchpoint: |
| 1877 | case bp_hardware_watchpoint: |
| 1878 | case bp_read_watchpoint: |
| 1879 | case bp_access_watchpoint: |
| 1880 | |
| 1881 | /* Likewise for watchpoints on local expressions. */ |
| 1882 | if (b->exp_valid_block != NULL) |
| 1883 | delete_breakpoint (b); |
| 1884 | else if (context == inf_starting) |
| 1885 | { |
| 1886 | /* Reset val field to force reread of starting value |
| 1887 | in insert_breakpoints. */ |
| 1888 | if (b->val) |
| 1889 | value_free (b->val); |
| 1890 | b->val = NULL; |
| 1891 | b->val_valid = 0; |
| 1892 | } |
| 1893 | break; |
| 1894 | default: |
| 1895 | break; |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | /* Get rid of the moribund locations. */ |
| 1900 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) |
| 1901 | free_bp_location (bpt); |
| 1902 | VEC_free (bp_location_p, moribund_locations); |
| 1903 | } |
| 1904 | |
| 1905 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
| 1906 | exists at PC. It returns ordinary_breakpoint_here if it's an |
| 1907 | ordinary breakpoint, or permanent_breakpoint_here if it's a |
| 1908 | permanent breakpoint. |
| 1909 | - When continuing from a location with an ordinary breakpoint, we |
| 1910 | actually single step once before calling insert_breakpoints. |
| 1911 | - When continuing from a localion with a permanent breakpoint, we |
| 1912 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
| 1913 | the target, to advance the PC past the breakpoint. */ |
| 1914 | |
| 1915 | enum breakpoint_here |
| 1916 | breakpoint_here_p (CORE_ADDR pc) |
| 1917 | { |
| 1918 | const struct bp_location *bpt; |
| 1919 | int any_breakpoint_here = 0; |
| 1920 | |
| 1921 | ALL_BP_LOCATIONS (bpt) |
| 1922 | { |
| 1923 | if (bpt->loc_type != bp_loc_software_breakpoint |
| 1924 | && bpt->loc_type != bp_loc_hardware_breakpoint) |
| 1925 | continue; |
| 1926 | |
| 1927 | if ((breakpoint_enabled (bpt->owner) |
| 1928 | || bpt->owner->enable_state == bp_permanent) |
| 1929 | && bpt->address == pc) /* bp is enabled and matches pc */ |
| 1930 | { |
| 1931 | if (overlay_debugging |
| 1932 | && section_is_overlay (bpt->section) |
| 1933 | && !section_is_mapped (bpt->section)) |
| 1934 | continue; /* unmapped overlay -- can't be a match */ |
| 1935 | else if (bpt->owner->enable_state == bp_permanent) |
| 1936 | return permanent_breakpoint_here; |
| 1937 | else |
| 1938 | any_breakpoint_here = 1; |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
| 1943 | } |
| 1944 | |
| 1945 | /* Return true if there's a moribund breakpoint at PC. */ |
| 1946 | |
| 1947 | int |
| 1948 | moribund_breakpoint_here_p (CORE_ADDR pc) |
| 1949 | { |
| 1950 | struct bp_location *loc; |
| 1951 | int ix; |
| 1952 | |
| 1953 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 1954 | if (loc->address == pc) |
| 1955 | return 1; |
| 1956 | |
| 1957 | return 0; |
| 1958 | } |
| 1959 | |
| 1960 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
| 1961 | inserted using regular breakpoint_chain/bp_location_chain mechanism. |
| 1962 | This does not check for single-step breakpoints, which are |
| 1963 | inserted and removed using direct target manipulation. */ |
| 1964 | |
| 1965 | int |
| 1966 | regular_breakpoint_inserted_here_p (CORE_ADDR pc) |
| 1967 | { |
| 1968 | const struct bp_location *bpt; |
| 1969 | |
| 1970 | ALL_BP_LOCATIONS (bpt) |
| 1971 | { |
| 1972 | if (bpt->loc_type != bp_loc_software_breakpoint |
| 1973 | && bpt->loc_type != bp_loc_hardware_breakpoint) |
| 1974 | continue; |
| 1975 | |
| 1976 | if (bpt->inserted |
| 1977 | && bpt->address == pc) /* bp is inserted and matches pc */ |
| 1978 | { |
| 1979 | if (overlay_debugging |
| 1980 | && section_is_overlay (bpt->section) |
| 1981 | && !section_is_mapped (bpt->section)) |
| 1982 | continue; /* unmapped overlay -- can't be a match */ |
| 1983 | else |
| 1984 | return 1; |
| 1985 | } |
| 1986 | } |
| 1987 | return 0; |
| 1988 | } |
| 1989 | |
| 1990 | /* Returns non-zero iff there's either regular breakpoint |
| 1991 | or a single step breakpoint inserted at PC. */ |
| 1992 | |
| 1993 | int |
| 1994 | breakpoint_inserted_here_p (CORE_ADDR pc) |
| 1995 | { |
| 1996 | if (regular_breakpoint_inserted_here_p (pc)) |
| 1997 | return 1; |
| 1998 | |
| 1999 | if (single_step_breakpoint_inserted_here_p (pc)) |
| 2000 | return 1; |
| 2001 | |
| 2002 | return 0; |
| 2003 | } |
| 2004 | |
| 2005 | /* This function returns non-zero iff there is a software breakpoint |
| 2006 | inserted at PC. */ |
| 2007 | |
| 2008 | int |
| 2009 | software_breakpoint_inserted_here_p (CORE_ADDR pc) |
| 2010 | { |
| 2011 | const struct bp_location *bpt; |
| 2012 | int any_breakpoint_here = 0; |
| 2013 | |
| 2014 | ALL_BP_LOCATIONS (bpt) |
| 2015 | { |
| 2016 | if (bpt->loc_type != bp_loc_software_breakpoint) |
| 2017 | continue; |
| 2018 | |
| 2019 | if (bpt->inserted |
| 2020 | && bpt->address == pc) /* bp is enabled and matches pc */ |
| 2021 | { |
| 2022 | if (overlay_debugging |
| 2023 | && section_is_overlay (bpt->section) |
| 2024 | && !section_is_mapped (bpt->section)) |
| 2025 | continue; /* unmapped overlay -- can't be a match */ |
| 2026 | else |
| 2027 | return 1; |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | /* Also check for software single-step breakpoints. */ |
| 2032 | if (single_step_breakpoint_inserted_here_p (pc)) |
| 2033 | return 1; |
| 2034 | |
| 2035 | return 0; |
| 2036 | } |
| 2037 | |
| 2038 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
| 2039 | PC is valid for process/thread PTID. */ |
| 2040 | |
| 2041 | int |
| 2042 | breakpoint_thread_match (CORE_ADDR pc, ptid_t ptid) |
| 2043 | { |
| 2044 | const struct bp_location *bpt; |
| 2045 | /* The thread and task IDs associated to PTID, computed lazily. */ |
| 2046 | int thread = -1; |
| 2047 | int task = 0; |
| 2048 | |
| 2049 | ALL_BP_LOCATIONS (bpt) |
| 2050 | { |
| 2051 | if (bpt->loc_type != bp_loc_software_breakpoint |
| 2052 | && bpt->loc_type != bp_loc_hardware_breakpoint) |
| 2053 | continue; |
| 2054 | |
| 2055 | if (!breakpoint_enabled (bpt->owner) |
| 2056 | && bpt->owner->enable_state != bp_permanent) |
| 2057 | continue; |
| 2058 | |
| 2059 | if (bpt->address != pc) |
| 2060 | continue; |
| 2061 | |
| 2062 | if (bpt->owner->thread != -1) |
| 2063 | { |
| 2064 | /* This is a thread-specific breakpoint. Check that ptid |
| 2065 | matches that thread. If thread hasn't been computed yet, |
| 2066 | it is now time to do so. */ |
| 2067 | if (thread == -1) |
| 2068 | thread = pid_to_thread_id (ptid); |
| 2069 | if (bpt->owner->thread != thread) |
| 2070 | continue; |
| 2071 | } |
| 2072 | |
| 2073 | if (bpt->owner->task != 0) |
| 2074 | { |
| 2075 | /* This is a task-specific breakpoint. Check that ptid |
| 2076 | matches that task. If task hasn't been computed yet, |
| 2077 | it is now time to do so. */ |
| 2078 | if (task == 0) |
| 2079 | task = ada_get_task_number (ptid); |
| 2080 | if (bpt->owner->task != task) |
| 2081 | continue; |
| 2082 | } |
| 2083 | |
| 2084 | if (overlay_debugging |
| 2085 | && section_is_overlay (bpt->section) |
| 2086 | && !section_is_mapped (bpt->section)) |
| 2087 | continue; /* unmapped overlay -- can't be a match */ |
| 2088 | |
| 2089 | return 1; |
| 2090 | } |
| 2091 | |
| 2092 | return 0; |
| 2093 | } |
| 2094 | \f |
| 2095 | |
| 2096 | /* bpstat stuff. External routines' interfaces are documented |
| 2097 | in breakpoint.h. */ |
| 2098 | |
| 2099 | int |
| 2100 | ep_is_catchpoint (struct breakpoint *ep) |
| 2101 | { |
| 2102 | return (ep->type == bp_catchpoint); |
| 2103 | } |
| 2104 | |
| 2105 | void |
| 2106 | bpstat_free (bpstat bs) |
| 2107 | { |
| 2108 | if (bs->old_val != NULL) |
| 2109 | value_free (bs->old_val); |
| 2110 | free_command_lines (&bs->commands); |
| 2111 | xfree (bs); |
| 2112 | } |
| 2113 | |
| 2114 | /* Clear a bpstat so that it says we are not at any breakpoint. |
| 2115 | Also free any storage that is part of a bpstat. */ |
| 2116 | |
| 2117 | void |
| 2118 | bpstat_clear (bpstat *bsp) |
| 2119 | { |
| 2120 | bpstat p; |
| 2121 | bpstat q; |
| 2122 | |
| 2123 | if (bsp == 0) |
| 2124 | return; |
| 2125 | p = *bsp; |
| 2126 | while (p != NULL) |
| 2127 | { |
| 2128 | q = p->next; |
| 2129 | bpstat_free (p); |
| 2130 | p = q; |
| 2131 | } |
| 2132 | *bsp = NULL; |
| 2133 | } |
| 2134 | |
| 2135 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
| 2136 | is part of the bpstat is copied as well. */ |
| 2137 | |
| 2138 | bpstat |
| 2139 | bpstat_copy (bpstat bs) |
| 2140 | { |
| 2141 | bpstat p = NULL; |
| 2142 | bpstat tmp; |
| 2143 | bpstat retval = NULL; |
| 2144 | |
| 2145 | if (bs == NULL) |
| 2146 | return bs; |
| 2147 | |
| 2148 | for (; bs != NULL; bs = bs->next) |
| 2149 | { |
| 2150 | tmp = (bpstat) xmalloc (sizeof (*tmp)); |
| 2151 | memcpy (tmp, bs, sizeof (*tmp)); |
| 2152 | if (bs->commands != NULL) |
| 2153 | tmp->commands = copy_command_lines (bs->commands); |
| 2154 | if (bs->old_val != NULL) |
| 2155 | { |
| 2156 | tmp->old_val = value_copy (bs->old_val); |
| 2157 | release_value (tmp->old_val); |
| 2158 | } |
| 2159 | |
| 2160 | if (p == NULL) |
| 2161 | /* This is the first thing in the chain. */ |
| 2162 | retval = tmp; |
| 2163 | else |
| 2164 | p->next = tmp; |
| 2165 | p = tmp; |
| 2166 | } |
| 2167 | p->next = NULL; |
| 2168 | return retval; |
| 2169 | } |
| 2170 | |
| 2171 | /* Find the bpstat associated with this breakpoint */ |
| 2172 | |
| 2173 | bpstat |
| 2174 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
| 2175 | { |
| 2176 | if (bsp == NULL) |
| 2177 | return NULL; |
| 2178 | |
| 2179 | for (; bsp != NULL; bsp = bsp->next) |
| 2180 | { |
| 2181 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
| 2182 | return bsp; |
| 2183 | } |
| 2184 | return NULL; |
| 2185 | } |
| 2186 | |
| 2187 | /* Find a step_resume breakpoint associated with this bpstat. |
| 2188 | (If there are multiple step_resume bp's on the list, this function |
| 2189 | will arbitrarily pick one.) |
| 2190 | |
| 2191 | It is an error to use this function if BPSTAT doesn't contain a |
| 2192 | step_resume breakpoint. |
| 2193 | |
| 2194 | See wait_for_inferior's use of this function. */ |
| 2195 | struct breakpoint * |
| 2196 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
| 2197 | { |
| 2198 | int current_thread; |
| 2199 | |
| 2200 | gdb_assert (bsp != NULL); |
| 2201 | |
| 2202 | current_thread = pid_to_thread_id (inferior_ptid); |
| 2203 | |
| 2204 | for (; bsp != NULL; bsp = bsp->next) |
| 2205 | { |
| 2206 | if ((bsp->breakpoint_at != NULL) |
| 2207 | && (bsp->breakpoint_at->owner->type == bp_step_resume) |
| 2208 | && (bsp->breakpoint_at->owner->thread == current_thread |
| 2209 | || bsp->breakpoint_at->owner->thread == -1)) |
| 2210 | return bsp->breakpoint_at->owner; |
| 2211 | } |
| 2212 | |
| 2213 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
| 2214 | } |
| 2215 | |
| 2216 | |
| 2217 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
| 2218 | at. *BSP upon return is a bpstat which points to the remaining |
| 2219 | breakpoints stopped at (but which is not guaranteed to be good for |
| 2220 | anything but further calls to bpstat_num). |
| 2221 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
| 2222 | Return -1 if stopped at a breakpoint that has been deleted since |
| 2223 | we set it. |
| 2224 | Return 1 otherwise. */ |
| 2225 | |
| 2226 | int |
| 2227 | bpstat_num (bpstat *bsp, int *num) |
| 2228 | { |
| 2229 | struct breakpoint *b; |
| 2230 | |
| 2231 | if ((*bsp) == NULL) |
| 2232 | return 0; /* No more breakpoint values */ |
| 2233 | |
| 2234 | /* We assume we'll never have several bpstats that |
| 2235 | correspond to a single breakpoint -- otherwise, |
| 2236 | this function might return the same number more |
| 2237 | than once and this will look ugly. */ |
| 2238 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; |
| 2239 | *bsp = (*bsp)->next; |
| 2240 | if (b == NULL) |
| 2241 | return -1; /* breakpoint that's been deleted since */ |
| 2242 | |
| 2243 | *num = b->number; /* We have its number */ |
| 2244 | return 1; |
| 2245 | } |
| 2246 | |
| 2247 | /* Modify BS so that the actions will not be performed. */ |
| 2248 | |
| 2249 | void |
| 2250 | bpstat_clear_actions (bpstat bs) |
| 2251 | { |
| 2252 | for (; bs != NULL; bs = bs->next) |
| 2253 | { |
| 2254 | free_command_lines (&bs->commands); |
| 2255 | if (bs->old_val != NULL) |
| 2256 | { |
| 2257 | value_free (bs->old_val); |
| 2258 | bs->old_val = NULL; |
| 2259 | } |
| 2260 | } |
| 2261 | } |
| 2262 | |
| 2263 | /* Called when a command is about to proceed the inferior. */ |
| 2264 | |
| 2265 | static void |
| 2266 | breakpoint_about_to_proceed (void) |
| 2267 | { |
| 2268 | if (!ptid_equal (inferior_ptid, null_ptid)) |
| 2269 | { |
| 2270 | struct thread_info *tp = inferior_thread (); |
| 2271 | |
| 2272 | /* Allow inferior function calls in breakpoint commands to not |
| 2273 | interrupt the command list. When the call finishes |
| 2274 | successfully, the inferior will be standing at the same |
| 2275 | breakpoint as if nothing happened. */ |
| 2276 | if (tp->in_infcall) |
| 2277 | return; |
| 2278 | } |
| 2279 | |
| 2280 | breakpoint_proceeded = 1; |
| 2281 | } |
| 2282 | |
| 2283 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
| 2284 | static void |
| 2285 | cleanup_executing_breakpoints (void *ignore) |
| 2286 | { |
| 2287 | executing_breakpoint_commands = 0; |
| 2288 | } |
| 2289 | |
| 2290 | /* Execute all the commands associated with all the breakpoints at this |
| 2291 | location. Any of these commands could cause the process to proceed |
| 2292 | beyond this point, etc. We look out for such changes by checking |
| 2293 | the global "breakpoint_proceeded" after each command. |
| 2294 | |
| 2295 | Returns true if a breakpoint command resumed the inferior. In that |
| 2296 | case, it is the caller's responsibility to recall it again with the |
| 2297 | bpstat of the current thread. */ |
| 2298 | |
| 2299 | static int |
| 2300 | bpstat_do_actions_1 (bpstat *bsp) |
| 2301 | { |
| 2302 | bpstat bs; |
| 2303 | struct cleanup *old_chain; |
| 2304 | int again = 0; |
| 2305 | |
| 2306 | /* Avoid endless recursion if a `source' command is contained |
| 2307 | in bs->commands. */ |
| 2308 | if (executing_breakpoint_commands) |
| 2309 | return 0; |
| 2310 | |
| 2311 | executing_breakpoint_commands = 1; |
| 2312 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); |
| 2313 | |
| 2314 | /* This pointer will iterate over the list of bpstat's. */ |
| 2315 | bs = *bsp; |
| 2316 | |
| 2317 | breakpoint_proceeded = 0; |
| 2318 | for (; bs != NULL; bs = bs->next) |
| 2319 | { |
| 2320 | struct command_line *cmd; |
| 2321 | struct cleanup *this_cmd_tree_chain; |
| 2322 | |
| 2323 | /* Take ownership of the BSP's command tree, if it has one. |
| 2324 | |
| 2325 | The command tree could legitimately contain commands like |
| 2326 | 'step' and 'next', which call clear_proceed_status, which |
| 2327 | frees stop_bpstat's command tree. To make sure this doesn't |
| 2328 | free the tree we're executing out from under us, we need to |
| 2329 | take ownership of the tree ourselves. Since a given bpstat's |
| 2330 | commands are only executed once, we don't need to copy it; we |
| 2331 | can clear the pointer in the bpstat, and make sure we free |
| 2332 | the tree when we're done. */ |
| 2333 | cmd = bs->commands; |
| 2334 | bs->commands = 0; |
| 2335 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); |
| 2336 | |
| 2337 | while (cmd != NULL) |
| 2338 | { |
| 2339 | execute_control_command (cmd); |
| 2340 | |
| 2341 | if (breakpoint_proceeded) |
| 2342 | break; |
| 2343 | else |
| 2344 | cmd = cmd->next; |
| 2345 | } |
| 2346 | |
| 2347 | /* We can free this command tree now. */ |
| 2348 | do_cleanups (this_cmd_tree_chain); |
| 2349 | |
| 2350 | if (breakpoint_proceeded) |
| 2351 | { |
| 2352 | if (target_can_async_p ()) |
| 2353 | /* If we are in async mode, then the target might be still |
| 2354 | running, not stopped at any breakpoint, so nothing for |
| 2355 | us to do here -- just return to the event loop. */ |
| 2356 | ; |
| 2357 | else |
| 2358 | /* In sync mode, when execute_control_command returns |
| 2359 | we're already standing on the next breakpoint. |
| 2360 | Breakpoint commands for that stop were not run, since |
| 2361 | execute_command does not run breakpoint commands -- |
| 2362 | only command_line_handler does, but that one is not |
| 2363 | involved in execution of breakpoint commands. So, we |
| 2364 | can now execute breakpoint commands. It should be |
| 2365 | noted that making execute_command do bpstat actions is |
| 2366 | not an option -- in this case we'll have recursive |
| 2367 | invocation of bpstat for each breakpoint with a |
| 2368 | command, and can easily blow up GDB stack. Instead, we |
| 2369 | return true, which will trigger the caller to recall us |
| 2370 | with the new stop_bpstat. */ |
| 2371 | again = 1; |
| 2372 | break; |
| 2373 | } |
| 2374 | } |
| 2375 | do_cleanups (old_chain); |
| 2376 | return again; |
| 2377 | } |
| 2378 | |
| 2379 | void |
| 2380 | bpstat_do_actions (void) |
| 2381 | { |
| 2382 | /* Do any commands attached to breakpoint we are stopped at. */ |
| 2383 | while (!ptid_equal (inferior_ptid, null_ptid) |
| 2384 | && target_has_execution |
| 2385 | && !is_exited (inferior_ptid) |
| 2386 | && !is_executing (inferior_ptid)) |
| 2387 | /* Since in sync mode, bpstat_do_actions may resume the inferior, |
| 2388 | and only return when it is stopped at the next breakpoint, we |
| 2389 | keep doing breakpoint actions until it returns false to |
| 2390 | indicate the inferior was not resumed. */ |
| 2391 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) |
| 2392 | break; |
| 2393 | } |
| 2394 | |
| 2395 | /* Print out the (old or new) value associated with a watchpoint. */ |
| 2396 | |
| 2397 | static void |
| 2398 | watchpoint_value_print (struct value *val, struct ui_file *stream) |
| 2399 | { |
| 2400 | if (val == NULL) |
| 2401 | fprintf_unfiltered (stream, _("<unreadable>")); |
| 2402 | else |
| 2403 | { |
| 2404 | struct value_print_options opts; |
| 2405 | get_user_print_options (&opts); |
| 2406 | value_print (val, stream, &opts); |
| 2407 | } |
| 2408 | } |
| 2409 | |
| 2410 | /* This is the normal print function for a bpstat. In the future, |
| 2411 | much of this logic could (should?) be moved to bpstat_stop_status, |
| 2412 | by having it set different print_it values. |
| 2413 | |
| 2414 | Current scheme: When we stop, bpstat_print() is called. It loops |
| 2415 | through the bpstat list of things causing this stop, calling the |
| 2416 | print_bp_stop_message function on each one. The behavior of the |
| 2417 | print_bp_stop_message function depends on the print_it field of |
| 2418 | bpstat. If such field so indicates, call this function here. |
| 2419 | |
| 2420 | Return values from this routine (ultimately used by bpstat_print() |
| 2421 | and normal_stop() to decide what to do): |
| 2422 | PRINT_NOTHING: Means we already printed all we needed to print, |
| 2423 | don't print anything else. |
| 2424 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire |
| 2425 | that something to be followed by a location. |
| 2426 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire |
| 2427 | that something to be followed by a location. |
| 2428 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more |
| 2429 | analysis. */ |
| 2430 | |
| 2431 | static enum print_stop_action |
| 2432 | print_it_typical (bpstat bs) |
| 2433 | { |
| 2434 | struct cleanup *old_chain; |
| 2435 | struct breakpoint *b; |
| 2436 | const struct bp_location *bl; |
| 2437 | struct ui_stream *stb; |
| 2438 | int bp_temp = 0; |
| 2439 | enum print_stop_action result; |
| 2440 | |
| 2441 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
| 2442 | which has since been deleted. */ |
| 2443 | if (bs->breakpoint_at == NULL) |
| 2444 | return PRINT_UNKNOWN; |
| 2445 | bl = bs->breakpoint_at; |
| 2446 | b = bl->owner; |
| 2447 | |
| 2448 | stb = ui_out_stream_new (uiout); |
| 2449 | old_chain = make_cleanup_ui_out_stream_delete (stb); |
| 2450 | |
| 2451 | switch (b->type) |
| 2452 | { |
| 2453 | case bp_breakpoint: |
| 2454 | case bp_hardware_breakpoint: |
| 2455 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
| 2456 | if (bl->address != bl->requested_address) |
| 2457 | breakpoint_adjustment_warning (bl->requested_address, |
| 2458 | bl->address, |
| 2459 | b->number, 1); |
| 2460 | annotate_breakpoint (b->number); |
| 2461 | if (bp_temp) |
| 2462 | ui_out_text (uiout, "\nTemporary breakpoint "); |
| 2463 | else |
| 2464 | ui_out_text (uiout, "\nBreakpoint "); |
| 2465 | if (ui_out_is_mi_like_p (uiout)) |
| 2466 | { |
| 2467 | ui_out_field_string (uiout, "reason", |
| 2468 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 2469 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 2470 | } |
| 2471 | ui_out_field_int (uiout, "bkptno", b->number); |
| 2472 | ui_out_text (uiout, ", "); |
| 2473 | result = PRINT_SRC_AND_LOC; |
| 2474 | break; |
| 2475 | |
| 2476 | case bp_shlib_event: |
| 2477 | /* Did we stop because the user set the stop_on_solib_events |
| 2478 | variable? (If so, we report this as a generic, "Stopped due |
| 2479 | to shlib event" message.) */ |
| 2480 | printf_filtered (_("Stopped due to shared library event\n")); |
| 2481 | result = PRINT_NOTHING; |
| 2482 | break; |
| 2483 | |
| 2484 | case bp_thread_event: |
| 2485 | /* Not sure how we will get here. |
| 2486 | GDB should not stop for these breakpoints. */ |
| 2487 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
| 2488 | result = PRINT_NOTHING; |
| 2489 | break; |
| 2490 | |
| 2491 | case bp_overlay_event: |
| 2492 | /* By analogy with the thread event, GDB should not stop for these. */ |
| 2493 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
| 2494 | result = PRINT_NOTHING; |
| 2495 | break; |
| 2496 | |
| 2497 | case bp_longjmp_master: |
| 2498 | /* These should never be enabled. */ |
| 2499 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); |
| 2500 | result = PRINT_NOTHING; |
| 2501 | break; |
| 2502 | |
| 2503 | case bp_watchpoint: |
| 2504 | case bp_hardware_watchpoint: |
| 2505 | annotate_watchpoint (b->number); |
| 2506 | if (ui_out_is_mi_like_p (uiout)) |
| 2507 | ui_out_field_string |
| 2508 | (uiout, "reason", |
| 2509 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 2510 | mention (b); |
| 2511 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 2512 | ui_out_text (uiout, "\nOld value = "); |
| 2513 | watchpoint_value_print (bs->old_val, stb->stream); |
| 2514 | ui_out_field_stream (uiout, "old", stb); |
| 2515 | ui_out_text (uiout, "\nNew value = "); |
| 2516 | watchpoint_value_print (b->val, stb->stream); |
| 2517 | ui_out_field_stream (uiout, "new", stb); |
| 2518 | ui_out_text (uiout, "\n"); |
| 2519 | /* More than one watchpoint may have been triggered. */ |
| 2520 | result = PRINT_UNKNOWN; |
| 2521 | break; |
| 2522 | |
| 2523 | case bp_read_watchpoint: |
| 2524 | if (ui_out_is_mi_like_p (uiout)) |
| 2525 | ui_out_field_string |
| 2526 | (uiout, "reason", |
| 2527 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 2528 | mention (b); |
| 2529 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 2530 | ui_out_text (uiout, "\nValue = "); |
| 2531 | watchpoint_value_print (b->val, stb->stream); |
| 2532 | ui_out_field_stream (uiout, "value", stb); |
| 2533 | ui_out_text (uiout, "\n"); |
| 2534 | result = PRINT_UNKNOWN; |
| 2535 | break; |
| 2536 | |
| 2537 | case bp_access_watchpoint: |
| 2538 | if (bs->old_val != NULL) |
| 2539 | { |
| 2540 | annotate_watchpoint (b->number); |
| 2541 | if (ui_out_is_mi_like_p (uiout)) |
| 2542 | ui_out_field_string |
| 2543 | (uiout, "reason", |
| 2544 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 2545 | mention (b); |
| 2546 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 2547 | ui_out_text (uiout, "\nOld value = "); |
| 2548 | watchpoint_value_print (bs->old_val, stb->stream); |
| 2549 | ui_out_field_stream (uiout, "old", stb); |
| 2550 | ui_out_text (uiout, "\nNew value = "); |
| 2551 | } |
| 2552 | else |
| 2553 | { |
| 2554 | mention (b); |
| 2555 | if (ui_out_is_mi_like_p (uiout)) |
| 2556 | ui_out_field_string |
| 2557 | (uiout, "reason", |
| 2558 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 2559 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 2560 | ui_out_text (uiout, "\nValue = "); |
| 2561 | } |
| 2562 | watchpoint_value_print (b->val, stb->stream); |
| 2563 | ui_out_field_stream (uiout, "new", stb); |
| 2564 | ui_out_text (uiout, "\n"); |
| 2565 | result = PRINT_UNKNOWN; |
| 2566 | break; |
| 2567 | |
| 2568 | /* Fall through, we don't deal with these types of breakpoints |
| 2569 | here. */ |
| 2570 | |
| 2571 | case bp_finish: |
| 2572 | if (ui_out_is_mi_like_p (uiout)) |
| 2573 | ui_out_field_string |
| 2574 | (uiout, "reason", |
| 2575 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); |
| 2576 | result = PRINT_UNKNOWN; |
| 2577 | break; |
| 2578 | |
| 2579 | case bp_until: |
| 2580 | if (ui_out_is_mi_like_p (uiout)) |
| 2581 | ui_out_field_string |
| 2582 | (uiout, "reason", |
| 2583 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); |
| 2584 | result = PRINT_UNKNOWN; |
| 2585 | break; |
| 2586 | |
| 2587 | case bp_none: |
| 2588 | case bp_longjmp: |
| 2589 | case bp_longjmp_resume: |
| 2590 | case bp_step_resume: |
| 2591 | case bp_watchpoint_scope: |
| 2592 | case bp_call_dummy: |
| 2593 | case bp_tracepoint: |
| 2594 | case bp_jit_event: |
| 2595 | default: |
| 2596 | result = PRINT_UNKNOWN; |
| 2597 | break; |
| 2598 | } |
| 2599 | |
| 2600 | do_cleanups (old_chain); |
| 2601 | return result; |
| 2602 | } |
| 2603 | |
| 2604 | /* Generic routine for printing messages indicating why we |
| 2605 | stopped. The behavior of this function depends on the value |
| 2606 | 'print_it' in the bpstat structure. Under some circumstances we |
| 2607 | may decide not to print anything here and delegate the task to |
| 2608 | normal_stop(). */ |
| 2609 | |
| 2610 | static enum print_stop_action |
| 2611 | print_bp_stop_message (bpstat bs) |
| 2612 | { |
| 2613 | switch (bs->print_it) |
| 2614 | { |
| 2615 | case print_it_noop: |
| 2616 | /* Nothing should be printed for this bpstat entry. */ |
| 2617 | return PRINT_UNKNOWN; |
| 2618 | break; |
| 2619 | |
| 2620 | case print_it_done: |
| 2621 | /* We still want to print the frame, but we already printed the |
| 2622 | relevant messages. */ |
| 2623 | return PRINT_SRC_AND_LOC; |
| 2624 | break; |
| 2625 | |
| 2626 | case print_it_normal: |
| 2627 | { |
| 2628 | const struct bp_location *bl = bs->breakpoint_at; |
| 2629 | struct breakpoint *b = bl ? bl->owner : NULL; |
| 2630 | |
| 2631 | /* Normal case. Call the breakpoint's print_it method, or |
| 2632 | print_it_typical. */ |
| 2633 | /* FIXME: how breakpoint can ever be NULL here? */ |
| 2634 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) |
| 2635 | return b->ops->print_it (b); |
| 2636 | else |
| 2637 | return print_it_typical (bs); |
| 2638 | } |
| 2639 | break; |
| 2640 | |
| 2641 | default: |
| 2642 | internal_error (__FILE__, __LINE__, |
| 2643 | _("print_bp_stop_message: unrecognized enum value")); |
| 2644 | break; |
| 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | /* Print a message indicating what happened. This is called from |
| 2649 | normal_stop(). The input to this routine is the head of the bpstat |
| 2650 | list - a list of the eventpoints that caused this stop. This |
| 2651 | routine calls the generic print routine for printing a message |
| 2652 | about reasons for stopping. This will print (for example) the |
| 2653 | "Breakpoint n," part of the output. The return value of this |
| 2654 | routine is one of: |
| 2655 | |
| 2656 | PRINT_UNKNOWN: Means we printed nothing |
| 2657 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
| 2658 | code to print the location. An example is |
| 2659 | "Breakpoint 1, " which should be followed by |
| 2660 | the location. |
| 2661 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
| 2662 | to also print the location part of the message. |
| 2663 | An example is the catch/throw messages, which |
| 2664 | don't require a location appended to the end. |
| 2665 | PRINT_NOTHING: We have done some printing and we don't need any |
| 2666 | further info to be printed.*/ |
| 2667 | |
| 2668 | enum print_stop_action |
| 2669 | bpstat_print (bpstat bs) |
| 2670 | { |
| 2671 | int val; |
| 2672 | |
| 2673 | /* Maybe another breakpoint in the chain caused us to stop. |
| 2674 | (Currently all watchpoints go on the bpstat whether hit or not. |
| 2675 | That probably could (should) be changed, provided care is taken |
| 2676 | with respect to bpstat_explains_signal). */ |
| 2677 | for (; bs; bs = bs->next) |
| 2678 | { |
| 2679 | val = print_bp_stop_message (bs); |
| 2680 | if (val == PRINT_SRC_ONLY |
| 2681 | || val == PRINT_SRC_AND_LOC |
| 2682 | || val == PRINT_NOTHING) |
| 2683 | return val; |
| 2684 | } |
| 2685 | |
| 2686 | /* We reached the end of the chain, or we got a null BS to start |
| 2687 | with and nothing was printed. */ |
| 2688 | return PRINT_UNKNOWN; |
| 2689 | } |
| 2690 | |
| 2691 | /* Evaluate the expression EXP and return 1 if value is zero. |
| 2692 | This is used inside a catch_errors to evaluate the breakpoint condition. |
| 2693 | The argument is a "struct expression *" that has been cast to char * to |
| 2694 | make it pass through catch_errors. */ |
| 2695 | |
| 2696 | static int |
| 2697 | breakpoint_cond_eval (void *exp) |
| 2698 | { |
| 2699 | struct value *mark = value_mark (); |
| 2700 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
| 2701 | value_free_to_mark (mark); |
| 2702 | return i; |
| 2703 | } |
| 2704 | |
| 2705 | /* Allocate a new bpstat and chain it to the current one. */ |
| 2706 | |
| 2707 | static bpstat |
| 2708 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
| 2709 | { |
| 2710 | bpstat bs; |
| 2711 | |
| 2712 | bs = (bpstat) xmalloc (sizeof (*bs)); |
| 2713 | cbs->next = bs; |
| 2714 | bs->breakpoint_at = bl; |
| 2715 | /* If the condition is false, etc., don't do the commands. */ |
| 2716 | bs->commands = NULL; |
| 2717 | bs->old_val = NULL; |
| 2718 | bs->print_it = print_it_normal; |
| 2719 | return bs; |
| 2720 | } |
| 2721 | \f |
| 2722 | /* The target has stopped with waitstatus WS. Check if any hardware |
| 2723 | watchpoints have triggered, according to the target. */ |
| 2724 | |
| 2725 | int |
| 2726 | watchpoints_triggered (struct target_waitstatus *ws) |
| 2727 | { |
| 2728 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
| 2729 | CORE_ADDR addr; |
| 2730 | struct breakpoint *b; |
| 2731 | |
| 2732 | if (!stopped_by_watchpoint) |
| 2733 | { |
| 2734 | /* We were not stopped by a watchpoint. Mark all watchpoints |
| 2735 | as not triggered. */ |
| 2736 | ALL_BREAKPOINTS (b) |
| 2737 | if (b->type == bp_hardware_watchpoint |
| 2738 | || b->type == bp_read_watchpoint |
| 2739 | || b->type == bp_access_watchpoint) |
| 2740 | b->watchpoint_triggered = watch_triggered_no; |
| 2741 | |
| 2742 | return 0; |
| 2743 | } |
| 2744 | |
| 2745 | if (!target_stopped_data_address (¤t_target, &addr)) |
| 2746 | { |
| 2747 | /* We were stopped by a watchpoint, but we don't know where. |
| 2748 | Mark all watchpoints as unknown. */ |
| 2749 | ALL_BREAKPOINTS (b) |
| 2750 | if (b->type == bp_hardware_watchpoint |
| 2751 | || b->type == bp_read_watchpoint |
| 2752 | || b->type == bp_access_watchpoint) |
| 2753 | b->watchpoint_triggered = watch_triggered_unknown; |
| 2754 | |
| 2755 | return stopped_by_watchpoint; |
| 2756 | } |
| 2757 | |
| 2758 | /* The target could report the data address. Mark watchpoints |
| 2759 | affected by this data address as triggered, and all others as not |
| 2760 | triggered. */ |
| 2761 | |
| 2762 | ALL_BREAKPOINTS (b) |
| 2763 | if (b->type == bp_hardware_watchpoint |
| 2764 | || b->type == bp_read_watchpoint |
| 2765 | || b->type == bp_access_watchpoint) |
| 2766 | { |
| 2767 | struct bp_location *loc; |
| 2768 | struct value *v; |
| 2769 | |
| 2770 | b->watchpoint_triggered = watch_triggered_no; |
| 2771 | for (loc = b->loc; loc; loc = loc->next) |
| 2772 | /* Exact match not required. Within range is |
| 2773 | sufficient. */ |
| 2774 | if (target_watchpoint_addr_within_range (¤t_target, |
| 2775 | addr, loc->address, |
| 2776 | loc->length)) |
| 2777 | { |
| 2778 | b->watchpoint_triggered = watch_triggered_yes; |
| 2779 | break; |
| 2780 | } |
| 2781 | } |
| 2782 | |
| 2783 | return 1; |
| 2784 | } |
| 2785 | |
| 2786 | /* Possible return values for watchpoint_check (this can't be an enum |
| 2787 | because of check_errors). */ |
| 2788 | /* The watchpoint has been deleted. */ |
| 2789 | #define WP_DELETED 1 |
| 2790 | /* The value has changed. */ |
| 2791 | #define WP_VALUE_CHANGED 2 |
| 2792 | /* The value has not changed. */ |
| 2793 | #define WP_VALUE_NOT_CHANGED 3 |
| 2794 | |
| 2795 | #define BP_TEMPFLAG 1 |
| 2796 | #define BP_HARDWAREFLAG 2 |
| 2797 | |
| 2798 | /* Check watchpoint condition. */ |
| 2799 | |
| 2800 | static int |
| 2801 | watchpoint_check (void *p) |
| 2802 | { |
| 2803 | bpstat bs = (bpstat) p; |
| 2804 | struct breakpoint *b; |
| 2805 | struct frame_info *fr; |
| 2806 | int within_current_scope; |
| 2807 | |
| 2808 | b = bs->breakpoint_at->owner; |
| 2809 | |
| 2810 | if (b->exp_valid_block == NULL) |
| 2811 | within_current_scope = 1; |
| 2812 | else |
| 2813 | { |
| 2814 | struct frame_info *frame = get_current_frame (); |
| 2815 | struct gdbarch *frame_arch = get_frame_arch (frame); |
| 2816 | CORE_ADDR frame_pc = get_frame_pc (frame); |
| 2817 | |
| 2818 | fr = frame_find_by_id (b->watchpoint_frame); |
| 2819 | within_current_scope = (fr != NULL); |
| 2820 | |
| 2821 | /* If we've gotten confused in the unwinder, we might have |
| 2822 | returned a frame that can't describe this variable. */ |
| 2823 | if (within_current_scope) |
| 2824 | { |
| 2825 | struct symbol *function; |
| 2826 | |
| 2827 | function = get_frame_function (fr); |
| 2828 | if (function == NULL |
| 2829 | || !contained_in (b->exp_valid_block, |
| 2830 | SYMBOL_BLOCK_VALUE (function))) |
| 2831 | within_current_scope = 0; |
| 2832 | } |
| 2833 | |
| 2834 | /* in_function_epilogue_p() returns a non-zero value if we're still |
| 2835 | in the function but the stack frame has already been invalidated. |
| 2836 | Since we can't rely on the values of local variables after the |
| 2837 | stack has been destroyed, we are treating the watchpoint in that |
| 2838 | state as `not changed' without further checking. Don't mark |
| 2839 | watchpoints as changed if the current frame is in an epilogue - |
| 2840 | even if they are in some other frame, our view of the stack |
| 2841 | is likely to be wrong. */ |
| 2842 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
| 2843 | return WP_VALUE_NOT_CHANGED; |
| 2844 | |
| 2845 | if (within_current_scope) |
| 2846 | /* If we end up stopping, the current frame will get selected |
| 2847 | in normal_stop. So this call to select_frame won't affect |
| 2848 | the user. */ |
| 2849 | select_frame (fr); |
| 2850 | } |
| 2851 | |
| 2852 | if (within_current_scope) |
| 2853 | { |
| 2854 | /* We use value_{,free_to_}mark because it could be a |
| 2855 | *long* time before we return to the command level and |
| 2856 | call free_all_values. We can't call free_all_values because |
| 2857 | we might be in the middle of evaluating a function call. */ |
| 2858 | |
| 2859 | struct value *mark = value_mark (); |
| 2860 | struct value *new_val; |
| 2861 | |
| 2862 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); |
| 2863 | if ((b->val != NULL) != (new_val != NULL) |
| 2864 | || (b->val != NULL && !value_equal (b->val, new_val))) |
| 2865 | { |
| 2866 | if (new_val != NULL) |
| 2867 | { |
| 2868 | release_value (new_val); |
| 2869 | value_free_to_mark (mark); |
| 2870 | } |
| 2871 | bs->old_val = b->val; |
| 2872 | b->val = new_val; |
| 2873 | b->val_valid = 1; |
| 2874 | /* We will stop here */ |
| 2875 | return WP_VALUE_CHANGED; |
| 2876 | } |
| 2877 | else |
| 2878 | { |
| 2879 | /* Nothing changed, don't do anything. */ |
| 2880 | value_free_to_mark (mark); |
| 2881 | /* We won't stop here */ |
| 2882 | return WP_VALUE_NOT_CHANGED; |
| 2883 | } |
| 2884 | } |
| 2885 | else |
| 2886 | { |
| 2887 | /* This seems like the only logical thing to do because |
| 2888 | if we temporarily ignored the watchpoint, then when |
| 2889 | we reenter the block in which it is valid it contains |
| 2890 | garbage (in the case of a function, it may have two |
| 2891 | garbage values, one before and one after the prologue). |
| 2892 | So we can't even detect the first assignment to it and |
| 2893 | watch after that (since the garbage may or may not equal |
| 2894 | the first value assigned). */ |
| 2895 | /* We print all the stop information in print_it_typical(), but |
| 2896 | in this case, by the time we call print_it_typical() this bp |
| 2897 | will be deleted already. So we have no choice but print the |
| 2898 | information here. */ |
| 2899 | if (ui_out_is_mi_like_p (uiout)) |
| 2900 | ui_out_field_string |
| 2901 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); |
| 2902 | ui_out_text (uiout, "\nWatchpoint "); |
| 2903 | ui_out_field_int (uiout, "wpnum", b->number); |
| 2904 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
| 2905 | which its expression is valid.\n"); |
| 2906 | |
| 2907 | if (b->related_breakpoint) |
| 2908 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
| 2909 | b->disposition = disp_del_at_next_stop; |
| 2910 | |
| 2911 | return WP_DELETED; |
| 2912 | } |
| 2913 | } |
| 2914 | |
| 2915 | /* Return true if it looks like target has stopped due to hitting |
| 2916 | breakpoint location BL. This function does not check if we |
| 2917 | should stop, only if BL explains the stop. */ |
| 2918 | static int |
| 2919 | bpstat_check_location (const struct bp_location *bl, CORE_ADDR bp_addr) |
| 2920 | { |
| 2921 | struct breakpoint *b = bl->owner; |
| 2922 | |
| 2923 | if (b->type != bp_watchpoint |
| 2924 | && b->type != bp_hardware_watchpoint |
| 2925 | && b->type != bp_read_watchpoint |
| 2926 | && b->type != bp_access_watchpoint |
| 2927 | && b->type != bp_hardware_breakpoint |
| 2928 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
| 2929 | { |
| 2930 | if (bl->address != bp_addr) /* address doesn't match */ |
| 2931 | return 0; |
| 2932 | if (overlay_debugging /* unmapped overlay section */ |
| 2933 | && section_is_overlay (bl->section) |
| 2934 | && !section_is_mapped (bl->section)) |
| 2935 | return 0; |
| 2936 | } |
| 2937 | |
| 2938 | /* Continuable hardware watchpoints are treated as non-existent if the |
| 2939 | reason we stopped wasn't a hardware watchpoint (we didn't stop on |
| 2940 | some data address). Otherwise gdb won't stop on a break instruction |
| 2941 | in the code (not from a breakpoint) when a hardware watchpoint has |
| 2942 | been defined. Also skip watchpoints which we know did not trigger |
| 2943 | (did not match the data address). */ |
| 2944 | |
| 2945 | if ((b->type == bp_hardware_watchpoint |
| 2946 | || b->type == bp_read_watchpoint |
| 2947 | || b->type == bp_access_watchpoint) |
| 2948 | && b->watchpoint_triggered == watch_triggered_no) |
| 2949 | return 0; |
| 2950 | |
| 2951 | if (b->type == bp_hardware_breakpoint) |
| 2952 | { |
| 2953 | if (bl->address != bp_addr) |
| 2954 | return 0; |
| 2955 | if (overlay_debugging /* unmapped overlay section */ |
| 2956 | && section_is_overlay (bl->section) |
| 2957 | && !section_is_mapped (bl->section)) |
| 2958 | return 0; |
| 2959 | } |
| 2960 | |
| 2961 | if (b->type == bp_catchpoint) |
| 2962 | { |
| 2963 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); |
| 2964 | if (!b->ops->breakpoint_hit (b)) |
| 2965 | return 0; |
| 2966 | } |
| 2967 | |
| 2968 | return 1; |
| 2969 | } |
| 2970 | |
| 2971 | /* If BS refers to a watchpoint, determine if the watched values |
| 2972 | has actually changed, and we should stop. If not, set BS->stop |
| 2973 | to 0. */ |
| 2974 | static void |
| 2975 | bpstat_check_watchpoint (bpstat bs) |
| 2976 | { |
| 2977 | const struct bp_location *bl = bs->breakpoint_at; |
| 2978 | struct breakpoint *b = bl->owner; |
| 2979 | |
| 2980 | if (b->type == bp_watchpoint |
| 2981 | || b->type == bp_read_watchpoint |
| 2982 | || b->type == bp_access_watchpoint |
| 2983 | || b->type == bp_hardware_watchpoint) |
| 2984 | { |
| 2985 | CORE_ADDR addr; |
| 2986 | struct value *v; |
| 2987 | int must_check_value = 0; |
| 2988 | |
| 2989 | if (b->type == bp_watchpoint) |
| 2990 | /* For a software watchpoint, we must always check the |
| 2991 | watched value. */ |
| 2992 | must_check_value = 1; |
| 2993 | else if (b->watchpoint_triggered == watch_triggered_yes) |
| 2994 | /* We have a hardware watchpoint (read, write, or access) |
| 2995 | and the target earlier reported an address watched by |
| 2996 | this watchpoint. */ |
| 2997 | must_check_value = 1; |
| 2998 | else if (b->watchpoint_triggered == watch_triggered_unknown |
| 2999 | && b->type == bp_hardware_watchpoint) |
| 3000 | /* We were stopped by a hardware watchpoint, but the target could |
| 3001 | not report the data address. We must check the watchpoint's |
| 3002 | value. Access and read watchpoints are out of luck; without |
| 3003 | a data address, we can't figure it out. */ |
| 3004 | must_check_value = 1; |
| 3005 | |
| 3006 | if (must_check_value) |
| 3007 | { |
| 3008 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", |
| 3009 | b->number); |
| 3010 | struct cleanup *cleanups = make_cleanup (xfree, message); |
| 3011 | int e = catch_errors (watchpoint_check, bs, message, |
| 3012 | RETURN_MASK_ALL); |
| 3013 | do_cleanups (cleanups); |
| 3014 | switch (e) |
| 3015 | { |
| 3016 | case WP_DELETED: |
| 3017 | /* We've already printed what needs to be printed. */ |
| 3018 | bs->print_it = print_it_done; |
| 3019 | /* Stop. */ |
| 3020 | break; |
| 3021 | case WP_VALUE_CHANGED: |
| 3022 | if (b->type == bp_read_watchpoint) |
| 3023 | { |
| 3024 | /* Don't stop: read watchpoints shouldn't fire if |
| 3025 | the value has changed. This is for targets |
| 3026 | which cannot set read-only watchpoints. */ |
| 3027 | bs->print_it = print_it_noop; |
| 3028 | bs->stop = 0; |
| 3029 | } |
| 3030 | break; |
| 3031 | case WP_VALUE_NOT_CHANGED: |
| 3032 | if (b->type == bp_hardware_watchpoint |
| 3033 | || b->type == bp_watchpoint) |
| 3034 | { |
| 3035 | /* Don't stop: write watchpoints shouldn't fire if |
| 3036 | the value hasn't changed. */ |
| 3037 | bs->print_it = print_it_noop; |
| 3038 | bs->stop = 0; |
| 3039 | } |
| 3040 | /* Stop. */ |
| 3041 | break; |
| 3042 | default: |
| 3043 | /* Can't happen. */ |
| 3044 | case 0: |
| 3045 | /* Error from catch_errors. */ |
| 3046 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); |
| 3047 | if (b->related_breakpoint) |
| 3048 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
| 3049 | b->disposition = disp_del_at_next_stop; |
| 3050 | /* We've already printed what needs to be printed. */ |
| 3051 | bs->print_it = print_it_done; |
| 3052 | break; |
| 3053 | } |
| 3054 | } |
| 3055 | else /* must_check_value == 0 */ |
| 3056 | { |
| 3057 | /* This is a case where some watchpoint(s) triggered, but |
| 3058 | not at the address of this watchpoint, or else no |
| 3059 | watchpoint triggered after all. So don't print |
| 3060 | anything for this watchpoint. */ |
| 3061 | bs->print_it = print_it_noop; |
| 3062 | bs->stop = 0; |
| 3063 | } |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | |
| 3068 | /* Check conditions (condition proper, frame, thread and ignore count) |
| 3069 | of breakpoint referred to by BS. If we should not stop for this |
| 3070 | breakpoint, set BS->stop to 0. */ |
| 3071 | static void |
| 3072 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) |
| 3073 | { |
| 3074 | int thread_id = pid_to_thread_id (ptid); |
| 3075 | const struct bp_location *bl = bs->breakpoint_at; |
| 3076 | struct breakpoint *b = bl->owner; |
| 3077 | |
| 3078 | if (frame_id_p (b->frame_id) |
| 3079 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
| 3080 | bs->stop = 0; |
| 3081 | else if (bs->stop) |
| 3082 | { |
| 3083 | int value_is_zero = 0; |
| 3084 | |
| 3085 | /* If this is a scope breakpoint, mark the associated |
| 3086 | watchpoint as triggered so that we will handle the |
| 3087 | out-of-scope event. We'll get to the watchpoint next |
| 3088 | iteration. */ |
| 3089 | if (b->type == bp_watchpoint_scope) |
| 3090 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; |
| 3091 | |
| 3092 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) |
| 3093 | { |
| 3094 | /* We use value_mark and value_free_to_mark because it could |
| 3095 | be a long time before we return to the command level and |
| 3096 | call free_all_values. We can't call free_all_values |
| 3097 | because we might be in the middle of evaluating a |
| 3098 | function call. */ |
| 3099 | struct value *mark = value_mark (); |
| 3100 | |
| 3101 | /* Need to select the frame, with all that implies so that |
| 3102 | the conditions will have the right context. Because we |
| 3103 | use the frame, we will not see an inlined function's |
| 3104 | variables when we arrive at a breakpoint at the start |
| 3105 | of the inlined function; the current frame will be the |
| 3106 | call site. */ |
| 3107 | select_frame (get_current_frame ()); |
| 3108 | value_is_zero |
| 3109 | = catch_errors (breakpoint_cond_eval, (bl->cond), |
| 3110 | "Error in testing breakpoint condition:\n", |
| 3111 | RETURN_MASK_ALL); |
| 3112 | /* FIXME-someday, should give breakpoint # */ |
| 3113 | value_free_to_mark (mark); |
| 3114 | } |
| 3115 | if (bl->cond && value_is_zero) |
| 3116 | { |
| 3117 | bs->stop = 0; |
| 3118 | } |
| 3119 | else if (b->thread != -1 && b->thread != thread_id) |
| 3120 | { |
| 3121 | bs->stop = 0; |
| 3122 | } |
| 3123 | else if (b->ignore_count > 0) |
| 3124 | { |
| 3125 | b->ignore_count--; |
| 3126 | annotate_ignore_count_change (); |
| 3127 | bs->stop = 0; |
| 3128 | /* Increase the hit count even though we don't |
| 3129 | stop. */ |
| 3130 | ++(b->hit_count); |
| 3131 | } |
| 3132 | } |
| 3133 | } |
| 3134 | |
| 3135 | |
| 3136 | /* Get a bpstat associated with having just stopped at address |
| 3137 | BP_ADDR in thread PTID. |
| 3138 | |
| 3139 | Determine whether we stopped at a breakpoint, etc, or whether we |
| 3140 | don't understand this stop. Result is a chain of bpstat's such that: |
| 3141 | |
| 3142 | if we don't understand the stop, the result is a null pointer. |
| 3143 | |
| 3144 | if we understand why we stopped, the result is not null. |
| 3145 | |
| 3146 | Each element of the chain refers to a particular breakpoint or |
| 3147 | watchpoint at which we have stopped. (We may have stopped for |
| 3148 | several reasons concurrently.) |
| 3149 | |
| 3150 | Each element of the chain has valid next, breakpoint_at, |
| 3151 | commands, FIXME??? fields. */ |
| 3152 | |
| 3153 | bpstat |
| 3154 | bpstat_stop_status (CORE_ADDR bp_addr, ptid_t ptid) |
| 3155 | { |
| 3156 | struct breakpoint *b = NULL; |
| 3157 | const struct bp_location *bl; |
| 3158 | struct bp_location *loc; |
| 3159 | /* Root of the chain of bpstat's */ |
| 3160 | struct bpstats root_bs[1]; |
| 3161 | /* Pointer to the last thing in the chain currently. */ |
| 3162 | bpstat bs = root_bs; |
| 3163 | int ix; |
| 3164 | int need_remove_insert; |
| 3165 | |
| 3166 | ALL_BP_LOCATIONS (bl) |
| 3167 | { |
| 3168 | b = bl->owner; |
| 3169 | gdb_assert (b); |
| 3170 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
| 3171 | continue; |
| 3172 | |
| 3173 | /* For hardware watchpoints, we look only at the first location. |
| 3174 | The watchpoint_check function will work on entire expression, |
| 3175 | not the individual locations. For read watchopints, the |
| 3176 | watchpoints_triggered function have checked all locations |
| 3177 | alrea |
| 3178 | */ |
| 3179 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
| 3180 | continue; |
| 3181 | |
| 3182 | if (!bpstat_check_location (bl, bp_addr)) |
| 3183 | continue; |
| 3184 | |
| 3185 | /* Come here if it's a watchpoint, or if the break address matches */ |
| 3186 | |
| 3187 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
| 3188 | |
| 3189 | /* Assume we stop. Should we find watchpoint that is not actually |
| 3190 | triggered, or if condition of breakpoint is false, we'll reset |
| 3191 | 'stop' to 0. */ |
| 3192 | bs->stop = 1; |
| 3193 | bs->print = 1; |
| 3194 | |
| 3195 | bpstat_check_watchpoint (bs); |
| 3196 | if (!bs->stop) |
| 3197 | continue; |
| 3198 | |
| 3199 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
| 3200 | || b->type == bp_longjmp_master) |
| 3201 | /* We do not stop for these. */ |
| 3202 | bs->stop = 0; |
| 3203 | else |
| 3204 | bpstat_check_breakpoint_conditions (bs, ptid); |
| 3205 | |
| 3206 | if (bs->stop) |
| 3207 | { |
| 3208 | ++(b->hit_count); |
| 3209 | |
| 3210 | /* We will stop here */ |
| 3211 | if (b->disposition == disp_disable) |
| 3212 | { |
| 3213 | if (b->enable_state != bp_permanent) |
| 3214 | b->enable_state = bp_disabled; |
| 3215 | update_global_location_list (0); |
| 3216 | } |
| 3217 | if (b->silent) |
| 3218 | bs->print = 0; |
| 3219 | bs->commands = b->commands; |
| 3220 | if (bs->commands |
| 3221 | && (strcmp ("silent", bs->commands->line) == 0 |
| 3222 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) |
| 3223 | { |
| 3224 | bs->commands = bs->commands->next; |
| 3225 | bs->print = 0; |
| 3226 | } |
| 3227 | bs->commands = copy_command_lines (bs->commands); |
| 3228 | } |
| 3229 | |
| 3230 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
| 3231 | if (bs->stop == 0 || bs->print == 0) |
| 3232 | bs->print_it = print_it_noop; |
| 3233 | } |
| 3234 | |
| 3235 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 3236 | { |
| 3237 | if (loc->address == bp_addr) |
| 3238 | { |
| 3239 | bs = bpstat_alloc (loc, bs); |
| 3240 | /* For hits of moribund locations, we should just proceed. */ |
| 3241 | bs->stop = 0; |
| 3242 | bs->print = 0; |
| 3243 | bs->print_it = print_it_noop; |
| 3244 | } |
| 3245 | } |
| 3246 | |
| 3247 | bs->next = NULL; /* Terminate the chain */ |
| 3248 | bs = root_bs->next; /* Re-grab the head of the chain */ |
| 3249 | |
| 3250 | /* If we aren't stopping, the value of some hardware watchpoint may |
| 3251 | not have changed, but the intermediate memory locations we are |
| 3252 | watching may have. Don't bother if we're stopping; this will get |
| 3253 | done later. */ |
| 3254 | for (bs = root_bs->next; bs != NULL; bs = bs->next) |
| 3255 | if (bs->stop) |
| 3256 | break; |
| 3257 | |
| 3258 | need_remove_insert = 0; |
| 3259 | if (bs == NULL) |
| 3260 | for (bs = root_bs->next; bs != NULL; bs = bs->next) |
| 3261 | if (!bs->stop |
| 3262 | && bs->breakpoint_at->owner |
| 3263 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
| 3264 | || bs->breakpoint_at->owner->type == bp_read_watchpoint |
| 3265 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) |
| 3266 | { |
| 3267 | /* remove/insert can invalidate bs->breakpoint_at, if this |
| 3268 | location is no longer used by the watchpoint. Prevent |
| 3269 | further code from trying to use it. */ |
| 3270 | bs->breakpoint_at = NULL; |
| 3271 | need_remove_insert = 1; |
| 3272 | } |
| 3273 | |
| 3274 | if (need_remove_insert) |
| 3275 | { |
| 3276 | remove_breakpoints (); |
| 3277 | insert_breakpoints (); |
| 3278 | } |
| 3279 | |
| 3280 | return root_bs->next; |
| 3281 | } |
| 3282 | \f |
| 3283 | /* Tell what to do about this bpstat. */ |
| 3284 | struct bpstat_what |
| 3285 | bpstat_what (bpstat bs) |
| 3286 | { |
| 3287 | /* Classify each bpstat as one of the following. */ |
| 3288 | enum class |
| 3289 | { |
| 3290 | /* This bpstat element has no effect on the main_action. */ |
| 3291 | no_effect = 0, |
| 3292 | |
| 3293 | /* There was a watchpoint, stop but don't print. */ |
| 3294 | wp_silent, |
| 3295 | |
| 3296 | /* There was a watchpoint, stop and print. */ |
| 3297 | wp_noisy, |
| 3298 | |
| 3299 | /* There was a breakpoint but we're not stopping. */ |
| 3300 | bp_nostop, |
| 3301 | |
| 3302 | /* There was a breakpoint, stop but don't print. */ |
| 3303 | bp_silent, |
| 3304 | |
| 3305 | /* There was a breakpoint, stop and print. */ |
| 3306 | bp_noisy, |
| 3307 | |
| 3308 | /* We hit the longjmp breakpoint. */ |
| 3309 | long_jump, |
| 3310 | |
| 3311 | /* We hit the longjmp_resume breakpoint. */ |
| 3312 | long_resume, |
| 3313 | |
| 3314 | /* We hit the step_resume breakpoint. */ |
| 3315 | step_resume, |
| 3316 | |
| 3317 | /* We hit the shared library event breakpoint. */ |
| 3318 | shlib_event, |
| 3319 | |
| 3320 | /* We hit the jit event breakpoint. */ |
| 3321 | jit_event, |
| 3322 | |
| 3323 | /* This is just used to count how many enums there are. */ |
| 3324 | class_last |
| 3325 | }; |
| 3326 | |
| 3327 | /* Here is the table which drives this routine. So that we can |
| 3328 | format it pretty, we define some abbreviations for the |
| 3329 | enum bpstat_what codes. */ |
| 3330 | #define kc BPSTAT_WHAT_KEEP_CHECKING |
| 3331 | #define ss BPSTAT_WHAT_STOP_SILENT |
| 3332 | #define sn BPSTAT_WHAT_STOP_NOISY |
| 3333 | #define sgl BPSTAT_WHAT_SINGLE |
| 3334 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME |
| 3335 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME |
| 3336 | #define sr BPSTAT_WHAT_STEP_RESUME |
| 3337 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
| 3338 | #define jit BPSTAT_WHAT_CHECK_JIT |
| 3339 | |
| 3340 | /* "Can't happen." Might want to print an error message. |
| 3341 | abort() is not out of the question, but chances are GDB is just |
| 3342 | a bit confused, not unusable. */ |
| 3343 | #define err BPSTAT_WHAT_STOP_NOISY |
| 3344 | |
| 3345 | /* Given an old action and a class, come up with a new action. */ |
| 3346 | /* One interesting property of this table is that wp_silent is the same |
| 3347 | as bp_silent and wp_noisy is the same as bp_noisy. That is because |
| 3348 | after stopping, the check for whether to step over a breakpoint |
| 3349 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without |
| 3350 | reference to how we stopped. We retain separate wp_silent and |
| 3351 | bp_silent codes in case we want to change that someday. |
| 3352 | |
| 3353 | Another possibly interesting property of this table is that |
| 3354 | there's a partial ordering, priority-like, of the actions. Once |
| 3355 | you've decided that some action is appropriate, you'll never go |
| 3356 | back and decide something of a lower priority is better. The |
| 3357 | ordering is: |
| 3358 | |
| 3359 | kc < jit clr sgl shl slr sn sr ss |
| 3360 | sgl < jit shl slr sn sr ss |
| 3361 | slr < jit err shl sn sr ss |
| 3362 | clr < jit err shl sn sr ss |
| 3363 | ss < jit shl sn sr |
| 3364 | sn < jit shl sr |
| 3365 | jit < shl sr |
| 3366 | shl < sr |
| 3367 | sr < |
| 3368 | |
| 3369 | What I think this means is that we don't need a damned table |
| 3370 | here. If you just put the rows and columns in the right order, |
| 3371 | it'd look awfully regular. We could simply walk the bpstat list |
| 3372 | and choose the highest priority action we find, with a little |
| 3373 | logic to handle the 'err' cases. */ |
| 3374 | |
| 3375 | /* step_resume entries: a step resume breakpoint overrides another |
| 3376 | breakpoint of signal handling (see comment in wait_for_inferior |
| 3377 | at where we set the step_resume breakpoint). */ |
| 3378 | |
| 3379 | static const enum bpstat_what_main_action |
| 3380 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
| 3381 | { |
| 3382 | /* old action */ |
| 3383 | /* kc ss sn sgl slr clr sr shl jit */ |
| 3384 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, |
| 3385 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, |
| 3386 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, |
| 3387 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, |
| 3388 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, |
| 3389 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, |
| 3390 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, |
| 3391 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, |
| 3392 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, |
| 3393 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, |
| 3394 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} |
| 3395 | }; |
| 3396 | |
| 3397 | #undef kc |
| 3398 | #undef ss |
| 3399 | #undef sn |
| 3400 | #undef sgl |
| 3401 | #undef slr |
| 3402 | #undef clr |
| 3403 | #undef err |
| 3404 | #undef sr |
| 3405 | #undef ts |
| 3406 | #undef shl |
| 3407 | #undef jit |
| 3408 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 3409 | struct bpstat_what retval; |
| 3410 | |
| 3411 | retval.call_dummy = 0; |
| 3412 | for (; bs != NULL; bs = bs->next) |
| 3413 | { |
| 3414 | enum class bs_class = no_effect; |
| 3415 | if (bs->breakpoint_at == NULL) |
| 3416 | /* I suspect this can happen if it was a momentary breakpoint |
| 3417 | which has since been deleted. */ |
| 3418 | continue; |
| 3419 | if (bs->breakpoint_at->owner == NULL) |
| 3420 | bs_class = bp_nostop; |
| 3421 | else |
| 3422 | switch (bs->breakpoint_at->owner->type) |
| 3423 | { |
| 3424 | case bp_none: |
| 3425 | continue; |
| 3426 | |
| 3427 | case bp_breakpoint: |
| 3428 | case bp_hardware_breakpoint: |
| 3429 | case bp_until: |
| 3430 | case bp_finish: |
| 3431 | if (bs->stop) |
| 3432 | { |
| 3433 | if (bs->print) |
| 3434 | bs_class = bp_noisy; |
| 3435 | else |
| 3436 | bs_class = bp_silent; |
| 3437 | } |
| 3438 | else |
| 3439 | bs_class = bp_nostop; |
| 3440 | break; |
| 3441 | case bp_watchpoint: |
| 3442 | case bp_hardware_watchpoint: |
| 3443 | case bp_read_watchpoint: |
| 3444 | case bp_access_watchpoint: |
| 3445 | if (bs->stop) |
| 3446 | { |
| 3447 | if (bs->print) |
| 3448 | bs_class = wp_noisy; |
| 3449 | else |
| 3450 | bs_class = wp_silent; |
| 3451 | } |
| 3452 | else |
| 3453 | /* There was a watchpoint, but we're not stopping. |
| 3454 | This requires no further action. */ |
| 3455 | bs_class = no_effect; |
| 3456 | break; |
| 3457 | case bp_longjmp: |
| 3458 | bs_class = long_jump; |
| 3459 | break; |
| 3460 | case bp_longjmp_resume: |
| 3461 | bs_class = long_resume; |
| 3462 | break; |
| 3463 | case bp_step_resume: |
| 3464 | if (bs->stop) |
| 3465 | { |
| 3466 | bs_class = step_resume; |
| 3467 | } |
| 3468 | else |
| 3469 | /* It is for the wrong frame. */ |
| 3470 | bs_class = bp_nostop; |
| 3471 | break; |
| 3472 | case bp_watchpoint_scope: |
| 3473 | bs_class = bp_nostop; |
| 3474 | break; |
| 3475 | case bp_shlib_event: |
| 3476 | bs_class = shlib_event; |
| 3477 | break; |
| 3478 | case bp_jit_event: |
| 3479 | bs_class = jit_event; |
| 3480 | break; |
| 3481 | case bp_thread_event: |
| 3482 | case bp_overlay_event: |
| 3483 | case bp_longjmp_master: |
| 3484 | bs_class = bp_nostop; |
| 3485 | break; |
| 3486 | case bp_catchpoint: |
| 3487 | if (bs->stop) |
| 3488 | { |
| 3489 | if (bs->print) |
| 3490 | bs_class = bp_noisy; |
| 3491 | else |
| 3492 | bs_class = bp_silent; |
| 3493 | } |
| 3494 | else |
| 3495 | /* There was a catchpoint, but we're not stopping. |
| 3496 | This requires no further action. */ |
| 3497 | bs_class = no_effect; |
| 3498 | break; |
| 3499 | case bp_call_dummy: |
| 3500 | /* Make sure the action is stop (silent or noisy), |
| 3501 | so infrun.c pops the dummy frame. */ |
| 3502 | bs_class = bp_silent; |
| 3503 | retval.call_dummy = 1; |
| 3504 | break; |
| 3505 | case bp_tracepoint: |
| 3506 | /* Tracepoint hits should not be reported back to GDB, and |
| 3507 | if one got through somehow, it should have been filtered |
| 3508 | out already. */ |
| 3509 | internal_error (__FILE__, __LINE__, |
| 3510 | _("bpstat_what: bp_tracepoint encountered")); |
| 3511 | break; |
| 3512 | } |
| 3513 | current_action = table[(int) bs_class][(int) current_action]; |
| 3514 | } |
| 3515 | retval.main_action = current_action; |
| 3516 | return retval; |
| 3517 | } |
| 3518 | |
| 3519 | /* Nonzero if we should step constantly (e.g. watchpoints on machines |
| 3520 | without hardware support). This isn't related to a specific bpstat, |
| 3521 | just to things like whether watchpoints are set. */ |
| 3522 | |
| 3523 | int |
| 3524 | bpstat_should_step (void) |
| 3525 | { |
| 3526 | struct breakpoint *b; |
| 3527 | ALL_BREAKPOINTS (b) |
| 3528 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
| 3529 | return 1; |
| 3530 | return 0; |
| 3531 | } |
| 3532 | |
| 3533 | \f |
| 3534 | |
| 3535 | static void print_breakpoint_location (struct breakpoint *b, |
| 3536 | struct bp_location *loc, |
| 3537 | char *wrap_indent, |
| 3538 | struct ui_stream *stb) |
| 3539 | { |
| 3540 | if (b->source_file) |
| 3541 | { |
| 3542 | struct symbol *sym |
| 3543 | = find_pc_sect_function (loc->address, loc->section); |
| 3544 | if (sym) |
| 3545 | { |
| 3546 | ui_out_text (uiout, "in "); |
| 3547 | ui_out_field_string (uiout, "func", |
| 3548 | SYMBOL_PRINT_NAME (sym)); |
| 3549 | ui_out_wrap_hint (uiout, wrap_indent); |
| 3550 | ui_out_text (uiout, " at "); |
| 3551 | } |
| 3552 | ui_out_field_string (uiout, "file", b->source_file); |
| 3553 | ui_out_text (uiout, ":"); |
| 3554 | |
| 3555 | if (ui_out_is_mi_like_p (uiout)) |
| 3556 | { |
| 3557 | struct symtab_and_line sal = find_pc_line (loc->address, 0); |
| 3558 | char *fullname = symtab_to_fullname (sal.symtab); |
| 3559 | |
| 3560 | if (fullname) |
| 3561 | ui_out_field_string (uiout, "fullname", fullname); |
| 3562 | } |
| 3563 | |
| 3564 | ui_out_field_int (uiout, "line", b->line_number); |
| 3565 | } |
| 3566 | else if (!b->loc) |
| 3567 | { |
| 3568 | ui_out_field_string (uiout, "pending", b->addr_string); |
| 3569 | } |
| 3570 | else |
| 3571 | { |
| 3572 | print_address_symbolic (loc->address, stb->stream, demangle, ""); |
| 3573 | ui_out_field_stream (uiout, "at", stb); |
| 3574 | } |
| 3575 | } |
| 3576 | |
| 3577 | /* Print B to gdb_stdout. */ |
| 3578 | static void |
| 3579 | print_one_breakpoint_location (struct breakpoint *b, |
| 3580 | struct bp_location *loc, |
| 3581 | int loc_number, |
| 3582 | struct bp_location **last_loc, |
| 3583 | int print_address_bits) |
| 3584 | { |
| 3585 | struct command_line *l; |
| 3586 | struct symbol *sym; |
| 3587 | struct ep_type_description |
| 3588 | { |
| 3589 | enum bptype type; |
| 3590 | char *description; |
| 3591 | }; |
| 3592 | static struct ep_type_description bptypes[] = |
| 3593 | { |
| 3594 | {bp_none, "?deleted?"}, |
| 3595 | {bp_breakpoint, "breakpoint"}, |
| 3596 | {bp_hardware_breakpoint, "hw breakpoint"}, |
| 3597 | {bp_until, "until"}, |
| 3598 | {bp_finish, "finish"}, |
| 3599 | {bp_watchpoint, "watchpoint"}, |
| 3600 | {bp_hardware_watchpoint, "hw watchpoint"}, |
| 3601 | {bp_read_watchpoint, "read watchpoint"}, |
| 3602 | {bp_access_watchpoint, "acc watchpoint"}, |
| 3603 | {bp_longjmp, "longjmp"}, |
| 3604 | {bp_longjmp_resume, "longjmp resume"}, |
| 3605 | {bp_step_resume, "step resume"}, |
| 3606 | {bp_watchpoint_scope, "watchpoint scope"}, |
| 3607 | {bp_call_dummy, "call dummy"}, |
| 3608 | {bp_shlib_event, "shlib events"}, |
| 3609 | {bp_thread_event, "thread events"}, |
| 3610 | {bp_overlay_event, "overlay events"}, |
| 3611 | {bp_longjmp_master, "longjmp master"}, |
| 3612 | {bp_catchpoint, "catchpoint"}, |
| 3613 | {bp_tracepoint, "tracepoint"}, |
| 3614 | {bp_jit_event, "jit events"}, |
| 3615 | }; |
| 3616 | |
| 3617 | static char bpenables[] = "nynny"; |
| 3618 | char wrap_indent[80]; |
| 3619 | struct ui_stream *stb = ui_out_stream_new (uiout); |
| 3620 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); |
| 3621 | struct cleanup *bkpt_chain; |
| 3622 | |
| 3623 | int header_of_multiple = 0; |
| 3624 | int part_of_multiple = (loc != NULL); |
| 3625 | struct value_print_options opts; |
| 3626 | |
| 3627 | get_user_print_options (&opts); |
| 3628 | |
| 3629 | gdb_assert (!loc || loc_number != 0); |
| 3630 | /* See comment in print_one_breakpoint concerning |
| 3631 | treatment of breakpoints with single disabled |
| 3632 | location. */ |
| 3633 | if (loc == NULL |
| 3634 | && (b->loc != NULL |
| 3635 | && (b->loc->next != NULL || !b->loc->enabled))) |
| 3636 | header_of_multiple = 1; |
| 3637 | if (loc == NULL) |
| 3638 | loc = b->loc; |
| 3639 | |
| 3640 | annotate_record (); |
| 3641 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
| 3642 | |
| 3643 | /* 1 */ |
| 3644 | annotate_field (0); |
| 3645 | if (part_of_multiple) |
| 3646 | { |
| 3647 | char *formatted; |
| 3648 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
| 3649 | ui_out_field_string (uiout, "number", formatted); |
| 3650 | xfree (formatted); |
| 3651 | } |
| 3652 | else |
| 3653 | { |
| 3654 | ui_out_field_int (uiout, "number", b->number); |
| 3655 | } |
| 3656 | |
| 3657 | /* 2 */ |
| 3658 | annotate_field (1); |
| 3659 | if (part_of_multiple) |
| 3660 | ui_out_field_skip (uiout, "type"); |
| 3661 | else |
| 3662 | { |
| 3663 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) |
| 3664 | || ((int) b->type != bptypes[(int) b->type].type)) |
| 3665 | internal_error (__FILE__, __LINE__, |
| 3666 | _("bptypes table does not describe type #%d."), |
| 3667 | (int) b->type); |
| 3668 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); |
| 3669 | } |
| 3670 | |
| 3671 | /* 3 */ |
| 3672 | annotate_field (2); |
| 3673 | if (part_of_multiple) |
| 3674 | ui_out_field_skip (uiout, "disp"); |
| 3675 | else |
| 3676 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 3677 | |
| 3678 | |
| 3679 | /* 4 */ |
| 3680 | annotate_field (3); |
| 3681 | if (part_of_multiple) |
| 3682 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
| 3683 | else |
| 3684 | ui_out_field_fmt (uiout, "enabled", "%c", |
| 3685 | bpenables[(int) b->enable_state]); |
| 3686 | ui_out_spaces (uiout, 2); |
| 3687 | |
| 3688 | |
| 3689 | /* 5 and 6 */ |
| 3690 | strcpy (wrap_indent, " "); |
| 3691 | if (opts.addressprint) |
| 3692 | { |
| 3693 | if (print_address_bits <= 32) |
| 3694 | strcat (wrap_indent, " "); |
| 3695 | else |
| 3696 | strcat (wrap_indent, " "); |
| 3697 | } |
| 3698 | |
| 3699 | if (b->ops != NULL && b->ops->print_one != NULL) |
| 3700 | { |
| 3701 | /* Although the print_one can possibly print |
| 3702 | all locations, calling it here is not likely |
| 3703 | to get any nice result. So, make sure there's |
| 3704 | just one location. */ |
| 3705 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
| 3706 | b->ops->print_one (b, last_loc); |
| 3707 | } |
| 3708 | else |
| 3709 | switch (b->type) |
| 3710 | { |
| 3711 | case bp_none: |
| 3712 | internal_error (__FILE__, __LINE__, |
| 3713 | _("print_one_breakpoint: bp_none encountered\n")); |
| 3714 | break; |
| 3715 | |
| 3716 | case bp_watchpoint: |
| 3717 | case bp_hardware_watchpoint: |
| 3718 | case bp_read_watchpoint: |
| 3719 | case bp_access_watchpoint: |
| 3720 | /* Field 4, the address, is omitted (which makes the columns |
| 3721 | not line up too nicely with the headers, but the effect |
| 3722 | is relatively readable). */ |
| 3723 | if (opts.addressprint) |
| 3724 | ui_out_field_skip (uiout, "addr"); |
| 3725 | annotate_field (5); |
| 3726 | ui_out_field_string (uiout, "what", b->exp_string); |
| 3727 | break; |
| 3728 | |
| 3729 | case bp_breakpoint: |
| 3730 | case bp_hardware_breakpoint: |
| 3731 | case bp_until: |
| 3732 | case bp_finish: |
| 3733 | case bp_longjmp: |
| 3734 | case bp_longjmp_resume: |
| 3735 | case bp_step_resume: |
| 3736 | case bp_watchpoint_scope: |
| 3737 | case bp_call_dummy: |
| 3738 | case bp_shlib_event: |
| 3739 | case bp_thread_event: |
| 3740 | case bp_overlay_event: |
| 3741 | case bp_longjmp_master: |
| 3742 | case bp_tracepoint: |
| 3743 | case bp_jit_event: |
| 3744 | if (opts.addressprint) |
| 3745 | { |
| 3746 | annotate_field (4); |
| 3747 | if (header_of_multiple) |
| 3748 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
| 3749 | else if (b->loc == NULL || loc->shlib_disabled) |
| 3750 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
| 3751 | else |
| 3752 | ui_out_field_core_addr (uiout, "addr", |
| 3753 | loc->gdbarch, loc->address); |
| 3754 | } |
| 3755 | annotate_field (5); |
| 3756 | if (!header_of_multiple) |
| 3757 | print_breakpoint_location (b, loc, wrap_indent, stb); |
| 3758 | if (b->loc) |
| 3759 | *last_loc = b->loc; |
| 3760 | break; |
| 3761 | } |
| 3762 | |
| 3763 | if (!part_of_multiple) |
| 3764 | { |
| 3765 | if (b->thread != -1) |
| 3766 | { |
| 3767 | /* FIXME: This seems to be redundant and lost here; see the |
| 3768 | "stop only in" line a little further down. */ |
| 3769 | ui_out_text (uiout, " thread "); |
| 3770 | ui_out_field_int (uiout, "thread", b->thread); |
| 3771 | } |
| 3772 | else if (b->task != 0) |
| 3773 | { |
| 3774 | ui_out_text (uiout, " task "); |
| 3775 | ui_out_field_int (uiout, "task", b->task); |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | ui_out_text (uiout, "\n"); |
| 3780 | |
| 3781 | if (part_of_multiple && frame_id_p (b->frame_id)) |
| 3782 | { |
| 3783 | annotate_field (6); |
| 3784 | ui_out_text (uiout, "\tstop only in stack frame at "); |
| 3785 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
| 3786 | the frame ID. */ |
| 3787 | ui_out_field_core_addr (uiout, "frame", |
| 3788 | b->gdbarch, b->frame_id.stack_addr); |
| 3789 | ui_out_text (uiout, "\n"); |
| 3790 | } |
| 3791 | |
| 3792 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
| 3793 | { |
| 3794 | /* We do not print the condition for Ada exception catchpoints |
| 3795 | because the condition is an internal implementation detail |
| 3796 | that we do not want to expose to the user. */ |
| 3797 | annotate_field (7); |
| 3798 | if (b->type == bp_tracepoint) |
| 3799 | ui_out_text (uiout, "\ttrace only if "); |
| 3800 | else |
| 3801 | ui_out_text (uiout, "\tstop only if "); |
| 3802 | ui_out_field_string (uiout, "cond", b->cond_string); |
| 3803 | ui_out_text (uiout, "\n"); |
| 3804 | } |
| 3805 | |
| 3806 | if (!part_of_multiple && b->thread != -1) |
| 3807 | { |
| 3808 | /* FIXME should make an annotation for this */ |
| 3809 | ui_out_text (uiout, "\tstop only in thread "); |
| 3810 | ui_out_field_int (uiout, "thread", b->thread); |
| 3811 | ui_out_text (uiout, "\n"); |
| 3812 | } |
| 3813 | |
| 3814 | if (!part_of_multiple && b->hit_count) |
| 3815 | { |
| 3816 | /* FIXME should make an annotation for this */ |
| 3817 | if (ep_is_catchpoint (b)) |
| 3818 | ui_out_text (uiout, "\tcatchpoint"); |
| 3819 | else |
| 3820 | ui_out_text (uiout, "\tbreakpoint"); |
| 3821 | ui_out_text (uiout, " already hit "); |
| 3822 | ui_out_field_int (uiout, "times", b->hit_count); |
| 3823 | if (b->hit_count == 1) |
| 3824 | ui_out_text (uiout, " time\n"); |
| 3825 | else |
| 3826 | ui_out_text (uiout, " times\n"); |
| 3827 | } |
| 3828 | |
| 3829 | /* Output the count also if it is zero, but only if this is |
| 3830 | mi. FIXME: Should have a better test for this. */ |
| 3831 | if (ui_out_is_mi_like_p (uiout)) |
| 3832 | if (!part_of_multiple && b->hit_count == 0) |
| 3833 | ui_out_field_int (uiout, "times", b->hit_count); |
| 3834 | |
| 3835 | if (!part_of_multiple && b->ignore_count) |
| 3836 | { |
| 3837 | annotate_field (8); |
| 3838 | ui_out_text (uiout, "\tignore next "); |
| 3839 | ui_out_field_int (uiout, "ignore", b->ignore_count); |
| 3840 | ui_out_text (uiout, " hits\n"); |
| 3841 | } |
| 3842 | |
| 3843 | l = b->commands; |
| 3844 | if (!part_of_multiple && l) |
| 3845 | { |
| 3846 | struct cleanup *script_chain; |
| 3847 | |
| 3848 | annotate_field (9); |
| 3849 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
| 3850 | print_command_lines (uiout, l, 4); |
| 3851 | do_cleanups (script_chain); |
| 3852 | } |
| 3853 | |
| 3854 | if (!part_of_multiple && b->pass_count) |
| 3855 | { |
| 3856 | annotate_field (10); |
| 3857 | ui_out_text (uiout, "\tpass count "); |
| 3858 | ui_out_field_int (uiout, "pass", b->pass_count); |
| 3859 | ui_out_text (uiout, " \n"); |
| 3860 | } |
| 3861 | |
| 3862 | if (!part_of_multiple && b->step_count) |
| 3863 | { |
| 3864 | annotate_field (11); |
| 3865 | ui_out_text (uiout, "\tstep count "); |
| 3866 | ui_out_field_int (uiout, "step", b->step_count); |
| 3867 | ui_out_text (uiout, " \n"); |
| 3868 | } |
| 3869 | |
| 3870 | if (!part_of_multiple && b->actions) |
| 3871 | { |
| 3872 | struct action_line *action; |
| 3873 | annotate_field (12); |
| 3874 | for (action = b->actions; action; action = action->next) |
| 3875 | { |
| 3876 | ui_out_text (uiout, " A\t"); |
| 3877 | ui_out_text (uiout, action->action); |
| 3878 | ui_out_text (uiout, "\n"); |
| 3879 | } |
| 3880 | } |
| 3881 | |
| 3882 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
| 3883 | { |
| 3884 | if (b->addr_string) |
| 3885 | ui_out_field_string (uiout, "original-location", b->addr_string); |
| 3886 | else if (b->exp_string) |
| 3887 | ui_out_field_string (uiout, "original-location", b->exp_string); |
| 3888 | } |
| 3889 | |
| 3890 | do_cleanups (bkpt_chain); |
| 3891 | do_cleanups (old_chain); |
| 3892 | } |
| 3893 | |
| 3894 | static void |
| 3895 | print_one_breakpoint (struct breakpoint *b, |
| 3896 | struct bp_location **last_loc, int print_address_bits) |
| 3897 | { |
| 3898 | print_one_breakpoint_location (b, NULL, 0, last_loc, print_address_bits); |
| 3899 | |
| 3900 | /* If this breakpoint has custom print function, |
| 3901 | it's already printed. Otherwise, print individual |
| 3902 | locations, if any. */ |
| 3903 | if (b->ops == NULL || b->ops->print_one == NULL) |
| 3904 | { |
| 3905 | /* If breakpoint has a single location that is |
| 3906 | disabled, we print it as if it had |
| 3907 | several locations, since otherwise it's hard to |
| 3908 | represent "breakpoint enabled, location disabled" |
| 3909 | situation. |
| 3910 | Note that while hardware watchpoints have |
| 3911 | several locations internally, that's no a property |
| 3912 | exposed to user. */ |
| 3913 | if (b->loc |
| 3914 | && !is_hardware_watchpoint (b) |
| 3915 | && (b->loc->next || !b->loc->enabled) |
| 3916 | && !ui_out_is_mi_like_p (uiout)) |
| 3917 | { |
| 3918 | struct bp_location *loc; |
| 3919 | int n = 1; |
| 3920 | for (loc = b->loc; loc; loc = loc->next, ++n) |
| 3921 | print_one_breakpoint_location (b, loc, n, last_loc, |
| 3922 | print_address_bits); |
| 3923 | } |
| 3924 | } |
| 3925 | } |
| 3926 | |
| 3927 | static int |
| 3928 | breakpoint_address_bits (struct breakpoint *b) |
| 3929 | { |
| 3930 | int print_address_bits = 0; |
| 3931 | struct bp_location *loc; |
| 3932 | |
| 3933 | for (loc = b->loc; loc; loc = loc->next) |
| 3934 | { |
| 3935 | int addr_bit = gdbarch_addr_bit (b->gdbarch); |
| 3936 | if (addr_bit > print_address_bits) |
| 3937 | print_address_bits = addr_bit; |
| 3938 | } |
| 3939 | |
| 3940 | return print_address_bits; |
| 3941 | } |
| 3942 | |
| 3943 | struct captured_breakpoint_query_args |
| 3944 | { |
| 3945 | int bnum; |
| 3946 | }; |
| 3947 | |
| 3948 | static int |
| 3949 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
| 3950 | { |
| 3951 | struct captured_breakpoint_query_args *args = data; |
| 3952 | struct breakpoint *b; |
| 3953 | struct bp_location *dummy_loc = NULL; |
| 3954 | ALL_BREAKPOINTS (b) |
| 3955 | { |
| 3956 | if (args->bnum == b->number) |
| 3957 | { |
| 3958 | int print_address_bits = breakpoint_address_bits (b); |
| 3959 | print_one_breakpoint (b, &dummy_loc, print_address_bits); |
| 3960 | return GDB_RC_OK; |
| 3961 | } |
| 3962 | } |
| 3963 | return GDB_RC_NONE; |
| 3964 | } |
| 3965 | |
| 3966 | enum gdb_rc |
| 3967 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
| 3968 | { |
| 3969 | struct captured_breakpoint_query_args args; |
| 3970 | args.bnum = bnum; |
| 3971 | /* For the moment we don't trust print_one_breakpoint() to not throw |
| 3972 | an error. */ |
| 3973 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
| 3974 | error_message, RETURN_MASK_ALL) < 0) |
| 3975 | return GDB_RC_FAIL; |
| 3976 | else |
| 3977 | return GDB_RC_OK; |
| 3978 | } |
| 3979 | |
| 3980 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
| 3981 | catchpoints, et.al.). */ |
| 3982 | |
| 3983 | static int |
| 3984 | user_settable_breakpoint (const struct breakpoint *b) |
| 3985 | { |
| 3986 | return (b->type == bp_breakpoint |
| 3987 | || b->type == bp_catchpoint |
| 3988 | || b->type == bp_hardware_breakpoint |
| 3989 | || b->type == bp_tracepoint |
| 3990 | || b->type == bp_watchpoint |
| 3991 | || b->type == bp_read_watchpoint |
| 3992 | || b->type == bp_access_watchpoint |
| 3993 | || b->type == bp_hardware_watchpoint); |
| 3994 | } |
| 3995 | |
| 3996 | /* Print information on user settable breakpoint (watchpoint, etc) |
| 3997 | number BNUM. If BNUM is -1 print all user settable breakpoints. |
| 3998 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ |
| 3999 | |
| 4000 | static void |
| 4001 | breakpoint_1 (int bnum, int allflag) |
| 4002 | { |
| 4003 | struct breakpoint *b; |
| 4004 | struct bp_location *last_loc = NULL; |
| 4005 | int nr_printable_breakpoints; |
| 4006 | struct cleanup *bkpttbl_chain; |
| 4007 | struct value_print_options opts; |
| 4008 | int print_address_bits = 0; |
| 4009 | |
| 4010 | get_user_print_options (&opts); |
| 4011 | |
| 4012 | /* Compute the number of rows in the table, as well as the |
| 4013 | size required for address fields. */ |
| 4014 | nr_printable_breakpoints = 0; |
| 4015 | ALL_BREAKPOINTS (b) |
| 4016 | if (bnum == -1 |
| 4017 | || bnum == b->number) |
| 4018 | { |
| 4019 | if (allflag || user_settable_breakpoint (b)) |
| 4020 | { |
| 4021 | int addr_bit = breakpoint_address_bits (b); |
| 4022 | if (addr_bit > print_address_bits) |
| 4023 | print_address_bits = addr_bit; |
| 4024 | |
| 4025 | nr_printable_breakpoints++; |
| 4026 | } |
| 4027 | } |
| 4028 | |
| 4029 | if (opts.addressprint) |
| 4030 | bkpttbl_chain |
| 4031 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, |
| 4032 | "BreakpointTable"); |
| 4033 | else |
| 4034 | bkpttbl_chain |
| 4035 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, |
| 4036 | "BreakpointTable"); |
| 4037 | |
| 4038 | if (nr_printable_breakpoints > 0) |
| 4039 | annotate_breakpoints_headers (); |
| 4040 | if (nr_printable_breakpoints > 0) |
| 4041 | annotate_field (0); |
| 4042 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
| 4043 | if (nr_printable_breakpoints > 0) |
| 4044 | annotate_field (1); |
| 4045 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ |
| 4046 | if (nr_printable_breakpoints > 0) |
| 4047 | annotate_field (2); |
| 4048 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
| 4049 | if (nr_printable_breakpoints > 0) |
| 4050 | annotate_field (3); |
| 4051 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
| 4052 | if (opts.addressprint) |
| 4053 | { |
| 4054 | if (nr_printable_breakpoints > 0) |
| 4055 | annotate_field (4); |
| 4056 | if (print_address_bits <= 32) |
| 4057 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
| 4058 | else |
| 4059 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
| 4060 | } |
| 4061 | if (nr_printable_breakpoints > 0) |
| 4062 | annotate_field (5); |
| 4063 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ |
| 4064 | ui_out_table_body (uiout); |
| 4065 | if (nr_printable_breakpoints > 0) |
| 4066 | annotate_breakpoints_table (); |
| 4067 | |
| 4068 | ALL_BREAKPOINTS (b) |
| 4069 | if (bnum == -1 |
| 4070 | || bnum == b->number) |
| 4071 | { |
| 4072 | /* We only print out user settable breakpoints unless the |
| 4073 | allflag is set. */ |
| 4074 | if (allflag || user_settable_breakpoint (b)) |
| 4075 | print_one_breakpoint (b, &last_loc, print_address_bits); |
| 4076 | } |
| 4077 | |
| 4078 | do_cleanups (bkpttbl_chain); |
| 4079 | |
| 4080 | if (nr_printable_breakpoints == 0) |
| 4081 | { |
| 4082 | if (bnum == -1) |
| 4083 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
| 4084 | else |
| 4085 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", |
| 4086 | bnum); |
| 4087 | } |
| 4088 | else |
| 4089 | { |
| 4090 | if (last_loc && !server_command) |
| 4091 | set_next_address (last_loc->gdbarch, last_loc->address); |
| 4092 | } |
| 4093 | |
| 4094 | /* FIXME? Should this be moved up so that it is only called when |
| 4095 | there have been breakpoints? */ |
| 4096 | annotate_breakpoints_table_end (); |
| 4097 | } |
| 4098 | |
| 4099 | static void |
| 4100 | breakpoints_info (char *bnum_exp, int from_tty) |
| 4101 | { |
| 4102 | int bnum = -1; |
| 4103 | |
| 4104 | if (bnum_exp) |
| 4105 | bnum = parse_and_eval_long (bnum_exp); |
| 4106 | |
| 4107 | breakpoint_1 (bnum, 0); |
| 4108 | } |
| 4109 | |
| 4110 | static void |
| 4111 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
| 4112 | { |
| 4113 | int bnum = -1; |
| 4114 | |
| 4115 | if (bnum_exp) |
| 4116 | bnum = parse_and_eval_long (bnum_exp); |
| 4117 | |
| 4118 | breakpoint_1 (bnum, 1); |
| 4119 | } |
| 4120 | |
| 4121 | static int |
| 4122 | breakpoint_has_pc (struct breakpoint *b, |
| 4123 | CORE_ADDR pc, struct obj_section *section) |
| 4124 | { |
| 4125 | struct bp_location *bl = b->loc; |
| 4126 | for (; bl; bl = bl->next) |
| 4127 | { |
| 4128 | if (bl->address == pc |
| 4129 | && (!overlay_debugging || bl->section == section)) |
| 4130 | return 1; |
| 4131 | } |
| 4132 | return 0; |
| 4133 | } |
| 4134 | |
| 4135 | /* Print a message describing any breakpoints set at PC. */ |
| 4136 | |
| 4137 | static void |
| 4138 | describe_other_breakpoints (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 4139 | struct obj_section *section, int thread) |
| 4140 | { |
| 4141 | int others = 0; |
| 4142 | struct breakpoint *b; |
| 4143 | |
| 4144 | ALL_BREAKPOINTS (b) |
| 4145 | others += breakpoint_has_pc (b, pc, section); |
| 4146 | if (others > 0) |
| 4147 | { |
| 4148 | if (others == 1) |
| 4149 | printf_filtered (_("Note: breakpoint ")); |
| 4150 | else /* if (others == ???) */ |
| 4151 | printf_filtered (_("Note: breakpoints ")); |
| 4152 | ALL_BREAKPOINTS (b) |
| 4153 | if (breakpoint_has_pc (b, pc, section)) |
| 4154 | { |
| 4155 | others--; |
| 4156 | printf_filtered ("%d", b->number); |
| 4157 | if (b->thread == -1 && thread != -1) |
| 4158 | printf_filtered (" (all threads)"); |
| 4159 | else if (b->thread != -1) |
| 4160 | printf_filtered (" (thread %d)", b->thread); |
| 4161 | printf_filtered ("%s%s ", |
| 4162 | ((b->enable_state == bp_disabled |
| 4163 | || b->enable_state == bp_call_disabled |
| 4164 | || b->enable_state == bp_startup_disabled) |
| 4165 | ? " (disabled)" |
| 4166 | : b->enable_state == bp_permanent |
| 4167 | ? " (permanent)" |
| 4168 | : ""), |
| 4169 | (others > 1) ? "," |
| 4170 | : ((others == 1) ? " and" : "")); |
| 4171 | } |
| 4172 | printf_filtered (_("also set at pc ")); |
| 4173 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
| 4174 | printf_filtered (".\n"); |
| 4175 | } |
| 4176 | } |
| 4177 | \f |
| 4178 | /* Set the default place to put a breakpoint |
| 4179 | for the `break' command with no arguments. */ |
| 4180 | |
| 4181 | void |
| 4182 | set_default_breakpoint (int valid, CORE_ADDR addr, struct symtab *symtab, |
| 4183 | int line) |
| 4184 | { |
| 4185 | default_breakpoint_valid = valid; |
| 4186 | default_breakpoint_address = addr; |
| 4187 | default_breakpoint_symtab = symtab; |
| 4188 | default_breakpoint_line = line; |
| 4189 | } |
| 4190 | |
| 4191 | /* Return true iff it is meaningful to use the address member of |
| 4192 | BPT. For some breakpoint types, the address member is irrelevant |
| 4193 | and it makes no sense to attempt to compare it to other addresses |
| 4194 | (or use it for any other purpose either). |
| 4195 | |
| 4196 | More specifically, each of the following breakpoint types will always |
| 4197 | have a zero valued address and we don't want check_duplicates() to mark |
| 4198 | breakpoints of any of these types to be a duplicate of an actual |
| 4199 | breakpoint at address zero: |
| 4200 | |
| 4201 | bp_watchpoint |
| 4202 | bp_hardware_watchpoint |
| 4203 | bp_read_watchpoint |
| 4204 | bp_access_watchpoint |
| 4205 | bp_catchpoint */ |
| 4206 | |
| 4207 | static int |
| 4208 | breakpoint_address_is_meaningful (struct breakpoint *bpt) |
| 4209 | { |
| 4210 | enum bptype type = bpt->type; |
| 4211 | |
| 4212 | return (type != bp_watchpoint |
| 4213 | && type != bp_hardware_watchpoint |
| 4214 | && type != bp_read_watchpoint |
| 4215 | && type != bp_access_watchpoint |
| 4216 | && type != bp_catchpoint); |
| 4217 | } |
| 4218 | |
| 4219 | /* Rescan breakpoints at the same address and section as BPT, |
| 4220 | marking the first one as "first" and any others as "duplicates". |
| 4221 | This is so that the bpt instruction is only inserted once. |
| 4222 | If we have a permanent breakpoint at the same place as BPT, make |
| 4223 | that one the official one, and the rest as duplicates. */ |
| 4224 | |
| 4225 | static void |
| 4226 | check_duplicates_for (CORE_ADDR address, struct obj_section *section) |
| 4227 | { |
| 4228 | struct bp_location *b; |
| 4229 | int count = 0; |
| 4230 | struct bp_location *perm_bp = 0; |
| 4231 | |
| 4232 | ALL_BP_LOCATIONS (b) |
| 4233 | if (b->owner->enable_state != bp_disabled |
| 4234 | && b->owner->enable_state != bp_call_disabled |
| 4235 | && b->owner->enable_state != bp_startup_disabled |
| 4236 | && b->enabled |
| 4237 | && !b->shlib_disabled |
| 4238 | && b->address == address /* address / overlay match */ |
| 4239 | && (!overlay_debugging || b->section == section) |
| 4240 | && breakpoint_address_is_meaningful (b->owner)) |
| 4241 | { |
| 4242 | /* Have we found a permanent breakpoint? */ |
| 4243 | if (b->owner->enable_state == bp_permanent) |
| 4244 | { |
| 4245 | perm_bp = b; |
| 4246 | break; |
| 4247 | } |
| 4248 | |
| 4249 | count++; |
| 4250 | b->duplicate = count > 1; |
| 4251 | } |
| 4252 | |
| 4253 | /* If we found a permanent breakpoint at this address, go over the |
| 4254 | list again and declare all the other breakpoints there (except |
| 4255 | other permanent breakpoints) to be the duplicates. */ |
| 4256 | if (perm_bp) |
| 4257 | { |
| 4258 | perm_bp->duplicate = 0; |
| 4259 | |
| 4260 | /* Permanent breakpoint should always be inserted. */ |
| 4261 | if (! perm_bp->inserted) |
| 4262 | internal_error (__FILE__, __LINE__, |
| 4263 | _("allegedly permanent breakpoint is not " |
| 4264 | "actually inserted")); |
| 4265 | |
| 4266 | ALL_BP_LOCATIONS (b) |
| 4267 | if (b != perm_bp) |
| 4268 | { |
| 4269 | if (b->owner->enable_state != bp_permanent |
| 4270 | && b->owner->enable_state != bp_disabled |
| 4271 | && b->owner->enable_state != bp_call_disabled |
| 4272 | && b->owner->enable_state != bp_startup_disabled |
| 4273 | && b->enabled && !b->shlib_disabled |
| 4274 | && b->address == address /* address / overlay match */ |
| 4275 | && (!overlay_debugging || b->section == section) |
| 4276 | && breakpoint_address_is_meaningful (b->owner)) |
| 4277 | { |
| 4278 | if (b->inserted) |
| 4279 | internal_error (__FILE__, __LINE__, |
| 4280 | _("another breakpoint was inserted on top of " |
| 4281 | "a permanent breakpoint")); |
| 4282 | |
| 4283 | b->duplicate = 1; |
| 4284 | } |
| 4285 | } |
| 4286 | } |
| 4287 | } |
| 4288 | |
| 4289 | static void |
| 4290 | check_duplicates (struct breakpoint *bpt) |
| 4291 | { |
| 4292 | struct bp_location *bl = bpt->loc; |
| 4293 | |
| 4294 | if (! breakpoint_address_is_meaningful (bpt)) |
| 4295 | return; |
| 4296 | |
| 4297 | for (; bl; bl = bl->next) |
| 4298 | check_duplicates_for (bl->address, bl->section); |
| 4299 | } |
| 4300 | |
| 4301 | static void |
| 4302 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, |
| 4303 | int bnum, int have_bnum) |
| 4304 | { |
| 4305 | char astr1[40]; |
| 4306 | char astr2[40]; |
| 4307 | |
| 4308 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
| 4309 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); |
| 4310 | if (have_bnum) |
| 4311 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
| 4312 | bnum, astr1, astr2); |
| 4313 | else |
| 4314 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
| 4315 | } |
| 4316 | |
| 4317 | /* Adjust a breakpoint's address to account for architectural constraints |
| 4318 | on breakpoint placement. Return the adjusted address. Note: Very |
| 4319 | few targets require this kind of adjustment. For most targets, |
| 4320 | this function is simply the identity function. */ |
| 4321 | |
| 4322 | static CORE_ADDR |
| 4323 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 4324 | CORE_ADDR bpaddr, enum bptype bptype) |
| 4325 | { |
| 4326 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
| 4327 | { |
| 4328 | /* Very few targets need any kind of breakpoint adjustment. */ |
| 4329 | return bpaddr; |
| 4330 | } |
| 4331 | else if (bptype == bp_watchpoint |
| 4332 | || bptype == bp_hardware_watchpoint |
| 4333 | || bptype == bp_read_watchpoint |
| 4334 | || bptype == bp_access_watchpoint |
| 4335 | || bptype == bp_catchpoint) |
| 4336 | { |
| 4337 | /* Watchpoints and the various bp_catch_* eventpoints should not |
| 4338 | have their addresses modified. */ |
| 4339 | return bpaddr; |
| 4340 | } |
| 4341 | else |
| 4342 | { |
| 4343 | CORE_ADDR adjusted_bpaddr; |
| 4344 | |
| 4345 | /* Some targets have architectural constraints on the placement |
| 4346 | of breakpoint instructions. Obtain the adjusted address. */ |
| 4347 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
| 4348 | |
| 4349 | /* An adjusted breakpoint address can significantly alter |
| 4350 | a user's expectations. Print a warning if an adjustment |
| 4351 | is required. */ |
| 4352 | if (adjusted_bpaddr != bpaddr) |
| 4353 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); |
| 4354 | |
| 4355 | return adjusted_bpaddr; |
| 4356 | } |
| 4357 | } |
| 4358 | |
| 4359 | /* Allocate a struct bp_location. */ |
| 4360 | |
| 4361 | static struct bp_location * |
| 4362 | allocate_bp_location (struct breakpoint *bpt) |
| 4363 | { |
| 4364 | struct bp_location *loc, *loc_p; |
| 4365 | |
| 4366 | loc = xmalloc (sizeof (struct bp_location)); |
| 4367 | memset (loc, 0, sizeof (*loc)); |
| 4368 | |
| 4369 | loc->owner = bpt; |
| 4370 | loc->cond = NULL; |
| 4371 | loc->shlib_disabled = 0; |
| 4372 | loc->enabled = 1; |
| 4373 | |
| 4374 | switch (bpt->type) |
| 4375 | { |
| 4376 | case bp_breakpoint: |
| 4377 | case bp_tracepoint: |
| 4378 | case bp_until: |
| 4379 | case bp_finish: |
| 4380 | case bp_longjmp: |
| 4381 | case bp_longjmp_resume: |
| 4382 | case bp_step_resume: |
| 4383 | case bp_watchpoint_scope: |
| 4384 | case bp_call_dummy: |
| 4385 | case bp_shlib_event: |
| 4386 | case bp_thread_event: |
| 4387 | case bp_overlay_event: |
| 4388 | case bp_jit_event: |
| 4389 | case bp_longjmp_master: |
| 4390 | loc->loc_type = bp_loc_software_breakpoint; |
| 4391 | break; |
| 4392 | case bp_hardware_breakpoint: |
| 4393 | loc->loc_type = bp_loc_hardware_breakpoint; |
| 4394 | break; |
| 4395 | case bp_hardware_watchpoint: |
| 4396 | case bp_read_watchpoint: |
| 4397 | case bp_access_watchpoint: |
| 4398 | loc->loc_type = bp_loc_hardware_watchpoint; |
| 4399 | break; |
| 4400 | case bp_watchpoint: |
| 4401 | case bp_catchpoint: |
| 4402 | loc->loc_type = bp_loc_other; |
| 4403 | break; |
| 4404 | default: |
| 4405 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
| 4406 | } |
| 4407 | |
| 4408 | return loc; |
| 4409 | } |
| 4410 | |
| 4411 | static void free_bp_location (struct bp_location *loc) |
| 4412 | { |
| 4413 | if (loc->cond) |
| 4414 | xfree (loc->cond); |
| 4415 | |
| 4416 | if (loc->function_name) |
| 4417 | xfree (loc->function_name); |
| 4418 | |
| 4419 | xfree (loc); |
| 4420 | } |
| 4421 | |
| 4422 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
| 4423 | that has type BPTYPE and has no locations as yet. */ |
| 4424 | /* This function is used in gdbtk sources and thus can not be made static. */ |
| 4425 | |
| 4426 | static struct breakpoint * |
| 4427 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
| 4428 | enum bptype bptype) |
| 4429 | { |
| 4430 | struct breakpoint *b, *b1; |
| 4431 | |
| 4432 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); |
| 4433 | memset (b, 0, sizeof (*b)); |
| 4434 | |
| 4435 | b->type = bptype; |
| 4436 | b->gdbarch = gdbarch; |
| 4437 | b->language = current_language->la_language; |
| 4438 | b->input_radix = input_radix; |
| 4439 | b->thread = -1; |
| 4440 | b->enable_state = bp_enabled; |
| 4441 | b->next = 0; |
| 4442 | b->silent = 0; |
| 4443 | b->ignore_count = 0; |
| 4444 | b->commands = NULL; |
| 4445 | b->frame_id = null_frame_id; |
| 4446 | b->forked_inferior_pid = null_ptid; |
| 4447 | b->exec_pathname = NULL; |
| 4448 | b->ops = NULL; |
| 4449 | b->condition_not_parsed = 0; |
| 4450 | |
| 4451 | /* Add this breakpoint to the end of the chain |
| 4452 | so that a list of breakpoints will come out in order |
| 4453 | of increasing numbers. */ |
| 4454 | |
| 4455 | b1 = breakpoint_chain; |
| 4456 | if (b1 == 0) |
| 4457 | breakpoint_chain = b; |
| 4458 | else |
| 4459 | { |
| 4460 | while (b1->next) |
| 4461 | b1 = b1->next; |
| 4462 | b1->next = b; |
| 4463 | } |
| 4464 | return b; |
| 4465 | } |
| 4466 | |
| 4467 | /* Initialize loc->function_name. */ |
| 4468 | static void |
| 4469 | set_breakpoint_location_function (struct bp_location *loc) |
| 4470 | { |
| 4471 | if (loc->owner->type == bp_breakpoint |
| 4472 | || loc->owner->type == bp_hardware_breakpoint |
| 4473 | || loc->owner->type == bp_tracepoint) |
| 4474 | { |
| 4475 | find_pc_partial_function (loc->address, &(loc->function_name), |
| 4476 | NULL, NULL); |
| 4477 | if (loc->function_name) |
| 4478 | loc->function_name = xstrdup (loc->function_name); |
| 4479 | } |
| 4480 | } |
| 4481 | |
| 4482 | /* Attempt to determine architecture of location identified by SAL. */ |
| 4483 | static struct gdbarch * |
| 4484 | get_sal_arch (struct symtab_and_line sal) |
| 4485 | { |
| 4486 | if (sal.section) |
| 4487 | return get_objfile_arch (sal.section->objfile); |
| 4488 | if (sal.symtab) |
| 4489 | return get_objfile_arch (sal.symtab->objfile); |
| 4490 | |
| 4491 | return NULL; |
| 4492 | } |
| 4493 | |
| 4494 | /* set_raw_breakpoint is a low level routine for allocating and |
| 4495 | partially initializing a breakpoint of type BPTYPE. The newly |
| 4496 | created breakpoint's address, section, source file name, and line |
| 4497 | number are provided by SAL. The newly created and partially |
| 4498 | initialized breakpoint is added to the breakpoint chain and |
| 4499 | is also returned as the value of this function. |
| 4500 | |
| 4501 | It is expected that the caller will complete the initialization of |
| 4502 | the newly created breakpoint struct as well as output any status |
| 4503 | information regarding the creation of a new breakpoint. In |
| 4504 | particular, set_raw_breakpoint does NOT set the breakpoint |
| 4505 | number! Care should be taken to not allow an error to occur |
| 4506 | prior to completing the initialization of the breakpoint. If this |
| 4507 | should happen, a bogus breakpoint will be left on the chain. */ |
| 4508 | |
| 4509 | struct breakpoint * |
| 4510 | set_raw_breakpoint (struct gdbarch *gdbarch, |
| 4511 | struct symtab_and_line sal, enum bptype bptype) |
| 4512 | { |
| 4513 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
| 4514 | CORE_ADDR adjusted_address; |
| 4515 | struct gdbarch *loc_gdbarch; |
| 4516 | |
| 4517 | loc_gdbarch = get_sal_arch (sal); |
| 4518 | if (!loc_gdbarch) |
| 4519 | loc_gdbarch = b->gdbarch; |
| 4520 | |
| 4521 | /* Adjust the breakpoint's address prior to allocating a location. |
| 4522 | Once we call allocate_bp_location(), that mostly uninitialized |
| 4523 | location will be placed on the location chain. Adjustment of the |
| 4524 | breakpoint may cause target_read_memory() to be called and we do |
| 4525 | not want its scan of the location chain to find a breakpoint and |
| 4526 | location that's only been partially initialized. */ |
| 4527 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
| 4528 | |
| 4529 | b->loc = allocate_bp_location (b); |
| 4530 | b->loc->gdbarch = loc_gdbarch; |
| 4531 | b->loc->requested_address = sal.pc; |
| 4532 | b->loc->address = adjusted_address; |
| 4533 | |
| 4534 | if (sal.symtab == NULL) |
| 4535 | b->source_file = NULL; |
| 4536 | else |
| 4537 | b->source_file = xstrdup (sal.symtab->filename); |
| 4538 | b->loc->section = sal.section; |
| 4539 | b->line_number = sal.line; |
| 4540 | |
| 4541 | set_breakpoint_location_function (b->loc); |
| 4542 | |
| 4543 | breakpoints_changed (); |
| 4544 | |
| 4545 | return b; |
| 4546 | } |
| 4547 | |
| 4548 | |
| 4549 | /* Note that the breakpoint object B describes a permanent breakpoint |
| 4550 | instruction, hard-wired into the inferior's code. */ |
| 4551 | void |
| 4552 | make_breakpoint_permanent (struct breakpoint *b) |
| 4553 | { |
| 4554 | struct bp_location *bl; |
| 4555 | b->enable_state = bp_permanent; |
| 4556 | |
| 4557 | /* By definition, permanent breakpoints are already present in the code. |
| 4558 | Mark all locations as inserted. For now, make_breakpoint_permanent |
| 4559 | is called in just one place, so it's hard to say if it's reasonable |
| 4560 | to have permanent breakpoint with multiple locations or not, |
| 4561 | but it's easy to implmement. */ |
| 4562 | for (bl = b->loc; bl; bl = bl->next) |
| 4563 | bl->inserted = 1; |
| 4564 | } |
| 4565 | |
| 4566 | /* Call this routine when stepping and nexting to enable a breakpoint |
| 4567 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
| 4568 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
| 4569 | |
| 4570 | void |
| 4571 | set_longjmp_breakpoint (int thread) |
| 4572 | { |
| 4573 | struct breakpoint *b, *temp; |
| 4574 | |
| 4575 | /* To avoid having to rescan all objfile symbols at every step, |
| 4576 | we maintain a list of continually-inserted but always disabled |
| 4577 | longjmp "master" breakpoints. Here, we simply create momentary |
| 4578 | clones of those and enable them for the requested thread. */ |
| 4579 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 4580 | if (b->type == bp_longjmp_master) |
| 4581 | { |
| 4582 | struct breakpoint *clone = clone_momentary_breakpoint (b); |
| 4583 | clone->type = bp_longjmp; |
| 4584 | clone->thread = thread; |
| 4585 | } |
| 4586 | } |
| 4587 | |
| 4588 | /* Delete all longjmp breakpoints from THREAD. */ |
| 4589 | void |
| 4590 | delete_longjmp_breakpoint (int thread) |
| 4591 | { |
| 4592 | struct breakpoint *b, *temp; |
| 4593 | |
| 4594 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 4595 | if (b->type == bp_longjmp) |
| 4596 | { |
| 4597 | if (b->thread == thread) |
| 4598 | delete_breakpoint (b); |
| 4599 | } |
| 4600 | } |
| 4601 | |
| 4602 | void |
| 4603 | enable_overlay_breakpoints (void) |
| 4604 | { |
| 4605 | struct breakpoint *b; |
| 4606 | |
| 4607 | ALL_BREAKPOINTS (b) |
| 4608 | if (b->type == bp_overlay_event) |
| 4609 | { |
| 4610 | b->enable_state = bp_enabled; |
| 4611 | update_global_location_list (1); |
| 4612 | overlay_events_enabled = 1; |
| 4613 | } |
| 4614 | } |
| 4615 | |
| 4616 | void |
| 4617 | disable_overlay_breakpoints (void) |
| 4618 | { |
| 4619 | struct breakpoint *b; |
| 4620 | |
| 4621 | ALL_BREAKPOINTS (b) |
| 4622 | if (b->type == bp_overlay_event) |
| 4623 | { |
| 4624 | b->enable_state = bp_disabled; |
| 4625 | update_global_location_list (0); |
| 4626 | overlay_events_enabled = 0; |
| 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | struct breakpoint * |
| 4631 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 4632 | { |
| 4633 | struct breakpoint *b; |
| 4634 | |
| 4635 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
| 4636 | |
| 4637 | b->enable_state = bp_enabled; |
| 4638 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
| 4639 | b->addr_string |
| 4640 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); |
| 4641 | |
| 4642 | update_global_location_list_nothrow (1); |
| 4643 | |
| 4644 | return b; |
| 4645 | } |
| 4646 | |
| 4647 | void |
| 4648 | remove_thread_event_breakpoints (void) |
| 4649 | { |
| 4650 | struct breakpoint *b, *temp; |
| 4651 | |
| 4652 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 4653 | if (b->type == bp_thread_event) |
| 4654 | delete_breakpoint (b); |
| 4655 | } |
| 4656 | |
| 4657 | struct captured_parse_breakpoint_args |
| 4658 | { |
| 4659 | char **arg_p; |
| 4660 | struct symtabs_and_lines *sals_p; |
| 4661 | char ***addr_string_p; |
| 4662 | int *not_found_ptr; |
| 4663 | }; |
| 4664 | |
| 4665 | struct lang_and_radix |
| 4666 | { |
| 4667 | enum language lang; |
| 4668 | int radix; |
| 4669 | }; |
| 4670 | |
| 4671 | /* Create a breakpoint for JIT code registration and unregistration. */ |
| 4672 | |
| 4673 | struct breakpoint * |
| 4674 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 4675 | { |
| 4676 | struct breakpoint *b; |
| 4677 | |
| 4678 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); |
| 4679 | update_global_location_list_nothrow (1); |
| 4680 | return b; |
| 4681 | } |
| 4682 | |
| 4683 | void |
| 4684 | remove_solib_event_breakpoints (void) |
| 4685 | { |
| 4686 | struct breakpoint *b, *temp; |
| 4687 | |
| 4688 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 4689 | if (b->type == bp_shlib_event) |
| 4690 | delete_breakpoint (b); |
| 4691 | } |
| 4692 | |
| 4693 | struct breakpoint * |
| 4694 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 4695 | { |
| 4696 | struct breakpoint *b; |
| 4697 | |
| 4698 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
| 4699 | update_global_location_list_nothrow (1); |
| 4700 | return b; |
| 4701 | } |
| 4702 | |
| 4703 | /* Disable any breakpoints that are on code in shared libraries. Only |
| 4704 | apply to enabled breakpoints, disabled ones can just stay disabled. */ |
| 4705 | |
| 4706 | void |
| 4707 | disable_breakpoints_in_shlibs (void) |
| 4708 | { |
| 4709 | struct bp_location *loc; |
| 4710 | |
| 4711 | ALL_BP_LOCATIONS (loc) |
| 4712 | { |
| 4713 | struct breakpoint *b = loc->owner; |
| 4714 | /* We apply the check to all breakpoints, including disabled |
| 4715 | for those with loc->duplicate set. This is so that when breakpoint |
| 4716 | becomes enabled, or the duplicate is removed, gdb will try to insert |
| 4717 | all breakpoints. If we don't set shlib_disabled here, we'll try |
| 4718 | to insert those breakpoints and fail. */ |
| 4719 | if (((b->type == bp_breakpoint) |
| 4720 | || (b->type == bp_hardware_breakpoint) |
| 4721 | || (b->type == bp_tracepoint)) |
| 4722 | && !loc->shlib_disabled |
| 4723 | #ifdef PC_SOLIB |
| 4724 | && PC_SOLIB (loc->address) |
| 4725 | #else |
| 4726 | && solib_name_from_address (loc->address) |
| 4727 | #endif |
| 4728 | ) |
| 4729 | { |
| 4730 | loc->shlib_disabled = 1; |
| 4731 | } |
| 4732 | } |
| 4733 | } |
| 4734 | |
| 4735 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
| 4736 | apply to enabled breakpoints, disabled ones can just stay disabled. */ |
| 4737 | |
| 4738 | static void |
| 4739 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
| 4740 | { |
| 4741 | struct bp_location *loc; |
| 4742 | int disabled_shlib_breaks = 0; |
| 4743 | |
| 4744 | /* SunOS a.out shared libraries are always mapped, so do not |
| 4745 | disable breakpoints; they will only be reported as unloaded |
| 4746 | through clear_solib when GDB discards its shared library |
| 4747 | list. See clear_solib for more information. */ |
| 4748 | if (exec_bfd != NULL |
| 4749 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) |
| 4750 | return; |
| 4751 | |
| 4752 | ALL_BP_LOCATIONS (loc) |
| 4753 | { |
| 4754 | struct breakpoint *b = loc->owner; |
| 4755 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
| 4756 | || loc->loc_type == bp_loc_software_breakpoint) |
| 4757 | && !loc->shlib_disabled |
| 4758 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) |
| 4759 | && solib_contains_address_p (solib, loc->address)) |
| 4760 | { |
| 4761 | loc->shlib_disabled = 1; |
| 4762 | /* At this point, we cannot rely on remove_breakpoint |
| 4763 | succeeding so we must mark the breakpoint as not inserted |
| 4764 | to prevent future errors occurring in remove_breakpoints. */ |
| 4765 | loc->inserted = 0; |
| 4766 | if (!disabled_shlib_breaks) |
| 4767 | { |
| 4768 | target_terminal_ours_for_output (); |
| 4769 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), |
| 4770 | solib->so_name); |
| 4771 | } |
| 4772 | disabled_shlib_breaks = 1; |
| 4773 | } |
| 4774 | } |
| 4775 | } |
| 4776 | |
| 4777 | /* FORK & VFORK catchpoints. */ |
| 4778 | |
| 4779 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ |
| 4780 | |
| 4781 | static void |
| 4782 | insert_catch_fork (struct breakpoint *b) |
| 4783 | { |
| 4784 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
| 4785 | } |
| 4786 | |
| 4787 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ |
| 4788 | |
| 4789 | static int |
| 4790 | remove_catch_fork (struct breakpoint *b) |
| 4791 | { |
| 4792 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); |
| 4793 | } |
| 4794 | |
| 4795 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork |
| 4796 | catchpoints. */ |
| 4797 | |
| 4798 | static int |
| 4799 | breakpoint_hit_catch_fork (struct breakpoint *b) |
| 4800 | { |
| 4801 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); |
| 4802 | } |
| 4803 | |
| 4804 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ |
| 4805 | |
| 4806 | static enum print_stop_action |
| 4807 | print_it_catch_fork (struct breakpoint *b) |
| 4808 | { |
| 4809 | annotate_catchpoint (b->number); |
| 4810 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), |
| 4811 | b->number, ptid_get_pid (b->forked_inferior_pid)); |
| 4812 | return PRINT_SRC_AND_LOC; |
| 4813 | } |
| 4814 | |
| 4815 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ |
| 4816 | |
| 4817 | static void |
| 4818 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
| 4819 | { |
| 4820 | struct value_print_options opts; |
| 4821 | |
| 4822 | get_user_print_options (&opts); |
| 4823 | |
| 4824 | /* Field 4, the address, is omitted (which makes the columns |
| 4825 | not line up too nicely with the headers, but the effect |
| 4826 | is relatively readable). */ |
| 4827 | if (opts.addressprint) |
| 4828 | ui_out_field_skip (uiout, "addr"); |
| 4829 | annotate_field (5); |
| 4830 | ui_out_text (uiout, "fork"); |
| 4831 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) |
| 4832 | { |
| 4833 | ui_out_text (uiout, ", process "); |
| 4834 | ui_out_field_int (uiout, "what", |
| 4835 | ptid_get_pid (b->forked_inferior_pid)); |
| 4836 | ui_out_spaces (uiout, 1); |
| 4837 | } |
| 4838 | } |
| 4839 | |
| 4840 | /* Implement the "print_mention" breakpoint_ops method for fork |
| 4841 | catchpoints. */ |
| 4842 | |
| 4843 | static void |
| 4844 | print_mention_catch_fork (struct breakpoint *b) |
| 4845 | { |
| 4846 | printf_filtered (_("Catchpoint %d (fork)"), b->number); |
| 4847 | } |
| 4848 | |
| 4849 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
| 4850 | |
| 4851 | static struct breakpoint_ops catch_fork_breakpoint_ops = |
| 4852 | { |
| 4853 | insert_catch_fork, |
| 4854 | remove_catch_fork, |
| 4855 | breakpoint_hit_catch_fork, |
| 4856 | print_it_catch_fork, |
| 4857 | print_one_catch_fork, |
| 4858 | print_mention_catch_fork |
| 4859 | }; |
| 4860 | |
| 4861 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ |
| 4862 | |
| 4863 | static void |
| 4864 | insert_catch_vfork (struct breakpoint *b) |
| 4865 | { |
| 4866 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
| 4867 | } |
| 4868 | |
| 4869 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ |
| 4870 | |
| 4871 | static int |
| 4872 | remove_catch_vfork (struct breakpoint *b) |
| 4873 | { |
| 4874 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); |
| 4875 | } |
| 4876 | |
| 4877 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork |
| 4878 | catchpoints. */ |
| 4879 | |
| 4880 | static int |
| 4881 | breakpoint_hit_catch_vfork (struct breakpoint *b) |
| 4882 | { |
| 4883 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); |
| 4884 | } |
| 4885 | |
| 4886 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ |
| 4887 | |
| 4888 | static enum print_stop_action |
| 4889 | print_it_catch_vfork (struct breakpoint *b) |
| 4890 | { |
| 4891 | annotate_catchpoint (b->number); |
| 4892 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), |
| 4893 | b->number, ptid_get_pid (b->forked_inferior_pid)); |
| 4894 | return PRINT_SRC_AND_LOC; |
| 4895 | } |
| 4896 | |
| 4897 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ |
| 4898 | |
| 4899 | static void |
| 4900 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
| 4901 | { |
| 4902 | struct value_print_options opts; |
| 4903 | |
| 4904 | get_user_print_options (&opts); |
| 4905 | /* Field 4, the address, is omitted (which makes the columns |
| 4906 | not line up too nicely with the headers, but the effect |
| 4907 | is relatively readable). */ |
| 4908 | if (opts.addressprint) |
| 4909 | ui_out_field_skip (uiout, "addr"); |
| 4910 | annotate_field (5); |
| 4911 | ui_out_text (uiout, "vfork"); |
| 4912 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) |
| 4913 | { |
| 4914 | ui_out_text (uiout, ", process "); |
| 4915 | ui_out_field_int (uiout, "what", |
| 4916 | ptid_get_pid (b->forked_inferior_pid)); |
| 4917 | ui_out_spaces (uiout, 1); |
| 4918 | } |
| 4919 | } |
| 4920 | |
| 4921 | /* Implement the "print_mention" breakpoint_ops method for vfork |
| 4922 | catchpoints. */ |
| 4923 | |
| 4924 | static void |
| 4925 | print_mention_catch_vfork (struct breakpoint *b) |
| 4926 | { |
| 4927 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); |
| 4928 | } |
| 4929 | |
| 4930 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
| 4931 | |
| 4932 | static struct breakpoint_ops catch_vfork_breakpoint_ops = |
| 4933 | { |
| 4934 | insert_catch_vfork, |
| 4935 | remove_catch_vfork, |
| 4936 | breakpoint_hit_catch_vfork, |
| 4937 | print_it_catch_vfork, |
| 4938 | print_one_catch_vfork, |
| 4939 | print_mention_catch_vfork |
| 4940 | }; |
| 4941 | |
| 4942 | /* Create a new breakpoint of the bp_catchpoint kind and return it. |
| 4943 | |
| 4944 | If TEMPFLAG is non-zero, then make the breakpoint temporary. |
| 4945 | If COND_STRING is not NULL, then store it in the breakpoint. |
| 4946 | OPS, if not NULL, is the breakpoint_ops structure associated |
| 4947 | to the catchpoint. */ |
| 4948 | |
| 4949 | static struct breakpoint * |
| 4950 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, |
| 4951 | char *cond_string, struct breakpoint_ops *ops) |
| 4952 | { |
| 4953 | struct symtab_and_line sal; |
| 4954 | struct breakpoint *b; |
| 4955 | |
| 4956 | init_sal (&sal); |
| 4957 | sal.pc = 0; |
| 4958 | sal.symtab = NULL; |
| 4959 | sal.line = 0; |
| 4960 | |
| 4961 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
| 4962 | set_breakpoint_count (breakpoint_count + 1); |
| 4963 | b->number = breakpoint_count; |
| 4964 | |
| 4965 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
| 4966 | b->thread = -1; |
| 4967 | b->addr_string = NULL; |
| 4968 | b->enable_state = bp_enabled; |
| 4969 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 4970 | b->ops = ops; |
| 4971 | |
| 4972 | mention (b); |
| 4973 | update_global_location_list (1); |
| 4974 | |
| 4975 | return b; |
| 4976 | } |
| 4977 | |
| 4978 | static void |
| 4979 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
| 4980 | int tempflag, char *cond_string, |
| 4981 | struct breakpoint_ops *ops) |
| 4982 | { |
| 4983 | struct breakpoint *b |
| 4984 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); |
| 4985 | |
| 4986 | /* FIXME: We should put this information in a breakpoint private data |
| 4987 | area. */ |
| 4988 | b->forked_inferior_pid = null_ptid; |
| 4989 | } |
| 4990 | |
| 4991 | /* Exec catchpoints. */ |
| 4992 | |
| 4993 | static void |
| 4994 | insert_catch_exec (struct breakpoint *b) |
| 4995 | { |
| 4996 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
| 4997 | } |
| 4998 | |
| 4999 | static int |
| 5000 | remove_catch_exec (struct breakpoint *b) |
| 5001 | { |
| 5002 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); |
| 5003 | } |
| 5004 | |
| 5005 | static int |
| 5006 | breakpoint_hit_catch_exec (struct breakpoint *b) |
| 5007 | { |
| 5008 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); |
| 5009 | } |
| 5010 | |
| 5011 | static enum print_stop_action |
| 5012 | print_it_catch_exec (struct breakpoint *b) |
| 5013 | { |
| 5014 | annotate_catchpoint (b->number); |
| 5015 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, |
| 5016 | b->exec_pathname); |
| 5017 | return PRINT_SRC_AND_LOC; |
| 5018 | } |
| 5019 | |
| 5020 | static void |
| 5021 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
| 5022 | { |
| 5023 | struct value_print_options opts; |
| 5024 | |
| 5025 | get_user_print_options (&opts); |
| 5026 | |
| 5027 | /* Field 4, the address, is omitted (which makes the columns |
| 5028 | not line up too nicely with the headers, but the effect |
| 5029 | is relatively readable). */ |
| 5030 | if (opts.addressprint) |
| 5031 | ui_out_field_skip (uiout, "addr"); |
| 5032 | annotate_field (5); |
| 5033 | ui_out_text (uiout, "exec"); |
| 5034 | if (b->exec_pathname != NULL) |
| 5035 | { |
| 5036 | ui_out_text (uiout, ", program \""); |
| 5037 | ui_out_field_string (uiout, "what", b->exec_pathname); |
| 5038 | ui_out_text (uiout, "\" "); |
| 5039 | } |
| 5040 | } |
| 5041 | |
| 5042 | static void |
| 5043 | print_mention_catch_exec (struct breakpoint *b) |
| 5044 | { |
| 5045 | printf_filtered (_("Catchpoint %d (exec)"), b->number); |
| 5046 | } |
| 5047 | |
| 5048 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
| 5049 | { |
| 5050 | insert_catch_exec, |
| 5051 | remove_catch_exec, |
| 5052 | breakpoint_hit_catch_exec, |
| 5053 | print_it_catch_exec, |
| 5054 | print_one_catch_exec, |
| 5055 | print_mention_catch_exec |
| 5056 | }; |
| 5057 | |
| 5058 | static int |
| 5059 | hw_breakpoint_used_count (void) |
| 5060 | { |
| 5061 | struct breakpoint *b; |
| 5062 | int i = 0; |
| 5063 | |
| 5064 | ALL_BREAKPOINTS (b) |
| 5065 | { |
| 5066 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
| 5067 | i++; |
| 5068 | } |
| 5069 | |
| 5070 | return i; |
| 5071 | } |
| 5072 | |
| 5073 | static int |
| 5074 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
| 5075 | { |
| 5076 | struct breakpoint *b; |
| 5077 | int i = 0; |
| 5078 | |
| 5079 | *other_type_used = 0; |
| 5080 | ALL_BREAKPOINTS (b) |
| 5081 | { |
| 5082 | if (breakpoint_enabled (b)) |
| 5083 | { |
| 5084 | if (b->type == type) |
| 5085 | i++; |
| 5086 | else if ((b->type == bp_hardware_watchpoint |
| 5087 | || b->type == bp_read_watchpoint |
| 5088 | || b->type == bp_access_watchpoint)) |
| 5089 | *other_type_used = 1; |
| 5090 | } |
| 5091 | } |
| 5092 | return i; |
| 5093 | } |
| 5094 | |
| 5095 | void |
| 5096 | disable_watchpoints_before_interactive_call_start (void) |
| 5097 | { |
| 5098 | struct breakpoint *b; |
| 5099 | |
| 5100 | ALL_BREAKPOINTS (b) |
| 5101 | { |
| 5102 | if (((b->type == bp_watchpoint) |
| 5103 | || (b->type == bp_hardware_watchpoint) |
| 5104 | || (b->type == bp_read_watchpoint) |
| 5105 | || (b->type == bp_access_watchpoint)) |
| 5106 | && breakpoint_enabled (b)) |
| 5107 | { |
| 5108 | b->enable_state = bp_call_disabled; |
| 5109 | update_global_location_list (0); |
| 5110 | } |
| 5111 | } |
| 5112 | } |
| 5113 | |
| 5114 | void |
| 5115 | enable_watchpoints_after_interactive_call_stop (void) |
| 5116 | { |
| 5117 | struct breakpoint *b; |
| 5118 | |
| 5119 | ALL_BREAKPOINTS (b) |
| 5120 | { |
| 5121 | if (((b->type == bp_watchpoint) |
| 5122 | || (b->type == bp_hardware_watchpoint) |
| 5123 | || (b->type == bp_read_watchpoint) |
| 5124 | || (b->type == bp_access_watchpoint)) |
| 5125 | && (b->enable_state == bp_call_disabled)) |
| 5126 | { |
| 5127 | b->enable_state = bp_enabled; |
| 5128 | update_global_location_list (1); |
| 5129 | } |
| 5130 | } |
| 5131 | } |
| 5132 | |
| 5133 | void |
| 5134 | disable_breakpoints_before_startup (void) |
| 5135 | { |
| 5136 | struct breakpoint *b; |
| 5137 | int found = 0; |
| 5138 | |
| 5139 | ALL_BREAKPOINTS (b) |
| 5140 | { |
| 5141 | if ((b->type == bp_breakpoint |
| 5142 | || b->type == bp_hardware_breakpoint) |
| 5143 | && breakpoint_enabled (b)) |
| 5144 | { |
| 5145 | b->enable_state = bp_startup_disabled; |
| 5146 | found = 1; |
| 5147 | } |
| 5148 | } |
| 5149 | |
| 5150 | if (found) |
| 5151 | update_global_location_list (0); |
| 5152 | |
| 5153 | executing_startup = 1; |
| 5154 | } |
| 5155 | |
| 5156 | void |
| 5157 | enable_breakpoints_after_startup (void) |
| 5158 | { |
| 5159 | struct breakpoint *b; |
| 5160 | int found = 0; |
| 5161 | |
| 5162 | executing_startup = 0; |
| 5163 | |
| 5164 | ALL_BREAKPOINTS (b) |
| 5165 | { |
| 5166 | if ((b->type == bp_breakpoint |
| 5167 | || b->type == bp_hardware_breakpoint) |
| 5168 | && b->enable_state == bp_startup_disabled) |
| 5169 | { |
| 5170 | b->enable_state = bp_enabled; |
| 5171 | found = 1; |
| 5172 | } |
| 5173 | } |
| 5174 | |
| 5175 | if (found) |
| 5176 | breakpoint_re_set (); |
| 5177 | } |
| 5178 | |
| 5179 | |
| 5180 | /* Set a breakpoint that will evaporate an end of command |
| 5181 | at address specified by SAL. |
| 5182 | Restrict it to frame FRAME if FRAME is nonzero. */ |
| 5183 | |
| 5184 | struct breakpoint * |
| 5185 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
| 5186 | struct frame_id frame_id, enum bptype type) |
| 5187 | { |
| 5188 | struct breakpoint *b; |
| 5189 | |
| 5190 | /* If FRAME_ID is valid, it should be a real frame, not an inlined |
| 5191 | one. */ |
| 5192 | gdb_assert (!frame_id_inlined_p (frame_id)); |
| 5193 | |
| 5194 | b = set_raw_breakpoint (gdbarch, sal, type); |
| 5195 | b->enable_state = bp_enabled; |
| 5196 | b->disposition = disp_donttouch; |
| 5197 | b->frame_id = frame_id; |
| 5198 | |
| 5199 | /* If we're debugging a multi-threaded program, then we |
| 5200 | want momentary breakpoints to be active in only a |
| 5201 | single thread of control. */ |
| 5202 | if (in_thread_list (inferior_ptid)) |
| 5203 | b->thread = pid_to_thread_id (inferior_ptid); |
| 5204 | |
| 5205 | update_global_location_list_nothrow (1); |
| 5206 | |
| 5207 | return b; |
| 5208 | } |
| 5209 | |
| 5210 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
| 5211 | ORIG is NULL. */ |
| 5212 | |
| 5213 | struct breakpoint * |
| 5214 | clone_momentary_breakpoint (struct breakpoint *orig) |
| 5215 | { |
| 5216 | struct breakpoint *copy; |
| 5217 | |
| 5218 | /* If there's nothing to clone, then return nothing. */ |
| 5219 | if (orig == NULL) |
| 5220 | return NULL; |
| 5221 | |
| 5222 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
| 5223 | copy->loc = allocate_bp_location (copy); |
| 5224 | set_breakpoint_location_function (copy->loc); |
| 5225 | |
| 5226 | copy->loc->gdbarch = orig->loc->gdbarch; |
| 5227 | copy->loc->requested_address = orig->loc->requested_address; |
| 5228 | copy->loc->address = orig->loc->address; |
| 5229 | copy->loc->section = orig->loc->section; |
| 5230 | |
| 5231 | if (orig->source_file == NULL) |
| 5232 | copy->source_file = NULL; |
| 5233 | else |
| 5234 | copy->source_file = xstrdup (orig->source_file); |
| 5235 | |
| 5236 | copy->line_number = orig->line_number; |
| 5237 | copy->frame_id = orig->frame_id; |
| 5238 | copy->thread = orig->thread; |
| 5239 | |
| 5240 | copy->enable_state = bp_enabled; |
| 5241 | copy->disposition = disp_donttouch; |
| 5242 | copy->number = internal_breakpoint_number--; |
| 5243 | |
| 5244 | update_global_location_list_nothrow (0); |
| 5245 | return copy; |
| 5246 | } |
| 5247 | |
| 5248 | struct breakpoint * |
| 5249 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 5250 | enum bptype type) |
| 5251 | { |
| 5252 | struct symtab_and_line sal; |
| 5253 | |
| 5254 | sal = find_pc_line (pc, 0); |
| 5255 | sal.pc = pc; |
| 5256 | sal.section = find_pc_overlay (pc); |
| 5257 | sal.explicit_pc = 1; |
| 5258 | |
| 5259 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
| 5260 | } |
| 5261 | \f |
| 5262 | |
| 5263 | /* Tell the user we have just set a breakpoint B. */ |
| 5264 | |
| 5265 | static void |
| 5266 | mention (struct breakpoint *b) |
| 5267 | { |
| 5268 | int say_where = 0; |
| 5269 | struct cleanup *ui_out_chain; |
| 5270 | struct value_print_options opts; |
| 5271 | |
| 5272 | get_user_print_options (&opts); |
| 5273 | |
| 5274 | /* FIXME: This is misplaced; mention() is called by things (like |
| 5275 | hitting a watchpoint) other than breakpoint creation. It should |
| 5276 | be possible to clean this up and at the same time replace the |
| 5277 | random calls to breakpoint_changed with this hook. */ |
| 5278 | observer_notify_breakpoint_created (b->number); |
| 5279 | |
| 5280 | if (b->ops != NULL && b->ops->print_mention != NULL) |
| 5281 | b->ops->print_mention (b); |
| 5282 | else |
| 5283 | switch (b->type) |
| 5284 | { |
| 5285 | case bp_none: |
| 5286 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
| 5287 | break; |
| 5288 | case bp_watchpoint: |
| 5289 | ui_out_text (uiout, "Watchpoint "); |
| 5290 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 5291 | ui_out_field_int (uiout, "number", b->number); |
| 5292 | ui_out_text (uiout, ": "); |
| 5293 | ui_out_field_string (uiout, "exp", b->exp_string); |
| 5294 | do_cleanups (ui_out_chain); |
| 5295 | break; |
| 5296 | case bp_hardware_watchpoint: |
| 5297 | ui_out_text (uiout, "Hardware watchpoint "); |
| 5298 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 5299 | ui_out_field_int (uiout, "number", b->number); |
| 5300 | ui_out_text (uiout, ": "); |
| 5301 | ui_out_field_string (uiout, "exp", b->exp_string); |
| 5302 | do_cleanups (ui_out_chain); |
| 5303 | break; |
| 5304 | case bp_read_watchpoint: |
| 5305 | ui_out_text (uiout, "Hardware read watchpoint "); |
| 5306 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
| 5307 | ui_out_field_int (uiout, "number", b->number); |
| 5308 | ui_out_text (uiout, ": "); |
| 5309 | ui_out_field_string (uiout, "exp", b->exp_string); |
| 5310 | do_cleanups (ui_out_chain); |
| 5311 | break; |
| 5312 | case bp_access_watchpoint: |
| 5313 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); |
| 5314 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
| 5315 | ui_out_field_int (uiout, "number", b->number); |
| 5316 | ui_out_text (uiout, ": "); |
| 5317 | ui_out_field_string (uiout, "exp", b->exp_string); |
| 5318 | do_cleanups (ui_out_chain); |
| 5319 | break; |
| 5320 | case bp_breakpoint: |
| 5321 | if (ui_out_is_mi_like_p (uiout)) |
| 5322 | { |
| 5323 | say_where = 0; |
| 5324 | break; |
| 5325 | } |
| 5326 | if (b->disposition == disp_del) |
| 5327 | printf_filtered (_("Temporary breakpoint")); |
| 5328 | else |
| 5329 | printf_filtered (_("Breakpoint")); |
| 5330 | printf_filtered (_(" %d"), b->number); |
| 5331 | say_where = 1; |
| 5332 | break; |
| 5333 | case bp_hardware_breakpoint: |
| 5334 | if (ui_out_is_mi_like_p (uiout)) |
| 5335 | { |
| 5336 | say_where = 0; |
| 5337 | break; |
| 5338 | } |
| 5339 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
| 5340 | say_where = 1; |
| 5341 | break; |
| 5342 | case bp_tracepoint: |
| 5343 | if (ui_out_is_mi_like_p (uiout)) |
| 5344 | { |
| 5345 | say_where = 0; |
| 5346 | break; |
| 5347 | } |
| 5348 | printf_filtered (_("Tracepoint")); |
| 5349 | printf_filtered (_(" %d"), b->number); |
| 5350 | say_where = 1; |
| 5351 | break; |
| 5352 | |
| 5353 | case bp_until: |
| 5354 | case bp_finish: |
| 5355 | case bp_longjmp: |
| 5356 | case bp_longjmp_resume: |
| 5357 | case bp_step_resume: |
| 5358 | case bp_call_dummy: |
| 5359 | case bp_watchpoint_scope: |
| 5360 | case bp_shlib_event: |
| 5361 | case bp_thread_event: |
| 5362 | case bp_overlay_event: |
| 5363 | case bp_jit_event: |
| 5364 | case bp_longjmp_master: |
| 5365 | break; |
| 5366 | } |
| 5367 | |
| 5368 | if (say_where) |
| 5369 | { |
| 5370 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
| 5371 | single string. */ |
| 5372 | if (b->loc == NULL) |
| 5373 | { |
| 5374 | printf_filtered (_(" (%s) pending."), b->addr_string); |
| 5375 | } |
| 5376 | else |
| 5377 | { |
| 5378 | if (opts.addressprint || b->source_file == NULL) |
| 5379 | { |
| 5380 | printf_filtered (" at "); |
| 5381 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
| 5382 | gdb_stdout); |
| 5383 | } |
| 5384 | if (b->source_file) |
| 5385 | printf_filtered (": file %s, line %d.", |
| 5386 | b->source_file, b->line_number); |
| 5387 | |
| 5388 | if (b->loc->next) |
| 5389 | { |
| 5390 | struct bp_location *loc = b->loc; |
| 5391 | int n = 0; |
| 5392 | for (; loc; loc = loc->next) |
| 5393 | ++n; |
| 5394 | printf_filtered (" (%d locations)", n); |
| 5395 | } |
| 5396 | |
| 5397 | } |
| 5398 | } |
| 5399 | if (ui_out_is_mi_like_p (uiout)) |
| 5400 | return; |
| 5401 | printf_filtered ("\n"); |
| 5402 | } |
| 5403 | \f |
| 5404 | |
| 5405 | static struct bp_location * |
| 5406 | add_location_to_breakpoint (struct breakpoint *b, |
| 5407 | const struct symtab_and_line *sal) |
| 5408 | { |
| 5409 | struct bp_location *loc, **tmp; |
| 5410 | |
| 5411 | loc = allocate_bp_location (b); |
| 5412 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
| 5413 | ; |
| 5414 | *tmp = loc; |
| 5415 | loc->gdbarch = get_sal_arch (*sal); |
| 5416 | if (!loc->gdbarch) |
| 5417 | loc->gdbarch = b->gdbarch; |
| 5418 | loc->requested_address = sal->pc; |
| 5419 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
| 5420 | loc->requested_address, b->type); |
| 5421 | loc->section = sal->section; |
| 5422 | |
| 5423 | set_breakpoint_location_function (loc); |
| 5424 | return loc; |
| 5425 | } |
| 5426 | \f |
| 5427 | |
| 5428 | /* Return 1 if LOC is pointing to a permanent breakpoint, |
| 5429 | return 0 otherwise. */ |
| 5430 | |
| 5431 | static int |
| 5432 | bp_loc_is_permanent (struct bp_location *loc) |
| 5433 | { |
| 5434 | int len; |
| 5435 | CORE_ADDR addr; |
| 5436 | const gdb_byte *brk; |
| 5437 | gdb_byte *target_mem; |
| 5438 | struct cleanup *cleanup; |
| 5439 | int retval = 0; |
| 5440 | |
| 5441 | gdb_assert (loc != NULL); |
| 5442 | |
| 5443 | addr = loc->address; |
| 5444 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
| 5445 | |
| 5446 | /* Software breakpoints unsupported? */ |
| 5447 | if (brk == NULL) |
| 5448 | return 0; |
| 5449 | |
| 5450 | target_mem = alloca (len); |
| 5451 | |
| 5452 | /* Enable the automatic memory restoration from breakpoints while |
| 5453 | we read the memory. Otherwise we could say about our temporary |
| 5454 | breakpoints they are permanent. */ |
| 5455 | cleanup = make_show_memory_breakpoints_cleanup (0); |
| 5456 | |
| 5457 | if (target_read_memory (loc->address, target_mem, len) == 0 |
| 5458 | && memcmp (target_mem, brk, len) == 0) |
| 5459 | retval = 1; |
| 5460 | |
| 5461 | do_cleanups (cleanup); |
| 5462 | |
| 5463 | return retval; |
| 5464 | } |
| 5465 | |
| 5466 | |
| 5467 | |
| 5468 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
| 5469 | as textual description of the location, and COND_STRING |
| 5470 | as condition expression. */ |
| 5471 | |
| 5472 | static void |
| 5473 | create_breakpoint (struct gdbarch *gdbarch, |
| 5474 | struct symtabs_and_lines sals, char *addr_string, |
| 5475 | char *cond_string, |
| 5476 | enum bptype type, enum bpdisp disposition, |
| 5477 | int thread, int task, int ignore_count, |
| 5478 | struct breakpoint_ops *ops, int from_tty, int enabled) |
| 5479 | { |
| 5480 | struct breakpoint *b = NULL; |
| 5481 | int i; |
| 5482 | |
| 5483 | if (type == bp_hardware_breakpoint) |
| 5484 | { |
| 5485 | int i = hw_breakpoint_used_count (); |
| 5486 | int target_resources_ok = |
| 5487 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 5488 | i + 1, 0); |
| 5489 | if (target_resources_ok == 0) |
| 5490 | error (_("No hardware breakpoint support in the target.")); |
| 5491 | else if (target_resources_ok < 0) |
| 5492 | error (_("Hardware breakpoints used exceeds limit.")); |
| 5493 | } |
| 5494 | |
| 5495 | for (i = 0; i < sals.nelts; ++i) |
| 5496 | { |
| 5497 | struct symtab_and_line sal = sals.sals[i]; |
| 5498 | struct bp_location *loc; |
| 5499 | |
| 5500 | if (from_tty) |
| 5501 | { |
| 5502 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 5503 | if (!loc_gdbarch) |
| 5504 | loc_gdbarch = gdbarch; |
| 5505 | |
| 5506 | describe_other_breakpoints (loc_gdbarch, |
| 5507 | sal.pc, sal.section, thread); |
| 5508 | } |
| 5509 | |
| 5510 | if (i == 0) |
| 5511 | { |
| 5512 | b = set_raw_breakpoint (gdbarch, sal, type); |
| 5513 | set_breakpoint_count (breakpoint_count + 1); |
| 5514 | b->number = breakpoint_count; |
| 5515 | b->thread = thread; |
| 5516 | b->task = task; |
| 5517 | |
| 5518 | b->cond_string = cond_string; |
| 5519 | b->ignore_count = ignore_count; |
| 5520 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 5521 | b->disposition = disposition; |
| 5522 | |
| 5523 | if (enabled && executing_startup |
| 5524 | && (b->type == bp_breakpoint |
| 5525 | || b->type == bp_hardware_breakpoint)) |
| 5526 | b->enable_state = bp_startup_disabled; |
| 5527 | |
| 5528 | loc = b->loc; |
| 5529 | } |
| 5530 | else |
| 5531 | { |
| 5532 | loc = add_location_to_breakpoint (b, &sal); |
| 5533 | } |
| 5534 | |
| 5535 | if (bp_loc_is_permanent (loc)) |
| 5536 | make_breakpoint_permanent (b); |
| 5537 | |
| 5538 | if (b->cond_string) |
| 5539 | { |
| 5540 | char *arg = b->cond_string; |
| 5541 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
| 5542 | if (*arg) |
| 5543 | error (_("Garbage %s follows condition"), arg); |
| 5544 | } |
| 5545 | } |
| 5546 | |
| 5547 | if (addr_string) |
| 5548 | b->addr_string = addr_string; |
| 5549 | else |
| 5550 | /* addr_string has to be used or breakpoint_re_set will delete |
| 5551 | me. */ |
| 5552 | b->addr_string |
| 5553 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); |
| 5554 | |
| 5555 | b->ops = ops; |
| 5556 | mention (b); |
| 5557 | } |
| 5558 | |
| 5559 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
| 5560 | elements to fill the void space. */ |
| 5561 | static void |
| 5562 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) |
| 5563 | { |
| 5564 | int i = index_to_remove+1; |
| 5565 | int last_index = sal->nelts-1; |
| 5566 | |
| 5567 | for (;i <= last_index; ++i) |
| 5568 | sal->sals[i-1] = sal->sals[i]; |
| 5569 | |
| 5570 | --(sal->nelts); |
| 5571 | } |
| 5572 | |
| 5573 | /* If appropriate, obtains all sals that correspond |
| 5574 | to the same file and line as SAL. This is done |
| 5575 | only if SAL does not have explicit PC and has |
| 5576 | line and file information. If we got just a single |
| 5577 | expanded sal, return the original. |
| 5578 | |
| 5579 | Otherwise, if SAL.explicit_line is not set, filter out |
| 5580 | all sals for which the name of enclosing function |
| 5581 | is different from SAL. This makes sure that if we have |
| 5582 | breakpoint originally set in template instantiation, say |
| 5583 | foo<int>(), we won't expand SAL to locations at the same |
| 5584 | line in all existing instantiations of 'foo'. |
| 5585 | |
| 5586 | */ |
| 5587 | static struct symtabs_and_lines |
| 5588 | expand_line_sal_maybe (struct symtab_and_line sal) |
| 5589 | { |
| 5590 | struct symtabs_and_lines expanded; |
| 5591 | CORE_ADDR original_pc = sal.pc; |
| 5592 | char *original_function = NULL; |
| 5593 | int found; |
| 5594 | int i; |
| 5595 | |
| 5596 | /* If we have explicit pc, don't expand. |
| 5597 | If we have no line number, we can't expand. */ |
| 5598 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) |
| 5599 | { |
| 5600 | expanded.nelts = 1; |
| 5601 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); |
| 5602 | expanded.sals[0] = sal; |
| 5603 | return expanded; |
| 5604 | } |
| 5605 | |
| 5606 | sal.pc = 0; |
| 5607 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
| 5608 | |
| 5609 | expanded = expand_line_sal (sal); |
| 5610 | if (expanded.nelts == 1) |
| 5611 | { |
| 5612 | /* We had one sal, we got one sal. Without futher |
| 5613 | processing, just return the original sal. */ |
| 5614 | xfree (expanded.sals); |
| 5615 | expanded.nelts = 1; |
| 5616 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); |
| 5617 | sal.pc = original_pc; |
| 5618 | expanded.sals[0] = sal; |
| 5619 | return expanded; |
| 5620 | } |
| 5621 | |
| 5622 | if (!sal.explicit_line) |
| 5623 | { |
| 5624 | CORE_ADDR func_addr, func_end; |
| 5625 | for (i = 0; i < expanded.nelts; ++i) |
| 5626 | { |
| 5627 | CORE_ADDR pc = expanded.sals[i].pc; |
| 5628 | char *this_function; |
| 5629 | if (find_pc_partial_function (pc, &this_function, |
| 5630 | &func_addr, &func_end)) |
| 5631 | { |
| 5632 | if (this_function |
| 5633 | && strcmp (this_function, original_function) != 0) |
| 5634 | { |
| 5635 | remove_sal (&expanded, i); |
| 5636 | --i; |
| 5637 | } |
| 5638 | else if (func_addr == pc) |
| 5639 | { |
| 5640 | /* We're at beginning of a function, and should |
| 5641 | skip prologue. */ |
| 5642 | struct symbol *sym = find_pc_function (pc); |
| 5643 | if (sym) |
| 5644 | expanded.sals[i] = find_function_start_sal (sym, 1); |
| 5645 | else |
| 5646 | { |
| 5647 | /* Since find_pc_partial_function returned true, |
| 5648 | we should really always find the section here. */ |
| 5649 | struct obj_section *section = find_pc_section (pc); |
| 5650 | if (section) |
| 5651 | { |
| 5652 | struct gdbarch *gdbarch |
| 5653 | = get_objfile_arch (section->objfile); |
| 5654 | expanded.sals[i].pc |
| 5655 | = gdbarch_skip_prologue (gdbarch, pc); |
| 5656 | } |
| 5657 | } |
| 5658 | } |
| 5659 | } |
| 5660 | } |
| 5661 | } |
| 5662 | else |
| 5663 | { |
| 5664 | for (i = 0; i < expanded.nelts; ++i) |
| 5665 | { |
| 5666 | /* If this SAL corresponds to a breakpoint inserted using a |
| 5667 | line number, then skip the function prologue if necessary. */ |
| 5668 | skip_prologue_sal (&expanded.sals[i]); |
| 5669 | } |
| 5670 | } |
| 5671 | |
| 5672 | |
| 5673 | if (expanded.nelts <= 1) |
| 5674 | { |
| 5675 | /* This is un ugly workaround. If we get zero |
| 5676 | expanded sals then something is really wrong. |
| 5677 | Fix that by returnign the original sal. */ |
| 5678 | xfree (expanded.sals); |
| 5679 | expanded.nelts = 1; |
| 5680 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); |
| 5681 | sal.pc = original_pc; |
| 5682 | expanded.sals[0] = sal; |
| 5683 | return expanded; |
| 5684 | } |
| 5685 | |
| 5686 | if (original_pc) |
| 5687 | { |
| 5688 | found = 0; |
| 5689 | for (i = 0; i < expanded.nelts; ++i) |
| 5690 | if (expanded.sals[i].pc == original_pc) |
| 5691 | { |
| 5692 | found = 1; |
| 5693 | break; |
| 5694 | } |
| 5695 | gdb_assert (found); |
| 5696 | } |
| 5697 | |
| 5698 | return expanded; |
| 5699 | } |
| 5700 | |
| 5701 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
| 5702 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] |
| 5703 | value. COND_STRING, if not NULL, specified the condition to be |
| 5704 | used for all breakpoints. Essentially the only case where |
| 5705 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded |
| 5706 | function. In that case, it's still not possible to specify |
| 5707 | separate conditions for different overloaded functions, so |
| 5708 | we take just a single condition string. |
| 5709 | |
| 5710 | NOTE: If the function succeeds, the caller is expected to cleanup |
| 5711 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
| 5712 | array contents). If the function fails (error() is called), the |
| 5713 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, |
| 5714 | COND and SALS arrays and each of those arrays contents. */ |
| 5715 | |
| 5716 | static void |
| 5717 | create_breakpoints (struct gdbarch *gdbarch, |
| 5718 | struct symtabs_and_lines sals, char **addr_string, |
| 5719 | char *cond_string, |
| 5720 | enum bptype type, enum bpdisp disposition, |
| 5721 | int thread, int task, int ignore_count, |
| 5722 | struct breakpoint_ops *ops, int from_tty, |
| 5723 | int enabled) |
| 5724 | { |
| 5725 | int i; |
| 5726 | for (i = 0; i < sals.nelts; ++i) |
| 5727 | { |
| 5728 | struct symtabs_and_lines expanded = |
| 5729 | expand_line_sal_maybe (sals.sals[i]); |
| 5730 | |
| 5731 | create_breakpoint (gdbarch, expanded, addr_string[i], |
| 5732 | cond_string, type, disposition, |
| 5733 | thread, task, ignore_count, ops, from_tty, enabled); |
| 5734 | } |
| 5735 | } |
| 5736 | |
| 5737 | /* Parse ARG which is assumed to be a SAL specification possibly |
| 5738 | followed by conditionals. On return, SALS contains an array of SAL |
| 5739 | addresses found. ADDR_STRING contains a vector of (canonical) |
| 5740 | address strings. ARG points to the end of the SAL. */ |
| 5741 | |
| 5742 | static void |
| 5743 | parse_breakpoint_sals (char **address, |
| 5744 | struct symtabs_and_lines *sals, |
| 5745 | char ***addr_string, |
| 5746 | int *not_found_ptr) |
| 5747 | { |
| 5748 | char *addr_start = *address; |
| 5749 | *addr_string = NULL; |
| 5750 | /* If no arg given, or if first arg is 'if ', use the default |
| 5751 | breakpoint. */ |
| 5752 | if ((*address) == NULL |
| 5753 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) |
| 5754 | { |
| 5755 | if (default_breakpoint_valid) |
| 5756 | { |
| 5757 | struct symtab_and_line sal; |
| 5758 | init_sal (&sal); /* initialize to zeroes */ |
| 5759 | sals->sals = (struct symtab_and_line *) |
| 5760 | xmalloc (sizeof (struct symtab_and_line)); |
| 5761 | sal.pc = default_breakpoint_address; |
| 5762 | sal.line = default_breakpoint_line; |
| 5763 | sal.symtab = default_breakpoint_symtab; |
| 5764 | sal.section = find_pc_overlay (sal.pc); |
| 5765 | |
| 5766 | /* "break" without arguments is equivalent to "break *PC" where PC is |
| 5767 | the default_breakpoint_address. So make sure to set |
| 5768 | sal.explicit_pc to prevent GDB from trying to expand the list of |
| 5769 | sals to include all other instances with the same symtab and line. |
| 5770 | */ |
| 5771 | sal.explicit_pc = 1; |
| 5772 | |
| 5773 | sals->sals[0] = sal; |
| 5774 | sals->nelts = 1; |
| 5775 | } |
| 5776 | else |
| 5777 | error (_("No default breakpoint address now.")); |
| 5778 | } |
| 5779 | else |
| 5780 | { |
| 5781 | /* Force almost all breakpoints to be in terms of the |
| 5782 | current_source_symtab (which is decode_line_1's default). This |
| 5783 | should produce the results we want almost all of the time while |
| 5784 | leaving default_breakpoint_* alone. |
| 5785 | ObjC: However, don't match an Objective-C method name which |
| 5786 | may have a '+' or '-' succeeded by a '[' */ |
| 5787 | |
| 5788 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
| 5789 | |
| 5790 | if (default_breakpoint_valid |
| 5791 | && (!cursal.symtab |
| 5792 | || ((strchr ("+-", (*address)[0]) != NULL) |
| 5793 | && ((*address)[1] != '[')))) |
| 5794 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
| 5795 | default_breakpoint_line, addr_string, |
| 5796 | not_found_ptr); |
| 5797 | else |
| 5798 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
| 5799 | addr_string, not_found_ptr); |
| 5800 | } |
| 5801 | /* For any SAL that didn't have a canonical string, fill one in. */ |
| 5802 | if (sals->nelts > 0 && *addr_string == NULL) |
| 5803 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); |
| 5804 | if (addr_start != (*address)) |
| 5805 | { |
| 5806 | int i; |
| 5807 | for (i = 0; i < sals->nelts; i++) |
| 5808 | { |
| 5809 | /* Add the string if not present. */ |
| 5810 | if ((*addr_string)[i] == NULL) |
| 5811 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); |
| 5812 | } |
| 5813 | } |
| 5814 | } |
| 5815 | |
| 5816 | |
| 5817 | /* Convert each SAL into a real PC. Verify that the PC can be |
| 5818 | inserted as a breakpoint. If it can't throw an error. */ |
| 5819 | |
| 5820 | static void |
| 5821 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
| 5822 | char *address) |
| 5823 | { |
| 5824 | int i; |
| 5825 | for (i = 0; i < sals->nelts; i++) |
| 5826 | resolve_sal_pc (&sals->sals[i]); |
| 5827 | } |
| 5828 | |
| 5829 | static void |
| 5830 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
| 5831 | { |
| 5832 | struct captured_parse_breakpoint_args *args = data; |
| 5833 | |
| 5834 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, |
| 5835 | args->not_found_ptr); |
| 5836 | } |
| 5837 | |
| 5838 | /* Given TOK, a string specification of condition and thread, as |
| 5839 | accepted by the 'break' command, extract the condition |
| 5840 | string and thread number and set *COND_STRING and *THREAD. |
| 5841 | PC identifies the context at which the condition should be parsed. |
| 5842 | If no condition is found, *COND_STRING is set to NULL. |
| 5843 | If no thread is found, *THREAD is set to -1. */ |
| 5844 | static void |
| 5845 | find_condition_and_thread (char *tok, CORE_ADDR pc, |
| 5846 | char **cond_string, int *thread, int *task) |
| 5847 | { |
| 5848 | *cond_string = NULL; |
| 5849 | *thread = -1; |
| 5850 | while (tok && *tok) |
| 5851 | { |
| 5852 | char *end_tok; |
| 5853 | int toklen; |
| 5854 | char *cond_start = NULL; |
| 5855 | char *cond_end = NULL; |
| 5856 | while (*tok == ' ' || *tok == '\t') |
| 5857 | tok++; |
| 5858 | |
| 5859 | end_tok = tok; |
| 5860 | |
| 5861 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') |
| 5862 | end_tok++; |
| 5863 | |
| 5864 | toklen = end_tok - tok; |
| 5865 | |
| 5866 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 5867 | { |
| 5868 | struct expression *expr; |
| 5869 | |
| 5870 | tok = cond_start = end_tok + 1; |
| 5871 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
| 5872 | xfree (expr); |
| 5873 | cond_end = tok; |
| 5874 | *cond_string = savestring (cond_start, |
| 5875 | cond_end - cond_start); |
| 5876 | } |
| 5877 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 5878 | { |
| 5879 | char *tmptok; |
| 5880 | |
| 5881 | tok = end_tok + 1; |
| 5882 | tmptok = tok; |
| 5883 | *thread = strtol (tok, &tok, 0); |
| 5884 | if (tok == tmptok) |
| 5885 | error (_("Junk after thread keyword.")); |
| 5886 | if (!valid_thread_id (*thread)) |
| 5887 | error (_("Unknown thread %d."), *thread); |
| 5888 | } |
| 5889 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
| 5890 | { |
| 5891 | char *tmptok; |
| 5892 | |
| 5893 | tok = end_tok + 1; |
| 5894 | tmptok = tok; |
| 5895 | *task = strtol (tok, &tok, 0); |
| 5896 | if (tok == tmptok) |
| 5897 | error (_("Junk after task keyword.")); |
| 5898 | if (!valid_task_id (*task)) |
| 5899 | error (_("Unknown task %d\n"), *task); |
| 5900 | } |
| 5901 | else |
| 5902 | error (_("Junk at end of arguments.")); |
| 5903 | } |
| 5904 | } |
| 5905 | |
| 5906 | /* Set a breakpoint. This function is shared between |
| 5907 | CLI and MI functions for setting a breakpoint. |
| 5908 | This function has two major modes of operations, |
| 5909 | selected by the PARSE_CONDITION_AND_THREAD parameter. |
| 5910 | If non-zero, the function will parse arg, extracting |
| 5911 | breakpoint location, address and thread. Otherwise, |
| 5912 | ARG is just the location of breakpoint, with condition |
| 5913 | and thread specified by the COND_STRING and THREAD |
| 5914 | parameters. */ |
| 5915 | |
| 5916 | static void |
| 5917 | break_command_really (struct gdbarch *gdbarch, |
| 5918 | char *arg, char *cond_string, int thread, |
| 5919 | int parse_condition_and_thread, |
| 5920 | int tempflag, int hardwareflag, int traceflag, |
| 5921 | int ignore_count, |
| 5922 | enum auto_boolean pending_break_support, |
| 5923 | struct breakpoint_ops *ops, |
| 5924 | int from_tty, |
| 5925 | int enabled) |
| 5926 | { |
| 5927 | struct gdb_exception e; |
| 5928 | struct symtabs_and_lines sals; |
| 5929 | struct symtab_and_line pending_sal; |
| 5930 | char *copy_arg; |
| 5931 | char *err_msg; |
| 5932 | char *addr_start = arg; |
| 5933 | char **addr_string; |
| 5934 | struct cleanup *old_chain; |
| 5935 | struct cleanup *bkpt_chain = NULL; |
| 5936 | struct captured_parse_breakpoint_args parse_args; |
| 5937 | int i; |
| 5938 | int pending = 0; |
| 5939 | int not_found = 0; |
| 5940 | enum bptype type_wanted; |
| 5941 | int task = 0; |
| 5942 | |
| 5943 | sals.sals = NULL; |
| 5944 | sals.nelts = 0; |
| 5945 | addr_string = NULL; |
| 5946 | |
| 5947 | parse_args.arg_p = &arg; |
| 5948 | parse_args.sals_p = &sals; |
| 5949 | parse_args.addr_string_p = &addr_string; |
| 5950 | parse_args.not_found_ptr = ¬_found; |
| 5951 | |
| 5952 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
| 5953 | &parse_args, RETURN_MASK_ALL); |
| 5954 | |
| 5955 | /* If caller is interested in rc value from parse, set value. */ |
| 5956 | switch (e.reason) |
| 5957 | { |
| 5958 | case RETURN_QUIT: |
| 5959 | throw_exception (e); |
| 5960 | case RETURN_ERROR: |
| 5961 | switch (e.error) |
| 5962 | { |
| 5963 | case NOT_FOUND_ERROR: |
| 5964 | |
| 5965 | /* If pending breakpoint support is turned off, throw |
| 5966 | error. */ |
| 5967 | |
| 5968 | if (pending_break_support == AUTO_BOOLEAN_FALSE) |
| 5969 | throw_exception (e); |
| 5970 | |
| 5971 | exception_print (gdb_stderr, e); |
| 5972 | |
| 5973 | /* If pending breakpoint support is auto query and the user |
| 5974 | selects no, then simply return the error code. */ |
| 5975 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
| 5976 | && !nquery ("Make breakpoint pending on future shared library load? ")) |
| 5977 | return; |
| 5978 | |
| 5979 | /* At this point, either the user was queried about setting |
| 5980 | a pending breakpoint and selected yes, or pending |
| 5981 | breakpoint behavior is on and thus a pending breakpoint |
| 5982 | is defaulted on behalf of the user. */ |
| 5983 | copy_arg = xstrdup (addr_start); |
| 5984 | addr_string = ©_arg; |
| 5985 | sals.nelts = 1; |
| 5986 | sals.sals = &pending_sal; |
| 5987 | pending_sal.pc = 0; |
| 5988 | pending = 1; |
| 5989 | break; |
| 5990 | default: |
| 5991 | throw_exception (e); |
| 5992 | } |
| 5993 | default: |
| 5994 | if (!sals.nelts) |
| 5995 | return; |
| 5996 | } |
| 5997 | |
| 5998 | /* Create a chain of things that always need to be cleaned up. */ |
| 5999 | old_chain = make_cleanup (null_cleanup, 0); |
| 6000 | |
| 6001 | if (!pending) |
| 6002 | { |
| 6003 | /* Make sure that all storage allocated to SALS gets freed. */ |
| 6004 | make_cleanup (xfree, sals.sals); |
| 6005 | |
| 6006 | /* Cleanup the addr_string array but not its contents. */ |
| 6007 | make_cleanup (xfree, addr_string); |
| 6008 | } |
| 6009 | |
| 6010 | /* ----------------------------- SNIP ----------------------------- |
| 6011 | Anything added to the cleanup chain beyond this point is assumed |
| 6012 | to be part of a breakpoint. If the breakpoint create succeeds |
| 6013 | then the memory is not reclaimed. */ |
| 6014 | bkpt_chain = make_cleanup (null_cleanup, 0); |
| 6015 | |
| 6016 | /* Mark the contents of the addr_string for cleanup. These go on |
| 6017 | the bkpt_chain and only occur if the breakpoint create fails. */ |
| 6018 | for (i = 0; i < sals.nelts; i++) |
| 6019 | { |
| 6020 | if (addr_string[i] != NULL) |
| 6021 | make_cleanup (xfree, addr_string[i]); |
| 6022 | } |
| 6023 | |
| 6024 | /* Resolve all line numbers to PC's and verify that the addresses |
| 6025 | are ok for the target. */ |
| 6026 | if (!pending) |
| 6027 | breakpoint_sals_to_pc (&sals, addr_start); |
| 6028 | |
| 6029 | type_wanted = (traceflag |
| 6030 | ? bp_tracepoint |
| 6031 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
| 6032 | |
| 6033 | /* Verify that condition can be parsed, before setting any |
| 6034 | breakpoints. Allocate a separate condition expression for each |
| 6035 | breakpoint. */ |
| 6036 | if (!pending) |
| 6037 | { |
| 6038 | if (parse_condition_and_thread) |
| 6039 | { |
| 6040 | /* Here we only parse 'arg' to separate condition |
| 6041 | from thread number, so parsing in context of first |
| 6042 | sal is OK. When setting the breakpoint we'll |
| 6043 | re-parse it in context of each sal. */ |
| 6044 | cond_string = NULL; |
| 6045 | thread = -1; |
| 6046 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
| 6047 | &thread, &task); |
| 6048 | if (cond_string) |
| 6049 | make_cleanup (xfree, cond_string); |
| 6050 | } |
| 6051 | else |
| 6052 | { |
| 6053 | /* Create a private copy of condition string. */ |
| 6054 | if (cond_string) |
| 6055 | { |
| 6056 | cond_string = xstrdup (cond_string); |
| 6057 | make_cleanup (xfree, cond_string); |
| 6058 | } |
| 6059 | } |
| 6060 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
| 6061 | tempflag ? disp_del : disp_donttouch, |
| 6062 | thread, task, ignore_count, ops, from_tty, enabled); |
| 6063 | } |
| 6064 | else |
| 6065 | { |
| 6066 | struct symtab_and_line sal = {0}; |
| 6067 | struct breakpoint *b; |
| 6068 | |
| 6069 | make_cleanup (xfree, copy_arg); |
| 6070 | |
| 6071 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
| 6072 | set_breakpoint_count (breakpoint_count + 1); |
| 6073 | b->number = breakpoint_count; |
| 6074 | b->thread = -1; |
| 6075 | b->addr_string = addr_string[0]; |
| 6076 | b->cond_string = NULL; |
| 6077 | b->ignore_count = ignore_count; |
| 6078 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 6079 | b->condition_not_parsed = 1; |
| 6080 | b->ops = ops; |
| 6081 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 6082 | |
| 6083 | if (enabled && executing_startup |
| 6084 | && (b->type == bp_breakpoint |
| 6085 | || b->type == bp_hardware_breakpoint)) |
| 6086 | b->enable_state = bp_startup_disabled; |
| 6087 | |
| 6088 | mention (b); |
| 6089 | } |
| 6090 | |
| 6091 | if (sals.nelts > 1) |
| 6092 | warning (_("Multiple breakpoints were set.\n" |
| 6093 | "Use the \"delete\" command to delete unwanted breakpoints.")); |
| 6094 | /* That's it. Discard the cleanups for data inserted into the |
| 6095 | breakpoint. */ |
| 6096 | discard_cleanups (bkpt_chain); |
| 6097 | /* But cleanup everything else. */ |
| 6098 | do_cleanups (old_chain); |
| 6099 | |
| 6100 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
| 6101 | update_global_location_list (1); |
| 6102 | } |
| 6103 | |
| 6104 | /* Set a breakpoint. |
| 6105 | ARG is a string describing breakpoint address, |
| 6106 | condition, and thread. |
| 6107 | FLAG specifies if a breakpoint is hardware on, |
| 6108 | and if breakpoint is temporary, using BP_HARDWARE_FLAG |
| 6109 | and BP_TEMPFLAG. */ |
| 6110 | |
| 6111 | static void |
| 6112 | break_command_1 (char *arg, int flag, int from_tty) |
| 6113 | { |
| 6114 | int hardwareflag = flag & BP_HARDWAREFLAG; |
| 6115 | int tempflag = flag & BP_TEMPFLAG; |
| 6116 | |
| 6117 | break_command_really (get_current_arch (), |
| 6118 | arg, |
| 6119 | NULL, 0, 1 /* parse arg */, |
| 6120 | tempflag, hardwareflag, 0 /* traceflag */, |
| 6121 | 0 /* Ignore count */, |
| 6122 | pending_break_support, |
| 6123 | NULL /* breakpoint_ops */, |
| 6124 | from_tty, |
| 6125 | 1 /* enabled */); |
| 6126 | } |
| 6127 | |
| 6128 | |
| 6129 | void |
| 6130 | set_breakpoint (struct gdbarch *gdbarch, |
| 6131 | char *address, char *condition, |
| 6132 | int hardwareflag, int tempflag, |
| 6133 | int thread, int ignore_count, |
| 6134 | int pending, int enabled) |
| 6135 | { |
| 6136 | break_command_really (gdbarch, |
| 6137 | address, condition, thread, |
| 6138 | 0 /* condition and thread are valid. */, |
| 6139 | tempflag, hardwareflag, 0 /* traceflag */, |
| 6140 | ignore_count, |
| 6141 | pending |
| 6142 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, |
| 6143 | NULL, 0, enabled); |
| 6144 | } |
| 6145 | |
| 6146 | /* Adjust SAL to the first instruction past the function prologue. |
| 6147 | The end of the prologue is determined using the line table from |
| 6148 | the debugging information. explicit_pc and explicit_line are |
| 6149 | not modified. |
| 6150 | |
| 6151 | If SAL is already past the prologue, then do nothing. */ |
| 6152 | |
| 6153 | static void |
| 6154 | skip_prologue_sal (struct symtab_and_line *sal) |
| 6155 | { |
| 6156 | struct symbol *sym = find_pc_function (sal->pc); |
| 6157 | struct symtab_and_line start_sal; |
| 6158 | |
| 6159 | if (sym == NULL) |
| 6160 | return; |
| 6161 | |
| 6162 | start_sal = find_function_start_sal (sym, 1); |
| 6163 | if (sal->pc < start_sal.pc) |
| 6164 | { |
| 6165 | start_sal.explicit_line = sal->explicit_line; |
| 6166 | start_sal.explicit_pc = sal->explicit_pc; |
| 6167 | *sal = start_sal; |
| 6168 | } |
| 6169 | } |
| 6170 | |
| 6171 | /* Helper function for break_command_1 and disassemble_command. */ |
| 6172 | |
| 6173 | void |
| 6174 | resolve_sal_pc (struct symtab_and_line *sal) |
| 6175 | { |
| 6176 | CORE_ADDR pc; |
| 6177 | |
| 6178 | if (sal->pc == 0 && sal->symtab != NULL) |
| 6179 | { |
| 6180 | if (!find_line_pc (sal->symtab, sal->line, &pc)) |
| 6181 | error (_("No line %d in file \"%s\"."), |
| 6182 | sal->line, sal->symtab->filename); |
| 6183 | sal->pc = pc; |
| 6184 | |
| 6185 | /* If this SAL corresponds to a breakpoint inserted using |
| 6186 | a line number, then skip the function prologue if necessary. */ |
| 6187 | if (sal->explicit_line) |
| 6188 | { |
| 6189 | /* Preserve the original line number. */ |
| 6190 | int saved_line = sal->line; |
| 6191 | skip_prologue_sal (sal); |
| 6192 | sal->line = saved_line; |
| 6193 | } |
| 6194 | } |
| 6195 | |
| 6196 | if (sal->section == 0 && sal->symtab != NULL) |
| 6197 | { |
| 6198 | struct blockvector *bv; |
| 6199 | struct block *b; |
| 6200 | struct symbol *sym; |
| 6201 | |
| 6202 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
| 6203 | if (bv != NULL) |
| 6204 | { |
| 6205 | sym = block_linkage_function (b); |
| 6206 | if (sym != NULL) |
| 6207 | { |
| 6208 | fixup_symbol_section (sym, sal->symtab->objfile); |
| 6209 | sal->section = SYMBOL_OBJ_SECTION (sym); |
| 6210 | } |
| 6211 | else |
| 6212 | { |
| 6213 | /* It really is worthwhile to have the section, so we'll just |
| 6214 | have to look harder. This case can be executed if we have |
| 6215 | line numbers but no functions (as can happen in assembly |
| 6216 | source). */ |
| 6217 | |
| 6218 | struct minimal_symbol *msym; |
| 6219 | |
| 6220 | msym = lookup_minimal_symbol_by_pc (sal->pc); |
| 6221 | if (msym) |
| 6222 | sal->section = SYMBOL_OBJ_SECTION (msym); |
| 6223 | } |
| 6224 | } |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | void |
| 6229 | break_command (char *arg, int from_tty) |
| 6230 | { |
| 6231 | break_command_1 (arg, 0, from_tty); |
| 6232 | } |
| 6233 | |
| 6234 | void |
| 6235 | tbreak_command (char *arg, int from_tty) |
| 6236 | { |
| 6237 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
| 6238 | } |
| 6239 | |
| 6240 | static void |
| 6241 | hbreak_command (char *arg, int from_tty) |
| 6242 | { |
| 6243 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
| 6244 | } |
| 6245 | |
| 6246 | static void |
| 6247 | thbreak_command (char *arg, int from_tty) |
| 6248 | { |
| 6249 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
| 6250 | } |
| 6251 | |
| 6252 | static void |
| 6253 | stop_command (char *arg, int from_tty) |
| 6254 | { |
| 6255 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
| 6256 | Usage: stop in <function | address>\n\ |
| 6257 | stop at <line>\n")); |
| 6258 | } |
| 6259 | |
| 6260 | static void |
| 6261 | stopin_command (char *arg, int from_tty) |
| 6262 | { |
| 6263 | int badInput = 0; |
| 6264 | |
| 6265 | if (arg == (char *) NULL) |
| 6266 | badInput = 1; |
| 6267 | else if (*arg != '*') |
| 6268 | { |
| 6269 | char *argptr = arg; |
| 6270 | int hasColon = 0; |
| 6271 | |
| 6272 | /* look for a ':'. If this is a line number specification, then |
| 6273 | say it is bad, otherwise, it should be an address or |
| 6274 | function/method name */ |
| 6275 | while (*argptr && !hasColon) |
| 6276 | { |
| 6277 | hasColon = (*argptr == ':'); |
| 6278 | argptr++; |
| 6279 | } |
| 6280 | |
| 6281 | if (hasColon) |
| 6282 | badInput = (*argptr != ':'); /* Not a class::method */ |
| 6283 | else |
| 6284 | badInput = isdigit (*arg); /* a simple line number */ |
| 6285 | } |
| 6286 | |
| 6287 | if (badInput) |
| 6288 | printf_filtered (_("Usage: stop in <function | address>\n")); |
| 6289 | else |
| 6290 | break_command_1 (arg, 0, from_tty); |
| 6291 | } |
| 6292 | |
| 6293 | static void |
| 6294 | stopat_command (char *arg, int from_tty) |
| 6295 | { |
| 6296 | int badInput = 0; |
| 6297 | |
| 6298 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
| 6299 | badInput = 1; |
| 6300 | else |
| 6301 | { |
| 6302 | char *argptr = arg; |
| 6303 | int hasColon = 0; |
| 6304 | |
| 6305 | /* look for a ':'. If there is a '::' then get out, otherwise |
| 6306 | it is probably a line number. */ |
| 6307 | while (*argptr && !hasColon) |
| 6308 | { |
| 6309 | hasColon = (*argptr == ':'); |
| 6310 | argptr++; |
| 6311 | } |
| 6312 | |
| 6313 | if (hasColon) |
| 6314 | badInput = (*argptr == ':'); /* we have class::method */ |
| 6315 | else |
| 6316 | badInput = !isdigit (*arg); /* not a line number */ |
| 6317 | } |
| 6318 | |
| 6319 | if (badInput) |
| 6320 | printf_filtered (_("Usage: stop at <line>\n")); |
| 6321 | else |
| 6322 | break_command_1 (arg, 0, from_tty); |
| 6323 | } |
| 6324 | |
| 6325 | /* accessflag: hw_write: watch write, |
| 6326 | hw_read: watch read, |
| 6327 | hw_access: watch access (read or write) */ |
| 6328 | static void |
| 6329 | watch_command_1 (char *arg, int accessflag, int from_tty) |
| 6330 | { |
| 6331 | struct gdbarch *gdbarch = get_current_arch (); |
| 6332 | struct breakpoint *b, *scope_breakpoint = NULL; |
| 6333 | struct symtab_and_line sal; |
| 6334 | struct expression *exp; |
| 6335 | struct block *exp_valid_block; |
| 6336 | struct value *val, *mark; |
| 6337 | struct frame_info *frame; |
| 6338 | char *exp_start = NULL; |
| 6339 | char *exp_end = NULL; |
| 6340 | char *tok, *id_tok_start, *end_tok; |
| 6341 | int toklen; |
| 6342 | char *cond_start = NULL; |
| 6343 | char *cond_end = NULL; |
| 6344 | struct expression *cond = NULL; |
| 6345 | int i, other_type_used, target_resources_ok = 0; |
| 6346 | enum bptype bp_type; |
| 6347 | int mem_cnt = 0; |
| 6348 | int thread = -1; |
| 6349 | |
| 6350 | init_sal (&sal); /* initialize to zeroes */ |
| 6351 | |
| 6352 | /* Make sure that we actually have parameters to parse. */ |
| 6353 | if (arg != NULL && arg[0] != '\0') |
| 6354 | { |
| 6355 | toklen = strlen (arg); /* Size of argument list. */ |
| 6356 | |
| 6357 | /* Points tok to the end of the argument list. */ |
| 6358 | tok = arg + toklen - 1; |
| 6359 | |
| 6360 | /* Go backwards in the parameters list. Skip the last parameter. |
| 6361 | If we're expecting a 'thread <thread_num>' parameter, this should |
| 6362 | be the thread identifier. */ |
| 6363 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 6364 | tok--; |
| 6365 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 6366 | tok--; |
| 6367 | |
| 6368 | /* Points end_tok to the beginning of the last token. */ |
| 6369 | id_tok_start = tok + 1; |
| 6370 | |
| 6371 | /* Go backwards in the parameters list. Skip one more parameter. |
| 6372 | If we're expecting a 'thread <thread_num>' parameter, we should |
| 6373 | reach a "thread" token. */ |
| 6374 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 6375 | tok--; |
| 6376 | |
| 6377 | end_tok = tok; |
| 6378 | |
| 6379 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 6380 | tok--; |
| 6381 | |
| 6382 | /* Move the pointer forward to skip the whitespace and |
| 6383 | calculate the length of the token. */ |
| 6384 | tok++; |
| 6385 | toklen = end_tok - tok; |
| 6386 | |
| 6387 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 6388 | { |
| 6389 | /* At this point we've found a "thread" token, which means |
| 6390 | the user is trying to set a watchpoint that triggers |
| 6391 | only in a specific thread. */ |
| 6392 | char *endp; |
| 6393 | |
| 6394 | /* Extract the thread ID from the next token. */ |
| 6395 | thread = strtol (id_tok_start, &endp, 0); |
| 6396 | |
| 6397 | /* Check if the user provided a valid numeric value for the |
| 6398 | thread ID. */ |
| 6399 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
| 6400 | error (_("Invalid thread ID specification %s."), id_tok_start); |
| 6401 | |
| 6402 | /* Check if the thread actually exists. */ |
| 6403 | if (!valid_thread_id (thread)) |
| 6404 | error (_("Unknown thread %d."), thread); |
| 6405 | |
| 6406 | /* Truncate the string and get rid of the thread <thread_num> |
| 6407 | parameter before the parameter list is parsed by the |
| 6408 | evaluate_expression() function. */ |
| 6409 | *tok = '\0'; |
| 6410 | } |
| 6411 | } |
| 6412 | |
| 6413 | /* Parse the rest of the arguments. */ |
| 6414 | innermost_block = NULL; |
| 6415 | exp_start = arg; |
| 6416 | exp = parse_exp_1 (&arg, 0, 0); |
| 6417 | exp_end = arg; |
| 6418 | /* Remove trailing whitespace from the expression before saving it. |
| 6419 | This makes the eventual display of the expression string a bit |
| 6420 | prettier. */ |
| 6421 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) |
| 6422 | --exp_end; |
| 6423 | |
| 6424 | exp_valid_block = innermost_block; |
| 6425 | mark = value_mark (); |
| 6426 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
| 6427 | if (val != NULL) |
| 6428 | release_value (val); |
| 6429 | |
| 6430 | tok = arg; |
| 6431 | while (*tok == ' ' || *tok == '\t') |
| 6432 | tok++; |
| 6433 | end_tok = tok; |
| 6434 | |
| 6435 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') |
| 6436 | end_tok++; |
| 6437 | |
| 6438 | toklen = end_tok - tok; |
| 6439 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 6440 | { |
| 6441 | tok = cond_start = end_tok + 1; |
| 6442 | cond = parse_exp_1 (&tok, 0, 0); |
| 6443 | cond_end = tok; |
| 6444 | } |
| 6445 | if (*tok) |
| 6446 | error (_("Junk at end of command.")); |
| 6447 | |
| 6448 | if (accessflag == hw_read) |
| 6449 | bp_type = bp_read_watchpoint; |
| 6450 | else if (accessflag == hw_access) |
| 6451 | bp_type = bp_access_watchpoint; |
| 6452 | else |
| 6453 | bp_type = bp_hardware_watchpoint; |
| 6454 | |
| 6455 | mem_cnt = can_use_hardware_watchpoint (val); |
| 6456 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) |
| 6457 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
| 6458 | if (mem_cnt != 0) |
| 6459 | { |
| 6460 | i = hw_watchpoint_used_count (bp_type, &other_type_used); |
| 6461 | target_resources_ok = |
| 6462 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
| 6463 | other_type_used); |
| 6464 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
| 6465 | error (_("Target does not support this type of hardware watchpoint.")); |
| 6466 | |
| 6467 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
| 6468 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
| 6469 | } |
| 6470 | |
| 6471 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
| 6472 | watchpoint could not be set. */ |
| 6473 | if (!mem_cnt || target_resources_ok <= 0) |
| 6474 | bp_type = bp_watchpoint; |
| 6475 | |
| 6476 | frame = block_innermost_frame (exp_valid_block); |
| 6477 | |
| 6478 | /* If the expression is "local", then set up a "watchpoint scope" |
| 6479 | breakpoint at the point where we've left the scope of the watchpoint |
| 6480 | expression. Create the scope breakpoint before the watchpoint, so |
| 6481 | that we will encounter it first in bpstat_stop_status. */ |
| 6482 | if (innermost_block && frame) |
| 6483 | { |
| 6484 | if (frame_id_p (frame_unwind_caller_id (frame))) |
| 6485 | { |
| 6486 | scope_breakpoint |
| 6487 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
| 6488 | frame_unwind_caller_pc (frame), |
| 6489 | bp_watchpoint_scope); |
| 6490 | |
| 6491 | scope_breakpoint->enable_state = bp_enabled; |
| 6492 | |
| 6493 | /* Automatically delete the breakpoint when it hits. */ |
| 6494 | scope_breakpoint->disposition = disp_del; |
| 6495 | |
| 6496 | /* Only break in the proper frame (help with recursion). */ |
| 6497 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); |
| 6498 | |
| 6499 | /* Set the address at which we will stop. */ |
| 6500 | scope_breakpoint->loc->gdbarch |
| 6501 | = frame_unwind_caller_arch (frame); |
| 6502 | scope_breakpoint->loc->requested_address |
| 6503 | = frame_unwind_caller_pc (frame); |
| 6504 | scope_breakpoint->loc->address |
| 6505 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
| 6506 | scope_breakpoint->loc->requested_address, |
| 6507 | scope_breakpoint->type); |
| 6508 | } |
| 6509 | } |
| 6510 | |
| 6511 | /* Now set up the breakpoint. */ |
| 6512 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
| 6513 | set_breakpoint_count (breakpoint_count + 1); |
| 6514 | b->number = breakpoint_count; |
| 6515 | b->thread = thread; |
| 6516 | b->disposition = disp_donttouch; |
| 6517 | b->exp = exp; |
| 6518 | b->exp_valid_block = exp_valid_block; |
| 6519 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
| 6520 | b->val = val; |
| 6521 | b->val_valid = 1; |
| 6522 | b->loc->cond = cond; |
| 6523 | if (cond_start) |
| 6524 | b->cond_string = savestring (cond_start, cond_end - cond_start); |
| 6525 | else |
| 6526 | b->cond_string = 0; |
| 6527 | |
| 6528 | if (frame) |
| 6529 | b->watchpoint_frame = get_frame_id (frame); |
| 6530 | else |
| 6531 | b->watchpoint_frame = null_frame_id; |
| 6532 | |
| 6533 | if (scope_breakpoint != NULL) |
| 6534 | { |
| 6535 | /* The scope breakpoint is related to the watchpoint. We will |
| 6536 | need to act on them together. */ |
| 6537 | b->related_breakpoint = scope_breakpoint; |
| 6538 | scope_breakpoint->related_breakpoint = b; |
| 6539 | } |
| 6540 | |
| 6541 | value_free_to_mark (mark); |
| 6542 | mention (b); |
| 6543 | update_global_location_list (1); |
| 6544 | } |
| 6545 | |
| 6546 | /* Return count of locations need to be watched and can be handled |
| 6547 | in hardware. If the watchpoint can not be handled |
| 6548 | in hardware return zero. */ |
| 6549 | |
| 6550 | static int |
| 6551 | can_use_hardware_watchpoint (struct value *v) |
| 6552 | { |
| 6553 | int found_memory_cnt = 0; |
| 6554 | struct value *head = v; |
| 6555 | |
| 6556 | /* Did the user specifically forbid us to use hardware watchpoints? */ |
| 6557 | if (!can_use_hw_watchpoints) |
| 6558 | return 0; |
| 6559 | |
| 6560 | /* Make sure that the value of the expression depends only upon |
| 6561 | memory contents, and values computed from them within GDB. If we |
| 6562 | find any register references or function calls, we can't use a |
| 6563 | hardware watchpoint. |
| 6564 | |
| 6565 | The idea here is that evaluating an expression generates a series |
| 6566 | of values, one holding the value of every subexpression. (The |
| 6567 | expression a*b+c has five subexpressions: a, b, a*b, c, and |
| 6568 | a*b+c.) GDB's values hold almost enough information to establish |
| 6569 | the criteria given above --- they identify memory lvalues, |
| 6570 | register lvalues, computed values, etcetera. So we can evaluate |
| 6571 | the expression, and then scan the chain of values that leaves |
| 6572 | behind to decide whether we can detect any possible change to the |
| 6573 | expression's final value using only hardware watchpoints. |
| 6574 | |
| 6575 | However, I don't think that the values returned by inferior |
| 6576 | function calls are special in any way. So this function may not |
| 6577 | notice that an expression involving an inferior function call |
| 6578 | can't be watched with hardware watchpoints. FIXME. */ |
| 6579 | for (; v; v = value_next (v)) |
| 6580 | { |
| 6581 | if (VALUE_LVAL (v) == lval_memory) |
| 6582 | { |
| 6583 | if (value_lazy (v)) |
| 6584 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
| 6585 | we either just used its address (e.g., `a' in `a.b') or |
| 6586 | we never needed it at all (e.g., `a' in `a,b'). */ |
| 6587 | ; |
| 6588 | else |
| 6589 | { |
| 6590 | /* Ahh, memory we actually used! Check if we can cover |
| 6591 | it with hardware watchpoints. */ |
| 6592 | struct type *vtype = check_typedef (value_type (v)); |
| 6593 | |
| 6594 | /* We only watch structs and arrays if user asked for it |
| 6595 | explicitly, never if they just happen to appear in a |
| 6596 | middle of some value chain. */ |
| 6597 | if (v == head |
| 6598 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 6599 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 6600 | { |
| 6601 | CORE_ADDR vaddr = value_address (v); |
| 6602 | int len = TYPE_LENGTH (value_type (v)); |
| 6603 | |
| 6604 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
| 6605 | return 0; |
| 6606 | else |
| 6607 | found_memory_cnt++; |
| 6608 | } |
| 6609 | } |
| 6610 | } |
| 6611 | else if (VALUE_LVAL (v) != not_lval |
| 6612 | && deprecated_value_modifiable (v) == 0) |
| 6613 | return 0; /* ??? What does this represent? */ |
| 6614 | else if (VALUE_LVAL (v) == lval_register) |
| 6615 | return 0; /* cannot watch a register with a HW watchpoint */ |
| 6616 | } |
| 6617 | |
| 6618 | /* The expression itself looks suitable for using a hardware |
| 6619 | watchpoint, but give the target machine a chance to reject it. */ |
| 6620 | return found_memory_cnt; |
| 6621 | } |
| 6622 | |
| 6623 | void |
| 6624 | watch_command_wrapper (char *arg, int from_tty) |
| 6625 | { |
| 6626 | watch_command (arg, from_tty); |
| 6627 | } |
| 6628 | |
| 6629 | static void |
| 6630 | watch_command (char *arg, int from_tty) |
| 6631 | { |
| 6632 | watch_command_1 (arg, hw_write, from_tty); |
| 6633 | } |
| 6634 | |
| 6635 | void |
| 6636 | rwatch_command_wrapper (char *arg, int from_tty) |
| 6637 | { |
| 6638 | rwatch_command (arg, from_tty); |
| 6639 | } |
| 6640 | |
| 6641 | static void |
| 6642 | rwatch_command (char *arg, int from_tty) |
| 6643 | { |
| 6644 | watch_command_1 (arg, hw_read, from_tty); |
| 6645 | } |
| 6646 | |
| 6647 | void |
| 6648 | awatch_command_wrapper (char *arg, int from_tty) |
| 6649 | { |
| 6650 | awatch_command (arg, from_tty); |
| 6651 | } |
| 6652 | |
| 6653 | static void |
| 6654 | awatch_command (char *arg, int from_tty) |
| 6655 | { |
| 6656 | watch_command_1 (arg, hw_access, from_tty); |
| 6657 | } |
| 6658 | \f |
| 6659 | |
| 6660 | /* Helper routines for the until_command routine in infcmd.c. Here |
| 6661 | because it uses the mechanisms of breakpoints. */ |
| 6662 | |
| 6663 | struct until_break_command_continuation_args |
| 6664 | { |
| 6665 | struct breakpoint *breakpoint; |
| 6666 | struct breakpoint *breakpoint2; |
| 6667 | }; |
| 6668 | |
| 6669 | /* This function is called by fetch_inferior_event via the |
| 6670 | cmd_continuation pointer, to complete the until command. It takes |
| 6671 | care of cleaning up the temporary breakpoints set up by the until |
| 6672 | command. */ |
| 6673 | static void |
| 6674 | until_break_command_continuation (void *arg) |
| 6675 | { |
| 6676 | struct until_break_command_continuation_args *a = arg; |
| 6677 | |
| 6678 | delete_breakpoint (a->breakpoint); |
| 6679 | if (a->breakpoint2) |
| 6680 | delete_breakpoint (a->breakpoint2); |
| 6681 | } |
| 6682 | |
| 6683 | void |
| 6684 | until_break_command (char *arg, int from_tty, int anywhere) |
| 6685 | { |
| 6686 | struct symtabs_and_lines sals; |
| 6687 | struct symtab_and_line sal; |
| 6688 | struct frame_info *frame = get_selected_frame (NULL); |
| 6689 | struct breakpoint *breakpoint; |
| 6690 | struct breakpoint *breakpoint2 = NULL; |
| 6691 | struct cleanup *old_chain; |
| 6692 | |
| 6693 | clear_proceed_status (); |
| 6694 | |
| 6695 | /* Set a breakpoint where the user wants it and at return from |
| 6696 | this function */ |
| 6697 | |
| 6698 | if (default_breakpoint_valid) |
| 6699 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, |
| 6700 | default_breakpoint_line, (char ***) NULL, NULL); |
| 6701 | else |
| 6702 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
| 6703 | 0, (char ***) NULL, NULL); |
| 6704 | |
| 6705 | if (sals.nelts != 1) |
| 6706 | error (_("Couldn't get information on specified line.")); |
| 6707 | |
| 6708 | sal = sals.sals[0]; |
| 6709 | xfree (sals.sals); /* malloc'd, so freed */ |
| 6710 | |
| 6711 | if (*arg) |
| 6712 | error (_("Junk at end of arguments.")); |
| 6713 | |
| 6714 | resolve_sal_pc (&sal); |
| 6715 | |
| 6716 | if (anywhere) |
| 6717 | /* If the user told us to continue until a specified location, |
| 6718 | we don't specify a frame at which we need to stop. */ |
| 6719 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
| 6720 | null_frame_id, bp_until); |
| 6721 | else |
| 6722 | /* Otherwise, specify the selected frame, because we want to stop only |
| 6723 | at the very same frame. */ |
| 6724 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
| 6725 | get_stack_frame_id (frame), |
| 6726 | bp_until); |
| 6727 | |
| 6728 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
| 6729 | |
| 6730 | /* Keep within the current frame, or in frames called by the current |
| 6731 | one. */ |
| 6732 | |
| 6733 | if (frame_id_p (frame_unwind_caller_id (frame))) |
| 6734 | { |
| 6735 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
| 6736 | sal.pc = frame_unwind_caller_pc (frame); |
| 6737 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
| 6738 | sal, |
| 6739 | frame_unwind_caller_id (frame), |
| 6740 | bp_until); |
| 6741 | make_cleanup_delete_breakpoint (breakpoint2); |
| 6742 | } |
| 6743 | |
| 6744 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
| 6745 | |
| 6746 | /* If we are running asynchronously, and proceed call above has actually |
| 6747 | managed to start the target, arrange for breakpoints to be |
| 6748 | deleted when the target stops. Otherwise, we're already stopped and |
| 6749 | delete breakpoints via cleanup chain. */ |
| 6750 | |
| 6751 | if (target_can_async_p () && is_running (inferior_ptid)) |
| 6752 | { |
| 6753 | struct until_break_command_continuation_args *args; |
| 6754 | args = xmalloc (sizeof (*args)); |
| 6755 | |
| 6756 | args->breakpoint = breakpoint; |
| 6757 | args->breakpoint2 = breakpoint2; |
| 6758 | |
| 6759 | discard_cleanups (old_chain); |
| 6760 | add_continuation (inferior_thread (), |
| 6761 | until_break_command_continuation, args, |
| 6762 | xfree); |
| 6763 | } |
| 6764 | else |
| 6765 | do_cleanups (old_chain); |
| 6766 | } |
| 6767 | |
| 6768 | static void |
| 6769 | ep_skip_leading_whitespace (char **s) |
| 6770 | { |
| 6771 | if ((s == NULL) || (*s == NULL)) |
| 6772 | return; |
| 6773 | while (isspace (**s)) |
| 6774 | *s += 1; |
| 6775 | } |
| 6776 | |
| 6777 | /* This function attempts to parse an optional "if <cond>" clause |
| 6778 | from the arg string. If one is not found, it returns NULL. |
| 6779 | |
| 6780 | Else, it returns a pointer to the condition string. (It does not |
| 6781 | attempt to evaluate the string against a particular block.) And, |
| 6782 | it updates arg to point to the first character following the parsed |
| 6783 | if clause in the arg string. */ |
| 6784 | |
| 6785 | static char * |
| 6786 | ep_parse_optional_if_clause (char **arg) |
| 6787 | { |
| 6788 | char *cond_string; |
| 6789 | |
| 6790 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) |
| 6791 | return NULL; |
| 6792 | |
| 6793 | /* Skip the "if" keyword. */ |
| 6794 | (*arg) += 2; |
| 6795 | |
| 6796 | /* Skip any extra leading whitespace, and record the start of the |
| 6797 | condition string. */ |
| 6798 | ep_skip_leading_whitespace (arg); |
| 6799 | cond_string = *arg; |
| 6800 | |
| 6801 | /* Assume that the condition occupies the remainder of the arg string. */ |
| 6802 | (*arg) += strlen (cond_string); |
| 6803 | |
| 6804 | return cond_string; |
| 6805 | } |
| 6806 | |
| 6807 | /* This function attempts to parse an optional filename from the arg |
| 6808 | string. If one is not found, it returns NULL. |
| 6809 | |
| 6810 | Else, it returns a pointer to the parsed filename. (This function |
| 6811 | makes no attempt to verify that a file of that name exists, or is |
| 6812 | accessible.) And, it updates arg to point to the first character |
| 6813 | following the parsed filename in the arg string. |
| 6814 | |
| 6815 | Note that clients needing to preserve the returned filename for |
| 6816 | future access should copy it to their own buffers. */ |
| 6817 | static char * |
| 6818 | ep_parse_optional_filename (char **arg) |
| 6819 | { |
| 6820 | static char filename[1024]; |
| 6821 | char *arg_p = *arg; |
| 6822 | int i; |
| 6823 | char c; |
| 6824 | |
| 6825 | if ((*arg_p == '\0') || isspace (*arg_p)) |
| 6826 | return NULL; |
| 6827 | |
| 6828 | for (i = 0;; i++) |
| 6829 | { |
| 6830 | c = *arg_p; |
| 6831 | if (isspace (c)) |
| 6832 | c = '\0'; |
| 6833 | filename[i] = c; |
| 6834 | if (c == '\0') |
| 6835 | break; |
| 6836 | arg_p++; |
| 6837 | } |
| 6838 | *arg = arg_p; |
| 6839 | |
| 6840 | return filename; |
| 6841 | } |
| 6842 | |
| 6843 | /* Commands to deal with catching events, such as signals, exceptions, |
| 6844 | process start/exit, etc. */ |
| 6845 | |
| 6846 | typedef enum |
| 6847 | { |
| 6848 | catch_fork_temporary, catch_vfork_temporary, |
| 6849 | catch_fork_permanent, catch_vfork_permanent |
| 6850 | } |
| 6851 | catch_fork_kind; |
| 6852 | |
| 6853 | static void |
| 6854 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
| 6855 | { |
| 6856 | struct gdbarch *gdbarch = get_current_arch (); |
| 6857 | char *cond_string = NULL; |
| 6858 | catch_fork_kind fork_kind; |
| 6859 | int tempflag; |
| 6860 | |
| 6861 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); |
| 6862 | tempflag = (fork_kind == catch_fork_temporary |
| 6863 | || fork_kind == catch_vfork_temporary); |
| 6864 | |
| 6865 | if (!arg) |
| 6866 | arg = ""; |
| 6867 | ep_skip_leading_whitespace (&arg); |
| 6868 | |
| 6869 | /* The allowed syntax is: |
| 6870 | catch [v]fork |
| 6871 | catch [v]fork if <cond> |
| 6872 | |
| 6873 | First, check if there's an if clause. */ |
| 6874 | cond_string = ep_parse_optional_if_clause (&arg); |
| 6875 | |
| 6876 | if ((*arg != '\0') && !isspace (*arg)) |
| 6877 | error (_("Junk at end of arguments.")); |
| 6878 | |
| 6879 | /* If this target supports it, create a fork or vfork catchpoint |
| 6880 | and enable reporting of such events. */ |
| 6881 | switch (fork_kind) |
| 6882 | { |
| 6883 | case catch_fork_temporary: |
| 6884 | case catch_fork_permanent: |
| 6885 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 6886 | &catch_fork_breakpoint_ops); |
| 6887 | break; |
| 6888 | case catch_vfork_temporary: |
| 6889 | case catch_vfork_permanent: |
| 6890 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 6891 | &catch_vfork_breakpoint_ops); |
| 6892 | break; |
| 6893 | default: |
| 6894 | error (_("unsupported or unknown fork kind; cannot catch it")); |
| 6895 | break; |
| 6896 | } |
| 6897 | } |
| 6898 | |
| 6899 | static void |
| 6900 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
| 6901 | { |
| 6902 | struct gdbarch *gdbarch = get_current_arch (); |
| 6903 | int tempflag; |
| 6904 | char *cond_string = NULL; |
| 6905 | |
| 6906 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 6907 | |
| 6908 | if (!arg) |
| 6909 | arg = ""; |
| 6910 | ep_skip_leading_whitespace (&arg); |
| 6911 | |
| 6912 | /* The allowed syntax is: |
| 6913 | catch exec |
| 6914 | catch exec if <cond> |
| 6915 | |
| 6916 | First, check if there's an if clause. */ |
| 6917 | cond_string = ep_parse_optional_if_clause (&arg); |
| 6918 | |
| 6919 | if ((*arg != '\0') && !isspace (*arg)) |
| 6920 | error (_("Junk at end of arguments.")); |
| 6921 | |
| 6922 | /* If this target supports it, create an exec catchpoint |
| 6923 | and enable reporting of such events. */ |
| 6924 | create_catchpoint (gdbarch, tempflag, cond_string, |
| 6925 | &catch_exec_breakpoint_ops); |
| 6926 | } |
| 6927 | |
| 6928 | static enum print_stop_action |
| 6929 | print_exception_catchpoint (struct breakpoint *b) |
| 6930 | { |
| 6931 | int bp_temp, bp_throw; |
| 6932 | |
| 6933 | annotate_catchpoint (b->number); |
| 6934 | |
| 6935 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
| 6936 | if (b->loc->address != b->loc->requested_address) |
| 6937 | breakpoint_adjustment_warning (b->loc->requested_address, |
| 6938 | b->loc->address, |
| 6939 | b->number, 1); |
| 6940 | bp_temp = b->disposition == disp_del; |
| 6941 | ui_out_text (uiout, |
| 6942 | bp_temp ? "Temporary catchpoint " |
| 6943 | : "Catchpoint "); |
| 6944 | if (!ui_out_is_mi_like_p (uiout)) |
| 6945 | ui_out_field_int (uiout, "bkptno", b->number); |
| 6946 | ui_out_text (uiout, |
| 6947 | bp_throw ? " (exception thrown), " |
| 6948 | : " (exception caught), "); |
| 6949 | if (ui_out_is_mi_like_p (uiout)) |
| 6950 | { |
| 6951 | ui_out_field_string (uiout, "reason", |
| 6952 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 6953 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 6954 | ui_out_field_int (uiout, "bkptno", b->number); |
| 6955 | } |
| 6956 | return PRINT_SRC_AND_LOC; |
| 6957 | } |
| 6958 | |
| 6959 | static void |
| 6960 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
| 6961 | { |
| 6962 | struct value_print_options opts; |
| 6963 | get_user_print_options (&opts); |
| 6964 | if (opts.addressprint) |
| 6965 | { |
| 6966 | annotate_field (4); |
| 6967 | if (b->loc == NULL || b->loc->shlib_disabled) |
| 6968 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
| 6969 | else |
| 6970 | ui_out_field_core_addr (uiout, "addr", |
| 6971 | b->loc->gdbarch, b->loc->address); |
| 6972 | } |
| 6973 | annotate_field (5); |
| 6974 | if (b->loc) |
| 6975 | *last_loc = b->loc; |
| 6976 | if (strstr (b->addr_string, "throw") != NULL) |
| 6977 | ui_out_field_string (uiout, "what", "exception throw"); |
| 6978 | else |
| 6979 | ui_out_field_string (uiout, "what", "exception catch"); |
| 6980 | } |
| 6981 | |
| 6982 | static void |
| 6983 | print_mention_exception_catchpoint (struct breakpoint *b) |
| 6984 | { |
| 6985 | int bp_temp; |
| 6986 | int bp_throw; |
| 6987 | |
| 6988 | bp_temp = b->disposition == disp_del; |
| 6989 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
| 6990 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") |
| 6991 | : _("Catchpoint ")); |
| 6992 | ui_out_field_int (uiout, "bkptno", b->number); |
| 6993 | ui_out_text (uiout, bp_throw ? _(" (throw)") |
| 6994 | : _(" (catch)")); |
| 6995 | } |
| 6996 | |
| 6997 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
| 6998 | NULL, /* insert */ |
| 6999 | NULL, /* remove */ |
| 7000 | NULL, /* breakpoint_hit */ |
| 7001 | print_exception_catchpoint, |
| 7002 | print_one_exception_catchpoint, |
| 7003 | print_mention_exception_catchpoint |
| 7004 | }; |
| 7005 | |
| 7006 | static int |
| 7007 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, |
| 7008 | enum exception_event_kind ex_event, int from_tty) |
| 7009 | { |
| 7010 | char *trigger_func_name; |
| 7011 | |
| 7012 | if (ex_event == EX_EVENT_CATCH) |
| 7013 | trigger_func_name = "__cxa_begin_catch"; |
| 7014 | else |
| 7015 | trigger_func_name = "__cxa_throw"; |
| 7016 | |
| 7017 | break_command_really (get_current_arch (), |
| 7018 | trigger_func_name, cond_string, -1, |
| 7019 | 0 /* condition and thread are valid. */, |
| 7020 | tempflag, 0, 0, |
| 7021 | 0, |
| 7022 | AUTO_BOOLEAN_TRUE /* pending */, |
| 7023 | &gnu_v3_exception_catchpoint_ops, from_tty, |
| 7024 | 1 /* enabled */); |
| 7025 | |
| 7026 | return 1; |
| 7027 | } |
| 7028 | |
| 7029 | /* Deal with "catch catch" and "catch throw" commands */ |
| 7030 | |
| 7031 | static void |
| 7032 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
| 7033 | int tempflag, int from_tty) |
| 7034 | { |
| 7035 | char *cond_string = NULL; |
| 7036 | struct symtab_and_line *sal = NULL; |
| 7037 | |
| 7038 | if (!arg) |
| 7039 | arg = ""; |
| 7040 | ep_skip_leading_whitespace (&arg); |
| 7041 | |
| 7042 | cond_string = ep_parse_optional_if_clause (&arg); |
| 7043 | |
| 7044 | if ((*arg != '\0') && !isspace (*arg)) |
| 7045 | error (_("Junk at end of arguments.")); |
| 7046 | |
| 7047 | if (ex_event != EX_EVENT_THROW |
| 7048 | && ex_event != EX_EVENT_CATCH) |
| 7049 | error (_("Unsupported or unknown exception event; cannot catch it")); |
| 7050 | |
| 7051 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
| 7052 | return; |
| 7053 | |
| 7054 | warning (_("Unsupported with this platform/compiler combination.")); |
| 7055 | } |
| 7056 | |
| 7057 | /* Implementation of "catch catch" command. */ |
| 7058 | |
| 7059 | static void |
| 7060 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) |
| 7061 | { |
| 7062 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 7063 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
| 7064 | } |
| 7065 | |
| 7066 | /* Implementation of "catch throw" command. */ |
| 7067 | |
| 7068 | static void |
| 7069 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) |
| 7070 | { |
| 7071 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 7072 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
| 7073 | } |
| 7074 | |
| 7075 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
| 7076 | |
| 7077 | static void |
| 7078 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
| 7079 | struct symtab_and_line sal, |
| 7080 | char *addr_string, |
| 7081 | char *exp_string, |
| 7082 | char *cond_string, |
| 7083 | struct expression *cond, |
| 7084 | struct breakpoint_ops *ops, |
| 7085 | int tempflag, |
| 7086 | int from_tty) |
| 7087 | { |
| 7088 | struct breakpoint *b; |
| 7089 | |
| 7090 | if (from_tty) |
| 7091 | { |
| 7092 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 7093 | if (!loc_gdbarch) |
| 7094 | loc_gdbarch = gdbarch; |
| 7095 | |
| 7096 | describe_other_breakpoints (loc_gdbarch, sal.pc, sal.section, -1); |
| 7097 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
| 7098 | version for exception catchpoints, because two catchpoints |
| 7099 | used for different exception names will use the same address. |
| 7100 | In this case, a "breakpoint ... also set at..." warning is |
| 7101 | unproductive. Besides. the warning phrasing is also a bit |
| 7102 | inapropriate, we should use the word catchpoint, and tell |
| 7103 | the user what type of catchpoint it is. The above is good |
| 7104 | enough for now, though. */ |
| 7105 | } |
| 7106 | |
| 7107 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
| 7108 | set_breakpoint_count (breakpoint_count + 1); |
| 7109 | |
| 7110 | b->enable_state = bp_enabled; |
| 7111 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 7112 | b->number = breakpoint_count; |
| 7113 | b->ignore_count = 0; |
| 7114 | b->loc->cond = cond; |
| 7115 | b->addr_string = addr_string; |
| 7116 | b->language = language_ada; |
| 7117 | b->cond_string = cond_string; |
| 7118 | b->exp_string = exp_string; |
| 7119 | b->thread = -1; |
| 7120 | b->ops = ops; |
| 7121 | |
| 7122 | mention (b); |
| 7123 | update_global_location_list (1); |
| 7124 | } |
| 7125 | |
| 7126 | /* Implement the "catch exception" command. */ |
| 7127 | |
| 7128 | static void |
| 7129 | catch_ada_exception_command (char *arg, int from_tty, |
| 7130 | struct cmd_list_element *command) |
| 7131 | { |
| 7132 | struct gdbarch *gdbarch = get_current_arch (); |
| 7133 | int tempflag; |
| 7134 | struct symtab_and_line sal; |
| 7135 | enum bptype type; |
| 7136 | char *addr_string = NULL; |
| 7137 | char *exp_string = NULL; |
| 7138 | char *cond_string = NULL; |
| 7139 | struct expression *cond = NULL; |
| 7140 | struct breakpoint_ops *ops = NULL; |
| 7141 | |
| 7142 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 7143 | |
| 7144 | if (!arg) |
| 7145 | arg = ""; |
| 7146 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
| 7147 | &cond_string, &cond, &ops); |
| 7148 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
| 7149 | cond_string, cond, ops, tempflag, |
| 7150 | from_tty); |
| 7151 | } |
| 7152 | |
| 7153 | /* Implement the "catch assert" command. */ |
| 7154 | |
| 7155 | static void |
| 7156 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
| 7157 | { |
| 7158 | struct gdbarch *gdbarch = get_current_arch (); |
| 7159 | int tempflag; |
| 7160 | struct symtab_and_line sal; |
| 7161 | char *addr_string = NULL; |
| 7162 | struct breakpoint_ops *ops = NULL; |
| 7163 | |
| 7164 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 7165 | |
| 7166 | if (!arg) |
| 7167 | arg = ""; |
| 7168 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
| 7169 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
| 7170 | ops, tempflag, from_tty); |
| 7171 | } |
| 7172 | |
| 7173 | static void |
| 7174 | catch_command (char *arg, int from_tty) |
| 7175 | { |
| 7176 | error (_("Catch requires an event name.")); |
| 7177 | } |
| 7178 | \f |
| 7179 | |
| 7180 | static void |
| 7181 | tcatch_command (char *arg, int from_tty) |
| 7182 | { |
| 7183 | error (_("Catch requires an event name.")); |
| 7184 | } |
| 7185 | |
| 7186 | /* Delete breakpoints by address or line. */ |
| 7187 | |
| 7188 | static void |
| 7189 | clear_command (char *arg, int from_tty) |
| 7190 | { |
| 7191 | struct breakpoint *b; |
| 7192 | VEC(breakpoint_p) *found = 0; |
| 7193 | int ix; |
| 7194 | int default_match; |
| 7195 | struct symtabs_and_lines sals; |
| 7196 | struct symtab_and_line sal; |
| 7197 | int i; |
| 7198 | |
| 7199 | if (arg) |
| 7200 | { |
| 7201 | sals = decode_line_spec (arg, 1); |
| 7202 | default_match = 0; |
| 7203 | } |
| 7204 | else |
| 7205 | { |
| 7206 | sals.sals = (struct symtab_and_line *) |
| 7207 | xmalloc (sizeof (struct symtab_and_line)); |
| 7208 | make_cleanup (xfree, sals.sals); |
| 7209 | init_sal (&sal); /* initialize to zeroes */ |
| 7210 | sal.line = default_breakpoint_line; |
| 7211 | sal.symtab = default_breakpoint_symtab; |
| 7212 | sal.pc = default_breakpoint_address; |
| 7213 | if (sal.symtab == 0) |
| 7214 | error (_("No source file specified.")); |
| 7215 | |
| 7216 | sals.sals[0] = sal; |
| 7217 | sals.nelts = 1; |
| 7218 | |
| 7219 | default_match = 1; |
| 7220 | } |
| 7221 | |
| 7222 | /* We don't call resolve_sal_pc here. That's not |
| 7223 | as bad as it seems, because all existing breakpoints |
| 7224 | typically have both file/line and pc set. So, if |
| 7225 | clear is given file/line, we can match this to existing |
| 7226 | breakpoint without obtaining pc at all. |
| 7227 | |
| 7228 | We only support clearing given the address explicitly |
| 7229 | present in breakpoint table. Say, we've set breakpoint |
| 7230 | at file:line. There were several PC values for that file:line, |
| 7231 | due to optimization, all in one block. |
| 7232 | We've picked one PC value. If "clear" is issued with another |
| 7233 | PC corresponding to the same file:line, the breakpoint won't |
| 7234 | be cleared. We probably can still clear the breakpoint, but |
| 7235 | since the other PC value is never presented to user, user |
| 7236 | can only find it by guessing, and it does not seem important |
| 7237 | to support that. */ |
| 7238 | |
| 7239 | /* For each line spec given, delete bps which correspond |
| 7240 | to it. Do it in two passes, solely to preserve the current |
| 7241 | behavior that from_tty is forced true if we delete more than |
| 7242 | one breakpoint. */ |
| 7243 | |
| 7244 | found = NULL; |
| 7245 | for (i = 0; i < sals.nelts; i++) |
| 7246 | { |
| 7247 | /* If exact pc given, clear bpts at that pc. |
| 7248 | If line given (pc == 0), clear all bpts on specified line. |
| 7249 | If defaulting, clear all bpts on default line |
| 7250 | or at default pc. |
| 7251 | |
| 7252 | defaulting sal.pc != 0 tests to do |
| 7253 | |
| 7254 | 0 1 pc |
| 7255 | 1 1 pc _and_ line |
| 7256 | 0 0 line |
| 7257 | 1 0 <can't happen> */ |
| 7258 | |
| 7259 | sal = sals.sals[i]; |
| 7260 | |
| 7261 | /* Find all matching breakpoints and add them to |
| 7262 | 'found'. */ |
| 7263 | ALL_BREAKPOINTS (b) |
| 7264 | { |
| 7265 | int match = 0; |
| 7266 | /* Are we going to delete b? */ |
| 7267 | if (b->type != bp_none |
| 7268 | && b->type != bp_watchpoint |
| 7269 | && b->type != bp_hardware_watchpoint |
| 7270 | && b->type != bp_read_watchpoint |
| 7271 | && b->type != bp_access_watchpoint) |
| 7272 | { |
| 7273 | struct bp_location *loc = b->loc; |
| 7274 | for (; loc; loc = loc->next) |
| 7275 | { |
| 7276 | int pc_match = sal.pc |
| 7277 | && (loc->address == sal.pc) |
| 7278 | && (!section_is_overlay (loc->section) |
| 7279 | || loc->section == sal.section); |
| 7280 | int line_match = ((default_match || (0 == sal.pc)) |
| 7281 | && b->source_file != NULL |
| 7282 | && sal.symtab != NULL |
| 7283 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
| 7284 | && b->line_number == sal.line); |
| 7285 | if (pc_match || line_match) |
| 7286 | { |
| 7287 | match = 1; |
| 7288 | break; |
| 7289 | } |
| 7290 | } |
| 7291 | } |
| 7292 | |
| 7293 | if (match) |
| 7294 | VEC_safe_push(breakpoint_p, found, b); |
| 7295 | } |
| 7296 | } |
| 7297 | /* Now go thru the 'found' chain and delete them. */ |
| 7298 | if (VEC_empty(breakpoint_p, found)) |
| 7299 | { |
| 7300 | if (arg) |
| 7301 | error (_("No breakpoint at %s."), arg); |
| 7302 | else |
| 7303 | error (_("No breakpoint at this line.")); |
| 7304 | } |
| 7305 | |
| 7306 | if (VEC_length(breakpoint_p, found) > 1) |
| 7307 | from_tty = 1; /* Always report if deleted more than one */ |
| 7308 | if (from_tty) |
| 7309 | { |
| 7310 | if (VEC_length(breakpoint_p, found) == 1) |
| 7311 | printf_unfiltered (_("Deleted breakpoint ")); |
| 7312 | else |
| 7313 | printf_unfiltered (_("Deleted breakpoints ")); |
| 7314 | } |
| 7315 | breakpoints_changed (); |
| 7316 | |
| 7317 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) |
| 7318 | { |
| 7319 | if (from_tty) |
| 7320 | printf_unfiltered ("%d ", b->number); |
| 7321 | delete_breakpoint (b); |
| 7322 | } |
| 7323 | if (from_tty) |
| 7324 | putchar_unfiltered ('\n'); |
| 7325 | } |
| 7326 | \f |
| 7327 | /* Delete breakpoint in BS if they are `delete' breakpoints and |
| 7328 | all breakpoints that are marked for deletion, whether hit or not. |
| 7329 | This is called after any breakpoint is hit, or after errors. */ |
| 7330 | |
| 7331 | void |
| 7332 | breakpoint_auto_delete (bpstat bs) |
| 7333 | { |
| 7334 | struct breakpoint *b, *temp; |
| 7335 | |
| 7336 | for (; bs; bs = bs->next) |
| 7337 | if (bs->breakpoint_at |
| 7338 | && bs->breakpoint_at->owner |
| 7339 | && bs->breakpoint_at->owner->disposition == disp_del |
| 7340 | && bs->stop) |
| 7341 | delete_breakpoint (bs->breakpoint_at->owner); |
| 7342 | |
| 7343 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 7344 | { |
| 7345 | if (b->disposition == disp_del_at_next_stop) |
| 7346 | delete_breakpoint (b); |
| 7347 | } |
| 7348 | } |
| 7349 | |
| 7350 | /* A cleanup function which destroys a vector. */ |
| 7351 | |
| 7352 | static void |
| 7353 | do_vec_free (void *p) |
| 7354 | { |
| 7355 | VEC(bp_location_p) **vec = p; |
| 7356 | if (*vec) |
| 7357 | VEC_free (bp_location_p, *vec); |
| 7358 | } |
| 7359 | |
| 7360 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
| 7361 | into the inferior, only remove already-inserted locations that no |
| 7362 | longer should be inserted. Functions that delete a breakpoint or |
| 7363 | breakpoints should pass false, so that deleting a breakpoint |
| 7364 | doesn't have the side effect of inserting the locations of other |
| 7365 | breakpoints that are marked not-inserted, but should_be_inserted |
| 7366 | returns true on them. |
| 7367 | |
| 7368 | This behaviour is useful is situations close to tear-down -- e.g., |
| 7369 | after an exec, while the target still has execution, but breakpoint |
| 7370 | shadows of the previous executable image should *NOT* be restored |
| 7371 | to the new image; or before detaching, where the target still has |
| 7372 | execution and wants to delete breakpoints from GDB's lists, and all |
| 7373 | breakpoints had already been removed from the inferior. */ |
| 7374 | |
| 7375 | static void |
| 7376 | update_global_location_list (int should_insert) |
| 7377 | { |
| 7378 | struct breakpoint *b; |
| 7379 | struct bp_location **next = &bp_location_chain; |
| 7380 | struct bp_location *loc; |
| 7381 | struct bp_location *loc2; |
| 7382 | VEC(bp_location_p) *old_locations = NULL; |
| 7383 | int ret; |
| 7384 | int ix; |
| 7385 | struct cleanup *cleanups; |
| 7386 | |
| 7387 | cleanups = make_cleanup (do_vec_free, &old_locations); |
| 7388 | /* Store old locations for future reference. */ |
| 7389 | for (loc = bp_location_chain; loc; loc = loc->global_next) |
| 7390 | VEC_safe_push (bp_location_p, old_locations, loc); |
| 7391 | |
| 7392 | bp_location_chain = NULL; |
| 7393 | ALL_BREAKPOINTS (b) |
| 7394 | { |
| 7395 | for (loc = b->loc; loc; loc = loc->next) |
| 7396 | { |
| 7397 | *next = loc; |
| 7398 | next = &(loc->global_next); |
| 7399 | *next = NULL; |
| 7400 | } |
| 7401 | } |
| 7402 | |
| 7403 | /* Identify bp_location instances that are no longer present in the new |
| 7404 | list, and therefore should be freed. Note that it's not necessary that |
| 7405 | those locations should be removed from inferior -- if there's another |
| 7406 | location at the same address (previously marked as duplicate), |
| 7407 | we don't need to remove/insert the location. */ |
| 7408 | for (ix = 0; VEC_iterate(bp_location_p, old_locations, ix, loc); ++ix) |
| 7409 | { |
| 7410 | /* Tells if 'loc' is found amoung the new locations. If not, we |
| 7411 | have to free it. */ |
| 7412 | int found_object = 0; |
| 7413 | /* Tells if the location should remain inserted in the target. */ |
| 7414 | int keep_in_target = 0; |
| 7415 | int removed = 0; |
| 7416 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
| 7417 | if (loc2 == loc) |
| 7418 | { |
| 7419 | found_object = 1; |
| 7420 | break; |
| 7421 | } |
| 7422 | |
| 7423 | /* If this location is no longer present, and inserted, look if there's |
| 7424 | maybe a new location at the same address. If so, mark that one |
| 7425 | inserted, and don't remove this one. This is needed so that we |
| 7426 | don't have a time window where a breakpoint at certain location is not |
| 7427 | inserted. */ |
| 7428 | |
| 7429 | if (loc->inserted) |
| 7430 | { |
| 7431 | /* If the location is inserted now, we might have to remove it. */ |
| 7432 | |
| 7433 | if (found_object && should_be_inserted (loc)) |
| 7434 | { |
| 7435 | /* The location is still present in the location list, and still |
| 7436 | should be inserted. Don't do anything. */ |
| 7437 | keep_in_target = 1; |
| 7438 | } |
| 7439 | else |
| 7440 | { |
| 7441 | /* The location is either no longer present, or got disabled. |
| 7442 | See if there's another location at the same address, in which |
| 7443 | case we don't need to remove this one from the target. */ |
| 7444 | if (breakpoint_address_is_meaningful (loc->owner)) |
| 7445 | for (loc2 = bp_location_chain; loc2; loc2 = loc2->global_next) |
| 7446 | { |
| 7447 | /* For the sake of should_insert_location. The |
| 7448 | call to check_duplicates will fix up this later. */ |
| 7449 | loc2->duplicate = 0; |
| 7450 | if (should_be_inserted (loc2) |
| 7451 | && loc2 != loc && loc2->address == loc->address) |
| 7452 | { |
| 7453 | loc2->inserted = 1; |
| 7454 | loc2->target_info = loc->target_info; |
| 7455 | keep_in_target = 1; |
| 7456 | break; |
| 7457 | } |
| 7458 | } |
| 7459 | } |
| 7460 | |
| 7461 | if (!keep_in_target) |
| 7462 | { |
| 7463 | if (remove_breakpoint (loc, mark_uninserted)) |
| 7464 | { |
| 7465 | /* This is just about all we can do. We could keep this |
| 7466 | location on the global list, and try to remove it next |
| 7467 | time, but there's no particular reason why we will |
| 7468 | succeed next time. |
| 7469 | |
| 7470 | Note that at this point, loc->owner is still valid, |
| 7471 | as delete_breakpoint frees the breakpoint only |
| 7472 | after calling us. */ |
| 7473 | printf_filtered (_("warning: Error removing breakpoint %d\n"), |
| 7474 | loc->owner->number); |
| 7475 | } |
| 7476 | removed = 1; |
| 7477 | } |
| 7478 | } |
| 7479 | |
| 7480 | if (!found_object) |
| 7481 | { |
| 7482 | if (removed && non_stop) |
| 7483 | { |
| 7484 | /* This location was removed from the targets. In non-stop mode, |
| 7485 | a race condition is possible where we've removed a breakpoint, |
| 7486 | but stop events for that breakpoint are already queued and will |
| 7487 | arrive later. To suppress spurious SIGTRAPs reported to user, |
| 7488 | we keep this breakpoint location for a bit, and will retire it |
| 7489 | after we see 3 * thread_count events. |
| 7490 | The theory here is that reporting of events should, |
| 7491 | "on the average", be fair, so after that many event we'll see |
| 7492 | events from all threads that have anything of interest, and no |
| 7493 | longer need to keep this breakpoint. This is just a |
| 7494 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
| 7495 | which is usability issue, but not a correctness problem. */ |
| 7496 | loc->events_till_retirement = 3 * (thread_count () + 1); |
| 7497 | loc->owner = NULL; |
| 7498 | |
| 7499 | VEC_safe_push (bp_location_p, moribund_locations, loc); |
| 7500 | } |
| 7501 | else |
| 7502 | free_bp_location (loc); |
| 7503 | } |
| 7504 | } |
| 7505 | |
| 7506 | ALL_BREAKPOINTS (b) |
| 7507 | { |
| 7508 | check_duplicates (b); |
| 7509 | } |
| 7510 | |
| 7511 | if (breakpoints_always_inserted_mode () && should_insert |
| 7512 | && (have_live_inferiors () |
| 7513 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
| 7514 | insert_breakpoint_locations (); |
| 7515 | |
| 7516 | do_cleanups (cleanups); |
| 7517 | } |
| 7518 | |
| 7519 | void |
| 7520 | breakpoint_retire_moribund (void) |
| 7521 | { |
| 7522 | struct bp_location *loc; |
| 7523 | int ix; |
| 7524 | |
| 7525 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 7526 | if (--(loc->events_till_retirement) == 0) |
| 7527 | { |
| 7528 | free_bp_location (loc); |
| 7529 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
| 7530 | --ix; |
| 7531 | } |
| 7532 | } |
| 7533 | |
| 7534 | static void |
| 7535 | update_global_location_list_nothrow (int inserting) |
| 7536 | { |
| 7537 | struct gdb_exception e; |
| 7538 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 7539 | update_global_location_list (inserting); |
| 7540 | } |
| 7541 | |
| 7542 | /* Clear BPT from a BPS. */ |
| 7543 | static void |
| 7544 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) |
| 7545 | { |
| 7546 | bpstat bs; |
| 7547 | for (bs = bps; bs; bs = bs->next) |
| 7548 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) |
| 7549 | { |
| 7550 | bs->breakpoint_at = NULL; |
| 7551 | bs->old_val = NULL; |
| 7552 | /* bs->commands will be freed later. */ |
| 7553 | } |
| 7554 | } |
| 7555 | |
| 7556 | /* Callback for iterate_over_threads. */ |
| 7557 | static int |
| 7558 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
| 7559 | { |
| 7560 | struct breakpoint *bpt = data; |
| 7561 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); |
| 7562 | return 0; |
| 7563 | } |
| 7564 | |
| 7565 | /* Delete a breakpoint and clean up all traces of it in the data |
| 7566 | structures. */ |
| 7567 | |
| 7568 | void |
| 7569 | delete_breakpoint (struct breakpoint *bpt) |
| 7570 | { |
| 7571 | struct breakpoint *b; |
| 7572 | struct bp_location *loc, *next; |
| 7573 | |
| 7574 | gdb_assert (bpt != NULL); |
| 7575 | |
| 7576 | /* Has this bp already been deleted? This can happen because multiple |
| 7577 | lists can hold pointers to bp's. bpstat lists are especial culprits. |
| 7578 | |
| 7579 | One example of this happening is a watchpoint's scope bp. When the |
| 7580 | scope bp triggers, we notice that the watchpoint is out of scope, and |
| 7581 | delete it. We also delete its scope bp. But the scope bp is marked |
| 7582 | "auto-deleting", and is already on a bpstat. That bpstat is then |
| 7583 | checked for auto-deleting bp's, which are deleted. |
| 7584 | |
| 7585 | A real solution to this problem might involve reference counts in bp's, |
| 7586 | and/or giving them pointers back to their referencing bpstat's, and |
| 7587 | teaching delete_breakpoint to only free a bp's storage when no more |
| 7588 | references were extent. A cheaper bandaid was chosen. */ |
| 7589 | if (bpt->type == bp_none) |
| 7590 | return; |
| 7591 | |
| 7592 | observer_notify_breakpoint_deleted (bpt->number); |
| 7593 | |
| 7594 | if (breakpoint_chain == bpt) |
| 7595 | breakpoint_chain = bpt->next; |
| 7596 | |
| 7597 | ALL_BREAKPOINTS (b) |
| 7598 | if (b->next == bpt) |
| 7599 | { |
| 7600 | b->next = bpt->next; |
| 7601 | break; |
| 7602 | } |
| 7603 | |
| 7604 | free_command_lines (&bpt->commands); |
| 7605 | if (bpt->cond_string != NULL) |
| 7606 | xfree (bpt->cond_string); |
| 7607 | if (bpt->addr_string != NULL) |
| 7608 | xfree (bpt->addr_string); |
| 7609 | if (bpt->exp != NULL) |
| 7610 | xfree (bpt->exp); |
| 7611 | if (bpt->exp_string != NULL) |
| 7612 | xfree (bpt->exp_string); |
| 7613 | if (bpt->val != NULL) |
| 7614 | value_free (bpt->val); |
| 7615 | if (bpt->source_file != NULL) |
| 7616 | xfree (bpt->source_file); |
| 7617 | if (bpt->exec_pathname != NULL) |
| 7618 | xfree (bpt->exec_pathname); |
| 7619 | |
| 7620 | /* Be sure no bpstat's are pointing at it after it's been freed. */ |
| 7621 | /* FIXME, how can we find all bpstat's? |
| 7622 | We just check stop_bpstat for now. Note that we cannot just |
| 7623 | remove bpstats pointing at bpt from the stop_bpstat list |
| 7624 | entirely, as breakpoint commands are associated with the bpstat; |
| 7625 | if we remove it here, then the later call to |
| 7626 | bpstat_do_actions (&stop_bpstat); |
| 7627 | in event-top.c won't do anything, and temporary breakpoints |
| 7628 | with commands won't work. */ |
| 7629 | |
| 7630 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
| 7631 | |
| 7632 | /* Now that breakpoint is removed from breakpoint |
| 7633 | list, update the global location list. This |
| 7634 | will remove locations that used to belong to |
| 7635 | this breakpoint. Do this before freeing |
| 7636 | the breakpoint itself, since remove_breakpoint |
| 7637 | looks at location's owner. It might be better |
| 7638 | design to have location completely self-contained, |
| 7639 | but it's not the case now. */ |
| 7640 | update_global_location_list (0); |
| 7641 | |
| 7642 | |
| 7643 | /* On the chance that someone will soon try again to delete this same |
| 7644 | bp, we mark it as deleted before freeing its storage. */ |
| 7645 | bpt->type = bp_none; |
| 7646 | |
| 7647 | xfree (bpt); |
| 7648 | } |
| 7649 | |
| 7650 | static void |
| 7651 | do_delete_breakpoint_cleanup (void *b) |
| 7652 | { |
| 7653 | delete_breakpoint (b); |
| 7654 | } |
| 7655 | |
| 7656 | struct cleanup * |
| 7657 | make_cleanup_delete_breakpoint (struct breakpoint *b) |
| 7658 | { |
| 7659 | return make_cleanup (do_delete_breakpoint_cleanup, b); |
| 7660 | } |
| 7661 | |
| 7662 | void |
| 7663 | delete_command (char *arg, int from_tty) |
| 7664 | { |
| 7665 | struct breakpoint *b, *temp; |
| 7666 | |
| 7667 | dont_repeat (); |
| 7668 | |
| 7669 | if (arg == 0) |
| 7670 | { |
| 7671 | int breaks_to_delete = 0; |
| 7672 | |
| 7673 | /* Delete all breakpoints if no argument. |
| 7674 | Do not delete internal or call-dummy breakpoints, these |
| 7675 | have to be deleted with an explicit breakpoint number argument. */ |
| 7676 | ALL_BREAKPOINTS (b) |
| 7677 | { |
| 7678 | if (b->type != bp_call_dummy |
| 7679 | && b->type != bp_shlib_event |
| 7680 | && b->type != bp_jit_event |
| 7681 | && b->type != bp_thread_event |
| 7682 | && b->type != bp_overlay_event |
| 7683 | && b->type != bp_longjmp_master |
| 7684 | && b->number >= 0) |
| 7685 | { |
| 7686 | breaks_to_delete = 1; |
| 7687 | break; |
| 7688 | } |
| 7689 | } |
| 7690 | |
| 7691 | /* Ask user only if there are some breakpoints to delete. */ |
| 7692 | if (!from_tty |
| 7693 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
| 7694 | { |
| 7695 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 7696 | { |
| 7697 | if (b->type != bp_call_dummy |
| 7698 | && b->type != bp_shlib_event |
| 7699 | && b->type != bp_thread_event |
| 7700 | && b->type != bp_jit_event |
| 7701 | && b->type != bp_overlay_event |
| 7702 | && b->type != bp_longjmp_master |
| 7703 | && b->number >= 0) |
| 7704 | delete_breakpoint (b); |
| 7705 | } |
| 7706 | } |
| 7707 | } |
| 7708 | else |
| 7709 | map_breakpoint_numbers (arg, delete_breakpoint); |
| 7710 | } |
| 7711 | |
| 7712 | static int |
| 7713 | all_locations_are_pending (struct bp_location *loc) |
| 7714 | { |
| 7715 | for (; loc; loc = loc->next) |
| 7716 | if (!loc->shlib_disabled) |
| 7717 | return 0; |
| 7718 | return 1; |
| 7719 | } |
| 7720 | |
| 7721 | /* Subroutine of update_breakpoint_locations to simplify it. |
| 7722 | Return non-zero if multiple fns in list LOC have the same name. |
| 7723 | Null names are ignored. */ |
| 7724 | |
| 7725 | static int |
| 7726 | ambiguous_names_p (struct bp_location *loc) |
| 7727 | { |
| 7728 | struct bp_location *l; |
| 7729 | htab_t htab = htab_create_alloc (13, htab_hash_string, |
| 7730 | (int (*) (const void *, const void *)) streq, |
| 7731 | NULL, xcalloc, xfree); |
| 7732 | |
| 7733 | for (l = loc; l != NULL; l = l->next) |
| 7734 | { |
| 7735 | const char **slot; |
| 7736 | const char *name = l->function_name; |
| 7737 | |
| 7738 | /* Allow for some names to be NULL, ignore them. */ |
| 7739 | if (name == NULL) |
| 7740 | continue; |
| 7741 | |
| 7742 | slot = (const char **) htab_find_slot (htab, (const void *) name, |
| 7743 | INSERT); |
| 7744 | /* NOTE: We can assume slot != NULL here because xcalloc never returns |
| 7745 | NULL. */ |
| 7746 | if (*slot != NULL) |
| 7747 | { |
| 7748 | htab_delete (htab); |
| 7749 | return 1; |
| 7750 | } |
| 7751 | *slot = name; |
| 7752 | } |
| 7753 | |
| 7754 | htab_delete (htab); |
| 7755 | return 0; |
| 7756 | } |
| 7757 | |
| 7758 | static void |
| 7759 | update_breakpoint_locations (struct breakpoint *b, |
| 7760 | struct symtabs_and_lines sals) |
| 7761 | { |
| 7762 | int i; |
| 7763 | char *s; |
| 7764 | struct bp_location *existing_locations = b->loc; |
| 7765 | |
| 7766 | /* If there's no new locations, and all existing locations |
| 7767 | are pending, don't do anything. This optimizes |
| 7768 | the common case where all locations are in the same |
| 7769 | shared library, that was unloaded. We'd like to |
| 7770 | retain the location, so that when the library |
| 7771 | is loaded again, we don't loose the enabled/disabled |
| 7772 | status of the individual locations. */ |
| 7773 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
| 7774 | return; |
| 7775 | |
| 7776 | b->loc = NULL; |
| 7777 | |
| 7778 | for (i = 0; i < sals.nelts; ++i) |
| 7779 | { |
| 7780 | struct bp_location *new_loc = |
| 7781 | add_location_to_breakpoint (b, &(sals.sals[i])); |
| 7782 | |
| 7783 | /* Reparse conditions, they might contain references to the |
| 7784 | old symtab. */ |
| 7785 | if (b->cond_string != NULL) |
| 7786 | { |
| 7787 | struct gdb_exception e; |
| 7788 | |
| 7789 | s = b->cond_string; |
| 7790 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 7791 | { |
| 7792 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), |
| 7793 | 0); |
| 7794 | } |
| 7795 | if (e.reason < 0) |
| 7796 | { |
| 7797 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), |
| 7798 | b->number, e.message); |
| 7799 | new_loc->enabled = 0; |
| 7800 | } |
| 7801 | } |
| 7802 | |
| 7803 | if (b->source_file != NULL) |
| 7804 | xfree (b->source_file); |
| 7805 | if (sals.sals[i].symtab == NULL) |
| 7806 | b->source_file = NULL; |
| 7807 | else |
| 7808 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
| 7809 | |
| 7810 | if (b->line_number == 0) |
| 7811 | b->line_number = sals.sals[i].line; |
| 7812 | } |
| 7813 | |
| 7814 | /* Update locations of permanent breakpoints. */ |
| 7815 | if (b->enable_state == bp_permanent) |
| 7816 | make_breakpoint_permanent (b); |
| 7817 | |
| 7818 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
| 7819 | { |
| 7820 | struct bp_location *e = existing_locations; |
| 7821 | /* If there are multiple breakpoints with the same function name, |
| 7822 | e.g. for inline functions, comparing function names won't work. |
| 7823 | Instead compare pc addresses; this is just a heuristic as things |
| 7824 | may have moved, but in practice it gives the correct answer |
| 7825 | often enough until a better solution is found. */ |
| 7826 | int have_ambiguous_names = ambiguous_names_p (b->loc); |
| 7827 | |
| 7828 | for (; e; e = e->next) |
| 7829 | { |
| 7830 | if (!e->enabled && e->function_name) |
| 7831 | { |
| 7832 | struct bp_location *l = b->loc; |
| 7833 | if (have_ambiguous_names) |
| 7834 | { |
| 7835 | for (; l; l = l->next) |
| 7836 | if (e->address == l->address) |
| 7837 | { |
| 7838 | l->enabled = 0; |
| 7839 | break; |
| 7840 | } |
| 7841 | } |
| 7842 | else |
| 7843 | { |
| 7844 | for (; l; l = l->next) |
| 7845 | if (l->function_name |
| 7846 | && strcmp (e->function_name, l->function_name) == 0) |
| 7847 | { |
| 7848 | l->enabled = 0; |
| 7849 | break; |
| 7850 | } |
| 7851 | } |
| 7852 | } |
| 7853 | } |
| 7854 | } |
| 7855 | |
| 7856 | update_global_location_list (1); |
| 7857 | } |
| 7858 | |
| 7859 | |
| 7860 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
| 7861 | The value we return ends up being the return value from catch_errors. |
| 7862 | Unused in this case. */ |
| 7863 | |
| 7864 | static int |
| 7865 | breakpoint_re_set_one (void *bint) |
| 7866 | { |
| 7867 | /* get past catch_errs */ |
| 7868 | struct breakpoint *b = (struct breakpoint *) bint; |
| 7869 | struct value *mark; |
| 7870 | int i; |
| 7871 | int not_found = 0; |
| 7872 | int *not_found_ptr = ¬_found; |
| 7873 | struct symtabs_and_lines sals = {}; |
| 7874 | struct symtabs_and_lines expanded; |
| 7875 | char *s; |
| 7876 | enum enable_state save_enable; |
| 7877 | struct gdb_exception e; |
| 7878 | struct cleanup *cleanups; |
| 7879 | |
| 7880 | switch (b->type) |
| 7881 | { |
| 7882 | case bp_none: |
| 7883 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
| 7884 | b->number); |
| 7885 | return 0; |
| 7886 | case bp_breakpoint: |
| 7887 | case bp_hardware_breakpoint: |
| 7888 | case bp_tracepoint: |
| 7889 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
| 7890 | if (b->enable_state == bp_startup_disabled) |
| 7891 | return 0; |
| 7892 | |
| 7893 | if (b->addr_string == NULL) |
| 7894 | { |
| 7895 | /* Anything without a string can't be re-set. */ |
| 7896 | delete_breakpoint (b); |
| 7897 | return 0; |
| 7898 | } |
| 7899 | |
| 7900 | set_language (b->language); |
| 7901 | input_radix = b->input_radix; |
| 7902 | s = b->addr_string; |
| 7903 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 7904 | { |
| 7905 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
| 7906 | not_found_ptr); |
| 7907 | } |
| 7908 | if (e.reason < 0) |
| 7909 | { |
| 7910 | int not_found_and_ok = 0; |
| 7911 | /* For pending breakpoints, it's expected that parsing |
| 7912 | will fail until the right shared library is loaded. |
| 7913 | User has already told to create pending breakpoints and |
| 7914 | don't need extra messages. If breakpoint is in bp_shlib_disabled |
| 7915 | state, then user already saw the message about that breakpoint |
| 7916 | being disabled, and don't want to see more errors. */ |
| 7917 | if (not_found |
| 7918 | && (b->condition_not_parsed |
| 7919 | || (b->loc && b->loc->shlib_disabled) |
| 7920 | || b->enable_state == bp_disabled)) |
| 7921 | not_found_and_ok = 1; |
| 7922 | |
| 7923 | if (!not_found_and_ok) |
| 7924 | { |
| 7925 | /* We surely don't want to warn about the same breakpoint |
| 7926 | 10 times. One solution, implemented here, is disable |
| 7927 | the breakpoint on error. Another solution would be to |
| 7928 | have separate 'warning emitted' flag. Since this |
| 7929 | happens only when a binary has changed, I don't know |
| 7930 | which approach is better. */ |
| 7931 | b->enable_state = bp_disabled; |
| 7932 | throw_exception (e); |
| 7933 | } |
| 7934 | } |
| 7935 | |
| 7936 | if (not_found) |
| 7937 | break; |
| 7938 | |
| 7939 | gdb_assert (sals.nelts == 1); |
| 7940 | resolve_sal_pc (&sals.sals[0]); |
| 7941 | if (b->condition_not_parsed && s && s[0]) |
| 7942 | { |
| 7943 | char *cond_string = 0; |
| 7944 | int thread = -1; |
| 7945 | int task = 0; |
| 7946 | |
| 7947 | find_condition_and_thread (s, sals.sals[0].pc, |
| 7948 | &cond_string, &thread, &task); |
| 7949 | if (cond_string) |
| 7950 | b->cond_string = cond_string; |
| 7951 | b->thread = thread; |
| 7952 | b->task = task; |
| 7953 | b->condition_not_parsed = 0; |
| 7954 | } |
| 7955 | expanded = expand_line_sal_maybe (sals.sals[0]); |
| 7956 | cleanups = make_cleanup (xfree, sals.sals); |
| 7957 | update_breakpoint_locations (b, expanded); |
| 7958 | do_cleanups (cleanups); |
| 7959 | break; |
| 7960 | |
| 7961 | case bp_watchpoint: |
| 7962 | case bp_hardware_watchpoint: |
| 7963 | case bp_read_watchpoint: |
| 7964 | case bp_access_watchpoint: |
| 7965 | /* Watchpoint can be either on expression using entirely global variables, |
| 7966 | or it can be on local variables. |
| 7967 | |
| 7968 | Watchpoints of the first kind are never auto-deleted, and even persist |
| 7969 | across program restarts. Since they can use variables from shared |
| 7970 | libraries, we need to reparse expression as libraries are loaded |
| 7971 | and unloaded. |
| 7972 | |
| 7973 | Watchpoints on local variables can also change meaning as result |
| 7974 | of solib event. For example, if a watchpoint uses both a local and |
| 7975 | a global variables in expression, it's a local watchpoint, but |
| 7976 | unloading of a shared library will make the expression invalid. |
| 7977 | This is not a very common use case, but we still re-evaluate |
| 7978 | expression, to avoid surprises to the user. |
| 7979 | |
| 7980 | Note that for local watchpoints, we re-evaluate it only if |
| 7981 | watchpoints frame id is still valid. If it's not, it means |
| 7982 | the watchpoint is out of scope and will be deleted soon. In fact, |
| 7983 | I'm not sure we'll ever be called in this case. |
| 7984 | |
| 7985 | If a local watchpoint's frame id is still valid, then |
| 7986 | b->exp_valid_block is likewise valid, and we can safely use it. |
| 7987 | |
| 7988 | Don't do anything about disabled watchpoints, since they will |
| 7989 | be reevaluated again when enabled. */ |
| 7990 | update_watchpoint (b, 1 /* reparse */); |
| 7991 | break; |
| 7992 | /* We needn't really do anything to reset these, since the mask |
| 7993 | that requests them is unaffected by e.g., new libraries being |
| 7994 | loaded. */ |
| 7995 | case bp_catchpoint: |
| 7996 | break; |
| 7997 | |
| 7998 | default: |
| 7999 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
| 8000 | /* fall through */ |
| 8001 | /* Delete overlay event and longjmp master breakpoints; they will be |
| 8002 | reset later by breakpoint_re_set. */ |
| 8003 | case bp_overlay_event: |
| 8004 | case bp_longjmp_master: |
| 8005 | delete_breakpoint (b); |
| 8006 | break; |
| 8007 | |
| 8008 | /* This breakpoint is special, it's set up when the inferior |
| 8009 | starts and we really don't want to touch it. */ |
| 8010 | case bp_shlib_event: |
| 8011 | |
| 8012 | /* Like bp_shlib_event, this breakpoint type is special. |
| 8013 | Once it is set up, we do not want to touch it. */ |
| 8014 | case bp_thread_event: |
| 8015 | |
| 8016 | /* Keep temporary breakpoints, which can be encountered when we step |
| 8017 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. |
| 8018 | Otherwise these should have been blown away via the cleanup chain |
| 8019 | or by breakpoint_init_inferior when we rerun the executable. */ |
| 8020 | case bp_until: |
| 8021 | case bp_finish: |
| 8022 | case bp_watchpoint_scope: |
| 8023 | case bp_call_dummy: |
| 8024 | case bp_step_resume: |
| 8025 | case bp_longjmp: |
| 8026 | case bp_longjmp_resume: |
| 8027 | case bp_jit_event: |
| 8028 | break; |
| 8029 | } |
| 8030 | |
| 8031 | return 0; |
| 8032 | } |
| 8033 | |
| 8034 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
| 8035 | void |
| 8036 | breakpoint_re_set (void) |
| 8037 | { |
| 8038 | struct breakpoint *b, *temp; |
| 8039 | enum language save_language; |
| 8040 | int save_input_radix; |
| 8041 | |
| 8042 | save_language = current_language->la_language; |
| 8043 | save_input_radix = input_radix; |
| 8044 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 8045 | { |
| 8046 | /* Format possible error msg */ |
| 8047 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
| 8048 | b->number); |
| 8049 | struct cleanup *cleanups = make_cleanup (xfree, message); |
| 8050 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
| 8051 | do_cleanups (cleanups); |
| 8052 | } |
| 8053 | set_language (save_language); |
| 8054 | input_radix = save_input_radix; |
| 8055 | |
| 8056 | jit_breakpoint_re_set (); |
| 8057 | |
| 8058 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
| 8059 | create_longjmp_master_breakpoint ("longjmp"); |
| 8060 | create_longjmp_master_breakpoint ("_longjmp"); |
| 8061 | create_longjmp_master_breakpoint ("siglongjmp"); |
| 8062 | create_longjmp_master_breakpoint ("_siglongjmp"); |
| 8063 | } |
| 8064 | \f |
| 8065 | /* Reset the thread number of this breakpoint: |
| 8066 | |
| 8067 | - If the breakpoint is for all threads, leave it as-is. |
| 8068 | - Else, reset it to the current thread for inferior_ptid. */ |
| 8069 | void |
| 8070 | breakpoint_re_set_thread (struct breakpoint *b) |
| 8071 | { |
| 8072 | if (b->thread != -1) |
| 8073 | { |
| 8074 | if (in_thread_list (inferior_ptid)) |
| 8075 | b->thread = pid_to_thread_id (inferior_ptid); |
| 8076 | } |
| 8077 | } |
| 8078 | |
| 8079 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 8080 | If from_tty is nonzero, it prints a message to that effect, |
| 8081 | which ends with a period (no newline). */ |
| 8082 | |
| 8083 | void |
| 8084 | set_ignore_count (int bptnum, int count, int from_tty) |
| 8085 | { |
| 8086 | struct breakpoint *b; |
| 8087 | |
| 8088 | if (count < 0) |
| 8089 | count = 0; |
| 8090 | |
| 8091 | ALL_BREAKPOINTS (b) |
| 8092 | if (b->number == bptnum) |
| 8093 | { |
| 8094 | b->ignore_count = count; |
| 8095 | if (from_tty) |
| 8096 | { |
| 8097 | if (count == 0) |
| 8098 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
| 8099 | bptnum); |
| 8100 | else if (count == 1) |
| 8101 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
| 8102 | bptnum); |
| 8103 | else |
| 8104 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
| 8105 | count, bptnum); |
| 8106 | } |
| 8107 | breakpoints_changed (); |
| 8108 | observer_notify_breakpoint_modified (b->number); |
| 8109 | return; |
| 8110 | } |
| 8111 | |
| 8112 | error (_("No breakpoint number %d."), bptnum); |
| 8113 | } |
| 8114 | |
| 8115 | void |
| 8116 | make_breakpoint_silent (struct breakpoint *b) |
| 8117 | { |
| 8118 | /* Silence the breakpoint. */ |
| 8119 | b->silent = 1; |
| 8120 | } |
| 8121 | |
| 8122 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
| 8123 | |
| 8124 | static void |
| 8125 | ignore_command (char *args, int from_tty) |
| 8126 | { |
| 8127 | char *p = args; |
| 8128 | int num; |
| 8129 | |
| 8130 | if (p == 0) |
| 8131 | error_no_arg (_("a breakpoint number")); |
| 8132 | |
| 8133 | num = get_number (&p); |
| 8134 | if (num == 0) |
| 8135 | error (_("bad breakpoint number: '%s'"), args); |
| 8136 | if (*p == 0) |
| 8137 | error (_("Second argument (specified ignore-count) is missing.")); |
| 8138 | |
| 8139 | set_ignore_count (num, |
| 8140 | longest_to_int (value_as_long (parse_and_eval (p))), |
| 8141 | from_tty); |
| 8142 | if (from_tty) |
| 8143 | printf_filtered ("\n"); |
| 8144 | } |
| 8145 | \f |
| 8146 | /* Call FUNCTION on each of the breakpoints |
| 8147 | whose numbers are given in ARGS. */ |
| 8148 | |
| 8149 | static void |
| 8150 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
| 8151 | { |
| 8152 | char *p = args; |
| 8153 | char *p1; |
| 8154 | int num; |
| 8155 | struct breakpoint *b, *tmp; |
| 8156 | int match; |
| 8157 | |
| 8158 | if (p == 0) |
| 8159 | error_no_arg (_("one or more breakpoint numbers")); |
| 8160 | |
| 8161 | while (*p) |
| 8162 | { |
| 8163 | match = 0; |
| 8164 | p1 = p; |
| 8165 | |
| 8166 | num = get_number_or_range (&p1); |
| 8167 | if (num == 0) |
| 8168 | { |
| 8169 | warning (_("bad breakpoint number at or near '%s'"), p); |
| 8170 | } |
| 8171 | else |
| 8172 | { |
| 8173 | ALL_BREAKPOINTS_SAFE (b, tmp) |
| 8174 | if (b->number == num) |
| 8175 | { |
| 8176 | struct breakpoint *related_breakpoint = b->related_breakpoint; |
| 8177 | match = 1; |
| 8178 | function (b); |
| 8179 | if (related_breakpoint) |
| 8180 | function (related_breakpoint); |
| 8181 | break; |
| 8182 | } |
| 8183 | if (match == 0) |
| 8184 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
| 8185 | } |
| 8186 | p = p1; |
| 8187 | } |
| 8188 | } |
| 8189 | |
| 8190 | static struct bp_location * |
| 8191 | find_location_by_number (char *number) |
| 8192 | { |
| 8193 | char *dot = strchr (number, '.'); |
| 8194 | char *p1; |
| 8195 | int bp_num; |
| 8196 | int loc_num; |
| 8197 | struct breakpoint *b; |
| 8198 | struct bp_location *loc; |
| 8199 | |
| 8200 | *dot = '\0'; |
| 8201 | |
| 8202 | p1 = number; |
| 8203 | bp_num = get_number_or_range (&p1); |
| 8204 | if (bp_num == 0) |
| 8205 | error (_("Bad breakpoint number '%s'"), number); |
| 8206 | |
| 8207 | ALL_BREAKPOINTS (b) |
| 8208 | if (b->number == bp_num) |
| 8209 | { |
| 8210 | break; |
| 8211 | } |
| 8212 | |
| 8213 | if (!b || b->number != bp_num) |
| 8214 | error (_("Bad breakpoint number '%s'"), number); |
| 8215 | |
| 8216 | p1 = dot+1; |
| 8217 | loc_num = get_number_or_range (&p1); |
| 8218 | if (loc_num == 0) |
| 8219 | error (_("Bad breakpoint location number '%s'"), number); |
| 8220 | |
| 8221 | --loc_num; |
| 8222 | loc = b->loc; |
| 8223 | for (;loc_num && loc; --loc_num, loc = loc->next) |
| 8224 | ; |
| 8225 | if (!loc) |
| 8226 | error (_("Bad breakpoint location number '%s'"), dot+1); |
| 8227 | |
| 8228 | return loc; |
| 8229 | } |
| 8230 | |
| 8231 | |
| 8232 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 8233 | If from_tty is nonzero, it prints a message to that effect, |
| 8234 | which ends with a period (no newline). */ |
| 8235 | |
| 8236 | void |
| 8237 | disable_breakpoint (struct breakpoint *bpt) |
| 8238 | { |
| 8239 | /* Never disable a watchpoint scope breakpoint; we want to |
| 8240 | hit them when we leave scope so we can delete both the |
| 8241 | watchpoint and its scope breakpoint at that time. */ |
| 8242 | if (bpt->type == bp_watchpoint_scope) |
| 8243 | return; |
| 8244 | |
| 8245 | /* You can't disable permanent breakpoints. */ |
| 8246 | if (bpt->enable_state == bp_permanent) |
| 8247 | return; |
| 8248 | |
| 8249 | bpt->enable_state = bp_disabled; |
| 8250 | |
| 8251 | update_global_location_list (0); |
| 8252 | |
| 8253 | observer_notify_breakpoint_modified (bpt->number); |
| 8254 | } |
| 8255 | |
| 8256 | static void |
| 8257 | disable_command (char *args, int from_tty) |
| 8258 | { |
| 8259 | struct breakpoint *bpt; |
| 8260 | if (args == 0) |
| 8261 | ALL_BREAKPOINTS (bpt) |
| 8262 | switch (bpt->type) |
| 8263 | { |
| 8264 | case bp_none: |
| 8265 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
| 8266 | bpt->number); |
| 8267 | continue; |
| 8268 | case bp_breakpoint: |
| 8269 | case bp_tracepoint: |
| 8270 | case bp_catchpoint: |
| 8271 | case bp_hardware_breakpoint: |
| 8272 | case bp_watchpoint: |
| 8273 | case bp_hardware_watchpoint: |
| 8274 | case bp_read_watchpoint: |
| 8275 | case bp_access_watchpoint: |
| 8276 | disable_breakpoint (bpt); |
| 8277 | default: |
| 8278 | continue; |
| 8279 | } |
| 8280 | else if (strchr (args, '.')) |
| 8281 | { |
| 8282 | struct bp_location *loc = find_location_by_number (args); |
| 8283 | if (loc) |
| 8284 | loc->enabled = 0; |
| 8285 | update_global_location_list (0); |
| 8286 | } |
| 8287 | else |
| 8288 | map_breakpoint_numbers (args, disable_breakpoint); |
| 8289 | } |
| 8290 | |
| 8291 | static void |
| 8292 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
| 8293 | { |
| 8294 | int target_resources_ok, other_type_used; |
| 8295 | struct value *mark; |
| 8296 | |
| 8297 | if (bpt->type == bp_hardware_breakpoint) |
| 8298 | { |
| 8299 | int i; |
| 8300 | i = hw_breakpoint_used_count (); |
| 8301 | target_resources_ok = |
| 8302 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 8303 | i + 1, 0); |
| 8304 | if (target_resources_ok == 0) |
| 8305 | error (_("No hardware breakpoint support in the target.")); |
| 8306 | else if (target_resources_ok < 0) |
| 8307 | error (_("Hardware breakpoints used exceeds limit.")); |
| 8308 | } |
| 8309 | |
| 8310 | if (bpt->type == bp_watchpoint |
| 8311 | || bpt->type == bp_hardware_watchpoint |
| 8312 | || bpt->type == bp_read_watchpoint |
| 8313 | || bpt->type == bp_access_watchpoint) |
| 8314 | { |
| 8315 | struct gdb_exception e; |
| 8316 | |
| 8317 | TRY_CATCH (e, RETURN_MASK_ALL) |
| 8318 | { |
| 8319 | update_watchpoint (bpt, 1 /* reparse */); |
| 8320 | } |
| 8321 | if (e.reason < 0) |
| 8322 | { |
| 8323 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
| 8324 | bpt->number); |
| 8325 | return; |
| 8326 | } |
| 8327 | } |
| 8328 | |
| 8329 | if (bpt->enable_state != bp_permanent) |
| 8330 | bpt->enable_state = bp_enabled; |
| 8331 | bpt->disposition = disposition; |
| 8332 | update_global_location_list (1); |
| 8333 | breakpoints_changed (); |
| 8334 | |
| 8335 | observer_notify_breakpoint_modified (bpt->number); |
| 8336 | } |
| 8337 | |
| 8338 | |
| 8339 | void |
| 8340 | enable_breakpoint (struct breakpoint *bpt) |
| 8341 | { |
| 8342 | do_enable_breakpoint (bpt, bpt->disposition); |
| 8343 | } |
| 8344 | |
| 8345 | /* The enable command enables the specified breakpoints (or all defined |
| 8346 | breakpoints) so they once again become (or continue to be) effective |
| 8347 | in stopping the inferior. */ |
| 8348 | |
| 8349 | static void |
| 8350 | enable_command (char *args, int from_tty) |
| 8351 | { |
| 8352 | struct breakpoint *bpt; |
| 8353 | if (args == 0) |
| 8354 | ALL_BREAKPOINTS (bpt) |
| 8355 | switch (bpt->type) |
| 8356 | { |
| 8357 | case bp_none: |
| 8358 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
| 8359 | bpt->number); |
| 8360 | continue; |
| 8361 | case bp_breakpoint: |
| 8362 | case bp_tracepoint: |
| 8363 | case bp_catchpoint: |
| 8364 | case bp_hardware_breakpoint: |
| 8365 | case bp_watchpoint: |
| 8366 | case bp_hardware_watchpoint: |
| 8367 | case bp_read_watchpoint: |
| 8368 | case bp_access_watchpoint: |
| 8369 | enable_breakpoint (bpt); |
| 8370 | default: |
| 8371 | continue; |
| 8372 | } |
| 8373 | else if (strchr (args, '.')) |
| 8374 | { |
| 8375 | struct bp_location *loc = find_location_by_number (args); |
| 8376 | if (loc) |
| 8377 | loc->enabled = 1; |
| 8378 | update_global_location_list (1); |
| 8379 | } |
| 8380 | else |
| 8381 | map_breakpoint_numbers (args, enable_breakpoint); |
| 8382 | } |
| 8383 | |
| 8384 | static void |
| 8385 | enable_once_breakpoint (struct breakpoint *bpt) |
| 8386 | { |
| 8387 | do_enable_breakpoint (bpt, disp_disable); |
| 8388 | } |
| 8389 | |
| 8390 | static void |
| 8391 | enable_once_command (char *args, int from_tty) |
| 8392 | { |
| 8393 | map_breakpoint_numbers (args, enable_once_breakpoint); |
| 8394 | } |
| 8395 | |
| 8396 | static void |
| 8397 | enable_delete_breakpoint (struct breakpoint *bpt) |
| 8398 | { |
| 8399 | do_enable_breakpoint (bpt, disp_del); |
| 8400 | } |
| 8401 | |
| 8402 | static void |
| 8403 | enable_delete_command (char *args, int from_tty) |
| 8404 | { |
| 8405 | map_breakpoint_numbers (args, enable_delete_breakpoint); |
| 8406 | } |
| 8407 | \f |
| 8408 | static void |
| 8409 | set_breakpoint_cmd (char *args, int from_tty) |
| 8410 | { |
| 8411 | } |
| 8412 | |
| 8413 | static void |
| 8414 | show_breakpoint_cmd (char *args, int from_tty) |
| 8415 | { |
| 8416 | } |
| 8417 | |
| 8418 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
| 8419 | |
| 8420 | struct symtabs_and_lines |
| 8421 | decode_line_spec_1 (char *string, int funfirstline) |
| 8422 | { |
| 8423 | struct symtabs_and_lines sals; |
| 8424 | if (string == 0) |
| 8425 | error (_("Empty line specification.")); |
| 8426 | if (default_breakpoint_valid) |
| 8427 | sals = decode_line_1 (&string, funfirstline, |
| 8428 | default_breakpoint_symtab, |
| 8429 | default_breakpoint_line, |
| 8430 | (char ***) NULL, NULL); |
| 8431 | else |
| 8432 | sals = decode_line_1 (&string, funfirstline, |
| 8433 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
| 8434 | if (*string) |
| 8435 | error (_("Junk at end of line specification: %s"), string); |
| 8436 | return sals; |
| 8437 | } |
| 8438 | |
| 8439 | /* Create and insert a raw software breakpoint at PC. Return an |
| 8440 | identifier, which should be used to remove the breakpoint later. |
| 8441 | In general, places which call this should be using something on the |
| 8442 | breakpoint chain instead; this function should be eliminated |
| 8443 | someday. */ |
| 8444 | |
| 8445 | void * |
| 8446 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, CORE_ADDR pc) |
| 8447 | { |
| 8448 | struct bp_target_info *bp_tgt; |
| 8449 | |
| 8450 | bp_tgt = xmalloc (sizeof (struct bp_target_info)); |
| 8451 | memset (bp_tgt, 0, sizeof (struct bp_target_info)); |
| 8452 | |
| 8453 | bp_tgt->placed_address = pc; |
| 8454 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
| 8455 | { |
| 8456 | /* Could not insert the breakpoint. */ |
| 8457 | xfree (bp_tgt); |
| 8458 | return NULL; |
| 8459 | } |
| 8460 | |
| 8461 | return bp_tgt; |
| 8462 | } |
| 8463 | |
| 8464 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ |
| 8465 | |
| 8466 | int |
| 8467 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
| 8468 | { |
| 8469 | struct bp_target_info *bp_tgt = bp; |
| 8470 | int ret; |
| 8471 | |
| 8472 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
| 8473 | xfree (bp_tgt); |
| 8474 | |
| 8475 | return ret; |
| 8476 | } |
| 8477 | |
| 8478 | /* One (or perhaps two) breakpoints used for software single stepping. */ |
| 8479 | |
| 8480 | static void *single_step_breakpoints[2]; |
| 8481 | static struct gdbarch *single_step_gdbarch[2]; |
| 8482 | |
| 8483 | /* Create and insert a breakpoint for software single step. */ |
| 8484 | |
| 8485 | void |
| 8486 | insert_single_step_breakpoint (struct gdbarch *gdbarch, CORE_ADDR next_pc) |
| 8487 | { |
| 8488 | void **bpt_p; |
| 8489 | |
| 8490 | if (single_step_breakpoints[0] == NULL) |
| 8491 | { |
| 8492 | bpt_p = &single_step_breakpoints[0]; |
| 8493 | single_step_gdbarch[0] = gdbarch; |
| 8494 | } |
| 8495 | else |
| 8496 | { |
| 8497 | gdb_assert (single_step_breakpoints[1] == NULL); |
| 8498 | bpt_p = &single_step_breakpoints[1]; |
| 8499 | single_step_gdbarch[1] = gdbarch; |
| 8500 | } |
| 8501 | |
| 8502 | /* NOTE drow/2006-04-11: A future improvement to this function would be |
| 8503 | to only create the breakpoints once, and actually put them on the |
| 8504 | breakpoint chain. That would let us use set_raw_breakpoint. We could |
| 8505 | adjust the addresses each time they were needed. Doing this requires |
| 8506 | corresponding changes elsewhere where single step breakpoints are |
| 8507 | handled, however. So, for now, we use this. */ |
| 8508 | |
| 8509 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, next_pc); |
| 8510 | if (*bpt_p == NULL) |
| 8511 | error (_("Could not insert single-step breakpoint at %s"), |
| 8512 | paddress (gdbarch, next_pc)); |
| 8513 | } |
| 8514 | |
| 8515 | /* Remove and delete any breakpoints used for software single step. */ |
| 8516 | |
| 8517 | void |
| 8518 | remove_single_step_breakpoints (void) |
| 8519 | { |
| 8520 | gdb_assert (single_step_breakpoints[0] != NULL); |
| 8521 | |
| 8522 | /* See insert_single_step_breakpoint for more about this deprecated |
| 8523 | call. */ |
| 8524 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
| 8525 | single_step_breakpoints[0]); |
| 8526 | single_step_gdbarch[0] = NULL; |
| 8527 | single_step_breakpoints[0] = NULL; |
| 8528 | |
| 8529 | if (single_step_breakpoints[1] != NULL) |
| 8530 | { |
| 8531 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
| 8532 | single_step_breakpoints[1]); |
| 8533 | single_step_gdbarch[1] = NULL; |
| 8534 | single_step_breakpoints[1] = NULL; |
| 8535 | } |
| 8536 | } |
| 8537 | |
| 8538 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
| 8539 | |
| 8540 | static int |
| 8541 | single_step_breakpoint_inserted_here_p (CORE_ADDR pc) |
| 8542 | { |
| 8543 | int i; |
| 8544 | |
| 8545 | for (i = 0; i < 2; i++) |
| 8546 | { |
| 8547 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; |
| 8548 | if (bp_tgt && bp_tgt->placed_address == pc) |
| 8549 | return 1; |
| 8550 | } |
| 8551 | |
| 8552 | return 0; |
| 8553 | } |
| 8554 | |
| 8555 | /* Tracepoint-specific operations. */ |
| 8556 | |
| 8557 | /* Set tracepoint count to NUM. */ |
| 8558 | static void |
| 8559 | set_tracepoint_count (int num) |
| 8560 | { |
| 8561 | tracepoint_count = num; |
| 8562 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
| 8563 | } |
| 8564 | |
| 8565 | void |
| 8566 | trace_command (char *arg, int from_tty) |
| 8567 | { |
| 8568 | break_command_really (get_current_arch (), |
| 8569 | arg, |
| 8570 | NULL, 0, 1 /* parse arg */, |
| 8571 | 0 /* tempflag */, 0 /* hardwareflag */, |
| 8572 | 1 /* traceflag */, |
| 8573 | 0 /* Ignore count */, |
| 8574 | pending_break_support, |
| 8575 | NULL, |
| 8576 | from_tty, |
| 8577 | 1 /* enabled */); |
| 8578 | set_tracepoint_count (breakpoint_count); |
| 8579 | } |
| 8580 | |
| 8581 | /* Print information on tracepoint number TPNUM_EXP, or all if |
| 8582 | omitted. */ |
| 8583 | |
| 8584 | static void |
| 8585 | tracepoints_info (char *tpnum_exp, int from_tty) |
| 8586 | { |
| 8587 | struct breakpoint *b; |
| 8588 | int tps_to_list = 0; |
| 8589 | |
| 8590 | /* In the no-arguments case, say "No tracepoints" if none found. */ |
| 8591 | if (tpnum_exp == 0) |
| 8592 | { |
| 8593 | ALL_TRACEPOINTS (b) |
| 8594 | { |
| 8595 | if (b->number >= 0) |
| 8596 | { |
| 8597 | tps_to_list = 1; |
| 8598 | break; |
| 8599 | } |
| 8600 | } |
| 8601 | if (!tps_to_list) |
| 8602 | { |
| 8603 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
| 8604 | return; |
| 8605 | } |
| 8606 | } |
| 8607 | |
| 8608 | /* Otherwise be the same as "info break". */ |
| 8609 | breakpoints_info (tpnum_exp, from_tty); |
| 8610 | } |
| 8611 | |
| 8612 | /* The 'enable trace' command enables tracepoints. |
| 8613 | Not supported by all targets. */ |
| 8614 | static void |
| 8615 | enable_trace_command (char *args, int from_tty) |
| 8616 | { |
| 8617 | enable_command (args, from_tty); |
| 8618 | } |
| 8619 | |
| 8620 | /* The 'disable trace' command disables tracepoints. |
| 8621 | Not supported by all targets. */ |
| 8622 | static void |
| 8623 | disable_trace_command (char *args, int from_tty) |
| 8624 | { |
| 8625 | disable_command (args, from_tty); |
| 8626 | } |
| 8627 | |
| 8628 | /* Remove a tracepoint (or all if no argument) */ |
| 8629 | static void |
| 8630 | delete_trace_command (char *arg, int from_tty) |
| 8631 | { |
| 8632 | struct breakpoint *b, *temp; |
| 8633 | |
| 8634 | dont_repeat (); |
| 8635 | |
| 8636 | if (arg == 0) |
| 8637 | { |
| 8638 | int breaks_to_delete = 0; |
| 8639 | |
| 8640 | /* Delete all breakpoints if no argument. |
| 8641 | Do not delete internal or call-dummy breakpoints, these |
| 8642 | have to be deleted with an explicit breakpoint number argument. */ |
| 8643 | ALL_TRACEPOINTS (b) |
| 8644 | { |
| 8645 | if (b->number >= 0) |
| 8646 | { |
| 8647 | breaks_to_delete = 1; |
| 8648 | break; |
| 8649 | } |
| 8650 | } |
| 8651 | |
| 8652 | /* Ask user only if there are some breakpoints to delete. */ |
| 8653 | if (!from_tty |
| 8654 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) |
| 8655 | { |
| 8656 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 8657 | { |
| 8658 | if (b->type == bp_tracepoint |
| 8659 | && b->number >= 0) |
| 8660 | delete_breakpoint (b); |
| 8661 | } |
| 8662 | } |
| 8663 | } |
| 8664 | else |
| 8665 | map_breakpoint_numbers (arg, delete_breakpoint); |
| 8666 | } |
| 8667 | |
| 8668 | /* Set passcount for tracepoint. |
| 8669 | |
| 8670 | First command argument is passcount, second is tracepoint number. |
| 8671 | If tracepoint number omitted, apply to most recently defined. |
| 8672 | Also accepts special argument "all". */ |
| 8673 | |
| 8674 | static void |
| 8675 | trace_pass_command (char *args, int from_tty) |
| 8676 | { |
| 8677 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; |
| 8678 | unsigned int count; |
| 8679 | int all = 0; |
| 8680 | |
| 8681 | if (args == 0 || *args == 0) |
| 8682 | error (_("passcount command requires an argument (count + optional TP num)")); |
| 8683 | |
| 8684 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
| 8685 | |
| 8686 | while (*args && isspace ((int) *args)) |
| 8687 | args++; |
| 8688 | |
| 8689 | if (*args && strncasecmp (args, "all", 3) == 0) |
| 8690 | { |
| 8691 | args += 3; /* Skip special argument "all". */ |
| 8692 | all = 1; |
| 8693 | if (*args) |
| 8694 | error (_("Junk at end of arguments.")); |
| 8695 | } |
| 8696 | else |
| 8697 | t1 = get_tracepoint_by_number (&args, 1, 1); |
| 8698 | |
| 8699 | do |
| 8700 | { |
| 8701 | if (t1) |
| 8702 | { |
| 8703 | ALL_TRACEPOINTS (t2) |
| 8704 | if (t1 == (struct breakpoint *) -1 || t1 == t2) |
| 8705 | { |
| 8706 | t2->pass_count = count; |
| 8707 | observer_notify_tracepoint_modified (t2->number); |
| 8708 | if (from_tty) |
| 8709 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), |
| 8710 | t2->number, count); |
| 8711 | } |
| 8712 | if (! all && *args) |
| 8713 | t1 = get_tracepoint_by_number (&args, 1, 0); |
| 8714 | } |
| 8715 | } |
| 8716 | while (*args); |
| 8717 | } |
| 8718 | |
| 8719 | struct breakpoint * |
| 8720 | get_tracepoint (int num) |
| 8721 | { |
| 8722 | struct breakpoint *t; |
| 8723 | |
| 8724 | ALL_TRACEPOINTS (t) |
| 8725 | if (t->number == num) |
| 8726 | return t; |
| 8727 | |
| 8728 | return NULL; |
| 8729 | } |
| 8730 | |
| 8731 | /* Utility: parse a tracepoint number and look it up in the list. |
| 8732 | If MULTI_P is true, there might be a range of tracepoints in ARG. |
| 8733 | if OPTIONAL_P is true, then if the argument is missing, the most |
| 8734 | recent tracepoint (tracepoint_count) is returned. */ |
| 8735 | struct breakpoint * |
| 8736 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) |
| 8737 | { |
| 8738 | extern int tracepoint_count; |
| 8739 | struct breakpoint *t; |
| 8740 | int tpnum; |
| 8741 | char *instring = arg == NULL ? NULL : *arg; |
| 8742 | |
| 8743 | if (arg == NULL || *arg == NULL || ! **arg) |
| 8744 | { |
| 8745 | if (optional_p) |
| 8746 | tpnum = tracepoint_count; |
| 8747 | else |
| 8748 | error_no_arg (_("tracepoint number")); |
| 8749 | } |
| 8750 | else |
| 8751 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); |
| 8752 | |
| 8753 | if (tpnum <= 0) |
| 8754 | { |
| 8755 | if (instring && *instring) |
| 8756 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), |
| 8757 | instring); |
| 8758 | else |
| 8759 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); |
| 8760 | return NULL; |
| 8761 | } |
| 8762 | |
| 8763 | ALL_TRACEPOINTS (t) |
| 8764 | if (t->number == tpnum) |
| 8765 | { |
| 8766 | return t; |
| 8767 | } |
| 8768 | |
| 8769 | /* FIXME: if we are in the middle of a range we don't want to give |
| 8770 | a message. The current interface to get_number_or_range doesn't |
| 8771 | allow us to discover this. */ |
| 8772 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
| 8773 | return NULL; |
| 8774 | } |
| 8775 | |
| 8776 | /* save-tracepoints command */ |
| 8777 | static void |
| 8778 | tracepoint_save_command (char *args, int from_tty) |
| 8779 | { |
| 8780 | struct breakpoint *tp; |
| 8781 | int any_tp = 0; |
| 8782 | struct action_line *line; |
| 8783 | FILE *fp; |
| 8784 | char *i1 = " ", *i2 = " "; |
| 8785 | char *indent, *actionline, *pathname; |
| 8786 | char tmp[40]; |
| 8787 | struct cleanup *cleanup; |
| 8788 | |
| 8789 | if (args == 0 || *args == 0) |
| 8790 | error (_("Argument required (file name in which to save tracepoints)")); |
| 8791 | |
| 8792 | /* See if we have anything to save. */ |
| 8793 | ALL_TRACEPOINTS (tp) |
| 8794 | { |
| 8795 | any_tp = 1; |
| 8796 | break; |
| 8797 | } |
| 8798 | if (!any_tp) |
| 8799 | { |
| 8800 | warning (_("save-tracepoints: no tracepoints to save.")); |
| 8801 | return; |
| 8802 | } |
| 8803 | |
| 8804 | pathname = tilde_expand (args); |
| 8805 | cleanup = make_cleanup (xfree, pathname); |
| 8806 | fp = fopen (pathname, "w"); |
| 8807 | if (!fp) |
| 8808 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
| 8809 | args, safe_strerror (errno)); |
| 8810 | make_cleanup_fclose (fp); |
| 8811 | |
| 8812 | ALL_TRACEPOINTS (tp) |
| 8813 | { |
| 8814 | if (tp->addr_string) |
| 8815 | fprintf (fp, "trace %s\n", tp->addr_string); |
| 8816 | else |
| 8817 | { |
| 8818 | sprintf_vma (tmp, tp->loc->address); |
| 8819 | fprintf (fp, "trace *0x%s\n", tmp); |
| 8820 | } |
| 8821 | |
| 8822 | if (tp->pass_count) |
| 8823 | fprintf (fp, " passcount %d\n", tp->pass_count); |
| 8824 | |
| 8825 | if (tp->actions) |
| 8826 | { |
| 8827 | fprintf (fp, " actions\n"); |
| 8828 | indent = i1; |
| 8829 | for (line = tp->actions; line; line = line->next) |
| 8830 | { |
| 8831 | struct cmd_list_element *cmd; |
| 8832 | |
| 8833 | QUIT; /* allow user to bail out with ^C */ |
| 8834 | actionline = line->action; |
| 8835 | while (isspace ((int) *actionline)) |
| 8836 | actionline++; |
| 8837 | |
| 8838 | fprintf (fp, "%s%s\n", indent, actionline); |
| 8839 | if (*actionline != '#') /* skip for comment lines */ |
| 8840 | { |
| 8841 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); |
| 8842 | if (cmd == 0) |
| 8843 | error (_("Bad action list item: %s"), actionline); |
| 8844 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) |
| 8845 | indent = i2; |
| 8846 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) |
| 8847 | indent = i1; |
| 8848 | } |
| 8849 | } |
| 8850 | } |
| 8851 | } |
| 8852 | do_cleanups (cleanup); |
| 8853 | if (from_tty) |
| 8854 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); |
| 8855 | return; |
| 8856 | } |
| 8857 | |
| 8858 | /* Create a vector of all tracepoints. */ |
| 8859 | |
| 8860 | VEC(breakpoint_p) * |
| 8861 | all_tracepoints () |
| 8862 | { |
| 8863 | VEC(breakpoint_p) *tp_vec = 0; |
| 8864 | struct breakpoint *tp; |
| 8865 | |
| 8866 | ALL_TRACEPOINTS (tp) |
| 8867 | { |
| 8868 | VEC_safe_push (breakpoint_p, tp_vec, tp); |
| 8869 | } |
| 8870 | |
| 8871 | return tp_vec; |
| 8872 | } |
| 8873 | |
| 8874 | \f |
| 8875 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
| 8876 | It is defined as a macro to prevent duplication. |
| 8877 | COMMAND should be a string constant containing the name of the command. */ |
| 8878 | #define BREAK_ARGS_HELP(command) \ |
| 8879 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
| 8880 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
| 8881 | If a line number is specified, break at start of code for that line.\n\ |
| 8882 | If a function is specified, break at start of code for that function.\n\ |
| 8883 | If an address is specified, break at that exact address.\n\ |
| 8884 | With no LOCATION, uses current execution address of selected stack frame.\n\ |
| 8885 | This is useful for breaking on return to a stack frame.\n\ |
| 8886 | \n\ |
| 8887 | THREADNUM is the number from \"info threads\".\n\ |
| 8888 | CONDITION is a boolean expression.\n\ |
| 8889 | \n\ |
| 8890 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ |
| 8891 | \n\ |
| 8892 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." |
| 8893 | |
| 8894 | /* List of subcommands for "catch". */ |
| 8895 | static struct cmd_list_element *catch_cmdlist; |
| 8896 | |
| 8897 | /* List of subcommands for "tcatch". */ |
| 8898 | static struct cmd_list_element *tcatch_cmdlist; |
| 8899 | |
| 8900 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" |
| 8901 | lists, and pass some additional user data to the command function. */ |
| 8902 | static void |
| 8903 | add_catch_command (char *name, char *docstring, |
| 8904 | void (*sfunc) (char *args, int from_tty, |
| 8905 | struct cmd_list_element *command), |
| 8906 | void *user_data_catch, |
| 8907 | void *user_data_tcatch) |
| 8908 | { |
| 8909 | struct cmd_list_element *command; |
| 8910 | |
| 8911 | command = add_cmd (name, class_breakpoint, NULL, docstring, |
| 8912 | &catch_cmdlist); |
| 8913 | set_cmd_sfunc (command, sfunc); |
| 8914 | set_cmd_context (command, user_data_catch); |
| 8915 | |
| 8916 | command = add_cmd (name, class_breakpoint, NULL, docstring, |
| 8917 | &tcatch_cmdlist); |
| 8918 | set_cmd_sfunc (command, sfunc); |
| 8919 | set_cmd_context (command, user_data_tcatch); |
| 8920 | } |
| 8921 | |
| 8922 | void |
| 8923 | _initialize_breakpoint (void) |
| 8924 | { |
| 8925 | static struct cmd_list_element *breakpoint_set_cmdlist; |
| 8926 | static struct cmd_list_element *breakpoint_show_cmdlist; |
| 8927 | struct cmd_list_element *c; |
| 8928 | |
| 8929 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
| 8930 | |
| 8931 | breakpoint_chain = 0; |
| 8932 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful |
| 8933 | before a breakpoint is set. */ |
| 8934 | breakpoint_count = 0; |
| 8935 | |
| 8936 | tracepoint_count = 0; |
| 8937 | |
| 8938 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
| 8939 | Set ignore-count of breakpoint number N to COUNT.\n\ |
| 8940 | Usage is `ignore N COUNT'.")); |
| 8941 | if (xdb_commands) |
| 8942 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
| 8943 | |
| 8944 | add_com ("commands", class_breakpoint, commands_command, _("\ |
| 8945 | Set commands to be executed when a breakpoint is hit.\n\ |
| 8946 | Give breakpoint number as argument after \"commands\".\n\ |
| 8947 | With no argument, the targeted breakpoint is the last one set.\n\ |
| 8948 | The commands themselves follow starting on the next line.\n\ |
| 8949 | Type a line containing \"end\" to indicate the end of them.\n\ |
| 8950 | Give \"silent\" as the first line to make the breakpoint silent;\n\ |
| 8951 | then no output is printed when it is hit, except what the commands print.")); |
| 8952 | |
| 8953 | add_com ("condition", class_breakpoint, condition_command, _("\ |
| 8954 | Specify breakpoint number N to break only if COND is true.\n\ |
| 8955 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
| 8956 | expression to be evaluated whenever breakpoint N is reached.")); |
| 8957 | |
| 8958 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
| 8959 | Set a temporary breakpoint.\n\ |
| 8960 | Like \"break\" except the breakpoint is only temporary,\n\ |
| 8961 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ |
| 8962 | by using \"enable delete\" on the breakpoint number.\n\ |
| 8963 | \n" |
| 8964 | BREAK_ARGS_HELP ("tbreak"))); |
| 8965 | set_cmd_completer (c, location_completer); |
| 8966 | |
| 8967 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
| 8968 | Set a hardware assisted breakpoint.\n\ |
| 8969 | Like \"break\" except the breakpoint requires hardware support,\n\ |
| 8970 | some target hardware may not have this support.\n\ |
| 8971 | \n" |
| 8972 | BREAK_ARGS_HELP ("hbreak"))); |
| 8973 | set_cmd_completer (c, location_completer); |
| 8974 | |
| 8975 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
| 8976 | Set a temporary hardware assisted breakpoint.\n\ |
| 8977 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
| 8978 | so it will be deleted when hit.\n\ |
| 8979 | \n" |
| 8980 | BREAK_ARGS_HELP ("thbreak"))); |
| 8981 | set_cmd_completer (c, location_completer); |
| 8982 | |
| 8983 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
| 8984 | Enable some breakpoints.\n\ |
| 8985 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 8986 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 8987 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 8988 | With a subcommand you can enable temporarily."), |
| 8989 | &enablelist, "enable ", 1, &cmdlist); |
| 8990 | if (xdb_commands) |
| 8991 | add_com ("ab", class_breakpoint, enable_command, _("\ |
| 8992 | Enable some breakpoints.\n\ |
| 8993 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 8994 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 8995 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 8996 | With a subcommand you can enable temporarily.")); |
| 8997 | |
| 8998 | add_com_alias ("en", "enable", class_breakpoint, 1); |
| 8999 | |
| 9000 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
| 9001 | Enable some breakpoints.\n\ |
| 9002 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 9003 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 9004 | May be abbreviated to simply \"enable\".\n"), |
| 9005 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
| 9006 | |
| 9007 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 9008 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 9009 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 9010 | &enablebreaklist); |
| 9011 | |
| 9012 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 9013 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 9014 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 9015 | &enablebreaklist); |
| 9016 | |
| 9017 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 9018 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 9019 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 9020 | &enablelist); |
| 9021 | |
| 9022 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 9023 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 9024 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 9025 | &enablelist); |
| 9026 | |
| 9027 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
| 9028 | Disable some breakpoints.\n\ |
| 9029 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 9030 | To disable all breakpoints, give no argument.\n\ |
| 9031 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
| 9032 | &disablelist, "disable ", 1, &cmdlist); |
| 9033 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
| 9034 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
| 9035 | if (xdb_commands) |
| 9036 | add_com ("sb", class_breakpoint, disable_command, _("\ |
| 9037 | Disable some breakpoints.\n\ |
| 9038 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 9039 | To disable all breakpoints, give no argument.\n\ |
| 9040 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
| 9041 | |
| 9042 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
| 9043 | Disable some breakpoints.\n\ |
| 9044 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 9045 | To disable all breakpoints, give no argument.\n\ |
| 9046 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ |
| 9047 | This command may be abbreviated \"disable\"."), |
| 9048 | &disablelist); |
| 9049 | |
| 9050 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
| 9051 | Delete some breakpoints or auto-display expressions.\n\ |
| 9052 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 9053 | To delete all breakpoints, give no argument.\n\ |
| 9054 | \n\ |
| 9055 | Also a prefix command for deletion of other GDB objects.\n\ |
| 9056 | The \"unset\" command is also an alias for \"delete\"."), |
| 9057 | &deletelist, "delete ", 1, &cmdlist); |
| 9058 | add_com_alias ("d", "delete", class_breakpoint, 1); |
| 9059 | add_com_alias ("del", "delete", class_breakpoint, 1); |
| 9060 | if (xdb_commands) |
| 9061 | add_com ("db", class_breakpoint, delete_command, _("\ |
| 9062 | Delete some breakpoints.\n\ |
| 9063 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 9064 | To delete all breakpoints, give no argument.\n")); |
| 9065 | |
| 9066 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
| 9067 | Delete some breakpoints or auto-display expressions.\n\ |
| 9068 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 9069 | To delete all breakpoints, give no argument.\n\ |
| 9070 | This command may be abbreviated \"delete\"."), |
| 9071 | &deletelist); |
| 9072 | |
| 9073 | add_com ("clear", class_breakpoint, clear_command, _("\ |
| 9074 | Clear breakpoint at specified line or function.\n\ |
| 9075 | Argument may be line number, function name, or \"*\" and an address.\n\ |
| 9076 | If line number is specified, all breakpoints in that line are cleared.\n\ |
| 9077 | If function is specified, breakpoints at beginning of function are cleared.\n\ |
| 9078 | If an address is specified, breakpoints at that address are cleared.\n\ |
| 9079 | \n\ |
| 9080 | With no argument, clears all breakpoints in the line that the selected frame\n\ |
| 9081 | is executing in.\n\ |
| 9082 | \n\ |
| 9083 | See also the \"delete\" command which clears breakpoints by number.")); |
| 9084 | |
| 9085 | c = add_com ("break", class_breakpoint, break_command, _("\ |
| 9086 | Set breakpoint at specified line or function.\n" |
| 9087 | BREAK_ARGS_HELP ("break"))); |
| 9088 | set_cmd_completer (c, location_completer); |
| 9089 | |
| 9090 | add_com_alias ("b", "break", class_run, 1); |
| 9091 | add_com_alias ("br", "break", class_run, 1); |
| 9092 | add_com_alias ("bre", "break", class_run, 1); |
| 9093 | add_com_alias ("brea", "break", class_run, 1); |
| 9094 | |
| 9095 | if (xdb_commands) |
| 9096 | add_com_alias ("ba", "break", class_breakpoint, 1); |
| 9097 | |
| 9098 | if (dbx_commands) |
| 9099 | { |
| 9100 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
| 9101 | Break in function/address or break at a line in the current file."), |
| 9102 | &stoplist, "stop ", 1, &cmdlist); |
| 9103 | add_cmd ("in", class_breakpoint, stopin_command, |
| 9104 | _("Break in function or address."), &stoplist); |
| 9105 | add_cmd ("at", class_breakpoint, stopat_command, |
| 9106 | _("Break at a line in the current file."), &stoplist); |
| 9107 | add_com ("status", class_info, breakpoints_info, _("\ |
| 9108 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 9109 | The \"Type\" column indicates one of:\n\ |
| 9110 | \tbreakpoint - normal breakpoint\n\ |
| 9111 | \twatchpoint - watchpoint\n\ |
| 9112 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 9113 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 9114 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 9115 | address and file/line number respectively.\n\ |
| 9116 | \n\ |
| 9117 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 9118 | are set to the address of the last breakpoint listed unless the command\n\ |
| 9119 | is prefixed with \"server \".\n\n\ |
| 9120 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 9121 | breakpoint set.")); |
| 9122 | } |
| 9123 | |
| 9124 | add_info ("breakpoints", breakpoints_info, _("\ |
| 9125 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 9126 | The \"Type\" column indicates one of:\n\ |
| 9127 | \tbreakpoint - normal breakpoint\n\ |
| 9128 | \twatchpoint - watchpoint\n\ |
| 9129 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 9130 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 9131 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 9132 | address and file/line number respectively.\n\ |
| 9133 | \n\ |
| 9134 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 9135 | are set to the address of the last breakpoint listed unless the command\n\ |
| 9136 | is prefixed with \"server \".\n\n\ |
| 9137 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 9138 | breakpoint set.")); |
| 9139 | |
| 9140 | if (xdb_commands) |
| 9141 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
| 9142 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 9143 | The \"Type\" column indicates one of:\n\ |
| 9144 | \tbreakpoint - normal breakpoint\n\ |
| 9145 | \twatchpoint - watchpoint\n\ |
| 9146 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 9147 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 9148 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 9149 | address and file/line number respectively.\n\ |
| 9150 | \n\ |
| 9151 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 9152 | are set to the address of the last breakpoint listed unless the command\n\ |
| 9153 | is prefixed with \"server \".\n\n\ |
| 9154 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 9155 | breakpoint set.")); |
| 9156 | |
| 9157 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
| 9158 | Status of all breakpoints, or breakpoint number NUMBER.\n\ |
| 9159 | The \"Type\" column indicates one of:\n\ |
| 9160 | \tbreakpoint - normal breakpoint\n\ |
| 9161 | \twatchpoint - watchpoint\n\ |
| 9162 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ |
| 9163 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ |
| 9164 | \tuntil - internal breakpoint used by the \"until\" command\n\ |
| 9165 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
| 9166 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 9167 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 9168 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 9169 | address and file/line number respectively.\n\ |
| 9170 | \n\ |
| 9171 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 9172 | are set to the address of the last breakpoint listed unless the command\n\ |
| 9173 | is prefixed with \"server \".\n\n\ |
| 9174 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 9175 | breakpoint set."), |
| 9176 | &maintenanceinfolist); |
| 9177 | |
| 9178 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
| 9179 | Set catchpoints to catch events."), |
| 9180 | &catch_cmdlist, "catch ", |
| 9181 | 0/*allow-unknown*/, &cmdlist); |
| 9182 | |
| 9183 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ |
| 9184 | Set temporary catchpoints to catch events."), |
| 9185 | &tcatch_cmdlist, "tcatch ", |
| 9186 | 0/*allow-unknown*/, &cmdlist); |
| 9187 | |
| 9188 | /* Add catch and tcatch sub-commands. */ |
| 9189 | add_catch_command ("catch", _("\ |
| 9190 | Catch an exception, when caught.\n\ |
| 9191 | With an argument, catch only exceptions with the given name."), |
| 9192 | catch_catch_command, |
| 9193 | CATCH_PERMANENT, |
| 9194 | CATCH_TEMPORARY); |
| 9195 | add_catch_command ("throw", _("\ |
| 9196 | Catch an exception, when thrown.\n\ |
| 9197 | With an argument, catch only exceptions with the given name."), |
| 9198 | catch_throw_command, |
| 9199 | CATCH_PERMANENT, |
| 9200 | CATCH_TEMPORARY); |
| 9201 | add_catch_command ("fork", _("Catch calls to fork."), |
| 9202 | catch_fork_command_1, |
| 9203 | (void *) (uintptr_t) catch_fork_permanent, |
| 9204 | (void *) (uintptr_t) catch_fork_temporary); |
| 9205 | add_catch_command ("vfork", _("Catch calls to vfork."), |
| 9206 | catch_fork_command_1, |
| 9207 | (void *) (uintptr_t) catch_vfork_permanent, |
| 9208 | (void *) (uintptr_t) catch_vfork_temporary); |
| 9209 | add_catch_command ("exec", _("Catch calls to exec."), |
| 9210 | catch_exec_command_1, |
| 9211 | CATCH_PERMANENT, |
| 9212 | CATCH_TEMPORARY); |
| 9213 | add_catch_command ("exception", _("\ |
| 9214 | Catch Ada exceptions, when raised.\n\ |
| 9215 | With an argument, catch only exceptions with the given name."), |
| 9216 | catch_ada_exception_command, |
| 9217 | CATCH_PERMANENT, |
| 9218 | CATCH_TEMPORARY); |
| 9219 | add_catch_command ("assert", _("\ |
| 9220 | Catch failed Ada assertions, when raised.\n\ |
| 9221 | With an argument, catch only exceptions with the given name."), |
| 9222 | catch_assert_command, |
| 9223 | CATCH_PERMANENT, |
| 9224 | CATCH_TEMPORARY); |
| 9225 | |
| 9226 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
| 9227 | Set a watchpoint for an expression.\n\ |
| 9228 | A watchpoint stops execution of your program whenever the value of\n\ |
| 9229 | an expression changes.")); |
| 9230 | set_cmd_completer (c, expression_completer); |
| 9231 | |
| 9232 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
| 9233 | Set a read watchpoint for an expression.\n\ |
| 9234 | A watchpoint stops execution of your program whenever the value of\n\ |
| 9235 | an expression is read.")); |
| 9236 | set_cmd_completer (c, expression_completer); |
| 9237 | |
| 9238 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
| 9239 | Set a watchpoint for an expression.\n\ |
| 9240 | A watchpoint stops execution of your program whenever the value of\n\ |
| 9241 | an expression is either read or written.")); |
| 9242 | set_cmd_completer (c, expression_completer); |
| 9243 | |
| 9244 | add_info ("watchpoints", breakpoints_info, |
| 9245 | _("Synonym for ``info breakpoints''.")); |
| 9246 | |
| 9247 | |
| 9248 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
| 9249 | respond to changes - contrary to the description. */ |
| 9250 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
| 9251 | &can_use_hw_watchpoints, _("\ |
| 9252 | Set debugger's willingness to use watchpoint hardware."), _("\ |
| 9253 | Show debugger's willingness to use watchpoint hardware."), _("\ |
| 9254 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
| 9255 | such is available. (However, any hardware watchpoints that were\n\ |
| 9256 | created before setting this to nonzero, will continue to use watchpoint\n\ |
| 9257 | hardware.)"), |
| 9258 | NULL, |
| 9259 | show_can_use_hw_watchpoints, |
| 9260 | &setlist, &showlist); |
| 9261 | |
| 9262 | can_use_hw_watchpoints = 1; |
| 9263 | |
| 9264 | /* Tracepoint manipulation commands. */ |
| 9265 | |
| 9266 | c = add_com ("trace", class_breakpoint, trace_command, _("\ |
| 9267 | Set a tracepoint at specified line or function.\n\ |
| 9268 | \n" |
| 9269 | BREAK_ARGS_HELP ("trace") "\n\ |
| 9270 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 9271 | set_cmd_completer (c, location_completer); |
| 9272 | |
| 9273 | add_com_alias ("tp", "trace", class_alias, 0); |
| 9274 | add_com_alias ("tr", "trace", class_alias, 1); |
| 9275 | add_com_alias ("tra", "trace", class_alias, 1); |
| 9276 | add_com_alias ("trac", "trace", class_alias, 1); |
| 9277 | |
| 9278 | add_info ("tracepoints", tracepoints_info, _("\ |
| 9279 | Status of tracepoints, or tracepoint number NUMBER.\n\ |
| 9280 | Convenience variable \"$tpnum\" contains the number of the\n\ |
| 9281 | last tracepoint set.")); |
| 9282 | |
| 9283 | add_info_alias ("tp", "tracepoints", 1); |
| 9284 | |
| 9285 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ |
| 9286 | Delete specified tracepoints.\n\ |
| 9287 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 9288 | No argument means delete all tracepoints."), |
| 9289 | &deletelist); |
| 9290 | |
| 9291 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ |
| 9292 | Disable specified tracepoints.\n\ |
| 9293 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 9294 | No argument means disable all tracepoints."), |
| 9295 | &disablelist); |
| 9296 | deprecate_cmd (c, "disable"); |
| 9297 | |
| 9298 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ |
| 9299 | Enable specified tracepoints.\n\ |
| 9300 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 9301 | No argument means enable all tracepoints."), |
| 9302 | &enablelist); |
| 9303 | deprecate_cmd (c, "enable"); |
| 9304 | |
| 9305 | add_com ("passcount", class_trace, trace_pass_command, _("\ |
| 9306 | Set the passcount for a tracepoint.\n\ |
| 9307 | The trace will end when the tracepoint has been passed 'count' times.\n\ |
| 9308 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ |
| 9309 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); |
| 9310 | |
| 9311 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ |
| 9312 | Save current tracepoint definitions as a script.\n\ |
| 9313 | Use the 'source' command in another debug session to restore them.")); |
| 9314 | set_cmd_completer (c, filename_completer); |
| 9315 | |
| 9316 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
| 9317 | Breakpoint specific settings\n\ |
| 9318 | Configure various breakpoint-specific variables such as\n\ |
| 9319 | pending breakpoint behavior"), |
| 9320 | &breakpoint_set_cmdlist, "set breakpoint ", |
| 9321 | 0/*allow-unknown*/, &setlist); |
| 9322 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
| 9323 | Breakpoint specific settings\n\ |
| 9324 | Configure various breakpoint-specific variables such as\n\ |
| 9325 | pending breakpoint behavior"), |
| 9326 | &breakpoint_show_cmdlist, "show breakpoint ", |
| 9327 | 0/*allow-unknown*/, &showlist); |
| 9328 | |
| 9329 | add_setshow_auto_boolean_cmd ("pending", no_class, |
| 9330 | &pending_break_support, _("\ |
| 9331 | Set debugger's behavior regarding pending breakpoints."), _("\ |
| 9332 | Show debugger's behavior regarding pending breakpoints."), _("\ |
| 9333 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
| 9334 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ |
| 9335 | an error. If auto, an unrecognized breakpoint location results in a\n\ |
| 9336 | user-query to see if a pending breakpoint should be created."), |
| 9337 | NULL, |
| 9338 | show_pending_break_support, |
| 9339 | &breakpoint_set_cmdlist, |
| 9340 | &breakpoint_show_cmdlist); |
| 9341 | |
| 9342 | pending_break_support = AUTO_BOOLEAN_AUTO; |
| 9343 | |
| 9344 | add_setshow_boolean_cmd ("auto-hw", no_class, |
| 9345 | &automatic_hardware_breakpoints, _("\ |
| 9346 | Set automatic usage of hardware breakpoints."), _("\ |
| 9347 | Show automatic usage of hardware breakpoints."), _("\ |
| 9348 | If set, the debugger will automatically use hardware breakpoints for\n\ |
| 9349 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ |
| 9350 | a warning will be emitted for such breakpoints."), |
| 9351 | NULL, |
| 9352 | show_automatic_hardware_breakpoints, |
| 9353 | &breakpoint_set_cmdlist, |
| 9354 | &breakpoint_show_cmdlist); |
| 9355 | |
| 9356 | add_setshow_enum_cmd ("always-inserted", class_support, |
| 9357 | always_inserted_enums, &always_inserted_mode, _("\ |
| 9358 | Set mode for inserting breakpoints."), _("\ |
| 9359 | Show mode for inserting breakpoints."), _("\ |
| 9360 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
| 9361 | resumed, and removed when execution stops. When this mode is on,\n\ |
| 9362 | breakpoints are inserted immediately and removed only when the user\n\ |
| 9363 | deletes the breakpoint. When this mode is auto (which is the default),\n\ |
| 9364 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ |
| 9365 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ |
| 9366 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ |
| 9367 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), |
| 9368 | NULL, |
| 9369 | &show_always_inserted_mode, |
| 9370 | &breakpoint_set_cmdlist, |
| 9371 | &breakpoint_show_cmdlist); |
| 9372 | |
| 9373 | automatic_hardware_breakpoints = 1; |
| 9374 | |
| 9375 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); |
| 9376 | } |