| 1 | /* Everything about breakpoints, for GDB. |
| 2 | |
| 3 | Copyright (C) 1986-2014 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #include "defs.h" |
| 21 | #include "arch-utils.h" |
| 22 | #include <ctype.h> |
| 23 | #include "hashtab.h" |
| 24 | #include "symtab.h" |
| 25 | #include "frame.h" |
| 26 | #include "breakpoint.h" |
| 27 | #include "tracepoint.h" |
| 28 | #include "gdbtypes.h" |
| 29 | #include "expression.h" |
| 30 | #include "gdbcore.h" |
| 31 | #include "gdbcmd.h" |
| 32 | #include "value.h" |
| 33 | #include "command.h" |
| 34 | #include "inferior.h" |
| 35 | #include "infrun.h" |
| 36 | #include "gdbthread.h" |
| 37 | #include "target.h" |
| 38 | #include "language.h" |
| 39 | #include "gdb-demangle.h" |
| 40 | #include "filenames.h" |
| 41 | #include "annotate.h" |
| 42 | #include "symfile.h" |
| 43 | #include "objfiles.h" |
| 44 | #include "source.h" |
| 45 | #include "linespec.h" |
| 46 | #include "completer.h" |
| 47 | #include "gdb.h" |
| 48 | #include "ui-out.h" |
| 49 | #include "cli/cli-script.h" |
| 50 | #include "block.h" |
| 51 | #include "solib.h" |
| 52 | #include "solist.h" |
| 53 | #include "observer.h" |
| 54 | #include "exceptions.h" |
| 55 | #include "memattr.h" |
| 56 | #include "ada-lang.h" |
| 57 | #include "top.h" |
| 58 | #include "valprint.h" |
| 59 | #include "jit.h" |
| 60 | #include "xml-syscall.h" |
| 61 | #include "parser-defs.h" |
| 62 | #include "gdb_regex.h" |
| 63 | #include "probe.h" |
| 64 | #include "cli/cli-utils.h" |
| 65 | #include "continuations.h" |
| 66 | #include "stack.h" |
| 67 | #include "skip.h" |
| 68 | #include "ax-gdb.h" |
| 69 | #include "dummy-frame.h" |
| 70 | |
| 71 | #include "format.h" |
| 72 | |
| 73 | /* readline include files */ |
| 74 | #include "readline/readline.h" |
| 75 | #include "readline/history.h" |
| 76 | |
| 77 | /* readline defines this. */ |
| 78 | #undef savestring |
| 79 | |
| 80 | #include "mi/mi-common.h" |
| 81 | #include "extension.h" |
| 82 | |
| 83 | /* Enums for exception-handling support. */ |
| 84 | enum exception_event_kind |
| 85 | { |
| 86 | EX_EVENT_THROW, |
| 87 | EX_EVENT_RETHROW, |
| 88 | EX_EVENT_CATCH |
| 89 | }; |
| 90 | |
| 91 | /* Prototypes for local functions. */ |
| 92 | |
| 93 | static void enable_delete_command (char *, int); |
| 94 | |
| 95 | static void enable_once_command (char *, int); |
| 96 | |
| 97 | static void enable_count_command (char *, int); |
| 98 | |
| 99 | static void disable_command (char *, int); |
| 100 | |
| 101 | static void enable_command (char *, int); |
| 102 | |
| 103 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
| 104 | void *), |
| 105 | void *); |
| 106 | |
| 107 | static void ignore_command (char *, int); |
| 108 | |
| 109 | static int breakpoint_re_set_one (void *); |
| 110 | |
| 111 | static void breakpoint_re_set_default (struct breakpoint *); |
| 112 | |
| 113 | static void create_sals_from_address_default (char **, |
| 114 | struct linespec_result *, |
| 115 | enum bptype, char *, |
| 116 | char **); |
| 117 | |
| 118 | static void create_breakpoints_sal_default (struct gdbarch *, |
| 119 | struct linespec_result *, |
| 120 | char *, char *, enum bptype, |
| 121 | enum bpdisp, int, int, |
| 122 | int, |
| 123 | const struct breakpoint_ops *, |
| 124 | int, int, int, unsigned); |
| 125 | |
| 126 | static void decode_linespec_default (struct breakpoint *, char **, |
| 127 | struct symtabs_and_lines *); |
| 128 | |
| 129 | static void clear_command (char *, int); |
| 130 | |
| 131 | static void catch_command (char *, int); |
| 132 | |
| 133 | static int can_use_hardware_watchpoint (struct value *); |
| 134 | |
| 135 | static void break_command_1 (char *, int, int); |
| 136 | |
| 137 | static void mention (struct breakpoint *); |
| 138 | |
| 139 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
| 140 | enum bptype, |
| 141 | const struct breakpoint_ops *); |
| 142 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
| 143 | const struct symtab_and_line *); |
| 144 | |
| 145 | /* This function is used in gdbtk sources and thus can not be made |
| 146 | static. */ |
| 147 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
| 148 | struct symtab_and_line, |
| 149 | enum bptype, |
| 150 | const struct breakpoint_ops *); |
| 151 | |
| 152 | static struct breakpoint * |
| 153 | momentary_breakpoint_from_master (struct breakpoint *orig, |
| 154 | enum bptype type, |
| 155 | const struct breakpoint_ops *ops, |
| 156 | int loc_enabled); |
| 157 | |
| 158 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
| 159 | |
| 160 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 161 | CORE_ADDR bpaddr, |
| 162 | enum bptype bptype); |
| 163 | |
| 164 | static void describe_other_breakpoints (struct gdbarch *, |
| 165 | struct program_space *, CORE_ADDR, |
| 166 | struct obj_section *, int); |
| 167 | |
| 168 | static int watchpoint_locations_match (struct bp_location *loc1, |
| 169 | struct bp_location *loc2); |
| 170 | |
| 171 | static int breakpoint_location_address_match (struct bp_location *bl, |
| 172 | struct address_space *aspace, |
| 173 | CORE_ADDR addr); |
| 174 | |
| 175 | static void breakpoints_info (char *, int); |
| 176 | |
| 177 | static void watchpoints_info (char *, int); |
| 178 | |
| 179 | static int breakpoint_1 (char *, int, |
| 180 | int (*) (const struct breakpoint *)); |
| 181 | |
| 182 | static int breakpoint_cond_eval (void *); |
| 183 | |
| 184 | static void cleanup_executing_breakpoints (void *); |
| 185 | |
| 186 | static void commands_command (char *, int); |
| 187 | |
| 188 | static void condition_command (char *, int); |
| 189 | |
| 190 | typedef enum |
| 191 | { |
| 192 | mark_inserted, |
| 193 | mark_uninserted |
| 194 | } |
| 195 | insertion_state_t; |
| 196 | |
| 197 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
| 198 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
| 199 | |
| 200 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
| 201 | |
| 202 | static int watchpoint_check (void *); |
| 203 | |
| 204 | static void maintenance_info_breakpoints (char *, int); |
| 205 | |
| 206 | static int hw_breakpoint_used_count (void); |
| 207 | |
| 208 | static int hw_watchpoint_use_count (struct breakpoint *); |
| 209 | |
| 210 | static int hw_watchpoint_used_count_others (struct breakpoint *except, |
| 211 | enum bptype type, |
| 212 | int *other_type_used); |
| 213 | |
| 214 | static void hbreak_command (char *, int); |
| 215 | |
| 216 | static void thbreak_command (char *, int); |
| 217 | |
| 218 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
| 219 | int count); |
| 220 | |
| 221 | static void stop_command (char *arg, int from_tty); |
| 222 | |
| 223 | static void stopin_command (char *arg, int from_tty); |
| 224 | |
| 225 | static void stopat_command (char *arg, int from_tty); |
| 226 | |
| 227 | static void tcatch_command (char *arg, int from_tty); |
| 228 | |
| 229 | static void detach_single_step_breakpoints (void); |
| 230 | |
| 231 | static int find_single_step_breakpoint (struct address_space *aspace, |
| 232 | CORE_ADDR pc); |
| 233 | |
| 234 | static void free_bp_location (struct bp_location *loc); |
| 235 | static void incref_bp_location (struct bp_location *loc); |
| 236 | static void decref_bp_location (struct bp_location **loc); |
| 237 | |
| 238 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
| 239 | |
| 240 | /* update_global_location_list's modes of operation wrt to whether to |
| 241 | insert locations now. */ |
| 242 | enum ugll_insert_mode |
| 243 | { |
| 244 | /* Don't insert any breakpoint locations into the inferior, only |
| 245 | remove already-inserted locations that no longer should be |
| 246 | inserted. Functions that delete a breakpoint or breakpoints |
| 247 | should specify this mode, so that deleting a breakpoint doesn't |
| 248 | have the side effect of inserting the locations of other |
| 249 | breakpoints that are marked not-inserted, but should_be_inserted |
| 250 | returns true on them. |
| 251 | |
| 252 | This behavior is useful is situations close to tear-down -- e.g., |
| 253 | after an exec, while the target still has execution, but |
| 254 | breakpoint shadows of the previous executable image should *NOT* |
| 255 | be restored to the new image; or before detaching, where the |
| 256 | target still has execution and wants to delete breakpoints from |
| 257 | GDB's lists, and all breakpoints had already been removed from |
| 258 | the inferior. */ |
| 259 | UGLL_DONT_INSERT, |
| 260 | |
| 261 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
| 262 | claims breakpoints should be inserted now. */ |
| 263 | UGLL_MAY_INSERT, |
| 264 | |
| 265 | /* Insert locations now, irrespective of |
| 266 | breakpoints_should_be_inserted_now. E.g., say all threads are |
| 267 | stopped right now, and the user did "continue". We need to |
| 268 | insert breakpoints _before_ resuming the target, but |
| 269 | UGLL_MAY_INSERT wouldn't insert them, because |
| 270 | breakpoints_should_be_inserted_now returns false at that point, |
| 271 | as no thread is running yet. */ |
| 272 | UGLL_INSERT |
| 273 | }; |
| 274 | |
| 275 | static void update_global_location_list (enum ugll_insert_mode); |
| 276 | |
| 277 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
| 278 | |
| 279 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
| 280 | |
| 281 | static void insert_breakpoint_locations (void); |
| 282 | |
| 283 | static int syscall_catchpoint_p (struct breakpoint *b); |
| 284 | |
| 285 | static void tracepoints_info (char *, int); |
| 286 | |
| 287 | static void delete_trace_command (char *, int); |
| 288 | |
| 289 | static void enable_trace_command (char *, int); |
| 290 | |
| 291 | static void disable_trace_command (char *, int); |
| 292 | |
| 293 | static void trace_pass_command (char *, int); |
| 294 | |
| 295 | static void set_tracepoint_count (int num); |
| 296 | |
| 297 | static int is_masked_watchpoint (const struct breakpoint *b); |
| 298 | |
| 299 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
| 300 | |
| 301 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
| 302 | otherwise. */ |
| 303 | |
| 304 | static int strace_marker_p (struct breakpoint *b); |
| 305 | |
| 306 | /* The abstract base class all breakpoint_ops structures inherit |
| 307 | from. */ |
| 308 | struct breakpoint_ops base_breakpoint_ops; |
| 309 | |
| 310 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
| 311 | that are implemented on top of software or hardware breakpoints |
| 312 | (user breakpoints, internal and momentary breakpoints, etc.). */ |
| 313 | static struct breakpoint_ops bkpt_base_breakpoint_ops; |
| 314 | |
| 315 | /* Internal breakpoints class type. */ |
| 316 | static struct breakpoint_ops internal_breakpoint_ops; |
| 317 | |
| 318 | /* Momentary breakpoints class type. */ |
| 319 | static struct breakpoint_ops momentary_breakpoint_ops; |
| 320 | |
| 321 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
| 322 | static struct breakpoint_ops longjmp_breakpoint_ops; |
| 323 | |
| 324 | /* The breakpoint_ops structure to be used in regular user created |
| 325 | breakpoints. */ |
| 326 | struct breakpoint_ops bkpt_breakpoint_ops; |
| 327 | |
| 328 | /* Breakpoints set on probes. */ |
| 329 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; |
| 330 | |
| 331 | /* Dynamic printf class type. */ |
| 332 | struct breakpoint_ops dprintf_breakpoint_ops; |
| 333 | |
| 334 | /* One (or perhaps two) breakpoints used for software single |
| 335 | stepping. */ |
| 336 | |
| 337 | static void *single_step_breakpoints[2]; |
| 338 | static struct gdbarch *single_step_gdbarch[2]; |
| 339 | |
| 340 | /* The style in which to perform a dynamic printf. This is a user |
| 341 | option because different output options have different tradeoffs; |
| 342 | if GDB does the printing, there is better error handling if there |
| 343 | is a problem with any of the arguments, but using an inferior |
| 344 | function lets you have special-purpose printers and sending of |
| 345 | output to the same place as compiled-in print functions. */ |
| 346 | |
| 347 | static const char dprintf_style_gdb[] = "gdb"; |
| 348 | static const char dprintf_style_call[] = "call"; |
| 349 | static const char dprintf_style_agent[] = "agent"; |
| 350 | static const char *const dprintf_style_enums[] = { |
| 351 | dprintf_style_gdb, |
| 352 | dprintf_style_call, |
| 353 | dprintf_style_agent, |
| 354 | NULL |
| 355 | }; |
| 356 | static const char *dprintf_style = dprintf_style_gdb; |
| 357 | |
| 358 | /* The function to use for dynamic printf if the preferred style is to |
| 359 | call into the inferior. The value is simply a string that is |
| 360 | copied into the command, so it can be anything that GDB can |
| 361 | evaluate to a callable address, not necessarily a function name. */ |
| 362 | |
| 363 | static char *dprintf_function = ""; |
| 364 | |
| 365 | /* The channel to use for dynamic printf if the preferred style is to |
| 366 | call into the inferior; if a nonempty string, it will be passed to |
| 367 | the call as the first argument, with the format string as the |
| 368 | second. As with the dprintf function, this can be anything that |
| 369 | GDB knows how to evaluate, so in addition to common choices like |
| 370 | "stderr", this could be an app-specific expression like |
| 371 | "mystreams[curlogger]". */ |
| 372 | |
| 373 | static char *dprintf_channel = ""; |
| 374 | |
| 375 | /* True if dprintf commands should continue to operate even if GDB |
| 376 | has disconnected. */ |
| 377 | static int disconnected_dprintf = 1; |
| 378 | |
| 379 | /* A reference-counted struct command_line. This lets multiple |
| 380 | breakpoints share a single command list. */ |
| 381 | struct counted_command_line |
| 382 | { |
| 383 | /* The reference count. */ |
| 384 | int refc; |
| 385 | |
| 386 | /* The command list. */ |
| 387 | struct command_line *commands; |
| 388 | }; |
| 389 | |
| 390 | struct command_line * |
| 391 | breakpoint_commands (struct breakpoint *b) |
| 392 | { |
| 393 | return b->commands ? b->commands->commands : NULL; |
| 394 | } |
| 395 | |
| 396 | /* Flag indicating that a command has proceeded the inferior past the |
| 397 | current breakpoint. */ |
| 398 | |
| 399 | static int breakpoint_proceeded; |
| 400 | |
| 401 | const char * |
| 402 | bpdisp_text (enum bpdisp disp) |
| 403 | { |
| 404 | /* NOTE: the following values are a part of MI protocol and |
| 405 | represent values of 'disp' field returned when inferior stops at |
| 406 | a breakpoint. */ |
| 407 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
| 408 | |
| 409 | return bpdisps[(int) disp]; |
| 410 | } |
| 411 | |
| 412 | /* Prototypes for exported functions. */ |
| 413 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
| 414 | if such is available. */ |
| 415 | static int can_use_hw_watchpoints; |
| 416 | |
| 417 | static void |
| 418 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, |
| 419 | struct cmd_list_element *c, |
| 420 | const char *value) |
| 421 | { |
| 422 | fprintf_filtered (file, |
| 423 | _("Debugger's willingness to use " |
| 424 | "watchpoint hardware is %s.\n"), |
| 425 | value); |
| 426 | } |
| 427 | |
| 428 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
| 429 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints |
| 430 | for unrecognized breakpoint locations. |
| 431 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
| 432 | static enum auto_boolean pending_break_support; |
| 433 | static void |
| 434 | show_pending_break_support (struct ui_file *file, int from_tty, |
| 435 | struct cmd_list_element *c, |
| 436 | const char *value) |
| 437 | { |
| 438 | fprintf_filtered (file, |
| 439 | _("Debugger's behavior regarding " |
| 440 | "pending breakpoints is %s.\n"), |
| 441 | value); |
| 442 | } |
| 443 | |
| 444 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
| 445 | set with "break" but falling in read-only memory. |
| 446 | If 0, gdb will warn about such breakpoints, but won't automatically |
| 447 | use hardware breakpoints. */ |
| 448 | static int automatic_hardware_breakpoints; |
| 449 | static void |
| 450 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, |
| 451 | struct cmd_list_element *c, |
| 452 | const char *value) |
| 453 | { |
| 454 | fprintf_filtered (file, |
| 455 | _("Automatic usage of hardware breakpoints is %s.\n"), |
| 456 | value); |
| 457 | } |
| 458 | |
| 459 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
| 460 | stopped, and immediately inserts any new breakpoints as soon as |
| 461 | they're created. If off (default), GDB keeps breakpoints off of |
| 462 | the target as long as possible. That is, it delays inserting |
| 463 | breakpoints until the next resume, and removes them again when the |
| 464 | target fully stops. This is a bit safer in case GDB crashes while |
| 465 | processing user input. */ |
| 466 | static int always_inserted_mode = 0; |
| 467 | |
| 468 | static void |
| 469 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
| 470 | struct cmd_list_element *c, const char *value) |
| 471 | { |
| 472 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
| 473 | value); |
| 474 | } |
| 475 | |
| 476 | int |
| 477 | breakpoints_should_be_inserted_now (void) |
| 478 | { |
| 479 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
| 480 | { |
| 481 | /* If breakpoints are global, they should be inserted even if no |
| 482 | thread under gdb's control is running, or even if there are |
| 483 | no threads under GDB's control yet. */ |
| 484 | return 1; |
| 485 | } |
| 486 | else if (target_has_execution) |
| 487 | { |
| 488 | struct thread_info *tp; |
| 489 | |
| 490 | if (always_inserted_mode) |
| 491 | { |
| 492 | /* The user wants breakpoints inserted even if all threads |
| 493 | are stopped. */ |
| 494 | return 1; |
| 495 | } |
| 496 | |
| 497 | ALL_NON_EXITED_THREADS (tp) |
| 498 | { |
| 499 | if (tp->executing) |
| 500 | return 1; |
| 501 | } |
| 502 | } |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static const char condition_evaluation_both[] = "host or target"; |
| 507 | |
| 508 | /* Modes for breakpoint condition evaluation. */ |
| 509 | static const char condition_evaluation_auto[] = "auto"; |
| 510 | static const char condition_evaluation_host[] = "host"; |
| 511 | static const char condition_evaluation_target[] = "target"; |
| 512 | static const char *const condition_evaluation_enums[] = { |
| 513 | condition_evaluation_auto, |
| 514 | condition_evaluation_host, |
| 515 | condition_evaluation_target, |
| 516 | NULL |
| 517 | }; |
| 518 | |
| 519 | /* Global that holds the current mode for breakpoint condition evaluation. */ |
| 520 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; |
| 521 | |
| 522 | /* Global that we use to display information to the user (gets its value from |
| 523 | condition_evaluation_mode_1. */ |
| 524 | static const char *condition_evaluation_mode = condition_evaluation_auto; |
| 525 | |
| 526 | /* Translate a condition evaluation mode MODE into either "host" |
| 527 | or "target". This is used mostly to translate from "auto" to the |
| 528 | real setting that is being used. It returns the translated |
| 529 | evaluation mode. */ |
| 530 | |
| 531 | static const char * |
| 532 | translate_condition_evaluation_mode (const char *mode) |
| 533 | { |
| 534 | if (mode == condition_evaluation_auto) |
| 535 | { |
| 536 | if (target_supports_evaluation_of_breakpoint_conditions ()) |
| 537 | return condition_evaluation_target; |
| 538 | else |
| 539 | return condition_evaluation_host; |
| 540 | } |
| 541 | else |
| 542 | return mode; |
| 543 | } |
| 544 | |
| 545 | /* Discovers what condition_evaluation_auto translates to. */ |
| 546 | |
| 547 | static const char * |
| 548 | breakpoint_condition_evaluation_mode (void) |
| 549 | { |
| 550 | return translate_condition_evaluation_mode (condition_evaluation_mode); |
| 551 | } |
| 552 | |
| 553 | /* Return true if GDB should evaluate breakpoint conditions or false |
| 554 | otherwise. */ |
| 555 | |
| 556 | static int |
| 557 | gdb_evaluates_breakpoint_condition_p (void) |
| 558 | { |
| 559 | const char *mode = breakpoint_condition_evaluation_mode (); |
| 560 | |
| 561 | return (mode == condition_evaluation_host); |
| 562 | } |
| 563 | |
| 564 | void _initialize_breakpoint (void); |
| 565 | |
| 566 | /* Are we executing breakpoint commands? */ |
| 567 | static int executing_breakpoint_commands; |
| 568 | |
| 569 | /* Are overlay event breakpoints enabled? */ |
| 570 | static int overlay_events_enabled; |
| 571 | |
| 572 | /* See description in breakpoint.h. */ |
| 573 | int target_exact_watchpoints = 0; |
| 574 | |
| 575 | /* Walk the following statement or block through all breakpoints. |
| 576 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
| 577 | current breakpoint. */ |
| 578 | |
| 579 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
| 580 | |
| 581 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
| 582 | for (B = breakpoint_chain; \ |
| 583 | B ? (TMP=B->next, 1): 0; \ |
| 584 | B = TMP) |
| 585 | |
| 586 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
| 587 | not provided so update_global_location_list must not be called |
| 588 | while executing the block of ALL_BP_LOCATIONS. */ |
| 589 | |
| 590 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
| 591 | for (BP_TMP = bp_location; \ |
| 592 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ |
| 593 | BP_TMP++) |
| 594 | |
| 595 | /* Iterates through locations with address ADDRESS for the currently selected |
| 596 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points |
| 597 | to where the loop should start from. |
| 598 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the |
| 599 | appropriate location to start with. */ |
| 600 | |
| 601 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ |
| 602 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ |
| 603 | BP_LOCP_TMP = BP_LOCP_START; \ |
| 604 | BP_LOCP_START \ |
| 605 | && (BP_LOCP_TMP < bp_location + bp_location_count \ |
| 606 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
| 607 | BP_LOCP_TMP++) |
| 608 | |
| 609 | /* Iterator for tracepoints only. */ |
| 610 | |
| 611 | #define ALL_TRACEPOINTS(B) \ |
| 612 | for (B = breakpoint_chain; B; B = B->next) \ |
| 613 | if (is_tracepoint (B)) |
| 614 | |
| 615 | /* Chains of all breakpoints defined. */ |
| 616 | |
| 617 | struct breakpoint *breakpoint_chain; |
| 618 | |
| 619 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
| 620 | |
| 621 | static struct bp_location **bp_location; |
| 622 | |
| 623 | /* Number of elements of BP_LOCATION. */ |
| 624 | |
| 625 | static unsigned bp_location_count; |
| 626 | |
| 627 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
| 628 | ADDRESS for the current elements of BP_LOCATION which get a valid |
| 629 | result from bp_location_has_shadow. You can use it for roughly |
| 630 | limiting the subrange of BP_LOCATION to scan for shadow bytes for |
| 631 | an address you need to read. */ |
| 632 | |
| 633 | static CORE_ADDR bp_location_placed_address_before_address_max; |
| 634 | |
| 635 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
| 636 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of |
| 637 | BP_LOCATION which get a valid result from bp_location_has_shadow. |
| 638 | You can use it for roughly limiting the subrange of BP_LOCATION to |
| 639 | scan for shadow bytes for an address you need to read. */ |
| 640 | |
| 641 | static CORE_ADDR bp_location_shadow_len_after_address_max; |
| 642 | |
| 643 | /* The locations that no longer correspond to any breakpoint, unlinked |
| 644 | from bp_location array, but for which a hit may still be reported |
| 645 | by a target. */ |
| 646 | VEC(bp_location_p) *moribund_locations = NULL; |
| 647 | |
| 648 | /* Number of last breakpoint made. */ |
| 649 | |
| 650 | static int breakpoint_count; |
| 651 | |
| 652 | /* The value of `breakpoint_count' before the last command that |
| 653 | created breakpoints. If the last (break-like) command created more |
| 654 | than one breakpoint, then the difference between BREAKPOINT_COUNT |
| 655 | and PREV_BREAKPOINT_COUNT is more than one. */ |
| 656 | static int prev_breakpoint_count; |
| 657 | |
| 658 | /* Number of last tracepoint made. */ |
| 659 | |
| 660 | static int tracepoint_count; |
| 661 | |
| 662 | static struct cmd_list_element *breakpoint_set_cmdlist; |
| 663 | static struct cmd_list_element *breakpoint_show_cmdlist; |
| 664 | struct cmd_list_element *save_cmdlist; |
| 665 | |
| 666 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
| 667 | static int |
| 668 | breakpoint_enabled (struct breakpoint *b) |
| 669 | { |
| 670 | return (b->enable_state == bp_enabled); |
| 671 | } |
| 672 | |
| 673 | /* Set breakpoint count to NUM. */ |
| 674 | |
| 675 | static void |
| 676 | set_breakpoint_count (int num) |
| 677 | { |
| 678 | prev_breakpoint_count = breakpoint_count; |
| 679 | breakpoint_count = num; |
| 680 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
| 681 | } |
| 682 | |
| 683 | /* Used by `start_rbreak_breakpoints' below, to record the current |
| 684 | breakpoint count before "rbreak" creates any breakpoint. */ |
| 685 | static int rbreak_start_breakpoint_count; |
| 686 | |
| 687 | /* Called at the start an "rbreak" command to record the first |
| 688 | breakpoint made. */ |
| 689 | |
| 690 | void |
| 691 | start_rbreak_breakpoints (void) |
| 692 | { |
| 693 | rbreak_start_breakpoint_count = breakpoint_count; |
| 694 | } |
| 695 | |
| 696 | /* Called at the end of an "rbreak" command to record the last |
| 697 | breakpoint made. */ |
| 698 | |
| 699 | void |
| 700 | end_rbreak_breakpoints (void) |
| 701 | { |
| 702 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
| 703 | } |
| 704 | |
| 705 | /* Used in run_command to zero the hit count when a new run starts. */ |
| 706 | |
| 707 | void |
| 708 | clear_breakpoint_hit_counts (void) |
| 709 | { |
| 710 | struct breakpoint *b; |
| 711 | |
| 712 | ALL_BREAKPOINTS (b) |
| 713 | b->hit_count = 0; |
| 714 | } |
| 715 | |
| 716 | /* Allocate a new counted_command_line with reference count of 1. |
| 717 | The new structure owns COMMANDS. */ |
| 718 | |
| 719 | static struct counted_command_line * |
| 720 | alloc_counted_command_line (struct command_line *commands) |
| 721 | { |
| 722 | struct counted_command_line *result |
| 723 | = xmalloc (sizeof (struct counted_command_line)); |
| 724 | |
| 725 | result->refc = 1; |
| 726 | result->commands = commands; |
| 727 | return result; |
| 728 | } |
| 729 | |
| 730 | /* Increment reference count. This does nothing if CMD is NULL. */ |
| 731 | |
| 732 | static void |
| 733 | incref_counted_command_line (struct counted_command_line *cmd) |
| 734 | { |
| 735 | if (cmd) |
| 736 | ++cmd->refc; |
| 737 | } |
| 738 | |
| 739 | /* Decrement reference count. If the reference count reaches 0, |
| 740 | destroy the counted_command_line. Sets *CMDP to NULL. This does |
| 741 | nothing if *CMDP is NULL. */ |
| 742 | |
| 743 | static void |
| 744 | decref_counted_command_line (struct counted_command_line **cmdp) |
| 745 | { |
| 746 | if (*cmdp) |
| 747 | { |
| 748 | if (--(*cmdp)->refc == 0) |
| 749 | { |
| 750 | free_command_lines (&(*cmdp)->commands); |
| 751 | xfree (*cmdp); |
| 752 | } |
| 753 | *cmdp = NULL; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | /* A cleanup function that calls decref_counted_command_line. */ |
| 758 | |
| 759 | static void |
| 760 | do_cleanup_counted_command_line (void *arg) |
| 761 | { |
| 762 | decref_counted_command_line (arg); |
| 763 | } |
| 764 | |
| 765 | /* Create a cleanup that calls decref_counted_command_line on the |
| 766 | argument. */ |
| 767 | |
| 768 | static struct cleanup * |
| 769 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) |
| 770 | { |
| 771 | return make_cleanup (do_cleanup_counted_command_line, cmdp); |
| 772 | } |
| 773 | |
| 774 | \f |
| 775 | /* Return the breakpoint with the specified number, or NULL |
| 776 | if the number does not refer to an existing breakpoint. */ |
| 777 | |
| 778 | struct breakpoint * |
| 779 | get_breakpoint (int num) |
| 780 | { |
| 781 | struct breakpoint *b; |
| 782 | |
| 783 | ALL_BREAKPOINTS (b) |
| 784 | if (b->number == num) |
| 785 | return b; |
| 786 | |
| 787 | return NULL; |
| 788 | } |
| 789 | |
| 790 | \f |
| 791 | |
| 792 | /* Mark locations as "conditions have changed" in case the target supports |
| 793 | evaluating conditions on its side. */ |
| 794 | |
| 795 | static void |
| 796 | mark_breakpoint_modified (struct breakpoint *b) |
| 797 | { |
| 798 | struct bp_location *loc; |
| 799 | |
| 800 | /* This is only meaningful if the target is |
| 801 | evaluating conditions and if the user has |
| 802 | opted for condition evaluation on the target's |
| 803 | side. */ |
| 804 | if (gdb_evaluates_breakpoint_condition_p () |
| 805 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 806 | return; |
| 807 | |
| 808 | if (!is_breakpoint (b)) |
| 809 | return; |
| 810 | |
| 811 | for (loc = b->loc; loc; loc = loc->next) |
| 812 | loc->condition_changed = condition_modified; |
| 813 | } |
| 814 | |
| 815 | /* Mark location as "conditions have changed" in case the target supports |
| 816 | evaluating conditions on its side. */ |
| 817 | |
| 818 | static void |
| 819 | mark_breakpoint_location_modified (struct bp_location *loc) |
| 820 | { |
| 821 | /* This is only meaningful if the target is |
| 822 | evaluating conditions and if the user has |
| 823 | opted for condition evaluation on the target's |
| 824 | side. */ |
| 825 | if (gdb_evaluates_breakpoint_condition_p () |
| 826 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 827 | |
| 828 | return; |
| 829 | |
| 830 | if (!is_breakpoint (loc->owner)) |
| 831 | return; |
| 832 | |
| 833 | loc->condition_changed = condition_modified; |
| 834 | } |
| 835 | |
| 836 | /* Sets the condition-evaluation mode using the static global |
| 837 | condition_evaluation_mode. */ |
| 838 | |
| 839 | static void |
| 840 | set_condition_evaluation_mode (char *args, int from_tty, |
| 841 | struct cmd_list_element *c) |
| 842 | { |
| 843 | const char *old_mode, *new_mode; |
| 844 | |
| 845 | if ((condition_evaluation_mode_1 == condition_evaluation_target) |
| 846 | && !target_supports_evaluation_of_breakpoint_conditions ()) |
| 847 | { |
| 848 | condition_evaluation_mode_1 = condition_evaluation_mode; |
| 849 | warning (_("Target does not support breakpoint condition evaluation.\n" |
| 850 | "Using host evaluation mode instead.")); |
| 851 | return; |
| 852 | } |
| 853 | |
| 854 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); |
| 855 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); |
| 856 | |
| 857 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
| 858 | settings was "auto". */ |
| 859 | condition_evaluation_mode = condition_evaluation_mode_1; |
| 860 | |
| 861 | /* Only update the mode if the user picked a different one. */ |
| 862 | if (new_mode != old_mode) |
| 863 | { |
| 864 | struct bp_location *loc, **loc_tmp; |
| 865 | /* If the user switched to a different evaluation mode, we |
| 866 | need to synch the changes with the target as follows: |
| 867 | |
| 868 | "host" -> "target": Send all (valid) conditions to the target. |
| 869 | "target" -> "host": Remove all the conditions from the target. |
| 870 | */ |
| 871 | |
| 872 | if (new_mode == condition_evaluation_target) |
| 873 | { |
| 874 | /* Mark everything modified and synch conditions with the |
| 875 | target. */ |
| 876 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 877 | mark_breakpoint_location_modified (loc); |
| 878 | } |
| 879 | else |
| 880 | { |
| 881 | /* Manually mark non-duplicate locations to synch conditions |
| 882 | with the target. We do this to remove all the conditions the |
| 883 | target knows about. */ |
| 884 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 885 | if (is_breakpoint (loc->owner) && loc->inserted) |
| 886 | loc->needs_update = 1; |
| 887 | } |
| 888 | |
| 889 | /* Do the update. */ |
| 890 | update_global_location_list (UGLL_MAY_INSERT); |
| 891 | } |
| 892 | |
| 893 | return; |
| 894 | } |
| 895 | |
| 896 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows |
| 897 | what "auto" is translating to. */ |
| 898 | |
| 899 | static void |
| 900 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, |
| 901 | struct cmd_list_element *c, const char *value) |
| 902 | { |
| 903 | if (condition_evaluation_mode == condition_evaluation_auto) |
| 904 | fprintf_filtered (file, |
| 905 | _("Breakpoint condition evaluation " |
| 906 | "mode is %s (currently %s).\n"), |
| 907 | value, |
| 908 | breakpoint_condition_evaluation_mode ()); |
| 909 | else |
| 910 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), |
| 911 | value); |
| 912 | } |
| 913 | |
| 914 | /* A comparison function for bp_location AP and BP that is used by |
| 915 | bsearch. This comparison function only cares about addresses, unlike |
| 916 | the more general bp_location_compare function. */ |
| 917 | |
| 918 | static int |
| 919 | bp_location_compare_addrs (const void *ap, const void *bp) |
| 920 | { |
| 921 | struct bp_location *a = *(void **) ap; |
| 922 | struct bp_location *b = *(void **) bp; |
| 923 | |
| 924 | if (a->address == b->address) |
| 925 | return 0; |
| 926 | else |
| 927 | return ((a->address > b->address) - (a->address < b->address)); |
| 928 | } |
| 929 | |
| 930 | /* Helper function to skip all bp_locations with addresses |
| 931 | less than ADDRESS. It returns the first bp_location that |
| 932 | is greater than or equal to ADDRESS. If none is found, just |
| 933 | return NULL. */ |
| 934 | |
| 935 | static struct bp_location ** |
| 936 | get_first_locp_gte_addr (CORE_ADDR address) |
| 937 | { |
| 938 | struct bp_location dummy_loc; |
| 939 | struct bp_location *dummy_locp = &dummy_loc; |
| 940 | struct bp_location **locp_found = NULL; |
| 941 | |
| 942 | /* Initialize the dummy location's address field. */ |
| 943 | memset (&dummy_loc, 0, sizeof (struct bp_location)); |
| 944 | dummy_loc.address = address; |
| 945 | |
| 946 | /* Find a close match to the first location at ADDRESS. */ |
| 947 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, |
| 948 | sizeof (struct bp_location **), |
| 949 | bp_location_compare_addrs); |
| 950 | |
| 951 | /* Nothing was found, nothing left to do. */ |
| 952 | if (locp_found == NULL) |
| 953 | return NULL; |
| 954 | |
| 955 | /* We may have found a location that is at ADDRESS but is not the first in the |
| 956 | location's list. Go backwards (if possible) and locate the first one. */ |
| 957 | while ((locp_found - 1) >= bp_location |
| 958 | && (*(locp_found - 1))->address == address) |
| 959 | locp_found--; |
| 960 | |
| 961 | return locp_found; |
| 962 | } |
| 963 | |
| 964 | void |
| 965 | set_breakpoint_condition (struct breakpoint *b, char *exp, |
| 966 | int from_tty) |
| 967 | { |
| 968 | xfree (b->cond_string); |
| 969 | b->cond_string = NULL; |
| 970 | |
| 971 | if (is_watchpoint (b)) |
| 972 | { |
| 973 | struct watchpoint *w = (struct watchpoint *) b; |
| 974 | |
| 975 | xfree (w->cond_exp); |
| 976 | w->cond_exp = NULL; |
| 977 | } |
| 978 | else |
| 979 | { |
| 980 | struct bp_location *loc; |
| 981 | |
| 982 | for (loc = b->loc; loc; loc = loc->next) |
| 983 | { |
| 984 | xfree (loc->cond); |
| 985 | loc->cond = NULL; |
| 986 | |
| 987 | /* No need to free the condition agent expression |
| 988 | bytecode (if we have one). We will handle this |
| 989 | when we go through update_global_location_list. */ |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | if (*exp == 0) |
| 994 | { |
| 995 | if (from_tty) |
| 996 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); |
| 997 | } |
| 998 | else |
| 999 | { |
| 1000 | const char *arg = exp; |
| 1001 | |
| 1002 | /* I don't know if it matters whether this is the string the user |
| 1003 | typed in or the decompiled expression. */ |
| 1004 | b->cond_string = xstrdup (arg); |
| 1005 | b->condition_not_parsed = 0; |
| 1006 | |
| 1007 | if (is_watchpoint (b)) |
| 1008 | { |
| 1009 | struct watchpoint *w = (struct watchpoint *) b; |
| 1010 | |
| 1011 | innermost_block = NULL; |
| 1012 | arg = exp; |
| 1013 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
| 1014 | if (*arg) |
| 1015 | error (_("Junk at end of expression")); |
| 1016 | w->cond_exp_valid_block = innermost_block; |
| 1017 | } |
| 1018 | else |
| 1019 | { |
| 1020 | struct bp_location *loc; |
| 1021 | |
| 1022 | for (loc = b->loc; loc; loc = loc->next) |
| 1023 | { |
| 1024 | arg = exp; |
| 1025 | loc->cond = |
| 1026 | parse_exp_1 (&arg, loc->address, |
| 1027 | block_for_pc (loc->address), 0); |
| 1028 | if (*arg) |
| 1029 | error (_("Junk at end of expression")); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | mark_breakpoint_modified (b); |
| 1034 | |
| 1035 | observer_notify_breakpoint_modified (b); |
| 1036 | } |
| 1037 | |
| 1038 | /* Completion for the "condition" command. */ |
| 1039 | |
| 1040 | static VEC (char_ptr) * |
| 1041 | condition_completer (struct cmd_list_element *cmd, |
| 1042 | const char *text, const char *word) |
| 1043 | { |
| 1044 | const char *space; |
| 1045 | |
| 1046 | text = skip_spaces_const (text); |
| 1047 | space = skip_to_space_const (text); |
| 1048 | if (*space == '\0') |
| 1049 | { |
| 1050 | int len; |
| 1051 | struct breakpoint *b; |
| 1052 | VEC (char_ptr) *result = NULL; |
| 1053 | |
| 1054 | if (text[0] == '$') |
| 1055 | { |
| 1056 | /* We don't support completion of history indices. */ |
| 1057 | if (isdigit (text[1])) |
| 1058 | return NULL; |
| 1059 | return complete_internalvar (&text[1]); |
| 1060 | } |
| 1061 | |
| 1062 | /* We're completing the breakpoint number. */ |
| 1063 | len = strlen (text); |
| 1064 | |
| 1065 | ALL_BREAKPOINTS (b) |
| 1066 | { |
| 1067 | char number[50]; |
| 1068 | |
| 1069 | xsnprintf (number, sizeof (number), "%d", b->number); |
| 1070 | |
| 1071 | if (strncmp (number, text, len) == 0) |
| 1072 | VEC_safe_push (char_ptr, result, xstrdup (number)); |
| 1073 | } |
| 1074 | |
| 1075 | return result; |
| 1076 | } |
| 1077 | |
| 1078 | /* We're completing the expression part. */ |
| 1079 | text = skip_spaces_const (space); |
| 1080 | return expression_completer (cmd, text, word); |
| 1081 | } |
| 1082 | |
| 1083 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
| 1084 | |
| 1085 | static void |
| 1086 | condition_command (char *arg, int from_tty) |
| 1087 | { |
| 1088 | struct breakpoint *b; |
| 1089 | char *p; |
| 1090 | int bnum; |
| 1091 | |
| 1092 | if (arg == 0) |
| 1093 | error_no_arg (_("breakpoint number")); |
| 1094 | |
| 1095 | p = arg; |
| 1096 | bnum = get_number (&p); |
| 1097 | if (bnum == 0) |
| 1098 | error (_("Bad breakpoint argument: '%s'"), arg); |
| 1099 | |
| 1100 | ALL_BREAKPOINTS (b) |
| 1101 | if (b->number == bnum) |
| 1102 | { |
| 1103 | /* Check if this breakpoint has a "stop" method implemented in an |
| 1104 | extension language. This method and conditions entered into GDB |
| 1105 | from the CLI are mutually exclusive. */ |
| 1106 | const struct extension_language_defn *extlang |
| 1107 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); |
| 1108 | |
| 1109 | if (extlang != NULL) |
| 1110 | { |
| 1111 | error (_("Only one stop condition allowed. There is currently" |
| 1112 | " a %s stop condition defined for this breakpoint."), |
| 1113 | ext_lang_capitalized_name (extlang)); |
| 1114 | } |
| 1115 | set_breakpoint_condition (b, p, from_tty); |
| 1116 | |
| 1117 | if (is_breakpoint (b)) |
| 1118 | update_global_location_list (UGLL_MAY_INSERT); |
| 1119 | |
| 1120 | return; |
| 1121 | } |
| 1122 | |
| 1123 | error (_("No breakpoint number %d."), bnum); |
| 1124 | } |
| 1125 | |
| 1126 | /* Check that COMMAND do not contain commands that are suitable |
| 1127 | only for tracepoints and not suitable for ordinary breakpoints. |
| 1128 | Throw if any such commands is found. */ |
| 1129 | |
| 1130 | static void |
| 1131 | check_no_tracepoint_commands (struct command_line *commands) |
| 1132 | { |
| 1133 | struct command_line *c; |
| 1134 | |
| 1135 | for (c = commands; c; c = c->next) |
| 1136 | { |
| 1137 | int i; |
| 1138 | |
| 1139 | if (c->control_type == while_stepping_control) |
| 1140 | error (_("The 'while-stepping' command can " |
| 1141 | "only be used for tracepoints")); |
| 1142 | |
| 1143 | for (i = 0; i < c->body_count; ++i) |
| 1144 | check_no_tracepoint_commands ((c->body_list)[i]); |
| 1145 | |
| 1146 | /* Not that command parsing removes leading whitespace and comment |
| 1147 | lines and also empty lines. So, we only need to check for |
| 1148 | command directly. */ |
| 1149 | if (strstr (c->line, "collect ") == c->line) |
| 1150 | error (_("The 'collect' command can only be used for tracepoints")); |
| 1151 | |
| 1152 | if (strstr (c->line, "teval ") == c->line) |
| 1153 | error (_("The 'teval' command can only be used for tracepoints")); |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | /* Encapsulate tests for different types of tracepoints. */ |
| 1158 | |
| 1159 | static int |
| 1160 | is_tracepoint_type (enum bptype type) |
| 1161 | { |
| 1162 | return (type == bp_tracepoint |
| 1163 | || type == bp_fast_tracepoint |
| 1164 | || type == bp_static_tracepoint); |
| 1165 | } |
| 1166 | |
| 1167 | int |
| 1168 | is_tracepoint (const struct breakpoint *b) |
| 1169 | { |
| 1170 | return is_tracepoint_type (b->type); |
| 1171 | } |
| 1172 | |
| 1173 | /* A helper function that validates that COMMANDS are valid for a |
| 1174 | breakpoint. This function will throw an exception if a problem is |
| 1175 | found. */ |
| 1176 | |
| 1177 | static void |
| 1178 | validate_commands_for_breakpoint (struct breakpoint *b, |
| 1179 | struct command_line *commands) |
| 1180 | { |
| 1181 | if (is_tracepoint (b)) |
| 1182 | { |
| 1183 | struct tracepoint *t = (struct tracepoint *) b; |
| 1184 | struct command_line *c; |
| 1185 | struct command_line *while_stepping = 0; |
| 1186 | |
| 1187 | /* Reset the while-stepping step count. The previous commands |
| 1188 | might have included a while-stepping action, while the new |
| 1189 | ones might not. */ |
| 1190 | t->step_count = 0; |
| 1191 | |
| 1192 | /* We need to verify that each top-level element of commands is |
| 1193 | valid for tracepoints, that there's at most one |
| 1194 | while-stepping element, and that the while-stepping's body |
| 1195 | has valid tracing commands excluding nested while-stepping. |
| 1196 | We also need to validate the tracepoint action line in the |
| 1197 | context of the tracepoint --- validate_actionline actually |
| 1198 | has side effects, like setting the tracepoint's |
| 1199 | while-stepping STEP_COUNT, in addition to checking if the |
| 1200 | collect/teval actions parse and make sense in the |
| 1201 | tracepoint's context. */ |
| 1202 | for (c = commands; c; c = c->next) |
| 1203 | { |
| 1204 | if (c->control_type == while_stepping_control) |
| 1205 | { |
| 1206 | if (b->type == bp_fast_tracepoint) |
| 1207 | error (_("The 'while-stepping' command " |
| 1208 | "cannot be used for fast tracepoint")); |
| 1209 | else if (b->type == bp_static_tracepoint) |
| 1210 | error (_("The 'while-stepping' command " |
| 1211 | "cannot be used for static tracepoint")); |
| 1212 | |
| 1213 | if (while_stepping) |
| 1214 | error (_("The 'while-stepping' command " |
| 1215 | "can be used only once")); |
| 1216 | else |
| 1217 | while_stepping = c; |
| 1218 | } |
| 1219 | |
| 1220 | validate_actionline (c->line, b); |
| 1221 | } |
| 1222 | if (while_stepping) |
| 1223 | { |
| 1224 | struct command_line *c2; |
| 1225 | |
| 1226 | gdb_assert (while_stepping->body_count == 1); |
| 1227 | c2 = while_stepping->body_list[0]; |
| 1228 | for (; c2; c2 = c2->next) |
| 1229 | { |
| 1230 | if (c2->control_type == while_stepping_control) |
| 1231 | error (_("The 'while-stepping' command cannot be nested")); |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | else |
| 1236 | { |
| 1237 | check_no_tracepoint_commands (commands); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | /* Return a vector of all the static tracepoints set at ADDR. The |
| 1242 | caller is responsible for releasing the vector. */ |
| 1243 | |
| 1244 | VEC(breakpoint_p) * |
| 1245 | static_tracepoints_here (CORE_ADDR addr) |
| 1246 | { |
| 1247 | struct breakpoint *b; |
| 1248 | VEC(breakpoint_p) *found = 0; |
| 1249 | struct bp_location *loc; |
| 1250 | |
| 1251 | ALL_BREAKPOINTS (b) |
| 1252 | if (b->type == bp_static_tracepoint) |
| 1253 | { |
| 1254 | for (loc = b->loc; loc; loc = loc->next) |
| 1255 | if (loc->address == addr) |
| 1256 | VEC_safe_push(breakpoint_p, found, b); |
| 1257 | } |
| 1258 | |
| 1259 | return found; |
| 1260 | } |
| 1261 | |
| 1262 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
| 1263 | validate that only allowed commands are included. */ |
| 1264 | |
| 1265 | void |
| 1266 | breakpoint_set_commands (struct breakpoint *b, |
| 1267 | struct command_line *commands) |
| 1268 | { |
| 1269 | validate_commands_for_breakpoint (b, commands); |
| 1270 | |
| 1271 | decref_counted_command_line (&b->commands); |
| 1272 | b->commands = alloc_counted_command_line (commands); |
| 1273 | observer_notify_breakpoint_modified (b); |
| 1274 | } |
| 1275 | |
| 1276 | /* Set the internal `silent' flag on the breakpoint. Note that this |
| 1277 | is not the same as the "silent" that may appear in the breakpoint's |
| 1278 | commands. */ |
| 1279 | |
| 1280 | void |
| 1281 | breakpoint_set_silent (struct breakpoint *b, int silent) |
| 1282 | { |
| 1283 | int old_silent = b->silent; |
| 1284 | |
| 1285 | b->silent = silent; |
| 1286 | if (old_silent != silent) |
| 1287 | observer_notify_breakpoint_modified (b); |
| 1288 | } |
| 1289 | |
| 1290 | /* Set the thread for this breakpoint. If THREAD is -1, make the |
| 1291 | breakpoint work for any thread. */ |
| 1292 | |
| 1293 | void |
| 1294 | breakpoint_set_thread (struct breakpoint *b, int thread) |
| 1295 | { |
| 1296 | int old_thread = b->thread; |
| 1297 | |
| 1298 | b->thread = thread; |
| 1299 | if (old_thread != thread) |
| 1300 | observer_notify_breakpoint_modified (b); |
| 1301 | } |
| 1302 | |
| 1303 | /* Set the task for this breakpoint. If TASK is 0, make the |
| 1304 | breakpoint work for any task. */ |
| 1305 | |
| 1306 | void |
| 1307 | breakpoint_set_task (struct breakpoint *b, int task) |
| 1308 | { |
| 1309 | int old_task = b->task; |
| 1310 | |
| 1311 | b->task = task; |
| 1312 | if (old_task != task) |
| 1313 | observer_notify_breakpoint_modified (b); |
| 1314 | } |
| 1315 | |
| 1316 | void |
| 1317 | check_tracepoint_command (char *line, void *closure) |
| 1318 | { |
| 1319 | struct breakpoint *b = closure; |
| 1320 | |
| 1321 | validate_actionline (line, b); |
| 1322 | } |
| 1323 | |
| 1324 | /* A structure used to pass information through |
| 1325 | map_breakpoint_numbers. */ |
| 1326 | |
| 1327 | struct commands_info |
| 1328 | { |
| 1329 | /* True if the command was typed at a tty. */ |
| 1330 | int from_tty; |
| 1331 | |
| 1332 | /* The breakpoint range spec. */ |
| 1333 | char *arg; |
| 1334 | |
| 1335 | /* Non-NULL if the body of the commands are being read from this |
| 1336 | already-parsed command. */ |
| 1337 | struct command_line *control; |
| 1338 | |
| 1339 | /* The command lines read from the user, or NULL if they have not |
| 1340 | yet been read. */ |
| 1341 | struct counted_command_line *cmd; |
| 1342 | }; |
| 1343 | |
| 1344 | /* A callback for map_breakpoint_numbers that sets the commands for |
| 1345 | commands_command. */ |
| 1346 | |
| 1347 | static void |
| 1348 | do_map_commands_command (struct breakpoint *b, void *data) |
| 1349 | { |
| 1350 | struct commands_info *info = data; |
| 1351 | |
| 1352 | if (info->cmd == NULL) |
| 1353 | { |
| 1354 | struct command_line *l; |
| 1355 | |
| 1356 | if (info->control != NULL) |
| 1357 | l = copy_command_lines (info->control->body_list[0]); |
| 1358 | else |
| 1359 | { |
| 1360 | struct cleanup *old_chain; |
| 1361 | char *str; |
| 1362 | |
| 1363 | str = xstrprintf (_("Type commands for breakpoint(s) " |
| 1364 | "%s, one per line."), |
| 1365 | info->arg); |
| 1366 | |
| 1367 | old_chain = make_cleanup (xfree, str); |
| 1368 | |
| 1369 | l = read_command_lines (str, |
| 1370 | info->from_tty, 1, |
| 1371 | (is_tracepoint (b) |
| 1372 | ? check_tracepoint_command : 0), |
| 1373 | b); |
| 1374 | |
| 1375 | do_cleanups (old_chain); |
| 1376 | } |
| 1377 | |
| 1378 | info->cmd = alloc_counted_command_line (l); |
| 1379 | } |
| 1380 | |
| 1381 | /* If a breakpoint was on the list more than once, we don't need to |
| 1382 | do anything. */ |
| 1383 | if (b->commands != info->cmd) |
| 1384 | { |
| 1385 | validate_commands_for_breakpoint (b, info->cmd->commands); |
| 1386 | incref_counted_command_line (info->cmd); |
| 1387 | decref_counted_command_line (&b->commands); |
| 1388 | b->commands = info->cmd; |
| 1389 | observer_notify_breakpoint_modified (b); |
| 1390 | } |
| 1391 | } |
| 1392 | |
| 1393 | static void |
| 1394 | commands_command_1 (char *arg, int from_tty, |
| 1395 | struct command_line *control) |
| 1396 | { |
| 1397 | struct cleanup *cleanups; |
| 1398 | struct commands_info info; |
| 1399 | |
| 1400 | info.from_tty = from_tty; |
| 1401 | info.control = control; |
| 1402 | info.cmd = NULL; |
| 1403 | /* If we read command lines from the user, then `info' will hold an |
| 1404 | extra reference to the commands that we must clean up. */ |
| 1405 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); |
| 1406 | |
| 1407 | if (arg == NULL || !*arg) |
| 1408 | { |
| 1409 | if (breakpoint_count - prev_breakpoint_count > 1) |
| 1410 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
| 1411 | breakpoint_count); |
| 1412 | else if (breakpoint_count > 0) |
| 1413 | arg = xstrprintf ("%d", breakpoint_count); |
| 1414 | else |
| 1415 | { |
| 1416 | /* So that we don't try to free the incoming non-NULL |
| 1417 | argument in the cleanup below. Mapping breakpoint |
| 1418 | numbers will fail in this case. */ |
| 1419 | arg = NULL; |
| 1420 | } |
| 1421 | } |
| 1422 | else |
| 1423 | /* The command loop has some static state, so we need to preserve |
| 1424 | our argument. */ |
| 1425 | arg = xstrdup (arg); |
| 1426 | |
| 1427 | if (arg != NULL) |
| 1428 | make_cleanup (xfree, arg); |
| 1429 | |
| 1430 | info.arg = arg; |
| 1431 | |
| 1432 | map_breakpoint_numbers (arg, do_map_commands_command, &info); |
| 1433 | |
| 1434 | if (info.cmd == NULL) |
| 1435 | error (_("No breakpoints specified.")); |
| 1436 | |
| 1437 | do_cleanups (cleanups); |
| 1438 | } |
| 1439 | |
| 1440 | static void |
| 1441 | commands_command (char *arg, int from_tty) |
| 1442 | { |
| 1443 | commands_command_1 (arg, from_tty, NULL); |
| 1444 | } |
| 1445 | |
| 1446 | /* Like commands_command, but instead of reading the commands from |
| 1447 | input stream, takes them from an already parsed command structure. |
| 1448 | |
| 1449 | This is used by cli-script.c to DTRT with breakpoint commands |
| 1450 | that are part of if and while bodies. */ |
| 1451 | enum command_control_type |
| 1452 | commands_from_control_command (char *arg, struct command_line *cmd) |
| 1453 | { |
| 1454 | commands_command_1 (arg, 0, cmd); |
| 1455 | return simple_control; |
| 1456 | } |
| 1457 | |
| 1458 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ |
| 1459 | |
| 1460 | static int |
| 1461 | bp_location_has_shadow (struct bp_location *bl) |
| 1462 | { |
| 1463 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 1464 | return 0; |
| 1465 | if (!bl->inserted) |
| 1466 | return 0; |
| 1467 | if (bl->target_info.shadow_len == 0) |
| 1468 | /* BL isn't valid, or doesn't shadow memory. */ |
| 1469 | return 0; |
| 1470 | return 1; |
| 1471 | } |
| 1472 | |
| 1473 | /* Update BUF, which is LEN bytes read from the target address |
| 1474 | MEMADDR, by replacing a memory breakpoint with its shadowed |
| 1475 | contents. |
| 1476 | |
| 1477 | If READBUF is not NULL, this buffer must not overlap with the of |
| 1478 | the breakpoint location's shadow_contents buffer. Otherwise, a |
| 1479 | failed assertion internal error will be raised. */ |
| 1480 | |
| 1481 | static void |
| 1482 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
| 1483 | const gdb_byte *writebuf_org, |
| 1484 | ULONGEST memaddr, LONGEST len, |
| 1485 | struct bp_target_info *target_info, |
| 1486 | struct gdbarch *gdbarch) |
| 1487 | { |
| 1488 | /* Now do full processing of the found relevant range of elements. */ |
| 1489 | CORE_ADDR bp_addr = 0; |
| 1490 | int bp_size = 0; |
| 1491 | int bptoffset = 0; |
| 1492 | |
| 1493 | if (!breakpoint_address_match (target_info->placed_address_space, 0, |
| 1494 | current_program_space->aspace, 0)) |
| 1495 | { |
| 1496 | /* The breakpoint is inserted in a different address space. */ |
| 1497 | return; |
| 1498 | } |
| 1499 | |
| 1500 | /* Addresses and length of the part of the breakpoint that |
| 1501 | we need to copy. */ |
| 1502 | bp_addr = target_info->placed_address; |
| 1503 | bp_size = target_info->shadow_len; |
| 1504 | |
| 1505 | if (bp_addr + bp_size <= memaddr) |
| 1506 | { |
| 1507 | /* The breakpoint is entirely before the chunk of memory we are |
| 1508 | reading. */ |
| 1509 | return; |
| 1510 | } |
| 1511 | |
| 1512 | if (bp_addr >= memaddr + len) |
| 1513 | { |
| 1514 | /* The breakpoint is entirely after the chunk of memory we are |
| 1515 | reading. */ |
| 1516 | return; |
| 1517 | } |
| 1518 | |
| 1519 | /* Offset within shadow_contents. */ |
| 1520 | if (bp_addr < memaddr) |
| 1521 | { |
| 1522 | /* Only copy the second part of the breakpoint. */ |
| 1523 | bp_size -= memaddr - bp_addr; |
| 1524 | bptoffset = memaddr - bp_addr; |
| 1525 | bp_addr = memaddr; |
| 1526 | } |
| 1527 | |
| 1528 | if (bp_addr + bp_size > memaddr + len) |
| 1529 | { |
| 1530 | /* Only copy the first part of the breakpoint. */ |
| 1531 | bp_size -= (bp_addr + bp_size) - (memaddr + len); |
| 1532 | } |
| 1533 | |
| 1534 | if (readbuf != NULL) |
| 1535 | { |
| 1536 | /* Verify that the readbuf buffer does not overlap with the |
| 1537 | shadow_contents buffer. */ |
| 1538 | gdb_assert (target_info->shadow_contents >= readbuf + len |
| 1539 | || readbuf >= (target_info->shadow_contents |
| 1540 | + target_info->shadow_len)); |
| 1541 | |
| 1542 | /* Update the read buffer with this inserted breakpoint's |
| 1543 | shadow. */ |
| 1544 | memcpy (readbuf + bp_addr - memaddr, |
| 1545 | target_info->shadow_contents + bptoffset, bp_size); |
| 1546 | } |
| 1547 | else |
| 1548 | { |
| 1549 | const unsigned char *bp; |
| 1550 | CORE_ADDR placed_address = target_info->placed_address; |
| 1551 | int placed_size = target_info->placed_size; |
| 1552 | |
| 1553 | /* Update the shadow with what we want to write to memory. */ |
| 1554 | memcpy (target_info->shadow_contents + bptoffset, |
| 1555 | writebuf_org + bp_addr - memaddr, bp_size); |
| 1556 | |
| 1557 | /* Determine appropriate breakpoint contents and size for this |
| 1558 | address. */ |
| 1559 | bp = gdbarch_breakpoint_from_pc (gdbarch, &placed_address, &placed_size); |
| 1560 | |
| 1561 | /* Update the final write buffer with this inserted |
| 1562 | breakpoint's INSN. */ |
| 1563 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
| 1568 | by replacing any memory breakpoints with their shadowed contents. |
| 1569 | |
| 1570 | If READBUF is not NULL, this buffer must not overlap with any of |
| 1571 | the breakpoint location's shadow_contents buffers. Otherwise, |
| 1572 | a failed assertion internal error will be raised. |
| 1573 | |
| 1574 | The range of shadowed area by each bp_location is: |
| 1575 | bl->address - bp_location_placed_address_before_address_max |
| 1576 | up to bl->address + bp_location_shadow_len_after_address_max |
| 1577 | The range we were requested to resolve shadows for is: |
| 1578 | memaddr ... memaddr + len |
| 1579 | Thus the safe cutoff boundaries for performance optimization are |
| 1580 | memaddr + len <= (bl->address |
| 1581 | - bp_location_placed_address_before_address_max) |
| 1582 | and: |
| 1583 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
| 1584 | |
| 1585 | void |
| 1586 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
| 1587 | const gdb_byte *writebuf_org, |
| 1588 | ULONGEST memaddr, LONGEST len) |
| 1589 | { |
| 1590 | /* Left boundary, right boundary and median element of our binary |
| 1591 | search. */ |
| 1592 | unsigned bc_l, bc_r, bc; |
| 1593 | size_t i; |
| 1594 | |
| 1595 | /* Find BC_L which is a leftmost element which may affect BUF |
| 1596 | content. It is safe to report lower value but a failure to |
| 1597 | report higher one. */ |
| 1598 | |
| 1599 | bc_l = 0; |
| 1600 | bc_r = bp_location_count; |
| 1601 | while (bc_l + 1 < bc_r) |
| 1602 | { |
| 1603 | struct bp_location *bl; |
| 1604 | |
| 1605 | bc = (bc_l + bc_r) / 2; |
| 1606 | bl = bp_location[bc]; |
| 1607 | |
| 1608 | /* Check first BL->ADDRESS will not overflow due to the added |
| 1609 | constant. Then advance the left boundary only if we are sure |
| 1610 | the BC element can in no way affect the BUF content (MEMADDR |
| 1611 | to MEMADDR + LEN range). |
| 1612 | |
| 1613 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
| 1614 | offset so that we cannot miss a breakpoint with its shadow |
| 1615 | range tail still reaching MEMADDR. */ |
| 1616 | |
| 1617 | if ((bl->address + bp_location_shadow_len_after_address_max |
| 1618 | >= bl->address) |
| 1619 | && (bl->address + bp_location_shadow_len_after_address_max |
| 1620 | <= memaddr)) |
| 1621 | bc_l = bc; |
| 1622 | else |
| 1623 | bc_r = bc; |
| 1624 | } |
| 1625 | |
| 1626 | /* Due to the binary search above, we need to make sure we pick the |
| 1627 | first location that's at BC_L's address. E.g., if there are |
| 1628 | multiple locations at the same address, BC_L may end up pointing |
| 1629 | at a duplicate location, and miss the "master"/"inserted" |
| 1630 | location. Say, given locations L1, L2 and L3 at addresses A and |
| 1631 | B: |
| 1632 | |
| 1633 | L1@A, L2@A, L3@B, ... |
| 1634 | |
| 1635 | BC_L could end up pointing at location L2, while the "master" |
| 1636 | location could be L1. Since the `loc->inserted' flag is only set |
| 1637 | on "master" locations, we'd forget to restore the shadow of L1 |
| 1638 | and L2. */ |
| 1639 | while (bc_l > 0 |
| 1640 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) |
| 1641 | bc_l--; |
| 1642 | |
| 1643 | /* Now do full processing of the found relevant range of elements. */ |
| 1644 | |
| 1645 | for (bc = bc_l; bc < bp_location_count; bc++) |
| 1646 | { |
| 1647 | struct bp_location *bl = bp_location[bc]; |
| 1648 | CORE_ADDR bp_addr = 0; |
| 1649 | int bp_size = 0; |
| 1650 | int bptoffset = 0; |
| 1651 | |
| 1652 | /* bp_location array has BL->OWNER always non-NULL. */ |
| 1653 | if (bl->owner->type == bp_none) |
| 1654 | warning (_("reading through apparently deleted breakpoint #%d?"), |
| 1655 | bl->owner->number); |
| 1656 | |
| 1657 | /* Performance optimization: any further element can no longer affect BUF |
| 1658 | content. */ |
| 1659 | |
| 1660 | if (bl->address >= bp_location_placed_address_before_address_max |
| 1661 | && memaddr + len <= (bl->address |
| 1662 | - bp_location_placed_address_before_address_max)) |
| 1663 | break; |
| 1664 | |
| 1665 | if (!bp_location_has_shadow (bl)) |
| 1666 | continue; |
| 1667 | |
| 1668 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
| 1669 | memaddr, len, &bl->target_info, bl->gdbarch); |
| 1670 | } |
| 1671 | |
| 1672 | /* Now process single-step breakpoints. These are not found in the |
| 1673 | bp_location array. */ |
| 1674 | for (i = 0; i < 2; i++) |
| 1675 | { |
| 1676 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; |
| 1677 | |
| 1678 | if (bp_tgt != NULL) |
| 1679 | { |
| 1680 | struct gdbarch *gdbarch = single_step_gdbarch[i]; |
| 1681 | |
| 1682 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
| 1683 | memaddr, len, bp_tgt, gdbarch); |
| 1684 | } |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | \f |
| 1689 | |
| 1690 | /* Return true if BPT is either a software breakpoint or a hardware |
| 1691 | breakpoint. */ |
| 1692 | |
| 1693 | int |
| 1694 | is_breakpoint (const struct breakpoint *bpt) |
| 1695 | { |
| 1696 | return (bpt->type == bp_breakpoint |
| 1697 | || bpt->type == bp_hardware_breakpoint |
| 1698 | || bpt->type == bp_dprintf); |
| 1699 | } |
| 1700 | |
| 1701 | /* Return true if BPT is of any hardware watchpoint kind. */ |
| 1702 | |
| 1703 | static int |
| 1704 | is_hardware_watchpoint (const struct breakpoint *bpt) |
| 1705 | { |
| 1706 | return (bpt->type == bp_hardware_watchpoint |
| 1707 | || bpt->type == bp_read_watchpoint |
| 1708 | || bpt->type == bp_access_watchpoint); |
| 1709 | } |
| 1710 | |
| 1711 | /* Return true if BPT is of any watchpoint kind, hardware or |
| 1712 | software. */ |
| 1713 | |
| 1714 | int |
| 1715 | is_watchpoint (const struct breakpoint *bpt) |
| 1716 | { |
| 1717 | return (is_hardware_watchpoint (bpt) |
| 1718 | || bpt->type == bp_watchpoint); |
| 1719 | } |
| 1720 | |
| 1721 | /* Returns true if the current thread and its running state are safe |
| 1722 | to evaluate or update watchpoint B. Watchpoints on local |
| 1723 | expressions need to be evaluated in the context of the thread that |
| 1724 | was current when the watchpoint was created, and, that thread needs |
| 1725 | to be stopped to be able to select the correct frame context. |
| 1726 | Watchpoints on global expressions can be evaluated on any thread, |
| 1727 | and in any state. It is presently left to the target allowing |
| 1728 | memory accesses when threads are running. */ |
| 1729 | |
| 1730 | static int |
| 1731 | watchpoint_in_thread_scope (struct watchpoint *b) |
| 1732 | { |
| 1733 | return (b->base.pspace == current_program_space |
| 1734 | && (ptid_equal (b->watchpoint_thread, null_ptid) |
| 1735 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) |
| 1736 | && !is_executing (inferior_ptid)))); |
| 1737 | } |
| 1738 | |
| 1739 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
| 1740 | associated bp_watchpoint_scope breakpoint. */ |
| 1741 | |
| 1742 | static void |
| 1743 | watchpoint_del_at_next_stop (struct watchpoint *w) |
| 1744 | { |
| 1745 | struct breakpoint *b = &w->base; |
| 1746 | |
| 1747 | if (b->related_breakpoint != b) |
| 1748 | { |
| 1749 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); |
| 1750 | gdb_assert (b->related_breakpoint->related_breakpoint == b); |
| 1751 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
| 1752 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; |
| 1753 | b->related_breakpoint = b; |
| 1754 | } |
| 1755 | b->disposition = disp_del_at_next_stop; |
| 1756 | } |
| 1757 | |
| 1758 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
| 1759 | watchpoint W. */ |
| 1760 | |
| 1761 | static struct value * |
| 1762 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) |
| 1763 | { |
| 1764 | struct value *bit_val; |
| 1765 | |
| 1766 | if (val == NULL) |
| 1767 | return NULL; |
| 1768 | |
| 1769 | bit_val = allocate_value (value_type (val)); |
| 1770 | |
| 1771 | unpack_value_bitfield (bit_val, |
| 1772 | w->val_bitpos, |
| 1773 | w->val_bitsize, |
| 1774 | value_contents_for_printing (val), |
| 1775 | value_offset (val), |
| 1776 | val); |
| 1777 | |
| 1778 | return bit_val; |
| 1779 | } |
| 1780 | |
| 1781 | /* Assuming that B is a watchpoint: |
| 1782 | - Reparse watchpoint expression, if REPARSE is non-zero |
| 1783 | - Evaluate expression and store the result in B->val |
| 1784 | - Evaluate the condition if there is one, and store the result |
| 1785 | in b->loc->cond. |
| 1786 | - Update the list of values that must be watched in B->loc. |
| 1787 | |
| 1788 | If the watchpoint disposition is disp_del_at_next_stop, then do |
| 1789 | nothing. If this is local watchpoint that is out of scope, delete |
| 1790 | it. |
| 1791 | |
| 1792 | Even with `set breakpoint always-inserted on' the watchpoints are |
| 1793 | removed + inserted on each stop here. Normal breakpoints must |
| 1794 | never be removed because they might be missed by a running thread |
| 1795 | when debugging in non-stop mode. On the other hand, hardware |
| 1796 | watchpoints (is_hardware_watchpoint; processed here) are specific |
| 1797 | to each LWP since they are stored in each LWP's hardware debug |
| 1798 | registers. Therefore, such LWP must be stopped first in order to |
| 1799 | be able to modify its hardware watchpoints. |
| 1800 | |
| 1801 | Hardware watchpoints must be reset exactly once after being |
| 1802 | presented to the user. It cannot be done sooner, because it would |
| 1803 | reset the data used to present the watchpoint hit to the user. And |
| 1804 | it must not be done later because it could display the same single |
| 1805 | watchpoint hit during multiple GDB stops. Note that the latter is |
| 1806 | relevant only to the hardware watchpoint types bp_read_watchpoint |
| 1807 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is |
| 1808 | not user-visible - its hit is suppressed if the memory content has |
| 1809 | not changed. |
| 1810 | |
| 1811 | The following constraints influence the location where we can reset |
| 1812 | hardware watchpoints: |
| 1813 | |
| 1814 | * target_stopped_by_watchpoint and target_stopped_data_address are |
| 1815 | called several times when GDB stops. |
| 1816 | |
| 1817 | [linux] |
| 1818 | * Multiple hardware watchpoints can be hit at the same time, |
| 1819 | causing GDB to stop. GDB only presents one hardware watchpoint |
| 1820 | hit at a time as the reason for stopping, and all the other hits |
| 1821 | are presented later, one after the other, each time the user |
| 1822 | requests the execution to be resumed. Execution is not resumed |
| 1823 | for the threads still having pending hit event stored in |
| 1824 | LWP_INFO->STATUS. While the watchpoint is already removed from |
| 1825 | the inferior on the first stop the thread hit event is kept being |
| 1826 | reported from its cached value by linux_nat_stopped_data_address |
| 1827 | until the real thread resume happens after the watchpoint gets |
| 1828 | presented and thus its LWP_INFO->STATUS gets reset. |
| 1829 | |
| 1830 | Therefore the hardware watchpoint hit can get safely reset on the |
| 1831 | watchpoint removal from inferior. */ |
| 1832 | |
| 1833 | static void |
| 1834 | update_watchpoint (struct watchpoint *b, int reparse) |
| 1835 | { |
| 1836 | int within_current_scope; |
| 1837 | struct frame_id saved_frame_id; |
| 1838 | int frame_saved; |
| 1839 | |
| 1840 | /* If this is a local watchpoint, we only want to check if the |
| 1841 | watchpoint frame is in scope if the current thread is the thread |
| 1842 | that was used to create the watchpoint. */ |
| 1843 | if (!watchpoint_in_thread_scope (b)) |
| 1844 | return; |
| 1845 | |
| 1846 | if (b->base.disposition == disp_del_at_next_stop) |
| 1847 | return; |
| 1848 | |
| 1849 | frame_saved = 0; |
| 1850 | |
| 1851 | /* Determine if the watchpoint is within scope. */ |
| 1852 | if (b->exp_valid_block == NULL) |
| 1853 | within_current_scope = 1; |
| 1854 | else |
| 1855 | { |
| 1856 | struct frame_info *fi = get_current_frame (); |
| 1857 | struct gdbarch *frame_arch = get_frame_arch (fi); |
| 1858 | CORE_ADDR frame_pc = get_frame_pc (fi); |
| 1859 | |
| 1860 | /* If we're in a function epilogue, unwinding may not work |
| 1861 | properly, so do not attempt to recreate locations at this |
| 1862 | point. See similar comments in watchpoint_check. */ |
| 1863 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
| 1864 | return; |
| 1865 | |
| 1866 | /* Save the current frame's ID so we can restore it after |
| 1867 | evaluating the watchpoint expression on its own frame. */ |
| 1868 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
| 1869 | took a frame parameter, so that we didn't have to change the |
| 1870 | selected frame. */ |
| 1871 | frame_saved = 1; |
| 1872 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); |
| 1873 | |
| 1874 | fi = frame_find_by_id (b->watchpoint_frame); |
| 1875 | within_current_scope = (fi != NULL); |
| 1876 | if (within_current_scope) |
| 1877 | select_frame (fi); |
| 1878 | } |
| 1879 | |
| 1880 | /* We don't free locations. They are stored in the bp_location array |
| 1881 | and update_global_location_list will eventually delete them and |
| 1882 | remove breakpoints if needed. */ |
| 1883 | b->base.loc = NULL; |
| 1884 | |
| 1885 | if (within_current_scope && reparse) |
| 1886 | { |
| 1887 | const char *s; |
| 1888 | |
| 1889 | if (b->exp) |
| 1890 | { |
| 1891 | xfree (b->exp); |
| 1892 | b->exp = NULL; |
| 1893 | } |
| 1894 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
| 1895 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
| 1896 | /* If the meaning of expression itself changed, the old value is |
| 1897 | no longer relevant. We don't want to report a watchpoint hit |
| 1898 | to the user when the old value and the new value may actually |
| 1899 | be completely different objects. */ |
| 1900 | value_free (b->val); |
| 1901 | b->val = NULL; |
| 1902 | b->val_valid = 0; |
| 1903 | |
| 1904 | /* Note that unlike with breakpoints, the watchpoint's condition |
| 1905 | expression is stored in the breakpoint object, not in the |
| 1906 | locations (re)created below. */ |
| 1907 | if (b->base.cond_string != NULL) |
| 1908 | { |
| 1909 | if (b->cond_exp != NULL) |
| 1910 | { |
| 1911 | xfree (b->cond_exp); |
| 1912 | b->cond_exp = NULL; |
| 1913 | } |
| 1914 | |
| 1915 | s = b->base.cond_string; |
| 1916 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
| 1917 | } |
| 1918 | } |
| 1919 | |
| 1920 | /* If we failed to parse the expression, for example because |
| 1921 | it refers to a global variable in a not-yet-loaded shared library, |
| 1922 | don't try to insert watchpoint. We don't automatically delete |
| 1923 | such watchpoint, though, since failure to parse expression |
| 1924 | is different from out-of-scope watchpoint. */ |
| 1925 | if (!target_has_execution) |
| 1926 | { |
| 1927 | /* Without execution, memory can't change. No use to try and |
| 1928 | set watchpoint locations. The watchpoint will be reset when |
| 1929 | the target gains execution, through breakpoint_re_set. */ |
| 1930 | if (!can_use_hw_watchpoints) |
| 1931 | { |
| 1932 | if (b->base.ops->works_in_software_mode (&b->base)) |
| 1933 | b->base.type = bp_watchpoint; |
| 1934 | else |
| 1935 | error (_("Can't set read/access watchpoint when " |
| 1936 | "hardware watchpoints are disabled.")); |
| 1937 | } |
| 1938 | } |
| 1939 | else if (within_current_scope && b->exp) |
| 1940 | { |
| 1941 | int pc = 0; |
| 1942 | struct value *val_chain, *v, *result, *next; |
| 1943 | struct program_space *frame_pspace; |
| 1944 | |
| 1945 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
| 1946 | |
| 1947 | /* Avoid setting b->val if it's already set. The meaning of |
| 1948 | b->val is 'the last value' user saw, and we should update |
| 1949 | it only if we reported that last value to user. As it |
| 1950 | happens, the code that reports it updates b->val directly. |
| 1951 | We don't keep track of the memory value for masked |
| 1952 | watchpoints. */ |
| 1953 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
| 1954 | { |
| 1955 | if (b->val_bitsize != 0) |
| 1956 | { |
| 1957 | v = extract_bitfield_from_watchpoint_value (b, v); |
| 1958 | if (v != NULL) |
| 1959 | release_value (v); |
| 1960 | } |
| 1961 | b->val = v; |
| 1962 | b->val_valid = 1; |
| 1963 | } |
| 1964 | |
| 1965 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
| 1966 | |
| 1967 | /* Look at each value on the value chain. */ |
| 1968 | for (v = val_chain; v; v = value_next (v)) |
| 1969 | { |
| 1970 | /* If it's a memory location, and GDB actually needed |
| 1971 | its contents to evaluate the expression, then we |
| 1972 | must watch it. If the first value returned is |
| 1973 | still lazy, that means an error occurred reading it; |
| 1974 | watch it anyway in case it becomes readable. */ |
| 1975 | if (VALUE_LVAL (v) == lval_memory |
| 1976 | && (v == val_chain || ! value_lazy (v))) |
| 1977 | { |
| 1978 | struct type *vtype = check_typedef (value_type (v)); |
| 1979 | |
| 1980 | /* We only watch structs and arrays if user asked |
| 1981 | for it explicitly, never if they just happen to |
| 1982 | appear in the middle of some value chain. */ |
| 1983 | if (v == result |
| 1984 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 1985 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 1986 | { |
| 1987 | CORE_ADDR addr; |
| 1988 | int type; |
| 1989 | struct bp_location *loc, **tmp; |
| 1990 | int bitpos = 0, bitsize = 0; |
| 1991 | |
| 1992 | if (value_bitsize (v) != 0) |
| 1993 | { |
| 1994 | /* Extract the bit parameters out from the bitfield |
| 1995 | sub-expression. */ |
| 1996 | bitpos = value_bitpos (v); |
| 1997 | bitsize = value_bitsize (v); |
| 1998 | } |
| 1999 | else if (v == result && b->val_bitsize != 0) |
| 2000 | { |
| 2001 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield |
| 2002 | lvalue whose bit parameters are saved in the fields |
| 2003 | VAL_BITPOS and VAL_BITSIZE. */ |
| 2004 | bitpos = b->val_bitpos; |
| 2005 | bitsize = b->val_bitsize; |
| 2006 | } |
| 2007 | |
| 2008 | addr = value_address (v); |
| 2009 | if (bitsize != 0) |
| 2010 | { |
| 2011 | /* Skip the bytes that don't contain the bitfield. */ |
| 2012 | addr += bitpos / 8; |
| 2013 | } |
| 2014 | |
| 2015 | type = hw_write; |
| 2016 | if (b->base.type == bp_read_watchpoint) |
| 2017 | type = hw_read; |
| 2018 | else if (b->base.type == bp_access_watchpoint) |
| 2019 | type = hw_access; |
| 2020 | |
| 2021 | loc = allocate_bp_location (&b->base); |
| 2022 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) |
| 2023 | ; |
| 2024 | *tmp = loc; |
| 2025 | loc->gdbarch = get_type_arch (value_type (v)); |
| 2026 | |
| 2027 | loc->pspace = frame_pspace; |
| 2028 | loc->address = addr; |
| 2029 | |
| 2030 | if (bitsize != 0) |
| 2031 | { |
| 2032 | /* Just cover the bytes that make up the bitfield. */ |
| 2033 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; |
| 2034 | } |
| 2035 | else |
| 2036 | loc->length = TYPE_LENGTH (value_type (v)); |
| 2037 | |
| 2038 | loc->watchpoint_type = type; |
| 2039 | } |
| 2040 | } |
| 2041 | } |
| 2042 | |
| 2043 | /* Change the type of breakpoint between hardware assisted or |
| 2044 | an ordinary watchpoint depending on the hardware support |
| 2045 | and free hardware slots. REPARSE is set when the inferior |
| 2046 | is started. */ |
| 2047 | if (reparse) |
| 2048 | { |
| 2049 | int reg_cnt; |
| 2050 | enum bp_loc_type loc_type; |
| 2051 | struct bp_location *bl; |
| 2052 | |
| 2053 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
| 2054 | |
| 2055 | if (reg_cnt) |
| 2056 | { |
| 2057 | int i, target_resources_ok, other_type_used; |
| 2058 | enum bptype type; |
| 2059 | |
| 2060 | /* Use an exact watchpoint when there's only one memory region to be |
| 2061 | watched, and only one debug register is needed to watch it. */ |
| 2062 | b->exact = target_exact_watchpoints && reg_cnt == 1; |
| 2063 | |
| 2064 | /* We need to determine how many resources are already |
| 2065 | used for all other hardware watchpoints plus this one |
| 2066 | to see if we still have enough resources to also fit |
| 2067 | this watchpoint in as well. */ |
| 2068 | |
| 2069 | /* If this is a software watchpoint, we try to turn it |
| 2070 | to a hardware one -- count resources as if B was of |
| 2071 | hardware watchpoint type. */ |
| 2072 | type = b->base.type; |
| 2073 | if (type == bp_watchpoint) |
| 2074 | type = bp_hardware_watchpoint; |
| 2075 | |
| 2076 | /* This watchpoint may or may not have been placed on |
| 2077 | the list yet at this point (it won't be in the list |
| 2078 | if we're trying to create it for the first time, |
| 2079 | through watch_command), so always account for it |
| 2080 | manually. */ |
| 2081 | |
| 2082 | /* Count resources used by all watchpoints except B. */ |
| 2083 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); |
| 2084 | |
| 2085 | /* Add in the resources needed for B. */ |
| 2086 | i += hw_watchpoint_use_count (&b->base); |
| 2087 | |
| 2088 | target_resources_ok |
| 2089 | = target_can_use_hardware_watchpoint (type, i, other_type_used); |
| 2090 | if (target_resources_ok <= 0) |
| 2091 | { |
| 2092 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
| 2093 | |
| 2094 | if (target_resources_ok == 0 && !sw_mode) |
| 2095 | error (_("Target does not support this type of " |
| 2096 | "hardware watchpoint.")); |
| 2097 | else if (target_resources_ok < 0 && !sw_mode) |
| 2098 | error (_("There are not enough available hardware " |
| 2099 | "resources for this watchpoint.")); |
| 2100 | |
| 2101 | /* Downgrade to software watchpoint. */ |
| 2102 | b->base.type = bp_watchpoint; |
| 2103 | } |
| 2104 | else |
| 2105 | { |
| 2106 | /* If this was a software watchpoint, we've just |
| 2107 | found we have enough resources to turn it to a |
| 2108 | hardware watchpoint. Otherwise, this is a |
| 2109 | nop. */ |
| 2110 | b->base.type = type; |
| 2111 | } |
| 2112 | } |
| 2113 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
| 2114 | { |
| 2115 | if (!can_use_hw_watchpoints) |
| 2116 | error (_("Can't set read/access watchpoint when " |
| 2117 | "hardware watchpoints are disabled.")); |
| 2118 | else |
| 2119 | error (_("Expression cannot be implemented with " |
| 2120 | "read/access watchpoint.")); |
| 2121 | } |
| 2122 | else |
| 2123 | b->base.type = bp_watchpoint; |
| 2124 | |
| 2125 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
| 2126 | : bp_loc_hardware_watchpoint); |
| 2127 | for (bl = b->base.loc; bl; bl = bl->next) |
| 2128 | bl->loc_type = loc_type; |
| 2129 | } |
| 2130 | |
| 2131 | for (v = val_chain; v; v = next) |
| 2132 | { |
| 2133 | next = value_next (v); |
| 2134 | if (v != b->val) |
| 2135 | value_free (v); |
| 2136 | } |
| 2137 | |
| 2138 | /* If a software watchpoint is not watching any memory, then the |
| 2139 | above left it without any location set up. But, |
| 2140 | bpstat_stop_status requires a location to be able to report |
| 2141 | stops, so make sure there's at least a dummy one. */ |
| 2142 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
| 2143 | { |
| 2144 | struct breakpoint *base = &b->base; |
| 2145 | base->loc = allocate_bp_location (base); |
| 2146 | base->loc->pspace = frame_pspace; |
| 2147 | base->loc->address = -1; |
| 2148 | base->loc->length = -1; |
| 2149 | base->loc->watchpoint_type = -1; |
| 2150 | } |
| 2151 | } |
| 2152 | else if (!within_current_scope) |
| 2153 | { |
| 2154 | printf_filtered (_("\ |
| 2155 | Watchpoint %d deleted because the program has left the block\n\ |
| 2156 | in which its expression is valid.\n"), |
| 2157 | b->base.number); |
| 2158 | watchpoint_del_at_next_stop (b); |
| 2159 | } |
| 2160 | |
| 2161 | /* Restore the selected frame. */ |
| 2162 | if (frame_saved) |
| 2163 | select_frame (frame_find_by_id (saved_frame_id)); |
| 2164 | } |
| 2165 | |
| 2166 | |
| 2167 | /* Returns 1 iff breakpoint location should be |
| 2168 | inserted in the inferior. We don't differentiate the type of BL's owner |
| 2169 | (breakpoint vs. tracepoint), although insert_location in tracepoint's |
| 2170 | breakpoint_ops is not defined, because in insert_bp_location, |
| 2171 | tracepoint's insert_location will not be called. */ |
| 2172 | static int |
| 2173 | should_be_inserted (struct bp_location *bl) |
| 2174 | { |
| 2175 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
| 2176 | return 0; |
| 2177 | |
| 2178 | if (bl->owner->disposition == disp_del_at_next_stop) |
| 2179 | return 0; |
| 2180 | |
| 2181 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
| 2182 | return 0; |
| 2183 | |
| 2184 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
| 2185 | return 0; |
| 2186 | |
| 2187 | /* This is set for example, when we're attached to the parent of a |
| 2188 | vfork, and have detached from the child. The child is running |
| 2189 | free, and we expect it to do an exec or exit, at which point the |
| 2190 | OS makes the parent schedulable again (and the target reports |
| 2191 | that the vfork is done). Until the child is done with the shared |
| 2192 | memory region, do not insert breakpoints in the parent, otherwise |
| 2193 | the child could still trip on the parent's breakpoints. Since |
| 2194 | the parent is blocked anyway, it won't miss any breakpoint. */ |
| 2195 | if (bl->pspace->breakpoints_not_allowed) |
| 2196 | return 0; |
| 2197 | |
| 2198 | /* Don't insert a breakpoint if we're trying to step past its |
| 2199 | location. */ |
| 2200 | if ((bl->loc_type == bp_loc_software_breakpoint |
| 2201 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 2202 | && stepping_past_instruction_at (bl->pspace->aspace, |
| 2203 | bl->address)) |
| 2204 | { |
| 2205 | if (debug_infrun) |
| 2206 | { |
| 2207 | fprintf_unfiltered (gdb_stdlog, |
| 2208 | "infrun: skipping breakpoint: " |
| 2209 | "stepping past insn at: %s\n", |
| 2210 | paddress (bl->gdbarch, bl->address)); |
| 2211 | } |
| 2212 | return 0; |
| 2213 | } |
| 2214 | |
| 2215 | return 1; |
| 2216 | } |
| 2217 | |
| 2218 | /* Same as should_be_inserted but does the check assuming |
| 2219 | that the location is not duplicated. */ |
| 2220 | |
| 2221 | static int |
| 2222 | unduplicated_should_be_inserted (struct bp_location *bl) |
| 2223 | { |
| 2224 | int result; |
| 2225 | const int save_duplicate = bl->duplicate; |
| 2226 | |
| 2227 | bl->duplicate = 0; |
| 2228 | result = should_be_inserted (bl); |
| 2229 | bl->duplicate = save_duplicate; |
| 2230 | return result; |
| 2231 | } |
| 2232 | |
| 2233 | /* Parses a conditional described by an expression COND into an |
| 2234 | agent expression bytecode suitable for evaluation |
| 2235 | by the bytecode interpreter. Return NULL if there was |
| 2236 | any error during parsing. */ |
| 2237 | |
| 2238 | static struct agent_expr * |
| 2239 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
| 2240 | { |
| 2241 | struct agent_expr *aexpr = NULL; |
| 2242 | volatile struct gdb_exception ex; |
| 2243 | |
| 2244 | if (!cond) |
| 2245 | return NULL; |
| 2246 | |
| 2247 | /* We don't want to stop processing, so catch any errors |
| 2248 | that may show up. */ |
| 2249 | TRY_CATCH (ex, RETURN_MASK_ERROR) |
| 2250 | { |
| 2251 | aexpr = gen_eval_for_expr (scope, cond); |
| 2252 | } |
| 2253 | |
| 2254 | if (ex.reason < 0) |
| 2255 | { |
| 2256 | /* If we got here, it means the condition could not be parsed to a valid |
| 2257 | bytecode expression and thus can't be evaluated on the target's side. |
| 2258 | It's no use iterating through the conditions. */ |
| 2259 | return NULL; |
| 2260 | } |
| 2261 | |
| 2262 | /* We have a valid agent expression. */ |
| 2263 | return aexpr; |
| 2264 | } |
| 2265 | |
| 2266 | /* Based on location BL, create a list of breakpoint conditions to be |
| 2267 | passed on to the target. If we have duplicated locations with different |
| 2268 | conditions, we will add such conditions to the list. The idea is that the |
| 2269 | target will evaluate the list of conditions and will only notify GDB when |
| 2270 | one of them is true. */ |
| 2271 | |
| 2272 | static void |
| 2273 | build_target_condition_list (struct bp_location *bl) |
| 2274 | { |
| 2275 | struct bp_location **locp = NULL, **loc2p; |
| 2276 | int null_condition_or_parse_error = 0; |
| 2277 | int modified = bl->needs_update; |
| 2278 | struct bp_location *loc; |
| 2279 | |
| 2280 | /* Release conditions left over from a previous insert. */ |
| 2281 | VEC_free (agent_expr_p, bl->target_info.conditions); |
| 2282 | |
| 2283 | /* This is only meaningful if the target is |
| 2284 | evaluating conditions and if the user has |
| 2285 | opted for condition evaluation on the target's |
| 2286 | side. */ |
| 2287 | if (gdb_evaluates_breakpoint_condition_p () |
| 2288 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 2289 | return; |
| 2290 | |
| 2291 | /* Do a first pass to check for locations with no assigned |
| 2292 | conditions or conditions that fail to parse to a valid agent expression |
| 2293 | bytecode. If any of these happen, then it's no use to send conditions |
| 2294 | to the target since this location will always trigger and generate a |
| 2295 | response back to GDB. */ |
| 2296 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2297 | { |
| 2298 | loc = (*loc2p); |
| 2299 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2300 | { |
| 2301 | if (modified) |
| 2302 | { |
| 2303 | struct agent_expr *aexpr; |
| 2304 | |
| 2305 | /* Re-parse the conditions since something changed. In that |
| 2306 | case we already freed the condition bytecodes (see |
| 2307 | force_breakpoint_reinsertion). We just |
| 2308 | need to parse the condition to bytecodes again. */ |
| 2309 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); |
| 2310 | loc->cond_bytecode = aexpr; |
| 2311 | |
| 2312 | /* Check if we managed to parse the conditional expression |
| 2313 | correctly. If not, we will not send this condition |
| 2314 | to the target. */ |
| 2315 | if (aexpr) |
| 2316 | continue; |
| 2317 | } |
| 2318 | |
| 2319 | /* If we have a NULL bytecode expression, it means something |
| 2320 | went wrong or we have a null condition expression. */ |
| 2321 | if (!loc->cond_bytecode) |
| 2322 | { |
| 2323 | null_condition_or_parse_error = 1; |
| 2324 | break; |
| 2325 | } |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | /* If any of these happened, it means we will have to evaluate the conditions |
| 2330 | for the location's address on gdb's side. It is no use keeping bytecodes |
| 2331 | for all the other duplicate locations, thus we free all of them here. |
| 2332 | |
| 2333 | This is so we have a finer control over which locations' conditions are |
| 2334 | being evaluated by GDB or the remote stub. */ |
| 2335 | if (null_condition_or_parse_error) |
| 2336 | { |
| 2337 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2338 | { |
| 2339 | loc = (*loc2p); |
| 2340 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2341 | { |
| 2342 | /* Only go as far as the first NULL bytecode is |
| 2343 | located. */ |
| 2344 | if (!loc->cond_bytecode) |
| 2345 | return; |
| 2346 | |
| 2347 | free_agent_expr (loc->cond_bytecode); |
| 2348 | loc->cond_bytecode = NULL; |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | /* No NULL conditions or failed bytecode generation. Build a condition list |
| 2354 | for this location's address. */ |
| 2355 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2356 | { |
| 2357 | loc = (*loc2p); |
| 2358 | if (loc->cond |
| 2359 | && is_breakpoint (loc->owner) |
| 2360 | && loc->pspace->num == bl->pspace->num |
| 2361 | && loc->owner->enable_state == bp_enabled |
| 2362 | && loc->enabled) |
| 2363 | /* Add the condition to the vector. This will be used later to send the |
| 2364 | conditions to the target. */ |
| 2365 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, |
| 2366 | loc->cond_bytecode); |
| 2367 | } |
| 2368 | |
| 2369 | return; |
| 2370 | } |
| 2371 | |
| 2372 | /* Parses a command described by string CMD into an agent expression |
| 2373 | bytecode suitable for evaluation by the bytecode interpreter. |
| 2374 | Return NULL if there was any error during parsing. */ |
| 2375 | |
| 2376 | static struct agent_expr * |
| 2377 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
| 2378 | { |
| 2379 | struct cleanup *old_cleanups = 0; |
| 2380 | struct expression *expr, **argvec; |
| 2381 | struct agent_expr *aexpr = NULL; |
| 2382 | volatile struct gdb_exception ex; |
| 2383 | const char *cmdrest; |
| 2384 | const char *format_start, *format_end; |
| 2385 | struct format_piece *fpieces; |
| 2386 | int nargs; |
| 2387 | struct gdbarch *gdbarch = get_current_arch (); |
| 2388 | |
| 2389 | if (!cmd) |
| 2390 | return NULL; |
| 2391 | |
| 2392 | cmdrest = cmd; |
| 2393 | |
| 2394 | if (*cmdrest == ',') |
| 2395 | ++cmdrest; |
| 2396 | cmdrest = skip_spaces_const (cmdrest); |
| 2397 | |
| 2398 | if (*cmdrest++ != '"') |
| 2399 | error (_("No format string following the location")); |
| 2400 | |
| 2401 | format_start = cmdrest; |
| 2402 | |
| 2403 | fpieces = parse_format_string (&cmdrest); |
| 2404 | |
| 2405 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); |
| 2406 | |
| 2407 | format_end = cmdrest; |
| 2408 | |
| 2409 | if (*cmdrest++ != '"') |
| 2410 | error (_("Bad format string, non-terminated '\"'.")); |
| 2411 | |
| 2412 | cmdrest = skip_spaces_const (cmdrest); |
| 2413 | |
| 2414 | if (!(*cmdrest == ',' || *cmdrest == '\0')) |
| 2415 | error (_("Invalid argument syntax")); |
| 2416 | |
| 2417 | if (*cmdrest == ',') |
| 2418 | cmdrest++; |
| 2419 | cmdrest = skip_spaces_const (cmdrest); |
| 2420 | |
| 2421 | /* For each argument, make an expression. */ |
| 2422 | |
| 2423 | argvec = (struct expression **) alloca (strlen (cmd) |
| 2424 | * sizeof (struct expression *)); |
| 2425 | |
| 2426 | nargs = 0; |
| 2427 | while (*cmdrest != '\0') |
| 2428 | { |
| 2429 | const char *cmd1; |
| 2430 | |
| 2431 | cmd1 = cmdrest; |
| 2432 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
| 2433 | argvec[nargs++] = expr; |
| 2434 | cmdrest = cmd1; |
| 2435 | if (*cmdrest == ',') |
| 2436 | ++cmdrest; |
| 2437 | } |
| 2438 | |
| 2439 | /* We don't want to stop processing, so catch any errors |
| 2440 | that may show up. */ |
| 2441 | TRY_CATCH (ex, RETURN_MASK_ERROR) |
| 2442 | { |
| 2443 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
| 2444 | format_start, format_end - format_start, |
| 2445 | fpieces, nargs, argvec); |
| 2446 | } |
| 2447 | |
| 2448 | do_cleanups (old_cleanups); |
| 2449 | |
| 2450 | if (ex.reason < 0) |
| 2451 | { |
| 2452 | /* If we got here, it means the command could not be parsed to a valid |
| 2453 | bytecode expression and thus can't be evaluated on the target's side. |
| 2454 | It's no use iterating through the other commands. */ |
| 2455 | return NULL; |
| 2456 | } |
| 2457 | |
| 2458 | /* We have a valid agent expression, return it. */ |
| 2459 | return aexpr; |
| 2460 | } |
| 2461 | |
| 2462 | /* Based on location BL, create a list of breakpoint commands to be |
| 2463 | passed on to the target. If we have duplicated locations with |
| 2464 | different commands, we will add any such to the list. */ |
| 2465 | |
| 2466 | static void |
| 2467 | build_target_command_list (struct bp_location *bl) |
| 2468 | { |
| 2469 | struct bp_location **locp = NULL, **loc2p; |
| 2470 | int null_command_or_parse_error = 0; |
| 2471 | int modified = bl->needs_update; |
| 2472 | struct bp_location *loc; |
| 2473 | |
| 2474 | /* Release commands left over from a previous insert. */ |
| 2475 | VEC_free (agent_expr_p, bl->target_info.tcommands); |
| 2476 | |
| 2477 | if (!target_can_run_breakpoint_commands ()) |
| 2478 | return; |
| 2479 | |
| 2480 | /* For now, limit to agent-style dprintf breakpoints. */ |
| 2481 | if (dprintf_style != dprintf_style_agent) |
| 2482 | return; |
| 2483 | |
| 2484 | /* For now, if we have any duplicate location that isn't a dprintf, |
| 2485 | don't install the target-side commands, as that would make the |
| 2486 | breakpoint not be reported to the core, and we'd lose |
| 2487 | control. */ |
| 2488 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2489 | { |
| 2490 | loc = (*loc2p); |
| 2491 | if (is_breakpoint (loc->owner) |
| 2492 | && loc->pspace->num == bl->pspace->num |
| 2493 | && loc->owner->type != bp_dprintf) |
| 2494 | return; |
| 2495 | } |
| 2496 | |
| 2497 | /* Do a first pass to check for locations with no assigned |
| 2498 | conditions or conditions that fail to parse to a valid agent expression |
| 2499 | bytecode. If any of these happen, then it's no use to send conditions |
| 2500 | to the target since this location will always trigger and generate a |
| 2501 | response back to GDB. */ |
| 2502 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2503 | { |
| 2504 | loc = (*loc2p); |
| 2505 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2506 | { |
| 2507 | if (modified) |
| 2508 | { |
| 2509 | struct agent_expr *aexpr; |
| 2510 | |
| 2511 | /* Re-parse the commands since something changed. In that |
| 2512 | case we already freed the command bytecodes (see |
| 2513 | force_breakpoint_reinsertion). We just |
| 2514 | need to parse the command to bytecodes again. */ |
| 2515 | aexpr = parse_cmd_to_aexpr (bl->address, |
| 2516 | loc->owner->extra_string); |
| 2517 | loc->cmd_bytecode = aexpr; |
| 2518 | |
| 2519 | if (!aexpr) |
| 2520 | continue; |
| 2521 | } |
| 2522 | |
| 2523 | /* If we have a NULL bytecode expression, it means something |
| 2524 | went wrong or we have a null command expression. */ |
| 2525 | if (!loc->cmd_bytecode) |
| 2526 | { |
| 2527 | null_command_or_parse_error = 1; |
| 2528 | break; |
| 2529 | } |
| 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | /* If anything failed, then we're not doing target-side commands, |
| 2534 | and so clean up. */ |
| 2535 | if (null_command_or_parse_error) |
| 2536 | { |
| 2537 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2538 | { |
| 2539 | loc = (*loc2p); |
| 2540 | if (is_breakpoint (loc->owner) |
| 2541 | && loc->pspace->num == bl->pspace->num) |
| 2542 | { |
| 2543 | /* Only go as far as the first NULL bytecode is |
| 2544 | located. */ |
| 2545 | if (loc->cmd_bytecode == NULL) |
| 2546 | return; |
| 2547 | |
| 2548 | free_agent_expr (loc->cmd_bytecode); |
| 2549 | loc->cmd_bytecode = NULL; |
| 2550 | } |
| 2551 | } |
| 2552 | } |
| 2553 | |
| 2554 | /* No NULL commands or failed bytecode generation. Build a command list |
| 2555 | for this location's address. */ |
| 2556 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2557 | { |
| 2558 | loc = (*loc2p); |
| 2559 | if (loc->owner->extra_string |
| 2560 | && is_breakpoint (loc->owner) |
| 2561 | && loc->pspace->num == bl->pspace->num |
| 2562 | && loc->owner->enable_state == bp_enabled |
| 2563 | && loc->enabled) |
| 2564 | /* Add the command to the vector. This will be used later |
| 2565 | to send the commands to the target. */ |
| 2566 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, |
| 2567 | loc->cmd_bytecode); |
| 2568 | } |
| 2569 | |
| 2570 | bl->target_info.persist = 0; |
| 2571 | /* Maybe flag this location as persistent. */ |
| 2572 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) |
| 2573 | bl->target_info.persist = 1; |
| 2574 | } |
| 2575 | |
| 2576 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
| 2577 | location. Any error messages are printed to TMP_ERROR_STREAM; and |
| 2578 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
| 2579 | Returns 0 for success, 1 if the bp_location type is not supported or |
| 2580 | -1 for failure. |
| 2581 | |
| 2582 | NOTE drow/2003-09-09: This routine could be broken down to an |
| 2583 | object-style method for each breakpoint or catchpoint type. */ |
| 2584 | static int |
| 2585 | insert_bp_location (struct bp_location *bl, |
| 2586 | struct ui_file *tmp_error_stream, |
| 2587 | int *disabled_breaks, |
| 2588 | int *hw_breakpoint_error, |
| 2589 | int *hw_bp_error_explained_already) |
| 2590 | { |
| 2591 | enum errors bp_err = GDB_NO_ERROR; |
| 2592 | const char *bp_err_message = NULL; |
| 2593 | volatile struct gdb_exception e; |
| 2594 | |
| 2595 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
| 2596 | return 0; |
| 2597 | |
| 2598 | /* Note we don't initialize bl->target_info, as that wipes out |
| 2599 | the breakpoint location's shadow_contents if the breakpoint |
| 2600 | is still inserted at that location. This in turn breaks |
| 2601 | target_read_memory which depends on these buffers when |
| 2602 | a memory read is requested at the breakpoint location: |
| 2603 | Once the target_info has been wiped, we fail to see that |
| 2604 | we have a breakpoint inserted at that address and thus |
| 2605 | read the breakpoint instead of returning the data saved in |
| 2606 | the breakpoint location's shadow contents. */ |
| 2607 | bl->target_info.placed_address = bl->address; |
| 2608 | bl->target_info.placed_address_space = bl->pspace->aspace; |
| 2609 | bl->target_info.length = bl->length; |
| 2610 | |
| 2611 | /* When working with target-side conditions, we must pass all the conditions |
| 2612 | for the same breakpoint address down to the target since GDB will not |
| 2613 | insert those locations. With a list of breakpoint conditions, the target |
| 2614 | can decide when to stop and notify GDB. */ |
| 2615 | |
| 2616 | if (is_breakpoint (bl->owner)) |
| 2617 | { |
| 2618 | build_target_condition_list (bl); |
| 2619 | build_target_command_list (bl); |
| 2620 | /* Reset the modification marker. */ |
| 2621 | bl->needs_update = 0; |
| 2622 | } |
| 2623 | |
| 2624 | if (bl->loc_type == bp_loc_software_breakpoint |
| 2625 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 2626 | { |
| 2627 | if (bl->owner->type != bp_hardware_breakpoint) |
| 2628 | { |
| 2629 | /* If the explicitly specified breakpoint type |
| 2630 | is not hardware breakpoint, check the memory map to see |
| 2631 | if the breakpoint address is in read only memory or not. |
| 2632 | |
| 2633 | Two important cases are: |
| 2634 | - location type is not hardware breakpoint, memory |
| 2635 | is readonly. We change the type of the location to |
| 2636 | hardware breakpoint. |
| 2637 | - location type is hardware breakpoint, memory is |
| 2638 | read-write. This means we've previously made the |
| 2639 | location hardware one, but then the memory map changed, |
| 2640 | so we undo. |
| 2641 | |
| 2642 | When breakpoints are removed, remove_breakpoints will use |
| 2643 | location types we've just set here, the only possible |
| 2644 | problem is that memory map has changed during running |
| 2645 | program, but it's not going to work anyway with current |
| 2646 | gdb. */ |
| 2647 | struct mem_region *mr |
| 2648 | = lookup_mem_region (bl->target_info.placed_address); |
| 2649 | |
| 2650 | if (mr) |
| 2651 | { |
| 2652 | if (automatic_hardware_breakpoints) |
| 2653 | { |
| 2654 | enum bp_loc_type new_type; |
| 2655 | |
| 2656 | if (mr->attrib.mode != MEM_RW) |
| 2657 | new_type = bp_loc_hardware_breakpoint; |
| 2658 | else |
| 2659 | new_type = bp_loc_software_breakpoint; |
| 2660 | |
| 2661 | if (new_type != bl->loc_type) |
| 2662 | { |
| 2663 | static int said = 0; |
| 2664 | |
| 2665 | bl->loc_type = new_type; |
| 2666 | if (!said) |
| 2667 | { |
| 2668 | fprintf_filtered (gdb_stdout, |
| 2669 | _("Note: automatically using " |
| 2670 | "hardware breakpoints for " |
| 2671 | "read-only addresses.\n")); |
| 2672 | said = 1; |
| 2673 | } |
| 2674 | } |
| 2675 | } |
| 2676 | else if (bl->loc_type == bp_loc_software_breakpoint |
| 2677 | && mr->attrib.mode != MEM_RW) |
| 2678 | { |
| 2679 | fprintf_unfiltered (tmp_error_stream, |
| 2680 | _("Cannot insert breakpoint %d.\n" |
| 2681 | "Cannot set software breakpoint " |
| 2682 | "at read-only address %s\n"), |
| 2683 | bl->owner->number, |
| 2684 | paddress (bl->gdbarch, bl->address)); |
| 2685 | return 1; |
| 2686 | } |
| 2687 | } |
| 2688 | } |
| 2689 | |
| 2690 | /* First check to see if we have to handle an overlay. */ |
| 2691 | if (overlay_debugging == ovly_off |
| 2692 | || bl->section == NULL |
| 2693 | || !(section_is_overlay (bl->section))) |
| 2694 | { |
| 2695 | /* No overlay handling: just set the breakpoint. */ |
| 2696 | TRY_CATCH (e, RETURN_MASK_ALL) |
| 2697 | { |
| 2698 | int val; |
| 2699 | |
| 2700 | val = bl->owner->ops->insert_location (bl); |
| 2701 | if (val) |
| 2702 | bp_err = GENERIC_ERROR; |
| 2703 | } |
| 2704 | if (e.reason < 0) |
| 2705 | { |
| 2706 | bp_err = e.error; |
| 2707 | bp_err_message = e.message; |
| 2708 | } |
| 2709 | } |
| 2710 | else |
| 2711 | { |
| 2712 | /* This breakpoint is in an overlay section. |
| 2713 | Shall we set a breakpoint at the LMA? */ |
| 2714 | if (!overlay_events_enabled) |
| 2715 | { |
| 2716 | /* Yes -- overlay event support is not active, |
| 2717 | so we must try to set a breakpoint at the LMA. |
| 2718 | This will not work for a hardware breakpoint. */ |
| 2719 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 2720 | warning (_("hardware breakpoint %d not supported in overlay!"), |
| 2721 | bl->owner->number); |
| 2722 | else |
| 2723 | { |
| 2724 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
| 2725 | bl->section); |
| 2726 | /* Set a software (trap) breakpoint at the LMA. */ |
| 2727 | bl->overlay_target_info = bl->target_info; |
| 2728 | bl->overlay_target_info.placed_address = addr; |
| 2729 | |
| 2730 | /* No overlay handling: just set the breakpoint. */ |
| 2731 | TRY_CATCH (e, RETURN_MASK_ALL) |
| 2732 | { |
| 2733 | int val; |
| 2734 | |
| 2735 | val = target_insert_breakpoint (bl->gdbarch, |
| 2736 | &bl->overlay_target_info); |
| 2737 | if (val) |
| 2738 | bp_err = GENERIC_ERROR; |
| 2739 | } |
| 2740 | if (e.reason < 0) |
| 2741 | { |
| 2742 | bp_err = e.error; |
| 2743 | bp_err_message = e.message; |
| 2744 | } |
| 2745 | |
| 2746 | if (bp_err != GDB_NO_ERROR) |
| 2747 | fprintf_unfiltered (tmp_error_stream, |
| 2748 | "Overlay breakpoint %d " |
| 2749 | "failed: in ROM?\n", |
| 2750 | bl->owner->number); |
| 2751 | } |
| 2752 | } |
| 2753 | /* Shall we set a breakpoint at the VMA? */ |
| 2754 | if (section_is_mapped (bl->section)) |
| 2755 | { |
| 2756 | /* Yes. This overlay section is mapped into memory. */ |
| 2757 | TRY_CATCH (e, RETURN_MASK_ALL) |
| 2758 | { |
| 2759 | int val; |
| 2760 | |
| 2761 | val = bl->owner->ops->insert_location (bl); |
| 2762 | if (val) |
| 2763 | bp_err = GENERIC_ERROR; |
| 2764 | } |
| 2765 | if (e.reason < 0) |
| 2766 | { |
| 2767 | bp_err = e.error; |
| 2768 | bp_err_message = e.message; |
| 2769 | } |
| 2770 | } |
| 2771 | else |
| 2772 | { |
| 2773 | /* No. This breakpoint will not be inserted. |
| 2774 | No error, but do not mark the bp as 'inserted'. */ |
| 2775 | return 0; |
| 2776 | } |
| 2777 | } |
| 2778 | |
| 2779 | if (bp_err != GDB_NO_ERROR) |
| 2780 | { |
| 2781 | /* Can't set the breakpoint. */ |
| 2782 | |
| 2783 | /* In some cases, we might not be able to insert a |
| 2784 | breakpoint in a shared library that has already been |
| 2785 | removed, but we have not yet processed the shlib unload |
| 2786 | event. Unfortunately, some targets that implement |
| 2787 | breakpoint insertion themselves can't tell why the |
| 2788 | breakpoint insertion failed (e.g., the remote target |
| 2789 | doesn't define error codes), so we must treat generic |
| 2790 | errors as memory errors. */ |
| 2791 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
| 2792 | && bl->loc_type == bp_loc_software_breakpoint |
| 2793 | && (solib_name_from_address (bl->pspace, bl->address) |
| 2794 | || shared_objfile_contains_address_p (bl->pspace, |
| 2795 | bl->address))) |
| 2796 | { |
| 2797 | /* See also: disable_breakpoints_in_shlibs. */ |
| 2798 | bl->shlib_disabled = 1; |
| 2799 | observer_notify_breakpoint_modified (bl->owner); |
| 2800 | if (!*disabled_breaks) |
| 2801 | { |
| 2802 | fprintf_unfiltered (tmp_error_stream, |
| 2803 | "Cannot insert breakpoint %d.\n", |
| 2804 | bl->owner->number); |
| 2805 | fprintf_unfiltered (tmp_error_stream, |
| 2806 | "Temporarily disabling shared " |
| 2807 | "library breakpoints:\n"); |
| 2808 | } |
| 2809 | *disabled_breaks = 1; |
| 2810 | fprintf_unfiltered (tmp_error_stream, |
| 2811 | "breakpoint #%d\n", bl->owner->number); |
| 2812 | return 0; |
| 2813 | } |
| 2814 | else |
| 2815 | { |
| 2816 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 2817 | { |
| 2818 | *hw_breakpoint_error = 1; |
| 2819 | *hw_bp_error_explained_already = bp_err_message != NULL; |
| 2820 | fprintf_unfiltered (tmp_error_stream, |
| 2821 | "Cannot insert hardware breakpoint %d%s", |
| 2822 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
| 2823 | if (bp_err_message != NULL) |
| 2824 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); |
| 2825 | } |
| 2826 | else |
| 2827 | { |
| 2828 | if (bp_err_message == NULL) |
| 2829 | { |
| 2830 | char *message |
| 2831 | = memory_error_message (TARGET_XFER_E_IO, |
| 2832 | bl->gdbarch, bl->address); |
| 2833 | struct cleanup *old_chain = make_cleanup (xfree, message); |
| 2834 | |
| 2835 | fprintf_unfiltered (tmp_error_stream, |
| 2836 | "Cannot insert breakpoint %d.\n" |
| 2837 | "%s\n", |
| 2838 | bl->owner->number, message); |
| 2839 | do_cleanups (old_chain); |
| 2840 | } |
| 2841 | else |
| 2842 | { |
| 2843 | fprintf_unfiltered (tmp_error_stream, |
| 2844 | "Cannot insert breakpoint %d: %s\n", |
| 2845 | bl->owner->number, |
| 2846 | bp_err_message); |
| 2847 | } |
| 2848 | } |
| 2849 | return 1; |
| 2850 | |
| 2851 | } |
| 2852 | } |
| 2853 | else |
| 2854 | bl->inserted = 1; |
| 2855 | |
| 2856 | return 0; |
| 2857 | } |
| 2858 | |
| 2859 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
| 2860 | /* NOTE drow/2003-09-08: This state only exists for removing |
| 2861 | watchpoints. It's not clear that it's necessary... */ |
| 2862 | && bl->owner->disposition != disp_del_at_next_stop) |
| 2863 | { |
| 2864 | int val; |
| 2865 | |
| 2866 | gdb_assert (bl->owner->ops != NULL |
| 2867 | && bl->owner->ops->insert_location != NULL); |
| 2868 | |
| 2869 | val = bl->owner->ops->insert_location (bl); |
| 2870 | |
| 2871 | /* If trying to set a read-watchpoint, and it turns out it's not |
| 2872 | supported, try emulating one with an access watchpoint. */ |
| 2873 | if (val == 1 && bl->watchpoint_type == hw_read) |
| 2874 | { |
| 2875 | struct bp_location *loc, **loc_temp; |
| 2876 | |
| 2877 | /* But don't try to insert it, if there's already another |
| 2878 | hw_access location that would be considered a duplicate |
| 2879 | of this one. */ |
| 2880 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 2881 | if (loc != bl |
| 2882 | && loc->watchpoint_type == hw_access |
| 2883 | && watchpoint_locations_match (bl, loc)) |
| 2884 | { |
| 2885 | bl->duplicate = 1; |
| 2886 | bl->inserted = 1; |
| 2887 | bl->target_info = loc->target_info; |
| 2888 | bl->watchpoint_type = hw_access; |
| 2889 | val = 0; |
| 2890 | break; |
| 2891 | } |
| 2892 | |
| 2893 | if (val == 1) |
| 2894 | { |
| 2895 | bl->watchpoint_type = hw_access; |
| 2896 | val = bl->owner->ops->insert_location (bl); |
| 2897 | |
| 2898 | if (val) |
| 2899 | /* Back to the original value. */ |
| 2900 | bl->watchpoint_type = hw_read; |
| 2901 | } |
| 2902 | } |
| 2903 | |
| 2904 | bl->inserted = (val == 0); |
| 2905 | } |
| 2906 | |
| 2907 | else if (bl->owner->type == bp_catchpoint) |
| 2908 | { |
| 2909 | int val; |
| 2910 | |
| 2911 | gdb_assert (bl->owner->ops != NULL |
| 2912 | && bl->owner->ops->insert_location != NULL); |
| 2913 | |
| 2914 | val = bl->owner->ops->insert_location (bl); |
| 2915 | if (val) |
| 2916 | { |
| 2917 | bl->owner->enable_state = bp_disabled; |
| 2918 | |
| 2919 | if (val == 1) |
| 2920 | warning (_("\ |
| 2921 | Error inserting catchpoint %d: Your system does not support this type\n\ |
| 2922 | of catchpoint."), bl->owner->number); |
| 2923 | else |
| 2924 | warning (_("Error inserting catchpoint %d."), bl->owner->number); |
| 2925 | } |
| 2926 | |
| 2927 | bl->inserted = (val == 0); |
| 2928 | |
| 2929 | /* We've already printed an error message if there was a problem |
| 2930 | inserting this catchpoint, and we've disabled the catchpoint, |
| 2931 | so just return success. */ |
| 2932 | return 0; |
| 2933 | } |
| 2934 | |
| 2935 | return 0; |
| 2936 | } |
| 2937 | |
| 2938 | /* This function is called when program space PSPACE is about to be |
| 2939 | deleted. It takes care of updating breakpoints to not reference |
| 2940 | PSPACE anymore. */ |
| 2941 | |
| 2942 | void |
| 2943 | breakpoint_program_space_exit (struct program_space *pspace) |
| 2944 | { |
| 2945 | struct breakpoint *b, *b_temp; |
| 2946 | struct bp_location *loc, **loc_temp; |
| 2947 | |
| 2948 | /* Remove any breakpoint that was set through this program space. */ |
| 2949 | ALL_BREAKPOINTS_SAFE (b, b_temp) |
| 2950 | { |
| 2951 | if (b->pspace == pspace) |
| 2952 | delete_breakpoint (b); |
| 2953 | } |
| 2954 | |
| 2955 | /* Breakpoints set through other program spaces could have locations |
| 2956 | bound to PSPACE as well. Remove those. */ |
| 2957 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 2958 | { |
| 2959 | struct bp_location *tmp; |
| 2960 | |
| 2961 | if (loc->pspace == pspace) |
| 2962 | { |
| 2963 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 2964 | if (loc->owner->loc == loc) |
| 2965 | loc->owner->loc = loc->next; |
| 2966 | else |
| 2967 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) |
| 2968 | if (tmp->next == loc) |
| 2969 | { |
| 2970 | tmp->next = loc->next; |
| 2971 | break; |
| 2972 | } |
| 2973 | } |
| 2974 | } |
| 2975 | |
| 2976 | /* Now update the global location list to permanently delete the |
| 2977 | removed locations above. */ |
| 2978 | update_global_location_list (UGLL_DONT_INSERT); |
| 2979 | } |
| 2980 | |
| 2981 | /* Make sure all breakpoints are inserted in inferior. |
| 2982 | Throws exception on any error. |
| 2983 | A breakpoint that is already inserted won't be inserted |
| 2984 | again, so calling this function twice is safe. */ |
| 2985 | void |
| 2986 | insert_breakpoints (void) |
| 2987 | { |
| 2988 | struct breakpoint *bpt; |
| 2989 | |
| 2990 | ALL_BREAKPOINTS (bpt) |
| 2991 | if (is_hardware_watchpoint (bpt)) |
| 2992 | { |
| 2993 | struct watchpoint *w = (struct watchpoint *) bpt; |
| 2994 | |
| 2995 | update_watchpoint (w, 0 /* don't reparse. */); |
| 2996 | } |
| 2997 | |
| 2998 | /* Updating watchpoints creates new locations, so update the global |
| 2999 | location list. Explicitly tell ugll to insert locations and |
| 3000 | ignore breakpoints_always_inserted_mode. */ |
| 3001 | update_global_location_list (UGLL_INSERT); |
| 3002 | } |
| 3003 | |
| 3004 | /* Invoke CALLBACK for each of bp_location. */ |
| 3005 | |
| 3006 | void |
| 3007 | iterate_over_bp_locations (walk_bp_location_callback callback) |
| 3008 | { |
| 3009 | struct bp_location *loc, **loc_tmp; |
| 3010 | |
| 3011 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 3012 | { |
| 3013 | callback (loc, NULL); |
| 3014 | } |
| 3015 | } |
| 3016 | |
| 3017 | /* This is used when we need to synch breakpoint conditions between GDB and the |
| 3018 | target. It is the case with deleting and disabling of breakpoints when using |
| 3019 | always-inserted mode. */ |
| 3020 | |
| 3021 | static void |
| 3022 | update_inserted_breakpoint_locations (void) |
| 3023 | { |
| 3024 | struct bp_location *bl, **blp_tmp; |
| 3025 | int error_flag = 0; |
| 3026 | int val = 0; |
| 3027 | int disabled_breaks = 0; |
| 3028 | int hw_breakpoint_error = 0; |
| 3029 | int hw_bp_details_reported = 0; |
| 3030 | |
| 3031 | struct ui_file *tmp_error_stream = mem_fileopen (); |
| 3032 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
| 3033 | |
| 3034 | /* Explicitly mark the warning -- this will only be printed if |
| 3035 | there was an error. */ |
| 3036 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); |
| 3037 | |
| 3038 | save_current_space_and_thread (); |
| 3039 | |
| 3040 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3041 | { |
| 3042 | /* We only want to update software breakpoints and hardware |
| 3043 | breakpoints. */ |
| 3044 | if (!is_breakpoint (bl->owner)) |
| 3045 | continue; |
| 3046 | |
| 3047 | /* We only want to update locations that are already inserted |
| 3048 | and need updating. This is to avoid unwanted insertion during |
| 3049 | deletion of breakpoints. */ |
| 3050 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) |
| 3051 | continue; |
| 3052 | |
| 3053 | switch_to_program_space_and_thread (bl->pspace); |
| 3054 | |
| 3055 | /* For targets that support global breakpoints, there's no need |
| 3056 | to select an inferior to insert breakpoint to. In fact, even |
| 3057 | if we aren't attached to any process yet, we should still |
| 3058 | insert breakpoints. */ |
| 3059 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 3060 | && ptid_equal (inferior_ptid, null_ptid)) |
| 3061 | continue; |
| 3062 | |
| 3063 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
| 3064 | &hw_breakpoint_error, &hw_bp_details_reported); |
| 3065 | if (val) |
| 3066 | error_flag = val; |
| 3067 | } |
| 3068 | |
| 3069 | if (error_flag) |
| 3070 | { |
| 3071 | target_terminal_ours_for_output (); |
| 3072 | error_stream (tmp_error_stream); |
| 3073 | } |
| 3074 | |
| 3075 | do_cleanups (cleanups); |
| 3076 | } |
| 3077 | |
| 3078 | /* Used when starting or continuing the program. */ |
| 3079 | |
| 3080 | static void |
| 3081 | insert_breakpoint_locations (void) |
| 3082 | { |
| 3083 | struct breakpoint *bpt; |
| 3084 | struct bp_location *bl, **blp_tmp; |
| 3085 | int error_flag = 0; |
| 3086 | int val = 0; |
| 3087 | int disabled_breaks = 0; |
| 3088 | int hw_breakpoint_error = 0; |
| 3089 | int hw_bp_error_explained_already = 0; |
| 3090 | |
| 3091 | struct ui_file *tmp_error_stream = mem_fileopen (); |
| 3092 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
| 3093 | |
| 3094 | /* Explicitly mark the warning -- this will only be printed if |
| 3095 | there was an error. */ |
| 3096 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); |
| 3097 | |
| 3098 | save_current_space_and_thread (); |
| 3099 | |
| 3100 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3101 | { |
| 3102 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
| 3103 | continue; |
| 3104 | |
| 3105 | /* There is no point inserting thread-specific breakpoints if |
| 3106 | the thread no longer exists. ALL_BP_LOCATIONS bp_location |
| 3107 | has BL->OWNER always non-NULL. */ |
| 3108 | if (bl->owner->thread != -1 |
| 3109 | && !valid_thread_id (bl->owner->thread)) |
| 3110 | continue; |
| 3111 | |
| 3112 | switch_to_program_space_and_thread (bl->pspace); |
| 3113 | |
| 3114 | /* For targets that support global breakpoints, there's no need |
| 3115 | to select an inferior to insert breakpoint to. In fact, even |
| 3116 | if we aren't attached to any process yet, we should still |
| 3117 | insert breakpoints. */ |
| 3118 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 3119 | && ptid_equal (inferior_ptid, null_ptid)) |
| 3120 | continue; |
| 3121 | |
| 3122 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
| 3123 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
| 3124 | if (val) |
| 3125 | error_flag = val; |
| 3126 | } |
| 3127 | |
| 3128 | /* If we failed to insert all locations of a watchpoint, remove |
| 3129 | them, as half-inserted watchpoint is of limited use. */ |
| 3130 | ALL_BREAKPOINTS (bpt) |
| 3131 | { |
| 3132 | int some_failed = 0; |
| 3133 | struct bp_location *loc; |
| 3134 | |
| 3135 | if (!is_hardware_watchpoint (bpt)) |
| 3136 | continue; |
| 3137 | |
| 3138 | if (!breakpoint_enabled (bpt)) |
| 3139 | continue; |
| 3140 | |
| 3141 | if (bpt->disposition == disp_del_at_next_stop) |
| 3142 | continue; |
| 3143 | |
| 3144 | for (loc = bpt->loc; loc; loc = loc->next) |
| 3145 | if (!loc->inserted && should_be_inserted (loc)) |
| 3146 | { |
| 3147 | some_failed = 1; |
| 3148 | break; |
| 3149 | } |
| 3150 | if (some_failed) |
| 3151 | { |
| 3152 | for (loc = bpt->loc; loc; loc = loc->next) |
| 3153 | if (loc->inserted) |
| 3154 | remove_breakpoint (loc, mark_uninserted); |
| 3155 | |
| 3156 | hw_breakpoint_error = 1; |
| 3157 | fprintf_unfiltered (tmp_error_stream, |
| 3158 | "Could not insert hardware watchpoint %d.\n", |
| 3159 | bpt->number); |
| 3160 | error_flag = -1; |
| 3161 | } |
| 3162 | } |
| 3163 | |
| 3164 | if (error_flag) |
| 3165 | { |
| 3166 | /* If a hardware breakpoint or watchpoint was inserted, add a |
| 3167 | message about possibly exhausted resources. */ |
| 3168 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
| 3169 | { |
| 3170 | fprintf_unfiltered (tmp_error_stream, |
| 3171 | "Could not insert hardware breakpoints:\n\ |
| 3172 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
| 3173 | } |
| 3174 | target_terminal_ours_for_output (); |
| 3175 | error_stream (tmp_error_stream); |
| 3176 | } |
| 3177 | |
| 3178 | do_cleanups (cleanups); |
| 3179 | } |
| 3180 | |
| 3181 | /* Used when the program stops. |
| 3182 | Returns zero if successful, or non-zero if there was a problem |
| 3183 | removing a breakpoint location. */ |
| 3184 | |
| 3185 | int |
| 3186 | remove_breakpoints (void) |
| 3187 | { |
| 3188 | struct bp_location *bl, **blp_tmp; |
| 3189 | int val = 0; |
| 3190 | |
| 3191 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3192 | { |
| 3193 | if (bl->inserted && !is_tracepoint (bl->owner)) |
| 3194 | val |= remove_breakpoint (bl, mark_uninserted); |
| 3195 | } |
| 3196 | return val; |
| 3197 | } |
| 3198 | |
| 3199 | /* When a thread exits, remove breakpoints that are related to |
| 3200 | that thread. */ |
| 3201 | |
| 3202 | static void |
| 3203 | remove_threaded_breakpoints (struct thread_info *tp, int silent) |
| 3204 | { |
| 3205 | struct breakpoint *b, *b_tmp; |
| 3206 | |
| 3207 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3208 | { |
| 3209 | if (b->thread == tp->num && user_breakpoint_p (b)) |
| 3210 | { |
| 3211 | b->disposition = disp_del_at_next_stop; |
| 3212 | |
| 3213 | printf_filtered (_("\ |
| 3214 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
| 3215 | b->number, tp->num); |
| 3216 | |
| 3217 | /* Hide it from the user. */ |
| 3218 | b->number = 0; |
| 3219 | } |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | /* Remove breakpoints of process PID. */ |
| 3224 | |
| 3225 | int |
| 3226 | remove_breakpoints_pid (int pid) |
| 3227 | { |
| 3228 | struct bp_location *bl, **blp_tmp; |
| 3229 | int val; |
| 3230 | struct inferior *inf = find_inferior_pid (pid); |
| 3231 | |
| 3232 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3233 | { |
| 3234 | if (bl->pspace != inf->pspace) |
| 3235 | continue; |
| 3236 | |
| 3237 | if (bl->owner->type == bp_dprintf) |
| 3238 | continue; |
| 3239 | |
| 3240 | if (bl->inserted) |
| 3241 | { |
| 3242 | val = remove_breakpoint (bl, mark_uninserted); |
| 3243 | if (val != 0) |
| 3244 | return val; |
| 3245 | } |
| 3246 | } |
| 3247 | return 0; |
| 3248 | } |
| 3249 | |
| 3250 | int |
| 3251 | reattach_breakpoints (int pid) |
| 3252 | { |
| 3253 | struct cleanup *old_chain; |
| 3254 | struct bp_location *bl, **blp_tmp; |
| 3255 | int val; |
| 3256 | struct ui_file *tmp_error_stream; |
| 3257 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
| 3258 | struct inferior *inf; |
| 3259 | struct thread_info *tp; |
| 3260 | |
| 3261 | tp = any_live_thread_of_process (pid); |
| 3262 | if (tp == NULL) |
| 3263 | return 1; |
| 3264 | |
| 3265 | inf = find_inferior_pid (pid); |
| 3266 | old_chain = save_inferior_ptid (); |
| 3267 | |
| 3268 | inferior_ptid = tp->ptid; |
| 3269 | |
| 3270 | tmp_error_stream = mem_fileopen (); |
| 3271 | make_cleanup_ui_file_delete (tmp_error_stream); |
| 3272 | |
| 3273 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3274 | { |
| 3275 | if (bl->pspace != inf->pspace) |
| 3276 | continue; |
| 3277 | |
| 3278 | if (bl->inserted) |
| 3279 | { |
| 3280 | bl->inserted = 0; |
| 3281 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
| 3282 | if (val != 0) |
| 3283 | { |
| 3284 | do_cleanups (old_chain); |
| 3285 | return val; |
| 3286 | } |
| 3287 | } |
| 3288 | } |
| 3289 | do_cleanups (old_chain); |
| 3290 | return 0; |
| 3291 | } |
| 3292 | |
| 3293 | static int internal_breakpoint_number = -1; |
| 3294 | |
| 3295 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
| 3296 | If INTERNAL is non-zero, the breakpoint number will be populated |
| 3297 | from internal_breakpoint_number and that variable decremented. |
| 3298 | Otherwise the breakpoint number will be populated from |
| 3299 | breakpoint_count and that value incremented. Internal breakpoints |
| 3300 | do not set the internal var bpnum. */ |
| 3301 | static void |
| 3302 | set_breakpoint_number (int internal, struct breakpoint *b) |
| 3303 | { |
| 3304 | if (internal) |
| 3305 | b->number = internal_breakpoint_number--; |
| 3306 | else |
| 3307 | { |
| 3308 | set_breakpoint_count (breakpoint_count + 1); |
| 3309 | b->number = breakpoint_count; |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | static struct breakpoint * |
| 3314 | create_internal_breakpoint (struct gdbarch *gdbarch, |
| 3315 | CORE_ADDR address, enum bptype type, |
| 3316 | const struct breakpoint_ops *ops) |
| 3317 | { |
| 3318 | struct symtab_and_line sal; |
| 3319 | struct breakpoint *b; |
| 3320 | |
| 3321 | init_sal (&sal); /* Initialize to zeroes. */ |
| 3322 | |
| 3323 | sal.pc = address; |
| 3324 | sal.section = find_pc_overlay (sal.pc); |
| 3325 | sal.pspace = current_program_space; |
| 3326 | |
| 3327 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
| 3328 | b->number = internal_breakpoint_number--; |
| 3329 | b->disposition = disp_donttouch; |
| 3330 | |
| 3331 | return b; |
| 3332 | } |
| 3333 | |
| 3334 | static const char *const longjmp_names[] = |
| 3335 | { |
| 3336 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" |
| 3337 | }; |
| 3338 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) |
| 3339 | |
| 3340 | /* Per-objfile data private to breakpoint.c. */ |
| 3341 | struct breakpoint_objfile_data |
| 3342 | { |
| 3343 | /* Minimal symbol for "_ovly_debug_event" (if any). */ |
| 3344 | struct bound_minimal_symbol overlay_msym; |
| 3345 | |
| 3346 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ |
| 3347 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
| 3348 | |
| 3349 | /* True if we have looked for longjmp probes. */ |
| 3350 | int longjmp_searched; |
| 3351 | |
| 3352 | /* SystemTap probe points for longjmp (if any). */ |
| 3353 | VEC (probe_p) *longjmp_probes; |
| 3354 | |
| 3355 | /* Minimal symbol for "std::terminate()" (if any). */ |
| 3356 | struct bound_minimal_symbol terminate_msym; |
| 3357 | |
| 3358 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ |
| 3359 | struct bound_minimal_symbol exception_msym; |
| 3360 | |
| 3361 | /* True if we have looked for exception probes. */ |
| 3362 | int exception_searched; |
| 3363 | |
| 3364 | /* SystemTap probe points for unwinding (if any). */ |
| 3365 | VEC (probe_p) *exception_probes; |
| 3366 | }; |
| 3367 | |
| 3368 | static const struct objfile_data *breakpoint_objfile_key; |
| 3369 | |
| 3370 | /* Minimal symbol not found sentinel. */ |
| 3371 | static struct minimal_symbol msym_not_found; |
| 3372 | |
| 3373 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ |
| 3374 | |
| 3375 | static int |
| 3376 | msym_not_found_p (const struct minimal_symbol *msym) |
| 3377 | { |
| 3378 | return msym == &msym_not_found; |
| 3379 | } |
| 3380 | |
| 3381 | /* Return per-objfile data needed by breakpoint.c. |
| 3382 | Allocate the data if necessary. */ |
| 3383 | |
| 3384 | static struct breakpoint_objfile_data * |
| 3385 | get_breakpoint_objfile_data (struct objfile *objfile) |
| 3386 | { |
| 3387 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3388 | |
| 3389 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); |
| 3390 | if (bp_objfile_data == NULL) |
| 3391 | { |
| 3392 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, |
| 3393 | sizeof (*bp_objfile_data)); |
| 3394 | |
| 3395 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); |
| 3396 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); |
| 3397 | } |
| 3398 | return bp_objfile_data; |
| 3399 | } |
| 3400 | |
| 3401 | static void |
| 3402 | free_breakpoint_probes (struct objfile *obj, void *data) |
| 3403 | { |
| 3404 | struct breakpoint_objfile_data *bp_objfile_data = data; |
| 3405 | |
| 3406 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); |
| 3407 | VEC_free (probe_p, bp_objfile_data->exception_probes); |
| 3408 | } |
| 3409 | |
| 3410 | static void |
| 3411 | create_overlay_event_breakpoint (void) |
| 3412 | { |
| 3413 | struct objfile *objfile; |
| 3414 | const char *const func_name = "_ovly_debug_event"; |
| 3415 | |
| 3416 | ALL_OBJFILES (objfile) |
| 3417 | { |
| 3418 | struct breakpoint *b; |
| 3419 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3420 | CORE_ADDR addr; |
| 3421 | |
| 3422 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3423 | |
| 3424 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
| 3425 | continue; |
| 3426 | |
| 3427 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
| 3428 | { |
| 3429 | struct bound_minimal_symbol m; |
| 3430 | |
| 3431 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 3432 | if (m.minsym == NULL) |
| 3433 | { |
| 3434 | /* Avoid future lookups in this objfile. */ |
| 3435 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
| 3436 | continue; |
| 3437 | } |
| 3438 | bp_objfile_data->overlay_msym = m; |
| 3439 | } |
| 3440 | |
| 3441 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
| 3442 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
| 3443 | bp_overlay_event, |
| 3444 | &internal_breakpoint_ops); |
| 3445 | b->addr_string = xstrdup (func_name); |
| 3446 | |
| 3447 | if (overlay_debugging == ovly_auto) |
| 3448 | { |
| 3449 | b->enable_state = bp_enabled; |
| 3450 | overlay_events_enabled = 1; |
| 3451 | } |
| 3452 | else |
| 3453 | { |
| 3454 | b->enable_state = bp_disabled; |
| 3455 | overlay_events_enabled = 0; |
| 3456 | } |
| 3457 | } |
| 3458 | update_global_location_list (UGLL_MAY_INSERT); |
| 3459 | } |
| 3460 | |
| 3461 | static void |
| 3462 | create_longjmp_master_breakpoint (void) |
| 3463 | { |
| 3464 | struct program_space *pspace; |
| 3465 | struct cleanup *old_chain; |
| 3466 | |
| 3467 | old_chain = save_current_program_space (); |
| 3468 | |
| 3469 | ALL_PSPACES (pspace) |
| 3470 | { |
| 3471 | struct objfile *objfile; |
| 3472 | |
| 3473 | set_current_program_space (pspace); |
| 3474 | |
| 3475 | ALL_OBJFILES (objfile) |
| 3476 | { |
| 3477 | int i; |
| 3478 | struct gdbarch *gdbarch; |
| 3479 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3480 | |
| 3481 | gdbarch = get_objfile_arch (objfile); |
| 3482 | |
| 3483 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3484 | |
| 3485 | if (!bp_objfile_data->longjmp_searched) |
| 3486 | { |
| 3487 | VEC (probe_p) *ret; |
| 3488 | |
| 3489 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); |
| 3490 | if (ret != NULL) |
| 3491 | { |
| 3492 | /* We are only interested in checking one element. */ |
| 3493 | struct probe *p = VEC_index (probe_p, ret, 0); |
| 3494 | |
| 3495 | if (!can_evaluate_probe_arguments (p)) |
| 3496 | { |
| 3497 | /* We cannot use the probe interface here, because it does |
| 3498 | not know how to evaluate arguments. */ |
| 3499 | VEC_free (probe_p, ret); |
| 3500 | ret = NULL; |
| 3501 | } |
| 3502 | } |
| 3503 | bp_objfile_data->longjmp_probes = ret; |
| 3504 | bp_objfile_data->longjmp_searched = 1; |
| 3505 | } |
| 3506 | |
| 3507 | if (bp_objfile_data->longjmp_probes != NULL) |
| 3508 | { |
| 3509 | int i; |
| 3510 | struct probe *probe; |
| 3511 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 3512 | |
| 3513 | for (i = 0; |
| 3514 | VEC_iterate (probe_p, |
| 3515 | bp_objfile_data->longjmp_probes, |
| 3516 | i, probe); |
| 3517 | ++i) |
| 3518 | { |
| 3519 | struct breakpoint *b; |
| 3520 | |
| 3521 | b = create_internal_breakpoint (gdbarch, |
| 3522 | get_probe_address (probe, |
| 3523 | objfile), |
| 3524 | bp_longjmp_master, |
| 3525 | &internal_breakpoint_ops); |
| 3526 | b->addr_string = xstrdup ("-probe-stap libc:longjmp"); |
| 3527 | b->enable_state = bp_disabled; |
| 3528 | } |
| 3529 | |
| 3530 | continue; |
| 3531 | } |
| 3532 | |
| 3533 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
| 3534 | continue; |
| 3535 | |
| 3536 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
| 3537 | { |
| 3538 | struct breakpoint *b; |
| 3539 | const char *func_name; |
| 3540 | CORE_ADDR addr; |
| 3541 | |
| 3542 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
| 3543 | continue; |
| 3544 | |
| 3545 | func_name = longjmp_names[i]; |
| 3546 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
| 3547 | { |
| 3548 | struct bound_minimal_symbol m; |
| 3549 | |
| 3550 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 3551 | if (m.minsym == NULL) |
| 3552 | { |
| 3553 | /* Prevent future lookups in this objfile. */ |
| 3554 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
| 3555 | continue; |
| 3556 | } |
| 3557 | bp_objfile_data->longjmp_msym[i] = m; |
| 3558 | } |
| 3559 | |
| 3560 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
| 3561 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
| 3562 | &internal_breakpoint_ops); |
| 3563 | b->addr_string = xstrdup (func_name); |
| 3564 | b->enable_state = bp_disabled; |
| 3565 | } |
| 3566 | } |
| 3567 | } |
| 3568 | update_global_location_list (UGLL_MAY_INSERT); |
| 3569 | |
| 3570 | do_cleanups (old_chain); |
| 3571 | } |
| 3572 | |
| 3573 | /* Create a master std::terminate breakpoint. */ |
| 3574 | static void |
| 3575 | create_std_terminate_master_breakpoint (void) |
| 3576 | { |
| 3577 | struct program_space *pspace; |
| 3578 | struct cleanup *old_chain; |
| 3579 | const char *const func_name = "std::terminate()"; |
| 3580 | |
| 3581 | old_chain = save_current_program_space (); |
| 3582 | |
| 3583 | ALL_PSPACES (pspace) |
| 3584 | { |
| 3585 | struct objfile *objfile; |
| 3586 | CORE_ADDR addr; |
| 3587 | |
| 3588 | set_current_program_space (pspace); |
| 3589 | |
| 3590 | ALL_OBJFILES (objfile) |
| 3591 | { |
| 3592 | struct breakpoint *b; |
| 3593 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3594 | |
| 3595 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3596 | |
| 3597 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
| 3598 | continue; |
| 3599 | |
| 3600 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
| 3601 | { |
| 3602 | struct bound_minimal_symbol m; |
| 3603 | |
| 3604 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
| 3605 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
| 3606 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) |
| 3607 | { |
| 3608 | /* Prevent future lookups in this objfile. */ |
| 3609 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
| 3610 | continue; |
| 3611 | } |
| 3612 | bp_objfile_data->terminate_msym = m; |
| 3613 | } |
| 3614 | |
| 3615 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
| 3616 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
| 3617 | bp_std_terminate_master, |
| 3618 | &internal_breakpoint_ops); |
| 3619 | b->addr_string = xstrdup (func_name); |
| 3620 | b->enable_state = bp_disabled; |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | update_global_location_list (UGLL_MAY_INSERT); |
| 3625 | |
| 3626 | do_cleanups (old_chain); |
| 3627 | } |
| 3628 | |
| 3629 | /* Install a master breakpoint on the unwinder's debug hook. */ |
| 3630 | |
| 3631 | static void |
| 3632 | create_exception_master_breakpoint (void) |
| 3633 | { |
| 3634 | struct objfile *objfile; |
| 3635 | const char *const func_name = "_Unwind_DebugHook"; |
| 3636 | |
| 3637 | ALL_OBJFILES (objfile) |
| 3638 | { |
| 3639 | struct breakpoint *b; |
| 3640 | struct gdbarch *gdbarch; |
| 3641 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3642 | CORE_ADDR addr; |
| 3643 | |
| 3644 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3645 | |
| 3646 | /* We prefer the SystemTap probe point if it exists. */ |
| 3647 | if (!bp_objfile_data->exception_searched) |
| 3648 | { |
| 3649 | VEC (probe_p) *ret; |
| 3650 | |
| 3651 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); |
| 3652 | |
| 3653 | if (ret != NULL) |
| 3654 | { |
| 3655 | /* We are only interested in checking one element. */ |
| 3656 | struct probe *p = VEC_index (probe_p, ret, 0); |
| 3657 | |
| 3658 | if (!can_evaluate_probe_arguments (p)) |
| 3659 | { |
| 3660 | /* We cannot use the probe interface here, because it does |
| 3661 | not know how to evaluate arguments. */ |
| 3662 | VEC_free (probe_p, ret); |
| 3663 | ret = NULL; |
| 3664 | } |
| 3665 | } |
| 3666 | bp_objfile_data->exception_probes = ret; |
| 3667 | bp_objfile_data->exception_searched = 1; |
| 3668 | } |
| 3669 | |
| 3670 | if (bp_objfile_data->exception_probes != NULL) |
| 3671 | { |
| 3672 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 3673 | int i; |
| 3674 | struct probe *probe; |
| 3675 | |
| 3676 | for (i = 0; |
| 3677 | VEC_iterate (probe_p, |
| 3678 | bp_objfile_data->exception_probes, |
| 3679 | i, probe); |
| 3680 | ++i) |
| 3681 | { |
| 3682 | struct breakpoint *b; |
| 3683 | |
| 3684 | b = create_internal_breakpoint (gdbarch, |
| 3685 | get_probe_address (probe, |
| 3686 | objfile), |
| 3687 | bp_exception_master, |
| 3688 | &internal_breakpoint_ops); |
| 3689 | b->addr_string = xstrdup ("-probe-stap libgcc:unwind"); |
| 3690 | b->enable_state = bp_disabled; |
| 3691 | } |
| 3692 | |
| 3693 | continue; |
| 3694 | } |
| 3695 | |
| 3696 | /* Otherwise, try the hook function. */ |
| 3697 | |
| 3698 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
| 3699 | continue; |
| 3700 | |
| 3701 | gdbarch = get_objfile_arch (objfile); |
| 3702 | |
| 3703 | if (bp_objfile_data->exception_msym.minsym == NULL) |
| 3704 | { |
| 3705 | struct bound_minimal_symbol debug_hook; |
| 3706 | |
| 3707 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
| 3708 | if (debug_hook.minsym == NULL) |
| 3709 | { |
| 3710 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
| 3711 | continue; |
| 3712 | } |
| 3713 | |
| 3714 | bp_objfile_data->exception_msym = debug_hook; |
| 3715 | } |
| 3716 | |
| 3717 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
| 3718 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
| 3719 | ¤t_target); |
| 3720 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
| 3721 | &internal_breakpoint_ops); |
| 3722 | b->addr_string = xstrdup (func_name); |
| 3723 | b->enable_state = bp_disabled; |
| 3724 | } |
| 3725 | |
| 3726 | update_global_location_list (UGLL_MAY_INSERT); |
| 3727 | } |
| 3728 | |
| 3729 | void |
| 3730 | update_breakpoints_after_exec (void) |
| 3731 | { |
| 3732 | struct breakpoint *b, *b_tmp; |
| 3733 | struct bp_location *bploc, **bplocp_tmp; |
| 3734 | |
| 3735 | /* We're about to delete breakpoints from GDB's lists. If the |
| 3736 | INSERTED flag is true, GDB will try to lift the breakpoints by |
| 3737 | writing the breakpoints' "shadow contents" back into memory. The |
| 3738 | "shadow contents" are NOT valid after an exec, so GDB should not |
| 3739 | do that. Instead, the target is responsible from marking |
| 3740 | breakpoints out as soon as it detects an exec. We don't do that |
| 3741 | here instead, because there may be other attempts to delete |
| 3742 | breakpoints after detecting an exec and before reaching here. */ |
| 3743 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
| 3744 | if (bploc->pspace == current_program_space) |
| 3745 | gdb_assert (!bploc->inserted); |
| 3746 | |
| 3747 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3748 | { |
| 3749 | if (b->pspace != current_program_space) |
| 3750 | continue; |
| 3751 | |
| 3752 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
| 3753 | if (b->type == bp_shlib_event) |
| 3754 | { |
| 3755 | delete_breakpoint (b); |
| 3756 | continue; |
| 3757 | } |
| 3758 | |
| 3759 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
| 3760 | if (b->type == bp_jit_event) |
| 3761 | { |
| 3762 | delete_breakpoint (b); |
| 3763 | continue; |
| 3764 | } |
| 3765 | |
| 3766 | /* Thread event breakpoints must be set anew after an exec(), |
| 3767 | as must overlay event and longjmp master breakpoints. */ |
| 3768 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
| 3769 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
| 3770 | || b->type == bp_exception_master) |
| 3771 | { |
| 3772 | delete_breakpoint (b); |
| 3773 | continue; |
| 3774 | } |
| 3775 | |
| 3776 | /* Step-resume breakpoints are meaningless after an exec(). */ |
| 3777 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
| 3778 | { |
| 3779 | delete_breakpoint (b); |
| 3780 | continue; |
| 3781 | } |
| 3782 | |
| 3783 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
| 3784 | after an exec. */ |
| 3785 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
| 3786 | || b->type == bp_longjmp_call_dummy |
| 3787 | || b->type == bp_exception || b->type == bp_exception_resume) |
| 3788 | { |
| 3789 | delete_breakpoint (b); |
| 3790 | continue; |
| 3791 | } |
| 3792 | |
| 3793 | if (b->type == bp_catchpoint) |
| 3794 | { |
| 3795 | /* For now, none of the bp_catchpoint breakpoints need to |
| 3796 | do anything at this point. In the future, if some of |
| 3797 | the catchpoints need to something, we will need to add |
| 3798 | a new method, and call this method from here. */ |
| 3799 | continue; |
| 3800 | } |
| 3801 | |
| 3802 | /* bp_finish is a special case. The only way we ought to be able |
| 3803 | to see one of these when an exec() has happened, is if the user |
| 3804 | caught a vfork, and then said "finish". Ordinarily a finish just |
| 3805 | carries them to the call-site of the current callee, by setting |
| 3806 | a temporary bp there and resuming. But in this case, the finish |
| 3807 | will carry them entirely through the vfork & exec. |
| 3808 | |
| 3809 | We don't want to allow a bp_finish to remain inserted now. But |
| 3810 | we can't safely delete it, 'cause finish_command has a handle to |
| 3811 | the bp on a bpstat, and will later want to delete it. There's a |
| 3812 | chance (and I've seen it happen) that if we delete the bp_finish |
| 3813 | here, that its storage will get reused by the time finish_command |
| 3814 | gets 'round to deleting the "use to be a bp_finish" breakpoint. |
| 3815 | We really must allow finish_command to delete a bp_finish. |
| 3816 | |
| 3817 | In the absence of a general solution for the "how do we know |
| 3818 | it's safe to delete something others may have handles to?" |
| 3819 | problem, what we'll do here is just uninsert the bp_finish, and |
| 3820 | let finish_command delete it. |
| 3821 | |
| 3822 | (We know the bp_finish is "doomed" in the sense that it's |
| 3823 | momentary, and will be deleted as soon as finish_command sees |
| 3824 | the inferior stopped. So it doesn't matter that the bp's |
| 3825 | address is probably bogus in the new a.out, unlike e.g., the |
| 3826 | solib breakpoints.) */ |
| 3827 | |
| 3828 | if (b->type == bp_finish) |
| 3829 | { |
| 3830 | continue; |
| 3831 | } |
| 3832 | |
| 3833 | /* Without a symbolic address, we have little hope of the |
| 3834 | pre-exec() address meaning the same thing in the post-exec() |
| 3835 | a.out. */ |
| 3836 | if (b->addr_string == NULL) |
| 3837 | { |
| 3838 | delete_breakpoint (b); |
| 3839 | continue; |
| 3840 | } |
| 3841 | } |
| 3842 | } |
| 3843 | |
| 3844 | int |
| 3845 | detach_breakpoints (ptid_t ptid) |
| 3846 | { |
| 3847 | struct bp_location *bl, **blp_tmp; |
| 3848 | int val = 0; |
| 3849 | struct cleanup *old_chain = save_inferior_ptid (); |
| 3850 | struct inferior *inf = current_inferior (); |
| 3851 | |
| 3852 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
| 3853 | error (_("Cannot detach breakpoints of inferior_ptid")); |
| 3854 | |
| 3855 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
| 3856 | inferior_ptid = ptid; |
| 3857 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3858 | { |
| 3859 | if (bl->pspace != inf->pspace) |
| 3860 | continue; |
| 3861 | |
| 3862 | /* This function must physically remove breakpoints locations |
| 3863 | from the specified ptid, without modifying the breakpoint |
| 3864 | package's state. Locations of type bp_loc_other are only |
| 3865 | maintained at GDB side. So, there is no need to remove |
| 3866 | these bp_loc_other locations. Moreover, removing these |
| 3867 | would modify the breakpoint package's state. */ |
| 3868 | if (bl->loc_type == bp_loc_other) |
| 3869 | continue; |
| 3870 | |
| 3871 | if (bl->inserted) |
| 3872 | val |= remove_breakpoint_1 (bl, mark_inserted); |
| 3873 | } |
| 3874 | |
| 3875 | /* Detach single-step breakpoints as well. */ |
| 3876 | detach_single_step_breakpoints (); |
| 3877 | |
| 3878 | do_cleanups (old_chain); |
| 3879 | return val; |
| 3880 | } |
| 3881 | |
| 3882 | /* Remove the breakpoint location BL from the current address space. |
| 3883 | Note that this is used to detach breakpoints from a child fork. |
| 3884 | When we get here, the child isn't in the inferior list, and neither |
| 3885 | do we have objects to represent its address space --- we should |
| 3886 | *not* look at bl->pspace->aspace here. */ |
| 3887 | |
| 3888 | static int |
| 3889 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
| 3890 | { |
| 3891 | int val; |
| 3892 | |
| 3893 | /* BL is never in moribund_locations by our callers. */ |
| 3894 | gdb_assert (bl->owner != NULL); |
| 3895 | |
| 3896 | if (bl->owner->enable_state == bp_permanent) |
| 3897 | /* Permanent breakpoints cannot be inserted or removed. */ |
| 3898 | return 0; |
| 3899 | |
| 3900 | /* The type of none suggests that owner is actually deleted. |
| 3901 | This should not ever happen. */ |
| 3902 | gdb_assert (bl->owner->type != bp_none); |
| 3903 | |
| 3904 | if (bl->loc_type == bp_loc_software_breakpoint |
| 3905 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 3906 | { |
| 3907 | /* "Normal" instruction breakpoint: either the standard |
| 3908 | trap-instruction bp (bp_breakpoint), or a |
| 3909 | bp_hardware_breakpoint. */ |
| 3910 | |
| 3911 | /* First check to see if we have to handle an overlay. */ |
| 3912 | if (overlay_debugging == ovly_off |
| 3913 | || bl->section == NULL |
| 3914 | || !(section_is_overlay (bl->section))) |
| 3915 | { |
| 3916 | /* No overlay handling: just remove the breakpoint. */ |
| 3917 | |
| 3918 | /* If we're trying to uninsert a memory breakpoint that we |
| 3919 | know is set in a dynamic object that is marked |
| 3920 | shlib_disabled, then either the dynamic object was |
| 3921 | removed with "remove-symbol-file" or with |
| 3922 | "nosharedlibrary". In the former case, we don't know |
| 3923 | whether another dynamic object might have loaded over the |
| 3924 | breakpoint's address -- the user might well let us know |
| 3925 | about it next with add-symbol-file (the whole point of |
| 3926 | add-symbol-file is letting the user manually maintain a |
| 3927 | list of dynamically loaded objects). If we have the |
| 3928 | breakpoint's shadow memory, that is, this is a software |
| 3929 | breakpoint managed by GDB, check whether the breakpoint |
| 3930 | is still inserted in memory, to avoid overwriting wrong |
| 3931 | code with stale saved shadow contents. Note that HW |
| 3932 | breakpoints don't have shadow memory, as they're |
| 3933 | implemented using a mechanism that is not dependent on |
| 3934 | being able to modify the target's memory, and as such |
| 3935 | they should always be removed. */ |
| 3936 | if (bl->shlib_disabled |
| 3937 | && bl->target_info.shadow_len != 0 |
| 3938 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) |
| 3939 | val = 0; |
| 3940 | else |
| 3941 | val = bl->owner->ops->remove_location (bl); |
| 3942 | } |
| 3943 | else |
| 3944 | { |
| 3945 | /* This breakpoint is in an overlay section. |
| 3946 | Did we set a breakpoint at the LMA? */ |
| 3947 | if (!overlay_events_enabled) |
| 3948 | { |
| 3949 | /* Yes -- overlay event support is not active, so we |
| 3950 | should have set a breakpoint at the LMA. Remove it. |
| 3951 | */ |
| 3952 | /* Ignore any failures: if the LMA is in ROM, we will |
| 3953 | have already warned when we failed to insert it. */ |
| 3954 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 3955 | target_remove_hw_breakpoint (bl->gdbarch, |
| 3956 | &bl->overlay_target_info); |
| 3957 | else |
| 3958 | target_remove_breakpoint (bl->gdbarch, |
| 3959 | &bl->overlay_target_info); |
| 3960 | } |
| 3961 | /* Did we set a breakpoint at the VMA? |
| 3962 | If so, we will have marked the breakpoint 'inserted'. */ |
| 3963 | if (bl->inserted) |
| 3964 | { |
| 3965 | /* Yes -- remove it. Previously we did not bother to |
| 3966 | remove the breakpoint if the section had been |
| 3967 | unmapped, but let's not rely on that being safe. We |
| 3968 | don't know what the overlay manager might do. */ |
| 3969 | |
| 3970 | /* However, we should remove *software* breakpoints only |
| 3971 | if the section is still mapped, or else we overwrite |
| 3972 | wrong code with the saved shadow contents. */ |
| 3973 | if (bl->loc_type == bp_loc_hardware_breakpoint |
| 3974 | || section_is_mapped (bl->section)) |
| 3975 | val = bl->owner->ops->remove_location (bl); |
| 3976 | else |
| 3977 | val = 0; |
| 3978 | } |
| 3979 | else |
| 3980 | { |
| 3981 | /* No -- not inserted, so no need to remove. No error. */ |
| 3982 | val = 0; |
| 3983 | } |
| 3984 | } |
| 3985 | |
| 3986 | /* In some cases, we might not be able to remove a breakpoint in |
| 3987 | a shared library that has already been removed, but we have |
| 3988 | not yet processed the shlib unload event. Similarly for an |
| 3989 | unloaded add-symbol-file object - the user might not yet have |
| 3990 | had the chance to remove-symbol-file it. shlib_disabled will |
| 3991 | be set if the library/object has already been removed, but |
| 3992 | the breakpoint hasn't been uninserted yet, e.g., after |
| 3993 | "nosharedlibrary" or "remove-symbol-file" with breakpoints |
| 3994 | always-inserted mode. */ |
| 3995 | if (val |
| 3996 | && (bl->loc_type == bp_loc_software_breakpoint |
| 3997 | && (bl->shlib_disabled |
| 3998 | || solib_name_from_address (bl->pspace, bl->address) |
| 3999 | || shared_objfile_contains_address_p (bl->pspace, |
| 4000 | bl->address)))) |
| 4001 | val = 0; |
| 4002 | |
| 4003 | if (val) |
| 4004 | return val; |
| 4005 | bl->inserted = (is == mark_inserted); |
| 4006 | } |
| 4007 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
| 4008 | { |
| 4009 | gdb_assert (bl->owner->ops != NULL |
| 4010 | && bl->owner->ops->remove_location != NULL); |
| 4011 | |
| 4012 | bl->inserted = (is == mark_inserted); |
| 4013 | bl->owner->ops->remove_location (bl); |
| 4014 | |
| 4015 | /* Failure to remove any of the hardware watchpoints comes here. */ |
| 4016 | if ((is == mark_uninserted) && (bl->inserted)) |
| 4017 | warning (_("Could not remove hardware watchpoint %d."), |
| 4018 | bl->owner->number); |
| 4019 | } |
| 4020 | else if (bl->owner->type == bp_catchpoint |
| 4021 | && breakpoint_enabled (bl->owner) |
| 4022 | && !bl->duplicate) |
| 4023 | { |
| 4024 | gdb_assert (bl->owner->ops != NULL |
| 4025 | && bl->owner->ops->remove_location != NULL); |
| 4026 | |
| 4027 | val = bl->owner->ops->remove_location (bl); |
| 4028 | if (val) |
| 4029 | return val; |
| 4030 | |
| 4031 | bl->inserted = (is == mark_inserted); |
| 4032 | } |
| 4033 | |
| 4034 | return 0; |
| 4035 | } |
| 4036 | |
| 4037 | static int |
| 4038 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
| 4039 | { |
| 4040 | int ret; |
| 4041 | struct cleanup *old_chain; |
| 4042 | |
| 4043 | /* BL is never in moribund_locations by our callers. */ |
| 4044 | gdb_assert (bl->owner != NULL); |
| 4045 | |
| 4046 | if (bl->owner->enable_state == bp_permanent) |
| 4047 | /* Permanent breakpoints cannot be inserted or removed. */ |
| 4048 | return 0; |
| 4049 | |
| 4050 | /* The type of none suggests that owner is actually deleted. |
| 4051 | This should not ever happen. */ |
| 4052 | gdb_assert (bl->owner->type != bp_none); |
| 4053 | |
| 4054 | old_chain = save_current_space_and_thread (); |
| 4055 | |
| 4056 | switch_to_program_space_and_thread (bl->pspace); |
| 4057 | |
| 4058 | ret = remove_breakpoint_1 (bl, is); |
| 4059 | |
| 4060 | do_cleanups (old_chain); |
| 4061 | return ret; |
| 4062 | } |
| 4063 | |
| 4064 | /* Clear the "inserted" flag in all breakpoints. */ |
| 4065 | |
| 4066 | void |
| 4067 | mark_breakpoints_out (void) |
| 4068 | { |
| 4069 | struct bp_location *bl, **blp_tmp; |
| 4070 | |
| 4071 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 4072 | if (bl->pspace == current_program_space) |
| 4073 | bl->inserted = 0; |
| 4074 | } |
| 4075 | |
| 4076 | /* Clear the "inserted" flag in all breakpoints and delete any |
| 4077 | breakpoints which should go away between runs of the program. |
| 4078 | |
| 4079 | Plus other such housekeeping that has to be done for breakpoints |
| 4080 | between runs. |
| 4081 | |
| 4082 | Note: this function gets called at the end of a run (by |
| 4083 | generic_mourn_inferior) and when a run begins (by |
| 4084 | init_wait_for_inferior). */ |
| 4085 | |
| 4086 | |
| 4087 | |
| 4088 | void |
| 4089 | breakpoint_init_inferior (enum inf_context context) |
| 4090 | { |
| 4091 | struct breakpoint *b, *b_tmp; |
| 4092 | struct bp_location *bl, **blp_tmp; |
| 4093 | int ix; |
| 4094 | struct program_space *pspace = current_program_space; |
| 4095 | |
| 4096 | /* If breakpoint locations are shared across processes, then there's |
| 4097 | nothing to do. */ |
| 4098 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
| 4099 | return; |
| 4100 | |
| 4101 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 4102 | { |
| 4103 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
| 4104 | if (bl->pspace == pspace |
| 4105 | && bl->owner->enable_state != bp_permanent) |
| 4106 | bl->inserted = 0; |
| 4107 | } |
| 4108 | |
| 4109 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 4110 | { |
| 4111 | if (b->loc && b->loc->pspace != pspace) |
| 4112 | continue; |
| 4113 | |
| 4114 | switch (b->type) |
| 4115 | { |
| 4116 | case bp_call_dummy: |
| 4117 | case bp_longjmp_call_dummy: |
| 4118 | |
| 4119 | /* If the call dummy breakpoint is at the entry point it will |
| 4120 | cause problems when the inferior is rerun, so we better get |
| 4121 | rid of it. */ |
| 4122 | |
| 4123 | case bp_watchpoint_scope: |
| 4124 | |
| 4125 | /* Also get rid of scope breakpoints. */ |
| 4126 | |
| 4127 | case bp_shlib_event: |
| 4128 | |
| 4129 | /* Also remove solib event breakpoints. Their addresses may |
| 4130 | have changed since the last time we ran the program. |
| 4131 | Actually we may now be debugging against different target; |
| 4132 | and so the solib backend that installed this breakpoint may |
| 4133 | not be used in by the target. E.g., |
| 4134 | |
| 4135 | (gdb) file prog-linux |
| 4136 | (gdb) run # native linux target |
| 4137 | ... |
| 4138 | (gdb) kill |
| 4139 | (gdb) file prog-win.exe |
| 4140 | (gdb) tar rem :9999 # remote Windows gdbserver. |
| 4141 | */ |
| 4142 | |
| 4143 | case bp_step_resume: |
| 4144 | |
| 4145 | /* Also remove step-resume breakpoints. */ |
| 4146 | |
| 4147 | delete_breakpoint (b); |
| 4148 | break; |
| 4149 | |
| 4150 | case bp_watchpoint: |
| 4151 | case bp_hardware_watchpoint: |
| 4152 | case bp_read_watchpoint: |
| 4153 | case bp_access_watchpoint: |
| 4154 | { |
| 4155 | struct watchpoint *w = (struct watchpoint *) b; |
| 4156 | |
| 4157 | /* Likewise for watchpoints on local expressions. */ |
| 4158 | if (w->exp_valid_block != NULL) |
| 4159 | delete_breakpoint (b); |
| 4160 | else if (context == inf_starting) |
| 4161 | { |
| 4162 | /* Reset val field to force reread of starting value in |
| 4163 | insert_breakpoints. */ |
| 4164 | if (w->val) |
| 4165 | value_free (w->val); |
| 4166 | w->val = NULL; |
| 4167 | w->val_valid = 0; |
| 4168 | } |
| 4169 | } |
| 4170 | break; |
| 4171 | default: |
| 4172 | break; |
| 4173 | } |
| 4174 | } |
| 4175 | |
| 4176 | /* Get rid of the moribund locations. */ |
| 4177 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
| 4178 | decref_bp_location (&bl); |
| 4179 | VEC_free (bp_location_p, moribund_locations); |
| 4180 | } |
| 4181 | |
| 4182 | /* These functions concern about actual breakpoints inserted in the |
| 4183 | target --- to e.g. check if we need to do decr_pc adjustment or if |
| 4184 | we need to hop over the bkpt --- so we check for address space |
| 4185 | match, not program space. */ |
| 4186 | |
| 4187 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
| 4188 | exists at PC. It returns ordinary_breakpoint_here if it's an |
| 4189 | ordinary breakpoint, or permanent_breakpoint_here if it's a |
| 4190 | permanent breakpoint. |
| 4191 | - When continuing from a location with an ordinary breakpoint, we |
| 4192 | actually single step once before calling insert_breakpoints. |
| 4193 | - When continuing from a location with a permanent breakpoint, we |
| 4194 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
| 4195 | the target, to advance the PC past the breakpoint. */ |
| 4196 | |
| 4197 | enum breakpoint_here |
| 4198 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 4199 | { |
| 4200 | struct bp_location *bl, **blp_tmp; |
| 4201 | int any_breakpoint_here = 0; |
| 4202 | |
| 4203 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 4204 | { |
| 4205 | if (bl->loc_type != bp_loc_software_breakpoint |
| 4206 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 4207 | continue; |
| 4208 | |
| 4209 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
| 4210 | if ((breakpoint_enabled (bl->owner) |
| 4211 | || bl->owner->enable_state == bp_permanent) |
| 4212 | && breakpoint_location_address_match (bl, aspace, pc)) |
| 4213 | { |
| 4214 | if (overlay_debugging |
| 4215 | && section_is_overlay (bl->section) |
| 4216 | && !section_is_mapped (bl->section)) |
| 4217 | continue; /* unmapped overlay -- can't be a match */ |
| 4218 | else if (bl->owner->enable_state == bp_permanent) |
| 4219 | return permanent_breakpoint_here; |
| 4220 | else |
| 4221 | any_breakpoint_here = 1; |
| 4222 | } |
| 4223 | } |
| 4224 | |
| 4225 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
| 4226 | } |
| 4227 | |
| 4228 | /* Return true if there's a moribund breakpoint at PC. */ |
| 4229 | |
| 4230 | int |
| 4231 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 4232 | { |
| 4233 | struct bp_location *loc; |
| 4234 | int ix; |
| 4235 | |
| 4236 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 4237 | if (breakpoint_location_address_match (loc, aspace, pc)) |
| 4238 | return 1; |
| 4239 | |
| 4240 | return 0; |
| 4241 | } |
| 4242 | |
| 4243 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
| 4244 | inserted using regular breakpoint_chain / bp_location array |
| 4245 | mechanism. This does not check for single-step breakpoints, which |
| 4246 | are inserted and removed using direct target manipulation. */ |
| 4247 | |
| 4248 | int |
| 4249 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
| 4250 | CORE_ADDR pc) |
| 4251 | { |
| 4252 | struct bp_location *bl, **blp_tmp; |
| 4253 | |
| 4254 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 4255 | { |
| 4256 | if (bl->loc_type != bp_loc_software_breakpoint |
| 4257 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 4258 | continue; |
| 4259 | |
| 4260 | if (bl->inserted |
| 4261 | && breakpoint_location_address_match (bl, aspace, pc)) |
| 4262 | { |
| 4263 | if (overlay_debugging |
| 4264 | && section_is_overlay (bl->section) |
| 4265 | && !section_is_mapped (bl->section)) |
| 4266 | continue; /* unmapped overlay -- can't be a match */ |
| 4267 | else |
| 4268 | return 1; |
| 4269 | } |
| 4270 | } |
| 4271 | return 0; |
| 4272 | } |
| 4273 | |
| 4274 | /* Returns non-zero iff there's either regular breakpoint |
| 4275 | or a single step breakpoint inserted at PC. */ |
| 4276 | |
| 4277 | int |
| 4278 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 4279 | { |
| 4280 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
| 4281 | return 1; |
| 4282 | |
| 4283 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
| 4284 | return 1; |
| 4285 | |
| 4286 | return 0; |
| 4287 | } |
| 4288 | |
| 4289 | /* Ignoring deprecated raw breakpoints, return non-zero iff there is a |
| 4290 | software breakpoint inserted at PC. */ |
| 4291 | |
| 4292 | static struct bp_location * |
| 4293 | find_non_raw_software_breakpoint_inserted_here (struct address_space *aspace, |
| 4294 | CORE_ADDR pc) |
| 4295 | { |
| 4296 | struct bp_location *bl, **blp_tmp; |
| 4297 | |
| 4298 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 4299 | { |
| 4300 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 4301 | continue; |
| 4302 | |
| 4303 | if (bl->inserted |
| 4304 | && breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 4305 | aspace, pc)) |
| 4306 | { |
| 4307 | if (overlay_debugging |
| 4308 | && section_is_overlay (bl->section) |
| 4309 | && !section_is_mapped (bl->section)) |
| 4310 | continue; /* unmapped overlay -- can't be a match */ |
| 4311 | else |
| 4312 | return bl; |
| 4313 | } |
| 4314 | } |
| 4315 | |
| 4316 | return NULL; |
| 4317 | } |
| 4318 | |
| 4319 | /* This function returns non-zero iff there is a software breakpoint |
| 4320 | inserted at PC. */ |
| 4321 | |
| 4322 | int |
| 4323 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
| 4324 | CORE_ADDR pc) |
| 4325 | { |
| 4326 | if (find_non_raw_software_breakpoint_inserted_here (aspace, pc) != NULL) |
| 4327 | return 1; |
| 4328 | |
| 4329 | /* Also check for software single-step breakpoints. */ |
| 4330 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
| 4331 | return 1; |
| 4332 | |
| 4333 | return 0; |
| 4334 | } |
| 4335 | |
| 4336 | int |
| 4337 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, |
| 4338 | CORE_ADDR addr, ULONGEST len) |
| 4339 | { |
| 4340 | struct breakpoint *bpt; |
| 4341 | |
| 4342 | ALL_BREAKPOINTS (bpt) |
| 4343 | { |
| 4344 | struct bp_location *loc; |
| 4345 | |
| 4346 | if (bpt->type != bp_hardware_watchpoint |
| 4347 | && bpt->type != bp_access_watchpoint) |
| 4348 | continue; |
| 4349 | |
| 4350 | if (!breakpoint_enabled (bpt)) |
| 4351 | continue; |
| 4352 | |
| 4353 | for (loc = bpt->loc; loc; loc = loc->next) |
| 4354 | if (loc->pspace->aspace == aspace && loc->inserted) |
| 4355 | { |
| 4356 | CORE_ADDR l, h; |
| 4357 | |
| 4358 | /* Check for intersection. */ |
| 4359 | l = max (loc->address, addr); |
| 4360 | h = min (loc->address + loc->length, addr + len); |
| 4361 | if (l < h) |
| 4362 | return 1; |
| 4363 | } |
| 4364 | } |
| 4365 | return 0; |
| 4366 | } |
| 4367 | |
| 4368 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
| 4369 | PC is valid for process/thread PTID. */ |
| 4370 | |
| 4371 | int |
| 4372 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
| 4373 | ptid_t ptid) |
| 4374 | { |
| 4375 | struct bp_location *bl, **blp_tmp; |
| 4376 | /* The thread and task IDs associated to PTID, computed lazily. */ |
| 4377 | int thread = -1; |
| 4378 | int task = 0; |
| 4379 | |
| 4380 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 4381 | { |
| 4382 | if (bl->loc_type != bp_loc_software_breakpoint |
| 4383 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 4384 | continue; |
| 4385 | |
| 4386 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
| 4387 | if (!breakpoint_enabled (bl->owner) |
| 4388 | && bl->owner->enable_state != bp_permanent) |
| 4389 | continue; |
| 4390 | |
| 4391 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
| 4392 | continue; |
| 4393 | |
| 4394 | if (bl->owner->thread != -1) |
| 4395 | { |
| 4396 | /* This is a thread-specific breakpoint. Check that ptid |
| 4397 | matches that thread. If thread hasn't been computed yet, |
| 4398 | it is now time to do so. */ |
| 4399 | if (thread == -1) |
| 4400 | thread = pid_to_thread_id (ptid); |
| 4401 | if (bl->owner->thread != thread) |
| 4402 | continue; |
| 4403 | } |
| 4404 | |
| 4405 | if (bl->owner->task != 0) |
| 4406 | { |
| 4407 | /* This is a task-specific breakpoint. Check that ptid |
| 4408 | matches that task. If task hasn't been computed yet, |
| 4409 | it is now time to do so. */ |
| 4410 | if (task == 0) |
| 4411 | task = ada_get_task_number (ptid); |
| 4412 | if (bl->owner->task != task) |
| 4413 | continue; |
| 4414 | } |
| 4415 | |
| 4416 | if (overlay_debugging |
| 4417 | && section_is_overlay (bl->section) |
| 4418 | && !section_is_mapped (bl->section)) |
| 4419 | continue; /* unmapped overlay -- can't be a match */ |
| 4420 | |
| 4421 | return 1; |
| 4422 | } |
| 4423 | |
| 4424 | return 0; |
| 4425 | } |
| 4426 | \f |
| 4427 | |
| 4428 | /* bpstat stuff. External routines' interfaces are documented |
| 4429 | in breakpoint.h. */ |
| 4430 | |
| 4431 | int |
| 4432 | is_catchpoint (struct breakpoint *ep) |
| 4433 | { |
| 4434 | return (ep->type == bp_catchpoint); |
| 4435 | } |
| 4436 | |
| 4437 | /* Frees any storage that is part of a bpstat. Does not walk the |
| 4438 | 'next' chain. */ |
| 4439 | |
| 4440 | static void |
| 4441 | bpstat_free (bpstat bs) |
| 4442 | { |
| 4443 | if (bs->old_val != NULL) |
| 4444 | value_free (bs->old_val); |
| 4445 | decref_counted_command_line (&bs->commands); |
| 4446 | decref_bp_location (&bs->bp_location_at); |
| 4447 | xfree (bs); |
| 4448 | } |
| 4449 | |
| 4450 | /* Clear a bpstat so that it says we are not at any breakpoint. |
| 4451 | Also free any storage that is part of a bpstat. */ |
| 4452 | |
| 4453 | void |
| 4454 | bpstat_clear (bpstat *bsp) |
| 4455 | { |
| 4456 | bpstat p; |
| 4457 | bpstat q; |
| 4458 | |
| 4459 | if (bsp == 0) |
| 4460 | return; |
| 4461 | p = *bsp; |
| 4462 | while (p != NULL) |
| 4463 | { |
| 4464 | q = p->next; |
| 4465 | bpstat_free (p); |
| 4466 | p = q; |
| 4467 | } |
| 4468 | *bsp = NULL; |
| 4469 | } |
| 4470 | |
| 4471 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
| 4472 | is part of the bpstat is copied as well. */ |
| 4473 | |
| 4474 | bpstat |
| 4475 | bpstat_copy (bpstat bs) |
| 4476 | { |
| 4477 | bpstat p = NULL; |
| 4478 | bpstat tmp; |
| 4479 | bpstat retval = NULL; |
| 4480 | |
| 4481 | if (bs == NULL) |
| 4482 | return bs; |
| 4483 | |
| 4484 | for (; bs != NULL; bs = bs->next) |
| 4485 | { |
| 4486 | tmp = (bpstat) xmalloc (sizeof (*tmp)); |
| 4487 | memcpy (tmp, bs, sizeof (*tmp)); |
| 4488 | incref_counted_command_line (tmp->commands); |
| 4489 | incref_bp_location (tmp->bp_location_at); |
| 4490 | if (bs->old_val != NULL) |
| 4491 | { |
| 4492 | tmp->old_val = value_copy (bs->old_val); |
| 4493 | release_value (tmp->old_val); |
| 4494 | } |
| 4495 | |
| 4496 | if (p == NULL) |
| 4497 | /* This is the first thing in the chain. */ |
| 4498 | retval = tmp; |
| 4499 | else |
| 4500 | p->next = tmp; |
| 4501 | p = tmp; |
| 4502 | } |
| 4503 | p->next = NULL; |
| 4504 | return retval; |
| 4505 | } |
| 4506 | |
| 4507 | /* Find the bpstat associated with this breakpoint. */ |
| 4508 | |
| 4509 | bpstat |
| 4510 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
| 4511 | { |
| 4512 | if (bsp == NULL) |
| 4513 | return NULL; |
| 4514 | |
| 4515 | for (; bsp != NULL; bsp = bsp->next) |
| 4516 | { |
| 4517 | if (bsp->breakpoint_at == breakpoint) |
| 4518 | return bsp; |
| 4519 | } |
| 4520 | return NULL; |
| 4521 | } |
| 4522 | |
| 4523 | /* See breakpoint.h. */ |
| 4524 | |
| 4525 | int |
| 4526 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
| 4527 | { |
| 4528 | for (; bsp != NULL; bsp = bsp->next) |
| 4529 | { |
| 4530 | if (bsp->breakpoint_at == NULL) |
| 4531 | { |
| 4532 | /* A moribund location can never explain a signal other than |
| 4533 | GDB_SIGNAL_TRAP. */ |
| 4534 | if (sig == GDB_SIGNAL_TRAP) |
| 4535 | return 1; |
| 4536 | } |
| 4537 | else |
| 4538 | { |
| 4539 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, |
| 4540 | sig)) |
| 4541 | return 1; |
| 4542 | } |
| 4543 | } |
| 4544 | |
| 4545 | return 0; |
| 4546 | } |
| 4547 | |
| 4548 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
| 4549 | stopped at. *BSP upon return is a bpstat which points to the |
| 4550 | remaining breakpoints stopped at (but which is not guaranteed to be |
| 4551 | good for anything but further calls to bpstat_num). |
| 4552 | |
| 4553 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
| 4554 | Return -1 if stopped at a breakpoint that has been deleted since |
| 4555 | we set it. |
| 4556 | Return 1 otherwise. */ |
| 4557 | |
| 4558 | int |
| 4559 | bpstat_num (bpstat *bsp, int *num) |
| 4560 | { |
| 4561 | struct breakpoint *b; |
| 4562 | |
| 4563 | if ((*bsp) == NULL) |
| 4564 | return 0; /* No more breakpoint values */ |
| 4565 | |
| 4566 | /* We assume we'll never have several bpstats that correspond to a |
| 4567 | single breakpoint -- otherwise, this function might return the |
| 4568 | same number more than once and this will look ugly. */ |
| 4569 | b = (*bsp)->breakpoint_at; |
| 4570 | *bsp = (*bsp)->next; |
| 4571 | if (b == NULL) |
| 4572 | return -1; /* breakpoint that's been deleted since */ |
| 4573 | |
| 4574 | *num = b->number; /* We have its number */ |
| 4575 | return 1; |
| 4576 | } |
| 4577 | |
| 4578 | /* See breakpoint.h. */ |
| 4579 | |
| 4580 | void |
| 4581 | bpstat_clear_actions (void) |
| 4582 | { |
| 4583 | struct thread_info *tp; |
| 4584 | bpstat bs; |
| 4585 | |
| 4586 | if (ptid_equal (inferior_ptid, null_ptid)) |
| 4587 | return; |
| 4588 | |
| 4589 | tp = find_thread_ptid (inferior_ptid); |
| 4590 | if (tp == NULL) |
| 4591 | return; |
| 4592 | |
| 4593 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
| 4594 | { |
| 4595 | decref_counted_command_line (&bs->commands); |
| 4596 | |
| 4597 | if (bs->old_val != NULL) |
| 4598 | { |
| 4599 | value_free (bs->old_val); |
| 4600 | bs->old_val = NULL; |
| 4601 | } |
| 4602 | } |
| 4603 | } |
| 4604 | |
| 4605 | /* Called when a command is about to proceed the inferior. */ |
| 4606 | |
| 4607 | static void |
| 4608 | breakpoint_about_to_proceed (void) |
| 4609 | { |
| 4610 | if (!ptid_equal (inferior_ptid, null_ptid)) |
| 4611 | { |
| 4612 | struct thread_info *tp = inferior_thread (); |
| 4613 | |
| 4614 | /* Allow inferior function calls in breakpoint commands to not |
| 4615 | interrupt the command list. When the call finishes |
| 4616 | successfully, the inferior will be standing at the same |
| 4617 | breakpoint as if nothing happened. */ |
| 4618 | if (tp->control.in_infcall) |
| 4619 | return; |
| 4620 | } |
| 4621 | |
| 4622 | breakpoint_proceeded = 1; |
| 4623 | } |
| 4624 | |
| 4625 | /* Stub for cleaning up our state if we error-out of a breakpoint |
| 4626 | command. */ |
| 4627 | static void |
| 4628 | cleanup_executing_breakpoints (void *ignore) |
| 4629 | { |
| 4630 | executing_breakpoint_commands = 0; |
| 4631 | } |
| 4632 | |
| 4633 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
| 4634 | or its equivalent. */ |
| 4635 | |
| 4636 | static int |
| 4637 | command_line_is_silent (struct command_line *cmd) |
| 4638 | { |
| 4639 | return cmd && (strcmp ("silent", cmd->line) == 0 |
| 4640 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); |
| 4641 | } |
| 4642 | |
| 4643 | /* Execute all the commands associated with all the breakpoints at |
| 4644 | this location. Any of these commands could cause the process to |
| 4645 | proceed beyond this point, etc. We look out for such changes by |
| 4646 | checking the global "breakpoint_proceeded" after each command. |
| 4647 | |
| 4648 | Returns true if a breakpoint command resumed the inferior. In that |
| 4649 | case, it is the caller's responsibility to recall it again with the |
| 4650 | bpstat of the current thread. */ |
| 4651 | |
| 4652 | static int |
| 4653 | bpstat_do_actions_1 (bpstat *bsp) |
| 4654 | { |
| 4655 | bpstat bs; |
| 4656 | struct cleanup *old_chain; |
| 4657 | int again = 0; |
| 4658 | |
| 4659 | /* Avoid endless recursion if a `source' command is contained |
| 4660 | in bs->commands. */ |
| 4661 | if (executing_breakpoint_commands) |
| 4662 | return 0; |
| 4663 | |
| 4664 | executing_breakpoint_commands = 1; |
| 4665 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); |
| 4666 | |
| 4667 | prevent_dont_repeat (); |
| 4668 | |
| 4669 | /* This pointer will iterate over the list of bpstat's. */ |
| 4670 | bs = *bsp; |
| 4671 | |
| 4672 | breakpoint_proceeded = 0; |
| 4673 | for (; bs != NULL; bs = bs->next) |
| 4674 | { |
| 4675 | struct counted_command_line *ccmd; |
| 4676 | struct command_line *cmd; |
| 4677 | struct cleanup *this_cmd_tree_chain; |
| 4678 | |
| 4679 | /* Take ownership of the BSP's command tree, if it has one. |
| 4680 | |
| 4681 | The command tree could legitimately contain commands like |
| 4682 | 'step' and 'next', which call clear_proceed_status, which |
| 4683 | frees stop_bpstat's command tree. To make sure this doesn't |
| 4684 | free the tree we're executing out from under us, we need to |
| 4685 | take ownership of the tree ourselves. Since a given bpstat's |
| 4686 | commands are only executed once, we don't need to copy it; we |
| 4687 | can clear the pointer in the bpstat, and make sure we free |
| 4688 | the tree when we're done. */ |
| 4689 | ccmd = bs->commands; |
| 4690 | bs->commands = NULL; |
| 4691 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
| 4692 | cmd = ccmd ? ccmd->commands : NULL; |
| 4693 | if (command_line_is_silent (cmd)) |
| 4694 | { |
| 4695 | /* The action has been already done by bpstat_stop_status. */ |
| 4696 | cmd = cmd->next; |
| 4697 | } |
| 4698 | |
| 4699 | while (cmd != NULL) |
| 4700 | { |
| 4701 | execute_control_command (cmd); |
| 4702 | |
| 4703 | if (breakpoint_proceeded) |
| 4704 | break; |
| 4705 | else |
| 4706 | cmd = cmd->next; |
| 4707 | } |
| 4708 | |
| 4709 | /* We can free this command tree now. */ |
| 4710 | do_cleanups (this_cmd_tree_chain); |
| 4711 | |
| 4712 | if (breakpoint_proceeded) |
| 4713 | { |
| 4714 | if (target_can_async_p ()) |
| 4715 | /* If we are in async mode, then the target might be still |
| 4716 | running, not stopped at any breakpoint, so nothing for |
| 4717 | us to do here -- just return to the event loop. */ |
| 4718 | ; |
| 4719 | else |
| 4720 | /* In sync mode, when execute_control_command returns |
| 4721 | we're already standing on the next breakpoint. |
| 4722 | Breakpoint commands for that stop were not run, since |
| 4723 | execute_command does not run breakpoint commands -- |
| 4724 | only command_line_handler does, but that one is not |
| 4725 | involved in execution of breakpoint commands. So, we |
| 4726 | can now execute breakpoint commands. It should be |
| 4727 | noted that making execute_command do bpstat actions is |
| 4728 | not an option -- in this case we'll have recursive |
| 4729 | invocation of bpstat for each breakpoint with a |
| 4730 | command, and can easily blow up GDB stack. Instead, we |
| 4731 | return true, which will trigger the caller to recall us |
| 4732 | with the new stop_bpstat. */ |
| 4733 | again = 1; |
| 4734 | break; |
| 4735 | } |
| 4736 | } |
| 4737 | do_cleanups (old_chain); |
| 4738 | return again; |
| 4739 | } |
| 4740 | |
| 4741 | void |
| 4742 | bpstat_do_actions (void) |
| 4743 | { |
| 4744 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
| 4745 | |
| 4746 | /* Do any commands attached to breakpoint we are stopped at. */ |
| 4747 | while (!ptid_equal (inferior_ptid, null_ptid) |
| 4748 | && target_has_execution |
| 4749 | && !is_exited (inferior_ptid) |
| 4750 | && !is_executing (inferior_ptid)) |
| 4751 | /* Since in sync mode, bpstat_do_actions may resume the inferior, |
| 4752 | and only return when it is stopped at the next breakpoint, we |
| 4753 | keep doing breakpoint actions until it returns false to |
| 4754 | indicate the inferior was not resumed. */ |
| 4755 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
| 4756 | break; |
| 4757 | |
| 4758 | discard_cleanups (cleanup_if_error); |
| 4759 | } |
| 4760 | |
| 4761 | /* Print out the (old or new) value associated with a watchpoint. */ |
| 4762 | |
| 4763 | static void |
| 4764 | watchpoint_value_print (struct value *val, struct ui_file *stream) |
| 4765 | { |
| 4766 | if (val == NULL) |
| 4767 | fprintf_unfiltered (stream, _("<unreadable>")); |
| 4768 | else |
| 4769 | { |
| 4770 | struct value_print_options opts; |
| 4771 | get_user_print_options (&opts); |
| 4772 | value_print (val, stream, &opts); |
| 4773 | } |
| 4774 | } |
| 4775 | |
| 4776 | /* Generic routine for printing messages indicating why we |
| 4777 | stopped. The behavior of this function depends on the value |
| 4778 | 'print_it' in the bpstat structure. Under some circumstances we |
| 4779 | may decide not to print anything here and delegate the task to |
| 4780 | normal_stop(). */ |
| 4781 | |
| 4782 | static enum print_stop_action |
| 4783 | print_bp_stop_message (bpstat bs) |
| 4784 | { |
| 4785 | switch (bs->print_it) |
| 4786 | { |
| 4787 | case print_it_noop: |
| 4788 | /* Nothing should be printed for this bpstat entry. */ |
| 4789 | return PRINT_UNKNOWN; |
| 4790 | break; |
| 4791 | |
| 4792 | case print_it_done: |
| 4793 | /* We still want to print the frame, but we already printed the |
| 4794 | relevant messages. */ |
| 4795 | return PRINT_SRC_AND_LOC; |
| 4796 | break; |
| 4797 | |
| 4798 | case print_it_normal: |
| 4799 | { |
| 4800 | struct breakpoint *b = bs->breakpoint_at; |
| 4801 | |
| 4802 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
| 4803 | which has since been deleted. */ |
| 4804 | if (b == NULL) |
| 4805 | return PRINT_UNKNOWN; |
| 4806 | |
| 4807 | /* Normal case. Call the breakpoint's print_it method. */ |
| 4808 | return b->ops->print_it (bs); |
| 4809 | } |
| 4810 | break; |
| 4811 | |
| 4812 | default: |
| 4813 | internal_error (__FILE__, __LINE__, |
| 4814 | _("print_bp_stop_message: unrecognized enum value")); |
| 4815 | break; |
| 4816 | } |
| 4817 | } |
| 4818 | |
| 4819 | /* A helper function that prints a shared library stopped event. */ |
| 4820 | |
| 4821 | static void |
| 4822 | print_solib_event (int is_catchpoint) |
| 4823 | { |
| 4824 | int any_deleted |
| 4825 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); |
| 4826 | int any_added |
| 4827 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); |
| 4828 | |
| 4829 | if (!is_catchpoint) |
| 4830 | { |
| 4831 | if (any_added || any_deleted) |
| 4832 | ui_out_text (current_uiout, |
| 4833 | _("Stopped due to shared library event:\n")); |
| 4834 | else |
| 4835 | ui_out_text (current_uiout, |
| 4836 | _("Stopped due to shared library event (no " |
| 4837 | "libraries added or removed)\n")); |
| 4838 | } |
| 4839 | |
| 4840 | if (ui_out_is_mi_like_p (current_uiout)) |
| 4841 | ui_out_field_string (current_uiout, "reason", |
| 4842 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); |
| 4843 | |
| 4844 | if (any_deleted) |
| 4845 | { |
| 4846 | struct cleanup *cleanup; |
| 4847 | char *name; |
| 4848 | int ix; |
| 4849 | |
| 4850 | ui_out_text (current_uiout, _(" Inferior unloaded ")); |
| 4851 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, |
| 4852 | "removed"); |
| 4853 | for (ix = 0; |
| 4854 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, |
| 4855 | ix, name); |
| 4856 | ++ix) |
| 4857 | { |
| 4858 | if (ix > 0) |
| 4859 | ui_out_text (current_uiout, " "); |
| 4860 | ui_out_field_string (current_uiout, "library", name); |
| 4861 | ui_out_text (current_uiout, "\n"); |
| 4862 | } |
| 4863 | |
| 4864 | do_cleanups (cleanup); |
| 4865 | } |
| 4866 | |
| 4867 | if (any_added) |
| 4868 | { |
| 4869 | struct so_list *iter; |
| 4870 | int ix; |
| 4871 | struct cleanup *cleanup; |
| 4872 | |
| 4873 | ui_out_text (current_uiout, _(" Inferior loaded ")); |
| 4874 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, |
| 4875 | "added"); |
| 4876 | for (ix = 0; |
| 4877 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, |
| 4878 | ix, iter); |
| 4879 | ++ix) |
| 4880 | { |
| 4881 | if (ix > 0) |
| 4882 | ui_out_text (current_uiout, " "); |
| 4883 | ui_out_field_string (current_uiout, "library", iter->so_name); |
| 4884 | ui_out_text (current_uiout, "\n"); |
| 4885 | } |
| 4886 | |
| 4887 | do_cleanups (cleanup); |
| 4888 | } |
| 4889 | } |
| 4890 | |
| 4891 | /* Print a message indicating what happened. This is called from |
| 4892 | normal_stop(). The input to this routine is the head of the bpstat |
| 4893 | list - a list of the eventpoints that caused this stop. KIND is |
| 4894 | the target_waitkind for the stopping event. This |
| 4895 | routine calls the generic print routine for printing a message |
| 4896 | about reasons for stopping. This will print (for example) the |
| 4897 | "Breakpoint n," part of the output. The return value of this |
| 4898 | routine is one of: |
| 4899 | |
| 4900 | PRINT_UNKNOWN: Means we printed nothing. |
| 4901 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
| 4902 | code to print the location. An example is |
| 4903 | "Breakpoint 1, " which should be followed by |
| 4904 | the location. |
| 4905 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
| 4906 | to also print the location part of the message. |
| 4907 | An example is the catch/throw messages, which |
| 4908 | don't require a location appended to the end. |
| 4909 | PRINT_NOTHING: We have done some printing and we don't need any |
| 4910 | further info to be printed. */ |
| 4911 | |
| 4912 | enum print_stop_action |
| 4913 | bpstat_print (bpstat bs, int kind) |
| 4914 | { |
| 4915 | int val; |
| 4916 | |
| 4917 | /* Maybe another breakpoint in the chain caused us to stop. |
| 4918 | (Currently all watchpoints go on the bpstat whether hit or not. |
| 4919 | That probably could (should) be changed, provided care is taken |
| 4920 | with respect to bpstat_explains_signal). */ |
| 4921 | for (; bs; bs = bs->next) |
| 4922 | { |
| 4923 | val = print_bp_stop_message (bs); |
| 4924 | if (val == PRINT_SRC_ONLY |
| 4925 | || val == PRINT_SRC_AND_LOC |
| 4926 | || val == PRINT_NOTHING) |
| 4927 | return val; |
| 4928 | } |
| 4929 | |
| 4930 | /* If we had hit a shared library event breakpoint, |
| 4931 | print_bp_stop_message would print out this message. If we hit an |
| 4932 | OS-level shared library event, do the same thing. */ |
| 4933 | if (kind == TARGET_WAITKIND_LOADED) |
| 4934 | { |
| 4935 | print_solib_event (0); |
| 4936 | return PRINT_NOTHING; |
| 4937 | } |
| 4938 | |
| 4939 | /* We reached the end of the chain, or we got a null BS to start |
| 4940 | with and nothing was printed. */ |
| 4941 | return PRINT_UNKNOWN; |
| 4942 | } |
| 4943 | |
| 4944 | /* Evaluate the expression EXP and return 1 if value is zero. |
| 4945 | This returns the inverse of the condition because it is called |
| 4946 | from catch_errors which returns 0 if an exception happened, and if an |
| 4947 | exception happens we want execution to stop. |
| 4948 | The argument is a "struct expression *" that has been cast to a |
| 4949 | "void *" to make it pass through catch_errors. */ |
| 4950 | |
| 4951 | static int |
| 4952 | breakpoint_cond_eval (void *exp) |
| 4953 | { |
| 4954 | struct value *mark = value_mark (); |
| 4955 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
| 4956 | |
| 4957 | value_free_to_mark (mark); |
| 4958 | return i; |
| 4959 | } |
| 4960 | |
| 4961 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
| 4962 | |
| 4963 | static bpstat |
| 4964 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
| 4965 | { |
| 4966 | bpstat bs; |
| 4967 | |
| 4968 | bs = (bpstat) xmalloc (sizeof (*bs)); |
| 4969 | bs->next = NULL; |
| 4970 | **bs_link_pointer = bs; |
| 4971 | *bs_link_pointer = &bs->next; |
| 4972 | bs->breakpoint_at = bl->owner; |
| 4973 | bs->bp_location_at = bl; |
| 4974 | incref_bp_location (bl); |
| 4975 | /* If the condition is false, etc., don't do the commands. */ |
| 4976 | bs->commands = NULL; |
| 4977 | bs->old_val = NULL; |
| 4978 | bs->print_it = print_it_normal; |
| 4979 | return bs; |
| 4980 | } |
| 4981 | \f |
| 4982 | /* The target has stopped with waitstatus WS. Check if any hardware |
| 4983 | watchpoints have triggered, according to the target. */ |
| 4984 | |
| 4985 | int |
| 4986 | watchpoints_triggered (struct target_waitstatus *ws) |
| 4987 | { |
| 4988 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
| 4989 | CORE_ADDR addr; |
| 4990 | struct breakpoint *b; |
| 4991 | |
| 4992 | if (!stopped_by_watchpoint) |
| 4993 | { |
| 4994 | /* We were not stopped by a watchpoint. Mark all watchpoints |
| 4995 | as not triggered. */ |
| 4996 | ALL_BREAKPOINTS (b) |
| 4997 | if (is_hardware_watchpoint (b)) |
| 4998 | { |
| 4999 | struct watchpoint *w = (struct watchpoint *) b; |
| 5000 | |
| 5001 | w->watchpoint_triggered = watch_triggered_no; |
| 5002 | } |
| 5003 | |
| 5004 | return 0; |
| 5005 | } |
| 5006 | |
| 5007 | if (!target_stopped_data_address (¤t_target, &addr)) |
| 5008 | { |
| 5009 | /* We were stopped by a watchpoint, but we don't know where. |
| 5010 | Mark all watchpoints as unknown. */ |
| 5011 | ALL_BREAKPOINTS (b) |
| 5012 | if (is_hardware_watchpoint (b)) |
| 5013 | { |
| 5014 | struct watchpoint *w = (struct watchpoint *) b; |
| 5015 | |
| 5016 | w->watchpoint_triggered = watch_triggered_unknown; |
| 5017 | } |
| 5018 | |
| 5019 | return 1; |
| 5020 | } |
| 5021 | |
| 5022 | /* The target could report the data address. Mark watchpoints |
| 5023 | affected by this data address as triggered, and all others as not |
| 5024 | triggered. */ |
| 5025 | |
| 5026 | ALL_BREAKPOINTS (b) |
| 5027 | if (is_hardware_watchpoint (b)) |
| 5028 | { |
| 5029 | struct watchpoint *w = (struct watchpoint *) b; |
| 5030 | struct bp_location *loc; |
| 5031 | |
| 5032 | w->watchpoint_triggered = watch_triggered_no; |
| 5033 | for (loc = b->loc; loc; loc = loc->next) |
| 5034 | { |
| 5035 | if (is_masked_watchpoint (b)) |
| 5036 | { |
| 5037 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
| 5038 | CORE_ADDR start = loc->address & w->hw_wp_mask; |
| 5039 | |
| 5040 | if (newaddr == start) |
| 5041 | { |
| 5042 | w->watchpoint_triggered = watch_triggered_yes; |
| 5043 | break; |
| 5044 | } |
| 5045 | } |
| 5046 | /* Exact match not required. Within range is sufficient. */ |
| 5047 | else if (target_watchpoint_addr_within_range (¤t_target, |
| 5048 | addr, loc->address, |
| 5049 | loc->length)) |
| 5050 | { |
| 5051 | w->watchpoint_triggered = watch_triggered_yes; |
| 5052 | break; |
| 5053 | } |
| 5054 | } |
| 5055 | } |
| 5056 | |
| 5057 | return 1; |
| 5058 | } |
| 5059 | |
| 5060 | /* Possible return values for watchpoint_check (this can't be an enum |
| 5061 | because of check_errors). */ |
| 5062 | /* The watchpoint has been deleted. */ |
| 5063 | #define WP_DELETED 1 |
| 5064 | /* The value has changed. */ |
| 5065 | #define WP_VALUE_CHANGED 2 |
| 5066 | /* The value has not changed. */ |
| 5067 | #define WP_VALUE_NOT_CHANGED 3 |
| 5068 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
| 5069 | #define WP_IGNORE 4 |
| 5070 | |
| 5071 | #define BP_TEMPFLAG 1 |
| 5072 | #define BP_HARDWAREFLAG 2 |
| 5073 | |
| 5074 | /* Evaluate watchpoint condition expression and check if its value |
| 5075 | changed. |
| 5076 | |
| 5077 | P should be a pointer to struct bpstat, but is defined as a void * |
| 5078 | in order for this function to be usable with catch_errors. */ |
| 5079 | |
| 5080 | static int |
| 5081 | watchpoint_check (void *p) |
| 5082 | { |
| 5083 | bpstat bs = (bpstat) p; |
| 5084 | struct watchpoint *b; |
| 5085 | struct frame_info *fr; |
| 5086 | int within_current_scope; |
| 5087 | |
| 5088 | /* BS is built from an existing struct breakpoint. */ |
| 5089 | gdb_assert (bs->breakpoint_at != NULL); |
| 5090 | b = (struct watchpoint *) bs->breakpoint_at; |
| 5091 | |
| 5092 | /* If this is a local watchpoint, we only want to check if the |
| 5093 | watchpoint frame is in scope if the current thread is the thread |
| 5094 | that was used to create the watchpoint. */ |
| 5095 | if (!watchpoint_in_thread_scope (b)) |
| 5096 | return WP_IGNORE; |
| 5097 | |
| 5098 | if (b->exp_valid_block == NULL) |
| 5099 | within_current_scope = 1; |
| 5100 | else |
| 5101 | { |
| 5102 | struct frame_info *frame = get_current_frame (); |
| 5103 | struct gdbarch *frame_arch = get_frame_arch (frame); |
| 5104 | CORE_ADDR frame_pc = get_frame_pc (frame); |
| 5105 | |
| 5106 | /* in_function_epilogue_p() returns a non-zero value if we're |
| 5107 | still in the function but the stack frame has already been |
| 5108 | invalidated. Since we can't rely on the values of local |
| 5109 | variables after the stack has been destroyed, we are treating |
| 5110 | the watchpoint in that state as `not changed' without further |
| 5111 | checking. Don't mark watchpoints as changed if the current |
| 5112 | frame is in an epilogue - even if they are in some other |
| 5113 | frame, our view of the stack is likely to be wrong and |
| 5114 | frame_find_by_id could error out. */ |
| 5115 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
| 5116 | return WP_IGNORE; |
| 5117 | |
| 5118 | fr = frame_find_by_id (b->watchpoint_frame); |
| 5119 | within_current_scope = (fr != NULL); |
| 5120 | |
| 5121 | /* If we've gotten confused in the unwinder, we might have |
| 5122 | returned a frame that can't describe this variable. */ |
| 5123 | if (within_current_scope) |
| 5124 | { |
| 5125 | struct symbol *function; |
| 5126 | |
| 5127 | function = get_frame_function (fr); |
| 5128 | if (function == NULL |
| 5129 | || !contained_in (b->exp_valid_block, |
| 5130 | SYMBOL_BLOCK_VALUE (function))) |
| 5131 | within_current_scope = 0; |
| 5132 | } |
| 5133 | |
| 5134 | if (within_current_scope) |
| 5135 | /* If we end up stopping, the current frame will get selected |
| 5136 | in normal_stop. So this call to select_frame won't affect |
| 5137 | the user. */ |
| 5138 | select_frame (fr); |
| 5139 | } |
| 5140 | |
| 5141 | if (within_current_scope) |
| 5142 | { |
| 5143 | /* We use value_{,free_to_}mark because it could be a *long* |
| 5144 | time before we return to the command level and call |
| 5145 | free_all_values. We can't call free_all_values because we |
| 5146 | might be in the middle of evaluating a function call. */ |
| 5147 | |
| 5148 | int pc = 0; |
| 5149 | struct value *mark; |
| 5150 | struct value *new_val; |
| 5151 | |
| 5152 | if (is_masked_watchpoint (&b->base)) |
| 5153 | /* Since we don't know the exact trigger address (from |
| 5154 | stopped_data_address), just tell the user we've triggered |
| 5155 | a mask watchpoint. */ |
| 5156 | return WP_VALUE_CHANGED; |
| 5157 | |
| 5158 | mark = value_mark (); |
| 5159 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
| 5160 | |
| 5161 | if (b->val_bitsize != 0) |
| 5162 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); |
| 5163 | |
| 5164 | /* We use value_equal_contents instead of value_equal because |
| 5165 | the latter coerces an array to a pointer, thus comparing just |
| 5166 | the address of the array instead of its contents. This is |
| 5167 | not what we want. */ |
| 5168 | if ((b->val != NULL) != (new_val != NULL) |
| 5169 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
| 5170 | { |
| 5171 | if (new_val != NULL) |
| 5172 | { |
| 5173 | release_value (new_val); |
| 5174 | value_free_to_mark (mark); |
| 5175 | } |
| 5176 | bs->old_val = b->val; |
| 5177 | b->val = new_val; |
| 5178 | b->val_valid = 1; |
| 5179 | return WP_VALUE_CHANGED; |
| 5180 | } |
| 5181 | else |
| 5182 | { |
| 5183 | /* Nothing changed. */ |
| 5184 | value_free_to_mark (mark); |
| 5185 | return WP_VALUE_NOT_CHANGED; |
| 5186 | } |
| 5187 | } |
| 5188 | else |
| 5189 | { |
| 5190 | struct ui_out *uiout = current_uiout; |
| 5191 | |
| 5192 | /* This seems like the only logical thing to do because |
| 5193 | if we temporarily ignored the watchpoint, then when |
| 5194 | we reenter the block in which it is valid it contains |
| 5195 | garbage (in the case of a function, it may have two |
| 5196 | garbage values, one before and one after the prologue). |
| 5197 | So we can't even detect the first assignment to it and |
| 5198 | watch after that (since the garbage may or may not equal |
| 5199 | the first value assigned). */ |
| 5200 | /* We print all the stop information in |
| 5201 | breakpoint_ops->print_it, but in this case, by the time we |
| 5202 | call breakpoint_ops->print_it this bp will be deleted |
| 5203 | already. So we have no choice but print the information |
| 5204 | here. */ |
| 5205 | if (ui_out_is_mi_like_p (uiout)) |
| 5206 | ui_out_field_string |
| 5207 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); |
| 5208 | ui_out_text (uiout, "\nWatchpoint "); |
| 5209 | ui_out_field_int (uiout, "wpnum", b->base.number); |
| 5210 | ui_out_text (uiout, |
| 5211 | " deleted because the program has left the block in\n\ |
| 5212 | which its expression is valid.\n"); |
| 5213 | |
| 5214 | /* Make sure the watchpoint's commands aren't executed. */ |
| 5215 | decref_counted_command_line (&b->base.commands); |
| 5216 | watchpoint_del_at_next_stop (b); |
| 5217 | |
| 5218 | return WP_DELETED; |
| 5219 | } |
| 5220 | } |
| 5221 | |
| 5222 | /* Return true if it looks like target has stopped due to hitting |
| 5223 | breakpoint location BL. This function does not check if we should |
| 5224 | stop, only if BL explains the stop. */ |
| 5225 | |
| 5226 | static int |
| 5227 | bpstat_check_location (const struct bp_location *bl, |
| 5228 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 5229 | const struct target_waitstatus *ws) |
| 5230 | { |
| 5231 | struct breakpoint *b = bl->owner; |
| 5232 | |
| 5233 | /* BL is from an existing breakpoint. */ |
| 5234 | gdb_assert (b != NULL); |
| 5235 | |
| 5236 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
| 5237 | } |
| 5238 | |
| 5239 | /* Determine if the watched values have actually changed, and we |
| 5240 | should stop. If not, set BS->stop to 0. */ |
| 5241 | |
| 5242 | static void |
| 5243 | bpstat_check_watchpoint (bpstat bs) |
| 5244 | { |
| 5245 | const struct bp_location *bl; |
| 5246 | struct watchpoint *b; |
| 5247 | |
| 5248 | /* BS is built for existing struct breakpoint. */ |
| 5249 | bl = bs->bp_location_at; |
| 5250 | gdb_assert (bl != NULL); |
| 5251 | b = (struct watchpoint *) bs->breakpoint_at; |
| 5252 | gdb_assert (b != NULL); |
| 5253 | |
| 5254 | { |
| 5255 | int must_check_value = 0; |
| 5256 | |
| 5257 | if (b->base.type == bp_watchpoint) |
| 5258 | /* For a software watchpoint, we must always check the |
| 5259 | watched value. */ |
| 5260 | must_check_value = 1; |
| 5261 | else if (b->watchpoint_triggered == watch_triggered_yes) |
| 5262 | /* We have a hardware watchpoint (read, write, or access) |
| 5263 | and the target earlier reported an address watched by |
| 5264 | this watchpoint. */ |
| 5265 | must_check_value = 1; |
| 5266 | else if (b->watchpoint_triggered == watch_triggered_unknown |
| 5267 | && b->base.type == bp_hardware_watchpoint) |
| 5268 | /* We were stopped by a hardware watchpoint, but the target could |
| 5269 | not report the data address. We must check the watchpoint's |
| 5270 | value. Access and read watchpoints are out of luck; without |
| 5271 | a data address, we can't figure it out. */ |
| 5272 | must_check_value = 1; |
| 5273 | |
| 5274 | if (must_check_value) |
| 5275 | { |
| 5276 | char *message |
| 5277 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", |
| 5278 | b->base.number); |
| 5279 | struct cleanup *cleanups = make_cleanup (xfree, message); |
| 5280 | int e = catch_errors (watchpoint_check, bs, message, |
| 5281 | RETURN_MASK_ALL); |
| 5282 | do_cleanups (cleanups); |
| 5283 | switch (e) |
| 5284 | { |
| 5285 | case WP_DELETED: |
| 5286 | /* We've already printed what needs to be printed. */ |
| 5287 | bs->print_it = print_it_done; |
| 5288 | /* Stop. */ |
| 5289 | break; |
| 5290 | case WP_IGNORE: |
| 5291 | bs->print_it = print_it_noop; |
| 5292 | bs->stop = 0; |
| 5293 | break; |
| 5294 | case WP_VALUE_CHANGED: |
| 5295 | if (b->base.type == bp_read_watchpoint) |
| 5296 | { |
| 5297 | /* There are two cases to consider here: |
| 5298 | |
| 5299 | 1. We're watching the triggered memory for reads. |
| 5300 | In that case, trust the target, and always report |
| 5301 | the watchpoint hit to the user. Even though |
| 5302 | reads don't cause value changes, the value may |
| 5303 | have changed since the last time it was read, and |
| 5304 | since we're not trapping writes, we will not see |
| 5305 | those, and as such we should ignore our notion of |
| 5306 | old value. |
| 5307 | |
| 5308 | 2. We're watching the triggered memory for both |
| 5309 | reads and writes. There are two ways this may |
| 5310 | happen: |
| 5311 | |
| 5312 | 2.1. This is a target that can't break on data |
| 5313 | reads only, but can break on accesses (reads or |
| 5314 | writes), such as e.g., x86. We detect this case |
| 5315 | at the time we try to insert read watchpoints. |
| 5316 | |
| 5317 | 2.2. Otherwise, the target supports read |
| 5318 | watchpoints, but, the user set an access or write |
| 5319 | watchpoint watching the same memory as this read |
| 5320 | watchpoint. |
| 5321 | |
| 5322 | If we're watching memory writes as well as reads, |
| 5323 | ignore watchpoint hits when we find that the |
| 5324 | value hasn't changed, as reads don't cause |
| 5325 | changes. This still gives false positives when |
| 5326 | the program writes the same value to memory as |
| 5327 | what there was already in memory (we will confuse |
| 5328 | it for a read), but it's much better than |
| 5329 | nothing. */ |
| 5330 | |
| 5331 | int other_write_watchpoint = 0; |
| 5332 | |
| 5333 | if (bl->watchpoint_type == hw_read) |
| 5334 | { |
| 5335 | struct breakpoint *other_b; |
| 5336 | |
| 5337 | ALL_BREAKPOINTS (other_b) |
| 5338 | if (other_b->type == bp_hardware_watchpoint |
| 5339 | || other_b->type == bp_access_watchpoint) |
| 5340 | { |
| 5341 | struct watchpoint *other_w = |
| 5342 | (struct watchpoint *) other_b; |
| 5343 | |
| 5344 | if (other_w->watchpoint_triggered |
| 5345 | == watch_triggered_yes) |
| 5346 | { |
| 5347 | other_write_watchpoint = 1; |
| 5348 | break; |
| 5349 | } |
| 5350 | } |
| 5351 | } |
| 5352 | |
| 5353 | if (other_write_watchpoint |
| 5354 | || bl->watchpoint_type == hw_access) |
| 5355 | { |
| 5356 | /* We're watching the same memory for writes, |
| 5357 | and the value changed since the last time we |
| 5358 | updated it, so this trap must be for a write. |
| 5359 | Ignore it. */ |
| 5360 | bs->print_it = print_it_noop; |
| 5361 | bs->stop = 0; |
| 5362 | } |
| 5363 | } |
| 5364 | break; |
| 5365 | case WP_VALUE_NOT_CHANGED: |
| 5366 | if (b->base.type == bp_hardware_watchpoint |
| 5367 | || b->base.type == bp_watchpoint) |
| 5368 | { |
| 5369 | /* Don't stop: write watchpoints shouldn't fire if |
| 5370 | the value hasn't changed. */ |
| 5371 | bs->print_it = print_it_noop; |
| 5372 | bs->stop = 0; |
| 5373 | } |
| 5374 | /* Stop. */ |
| 5375 | break; |
| 5376 | default: |
| 5377 | /* Can't happen. */ |
| 5378 | case 0: |
| 5379 | /* Error from catch_errors. */ |
| 5380 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
| 5381 | watchpoint_del_at_next_stop (b); |
| 5382 | /* We've already printed what needs to be printed. */ |
| 5383 | bs->print_it = print_it_done; |
| 5384 | break; |
| 5385 | } |
| 5386 | } |
| 5387 | else /* must_check_value == 0 */ |
| 5388 | { |
| 5389 | /* This is a case where some watchpoint(s) triggered, but |
| 5390 | not at the address of this watchpoint, or else no |
| 5391 | watchpoint triggered after all. So don't print |
| 5392 | anything for this watchpoint. */ |
| 5393 | bs->print_it = print_it_noop; |
| 5394 | bs->stop = 0; |
| 5395 | } |
| 5396 | } |
| 5397 | } |
| 5398 | |
| 5399 | /* For breakpoints that are currently marked as telling gdb to stop, |
| 5400 | check conditions (condition proper, frame, thread and ignore count) |
| 5401 | of breakpoint referred to by BS. If we should not stop for this |
| 5402 | breakpoint, set BS->stop to 0. */ |
| 5403 | |
| 5404 | static void |
| 5405 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) |
| 5406 | { |
| 5407 | const struct bp_location *bl; |
| 5408 | struct breakpoint *b; |
| 5409 | int value_is_zero = 0; |
| 5410 | struct expression *cond; |
| 5411 | |
| 5412 | gdb_assert (bs->stop); |
| 5413 | |
| 5414 | /* BS is built for existing struct breakpoint. */ |
| 5415 | bl = bs->bp_location_at; |
| 5416 | gdb_assert (bl != NULL); |
| 5417 | b = bs->breakpoint_at; |
| 5418 | gdb_assert (b != NULL); |
| 5419 | |
| 5420 | /* Even if the target evaluated the condition on its end and notified GDB, we |
| 5421 | need to do so again since GDB does not know if we stopped due to a |
| 5422 | breakpoint or a single step breakpoint. */ |
| 5423 | |
| 5424 | if (frame_id_p (b->frame_id) |
| 5425 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
| 5426 | { |
| 5427 | bs->stop = 0; |
| 5428 | return; |
| 5429 | } |
| 5430 | |
| 5431 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
| 5432 | evaluating the condition if this isn't the specified |
| 5433 | thread/task. */ |
| 5434 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) |
| 5435 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
| 5436 | |
| 5437 | { |
| 5438 | bs->stop = 0; |
| 5439 | return; |
| 5440 | } |
| 5441 | |
| 5442 | /* Evaluate extension language breakpoints that have a "stop" method |
| 5443 | implemented. */ |
| 5444 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); |
| 5445 | |
| 5446 | if (is_watchpoint (b)) |
| 5447 | { |
| 5448 | struct watchpoint *w = (struct watchpoint *) b; |
| 5449 | |
| 5450 | cond = w->cond_exp; |
| 5451 | } |
| 5452 | else |
| 5453 | cond = bl->cond; |
| 5454 | |
| 5455 | if (cond && b->disposition != disp_del_at_next_stop) |
| 5456 | { |
| 5457 | int within_current_scope = 1; |
| 5458 | struct watchpoint * w; |
| 5459 | |
| 5460 | /* We use value_mark and value_free_to_mark because it could |
| 5461 | be a long time before we return to the command level and |
| 5462 | call free_all_values. We can't call free_all_values |
| 5463 | because we might be in the middle of evaluating a |
| 5464 | function call. */ |
| 5465 | struct value *mark = value_mark (); |
| 5466 | |
| 5467 | if (is_watchpoint (b)) |
| 5468 | w = (struct watchpoint *) b; |
| 5469 | else |
| 5470 | w = NULL; |
| 5471 | |
| 5472 | /* Need to select the frame, with all that implies so that |
| 5473 | the conditions will have the right context. Because we |
| 5474 | use the frame, we will not see an inlined function's |
| 5475 | variables when we arrive at a breakpoint at the start |
| 5476 | of the inlined function; the current frame will be the |
| 5477 | call site. */ |
| 5478 | if (w == NULL || w->cond_exp_valid_block == NULL) |
| 5479 | select_frame (get_current_frame ()); |
| 5480 | else |
| 5481 | { |
| 5482 | struct frame_info *frame; |
| 5483 | |
| 5484 | /* For local watchpoint expressions, which particular |
| 5485 | instance of a local is being watched matters, so we |
| 5486 | keep track of the frame to evaluate the expression |
| 5487 | in. To evaluate the condition however, it doesn't |
| 5488 | really matter which instantiation of the function |
| 5489 | where the condition makes sense triggers the |
| 5490 | watchpoint. This allows an expression like "watch |
| 5491 | global if q > 10" set in `func', catch writes to |
| 5492 | global on all threads that call `func', or catch |
| 5493 | writes on all recursive calls of `func' by a single |
| 5494 | thread. We simply always evaluate the condition in |
| 5495 | the innermost frame that's executing where it makes |
| 5496 | sense to evaluate the condition. It seems |
| 5497 | intuitive. */ |
| 5498 | frame = block_innermost_frame (w->cond_exp_valid_block); |
| 5499 | if (frame != NULL) |
| 5500 | select_frame (frame); |
| 5501 | else |
| 5502 | within_current_scope = 0; |
| 5503 | } |
| 5504 | if (within_current_scope) |
| 5505 | value_is_zero |
| 5506 | = catch_errors (breakpoint_cond_eval, cond, |
| 5507 | "Error in testing breakpoint condition:\n", |
| 5508 | RETURN_MASK_ALL); |
| 5509 | else |
| 5510 | { |
| 5511 | warning (_("Watchpoint condition cannot be tested " |
| 5512 | "in the current scope")); |
| 5513 | /* If we failed to set the right context for this |
| 5514 | watchpoint, unconditionally report it. */ |
| 5515 | value_is_zero = 0; |
| 5516 | } |
| 5517 | /* FIXME-someday, should give breakpoint #. */ |
| 5518 | value_free_to_mark (mark); |
| 5519 | } |
| 5520 | |
| 5521 | if (cond && value_is_zero) |
| 5522 | { |
| 5523 | bs->stop = 0; |
| 5524 | } |
| 5525 | else if (b->ignore_count > 0) |
| 5526 | { |
| 5527 | b->ignore_count--; |
| 5528 | bs->stop = 0; |
| 5529 | /* Increase the hit count even though we don't stop. */ |
| 5530 | ++(b->hit_count); |
| 5531 | observer_notify_breakpoint_modified (b); |
| 5532 | } |
| 5533 | } |
| 5534 | |
| 5535 | |
| 5536 | /* Get a bpstat associated with having just stopped at address |
| 5537 | BP_ADDR in thread PTID. |
| 5538 | |
| 5539 | Determine whether we stopped at a breakpoint, etc, or whether we |
| 5540 | don't understand this stop. Result is a chain of bpstat's such |
| 5541 | that: |
| 5542 | |
| 5543 | if we don't understand the stop, the result is a null pointer. |
| 5544 | |
| 5545 | if we understand why we stopped, the result is not null. |
| 5546 | |
| 5547 | Each element of the chain refers to a particular breakpoint or |
| 5548 | watchpoint at which we have stopped. (We may have stopped for |
| 5549 | several reasons concurrently.) |
| 5550 | |
| 5551 | Each element of the chain has valid next, breakpoint_at, |
| 5552 | commands, FIXME??? fields. */ |
| 5553 | |
| 5554 | bpstat |
| 5555 | bpstat_stop_status (struct address_space *aspace, |
| 5556 | CORE_ADDR bp_addr, ptid_t ptid, |
| 5557 | const struct target_waitstatus *ws) |
| 5558 | { |
| 5559 | struct breakpoint *b = NULL; |
| 5560 | struct bp_location *bl; |
| 5561 | struct bp_location *loc; |
| 5562 | /* First item of allocated bpstat's. */ |
| 5563 | bpstat bs_head = NULL, *bs_link = &bs_head; |
| 5564 | /* Pointer to the last thing in the chain currently. */ |
| 5565 | bpstat bs; |
| 5566 | int ix; |
| 5567 | int need_remove_insert; |
| 5568 | int removed_any; |
| 5569 | |
| 5570 | /* First, build the bpstat chain with locations that explain a |
| 5571 | target stop, while being careful to not set the target running, |
| 5572 | as that may invalidate locations (in particular watchpoint |
| 5573 | locations are recreated). Resuming will happen here with |
| 5574 | breakpoint conditions or watchpoint expressions that include |
| 5575 | inferior function calls. */ |
| 5576 | |
| 5577 | ALL_BREAKPOINTS (b) |
| 5578 | { |
| 5579 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
| 5580 | continue; |
| 5581 | |
| 5582 | for (bl = b->loc; bl != NULL; bl = bl->next) |
| 5583 | { |
| 5584 | /* For hardware watchpoints, we look only at the first |
| 5585 | location. The watchpoint_check function will work on the |
| 5586 | entire expression, not the individual locations. For |
| 5587 | read watchpoints, the watchpoints_triggered function has |
| 5588 | checked all locations already. */ |
| 5589 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
| 5590 | break; |
| 5591 | |
| 5592 | if (!bl->enabled || bl->shlib_disabled) |
| 5593 | continue; |
| 5594 | |
| 5595 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
| 5596 | continue; |
| 5597 | |
| 5598 | /* Come here if it's a watchpoint, or if the break address |
| 5599 | matches. */ |
| 5600 | |
| 5601 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
| 5602 | explain stop. */ |
| 5603 | |
| 5604 | /* Assume we stop. Should we find a watchpoint that is not |
| 5605 | actually triggered, or if the condition of the breakpoint |
| 5606 | evaluates as false, we'll reset 'stop' to 0. */ |
| 5607 | bs->stop = 1; |
| 5608 | bs->print = 1; |
| 5609 | |
| 5610 | /* If this is a scope breakpoint, mark the associated |
| 5611 | watchpoint as triggered so that we will handle the |
| 5612 | out-of-scope event. We'll get to the watchpoint next |
| 5613 | iteration. */ |
| 5614 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
| 5615 | { |
| 5616 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; |
| 5617 | |
| 5618 | w->watchpoint_triggered = watch_triggered_yes; |
| 5619 | } |
| 5620 | } |
| 5621 | } |
| 5622 | |
| 5623 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 5624 | { |
| 5625 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
| 5626 | { |
| 5627 | bs = bpstat_alloc (loc, &bs_link); |
| 5628 | /* For hits of moribund locations, we should just proceed. */ |
| 5629 | bs->stop = 0; |
| 5630 | bs->print = 0; |
| 5631 | bs->print_it = print_it_noop; |
| 5632 | } |
| 5633 | } |
| 5634 | |
| 5635 | /* A bit of special processing for shlib breakpoints. We need to |
| 5636 | process solib loading here, so that the lists of loaded and |
| 5637 | unloaded libraries are correct before we handle "catch load" and |
| 5638 | "catch unload". */ |
| 5639 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5640 | { |
| 5641 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
| 5642 | { |
| 5643 | handle_solib_event (); |
| 5644 | break; |
| 5645 | } |
| 5646 | } |
| 5647 | |
| 5648 | /* Now go through the locations that caused the target to stop, and |
| 5649 | check whether we're interested in reporting this stop to higher |
| 5650 | layers, or whether we should resume the target transparently. */ |
| 5651 | |
| 5652 | removed_any = 0; |
| 5653 | |
| 5654 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5655 | { |
| 5656 | if (!bs->stop) |
| 5657 | continue; |
| 5658 | |
| 5659 | b = bs->breakpoint_at; |
| 5660 | b->ops->check_status (bs); |
| 5661 | if (bs->stop) |
| 5662 | { |
| 5663 | bpstat_check_breakpoint_conditions (bs, ptid); |
| 5664 | |
| 5665 | if (bs->stop) |
| 5666 | { |
| 5667 | ++(b->hit_count); |
| 5668 | observer_notify_breakpoint_modified (b); |
| 5669 | |
| 5670 | /* We will stop here. */ |
| 5671 | if (b->disposition == disp_disable) |
| 5672 | { |
| 5673 | --(b->enable_count); |
| 5674 | if (b->enable_count <= 0 |
| 5675 | && b->enable_state != bp_permanent) |
| 5676 | b->enable_state = bp_disabled; |
| 5677 | removed_any = 1; |
| 5678 | } |
| 5679 | if (b->silent) |
| 5680 | bs->print = 0; |
| 5681 | bs->commands = b->commands; |
| 5682 | incref_counted_command_line (bs->commands); |
| 5683 | if (command_line_is_silent (bs->commands |
| 5684 | ? bs->commands->commands : NULL)) |
| 5685 | bs->print = 0; |
| 5686 | |
| 5687 | b->ops->after_condition_true (bs); |
| 5688 | } |
| 5689 | |
| 5690 | } |
| 5691 | |
| 5692 | /* Print nothing for this entry if we don't stop or don't |
| 5693 | print. */ |
| 5694 | if (!bs->stop || !bs->print) |
| 5695 | bs->print_it = print_it_noop; |
| 5696 | } |
| 5697 | |
| 5698 | /* If we aren't stopping, the value of some hardware watchpoint may |
| 5699 | not have changed, but the intermediate memory locations we are |
| 5700 | watching may have. Don't bother if we're stopping; this will get |
| 5701 | done later. */ |
| 5702 | need_remove_insert = 0; |
| 5703 | if (! bpstat_causes_stop (bs_head)) |
| 5704 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5705 | if (!bs->stop |
| 5706 | && bs->breakpoint_at |
| 5707 | && is_hardware_watchpoint (bs->breakpoint_at)) |
| 5708 | { |
| 5709 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
| 5710 | |
| 5711 | update_watchpoint (w, 0 /* don't reparse. */); |
| 5712 | need_remove_insert = 1; |
| 5713 | } |
| 5714 | |
| 5715 | if (need_remove_insert) |
| 5716 | update_global_location_list (UGLL_MAY_INSERT); |
| 5717 | else if (removed_any) |
| 5718 | update_global_location_list (UGLL_DONT_INSERT); |
| 5719 | |
| 5720 | return bs_head; |
| 5721 | } |
| 5722 | |
| 5723 | static void |
| 5724 | handle_jit_event (void) |
| 5725 | { |
| 5726 | struct frame_info *frame; |
| 5727 | struct gdbarch *gdbarch; |
| 5728 | |
| 5729 | /* Switch terminal for any messages produced by |
| 5730 | breakpoint_re_set. */ |
| 5731 | target_terminal_ours_for_output (); |
| 5732 | |
| 5733 | frame = get_current_frame (); |
| 5734 | gdbarch = get_frame_arch (frame); |
| 5735 | |
| 5736 | jit_event_handler (gdbarch); |
| 5737 | |
| 5738 | target_terminal_inferior (); |
| 5739 | } |
| 5740 | |
| 5741 | /* Prepare WHAT final decision for infrun. */ |
| 5742 | |
| 5743 | /* Decide what infrun needs to do with this bpstat. */ |
| 5744 | |
| 5745 | struct bpstat_what |
| 5746 | bpstat_what (bpstat bs_head) |
| 5747 | { |
| 5748 | struct bpstat_what retval; |
| 5749 | int jit_event = 0; |
| 5750 | bpstat bs; |
| 5751 | |
| 5752 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5753 | retval.call_dummy = STOP_NONE; |
| 5754 | retval.is_longjmp = 0; |
| 5755 | |
| 5756 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5757 | { |
| 5758 | /* Extract this BS's action. After processing each BS, we check |
| 5759 | if its action overrides all we've seem so far. */ |
| 5760 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5761 | enum bptype bptype; |
| 5762 | |
| 5763 | if (bs->breakpoint_at == NULL) |
| 5764 | { |
| 5765 | /* I suspect this can happen if it was a momentary |
| 5766 | breakpoint which has since been deleted. */ |
| 5767 | bptype = bp_none; |
| 5768 | } |
| 5769 | else |
| 5770 | bptype = bs->breakpoint_at->type; |
| 5771 | |
| 5772 | switch (bptype) |
| 5773 | { |
| 5774 | case bp_none: |
| 5775 | break; |
| 5776 | case bp_breakpoint: |
| 5777 | case bp_hardware_breakpoint: |
| 5778 | case bp_until: |
| 5779 | case bp_finish: |
| 5780 | case bp_shlib_event: |
| 5781 | if (bs->stop) |
| 5782 | { |
| 5783 | if (bs->print) |
| 5784 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5785 | else |
| 5786 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5787 | } |
| 5788 | else |
| 5789 | this_action = BPSTAT_WHAT_SINGLE; |
| 5790 | break; |
| 5791 | case bp_watchpoint: |
| 5792 | case bp_hardware_watchpoint: |
| 5793 | case bp_read_watchpoint: |
| 5794 | case bp_access_watchpoint: |
| 5795 | if (bs->stop) |
| 5796 | { |
| 5797 | if (bs->print) |
| 5798 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5799 | else |
| 5800 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5801 | } |
| 5802 | else |
| 5803 | { |
| 5804 | /* There was a watchpoint, but we're not stopping. |
| 5805 | This requires no further action. */ |
| 5806 | } |
| 5807 | break; |
| 5808 | case bp_longjmp: |
| 5809 | case bp_longjmp_call_dummy: |
| 5810 | case bp_exception: |
| 5811 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
| 5812 | retval.is_longjmp = bptype != bp_exception; |
| 5813 | break; |
| 5814 | case bp_longjmp_resume: |
| 5815 | case bp_exception_resume: |
| 5816 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
| 5817 | retval.is_longjmp = bptype == bp_longjmp_resume; |
| 5818 | break; |
| 5819 | case bp_step_resume: |
| 5820 | if (bs->stop) |
| 5821 | this_action = BPSTAT_WHAT_STEP_RESUME; |
| 5822 | else |
| 5823 | { |
| 5824 | /* It is for the wrong frame. */ |
| 5825 | this_action = BPSTAT_WHAT_SINGLE; |
| 5826 | } |
| 5827 | break; |
| 5828 | case bp_hp_step_resume: |
| 5829 | if (bs->stop) |
| 5830 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; |
| 5831 | else |
| 5832 | { |
| 5833 | /* It is for the wrong frame. */ |
| 5834 | this_action = BPSTAT_WHAT_SINGLE; |
| 5835 | } |
| 5836 | break; |
| 5837 | case bp_watchpoint_scope: |
| 5838 | case bp_thread_event: |
| 5839 | case bp_overlay_event: |
| 5840 | case bp_longjmp_master: |
| 5841 | case bp_std_terminate_master: |
| 5842 | case bp_exception_master: |
| 5843 | this_action = BPSTAT_WHAT_SINGLE; |
| 5844 | break; |
| 5845 | case bp_catchpoint: |
| 5846 | if (bs->stop) |
| 5847 | { |
| 5848 | if (bs->print) |
| 5849 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5850 | else |
| 5851 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5852 | } |
| 5853 | else |
| 5854 | { |
| 5855 | /* There was a catchpoint, but we're not stopping. |
| 5856 | This requires no further action. */ |
| 5857 | } |
| 5858 | break; |
| 5859 | case bp_jit_event: |
| 5860 | jit_event = 1; |
| 5861 | this_action = BPSTAT_WHAT_SINGLE; |
| 5862 | break; |
| 5863 | case bp_call_dummy: |
| 5864 | /* Make sure the action is stop (silent or noisy), |
| 5865 | so infrun.c pops the dummy frame. */ |
| 5866 | retval.call_dummy = STOP_STACK_DUMMY; |
| 5867 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5868 | break; |
| 5869 | case bp_std_terminate: |
| 5870 | /* Make sure the action is stop (silent or noisy), |
| 5871 | so infrun.c pops the dummy frame. */ |
| 5872 | retval.call_dummy = STOP_STD_TERMINATE; |
| 5873 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5874 | break; |
| 5875 | case bp_tracepoint: |
| 5876 | case bp_fast_tracepoint: |
| 5877 | case bp_static_tracepoint: |
| 5878 | /* Tracepoint hits should not be reported back to GDB, and |
| 5879 | if one got through somehow, it should have been filtered |
| 5880 | out already. */ |
| 5881 | internal_error (__FILE__, __LINE__, |
| 5882 | _("bpstat_what: tracepoint encountered")); |
| 5883 | break; |
| 5884 | case bp_gnu_ifunc_resolver: |
| 5885 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ |
| 5886 | this_action = BPSTAT_WHAT_SINGLE; |
| 5887 | break; |
| 5888 | case bp_gnu_ifunc_resolver_return: |
| 5889 | /* The breakpoint will be removed, execution will restart from the |
| 5890 | PC of the former breakpoint. */ |
| 5891 | this_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5892 | break; |
| 5893 | |
| 5894 | case bp_dprintf: |
| 5895 | if (bs->stop) |
| 5896 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5897 | else |
| 5898 | this_action = BPSTAT_WHAT_SINGLE; |
| 5899 | break; |
| 5900 | |
| 5901 | default: |
| 5902 | internal_error (__FILE__, __LINE__, |
| 5903 | _("bpstat_what: unhandled bptype %d"), (int) bptype); |
| 5904 | } |
| 5905 | |
| 5906 | retval.main_action = max (retval.main_action, this_action); |
| 5907 | } |
| 5908 | |
| 5909 | /* These operations may affect the bs->breakpoint_at state so they are |
| 5910 | delayed after MAIN_ACTION is decided above. */ |
| 5911 | |
| 5912 | if (jit_event) |
| 5913 | { |
| 5914 | if (debug_infrun) |
| 5915 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); |
| 5916 | |
| 5917 | handle_jit_event (); |
| 5918 | } |
| 5919 | |
| 5920 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5921 | { |
| 5922 | struct breakpoint *b = bs->breakpoint_at; |
| 5923 | |
| 5924 | if (b == NULL) |
| 5925 | continue; |
| 5926 | switch (b->type) |
| 5927 | { |
| 5928 | case bp_gnu_ifunc_resolver: |
| 5929 | gnu_ifunc_resolver_stop (b); |
| 5930 | break; |
| 5931 | case bp_gnu_ifunc_resolver_return: |
| 5932 | gnu_ifunc_resolver_return_stop (b); |
| 5933 | break; |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | return retval; |
| 5938 | } |
| 5939 | |
| 5940 | /* Nonzero if we should step constantly (e.g. watchpoints on machines |
| 5941 | without hardware support). This isn't related to a specific bpstat, |
| 5942 | just to things like whether watchpoints are set. */ |
| 5943 | |
| 5944 | int |
| 5945 | bpstat_should_step (void) |
| 5946 | { |
| 5947 | struct breakpoint *b; |
| 5948 | |
| 5949 | ALL_BREAKPOINTS (b) |
| 5950 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
| 5951 | return 1; |
| 5952 | return 0; |
| 5953 | } |
| 5954 | |
| 5955 | int |
| 5956 | bpstat_causes_stop (bpstat bs) |
| 5957 | { |
| 5958 | for (; bs != NULL; bs = bs->next) |
| 5959 | if (bs->stop) |
| 5960 | return 1; |
| 5961 | |
| 5962 | return 0; |
| 5963 | } |
| 5964 | |
| 5965 | \f |
| 5966 | |
| 5967 | /* Compute a string of spaces suitable to indent the next line |
| 5968 | so it starts at the position corresponding to the table column |
| 5969 | named COL_NAME in the currently active table of UIOUT. */ |
| 5970 | |
| 5971 | static char * |
| 5972 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) |
| 5973 | { |
| 5974 | static char wrap_indent[80]; |
| 5975 | int i, total_width, width, align; |
| 5976 | char *text; |
| 5977 | |
| 5978 | total_width = 0; |
| 5979 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) |
| 5980 | { |
| 5981 | if (strcmp (text, col_name) == 0) |
| 5982 | { |
| 5983 | gdb_assert (total_width < sizeof wrap_indent); |
| 5984 | memset (wrap_indent, ' ', total_width); |
| 5985 | wrap_indent[total_width] = 0; |
| 5986 | |
| 5987 | return wrap_indent; |
| 5988 | } |
| 5989 | |
| 5990 | total_width += width + 1; |
| 5991 | } |
| 5992 | |
| 5993 | return NULL; |
| 5994 | } |
| 5995 | |
| 5996 | /* Determine if the locations of this breakpoint will have their conditions |
| 5997 | evaluated by the target, host or a mix of both. Returns the following: |
| 5998 | |
| 5999 | "host": Host evals condition. |
| 6000 | "host or target": Host or Target evals condition. |
| 6001 | "target": Target evals condition. |
| 6002 | */ |
| 6003 | |
| 6004 | static const char * |
| 6005 | bp_condition_evaluator (struct breakpoint *b) |
| 6006 | { |
| 6007 | struct bp_location *bl; |
| 6008 | char host_evals = 0; |
| 6009 | char target_evals = 0; |
| 6010 | |
| 6011 | if (!b) |
| 6012 | return NULL; |
| 6013 | |
| 6014 | if (!is_breakpoint (b)) |
| 6015 | return NULL; |
| 6016 | |
| 6017 | if (gdb_evaluates_breakpoint_condition_p () |
| 6018 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 6019 | return condition_evaluation_host; |
| 6020 | |
| 6021 | for (bl = b->loc; bl; bl = bl->next) |
| 6022 | { |
| 6023 | if (bl->cond_bytecode) |
| 6024 | target_evals++; |
| 6025 | else |
| 6026 | host_evals++; |
| 6027 | } |
| 6028 | |
| 6029 | if (host_evals && target_evals) |
| 6030 | return condition_evaluation_both; |
| 6031 | else if (target_evals) |
| 6032 | return condition_evaluation_target; |
| 6033 | else |
| 6034 | return condition_evaluation_host; |
| 6035 | } |
| 6036 | |
| 6037 | /* Determine the breakpoint location's condition evaluator. This is |
| 6038 | similar to bp_condition_evaluator, but for locations. */ |
| 6039 | |
| 6040 | static const char * |
| 6041 | bp_location_condition_evaluator (struct bp_location *bl) |
| 6042 | { |
| 6043 | if (bl && !is_breakpoint (bl->owner)) |
| 6044 | return NULL; |
| 6045 | |
| 6046 | if (gdb_evaluates_breakpoint_condition_p () |
| 6047 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 6048 | return condition_evaluation_host; |
| 6049 | |
| 6050 | if (bl && bl->cond_bytecode) |
| 6051 | return condition_evaluation_target; |
| 6052 | else |
| 6053 | return condition_evaluation_host; |
| 6054 | } |
| 6055 | |
| 6056 | /* Print the LOC location out of the list of B->LOC locations. */ |
| 6057 | |
| 6058 | static void |
| 6059 | print_breakpoint_location (struct breakpoint *b, |
| 6060 | struct bp_location *loc) |
| 6061 | { |
| 6062 | struct ui_out *uiout = current_uiout; |
| 6063 | struct cleanup *old_chain = save_current_program_space (); |
| 6064 | |
| 6065 | if (loc != NULL && loc->shlib_disabled) |
| 6066 | loc = NULL; |
| 6067 | |
| 6068 | if (loc != NULL) |
| 6069 | set_current_program_space (loc->pspace); |
| 6070 | |
| 6071 | if (b->display_canonical) |
| 6072 | ui_out_field_string (uiout, "what", b->addr_string); |
| 6073 | else if (loc && loc->symtab) |
| 6074 | { |
| 6075 | struct symbol *sym |
| 6076 | = find_pc_sect_function (loc->address, loc->section); |
| 6077 | if (sym) |
| 6078 | { |
| 6079 | ui_out_text (uiout, "in "); |
| 6080 | ui_out_field_string (uiout, "func", |
| 6081 | SYMBOL_PRINT_NAME (sym)); |
| 6082 | ui_out_text (uiout, " "); |
| 6083 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); |
| 6084 | ui_out_text (uiout, "at "); |
| 6085 | } |
| 6086 | ui_out_field_string (uiout, "file", |
| 6087 | symtab_to_filename_for_display (loc->symtab)); |
| 6088 | ui_out_text (uiout, ":"); |
| 6089 | |
| 6090 | if (ui_out_is_mi_like_p (uiout)) |
| 6091 | ui_out_field_string (uiout, "fullname", |
| 6092 | symtab_to_fullname (loc->symtab)); |
| 6093 | |
| 6094 | ui_out_field_int (uiout, "line", loc->line_number); |
| 6095 | } |
| 6096 | else if (loc) |
| 6097 | { |
| 6098 | struct ui_file *stb = mem_fileopen (); |
| 6099 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); |
| 6100 | |
| 6101 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
| 6102 | demangle, ""); |
| 6103 | ui_out_field_stream (uiout, "at", stb); |
| 6104 | |
| 6105 | do_cleanups (stb_chain); |
| 6106 | } |
| 6107 | else |
| 6108 | ui_out_field_string (uiout, "pending", b->addr_string); |
| 6109 | |
| 6110 | if (loc && is_breakpoint (b) |
| 6111 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target |
| 6112 | && bp_condition_evaluator (b) == condition_evaluation_both) |
| 6113 | { |
| 6114 | ui_out_text (uiout, " ("); |
| 6115 | ui_out_field_string (uiout, "evaluated-by", |
| 6116 | bp_location_condition_evaluator (loc)); |
| 6117 | ui_out_text (uiout, ")"); |
| 6118 | } |
| 6119 | |
| 6120 | do_cleanups (old_chain); |
| 6121 | } |
| 6122 | |
| 6123 | static const char * |
| 6124 | bptype_string (enum bptype type) |
| 6125 | { |
| 6126 | struct ep_type_description |
| 6127 | { |
| 6128 | enum bptype type; |
| 6129 | char *description; |
| 6130 | }; |
| 6131 | static struct ep_type_description bptypes[] = |
| 6132 | { |
| 6133 | {bp_none, "?deleted?"}, |
| 6134 | {bp_breakpoint, "breakpoint"}, |
| 6135 | {bp_hardware_breakpoint, "hw breakpoint"}, |
| 6136 | {bp_until, "until"}, |
| 6137 | {bp_finish, "finish"}, |
| 6138 | {bp_watchpoint, "watchpoint"}, |
| 6139 | {bp_hardware_watchpoint, "hw watchpoint"}, |
| 6140 | {bp_read_watchpoint, "read watchpoint"}, |
| 6141 | {bp_access_watchpoint, "acc watchpoint"}, |
| 6142 | {bp_longjmp, "longjmp"}, |
| 6143 | {bp_longjmp_resume, "longjmp resume"}, |
| 6144 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
| 6145 | {bp_exception, "exception"}, |
| 6146 | {bp_exception_resume, "exception resume"}, |
| 6147 | {bp_step_resume, "step resume"}, |
| 6148 | {bp_hp_step_resume, "high-priority step resume"}, |
| 6149 | {bp_watchpoint_scope, "watchpoint scope"}, |
| 6150 | {bp_call_dummy, "call dummy"}, |
| 6151 | {bp_std_terminate, "std::terminate"}, |
| 6152 | {bp_shlib_event, "shlib events"}, |
| 6153 | {bp_thread_event, "thread events"}, |
| 6154 | {bp_overlay_event, "overlay events"}, |
| 6155 | {bp_longjmp_master, "longjmp master"}, |
| 6156 | {bp_std_terminate_master, "std::terminate master"}, |
| 6157 | {bp_exception_master, "exception master"}, |
| 6158 | {bp_catchpoint, "catchpoint"}, |
| 6159 | {bp_tracepoint, "tracepoint"}, |
| 6160 | {bp_fast_tracepoint, "fast tracepoint"}, |
| 6161 | {bp_static_tracepoint, "static tracepoint"}, |
| 6162 | {bp_dprintf, "dprintf"}, |
| 6163 | {bp_jit_event, "jit events"}, |
| 6164 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
| 6165 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, |
| 6166 | }; |
| 6167 | |
| 6168 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) |
| 6169 | || ((int) type != bptypes[(int) type].type)) |
| 6170 | internal_error (__FILE__, __LINE__, |
| 6171 | _("bptypes table does not describe type #%d."), |
| 6172 | (int) type); |
| 6173 | |
| 6174 | return bptypes[(int) type].description; |
| 6175 | } |
| 6176 | |
| 6177 | /* For MI, output a field named 'thread-groups' with a list as the value. |
| 6178 | For CLI, prefix the list with the string 'inf'. */ |
| 6179 | |
| 6180 | static void |
| 6181 | output_thread_groups (struct ui_out *uiout, |
| 6182 | const char *field_name, |
| 6183 | VEC(int) *inf_num, |
| 6184 | int mi_only) |
| 6185 | { |
| 6186 | struct cleanup *back_to; |
| 6187 | int is_mi = ui_out_is_mi_like_p (uiout); |
| 6188 | int inf; |
| 6189 | int i; |
| 6190 | |
| 6191 | /* For backward compatibility, don't display inferiors in CLI unless |
| 6192 | there are several. Always display them for MI. */ |
| 6193 | if (!is_mi && mi_only) |
| 6194 | return; |
| 6195 | |
| 6196 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
| 6197 | |
| 6198 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
| 6199 | { |
| 6200 | if (is_mi) |
| 6201 | { |
| 6202 | char mi_group[10]; |
| 6203 | |
| 6204 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); |
| 6205 | ui_out_field_string (uiout, NULL, mi_group); |
| 6206 | } |
| 6207 | else |
| 6208 | { |
| 6209 | if (i == 0) |
| 6210 | ui_out_text (uiout, " inf "); |
| 6211 | else |
| 6212 | ui_out_text (uiout, ", "); |
| 6213 | |
| 6214 | ui_out_text (uiout, plongest (inf)); |
| 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | do_cleanups (back_to); |
| 6219 | } |
| 6220 | |
| 6221 | /* Print B to gdb_stdout. */ |
| 6222 | |
| 6223 | static void |
| 6224 | print_one_breakpoint_location (struct breakpoint *b, |
| 6225 | struct bp_location *loc, |
| 6226 | int loc_number, |
| 6227 | struct bp_location **last_loc, |
| 6228 | int allflag) |
| 6229 | { |
| 6230 | struct command_line *l; |
| 6231 | static char bpenables[] = "nynny"; |
| 6232 | |
| 6233 | struct ui_out *uiout = current_uiout; |
| 6234 | int header_of_multiple = 0; |
| 6235 | int part_of_multiple = (loc != NULL); |
| 6236 | struct value_print_options opts; |
| 6237 | |
| 6238 | get_user_print_options (&opts); |
| 6239 | |
| 6240 | gdb_assert (!loc || loc_number != 0); |
| 6241 | /* See comment in print_one_breakpoint concerning treatment of |
| 6242 | breakpoints with single disabled location. */ |
| 6243 | if (loc == NULL |
| 6244 | && (b->loc != NULL |
| 6245 | && (b->loc->next != NULL || !b->loc->enabled))) |
| 6246 | header_of_multiple = 1; |
| 6247 | if (loc == NULL) |
| 6248 | loc = b->loc; |
| 6249 | |
| 6250 | annotate_record (); |
| 6251 | |
| 6252 | /* 1 */ |
| 6253 | annotate_field (0); |
| 6254 | if (part_of_multiple) |
| 6255 | { |
| 6256 | char *formatted; |
| 6257 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
| 6258 | ui_out_field_string (uiout, "number", formatted); |
| 6259 | xfree (formatted); |
| 6260 | } |
| 6261 | else |
| 6262 | { |
| 6263 | ui_out_field_int (uiout, "number", b->number); |
| 6264 | } |
| 6265 | |
| 6266 | /* 2 */ |
| 6267 | annotate_field (1); |
| 6268 | if (part_of_multiple) |
| 6269 | ui_out_field_skip (uiout, "type"); |
| 6270 | else |
| 6271 | ui_out_field_string (uiout, "type", bptype_string (b->type)); |
| 6272 | |
| 6273 | /* 3 */ |
| 6274 | annotate_field (2); |
| 6275 | if (part_of_multiple) |
| 6276 | ui_out_field_skip (uiout, "disp"); |
| 6277 | else |
| 6278 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 6279 | |
| 6280 | |
| 6281 | /* 4 */ |
| 6282 | annotate_field (3); |
| 6283 | if (part_of_multiple) |
| 6284 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
| 6285 | else |
| 6286 | ui_out_field_fmt (uiout, "enabled", "%c", |
| 6287 | bpenables[(int) b->enable_state]); |
| 6288 | ui_out_spaces (uiout, 2); |
| 6289 | |
| 6290 | |
| 6291 | /* 5 and 6 */ |
| 6292 | if (b->ops != NULL && b->ops->print_one != NULL) |
| 6293 | { |
| 6294 | /* Although the print_one can possibly print all locations, |
| 6295 | calling it here is not likely to get any nice result. So, |
| 6296 | make sure there's just one location. */ |
| 6297 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
| 6298 | b->ops->print_one (b, last_loc); |
| 6299 | } |
| 6300 | else |
| 6301 | switch (b->type) |
| 6302 | { |
| 6303 | case bp_none: |
| 6304 | internal_error (__FILE__, __LINE__, |
| 6305 | _("print_one_breakpoint: bp_none encountered\n")); |
| 6306 | break; |
| 6307 | |
| 6308 | case bp_watchpoint: |
| 6309 | case bp_hardware_watchpoint: |
| 6310 | case bp_read_watchpoint: |
| 6311 | case bp_access_watchpoint: |
| 6312 | { |
| 6313 | struct watchpoint *w = (struct watchpoint *) b; |
| 6314 | |
| 6315 | /* Field 4, the address, is omitted (which makes the columns |
| 6316 | not line up too nicely with the headers, but the effect |
| 6317 | is relatively readable). */ |
| 6318 | if (opts.addressprint) |
| 6319 | ui_out_field_skip (uiout, "addr"); |
| 6320 | annotate_field (5); |
| 6321 | ui_out_field_string (uiout, "what", w->exp_string); |
| 6322 | } |
| 6323 | break; |
| 6324 | |
| 6325 | case bp_breakpoint: |
| 6326 | case bp_hardware_breakpoint: |
| 6327 | case bp_until: |
| 6328 | case bp_finish: |
| 6329 | case bp_longjmp: |
| 6330 | case bp_longjmp_resume: |
| 6331 | case bp_longjmp_call_dummy: |
| 6332 | case bp_exception: |
| 6333 | case bp_exception_resume: |
| 6334 | case bp_step_resume: |
| 6335 | case bp_hp_step_resume: |
| 6336 | case bp_watchpoint_scope: |
| 6337 | case bp_call_dummy: |
| 6338 | case bp_std_terminate: |
| 6339 | case bp_shlib_event: |
| 6340 | case bp_thread_event: |
| 6341 | case bp_overlay_event: |
| 6342 | case bp_longjmp_master: |
| 6343 | case bp_std_terminate_master: |
| 6344 | case bp_exception_master: |
| 6345 | case bp_tracepoint: |
| 6346 | case bp_fast_tracepoint: |
| 6347 | case bp_static_tracepoint: |
| 6348 | case bp_dprintf: |
| 6349 | case bp_jit_event: |
| 6350 | case bp_gnu_ifunc_resolver: |
| 6351 | case bp_gnu_ifunc_resolver_return: |
| 6352 | if (opts.addressprint) |
| 6353 | { |
| 6354 | annotate_field (4); |
| 6355 | if (header_of_multiple) |
| 6356 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
| 6357 | else if (b->loc == NULL || loc->shlib_disabled) |
| 6358 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
| 6359 | else |
| 6360 | ui_out_field_core_addr (uiout, "addr", |
| 6361 | loc->gdbarch, loc->address); |
| 6362 | } |
| 6363 | annotate_field (5); |
| 6364 | if (!header_of_multiple) |
| 6365 | print_breakpoint_location (b, loc); |
| 6366 | if (b->loc) |
| 6367 | *last_loc = b->loc; |
| 6368 | break; |
| 6369 | } |
| 6370 | |
| 6371 | |
| 6372 | if (loc != NULL && !header_of_multiple) |
| 6373 | { |
| 6374 | struct inferior *inf; |
| 6375 | VEC(int) *inf_num = NULL; |
| 6376 | int mi_only = 1; |
| 6377 | |
| 6378 | ALL_INFERIORS (inf) |
| 6379 | { |
| 6380 | if (inf->pspace == loc->pspace) |
| 6381 | VEC_safe_push (int, inf_num, inf->num); |
| 6382 | } |
| 6383 | |
| 6384 | /* For backward compatibility, don't display inferiors in CLI unless |
| 6385 | there are several. Always display for MI. */ |
| 6386 | if (allflag |
| 6387 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6388 | && (number_of_program_spaces () > 1 |
| 6389 | || number_of_inferiors () > 1) |
| 6390 | /* LOC is for existing B, it cannot be in |
| 6391 | moribund_locations and thus having NULL OWNER. */ |
| 6392 | && loc->owner->type != bp_catchpoint)) |
| 6393 | mi_only = 0; |
| 6394 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); |
| 6395 | VEC_free (int, inf_num); |
| 6396 | } |
| 6397 | |
| 6398 | if (!part_of_multiple) |
| 6399 | { |
| 6400 | if (b->thread != -1) |
| 6401 | { |
| 6402 | /* FIXME: This seems to be redundant and lost here; see the |
| 6403 | "stop only in" line a little further down. */ |
| 6404 | ui_out_text (uiout, " thread "); |
| 6405 | ui_out_field_int (uiout, "thread", b->thread); |
| 6406 | } |
| 6407 | else if (b->task != 0) |
| 6408 | { |
| 6409 | ui_out_text (uiout, " task "); |
| 6410 | ui_out_field_int (uiout, "task", b->task); |
| 6411 | } |
| 6412 | } |
| 6413 | |
| 6414 | ui_out_text (uiout, "\n"); |
| 6415 | |
| 6416 | if (!part_of_multiple) |
| 6417 | b->ops->print_one_detail (b, uiout); |
| 6418 | |
| 6419 | if (part_of_multiple && frame_id_p (b->frame_id)) |
| 6420 | { |
| 6421 | annotate_field (6); |
| 6422 | ui_out_text (uiout, "\tstop only in stack frame at "); |
| 6423 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
| 6424 | the frame ID. */ |
| 6425 | ui_out_field_core_addr (uiout, "frame", |
| 6426 | b->gdbarch, b->frame_id.stack_addr); |
| 6427 | ui_out_text (uiout, "\n"); |
| 6428 | } |
| 6429 | |
| 6430 | if (!part_of_multiple && b->cond_string) |
| 6431 | { |
| 6432 | annotate_field (7); |
| 6433 | if (is_tracepoint (b)) |
| 6434 | ui_out_text (uiout, "\ttrace only if "); |
| 6435 | else |
| 6436 | ui_out_text (uiout, "\tstop only if "); |
| 6437 | ui_out_field_string (uiout, "cond", b->cond_string); |
| 6438 | |
| 6439 | /* Print whether the target is doing the breakpoint's condition |
| 6440 | evaluation. If GDB is doing the evaluation, don't print anything. */ |
| 6441 | if (is_breakpoint (b) |
| 6442 | && breakpoint_condition_evaluation_mode () |
| 6443 | == condition_evaluation_target) |
| 6444 | { |
| 6445 | ui_out_text (uiout, " ("); |
| 6446 | ui_out_field_string (uiout, "evaluated-by", |
| 6447 | bp_condition_evaluator (b)); |
| 6448 | ui_out_text (uiout, " evals)"); |
| 6449 | } |
| 6450 | ui_out_text (uiout, "\n"); |
| 6451 | } |
| 6452 | |
| 6453 | if (!part_of_multiple && b->thread != -1) |
| 6454 | { |
| 6455 | /* FIXME should make an annotation for this. */ |
| 6456 | ui_out_text (uiout, "\tstop only in thread "); |
| 6457 | ui_out_field_int (uiout, "thread", b->thread); |
| 6458 | ui_out_text (uiout, "\n"); |
| 6459 | } |
| 6460 | |
| 6461 | if (!part_of_multiple) |
| 6462 | { |
| 6463 | if (b->hit_count) |
| 6464 | { |
| 6465 | /* FIXME should make an annotation for this. */ |
| 6466 | if (is_catchpoint (b)) |
| 6467 | ui_out_text (uiout, "\tcatchpoint"); |
| 6468 | else if (is_tracepoint (b)) |
| 6469 | ui_out_text (uiout, "\ttracepoint"); |
| 6470 | else |
| 6471 | ui_out_text (uiout, "\tbreakpoint"); |
| 6472 | ui_out_text (uiout, " already hit "); |
| 6473 | ui_out_field_int (uiout, "times", b->hit_count); |
| 6474 | if (b->hit_count == 1) |
| 6475 | ui_out_text (uiout, " time\n"); |
| 6476 | else |
| 6477 | ui_out_text (uiout, " times\n"); |
| 6478 | } |
| 6479 | else |
| 6480 | { |
| 6481 | /* Output the count also if it is zero, but only if this is mi. */ |
| 6482 | if (ui_out_is_mi_like_p (uiout)) |
| 6483 | ui_out_field_int (uiout, "times", b->hit_count); |
| 6484 | } |
| 6485 | } |
| 6486 | |
| 6487 | if (!part_of_multiple && b->ignore_count) |
| 6488 | { |
| 6489 | annotate_field (8); |
| 6490 | ui_out_text (uiout, "\tignore next "); |
| 6491 | ui_out_field_int (uiout, "ignore", b->ignore_count); |
| 6492 | ui_out_text (uiout, " hits\n"); |
| 6493 | } |
| 6494 | |
| 6495 | /* Note that an enable count of 1 corresponds to "enable once" |
| 6496 | behavior, which is reported by the combination of enablement and |
| 6497 | disposition, so we don't need to mention it here. */ |
| 6498 | if (!part_of_multiple && b->enable_count > 1) |
| 6499 | { |
| 6500 | annotate_field (8); |
| 6501 | ui_out_text (uiout, "\tdisable after "); |
| 6502 | /* Tweak the wording to clarify that ignore and enable counts |
| 6503 | are distinct, and have additive effect. */ |
| 6504 | if (b->ignore_count) |
| 6505 | ui_out_text (uiout, "additional "); |
| 6506 | else |
| 6507 | ui_out_text (uiout, "next "); |
| 6508 | ui_out_field_int (uiout, "enable", b->enable_count); |
| 6509 | ui_out_text (uiout, " hits\n"); |
| 6510 | } |
| 6511 | |
| 6512 | if (!part_of_multiple && is_tracepoint (b)) |
| 6513 | { |
| 6514 | struct tracepoint *tp = (struct tracepoint *) b; |
| 6515 | |
| 6516 | if (tp->traceframe_usage) |
| 6517 | { |
| 6518 | ui_out_text (uiout, "\ttrace buffer usage "); |
| 6519 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); |
| 6520 | ui_out_text (uiout, " bytes\n"); |
| 6521 | } |
| 6522 | } |
| 6523 | |
| 6524 | l = b->commands ? b->commands->commands : NULL; |
| 6525 | if (!part_of_multiple && l) |
| 6526 | { |
| 6527 | struct cleanup *script_chain; |
| 6528 | |
| 6529 | annotate_field (9); |
| 6530 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
| 6531 | print_command_lines (uiout, l, 4); |
| 6532 | do_cleanups (script_chain); |
| 6533 | } |
| 6534 | |
| 6535 | if (is_tracepoint (b)) |
| 6536 | { |
| 6537 | struct tracepoint *t = (struct tracepoint *) b; |
| 6538 | |
| 6539 | if (!part_of_multiple && t->pass_count) |
| 6540 | { |
| 6541 | annotate_field (10); |
| 6542 | ui_out_text (uiout, "\tpass count "); |
| 6543 | ui_out_field_int (uiout, "pass", t->pass_count); |
| 6544 | ui_out_text (uiout, " \n"); |
| 6545 | } |
| 6546 | |
| 6547 | /* Don't display it when tracepoint or tracepoint location is |
| 6548 | pending. */ |
| 6549 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) |
| 6550 | { |
| 6551 | annotate_field (11); |
| 6552 | |
| 6553 | if (ui_out_is_mi_like_p (uiout)) |
| 6554 | ui_out_field_string (uiout, "installed", |
| 6555 | loc->inserted ? "y" : "n"); |
| 6556 | else |
| 6557 | { |
| 6558 | if (loc->inserted) |
| 6559 | ui_out_text (uiout, "\t"); |
| 6560 | else |
| 6561 | ui_out_text (uiout, "\tnot "); |
| 6562 | ui_out_text (uiout, "installed on target\n"); |
| 6563 | } |
| 6564 | } |
| 6565 | } |
| 6566 | |
| 6567 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
| 6568 | { |
| 6569 | if (is_watchpoint (b)) |
| 6570 | { |
| 6571 | struct watchpoint *w = (struct watchpoint *) b; |
| 6572 | |
| 6573 | ui_out_field_string (uiout, "original-location", w->exp_string); |
| 6574 | } |
| 6575 | else if (b->addr_string) |
| 6576 | ui_out_field_string (uiout, "original-location", b->addr_string); |
| 6577 | } |
| 6578 | } |
| 6579 | |
| 6580 | static void |
| 6581 | print_one_breakpoint (struct breakpoint *b, |
| 6582 | struct bp_location **last_loc, |
| 6583 | int allflag) |
| 6584 | { |
| 6585 | struct cleanup *bkpt_chain; |
| 6586 | struct ui_out *uiout = current_uiout; |
| 6587 | |
| 6588 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
| 6589 | |
| 6590 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
| 6591 | do_cleanups (bkpt_chain); |
| 6592 | |
| 6593 | /* If this breakpoint has custom print function, |
| 6594 | it's already printed. Otherwise, print individual |
| 6595 | locations, if any. */ |
| 6596 | if (b->ops == NULL || b->ops->print_one == NULL) |
| 6597 | { |
| 6598 | /* If breakpoint has a single location that is disabled, we |
| 6599 | print it as if it had several locations, since otherwise it's |
| 6600 | hard to represent "breakpoint enabled, location disabled" |
| 6601 | situation. |
| 6602 | |
| 6603 | Note that while hardware watchpoints have several locations |
| 6604 | internally, that's not a property exposed to user. */ |
| 6605 | if (b->loc |
| 6606 | && !is_hardware_watchpoint (b) |
| 6607 | && (b->loc->next || !b->loc->enabled)) |
| 6608 | { |
| 6609 | struct bp_location *loc; |
| 6610 | int n = 1; |
| 6611 | |
| 6612 | for (loc = b->loc; loc; loc = loc->next, ++n) |
| 6613 | { |
| 6614 | struct cleanup *inner2 = |
| 6615 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); |
| 6616 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
| 6617 | do_cleanups (inner2); |
| 6618 | } |
| 6619 | } |
| 6620 | } |
| 6621 | } |
| 6622 | |
| 6623 | static int |
| 6624 | breakpoint_address_bits (struct breakpoint *b) |
| 6625 | { |
| 6626 | int print_address_bits = 0; |
| 6627 | struct bp_location *loc; |
| 6628 | |
| 6629 | for (loc = b->loc; loc; loc = loc->next) |
| 6630 | { |
| 6631 | int addr_bit; |
| 6632 | |
| 6633 | /* Software watchpoints that aren't watching memory don't have |
| 6634 | an address to print. */ |
| 6635 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) |
| 6636 | continue; |
| 6637 | |
| 6638 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
| 6639 | if (addr_bit > print_address_bits) |
| 6640 | print_address_bits = addr_bit; |
| 6641 | } |
| 6642 | |
| 6643 | return print_address_bits; |
| 6644 | } |
| 6645 | |
| 6646 | struct captured_breakpoint_query_args |
| 6647 | { |
| 6648 | int bnum; |
| 6649 | }; |
| 6650 | |
| 6651 | static int |
| 6652 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
| 6653 | { |
| 6654 | struct captured_breakpoint_query_args *args = data; |
| 6655 | struct breakpoint *b; |
| 6656 | struct bp_location *dummy_loc = NULL; |
| 6657 | |
| 6658 | ALL_BREAKPOINTS (b) |
| 6659 | { |
| 6660 | if (args->bnum == b->number) |
| 6661 | { |
| 6662 | print_one_breakpoint (b, &dummy_loc, 0); |
| 6663 | return GDB_RC_OK; |
| 6664 | } |
| 6665 | } |
| 6666 | return GDB_RC_NONE; |
| 6667 | } |
| 6668 | |
| 6669 | enum gdb_rc |
| 6670 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
| 6671 | char **error_message) |
| 6672 | { |
| 6673 | struct captured_breakpoint_query_args args; |
| 6674 | |
| 6675 | args.bnum = bnum; |
| 6676 | /* For the moment we don't trust print_one_breakpoint() to not throw |
| 6677 | an error. */ |
| 6678 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
| 6679 | error_message, RETURN_MASK_ALL) < 0) |
| 6680 | return GDB_RC_FAIL; |
| 6681 | else |
| 6682 | return GDB_RC_OK; |
| 6683 | } |
| 6684 | |
| 6685 | /* Return true if this breakpoint was set by the user, false if it is |
| 6686 | internal or momentary. */ |
| 6687 | |
| 6688 | int |
| 6689 | user_breakpoint_p (struct breakpoint *b) |
| 6690 | { |
| 6691 | return b->number > 0; |
| 6692 | } |
| 6693 | |
| 6694 | /* Print information on user settable breakpoint (watchpoint, etc) |
| 6695 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
| 6696 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If |
| 6697 | FILTER is non-NULL, call it on each breakpoint and only include the |
| 6698 | ones for which it returns non-zero. Return the total number of |
| 6699 | breakpoints listed. */ |
| 6700 | |
| 6701 | static int |
| 6702 | breakpoint_1 (char *args, int allflag, |
| 6703 | int (*filter) (const struct breakpoint *)) |
| 6704 | { |
| 6705 | struct breakpoint *b; |
| 6706 | struct bp_location *last_loc = NULL; |
| 6707 | int nr_printable_breakpoints; |
| 6708 | struct cleanup *bkpttbl_chain; |
| 6709 | struct value_print_options opts; |
| 6710 | int print_address_bits = 0; |
| 6711 | int print_type_col_width = 14; |
| 6712 | struct ui_out *uiout = current_uiout; |
| 6713 | |
| 6714 | get_user_print_options (&opts); |
| 6715 | |
| 6716 | /* Compute the number of rows in the table, as well as the size |
| 6717 | required for address fields. */ |
| 6718 | nr_printable_breakpoints = 0; |
| 6719 | ALL_BREAKPOINTS (b) |
| 6720 | { |
| 6721 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 6722 | if (filter && !filter (b)) |
| 6723 | continue; |
| 6724 | |
| 6725 | /* If we have an "args" string, it is a list of breakpoints to |
| 6726 | accept. Skip the others. */ |
| 6727 | if (args != NULL && *args != '\0') |
| 6728 | { |
| 6729 | if (allflag && parse_and_eval_long (args) != b->number) |
| 6730 | continue; |
| 6731 | if (!allflag && !number_is_in_list (args, b->number)) |
| 6732 | continue; |
| 6733 | } |
| 6734 | |
| 6735 | if (allflag || user_breakpoint_p (b)) |
| 6736 | { |
| 6737 | int addr_bit, type_len; |
| 6738 | |
| 6739 | addr_bit = breakpoint_address_bits (b); |
| 6740 | if (addr_bit > print_address_bits) |
| 6741 | print_address_bits = addr_bit; |
| 6742 | |
| 6743 | type_len = strlen (bptype_string (b->type)); |
| 6744 | if (type_len > print_type_col_width) |
| 6745 | print_type_col_width = type_len; |
| 6746 | |
| 6747 | nr_printable_breakpoints++; |
| 6748 | } |
| 6749 | } |
| 6750 | |
| 6751 | if (opts.addressprint) |
| 6752 | bkpttbl_chain |
| 6753 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
| 6754 | nr_printable_breakpoints, |
| 6755 | "BreakpointTable"); |
| 6756 | else |
| 6757 | bkpttbl_chain |
| 6758 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
| 6759 | nr_printable_breakpoints, |
| 6760 | "BreakpointTable"); |
| 6761 | |
| 6762 | if (nr_printable_breakpoints > 0) |
| 6763 | annotate_breakpoints_headers (); |
| 6764 | if (nr_printable_breakpoints > 0) |
| 6765 | annotate_field (0); |
| 6766 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
| 6767 | if (nr_printable_breakpoints > 0) |
| 6768 | annotate_field (1); |
| 6769 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
| 6770 | "type", "Type"); /* 2 */ |
| 6771 | if (nr_printable_breakpoints > 0) |
| 6772 | annotate_field (2); |
| 6773 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
| 6774 | if (nr_printable_breakpoints > 0) |
| 6775 | annotate_field (3); |
| 6776 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
| 6777 | if (opts.addressprint) |
| 6778 | { |
| 6779 | if (nr_printable_breakpoints > 0) |
| 6780 | annotate_field (4); |
| 6781 | if (print_address_bits <= 32) |
| 6782 | ui_out_table_header (uiout, 10, ui_left, |
| 6783 | "addr", "Address"); /* 5 */ |
| 6784 | else |
| 6785 | ui_out_table_header (uiout, 18, ui_left, |
| 6786 | "addr", "Address"); /* 5 */ |
| 6787 | } |
| 6788 | if (nr_printable_breakpoints > 0) |
| 6789 | annotate_field (5); |
| 6790 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ |
| 6791 | ui_out_table_body (uiout); |
| 6792 | if (nr_printable_breakpoints > 0) |
| 6793 | annotate_breakpoints_table (); |
| 6794 | |
| 6795 | ALL_BREAKPOINTS (b) |
| 6796 | { |
| 6797 | QUIT; |
| 6798 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 6799 | if (filter && !filter (b)) |
| 6800 | continue; |
| 6801 | |
| 6802 | /* If we have an "args" string, it is a list of breakpoints to |
| 6803 | accept. Skip the others. */ |
| 6804 | |
| 6805 | if (args != NULL && *args != '\0') |
| 6806 | { |
| 6807 | if (allflag) /* maintenance info breakpoint */ |
| 6808 | { |
| 6809 | if (parse_and_eval_long (args) != b->number) |
| 6810 | continue; |
| 6811 | } |
| 6812 | else /* all others */ |
| 6813 | { |
| 6814 | if (!number_is_in_list (args, b->number)) |
| 6815 | continue; |
| 6816 | } |
| 6817 | } |
| 6818 | /* We only print out user settable breakpoints unless the |
| 6819 | allflag is set. */ |
| 6820 | if (allflag || user_breakpoint_p (b)) |
| 6821 | print_one_breakpoint (b, &last_loc, allflag); |
| 6822 | } |
| 6823 | |
| 6824 | do_cleanups (bkpttbl_chain); |
| 6825 | |
| 6826 | if (nr_printable_breakpoints == 0) |
| 6827 | { |
| 6828 | /* If there's a filter, let the caller decide how to report |
| 6829 | empty list. */ |
| 6830 | if (!filter) |
| 6831 | { |
| 6832 | if (args == NULL || *args == '\0') |
| 6833 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
| 6834 | else |
| 6835 | ui_out_message (uiout, 0, |
| 6836 | "No breakpoint or watchpoint matching '%s'.\n", |
| 6837 | args); |
| 6838 | } |
| 6839 | } |
| 6840 | else |
| 6841 | { |
| 6842 | if (last_loc && !server_command) |
| 6843 | set_next_address (last_loc->gdbarch, last_loc->address); |
| 6844 | } |
| 6845 | |
| 6846 | /* FIXME? Should this be moved up so that it is only called when |
| 6847 | there have been breakpoints? */ |
| 6848 | annotate_breakpoints_table_end (); |
| 6849 | |
| 6850 | return nr_printable_breakpoints; |
| 6851 | } |
| 6852 | |
| 6853 | /* Display the value of default-collect in a way that is generally |
| 6854 | compatible with the breakpoint list. */ |
| 6855 | |
| 6856 | static void |
| 6857 | default_collect_info (void) |
| 6858 | { |
| 6859 | struct ui_out *uiout = current_uiout; |
| 6860 | |
| 6861 | /* If it has no value (which is frequently the case), say nothing; a |
| 6862 | message like "No default-collect." gets in user's face when it's |
| 6863 | not wanted. */ |
| 6864 | if (!*default_collect) |
| 6865 | return; |
| 6866 | |
| 6867 | /* The following phrase lines up nicely with per-tracepoint collect |
| 6868 | actions. */ |
| 6869 | ui_out_text (uiout, "default collect "); |
| 6870 | ui_out_field_string (uiout, "default-collect", default_collect); |
| 6871 | ui_out_text (uiout, " \n"); |
| 6872 | } |
| 6873 | |
| 6874 | static void |
| 6875 | breakpoints_info (char *args, int from_tty) |
| 6876 | { |
| 6877 | breakpoint_1 (args, 0, NULL); |
| 6878 | |
| 6879 | default_collect_info (); |
| 6880 | } |
| 6881 | |
| 6882 | static void |
| 6883 | watchpoints_info (char *args, int from_tty) |
| 6884 | { |
| 6885 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
| 6886 | struct ui_out *uiout = current_uiout; |
| 6887 | |
| 6888 | if (num_printed == 0) |
| 6889 | { |
| 6890 | if (args == NULL || *args == '\0') |
| 6891 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
| 6892 | else |
| 6893 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
| 6894 | } |
| 6895 | } |
| 6896 | |
| 6897 | static void |
| 6898 | maintenance_info_breakpoints (char *args, int from_tty) |
| 6899 | { |
| 6900 | breakpoint_1 (args, 1, NULL); |
| 6901 | |
| 6902 | default_collect_info (); |
| 6903 | } |
| 6904 | |
| 6905 | static int |
| 6906 | breakpoint_has_pc (struct breakpoint *b, |
| 6907 | struct program_space *pspace, |
| 6908 | CORE_ADDR pc, struct obj_section *section) |
| 6909 | { |
| 6910 | struct bp_location *bl = b->loc; |
| 6911 | |
| 6912 | for (; bl; bl = bl->next) |
| 6913 | { |
| 6914 | if (bl->pspace == pspace |
| 6915 | && bl->address == pc |
| 6916 | && (!overlay_debugging || bl->section == section)) |
| 6917 | return 1; |
| 6918 | } |
| 6919 | return 0; |
| 6920 | } |
| 6921 | |
| 6922 | /* Print a message describing any user-breakpoints set at PC. This |
| 6923 | concerns with logical breakpoints, so we match program spaces, not |
| 6924 | address spaces. */ |
| 6925 | |
| 6926 | static void |
| 6927 | describe_other_breakpoints (struct gdbarch *gdbarch, |
| 6928 | struct program_space *pspace, CORE_ADDR pc, |
| 6929 | struct obj_section *section, int thread) |
| 6930 | { |
| 6931 | int others = 0; |
| 6932 | struct breakpoint *b; |
| 6933 | |
| 6934 | ALL_BREAKPOINTS (b) |
| 6935 | others += (user_breakpoint_p (b) |
| 6936 | && breakpoint_has_pc (b, pspace, pc, section)); |
| 6937 | if (others > 0) |
| 6938 | { |
| 6939 | if (others == 1) |
| 6940 | printf_filtered (_("Note: breakpoint ")); |
| 6941 | else /* if (others == ???) */ |
| 6942 | printf_filtered (_("Note: breakpoints ")); |
| 6943 | ALL_BREAKPOINTS (b) |
| 6944 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
| 6945 | { |
| 6946 | others--; |
| 6947 | printf_filtered ("%d", b->number); |
| 6948 | if (b->thread == -1 && thread != -1) |
| 6949 | printf_filtered (" (all threads)"); |
| 6950 | else if (b->thread != -1) |
| 6951 | printf_filtered (" (thread %d)", b->thread); |
| 6952 | printf_filtered ("%s%s ", |
| 6953 | ((b->enable_state == bp_disabled |
| 6954 | || b->enable_state == bp_call_disabled) |
| 6955 | ? " (disabled)" |
| 6956 | : b->enable_state == bp_permanent |
| 6957 | ? " (permanent)" |
| 6958 | : ""), |
| 6959 | (others > 1) ? "," |
| 6960 | : ((others == 1) ? " and" : "")); |
| 6961 | } |
| 6962 | printf_filtered (_("also set at pc ")); |
| 6963 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
| 6964 | printf_filtered (".\n"); |
| 6965 | } |
| 6966 | } |
| 6967 | \f |
| 6968 | |
| 6969 | /* Return true iff it is meaningful to use the address member of |
| 6970 | BPT. For some breakpoint types, the address member is irrelevant |
| 6971 | and it makes no sense to attempt to compare it to other addresses |
| 6972 | (or use it for any other purpose either). |
| 6973 | |
| 6974 | More specifically, each of the following breakpoint types will |
| 6975 | always have a zero valued address and we don't want to mark |
| 6976 | breakpoints of any of these types to be a duplicate of an actual |
| 6977 | breakpoint at address zero: |
| 6978 | |
| 6979 | bp_watchpoint |
| 6980 | bp_catchpoint |
| 6981 | |
| 6982 | */ |
| 6983 | |
| 6984 | static int |
| 6985 | breakpoint_address_is_meaningful (struct breakpoint *bpt) |
| 6986 | { |
| 6987 | enum bptype type = bpt->type; |
| 6988 | |
| 6989 | return (type != bp_watchpoint && type != bp_catchpoint); |
| 6990 | } |
| 6991 | |
| 6992 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns |
| 6993 | true if LOC1 and LOC2 represent the same watchpoint location. */ |
| 6994 | |
| 6995 | static int |
| 6996 | watchpoint_locations_match (struct bp_location *loc1, |
| 6997 | struct bp_location *loc2) |
| 6998 | { |
| 6999 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
| 7000 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; |
| 7001 | |
| 7002 | /* Both of them must exist. */ |
| 7003 | gdb_assert (w1 != NULL); |
| 7004 | gdb_assert (w2 != NULL); |
| 7005 | |
| 7006 | /* If the target can evaluate the condition expression in hardware, |
| 7007 | then we we need to insert both watchpoints even if they are at |
| 7008 | the same place. Otherwise the watchpoint will only trigger when |
| 7009 | the condition of whichever watchpoint was inserted evaluates to |
| 7010 | true, not giving a chance for GDB to check the condition of the |
| 7011 | other watchpoint. */ |
| 7012 | if ((w1->cond_exp |
| 7013 | && target_can_accel_watchpoint_condition (loc1->address, |
| 7014 | loc1->length, |
| 7015 | loc1->watchpoint_type, |
| 7016 | w1->cond_exp)) |
| 7017 | || (w2->cond_exp |
| 7018 | && target_can_accel_watchpoint_condition (loc2->address, |
| 7019 | loc2->length, |
| 7020 | loc2->watchpoint_type, |
| 7021 | w2->cond_exp))) |
| 7022 | return 0; |
| 7023 | |
| 7024 | /* Note that this checks the owner's type, not the location's. In |
| 7025 | case the target does not support read watchpoints, but does |
| 7026 | support access watchpoints, we'll have bp_read_watchpoint |
| 7027 | watchpoints with hw_access locations. Those should be considered |
| 7028 | duplicates of hw_read locations. The hw_read locations will |
| 7029 | become hw_access locations later. */ |
| 7030 | return (loc1->owner->type == loc2->owner->type |
| 7031 | && loc1->pspace->aspace == loc2->pspace->aspace |
| 7032 | && loc1->address == loc2->address |
| 7033 | && loc1->length == loc2->length); |
| 7034 | } |
| 7035 | |
| 7036 | /* See breakpoint.h. */ |
| 7037 | |
| 7038 | int |
| 7039 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
| 7040 | struct address_space *aspace2, CORE_ADDR addr2) |
| 7041 | { |
| 7042 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 7043 | || aspace1 == aspace2) |
| 7044 | && addr1 == addr2); |
| 7045 | } |
| 7046 | |
| 7047 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
| 7048 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 |
| 7049 | matches ASPACE2. On targets that have global breakpoints, the address |
| 7050 | space doesn't really matter. */ |
| 7051 | |
| 7052 | static int |
| 7053 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, |
| 7054 | int len1, struct address_space *aspace2, |
| 7055 | CORE_ADDR addr2) |
| 7056 | { |
| 7057 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 7058 | || aspace1 == aspace2) |
| 7059 | && addr2 >= addr1 && addr2 < addr1 + len1); |
| 7060 | } |
| 7061 | |
| 7062 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be |
| 7063 | a ranged breakpoint. In most targets, a match happens only if ASPACE |
| 7064 | matches the breakpoint's address space. On targets that have global |
| 7065 | breakpoints, the address space doesn't really matter. */ |
| 7066 | |
| 7067 | static int |
| 7068 | breakpoint_location_address_match (struct bp_location *bl, |
| 7069 | struct address_space *aspace, |
| 7070 | CORE_ADDR addr) |
| 7071 | { |
| 7072 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 7073 | aspace, addr) |
| 7074 | || (bl->length |
| 7075 | && breakpoint_address_match_range (bl->pspace->aspace, |
| 7076 | bl->address, bl->length, |
| 7077 | aspace, addr))); |
| 7078 | } |
| 7079 | |
| 7080 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
| 7081 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns |
| 7082 | true, otherwise returns false. */ |
| 7083 | |
| 7084 | static int |
| 7085 | tracepoint_locations_match (struct bp_location *loc1, |
| 7086 | struct bp_location *loc2) |
| 7087 | { |
| 7088 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) |
| 7089 | /* Since tracepoint locations are never duplicated with others', tracepoint |
| 7090 | locations at the same address of different tracepoints are regarded as |
| 7091 | different locations. */ |
| 7092 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); |
| 7093 | else |
| 7094 | return 0; |
| 7095 | } |
| 7096 | |
| 7097 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
| 7098 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 |
| 7099 | represent the same location. */ |
| 7100 | |
| 7101 | static int |
| 7102 | breakpoint_locations_match (struct bp_location *loc1, |
| 7103 | struct bp_location *loc2) |
| 7104 | { |
| 7105 | int hw_point1, hw_point2; |
| 7106 | |
| 7107 | /* Both of them must not be in moribund_locations. */ |
| 7108 | gdb_assert (loc1->owner != NULL); |
| 7109 | gdb_assert (loc2->owner != NULL); |
| 7110 | |
| 7111 | hw_point1 = is_hardware_watchpoint (loc1->owner); |
| 7112 | hw_point2 = is_hardware_watchpoint (loc2->owner); |
| 7113 | |
| 7114 | if (hw_point1 != hw_point2) |
| 7115 | return 0; |
| 7116 | else if (hw_point1) |
| 7117 | return watchpoint_locations_match (loc1, loc2); |
| 7118 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
| 7119 | return tracepoint_locations_match (loc1, loc2); |
| 7120 | else |
| 7121 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
| 7122 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
| 7123 | loc2->pspace->aspace, loc2->address) |
| 7124 | && loc1->length == loc2->length); |
| 7125 | } |
| 7126 | |
| 7127 | static void |
| 7128 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, |
| 7129 | int bnum, int have_bnum) |
| 7130 | { |
| 7131 | /* The longest string possibly returned by hex_string_custom |
| 7132 | is 50 chars. These must be at least that big for safety. */ |
| 7133 | char astr1[64]; |
| 7134 | char astr2[64]; |
| 7135 | |
| 7136 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
| 7137 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); |
| 7138 | if (have_bnum) |
| 7139 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
| 7140 | bnum, astr1, astr2); |
| 7141 | else |
| 7142 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
| 7143 | } |
| 7144 | |
| 7145 | /* Adjust a breakpoint's address to account for architectural |
| 7146 | constraints on breakpoint placement. Return the adjusted address. |
| 7147 | Note: Very few targets require this kind of adjustment. For most |
| 7148 | targets, this function is simply the identity function. */ |
| 7149 | |
| 7150 | static CORE_ADDR |
| 7151 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 7152 | CORE_ADDR bpaddr, enum bptype bptype) |
| 7153 | { |
| 7154 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
| 7155 | { |
| 7156 | /* Very few targets need any kind of breakpoint adjustment. */ |
| 7157 | return bpaddr; |
| 7158 | } |
| 7159 | else if (bptype == bp_watchpoint |
| 7160 | || bptype == bp_hardware_watchpoint |
| 7161 | || bptype == bp_read_watchpoint |
| 7162 | || bptype == bp_access_watchpoint |
| 7163 | || bptype == bp_catchpoint) |
| 7164 | { |
| 7165 | /* Watchpoints and the various bp_catch_* eventpoints should not |
| 7166 | have their addresses modified. */ |
| 7167 | return bpaddr; |
| 7168 | } |
| 7169 | else |
| 7170 | { |
| 7171 | CORE_ADDR adjusted_bpaddr; |
| 7172 | |
| 7173 | /* Some targets have architectural constraints on the placement |
| 7174 | of breakpoint instructions. Obtain the adjusted address. */ |
| 7175 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
| 7176 | |
| 7177 | /* An adjusted breakpoint address can significantly alter |
| 7178 | a user's expectations. Print a warning if an adjustment |
| 7179 | is required. */ |
| 7180 | if (adjusted_bpaddr != bpaddr) |
| 7181 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); |
| 7182 | |
| 7183 | return adjusted_bpaddr; |
| 7184 | } |
| 7185 | } |
| 7186 | |
| 7187 | void |
| 7188 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, |
| 7189 | struct breakpoint *owner) |
| 7190 | { |
| 7191 | memset (loc, 0, sizeof (*loc)); |
| 7192 | |
| 7193 | gdb_assert (ops != NULL); |
| 7194 | |
| 7195 | loc->ops = ops; |
| 7196 | loc->owner = owner; |
| 7197 | loc->cond = NULL; |
| 7198 | loc->cond_bytecode = NULL; |
| 7199 | loc->shlib_disabled = 0; |
| 7200 | loc->enabled = 1; |
| 7201 | |
| 7202 | switch (owner->type) |
| 7203 | { |
| 7204 | case bp_breakpoint: |
| 7205 | case bp_until: |
| 7206 | case bp_finish: |
| 7207 | case bp_longjmp: |
| 7208 | case bp_longjmp_resume: |
| 7209 | case bp_longjmp_call_dummy: |
| 7210 | case bp_exception: |
| 7211 | case bp_exception_resume: |
| 7212 | case bp_step_resume: |
| 7213 | case bp_hp_step_resume: |
| 7214 | case bp_watchpoint_scope: |
| 7215 | case bp_call_dummy: |
| 7216 | case bp_std_terminate: |
| 7217 | case bp_shlib_event: |
| 7218 | case bp_thread_event: |
| 7219 | case bp_overlay_event: |
| 7220 | case bp_jit_event: |
| 7221 | case bp_longjmp_master: |
| 7222 | case bp_std_terminate_master: |
| 7223 | case bp_exception_master: |
| 7224 | case bp_gnu_ifunc_resolver: |
| 7225 | case bp_gnu_ifunc_resolver_return: |
| 7226 | case bp_dprintf: |
| 7227 | loc->loc_type = bp_loc_software_breakpoint; |
| 7228 | mark_breakpoint_location_modified (loc); |
| 7229 | break; |
| 7230 | case bp_hardware_breakpoint: |
| 7231 | loc->loc_type = bp_loc_hardware_breakpoint; |
| 7232 | mark_breakpoint_location_modified (loc); |
| 7233 | break; |
| 7234 | case bp_hardware_watchpoint: |
| 7235 | case bp_read_watchpoint: |
| 7236 | case bp_access_watchpoint: |
| 7237 | loc->loc_type = bp_loc_hardware_watchpoint; |
| 7238 | break; |
| 7239 | case bp_watchpoint: |
| 7240 | case bp_catchpoint: |
| 7241 | case bp_tracepoint: |
| 7242 | case bp_fast_tracepoint: |
| 7243 | case bp_static_tracepoint: |
| 7244 | loc->loc_type = bp_loc_other; |
| 7245 | break; |
| 7246 | default: |
| 7247 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
| 7248 | } |
| 7249 | |
| 7250 | loc->refc = 1; |
| 7251 | } |
| 7252 | |
| 7253 | /* Allocate a struct bp_location. */ |
| 7254 | |
| 7255 | static struct bp_location * |
| 7256 | allocate_bp_location (struct breakpoint *bpt) |
| 7257 | { |
| 7258 | return bpt->ops->allocate_location (bpt); |
| 7259 | } |
| 7260 | |
| 7261 | static void |
| 7262 | free_bp_location (struct bp_location *loc) |
| 7263 | { |
| 7264 | loc->ops->dtor (loc); |
| 7265 | xfree (loc); |
| 7266 | } |
| 7267 | |
| 7268 | /* Increment reference count. */ |
| 7269 | |
| 7270 | static void |
| 7271 | incref_bp_location (struct bp_location *bl) |
| 7272 | { |
| 7273 | ++bl->refc; |
| 7274 | } |
| 7275 | |
| 7276 | /* Decrement reference count. If the reference count reaches 0, |
| 7277 | destroy the bp_location. Sets *BLP to NULL. */ |
| 7278 | |
| 7279 | static void |
| 7280 | decref_bp_location (struct bp_location **blp) |
| 7281 | { |
| 7282 | gdb_assert ((*blp)->refc > 0); |
| 7283 | |
| 7284 | if (--(*blp)->refc == 0) |
| 7285 | free_bp_location (*blp); |
| 7286 | *blp = NULL; |
| 7287 | } |
| 7288 | |
| 7289 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
| 7290 | |
| 7291 | static void |
| 7292 | add_to_breakpoint_chain (struct breakpoint *b) |
| 7293 | { |
| 7294 | struct breakpoint *b1; |
| 7295 | |
| 7296 | /* Add this breakpoint to the end of the chain so that a list of |
| 7297 | breakpoints will come out in order of increasing numbers. */ |
| 7298 | |
| 7299 | b1 = breakpoint_chain; |
| 7300 | if (b1 == 0) |
| 7301 | breakpoint_chain = b; |
| 7302 | else |
| 7303 | { |
| 7304 | while (b1->next) |
| 7305 | b1 = b1->next; |
| 7306 | b1->next = b; |
| 7307 | } |
| 7308 | } |
| 7309 | |
| 7310 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ |
| 7311 | |
| 7312 | static void |
| 7313 | init_raw_breakpoint_without_location (struct breakpoint *b, |
| 7314 | struct gdbarch *gdbarch, |
| 7315 | enum bptype bptype, |
| 7316 | const struct breakpoint_ops *ops) |
| 7317 | { |
| 7318 | memset (b, 0, sizeof (*b)); |
| 7319 | |
| 7320 | gdb_assert (ops != NULL); |
| 7321 | |
| 7322 | b->ops = ops; |
| 7323 | b->type = bptype; |
| 7324 | b->gdbarch = gdbarch; |
| 7325 | b->language = current_language->la_language; |
| 7326 | b->input_radix = input_radix; |
| 7327 | b->thread = -1; |
| 7328 | b->enable_state = bp_enabled; |
| 7329 | b->next = 0; |
| 7330 | b->silent = 0; |
| 7331 | b->ignore_count = 0; |
| 7332 | b->commands = NULL; |
| 7333 | b->frame_id = null_frame_id; |
| 7334 | b->condition_not_parsed = 0; |
| 7335 | b->py_bp_object = NULL; |
| 7336 | b->related_breakpoint = b; |
| 7337 | } |
| 7338 | |
| 7339 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
| 7340 | that has type BPTYPE and has no locations as yet. */ |
| 7341 | |
| 7342 | static struct breakpoint * |
| 7343 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
| 7344 | enum bptype bptype, |
| 7345 | const struct breakpoint_ops *ops) |
| 7346 | { |
| 7347 | struct breakpoint *b = XNEW (struct breakpoint); |
| 7348 | |
| 7349 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
| 7350 | add_to_breakpoint_chain (b); |
| 7351 | return b; |
| 7352 | } |
| 7353 | |
| 7354 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
| 7355 | resolutions should be made as the user specified the location explicitly |
| 7356 | enough. */ |
| 7357 | |
| 7358 | static void |
| 7359 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
| 7360 | { |
| 7361 | gdb_assert (loc->owner != NULL); |
| 7362 | |
| 7363 | if (loc->owner->type == bp_breakpoint |
| 7364 | || loc->owner->type == bp_hardware_breakpoint |
| 7365 | || is_tracepoint (loc->owner)) |
| 7366 | { |
| 7367 | int is_gnu_ifunc; |
| 7368 | const char *function_name; |
| 7369 | CORE_ADDR func_addr; |
| 7370 | |
| 7371 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
| 7372 | &func_addr, NULL, &is_gnu_ifunc); |
| 7373 | |
| 7374 | if (is_gnu_ifunc && !explicit_loc) |
| 7375 | { |
| 7376 | struct breakpoint *b = loc->owner; |
| 7377 | |
| 7378 | gdb_assert (loc->pspace == current_program_space); |
| 7379 | if (gnu_ifunc_resolve_name (function_name, |
| 7380 | &loc->requested_address)) |
| 7381 | { |
| 7382 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ |
| 7383 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
| 7384 | loc->requested_address, |
| 7385 | b->type); |
| 7386 | } |
| 7387 | else if (b->type == bp_breakpoint && b->loc == loc |
| 7388 | && loc->next == NULL && b->related_breakpoint == b) |
| 7389 | { |
| 7390 | /* Create only the whole new breakpoint of this type but do not |
| 7391 | mess more complicated breakpoints with multiple locations. */ |
| 7392 | b->type = bp_gnu_ifunc_resolver; |
| 7393 | /* Remember the resolver's address for use by the return |
| 7394 | breakpoint. */ |
| 7395 | loc->related_address = func_addr; |
| 7396 | } |
| 7397 | } |
| 7398 | |
| 7399 | if (function_name) |
| 7400 | loc->function_name = xstrdup (function_name); |
| 7401 | } |
| 7402 | } |
| 7403 | |
| 7404 | /* Attempt to determine architecture of location identified by SAL. */ |
| 7405 | struct gdbarch * |
| 7406 | get_sal_arch (struct symtab_and_line sal) |
| 7407 | { |
| 7408 | if (sal.section) |
| 7409 | return get_objfile_arch (sal.section->objfile); |
| 7410 | if (sal.symtab) |
| 7411 | return get_objfile_arch (sal.symtab->objfile); |
| 7412 | |
| 7413 | return NULL; |
| 7414 | } |
| 7415 | |
| 7416 | /* Low level routine for partially initializing a breakpoint of type |
| 7417 | BPTYPE. The newly created breakpoint's address, section, source |
| 7418 | file name, and line number are provided by SAL. |
| 7419 | |
| 7420 | It is expected that the caller will complete the initialization of |
| 7421 | the newly created breakpoint struct as well as output any status |
| 7422 | information regarding the creation of a new breakpoint. */ |
| 7423 | |
| 7424 | static void |
| 7425 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, |
| 7426 | struct symtab_and_line sal, enum bptype bptype, |
| 7427 | const struct breakpoint_ops *ops) |
| 7428 | { |
| 7429 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
| 7430 | |
| 7431 | add_location_to_breakpoint (b, &sal); |
| 7432 | |
| 7433 | if (bptype != bp_catchpoint) |
| 7434 | gdb_assert (sal.pspace != NULL); |
| 7435 | |
| 7436 | /* Store the program space that was used to set the breakpoint, |
| 7437 | except for ordinary breakpoints, which are independent of the |
| 7438 | program space. */ |
| 7439 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) |
| 7440 | b->pspace = sal.pspace; |
| 7441 | } |
| 7442 | |
| 7443 | /* set_raw_breakpoint is a low level routine for allocating and |
| 7444 | partially initializing a breakpoint of type BPTYPE. The newly |
| 7445 | created breakpoint's address, section, source file name, and line |
| 7446 | number are provided by SAL. The newly created and partially |
| 7447 | initialized breakpoint is added to the breakpoint chain and |
| 7448 | is also returned as the value of this function. |
| 7449 | |
| 7450 | It is expected that the caller will complete the initialization of |
| 7451 | the newly created breakpoint struct as well as output any status |
| 7452 | information regarding the creation of a new breakpoint. In |
| 7453 | particular, set_raw_breakpoint does NOT set the breakpoint |
| 7454 | number! Care should be taken to not allow an error to occur |
| 7455 | prior to completing the initialization of the breakpoint. If this |
| 7456 | should happen, a bogus breakpoint will be left on the chain. */ |
| 7457 | |
| 7458 | struct breakpoint * |
| 7459 | set_raw_breakpoint (struct gdbarch *gdbarch, |
| 7460 | struct symtab_and_line sal, enum bptype bptype, |
| 7461 | const struct breakpoint_ops *ops) |
| 7462 | { |
| 7463 | struct breakpoint *b = XNEW (struct breakpoint); |
| 7464 | |
| 7465 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
| 7466 | add_to_breakpoint_chain (b); |
| 7467 | return b; |
| 7468 | } |
| 7469 | |
| 7470 | |
| 7471 | /* Note that the breakpoint object B describes a permanent breakpoint |
| 7472 | instruction, hard-wired into the inferior's code. */ |
| 7473 | void |
| 7474 | make_breakpoint_permanent (struct breakpoint *b) |
| 7475 | { |
| 7476 | struct bp_location *bl; |
| 7477 | |
| 7478 | b->enable_state = bp_permanent; |
| 7479 | |
| 7480 | /* By definition, permanent breakpoints are already present in the |
| 7481 | code. Mark all locations as inserted. For now, |
| 7482 | make_breakpoint_permanent is called in just one place, so it's |
| 7483 | hard to say if it's reasonable to have permanent breakpoint with |
| 7484 | multiple locations or not, but it's easy to implement. */ |
| 7485 | for (bl = b->loc; bl; bl = bl->next) |
| 7486 | bl->inserted = 1; |
| 7487 | } |
| 7488 | |
| 7489 | /* Call this routine when stepping and nexting to enable a breakpoint |
| 7490 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
| 7491 | initiated the operation. */ |
| 7492 | |
| 7493 | void |
| 7494 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
| 7495 | { |
| 7496 | struct breakpoint *b, *b_tmp; |
| 7497 | int thread = tp->num; |
| 7498 | |
| 7499 | /* To avoid having to rescan all objfile symbols at every step, |
| 7500 | we maintain a list of continually-inserted but always disabled |
| 7501 | longjmp "master" breakpoints. Here, we simply create momentary |
| 7502 | clones of those and enable them for the requested thread. */ |
| 7503 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7504 | if (b->pspace == current_program_space |
| 7505 | && (b->type == bp_longjmp_master |
| 7506 | || b->type == bp_exception_master)) |
| 7507 | { |
| 7508 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
| 7509 | struct breakpoint *clone; |
| 7510 | |
| 7511 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
| 7512 | after their removal. */ |
| 7513 | clone = momentary_breakpoint_from_master (b, type, |
| 7514 | &longjmp_breakpoint_ops, 1); |
| 7515 | clone->thread = thread; |
| 7516 | } |
| 7517 | |
| 7518 | tp->initiating_frame = frame; |
| 7519 | } |
| 7520 | |
| 7521 | /* Delete all longjmp breakpoints from THREAD. */ |
| 7522 | void |
| 7523 | delete_longjmp_breakpoint (int thread) |
| 7524 | { |
| 7525 | struct breakpoint *b, *b_tmp; |
| 7526 | |
| 7527 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7528 | if (b->type == bp_longjmp || b->type == bp_exception) |
| 7529 | { |
| 7530 | if (b->thread == thread) |
| 7531 | delete_breakpoint (b); |
| 7532 | } |
| 7533 | } |
| 7534 | |
| 7535 | void |
| 7536 | delete_longjmp_breakpoint_at_next_stop (int thread) |
| 7537 | { |
| 7538 | struct breakpoint *b, *b_tmp; |
| 7539 | |
| 7540 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7541 | if (b->type == bp_longjmp || b->type == bp_exception) |
| 7542 | { |
| 7543 | if (b->thread == thread) |
| 7544 | b->disposition = disp_del_at_next_stop; |
| 7545 | } |
| 7546 | } |
| 7547 | |
| 7548 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
| 7549 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return |
| 7550 | pointer to any of them. Return NULL if this system cannot place longjmp |
| 7551 | breakpoints. */ |
| 7552 | |
| 7553 | struct breakpoint * |
| 7554 | set_longjmp_breakpoint_for_call_dummy (void) |
| 7555 | { |
| 7556 | struct breakpoint *b, *retval = NULL; |
| 7557 | |
| 7558 | ALL_BREAKPOINTS (b) |
| 7559 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) |
| 7560 | { |
| 7561 | struct breakpoint *new_b; |
| 7562 | |
| 7563 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, |
| 7564 | &momentary_breakpoint_ops, |
| 7565 | 1); |
| 7566 | new_b->thread = pid_to_thread_id (inferior_ptid); |
| 7567 | |
| 7568 | /* Link NEW_B into the chain of RETVAL breakpoints. */ |
| 7569 | |
| 7570 | gdb_assert (new_b->related_breakpoint == new_b); |
| 7571 | if (retval == NULL) |
| 7572 | retval = new_b; |
| 7573 | new_b->related_breakpoint = retval; |
| 7574 | while (retval->related_breakpoint != new_b->related_breakpoint) |
| 7575 | retval = retval->related_breakpoint; |
| 7576 | retval->related_breakpoint = new_b; |
| 7577 | } |
| 7578 | |
| 7579 | return retval; |
| 7580 | } |
| 7581 | |
| 7582 | /* Verify all existing dummy frames and their associated breakpoints for |
| 7583 | TP. Remove those which can no longer be found in the current frame |
| 7584 | stack. |
| 7585 | |
| 7586 | You should call this function only at places where it is safe to currently |
| 7587 | unwind the whole stack. Failed stack unwind would discard live dummy |
| 7588 | frames. */ |
| 7589 | |
| 7590 | void |
| 7591 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
| 7592 | { |
| 7593 | struct breakpoint *b, *b_tmp; |
| 7594 | |
| 7595 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7596 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
| 7597 | { |
| 7598 | struct breakpoint *dummy_b = b->related_breakpoint; |
| 7599 | |
| 7600 | while (dummy_b != b && dummy_b->type != bp_call_dummy) |
| 7601 | dummy_b = dummy_b->related_breakpoint; |
| 7602 | if (dummy_b->type != bp_call_dummy |
| 7603 | || frame_find_by_id (dummy_b->frame_id) != NULL) |
| 7604 | continue; |
| 7605 | |
| 7606 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
| 7607 | |
| 7608 | while (b->related_breakpoint != b) |
| 7609 | { |
| 7610 | if (b_tmp == b->related_breakpoint) |
| 7611 | b_tmp = b->related_breakpoint->next; |
| 7612 | delete_breakpoint (b->related_breakpoint); |
| 7613 | } |
| 7614 | delete_breakpoint (b); |
| 7615 | } |
| 7616 | } |
| 7617 | |
| 7618 | void |
| 7619 | enable_overlay_breakpoints (void) |
| 7620 | { |
| 7621 | struct breakpoint *b; |
| 7622 | |
| 7623 | ALL_BREAKPOINTS (b) |
| 7624 | if (b->type == bp_overlay_event) |
| 7625 | { |
| 7626 | b->enable_state = bp_enabled; |
| 7627 | update_global_location_list (UGLL_MAY_INSERT); |
| 7628 | overlay_events_enabled = 1; |
| 7629 | } |
| 7630 | } |
| 7631 | |
| 7632 | void |
| 7633 | disable_overlay_breakpoints (void) |
| 7634 | { |
| 7635 | struct breakpoint *b; |
| 7636 | |
| 7637 | ALL_BREAKPOINTS (b) |
| 7638 | if (b->type == bp_overlay_event) |
| 7639 | { |
| 7640 | b->enable_state = bp_disabled; |
| 7641 | update_global_location_list (UGLL_DONT_INSERT); |
| 7642 | overlay_events_enabled = 0; |
| 7643 | } |
| 7644 | } |
| 7645 | |
| 7646 | /* Set an active std::terminate breakpoint for each std::terminate |
| 7647 | master breakpoint. */ |
| 7648 | void |
| 7649 | set_std_terminate_breakpoint (void) |
| 7650 | { |
| 7651 | struct breakpoint *b, *b_tmp; |
| 7652 | |
| 7653 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7654 | if (b->pspace == current_program_space |
| 7655 | && b->type == bp_std_terminate_master) |
| 7656 | { |
| 7657 | momentary_breakpoint_from_master (b, bp_std_terminate, |
| 7658 | &momentary_breakpoint_ops, 1); |
| 7659 | } |
| 7660 | } |
| 7661 | |
| 7662 | /* Delete all the std::terminate breakpoints. */ |
| 7663 | void |
| 7664 | delete_std_terminate_breakpoint (void) |
| 7665 | { |
| 7666 | struct breakpoint *b, *b_tmp; |
| 7667 | |
| 7668 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7669 | if (b->type == bp_std_terminate) |
| 7670 | delete_breakpoint (b); |
| 7671 | } |
| 7672 | |
| 7673 | struct breakpoint * |
| 7674 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7675 | { |
| 7676 | struct breakpoint *b; |
| 7677 | |
| 7678 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
| 7679 | &internal_breakpoint_ops); |
| 7680 | |
| 7681 | b->enable_state = bp_enabled; |
| 7682 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
| 7683 | b->addr_string |
| 7684 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); |
| 7685 | |
| 7686 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 7687 | |
| 7688 | return b; |
| 7689 | } |
| 7690 | |
| 7691 | void |
| 7692 | remove_thread_event_breakpoints (void) |
| 7693 | { |
| 7694 | struct breakpoint *b, *b_tmp; |
| 7695 | |
| 7696 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7697 | if (b->type == bp_thread_event |
| 7698 | && b->loc->pspace == current_program_space) |
| 7699 | delete_breakpoint (b); |
| 7700 | } |
| 7701 | |
| 7702 | struct lang_and_radix |
| 7703 | { |
| 7704 | enum language lang; |
| 7705 | int radix; |
| 7706 | }; |
| 7707 | |
| 7708 | /* Create a breakpoint for JIT code registration and unregistration. */ |
| 7709 | |
| 7710 | struct breakpoint * |
| 7711 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7712 | { |
| 7713 | struct breakpoint *b; |
| 7714 | |
| 7715 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
| 7716 | &internal_breakpoint_ops); |
| 7717 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 7718 | return b; |
| 7719 | } |
| 7720 | |
| 7721 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
| 7722 | |
| 7723 | void |
| 7724 | remove_jit_event_breakpoints (void) |
| 7725 | { |
| 7726 | struct breakpoint *b, *b_tmp; |
| 7727 | |
| 7728 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7729 | if (b->type == bp_jit_event |
| 7730 | && b->loc->pspace == current_program_space) |
| 7731 | delete_breakpoint (b); |
| 7732 | } |
| 7733 | |
| 7734 | void |
| 7735 | remove_solib_event_breakpoints (void) |
| 7736 | { |
| 7737 | struct breakpoint *b, *b_tmp; |
| 7738 | |
| 7739 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7740 | if (b->type == bp_shlib_event |
| 7741 | && b->loc->pspace == current_program_space) |
| 7742 | delete_breakpoint (b); |
| 7743 | } |
| 7744 | |
| 7745 | /* See breakpoint.h. */ |
| 7746 | |
| 7747 | void |
| 7748 | remove_solib_event_breakpoints_at_next_stop (void) |
| 7749 | { |
| 7750 | struct breakpoint *b, *b_tmp; |
| 7751 | |
| 7752 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7753 | if (b->type == bp_shlib_event |
| 7754 | && b->loc->pspace == current_program_space) |
| 7755 | b->disposition = disp_del_at_next_stop; |
| 7756 | } |
| 7757 | |
| 7758 | /* Helper for create_solib_event_breakpoint / |
| 7759 | create_and_insert_solib_event_breakpoint. Allows specifying which |
| 7760 | INSERT_MODE to pass through to update_global_location_list. */ |
| 7761 | |
| 7762 | static struct breakpoint * |
| 7763 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, |
| 7764 | enum ugll_insert_mode insert_mode) |
| 7765 | { |
| 7766 | struct breakpoint *b; |
| 7767 | |
| 7768 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
| 7769 | &internal_breakpoint_ops); |
| 7770 | update_global_location_list_nothrow (insert_mode); |
| 7771 | return b; |
| 7772 | } |
| 7773 | |
| 7774 | struct breakpoint * |
| 7775 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7776 | { |
| 7777 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); |
| 7778 | } |
| 7779 | |
| 7780 | /* See breakpoint.h. */ |
| 7781 | |
| 7782 | struct breakpoint * |
| 7783 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7784 | { |
| 7785 | struct breakpoint *b; |
| 7786 | |
| 7787 | /* Explicitly tell update_global_location_list to insert |
| 7788 | locations. */ |
| 7789 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); |
| 7790 | if (!b->loc->inserted) |
| 7791 | { |
| 7792 | delete_breakpoint (b); |
| 7793 | return NULL; |
| 7794 | } |
| 7795 | return b; |
| 7796 | } |
| 7797 | |
| 7798 | /* Disable any breakpoints that are on code in shared libraries. Only |
| 7799 | apply to enabled breakpoints, disabled ones can just stay disabled. */ |
| 7800 | |
| 7801 | void |
| 7802 | disable_breakpoints_in_shlibs (void) |
| 7803 | { |
| 7804 | struct bp_location *loc, **locp_tmp; |
| 7805 | |
| 7806 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 7807 | { |
| 7808 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 7809 | struct breakpoint *b = loc->owner; |
| 7810 | |
| 7811 | /* We apply the check to all breakpoints, including disabled for |
| 7812 | those with loc->duplicate set. This is so that when breakpoint |
| 7813 | becomes enabled, or the duplicate is removed, gdb will try to |
| 7814 | insert all breakpoints. If we don't set shlib_disabled here, |
| 7815 | we'll try to insert those breakpoints and fail. */ |
| 7816 | if (((b->type == bp_breakpoint) |
| 7817 | || (b->type == bp_jit_event) |
| 7818 | || (b->type == bp_hardware_breakpoint) |
| 7819 | || (is_tracepoint (b))) |
| 7820 | && loc->pspace == current_program_space |
| 7821 | && !loc->shlib_disabled |
| 7822 | && solib_name_from_address (loc->pspace, loc->address) |
| 7823 | ) |
| 7824 | { |
| 7825 | loc->shlib_disabled = 1; |
| 7826 | } |
| 7827 | } |
| 7828 | } |
| 7829 | |
| 7830 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
| 7831 | notification of unloaded_shlib. Only apply to enabled breakpoints, |
| 7832 | disabled ones can just stay disabled. */ |
| 7833 | |
| 7834 | static void |
| 7835 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
| 7836 | { |
| 7837 | struct bp_location *loc, **locp_tmp; |
| 7838 | int disabled_shlib_breaks = 0; |
| 7839 | |
| 7840 | /* SunOS a.out shared libraries are always mapped, so do not |
| 7841 | disable breakpoints; they will only be reported as unloaded |
| 7842 | through clear_solib when GDB discards its shared library |
| 7843 | list. See clear_solib for more information. */ |
| 7844 | if (exec_bfd != NULL |
| 7845 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) |
| 7846 | return; |
| 7847 | |
| 7848 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 7849 | { |
| 7850 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 7851 | struct breakpoint *b = loc->owner; |
| 7852 | |
| 7853 | if (solib->pspace == loc->pspace |
| 7854 | && !loc->shlib_disabled |
| 7855 | && (((b->type == bp_breakpoint |
| 7856 | || b->type == bp_jit_event |
| 7857 | || b->type == bp_hardware_breakpoint) |
| 7858 | && (loc->loc_type == bp_loc_hardware_breakpoint |
| 7859 | || loc->loc_type == bp_loc_software_breakpoint)) |
| 7860 | || is_tracepoint (b)) |
| 7861 | && solib_contains_address_p (solib, loc->address)) |
| 7862 | { |
| 7863 | loc->shlib_disabled = 1; |
| 7864 | /* At this point, we cannot rely on remove_breakpoint |
| 7865 | succeeding so we must mark the breakpoint as not inserted |
| 7866 | to prevent future errors occurring in remove_breakpoints. */ |
| 7867 | loc->inserted = 0; |
| 7868 | |
| 7869 | /* This may cause duplicate notifications for the same breakpoint. */ |
| 7870 | observer_notify_breakpoint_modified (b); |
| 7871 | |
| 7872 | if (!disabled_shlib_breaks) |
| 7873 | { |
| 7874 | target_terminal_ours_for_output (); |
| 7875 | warning (_("Temporarily disabling breakpoints " |
| 7876 | "for unloaded shared library \"%s\""), |
| 7877 | solib->so_name); |
| 7878 | } |
| 7879 | disabled_shlib_breaks = 1; |
| 7880 | } |
| 7881 | } |
| 7882 | } |
| 7883 | |
| 7884 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
| 7885 | notification of free_objfile. Only apply to enabled breakpoints, |
| 7886 | disabled ones can just stay disabled. */ |
| 7887 | |
| 7888 | static void |
| 7889 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) |
| 7890 | { |
| 7891 | struct breakpoint *b; |
| 7892 | |
| 7893 | if (objfile == NULL) |
| 7894 | return; |
| 7895 | |
| 7896 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
| 7897 | managed by the user with add-symbol-file/remove-symbol-file. |
| 7898 | Similarly to how breakpoints in shared libraries are handled in |
| 7899 | response to "nosharedlibrary", mark breakpoints in such modules |
| 7900 | shlib_disabled so they end up uninserted on the next global |
| 7901 | location list update. Shared libraries not loaded by the user |
| 7902 | aren't handled here -- they're already handled in |
| 7903 | disable_breakpoints_in_unloaded_shlib, called by solib.c's |
| 7904 | solib_unloaded observer. We skip objfiles that are not |
| 7905 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
| 7906 | main objfile). */ |
| 7907 | if ((objfile->flags & OBJF_SHARED) == 0 |
| 7908 | || (objfile->flags & OBJF_USERLOADED) == 0) |
| 7909 | return; |
| 7910 | |
| 7911 | ALL_BREAKPOINTS (b) |
| 7912 | { |
| 7913 | struct bp_location *loc; |
| 7914 | int bp_modified = 0; |
| 7915 | |
| 7916 | if (!is_breakpoint (b) && !is_tracepoint (b)) |
| 7917 | continue; |
| 7918 | |
| 7919 | for (loc = b->loc; loc != NULL; loc = loc->next) |
| 7920 | { |
| 7921 | CORE_ADDR loc_addr = loc->address; |
| 7922 | |
| 7923 | if (loc->loc_type != bp_loc_hardware_breakpoint |
| 7924 | && loc->loc_type != bp_loc_software_breakpoint) |
| 7925 | continue; |
| 7926 | |
| 7927 | if (loc->shlib_disabled != 0) |
| 7928 | continue; |
| 7929 | |
| 7930 | if (objfile->pspace != loc->pspace) |
| 7931 | continue; |
| 7932 | |
| 7933 | if (loc->loc_type != bp_loc_hardware_breakpoint |
| 7934 | && loc->loc_type != bp_loc_software_breakpoint) |
| 7935 | continue; |
| 7936 | |
| 7937 | if (is_addr_in_objfile (loc_addr, objfile)) |
| 7938 | { |
| 7939 | loc->shlib_disabled = 1; |
| 7940 | /* At this point, we don't know whether the object was |
| 7941 | unmapped from the inferior or not, so leave the |
| 7942 | inserted flag alone. We'll handle failure to |
| 7943 | uninsert quietly, in case the object was indeed |
| 7944 | unmapped. */ |
| 7945 | |
| 7946 | mark_breakpoint_location_modified (loc); |
| 7947 | |
| 7948 | bp_modified = 1; |
| 7949 | } |
| 7950 | } |
| 7951 | |
| 7952 | if (bp_modified) |
| 7953 | observer_notify_breakpoint_modified (b); |
| 7954 | } |
| 7955 | } |
| 7956 | |
| 7957 | /* FORK & VFORK catchpoints. */ |
| 7958 | |
| 7959 | /* An instance of this type is used to represent a fork or vfork |
| 7960 | catchpoint. It includes a "struct breakpoint" as a kind of base |
| 7961 | class; users downcast to "struct breakpoint *" when needed. A |
| 7962 | breakpoint is really of this type iff its ops pointer points to |
| 7963 | CATCH_FORK_BREAKPOINT_OPS. */ |
| 7964 | |
| 7965 | struct fork_catchpoint |
| 7966 | { |
| 7967 | /* The base class. */ |
| 7968 | struct breakpoint base; |
| 7969 | |
| 7970 | /* Process id of a child process whose forking triggered this |
| 7971 | catchpoint. This field is only valid immediately after this |
| 7972 | catchpoint has triggered. */ |
| 7973 | ptid_t forked_inferior_pid; |
| 7974 | }; |
| 7975 | |
| 7976 | /* Implement the "insert" breakpoint_ops method for fork |
| 7977 | catchpoints. */ |
| 7978 | |
| 7979 | static int |
| 7980 | insert_catch_fork (struct bp_location *bl) |
| 7981 | { |
| 7982 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
| 7983 | } |
| 7984 | |
| 7985 | /* Implement the "remove" breakpoint_ops method for fork |
| 7986 | catchpoints. */ |
| 7987 | |
| 7988 | static int |
| 7989 | remove_catch_fork (struct bp_location *bl) |
| 7990 | { |
| 7991 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
| 7992 | } |
| 7993 | |
| 7994 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork |
| 7995 | catchpoints. */ |
| 7996 | |
| 7997 | static int |
| 7998 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
| 7999 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 8000 | const struct target_waitstatus *ws) |
| 8001 | { |
| 8002 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
| 8003 | |
| 8004 | if (ws->kind != TARGET_WAITKIND_FORKED) |
| 8005 | return 0; |
| 8006 | |
| 8007 | c->forked_inferior_pid = ws->value.related_pid; |
| 8008 | return 1; |
| 8009 | } |
| 8010 | |
| 8011 | /* Implement the "print_it" breakpoint_ops method for fork |
| 8012 | catchpoints. */ |
| 8013 | |
| 8014 | static enum print_stop_action |
| 8015 | print_it_catch_fork (bpstat bs) |
| 8016 | { |
| 8017 | struct ui_out *uiout = current_uiout; |
| 8018 | struct breakpoint *b = bs->breakpoint_at; |
| 8019 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; |
| 8020 | |
| 8021 | annotate_catchpoint (b->number); |
| 8022 | if (b->disposition == disp_del) |
| 8023 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8024 | else |
| 8025 | ui_out_text (uiout, "\nCatchpoint "); |
| 8026 | if (ui_out_is_mi_like_p (uiout)) |
| 8027 | { |
| 8028 | ui_out_field_string (uiout, "reason", |
| 8029 | async_reason_lookup (EXEC_ASYNC_FORK)); |
| 8030 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8031 | } |
| 8032 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8033 | ui_out_text (uiout, " (forked process "); |
| 8034 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); |
| 8035 | ui_out_text (uiout, "), "); |
| 8036 | return PRINT_SRC_AND_LOC; |
| 8037 | } |
| 8038 | |
| 8039 | /* Implement the "print_one" breakpoint_ops method for fork |
| 8040 | catchpoints. */ |
| 8041 | |
| 8042 | static void |
| 8043 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
| 8044 | { |
| 8045 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 8046 | struct value_print_options opts; |
| 8047 | struct ui_out *uiout = current_uiout; |
| 8048 | |
| 8049 | get_user_print_options (&opts); |
| 8050 | |
| 8051 | /* Field 4, the address, is omitted (which makes the columns not |
| 8052 | line up too nicely with the headers, but the effect is relatively |
| 8053 | readable). */ |
| 8054 | if (opts.addressprint) |
| 8055 | ui_out_field_skip (uiout, "addr"); |
| 8056 | annotate_field (5); |
| 8057 | ui_out_text (uiout, "fork"); |
| 8058 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
| 8059 | { |
| 8060 | ui_out_text (uiout, ", process "); |
| 8061 | ui_out_field_int (uiout, "what", |
| 8062 | ptid_get_pid (c->forked_inferior_pid)); |
| 8063 | ui_out_spaces (uiout, 1); |
| 8064 | } |
| 8065 | |
| 8066 | if (ui_out_is_mi_like_p (uiout)) |
| 8067 | ui_out_field_string (uiout, "catch-type", "fork"); |
| 8068 | } |
| 8069 | |
| 8070 | /* Implement the "print_mention" breakpoint_ops method for fork |
| 8071 | catchpoints. */ |
| 8072 | |
| 8073 | static void |
| 8074 | print_mention_catch_fork (struct breakpoint *b) |
| 8075 | { |
| 8076 | printf_filtered (_("Catchpoint %d (fork)"), b->number); |
| 8077 | } |
| 8078 | |
| 8079 | /* Implement the "print_recreate" breakpoint_ops method for fork |
| 8080 | catchpoints. */ |
| 8081 | |
| 8082 | static void |
| 8083 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) |
| 8084 | { |
| 8085 | fprintf_unfiltered (fp, "catch fork"); |
| 8086 | print_recreate_thread (b, fp); |
| 8087 | } |
| 8088 | |
| 8089 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
| 8090 | |
| 8091 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
| 8092 | |
| 8093 | /* Implement the "insert" breakpoint_ops method for vfork |
| 8094 | catchpoints. */ |
| 8095 | |
| 8096 | static int |
| 8097 | insert_catch_vfork (struct bp_location *bl) |
| 8098 | { |
| 8099 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
| 8100 | } |
| 8101 | |
| 8102 | /* Implement the "remove" breakpoint_ops method for vfork |
| 8103 | catchpoints. */ |
| 8104 | |
| 8105 | static int |
| 8106 | remove_catch_vfork (struct bp_location *bl) |
| 8107 | { |
| 8108 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
| 8109 | } |
| 8110 | |
| 8111 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork |
| 8112 | catchpoints. */ |
| 8113 | |
| 8114 | static int |
| 8115 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
| 8116 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 8117 | const struct target_waitstatus *ws) |
| 8118 | { |
| 8119 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
| 8120 | |
| 8121 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
| 8122 | return 0; |
| 8123 | |
| 8124 | c->forked_inferior_pid = ws->value.related_pid; |
| 8125 | return 1; |
| 8126 | } |
| 8127 | |
| 8128 | /* Implement the "print_it" breakpoint_ops method for vfork |
| 8129 | catchpoints. */ |
| 8130 | |
| 8131 | static enum print_stop_action |
| 8132 | print_it_catch_vfork (bpstat bs) |
| 8133 | { |
| 8134 | struct ui_out *uiout = current_uiout; |
| 8135 | struct breakpoint *b = bs->breakpoint_at; |
| 8136 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 8137 | |
| 8138 | annotate_catchpoint (b->number); |
| 8139 | if (b->disposition == disp_del) |
| 8140 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8141 | else |
| 8142 | ui_out_text (uiout, "\nCatchpoint "); |
| 8143 | if (ui_out_is_mi_like_p (uiout)) |
| 8144 | { |
| 8145 | ui_out_field_string (uiout, "reason", |
| 8146 | async_reason_lookup (EXEC_ASYNC_VFORK)); |
| 8147 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8148 | } |
| 8149 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8150 | ui_out_text (uiout, " (vforked process "); |
| 8151 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); |
| 8152 | ui_out_text (uiout, "), "); |
| 8153 | return PRINT_SRC_AND_LOC; |
| 8154 | } |
| 8155 | |
| 8156 | /* Implement the "print_one" breakpoint_ops method for vfork |
| 8157 | catchpoints. */ |
| 8158 | |
| 8159 | static void |
| 8160 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
| 8161 | { |
| 8162 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 8163 | struct value_print_options opts; |
| 8164 | struct ui_out *uiout = current_uiout; |
| 8165 | |
| 8166 | get_user_print_options (&opts); |
| 8167 | /* Field 4, the address, is omitted (which makes the columns not |
| 8168 | line up too nicely with the headers, but the effect is relatively |
| 8169 | readable). */ |
| 8170 | if (opts.addressprint) |
| 8171 | ui_out_field_skip (uiout, "addr"); |
| 8172 | annotate_field (5); |
| 8173 | ui_out_text (uiout, "vfork"); |
| 8174 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
| 8175 | { |
| 8176 | ui_out_text (uiout, ", process "); |
| 8177 | ui_out_field_int (uiout, "what", |
| 8178 | ptid_get_pid (c->forked_inferior_pid)); |
| 8179 | ui_out_spaces (uiout, 1); |
| 8180 | } |
| 8181 | |
| 8182 | if (ui_out_is_mi_like_p (uiout)) |
| 8183 | ui_out_field_string (uiout, "catch-type", "vfork"); |
| 8184 | } |
| 8185 | |
| 8186 | /* Implement the "print_mention" breakpoint_ops method for vfork |
| 8187 | catchpoints. */ |
| 8188 | |
| 8189 | static void |
| 8190 | print_mention_catch_vfork (struct breakpoint *b) |
| 8191 | { |
| 8192 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); |
| 8193 | } |
| 8194 | |
| 8195 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
| 8196 | catchpoints. */ |
| 8197 | |
| 8198 | static void |
| 8199 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) |
| 8200 | { |
| 8201 | fprintf_unfiltered (fp, "catch vfork"); |
| 8202 | print_recreate_thread (b, fp); |
| 8203 | } |
| 8204 | |
| 8205 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
| 8206 | |
| 8207 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
| 8208 | |
| 8209 | /* An instance of this type is used to represent an solib catchpoint. |
| 8210 | It includes a "struct breakpoint" as a kind of base class; users |
| 8211 | downcast to "struct breakpoint *" when needed. A breakpoint is |
| 8212 | really of this type iff its ops pointer points to |
| 8213 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
| 8214 | |
| 8215 | struct solib_catchpoint |
| 8216 | { |
| 8217 | /* The base class. */ |
| 8218 | struct breakpoint base; |
| 8219 | |
| 8220 | /* True for "catch load", false for "catch unload". */ |
| 8221 | unsigned char is_load; |
| 8222 | |
| 8223 | /* Regular expression to match, if any. COMPILED is only valid when |
| 8224 | REGEX is non-NULL. */ |
| 8225 | char *regex; |
| 8226 | regex_t compiled; |
| 8227 | }; |
| 8228 | |
| 8229 | static void |
| 8230 | dtor_catch_solib (struct breakpoint *b) |
| 8231 | { |
| 8232 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8233 | |
| 8234 | if (self->regex) |
| 8235 | regfree (&self->compiled); |
| 8236 | xfree (self->regex); |
| 8237 | |
| 8238 | base_breakpoint_ops.dtor (b); |
| 8239 | } |
| 8240 | |
| 8241 | static int |
| 8242 | insert_catch_solib (struct bp_location *ignore) |
| 8243 | { |
| 8244 | return 0; |
| 8245 | } |
| 8246 | |
| 8247 | static int |
| 8248 | remove_catch_solib (struct bp_location *ignore) |
| 8249 | { |
| 8250 | return 0; |
| 8251 | } |
| 8252 | |
| 8253 | static int |
| 8254 | breakpoint_hit_catch_solib (const struct bp_location *bl, |
| 8255 | struct address_space *aspace, |
| 8256 | CORE_ADDR bp_addr, |
| 8257 | const struct target_waitstatus *ws) |
| 8258 | { |
| 8259 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; |
| 8260 | struct breakpoint *other; |
| 8261 | |
| 8262 | if (ws->kind == TARGET_WAITKIND_LOADED) |
| 8263 | return 1; |
| 8264 | |
| 8265 | ALL_BREAKPOINTS (other) |
| 8266 | { |
| 8267 | struct bp_location *other_bl; |
| 8268 | |
| 8269 | if (other == bl->owner) |
| 8270 | continue; |
| 8271 | |
| 8272 | if (other->type != bp_shlib_event) |
| 8273 | continue; |
| 8274 | |
| 8275 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) |
| 8276 | continue; |
| 8277 | |
| 8278 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) |
| 8279 | { |
| 8280 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) |
| 8281 | return 1; |
| 8282 | } |
| 8283 | } |
| 8284 | |
| 8285 | return 0; |
| 8286 | } |
| 8287 | |
| 8288 | static void |
| 8289 | check_status_catch_solib (struct bpstats *bs) |
| 8290 | { |
| 8291 | struct solib_catchpoint *self |
| 8292 | = (struct solib_catchpoint *) bs->breakpoint_at; |
| 8293 | int ix; |
| 8294 | |
| 8295 | if (self->is_load) |
| 8296 | { |
| 8297 | struct so_list *iter; |
| 8298 | |
| 8299 | for (ix = 0; |
| 8300 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, |
| 8301 | ix, iter); |
| 8302 | ++ix) |
| 8303 | { |
| 8304 | if (!self->regex |
| 8305 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) |
| 8306 | return; |
| 8307 | } |
| 8308 | } |
| 8309 | else |
| 8310 | { |
| 8311 | char *iter; |
| 8312 | |
| 8313 | for (ix = 0; |
| 8314 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, |
| 8315 | ix, iter); |
| 8316 | ++ix) |
| 8317 | { |
| 8318 | if (!self->regex |
| 8319 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) |
| 8320 | return; |
| 8321 | } |
| 8322 | } |
| 8323 | |
| 8324 | bs->stop = 0; |
| 8325 | bs->print_it = print_it_noop; |
| 8326 | } |
| 8327 | |
| 8328 | static enum print_stop_action |
| 8329 | print_it_catch_solib (bpstat bs) |
| 8330 | { |
| 8331 | struct breakpoint *b = bs->breakpoint_at; |
| 8332 | struct ui_out *uiout = current_uiout; |
| 8333 | |
| 8334 | annotate_catchpoint (b->number); |
| 8335 | if (b->disposition == disp_del) |
| 8336 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8337 | else |
| 8338 | ui_out_text (uiout, "\nCatchpoint "); |
| 8339 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8340 | ui_out_text (uiout, "\n"); |
| 8341 | if (ui_out_is_mi_like_p (uiout)) |
| 8342 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8343 | print_solib_event (1); |
| 8344 | return PRINT_SRC_AND_LOC; |
| 8345 | } |
| 8346 | |
| 8347 | static void |
| 8348 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) |
| 8349 | { |
| 8350 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8351 | struct value_print_options opts; |
| 8352 | struct ui_out *uiout = current_uiout; |
| 8353 | char *msg; |
| 8354 | |
| 8355 | get_user_print_options (&opts); |
| 8356 | /* Field 4, the address, is omitted (which makes the columns not |
| 8357 | line up too nicely with the headers, but the effect is relatively |
| 8358 | readable). */ |
| 8359 | if (opts.addressprint) |
| 8360 | { |
| 8361 | annotate_field (4); |
| 8362 | ui_out_field_skip (uiout, "addr"); |
| 8363 | } |
| 8364 | |
| 8365 | annotate_field (5); |
| 8366 | if (self->is_load) |
| 8367 | { |
| 8368 | if (self->regex) |
| 8369 | msg = xstrprintf (_("load of library matching %s"), self->regex); |
| 8370 | else |
| 8371 | msg = xstrdup (_("load of library")); |
| 8372 | } |
| 8373 | else |
| 8374 | { |
| 8375 | if (self->regex) |
| 8376 | msg = xstrprintf (_("unload of library matching %s"), self->regex); |
| 8377 | else |
| 8378 | msg = xstrdup (_("unload of library")); |
| 8379 | } |
| 8380 | ui_out_field_string (uiout, "what", msg); |
| 8381 | xfree (msg); |
| 8382 | |
| 8383 | if (ui_out_is_mi_like_p (uiout)) |
| 8384 | ui_out_field_string (uiout, "catch-type", |
| 8385 | self->is_load ? "load" : "unload"); |
| 8386 | } |
| 8387 | |
| 8388 | static void |
| 8389 | print_mention_catch_solib (struct breakpoint *b) |
| 8390 | { |
| 8391 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8392 | |
| 8393 | printf_filtered (_("Catchpoint %d (%s)"), b->number, |
| 8394 | self->is_load ? "load" : "unload"); |
| 8395 | } |
| 8396 | |
| 8397 | static void |
| 8398 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) |
| 8399 | { |
| 8400 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8401 | |
| 8402 | fprintf_unfiltered (fp, "%s %s", |
| 8403 | b->disposition == disp_del ? "tcatch" : "catch", |
| 8404 | self->is_load ? "load" : "unload"); |
| 8405 | if (self->regex) |
| 8406 | fprintf_unfiltered (fp, " %s", self->regex); |
| 8407 | fprintf_unfiltered (fp, "\n"); |
| 8408 | } |
| 8409 | |
| 8410 | static struct breakpoint_ops catch_solib_breakpoint_ops; |
| 8411 | |
| 8412 | /* Shared helper function (MI and CLI) for creating and installing |
| 8413 | a shared object event catchpoint. If IS_LOAD is non-zero then |
| 8414 | the events to be caught are load events, otherwise they are |
| 8415 | unload events. If IS_TEMP is non-zero the catchpoint is a |
| 8416 | temporary one. If ENABLED is non-zero the catchpoint is |
| 8417 | created in an enabled state. */ |
| 8418 | |
| 8419 | void |
| 8420 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) |
| 8421 | { |
| 8422 | struct solib_catchpoint *c; |
| 8423 | struct gdbarch *gdbarch = get_current_arch (); |
| 8424 | struct cleanup *cleanup; |
| 8425 | |
| 8426 | if (!arg) |
| 8427 | arg = ""; |
| 8428 | arg = skip_spaces (arg); |
| 8429 | |
| 8430 | c = XCNEW (struct solib_catchpoint); |
| 8431 | cleanup = make_cleanup (xfree, c); |
| 8432 | |
| 8433 | if (*arg != '\0') |
| 8434 | { |
| 8435 | int errcode; |
| 8436 | |
| 8437 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); |
| 8438 | if (errcode != 0) |
| 8439 | { |
| 8440 | char *err = get_regcomp_error (errcode, &c->compiled); |
| 8441 | |
| 8442 | make_cleanup (xfree, err); |
| 8443 | error (_("Invalid regexp (%s): %s"), err, arg); |
| 8444 | } |
| 8445 | c->regex = xstrdup (arg); |
| 8446 | } |
| 8447 | |
| 8448 | c->is_load = is_load; |
| 8449 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
| 8450 | &catch_solib_breakpoint_ops); |
| 8451 | |
| 8452 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
| 8453 | |
| 8454 | discard_cleanups (cleanup); |
| 8455 | install_breakpoint (0, &c->base, 1); |
| 8456 | } |
| 8457 | |
| 8458 | /* A helper function that does all the work for "catch load" and |
| 8459 | "catch unload". */ |
| 8460 | |
| 8461 | static void |
| 8462 | catch_load_or_unload (char *arg, int from_tty, int is_load, |
| 8463 | struct cmd_list_element *command) |
| 8464 | { |
| 8465 | int tempflag; |
| 8466 | const int enabled = 1; |
| 8467 | |
| 8468 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8469 | |
| 8470 | add_solib_catchpoint (arg, is_load, tempflag, enabled); |
| 8471 | } |
| 8472 | |
| 8473 | static void |
| 8474 | catch_load_command_1 (char *arg, int from_tty, |
| 8475 | struct cmd_list_element *command) |
| 8476 | { |
| 8477 | catch_load_or_unload (arg, from_tty, 1, command); |
| 8478 | } |
| 8479 | |
| 8480 | static void |
| 8481 | catch_unload_command_1 (char *arg, int from_tty, |
| 8482 | struct cmd_list_element *command) |
| 8483 | { |
| 8484 | catch_load_or_unload (arg, from_tty, 0, command); |
| 8485 | } |
| 8486 | |
| 8487 | /* An instance of this type is used to represent a syscall catchpoint. |
| 8488 | It includes a "struct breakpoint" as a kind of base class; users |
| 8489 | downcast to "struct breakpoint *" when needed. A breakpoint is |
| 8490 | really of this type iff its ops pointer points to |
| 8491 | CATCH_SYSCALL_BREAKPOINT_OPS. */ |
| 8492 | |
| 8493 | struct syscall_catchpoint |
| 8494 | { |
| 8495 | /* The base class. */ |
| 8496 | struct breakpoint base; |
| 8497 | |
| 8498 | /* Syscall numbers used for the 'catch syscall' feature. If no |
| 8499 | syscall has been specified for filtering, its value is NULL. |
| 8500 | Otherwise, it holds a list of all syscalls to be caught. The |
| 8501 | list elements are allocated with xmalloc. */ |
| 8502 | VEC(int) *syscalls_to_be_caught; |
| 8503 | }; |
| 8504 | |
| 8505 | /* Implement the "dtor" breakpoint_ops method for syscall |
| 8506 | catchpoints. */ |
| 8507 | |
| 8508 | static void |
| 8509 | dtor_catch_syscall (struct breakpoint *b) |
| 8510 | { |
| 8511 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
| 8512 | |
| 8513 | VEC_free (int, c->syscalls_to_be_caught); |
| 8514 | |
| 8515 | base_breakpoint_ops.dtor (b); |
| 8516 | } |
| 8517 | |
| 8518 | static const struct inferior_data *catch_syscall_inferior_data = NULL; |
| 8519 | |
| 8520 | struct catch_syscall_inferior_data |
| 8521 | { |
| 8522 | /* We keep a count of the number of times the user has requested a |
| 8523 | particular syscall to be tracked, and pass this information to the |
| 8524 | target. This lets capable targets implement filtering directly. */ |
| 8525 | |
| 8526 | /* Number of times that "any" syscall is requested. */ |
| 8527 | int any_syscall_count; |
| 8528 | |
| 8529 | /* Count of each system call. */ |
| 8530 | VEC(int) *syscalls_counts; |
| 8531 | |
| 8532 | /* This counts all syscall catch requests, so we can readily determine |
| 8533 | if any catching is necessary. */ |
| 8534 | int total_syscalls_count; |
| 8535 | }; |
| 8536 | |
| 8537 | static struct catch_syscall_inferior_data* |
| 8538 | get_catch_syscall_inferior_data (struct inferior *inf) |
| 8539 | { |
| 8540 | struct catch_syscall_inferior_data *inf_data; |
| 8541 | |
| 8542 | inf_data = inferior_data (inf, catch_syscall_inferior_data); |
| 8543 | if (inf_data == NULL) |
| 8544 | { |
| 8545 | inf_data = XCNEW (struct catch_syscall_inferior_data); |
| 8546 | set_inferior_data (inf, catch_syscall_inferior_data, inf_data); |
| 8547 | } |
| 8548 | |
| 8549 | return inf_data; |
| 8550 | } |
| 8551 | |
| 8552 | static void |
| 8553 | catch_syscall_inferior_data_cleanup (struct inferior *inf, void *arg) |
| 8554 | { |
| 8555 | xfree (arg); |
| 8556 | } |
| 8557 | |
| 8558 | |
| 8559 | /* Implement the "insert" breakpoint_ops method for syscall |
| 8560 | catchpoints. */ |
| 8561 | |
| 8562 | static int |
| 8563 | insert_catch_syscall (struct bp_location *bl) |
| 8564 | { |
| 8565 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
| 8566 | struct inferior *inf = current_inferior (); |
| 8567 | struct catch_syscall_inferior_data *inf_data |
| 8568 | = get_catch_syscall_inferior_data (inf); |
| 8569 | |
| 8570 | ++inf_data->total_syscalls_count; |
| 8571 | if (!c->syscalls_to_be_caught) |
| 8572 | ++inf_data->any_syscall_count; |
| 8573 | else |
| 8574 | { |
| 8575 | int i, iter; |
| 8576 | |
| 8577 | for (i = 0; |
| 8578 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
| 8579 | i++) |
| 8580 | { |
| 8581 | int elem; |
| 8582 | |
| 8583 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
| 8584 | { |
| 8585 | int old_size = VEC_length (int, inf_data->syscalls_counts); |
| 8586 | uintptr_t vec_addr_offset |
| 8587 | = old_size * ((uintptr_t) sizeof (int)); |
| 8588 | uintptr_t vec_addr; |
| 8589 | VEC_safe_grow (int, inf_data->syscalls_counts, iter + 1); |
| 8590 | vec_addr = ((uintptr_t) VEC_address (int, |
| 8591 | inf_data->syscalls_counts) |
| 8592 | + vec_addr_offset); |
| 8593 | memset ((void *) vec_addr, 0, |
| 8594 | (iter + 1 - old_size) * sizeof (int)); |
| 8595 | } |
| 8596 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
| 8597 | VEC_replace (int, inf_data->syscalls_counts, iter, ++elem); |
| 8598 | } |
| 8599 | } |
| 8600 | |
| 8601 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
| 8602 | inf_data->total_syscalls_count != 0, |
| 8603 | inf_data->any_syscall_count, |
| 8604 | VEC_length (int, |
| 8605 | inf_data->syscalls_counts), |
| 8606 | VEC_address (int, |
| 8607 | inf_data->syscalls_counts)); |
| 8608 | } |
| 8609 | |
| 8610 | /* Implement the "remove" breakpoint_ops method for syscall |
| 8611 | catchpoints. */ |
| 8612 | |
| 8613 | static int |
| 8614 | remove_catch_syscall (struct bp_location *bl) |
| 8615 | { |
| 8616 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
| 8617 | struct inferior *inf = current_inferior (); |
| 8618 | struct catch_syscall_inferior_data *inf_data |
| 8619 | = get_catch_syscall_inferior_data (inf); |
| 8620 | |
| 8621 | --inf_data->total_syscalls_count; |
| 8622 | if (!c->syscalls_to_be_caught) |
| 8623 | --inf_data->any_syscall_count; |
| 8624 | else |
| 8625 | { |
| 8626 | int i, iter; |
| 8627 | |
| 8628 | for (i = 0; |
| 8629 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
| 8630 | i++) |
| 8631 | { |
| 8632 | int elem; |
| 8633 | if (iter >= VEC_length (int, inf_data->syscalls_counts)) |
| 8634 | /* Shouldn't happen. */ |
| 8635 | continue; |
| 8636 | elem = VEC_index (int, inf_data->syscalls_counts, iter); |
| 8637 | VEC_replace (int, inf_data->syscalls_counts, iter, --elem); |
| 8638 | } |
| 8639 | } |
| 8640 | |
| 8641 | return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid), |
| 8642 | inf_data->total_syscalls_count != 0, |
| 8643 | inf_data->any_syscall_count, |
| 8644 | VEC_length (int, |
| 8645 | inf_data->syscalls_counts), |
| 8646 | VEC_address (int, |
| 8647 | inf_data->syscalls_counts)); |
| 8648 | } |
| 8649 | |
| 8650 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall |
| 8651 | catchpoints. */ |
| 8652 | |
| 8653 | static int |
| 8654 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
| 8655 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 8656 | const struct target_waitstatus *ws) |
| 8657 | { |
| 8658 | /* We must check if we are catching specific syscalls in this |
| 8659 | breakpoint. If we are, then we must guarantee that the called |
| 8660 | syscall is the same syscall we are catching. */ |
| 8661 | int syscall_number = 0; |
| 8662 | const struct syscall_catchpoint *c |
| 8663 | = (const struct syscall_catchpoint *) bl->owner; |
| 8664 | |
| 8665 | if (ws->kind != TARGET_WAITKIND_SYSCALL_ENTRY |
| 8666 | && ws->kind != TARGET_WAITKIND_SYSCALL_RETURN) |
| 8667 | return 0; |
| 8668 | |
| 8669 | syscall_number = ws->value.syscall_number; |
| 8670 | |
| 8671 | /* Now, checking if the syscall is the same. */ |
| 8672 | if (c->syscalls_to_be_caught) |
| 8673 | { |
| 8674 | int i, iter; |
| 8675 | |
| 8676 | for (i = 0; |
| 8677 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
| 8678 | i++) |
| 8679 | if (syscall_number == iter) |
| 8680 | return 1; |
| 8681 | |
| 8682 | return 0; |
| 8683 | } |
| 8684 | |
| 8685 | return 1; |
| 8686 | } |
| 8687 | |
| 8688 | /* Implement the "print_it" breakpoint_ops method for syscall |
| 8689 | catchpoints. */ |
| 8690 | |
| 8691 | static enum print_stop_action |
| 8692 | print_it_catch_syscall (bpstat bs) |
| 8693 | { |
| 8694 | struct ui_out *uiout = current_uiout; |
| 8695 | struct breakpoint *b = bs->breakpoint_at; |
| 8696 | /* These are needed because we want to know in which state a |
| 8697 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY |
| 8698 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we |
| 8699 | must print "called syscall" or "returned from syscall". */ |
| 8700 | ptid_t ptid; |
| 8701 | struct target_waitstatus last; |
| 8702 | struct syscall s; |
| 8703 | |
| 8704 | get_last_target_status (&ptid, &last); |
| 8705 | |
| 8706 | get_syscall_by_number (last.value.syscall_number, &s); |
| 8707 | |
| 8708 | annotate_catchpoint (b->number); |
| 8709 | |
| 8710 | if (b->disposition == disp_del) |
| 8711 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8712 | else |
| 8713 | ui_out_text (uiout, "\nCatchpoint "); |
| 8714 | if (ui_out_is_mi_like_p (uiout)) |
| 8715 | { |
| 8716 | ui_out_field_string (uiout, "reason", |
| 8717 | async_reason_lookup (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY |
| 8718 | ? EXEC_ASYNC_SYSCALL_ENTRY |
| 8719 | : EXEC_ASYNC_SYSCALL_RETURN)); |
| 8720 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8721 | } |
| 8722 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8723 | |
| 8724 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) |
| 8725 | ui_out_text (uiout, " (call to syscall "); |
| 8726 | else |
| 8727 | ui_out_text (uiout, " (returned from syscall "); |
| 8728 | |
| 8729 | if (s.name == NULL || ui_out_is_mi_like_p (uiout)) |
| 8730 | ui_out_field_int (uiout, "syscall-number", last.value.syscall_number); |
| 8731 | if (s.name != NULL) |
| 8732 | ui_out_field_string (uiout, "syscall-name", s.name); |
| 8733 | |
| 8734 | ui_out_text (uiout, "), "); |
| 8735 | |
| 8736 | return PRINT_SRC_AND_LOC; |
| 8737 | } |
| 8738 | |
| 8739 | /* Implement the "print_one" breakpoint_ops method for syscall |
| 8740 | catchpoints. */ |
| 8741 | |
| 8742 | static void |
| 8743 | print_one_catch_syscall (struct breakpoint *b, |
| 8744 | struct bp_location **last_loc) |
| 8745 | { |
| 8746 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
| 8747 | struct value_print_options opts; |
| 8748 | struct ui_out *uiout = current_uiout; |
| 8749 | |
| 8750 | get_user_print_options (&opts); |
| 8751 | /* Field 4, the address, is omitted (which makes the columns not |
| 8752 | line up too nicely with the headers, but the effect is relatively |
| 8753 | readable). */ |
| 8754 | if (opts.addressprint) |
| 8755 | ui_out_field_skip (uiout, "addr"); |
| 8756 | annotate_field (5); |
| 8757 | |
| 8758 | if (c->syscalls_to_be_caught |
| 8759 | && VEC_length (int, c->syscalls_to_be_caught) > 1) |
| 8760 | ui_out_text (uiout, "syscalls \""); |
| 8761 | else |
| 8762 | ui_out_text (uiout, "syscall \""); |
| 8763 | |
| 8764 | if (c->syscalls_to_be_caught) |
| 8765 | { |
| 8766 | int i, iter; |
| 8767 | char *text = xstrprintf ("%s", ""); |
| 8768 | |
| 8769 | for (i = 0; |
| 8770 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
| 8771 | i++) |
| 8772 | { |
| 8773 | char *x = text; |
| 8774 | struct syscall s; |
| 8775 | get_syscall_by_number (iter, &s); |
| 8776 | |
| 8777 | if (s.name != NULL) |
| 8778 | text = xstrprintf ("%s%s, ", text, s.name); |
| 8779 | else |
| 8780 | text = xstrprintf ("%s%d, ", text, iter); |
| 8781 | |
| 8782 | /* We have to xfree the last 'text' (now stored at 'x') |
| 8783 | because xstrprintf dynamically allocates new space for it |
| 8784 | on every call. */ |
| 8785 | xfree (x); |
| 8786 | } |
| 8787 | /* Remove the last comma. */ |
| 8788 | text[strlen (text) - 2] = '\0'; |
| 8789 | ui_out_field_string (uiout, "what", text); |
| 8790 | } |
| 8791 | else |
| 8792 | ui_out_field_string (uiout, "what", "<any syscall>"); |
| 8793 | ui_out_text (uiout, "\" "); |
| 8794 | |
| 8795 | if (ui_out_is_mi_like_p (uiout)) |
| 8796 | ui_out_field_string (uiout, "catch-type", "syscall"); |
| 8797 | } |
| 8798 | |
| 8799 | /* Implement the "print_mention" breakpoint_ops method for syscall |
| 8800 | catchpoints. */ |
| 8801 | |
| 8802 | static void |
| 8803 | print_mention_catch_syscall (struct breakpoint *b) |
| 8804 | { |
| 8805 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
| 8806 | |
| 8807 | if (c->syscalls_to_be_caught) |
| 8808 | { |
| 8809 | int i, iter; |
| 8810 | |
| 8811 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
| 8812 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
| 8813 | else |
| 8814 | printf_filtered (_("Catchpoint %d (syscall"), b->number); |
| 8815 | |
| 8816 | for (i = 0; |
| 8817 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
| 8818 | i++) |
| 8819 | { |
| 8820 | struct syscall s; |
| 8821 | get_syscall_by_number (iter, &s); |
| 8822 | |
| 8823 | if (s.name) |
| 8824 | printf_filtered (" '%s' [%d]", s.name, s.number); |
| 8825 | else |
| 8826 | printf_filtered (" %d", s.number); |
| 8827 | } |
| 8828 | printf_filtered (")"); |
| 8829 | } |
| 8830 | else |
| 8831 | printf_filtered (_("Catchpoint %d (any syscall)"), |
| 8832 | b->number); |
| 8833 | } |
| 8834 | |
| 8835 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
| 8836 | catchpoints. */ |
| 8837 | |
| 8838 | static void |
| 8839 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) |
| 8840 | { |
| 8841 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
| 8842 | |
| 8843 | fprintf_unfiltered (fp, "catch syscall"); |
| 8844 | |
| 8845 | if (c->syscalls_to_be_caught) |
| 8846 | { |
| 8847 | int i, iter; |
| 8848 | |
| 8849 | for (i = 0; |
| 8850 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
| 8851 | i++) |
| 8852 | { |
| 8853 | struct syscall s; |
| 8854 | |
| 8855 | get_syscall_by_number (iter, &s); |
| 8856 | if (s.name) |
| 8857 | fprintf_unfiltered (fp, " %s", s.name); |
| 8858 | else |
| 8859 | fprintf_unfiltered (fp, " %d", s.number); |
| 8860 | } |
| 8861 | } |
| 8862 | print_recreate_thread (b, fp); |
| 8863 | } |
| 8864 | |
| 8865 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
| 8866 | |
| 8867 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
| 8868 | |
| 8869 | /* Returns non-zero if 'b' is a syscall catchpoint. */ |
| 8870 | |
| 8871 | static int |
| 8872 | syscall_catchpoint_p (struct breakpoint *b) |
| 8873 | { |
| 8874 | return (b->ops == &catch_syscall_breakpoint_ops); |
| 8875 | } |
| 8876 | |
| 8877 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
| 8878 | is non-zero, then make the breakpoint temporary. If COND_STRING is |
| 8879 | not NULL, then store it in the breakpoint. OPS, if not NULL, is |
| 8880 | the breakpoint_ops structure associated to the catchpoint. */ |
| 8881 | |
| 8882 | void |
| 8883 | init_catchpoint (struct breakpoint *b, |
| 8884 | struct gdbarch *gdbarch, int tempflag, |
| 8885 | char *cond_string, |
| 8886 | const struct breakpoint_ops *ops) |
| 8887 | { |
| 8888 | struct symtab_and_line sal; |
| 8889 | |
| 8890 | init_sal (&sal); |
| 8891 | sal.pspace = current_program_space; |
| 8892 | |
| 8893 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
| 8894 | |
| 8895 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
| 8896 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 8897 | } |
| 8898 | |
| 8899 | void |
| 8900 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
| 8901 | { |
| 8902 | add_to_breakpoint_chain (b); |
| 8903 | set_breakpoint_number (internal, b); |
| 8904 | if (is_tracepoint (b)) |
| 8905 | set_tracepoint_count (breakpoint_count); |
| 8906 | if (!internal) |
| 8907 | mention (b); |
| 8908 | observer_notify_breakpoint_created (b); |
| 8909 | |
| 8910 | if (update_gll) |
| 8911 | update_global_location_list (UGLL_MAY_INSERT); |
| 8912 | } |
| 8913 | |
| 8914 | static void |
| 8915 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
| 8916 | int tempflag, char *cond_string, |
| 8917 | const struct breakpoint_ops *ops) |
| 8918 | { |
| 8919 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
| 8920 | |
| 8921 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
| 8922 | |
| 8923 | c->forked_inferior_pid = null_ptid; |
| 8924 | |
| 8925 | install_breakpoint (0, &c->base, 1); |
| 8926 | } |
| 8927 | |
| 8928 | /* Exec catchpoints. */ |
| 8929 | |
| 8930 | /* An instance of this type is used to represent an exec catchpoint. |
| 8931 | It includes a "struct breakpoint" as a kind of base class; users |
| 8932 | downcast to "struct breakpoint *" when needed. A breakpoint is |
| 8933 | really of this type iff its ops pointer points to |
| 8934 | CATCH_EXEC_BREAKPOINT_OPS. */ |
| 8935 | |
| 8936 | struct exec_catchpoint |
| 8937 | { |
| 8938 | /* The base class. */ |
| 8939 | struct breakpoint base; |
| 8940 | |
| 8941 | /* Filename of a program whose exec triggered this catchpoint. |
| 8942 | This field is only valid immediately after this catchpoint has |
| 8943 | triggered. */ |
| 8944 | char *exec_pathname; |
| 8945 | }; |
| 8946 | |
| 8947 | /* Implement the "dtor" breakpoint_ops method for exec |
| 8948 | catchpoints. */ |
| 8949 | |
| 8950 | static void |
| 8951 | dtor_catch_exec (struct breakpoint *b) |
| 8952 | { |
| 8953 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8954 | |
| 8955 | xfree (c->exec_pathname); |
| 8956 | |
| 8957 | base_breakpoint_ops.dtor (b); |
| 8958 | } |
| 8959 | |
| 8960 | static int |
| 8961 | insert_catch_exec (struct bp_location *bl) |
| 8962 | { |
| 8963 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
| 8964 | } |
| 8965 | |
| 8966 | static int |
| 8967 | remove_catch_exec (struct bp_location *bl) |
| 8968 | { |
| 8969 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
| 8970 | } |
| 8971 | |
| 8972 | static int |
| 8973 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
| 8974 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 8975 | const struct target_waitstatus *ws) |
| 8976 | { |
| 8977 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
| 8978 | |
| 8979 | if (ws->kind != TARGET_WAITKIND_EXECD) |
| 8980 | return 0; |
| 8981 | |
| 8982 | c->exec_pathname = xstrdup (ws->value.execd_pathname); |
| 8983 | return 1; |
| 8984 | } |
| 8985 | |
| 8986 | static enum print_stop_action |
| 8987 | print_it_catch_exec (bpstat bs) |
| 8988 | { |
| 8989 | struct ui_out *uiout = current_uiout; |
| 8990 | struct breakpoint *b = bs->breakpoint_at; |
| 8991 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8992 | |
| 8993 | annotate_catchpoint (b->number); |
| 8994 | if (b->disposition == disp_del) |
| 8995 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8996 | else |
| 8997 | ui_out_text (uiout, "\nCatchpoint "); |
| 8998 | if (ui_out_is_mi_like_p (uiout)) |
| 8999 | { |
| 9000 | ui_out_field_string (uiout, "reason", |
| 9001 | async_reason_lookup (EXEC_ASYNC_EXEC)); |
| 9002 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 9003 | } |
| 9004 | ui_out_field_int (uiout, "bkptno", b->number); |
| 9005 | ui_out_text (uiout, " (exec'd "); |
| 9006 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); |
| 9007 | ui_out_text (uiout, "), "); |
| 9008 | |
| 9009 | return PRINT_SRC_AND_LOC; |
| 9010 | } |
| 9011 | |
| 9012 | static void |
| 9013 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
| 9014 | { |
| 9015 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 9016 | struct value_print_options opts; |
| 9017 | struct ui_out *uiout = current_uiout; |
| 9018 | |
| 9019 | get_user_print_options (&opts); |
| 9020 | |
| 9021 | /* Field 4, the address, is omitted (which makes the columns |
| 9022 | not line up too nicely with the headers, but the effect |
| 9023 | is relatively readable). */ |
| 9024 | if (opts.addressprint) |
| 9025 | ui_out_field_skip (uiout, "addr"); |
| 9026 | annotate_field (5); |
| 9027 | ui_out_text (uiout, "exec"); |
| 9028 | if (c->exec_pathname != NULL) |
| 9029 | { |
| 9030 | ui_out_text (uiout, ", program \""); |
| 9031 | ui_out_field_string (uiout, "what", c->exec_pathname); |
| 9032 | ui_out_text (uiout, "\" "); |
| 9033 | } |
| 9034 | |
| 9035 | if (ui_out_is_mi_like_p (uiout)) |
| 9036 | ui_out_field_string (uiout, "catch-type", "exec"); |
| 9037 | } |
| 9038 | |
| 9039 | static void |
| 9040 | print_mention_catch_exec (struct breakpoint *b) |
| 9041 | { |
| 9042 | printf_filtered (_("Catchpoint %d (exec)"), b->number); |
| 9043 | } |
| 9044 | |
| 9045 | /* Implement the "print_recreate" breakpoint_ops method for exec |
| 9046 | catchpoints. */ |
| 9047 | |
| 9048 | static void |
| 9049 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) |
| 9050 | { |
| 9051 | fprintf_unfiltered (fp, "catch exec"); |
| 9052 | print_recreate_thread (b, fp); |
| 9053 | } |
| 9054 | |
| 9055 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
| 9056 | |
| 9057 | static void |
| 9058 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, |
| 9059 | const struct breakpoint_ops *ops) |
| 9060 | { |
| 9061 | struct syscall_catchpoint *c; |
| 9062 | struct gdbarch *gdbarch = get_current_arch (); |
| 9063 | |
| 9064 | c = XNEW (struct syscall_catchpoint); |
| 9065 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); |
| 9066 | c->syscalls_to_be_caught = filter; |
| 9067 | |
| 9068 | install_breakpoint (0, &c->base, 1); |
| 9069 | } |
| 9070 | |
| 9071 | static int |
| 9072 | hw_breakpoint_used_count (void) |
| 9073 | { |
| 9074 | int i = 0; |
| 9075 | struct breakpoint *b; |
| 9076 | struct bp_location *bl; |
| 9077 | |
| 9078 | ALL_BREAKPOINTS (b) |
| 9079 | { |
| 9080 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
| 9081 | for (bl = b->loc; bl; bl = bl->next) |
| 9082 | { |
| 9083 | /* Special types of hardware breakpoints may use more than |
| 9084 | one register. */ |
| 9085 | i += b->ops->resources_needed (bl); |
| 9086 | } |
| 9087 | } |
| 9088 | |
| 9089 | return i; |
| 9090 | } |
| 9091 | |
| 9092 | /* Returns the resources B would use if it were a hardware |
| 9093 | watchpoint. */ |
| 9094 | |
| 9095 | static int |
| 9096 | hw_watchpoint_use_count (struct breakpoint *b) |
| 9097 | { |
| 9098 | int i = 0; |
| 9099 | struct bp_location *bl; |
| 9100 | |
| 9101 | if (!breakpoint_enabled (b)) |
| 9102 | return 0; |
| 9103 | |
| 9104 | for (bl = b->loc; bl; bl = bl->next) |
| 9105 | { |
| 9106 | /* Special types of hardware watchpoints may use more than |
| 9107 | one register. */ |
| 9108 | i += b->ops->resources_needed (bl); |
| 9109 | } |
| 9110 | |
| 9111 | return i; |
| 9112 | } |
| 9113 | |
| 9114 | /* Returns the sum the used resources of all hardware watchpoints of |
| 9115 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED |
| 9116 | the sum of the used resources of all hardware watchpoints of other |
| 9117 | types _not_ TYPE. */ |
| 9118 | |
| 9119 | static int |
| 9120 | hw_watchpoint_used_count_others (struct breakpoint *except, |
| 9121 | enum bptype type, int *other_type_used) |
| 9122 | { |
| 9123 | int i = 0; |
| 9124 | struct breakpoint *b; |
| 9125 | |
| 9126 | *other_type_used = 0; |
| 9127 | ALL_BREAKPOINTS (b) |
| 9128 | { |
| 9129 | if (b == except) |
| 9130 | continue; |
| 9131 | if (!breakpoint_enabled (b)) |
| 9132 | continue; |
| 9133 | |
| 9134 | if (b->type == type) |
| 9135 | i += hw_watchpoint_use_count (b); |
| 9136 | else if (is_hardware_watchpoint (b)) |
| 9137 | *other_type_used = 1; |
| 9138 | } |
| 9139 | |
| 9140 | return i; |
| 9141 | } |
| 9142 | |
| 9143 | void |
| 9144 | disable_watchpoints_before_interactive_call_start (void) |
| 9145 | { |
| 9146 | struct breakpoint *b; |
| 9147 | |
| 9148 | ALL_BREAKPOINTS (b) |
| 9149 | { |
| 9150 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
| 9151 | { |
| 9152 | b->enable_state = bp_call_disabled; |
| 9153 | update_global_location_list (UGLL_DONT_INSERT); |
| 9154 | } |
| 9155 | } |
| 9156 | } |
| 9157 | |
| 9158 | void |
| 9159 | enable_watchpoints_after_interactive_call_stop (void) |
| 9160 | { |
| 9161 | struct breakpoint *b; |
| 9162 | |
| 9163 | ALL_BREAKPOINTS (b) |
| 9164 | { |
| 9165 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
| 9166 | { |
| 9167 | b->enable_state = bp_enabled; |
| 9168 | update_global_location_list (UGLL_MAY_INSERT); |
| 9169 | } |
| 9170 | } |
| 9171 | } |
| 9172 | |
| 9173 | void |
| 9174 | disable_breakpoints_before_startup (void) |
| 9175 | { |
| 9176 | current_program_space->executing_startup = 1; |
| 9177 | update_global_location_list (UGLL_DONT_INSERT); |
| 9178 | } |
| 9179 | |
| 9180 | void |
| 9181 | enable_breakpoints_after_startup (void) |
| 9182 | { |
| 9183 | current_program_space->executing_startup = 0; |
| 9184 | breakpoint_re_set (); |
| 9185 | } |
| 9186 | |
| 9187 | |
| 9188 | /* Set a breakpoint that will evaporate an end of command |
| 9189 | at address specified by SAL. |
| 9190 | Restrict it to frame FRAME if FRAME is nonzero. */ |
| 9191 | |
| 9192 | struct breakpoint * |
| 9193 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
| 9194 | struct frame_id frame_id, enum bptype type) |
| 9195 | { |
| 9196 | struct breakpoint *b; |
| 9197 | |
| 9198 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
| 9199 | tail-called one. */ |
| 9200 | gdb_assert (!frame_id_artificial_p (frame_id)); |
| 9201 | |
| 9202 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
| 9203 | b->enable_state = bp_enabled; |
| 9204 | b->disposition = disp_donttouch; |
| 9205 | b->frame_id = frame_id; |
| 9206 | |
| 9207 | /* If we're debugging a multi-threaded program, then we want |
| 9208 | momentary breakpoints to be active in only a single thread of |
| 9209 | control. */ |
| 9210 | if (in_thread_list (inferior_ptid)) |
| 9211 | b->thread = pid_to_thread_id (inferior_ptid); |
| 9212 | |
| 9213 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 9214 | |
| 9215 | return b; |
| 9216 | } |
| 9217 | |
| 9218 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
| 9219 | The new breakpoint will have type TYPE, use OPS as its |
| 9220 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ |
| 9221 | |
| 9222 | static struct breakpoint * |
| 9223 | momentary_breakpoint_from_master (struct breakpoint *orig, |
| 9224 | enum bptype type, |
| 9225 | const struct breakpoint_ops *ops, |
| 9226 | int loc_enabled) |
| 9227 | { |
| 9228 | struct breakpoint *copy; |
| 9229 | |
| 9230 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
| 9231 | copy->loc = allocate_bp_location (copy); |
| 9232 | set_breakpoint_location_function (copy->loc, 1); |
| 9233 | |
| 9234 | copy->loc->gdbarch = orig->loc->gdbarch; |
| 9235 | copy->loc->requested_address = orig->loc->requested_address; |
| 9236 | copy->loc->address = orig->loc->address; |
| 9237 | copy->loc->section = orig->loc->section; |
| 9238 | copy->loc->pspace = orig->loc->pspace; |
| 9239 | copy->loc->probe = orig->loc->probe; |
| 9240 | copy->loc->line_number = orig->loc->line_number; |
| 9241 | copy->loc->symtab = orig->loc->symtab; |
| 9242 | copy->loc->enabled = loc_enabled; |
| 9243 | copy->frame_id = orig->frame_id; |
| 9244 | copy->thread = orig->thread; |
| 9245 | copy->pspace = orig->pspace; |
| 9246 | |
| 9247 | copy->enable_state = bp_enabled; |
| 9248 | copy->disposition = disp_donttouch; |
| 9249 | copy->number = internal_breakpoint_number--; |
| 9250 | |
| 9251 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
| 9252 | return copy; |
| 9253 | } |
| 9254 | |
| 9255 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
| 9256 | ORIG is NULL. */ |
| 9257 | |
| 9258 | struct breakpoint * |
| 9259 | clone_momentary_breakpoint (struct breakpoint *orig) |
| 9260 | { |
| 9261 | /* If there's nothing to clone, then return nothing. */ |
| 9262 | if (orig == NULL) |
| 9263 | return NULL; |
| 9264 | |
| 9265 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
| 9266 | } |
| 9267 | |
| 9268 | struct breakpoint * |
| 9269 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 9270 | enum bptype type) |
| 9271 | { |
| 9272 | struct symtab_and_line sal; |
| 9273 | |
| 9274 | sal = find_pc_line (pc, 0); |
| 9275 | sal.pc = pc; |
| 9276 | sal.section = find_pc_overlay (pc); |
| 9277 | sal.explicit_pc = 1; |
| 9278 | |
| 9279 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
| 9280 | } |
| 9281 | \f |
| 9282 | |
| 9283 | /* Tell the user we have just set a breakpoint B. */ |
| 9284 | |
| 9285 | static void |
| 9286 | mention (struct breakpoint *b) |
| 9287 | { |
| 9288 | b->ops->print_mention (b); |
| 9289 | if (ui_out_is_mi_like_p (current_uiout)) |
| 9290 | return; |
| 9291 | printf_filtered ("\n"); |
| 9292 | } |
| 9293 | \f |
| 9294 | |
| 9295 | static struct bp_location * |
| 9296 | add_location_to_breakpoint (struct breakpoint *b, |
| 9297 | const struct symtab_and_line *sal) |
| 9298 | { |
| 9299 | struct bp_location *loc, **tmp; |
| 9300 | CORE_ADDR adjusted_address; |
| 9301 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); |
| 9302 | |
| 9303 | if (loc_gdbarch == NULL) |
| 9304 | loc_gdbarch = b->gdbarch; |
| 9305 | |
| 9306 | /* Adjust the breakpoint's address prior to allocating a location. |
| 9307 | Once we call allocate_bp_location(), that mostly uninitialized |
| 9308 | location will be placed on the location chain. Adjustment of the |
| 9309 | breakpoint may cause target_read_memory() to be called and we do |
| 9310 | not want its scan of the location chain to find a breakpoint and |
| 9311 | location that's only been partially initialized. */ |
| 9312 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
| 9313 | sal->pc, b->type); |
| 9314 | |
| 9315 | /* Sort the locations by their ADDRESS. */ |
| 9316 | loc = allocate_bp_location (b); |
| 9317 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
| 9318 | tmp = &((*tmp)->next)) |
| 9319 | ; |
| 9320 | loc->next = *tmp; |
| 9321 | *tmp = loc; |
| 9322 | |
| 9323 | loc->requested_address = sal->pc; |
| 9324 | loc->address = adjusted_address; |
| 9325 | loc->pspace = sal->pspace; |
| 9326 | loc->probe.probe = sal->probe; |
| 9327 | loc->probe.objfile = sal->objfile; |
| 9328 | gdb_assert (loc->pspace != NULL); |
| 9329 | loc->section = sal->section; |
| 9330 | loc->gdbarch = loc_gdbarch; |
| 9331 | loc->line_number = sal->line; |
| 9332 | loc->symtab = sal->symtab; |
| 9333 | |
| 9334 | set_breakpoint_location_function (loc, |
| 9335 | sal->explicit_pc || sal->explicit_line); |
| 9336 | return loc; |
| 9337 | } |
| 9338 | \f |
| 9339 | |
| 9340 | /* Return 1 if LOC is pointing to a permanent breakpoint, |
| 9341 | return 0 otherwise. */ |
| 9342 | |
| 9343 | static int |
| 9344 | bp_loc_is_permanent (struct bp_location *loc) |
| 9345 | { |
| 9346 | int len; |
| 9347 | CORE_ADDR addr; |
| 9348 | const gdb_byte *bpoint; |
| 9349 | gdb_byte *target_mem; |
| 9350 | struct cleanup *cleanup; |
| 9351 | int retval = 0; |
| 9352 | |
| 9353 | gdb_assert (loc != NULL); |
| 9354 | |
| 9355 | addr = loc->address; |
| 9356 | bpoint = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
| 9357 | |
| 9358 | /* Software breakpoints unsupported? */ |
| 9359 | if (bpoint == NULL) |
| 9360 | return 0; |
| 9361 | |
| 9362 | target_mem = alloca (len); |
| 9363 | |
| 9364 | /* Enable the automatic memory restoration from breakpoints while |
| 9365 | we read the memory. Otherwise we could say about our temporary |
| 9366 | breakpoints they are permanent. */ |
| 9367 | cleanup = save_current_space_and_thread (); |
| 9368 | |
| 9369 | switch_to_program_space_and_thread (loc->pspace); |
| 9370 | make_show_memory_breakpoints_cleanup (0); |
| 9371 | |
| 9372 | if (target_read_memory (loc->address, target_mem, len) == 0 |
| 9373 | && memcmp (target_mem, bpoint, len) == 0) |
| 9374 | retval = 1; |
| 9375 | |
| 9376 | do_cleanups (cleanup); |
| 9377 | |
| 9378 | return retval; |
| 9379 | } |
| 9380 | |
| 9381 | /* Build a command list for the dprintf corresponding to the current |
| 9382 | settings of the dprintf style options. */ |
| 9383 | |
| 9384 | static void |
| 9385 | update_dprintf_command_list (struct breakpoint *b) |
| 9386 | { |
| 9387 | char *dprintf_args = b->extra_string; |
| 9388 | char *printf_line = NULL; |
| 9389 | |
| 9390 | if (!dprintf_args) |
| 9391 | return; |
| 9392 | |
| 9393 | dprintf_args = skip_spaces (dprintf_args); |
| 9394 | |
| 9395 | /* Allow a comma, as it may have terminated a location, but don't |
| 9396 | insist on it. */ |
| 9397 | if (*dprintf_args == ',') |
| 9398 | ++dprintf_args; |
| 9399 | dprintf_args = skip_spaces (dprintf_args); |
| 9400 | |
| 9401 | if (*dprintf_args != '"') |
| 9402 | error (_("Bad format string, missing '\"'.")); |
| 9403 | |
| 9404 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
| 9405 | printf_line = xstrprintf ("printf %s", dprintf_args); |
| 9406 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
| 9407 | { |
| 9408 | if (!dprintf_function) |
| 9409 | error (_("No function supplied for dprintf call")); |
| 9410 | |
| 9411 | if (dprintf_channel && strlen (dprintf_channel) > 0) |
| 9412 | printf_line = xstrprintf ("call (void) %s (%s,%s)", |
| 9413 | dprintf_function, |
| 9414 | dprintf_channel, |
| 9415 | dprintf_args); |
| 9416 | else |
| 9417 | printf_line = xstrprintf ("call (void) %s (%s)", |
| 9418 | dprintf_function, |
| 9419 | dprintf_args); |
| 9420 | } |
| 9421 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
| 9422 | { |
| 9423 | if (target_can_run_breakpoint_commands ()) |
| 9424 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); |
| 9425 | else |
| 9426 | { |
| 9427 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); |
| 9428 | printf_line = xstrprintf ("printf %s", dprintf_args); |
| 9429 | } |
| 9430 | } |
| 9431 | else |
| 9432 | internal_error (__FILE__, __LINE__, |
| 9433 | _("Invalid dprintf style.")); |
| 9434 | |
| 9435 | gdb_assert (printf_line != NULL); |
| 9436 | /* Manufacture a printf sequence. */ |
| 9437 | { |
| 9438 | struct command_line *printf_cmd_line |
| 9439 | = xmalloc (sizeof (struct command_line)); |
| 9440 | |
| 9441 | printf_cmd_line = xmalloc (sizeof (struct command_line)); |
| 9442 | printf_cmd_line->control_type = simple_control; |
| 9443 | printf_cmd_line->body_count = 0; |
| 9444 | printf_cmd_line->body_list = NULL; |
| 9445 | printf_cmd_line->next = NULL; |
| 9446 | printf_cmd_line->line = printf_line; |
| 9447 | |
| 9448 | breakpoint_set_commands (b, printf_cmd_line); |
| 9449 | } |
| 9450 | } |
| 9451 | |
| 9452 | /* Update all dprintf commands, making their command lists reflect |
| 9453 | current style settings. */ |
| 9454 | |
| 9455 | static void |
| 9456 | update_dprintf_commands (char *args, int from_tty, |
| 9457 | struct cmd_list_element *c) |
| 9458 | { |
| 9459 | struct breakpoint *b; |
| 9460 | |
| 9461 | ALL_BREAKPOINTS (b) |
| 9462 | { |
| 9463 | if (b->type == bp_dprintf) |
| 9464 | update_dprintf_command_list (b); |
| 9465 | } |
| 9466 | } |
| 9467 | |
| 9468 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
| 9469 | as textual description of the location, and COND_STRING |
| 9470 | as condition expression. */ |
| 9471 | |
| 9472 | static void |
| 9473 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
| 9474 | struct symtabs_and_lines sals, char *addr_string, |
| 9475 | char *filter, char *cond_string, |
| 9476 | char *extra_string, |
| 9477 | enum bptype type, enum bpdisp disposition, |
| 9478 | int thread, int task, int ignore_count, |
| 9479 | const struct breakpoint_ops *ops, int from_tty, |
| 9480 | int enabled, int internal, unsigned flags, |
| 9481 | int display_canonical) |
| 9482 | { |
| 9483 | int i; |
| 9484 | |
| 9485 | if (type == bp_hardware_breakpoint) |
| 9486 | { |
| 9487 | int target_resources_ok; |
| 9488 | |
| 9489 | i = hw_breakpoint_used_count (); |
| 9490 | target_resources_ok = |
| 9491 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 9492 | i + 1, 0); |
| 9493 | if (target_resources_ok == 0) |
| 9494 | error (_("No hardware breakpoint support in the target.")); |
| 9495 | else if (target_resources_ok < 0) |
| 9496 | error (_("Hardware breakpoints used exceeds limit.")); |
| 9497 | } |
| 9498 | |
| 9499 | gdb_assert (sals.nelts > 0); |
| 9500 | |
| 9501 | for (i = 0; i < sals.nelts; ++i) |
| 9502 | { |
| 9503 | struct symtab_and_line sal = sals.sals[i]; |
| 9504 | struct bp_location *loc; |
| 9505 | |
| 9506 | if (from_tty) |
| 9507 | { |
| 9508 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 9509 | if (!loc_gdbarch) |
| 9510 | loc_gdbarch = gdbarch; |
| 9511 | |
| 9512 | describe_other_breakpoints (loc_gdbarch, |
| 9513 | sal.pspace, sal.pc, sal.section, thread); |
| 9514 | } |
| 9515 | |
| 9516 | if (i == 0) |
| 9517 | { |
| 9518 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
| 9519 | b->thread = thread; |
| 9520 | b->task = task; |
| 9521 | |
| 9522 | b->cond_string = cond_string; |
| 9523 | b->extra_string = extra_string; |
| 9524 | b->ignore_count = ignore_count; |
| 9525 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 9526 | b->disposition = disposition; |
| 9527 | |
| 9528 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
| 9529 | b->loc->inserted = 1; |
| 9530 | |
| 9531 | if (type == bp_static_tracepoint) |
| 9532 | { |
| 9533 | struct tracepoint *t = (struct tracepoint *) b; |
| 9534 | struct static_tracepoint_marker marker; |
| 9535 | |
| 9536 | if (strace_marker_p (b)) |
| 9537 | { |
| 9538 | /* We already know the marker exists, otherwise, we |
| 9539 | wouldn't see a sal for it. */ |
| 9540 | char *p = &addr_string[3]; |
| 9541 | char *endp; |
| 9542 | char *marker_str; |
| 9543 | |
| 9544 | p = skip_spaces (p); |
| 9545 | |
| 9546 | endp = skip_to_space (p); |
| 9547 | |
| 9548 | marker_str = savestring (p, endp - p); |
| 9549 | t->static_trace_marker_id = marker_str; |
| 9550 | |
| 9551 | printf_filtered (_("Probed static tracepoint " |
| 9552 | "marker \"%s\"\n"), |
| 9553 | t->static_trace_marker_id); |
| 9554 | } |
| 9555 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) |
| 9556 | { |
| 9557 | t->static_trace_marker_id = xstrdup (marker.str_id); |
| 9558 | release_static_tracepoint_marker (&marker); |
| 9559 | |
| 9560 | printf_filtered (_("Probed static tracepoint " |
| 9561 | "marker \"%s\"\n"), |
| 9562 | t->static_trace_marker_id); |
| 9563 | } |
| 9564 | else |
| 9565 | warning (_("Couldn't determine the static " |
| 9566 | "tracepoint marker to probe")); |
| 9567 | } |
| 9568 | |
| 9569 | loc = b->loc; |
| 9570 | } |
| 9571 | else |
| 9572 | { |
| 9573 | loc = add_location_to_breakpoint (b, &sal); |
| 9574 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
| 9575 | loc->inserted = 1; |
| 9576 | } |
| 9577 | |
| 9578 | if (bp_loc_is_permanent (loc)) |
| 9579 | make_breakpoint_permanent (b); |
| 9580 | |
| 9581 | if (b->cond_string) |
| 9582 | { |
| 9583 | const char *arg = b->cond_string; |
| 9584 | |
| 9585 | loc->cond = parse_exp_1 (&arg, loc->address, |
| 9586 | block_for_pc (loc->address), 0); |
| 9587 | if (*arg) |
| 9588 | error (_("Garbage '%s' follows condition"), arg); |
| 9589 | } |
| 9590 | |
| 9591 | /* Dynamic printf requires and uses additional arguments on the |
| 9592 | command line, otherwise it's an error. */ |
| 9593 | if (type == bp_dprintf) |
| 9594 | { |
| 9595 | if (b->extra_string) |
| 9596 | update_dprintf_command_list (b); |
| 9597 | else |
| 9598 | error (_("Format string required")); |
| 9599 | } |
| 9600 | else if (b->extra_string) |
| 9601 | error (_("Garbage '%s' at end of command"), b->extra_string); |
| 9602 | } |
| 9603 | |
| 9604 | b->display_canonical = display_canonical; |
| 9605 | if (addr_string) |
| 9606 | b->addr_string = addr_string; |
| 9607 | else |
| 9608 | /* addr_string has to be used or breakpoint_re_set will delete |
| 9609 | me. */ |
| 9610 | b->addr_string |
| 9611 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); |
| 9612 | b->filter = filter; |
| 9613 | } |
| 9614 | |
| 9615 | static void |
| 9616 | create_breakpoint_sal (struct gdbarch *gdbarch, |
| 9617 | struct symtabs_and_lines sals, char *addr_string, |
| 9618 | char *filter, char *cond_string, |
| 9619 | char *extra_string, |
| 9620 | enum bptype type, enum bpdisp disposition, |
| 9621 | int thread, int task, int ignore_count, |
| 9622 | const struct breakpoint_ops *ops, int from_tty, |
| 9623 | int enabled, int internal, unsigned flags, |
| 9624 | int display_canonical) |
| 9625 | { |
| 9626 | struct breakpoint *b; |
| 9627 | struct cleanup *old_chain; |
| 9628 | |
| 9629 | if (is_tracepoint_type (type)) |
| 9630 | { |
| 9631 | struct tracepoint *t; |
| 9632 | |
| 9633 | t = XCNEW (struct tracepoint); |
| 9634 | b = &t->base; |
| 9635 | } |
| 9636 | else |
| 9637 | b = XNEW (struct breakpoint); |
| 9638 | |
| 9639 | old_chain = make_cleanup (xfree, b); |
| 9640 | |
| 9641 | init_breakpoint_sal (b, gdbarch, |
| 9642 | sals, addr_string, |
| 9643 | filter, cond_string, extra_string, |
| 9644 | type, disposition, |
| 9645 | thread, task, ignore_count, |
| 9646 | ops, from_tty, |
| 9647 | enabled, internal, flags, |
| 9648 | display_canonical); |
| 9649 | discard_cleanups (old_chain); |
| 9650 | |
| 9651 | install_breakpoint (internal, b, 0); |
| 9652 | } |
| 9653 | |
| 9654 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
| 9655 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] |
| 9656 | value. COND_STRING, if not NULL, specified the condition to be |
| 9657 | used for all breakpoints. Essentially the only case where |
| 9658 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded |
| 9659 | function. In that case, it's still not possible to specify |
| 9660 | separate conditions for different overloaded functions, so |
| 9661 | we take just a single condition string. |
| 9662 | |
| 9663 | NOTE: If the function succeeds, the caller is expected to cleanup |
| 9664 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
| 9665 | array contents). If the function fails (error() is called), the |
| 9666 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, |
| 9667 | COND and SALS arrays and each of those arrays contents. */ |
| 9668 | |
| 9669 | static void |
| 9670 | create_breakpoints_sal (struct gdbarch *gdbarch, |
| 9671 | struct linespec_result *canonical, |
| 9672 | char *cond_string, char *extra_string, |
| 9673 | enum bptype type, enum bpdisp disposition, |
| 9674 | int thread, int task, int ignore_count, |
| 9675 | const struct breakpoint_ops *ops, int from_tty, |
| 9676 | int enabled, int internal, unsigned flags) |
| 9677 | { |
| 9678 | int i; |
| 9679 | struct linespec_sals *lsal; |
| 9680 | |
| 9681 | if (canonical->pre_expanded) |
| 9682 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); |
| 9683 | |
| 9684 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) |
| 9685 | { |
| 9686 | /* Note that 'addr_string' can be NULL in the case of a plain |
| 9687 | 'break', without arguments. */ |
| 9688 | char *addr_string = (canonical->addr_string |
| 9689 | ? xstrdup (canonical->addr_string) |
| 9690 | : NULL); |
| 9691 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
| 9692 | struct cleanup *inner = make_cleanup (xfree, addr_string); |
| 9693 | |
| 9694 | make_cleanup (xfree, filter_string); |
| 9695 | create_breakpoint_sal (gdbarch, lsal->sals, |
| 9696 | addr_string, |
| 9697 | filter_string, |
| 9698 | cond_string, extra_string, |
| 9699 | type, disposition, |
| 9700 | thread, task, ignore_count, ops, |
| 9701 | from_tty, enabled, internal, flags, |
| 9702 | canonical->special_display); |
| 9703 | discard_cleanups (inner); |
| 9704 | } |
| 9705 | } |
| 9706 | |
| 9707 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
| 9708 | followed by conditionals. On return, SALS contains an array of SAL |
| 9709 | addresses found. ADDR_STRING contains a vector of (canonical) |
| 9710 | address strings. ADDRESS points to the end of the SAL. |
| 9711 | |
| 9712 | The array and the line spec strings are allocated on the heap, it is |
| 9713 | the caller's responsibility to free them. */ |
| 9714 | |
| 9715 | static void |
| 9716 | parse_breakpoint_sals (char **address, |
| 9717 | struct linespec_result *canonical) |
| 9718 | { |
| 9719 | /* If no arg given, or if first arg is 'if ', use the default |
| 9720 | breakpoint. */ |
| 9721 | if ((*address) == NULL |
| 9722 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) |
| 9723 | { |
| 9724 | /* The last displayed codepoint, if it's valid, is our default breakpoint |
| 9725 | address. */ |
| 9726 | if (last_displayed_sal_is_valid ()) |
| 9727 | { |
| 9728 | struct linespec_sals lsal; |
| 9729 | struct symtab_and_line sal; |
| 9730 | CORE_ADDR pc; |
| 9731 | |
| 9732 | init_sal (&sal); /* Initialize to zeroes. */ |
| 9733 | lsal.sals.sals = (struct symtab_and_line *) |
| 9734 | xmalloc (sizeof (struct symtab_and_line)); |
| 9735 | |
| 9736 | /* Set sal's pspace, pc, symtab, and line to the values |
| 9737 | corresponding to the last call to print_frame_info. |
| 9738 | Be sure to reinitialize LINE with NOTCURRENT == 0 |
| 9739 | as the breakpoint line number is inappropriate otherwise. |
| 9740 | find_pc_line would adjust PC, re-set it back. */ |
| 9741 | get_last_displayed_sal (&sal); |
| 9742 | pc = sal.pc; |
| 9743 | sal = find_pc_line (pc, 0); |
| 9744 | |
| 9745 | /* "break" without arguments is equivalent to "break *PC" |
| 9746 | where PC is the last displayed codepoint's address. So |
| 9747 | make sure to set sal.explicit_pc to prevent GDB from |
| 9748 | trying to expand the list of sals to include all other |
| 9749 | instances with the same symtab and line. */ |
| 9750 | sal.pc = pc; |
| 9751 | sal.explicit_pc = 1; |
| 9752 | |
| 9753 | lsal.sals.sals[0] = sal; |
| 9754 | lsal.sals.nelts = 1; |
| 9755 | lsal.canonical = NULL; |
| 9756 | |
| 9757 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
| 9758 | } |
| 9759 | else |
| 9760 | error (_("No default breakpoint address now.")); |
| 9761 | } |
| 9762 | else |
| 9763 | { |
| 9764 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
| 9765 | |
| 9766 | /* Force almost all breakpoints to be in terms of the |
| 9767 | current_source_symtab (which is decode_line_1's default). |
| 9768 | This should produce the results we want almost all of the |
| 9769 | time while leaving default_breakpoint_* alone. |
| 9770 | |
| 9771 | ObjC: However, don't match an Objective-C method name which |
| 9772 | may have a '+' or '-' succeeded by a '['. */ |
| 9773 | if (last_displayed_sal_is_valid () |
| 9774 | && (!cursal.symtab |
| 9775 | || ((strchr ("+-", (*address)[0]) != NULL) |
| 9776 | && ((*address)[1] != '[')))) |
| 9777 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
| 9778 | get_last_displayed_symtab (), |
| 9779 | get_last_displayed_line (), |
| 9780 | canonical, NULL, NULL); |
| 9781 | else |
| 9782 | decode_line_full (address, DECODE_LINE_FUNFIRSTLINE, |
| 9783 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
| 9784 | } |
| 9785 | } |
| 9786 | |
| 9787 | |
| 9788 | /* Convert each SAL into a real PC. Verify that the PC can be |
| 9789 | inserted as a breakpoint. If it can't throw an error. */ |
| 9790 | |
| 9791 | static void |
| 9792 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
| 9793 | { |
| 9794 | int i; |
| 9795 | |
| 9796 | for (i = 0; i < sals->nelts; i++) |
| 9797 | resolve_sal_pc (&sals->sals[i]); |
| 9798 | } |
| 9799 | |
| 9800 | /* Fast tracepoints may have restrictions on valid locations. For |
| 9801 | instance, a fast tracepoint using a jump instead of a trap will |
| 9802 | likely have to overwrite more bytes than a trap would, and so can |
| 9803 | only be placed where the instruction is longer than the jump, or a |
| 9804 | multi-instruction sequence does not have a jump into the middle of |
| 9805 | it, etc. */ |
| 9806 | |
| 9807 | static void |
| 9808 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, |
| 9809 | struct symtabs_and_lines *sals) |
| 9810 | { |
| 9811 | int i, rslt; |
| 9812 | struct symtab_and_line *sal; |
| 9813 | char *msg; |
| 9814 | struct cleanup *old_chain; |
| 9815 | |
| 9816 | for (i = 0; i < sals->nelts; i++) |
| 9817 | { |
| 9818 | struct gdbarch *sarch; |
| 9819 | |
| 9820 | sal = &sals->sals[i]; |
| 9821 | |
| 9822 | sarch = get_sal_arch (*sal); |
| 9823 | /* We fall back to GDBARCH if there is no architecture |
| 9824 | associated with SAL. */ |
| 9825 | if (sarch == NULL) |
| 9826 | sarch = gdbarch; |
| 9827 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, |
| 9828 | NULL, &msg); |
| 9829 | old_chain = make_cleanup (xfree, msg); |
| 9830 | |
| 9831 | if (!rslt) |
| 9832 | error (_("May not have a fast tracepoint at 0x%s%s"), |
| 9833 | paddress (sarch, sal->pc), (msg ? msg : "")); |
| 9834 | |
| 9835 | do_cleanups (old_chain); |
| 9836 | } |
| 9837 | } |
| 9838 | |
| 9839 | /* Issue an invalid thread ID error. */ |
| 9840 | |
| 9841 | static void ATTRIBUTE_NORETURN |
| 9842 | invalid_thread_id_error (int id) |
| 9843 | { |
| 9844 | error (_("Unknown thread %d."), id); |
| 9845 | } |
| 9846 | |
| 9847 | /* Given TOK, a string specification of condition and thread, as |
| 9848 | accepted by the 'break' command, extract the condition |
| 9849 | string and thread number and set *COND_STRING and *THREAD. |
| 9850 | PC identifies the context at which the condition should be parsed. |
| 9851 | If no condition is found, *COND_STRING is set to NULL. |
| 9852 | If no thread is found, *THREAD is set to -1. */ |
| 9853 | |
| 9854 | static void |
| 9855 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
| 9856 | char **cond_string, int *thread, int *task, |
| 9857 | char **rest) |
| 9858 | { |
| 9859 | *cond_string = NULL; |
| 9860 | *thread = -1; |
| 9861 | *task = 0; |
| 9862 | *rest = NULL; |
| 9863 | |
| 9864 | while (tok && *tok) |
| 9865 | { |
| 9866 | const char *end_tok; |
| 9867 | int toklen; |
| 9868 | const char *cond_start = NULL; |
| 9869 | const char *cond_end = NULL; |
| 9870 | |
| 9871 | tok = skip_spaces_const (tok); |
| 9872 | |
| 9873 | if ((*tok == '"' || *tok == ',') && rest) |
| 9874 | { |
| 9875 | *rest = savestring (tok, strlen (tok)); |
| 9876 | return; |
| 9877 | } |
| 9878 | |
| 9879 | end_tok = skip_to_space_const (tok); |
| 9880 | |
| 9881 | toklen = end_tok - tok; |
| 9882 | |
| 9883 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 9884 | { |
| 9885 | struct expression *expr; |
| 9886 | |
| 9887 | tok = cond_start = end_tok + 1; |
| 9888 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
| 9889 | xfree (expr); |
| 9890 | cond_end = tok; |
| 9891 | *cond_string = savestring (cond_start, cond_end - cond_start); |
| 9892 | } |
| 9893 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 9894 | { |
| 9895 | char *tmptok; |
| 9896 | |
| 9897 | tok = end_tok + 1; |
| 9898 | *thread = strtol (tok, &tmptok, 0); |
| 9899 | if (tok == tmptok) |
| 9900 | error (_("Junk after thread keyword.")); |
| 9901 | if (!valid_thread_id (*thread)) |
| 9902 | invalid_thread_id_error (*thread); |
| 9903 | tok = tmptok; |
| 9904 | } |
| 9905 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
| 9906 | { |
| 9907 | char *tmptok; |
| 9908 | |
| 9909 | tok = end_tok + 1; |
| 9910 | *task = strtol (tok, &tmptok, 0); |
| 9911 | if (tok == tmptok) |
| 9912 | error (_("Junk after task keyword.")); |
| 9913 | if (!valid_task_id (*task)) |
| 9914 | error (_("Unknown task %d."), *task); |
| 9915 | tok = tmptok; |
| 9916 | } |
| 9917 | else if (rest) |
| 9918 | { |
| 9919 | *rest = savestring (tok, strlen (tok)); |
| 9920 | return; |
| 9921 | } |
| 9922 | else |
| 9923 | error (_("Junk at end of arguments.")); |
| 9924 | } |
| 9925 | } |
| 9926 | |
| 9927 | /* Decode a static tracepoint marker spec. */ |
| 9928 | |
| 9929 | static struct symtabs_and_lines |
| 9930 | decode_static_tracepoint_spec (char **arg_p) |
| 9931 | { |
| 9932 | VEC(static_tracepoint_marker_p) *markers = NULL; |
| 9933 | struct symtabs_and_lines sals; |
| 9934 | struct cleanup *old_chain; |
| 9935 | char *p = &(*arg_p)[3]; |
| 9936 | char *endp; |
| 9937 | char *marker_str; |
| 9938 | int i; |
| 9939 | |
| 9940 | p = skip_spaces (p); |
| 9941 | |
| 9942 | endp = skip_to_space (p); |
| 9943 | |
| 9944 | marker_str = savestring (p, endp - p); |
| 9945 | old_chain = make_cleanup (xfree, marker_str); |
| 9946 | |
| 9947 | markers = target_static_tracepoint_markers_by_strid (marker_str); |
| 9948 | if (VEC_empty(static_tracepoint_marker_p, markers)) |
| 9949 | error (_("No known static tracepoint marker named %s"), marker_str); |
| 9950 | |
| 9951 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); |
| 9952 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); |
| 9953 | |
| 9954 | for (i = 0; i < sals.nelts; i++) |
| 9955 | { |
| 9956 | struct static_tracepoint_marker *marker; |
| 9957 | |
| 9958 | marker = VEC_index (static_tracepoint_marker_p, markers, i); |
| 9959 | |
| 9960 | init_sal (&sals.sals[i]); |
| 9961 | |
| 9962 | sals.sals[i] = find_pc_line (marker->address, 0); |
| 9963 | sals.sals[i].pc = marker->address; |
| 9964 | |
| 9965 | release_static_tracepoint_marker (marker); |
| 9966 | } |
| 9967 | |
| 9968 | do_cleanups (old_chain); |
| 9969 | |
| 9970 | *arg_p = endp; |
| 9971 | return sals; |
| 9972 | } |
| 9973 | |
| 9974 | /* Set a breakpoint. This function is shared between CLI and MI |
| 9975 | functions for setting a breakpoint. This function has two major |
| 9976 | modes of operations, selected by the PARSE_ARG parameter. If |
| 9977 | non-zero, the function will parse ARG, extracting location, |
| 9978 | condition, thread and extra string. Otherwise, ARG is just the |
| 9979 | breakpoint's location, with condition, thread, and extra string |
| 9980 | specified by the COND_STRING, THREAD and EXTRA_STRING parameters. |
| 9981 | If INTERNAL is non-zero, the breakpoint number will be allocated |
| 9982 | from the internal breakpoint count. Returns true if any breakpoint |
| 9983 | was created; false otherwise. */ |
| 9984 | |
| 9985 | int |
| 9986 | create_breakpoint (struct gdbarch *gdbarch, |
| 9987 | char *arg, char *cond_string, |
| 9988 | int thread, char *extra_string, |
| 9989 | int parse_arg, |
| 9990 | int tempflag, enum bptype type_wanted, |
| 9991 | int ignore_count, |
| 9992 | enum auto_boolean pending_break_support, |
| 9993 | const struct breakpoint_ops *ops, |
| 9994 | int from_tty, int enabled, int internal, |
| 9995 | unsigned flags) |
| 9996 | { |
| 9997 | volatile struct gdb_exception e; |
| 9998 | char *copy_arg = NULL; |
| 9999 | char *addr_start = arg; |
| 10000 | struct linespec_result canonical; |
| 10001 | struct cleanup *old_chain; |
| 10002 | struct cleanup *bkpt_chain = NULL; |
| 10003 | int pending = 0; |
| 10004 | int task = 0; |
| 10005 | int prev_bkpt_count = breakpoint_count; |
| 10006 | |
| 10007 | gdb_assert (ops != NULL); |
| 10008 | |
| 10009 | init_linespec_result (&canonical); |
| 10010 | |
| 10011 | TRY_CATCH (e, RETURN_MASK_ALL) |
| 10012 | { |
| 10013 | ops->create_sals_from_address (&arg, &canonical, type_wanted, |
| 10014 | addr_start, ©_arg); |
| 10015 | } |
| 10016 | |
| 10017 | /* If caller is interested in rc value from parse, set value. */ |
| 10018 | switch (e.reason) |
| 10019 | { |
| 10020 | case GDB_NO_ERROR: |
| 10021 | if (VEC_empty (linespec_sals, canonical.sals)) |
| 10022 | return 0; |
| 10023 | break; |
| 10024 | case RETURN_ERROR: |
| 10025 | switch (e.error) |
| 10026 | { |
| 10027 | case NOT_FOUND_ERROR: |
| 10028 | |
| 10029 | /* If pending breakpoint support is turned off, throw |
| 10030 | error. */ |
| 10031 | |
| 10032 | if (pending_break_support == AUTO_BOOLEAN_FALSE) |
| 10033 | throw_exception (e); |
| 10034 | |
| 10035 | exception_print (gdb_stderr, e); |
| 10036 | |
| 10037 | /* If pending breakpoint support is auto query and the user |
| 10038 | selects no, then simply return the error code. */ |
| 10039 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
| 10040 | && !nquery (_("Make %s pending on future shared library load? "), |
| 10041 | bptype_string (type_wanted))) |
| 10042 | return 0; |
| 10043 | |
| 10044 | /* At this point, either the user was queried about setting |
| 10045 | a pending breakpoint and selected yes, or pending |
| 10046 | breakpoint behavior is on and thus a pending breakpoint |
| 10047 | is defaulted on behalf of the user. */ |
| 10048 | { |
| 10049 | struct linespec_sals lsal; |
| 10050 | |
| 10051 | copy_arg = xstrdup (addr_start); |
| 10052 | lsal.canonical = xstrdup (copy_arg); |
| 10053 | lsal.sals.nelts = 1; |
| 10054 | lsal.sals.sals = XNEW (struct symtab_and_line); |
| 10055 | init_sal (&lsal.sals.sals[0]); |
| 10056 | pending = 1; |
| 10057 | VEC_safe_push (linespec_sals, canonical.sals, &lsal); |
| 10058 | } |
| 10059 | break; |
| 10060 | default: |
| 10061 | throw_exception (e); |
| 10062 | } |
| 10063 | break; |
| 10064 | default: |
| 10065 | throw_exception (e); |
| 10066 | } |
| 10067 | |
| 10068 | /* Create a chain of things that always need to be cleaned up. */ |
| 10069 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
| 10070 | |
| 10071 | /* ----------------------------- SNIP ----------------------------- |
| 10072 | Anything added to the cleanup chain beyond this point is assumed |
| 10073 | to be part of a breakpoint. If the breakpoint create succeeds |
| 10074 | then the memory is not reclaimed. */ |
| 10075 | bkpt_chain = make_cleanup (null_cleanup, 0); |
| 10076 | |
| 10077 | /* Resolve all line numbers to PC's and verify that the addresses |
| 10078 | are ok for the target. */ |
| 10079 | if (!pending) |
| 10080 | { |
| 10081 | int ix; |
| 10082 | struct linespec_sals *iter; |
| 10083 | |
| 10084 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) |
| 10085 | breakpoint_sals_to_pc (&iter->sals); |
| 10086 | } |
| 10087 | |
| 10088 | /* Fast tracepoints may have additional restrictions on location. */ |
| 10089 | if (!pending && type_wanted == bp_fast_tracepoint) |
| 10090 | { |
| 10091 | int ix; |
| 10092 | struct linespec_sals *iter; |
| 10093 | |
| 10094 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) |
| 10095 | check_fast_tracepoint_sals (gdbarch, &iter->sals); |
| 10096 | } |
| 10097 | |
| 10098 | /* Verify that condition can be parsed, before setting any |
| 10099 | breakpoints. Allocate a separate condition expression for each |
| 10100 | breakpoint. */ |
| 10101 | if (!pending) |
| 10102 | { |
| 10103 | if (parse_arg) |
| 10104 | { |
| 10105 | char *rest; |
| 10106 | struct linespec_sals *lsal; |
| 10107 | |
| 10108 | lsal = VEC_index (linespec_sals, canonical.sals, 0); |
| 10109 | |
| 10110 | /* Here we only parse 'arg' to separate condition |
| 10111 | from thread number, so parsing in context of first |
| 10112 | sal is OK. When setting the breakpoint we'll |
| 10113 | re-parse it in context of each sal. */ |
| 10114 | |
| 10115 | find_condition_and_thread (arg, lsal->sals.sals[0].pc, &cond_string, |
| 10116 | &thread, &task, &rest); |
| 10117 | if (cond_string) |
| 10118 | make_cleanup (xfree, cond_string); |
| 10119 | if (rest) |
| 10120 | make_cleanup (xfree, rest); |
| 10121 | if (rest) |
| 10122 | extra_string = rest; |
| 10123 | } |
| 10124 | else |
| 10125 | { |
| 10126 | if (*arg != '\0') |
| 10127 | error (_("Garbage '%s' at end of location"), arg); |
| 10128 | |
| 10129 | /* Create a private copy of condition string. */ |
| 10130 | if (cond_string) |
| 10131 | { |
| 10132 | cond_string = xstrdup (cond_string); |
| 10133 | make_cleanup (xfree, cond_string); |
| 10134 | } |
| 10135 | /* Create a private copy of any extra string. */ |
| 10136 | if (extra_string) |
| 10137 | { |
| 10138 | extra_string = xstrdup (extra_string); |
| 10139 | make_cleanup (xfree, extra_string); |
| 10140 | } |
| 10141 | } |
| 10142 | |
| 10143 | ops->create_breakpoints_sal (gdbarch, &canonical, |
| 10144 | cond_string, extra_string, type_wanted, |
| 10145 | tempflag ? disp_del : disp_donttouch, |
| 10146 | thread, task, ignore_count, ops, |
| 10147 | from_tty, enabled, internal, flags); |
| 10148 | } |
| 10149 | else |
| 10150 | { |
| 10151 | struct breakpoint *b; |
| 10152 | |
| 10153 | make_cleanup (xfree, copy_arg); |
| 10154 | |
| 10155 | if (is_tracepoint_type (type_wanted)) |
| 10156 | { |
| 10157 | struct tracepoint *t; |
| 10158 | |
| 10159 | t = XCNEW (struct tracepoint); |
| 10160 | b = &t->base; |
| 10161 | } |
| 10162 | else |
| 10163 | b = XNEW (struct breakpoint); |
| 10164 | |
| 10165 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); |
| 10166 | |
| 10167 | b->addr_string = copy_arg; |
| 10168 | if (parse_arg) |
| 10169 | b->cond_string = NULL; |
| 10170 | else |
| 10171 | { |
| 10172 | /* Create a private copy of condition string. */ |
| 10173 | if (cond_string) |
| 10174 | { |
| 10175 | cond_string = xstrdup (cond_string); |
| 10176 | make_cleanup (xfree, cond_string); |
| 10177 | } |
| 10178 | b->cond_string = cond_string; |
| 10179 | } |
| 10180 | b->extra_string = NULL; |
| 10181 | b->ignore_count = ignore_count; |
| 10182 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 10183 | b->condition_not_parsed = 1; |
| 10184 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 10185 | if ((type_wanted != bp_breakpoint |
| 10186 | && type_wanted != bp_hardware_breakpoint) || thread != -1) |
| 10187 | b->pspace = current_program_space; |
| 10188 | |
| 10189 | install_breakpoint (internal, b, 0); |
| 10190 | } |
| 10191 | |
| 10192 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
| 10193 | { |
| 10194 | warning (_("Multiple breakpoints were set.\nUse the " |
| 10195 | "\"delete\" command to delete unwanted breakpoints.")); |
| 10196 | prev_breakpoint_count = prev_bkpt_count; |
| 10197 | } |
| 10198 | |
| 10199 | /* That's it. Discard the cleanups for data inserted into the |
| 10200 | breakpoint. */ |
| 10201 | discard_cleanups (bkpt_chain); |
| 10202 | /* But cleanup everything else. */ |
| 10203 | do_cleanups (old_chain); |
| 10204 | |
| 10205 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
| 10206 | update_global_location_list (UGLL_MAY_INSERT); |
| 10207 | |
| 10208 | return 1; |
| 10209 | } |
| 10210 | |
| 10211 | /* Set a breakpoint. |
| 10212 | ARG is a string describing breakpoint address, |
| 10213 | condition, and thread. |
| 10214 | FLAG specifies if a breakpoint is hardware on, |
| 10215 | and if breakpoint is temporary, using BP_HARDWARE_FLAG |
| 10216 | and BP_TEMPFLAG. */ |
| 10217 | |
| 10218 | static void |
| 10219 | break_command_1 (char *arg, int flag, int from_tty) |
| 10220 | { |
| 10221 | int tempflag = flag & BP_TEMPFLAG; |
| 10222 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
| 10223 | ? bp_hardware_breakpoint |
| 10224 | : bp_breakpoint); |
| 10225 | struct breakpoint_ops *ops; |
| 10226 | const char *arg_cp = arg; |
| 10227 | |
| 10228 | /* Matching breakpoints on probes. */ |
| 10229 | if (arg && probe_linespec_to_ops (&arg_cp) != NULL) |
| 10230 | ops = &bkpt_probe_breakpoint_ops; |
| 10231 | else |
| 10232 | ops = &bkpt_breakpoint_ops; |
| 10233 | |
| 10234 | create_breakpoint (get_current_arch (), |
| 10235 | arg, |
| 10236 | NULL, 0, NULL, 1 /* parse arg */, |
| 10237 | tempflag, type_wanted, |
| 10238 | 0 /* Ignore count */, |
| 10239 | pending_break_support, |
| 10240 | ops, |
| 10241 | from_tty, |
| 10242 | 1 /* enabled */, |
| 10243 | 0 /* internal */, |
| 10244 | 0); |
| 10245 | } |
| 10246 | |
| 10247 | /* Helper function for break_command_1 and disassemble_command. */ |
| 10248 | |
| 10249 | void |
| 10250 | resolve_sal_pc (struct symtab_and_line *sal) |
| 10251 | { |
| 10252 | CORE_ADDR pc; |
| 10253 | |
| 10254 | if (sal->pc == 0 && sal->symtab != NULL) |
| 10255 | { |
| 10256 | if (!find_line_pc (sal->symtab, sal->line, &pc)) |
| 10257 | error (_("No line %d in file \"%s\"."), |
| 10258 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
| 10259 | sal->pc = pc; |
| 10260 | |
| 10261 | /* If this SAL corresponds to a breakpoint inserted using a line |
| 10262 | number, then skip the function prologue if necessary. */ |
| 10263 | if (sal->explicit_line) |
| 10264 | skip_prologue_sal (sal); |
| 10265 | } |
| 10266 | |
| 10267 | if (sal->section == 0 && sal->symtab != NULL) |
| 10268 | { |
| 10269 | const struct blockvector *bv; |
| 10270 | const struct block *b; |
| 10271 | struct symbol *sym; |
| 10272 | |
| 10273 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
| 10274 | if (bv != NULL) |
| 10275 | { |
| 10276 | sym = block_linkage_function (b); |
| 10277 | if (sym != NULL) |
| 10278 | { |
| 10279 | fixup_symbol_section (sym, sal->symtab->objfile); |
| 10280 | sal->section = SYMBOL_OBJ_SECTION (sal->symtab->objfile, sym); |
| 10281 | } |
| 10282 | else |
| 10283 | { |
| 10284 | /* It really is worthwhile to have the section, so we'll |
| 10285 | just have to look harder. This case can be executed |
| 10286 | if we have line numbers but no functions (as can |
| 10287 | happen in assembly source). */ |
| 10288 | |
| 10289 | struct bound_minimal_symbol msym; |
| 10290 | struct cleanup *old_chain = save_current_space_and_thread (); |
| 10291 | |
| 10292 | switch_to_program_space_and_thread (sal->pspace); |
| 10293 | |
| 10294 | msym = lookup_minimal_symbol_by_pc (sal->pc); |
| 10295 | if (msym.minsym) |
| 10296 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
| 10297 | |
| 10298 | do_cleanups (old_chain); |
| 10299 | } |
| 10300 | } |
| 10301 | } |
| 10302 | } |
| 10303 | |
| 10304 | void |
| 10305 | break_command (char *arg, int from_tty) |
| 10306 | { |
| 10307 | break_command_1 (arg, 0, from_tty); |
| 10308 | } |
| 10309 | |
| 10310 | void |
| 10311 | tbreak_command (char *arg, int from_tty) |
| 10312 | { |
| 10313 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
| 10314 | } |
| 10315 | |
| 10316 | static void |
| 10317 | hbreak_command (char *arg, int from_tty) |
| 10318 | { |
| 10319 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
| 10320 | } |
| 10321 | |
| 10322 | static void |
| 10323 | thbreak_command (char *arg, int from_tty) |
| 10324 | { |
| 10325 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
| 10326 | } |
| 10327 | |
| 10328 | static void |
| 10329 | stop_command (char *arg, int from_tty) |
| 10330 | { |
| 10331 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
| 10332 | Usage: stop in <function | address>\n\ |
| 10333 | stop at <line>\n")); |
| 10334 | } |
| 10335 | |
| 10336 | static void |
| 10337 | stopin_command (char *arg, int from_tty) |
| 10338 | { |
| 10339 | int badInput = 0; |
| 10340 | |
| 10341 | if (arg == (char *) NULL) |
| 10342 | badInput = 1; |
| 10343 | else if (*arg != '*') |
| 10344 | { |
| 10345 | char *argptr = arg; |
| 10346 | int hasColon = 0; |
| 10347 | |
| 10348 | /* Look for a ':'. If this is a line number specification, then |
| 10349 | say it is bad, otherwise, it should be an address or |
| 10350 | function/method name. */ |
| 10351 | while (*argptr && !hasColon) |
| 10352 | { |
| 10353 | hasColon = (*argptr == ':'); |
| 10354 | argptr++; |
| 10355 | } |
| 10356 | |
| 10357 | if (hasColon) |
| 10358 | badInput = (*argptr != ':'); /* Not a class::method */ |
| 10359 | else |
| 10360 | badInput = isdigit (*arg); /* a simple line number */ |
| 10361 | } |
| 10362 | |
| 10363 | if (badInput) |
| 10364 | printf_filtered (_("Usage: stop in <function | address>\n")); |
| 10365 | else |
| 10366 | break_command_1 (arg, 0, from_tty); |
| 10367 | } |
| 10368 | |
| 10369 | static void |
| 10370 | stopat_command (char *arg, int from_tty) |
| 10371 | { |
| 10372 | int badInput = 0; |
| 10373 | |
| 10374 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
| 10375 | badInput = 1; |
| 10376 | else |
| 10377 | { |
| 10378 | char *argptr = arg; |
| 10379 | int hasColon = 0; |
| 10380 | |
| 10381 | /* Look for a ':'. If there is a '::' then get out, otherwise |
| 10382 | it is probably a line number. */ |
| 10383 | while (*argptr && !hasColon) |
| 10384 | { |
| 10385 | hasColon = (*argptr == ':'); |
| 10386 | argptr++; |
| 10387 | } |
| 10388 | |
| 10389 | if (hasColon) |
| 10390 | badInput = (*argptr == ':'); /* we have class::method */ |
| 10391 | else |
| 10392 | badInput = !isdigit (*arg); /* not a line number */ |
| 10393 | } |
| 10394 | |
| 10395 | if (badInput) |
| 10396 | printf_filtered (_("Usage: stop at <line>\n")); |
| 10397 | else |
| 10398 | break_command_1 (arg, 0, from_tty); |
| 10399 | } |
| 10400 | |
| 10401 | /* The dynamic printf command is mostly like a regular breakpoint, but |
| 10402 | with a prewired command list consisting of a single output command, |
| 10403 | built from extra arguments supplied on the dprintf command |
| 10404 | line. */ |
| 10405 | |
| 10406 | static void |
| 10407 | dprintf_command (char *arg, int from_tty) |
| 10408 | { |
| 10409 | create_breakpoint (get_current_arch (), |
| 10410 | arg, |
| 10411 | NULL, 0, NULL, 1 /* parse arg */, |
| 10412 | 0, bp_dprintf, |
| 10413 | 0 /* Ignore count */, |
| 10414 | pending_break_support, |
| 10415 | &dprintf_breakpoint_ops, |
| 10416 | from_tty, |
| 10417 | 1 /* enabled */, |
| 10418 | 0 /* internal */, |
| 10419 | 0); |
| 10420 | } |
| 10421 | |
| 10422 | static void |
| 10423 | agent_printf_command (char *arg, int from_tty) |
| 10424 | { |
| 10425 | error (_("May only run agent-printf on the target")); |
| 10426 | } |
| 10427 | |
| 10428 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
| 10429 | ranged breakpoints. */ |
| 10430 | |
| 10431 | static int |
| 10432 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, |
| 10433 | struct address_space *aspace, |
| 10434 | CORE_ADDR bp_addr, |
| 10435 | const struct target_waitstatus *ws) |
| 10436 | { |
| 10437 | if (ws->kind != TARGET_WAITKIND_STOPPED |
| 10438 | || ws->value.sig != GDB_SIGNAL_TRAP) |
| 10439 | return 0; |
| 10440 | |
| 10441 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
| 10442 | bl->length, aspace, bp_addr); |
| 10443 | } |
| 10444 | |
| 10445 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10446 | ranged breakpoints. */ |
| 10447 | |
| 10448 | static int |
| 10449 | resources_needed_ranged_breakpoint (const struct bp_location *bl) |
| 10450 | { |
| 10451 | return target_ranged_break_num_registers (); |
| 10452 | } |
| 10453 | |
| 10454 | /* Implement the "print_it" breakpoint_ops method for |
| 10455 | ranged breakpoints. */ |
| 10456 | |
| 10457 | static enum print_stop_action |
| 10458 | print_it_ranged_breakpoint (bpstat bs) |
| 10459 | { |
| 10460 | struct breakpoint *b = bs->breakpoint_at; |
| 10461 | struct bp_location *bl = b->loc; |
| 10462 | struct ui_out *uiout = current_uiout; |
| 10463 | |
| 10464 | gdb_assert (b->type == bp_hardware_breakpoint); |
| 10465 | |
| 10466 | /* Ranged breakpoints have only one location. */ |
| 10467 | gdb_assert (bl && bl->next == NULL); |
| 10468 | |
| 10469 | annotate_breakpoint (b->number); |
| 10470 | if (b->disposition == disp_del) |
| 10471 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); |
| 10472 | else |
| 10473 | ui_out_text (uiout, "\nRanged breakpoint "); |
| 10474 | if (ui_out_is_mi_like_p (uiout)) |
| 10475 | { |
| 10476 | ui_out_field_string (uiout, "reason", |
| 10477 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 10478 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 10479 | } |
| 10480 | ui_out_field_int (uiout, "bkptno", b->number); |
| 10481 | ui_out_text (uiout, ", "); |
| 10482 | |
| 10483 | return PRINT_SRC_AND_LOC; |
| 10484 | } |
| 10485 | |
| 10486 | /* Implement the "print_one" breakpoint_ops method for |
| 10487 | ranged breakpoints. */ |
| 10488 | |
| 10489 | static void |
| 10490 | print_one_ranged_breakpoint (struct breakpoint *b, |
| 10491 | struct bp_location **last_loc) |
| 10492 | { |
| 10493 | struct bp_location *bl = b->loc; |
| 10494 | struct value_print_options opts; |
| 10495 | struct ui_out *uiout = current_uiout; |
| 10496 | |
| 10497 | /* Ranged breakpoints have only one location. */ |
| 10498 | gdb_assert (bl && bl->next == NULL); |
| 10499 | |
| 10500 | get_user_print_options (&opts); |
| 10501 | |
| 10502 | if (opts.addressprint) |
| 10503 | /* We don't print the address range here, it will be printed later |
| 10504 | by print_one_detail_ranged_breakpoint. */ |
| 10505 | ui_out_field_skip (uiout, "addr"); |
| 10506 | annotate_field (5); |
| 10507 | print_breakpoint_location (b, bl); |
| 10508 | *last_loc = bl; |
| 10509 | } |
| 10510 | |
| 10511 | /* Implement the "print_one_detail" breakpoint_ops method for |
| 10512 | ranged breakpoints. */ |
| 10513 | |
| 10514 | static void |
| 10515 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, |
| 10516 | struct ui_out *uiout) |
| 10517 | { |
| 10518 | CORE_ADDR address_start, address_end; |
| 10519 | struct bp_location *bl = b->loc; |
| 10520 | struct ui_file *stb = mem_fileopen (); |
| 10521 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); |
| 10522 | |
| 10523 | gdb_assert (bl); |
| 10524 | |
| 10525 | address_start = bl->address; |
| 10526 | address_end = address_start + bl->length - 1; |
| 10527 | |
| 10528 | ui_out_text (uiout, "\taddress range: "); |
| 10529 | fprintf_unfiltered (stb, "[%s, %s]", |
| 10530 | print_core_address (bl->gdbarch, address_start), |
| 10531 | print_core_address (bl->gdbarch, address_end)); |
| 10532 | ui_out_field_stream (uiout, "addr", stb); |
| 10533 | ui_out_text (uiout, "\n"); |
| 10534 | |
| 10535 | do_cleanups (cleanup); |
| 10536 | } |
| 10537 | |
| 10538 | /* Implement the "print_mention" breakpoint_ops method for |
| 10539 | ranged breakpoints. */ |
| 10540 | |
| 10541 | static void |
| 10542 | print_mention_ranged_breakpoint (struct breakpoint *b) |
| 10543 | { |
| 10544 | struct bp_location *bl = b->loc; |
| 10545 | struct ui_out *uiout = current_uiout; |
| 10546 | |
| 10547 | gdb_assert (bl); |
| 10548 | gdb_assert (b->type == bp_hardware_breakpoint); |
| 10549 | |
| 10550 | if (ui_out_is_mi_like_p (uiout)) |
| 10551 | return; |
| 10552 | |
| 10553 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
| 10554 | b->number, paddress (bl->gdbarch, bl->address), |
| 10555 | paddress (bl->gdbarch, bl->address + bl->length - 1)); |
| 10556 | } |
| 10557 | |
| 10558 | /* Implement the "print_recreate" breakpoint_ops method for |
| 10559 | ranged breakpoints. */ |
| 10560 | |
| 10561 | static void |
| 10562 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) |
| 10563 | { |
| 10564 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, |
| 10565 | b->addr_string_range_end); |
| 10566 | print_recreate_thread (b, fp); |
| 10567 | } |
| 10568 | |
| 10569 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ |
| 10570 | |
| 10571 | static struct breakpoint_ops ranged_breakpoint_ops; |
| 10572 | |
| 10573 | /* Find the address where the end of the breakpoint range should be |
| 10574 | placed, given the SAL of the end of the range. This is so that if |
| 10575 | the user provides a line number, the end of the range is set to the |
| 10576 | last instruction of the given line. */ |
| 10577 | |
| 10578 | static CORE_ADDR |
| 10579 | find_breakpoint_range_end (struct symtab_and_line sal) |
| 10580 | { |
| 10581 | CORE_ADDR end; |
| 10582 | |
| 10583 | /* If the user provided a PC value, use it. Otherwise, |
| 10584 | find the address of the end of the given location. */ |
| 10585 | if (sal.explicit_pc) |
| 10586 | end = sal.pc; |
| 10587 | else |
| 10588 | { |
| 10589 | int ret; |
| 10590 | CORE_ADDR start; |
| 10591 | |
| 10592 | ret = find_line_pc_range (sal, &start, &end); |
| 10593 | if (!ret) |
| 10594 | error (_("Could not find location of the end of the range.")); |
| 10595 | |
| 10596 | /* find_line_pc_range returns the start of the next line. */ |
| 10597 | end--; |
| 10598 | } |
| 10599 | |
| 10600 | return end; |
| 10601 | } |
| 10602 | |
| 10603 | /* Implement the "break-range" CLI command. */ |
| 10604 | |
| 10605 | static void |
| 10606 | break_range_command (char *arg, int from_tty) |
| 10607 | { |
| 10608 | char *arg_start, *addr_string_start, *addr_string_end; |
| 10609 | struct linespec_result canonical_start, canonical_end; |
| 10610 | int bp_count, can_use_bp, length; |
| 10611 | CORE_ADDR end; |
| 10612 | struct breakpoint *b; |
| 10613 | struct symtab_and_line sal_start, sal_end; |
| 10614 | struct cleanup *cleanup_bkpt; |
| 10615 | struct linespec_sals *lsal_start, *lsal_end; |
| 10616 | |
| 10617 | /* We don't support software ranged breakpoints. */ |
| 10618 | if (target_ranged_break_num_registers () < 0) |
| 10619 | error (_("This target does not support hardware ranged breakpoints.")); |
| 10620 | |
| 10621 | bp_count = hw_breakpoint_used_count (); |
| 10622 | bp_count += target_ranged_break_num_registers (); |
| 10623 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 10624 | bp_count, 0); |
| 10625 | if (can_use_bp < 0) |
| 10626 | error (_("Hardware breakpoints used exceeds limit.")); |
| 10627 | |
| 10628 | arg = skip_spaces (arg); |
| 10629 | if (arg == NULL || arg[0] == '\0') |
| 10630 | error(_("No address range specified.")); |
| 10631 | |
| 10632 | init_linespec_result (&canonical_start); |
| 10633 | |
| 10634 | arg_start = arg; |
| 10635 | parse_breakpoint_sals (&arg, &canonical_start); |
| 10636 | |
| 10637 | cleanup_bkpt = make_cleanup_destroy_linespec_result (&canonical_start); |
| 10638 | |
| 10639 | if (arg[0] != ',') |
| 10640 | error (_("Too few arguments.")); |
| 10641 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
| 10642 | error (_("Could not find location of the beginning of the range.")); |
| 10643 | |
| 10644 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); |
| 10645 | |
| 10646 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 |
| 10647 | || lsal_start->sals.nelts != 1) |
| 10648 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
| 10649 | |
| 10650 | sal_start = lsal_start->sals.sals[0]; |
| 10651 | addr_string_start = savestring (arg_start, arg - arg_start); |
| 10652 | make_cleanup (xfree, addr_string_start); |
| 10653 | |
| 10654 | arg++; /* Skip the comma. */ |
| 10655 | arg = skip_spaces (arg); |
| 10656 | |
| 10657 | /* Parse the end location. */ |
| 10658 | |
| 10659 | init_linespec_result (&canonical_end); |
| 10660 | arg_start = arg; |
| 10661 | |
| 10662 | /* We call decode_line_full directly here instead of using |
| 10663 | parse_breakpoint_sals because we need to specify the start location's |
| 10664 | symtab and line as the default symtab and line for the end of the |
| 10665 | range. This makes it possible to have ranges like "foo.c:27, +14", |
| 10666 | where +14 means 14 lines from the start location. */ |
| 10667 | decode_line_full (&arg, DECODE_LINE_FUNFIRSTLINE, |
| 10668 | sal_start.symtab, sal_start.line, |
| 10669 | &canonical_end, NULL, NULL); |
| 10670 | |
| 10671 | make_cleanup_destroy_linespec_result (&canonical_end); |
| 10672 | |
| 10673 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
| 10674 | error (_("Could not find location of the end of the range.")); |
| 10675 | |
| 10676 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); |
| 10677 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 |
| 10678 | || lsal_end->sals.nelts != 1) |
| 10679 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
| 10680 | |
| 10681 | sal_end = lsal_end->sals.sals[0]; |
| 10682 | addr_string_end = savestring (arg_start, arg - arg_start); |
| 10683 | make_cleanup (xfree, addr_string_end); |
| 10684 | |
| 10685 | end = find_breakpoint_range_end (sal_end); |
| 10686 | if (sal_start.pc > end) |
| 10687 | error (_("Invalid address range, end precedes start.")); |
| 10688 | |
| 10689 | length = end - sal_start.pc + 1; |
| 10690 | if (length < 0) |
| 10691 | /* Length overflowed. */ |
| 10692 | error (_("Address range too large.")); |
| 10693 | else if (length == 1) |
| 10694 | { |
| 10695 | /* This range is simple enough to be handled by |
| 10696 | the `hbreak' command. */ |
| 10697 | hbreak_command (addr_string_start, 1); |
| 10698 | |
| 10699 | do_cleanups (cleanup_bkpt); |
| 10700 | |
| 10701 | return; |
| 10702 | } |
| 10703 | |
| 10704 | /* Now set up the breakpoint. */ |
| 10705 | b = set_raw_breakpoint (get_current_arch (), sal_start, |
| 10706 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
| 10707 | set_breakpoint_count (breakpoint_count + 1); |
| 10708 | b->number = breakpoint_count; |
| 10709 | b->disposition = disp_donttouch; |
| 10710 | b->addr_string = xstrdup (addr_string_start); |
| 10711 | b->addr_string_range_end = xstrdup (addr_string_end); |
| 10712 | b->loc->length = length; |
| 10713 | |
| 10714 | do_cleanups (cleanup_bkpt); |
| 10715 | |
| 10716 | mention (b); |
| 10717 | observer_notify_breakpoint_created (b); |
| 10718 | update_global_location_list (UGLL_MAY_INSERT); |
| 10719 | } |
| 10720 | |
| 10721 | /* Return non-zero if EXP is verified as constant. Returned zero |
| 10722 | means EXP is variable. Also the constant detection may fail for |
| 10723 | some constant expressions and in such case still falsely return |
| 10724 | zero. */ |
| 10725 | |
| 10726 | static int |
| 10727 | watchpoint_exp_is_const (const struct expression *exp) |
| 10728 | { |
| 10729 | int i = exp->nelts; |
| 10730 | |
| 10731 | while (i > 0) |
| 10732 | { |
| 10733 | int oplenp, argsp; |
| 10734 | |
| 10735 | /* We are only interested in the descriptor of each element. */ |
| 10736 | operator_length (exp, i, &oplenp, &argsp); |
| 10737 | i -= oplenp; |
| 10738 | |
| 10739 | switch (exp->elts[i].opcode) |
| 10740 | { |
| 10741 | case BINOP_ADD: |
| 10742 | case BINOP_SUB: |
| 10743 | case BINOP_MUL: |
| 10744 | case BINOP_DIV: |
| 10745 | case BINOP_REM: |
| 10746 | case BINOP_MOD: |
| 10747 | case BINOP_LSH: |
| 10748 | case BINOP_RSH: |
| 10749 | case BINOP_LOGICAL_AND: |
| 10750 | case BINOP_LOGICAL_OR: |
| 10751 | case BINOP_BITWISE_AND: |
| 10752 | case BINOP_BITWISE_IOR: |
| 10753 | case BINOP_BITWISE_XOR: |
| 10754 | case BINOP_EQUAL: |
| 10755 | case BINOP_NOTEQUAL: |
| 10756 | case BINOP_LESS: |
| 10757 | case BINOP_GTR: |
| 10758 | case BINOP_LEQ: |
| 10759 | case BINOP_GEQ: |
| 10760 | case BINOP_REPEAT: |
| 10761 | case BINOP_COMMA: |
| 10762 | case BINOP_EXP: |
| 10763 | case BINOP_MIN: |
| 10764 | case BINOP_MAX: |
| 10765 | case BINOP_INTDIV: |
| 10766 | case BINOP_CONCAT: |
| 10767 | case TERNOP_COND: |
| 10768 | case TERNOP_SLICE: |
| 10769 | |
| 10770 | case OP_LONG: |
| 10771 | case OP_DOUBLE: |
| 10772 | case OP_DECFLOAT: |
| 10773 | case OP_LAST: |
| 10774 | case OP_COMPLEX: |
| 10775 | case OP_STRING: |
| 10776 | case OP_ARRAY: |
| 10777 | case OP_TYPE: |
| 10778 | case OP_TYPEOF: |
| 10779 | case OP_DECLTYPE: |
| 10780 | case OP_TYPEID: |
| 10781 | case OP_NAME: |
| 10782 | case OP_OBJC_NSSTRING: |
| 10783 | |
| 10784 | case UNOP_NEG: |
| 10785 | case UNOP_LOGICAL_NOT: |
| 10786 | case UNOP_COMPLEMENT: |
| 10787 | case UNOP_ADDR: |
| 10788 | case UNOP_HIGH: |
| 10789 | case UNOP_CAST: |
| 10790 | |
| 10791 | case UNOP_CAST_TYPE: |
| 10792 | case UNOP_REINTERPRET_CAST: |
| 10793 | case UNOP_DYNAMIC_CAST: |
| 10794 | /* Unary, binary and ternary operators: We have to check |
| 10795 | their operands. If they are constant, then so is the |
| 10796 | result of that operation. For instance, if A and B are |
| 10797 | determined to be constants, then so is "A + B". |
| 10798 | |
| 10799 | UNOP_IND is one exception to the rule above, because the |
| 10800 | value of *ADDR is not necessarily a constant, even when |
| 10801 | ADDR is. */ |
| 10802 | break; |
| 10803 | |
| 10804 | case OP_VAR_VALUE: |
| 10805 | /* Check whether the associated symbol is a constant. |
| 10806 | |
| 10807 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
| 10808 | possible that a buggy compiler could mark a variable as |
| 10809 | constant even when it is not, and TYPE_CONST would return |
| 10810 | true in this case, while SYMBOL_CLASS wouldn't. |
| 10811 | |
| 10812 | We also have to check for function symbols because they |
| 10813 | are always constant. */ |
| 10814 | { |
| 10815 | struct symbol *s = exp->elts[i + 2].symbol; |
| 10816 | |
| 10817 | if (SYMBOL_CLASS (s) != LOC_BLOCK |
| 10818 | && SYMBOL_CLASS (s) != LOC_CONST |
| 10819 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) |
| 10820 | return 0; |
| 10821 | break; |
| 10822 | } |
| 10823 | |
| 10824 | /* The default action is to return 0 because we are using |
| 10825 | the optimistic approach here: If we don't know something, |
| 10826 | then it is not a constant. */ |
| 10827 | default: |
| 10828 | return 0; |
| 10829 | } |
| 10830 | } |
| 10831 | |
| 10832 | return 1; |
| 10833 | } |
| 10834 | |
| 10835 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
| 10836 | |
| 10837 | static void |
| 10838 | dtor_watchpoint (struct breakpoint *self) |
| 10839 | { |
| 10840 | struct watchpoint *w = (struct watchpoint *) self; |
| 10841 | |
| 10842 | xfree (w->cond_exp); |
| 10843 | xfree (w->exp); |
| 10844 | xfree (w->exp_string); |
| 10845 | xfree (w->exp_string_reparse); |
| 10846 | value_free (w->val); |
| 10847 | |
| 10848 | base_breakpoint_ops.dtor (self); |
| 10849 | } |
| 10850 | |
| 10851 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
| 10852 | |
| 10853 | static void |
| 10854 | re_set_watchpoint (struct breakpoint *b) |
| 10855 | { |
| 10856 | struct watchpoint *w = (struct watchpoint *) b; |
| 10857 | |
| 10858 | /* Watchpoint can be either on expression using entirely global |
| 10859 | variables, or it can be on local variables. |
| 10860 | |
| 10861 | Watchpoints of the first kind are never auto-deleted, and even |
| 10862 | persist across program restarts. Since they can use variables |
| 10863 | from shared libraries, we need to reparse expression as libraries |
| 10864 | are loaded and unloaded. |
| 10865 | |
| 10866 | Watchpoints on local variables can also change meaning as result |
| 10867 | of solib event. For example, if a watchpoint uses both a local |
| 10868 | and a global variables in expression, it's a local watchpoint, |
| 10869 | but unloading of a shared library will make the expression |
| 10870 | invalid. This is not a very common use case, but we still |
| 10871 | re-evaluate expression, to avoid surprises to the user. |
| 10872 | |
| 10873 | Note that for local watchpoints, we re-evaluate it only if |
| 10874 | watchpoints frame id is still valid. If it's not, it means the |
| 10875 | watchpoint is out of scope and will be deleted soon. In fact, |
| 10876 | I'm not sure we'll ever be called in this case. |
| 10877 | |
| 10878 | If a local watchpoint's frame id is still valid, then |
| 10879 | w->exp_valid_block is likewise valid, and we can safely use it. |
| 10880 | |
| 10881 | Don't do anything about disabled watchpoints, since they will be |
| 10882 | reevaluated again when enabled. */ |
| 10883 | update_watchpoint (w, 1 /* reparse */); |
| 10884 | } |
| 10885 | |
| 10886 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
| 10887 | |
| 10888 | static int |
| 10889 | insert_watchpoint (struct bp_location *bl) |
| 10890 | { |
| 10891 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10892 | int length = w->exact ? 1 : bl->length; |
| 10893 | |
| 10894 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, |
| 10895 | w->cond_exp); |
| 10896 | } |
| 10897 | |
| 10898 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ |
| 10899 | |
| 10900 | static int |
| 10901 | remove_watchpoint (struct bp_location *bl) |
| 10902 | { |
| 10903 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10904 | int length = w->exact ? 1 : bl->length; |
| 10905 | |
| 10906 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, |
| 10907 | w->cond_exp); |
| 10908 | } |
| 10909 | |
| 10910 | static int |
| 10911 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
| 10912 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 10913 | const struct target_waitstatus *ws) |
| 10914 | { |
| 10915 | struct breakpoint *b = bl->owner; |
| 10916 | struct watchpoint *w = (struct watchpoint *) b; |
| 10917 | |
| 10918 | /* Continuable hardware watchpoints are treated as non-existent if the |
| 10919 | reason we stopped wasn't a hardware watchpoint (we didn't stop on |
| 10920 | some data address). Otherwise gdb won't stop on a break instruction |
| 10921 | in the code (not from a breakpoint) when a hardware watchpoint has |
| 10922 | been defined. Also skip watchpoints which we know did not trigger |
| 10923 | (did not match the data address). */ |
| 10924 | if (is_hardware_watchpoint (b) |
| 10925 | && w->watchpoint_triggered == watch_triggered_no) |
| 10926 | return 0; |
| 10927 | |
| 10928 | return 1; |
| 10929 | } |
| 10930 | |
| 10931 | static void |
| 10932 | check_status_watchpoint (bpstat bs) |
| 10933 | { |
| 10934 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
| 10935 | |
| 10936 | bpstat_check_watchpoint (bs); |
| 10937 | } |
| 10938 | |
| 10939 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10940 | hardware watchpoints. */ |
| 10941 | |
| 10942 | static int |
| 10943 | resources_needed_watchpoint (const struct bp_location *bl) |
| 10944 | { |
| 10945 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10946 | int length = w->exact? 1 : bl->length; |
| 10947 | |
| 10948 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
| 10949 | } |
| 10950 | |
| 10951 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
| 10952 | hardware watchpoints. */ |
| 10953 | |
| 10954 | static int |
| 10955 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
| 10956 | { |
| 10957 | /* Read and access watchpoints only work with hardware support. */ |
| 10958 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; |
| 10959 | } |
| 10960 | |
| 10961 | static enum print_stop_action |
| 10962 | print_it_watchpoint (bpstat bs) |
| 10963 | { |
| 10964 | struct cleanup *old_chain; |
| 10965 | struct breakpoint *b; |
| 10966 | struct ui_file *stb; |
| 10967 | enum print_stop_action result; |
| 10968 | struct watchpoint *w; |
| 10969 | struct ui_out *uiout = current_uiout; |
| 10970 | |
| 10971 | gdb_assert (bs->bp_location_at != NULL); |
| 10972 | |
| 10973 | b = bs->breakpoint_at; |
| 10974 | w = (struct watchpoint *) b; |
| 10975 | |
| 10976 | stb = mem_fileopen (); |
| 10977 | old_chain = make_cleanup_ui_file_delete (stb); |
| 10978 | |
| 10979 | switch (b->type) |
| 10980 | { |
| 10981 | case bp_watchpoint: |
| 10982 | case bp_hardware_watchpoint: |
| 10983 | annotate_watchpoint (b->number); |
| 10984 | if (ui_out_is_mi_like_p (uiout)) |
| 10985 | ui_out_field_string |
| 10986 | (uiout, "reason", |
| 10987 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 10988 | mention (b); |
| 10989 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 10990 | ui_out_text (uiout, "\nOld value = "); |
| 10991 | watchpoint_value_print (bs->old_val, stb); |
| 10992 | ui_out_field_stream (uiout, "old", stb); |
| 10993 | ui_out_text (uiout, "\nNew value = "); |
| 10994 | watchpoint_value_print (w->val, stb); |
| 10995 | ui_out_field_stream (uiout, "new", stb); |
| 10996 | ui_out_text (uiout, "\n"); |
| 10997 | /* More than one watchpoint may have been triggered. */ |
| 10998 | result = PRINT_UNKNOWN; |
| 10999 | break; |
| 11000 | |
| 11001 | case bp_read_watchpoint: |
| 11002 | if (ui_out_is_mi_like_p (uiout)) |
| 11003 | ui_out_field_string |
| 11004 | (uiout, "reason", |
| 11005 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 11006 | mention (b); |
| 11007 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 11008 | ui_out_text (uiout, "\nValue = "); |
| 11009 | watchpoint_value_print (w->val, stb); |
| 11010 | ui_out_field_stream (uiout, "value", stb); |
| 11011 | ui_out_text (uiout, "\n"); |
| 11012 | result = PRINT_UNKNOWN; |
| 11013 | break; |
| 11014 | |
| 11015 | case bp_access_watchpoint: |
| 11016 | if (bs->old_val != NULL) |
| 11017 | { |
| 11018 | annotate_watchpoint (b->number); |
| 11019 | if (ui_out_is_mi_like_p (uiout)) |
| 11020 | ui_out_field_string |
| 11021 | (uiout, "reason", |
| 11022 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 11023 | mention (b); |
| 11024 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 11025 | ui_out_text (uiout, "\nOld value = "); |
| 11026 | watchpoint_value_print (bs->old_val, stb); |
| 11027 | ui_out_field_stream (uiout, "old", stb); |
| 11028 | ui_out_text (uiout, "\nNew value = "); |
| 11029 | } |
| 11030 | else |
| 11031 | { |
| 11032 | mention (b); |
| 11033 | if (ui_out_is_mi_like_p (uiout)) |
| 11034 | ui_out_field_string |
| 11035 | (uiout, "reason", |
| 11036 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 11037 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 11038 | ui_out_text (uiout, "\nValue = "); |
| 11039 | } |
| 11040 | watchpoint_value_print (w->val, stb); |
| 11041 | ui_out_field_stream (uiout, "new", stb); |
| 11042 | ui_out_text (uiout, "\n"); |
| 11043 | result = PRINT_UNKNOWN; |
| 11044 | break; |
| 11045 | default: |
| 11046 | result = PRINT_UNKNOWN; |
| 11047 | } |
| 11048 | |
| 11049 | do_cleanups (old_chain); |
| 11050 | return result; |
| 11051 | } |
| 11052 | |
| 11053 | /* Implement the "print_mention" breakpoint_ops method for hardware |
| 11054 | watchpoints. */ |
| 11055 | |
| 11056 | static void |
| 11057 | print_mention_watchpoint (struct breakpoint *b) |
| 11058 | { |
| 11059 | struct cleanup *ui_out_chain; |
| 11060 | struct watchpoint *w = (struct watchpoint *) b; |
| 11061 | struct ui_out *uiout = current_uiout; |
| 11062 | |
| 11063 | switch (b->type) |
| 11064 | { |
| 11065 | case bp_watchpoint: |
| 11066 | ui_out_text (uiout, "Watchpoint "); |
| 11067 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 11068 | break; |
| 11069 | case bp_hardware_watchpoint: |
| 11070 | ui_out_text (uiout, "Hardware watchpoint "); |
| 11071 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 11072 | break; |
| 11073 | case bp_read_watchpoint: |
| 11074 | ui_out_text (uiout, "Hardware read watchpoint "); |
| 11075 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
| 11076 | break; |
| 11077 | case bp_access_watchpoint: |
| 11078 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); |
| 11079 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
| 11080 | break; |
| 11081 | default: |
| 11082 | internal_error (__FILE__, __LINE__, |
| 11083 | _("Invalid hardware watchpoint type.")); |
| 11084 | } |
| 11085 | |
| 11086 | ui_out_field_int (uiout, "number", b->number); |
| 11087 | ui_out_text (uiout, ": "); |
| 11088 | ui_out_field_string (uiout, "exp", w->exp_string); |
| 11089 | do_cleanups (ui_out_chain); |
| 11090 | } |
| 11091 | |
| 11092 | /* Implement the "print_recreate" breakpoint_ops method for |
| 11093 | watchpoints. */ |
| 11094 | |
| 11095 | static void |
| 11096 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) |
| 11097 | { |
| 11098 | struct watchpoint *w = (struct watchpoint *) b; |
| 11099 | |
| 11100 | switch (b->type) |
| 11101 | { |
| 11102 | case bp_watchpoint: |
| 11103 | case bp_hardware_watchpoint: |
| 11104 | fprintf_unfiltered (fp, "watch"); |
| 11105 | break; |
| 11106 | case bp_read_watchpoint: |
| 11107 | fprintf_unfiltered (fp, "rwatch"); |
| 11108 | break; |
| 11109 | case bp_access_watchpoint: |
| 11110 | fprintf_unfiltered (fp, "awatch"); |
| 11111 | break; |
| 11112 | default: |
| 11113 | internal_error (__FILE__, __LINE__, |
| 11114 | _("Invalid watchpoint type.")); |
| 11115 | } |
| 11116 | |
| 11117 | fprintf_unfiltered (fp, " %s", w->exp_string); |
| 11118 | print_recreate_thread (b, fp); |
| 11119 | } |
| 11120 | |
| 11121 | /* Implement the "explains_signal" breakpoint_ops method for |
| 11122 | watchpoints. */ |
| 11123 | |
| 11124 | static int |
| 11125 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
| 11126 | { |
| 11127 | /* A software watchpoint cannot cause a signal other than |
| 11128 | GDB_SIGNAL_TRAP. */ |
| 11129 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) |
| 11130 | return 0; |
| 11131 | |
| 11132 | return 1; |
| 11133 | } |
| 11134 | |
| 11135 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
| 11136 | |
| 11137 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
| 11138 | |
| 11139 | /* Implement the "insert" breakpoint_ops method for |
| 11140 | masked hardware watchpoints. */ |
| 11141 | |
| 11142 | static int |
| 11143 | insert_masked_watchpoint (struct bp_location *bl) |
| 11144 | { |
| 11145 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 11146 | |
| 11147 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, |
| 11148 | bl->watchpoint_type); |
| 11149 | } |
| 11150 | |
| 11151 | /* Implement the "remove" breakpoint_ops method for |
| 11152 | masked hardware watchpoints. */ |
| 11153 | |
| 11154 | static int |
| 11155 | remove_masked_watchpoint (struct bp_location *bl) |
| 11156 | { |
| 11157 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 11158 | |
| 11159 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, |
| 11160 | bl->watchpoint_type); |
| 11161 | } |
| 11162 | |
| 11163 | /* Implement the "resources_needed" breakpoint_ops method for |
| 11164 | masked hardware watchpoints. */ |
| 11165 | |
| 11166 | static int |
| 11167 | resources_needed_masked_watchpoint (const struct bp_location *bl) |
| 11168 | { |
| 11169 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 11170 | |
| 11171 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); |
| 11172 | } |
| 11173 | |
| 11174 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
| 11175 | masked hardware watchpoints. */ |
| 11176 | |
| 11177 | static int |
| 11178 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) |
| 11179 | { |
| 11180 | return 0; |
| 11181 | } |
| 11182 | |
| 11183 | /* Implement the "print_it" breakpoint_ops method for |
| 11184 | masked hardware watchpoints. */ |
| 11185 | |
| 11186 | static enum print_stop_action |
| 11187 | print_it_masked_watchpoint (bpstat bs) |
| 11188 | { |
| 11189 | struct breakpoint *b = bs->breakpoint_at; |
| 11190 | struct ui_out *uiout = current_uiout; |
| 11191 | |
| 11192 | /* Masked watchpoints have only one location. */ |
| 11193 | gdb_assert (b->loc && b->loc->next == NULL); |
| 11194 | |
| 11195 | switch (b->type) |
| 11196 | { |
| 11197 | case bp_hardware_watchpoint: |
| 11198 | annotate_watchpoint (b->number); |
| 11199 | if (ui_out_is_mi_like_p (uiout)) |
| 11200 | ui_out_field_string |
| 11201 | (uiout, "reason", |
| 11202 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 11203 | break; |
| 11204 | |
| 11205 | case bp_read_watchpoint: |
| 11206 | if (ui_out_is_mi_like_p (uiout)) |
| 11207 | ui_out_field_string |
| 11208 | (uiout, "reason", |
| 11209 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 11210 | break; |
| 11211 | |
| 11212 | case bp_access_watchpoint: |
| 11213 | if (ui_out_is_mi_like_p (uiout)) |
| 11214 | ui_out_field_string |
| 11215 | (uiout, "reason", |
| 11216 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 11217 | break; |
| 11218 | default: |
| 11219 | internal_error (__FILE__, __LINE__, |
| 11220 | _("Invalid hardware watchpoint type.")); |
| 11221 | } |
| 11222 | |
| 11223 | mention (b); |
| 11224 | ui_out_text (uiout, _("\n\ |
| 11225 | Check the underlying instruction at PC for the memory\n\ |
| 11226 | address and value which triggered this watchpoint.\n")); |
| 11227 | ui_out_text (uiout, "\n"); |
| 11228 | |
| 11229 | /* More than one watchpoint may have been triggered. */ |
| 11230 | return PRINT_UNKNOWN; |
| 11231 | } |
| 11232 | |
| 11233 | /* Implement the "print_one_detail" breakpoint_ops method for |
| 11234 | masked hardware watchpoints. */ |
| 11235 | |
| 11236 | static void |
| 11237 | print_one_detail_masked_watchpoint (const struct breakpoint *b, |
| 11238 | struct ui_out *uiout) |
| 11239 | { |
| 11240 | struct watchpoint *w = (struct watchpoint *) b; |
| 11241 | |
| 11242 | /* Masked watchpoints have only one location. */ |
| 11243 | gdb_assert (b->loc && b->loc->next == NULL); |
| 11244 | |
| 11245 | ui_out_text (uiout, "\tmask "); |
| 11246 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
| 11247 | ui_out_text (uiout, "\n"); |
| 11248 | } |
| 11249 | |
| 11250 | /* Implement the "print_mention" breakpoint_ops method for |
| 11251 | masked hardware watchpoints. */ |
| 11252 | |
| 11253 | static void |
| 11254 | print_mention_masked_watchpoint (struct breakpoint *b) |
| 11255 | { |
| 11256 | struct watchpoint *w = (struct watchpoint *) b; |
| 11257 | struct ui_out *uiout = current_uiout; |
| 11258 | struct cleanup *ui_out_chain; |
| 11259 | |
| 11260 | switch (b->type) |
| 11261 | { |
| 11262 | case bp_hardware_watchpoint: |
| 11263 | ui_out_text (uiout, "Masked hardware watchpoint "); |
| 11264 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 11265 | break; |
| 11266 | case bp_read_watchpoint: |
| 11267 | ui_out_text (uiout, "Masked hardware read watchpoint "); |
| 11268 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
| 11269 | break; |
| 11270 | case bp_access_watchpoint: |
| 11271 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); |
| 11272 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
| 11273 | break; |
| 11274 | default: |
| 11275 | internal_error (__FILE__, __LINE__, |
| 11276 | _("Invalid hardware watchpoint type.")); |
| 11277 | } |
| 11278 | |
| 11279 | ui_out_field_int (uiout, "number", b->number); |
| 11280 | ui_out_text (uiout, ": "); |
| 11281 | ui_out_field_string (uiout, "exp", w->exp_string); |
| 11282 | do_cleanups (ui_out_chain); |
| 11283 | } |
| 11284 | |
| 11285 | /* Implement the "print_recreate" breakpoint_ops method for |
| 11286 | masked hardware watchpoints. */ |
| 11287 | |
| 11288 | static void |
| 11289 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) |
| 11290 | { |
| 11291 | struct watchpoint *w = (struct watchpoint *) b; |
| 11292 | char tmp[40]; |
| 11293 | |
| 11294 | switch (b->type) |
| 11295 | { |
| 11296 | case bp_hardware_watchpoint: |
| 11297 | fprintf_unfiltered (fp, "watch"); |
| 11298 | break; |
| 11299 | case bp_read_watchpoint: |
| 11300 | fprintf_unfiltered (fp, "rwatch"); |
| 11301 | break; |
| 11302 | case bp_access_watchpoint: |
| 11303 | fprintf_unfiltered (fp, "awatch"); |
| 11304 | break; |
| 11305 | default: |
| 11306 | internal_error (__FILE__, __LINE__, |
| 11307 | _("Invalid hardware watchpoint type.")); |
| 11308 | } |
| 11309 | |
| 11310 | sprintf_vma (tmp, w->hw_wp_mask); |
| 11311 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); |
| 11312 | print_recreate_thread (b, fp); |
| 11313 | } |
| 11314 | |
| 11315 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ |
| 11316 | |
| 11317 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
| 11318 | |
| 11319 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ |
| 11320 | |
| 11321 | static int |
| 11322 | is_masked_watchpoint (const struct breakpoint *b) |
| 11323 | { |
| 11324 | return b->ops == &masked_watchpoint_breakpoint_ops; |
| 11325 | } |
| 11326 | |
| 11327 | /* accessflag: hw_write: watch write, |
| 11328 | hw_read: watch read, |
| 11329 | hw_access: watch access (read or write) */ |
| 11330 | static void |
| 11331 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
| 11332 | int just_location, int internal) |
| 11333 | { |
| 11334 | volatile struct gdb_exception e; |
| 11335 | struct breakpoint *b, *scope_breakpoint = NULL; |
| 11336 | struct expression *exp; |
| 11337 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
| 11338 | struct value *val, *mark, *result; |
| 11339 | int saved_bitpos = 0, saved_bitsize = 0; |
| 11340 | struct frame_info *frame; |
| 11341 | const char *exp_start = NULL; |
| 11342 | const char *exp_end = NULL; |
| 11343 | const char *tok, *end_tok; |
| 11344 | int toklen = -1; |
| 11345 | const char *cond_start = NULL; |
| 11346 | const char *cond_end = NULL; |
| 11347 | enum bptype bp_type; |
| 11348 | int thread = -1; |
| 11349 | int pc = 0; |
| 11350 | /* Flag to indicate whether we are going to use masks for |
| 11351 | the hardware watchpoint. */ |
| 11352 | int use_mask = 0; |
| 11353 | CORE_ADDR mask = 0; |
| 11354 | struct watchpoint *w; |
| 11355 | char *expression; |
| 11356 | struct cleanup *back_to; |
| 11357 | |
| 11358 | /* Make sure that we actually have parameters to parse. */ |
| 11359 | if (arg != NULL && arg[0] != '\0') |
| 11360 | { |
| 11361 | const char *value_start; |
| 11362 | |
| 11363 | exp_end = arg + strlen (arg); |
| 11364 | |
| 11365 | /* Look for "parameter value" pairs at the end |
| 11366 | of the arguments string. */ |
| 11367 | for (tok = exp_end - 1; tok > arg; tok--) |
| 11368 | { |
| 11369 | /* Skip whitespace at the end of the argument list. */ |
| 11370 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 11371 | tok--; |
| 11372 | |
| 11373 | /* Find the beginning of the last token. |
| 11374 | This is the value of the parameter. */ |
| 11375 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 11376 | tok--; |
| 11377 | value_start = tok + 1; |
| 11378 | |
| 11379 | /* Skip whitespace. */ |
| 11380 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 11381 | tok--; |
| 11382 | |
| 11383 | end_tok = tok; |
| 11384 | |
| 11385 | /* Find the beginning of the second to last token. |
| 11386 | This is the parameter itself. */ |
| 11387 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 11388 | tok--; |
| 11389 | tok++; |
| 11390 | toklen = end_tok - tok + 1; |
| 11391 | |
| 11392 | if (toklen == 6 && !strncmp (tok, "thread", 6)) |
| 11393 | { |
| 11394 | /* At this point we've found a "thread" token, which means |
| 11395 | the user is trying to set a watchpoint that triggers |
| 11396 | only in a specific thread. */ |
| 11397 | char *endp; |
| 11398 | |
| 11399 | if (thread != -1) |
| 11400 | error(_("You can specify only one thread.")); |
| 11401 | |
| 11402 | /* Extract the thread ID from the next token. */ |
| 11403 | thread = strtol (value_start, &endp, 0); |
| 11404 | |
| 11405 | /* Check if the user provided a valid numeric value for the |
| 11406 | thread ID. */ |
| 11407 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
| 11408 | error (_("Invalid thread ID specification %s."), value_start); |
| 11409 | |
| 11410 | /* Check if the thread actually exists. */ |
| 11411 | if (!valid_thread_id (thread)) |
| 11412 | invalid_thread_id_error (thread); |
| 11413 | } |
| 11414 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) |
| 11415 | { |
| 11416 | /* We've found a "mask" token, which means the user wants to |
| 11417 | create a hardware watchpoint that is going to have the mask |
| 11418 | facility. */ |
| 11419 | struct value *mask_value, *mark; |
| 11420 | |
| 11421 | if (use_mask) |
| 11422 | error(_("You can specify only one mask.")); |
| 11423 | |
| 11424 | use_mask = just_location = 1; |
| 11425 | |
| 11426 | mark = value_mark (); |
| 11427 | mask_value = parse_to_comma_and_eval (&value_start); |
| 11428 | mask = value_as_address (mask_value); |
| 11429 | value_free_to_mark (mark); |
| 11430 | } |
| 11431 | else |
| 11432 | /* We didn't recognize what we found. We should stop here. */ |
| 11433 | break; |
| 11434 | |
| 11435 | /* Truncate the string and get rid of the "parameter value" pair before |
| 11436 | the arguments string is parsed by the parse_exp_1 function. */ |
| 11437 | exp_end = tok; |
| 11438 | } |
| 11439 | } |
| 11440 | else |
| 11441 | exp_end = arg; |
| 11442 | |
| 11443 | /* Parse the rest of the arguments. From here on out, everything |
| 11444 | is in terms of a newly allocated string instead of the original |
| 11445 | ARG. */ |
| 11446 | innermost_block = NULL; |
| 11447 | expression = savestring (arg, exp_end - arg); |
| 11448 | back_to = make_cleanup (xfree, expression); |
| 11449 | exp_start = arg = expression; |
| 11450 | exp = parse_exp_1 (&arg, 0, 0, 0); |
| 11451 | exp_end = arg; |
| 11452 | /* Remove trailing whitespace from the expression before saving it. |
| 11453 | This makes the eventual display of the expression string a bit |
| 11454 | prettier. */ |
| 11455 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) |
| 11456 | --exp_end; |
| 11457 | |
| 11458 | /* Checking if the expression is not constant. */ |
| 11459 | if (watchpoint_exp_is_const (exp)) |
| 11460 | { |
| 11461 | int len; |
| 11462 | |
| 11463 | len = exp_end - exp_start; |
| 11464 | while (len > 0 && isspace (exp_start[len - 1])) |
| 11465 | len--; |
| 11466 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); |
| 11467 | } |
| 11468 | |
| 11469 | exp_valid_block = innermost_block; |
| 11470 | mark = value_mark (); |
| 11471 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
| 11472 | |
| 11473 | if (val != NULL && just_location) |
| 11474 | { |
| 11475 | saved_bitpos = value_bitpos (val); |
| 11476 | saved_bitsize = value_bitsize (val); |
| 11477 | } |
| 11478 | |
| 11479 | if (just_location) |
| 11480 | { |
| 11481 | int ret; |
| 11482 | |
| 11483 | exp_valid_block = NULL; |
| 11484 | val = value_addr (result); |
| 11485 | release_value (val); |
| 11486 | value_free_to_mark (mark); |
| 11487 | |
| 11488 | if (use_mask) |
| 11489 | { |
| 11490 | ret = target_masked_watch_num_registers (value_as_address (val), |
| 11491 | mask); |
| 11492 | if (ret == -1) |
| 11493 | error (_("This target does not support masked watchpoints.")); |
| 11494 | else if (ret == -2) |
| 11495 | error (_("Invalid mask or memory region.")); |
| 11496 | } |
| 11497 | } |
| 11498 | else if (val != NULL) |
| 11499 | release_value (val); |
| 11500 | |
| 11501 | tok = skip_spaces_const (arg); |
| 11502 | end_tok = skip_to_space_const (tok); |
| 11503 | |
| 11504 | toklen = end_tok - tok; |
| 11505 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 11506 | { |
| 11507 | struct expression *cond; |
| 11508 | |
| 11509 | innermost_block = NULL; |
| 11510 | tok = cond_start = end_tok + 1; |
| 11511 | cond = parse_exp_1 (&tok, 0, 0, 0); |
| 11512 | |
| 11513 | /* The watchpoint expression may not be local, but the condition |
| 11514 | may still be. E.g.: `watch global if local > 0'. */ |
| 11515 | cond_exp_valid_block = innermost_block; |
| 11516 | |
| 11517 | xfree (cond); |
| 11518 | cond_end = tok; |
| 11519 | } |
| 11520 | if (*tok) |
| 11521 | error (_("Junk at end of command.")); |
| 11522 | |
| 11523 | frame = block_innermost_frame (exp_valid_block); |
| 11524 | |
| 11525 | /* If the expression is "local", then set up a "watchpoint scope" |
| 11526 | breakpoint at the point where we've left the scope of the watchpoint |
| 11527 | expression. Create the scope breakpoint before the watchpoint, so |
| 11528 | that we will encounter it first in bpstat_stop_status. */ |
| 11529 | if (exp_valid_block && frame) |
| 11530 | { |
| 11531 | if (frame_id_p (frame_unwind_caller_id (frame))) |
| 11532 | { |
| 11533 | scope_breakpoint |
| 11534 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
| 11535 | frame_unwind_caller_pc (frame), |
| 11536 | bp_watchpoint_scope, |
| 11537 | &momentary_breakpoint_ops); |
| 11538 | |
| 11539 | scope_breakpoint->enable_state = bp_enabled; |
| 11540 | |
| 11541 | /* Automatically delete the breakpoint when it hits. */ |
| 11542 | scope_breakpoint->disposition = disp_del; |
| 11543 | |
| 11544 | /* Only break in the proper frame (help with recursion). */ |
| 11545 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); |
| 11546 | |
| 11547 | /* Set the address at which we will stop. */ |
| 11548 | scope_breakpoint->loc->gdbarch |
| 11549 | = frame_unwind_caller_arch (frame); |
| 11550 | scope_breakpoint->loc->requested_address |
| 11551 | = frame_unwind_caller_pc (frame); |
| 11552 | scope_breakpoint->loc->address |
| 11553 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
| 11554 | scope_breakpoint->loc->requested_address, |
| 11555 | scope_breakpoint->type); |
| 11556 | } |
| 11557 | } |
| 11558 | |
| 11559 | /* Now set up the breakpoint. We create all watchpoints as hardware |
| 11560 | watchpoints here even if hardware watchpoints are turned off, a call |
| 11561 | to update_watchpoint later in this function will cause the type to |
| 11562 | drop back to bp_watchpoint (software watchpoint) if required. */ |
| 11563 | |
| 11564 | if (accessflag == hw_read) |
| 11565 | bp_type = bp_read_watchpoint; |
| 11566 | else if (accessflag == hw_access) |
| 11567 | bp_type = bp_access_watchpoint; |
| 11568 | else |
| 11569 | bp_type = bp_hardware_watchpoint; |
| 11570 | |
| 11571 | w = XCNEW (struct watchpoint); |
| 11572 | b = &w->base; |
| 11573 | if (use_mask) |
| 11574 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
| 11575 | &masked_watchpoint_breakpoint_ops); |
| 11576 | else |
| 11577 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
| 11578 | &watchpoint_breakpoint_ops); |
| 11579 | b->thread = thread; |
| 11580 | b->disposition = disp_donttouch; |
| 11581 | b->pspace = current_program_space; |
| 11582 | w->exp = exp; |
| 11583 | w->exp_valid_block = exp_valid_block; |
| 11584 | w->cond_exp_valid_block = cond_exp_valid_block; |
| 11585 | if (just_location) |
| 11586 | { |
| 11587 | struct type *t = value_type (val); |
| 11588 | CORE_ADDR addr = value_as_address (val); |
| 11589 | char *name; |
| 11590 | |
| 11591 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); |
| 11592 | name = type_to_string (t); |
| 11593 | |
| 11594 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
| 11595 | core_addr_to_string (addr)); |
| 11596 | xfree (name); |
| 11597 | |
| 11598 | w->exp_string = xstrprintf ("-location %.*s", |
| 11599 | (int) (exp_end - exp_start), exp_start); |
| 11600 | |
| 11601 | /* The above expression is in C. */ |
| 11602 | b->language = language_c; |
| 11603 | } |
| 11604 | else |
| 11605 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
| 11606 | |
| 11607 | if (use_mask) |
| 11608 | { |
| 11609 | w->hw_wp_mask = mask; |
| 11610 | } |
| 11611 | else |
| 11612 | { |
| 11613 | w->val = val; |
| 11614 | w->val_bitpos = saved_bitpos; |
| 11615 | w->val_bitsize = saved_bitsize; |
| 11616 | w->val_valid = 1; |
| 11617 | } |
| 11618 | |
| 11619 | if (cond_start) |
| 11620 | b->cond_string = savestring (cond_start, cond_end - cond_start); |
| 11621 | else |
| 11622 | b->cond_string = 0; |
| 11623 | |
| 11624 | if (frame) |
| 11625 | { |
| 11626 | w->watchpoint_frame = get_frame_id (frame); |
| 11627 | w->watchpoint_thread = inferior_ptid; |
| 11628 | } |
| 11629 | else |
| 11630 | { |
| 11631 | w->watchpoint_frame = null_frame_id; |
| 11632 | w->watchpoint_thread = null_ptid; |
| 11633 | } |
| 11634 | |
| 11635 | if (scope_breakpoint != NULL) |
| 11636 | { |
| 11637 | /* The scope breakpoint is related to the watchpoint. We will |
| 11638 | need to act on them together. */ |
| 11639 | b->related_breakpoint = scope_breakpoint; |
| 11640 | scope_breakpoint->related_breakpoint = b; |
| 11641 | } |
| 11642 | |
| 11643 | if (!just_location) |
| 11644 | value_free_to_mark (mark); |
| 11645 | |
| 11646 | TRY_CATCH (e, RETURN_MASK_ALL) |
| 11647 | { |
| 11648 | /* Finally update the new watchpoint. This creates the locations |
| 11649 | that should be inserted. */ |
| 11650 | update_watchpoint (w, 1); |
| 11651 | } |
| 11652 | if (e.reason < 0) |
| 11653 | { |
| 11654 | delete_breakpoint (b); |
| 11655 | throw_exception (e); |
| 11656 | } |
| 11657 | |
| 11658 | install_breakpoint (internal, b, 1); |
| 11659 | do_cleanups (back_to); |
| 11660 | } |
| 11661 | |
| 11662 | /* Return count of debug registers needed to watch the given expression. |
| 11663 | If the watchpoint cannot be handled in hardware return zero. */ |
| 11664 | |
| 11665 | static int |
| 11666 | can_use_hardware_watchpoint (struct value *v) |
| 11667 | { |
| 11668 | int found_memory_cnt = 0; |
| 11669 | struct value *head = v; |
| 11670 | |
| 11671 | /* Did the user specifically forbid us to use hardware watchpoints? */ |
| 11672 | if (!can_use_hw_watchpoints) |
| 11673 | return 0; |
| 11674 | |
| 11675 | /* Make sure that the value of the expression depends only upon |
| 11676 | memory contents, and values computed from them within GDB. If we |
| 11677 | find any register references or function calls, we can't use a |
| 11678 | hardware watchpoint. |
| 11679 | |
| 11680 | The idea here is that evaluating an expression generates a series |
| 11681 | of values, one holding the value of every subexpression. (The |
| 11682 | expression a*b+c has five subexpressions: a, b, a*b, c, and |
| 11683 | a*b+c.) GDB's values hold almost enough information to establish |
| 11684 | the criteria given above --- they identify memory lvalues, |
| 11685 | register lvalues, computed values, etcetera. So we can evaluate |
| 11686 | the expression, and then scan the chain of values that leaves |
| 11687 | behind to decide whether we can detect any possible change to the |
| 11688 | expression's final value using only hardware watchpoints. |
| 11689 | |
| 11690 | However, I don't think that the values returned by inferior |
| 11691 | function calls are special in any way. So this function may not |
| 11692 | notice that an expression involving an inferior function call |
| 11693 | can't be watched with hardware watchpoints. FIXME. */ |
| 11694 | for (; v; v = value_next (v)) |
| 11695 | { |
| 11696 | if (VALUE_LVAL (v) == lval_memory) |
| 11697 | { |
| 11698 | if (v != head && value_lazy (v)) |
| 11699 | /* A lazy memory lvalue in the chain is one that GDB never |
| 11700 | needed to fetch; we either just used its address (e.g., |
| 11701 | `a' in `a.b') or we never needed it at all (e.g., `a' |
| 11702 | in `a,b'). This doesn't apply to HEAD; if that is |
| 11703 | lazy then it was not readable, but watch it anyway. */ |
| 11704 | ; |
| 11705 | else |
| 11706 | { |
| 11707 | /* Ahh, memory we actually used! Check if we can cover |
| 11708 | it with hardware watchpoints. */ |
| 11709 | struct type *vtype = check_typedef (value_type (v)); |
| 11710 | |
| 11711 | /* We only watch structs and arrays if user asked for it |
| 11712 | explicitly, never if they just happen to appear in a |
| 11713 | middle of some value chain. */ |
| 11714 | if (v == head |
| 11715 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 11716 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 11717 | { |
| 11718 | CORE_ADDR vaddr = value_address (v); |
| 11719 | int len; |
| 11720 | int num_regs; |
| 11721 | |
| 11722 | len = (target_exact_watchpoints |
| 11723 | && is_scalar_type_recursive (vtype))? |
| 11724 | 1 : TYPE_LENGTH (value_type (v)); |
| 11725 | |
| 11726 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
| 11727 | if (!num_regs) |
| 11728 | return 0; |
| 11729 | else |
| 11730 | found_memory_cnt += num_regs; |
| 11731 | } |
| 11732 | } |
| 11733 | } |
| 11734 | else if (VALUE_LVAL (v) != not_lval |
| 11735 | && deprecated_value_modifiable (v) == 0) |
| 11736 | return 0; /* These are values from the history (e.g., $1). */ |
| 11737 | else if (VALUE_LVAL (v) == lval_register) |
| 11738 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
| 11739 | } |
| 11740 | |
| 11741 | /* The expression itself looks suitable for using a hardware |
| 11742 | watchpoint, but give the target machine a chance to reject it. */ |
| 11743 | return found_memory_cnt; |
| 11744 | } |
| 11745 | |
| 11746 | void |
| 11747 | watch_command_wrapper (char *arg, int from_tty, int internal) |
| 11748 | { |
| 11749 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
| 11750 | } |
| 11751 | |
| 11752 | /* A helper function that looks for the "-location" argument and then |
| 11753 | calls watch_command_1. */ |
| 11754 | |
| 11755 | static void |
| 11756 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) |
| 11757 | { |
| 11758 | int just_location = 0; |
| 11759 | |
| 11760 | if (arg |
| 11761 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) |
| 11762 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) |
| 11763 | { |
| 11764 | arg = skip_spaces (arg); |
| 11765 | just_location = 1; |
| 11766 | } |
| 11767 | |
| 11768 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
| 11769 | } |
| 11770 | |
| 11771 | static void |
| 11772 | watch_command (char *arg, int from_tty) |
| 11773 | { |
| 11774 | watch_maybe_just_location (arg, hw_write, from_tty); |
| 11775 | } |
| 11776 | |
| 11777 | void |
| 11778 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
| 11779 | { |
| 11780 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
| 11781 | } |
| 11782 | |
| 11783 | static void |
| 11784 | rwatch_command (char *arg, int from_tty) |
| 11785 | { |
| 11786 | watch_maybe_just_location (arg, hw_read, from_tty); |
| 11787 | } |
| 11788 | |
| 11789 | void |
| 11790 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
| 11791 | { |
| 11792 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
| 11793 | } |
| 11794 | |
| 11795 | static void |
| 11796 | awatch_command (char *arg, int from_tty) |
| 11797 | { |
| 11798 | watch_maybe_just_location (arg, hw_access, from_tty); |
| 11799 | } |
| 11800 | \f |
| 11801 | |
| 11802 | /* Helper routines for the until_command routine in infcmd.c. Here |
| 11803 | because it uses the mechanisms of breakpoints. */ |
| 11804 | |
| 11805 | struct until_break_command_continuation_args |
| 11806 | { |
| 11807 | struct breakpoint *breakpoint; |
| 11808 | struct breakpoint *breakpoint2; |
| 11809 | int thread_num; |
| 11810 | }; |
| 11811 | |
| 11812 | /* This function is called by fetch_inferior_event via the |
| 11813 | cmd_continuation pointer, to complete the until command. It takes |
| 11814 | care of cleaning up the temporary breakpoints set up by the until |
| 11815 | command. */ |
| 11816 | static void |
| 11817 | until_break_command_continuation (void *arg, int err) |
| 11818 | { |
| 11819 | struct until_break_command_continuation_args *a = arg; |
| 11820 | |
| 11821 | delete_breakpoint (a->breakpoint); |
| 11822 | if (a->breakpoint2) |
| 11823 | delete_breakpoint (a->breakpoint2); |
| 11824 | delete_longjmp_breakpoint (a->thread_num); |
| 11825 | } |
| 11826 | |
| 11827 | void |
| 11828 | until_break_command (char *arg, int from_tty, int anywhere) |
| 11829 | { |
| 11830 | struct symtabs_and_lines sals; |
| 11831 | struct symtab_and_line sal; |
| 11832 | struct frame_info *frame; |
| 11833 | struct gdbarch *frame_gdbarch; |
| 11834 | struct frame_id stack_frame_id; |
| 11835 | struct frame_id caller_frame_id; |
| 11836 | struct breakpoint *breakpoint; |
| 11837 | struct breakpoint *breakpoint2 = NULL; |
| 11838 | struct cleanup *old_chain; |
| 11839 | int thread; |
| 11840 | struct thread_info *tp; |
| 11841 | |
| 11842 | clear_proceed_status (0); |
| 11843 | |
| 11844 | /* Set a breakpoint where the user wants it and at return from |
| 11845 | this function. */ |
| 11846 | |
| 11847 | if (last_displayed_sal_is_valid ()) |
| 11848 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
| 11849 | get_last_displayed_symtab (), |
| 11850 | get_last_displayed_line ()); |
| 11851 | else |
| 11852 | sals = decode_line_1 (&arg, DECODE_LINE_FUNFIRSTLINE, |
| 11853 | (struct symtab *) NULL, 0); |
| 11854 | |
| 11855 | if (sals.nelts != 1) |
| 11856 | error (_("Couldn't get information on specified line.")); |
| 11857 | |
| 11858 | sal = sals.sals[0]; |
| 11859 | xfree (sals.sals); /* malloc'd, so freed. */ |
| 11860 | |
| 11861 | if (*arg) |
| 11862 | error (_("Junk at end of arguments.")); |
| 11863 | |
| 11864 | resolve_sal_pc (&sal); |
| 11865 | |
| 11866 | tp = inferior_thread (); |
| 11867 | thread = tp->num; |
| 11868 | |
| 11869 | old_chain = make_cleanup (null_cleanup, NULL); |
| 11870 | |
| 11871 | /* Note linespec handling above invalidates the frame chain. |
| 11872 | Installing a breakpoint also invalidates the frame chain (as it |
| 11873 | may need to switch threads), so do any frame handling before |
| 11874 | that. */ |
| 11875 | |
| 11876 | frame = get_selected_frame (NULL); |
| 11877 | frame_gdbarch = get_frame_arch (frame); |
| 11878 | stack_frame_id = get_stack_frame_id (frame); |
| 11879 | caller_frame_id = frame_unwind_caller_id (frame); |
| 11880 | |
| 11881 | /* Keep within the current frame, or in frames called by the current |
| 11882 | one. */ |
| 11883 | |
| 11884 | if (frame_id_p (caller_frame_id)) |
| 11885 | { |
| 11886 | struct symtab_and_line sal2; |
| 11887 | |
| 11888 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); |
| 11889 | sal2.pc = frame_unwind_caller_pc (frame); |
| 11890 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
| 11891 | sal2, |
| 11892 | caller_frame_id, |
| 11893 | bp_until); |
| 11894 | make_cleanup_delete_breakpoint (breakpoint2); |
| 11895 | |
| 11896 | set_longjmp_breakpoint (tp, caller_frame_id); |
| 11897 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
| 11898 | } |
| 11899 | |
| 11900 | /* set_momentary_breakpoint could invalidate FRAME. */ |
| 11901 | frame = NULL; |
| 11902 | |
| 11903 | if (anywhere) |
| 11904 | /* If the user told us to continue until a specified location, |
| 11905 | we don't specify a frame at which we need to stop. */ |
| 11906 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
| 11907 | null_frame_id, bp_until); |
| 11908 | else |
| 11909 | /* Otherwise, specify the selected frame, because we want to stop |
| 11910 | only at the very same frame. */ |
| 11911 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
| 11912 | stack_frame_id, bp_until); |
| 11913 | make_cleanup_delete_breakpoint (breakpoint); |
| 11914 | |
| 11915 | proceed (-1, GDB_SIGNAL_DEFAULT, 0); |
| 11916 | |
| 11917 | /* If we are running asynchronously, and proceed call above has |
| 11918 | actually managed to start the target, arrange for breakpoints to |
| 11919 | be deleted when the target stops. Otherwise, we're already |
| 11920 | stopped and delete breakpoints via cleanup chain. */ |
| 11921 | |
| 11922 | if (target_can_async_p () && is_running (inferior_ptid)) |
| 11923 | { |
| 11924 | struct until_break_command_continuation_args *args; |
| 11925 | args = xmalloc (sizeof (*args)); |
| 11926 | |
| 11927 | args->breakpoint = breakpoint; |
| 11928 | args->breakpoint2 = breakpoint2; |
| 11929 | args->thread_num = thread; |
| 11930 | |
| 11931 | discard_cleanups (old_chain); |
| 11932 | add_continuation (inferior_thread (), |
| 11933 | until_break_command_continuation, args, |
| 11934 | xfree); |
| 11935 | } |
| 11936 | else |
| 11937 | do_cleanups (old_chain); |
| 11938 | } |
| 11939 | |
| 11940 | /* This function attempts to parse an optional "if <cond>" clause |
| 11941 | from the arg string. If one is not found, it returns NULL. |
| 11942 | |
| 11943 | Else, it returns a pointer to the condition string. (It does not |
| 11944 | attempt to evaluate the string against a particular block.) And, |
| 11945 | it updates arg to point to the first character following the parsed |
| 11946 | if clause in the arg string. */ |
| 11947 | |
| 11948 | char * |
| 11949 | ep_parse_optional_if_clause (char **arg) |
| 11950 | { |
| 11951 | char *cond_string; |
| 11952 | |
| 11953 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) |
| 11954 | return NULL; |
| 11955 | |
| 11956 | /* Skip the "if" keyword. */ |
| 11957 | (*arg) += 2; |
| 11958 | |
| 11959 | /* Skip any extra leading whitespace, and record the start of the |
| 11960 | condition string. */ |
| 11961 | *arg = skip_spaces (*arg); |
| 11962 | cond_string = *arg; |
| 11963 | |
| 11964 | /* Assume that the condition occupies the remainder of the arg |
| 11965 | string. */ |
| 11966 | (*arg) += strlen (cond_string); |
| 11967 | |
| 11968 | return cond_string; |
| 11969 | } |
| 11970 | |
| 11971 | /* Commands to deal with catching events, such as signals, exceptions, |
| 11972 | process start/exit, etc. */ |
| 11973 | |
| 11974 | typedef enum |
| 11975 | { |
| 11976 | catch_fork_temporary, catch_vfork_temporary, |
| 11977 | catch_fork_permanent, catch_vfork_permanent |
| 11978 | } |
| 11979 | catch_fork_kind; |
| 11980 | |
| 11981 | static void |
| 11982 | catch_fork_command_1 (char *arg, int from_tty, |
| 11983 | struct cmd_list_element *command) |
| 11984 | { |
| 11985 | struct gdbarch *gdbarch = get_current_arch (); |
| 11986 | char *cond_string = NULL; |
| 11987 | catch_fork_kind fork_kind; |
| 11988 | int tempflag; |
| 11989 | |
| 11990 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); |
| 11991 | tempflag = (fork_kind == catch_fork_temporary |
| 11992 | || fork_kind == catch_vfork_temporary); |
| 11993 | |
| 11994 | if (!arg) |
| 11995 | arg = ""; |
| 11996 | arg = skip_spaces (arg); |
| 11997 | |
| 11998 | /* The allowed syntax is: |
| 11999 | catch [v]fork |
| 12000 | catch [v]fork if <cond> |
| 12001 | |
| 12002 | First, check if there's an if clause. */ |
| 12003 | cond_string = ep_parse_optional_if_clause (&arg); |
| 12004 | |
| 12005 | if ((*arg != '\0') && !isspace (*arg)) |
| 12006 | error (_("Junk at end of arguments.")); |
| 12007 | |
| 12008 | /* If this target supports it, create a fork or vfork catchpoint |
| 12009 | and enable reporting of such events. */ |
| 12010 | switch (fork_kind) |
| 12011 | { |
| 12012 | case catch_fork_temporary: |
| 12013 | case catch_fork_permanent: |
| 12014 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 12015 | &catch_fork_breakpoint_ops); |
| 12016 | break; |
| 12017 | case catch_vfork_temporary: |
| 12018 | case catch_vfork_permanent: |
| 12019 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 12020 | &catch_vfork_breakpoint_ops); |
| 12021 | break; |
| 12022 | default: |
| 12023 | error (_("unsupported or unknown fork kind; cannot catch it")); |
| 12024 | break; |
| 12025 | } |
| 12026 | } |
| 12027 | |
| 12028 | static void |
| 12029 | catch_exec_command_1 (char *arg, int from_tty, |
| 12030 | struct cmd_list_element *command) |
| 12031 | { |
| 12032 | struct exec_catchpoint *c; |
| 12033 | struct gdbarch *gdbarch = get_current_arch (); |
| 12034 | int tempflag; |
| 12035 | char *cond_string = NULL; |
| 12036 | |
| 12037 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 12038 | |
| 12039 | if (!arg) |
| 12040 | arg = ""; |
| 12041 | arg = skip_spaces (arg); |
| 12042 | |
| 12043 | /* The allowed syntax is: |
| 12044 | catch exec |
| 12045 | catch exec if <cond> |
| 12046 | |
| 12047 | First, check if there's an if clause. */ |
| 12048 | cond_string = ep_parse_optional_if_clause (&arg); |
| 12049 | |
| 12050 | if ((*arg != '\0') && !isspace (*arg)) |
| 12051 | error (_("Junk at end of arguments.")); |
| 12052 | |
| 12053 | c = XNEW (struct exec_catchpoint); |
| 12054 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, |
| 12055 | &catch_exec_breakpoint_ops); |
| 12056 | c->exec_pathname = NULL; |
| 12057 | |
| 12058 | install_breakpoint (0, &c->base, 1); |
| 12059 | } |
| 12060 | |
| 12061 | void |
| 12062 | init_ada_exception_breakpoint (struct breakpoint *b, |
| 12063 | struct gdbarch *gdbarch, |
| 12064 | struct symtab_and_line sal, |
| 12065 | char *addr_string, |
| 12066 | const struct breakpoint_ops *ops, |
| 12067 | int tempflag, |
| 12068 | int enabled, |
| 12069 | int from_tty) |
| 12070 | { |
| 12071 | if (from_tty) |
| 12072 | { |
| 12073 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 12074 | if (!loc_gdbarch) |
| 12075 | loc_gdbarch = gdbarch; |
| 12076 | |
| 12077 | describe_other_breakpoints (loc_gdbarch, |
| 12078 | sal.pspace, sal.pc, sal.section, -1); |
| 12079 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
| 12080 | version for exception catchpoints, because two catchpoints |
| 12081 | used for different exception names will use the same address. |
| 12082 | In this case, a "breakpoint ... also set at..." warning is |
| 12083 | unproductive. Besides, the warning phrasing is also a bit |
| 12084 | inappropriate, we should use the word catchpoint, and tell |
| 12085 | the user what type of catchpoint it is. The above is good |
| 12086 | enough for now, though. */ |
| 12087 | } |
| 12088 | |
| 12089 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
| 12090 | |
| 12091 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 12092 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 12093 | b->addr_string = addr_string; |
| 12094 | b->language = language_ada; |
| 12095 | } |
| 12096 | |
| 12097 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
| 12098 | filter list, or NULL if no filtering is required. */ |
| 12099 | static VEC(int) * |
| 12100 | catch_syscall_split_args (char *arg) |
| 12101 | { |
| 12102 | VEC(int) *result = NULL; |
| 12103 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
| 12104 | |
| 12105 | while (*arg != '\0') |
| 12106 | { |
| 12107 | int i, syscall_number; |
| 12108 | char *endptr; |
| 12109 | char cur_name[128]; |
| 12110 | struct syscall s; |
| 12111 | |
| 12112 | /* Skip whitespace. */ |
| 12113 | arg = skip_spaces (arg); |
| 12114 | |
| 12115 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) |
| 12116 | cur_name[i] = arg[i]; |
| 12117 | cur_name[i] = '\0'; |
| 12118 | arg += i; |
| 12119 | |
| 12120 | /* Check if the user provided a syscall name or a number. */ |
| 12121 | syscall_number = (int) strtol (cur_name, &endptr, 0); |
| 12122 | if (*endptr == '\0') |
| 12123 | get_syscall_by_number (syscall_number, &s); |
| 12124 | else |
| 12125 | { |
| 12126 | /* We have a name. Let's check if it's valid and convert it |
| 12127 | to a number. */ |
| 12128 | get_syscall_by_name (cur_name, &s); |
| 12129 | |
| 12130 | if (s.number == UNKNOWN_SYSCALL) |
| 12131 | /* Here we have to issue an error instead of a warning, |
| 12132 | because GDB cannot do anything useful if there's no |
| 12133 | syscall number to be caught. */ |
| 12134 | error (_("Unknown syscall name '%s'."), cur_name); |
| 12135 | } |
| 12136 | |
| 12137 | /* Ok, it's valid. */ |
| 12138 | VEC_safe_push (int, result, s.number); |
| 12139 | } |
| 12140 | |
| 12141 | discard_cleanups (cleanup); |
| 12142 | return result; |
| 12143 | } |
| 12144 | |
| 12145 | /* Implement the "catch syscall" command. */ |
| 12146 | |
| 12147 | static void |
| 12148 | catch_syscall_command_1 (char *arg, int from_tty, |
| 12149 | struct cmd_list_element *command) |
| 12150 | { |
| 12151 | int tempflag; |
| 12152 | VEC(int) *filter; |
| 12153 | struct syscall s; |
| 12154 | struct gdbarch *gdbarch = get_current_arch (); |
| 12155 | |
| 12156 | /* Checking if the feature if supported. */ |
| 12157 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) |
| 12158 | error (_("The feature 'catch syscall' is not supported on \ |
| 12159 | this architecture yet.")); |
| 12160 | |
| 12161 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 12162 | |
| 12163 | arg = skip_spaces (arg); |
| 12164 | |
| 12165 | /* We need to do this first "dummy" translation in order |
| 12166 | to get the syscall XML file loaded or, most important, |
| 12167 | to display a warning to the user if there's no XML file |
| 12168 | for his/her architecture. */ |
| 12169 | get_syscall_by_number (0, &s); |
| 12170 | |
| 12171 | /* The allowed syntax is: |
| 12172 | catch syscall |
| 12173 | catch syscall <name | number> [<name | number> ... <name | number>] |
| 12174 | |
| 12175 | Let's check if there's a syscall name. */ |
| 12176 | |
| 12177 | if (arg != NULL) |
| 12178 | filter = catch_syscall_split_args (arg); |
| 12179 | else |
| 12180 | filter = NULL; |
| 12181 | |
| 12182 | create_syscall_event_catchpoint (tempflag, filter, |
| 12183 | &catch_syscall_breakpoint_ops); |
| 12184 | } |
| 12185 | |
| 12186 | static void |
| 12187 | catch_command (char *arg, int from_tty) |
| 12188 | { |
| 12189 | error (_("Catch requires an event name.")); |
| 12190 | } |
| 12191 | \f |
| 12192 | |
| 12193 | static void |
| 12194 | tcatch_command (char *arg, int from_tty) |
| 12195 | { |
| 12196 | error (_("Catch requires an event name.")); |
| 12197 | } |
| 12198 | |
| 12199 | /* A qsort comparison function that sorts breakpoints in order. */ |
| 12200 | |
| 12201 | static int |
| 12202 | compare_breakpoints (const void *a, const void *b) |
| 12203 | { |
| 12204 | const breakpoint_p *ba = a; |
| 12205 | uintptr_t ua = (uintptr_t) *ba; |
| 12206 | const breakpoint_p *bb = b; |
| 12207 | uintptr_t ub = (uintptr_t) *bb; |
| 12208 | |
| 12209 | if ((*ba)->number < (*bb)->number) |
| 12210 | return -1; |
| 12211 | else if ((*ba)->number > (*bb)->number) |
| 12212 | return 1; |
| 12213 | |
| 12214 | /* Now sort by address, in case we see, e..g, two breakpoints with |
| 12215 | the number 0. */ |
| 12216 | if (ua < ub) |
| 12217 | return -1; |
| 12218 | return ua > ub ? 1 : 0; |
| 12219 | } |
| 12220 | |
| 12221 | /* Delete breakpoints by address or line. */ |
| 12222 | |
| 12223 | static void |
| 12224 | clear_command (char *arg, int from_tty) |
| 12225 | { |
| 12226 | struct breakpoint *b, *prev; |
| 12227 | VEC(breakpoint_p) *found = 0; |
| 12228 | int ix; |
| 12229 | int default_match; |
| 12230 | struct symtabs_and_lines sals; |
| 12231 | struct symtab_and_line sal; |
| 12232 | int i; |
| 12233 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
| 12234 | |
| 12235 | if (arg) |
| 12236 | { |
| 12237 | sals = decode_line_with_current_source (arg, |
| 12238 | (DECODE_LINE_FUNFIRSTLINE |
| 12239 | | DECODE_LINE_LIST_MODE)); |
| 12240 | make_cleanup (xfree, sals.sals); |
| 12241 | default_match = 0; |
| 12242 | } |
| 12243 | else |
| 12244 | { |
| 12245 | sals.sals = (struct symtab_and_line *) |
| 12246 | xmalloc (sizeof (struct symtab_and_line)); |
| 12247 | make_cleanup (xfree, sals.sals); |
| 12248 | init_sal (&sal); /* Initialize to zeroes. */ |
| 12249 | |
| 12250 | /* Set sal's line, symtab, pc, and pspace to the values |
| 12251 | corresponding to the last call to print_frame_info. If the |
| 12252 | codepoint is not valid, this will set all the fields to 0. */ |
| 12253 | get_last_displayed_sal (&sal); |
| 12254 | if (sal.symtab == 0) |
| 12255 | error (_("No source file specified.")); |
| 12256 | |
| 12257 | sals.sals[0] = sal; |
| 12258 | sals.nelts = 1; |
| 12259 | |
| 12260 | default_match = 1; |
| 12261 | } |
| 12262 | |
| 12263 | /* We don't call resolve_sal_pc here. That's not as bad as it |
| 12264 | seems, because all existing breakpoints typically have both |
| 12265 | file/line and pc set. So, if clear is given file/line, we can |
| 12266 | match this to existing breakpoint without obtaining pc at all. |
| 12267 | |
| 12268 | We only support clearing given the address explicitly |
| 12269 | present in breakpoint table. Say, we've set breakpoint |
| 12270 | at file:line. There were several PC values for that file:line, |
| 12271 | due to optimization, all in one block. |
| 12272 | |
| 12273 | We've picked one PC value. If "clear" is issued with another |
| 12274 | PC corresponding to the same file:line, the breakpoint won't |
| 12275 | be cleared. We probably can still clear the breakpoint, but |
| 12276 | since the other PC value is never presented to user, user |
| 12277 | can only find it by guessing, and it does not seem important |
| 12278 | to support that. */ |
| 12279 | |
| 12280 | /* For each line spec given, delete bps which correspond to it. Do |
| 12281 | it in two passes, solely to preserve the current behavior that |
| 12282 | from_tty is forced true if we delete more than one |
| 12283 | breakpoint. */ |
| 12284 | |
| 12285 | found = NULL; |
| 12286 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
| 12287 | for (i = 0; i < sals.nelts; i++) |
| 12288 | { |
| 12289 | const char *sal_fullname; |
| 12290 | |
| 12291 | /* If exact pc given, clear bpts at that pc. |
| 12292 | If line given (pc == 0), clear all bpts on specified line. |
| 12293 | If defaulting, clear all bpts on default line |
| 12294 | or at default pc. |
| 12295 | |
| 12296 | defaulting sal.pc != 0 tests to do |
| 12297 | |
| 12298 | 0 1 pc |
| 12299 | 1 1 pc _and_ line |
| 12300 | 0 0 line |
| 12301 | 1 0 <can't happen> */ |
| 12302 | |
| 12303 | sal = sals.sals[i]; |
| 12304 | sal_fullname = (sal.symtab == NULL |
| 12305 | ? NULL : symtab_to_fullname (sal.symtab)); |
| 12306 | |
| 12307 | /* Find all matching breakpoints and add them to 'found'. */ |
| 12308 | ALL_BREAKPOINTS (b) |
| 12309 | { |
| 12310 | int match = 0; |
| 12311 | /* Are we going to delete b? */ |
| 12312 | if (b->type != bp_none && !is_watchpoint (b)) |
| 12313 | { |
| 12314 | struct bp_location *loc = b->loc; |
| 12315 | for (; loc; loc = loc->next) |
| 12316 | { |
| 12317 | /* If the user specified file:line, don't allow a PC |
| 12318 | match. This matches historical gdb behavior. */ |
| 12319 | int pc_match = (!sal.explicit_line |
| 12320 | && sal.pc |
| 12321 | && (loc->pspace == sal.pspace) |
| 12322 | && (loc->address == sal.pc) |
| 12323 | && (!section_is_overlay (loc->section) |
| 12324 | || loc->section == sal.section)); |
| 12325 | int line_match = 0; |
| 12326 | |
| 12327 | if ((default_match || sal.explicit_line) |
| 12328 | && loc->symtab != NULL |
| 12329 | && sal_fullname != NULL |
| 12330 | && sal.pspace == loc->pspace |
| 12331 | && loc->line_number == sal.line |
| 12332 | && filename_cmp (symtab_to_fullname (loc->symtab), |
| 12333 | sal_fullname) == 0) |
| 12334 | line_match = 1; |
| 12335 | |
| 12336 | if (pc_match || line_match) |
| 12337 | { |
| 12338 | match = 1; |
| 12339 | break; |
| 12340 | } |
| 12341 | } |
| 12342 | } |
| 12343 | |
| 12344 | if (match) |
| 12345 | VEC_safe_push(breakpoint_p, found, b); |
| 12346 | } |
| 12347 | } |
| 12348 | |
| 12349 | /* Now go thru the 'found' chain and delete them. */ |
| 12350 | if (VEC_empty(breakpoint_p, found)) |
| 12351 | { |
| 12352 | if (arg) |
| 12353 | error (_("No breakpoint at %s."), arg); |
| 12354 | else |
| 12355 | error (_("No breakpoint at this line.")); |
| 12356 | } |
| 12357 | |
| 12358 | /* Remove duplicates from the vec. */ |
| 12359 | qsort (VEC_address (breakpoint_p, found), |
| 12360 | VEC_length (breakpoint_p, found), |
| 12361 | sizeof (breakpoint_p), |
| 12362 | compare_breakpoints); |
| 12363 | prev = VEC_index (breakpoint_p, found, 0); |
| 12364 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) |
| 12365 | { |
| 12366 | if (b == prev) |
| 12367 | { |
| 12368 | VEC_ordered_remove (breakpoint_p, found, ix); |
| 12369 | --ix; |
| 12370 | } |
| 12371 | } |
| 12372 | |
| 12373 | if (VEC_length(breakpoint_p, found) > 1) |
| 12374 | from_tty = 1; /* Always report if deleted more than one. */ |
| 12375 | if (from_tty) |
| 12376 | { |
| 12377 | if (VEC_length(breakpoint_p, found) == 1) |
| 12378 | printf_unfiltered (_("Deleted breakpoint ")); |
| 12379 | else |
| 12380 | printf_unfiltered (_("Deleted breakpoints ")); |
| 12381 | } |
| 12382 | |
| 12383 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) |
| 12384 | { |
| 12385 | if (from_tty) |
| 12386 | printf_unfiltered ("%d ", b->number); |
| 12387 | delete_breakpoint (b); |
| 12388 | } |
| 12389 | if (from_tty) |
| 12390 | putchar_unfiltered ('\n'); |
| 12391 | |
| 12392 | do_cleanups (cleanups); |
| 12393 | } |
| 12394 | \f |
| 12395 | /* Delete breakpoint in BS if they are `delete' breakpoints and |
| 12396 | all breakpoints that are marked for deletion, whether hit or not. |
| 12397 | This is called after any breakpoint is hit, or after errors. */ |
| 12398 | |
| 12399 | void |
| 12400 | breakpoint_auto_delete (bpstat bs) |
| 12401 | { |
| 12402 | struct breakpoint *b, *b_tmp; |
| 12403 | |
| 12404 | for (; bs; bs = bs->next) |
| 12405 | if (bs->breakpoint_at |
| 12406 | && bs->breakpoint_at->disposition == disp_del |
| 12407 | && bs->stop) |
| 12408 | delete_breakpoint (bs->breakpoint_at); |
| 12409 | |
| 12410 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 12411 | { |
| 12412 | if (b->disposition == disp_del_at_next_stop) |
| 12413 | delete_breakpoint (b); |
| 12414 | } |
| 12415 | } |
| 12416 | |
| 12417 | /* A comparison function for bp_location AP and BP being interfaced to |
| 12418 | qsort. Sort elements primarily by their ADDRESS (no matter what |
| 12419 | does breakpoint_address_is_meaningful say for its OWNER), |
| 12420 | secondarily by ordering first bp_permanent OWNERed elements and |
| 12421 | terciarily just ensuring the array is sorted stable way despite |
| 12422 | qsort being an unstable algorithm. */ |
| 12423 | |
| 12424 | static int |
| 12425 | bp_location_compare (const void *ap, const void *bp) |
| 12426 | { |
| 12427 | struct bp_location *a = *(void **) ap; |
| 12428 | struct bp_location *b = *(void **) bp; |
| 12429 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
| 12430 | int a_perm = a->owner->enable_state == bp_permanent; |
| 12431 | int b_perm = b->owner->enable_state == bp_permanent; |
| 12432 | |
| 12433 | if (a->address != b->address) |
| 12434 | return (a->address > b->address) - (a->address < b->address); |
| 12435 | |
| 12436 | /* Sort locations at the same address by their pspace number, keeping |
| 12437 | locations of the same inferior (in a multi-inferior environment) |
| 12438 | grouped. */ |
| 12439 | |
| 12440 | if (a->pspace->num != b->pspace->num) |
| 12441 | return ((a->pspace->num > b->pspace->num) |
| 12442 | - (a->pspace->num < b->pspace->num)); |
| 12443 | |
| 12444 | /* Sort permanent breakpoints first. */ |
| 12445 | if (a_perm != b_perm) |
| 12446 | return (a_perm < b_perm) - (a_perm > b_perm); |
| 12447 | |
| 12448 | /* Make the internal GDB representation stable across GDB runs |
| 12449 | where A and B memory inside GDB can differ. Breakpoint locations of |
| 12450 | the same type at the same address can be sorted in arbitrary order. */ |
| 12451 | |
| 12452 | if (a->owner->number != b->owner->number) |
| 12453 | return ((a->owner->number > b->owner->number) |
| 12454 | - (a->owner->number < b->owner->number)); |
| 12455 | |
| 12456 | return (a > b) - (a < b); |
| 12457 | } |
| 12458 | |
| 12459 | /* Set bp_location_placed_address_before_address_max and |
| 12460 | bp_location_shadow_len_after_address_max according to the current |
| 12461 | content of the bp_location array. */ |
| 12462 | |
| 12463 | static void |
| 12464 | bp_location_target_extensions_update (void) |
| 12465 | { |
| 12466 | struct bp_location *bl, **blp_tmp; |
| 12467 | |
| 12468 | bp_location_placed_address_before_address_max = 0; |
| 12469 | bp_location_shadow_len_after_address_max = 0; |
| 12470 | |
| 12471 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 12472 | { |
| 12473 | CORE_ADDR start, end, addr; |
| 12474 | |
| 12475 | if (!bp_location_has_shadow (bl)) |
| 12476 | continue; |
| 12477 | |
| 12478 | start = bl->target_info.placed_address; |
| 12479 | end = start + bl->target_info.shadow_len; |
| 12480 | |
| 12481 | gdb_assert (bl->address >= start); |
| 12482 | addr = bl->address - start; |
| 12483 | if (addr > bp_location_placed_address_before_address_max) |
| 12484 | bp_location_placed_address_before_address_max = addr; |
| 12485 | |
| 12486 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ |
| 12487 | |
| 12488 | gdb_assert (bl->address < end); |
| 12489 | addr = end - bl->address; |
| 12490 | if (addr > bp_location_shadow_len_after_address_max) |
| 12491 | bp_location_shadow_len_after_address_max = addr; |
| 12492 | } |
| 12493 | } |
| 12494 | |
| 12495 | /* Download tracepoint locations if they haven't been. */ |
| 12496 | |
| 12497 | static void |
| 12498 | download_tracepoint_locations (void) |
| 12499 | { |
| 12500 | struct breakpoint *b; |
| 12501 | struct cleanup *old_chain; |
| 12502 | |
| 12503 | if (!target_can_download_tracepoint ()) |
| 12504 | return; |
| 12505 | |
| 12506 | old_chain = save_current_space_and_thread (); |
| 12507 | |
| 12508 | ALL_TRACEPOINTS (b) |
| 12509 | { |
| 12510 | struct bp_location *bl; |
| 12511 | struct tracepoint *t; |
| 12512 | int bp_location_downloaded = 0; |
| 12513 | |
| 12514 | if ((b->type == bp_fast_tracepoint |
| 12515 | ? !may_insert_fast_tracepoints |
| 12516 | : !may_insert_tracepoints)) |
| 12517 | continue; |
| 12518 | |
| 12519 | for (bl = b->loc; bl; bl = bl->next) |
| 12520 | { |
| 12521 | /* In tracepoint, locations are _never_ duplicated, so |
| 12522 | should_be_inserted is equivalent to |
| 12523 | unduplicated_should_be_inserted. */ |
| 12524 | if (!should_be_inserted (bl) || bl->inserted) |
| 12525 | continue; |
| 12526 | |
| 12527 | switch_to_program_space_and_thread (bl->pspace); |
| 12528 | |
| 12529 | target_download_tracepoint (bl); |
| 12530 | |
| 12531 | bl->inserted = 1; |
| 12532 | bp_location_downloaded = 1; |
| 12533 | } |
| 12534 | t = (struct tracepoint *) b; |
| 12535 | t->number_on_target = b->number; |
| 12536 | if (bp_location_downloaded) |
| 12537 | observer_notify_breakpoint_modified (b); |
| 12538 | } |
| 12539 | |
| 12540 | do_cleanups (old_chain); |
| 12541 | } |
| 12542 | |
| 12543 | /* Swap the insertion/duplication state between two locations. */ |
| 12544 | |
| 12545 | static void |
| 12546 | swap_insertion (struct bp_location *left, struct bp_location *right) |
| 12547 | { |
| 12548 | const int left_inserted = left->inserted; |
| 12549 | const int left_duplicate = left->duplicate; |
| 12550 | const int left_needs_update = left->needs_update; |
| 12551 | const struct bp_target_info left_target_info = left->target_info; |
| 12552 | |
| 12553 | /* Locations of tracepoints can never be duplicated. */ |
| 12554 | if (is_tracepoint (left->owner)) |
| 12555 | gdb_assert (!left->duplicate); |
| 12556 | if (is_tracepoint (right->owner)) |
| 12557 | gdb_assert (!right->duplicate); |
| 12558 | |
| 12559 | left->inserted = right->inserted; |
| 12560 | left->duplicate = right->duplicate; |
| 12561 | left->needs_update = right->needs_update; |
| 12562 | left->target_info = right->target_info; |
| 12563 | right->inserted = left_inserted; |
| 12564 | right->duplicate = left_duplicate; |
| 12565 | right->needs_update = left_needs_update; |
| 12566 | right->target_info = left_target_info; |
| 12567 | } |
| 12568 | |
| 12569 | /* Force the re-insertion of the locations at ADDRESS. This is called |
| 12570 | once a new/deleted/modified duplicate location is found and we are evaluating |
| 12571 | conditions on the target's side. Such conditions need to be updated on |
| 12572 | the target. */ |
| 12573 | |
| 12574 | static void |
| 12575 | force_breakpoint_reinsertion (struct bp_location *bl) |
| 12576 | { |
| 12577 | struct bp_location **locp = NULL, **loc2p; |
| 12578 | struct bp_location *loc; |
| 12579 | CORE_ADDR address = 0; |
| 12580 | int pspace_num; |
| 12581 | |
| 12582 | address = bl->address; |
| 12583 | pspace_num = bl->pspace->num; |
| 12584 | |
| 12585 | /* This is only meaningful if the target is |
| 12586 | evaluating conditions and if the user has |
| 12587 | opted for condition evaluation on the target's |
| 12588 | side. */ |
| 12589 | if (gdb_evaluates_breakpoint_condition_p () |
| 12590 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 12591 | return; |
| 12592 | |
| 12593 | /* Flag all breakpoint locations with this address and |
| 12594 | the same program space as the location |
| 12595 | as "its condition has changed". We need to |
| 12596 | update the conditions on the target's side. */ |
| 12597 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) |
| 12598 | { |
| 12599 | loc = *loc2p; |
| 12600 | |
| 12601 | if (!is_breakpoint (loc->owner) |
| 12602 | || pspace_num != loc->pspace->num) |
| 12603 | continue; |
| 12604 | |
| 12605 | /* Flag the location appropriately. We use a different state to |
| 12606 | let everyone know that we already updated the set of locations |
| 12607 | with addr bl->address and program space bl->pspace. This is so |
| 12608 | we don't have to keep calling these functions just to mark locations |
| 12609 | that have already been marked. */ |
| 12610 | loc->condition_changed = condition_updated; |
| 12611 | |
| 12612 | /* Free the agent expression bytecode as well. We will compute |
| 12613 | it later on. */ |
| 12614 | if (loc->cond_bytecode) |
| 12615 | { |
| 12616 | free_agent_expr (loc->cond_bytecode); |
| 12617 | loc->cond_bytecode = NULL; |
| 12618 | } |
| 12619 | } |
| 12620 | } |
| 12621 | /* Called whether new breakpoints are created, or existing breakpoints |
| 12622 | deleted, to update the global location list and recompute which |
| 12623 | locations are duplicate of which. |
| 12624 | |
| 12625 | The INSERT_MODE flag determines whether locations may not, may, or |
| 12626 | shall be inserted now. See 'enum ugll_insert_mode' for more |
| 12627 | info. */ |
| 12628 | |
| 12629 | static void |
| 12630 | update_global_location_list (enum ugll_insert_mode insert_mode) |
| 12631 | { |
| 12632 | struct breakpoint *b; |
| 12633 | struct bp_location **locp, *loc; |
| 12634 | struct cleanup *cleanups; |
| 12635 | /* Last breakpoint location address that was marked for update. */ |
| 12636 | CORE_ADDR last_addr = 0; |
| 12637 | /* Last breakpoint location program space that was marked for update. */ |
| 12638 | int last_pspace_num = -1; |
| 12639 | |
| 12640 | /* Used in the duplicates detection below. When iterating over all |
| 12641 | bp_locations, points to the first bp_location of a given address. |
| 12642 | Breakpoints and watchpoints of different types are never |
| 12643 | duplicates of each other. Keep one pointer for each type of |
| 12644 | breakpoint/watchpoint, so we only need to loop over all locations |
| 12645 | once. */ |
| 12646 | struct bp_location *bp_loc_first; /* breakpoint */ |
| 12647 | struct bp_location *wp_loc_first; /* hardware watchpoint */ |
| 12648 | struct bp_location *awp_loc_first; /* access watchpoint */ |
| 12649 | struct bp_location *rwp_loc_first; /* read watchpoint */ |
| 12650 | |
| 12651 | /* Saved former bp_location array which we compare against the newly |
| 12652 | built bp_location from the current state of ALL_BREAKPOINTS. */ |
| 12653 | struct bp_location **old_location, **old_locp; |
| 12654 | unsigned old_location_count; |
| 12655 | |
| 12656 | old_location = bp_location; |
| 12657 | old_location_count = bp_location_count; |
| 12658 | bp_location = NULL; |
| 12659 | bp_location_count = 0; |
| 12660 | cleanups = make_cleanup (xfree, old_location); |
| 12661 | |
| 12662 | ALL_BREAKPOINTS (b) |
| 12663 | for (loc = b->loc; loc; loc = loc->next) |
| 12664 | bp_location_count++; |
| 12665 | |
| 12666 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); |
| 12667 | locp = bp_location; |
| 12668 | ALL_BREAKPOINTS (b) |
| 12669 | for (loc = b->loc; loc; loc = loc->next) |
| 12670 | *locp++ = loc; |
| 12671 | qsort (bp_location, bp_location_count, sizeof (*bp_location), |
| 12672 | bp_location_compare); |
| 12673 | |
| 12674 | bp_location_target_extensions_update (); |
| 12675 | |
| 12676 | /* Identify bp_location instances that are no longer present in the |
| 12677 | new list, and therefore should be freed. Note that it's not |
| 12678 | necessary that those locations should be removed from inferior -- |
| 12679 | if there's another location at the same address (previously |
| 12680 | marked as duplicate), we don't need to remove/insert the |
| 12681 | location. |
| 12682 | |
| 12683 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
| 12684 | and former bp_location array state respectively. */ |
| 12685 | |
| 12686 | locp = bp_location; |
| 12687 | for (old_locp = old_location; old_locp < old_location + old_location_count; |
| 12688 | old_locp++) |
| 12689 | { |
| 12690 | struct bp_location *old_loc = *old_locp; |
| 12691 | struct bp_location **loc2p; |
| 12692 | |
| 12693 | /* Tells if 'old_loc' is found among the new locations. If |
| 12694 | not, we have to free it. */ |
| 12695 | int found_object = 0; |
| 12696 | /* Tells if the location should remain inserted in the target. */ |
| 12697 | int keep_in_target = 0; |
| 12698 | int removed = 0; |
| 12699 | |
| 12700 | /* Skip LOCP entries which will definitely never be needed. |
| 12701 | Stop either at or being the one matching OLD_LOC. */ |
| 12702 | while (locp < bp_location + bp_location_count |
| 12703 | && (*locp)->address < old_loc->address) |
| 12704 | locp++; |
| 12705 | |
| 12706 | for (loc2p = locp; |
| 12707 | (loc2p < bp_location + bp_location_count |
| 12708 | && (*loc2p)->address == old_loc->address); |
| 12709 | loc2p++) |
| 12710 | { |
| 12711 | /* Check if this is a new/duplicated location or a duplicated |
| 12712 | location that had its condition modified. If so, we want to send |
| 12713 | its condition to the target if evaluation of conditions is taking |
| 12714 | place there. */ |
| 12715 | if ((*loc2p)->condition_changed == condition_modified |
| 12716 | && (last_addr != old_loc->address |
| 12717 | || last_pspace_num != old_loc->pspace->num)) |
| 12718 | { |
| 12719 | force_breakpoint_reinsertion (*loc2p); |
| 12720 | last_pspace_num = old_loc->pspace->num; |
| 12721 | } |
| 12722 | |
| 12723 | if (*loc2p == old_loc) |
| 12724 | found_object = 1; |
| 12725 | } |
| 12726 | |
| 12727 | /* We have already handled this address, update it so that we don't |
| 12728 | have to go through updates again. */ |
| 12729 | last_addr = old_loc->address; |
| 12730 | |
| 12731 | /* Target-side condition evaluation: Handle deleted locations. */ |
| 12732 | if (!found_object) |
| 12733 | force_breakpoint_reinsertion (old_loc); |
| 12734 | |
| 12735 | /* If this location is no longer present, and inserted, look if |
| 12736 | there's maybe a new location at the same address. If so, |
| 12737 | mark that one inserted, and don't remove this one. This is |
| 12738 | needed so that we don't have a time window where a breakpoint |
| 12739 | at certain location is not inserted. */ |
| 12740 | |
| 12741 | if (old_loc->inserted) |
| 12742 | { |
| 12743 | /* If the location is inserted now, we might have to remove |
| 12744 | it. */ |
| 12745 | |
| 12746 | if (found_object && should_be_inserted (old_loc)) |
| 12747 | { |
| 12748 | /* The location is still present in the location list, |
| 12749 | and still should be inserted. Don't do anything. */ |
| 12750 | keep_in_target = 1; |
| 12751 | } |
| 12752 | else |
| 12753 | { |
| 12754 | /* This location still exists, but it won't be kept in the |
| 12755 | target since it may have been disabled. We proceed to |
| 12756 | remove its target-side condition. */ |
| 12757 | |
| 12758 | /* The location is either no longer present, or got |
| 12759 | disabled. See if there's another location at the |
| 12760 | same address, in which case we don't need to remove |
| 12761 | this one from the target. */ |
| 12762 | |
| 12763 | /* OLD_LOC comes from existing struct breakpoint. */ |
| 12764 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
| 12765 | { |
| 12766 | for (loc2p = locp; |
| 12767 | (loc2p < bp_location + bp_location_count |
| 12768 | && (*loc2p)->address == old_loc->address); |
| 12769 | loc2p++) |
| 12770 | { |
| 12771 | struct bp_location *loc2 = *loc2p; |
| 12772 | |
| 12773 | if (breakpoint_locations_match (loc2, old_loc)) |
| 12774 | { |
| 12775 | /* Read watchpoint locations are switched to |
| 12776 | access watchpoints, if the former are not |
| 12777 | supported, but the latter are. */ |
| 12778 | if (is_hardware_watchpoint (old_loc->owner)) |
| 12779 | { |
| 12780 | gdb_assert (is_hardware_watchpoint (loc2->owner)); |
| 12781 | loc2->watchpoint_type = old_loc->watchpoint_type; |
| 12782 | } |
| 12783 | |
| 12784 | /* loc2 is a duplicated location. We need to check |
| 12785 | if it should be inserted in case it will be |
| 12786 | unduplicated. */ |
| 12787 | if (loc2 != old_loc |
| 12788 | && unduplicated_should_be_inserted (loc2)) |
| 12789 | { |
| 12790 | swap_insertion (old_loc, loc2); |
| 12791 | keep_in_target = 1; |
| 12792 | break; |
| 12793 | } |
| 12794 | } |
| 12795 | } |
| 12796 | } |
| 12797 | } |
| 12798 | |
| 12799 | if (!keep_in_target) |
| 12800 | { |
| 12801 | if (remove_breakpoint (old_loc, mark_uninserted)) |
| 12802 | { |
| 12803 | /* This is just about all we can do. We could keep |
| 12804 | this location on the global list, and try to |
| 12805 | remove it next time, but there's no particular |
| 12806 | reason why we will succeed next time. |
| 12807 | |
| 12808 | Note that at this point, old_loc->owner is still |
| 12809 | valid, as delete_breakpoint frees the breakpoint |
| 12810 | only after calling us. */ |
| 12811 | printf_filtered (_("warning: Error removing " |
| 12812 | "breakpoint %d\n"), |
| 12813 | old_loc->owner->number); |
| 12814 | } |
| 12815 | removed = 1; |
| 12816 | } |
| 12817 | } |
| 12818 | |
| 12819 | if (!found_object) |
| 12820 | { |
| 12821 | if (removed && non_stop |
| 12822 | && breakpoint_address_is_meaningful (old_loc->owner) |
| 12823 | && !is_hardware_watchpoint (old_loc->owner)) |
| 12824 | { |
| 12825 | /* This location was removed from the target. In |
| 12826 | non-stop mode, a race condition is possible where |
| 12827 | we've removed a breakpoint, but stop events for that |
| 12828 | breakpoint are already queued and will arrive later. |
| 12829 | We apply an heuristic to be able to distinguish such |
| 12830 | SIGTRAPs from other random SIGTRAPs: we keep this |
| 12831 | breakpoint location for a bit, and will retire it |
| 12832 | after we see some number of events. The theory here |
| 12833 | is that reporting of events should, "on the average", |
| 12834 | be fair, so after a while we'll see events from all |
| 12835 | threads that have anything of interest, and no longer |
| 12836 | need to keep this breakpoint location around. We |
| 12837 | don't hold locations forever so to reduce chances of |
| 12838 | mistaking a non-breakpoint SIGTRAP for a breakpoint |
| 12839 | SIGTRAP. |
| 12840 | |
| 12841 | The heuristic failing can be disastrous on |
| 12842 | decr_pc_after_break targets. |
| 12843 | |
| 12844 | On decr_pc_after_break targets, like e.g., x86-linux, |
| 12845 | if we fail to recognize a late breakpoint SIGTRAP, |
| 12846 | because events_till_retirement has reached 0 too |
| 12847 | soon, we'll fail to do the PC adjustment, and report |
| 12848 | a random SIGTRAP to the user. When the user resumes |
| 12849 | the inferior, it will most likely immediately crash |
| 12850 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
| 12851 | corrupted, because of being resumed e.g., in the |
| 12852 | middle of a multi-byte instruction, or skipped a |
| 12853 | one-byte instruction. This was actually seen happen |
| 12854 | on native x86-linux, and should be less rare on |
| 12855 | targets that do not support new thread events, like |
| 12856 | remote, due to the heuristic depending on |
| 12857 | thread_count. |
| 12858 | |
| 12859 | Mistaking a random SIGTRAP for a breakpoint trap |
| 12860 | causes similar symptoms (PC adjustment applied when |
| 12861 | it shouldn't), but then again, playing with SIGTRAPs |
| 12862 | behind the debugger's back is asking for trouble. |
| 12863 | |
| 12864 | Since hardware watchpoint traps are always |
| 12865 | distinguishable from other traps, so we don't need to |
| 12866 | apply keep hardware watchpoint moribund locations |
| 12867 | around. We simply always ignore hardware watchpoint |
| 12868 | traps we can no longer explain. */ |
| 12869 | |
| 12870 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
| 12871 | old_loc->owner = NULL; |
| 12872 | |
| 12873 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
| 12874 | } |
| 12875 | else |
| 12876 | { |
| 12877 | old_loc->owner = NULL; |
| 12878 | decref_bp_location (&old_loc); |
| 12879 | } |
| 12880 | } |
| 12881 | } |
| 12882 | |
| 12883 | /* Rescan breakpoints at the same address and section, marking the |
| 12884 | first one as "first" and any others as "duplicates". This is so |
| 12885 | that the bpt instruction is only inserted once. If we have a |
| 12886 | permanent breakpoint at the same place as BPT, make that one the |
| 12887 | official one, and the rest as duplicates. Permanent breakpoints |
| 12888 | are sorted first for the same address. |
| 12889 | |
| 12890 | Do the same for hardware watchpoints, but also considering the |
| 12891 | watchpoint's type (regular/access/read) and length. */ |
| 12892 | |
| 12893 | bp_loc_first = NULL; |
| 12894 | wp_loc_first = NULL; |
| 12895 | awp_loc_first = NULL; |
| 12896 | rwp_loc_first = NULL; |
| 12897 | ALL_BP_LOCATIONS (loc, locp) |
| 12898 | { |
| 12899 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
| 12900 | non-NULL. */ |
| 12901 | struct bp_location **loc_first_p; |
| 12902 | b = loc->owner; |
| 12903 | |
| 12904 | if (!unduplicated_should_be_inserted (loc) |
| 12905 | || !breakpoint_address_is_meaningful (b) |
| 12906 | /* Don't detect duplicate for tracepoint locations because they are |
| 12907 | never duplicated. See the comments in field `duplicate' of |
| 12908 | `struct bp_location'. */ |
| 12909 | || is_tracepoint (b)) |
| 12910 | { |
| 12911 | /* Clear the condition modification flag. */ |
| 12912 | loc->condition_changed = condition_unchanged; |
| 12913 | continue; |
| 12914 | } |
| 12915 | |
| 12916 | /* Permanent breakpoint should always be inserted. */ |
| 12917 | if (b->enable_state == bp_permanent && ! loc->inserted) |
| 12918 | internal_error (__FILE__, __LINE__, |
| 12919 | _("allegedly permanent breakpoint is not " |
| 12920 | "actually inserted")); |
| 12921 | |
| 12922 | if (b->type == bp_hardware_watchpoint) |
| 12923 | loc_first_p = &wp_loc_first; |
| 12924 | else if (b->type == bp_read_watchpoint) |
| 12925 | loc_first_p = &rwp_loc_first; |
| 12926 | else if (b->type == bp_access_watchpoint) |
| 12927 | loc_first_p = &awp_loc_first; |
| 12928 | else |
| 12929 | loc_first_p = &bp_loc_first; |
| 12930 | |
| 12931 | if (*loc_first_p == NULL |
| 12932 | || (overlay_debugging && loc->section != (*loc_first_p)->section) |
| 12933 | || !breakpoint_locations_match (loc, *loc_first_p)) |
| 12934 | { |
| 12935 | *loc_first_p = loc; |
| 12936 | loc->duplicate = 0; |
| 12937 | |
| 12938 | if (is_breakpoint (loc->owner) && loc->condition_changed) |
| 12939 | { |
| 12940 | loc->needs_update = 1; |
| 12941 | /* Clear the condition modification flag. */ |
| 12942 | loc->condition_changed = condition_unchanged; |
| 12943 | } |
| 12944 | continue; |
| 12945 | } |
| 12946 | |
| 12947 | |
| 12948 | /* This and the above ensure the invariant that the first location |
| 12949 | is not duplicated, and is the inserted one. |
| 12950 | All following are marked as duplicated, and are not inserted. */ |
| 12951 | if (loc->inserted) |
| 12952 | swap_insertion (loc, *loc_first_p); |
| 12953 | loc->duplicate = 1; |
| 12954 | |
| 12955 | /* Clear the condition modification flag. */ |
| 12956 | loc->condition_changed = condition_unchanged; |
| 12957 | |
| 12958 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
| 12959 | && b->enable_state != bp_permanent) |
| 12960 | internal_error (__FILE__, __LINE__, |
| 12961 | _("another breakpoint was inserted on top of " |
| 12962 | "a permanent breakpoint")); |
| 12963 | } |
| 12964 | |
| 12965 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
| 12966 | { |
| 12967 | if (insert_mode != UGLL_DONT_INSERT) |
| 12968 | insert_breakpoint_locations (); |
| 12969 | else |
| 12970 | { |
| 12971 | /* Even though the caller told us to not insert new |
| 12972 | locations, we may still need to update conditions on the |
| 12973 | target's side of breakpoints that were already inserted |
| 12974 | if the target is evaluating breakpoint conditions. We |
| 12975 | only update conditions for locations that are marked |
| 12976 | "needs_update". */ |
| 12977 | update_inserted_breakpoint_locations (); |
| 12978 | } |
| 12979 | } |
| 12980 | |
| 12981 | if (insert_mode != UGLL_DONT_INSERT) |
| 12982 | download_tracepoint_locations (); |
| 12983 | |
| 12984 | do_cleanups (cleanups); |
| 12985 | } |
| 12986 | |
| 12987 | void |
| 12988 | breakpoint_retire_moribund (void) |
| 12989 | { |
| 12990 | struct bp_location *loc; |
| 12991 | int ix; |
| 12992 | |
| 12993 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 12994 | if (--(loc->events_till_retirement) == 0) |
| 12995 | { |
| 12996 | decref_bp_location (&loc); |
| 12997 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
| 12998 | --ix; |
| 12999 | } |
| 13000 | } |
| 13001 | |
| 13002 | static void |
| 13003 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
| 13004 | { |
| 13005 | volatile struct gdb_exception e; |
| 13006 | |
| 13007 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 13008 | update_global_location_list (insert_mode); |
| 13009 | } |
| 13010 | |
| 13011 | /* Clear BKP from a BPS. */ |
| 13012 | |
| 13013 | static void |
| 13014 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
| 13015 | { |
| 13016 | bpstat bs; |
| 13017 | |
| 13018 | for (bs = bps; bs; bs = bs->next) |
| 13019 | if (bs->breakpoint_at == bpt) |
| 13020 | { |
| 13021 | bs->breakpoint_at = NULL; |
| 13022 | bs->old_val = NULL; |
| 13023 | /* bs->commands will be freed later. */ |
| 13024 | } |
| 13025 | } |
| 13026 | |
| 13027 | /* Callback for iterate_over_threads. */ |
| 13028 | static int |
| 13029 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
| 13030 | { |
| 13031 | struct breakpoint *bpt = data; |
| 13032 | |
| 13033 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
| 13034 | return 0; |
| 13035 | } |
| 13036 | |
| 13037 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention |
| 13038 | callbacks. */ |
| 13039 | |
| 13040 | static void |
| 13041 | say_where (struct breakpoint *b) |
| 13042 | { |
| 13043 | struct value_print_options opts; |
| 13044 | |
| 13045 | get_user_print_options (&opts); |
| 13046 | |
| 13047 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
| 13048 | single string. */ |
| 13049 | if (b->loc == NULL) |
| 13050 | { |
| 13051 | printf_filtered (_(" (%s) pending."), b->addr_string); |
| 13052 | } |
| 13053 | else |
| 13054 | { |
| 13055 | if (opts.addressprint || b->loc->symtab == NULL) |
| 13056 | { |
| 13057 | printf_filtered (" at "); |
| 13058 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
| 13059 | gdb_stdout); |
| 13060 | } |
| 13061 | if (b->loc->symtab != NULL) |
| 13062 | { |
| 13063 | /* If there is a single location, we can print the location |
| 13064 | more nicely. */ |
| 13065 | if (b->loc->next == NULL) |
| 13066 | printf_filtered (": file %s, line %d.", |
| 13067 | symtab_to_filename_for_display (b->loc->symtab), |
| 13068 | b->loc->line_number); |
| 13069 | else |
| 13070 | /* This is not ideal, but each location may have a |
| 13071 | different file name, and this at least reflects the |
| 13072 | real situation somewhat. */ |
| 13073 | printf_filtered (": %s.", b->addr_string); |
| 13074 | } |
| 13075 | |
| 13076 | if (b->loc->next) |
| 13077 | { |
| 13078 | struct bp_location *loc = b->loc; |
| 13079 | int n = 0; |
| 13080 | for (; loc; loc = loc->next) |
| 13081 | ++n; |
| 13082 | printf_filtered (" (%d locations)", n); |
| 13083 | } |
| 13084 | } |
| 13085 | } |
| 13086 | |
| 13087 | /* Default bp_location_ops methods. */ |
| 13088 | |
| 13089 | static void |
| 13090 | bp_location_dtor (struct bp_location *self) |
| 13091 | { |
| 13092 | xfree (self->cond); |
| 13093 | if (self->cond_bytecode) |
| 13094 | free_agent_expr (self->cond_bytecode); |
| 13095 | xfree (self->function_name); |
| 13096 | |
| 13097 | VEC_free (agent_expr_p, self->target_info.conditions); |
| 13098 | VEC_free (agent_expr_p, self->target_info.tcommands); |
| 13099 | } |
| 13100 | |
| 13101 | static const struct bp_location_ops bp_location_ops = |
| 13102 | { |
| 13103 | bp_location_dtor |
| 13104 | }; |
| 13105 | |
| 13106 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
| 13107 | inherit from. */ |
| 13108 | |
| 13109 | static void |
| 13110 | base_breakpoint_dtor (struct breakpoint *self) |
| 13111 | { |
| 13112 | decref_counted_command_line (&self->commands); |
| 13113 | xfree (self->cond_string); |
| 13114 | xfree (self->extra_string); |
| 13115 | xfree (self->addr_string); |
| 13116 | xfree (self->filter); |
| 13117 | xfree (self->addr_string_range_end); |
| 13118 | } |
| 13119 | |
| 13120 | static struct bp_location * |
| 13121 | base_breakpoint_allocate_location (struct breakpoint *self) |
| 13122 | { |
| 13123 | struct bp_location *loc; |
| 13124 | |
| 13125 | loc = XNEW (struct bp_location); |
| 13126 | init_bp_location (loc, &bp_location_ops, self); |
| 13127 | return loc; |
| 13128 | } |
| 13129 | |
| 13130 | static void |
| 13131 | base_breakpoint_re_set (struct breakpoint *b) |
| 13132 | { |
| 13133 | /* Nothing to re-set. */ |
| 13134 | } |
| 13135 | |
| 13136 | #define internal_error_pure_virtual_called() \ |
| 13137 | gdb_assert_not_reached ("pure virtual function called") |
| 13138 | |
| 13139 | static int |
| 13140 | base_breakpoint_insert_location (struct bp_location *bl) |
| 13141 | { |
| 13142 | internal_error_pure_virtual_called (); |
| 13143 | } |
| 13144 | |
| 13145 | static int |
| 13146 | base_breakpoint_remove_location (struct bp_location *bl) |
| 13147 | { |
| 13148 | internal_error_pure_virtual_called (); |
| 13149 | } |
| 13150 | |
| 13151 | static int |
| 13152 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, |
| 13153 | struct address_space *aspace, |
| 13154 | CORE_ADDR bp_addr, |
| 13155 | const struct target_waitstatus *ws) |
| 13156 | { |
| 13157 | internal_error_pure_virtual_called (); |
| 13158 | } |
| 13159 | |
| 13160 | static void |
| 13161 | base_breakpoint_check_status (bpstat bs) |
| 13162 | { |
| 13163 | /* Always stop. */ |
| 13164 | } |
| 13165 | |
| 13166 | /* A "works_in_software_mode" breakpoint_ops method that just internal |
| 13167 | errors. */ |
| 13168 | |
| 13169 | static int |
| 13170 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) |
| 13171 | { |
| 13172 | internal_error_pure_virtual_called (); |
| 13173 | } |
| 13174 | |
| 13175 | /* A "resources_needed" breakpoint_ops method that just internal |
| 13176 | errors. */ |
| 13177 | |
| 13178 | static int |
| 13179 | base_breakpoint_resources_needed (const struct bp_location *bl) |
| 13180 | { |
| 13181 | internal_error_pure_virtual_called (); |
| 13182 | } |
| 13183 | |
| 13184 | static enum print_stop_action |
| 13185 | base_breakpoint_print_it (bpstat bs) |
| 13186 | { |
| 13187 | internal_error_pure_virtual_called (); |
| 13188 | } |
| 13189 | |
| 13190 | static void |
| 13191 | base_breakpoint_print_one_detail (const struct breakpoint *self, |
| 13192 | struct ui_out *uiout) |
| 13193 | { |
| 13194 | /* nothing */ |
| 13195 | } |
| 13196 | |
| 13197 | static void |
| 13198 | base_breakpoint_print_mention (struct breakpoint *b) |
| 13199 | { |
| 13200 | internal_error_pure_virtual_called (); |
| 13201 | } |
| 13202 | |
| 13203 | static void |
| 13204 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) |
| 13205 | { |
| 13206 | internal_error_pure_virtual_called (); |
| 13207 | } |
| 13208 | |
| 13209 | static void |
| 13210 | base_breakpoint_create_sals_from_address (char **arg, |
| 13211 | struct linespec_result *canonical, |
| 13212 | enum bptype type_wanted, |
| 13213 | char *addr_start, |
| 13214 | char **copy_arg) |
| 13215 | { |
| 13216 | internal_error_pure_virtual_called (); |
| 13217 | } |
| 13218 | |
| 13219 | static void |
| 13220 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 13221 | struct linespec_result *c, |
| 13222 | char *cond_string, |
| 13223 | char *extra_string, |
| 13224 | enum bptype type_wanted, |
| 13225 | enum bpdisp disposition, |
| 13226 | int thread, |
| 13227 | int task, int ignore_count, |
| 13228 | const struct breakpoint_ops *o, |
| 13229 | int from_tty, int enabled, |
| 13230 | int internal, unsigned flags) |
| 13231 | { |
| 13232 | internal_error_pure_virtual_called (); |
| 13233 | } |
| 13234 | |
| 13235 | static void |
| 13236 | base_breakpoint_decode_linespec (struct breakpoint *b, char **s, |
| 13237 | struct symtabs_and_lines *sals) |
| 13238 | { |
| 13239 | internal_error_pure_virtual_called (); |
| 13240 | } |
| 13241 | |
| 13242 | /* The default 'explains_signal' method. */ |
| 13243 | |
| 13244 | static int |
| 13245 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
| 13246 | { |
| 13247 | return 1; |
| 13248 | } |
| 13249 | |
| 13250 | /* The default "after_condition_true" method. */ |
| 13251 | |
| 13252 | static void |
| 13253 | base_breakpoint_after_condition_true (struct bpstats *bs) |
| 13254 | { |
| 13255 | /* Nothing to do. */ |
| 13256 | } |
| 13257 | |
| 13258 | struct breakpoint_ops base_breakpoint_ops = |
| 13259 | { |
| 13260 | base_breakpoint_dtor, |
| 13261 | base_breakpoint_allocate_location, |
| 13262 | base_breakpoint_re_set, |
| 13263 | base_breakpoint_insert_location, |
| 13264 | base_breakpoint_remove_location, |
| 13265 | base_breakpoint_breakpoint_hit, |
| 13266 | base_breakpoint_check_status, |
| 13267 | base_breakpoint_resources_needed, |
| 13268 | base_breakpoint_works_in_software_mode, |
| 13269 | base_breakpoint_print_it, |
| 13270 | NULL, |
| 13271 | base_breakpoint_print_one_detail, |
| 13272 | base_breakpoint_print_mention, |
| 13273 | base_breakpoint_print_recreate, |
| 13274 | base_breakpoint_create_sals_from_address, |
| 13275 | base_breakpoint_create_breakpoints_sal, |
| 13276 | base_breakpoint_decode_linespec, |
| 13277 | base_breakpoint_explains_signal, |
| 13278 | base_breakpoint_after_condition_true, |
| 13279 | }; |
| 13280 | |
| 13281 | /* Default breakpoint_ops methods. */ |
| 13282 | |
| 13283 | static void |
| 13284 | bkpt_re_set (struct breakpoint *b) |
| 13285 | { |
| 13286 | /* FIXME: is this still reachable? */ |
| 13287 | if (b->addr_string == NULL) |
| 13288 | { |
| 13289 | /* Anything without a string can't be re-set. */ |
| 13290 | delete_breakpoint (b); |
| 13291 | return; |
| 13292 | } |
| 13293 | |
| 13294 | breakpoint_re_set_default (b); |
| 13295 | } |
| 13296 | |
| 13297 | /* Copy SRC's shadow buffer and whatever else we'd set if we actually |
| 13298 | inserted DEST, so we can remove it later, in case SRC is removed |
| 13299 | first. */ |
| 13300 | |
| 13301 | static void |
| 13302 | bp_target_info_copy_insertion_state (struct bp_target_info *dest, |
| 13303 | const struct bp_target_info *src) |
| 13304 | { |
| 13305 | dest->shadow_len = src->shadow_len; |
| 13306 | memcpy (dest->shadow_contents, src->shadow_contents, src->shadow_len); |
| 13307 | dest->placed_size = src->placed_size; |
| 13308 | } |
| 13309 | |
| 13310 | static int |
| 13311 | bkpt_insert_location (struct bp_location *bl) |
| 13312 | { |
| 13313 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 13314 | return target_insert_hw_breakpoint (bl->gdbarch, |
| 13315 | &bl->target_info); |
| 13316 | else |
| 13317 | { |
| 13318 | struct bp_target_info *bp_tgt = &bl->target_info; |
| 13319 | int ret; |
| 13320 | int sss_slot; |
| 13321 | |
| 13322 | /* There is no need to insert a breakpoint if an unconditional |
| 13323 | raw/sss breakpoint is already inserted at that location. */ |
| 13324 | sss_slot = find_single_step_breakpoint (bp_tgt->placed_address_space, |
| 13325 | bp_tgt->placed_address); |
| 13326 | if (sss_slot >= 0) |
| 13327 | { |
| 13328 | struct bp_target_info *sss_bp_tgt = single_step_breakpoints[sss_slot]; |
| 13329 | |
| 13330 | bp_target_info_copy_insertion_state (bp_tgt, sss_bp_tgt); |
| 13331 | return 0; |
| 13332 | } |
| 13333 | |
| 13334 | return target_insert_breakpoint (bl->gdbarch, bp_tgt); |
| 13335 | } |
| 13336 | } |
| 13337 | |
| 13338 | static int |
| 13339 | bkpt_remove_location (struct bp_location *bl) |
| 13340 | { |
| 13341 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 13342 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); |
| 13343 | else |
| 13344 | { |
| 13345 | struct bp_target_info *bp_tgt = &bl->target_info; |
| 13346 | struct address_space *aspace = bp_tgt->placed_address_space; |
| 13347 | CORE_ADDR address = bp_tgt->placed_address; |
| 13348 | |
| 13349 | /* Only remove the breakpoint if there is no raw/sss breakpoint |
| 13350 | still inserted at this location. Otherwise, we would be |
| 13351 | effectively disabling the raw/sss breakpoint. */ |
| 13352 | if (single_step_breakpoint_inserted_here_p (aspace, address)) |
| 13353 | return 0; |
| 13354 | |
| 13355 | return target_remove_breakpoint (bl->gdbarch, bp_tgt); |
| 13356 | } |
| 13357 | } |
| 13358 | |
| 13359 | static int |
| 13360 | bkpt_breakpoint_hit (const struct bp_location *bl, |
| 13361 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 13362 | const struct target_waitstatus *ws) |
| 13363 | { |
| 13364 | if (ws->kind != TARGET_WAITKIND_STOPPED |
| 13365 | || ws->value.sig != GDB_SIGNAL_TRAP) |
| 13366 | return 0; |
| 13367 | |
| 13368 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 13369 | aspace, bp_addr)) |
| 13370 | return 0; |
| 13371 | |
| 13372 | if (overlay_debugging /* unmapped overlay section */ |
| 13373 | && section_is_overlay (bl->section) |
| 13374 | && !section_is_mapped (bl->section)) |
| 13375 | return 0; |
| 13376 | |
| 13377 | return 1; |
| 13378 | } |
| 13379 | |
| 13380 | static int |
| 13381 | dprintf_breakpoint_hit (const struct bp_location *bl, |
| 13382 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 13383 | const struct target_waitstatus *ws) |
| 13384 | { |
| 13385 | if (dprintf_style == dprintf_style_agent |
| 13386 | && target_can_run_breakpoint_commands ()) |
| 13387 | { |
| 13388 | /* An agent-style dprintf never causes a stop. If we see a trap |
| 13389 | for this address it must be for a breakpoint that happens to |
| 13390 | be set at the same address. */ |
| 13391 | return 0; |
| 13392 | } |
| 13393 | |
| 13394 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); |
| 13395 | } |
| 13396 | |
| 13397 | static int |
| 13398 | bkpt_resources_needed (const struct bp_location *bl) |
| 13399 | { |
| 13400 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); |
| 13401 | |
| 13402 | return 1; |
| 13403 | } |
| 13404 | |
| 13405 | static enum print_stop_action |
| 13406 | bkpt_print_it (bpstat bs) |
| 13407 | { |
| 13408 | struct breakpoint *b; |
| 13409 | const struct bp_location *bl; |
| 13410 | int bp_temp; |
| 13411 | struct ui_out *uiout = current_uiout; |
| 13412 | |
| 13413 | gdb_assert (bs->bp_location_at != NULL); |
| 13414 | |
| 13415 | bl = bs->bp_location_at; |
| 13416 | b = bs->breakpoint_at; |
| 13417 | |
| 13418 | bp_temp = b->disposition == disp_del; |
| 13419 | if (bl->address != bl->requested_address) |
| 13420 | breakpoint_adjustment_warning (bl->requested_address, |
| 13421 | bl->address, |
| 13422 | b->number, 1); |
| 13423 | annotate_breakpoint (b->number); |
| 13424 | if (bp_temp) |
| 13425 | ui_out_text (uiout, "\nTemporary breakpoint "); |
| 13426 | else |
| 13427 | ui_out_text (uiout, "\nBreakpoint "); |
| 13428 | if (ui_out_is_mi_like_p (uiout)) |
| 13429 | { |
| 13430 | ui_out_field_string (uiout, "reason", |
| 13431 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 13432 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 13433 | } |
| 13434 | ui_out_field_int (uiout, "bkptno", b->number); |
| 13435 | ui_out_text (uiout, ", "); |
| 13436 | |
| 13437 | return PRINT_SRC_AND_LOC; |
| 13438 | } |
| 13439 | |
| 13440 | static void |
| 13441 | bkpt_print_mention (struct breakpoint *b) |
| 13442 | { |
| 13443 | if (ui_out_is_mi_like_p (current_uiout)) |
| 13444 | return; |
| 13445 | |
| 13446 | switch (b->type) |
| 13447 | { |
| 13448 | case bp_breakpoint: |
| 13449 | case bp_gnu_ifunc_resolver: |
| 13450 | if (b->disposition == disp_del) |
| 13451 | printf_filtered (_("Temporary breakpoint")); |
| 13452 | else |
| 13453 | printf_filtered (_("Breakpoint")); |
| 13454 | printf_filtered (_(" %d"), b->number); |
| 13455 | if (b->type == bp_gnu_ifunc_resolver) |
| 13456 | printf_filtered (_(" at gnu-indirect-function resolver")); |
| 13457 | break; |
| 13458 | case bp_hardware_breakpoint: |
| 13459 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
| 13460 | break; |
| 13461 | case bp_dprintf: |
| 13462 | printf_filtered (_("Dprintf %d"), b->number); |
| 13463 | break; |
| 13464 | } |
| 13465 | |
| 13466 | say_where (b); |
| 13467 | } |
| 13468 | |
| 13469 | static void |
| 13470 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
| 13471 | { |
| 13472 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) |
| 13473 | fprintf_unfiltered (fp, "tbreak"); |
| 13474 | else if (tp->type == bp_breakpoint) |
| 13475 | fprintf_unfiltered (fp, "break"); |
| 13476 | else if (tp->type == bp_hardware_breakpoint |
| 13477 | && tp->disposition == disp_del) |
| 13478 | fprintf_unfiltered (fp, "thbreak"); |
| 13479 | else if (tp->type == bp_hardware_breakpoint) |
| 13480 | fprintf_unfiltered (fp, "hbreak"); |
| 13481 | else |
| 13482 | internal_error (__FILE__, __LINE__, |
| 13483 | _("unhandled breakpoint type %d"), (int) tp->type); |
| 13484 | |
| 13485 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
| 13486 | print_recreate_thread (tp, fp); |
| 13487 | } |
| 13488 | |
| 13489 | static void |
| 13490 | bkpt_create_sals_from_address (char **arg, |
| 13491 | struct linespec_result *canonical, |
| 13492 | enum bptype type_wanted, |
| 13493 | char *addr_start, char **copy_arg) |
| 13494 | { |
| 13495 | create_sals_from_address_default (arg, canonical, type_wanted, |
| 13496 | addr_start, copy_arg); |
| 13497 | } |
| 13498 | |
| 13499 | static void |
| 13500 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 13501 | struct linespec_result *canonical, |
| 13502 | char *cond_string, |
| 13503 | char *extra_string, |
| 13504 | enum bptype type_wanted, |
| 13505 | enum bpdisp disposition, |
| 13506 | int thread, |
| 13507 | int task, int ignore_count, |
| 13508 | const struct breakpoint_ops *ops, |
| 13509 | int from_tty, int enabled, |
| 13510 | int internal, unsigned flags) |
| 13511 | { |
| 13512 | create_breakpoints_sal_default (gdbarch, canonical, |
| 13513 | cond_string, extra_string, |
| 13514 | type_wanted, |
| 13515 | disposition, thread, task, |
| 13516 | ignore_count, ops, from_tty, |
| 13517 | enabled, internal, flags); |
| 13518 | } |
| 13519 | |
| 13520 | static void |
| 13521 | bkpt_decode_linespec (struct breakpoint *b, char **s, |
| 13522 | struct symtabs_and_lines *sals) |
| 13523 | { |
| 13524 | decode_linespec_default (b, s, sals); |
| 13525 | } |
| 13526 | |
| 13527 | /* Virtual table for internal breakpoints. */ |
| 13528 | |
| 13529 | static void |
| 13530 | internal_bkpt_re_set (struct breakpoint *b) |
| 13531 | { |
| 13532 | switch (b->type) |
| 13533 | { |
| 13534 | /* Delete overlay event and longjmp master breakpoints; they |
| 13535 | will be reset later by breakpoint_re_set. */ |
| 13536 | case bp_overlay_event: |
| 13537 | case bp_longjmp_master: |
| 13538 | case bp_std_terminate_master: |
| 13539 | case bp_exception_master: |
| 13540 | delete_breakpoint (b); |
| 13541 | break; |
| 13542 | |
| 13543 | /* This breakpoint is special, it's set up when the inferior |
| 13544 | starts and we really don't want to touch it. */ |
| 13545 | case bp_shlib_event: |
| 13546 | |
| 13547 | /* Like bp_shlib_event, this breakpoint type is special. Once |
| 13548 | it is set up, we do not want to touch it. */ |
| 13549 | case bp_thread_event: |
| 13550 | break; |
| 13551 | } |
| 13552 | } |
| 13553 | |
| 13554 | static void |
| 13555 | internal_bkpt_check_status (bpstat bs) |
| 13556 | { |
| 13557 | if (bs->breakpoint_at->type == bp_shlib_event) |
| 13558 | { |
| 13559 | /* If requested, stop when the dynamic linker notifies GDB of |
| 13560 | events. This allows the user to get control and place |
| 13561 | breakpoints in initializer routines for dynamically loaded |
| 13562 | objects (among other things). */ |
| 13563 | bs->stop = stop_on_solib_events; |
| 13564 | bs->print = stop_on_solib_events; |
| 13565 | } |
| 13566 | else |
| 13567 | bs->stop = 0; |
| 13568 | } |
| 13569 | |
| 13570 | static enum print_stop_action |
| 13571 | internal_bkpt_print_it (bpstat bs) |
| 13572 | { |
| 13573 | struct breakpoint *b; |
| 13574 | |
| 13575 | b = bs->breakpoint_at; |
| 13576 | |
| 13577 | switch (b->type) |
| 13578 | { |
| 13579 | case bp_shlib_event: |
| 13580 | /* Did we stop because the user set the stop_on_solib_events |
| 13581 | variable? (If so, we report this as a generic, "Stopped due |
| 13582 | to shlib event" message.) */ |
| 13583 | print_solib_event (0); |
| 13584 | break; |
| 13585 | |
| 13586 | case bp_thread_event: |
| 13587 | /* Not sure how we will get here. |
| 13588 | GDB should not stop for these breakpoints. */ |
| 13589 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
| 13590 | break; |
| 13591 | |
| 13592 | case bp_overlay_event: |
| 13593 | /* By analogy with the thread event, GDB should not stop for these. */ |
| 13594 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
| 13595 | break; |
| 13596 | |
| 13597 | case bp_longjmp_master: |
| 13598 | /* These should never be enabled. */ |
| 13599 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); |
| 13600 | break; |
| 13601 | |
| 13602 | case bp_std_terminate_master: |
| 13603 | /* These should never be enabled. */ |
| 13604 | printf_filtered (_("std::terminate Master Breakpoint: " |
| 13605 | "gdb should not stop!\n")); |
| 13606 | break; |
| 13607 | |
| 13608 | case bp_exception_master: |
| 13609 | /* These should never be enabled. */ |
| 13610 | printf_filtered (_("Exception Master Breakpoint: " |
| 13611 | "gdb should not stop!\n")); |
| 13612 | break; |
| 13613 | } |
| 13614 | |
| 13615 | return PRINT_NOTHING; |
| 13616 | } |
| 13617 | |
| 13618 | static void |
| 13619 | internal_bkpt_print_mention (struct breakpoint *b) |
| 13620 | { |
| 13621 | /* Nothing to mention. These breakpoints are internal. */ |
| 13622 | } |
| 13623 | |
| 13624 | /* Virtual table for momentary breakpoints */ |
| 13625 | |
| 13626 | static void |
| 13627 | momentary_bkpt_re_set (struct breakpoint *b) |
| 13628 | { |
| 13629 | /* Keep temporary breakpoints, which can be encountered when we step |
| 13630 | over a dlopen call and solib_add is resetting the breakpoints. |
| 13631 | Otherwise these should have been blown away via the cleanup chain |
| 13632 | or by breakpoint_init_inferior when we rerun the executable. */ |
| 13633 | } |
| 13634 | |
| 13635 | static void |
| 13636 | momentary_bkpt_check_status (bpstat bs) |
| 13637 | { |
| 13638 | /* Nothing. The point of these breakpoints is causing a stop. */ |
| 13639 | } |
| 13640 | |
| 13641 | static enum print_stop_action |
| 13642 | momentary_bkpt_print_it (bpstat bs) |
| 13643 | { |
| 13644 | struct ui_out *uiout = current_uiout; |
| 13645 | |
| 13646 | if (ui_out_is_mi_like_p (uiout)) |
| 13647 | { |
| 13648 | struct breakpoint *b = bs->breakpoint_at; |
| 13649 | |
| 13650 | switch (b->type) |
| 13651 | { |
| 13652 | case bp_finish: |
| 13653 | ui_out_field_string |
| 13654 | (uiout, "reason", |
| 13655 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); |
| 13656 | break; |
| 13657 | |
| 13658 | case bp_until: |
| 13659 | ui_out_field_string |
| 13660 | (uiout, "reason", |
| 13661 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); |
| 13662 | break; |
| 13663 | } |
| 13664 | } |
| 13665 | |
| 13666 | return PRINT_UNKNOWN; |
| 13667 | } |
| 13668 | |
| 13669 | static void |
| 13670 | momentary_bkpt_print_mention (struct breakpoint *b) |
| 13671 | { |
| 13672 | /* Nothing to mention. These breakpoints are internal. */ |
| 13673 | } |
| 13674 | |
| 13675 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
| 13676 | |
| 13677 | It gets cleared already on the removal of the first one of such placed |
| 13678 | breakpoints. This is OK as they get all removed altogether. */ |
| 13679 | |
| 13680 | static void |
| 13681 | longjmp_bkpt_dtor (struct breakpoint *self) |
| 13682 | { |
| 13683 | struct thread_info *tp = find_thread_id (self->thread); |
| 13684 | |
| 13685 | if (tp) |
| 13686 | tp->initiating_frame = null_frame_id; |
| 13687 | |
| 13688 | momentary_breakpoint_ops.dtor (self); |
| 13689 | } |
| 13690 | |
| 13691 | /* Specific methods for probe breakpoints. */ |
| 13692 | |
| 13693 | static int |
| 13694 | bkpt_probe_insert_location (struct bp_location *bl) |
| 13695 | { |
| 13696 | int v = bkpt_insert_location (bl); |
| 13697 | |
| 13698 | if (v == 0) |
| 13699 | { |
| 13700 | /* The insertion was successful, now let's set the probe's semaphore |
| 13701 | if needed. */ |
| 13702 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, |
| 13703 | bl->probe.objfile, |
| 13704 | bl->gdbarch); |
| 13705 | } |
| 13706 | |
| 13707 | return v; |
| 13708 | } |
| 13709 | |
| 13710 | static int |
| 13711 | bkpt_probe_remove_location (struct bp_location *bl) |
| 13712 | { |
| 13713 | /* Let's clear the semaphore before removing the location. */ |
| 13714 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, |
| 13715 | bl->probe.objfile, |
| 13716 | bl->gdbarch); |
| 13717 | |
| 13718 | return bkpt_remove_location (bl); |
| 13719 | } |
| 13720 | |
| 13721 | static void |
| 13722 | bkpt_probe_create_sals_from_address (char **arg, |
| 13723 | struct linespec_result *canonical, |
| 13724 | enum bptype type_wanted, |
| 13725 | char *addr_start, char **copy_arg) |
| 13726 | { |
| 13727 | struct linespec_sals lsal; |
| 13728 | |
| 13729 | lsal.sals = parse_probes (arg, canonical); |
| 13730 | |
| 13731 | *copy_arg = xstrdup (canonical->addr_string); |
| 13732 | lsal.canonical = xstrdup (*copy_arg); |
| 13733 | |
| 13734 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
| 13735 | } |
| 13736 | |
| 13737 | static void |
| 13738 | bkpt_probe_decode_linespec (struct breakpoint *b, char **s, |
| 13739 | struct symtabs_and_lines *sals) |
| 13740 | { |
| 13741 | *sals = parse_probes (s, NULL); |
| 13742 | if (!sals->sals) |
| 13743 | error (_("probe not found")); |
| 13744 | } |
| 13745 | |
| 13746 | /* The breakpoint_ops structure to be used in tracepoints. */ |
| 13747 | |
| 13748 | static void |
| 13749 | tracepoint_re_set (struct breakpoint *b) |
| 13750 | { |
| 13751 | breakpoint_re_set_default (b); |
| 13752 | } |
| 13753 | |
| 13754 | static int |
| 13755 | tracepoint_breakpoint_hit (const struct bp_location *bl, |
| 13756 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 13757 | const struct target_waitstatus *ws) |
| 13758 | { |
| 13759 | /* By definition, the inferior does not report stops at |
| 13760 | tracepoints. */ |
| 13761 | return 0; |
| 13762 | } |
| 13763 | |
| 13764 | static void |
| 13765 | tracepoint_print_one_detail (const struct breakpoint *self, |
| 13766 | struct ui_out *uiout) |
| 13767 | { |
| 13768 | struct tracepoint *tp = (struct tracepoint *) self; |
| 13769 | if (tp->static_trace_marker_id) |
| 13770 | { |
| 13771 | gdb_assert (self->type == bp_static_tracepoint); |
| 13772 | |
| 13773 | ui_out_text (uiout, "\tmarker id is "); |
| 13774 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", |
| 13775 | tp->static_trace_marker_id); |
| 13776 | ui_out_text (uiout, "\n"); |
| 13777 | } |
| 13778 | } |
| 13779 | |
| 13780 | static void |
| 13781 | tracepoint_print_mention (struct breakpoint *b) |
| 13782 | { |
| 13783 | if (ui_out_is_mi_like_p (current_uiout)) |
| 13784 | return; |
| 13785 | |
| 13786 | switch (b->type) |
| 13787 | { |
| 13788 | case bp_tracepoint: |
| 13789 | printf_filtered (_("Tracepoint")); |
| 13790 | printf_filtered (_(" %d"), b->number); |
| 13791 | break; |
| 13792 | case bp_fast_tracepoint: |
| 13793 | printf_filtered (_("Fast tracepoint")); |
| 13794 | printf_filtered (_(" %d"), b->number); |
| 13795 | break; |
| 13796 | case bp_static_tracepoint: |
| 13797 | printf_filtered (_("Static tracepoint")); |
| 13798 | printf_filtered (_(" %d"), b->number); |
| 13799 | break; |
| 13800 | default: |
| 13801 | internal_error (__FILE__, __LINE__, |
| 13802 | _("unhandled tracepoint type %d"), (int) b->type); |
| 13803 | } |
| 13804 | |
| 13805 | say_where (b); |
| 13806 | } |
| 13807 | |
| 13808 | static void |
| 13809 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
| 13810 | { |
| 13811 | struct tracepoint *tp = (struct tracepoint *) self; |
| 13812 | |
| 13813 | if (self->type == bp_fast_tracepoint) |
| 13814 | fprintf_unfiltered (fp, "ftrace"); |
| 13815 | if (self->type == bp_static_tracepoint) |
| 13816 | fprintf_unfiltered (fp, "strace"); |
| 13817 | else if (self->type == bp_tracepoint) |
| 13818 | fprintf_unfiltered (fp, "trace"); |
| 13819 | else |
| 13820 | internal_error (__FILE__, __LINE__, |
| 13821 | _("unhandled tracepoint type %d"), (int) self->type); |
| 13822 | |
| 13823 | fprintf_unfiltered (fp, " %s", self->addr_string); |
| 13824 | print_recreate_thread (self, fp); |
| 13825 | |
| 13826 | if (tp->pass_count) |
| 13827 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
| 13828 | } |
| 13829 | |
| 13830 | static void |
| 13831 | tracepoint_create_sals_from_address (char **arg, |
| 13832 | struct linespec_result *canonical, |
| 13833 | enum bptype type_wanted, |
| 13834 | char *addr_start, char **copy_arg) |
| 13835 | { |
| 13836 | create_sals_from_address_default (arg, canonical, type_wanted, |
| 13837 | addr_start, copy_arg); |
| 13838 | } |
| 13839 | |
| 13840 | static void |
| 13841 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 13842 | struct linespec_result *canonical, |
| 13843 | char *cond_string, |
| 13844 | char *extra_string, |
| 13845 | enum bptype type_wanted, |
| 13846 | enum bpdisp disposition, |
| 13847 | int thread, |
| 13848 | int task, int ignore_count, |
| 13849 | const struct breakpoint_ops *ops, |
| 13850 | int from_tty, int enabled, |
| 13851 | int internal, unsigned flags) |
| 13852 | { |
| 13853 | create_breakpoints_sal_default (gdbarch, canonical, |
| 13854 | cond_string, extra_string, |
| 13855 | type_wanted, |
| 13856 | disposition, thread, task, |
| 13857 | ignore_count, ops, from_tty, |
| 13858 | enabled, internal, flags); |
| 13859 | } |
| 13860 | |
| 13861 | static void |
| 13862 | tracepoint_decode_linespec (struct breakpoint *b, char **s, |
| 13863 | struct symtabs_and_lines *sals) |
| 13864 | { |
| 13865 | decode_linespec_default (b, s, sals); |
| 13866 | } |
| 13867 | |
| 13868 | struct breakpoint_ops tracepoint_breakpoint_ops; |
| 13869 | |
| 13870 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
| 13871 | static probe. */ |
| 13872 | |
| 13873 | static void |
| 13874 | tracepoint_probe_create_sals_from_address (char **arg, |
| 13875 | struct linespec_result *canonical, |
| 13876 | enum bptype type_wanted, |
| 13877 | char *addr_start, char **copy_arg) |
| 13878 | { |
| 13879 | /* We use the same method for breakpoint on probes. */ |
| 13880 | bkpt_probe_create_sals_from_address (arg, canonical, type_wanted, |
| 13881 | addr_start, copy_arg); |
| 13882 | } |
| 13883 | |
| 13884 | static void |
| 13885 | tracepoint_probe_decode_linespec (struct breakpoint *b, char **s, |
| 13886 | struct symtabs_and_lines *sals) |
| 13887 | { |
| 13888 | /* We use the same method for breakpoint on probes. */ |
| 13889 | bkpt_probe_decode_linespec (b, s, sals); |
| 13890 | } |
| 13891 | |
| 13892 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; |
| 13893 | |
| 13894 | /* Dprintf breakpoint_ops methods. */ |
| 13895 | |
| 13896 | static void |
| 13897 | dprintf_re_set (struct breakpoint *b) |
| 13898 | { |
| 13899 | breakpoint_re_set_default (b); |
| 13900 | |
| 13901 | /* This breakpoint could have been pending, and be resolved now, and |
| 13902 | if so, we should now have the extra string. If we don't, the |
| 13903 | dprintf was malformed when created, but we couldn't tell because |
| 13904 | we can't extract the extra string until the location is |
| 13905 | resolved. */ |
| 13906 | if (b->loc != NULL && b->extra_string == NULL) |
| 13907 | error (_("Format string required")); |
| 13908 | |
| 13909 | /* 1 - connect to target 1, that can run breakpoint commands. |
| 13910 | 2 - create a dprintf, which resolves fine. |
| 13911 | 3 - disconnect from target 1 |
| 13912 | 4 - connect to target 2, that can NOT run breakpoint commands. |
| 13913 | |
| 13914 | After steps #3/#4, you'll want the dprintf command list to |
| 13915 | be updated, because target 1 and 2 may well return different |
| 13916 | answers for target_can_run_breakpoint_commands(). |
| 13917 | Given absence of finer grained resetting, we get to do |
| 13918 | it all the time. */ |
| 13919 | if (b->extra_string != NULL) |
| 13920 | update_dprintf_command_list (b); |
| 13921 | } |
| 13922 | |
| 13923 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
| 13924 | |
| 13925 | static void |
| 13926 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
| 13927 | { |
| 13928 | fprintf_unfiltered (fp, "dprintf %s%s", tp->addr_string, |
| 13929 | tp->extra_string); |
| 13930 | print_recreate_thread (tp, fp); |
| 13931 | } |
| 13932 | |
| 13933 | /* Implement the "after_condition_true" breakpoint_ops method for |
| 13934 | dprintf. |
| 13935 | |
| 13936 | dprintf's are implemented with regular commands in their command |
| 13937 | list, but we run the commands here instead of before presenting the |
| 13938 | stop to the user, as dprintf's don't actually cause a stop. This |
| 13939 | also makes it so that the commands of multiple dprintfs at the same |
| 13940 | address are all handled. */ |
| 13941 | |
| 13942 | static void |
| 13943 | dprintf_after_condition_true (struct bpstats *bs) |
| 13944 | { |
| 13945 | struct cleanup *old_chain; |
| 13946 | struct bpstats tmp_bs = { NULL }; |
| 13947 | struct bpstats *tmp_bs_p = &tmp_bs; |
| 13948 | |
| 13949 | /* dprintf's never cause a stop. This wasn't set in the |
| 13950 | check_status hook instead because that would make the dprintf's |
| 13951 | condition not be evaluated. */ |
| 13952 | bs->stop = 0; |
| 13953 | |
| 13954 | /* Run the command list here. Take ownership of it instead of |
| 13955 | copying. We never want these commands to run later in |
| 13956 | bpstat_do_actions, if a breakpoint that causes a stop happens to |
| 13957 | be set at same address as this dprintf, or even if running the |
| 13958 | commands here throws. */ |
| 13959 | tmp_bs.commands = bs->commands; |
| 13960 | bs->commands = NULL; |
| 13961 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); |
| 13962 | |
| 13963 | bpstat_do_actions_1 (&tmp_bs_p); |
| 13964 | |
| 13965 | /* 'tmp_bs.commands' will usually be NULL by now, but |
| 13966 | bpstat_do_actions_1 may return early without processing the whole |
| 13967 | list. */ |
| 13968 | do_cleanups (old_chain); |
| 13969 | } |
| 13970 | |
| 13971 | /* The breakpoint_ops structure to be used on static tracepoints with |
| 13972 | markers (`-m'). */ |
| 13973 | |
| 13974 | static void |
| 13975 | strace_marker_create_sals_from_address (char **arg, |
| 13976 | struct linespec_result *canonical, |
| 13977 | enum bptype type_wanted, |
| 13978 | char *addr_start, char **copy_arg) |
| 13979 | { |
| 13980 | struct linespec_sals lsal; |
| 13981 | |
| 13982 | lsal.sals = decode_static_tracepoint_spec (arg); |
| 13983 | |
| 13984 | *copy_arg = savestring (addr_start, *arg - addr_start); |
| 13985 | |
| 13986 | canonical->addr_string = xstrdup (*copy_arg); |
| 13987 | lsal.canonical = xstrdup (*copy_arg); |
| 13988 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
| 13989 | } |
| 13990 | |
| 13991 | static void |
| 13992 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 13993 | struct linespec_result *canonical, |
| 13994 | char *cond_string, |
| 13995 | char *extra_string, |
| 13996 | enum bptype type_wanted, |
| 13997 | enum bpdisp disposition, |
| 13998 | int thread, |
| 13999 | int task, int ignore_count, |
| 14000 | const struct breakpoint_ops *ops, |
| 14001 | int from_tty, int enabled, |
| 14002 | int internal, unsigned flags) |
| 14003 | { |
| 14004 | int i; |
| 14005 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
| 14006 | canonical->sals, 0); |
| 14007 | |
| 14008 | /* If the user is creating a static tracepoint by marker id |
| 14009 | (strace -m MARKER_ID), then store the sals index, so that |
| 14010 | breakpoint_re_set can try to match up which of the newly |
| 14011 | found markers corresponds to this one, and, don't try to |
| 14012 | expand multiple locations for each sal, given than SALS |
| 14013 | already should contain all sals for MARKER_ID. */ |
| 14014 | |
| 14015 | for (i = 0; i < lsal->sals.nelts; ++i) |
| 14016 | { |
| 14017 | struct symtabs_and_lines expanded; |
| 14018 | struct tracepoint *tp; |
| 14019 | struct cleanup *old_chain; |
| 14020 | char *addr_string; |
| 14021 | |
| 14022 | expanded.nelts = 1; |
| 14023 | expanded.sals = &lsal->sals.sals[i]; |
| 14024 | |
| 14025 | addr_string = xstrdup (canonical->addr_string); |
| 14026 | old_chain = make_cleanup (xfree, addr_string); |
| 14027 | |
| 14028 | tp = XCNEW (struct tracepoint); |
| 14029 | init_breakpoint_sal (&tp->base, gdbarch, expanded, |
| 14030 | addr_string, NULL, |
| 14031 | cond_string, extra_string, |
| 14032 | type_wanted, disposition, |
| 14033 | thread, task, ignore_count, ops, |
| 14034 | from_tty, enabled, internal, flags, |
| 14035 | canonical->special_display); |
| 14036 | /* Given that its possible to have multiple markers with |
| 14037 | the same string id, if the user is creating a static |
| 14038 | tracepoint by marker id ("strace -m MARKER_ID"), then |
| 14039 | store the sals index, so that breakpoint_re_set can |
| 14040 | try to match up which of the newly found markers |
| 14041 | corresponds to this one */ |
| 14042 | tp->static_trace_marker_id_idx = i; |
| 14043 | |
| 14044 | install_breakpoint (internal, &tp->base, 0); |
| 14045 | |
| 14046 | discard_cleanups (old_chain); |
| 14047 | } |
| 14048 | } |
| 14049 | |
| 14050 | static void |
| 14051 | strace_marker_decode_linespec (struct breakpoint *b, char **s, |
| 14052 | struct symtabs_and_lines *sals) |
| 14053 | { |
| 14054 | struct tracepoint *tp = (struct tracepoint *) b; |
| 14055 | |
| 14056 | *sals = decode_static_tracepoint_spec (s); |
| 14057 | if (sals->nelts > tp->static_trace_marker_id_idx) |
| 14058 | { |
| 14059 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; |
| 14060 | sals->nelts = 1; |
| 14061 | } |
| 14062 | else |
| 14063 | error (_("marker %s not found"), tp->static_trace_marker_id); |
| 14064 | } |
| 14065 | |
| 14066 | static struct breakpoint_ops strace_marker_breakpoint_ops; |
| 14067 | |
| 14068 | static int |
| 14069 | strace_marker_p (struct breakpoint *b) |
| 14070 | { |
| 14071 | return b->ops == &strace_marker_breakpoint_ops; |
| 14072 | } |
| 14073 | |
| 14074 | /* Delete a breakpoint and clean up all traces of it in the data |
| 14075 | structures. */ |
| 14076 | |
| 14077 | void |
| 14078 | delete_breakpoint (struct breakpoint *bpt) |
| 14079 | { |
| 14080 | struct breakpoint *b; |
| 14081 | |
| 14082 | gdb_assert (bpt != NULL); |
| 14083 | |
| 14084 | /* Has this bp already been deleted? This can happen because |
| 14085 | multiple lists can hold pointers to bp's. bpstat lists are |
| 14086 | especial culprits. |
| 14087 | |
| 14088 | One example of this happening is a watchpoint's scope bp. When |
| 14089 | the scope bp triggers, we notice that the watchpoint is out of |
| 14090 | scope, and delete it. We also delete its scope bp. But the |
| 14091 | scope bp is marked "auto-deleting", and is already on a bpstat. |
| 14092 | That bpstat is then checked for auto-deleting bp's, which are |
| 14093 | deleted. |
| 14094 | |
| 14095 | A real solution to this problem might involve reference counts in |
| 14096 | bp's, and/or giving them pointers back to their referencing |
| 14097 | bpstat's, and teaching delete_breakpoint to only free a bp's |
| 14098 | storage when no more references were extent. A cheaper bandaid |
| 14099 | was chosen. */ |
| 14100 | if (bpt->type == bp_none) |
| 14101 | return; |
| 14102 | |
| 14103 | /* At least avoid this stale reference until the reference counting |
| 14104 | of breakpoints gets resolved. */ |
| 14105 | if (bpt->related_breakpoint != bpt) |
| 14106 | { |
| 14107 | struct breakpoint *related; |
| 14108 | struct watchpoint *w; |
| 14109 | |
| 14110 | if (bpt->type == bp_watchpoint_scope) |
| 14111 | w = (struct watchpoint *) bpt->related_breakpoint; |
| 14112 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
| 14113 | w = (struct watchpoint *) bpt; |
| 14114 | else |
| 14115 | w = NULL; |
| 14116 | if (w != NULL) |
| 14117 | watchpoint_del_at_next_stop (w); |
| 14118 | |
| 14119 | /* Unlink bpt from the bpt->related_breakpoint ring. */ |
| 14120 | for (related = bpt; related->related_breakpoint != bpt; |
| 14121 | related = related->related_breakpoint); |
| 14122 | related->related_breakpoint = bpt->related_breakpoint; |
| 14123 | bpt->related_breakpoint = bpt; |
| 14124 | } |
| 14125 | |
| 14126 | /* watch_command_1 creates a watchpoint but only sets its number if |
| 14127 | update_watchpoint succeeds in creating its bp_locations. If there's |
| 14128 | a problem in that process, we'll be asked to delete the half-created |
| 14129 | watchpoint. In that case, don't announce the deletion. */ |
| 14130 | if (bpt->number) |
| 14131 | observer_notify_breakpoint_deleted (bpt); |
| 14132 | |
| 14133 | if (breakpoint_chain == bpt) |
| 14134 | breakpoint_chain = bpt->next; |
| 14135 | |
| 14136 | ALL_BREAKPOINTS (b) |
| 14137 | if (b->next == bpt) |
| 14138 | { |
| 14139 | b->next = bpt->next; |
| 14140 | break; |
| 14141 | } |
| 14142 | |
| 14143 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
| 14144 | been freed. */ |
| 14145 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat |
| 14146 | in all threads for now. Note that we cannot just remove bpstats |
| 14147 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
| 14148 | commands are associated with the bpstat; if we remove it here, |
| 14149 | then the later call to bpstat_do_actions (&stop_bpstat); in |
| 14150 | event-top.c won't do anything, and temporary breakpoints with |
| 14151 | commands won't work. */ |
| 14152 | |
| 14153 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
| 14154 | |
| 14155 | /* Now that breakpoint is removed from breakpoint list, update the |
| 14156 | global location list. This will remove locations that used to |
| 14157 | belong to this breakpoint. Do this before freeing the breakpoint |
| 14158 | itself, since remove_breakpoint looks at location's owner. It |
| 14159 | might be better design to have location completely |
| 14160 | self-contained, but it's not the case now. */ |
| 14161 | update_global_location_list (UGLL_DONT_INSERT); |
| 14162 | |
| 14163 | bpt->ops->dtor (bpt); |
| 14164 | /* On the chance that someone will soon try again to delete this |
| 14165 | same bp, we mark it as deleted before freeing its storage. */ |
| 14166 | bpt->type = bp_none; |
| 14167 | xfree (bpt); |
| 14168 | } |
| 14169 | |
| 14170 | static void |
| 14171 | do_delete_breakpoint_cleanup (void *b) |
| 14172 | { |
| 14173 | delete_breakpoint (b); |
| 14174 | } |
| 14175 | |
| 14176 | struct cleanup * |
| 14177 | make_cleanup_delete_breakpoint (struct breakpoint *b) |
| 14178 | { |
| 14179 | return make_cleanup (do_delete_breakpoint_cleanup, b); |
| 14180 | } |
| 14181 | |
| 14182 | /* Iterator function to call a user-provided callback function once |
| 14183 | for each of B and its related breakpoints. */ |
| 14184 | |
| 14185 | static void |
| 14186 | iterate_over_related_breakpoints (struct breakpoint *b, |
| 14187 | void (*function) (struct breakpoint *, |
| 14188 | void *), |
| 14189 | void *data) |
| 14190 | { |
| 14191 | struct breakpoint *related; |
| 14192 | |
| 14193 | related = b; |
| 14194 | do |
| 14195 | { |
| 14196 | struct breakpoint *next; |
| 14197 | |
| 14198 | /* FUNCTION may delete RELATED. */ |
| 14199 | next = related->related_breakpoint; |
| 14200 | |
| 14201 | if (next == related) |
| 14202 | { |
| 14203 | /* RELATED is the last ring entry. */ |
| 14204 | function (related, data); |
| 14205 | |
| 14206 | /* FUNCTION may have deleted it, so we'd never reach back to |
| 14207 | B. There's nothing left to do anyway, so just break |
| 14208 | out. */ |
| 14209 | break; |
| 14210 | } |
| 14211 | else |
| 14212 | function (related, data); |
| 14213 | |
| 14214 | related = next; |
| 14215 | } |
| 14216 | while (related != b); |
| 14217 | } |
| 14218 | |
| 14219 | static void |
| 14220 | do_delete_breakpoint (struct breakpoint *b, void *ignore) |
| 14221 | { |
| 14222 | delete_breakpoint (b); |
| 14223 | } |
| 14224 | |
| 14225 | /* A callback for map_breakpoint_numbers that calls |
| 14226 | delete_breakpoint. */ |
| 14227 | |
| 14228 | static void |
| 14229 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) |
| 14230 | { |
| 14231 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); |
| 14232 | } |
| 14233 | |
| 14234 | void |
| 14235 | delete_command (char *arg, int from_tty) |
| 14236 | { |
| 14237 | struct breakpoint *b, *b_tmp; |
| 14238 | |
| 14239 | dont_repeat (); |
| 14240 | |
| 14241 | if (arg == 0) |
| 14242 | { |
| 14243 | int breaks_to_delete = 0; |
| 14244 | |
| 14245 | /* Delete all breakpoints if no argument. Do not delete |
| 14246 | internal breakpoints, these have to be deleted with an |
| 14247 | explicit breakpoint number argument. */ |
| 14248 | ALL_BREAKPOINTS (b) |
| 14249 | if (user_breakpoint_p (b)) |
| 14250 | { |
| 14251 | breaks_to_delete = 1; |
| 14252 | break; |
| 14253 | } |
| 14254 | |
| 14255 | /* Ask user only if there are some breakpoints to delete. */ |
| 14256 | if (!from_tty |
| 14257 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
| 14258 | { |
| 14259 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 14260 | if (user_breakpoint_p (b)) |
| 14261 | delete_breakpoint (b); |
| 14262 | } |
| 14263 | } |
| 14264 | else |
| 14265 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
| 14266 | } |
| 14267 | |
| 14268 | static int |
| 14269 | all_locations_are_pending (struct bp_location *loc) |
| 14270 | { |
| 14271 | for (; loc; loc = loc->next) |
| 14272 | if (!loc->shlib_disabled |
| 14273 | && !loc->pspace->executing_startup) |
| 14274 | return 0; |
| 14275 | return 1; |
| 14276 | } |
| 14277 | |
| 14278 | /* Subroutine of update_breakpoint_locations to simplify it. |
| 14279 | Return non-zero if multiple fns in list LOC have the same name. |
| 14280 | Null names are ignored. */ |
| 14281 | |
| 14282 | static int |
| 14283 | ambiguous_names_p (struct bp_location *loc) |
| 14284 | { |
| 14285 | struct bp_location *l; |
| 14286 | htab_t htab = htab_create_alloc (13, htab_hash_string, |
| 14287 | (int (*) (const void *, |
| 14288 | const void *)) streq, |
| 14289 | NULL, xcalloc, xfree); |
| 14290 | |
| 14291 | for (l = loc; l != NULL; l = l->next) |
| 14292 | { |
| 14293 | const char **slot; |
| 14294 | const char *name = l->function_name; |
| 14295 | |
| 14296 | /* Allow for some names to be NULL, ignore them. */ |
| 14297 | if (name == NULL) |
| 14298 | continue; |
| 14299 | |
| 14300 | slot = (const char **) htab_find_slot (htab, (const void *) name, |
| 14301 | INSERT); |
| 14302 | /* NOTE: We can assume slot != NULL here because xcalloc never |
| 14303 | returns NULL. */ |
| 14304 | if (*slot != NULL) |
| 14305 | { |
| 14306 | htab_delete (htab); |
| 14307 | return 1; |
| 14308 | } |
| 14309 | *slot = name; |
| 14310 | } |
| 14311 | |
| 14312 | htab_delete (htab); |
| 14313 | return 0; |
| 14314 | } |
| 14315 | |
| 14316 | /* When symbols change, it probably means the sources changed as well, |
| 14317 | and it might mean the static tracepoint markers are no longer at |
| 14318 | the same address or line numbers they used to be at last we |
| 14319 | checked. Losing your static tracepoints whenever you rebuild is |
| 14320 | undesirable. This function tries to resync/rematch gdb static |
| 14321 | tracepoints with the markers on the target, for static tracepoints |
| 14322 | that have not been set by marker id. Static tracepoint that have |
| 14323 | been set by marker id are reset by marker id in breakpoint_re_set. |
| 14324 | The heuristic is: |
| 14325 | |
| 14326 | 1) For a tracepoint set at a specific address, look for a marker at |
| 14327 | the old PC. If one is found there, assume to be the same marker. |
| 14328 | If the name / string id of the marker found is different from the |
| 14329 | previous known name, assume that means the user renamed the marker |
| 14330 | in the sources, and output a warning. |
| 14331 | |
| 14332 | 2) For a tracepoint set at a given line number, look for a marker |
| 14333 | at the new address of the old line number. If one is found there, |
| 14334 | assume to be the same marker. If the name / string id of the |
| 14335 | marker found is different from the previous known name, assume that |
| 14336 | means the user renamed the marker in the sources, and output a |
| 14337 | warning. |
| 14338 | |
| 14339 | 3) If a marker is no longer found at the same address or line, it |
| 14340 | may mean the marker no longer exists. But it may also just mean |
| 14341 | the code changed a bit. Maybe the user added a few lines of code |
| 14342 | that made the marker move up or down (in line number terms). Ask |
| 14343 | the target for info about the marker with the string id as we knew |
| 14344 | it. If found, update line number and address in the matching |
| 14345 | static tracepoint. This will get confused if there's more than one |
| 14346 | marker with the same ID (possible in UST, although unadvised |
| 14347 | precisely because it confuses tools). */ |
| 14348 | |
| 14349 | static struct symtab_and_line |
| 14350 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) |
| 14351 | { |
| 14352 | struct tracepoint *tp = (struct tracepoint *) b; |
| 14353 | struct static_tracepoint_marker marker; |
| 14354 | CORE_ADDR pc; |
| 14355 | |
| 14356 | pc = sal.pc; |
| 14357 | if (sal.line) |
| 14358 | find_line_pc (sal.symtab, sal.line, &pc); |
| 14359 | |
| 14360 | if (target_static_tracepoint_marker_at (pc, &marker)) |
| 14361 | { |
| 14362 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
| 14363 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
| 14364 | b->number, |
| 14365 | tp->static_trace_marker_id, marker.str_id); |
| 14366 | |
| 14367 | xfree (tp->static_trace_marker_id); |
| 14368 | tp->static_trace_marker_id = xstrdup (marker.str_id); |
| 14369 | release_static_tracepoint_marker (&marker); |
| 14370 | |
| 14371 | return sal; |
| 14372 | } |
| 14373 | |
| 14374 | /* Old marker wasn't found on target at lineno. Try looking it up |
| 14375 | by string ID. */ |
| 14376 | if (!sal.explicit_pc |
| 14377 | && sal.line != 0 |
| 14378 | && sal.symtab != NULL |
| 14379 | && tp->static_trace_marker_id != NULL) |
| 14380 | { |
| 14381 | VEC(static_tracepoint_marker_p) *markers; |
| 14382 | |
| 14383 | markers |
| 14384 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
| 14385 | |
| 14386 | if (!VEC_empty(static_tracepoint_marker_p, markers)) |
| 14387 | { |
| 14388 | struct symtab_and_line sal2; |
| 14389 | struct symbol *sym; |
| 14390 | struct static_tracepoint_marker *tpmarker; |
| 14391 | struct ui_out *uiout = current_uiout; |
| 14392 | |
| 14393 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
| 14394 | |
| 14395 | xfree (tp->static_trace_marker_id); |
| 14396 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
| 14397 | |
| 14398 | warning (_("marker for static tracepoint %d (%s) not " |
| 14399 | "found at previous line number"), |
| 14400 | b->number, tp->static_trace_marker_id); |
| 14401 | |
| 14402 | init_sal (&sal2); |
| 14403 | |
| 14404 | sal2.pc = tpmarker->address; |
| 14405 | |
| 14406 | sal2 = find_pc_line (tpmarker->address, 0); |
| 14407 | sym = find_pc_sect_function (tpmarker->address, NULL); |
| 14408 | ui_out_text (uiout, "Now in "); |
| 14409 | if (sym) |
| 14410 | { |
| 14411 | ui_out_field_string (uiout, "func", |
| 14412 | SYMBOL_PRINT_NAME (sym)); |
| 14413 | ui_out_text (uiout, " at "); |
| 14414 | } |
| 14415 | ui_out_field_string (uiout, "file", |
| 14416 | symtab_to_filename_for_display (sal2.symtab)); |
| 14417 | ui_out_text (uiout, ":"); |
| 14418 | |
| 14419 | if (ui_out_is_mi_like_p (uiout)) |
| 14420 | { |
| 14421 | const char *fullname = symtab_to_fullname (sal2.symtab); |
| 14422 | |
| 14423 | ui_out_field_string (uiout, "fullname", fullname); |
| 14424 | } |
| 14425 | |
| 14426 | ui_out_field_int (uiout, "line", sal2.line); |
| 14427 | ui_out_text (uiout, "\n"); |
| 14428 | |
| 14429 | b->loc->line_number = sal2.line; |
| 14430 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
| 14431 | |
| 14432 | xfree (b->addr_string); |
| 14433 | b->addr_string = xstrprintf ("%s:%d", |
| 14434 | symtab_to_filename_for_display (sal2.symtab), |
| 14435 | b->loc->line_number); |
| 14436 | |
| 14437 | /* Might be nice to check if function changed, and warn if |
| 14438 | so. */ |
| 14439 | |
| 14440 | release_static_tracepoint_marker (tpmarker); |
| 14441 | } |
| 14442 | } |
| 14443 | return sal; |
| 14444 | } |
| 14445 | |
| 14446 | /* Returns 1 iff locations A and B are sufficiently same that |
| 14447 | we don't need to report breakpoint as changed. */ |
| 14448 | |
| 14449 | static int |
| 14450 | locations_are_equal (struct bp_location *a, struct bp_location *b) |
| 14451 | { |
| 14452 | while (a && b) |
| 14453 | { |
| 14454 | if (a->address != b->address) |
| 14455 | return 0; |
| 14456 | |
| 14457 | if (a->shlib_disabled != b->shlib_disabled) |
| 14458 | return 0; |
| 14459 | |
| 14460 | if (a->enabled != b->enabled) |
| 14461 | return 0; |
| 14462 | |
| 14463 | a = a->next; |
| 14464 | b = b->next; |
| 14465 | } |
| 14466 | |
| 14467 | if ((a == NULL) != (b == NULL)) |
| 14468 | return 0; |
| 14469 | |
| 14470 | return 1; |
| 14471 | } |
| 14472 | |
| 14473 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
| 14474 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is |
| 14475 | a ranged breakpoint. */ |
| 14476 | |
| 14477 | void |
| 14478 | update_breakpoint_locations (struct breakpoint *b, |
| 14479 | struct symtabs_and_lines sals, |
| 14480 | struct symtabs_and_lines sals_end) |
| 14481 | { |
| 14482 | int i; |
| 14483 | struct bp_location *existing_locations = b->loc; |
| 14484 | |
| 14485 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
| 14486 | { |
| 14487 | /* Ranged breakpoints have only one start location and one end |
| 14488 | location. */ |
| 14489 | b->enable_state = bp_disabled; |
| 14490 | update_global_location_list (UGLL_MAY_INSERT); |
| 14491 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
| 14492 | "multiple locations found\n"), |
| 14493 | b->number); |
| 14494 | return; |
| 14495 | } |
| 14496 | |
| 14497 | /* If there's no new locations, and all existing locations are |
| 14498 | pending, don't do anything. This optimizes the common case where |
| 14499 | all locations are in the same shared library, that was unloaded. |
| 14500 | We'd like to retain the location, so that when the library is |
| 14501 | loaded again, we don't loose the enabled/disabled status of the |
| 14502 | individual locations. */ |
| 14503 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
| 14504 | return; |
| 14505 | |
| 14506 | b->loc = NULL; |
| 14507 | |
| 14508 | for (i = 0; i < sals.nelts; ++i) |
| 14509 | { |
| 14510 | struct bp_location *new_loc; |
| 14511 | |
| 14512 | switch_to_program_space_and_thread (sals.sals[i].pspace); |
| 14513 | |
| 14514 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); |
| 14515 | |
| 14516 | /* Reparse conditions, they might contain references to the |
| 14517 | old symtab. */ |
| 14518 | if (b->cond_string != NULL) |
| 14519 | { |
| 14520 | const char *s; |
| 14521 | volatile struct gdb_exception e; |
| 14522 | |
| 14523 | s = b->cond_string; |
| 14524 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 14525 | { |
| 14526 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
| 14527 | block_for_pc (sals.sals[i].pc), |
| 14528 | 0); |
| 14529 | } |
| 14530 | if (e.reason < 0) |
| 14531 | { |
| 14532 | warning (_("failed to reevaluate condition " |
| 14533 | "for breakpoint %d: %s"), |
| 14534 | b->number, e.message); |
| 14535 | new_loc->enabled = 0; |
| 14536 | } |
| 14537 | } |
| 14538 | |
| 14539 | if (sals_end.nelts) |
| 14540 | { |
| 14541 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); |
| 14542 | |
| 14543 | new_loc->length = end - sals.sals[0].pc + 1; |
| 14544 | } |
| 14545 | } |
| 14546 | |
| 14547 | /* Update locations of permanent breakpoints. */ |
| 14548 | if (b->enable_state == bp_permanent) |
| 14549 | make_breakpoint_permanent (b); |
| 14550 | |
| 14551 | /* If possible, carry over 'disable' status from existing |
| 14552 | breakpoints. */ |
| 14553 | { |
| 14554 | struct bp_location *e = existing_locations; |
| 14555 | /* If there are multiple breakpoints with the same function name, |
| 14556 | e.g. for inline functions, comparing function names won't work. |
| 14557 | Instead compare pc addresses; this is just a heuristic as things |
| 14558 | may have moved, but in practice it gives the correct answer |
| 14559 | often enough until a better solution is found. */ |
| 14560 | int have_ambiguous_names = ambiguous_names_p (b->loc); |
| 14561 | |
| 14562 | for (; e; e = e->next) |
| 14563 | { |
| 14564 | if (!e->enabled && e->function_name) |
| 14565 | { |
| 14566 | struct bp_location *l = b->loc; |
| 14567 | if (have_ambiguous_names) |
| 14568 | { |
| 14569 | for (; l; l = l->next) |
| 14570 | if (breakpoint_locations_match (e, l)) |
| 14571 | { |
| 14572 | l->enabled = 0; |
| 14573 | break; |
| 14574 | } |
| 14575 | } |
| 14576 | else |
| 14577 | { |
| 14578 | for (; l; l = l->next) |
| 14579 | if (l->function_name |
| 14580 | && strcmp (e->function_name, l->function_name) == 0) |
| 14581 | { |
| 14582 | l->enabled = 0; |
| 14583 | break; |
| 14584 | } |
| 14585 | } |
| 14586 | } |
| 14587 | } |
| 14588 | } |
| 14589 | |
| 14590 | if (!locations_are_equal (existing_locations, b->loc)) |
| 14591 | observer_notify_breakpoint_modified (b); |
| 14592 | |
| 14593 | update_global_location_list (UGLL_MAY_INSERT); |
| 14594 | } |
| 14595 | |
| 14596 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
| 14597 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
| 14598 | |
| 14599 | static struct symtabs_and_lines |
| 14600 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) |
| 14601 | { |
| 14602 | char *s; |
| 14603 | struct symtabs_and_lines sals = {0}; |
| 14604 | volatile struct gdb_exception e; |
| 14605 | |
| 14606 | gdb_assert (b->ops != NULL); |
| 14607 | s = addr_string; |
| 14608 | |
| 14609 | TRY_CATCH (e, RETURN_MASK_ERROR) |
| 14610 | { |
| 14611 | b->ops->decode_linespec (b, &s, &sals); |
| 14612 | } |
| 14613 | if (e.reason < 0) |
| 14614 | { |
| 14615 | int not_found_and_ok = 0; |
| 14616 | /* For pending breakpoints, it's expected that parsing will |
| 14617 | fail until the right shared library is loaded. User has |
| 14618 | already told to create pending breakpoints and don't need |
| 14619 | extra messages. If breakpoint is in bp_shlib_disabled |
| 14620 | state, then user already saw the message about that |
| 14621 | breakpoint being disabled, and don't want to see more |
| 14622 | errors. */ |
| 14623 | if (e.error == NOT_FOUND_ERROR |
| 14624 | && (b->condition_not_parsed |
| 14625 | || (b->loc && b->loc->shlib_disabled) |
| 14626 | || (b->loc && b->loc->pspace->executing_startup) |
| 14627 | || b->enable_state == bp_disabled)) |
| 14628 | not_found_and_ok = 1; |
| 14629 | |
| 14630 | if (!not_found_and_ok) |
| 14631 | { |
| 14632 | /* We surely don't want to warn about the same breakpoint |
| 14633 | 10 times. One solution, implemented here, is disable |
| 14634 | the breakpoint on error. Another solution would be to |
| 14635 | have separate 'warning emitted' flag. Since this |
| 14636 | happens only when a binary has changed, I don't know |
| 14637 | which approach is better. */ |
| 14638 | b->enable_state = bp_disabled; |
| 14639 | throw_exception (e); |
| 14640 | } |
| 14641 | } |
| 14642 | |
| 14643 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
| 14644 | { |
| 14645 | int i; |
| 14646 | |
| 14647 | for (i = 0; i < sals.nelts; ++i) |
| 14648 | resolve_sal_pc (&sals.sals[i]); |
| 14649 | if (b->condition_not_parsed && s && s[0]) |
| 14650 | { |
| 14651 | char *cond_string, *extra_string; |
| 14652 | int thread, task; |
| 14653 | |
| 14654 | find_condition_and_thread (s, sals.sals[0].pc, |
| 14655 | &cond_string, &thread, &task, |
| 14656 | &extra_string); |
| 14657 | if (cond_string) |
| 14658 | b->cond_string = cond_string; |
| 14659 | b->thread = thread; |
| 14660 | b->task = task; |
| 14661 | if (extra_string) |
| 14662 | b->extra_string = extra_string; |
| 14663 | b->condition_not_parsed = 0; |
| 14664 | } |
| 14665 | |
| 14666 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
| 14667 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
| 14668 | |
| 14669 | *found = 1; |
| 14670 | } |
| 14671 | else |
| 14672 | *found = 0; |
| 14673 | |
| 14674 | return sals; |
| 14675 | } |
| 14676 | |
| 14677 | /* The default re_set method, for typical hardware or software |
| 14678 | breakpoints. Reevaluate the breakpoint and recreate its |
| 14679 | locations. */ |
| 14680 | |
| 14681 | static void |
| 14682 | breakpoint_re_set_default (struct breakpoint *b) |
| 14683 | { |
| 14684 | int found; |
| 14685 | struct symtabs_and_lines sals, sals_end; |
| 14686 | struct symtabs_and_lines expanded = {0}; |
| 14687 | struct symtabs_and_lines expanded_end = {0}; |
| 14688 | |
| 14689 | sals = addr_string_to_sals (b, b->addr_string, &found); |
| 14690 | if (found) |
| 14691 | { |
| 14692 | make_cleanup (xfree, sals.sals); |
| 14693 | expanded = sals; |
| 14694 | } |
| 14695 | |
| 14696 | if (b->addr_string_range_end) |
| 14697 | { |
| 14698 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); |
| 14699 | if (found) |
| 14700 | { |
| 14701 | make_cleanup (xfree, sals_end.sals); |
| 14702 | expanded_end = sals_end; |
| 14703 | } |
| 14704 | } |
| 14705 | |
| 14706 | update_breakpoint_locations (b, expanded, expanded_end); |
| 14707 | } |
| 14708 | |
| 14709 | /* Default method for creating SALs from an address string. It basically |
| 14710 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ |
| 14711 | |
| 14712 | static void |
| 14713 | create_sals_from_address_default (char **arg, |
| 14714 | struct linespec_result *canonical, |
| 14715 | enum bptype type_wanted, |
| 14716 | char *addr_start, char **copy_arg) |
| 14717 | { |
| 14718 | parse_breakpoint_sals (arg, canonical); |
| 14719 | } |
| 14720 | |
| 14721 | /* Call create_breakpoints_sal for the given arguments. This is the default |
| 14722 | function for the `create_breakpoints_sal' method of |
| 14723 | breakpoint_ops. */ |
| 14724 | |
| 14725 | static void |
| 14726 | create_breakpoints_sal_default (struct gdbarch *gdbarch, |
| 14727 | struct linespec_result *canonical, |
| 14728 | char *cond_string, |
| 14729 | char *extra_string, |
| 14730 | enum bptype type_wanted, |
| 14731 | enum bpdisp disposition, |
| 14732 | int thread, |
| 14733 | int task, int ignore_count, |
| 14734 | const struct breakpoint_ops *ops, |
| 14735 | int from_tty, int enabled, |
| 14736 | int internal, unsigned flags) |
| 14737 | { |
| 14738 | create_breakpoints_sal (gdbarch, canonical, cond_string, |
| 14739 | extra_string, |
| 14740 | type_wanted, disposition, |
| 14741 | thread, task, ignore_count, ops, from_tty, |
| 14742 | enabled, internal, flags); |
| 14743 | } |
| 14744 | |
| 14745 | /* Decode the line represented by S by calling decode_line_full. This is the |
| 14746 | default function for the `decode_linespec' method of breakpoint_ops. */ |
| 14747 | |
| 14748 | static void |
| 14749 | decode_linespec_default (struct breakpoint *b, char **s, |
| 14750 | struct symtabs_and_lines *sals) |
| 14751 | { |
| 14752 | struct linespec_result canonical; |
| 14753 | |
| 14754 | init_linespec_result (&canonical); |
| 14755 | decode_line_full (s, DECODE_LINE_FUNFIRSTLINE, |
| 14756 | (struct symtab *) NULL, 0, |
| 14757 | &canonical, multiple_symbols_all, |
| 14758 | b->filter); |
| 14759 | |
| 14760 | /* We should get 0 or 1 resulting SALs. */ |
| 14761 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); |
| 14762 | |
| 14763 | if (VEC_length (linespec_sals, canonical.sals) > 0) |
| 14764 | { |
| 14765 | struct linespec_sals *lsal; |
| 14766 | |
| 14767 | lsal = VEC_index (linespec_sals, canonical.sals, 0); |
| 14768 | *sals = lsal->sals; |
| 14769 | /* Arrange it so the destructor does not free the |
| 14770 | contents. */ |
| 14771 | lsal->sals.sals = NULL; |
| 14772 | } |
| 14773 | |
| 14774 | destroy_linespec_result (&canonical); |
| 14775 | } |
| 14776 | |
| 14777 | /* Prepare the global context for a re-set of breakpoint B. */ |
| 14778 | |
| 14779 | static struct cleanup * |
| 14780 | prepare_re_set_context (struct breakpoint *b) |
| 14781 | { |
| 14782 | struct cleanup *cleanups; |
| 14783 | |
| 14784 | input_radix = b->input_radix; |
| 14785 | cleanups = save_current_space_and_thread (); |
| 14786 | if (b->pspace != NULL) |
| 14787 | switch_to_program_space_and_thread (b->pspace); |
| 14788 | set_language (b->language); |
| 14789 | |
| 14790 | return cleanups; |
| 14791 | } |
| 14792 | |
| 14793 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
| 14794 | The value we return ends up being the return value from catch_errors. |
| 14795 | Unused in this case. */ |
| 14796 | |
| 14797 | static int |
| 14798 | breakpoint_re_set_one (void *bint) |
| 14799 | { |
| 14800 | /* Get past catch_errs. */ |
| 14801 | struct breakpoint *b = (struct breakpoint *) bint; |
| 14802 | struct cleanup *cleanups; |
| 14803 | |
| 14804 | cleanups = prepare_re_set_context (b); |
| 14805 | b->ops->re_set (b); |
| 14806 | do_cleanups (cleanups); |
| 14807 | return 0; |
| 14808 | } |
| 14809 | |
| 14810 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
| 14811 | void |
| 14812 | breakpoint_re_set (void) |
| 14813 | { |
| 14814 | struct breakpoint *b, *b_tmp; |
| 14815 | enum language save_language; |
| 14816 | int save_input_radix; |
| 14817 | struct cleanup *old_chain; |
| 14818 | |
| 14819 | save_language = current_language->la_language; |
| 14820 | save_input_radix = input_radix; |
| 14821 | old_chain = save_current_program_space (); |
| 14822 | |
| 14823 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 14824 | { |
| 14825 | /* Format possible error msg. */ |
| 14826 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
| 14827 | b->number); |
| 14828 | struct cleanup *cleanups = make_cleanup (xfree, message); |
| 14829 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
| 14830 | do_cleanups (cleanups); |
| 14831 | } |
| 14832 | set_language (save_language); |
| 14833 | input_radix = save_input_radix; |
| 14834 | |
| 14835 | jit_breakpoint_re_set (); |
| 14836 | |
| 14837 | do_cleanups (old_chain); |
| 14838 | |
| 14839 | create_overlay_event_breakpoint (); |
| 14840 | create_longjmp_master_breakpoint (); |
| 14841 | create_std_terminate_master_breakpoint (); |
| 14842 | create_exception_master_breakpoint (); |
| 14843 | } |
| 14844 | \f |
| 14845 | /* Reset the thread number of this breakpoint: |
| 14846 | |
| 14847 | - If the breakpoint is for all threads, leave it as-is. |
| 14848 | - Else, reset it to the current thread for inferior_ptid. */ |
| 14849 | void |
| 14850 | breakpoint_re_set_thread (struct breakpoint *b) |
| 14851 | { |
| 14852 | if (b->thread != -1) |
| 14853 | { |
| 14854 | if (in_thread_list (inferior_ptid)) |
| 14855 | b->thread = pid_to_thread_id (inferior_ptid); |
| 14856 | |
| 14857 | /* We're being called after following a fork. The new fork is |
| 14858 | selected as current, and unless this was a vfork will have a |
| 14859 | different program space from the original thread. Reset that |
| 14860 | as well. */ |
| 14861 | b->loc->pspace = current_program_space; |
| 14862 | } |
| 14863 | } |
| 14864 | |
| 14865 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 14866 | If from_tty is nonzero, it prints a message to that effect, |
| 14867 | which ends with a period (no newline). */ |
| 14868 | |
| 14869 | void |
| 14870 | set_ignore_count (int bptnum, int count, int from_tty) |
| 14871 | { |
| 14872 | struct breakpoint *b; |
| 14873 | |
| 14874 | if (count < 0) |
| 14875 | count = 0; |
| 14876 | |
| 14877 | ALL_BREAKPOINTS (b) |
| 14878 | if (b->number == bptnum) |
| 14879 | { |
| 14880 | if (is_tracepoint (b)) |
| 14881 | { |
| 14882 | if (from_tty && count != 0) |
| 14883 | printf_filtered (_("Ignore count ignored for tracepoint %d."), |
| 14884 | bptnum); |
| 14885 | return; |
| 14886 | } |
| 14887 | |
| 14888 | b->ignore_count = count; |
| 14889 | if (from_tty) |
| 14890 | { |
| 14891 | if (count == 0) |
| 14892 | printf_filtered (_("Will stop next time " |
| 14893 | "breakpoint %d is reached."), |
| 14894 | bptnum); |
| 14895 | else if (count == 1) |
| 14896 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
| 14897 | bptnum); |
| 14898 | else |
| 14899 | printf_filtered (_("Will ignore next %d " |
| 14900 | "crossings of breakpoint %d."), |
| 14901 | count, bptnum); |
| 14902 | } |
| 14903 | observer_notify_breakpoint_modified (b); |
| 14904 | return; |
| 14905 | } |
| 14906 | |
| 14907 | error (_("No breakpoint number %d."), bptnum); |
| 14908 | } |
| 14909 | |
| 14910 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
| 14911 | |
| 14912 | static void |
| 14913 | ignore_command (char *args, int from_tty) |
| 14914 | { |
| 14915 | char *p = args; |
| 14916 | int num; |
| 14917 | |
| 14918 | if (p == 0) |
| 14919 | error_no_arg (_("a breakpoint number")); |
| 14920 | |
| 14921 | num = get_number (&p); |
| 14922 | if (num == 0) |
| 14923 | error (_("bad breakpoint number: '%s'"), args); |
| 14924 | if (*p == 0) |
| 14925 | error (_("Second argument (specified ignore-count) is missing.")); |
| 14926 | |
| 14927 | set_ignore_count (num, |
| 14928 | longest_to_int (value_as_long (parse_and_eval (p))), |
| 14929 | from_tty); |
| 14930 | if (from_tty) |
| 14931 | printf_filtered ("\n"); |
| 14932 | } |
| 14933 | \f |
| 14934 | /* Call FUNCTION on each of the breakpoints |
| 14935 | whose numbers are given in ARGS. */ |
| 14936 | |
| 14937 | static void |
| 14938 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
| 14939 | void *), |
| 14940 | void *data) |
| 14941 | { |
| 14942 | int num; |
| 14943 | struct breakpoint *b, *tmp; |
| 14944 | int match; |
| 14945 | struct get_number_or_range_state state; |
| 14946 | |
| 14947 | if (args == 0) |
| 14948 | error_no_arg (_("one or more breakpoint numbers")); |
| 14949 | |
| 14950 | init_number_or_range (&state, args); |
| 14951 | |
| 14952 | while (!state.finished) |
| 14953 | { |
| 14954 | const char *p = state.string; |
| 14955 | |
| 14956 | match = 0; |
| 14957 | |
| 14958 | num = get_number_or_range (&state); |
| 14959 | if (num == 0) |
| 14960 | { |
| 14961 | warning (_("bad breakpoint number at or near '%s'"), p); |
| 14962 | } |
| 14963 | else |
| 14964 | { |
| 14965 | ALL_BREAKPOINTS_SAFE (b, tmp) |
| 14966 | if (b->number == num) |
| 14967 | { |
| 14968 | match = 1; |
| 14969 | function (b, data); |
| 14970 | break; |
| 14971 | } |
| 14972 | if (match == 0) |
| 14973 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
| 14974 | } |
| 14975 | } |
| 14976 | } |
| 14977 | |
| 14978 | static struct bp_location * |
| 14979 | find_location_by_number (char *number) |
| 14980 | { |
| 14981 | char *dot = strchr (number, '.'); |
| 14982 | char *p1; |
| 14983 | int bp_num; |
| 14984 | int loc_num; |
| 14985 | struct breakpoint *b; |
| 14986 | struct bp_location *loc; |
| 14987 | |
| 14988 | *dot = '\0'; |
| 14989 | |
| 14990 | p1 = number; |
| 14991 | bp_num = get_number (&p1); |
| 14992 | if (bp_num == 0) |
| 14993 | error (_("Bad breakpoint number '%s'"), number); |
| 14994 | |
| 14995 | ALL_BREAKPOINTS (b) |
| 14996 | if (b->number == bp_num) |
| 14997 | { |
| 14998 | break; |
| 14999 | } |
| 15000 | |
| 15001 | if (!b || b->number != bp_num) |
| 15002 | error (_("Bad breakpoint number '%s'"), number); |
| 15003 | |
| 15004 | p1 = dot+1; |
| 15005 | loc_num = get_number (&p1); |
| 15006 | if (loc_num == 0) |
| 15007 | error (_("Bad breakpoint location number '%s'"), number); |
| 15008 | |
| 15009 | --loc_num; |
| 15010 | loc = b->loc; |
| 15011 | for (;loc_num && loc; --loc_num, loc = loc->next) |
| 15012 | ; |
| 15013 | if (!loc) |
| 15014 | error (_("Bad breakpoint location number '%s'"), dot+1); |
| 15015 | |
| 15016 | return loc; |
| 15017 | } |
| 15018 | |
| 15019 | |
| 15020 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 15021 | If from_tty is nonzero, it prints a message to that effect, |
| 15022 | which ends with a period (no newline). */ |
| 15023 | |
| 15024 | void |
| 15025 | disable_breakpoint (struct breakpoint *bpt) |
| 15026 | { |
| 15027 | /* Never disable a watchpoint scope breakpoint; we want to |
| 15028 | hit them when we leave scope so we can delete both the |
| 15029 | watchpoint and its scope breakpoint at that time. */ |
| 15030 | if (bpt->type == bp_watchpoint_scope) |
| 15031 | return; |
| 15032 | |
| 15033 | /* You can't disable permanent breakpoints. */ |
| 15034 | if (bpt->enable_state == bp_permanent) |
| 15035 | return; |
| 15036 | |
| 15037 | bpt->enable_state = bp_disabled; |
| 15038 | |
| 15039 | /* Mark breakpoint locations modified. */ |
| 15040 | mark_breakpoint_modified (bpt); |
| 15041 | |
| 15042 | if (target_supports_enable_disable_tracepoint () |
| 15043 | && current_trace_status ()->running && is_tracepoint (bpt)) |
| 15044 | { |
| 15045 | struct bp_location *location; |
| 15046 | |
| 15047 | for (location = bpt->loc; location; location = location->next) |
| 15048 | target_disable_tracepoint (location); |
| 15049 | } |
| 15050 | |
| 15051 | update_global_location_list (UGLL_DONT_INSERT); |
| 15052 | |
| 15053 | observer_notify_breakpoint_modified (bpt); |
| 15054 | } |
| 15055 | |
| 15056 | /* A callback for iterate_over_related_breakpoints. */ |
| 15057 | |
| 15058 | static void |
| 15059 | do_disable_breakpoint (struct breakpoint *b, void *ignore) |
| 15060 | { |
| 15061 | disable_breakpoint (b); |
| 15062 | } |
| 15063 | |
| 15064 | /* A callback for map_breakpoint_numbers that calls |
| 15065 | disable_breakpoint. */ |
| 15066 | |
| 15067 | static void |
| 15068 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) |
| 15069 | { |
| 15070 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
| 15071 | } |
| 15072 | |
| 15073 | static void |
| 15074 | disable_command (char *args, int from_tty) |
| 15075 | { |
| 15076 | if (args == 0) |
| 15077 | { |
| 15078 | struct breakpoint *bpt; |
| 15079 | |
| 15080 | ALL_BREAKPOINTS (bpt) |
| 15081 | if (user_breakpoint_p (bpt)) |
| 15082 | disable_breakpoint (bpt); |
| 15083 | } |
| 15084 | else |
| 15085 | { |
| 15086 | char *num = extract_arg (&args); |
| 15087 | |
| 15088 | while (num) |
| 15089 | { |
| 15090 | if (strchr (num, '.')) |
| 15091 | { |
| 15092 | struct bp_location *loc = find_location_by_number (num); |
| 15093 | |
| 15094 | if (loc) |
| 15095 | { |
| 15096 | if (loc->enabled) |
| 15097 | { |
| 15098 | loc->enabled = 0; |
| 15099 | mark_breakpoint_location_modified (loc); |
| 15100 | } |
| 15101 | if (target_supports_enable_disable_tracepoint () |
| 15102 | && current_trace_status ()->running && loc->owner |
| 15103 | && is_tracepoint (loc->owner)) |
| 15104 | target_disable_tracepoint (loc); |
| 15105 | } |
| 15106 | update_global_location_list (UGLL_DONT_INSERT); |
| 15107 | } |
| 15108 | else |
| 15109 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); |
| 15110 | num = extract_arg (&args); |
| 15111 | } |
| 15112 | } |
| 15113 | } |
| 15114 | |
| 15115 | static void |
| 15116 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
| 15117 | int count) |
| 15118 | { |
| 15119 | int target_resources_ok; |
| 15120 | |
| 15121 | if (bpt->type == bp_hardware_breakpoint) |
| 15122 | { |
| 15123 | int i; |
| 15124 | i = hw_breakpoint_used_count (); |
| 15125 | target_resources_ok = |
| 15126 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 15127 | i + 1, 0); |
| 15128 | if (target_resources_ok == 0) |
| 15129 | error (_("No hardware breakpoint support in the target.")); |
| 15130 | else if (target_resources_ok < 0) |
| 15131 | error (_("Hardware breakpoints used exceeds limit.")); |
| 15132 | } |
| 15133 | |
| 15134 | if (is_watchpoint (bpt)) |
| 15135 | { |
| 15136 | /* Initialize it just to avoid a GCC false warning. */ |
| 15137 | enum enable_state orig_enable_state = 0; |
| 15138 | volatile struct gdb_exception e; |
| 15139 | |
| 15140 | TRY_CATCH (e, RETURN_MASK_ALL) |
| 15141 | { |
| 15142 | struct watchpoint *w = (struct watchpoint *) bpt; |
| 15143 | |
| 15144 | orig_enable_state = bpt->enable_state; |
| 15145 | bpt->enable_state = bp_enabled; |
| 15146 | update_watchpoint (w, 1 /* reparse */); |
| 15147 | } |
| 15148 | if (e.reason < 0) |
| 15149 | { |
| 15150 | bpt->enable_state = orig_enable_state; |
| 15151 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
| 15152 | bpt->number); |
| 15153 | return; |
| 15154 | } |
| 15155 | } |
| 15156 | |
| 15157 | if (bpt->enable_state != bp_permanent) |
| 15158 | bpt->enable_state = bp_enabled; |
| 15159 | |
| 15160 | bpt->enable_state = bp_enabled; |
| 15161 | |
| 15162 | /* Mark breakpoint locations modified. */ |
| 15163 | mark_breakpoint_modified (bpt); |
| 15164 | |
| 15165 | if (target_supports_enable_disable_tracepoint () |
| 15166 | && current_trace_status ()->running && is_tracepoint (bpt)) |
| 15167 | { |
| 15168 | struct bp_location *location; |
| 15169 | |
| 15170 | for (location = bpt->loc; location; location = location->next) |
| 15171 | target_enable_tracepoint (location); |
| 15172 | } |
| 15173 | |
| 15174 | bpt->disposition = disposition; |
| 15175 | bpt->enable_count = count; |
| 15176 | update_global_location_list (UGLL_MAY_INSERT); |
| 15177 | |
| 15178 | observer_notify_breakpoint_modified (bpt); |
| 15179 | } |
| 15180 | |
| 15181 | |
| 15182 | void |
| 15183 | enable_breakpoint (struct breakpoint *bpt) |
| 15184 | { |
| 15185 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
| 15186 | } |
| 15187 | |
| 15188 | static void |
| 15189 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) |
| 15190 | { |
| 15191 | enable_breakpoint (bpt); |
| 15192 | } |
| 15193 | |
| 15194 | /* A callback for map_breakpoint_numbers that calls |
| 15195 | enable_breakpoint. */ |
| 15196 | |
| 15197 | static void |
| 15198 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) |
| 15199 | { |
| 15200 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
| 15201 | } |
| 15202 | |
| 15203 | /* The enable command enables the specified breakpoints (or all defined |
| 15204 | breakpoints) so they once again become (or continue to be) effective |
| 15205 | in stopping the inferior. */ |
| 15206 | |
| 15207 | static void |
| 15208 | enable_command (char *args, int from_tty) |
| 15209 | { |
| 15210 | if (args == 0) |
| 15211 | { |
| 15212 | struct breakpoint *bpt; |
| 15213 | |
| 15214 | ALL_BREAKPOINTS (bpt) |
| 15215 | if (user_breakpoint_p (bpt)) |
| 15216 | enable_breakpoint (bpt); |
| 15217 | } |
| 15218 | else |
| 15219 | { |
| 15220 | char *num = extract_arg (&args); |
| 15221 | |
| 15222 | while (num) |
| 15223 | { |
| 15224 | if (strchr (num, '.')) |
| 15225 | { |
| 15226 | struct bp_location *loc = find_location_by_number (num); |
| 15227 | |
| 15228 | if (loc) |
| 15229 | { |
| 15230 | if (!loc->enabled) |
| 15231 | { |
| 15232 | loc->enabled = 1; |
| 15233 | mark_breakpoint_location_modified (loc); |
| 15234 | } |
| 15235 | if (target_supports_enable_disable_tracepoint () |
| 15236 | && current_trace_status ()->running && loc->owner |
| 15237 | && is_tracepoint (loc->owner)) |
| 15238 | target_enable_tracepoint (loc); |
| 15239 | } |
| 15240 | update_global_location_list (UGLL_MAY_INSERT); |
| 15241 | } |
| 15242 | else |
| 15243 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); |
| 15244 | num = extract_arg (&args); |
| 15245 | } |
| 15246 | } |
| 15247 | } |
| 15248 | |
| 15249 | /* This struct packages up disposition data for application to multiple |
| 15250 | breakpoints. */ |
| 15251 | |
| 15252 | struct disp_data |
| 15253 | { |
| 15254 | enum bpdisp disp; |
| 15255 | int count; |
| 15256 | }; |
| 15257 | |
| 15258 | static void |
| 15259 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
| 15260 | { |
| 15261 | struct disp_data disp_data = *(struct disp_data *) arg; |
| 15262 | |
| 15263 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
| 15264 | } |
| 15265 | |
| 15266 | static void |
| 15267 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
| 15268 | { |
| 15269 | struct disp_data disp = { disp_disable, 1 }; |
| 15270 | |
| 15271 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); |
| 15272 | } |
| 15273 | |
| 15274 | static void |
| 15275 | enable_once_command (char *args, int from_tty) |
| 15276 | { |
| 15277 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
| 15278 | } |
| 15279 | |
| 15280 | static void |
| 15281 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) |
| 15282 | { |
| 15283 | struct disp_data disp = { disp_disable, *(int *) countptr }; |
| 15284 | |
| 15285 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); |
| 15286 | } |
| 15287 | |
| 15288 | static void |
| 15289 | enable_count_command (char *args, int from_tty) |
| 15290 | { |
| 15291 | int count = get_number (&args); |
| 15292 | |
| 15293 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); |
| 15294 | } |
| 15295 | |
| 15296 | static void |
| 15297 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
| 15298 | { |
| 15299 | struct disp_data disp = { disp_del, 1 }; |
| 15300 | |
| 15301 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); |
| 15302 | } |
| 15303 | |
| 15304 | static void |
| 15305 | enable_delete_command (char *args, int from_tty) |
| 15306 | { |
| 15307 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
| 15308 | } |
| 15309 | \f |
| 15310 | static void |
| 15311 | set_breakpoint_cmd (char *args, int from_tty) |
| 15312 | { |
| 15313 | } |
| 15314 | |
| 15315 | static void |
| 15316 | show_breakpoint_cmd (char *args, int from_tty) |
| 15317 | { |
| 15318 | } |
| 15319 | |
| 15320 | /* Invalidate last known value of any hardware watchpoint if |
| 15321 | the memory which that value represents has been written to by |
| 15322 | GDB itself. */ |
| 15323 | |
| 15324 | static void |
| 15325 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
| 15326 | CORE_ADDR addr, ssize_t len, |
| 15327 | const bfd_byte *data) |
| 15328 | { |
| 15329 | struct breakpoint *bp; |
| 15330 | |
| 15331 | ALL_BREAKPOINTS (bp) |
| 15332 | if (bp->enable_state == bp_enabled |
| 15333 | && bp->type == bp_hardware_watchpoint) |
| 15334 | { |
| 15335 | struct watchpoint *wp = (struct watchpoint *) bp; |
| 15336 | |
| 15337 | if (wp->val_valid && wp->val) |
| 15338 | { |
| 15339 | struct bp_location *loc; |
| 15340 | |
| 15341 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
| 15342 | if (loc->loc_type == bp_loc_hardware_watchpoint |
| 15343 | && loc->address + loc->length > addr |
| 15344 | && addr + len > loc->address) |
| 15345 | { |
| 15346 | value_free (wp->val); |
| 15347 | wp->val = NULL; |
| 15348 | wp->val_valid = 0; |
| 15349 | } |
| 15350 | } |
| 15351 | } |
| 15352 | } |
| 15353 | |
| 15354 | /* Create and insert a raw software breakpoint at PC. Return an |
| 15355 | identifier, which should be used to remove the breakpoint later. |
| 15356 | In general, places which call this should be using something on the |
| 15357 | breakpoint chain instead; this function should be eliminated |
| 15358 | someday. */ |
| 15359 | |
| 15360 | void * |
| 15361 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
| 15362 | struct address_space *aspace, CORE_ADDR pc) |
| 15363 | { |
| 15364 | struct bp_target_info *bp_tgt; |
| 15365 | struct bp_location *bl; |
| 15366 | |
| 15367 | bp_tgt = XCNEW (struct bp_target_info); |
| 15368 | |
| 15369 | bp_tgt->placed_address_space = aspace; |
| 15370 | bp_tgt->placed_address = pc; |
| 15371 | |
| 15372 | /* If an unconditional non-raw breakpoint is already inserted at |
| 15373 | that location, there's no need to insert another. However, with |
| 15374 | target-side evaluation of breakpoint conditions, if the |
| 15375 | breakpoint that is currently inserted on the target is |
| 15376 | conditional, we need to make it unconditional. Note that a |
| 15377 | breakpoint with target-side commands is not reported even if |
| 15378 | unconditional, so we need to remove the commands from the target |
| 15379 | as well. */ |
| 15380 | bl = find_non_raw_software_breakpoint_inserted_here (aspace, pc); |
| 15381 | if (bl != NULL |
| 15382 | && VEC_empty (agent_expr_p, bl->target_info.conditions) |
| 15383 | && VEC_empty (agent_expr_p, bl->target_info.tcommands)) |
| 15384 | { |
| 15385 | bp_target_info_copy_insertion_state (bp_tgt, &bl->target_info); |
| 15386 | return bp_tgt; |
| 15387 | } |
| 15388 | |
| 15389 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
| 15390 | { |
| 15391 | /* Could not insert the breakpoint. */ |
| 15392 | xfree (bp_tgt); |
| 15393 | return NULL; |
| 15394 | } |
| 15395 | |
| 15396 | return bp_tgt; |
| 15397 | } |
| 15398 | |
| 15399 | /* Remove a breakpoint BP inserted by |
| 15400 | deprecated_insert_raw_breakpoint. */ |
| 15401 | |
| 15402 | int |
| 15403 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
| 15404 | { |
| 15405 | struct bp_target_info *bp_tgt = bp; |
| 15406 | struct address_space *aspace = bp_tgt->placed_address_space; |
| 15407 | CORE_ADDR address = bp_tgt->placed_address; |
| 15408 | struct bp_location *bl; |
| 15409 | int ret; |
| 15410 | |
| 15411 | bl = find_non_raw_software_breakpoint_inserted_here (aspace, address); |
| 15412 | |
| 15413 | /* Only remove the raw breakpoint if there are no other non-raw |
| 15414 | breakpoints still inserted at this location. Otherwise, we would |
| 15415 | be effectively disabling those breakpoints. */ |
| 15416 | if (bl == NULL) |
| 15417 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
| 15418 | else if (!VEC_empty (agent_expr_p, bl->target_info.conditions) |
| 15419 | || !VEC_empty (agent_expr_p, bl->target_info.tcommands)) |
| 15420 | { |
| 15421 | /* The target is evaluating conditions, and when we inserted the |
| 15422 | software single-step breakpoint, we had made the breakpoint |
| 15423 | unconditional and command-less on the target side. Reinsert |
| 15424 | to restore the conditions/commands. */ |
| 15425 | ret = target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
| 15426 | } |
| 15427 | else |
| 15428 | ret = 0; |
| 15429 | |
| 15430 | xfree (bp_tgt); |
| 15431 | |
| 15432 | return ret; |
| 15433 | } |
| 15434 | |
| 15435 | /* Create and insert a breakpoint for software single step. */ |
| 15436 | |
| 15437 | void |
| 15438 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
| 15439 | struct address_space *aspace, |
| 15440 | CORE_ADDR next_pc) |
| 15441 | { |
| 15442 | void **bpt_p; |
| 15443 | |
| 15444 | if (single_step_breakpoints[0] == NULL) |
| 15445 | { |
| 15446 | bpt_p = &single_step_breakpoints[0]; |
| 15447 | single_step_gdbarch[0] = gdbarch; |
| 15448 | } |
| 15449 | else |
| 15450 | { |
| 15451 | gdb_assert (single_step_breakpoints[1] == NULL); |
| 15452 | bpt_p = &single_step_breakpoints[1]; |
| 15453 | single_step_gdbarch[1] = gdbarch; |
| 15454 | } |
| 15455 | |
| 15456 | /* NOTE drow/2006-04-11: A future improvement to this function would |
| 15457 | be to only create the breakpoints once, and actually put them on |
| 15458 | the breakpoint chain. That would let us use set_raw_breakpoint. |
| 15459 | We could adjust the addresses each time they were needed. Doing |
| 15460 | this requires corresponding changes elsewhere where single step |
| 15461 | breakpoints are handled, however. So, for now, we use this. */ |
| 15462 | |
| 15463 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
| 15464 | if (*bpt_p == NULL) |
| 15465 | error (_("Could not insert single-step breakpoint at %s"), |
| 15466 | paddress (gdbarch, next_pc)); |
| 15467 | } |
| 15468 | |
| 15469 | /* Check if the breakpoints used for software single stepping |
| 15470 | were inserted or not. */ |
| 15471 | |
| 15472 | int |
| 15473 | single_step_breakpoints_inserted (void) |
| 15474 | { |
| 15475 | return (single_step_breakpoints[0] != NULL |
| 15476 | || single_step_breakpoints[1] != NULL); |
| 15477 | } |
| 15478 | |
| 15479 | /* Remove and delete any breakpoints used for software single step. */ |
| 15480 | |
| 15481 | void |
| 15482 | remove_single_step_breakpoints (void) |
| 15483 | { |
| 15484 | gdb_assert (single_step_breakpoints[0] != NULL); |
| 15485 | |
| 15486 | /* See insert_single_step_breakpoint for more about this deprecated |
| 15487 | call. */ |
| 15488 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
| 15489 | single_step_breakpoints[0]); |
| 15490 | single_step_gdbarch[0] = NULL; |
| 15491 | single_step_breakpoints[0] = NULL; |
| 15492 | |
| 15493 | if (single_step_breakpoints[1] != NULL) |
| 15494 | { |
| 15495 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
| 15496 | single_step_breakpoints[1]); |
| 15497 | single_step_gdbarch[1] = NULL; |
| 15498 | single_step_breakpoints[1] = NULL; |
| 15499 | } |
| 15500 | } |
| 15501 | |
| 15502 | /* Delete software single step breakpoints without removing them from |
| 15503 | the inferior. This is intended to be used if the inferior's address |
| 15504 | space where they were inserted is already gone, e.g. after exit or |
| 15505 | exec. */ |
| 15506 | |
| 15507 | void |
| 15508 | cancel_single_step_breakpoints (void) |
| 15509 | { |
| 15510 | int i; |
| 15511 | |
| 15512 | for (i = 0; i < 2; i++) |
| 15513 | if (single_step_breakpoints[i]) |
| 15514 | { |
| 15515 | xfree (single_step_breakpoints[i]); |
| 15516 | single_step_breakpoints[i] = NULL; |
| 15517 | single_step_gdbarch[i] = NULL; |
| 15518 | } |
| 15519 | } |
| 15520 | |
| 15521 | /* Detach software single-step breakpoints from INFERIOR_PTID without |
| 15522 | removing them. */ |
| 15523 | |
| 15524 | static void |
| 15525 | detach_single_step_breakpoints (void) |
| 15526 | { |
| 15527 | int i; |
| 15528 | |
| 15529 | for (i = 0; i < 2; i++) |
| 15530 | if (single_step_breakpoints[i]) |
| 15531 | target_remove_breakpoint (single_step_gdbarch[i], |
| 15532 | single_step_breakpoints[i]); |
| 15533 | } |
| 15534 | |
| 15535 | /* Find the software single-step breakpoint that inserted at PC. |
| 15536 | Returns its slot if found, and -1 if not found. */ |
| 15537 | |
| 15538 | static int |
| 15539 | find_single_step_breakpoint (struct address_space *aspace, |
| 15540 | CORE_ADDR pc) |
| 15541 | { |
| 15542 | int i; |
| 15543 | |
| 15544 | for (i = 0; i < 2; i++) |
| 15545 | { |
| 15546 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; |
| 15547 | if (bp_tgt |
| 15548 | && breakpoint_address_match (bp_tgt->placed_address_space, |
| 15549 | bp_tgt->placed_address, |
| 15550 | aspace, pc)) |
| 15551 | return i; |
| 15552 | } |
| 15553 | |
| 15554 | return -1; |
| 15555 | } |
| 15556 | |
| 15557 | /* Check whether a software single-step breakpoint is inserted at |
| 15558 | PC. */ |
| 15559 | |
| 15560 | int |
| 15561 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
| 15562 | CORE_ADDR pc) |
| 15563 | { |
| 15564 | return find_single_step_breakpoint (aspace, pc) >= 0; |
| 15565 | } |
| 15566 | |
| 15567 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
| 15568 | non-zero otherwise. */ |
| 15569 | static int |
| 15570 | is_syscall_catchpoint_enabled (struct breakpoint *bp) |
| 15571 | { |
| 15572 | if (syscall_catchpoint_p (bp) |
| 15573 | && bp->enable_state != bp_disabled |
| 15574 | && bp->enable_state != bp_call_disabled) |
| 15575 | return 1; |
| 15576 | else |
| 15577 | return 0; |
| 15578 | } |
| 15579 | |
| 15580 | int |
| 15581 | catch_syscall_enabled (void) |
| 15582 | { |
| 15583 | struct catch_syscall_inferior_data *inf_data |
| 15584 | = get_catch_syscall_inferior_data (current_inferior ()); |
| 15585 | |
| 15586 | return inf_data->total_syscalls_count != 0; |
| 15587 | } |
| 15588 | |
| 15589 | int |
| 15590 | catching_syscall_number (int syscall_number) |
| 15591 | { |
| 15592 | struct breakpoint *bp; |
| 15593 | |
| 15594 | ALL_BREAKPOINTS (bp) |
| 15595 | if (is_syscall_catchpoint_enabled (bp)) |
| 15596 | { |
| 15597 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
| 15598 | |
| 15599 | if (c->syscalls_to_be_caught) |
| 15600 | { |
| 15601 | int i, iter; |
| 15602 | for (i = 0; |
| 15603 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
| 15604 | i++) |
| 15605 | if (syscall_number == iter) |
| 15606 | return 1; |
| 15607 | } |
| 15608 | else |
| 15609 | return 1; |
| 15610 | } |
| 15611 | |
| 15612 | return 0; |
| 15613 | } |
| 15614 | |
| 15615 | /* Complete syscall names. Used by "catch syscall". */ |
| 15616 | static VEC (char_ptr) * |
| 15617 | catch_syscall_completer (struct cmd_list_element *cmd, |
| 15618 | const char *text, const char *word) |
| 15619 | { |
| 15620 | const char **list = get_syscall_names (); |
| 15621 | VEC (char_ptr) *retlist |
| 15622 | = (list == NULL) ? NULL : complete_on_enum (list, word, word); |
| 15623 | |
| 15624 | xfree (list); |
| 15625 | return retlist; |
| 15626 | } |
| 15627 | |
| 15628 | /* Tracepoint-specific operations. */ |
| 15629 | |
| 15630 | /* Set tracepoint count to NUM. */ |
| 15631 | static void |
| 15632 | set_tracepoint_count (int num) |
| 15633 | { |
| 15634 | tracepoint_count = num; |
| 15635 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
| 15636 | } |
| 15637 | |
| 15638 | static void |
| 15639 | trace_command (char *arg, int from_tty) |
| 15640 | { |
| 15641 | struct breakpoint_ops *ops; |
| 15642 | const char *arg_cp = arg; |
| 15643 | |
| 15644 | if (arg && probe_linespec_to_ops (&arg_cp)) |
| 15645 | ops = &tracepoint_probe_breakpoint_ops; |
| 15646 | else |
| 15647 | ops = &tracepoint_breakpoint_ops; |
| 15648 | |
| 15649 | create_breakpoint (get_current_arch (), |
| 15650 | arg, |
| 15651 | NULL, 0, NULL, 1 /* parse arg */, |
| 15652 | 0 /* tempflag */, |
| 15653 | bp_tracepoint /* type_wanted */, |
| 15654 | 0 /* Ignore count */, |
| 15655 | pending_break_support, |
| 15656 | ops, |
| 15657 | from_tty, |
| 15658 | 1 /* enabled */, |
| 15659 | 0 /* internal */, 0); |
| 15660 | } |
| 15661 | |
| 15662 | static void |
| 15663 | ftrace_command (char *arg, int from_tty) |
| 15664 | { |
| 15665 | create_breakpoint (get_current_arch (), |
| 15666 | arg, |
| 15667 | NULL, 0, NULL, 1 /* parse arg */, |
| 15668 | 0 /* tempflag */, |
| 15669 | bp_fast_tracepoint /* type_wanted */, |
| 15670 | 0 /* Ignore count */, |
| 15671 | pending_break_support, |
| 15672 | &tracepoint_breakpoint_ops, |
| 15673 | from_tty, |
| 15674 | 1 /* enabled */, |
| 15675 | 0 /* internal */, 0); |
| 15676 | } |
| 15677 | |
| 15678 | /* strace command implementation. Creates a static tracepoint. */ |
| 15679 | |
| 15680 | static void |
| 15681 | strace_command (char *arg, int from_tty) |
| 15682 | { |
| 15683 | struct breakpoint_ops *ops; |
| 15684 | |
| 15685 | /* Decide if we are dealing with a static tracepoint marker (`-m'), |
| 15686 | or with a normal static tracepoint. */ |
| 15687 | if (arg && strncmp (arg, "-m", 2) == 0 && isspace (arg[2])) |
| 15688 | ops = &strace_marker_breakpoint_ops; |
| 15689 | else |
| 15690 | ops = &tracepoint_breakpoint_ops; |
| 15691 | |
| 15692 | create_breakpoint (get_current_arch (), |
| 15693 | arg, |
| 15694 | NULL, 0, NULL, 1 /* parse arg */, |
| 15695 | 0 /* tempflag */, |
| 15696 | bp_static_tracepoint /* type_wanted */, |
| 15697 | 0 /* Ignore count */, |
| 15698 | pending_break_support, |
| 15699 | ops, |
| 15700 | from_tty, |
| 15701 | 1 /* enabled */, |
| 15702 | 0 /* internal */, 0); |
| 15703 | } |
| 15704 | |
| 15705 | /* Set up a fake reader function that gets command lines from a linked |
| 15706 | list that was acquired during tracepoint uploading. */ |
| 15707 | |
| 15708 | static struct uploaded_tp *this_utp; |
| 15709 | static int next_cmd; |
| 15710 | |
| 15711 | static char * |
| 15712 | read_uploaded_action (void) |
| 15713 | { |
| 15714 | char *rslt; |
| 15715 | |
| 15716 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
| 15717 | |
| 15718 | next_cmd++; |
| 15719 | |
| 15720 | return rslt; |
| 15721 | } |
| 15722 | |
| 15723 | /* Given information about a tracepoint as recorded on a target (which |
| 15724 | can be either a live system or a trace file), attempt to create an |
| 15725 | equivalent GDB tracepoint. This is not a reliable process, since |
| 15726 | the target does not necessarily have all the information used when |
| 15727 | the tracepoint was originally defined. */ |
| 15728 | |
| 15729 | struct tracepoint * |
| 15730 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
| 15731 | { |
| 15732 | char *addr_str, small_buf[100]; |
| 15733 | struct tracepoint *tp; |
| 15734 | |
| 15735 | if (utp->at_string) |
| 15736 | addr_str = utp->at_string; |
| 15737 | else |
| 15738 | { |
| 15739 | /* In the absence of a source location, fall back to raw |
| 15740 | address. Since there is no way to confirm that the address |
| 15741 | means the same thing as when the trace was started, warn the |
| 15742 | user. */ |
| 15743 | warning (_("Uploaded tracepoint %d has no " |
| 15744 | "source location, using raw address"), |
| 15745 | utp->number); |
| 15746 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
| 15747 | addr_str = small_buf; |
| 15748 | } |
| 15749 | |
| 15750 | /* There's not much we can do with a sequence of bytecodes. */ |
| 15751 | if (utp->cond && !utp->cond_string) |
| 15752 | warning (_("Uploaded tracepoint %d condition " |
| 15753 | "has no source form, ignoring it"), |
| 15754 | utp->number); |
| 15755 | |
| 15756 | if (!create_breakpoint (get_current_arch (), |
| 15757 | addr_str, |
| 15758 | utp->cond_string, -1, NULL, |
| 15759 | 0 /* parse cond/thread */, |
| 15760 | 0 /* tempflag */, |
| 15761 | utp->type /* type_wanted */, |
| 15762 | 0 /* Ignore count */, |
| 15763 | pending_break_support, |
| 15764 | &tracepoint_breakpoint_ops, |
| 15765 | 0 /* from_tty */, |
| 15766 | utp->enabled /* enabled */, |
| 15767 | 0 /* internal */, |
| 15768 | CREATE_BREAKPOINT_FLAGS_INSERTED)) |
| 15769 | return NULL; |
| 15770 | |
| 15771 | /* Get the tracepoint we just created. */ |
| 15772 | tp = get_tracepoint (tracepoint_count); |
| 15773 | gdb_assert (tp != NULL); |
| 15774 | |
| 15775 | if (utp->pass > 0) |
| 15776 | { |
| 15777 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
| 15778 | tp->base.number); |
| 15779 | |
| 15780 | trace_pass_command (small_buf, 0); |
| 15781 | } |
| 15782 | |
| 15783 | /* If we have uploaded versions of the original commands, set up a |
| 15784 | special-purpose "reader" function and call the usual command line |
| 15785 | reader, then pass the result to the breakpoint command-setting |
| 15786 | function. */ |
| 15787 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
| 15788 | { |
| 15789 | struct command_line *cmd_list; |
| 15790 | |
| 15791 | this_utp = utp; |
| 15792 | next_cmd = 0; |
| 15793 | |
| 15794 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
| 15795 | |
| 15796 | breakpoint_set_commands (&tp->base, cmd_list); |
| 15797 | } |
| 15798 | else if (!VEC_empty (char_ptr, utp->actions) |
| 15799 | || !VEC_empty (char_ptr, utp->step_actions)) |
| 15800 | warning (_("Uploaded tracepoint %d actions " |
| 15801 | "have no source form, ignoring them"), |
| 15802 | utp->number); |
| 15803 | |
| 15804 | /* Copy any status information that might be available. */ |
| 15805 | tp->base.hit_count = utp->hit_count; |
| 15806 | tp->traceframe_usage = utp->traceframe_usage; |
| 15807 | |
| 15808 | return tp; |
| 15809 | } |
| 15810 | |
| 15811 | /* Print information on tracepoint number TPNUM_EXP, or all if |
| 15812 | omitted. */ |
| 15813 | |
| 15814 | static void |
| 15815 | tracepoints_info (char *args, int from_tty) |
| 15816 | { |
| 15817 | struct ui_out *uiout = current_uiout; |
| 15818 | int num_printed; |
| 15819 | |
| 15820 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
| 15821 | |
| 15822 | if (num_printed == 0) |
| 15823 | { |
| 15824 | if (args == NULL || *args == '\0') |
| 15825 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
| 15826 | else |
| 15827 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
| 15828 | } |
| 15829 | |
| 15830 | default_collect_info (); |
| 15831 | } |
| 15832 | |
| 15833 | /* The 'enable trace' command enables tracepoints. |
| 15834 | Not supported by all targets. */ |
| 15835 | static void |
| 15836 | enable_trace_command (char *args, int from_tty) |
| 15837 | { |
| 15838 | enable_command (args, from_tty); |
| 15839 | } |
| 15840 | |
| 15841 | /* The 'disable trace' command disables tracepoints. |
| 15842 | Not supported by all targets. */ |
| 15843 | static void |
| 15844 | disable_trace_command (char *args, int from_tty) |
| 15845 | { |
| 15846 | disable_command (args, from_tty); |
| 15847 | } |
| 15848 | |
| 15849 | /* Remove a tracepoint (or all if no argument). */ |
| 15850 | static void |
| 15851 | delete_trace_command (char *arg, int from_tty) |
| 15852 | { |
| 15853 | struct breakpoint *b, *b_tmp; |
| 15854 | |
| 15855 | dont_repeat (); |
| 15856 | |
| 15857 | if (arg == 0) |
| 15858 | { |
| 15859 | int breaks_to_delete = 0; |
| 15860 | |
| 15861 | /* Delete all breakpoints if no argument. |
| 15862 | Do not delete internal or call-dummy breakpoints, these |
| 15863 | have to be deleted with an explicit breakpoint number |
| 15864 | argument. */ |
| 15865 | ALL_TRACEPOINTS (b) |
| 15866 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
| 15867 | { |
| 15868 | breaks_to_delete = 1; |
| 15869 | break; |
| 15870 | } |
| 15871 | |
| 15872 | /* Ask user only if there are some breakpoints to delete. */ |
| 15873 | if (!from_tty |
| 15874 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) |
| 15875 | { |
| 15876 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 15877 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
| 15878 | delete_breakpoint (b); |
| 15879 | } |
| 15880 | } |
| 15881 | else |
| 15882 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
| 15883 | } |
| 15884 | |
| 15885 | /* Helper function for trace_pass_command. */ |
| 15886 | |
| 15887 | static void |
| 15888 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
| 15889 | { |
| 15890 | tp->pass_count = count; |
| 15891 | observer_notify_breakpoint_modified (&tp->base); |
| 15892 | if (from_tty) |
| 15893 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), |
| 15894 | tp->base.number, count); |
| 15895 | } |
| 15896 | |
| 15897 | /* Set passcount for tracepoint. |
| 15898 | |
| 15899 | First command argument is passcount, second is tracepoint number. |
| 15900 | If tracepoint number omitted, apply to most recently defined. |
| 15901 | Also accepts special argument "all". */ |
| 15902 | |
| 15903 | static void |
| 15904 | trace_pass_command (char *args, int from_tty) |
| 15905 | { |
| 15906 | struct tracepoint *t1; |
| 15907 | unsigned int count; |
| 15908 | |
| 15909 | if (args == 0 || *args == 0) |
| 15910 | error (_("passcount command requires an " |
| 15911 | "argument (count + optional TP num)")); |
| 15912 | |
| 15913 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
| 15914 | |
| 15915 | args = skip_spaces (args); |
| 15916 | if (*args && strncasecmp (args, "all", 3) == 0) |
| 15917 | { |
| 15918 | struct breakpoint *b; |
| 15919 | |
| 15920 | args += 3; /* Skip special argument "all". */ |
| 15921 | if (*args) |
| 15922 | error (_("Junk at end of arguments.")); |
| 15923 | |
| 15924 | ALL_TRACEPOINTS (b) |
| 15925 | { |
| 15926 | t1 = (struct tracepoint *) b; |
| 15927 | trace_pass_set_count (t1, count, from_tty); |
| 15928 | } |
| 15929 | } |
| 15930 | else if (*args == '\0') |
| 15931 | { |
| 15932 | t1 = get_tracepoint_by_number (&args, NULL); |
| 15933 | if (t1) |
| 15934 | trace_pass_set_count (t1, count, from_tty); |
| 15935 | } |
| 15936 | else |
| 15937 | { |
| 15938 | struct get_number_or_range_state state; |
| 15939 | |
| 15940 | init_number_or_range (&state, args); |
| 15941 | while (!state.finished) |
| 15942 | { |
| 15943 | t1 = get_tracepoint_by_number (&args, &state); |
| 15944 | if (t1) |
| 15945 | trace_pass_set_count (t1, count, from_tty); |
| 15946 | } |
| 15947 | } |
| 15948 | } |
| 15949 | |
| 15950 | struct tracepoint * |
| 15951 | get_tracepoint (int num) |
| 15952 | { |
| 15953 | struct breakpoint *t; |
| 15954 | |
| 15955 | ALL_TRACEPOINTS (t) |
| 15956 | if (t->number == num) |
| 15957 | return (struct tracepoint *) t; |
| 15958 | |
| 15959 | return NULL; |
| 15960 | } |
| 15961 | |
| 15962 | /* Find the tracepoint with the given target-side number (which may be |
| 15963 | different from the tracepoint number after disconnecting and |
| 15964 | reconnecting). */ |
| 15965 | |
| 15966 | struct tracepoint * |
| 15967 | get_tracepoint_by_number_on_target (int num) |
| 15968 | { |
| 15969 | struct breakpoint *b; |
| 15970 | |
| 15971 | ALL_TRACEPOINTS (b) |
| 15972 | { |
| 15973 | struct tracepoint *t = (struct tracepoint *) b; |
| 15974 | |
| 15975 | if (t->number_on_target == num) |
| 15976 | return t; |
| 15977 | } |
| 15978 | |
| 15979 | return NULL; |
| 15980 | } |
| 15981 | |
| 15982 | /* Utility: parse a tracepoint number and look it up in the list. |
| 15983 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
| 15984 | If the argument is missing, the most recent tracepoint |
| 15985 | (tracepoint_count) is returned. */ |
| 15986 | |
| 15987 | struct tracepoint * |
| 15988 | get_tracepoint_by_number (char **arg, |
| 15989 | struct get_number_or_range_state *state) |
| 15990 | { |
| 15991 | struct breakpoint *t; |
| 15992 | int tpnum; |
| 15993 | char *instring = arg == NULL ? NULL : *arg; |
| 15994 | |
| 15995 | if (state) |
| 15996 | { |
| 15997 | gdb_assert (!state->finished); |
| 15998 | tpnum = get_number_or_range (state); |
| 15999 | } |
| 16000 | else if (arg == NULL || *arg == NULL || ! **arg) |
| 16001 | tpnum = tracepoint_count; |
| 16002 | else |
| 16003 | tpnum = get_number (arg); |
| 16004 | |
| 16005 | if (tpnum <= 0) |
| 16006 | { |
| 16007 | if (instring && *instring) |
| 16008 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), |
| 16009 | instring); |
| 16010 | else |
| 16011 | printf_filtered (_("No previous tracepoint\n")); |
| 16012 | return NULL; |
| 16013 | } |
| 16014 | |
| 16015 | ALL_TRACEPOINTS (t) |
| 16016 | if (t->number == tpnum) |
| 16017 | { |
| 16018 | return (struct tracepoint *) t; |
| 16019 | } |
| 16020 | |
| 16021 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
| 16022 | return NULL; |
| 16023 | } |
| 16024 | |
| 16025 | void |
| 16026 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) |
| 16027 | { |
| 16028 | if (b->thread != -1) |
| 16029 | fprintf_unfiltered (fp, " thread %d", b->thread); |
| 16030 | |
| 16031 | if (b->task != 0) |
| 16032 | fprintf_unfiltered (fp, " task %d", b->task); |
| 16033 | |
| 16034 | fprintf_unfiltered (fp, "\n"); |
| 16035 | } |
| 16036 | |
| 16037 | /* Save information on user settable breakpoints (watchpoints, etc) to |
| 16038 | a new script file named FILENAME. If FILTER is non-NULL, call it |
| 16039 | on each breakpoint and only include the ones for which it returns |
| 16040 | non-zero. */ |
| 16041 | |
| 16042 | static void |
| 16043 | save_breakpoints (char *filename, int from_tty, |
| 16044 | int (*filter) (const struct breakpoint *)) |
| 16045 | { |
| 16046 | struct breakpoint *tp; |
| 16047 | int any = 0; |
| 16048 | struct cleanup *cleanup; |
| 16049 | struct ui_file *fp; |
| 16050 | int extra_trace_bits = 0; |
| 16051 | |
| 16052 | if (filename == 0 || *filename == 0) |
| 16053 | error (_("Argument required (file name in which to save)")); |
| 16054 | |
| 16055 | /* See if we have anything to save. */ |
| 16056 | ALL_BREAKPOINTS (tp) |
| 16057 | { |
| 16058 | /* Skip internal and momentary breakpoints. */ |
| 16059 | if (!user_breakpoint_p (tp)) |
| 16060 | continue; |
| 16061 | |
| 16062 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 16063 | if (filter && !filter (tp)) |
| 16064 | continue; |
| 16065 | |
| 16066 | any = 1; |
| 16067 | |
| 16068 | if (is_tracepoint (tp)) |
| 16069 | { |
| 16070 | extra_trace_bits = 1; |
| 16071 | |
| 16072 | /* We can stop searching. */ |
| 16073 | break; |
| 16074 | } |
| 16075 | } |
| 16076 | |
| 16077 | if (!any) |
| 16078 | { |
| 16079 | warning (_("Nothing to save.")); |
| 16080 | return; |
| 16081 | } |
| 16082 | |
| 16083 | filename = tilde_expand (filename); |
| 16084 | cleanup = make_cleanup (xfree, filename); |
| 16085 | fp = gdb_fopen (filename, "w"); |
| 16086 | if (!fp) |
| 16087 | error (_("Unable to open file '%s' for saving (%s)"), |
| 16088 | filename, safe_strerror (errno)); |
| 16089 | make_cleanup_ui_file_delete (fp); |
| 16090 | |
| 16091 | if (extra_trace_bits) |
| 16092 | save_trace_state_variables (fp); |
| 16093 | |
| 16094 | ALL_BREAKPOINTS (tp) |
| 16095 | { |
| 16096 | /* Skip internal and momentary breakpoints. */ |
| 16097 | if (!user_breakpoint_p (tp)) |
| 16098 | continue; |
| 16099 | |
| 16100 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 16101 | if (filter && !filter (tp)) |
| 16102 | continue; |
| 16103 | |
| 16104 | tp->ops->print_recreate (tp, fp); |
| 16105 | |
| 16106 | /* Note, we can't rely on tp->number for anything, as we can't |
| 16107 | assume the recreated breakpoint numbers will match. Use $bpnum |
| 16108 | instead. */ |
| 16109 | |
| 16110 | if (tp->cond_string) |
| 16111 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); |
| 16112 | |
| 16113 | if (tp->ignore_count) |
| 16114 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); |
| 16115 | |
| 16116 | if (tp->type != bp_dprintf && tp->commands) |
| 16117 | { |
| 16118 | volatile struct gdb_exception ex; |
| 16119 | |
| 16120 | fprintf_unfiltered (fp, " commands\n"); |
| 16121 | |
| 16122 | ui_out_redirect (current_uiout, fp); |
| 16123 | TRY_CATCH (ex, RETURN_MASK_ALL) |
| 16124 | { |
| 16125 | print_command_lines (current_uiout, tp->commands->commands, 2); |
| 16126 | } |
| 16127 | ui_out_redirect (current_uiout, NULL); |
| 16128 | |
| 16129 | if (ex.reason < 0) |
| 16130 | throw_exception (ex); |
| 16131 | |
| 16132 | fprintf_unfiltered (fp, " end\n"); |
| 16133 | } |
| 16134 | |
| 16135 | if (tp->enable_state == bp_disabled) |
| 16136 | fprintf_unfiltered (fp, "disable\n"); |
| 16137 | |
| 16138 | /* If this is a multi-location breakpoint, check if the locations |
| 16139 | should be individually disabled. Watchpoint locations are |
| 16140 | special, and not user visible. */ |
| 16141 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) |
| 16142 | { |
| 16143 | struct bp_location *loc; |
| 16144 | int n = 1; |
| 16145 | |
| 16146 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) |
| 16147 | if (!loc->enabled) |
| 16148 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); |
| 16149 | } |
| 16150 | } |
| 16151 | |
| 16152 | if (extra_trace_bits && *default_collect) |
| 16153 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
| 16154 | |
| 16155 | if (from_tty) |
| 16156 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
| 16157 | do_cleanups (cleanup); |
| 16158 | } |
| 16159 | |
| 16160 | /* The `save breakpoints' command. */ |
| 16161 | |
| 16162 | static void |
| 16163 | save_breakpoints_command (char *args, int from_tty) |
| 16164 | { |
| 16165 | save_breakpoints (args, from_tty, NULL); |
| 16166 | } |
| 16167 | |
| 16168 | /* The `save tracepoints' command. */ |
| 16169 | |
| 16170 | static void |
| 16171 | save_tracepoints_command (char *args, int from_tty) |
| 16172 | { |
| 16173 | save_breakpoints (args, from_tty, is_tracepoint); |
| 16174 | } |
| 16175 | |
| 16176 | /* Create a vector of all tracepoints. */ |
| 16177 | |
| 16178 | VEC(breakpoint_p) * |
| 16179 | all_tracepoints (void) |
| 16180 | { |
| 16181 | VEC(breakpoint_p) *tp_vec = 0; |
| 16182 | struct breakpoint *tp; |
| 16183 | |
| 16184 | ALL_TRACEPOINTS (tp) |
| 16185 | { |
| 16186 | VEC_safe_push (breakpoint_p, tp_vec, tp); |
| 16187 | } |
| 16188 | |
| 16189 | return tp_vec; |
| 16190 | } |
| 16191 | |
| 16192 | \f |
| 16193 | /* This help string is used for the break, hbreak, tbreak and thbreak |
| 16194 | commands. It is defined as a macro to prevent duplication. |
| 16195 | COMMAND should be a string constant containing the name of the |
| 16196 | command. */ |
| 16197 | #define BREAK_ARGS_HELP(command) \ |
| 16198 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
| 16199 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ |
| 16200 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ |
| 16201 | guessed probe type) or `-probe-stap' (for a SystemTap probe).\n\ |
| 16202 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
| 16203 | If a line number is specified, break at start of code for that line.\n\ |
| 16204 | If a function is specified, break at start of code for that function.\n\ |
| 16205 | If an address is specified, break at that exact address.\n\ |
| 16206 | With no LOCATION, uses current execution address of the selected\n\ |
| 16207 | stack frame. This is useful for breaking on return to a stack frame.\n\ |
| 16208 | \n\ |
| 16209 | THREADNUM is the number from \"info threads\".\n\ |
| 16210 | CONDITION is a boolean expression.\n\ |
| 16211 | \n\ |
| 16212 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
| 16213 | conditions are different.\n\ |
| 16214 | \n\ |
| 16215 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." |
| 16216 | |
| 16217 | /* List of subcommands for "catch". */ |
| 16218 | static struct cmd_list_element *catch_cmdlist; |
| 16219 | |
| 16220 | /* List of subcommands for "tcatch". */ |
| 16221 | static struct cmd_list_element *tcatch_cmdlist; |
| 16222 | |
| 16223 | void |
| 16224 | add_catch_command (char *name, char *docstring, |
| 16225 | cmd_sfunc_ftype *sfunc, |
| 16226 | completer_ftype *completer, |
| 16227 | void *user_data_catch, |
| 16228 | void *user_data_tcatch) |
| 16229 | { |
| 16230 | struct cmd_list_element *command; |
| 16231 | |
| 16232 | command = add_cmd (name, class_breakpoint, NULL, docstring, |
| 16233 | &catch_cmdlist); |
| 16234 | set_cmd_sfunc (command, sfunc); |
| 16235 | set_cmd_context (command, user_data_catch); |
| 16236 | set_cmd_completer (command, completer); |
| 16237 | |
| 16238 | command = add_cmd (name, class_breakpoint, NULL, docstring, |
| 16239 | &tcatch_cmdlist); |
| 16240 | set_cmd_sfunc (command, sfunc); |
| 16241 | set_cmd_context (command, user_data_tcatch); |
| 16242 | set_cmd_completer (command, completer); |
| 16243 | } |
| 16244 | |
| 16245 | static void |
| 16246 | clear_syscall_counts (struct inferior *inf) |
| 16247 | { |
| 16248 | struct catch_syscall_inferior_data *inf_data |
| 16249 | = get_catch_syscall_inferior_data (inf); |
| 16250 | |
| 16251 | inf_data->total_syscalls_count = 0; |
| 16252 | inf_data->any_syscall_count = 0; |
| 16253 | VEC_free (int, inf_data->syscalls_counts); |
| 16254 | } |
| 16255 | |
| 16256 | static void |
| 16257 | save_command (char *arg, int from_tty) |
| 16258 | { |
| 16259 | printf_unfiltered (_("\"save\" must be followed by " |
| 16260 | "the name of a save subcommand.\n")); |
| 16261 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
| 16262 | } |
| 16263 | |
| 16264 | struct breakpoint * |
| 16265 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), |
| 16266 | void *data) |
| 16267 | { |
| 16268 | struct breakpoint *b, *b_tmp; |
| 16269 | |
| 16270 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 16271 | { |
| 16272 | if ((*callback) (b, data)) |
| 16273 | return b; |
| 16274 | } |
| 16275 | |
| 16276 | return NULL; |
| 16277 | } |
| 16278 | |
| 16279 | /* Zero if any of the breakpoint's locations could be a location where |
| 16280 | functions have been inlined, nonzero otherwise. */ |
| 16281 | |
| 16282 | static int |
| 16283 | is_non_inline_function (struct breakpoint *b) |
| 16284 | { |
| 16285 | /* The shared library event breakpoint is set on the address of a |
| 16286 | non-inline function. */ |
| 16287 | if (b->type == bp_shlib_event) |
| 16288 | return 1; |
| 16289 | |
| 16290 | return 0; |
| 16291 | } |
| 16292 | |
| 16293 | /* Nonzero if the specified PC cannot be a location where functions |
| 16294 | have been inlined. */ |
| 16295 | |
| 16296 | int |
| 16297 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
| 16298 | const struct target_waitstatus *ws) |
| 16299 | { |
| 16300 | struct breakpoint *b; |
| 16301 | struct bp_location *bl; |
| 16302 | |
| 16303 | ALL_BREAKPOINTS (b) |
| 16304 | { |
| 16305 | if (!is_non_inline_function (b)) |
| 16306 | continue; |
| 16307 | |
| 16308 | for (bl = b->loc; bl != NULL; bl = bl->next) |
| 16309 | { |
| 16310 | if (!bl->shlib_disabled |
| 16311 | && bpstat_check_location (bl, aspace, pc, ws)) |
| 16312 | return 1; |
| 16313 | } |
| 16314 | } |
| 16315 | |
| 16316 | return 0; |
| 16317 | } |
| 16318 | |
| 16319 | /* Remove any references to OBJFILE which is going to be freed. */ |
| 16320 | |
| 16321 | void |
| 16322 | breakpoint_free_objfile (struct objfile *objfile) |
| 16323 | { |
| 16324 | struct bp_location **locp, *loc; |
| 16325 | |
| 16326 | ALL_BP_LOCATIONS (loc, locp) |
| 16327 | if (loc->symtab != NULL && loc->symtab->objfile == objfile) |
| 16328 | loc->symtab = NULL; |
| 16329 | } |
| 16330 | |
| 16331 | void |
| 16332 | initialize_breakpoint_ops (void) |
| 16333 | { |
| 16334 | static int initialized = 0; |
| 16335 | |
| 16336 | struct breakpoint_ops *ops; |
| 16337 | |
| 16338 | if (initialized) |
| 16339 | return; |
| 16340 | initialized = 1; |
| 16341 | |
| 16342 | /* The breakpoint_ops structure to be inherit by all kinds of |
| 16343 | breakpoints (real breakpoints, i.e., user "break" breakpoints, |
| 16344 | internal and momentary breakpoints, etc.). */ |
| 16345 | ops = &bkpt_base_breakpoint_ops; |
| 16346 | *ops = base_breakpoint_ops; |
| 16347 | ops->re_set = bkpt_re_set; |
| 16348 | ops->insert_location = bkpt_insert_location; |
| 16349 | ops->remove_location = bkpt_remove_location; |
| 16350 | ops->breakpoint_hit = bkpt_breakpoint_hit; |
| 16351 | ops->create_sals_from_address = bkpt_create_sals_from_address; |
| 16352 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
| 16353 | ops->decode_linespec = bkpt_decode_linespec; |
| 16354 | |
| 16355 | /* The breakpoint_ops structure to be used in regular breakpoints. */ |
| 16356 | ops = &bkpt_breakpoint_ops; |
| 16357 | *ops = bkpt_base_breakpoint_ops; |
| 16358 | ops->re_set = bkpt_re_set; |
| 16359 | ops->resources_needed = bkpt_resources_needed; |
| 16360 | ops->print_it = bkpt_print_it; |
| 16361 | ops->print_mention = bkpt_print_mention; |
| 16362 | ops->print_recreate = bkpt_print_recreate; |
| 16363 | |
| 16364 | /* Ranged breakpoints. */ |
| 16365 | ops = &ranged_breakpoint_ops; |
| 16366 | *ops = bkpt_breakpoint_ops; |
| 16367 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; |
| 16368 | ops->resources_needed = resources_needed_ranged_breakpoint; |
| 16369 | ops->print_it = print_it_ranged_breakpoint; |
| 16370 | ops->print_one = print_one_ranged_breakpoint; |
| 16371 | ops->print_one_detail = print_one_detail_ranged_breakpoint; |
| 16372 | ops->print_mention = print_mention_ranged_breakpoint; |
| 16373 | ops->print_recreate = print_recreate_ranged_breakpoint; |
| 16374 | |
| 16375 | /* Internal breakpoints. */ |
| 16376 | ops = &internal_breakpoint_ops; |
| 16377 | *ops = bkpt_base_breakpoint_ops; |
| 16378 | ops->re_set = internal_bkpt_re_set; |
| 16379 | ops->check_status = internal_bkpt_check_status; |
| 16380 | ops->print_it = internal_bkpt_print_it; |
| 16381 | ops->print_mention = internal_bkpt_print_mention; |
| 16382 | |
| 16383 | /* Momentary breakpoints. */ |
| 16384 | ops = &momentary_breakpoint_ops; |
| 16385 | *ops = bkpt_base_breakpoint_ops; |
| 16386 | ops->re_set = momentary_bkpt_re_set; |
| 16387 | ops->check_status = momentary_bkpt_check_status; |
| 16388 | ops->print_it = momentary_bkpt_print_it; |
| 16389 | ops->print_mention = momentary_bkpt_print_mention; |
| 16390 | |
| 16391 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
| 16392 | ops = &longjmp_breakpoint_ops; |
| 16393 | *ops = momentary_breakpoint_ops; |
| 16394 | ops->dtor = longjmp_bkpt_dtor; |
| 16395 | |
| 16396 | /* Probe breakpoints. */ |
| 16397 | ops = &bkpt_probe_breakpoint_ops; |
| 16398 | *ops = bkpt_breakpoint_ops; |
| 16399 | ops->insert_location = bkpt_probe_insert_location; |
| 16400 | ops->remove_location = bkpt_probe_remove_location; |
| 16401 | ops->create_sals_from_address = bkpt_probe_create_sals_from_address; |
| 16402 | ops->decode_linespec = bkpt_probe_decode_linespec; |
| 16403 | |
| 16404 | /* Watchpoints. */ |
| 16405 | ops = &watchpoint_breakpoint_ops; |
| 16406 | *ops = base_breakpoint_ops; |
| 16407 | ops->dtor = dtor_watchpoint; |
| 16408 | ops->re_set = re_set_watchpoint; |
| 16409 | ops->insert_location = insert_watchpoint; |
| 16410 | ops->remove_location = remove_watchpoint; |
| 16411 | ops->breakpoint_hit = breakpoint_hit_watchpoint; |
| 16412 | ops->check_status = check_status_watchpoint; |
| 16413 | ops->resources_needed = resources_needed_watchpoint; |
| 16414 | ops->works_in_software_mode = works_in_software_mode_watchpoint; |
| 16415 | ops->print_it = print_it_watchpoint; |
| 16416 | ops->print_mention = print_mention_watchpoint; |
| 16417 | ops->print_recreate = print_recreate_watchpoint; |
| 16418 | ops->explains_signal = explains_signal_watchpoint; |
| 16419 | |
| 16420 | /* Masked watchpoints. */ |
| 16421 | ops = &masked_watchpoint_breakpoint_ops; |
| 16422 | *ops = watchpoint_breakpoint_ops; |
| 16423 | ops->insert_location = insert_masked_watchpoint; |
| 16424 | ops->remove_location = remove_masked_watchpoint; |
| 16425 | ops->resources_needed = resources_needed_masked_watchpoint; |
| 16426 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; |
| 16427 | ops->print_it = print_it_masked_watchpoint; |
| 16428 | ops->print_one_detail = print_one_detail_masked_watchpoint; |
| 16429 | ops->print_mention = print_mention_masked_watchpoint; |
| 16430 | ops->print_recreate = print_recreate_masked_watchpoint; |
| 16431 | |
| 16432 | /* Tracepoints. */ |
| 16433 | ops = &tracepoint_breakpoint_ops; |
| 16434 | *ops = base_breakpoint_ops; |
| 16435 | ops->re_set = tracepoint_re_set; |
| 16436 | ops->breakpoint_hit = tracepoint_breakpoint_hit; |
| 16437 | ops->print_one_detail = tracepoint_print_one_detail; |
| 16438 | ops->print_mention = tracepoint_print_mention; |
| 16439 | ops->print_recreate = tracepoint_print_recreate; |
| 16440 | ops->create_sals_from_address = tracepoint_create_sals_from_address; |
| 16441 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
| 16442 | ops->decode_linespec = tracepoint_decode_linespec; |
| 16443 | |
| 16444 | /* Probe tracepoints. */ |
| 16445 | ops = &tracepoint_probe_breakpoint_ops; |
| 16446 | *ops = tracepoint_breakpoint_ops; |
| 16447 | ops->create_sals_from_address = tracepoint_probe_create_sals_from_address; |
| 16448 | ops->decode_linespec = tracepoint_probe_decode_linespec; |
| 16449 | |
| 16450 | /* Static tracepoints with marker (`-m'). */ |
| 16451 | ops = &strace_marker_breakpoint_ops; |
| 16452 | *ops = tracepoint_breakpoint_ops; |
| 16453 | ops->create_sals_from_address = strace_marker_create_sals_from_address; |
| 16454 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
| 16455 | ops->decode_linespec = strace_marker_decode_linespec; |
| 16456 | |
| 16457 | /* Fork catchpoints. */ |
| 16458 | ops = &catch_fork_breakpoint_ops; |
| 16459 | *ops = base_breakpoint_ops; |
| 16460 | ops->insert_location = insert_catch_fork; |
| 16461 | ops->remove_location = remove_catch_fork; |
| 16462 | ops->breakpoint_hit = breakpoint_hit_catch_fork; |
| 16463 | ops->print_it = print_it_catch_fork; |
| 16464 | ops->print_one = print_one_catch_fork; |
| 16465 | ops->print_mention = print_mention_catch_fork; |
| 16466 | ops->print_recreate = print_recreate_catch_fork; |
| 16467 | |
| 16468 | /* Vfork catchpoints. */ |
| 16469 | ops = &catch_vfork_breakpoint_ops; |
| 16470 | *ops = base_breakpoint_ops; |
| 16471 | ops->insert_location = insert_catch_vfork; |
| 16472 | ops->remove_location = remove_catch_vfork; |
| 16473 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; |
| 16474 | ops->print_it = print_it_catch_vfork; |
| 16475 | ops->print_one = print_one_catch_vfork; |
| 16476 | ops->print_mention = print_mention_catch_vfork; |
| 16477 | ops->print_recreate = print_recreate_catch_vfork; |
| 16478 | |
| 16479 | /* Exec catchpoints. */ |
| 16480 | ops = &catch_exec_breakpoint_ops; |
| 16481 | *ops = base_breakpoint_ops; |
| 16482 | ops->dtor = dtor_catch_exec; |
| 16483 | ops->insert_location = insert_catch_exec; |
| 16484 | ops->remove_location = remove_catch_exec; |
| 16485 | ops->breakpoint_hit = breakpoint_hit_catch_exec; |
| 16486 | ops->print_it = print_it_catch_exec; |
| 16487 | ops->print_one = print_one_catch_exec; |
| 16488 | ops->print_mention = print_mention_catch_exec; |
| 16489 | ops->print_recreate = print_recreate_catch_exec; |
| 16490 | |
| 16491 | /* Syscall catchpoints. */ |
| 16492 | ops = &catch_syscall_breakpoint_ops; |
| 16493 | *ops = base_breakpoint_ops; |
| 16494 | ops->dtor = dtor_catch_syscall; |
| 16495 | ops->insert_location = insert_catch_syscall; |
| 16496 | ops->remove_location = remove_catch_syscall; |
| 16497 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; |
| 16498 | ops->print_it = print_it_catch_syscall; |
| 16499 | ops->print_one = print_one_catch_syscall; |
| 16500 | ops->print_mention = print_mention_catch_syscall; |
| 16501 | ops->print_recreate = print_recreate_catch_syscall; |
| 16502 | |
| 16503 | /* Solib-related catchpoints. */ |
| 16504 | ops = &catch_solib_breakpoint_ops; |
| 16505 | *ops = base_breakpoint_ops; |
| 16506 | ops->dtor = dtor_catch_solib; |
| 16507 | ops->insert_location = insert_catch_solib; |
| 16508 | ops->remove_location = remove_catch_solib; |
| 16509 | ops->breakpoint_hit = breakpoint_hit_catch_solib; |
| 16510 | ops->check_status = check_status_catch_solib; |
| 16511 | ops->print_it = print_it_catch_solib; |
| 16512 | ops->print_one = print_one_catch_solib; |
| 16513 | ops->print_mention = print_mention_catch_solib; |
| 16514 | ops->print_recreate = print_recreate_catch_solib; |
| 16515 | |
| 16516 | ops = &dprintf_breakpoint_ops; |
| 16517 | *ops = bkpt_base_breakpoint_ops; |
| 16518 | ops->re_set = dprintf_re_set; |
| 16519 | ops->resources_needed = bkpt_resources_needed; |
| 16520 | ops->print_it = bkpt_print_it; |
| 16521 | ops->print_mention = bkpt_print_mention; |
| 16522 | ops->print_recreate = dprintf_print_recreate; |
| 16523 | ops->after_condition_true = dprintf_after_condition_true; |
| 16524 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
| 16525 | } |
| 16526 | |
| 16527 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
| 16528 | |
| 16529 | static struct cmd_list_element *enablebreaklist = NULL; |
| 16530 | |
| 16531 | void |
| 16532 | _initialize_breakpoint (void) |
| 16533 | { |
| 16534 | struct cmd_list_element *c; |
| 16535 | |
| 16536 | initialize_breakpoint_ops (); |
| 16537 | |
| 16538 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
| 16539 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
| 16540 | observer_attach_inferior_exit (clear_syscall_counts); |
| 16541 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
| 16542 | |
| 16543 | breakpoint_objfile_key |
| 16544 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); |
| 16545 | |
| 16546 | catch_syscall_inferior_data |
| 16547 | = register_inferior_data_with_cleanup (NULL, |
| 16548 | catch_syscall_inferior_data_cleanup); |
| 16549 | |
| 16550 | breakpoint_chain = 0; |
| 16551 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful |
| 16552 | before a breakpoint is set. */ |
| 16553 | breakpoint_count = 0; |
| 16554 | |
| 16555 | tracepoint_count = 0; |
| 16556 | |
| 16557 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
| 16558 | Set ignore-count of breakpoint number N to COUNT.\n\ |
| 16559 | Usage is `ignore N COUNT'.")); |
| 16560 | if (xdb_commands) |
| 16561 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
| 16562 | |
| 16563 | add_com ("commands", class_breakpoint, commands_command, _("\ |
| 16564 | Set commands to be executed when a breakpoint is hit.\n\ |
| 16565 | Give breakpoint number as argument after \"commands\".\n\ |
| 16566 | With no argument, the targeted breakpoint is the last one set.\n\ |
| 16567 | The commands themselves follow starting on the next line.\n\ |
| 16568 | Type a line containing \"end\" to indicate the end of them.\n\ |
| 16569 | Give \"silent\" as the first line to make the breakpoint silent;\n\ |
| 16570 | then no output is printed when it is hit, except what the commands print.")); |
| 16571 | |
| 16572 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
| 16573 | Specify breakpoint number N to break only if COND is true.\n\ |
| 16574 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
| 16575 | expression to be evaluated whenever breakpoint N is reached.")); |
| 16576 | set_cmd_completer (c, condition_completer); |
| 16577 | |
| 16578 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
| 16579 | Set a temporary breakpoint.\n\ |
| 16580 | Like \"break\" except the breakpoint is only temporary,\n\ |
| 16581 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ |
| 16582 | by using \"enable delete\" on the breakpoint number.\n\ |
| 16583 | \n" |
| 16584 | BREAK_ARGS_HELP ("tbreak"))); |
| 16585 | set_cmd_completer (c, location_completer); |
| 16586 | |
| 16587 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
| 16588 | Set a hardware assisted breakpoint.\n\ |
| 16589 | Like \"break\" except the breakpoint requires hardware support,\n\ |
| 16590 | some target hardware may not have this support.\n\ |
| 16591 | \n" |
| 16592 | BREAK_ARGS_HELP ("hbreak"))); |
| 16593 | set_cmd_completer (c, location_completer); |
| 16594 | |
| 16595 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
| 16596 | Set a temporary hardware assisted breakpoint.\n\ |
| 16597 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
| 16598 | so it will be deleted when hit.\n\ |
| 16599 | \n" |
| 16600 | BREAK_ARGS_HELP ("thbreak"))); |
| 16601 | set_cmd_completer (c, location_completer); |
| 16602 | |
| 16603 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
| 16604 | Enable some breakpoints.\n\ |
| 16605 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 16606 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 16607 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 16608 | With a subcommand you can enable temporarily."), |
| 16609 | &enablelist, "enable ", 1, &cmdlist); |
| 16610 | if (xdb_commands) |
| 16611 | add_com ("ab", class_breakpoint, enable_command, _("\ |
| 16612 | Enable some breakpoints.\n\ |
| 16613 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 16614 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 16615 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 16616 | With a subcommand you can enable temporarily.")); |
| 16617 | |
| 16618 | add_com_alias ("en", "enable", class_breakpoint, 1); |
| 16619 | |
| 16620 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
| 16621 | Enable some breakpoints.\n\ |
| 16622 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 16623 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 16624 | May be abbreviated to simply \"enable\".\n"), |
| 16625 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
| 16626 | |
| 16627 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 16628 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 16629 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 16630 | &enablebreaklist); |
| 16631 | |
| 16632 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 16633 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 16634 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 16635 | &enablebreaklist); |
| 16636 | |
| 16637 | add_cmd ("count", no_class, enable_count_command, _("\ |
| 16638 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ |
| 16639 | If a breakpoint is hit while enabled in this fashion,\n\ |
| 16640 | the count is decremented; when it reaches zero, the breakpoint is disabled."), |
| 16641 | &enablebreaklist); |
| 16642 | |
| 16643 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 16644 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 16645 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 16646 | &enablelist); |
| 16647 | |
| 16648 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 16649 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 16650 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 16651 | &enablelist); |
| 16652 | |
| 16653 | add_cmd ("count", no_class, enable_count_command, _("\ |
| 16654 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ |
| 16655 | If a breakpoint is hit while enabled in this fashion,\n\ |
| 16656 | the count is decremented; when it reaches zero, the breakpoint is disabled."), |
| 16657 | &enablelist); |
| 16658 | |
| 16659 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
| 16660 | Disable some breakpoints.\n\ |
| 16661 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16662 | To disable all breakpoints, give no argument.\n\ |
| 16663 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
| 16664 | &disablelist, "disable ", 1, &cmdlist); |
| 16665 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
| 16666 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
| 16667 | if (xdb_commands) |
| 16668 | add_com ("sb", class_breakpoint, disable_command, _("\ |
| 16669 | Disable some breakpoints.\n\ |
| 16670 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16671 | To disable all breakpoints, give no argument.\n\ |
| 16672 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
| 16673 | |
| 16674 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
| 16675 | Disable some breakpoints.\n\ |
| 16676 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16677 | To disable all breakpoints, give no argument.\n\ |
| 16678 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
| 16679 | This command may be abbreviated \"disable\"."), |
| 16680 | &disablelist); |
| 16681 | |
| 16682 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
| 16683 | Delete some breakpoints or auto-display expressions.\n\ |
| 16684 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16685 | To delete all breakpoints, give no argument.\n\ |
| 16686 | \n\ |
| 16687 | Also a prefix command for deletion of other GDB objects.\n\ |
| 16688 | The \"unset\" command is also an alias for \"delete\"."), |
| 16689 | &deletelist, "delete ", 1, &cmdlist); |
| 16690 | add_com_alias ("d", "delete", class_breakpoint, 1); |
| 16691 | add_com_alias ("del", "delete", class_breakpoint, 1); |
| 16692 | if (xdb_commands) |
| 16693 | add_com ("db", class_breakpoint, delete_command, _("\ |
| 16694 | Delete some breakpoints.\n\ |
| 16695 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16696 | To delete all breakpoints, give no argument.\n")); |
| 16697 | |
| 16698 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
| 16699 | Delete some breakpoints or auto-display expressions.\n\ |
| 16700 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16701 | To delete all breakpoints, give no argument.\n\ |
| 16702 | This command may be abbreviated \"delete\"."), |
| 16703 | &deletelist); |
| 16704 | |
| 16705 | add_com ("clear", class_breakpoint, clear_command, _("\ |
| 16706 | Clear breakpoint at specified line or function.\n\ |
| 16707 | Argument may be line number, function name, or \"*\" and an address.\n\ |
| 16708 | If line number is specified, all breakpoints in that line are cleared.\n\ |
| 16709 | If function is specified, breakpoints at beginning of function are cleared.\n\ |
| 16710 | If an address is specified, breakpoints at that address are cleared.\n\ |
| 16711 | \n\ |
| 16712 | With no argument, clears all breakpoints in the line that the selected frame\n\ |
| 16713 | is executing in.\n\ |
| 16714 | \n\ |
| 16715 | See also the \"delete\" command which clears breakpoints by number.")); |
| 16716 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
| 16717 | |
| 16718 | c = add_com ("break", class_breakpoint, break_command, _("\ |
| 16719 | Set breakpoint at specified line or function.\n" |
| 16720 | BREAK_ARGS_HELP ("break"))); |
| 16721 | set_cmd_completer (c, location_completer); |
| 16722 | |
| 16723 | add_com_alias ("b", "break", class_run, 1); |
| 16724 | add_com_alias ("br", "break", class_run, 1); |
| 16725 | add_com_alias ("bre", "break", class_run, 1); |
| 16726 | add_com_alias ("brea", "break", class_run, 1); |
| 16727 | |
| 16728 | if (xdb_commands) |
| 16729 | add_com_alias ("ba", "break", class_breakpoint, 1); |
| 16730 | |
| 16731 | if (dbx_commands) |
| 16732 | { |
| 16733 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
| 16734 | Break in function/address or break at a line in the current file."), |
| 16735 | &stoplist, "stop ", 1, &cmdlist); |
| 16736 | add_cmd ("in", class_breakpoint, stopin_command, |
| 16737 | _("Break in function or address."), &stoplist); |
| 16738 | add_cmd ("at", class_breakpoint, stopat_command, |
| 16739 | _("Break at a line in the current file."), &stoplist); |
| 16740 | add_com ("status", class_info, breakpoints_info, _("\ |
| 16741 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 16742 | The \"Type\" column indicates one of:\n\ |
| 16743 | \tbreakpoint - normal breakpoint\n\ |
| 16744 | \twatchpoint - watchpoint\n\ |
| 16745 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 16746 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 16747 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 16748 | address and file/line number respectively.\n\ |
| 16749 | \n\ |
| 16750 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 16751 | are set to the address of the last breakpoint listed unless the command\n\ |
| 16752 | is prefixed with \"server \".\n\n\ |
| 16753 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 16754 | breakpoint set.")); |
| 16755 | } |
| 16756 | |
| 16757 | add_info ("breakpoints", breakpoints_info, _("\ |
| 16758 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
| 16759 | The \"Type\" column indicates one of:\n\ |
| 16760 | \tbreakpoint - normal breakpoint\n\ |
| 16761 | \twatchpoint - watchpoint\n\ |
| 16762 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 16763 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 16764 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 16765 | address and file/line number respectively.\n\ |
| 16766 | \n\ |
| 16767 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 16768 | are set to the address of the last breakpoint listed unless the command\n\ |
| 16769 | is prefixed with \"server \".\n\n\ |
| 16770 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 16771 | breakpoint set.")); |
| 16772 | |
| 16773 | add_info_alias ("b", "breakpoints", 1); |
| 16774 | |
| 16775 | if (xdb_commands) |
| 16776 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
| 16777 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 16778 | The \"Type\" column indicates one of:\n\ |
| 16779 | \tbreakpoint - normal breakpoint\n\ |
| 16780 | \twatchpoint - watchpoint\n\ |
| 16781 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 16782 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 16783 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 16784 | address and file/line number respectively.\n\ |
| 16785 | \n\ |
| 16786 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 16787 | are set to the address of the last breakpoint listed unless the command\n\ |
| 16788 | is prefixed with \"server \".\n\n\ |
| 16789 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 16790 | breakpoint set.")); |
| 16791 | |
| 16792 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
| 16793 | Status of all breakpoints, or breakpoint number NUMBER.\n\ |
| 16794 | The \"Type\" column indicates one of:\n\ |
| 16795 | \tbreakpoint - normal breakpoint\n\ |
| 16796 | \twatchpoint - watchpoint\n\ |
| 16797 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ |
| 16798 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ |
| 16799 | \tuntil - internal breakpoint used by the \"until\" command\n\ |
| 16800 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
| 16801 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 16802 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 16803 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 16804 | address and file/line number respectively.\n\ |
| 16805 | \n\ |
| 16806 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 16807 | are set to the address of the last breakpoint listed unless the command\n\ |
| 16808 | is prefixed with \"server \".\n\n\ |
| 16809 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 16810 | breakpoint set."), |
| 16811 | &maintenanceinfolist); |
| 16812 | |
| 16813 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
| 16814 | Set catchpoints to catch events."), |
| 16815 | &catch_cmdlist, "catch ", |
| 16816 | 0/*allow-unknown*/, &cmdlist); |
| 16817 | |
| 16818 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ |
| 16819 | Set temporary catchpoints to catch events."), |
| 16820 | &tcatch_cmdlist, "tcatch ", |
| 16821 | 0/*allow-unknown*/, &cmdlist); |
| 16822 | |
| 16823 | add_catch_command ("fork", _("Catch calls to fork."), |
| 16824 | catch_fork_command_1, |
| 16825 | NULL, |
| 16826 | (void *) (uintptr_t) catch_fork_permanent, |
| 16827 | (void *) (uintptr_t) catch_fork_temporary); |
| 16828 | add_catch_command ("vfork", _("Catch calls to vfork."), |
| 16829 | catch_fork_command_1, |
| 16830 | NULL, |
| 16831 | (void *) (uintptr_t) catch_vfork_permanent, |
| 16832 | (void *) (uintptr_t) catch_vfork_temporary); |
| 16833 | add_catch_command ("exec", _("Catch calls to exec."), |
| 16834 | catch_exec_command_1, |
| 16835 | NULL, |
| 16836 | CATCH_PERMANENT, |
| 16837 | CATCH_TEMPORARY); |
| 16838 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
| 16839 | Usage: catch load [REGEX]\n\ |
| 16840 | If REGEX is given, only stop for libraries matching the regular expression."), |
| 16841 | catch_load_command_1, |
| 16842 | NULL, |
| 16843 | CATCH_PERMANENT, |
| 16844 | CATCH_TEMPORARY); |
| 16845 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ |
| 16846 | Usage: catch unload [REGEX]\n\ |
| 16847 | If REGEX is given, only stop for libraries matching the regular expression."), |
| 16848 | catch_unload_command_1, |
| 16849 | NULL, |
| 16850 | CATCH_PERMANENT, |
| 16851 | CATCH_TEMPORARY); |
| 16852 | add_catch_command ("syscall", _("\ |
| 16853 | Catch system calls by their names and/or numbers.\n\ |
| 16854 | Arguments say which system calls to catch. If no arguments\n\ |
| 16855 | are given, every system call will be caught.\n\ |
| 16856 | Arguments, if given, should be one or more system call names\n\ |
| 16857 | (if your system supports that), or system call numbers."), |
| 16858 | catch_syscall_command_1, |
| 16859 | catch_syscall_completer, |
| 16860 | CATCH_PERMANENT, |
| 16861 | CATCH_TEMPORARY); |
| 16862 | |
| 16863 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
| 16864 | Set a watchpoint for an expression.\n\ |
| 16865 | Usage: watch [-l|-location] EXPRESSION\n\ |
| 16866 | A watchpoint stops execution of your program whenever the value of\n\ |
| 16867 | an expression changes.\n\ |
| 16868 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 16869 | the memory to which it refers.")); |
| 16870 | set_cmd_completer (c, expression_completer); |
| 16871 | |
| 16872 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
| 16873 | Set a read watchpoint for an expression.\n\ |
| 16874 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
| 16875 | A watchpoint stops execution of your program whenever the value of\n\ |
| 16876 | an expression is read.\n\ |
| 16877 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 16878 | the memory to which it refers.")); |
| 16879 | set_cmd_completer (c, expression_completer); |
| 16880 | |
| 16881 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
| 16882 | Set a watchpoint for an expression.\n\ |
| 16883 | Usage: awatch [-l|-location] EXPRESSION\n\ |
| 16884 | A watchpoint stops execution of your program whenever the value of\n\ |
| 16885 | an expression is either read or written.\n\ |
| 16886 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 16887 | the memory to which it refers.")); |
| 16888 | set_cmd_completer (c, expression_completer); |
| 16889 | |
| 16890 | add_info ("watchpoints", watchpoints_info, _("\ |
| 16891 | Status of specified watchpoints (all watchpoints if no argument).")); |
| 16892 | |
| 16893 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
| 16894 | respond to changes - contrary to the description. */ |
| 16895 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
| 16896 | &can_use_hw_watchpoints, _("\ |
| 16897 | Set debugger's willingness to use watchpoint hardware."), _("\ |
| 16898 | Show debugger's willingness to use watchpoint hardware."), _("\ |
| 16899 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
| 16900 | such is available. (However, any hardware watchpoints that were\n\ |
| 16901 | created before setting this to nonzero, will continue to use watchpoint\n\ |
| 16902 | hardware.)"), |
| 16903 | NULL, |
| 16904 | show_can_use_hw_watchpoints, |
| 16905 | &setlist, &showlist); |
| 16906 | |
| 16907 | can_use_hw_watchpoints = 1; |
| 16908 | |
| 16909 | /* Tracepoint manipulation commands. */ |
| 16910 | |
| 16911 | c = add_com ("trace", class_breakpoint, trace_command, _("\ |
| 16912 | Set a tracepoint at specified line or function.\n\ |
| 16913 | \n" |
| 16914 | BREAK_ARGS_HELP ("trace") "\n\ |
| 16915 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 16916 | set_cmd_completer (c, location_completer); |
| 16917 | |
| 16918 | add_com_alias ("tp", "trace", class_alias, 0); |
| 16919 | add_com_alias ("tr", "trace", class_alias, 1); |
| 16920 | add_com_alias ("tra", "trace", class_alias, 1); |
| 16921 | add_com_alias ("trac", "trace", class_alias, 1); |
| 16922 | |
| 16923 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
| 16924 | Set a fast tracepoint at specified line or function.\n\ |
| 16925 | \n" |
| 16926 | BREAK_ARGS_HELP ("ftrace") "\n\ |
| 16927 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 16928 | set_cmd_completer (c, location_completer); |
| 16929 | |
| 16930 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
| 16931 | Set a static tracepoint at specified line, function or marker.\n\ |
| 16932 | \n\ |
| 16933 | strace [LOCATION] [if CONDITION]\n\ |
| 16934 | LOCATION may be a line number, function name, \"*\" and an address,\n\ |
| 16935 | or -m MARKER_ID.\n\ |
| 16936 | If a line number is specified, probe the marker at start of code\n\ |
| 16937 | for that line. If a function is specified, probe the marker at start\n\ |
| 16938 | of code for that function. If an address is specified, probe the marker\n\ |
| 16939 | at that exact address. If a marker id is specified, probe the marker\n\ |
| 16940 | with that name. With no LOCATION, uses current execution address of\n\ |
| 16941 | the selected stack frame.\n\ |
| 16942 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
| 16943 | This collects arbitrary user data passed in the probe point call to the\n\ |
| 16944 | tracing library. You can inspect it when analyzing the trace buffer,\n\ |
| 16945 | by printing the $_sdata variable like any other convenience variable.\n\ |
| 16946 | \n\ |
| 16947 | CONDITION is a boolean expression.\n\ |
| 16948 | \n\ |
| 16949 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
| 16950 | conditions are different.\n\ |
| 16951 | \n\ |
| 16952 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ |
| 16953 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 16954 | set_cmd_completer (c, location_completer); |
| 16955 | |
| 16956 | add_info ("tracepoints", tracepoints_info, _("\ |
| 16957 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
| 16958 | Convenience variable \"$tpnum\" contains the number of the\n\ |
| 16959 | last tracepoint set.")); |
| 16960 | |
| 16961 | add_info_alias ("tp", "tracepoints", 1); |
| 16962 | |
| 16963 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ |
| 16964 | Delete specified tracepoints.\n\ |
| 16965 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 16966 | No argument means delete all tracepoints."), |
| 16967 | &deletelist); |
| 16968 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
| 16969 | |
| 16970 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ |
| 16971 | Disable specified tracepoints.\n\ |
| 16972 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 16973 | No argument means disable all tracepoints."), |
| 16974 | &disablelist); |
| 16975 | deprecate_cmd (c, "disable"); |
| 16976 | |
| 16977 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ |
| 16978 | Enable specified tracepoints.\n\ |
| 16979 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 16980 | No argument means enable all tracepoints."), |
| 16981 | &enablelist); |
| 16982 | deprecate_cmd (c, "enable"); |
| 16983 | |
| 16984 | add_com ("passcount", class_trace, trace_pass_command, _("\ |
| 16985 | Set the passcount for a tracepoint.\n\ |
| 16986 | The trace will end when the tracepoint has been passed 'count' times.\n\ |
| 16987 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ |
| 16988 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); |
| 16989 | |
| 16990 | add_prefix_cmd ("save", class_breakpoint, save_command, |
| 16991 | _("Save breakpoint definitions as a script."), |
| 16992 | &save_cmdlist, "save ", |
| 16993 | 0/*allow-unknown*/, &cmdlist); |
| 16994 | |
| 16995 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ |
| 16996 | Save current breakpoint definitions as a script.\n\ |
| 16997 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
| 16998 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
| 16999 | session to restore them."), |
| 17000 | &save_cmdlist); |
| 17001 | set_cmd_completer (c, filename_completer); |
| 17002 | |
| 17003 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ |
| 17004 | Save current tracepoint definitions as a script.\n\ |
| 17005 | Use the 'source' command in another debug session to restore them."), |
| 17006 | &save_cmdlist); |
| 17007 | set_cmd_completer (c, filename_completer); |
| 17008 | |
| 17009 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
| 17010 | deprecate_cmd (c, "save tracepoints"); |
| 17011 | |
| 17012 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
| 17013 | Breakpoint specific settings\n\ |
| 17014 | Configure various breakpoint-specific variables such as\n\ |
| 17015 | pending breakpoint behavior"), |
| 17016 | &breakpoint_set_cmdlist, "set breakpoint ", |
| 17017 | 0/*allow-unknown*/, &setlist); |
| 17018 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
| 17019 | Breakpoint specific settings\n\ |
| 17020 | Configure various breakpoint-specific variables such as\n\ |
| 17021 | pending breakpoint behavior"), |
| 17022 | &breakpoint_show_cmdlist, "show breakpoint ", |
| 17023 | 0/*allow-unknown*/, &showlist); |
| 17024 | |
| 17025 | add_setshow_auto_boolean_cmd ("pending", no_class, |
| 17026 | &pending_break_support, _("\ |
| 17027 | Set debugger's behavior regarding pending breakpoints."), _("\ |
| 17028 | Show debugger's behavior regarding pending breakpoints."), _("\ |
| 17029 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
| 17030 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ |
| 17031 | an error. If auto, an unrecognized breakpoint location results in a\n\ |
| 17032 | user-query to see if a pending breakpoint should be created."), |
| 17033 | NULL, |
| 17034 | show_pending_break_support, |
| 17035 | &breakpoint_set_cmdlist, |
| 17036 | &breakpoint_show_cmdlist); |
| 17037 | |
| 17038 | pending_break_support = AUTO_BOOLEAN_AUTO; |
| 17039 | |
| 17040 | add_setshow_boolean_cmd ("auto-hw", no_class, |
| 17041 | &automatic_hardware_breakpoints, _("\ |
| 17042 | Set automatic usage of hardware breakpoints."), _("\ |
| 17043 | Show automatic usage of hardware breakpoints."), _("\ |
| 17044 | If set, the debugger will automatically use hardware breakpoints for\n\ |
| 17045 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ |
| 17046 | a warning will be emitted for such breakpoints."), |
| 17047 | NULL, |
| 17048 | show_automatic_hardware_breakpoints, |
| 17049 | &breakpoint_set_cmdlist, |
| 17050 | &breakpoint_show_cmdlist); |
| 17051 | |
| 17052 | add_setshow_boolean_cmd ("always-inserted", class_support, |
| 17053 | &always_inserted_mode, _("\ |
| 17054 | Set mode for inserting breakpoints."), _("\ |
| 17055 | Show mode for inserting breakpoints."), _("\ |
| 17056 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
| 17057 | they're created, kept inserted even when execution stops, and removed\n\ |
| 17058 | only when the user deletes them. When this mode is off (the default),\n\ |
| 17059 | breakpoints are inserted only when execution continues, and removed\n\ |
| 17060 | when execution stops."), |
| 17061 | NULL, |
| 17062 | &show_always_inserted_mode, |
| 17063 | &breakpoint_set_cmdlist, |
| 17064 | &breakpoint_show_cmdlist); |
| 17065 | |
| 17066 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
| 17067 | condition_evaluation_enums, |
| 17068 | &condition_evaluation_mode_1, _("\ |
| 17069 | Set mode of breakpoint condition evaluation."), _("\ |
| 17070 | Show mode of breakpoint condition evaluation."), _("\ |
| 17071 | When this is set to \"host\", breakpoint conditions will be\n\ |
| 17072 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
| 17073 | breakpoint conditions will be downloaded to the target (if the target\n\ |
| 17074 | supports such feature) and conditions will be evaluated on the target's side.\n\ |
| 17075 | If this is set to \"auto\" (default), this will be automatically set to\n\ |
| 17076 | \"target\" if it supports condition evaluation, otherwise it will\n\ |
| 17077 | be set to \"gdb\""), |
| 17078 | &set_condition_evaluation_mode, |
| 17079 | &show_condition_evaluation_mode, |
| 17080 | &breakpoint_set_cmdlist, |
| 17081 | &breakpoint_show_cmdlist); |
| 17082 | |
| 17083 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
| 17084 | Set a breakpoint for an address range.\n\ |
| 17085 | break-range START-LOCATION, END-LOCATION\n\ |
| 17086 | where START-LOCATION and END-LOCATION can be one of the following:\n\ |
| 17087 | LINENUM, for that line in the current file,\n\ |
| 17088 | FILE:LINENUM, for that line in that file,\n\ |
| 17089 | +OFFSET, for that number of lines after the current line\n\ |
| 17090 | or the start of the range\n\ |
| 17091 | FUNCTION, for the first line in that function,\n\ |
| 17092 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ |
| 17093 | *ADDRESS, for the instruction at that address.\n\ |
| 17094 | \n\ |
| 17095 | The breakpoint will stop execution of the inferior whenever it executes\n\ |
| 17096 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ |
| 17097 | range (including START-LOCATION and END-LOCATION).")); |
| 17098 | |
| 17099 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
| 17100 | Set a dynamic printf at specified line or function.\n\ |
| 17101 | dprintf location,format string,arg1,arg2,...\n\ |
| 17102 | location may be a line number, function name, or \"*\" and an address.\n\ |
| 17103 | If a line number is specified, break at start of code for that line.\n\ |
| 17104 | If a function is specified, break at start of code for that function.")); |
| 17105 | set_cmd_completer (c, location_completer); |
| 17106 | |
| 17107 | add_setshow_enum_cmd ("dprintf-style", class_support, |
| 17108 | dprintf_style_enums, &dprintf_style, _("\ |
| 17109 | Set the style of usage for dynamic printf."), _("\ |
| 17110 | Show the style of usage for dynamic printf."), _("\ |
| 17111 | This setting chooses how GDB will do a dynamic printf.\n\ |
| 17112 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ |
| 17113 | console, as with the \"printf\" command.\n\ |
| 17114 | If the value is \"call\", the print is done by calling a function in your\n\ |
| 17115 | program; by default printf(), but you can choose a different function or\n\ |
| 17116 | output stream by setting dprintf-function and dprintf-channel."), |
| 17117 | update_dprintf_commands, NULL, |
| 17118 | &setlist, &showlist); |
| 17119 | |
| 17120 | dprintf_function = xstrdup ("printf"); |
| 17121 | add_setshow_string_cmd ("dprintf-function", class_support, |
| 17122 | &dprintf_function, _("\ |
| 17123 | Set the function to use for dynamic printf"), _("\ |
| 17124 | Show the function to use for dynamic printf"), NULL, |
| 17125 | update_dprintf_commands, NULL, |
| 17126 | &setlist, &showlist); |
| 17127 | |
| 17128 | dprintf_channel = xstrdup (""); |
| 17129 | add_setshow_string_cmd ("dprintf-channel", class_support, |
| 17130 | &dprintf_channel, _("\ |
| 17131 | Set the channel to use for dynamic printf"), _("\ |
| 17132 | Show the channel to use for dynamic printf"), NULL, |
| 17133 | update_dprintf_commands, NULL, |
| 17134 | &setlist, &showlist); |
| 17135 | |
| 17136 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
| 17137 | &disconnected_dprintf, _("\ |
| 17138 | Set whether dprintf continues after GDB disconnects."), _("\ |
| 17139 | Show whether dprintf continues after GDB disconnects."), _("\ |
| 17140 | Use this to let dprintf commands continue to hit and produce output\n\ |
| 17141 | even if GDB disconnects or detaches from the target."), |
| 17142 | NULL, |
| 17143 | NULL, |
| 17144 | &setlist, &showlist); |
| 17145 | |
| 17146 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ |
| 17147 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ |
| 17148 | (target agent only) This is useful for formatted output in user-defined commands.")); |
| 17149 | |
| 17150 | automatic_hardware_breakpoints = 1; |
| 17151 | |
| 17152 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); |
| 17153 | observer_attach_thread_exit (remove_threaded_breakpoints); |
| 17154 | } |