| 1 | /* Everything about breakpoints, for GDB. |
| 2 | |
| 3 | Copyright (C) 1986-2015 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 "memattr.h" |
| 55 | #include "ada-lang.h" |
| 56 | #include "top.h" |
| 57 | #include "valprint.h" |
| 58 | #include "jit.h" |
| 59 | #include "parser-defs.h" |
| 60 | #include "gdb_regex.h" |
| 61 | #include "probe.h" |
| 62 | #include "cli/cli-utils.h" |
| 63 | #include "continuations.h" |
| 64 | #include "stack.h" |
| 65 | #include "skip.h" |
| 66 | #include "ax-gdb.h" |
| 67 | #include "dummy-frame.h" |
| 68 | #include "interps.h" |
| 69 | #include "format.h" |
| 70 | #include "location.h" |
| 71 | |
| 72 | /* readline include files */ |
| 73 | #include "readline/readline.h" |
| 74 | #include "readline/history.h" |
| 75 | |
| 76 | /* readline defines this. */ |
| 77 | #undef savestring |
| 78 | |
| 79 | #include "mi/mi-common.h" |
| 80 | #include "extension.h" |
| 81 | |
| 82 | /* Enums for exception-handling support. */ |
| 83 | enum exception_event_kind |
| 84 | { |
| 85 | EX_EVENT_THROW, |
| 86 | EX_EVENT_RETHROW, |
| 87 | EX_EVENT_CATCH |
| 88 | }; |
| 89 | |
| 90 | /* Prototypes for local functions. */ |
| 91 | |
| 92 | static void enable_delete_command (char *, int); |
| 93 | |
| 94 | static void enable_once_command (char *, int); |
| 95 | |
| 96 | static void enable_count_command (char *, int); |
| 97 | |
| 98 | static void disable_command (char *, int); |
| 99 | |
| 100 | static void enable_command (char *, int); |
| 101 | |
| 102 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
| 103 | void *), |
| 104 | void *); |
| 105 | |
| 106 | static void ignore_command (char *, int); |
| 107 | |
| 108 | static int breakpoint_re_set_one (void *); |
| 109 | |
| 110 | static void breakpoint_re_set_default (struct breakpoint *); |
| 111 | |
| 112 | static void |
| 113 | create_sals_from_location_default (const struct event_location *location, |
| 114 | struct linespec_result *canonical, |
| 115 | enum bptype type_wanted); |
| 116 | |
| 117 | static void create_breakpoints_sal_default (struct gdbarch *, |
| 118 | struct linespec_result *, |
| 119 | char *, char *, enum bptype, |
| 120 | enum bpdisp, int, int, |
| 121 | int, |
| 122 | const struct breakpoint_ops *, |
| 123 | int, int, int, unsigned); |
| 124 | |
| 125 | static void decode_location_default (struct breakpoint *b, |
| 126 | const struct event_location *location, |
| 127 | struct symtabs_and_lines *sals); |
| 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 free_bp_location (struct bp_location *loc); |
| 230 | static void incref_bp_location (struct bp_location *loc); |
| 231 | static void decref_bp_location (struct bp_location **loc); |
| 232 | |
| 233 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
| 234 | |
| 235 | /* update_global_location_list's modes of operation wrt to whether to |
| 236 | insert locations now. */ |
| 237 | enum ugll_insert_mode |
| 238 | { |
| 239 | /* Don't insert any breakpoint locations into the inferior, only |
| 240 | remove already-inserted locations that no longer should be |
| 241 | inserted. Functions that delete a breakpoint or breakpoints |
| 242 | should specify this mode, so that deleting a breakpoint doesn't |
| 243 | have the side effect of inserting the locations of other |
| 244 | breakpoints that are marked not-inserted, but should_be_inserted |
| 245 | returns true on them. |
| 246 | |
| 247 | This behavior is useful is situations close to tear-down -- e.g., |
| 248 | after an exec, while the target still has execution, but |
| 249 | breakpoint shadows of the previous executable image should *NOT* |
| 250 | be restored to the new image; or before detaching, where the |
| 251 | target still has execution and wants to delete breakpoints from |
| 252 | GDB's lists, and all breakpoints had already been removed from |
| 253 | the inferior. */ |
| 254 | UGLL_DONT_INSERT, |
| 255 | |
| 256 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
| 257 | claims breakpoints should be inserted now. */ |
| 258 | UGLL_MAY_INSERT, |
| 259 | |
| 260 | /* Insert locations now, irrespective of |
| 261 | breakpoints_should_be_inserted_now. E.g., say all threads are |
| 262 | stopped right now, and the user did "continue". We need to |
| 263 | insert breakpoints _before_ resuming the target, but |
| 264 | UGLL_MAY_INSERT wouldn't insert them, because |
| 265 | breakpoints_should_be_inserted_now returns false at that point, |
| 266 | as no thread is running yet. */ |
| 267 | UGLL_INSERT |
| 268 | }; |
| 269 | |
| 270 | static void update_global_location_list (enum ugll_insert_mode); |
| 271 | |
| 272 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
| 273 | |
| 274 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
| 275 | |
| 276 | static void insert_breakpoint_locations (void); |
| 277 | |
| 278 | static void tracepoints_info (char *, int); |
| 279 | |
| 280 | static void delete_trace_command (char *, int); |
| 281 | |
| 282 | static void enable_trace_command (char *, int); |
| 283 | |
| 284 | static void disable_trace_command (char *, int); |
| 285 | |
| 286 | static void trace_pass_command (char *, int); |
| 287 | |
| 288 | static void set_tracepoint_count (int num); |
| 289 | |
| 290 | static int is_masked_watchpoint (const struct breakpoint *b); |
| 291 | |
| 292 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
| 293 | |
| 294 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
| 295 | otherwise. */ |
| 296 | |
| 297 | static int strace_marker_p (struct breakpoint *b); |
| 298 | |
| 299 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
| 300 | that are implemented on top of software or hardware breakpoints |
| 301 | (user breakpoints, internal and momentary breakpoints, etc.). */ |
| 302 | static struct breakpoint_ops bkpt_base_breakpoint_ops; |
| 303 | |
| 304 | /* Internal breakpoints class type. */ |
| 305 | static struct breakpoint_ops internal_breakpoint_ops; |
| 306 | |
| 307 | /* Momentary breakpoints class type. */ |
| 308 | static struct breakpoint_ops momentary_breakpoint_ops; |
| 309 | |
| 310 | /* Momentary breakpoints for bp_longjmp and bp_exception class type. */ |
| 311 | static struct breakpoint_ops longjmp_breakpoint_ops; |
| 312 | |
| 313 | /* The breakpoint_ops structure to be used in regular user created |
| 314 | breakpoints. */ |
| 315 | struct breakpoint_ops bkpt_breakpoint_ops; |
| 316 | |
| 317 | /* Breakpoints set on probes. */ |
| 318 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; |
| 319 | |
| 320 | /* Dynamic printf class type. */ |
| 321 | struct breakpoint_ops dprintf_breakpoint_ops; |
| 322 | |
| 323 | /* The style in which to perform a dynamic printf. This is a user |
| 324 | option because different output options have different tradeoffs; |
| 325 | if GDB does the printing, there is better error handling if there |
| 326 | is a problem with any of the arguments, but using an inferior |
| 327 | function lets you have special-purpose printers and sending of |
| 328 | output to the same place as compiled-in print functions. */ |
| 329 | |
| 330 | static const char dprintf_style_gdb[] = "gdb"; |
| 331 | static const char dprintf_style_call[] = "call"; |
| 332 | static const char dprintf_style_agent[] = "agent"; |
| 333 | static const char *const dprintf_style_enums[] = { |
| 334 | dprintf_style_gdb, |
| 335 | dprintf_style_call, |
| 336 | dprintf_style_agent, |
| 337 | NULL |
| 338 | }; |
| 339 | static const char *dprintf_style = dprintf_style_gdb; |
| 340 | |
| 341 | /* The function to use for dynamic printf if the preferred style is to |
| 342 | call into the inferior. The value is simply a string that is |
| 343 | copied into the command, so it can be anything that GDB can |
| 344 | evaluate to a callable address, not necessarily a function name. */ |
| 345 | |
| 346 | static char *dprintf_function = ""; |
| 347 | |
| 348 | /* The channel to use for dynamic printf if the preferred style is to |
| 349 | call into the inferior; if a nonempty string, it will be passed to |
| 350 | the call as the first argument, with the format string as the |
| 351 | second. As with the dprintf function, this can be anything that |
| 352 | GDB knows how to evaluate, so in addition to common choices like |
| 353 | "stderr", this could be an app-specific expression like |
| 354 | "mystreams[curlogger]". */ |
| 355 | |
| 356 | static char *dprintf_channel = ""; |
| 357 | |
| 358 | /* True if dprintf commands should continue to operate even if GDB |
| 359 | has disconnected. */ |
| 360 | static int disconnected_dprintf = 1; |
| 361 | |
| 362 | /* A reference-counted struct command_line. This lets multiple |
| 363 | breakpoints share a single command list. */ |
| 364 | struct counted_command_line |
| 365 | { |
| 366 | /* The reference count. */ |
| 367 | int refc; |
| 368 | |
| 369 | /* The command list. */ |
| 370 | struct command_line *commands; |
| 371 | }; |
| 372 | |
| 373 | struct command_line * |
| 374 | breakpoint_commands (struct breakpoint *b) |
| 375 | { |
| 376 | return b->commands ? b->commands->commands : NULL; |
| 377 | } |
| 378 | |
| 379 | /* Flag indicating that a command has proceeded the inferior past the |
| 380 | current breakpoint. */ |
| 381 | |
| 382 | static int breakpoint_proceeded; |
| 383 | |
| 384 | const char * |
| 385 | bpdisp_text (enum bpdisp disp) |
| 386 | { |
| 387 | /* NOTE: the following values are a part of MI protocol and |
| 388 | represent values of 'disp' field returned when inferior stops at |
| 389 | a breakpoint. */ |
| 390 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
| 391 | |
| 392 | return bpdisps[(int) disp]; |
| 393 | } |
| 394 | |
| 395 | /* Prototypes for exported functions. */ |
| 396 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
| 397 | if such is available. */ |
| 398 | static int can_use_hw_watchpoints; |
| 399 | |
| 400 | static void |
| 401 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, |
| 402 | struct cmd_list_element *c, |
| 403 | const char *value) |
| 404 | { |
| 405 | fprintf_filtered (file, |
| 406 | _("Debugger's willingness to use " |
| 407 | "watchpoint hardware is %s.\n"), |
| 408 | value); |
| 409 | } |
| 410 | |
| 411 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
| 412 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints |
| 413 | for unrecognized breakpoint locations. |
| 414 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
| 415 | static enum auto_boolean pending_break_support; |
| 416 | static void |
| 417 | show_pending_break_support (struct ui_file *file, int from_tty, |
| 418 | struct cmd_list_element *c, |
| 419 | const char *value) |
| 420 | { |
| 421 | fprintf_filtered (file, |
| 422 | _("Debugger's behavior regarding " |
| 423 | "pending breakpoints is %s.\n"), |
| 424 | value); |
| 425 | } |
| 426 | |
| 427 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
| 428 | set with "break" but falling in read-only memory. |
| 429 | If 0, gdb will warn about such breakpoints, but won't automatically |
| 430 | use hardware breakpoints. */ |
| 431 | static int automatic_hardware_breakpoints; |
| 432 | static void |
| 433 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, |
| 434 | struct cmd_list_element *c, |
| 435 | const char *value) |
| 436 | { |
| 437 | fprintf_filtered (file, |
| 438 | _("Automatic usage of hardware breakpoints is %s.\n"), |
| 439 | value); |
| 440 | } |
| 441 | |
| 442 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
| 443 | stopped, and immediately inserts any new breakpoints as soon as |
| 444 | they're created. If off (default), GDB keeps breakpoints off of |
| 445 | the target as long as possible. That is, it delays inserting |
| 446 | breakpoints until the next resume, and removes them again when the |
| 447 | target fully stops. This is a bit safer in case GDB crashes while |
| 448 | processing user input. */ |
| 449 | static int always_inserted_mode = 0; |
| 450 | |
| 451 | static void |
| 452 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
| 453 | struct cmd_list_element *c, const char *value) |
| 454 | { |
| 455 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
| 456 | value); |
| 457 | } |
| 458 | |
| 459 | /* See breakpoint.h. */ |
| 460 | |
| 461 | int |
| 462 | breakpoints_should_be_inserted_now (void) |
| 463 | { |
| 464 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
| 465 | { |
| 466 | /* If breakpoints are global, they should be inserted even if no |
| 467 | thread under gdb's control is running, or even if there are |
| 468 | no threads under GDB's control yet. */ |
| 469 | return 1; |
| 470 | } |
| 471 | else if (target_has_execution) |
| 472 | { |
| 473 | struct thread_info *tp; |
| 474 | |
| 475 | if (always_inserted_mode) |
| 476 | { |
| 477 | /* The user wants breakpoints inserted even if all threads |
| 478 | are stopped. */ |
| 479 | return 1; |
| 480 | } |
| 481 | |
| 482 | if (threads_are_executing ()) |
| 483 | return 1; |
| 484 | |
| 485 | /* Don't remove breakpoints yet if, even though all threads are |
| 486 | stopped, we still have events to process. */ |
| 487 | ALL_NON_EXITED_THREADS (tp) |
| 488 | if (tp->resumed |
| 489 | && tp->suspend.waitstatus_pending_p) |
| 490 | return 1; |
| 491 | } |
| 492 | return 0; |
| 493 | } |
| 494 | |
| 495 | static const char condition_evaluation_both[] = "host or target"; |
| 496 | |
| 497 | /* Modes for breakpoint condition evaluation. */ |
| 498 | static const char condition_evaluation_auto[] = "auto"; |
| 499 | static const char condition_evaluation_host[] = "host"; |
| 500 | static const char condition_evaluation_target[] = "target"; |
| 501 | static const char *const condition_evaluation_enums[] = { |
| 502 | condition_evaluation_auto, |
| 503 | condition_evaluation_host, |
| 504 | condition_evaluation_target, |
| 505 | NULL |
| 506 | }; |
| 507 | |
| 508 | /* Global that holds the current mode for breakpoint condition evaluation. */ |
| 509 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; |
| 510 | |
| 511 | /* Global that we use to display information to the user (gets its value from |
| 512 | condition_evaluation_mode_1. */ |
| 513 | static const char *condition_evaluation_mode = condition_evaluation_auto; |
| 514 | |
| 515 | /* Translate a condition evaluation mode MODE into either "host" |
| 516 | or "target". This is used mostly to translate from "auto" to the |
| 517 | real setting that is being used. It returns the translated |
| 518 | evaluation mode. */ |
| 519 | |
| 520 | static const char * |
| 521 | translate_condition_evaluation_mode (const char *mode) |
| 522 | { |
| 523 | if (mode == condition_evaluation_auto) |
| 524 | { |
| 525 | if (target_supports_evaluation_of_breakpoint_conditions ()) |
| 526 | return condition_evaluation_target; |
| 527 | else |
| 528 | return condition_evaluation_host; |
| 529 | } |
| 530 | else |
| 531 | return mode; |
| 532 | } |
| 533 | |
| 534 | /* Discovers what condition_evaluation_auto translates to. */ |
| 535 | |
| 536 | static const char * |
| 537 | breakpoint_condition_evaluation_mode (void) |
| 538 | { |
| 539 | return translate_condition_evaluation_mode (condition_evaluation_mode); |
| 540 | } |
| 541 | |
| 542 | /* Return true if GDB should evaluate breakpoint conditions or false |
| 543 | otherwise. */ |
| 544 | |
| 545 | static int |
| 546 | gdb_evaluates_breakpoint_condition_p (void) |
| 547 | { |
| 548 | const char *mode = breakpoint_condition_evaluation_mode (); |
| 549 | |
| 550 | return (mode == condition_evaluation_host); |
| 551 | } |
| 552 | |
| 553 | void _initialize_breakpoint (void); |
| 554 | |
| 555 | /* Are we executing breakpoint commands? */ |
| 556 | static int executing_breakpoint_commands; |
| 557 | |
| 558 | /* Are overlay event breakpoints enabled? */ |
| 559 | static int overlay_events_enabled; |
| 560 | |
| 561 | /* See description in breakpoint.h. */ |
| 562 | int target_exact_watchpoints = 0; |
| 563 | |
| 564 | /* Walk the following statement or block through all breakpoints. |
| 565 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
| 566 | current breakpoint. */ |
| 567 | |
| 568 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
| 569 | |
| 570 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
| 571 | for (B = breakpoint_chain; \ |
| 572 | B ? (TMP=B->next, 1): 0; \ |
| 573 | B = TMP) |
| 574 | |
| 575 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
| 576 | not provided so update_global_location_list must not be called |
| 577 | while executing the block of ALL_BP_LOCATIONS. */ |
| 578 | |
| 579 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
| 580 | for (BP_TMP = bp_location; \ |
| 581 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ |
| 582 | BP_TMP++) |
| 583 | |
| 584 | /* Iterates through locations with address ADDRESS for the currently selected |
| 585 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points |
| 586 | to where the loop should start from. |
| 587 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the |
| 588 | appropriate location to start with. */ |
| 589 | |
| 590 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ |
| 591 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ |
| 592 | BP_LOCP_TMP = BP_LOCP_START; \ |
| 593 | BP_LOCP_START \ |
| 594 | && (BP_LOCP_TMP < bp_location + bp_location_count \ |
| 595 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
| 596 | BP_LOCP_TMP++) |
| 597 | |
| 598 | /* Iterator for tracepoints only. */ |
| 599 | |
| 600 | #define ALL_TRACEPOINTS(B) \ |
| 601 | for (B = breakpoint_chain; B; B = B->next) \ |
| 602 | if (is_tracepoint (B)) |
| 603 | |
| 604 | /* Chains of all breakpoints defined. */ |
| 605 | |
| 606 | struct breakpoint *breakpoint_chain; |
| 607 | |
| 608 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
| 609 | |
| 610 | static struct bp_location **bp_location; |
| 611 | |
| 612 | /* Number of elements of BP_LOCATION. */ |
| 613 | |
| 614 | static unsigned bp_location_count; |
| 615 | |
| 616 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
| 617 | ADDRESS for the current elements of BP_LOCATION which get a valid |
| 618 | result from bp_location_has_shadow. You can use it for roughly |
| 619 | limiting the subrange of BP_LOCATION to scan for shadow bytes for |
| 620 | an address you need to read. */ |
| 621 | |
| 622 | static CORE_ADDR bp_location_placed_address_before_address_max; |
| 623 | |
| 624 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
| 625 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of |
| 626 | BP_LOCATION which get a valid result from bp_location_has_shadow. |
| 627 | You can use it for roughly limiting the subrange of BP_LOCATION to |
| 628 | scan for shadow bytes for an address you need to read. */ |
| 629 | |
| 630 | static CORE_ADDR bp_location_shadow_len_after_address_max; |
| 631 | |
| 632 | /* The locations that no longer correspond to any breakpoint, unlinked |
| 633 | from bp_location array, but for which a hit may still be reported |
| 634 | by a target. */ |
| 635 | VEC(bp_location_p) *moribund_locations = NULL; |
| 636 | |
| 637 | /* Number of last breakpoint made. */ |
| 638 | |
| 639 | static int breakpoint_count; |
| 640 | |
| 641 | /* The value of `breakpoint_count' before the last command that |
| 642 | created breakpoints. If the last (break-like) command created more |
| 643 | than one breakpoint, then the difference between BREAKPOINT_COUNT |
| 644 | and PREV_BREAKPOINT_COUNT is more than one. */ |
| 645 | static int prev_breakpoint_count; |
| 646 | |
| 647 | /* Number of last tracepoint made. */ |
| 648 | |
| 649 | static int tracepoint_count; |
| 650 | |
| 651 | static struct cmd_list_element *breakpoint_set_cmdlist; |
| 652 | static struct cmd_list_element *breakpoint_show_cmdlist; |
| 653 | struct cmd_list_element *save_cmdlist; |
| 654 | |
| 655 | /* See declaration at breakpoint.h. */ |
| 656 | |
| 657 | struct breakpoint * |
| 658 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), |
| 659 | void *user_data) |
| 660 | { |
| 661 | struct breakpoint *b = NULL; |
| 662 | |
| 663 | ALL_BREAKPOINTS (b) |
| 664 | { |
| 665 | if (func (b, user_data) != 0) |
| 666 | break; |
| 667 | } |
| 668 | |
| 669 | return b; |
| 670 | } |
| 671 | |
| 672 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
| 673 | static int |
| 674 | breakpoint_enabled (struct breakpoint *b) |
| 675 | { |
| 676 | return (b->enable_state == bp_enabled); |
| 677 | } |
| 678 | |
| 679 | /* Set breakpoint count to NUM. */ |
| 680 | |
| 681 | static void |
| 682 | set_breakpoint_count (int num) |
| 683 | { |
| 684 | prev_breakpoint_count = breakpoint_count; |
| 685 | breakpoint_count = num; |
| 686 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
| 687 | } |
| 688 | |
| 689 | /* Used by `start_rbreak_breakpoints' below, to record the current |
| 690 | breakpoint count before "rbreak" creates any breakpoint. */ |
| 691 | static int rbreak_start_breakpoint_count; |
| 692 | |
| 693 | /* Called at the start an "rbreak" command to record the first |
| 694 | breakpoint made. */ |
| 695 | |
| 696 | void |
| 697 | start_rbreak_breakpoints (void) |
| 698 | { |
| 699 | rbreak_start_breakpoint_count = breakpoint_count; |
| 700 | } |
| 701 | |
| 702 | /* Called at the end of an "rbreak" command to record the last |
| 703 | breakpoint made. */ |
| 704 | |
| 705 | void |
| 706 | end_rbreak_breakpoints (void) |
| 707 | { |
| 708 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
| 709 | } |
| 710 | |
| 711 | /* Used in run_command to zero the hit count when a new run starts. */ |
| 712 | |
| 713 | void |
| 714 | clear_breakpoint_hit_counts (void) |
| 715 | { |
| 716 | struct breakpoint *b; |
| 717 | |
| 718 | ALL_BREAKPOINTS (b) |
| 719 | b->hit_count = 0; |
| 720 | } |
| 721 | |
| 722 | /* Allocate a new counted_command_line with reference count of 1. |
| 723 | The new structure owns COMMANDS. */ |
| 724 | |
| 725 | static struct counted_command_line * |
| 726 | alloc_counted_command_line (struct command_line *commands) |
| 727 | { |
| 728 | struct counted_command_line *result |
| 729 | = xmalloc (sizeof (struct counted_command_line)); |
| 730 | |
| 731 | result->refc = 1; |
| 732 | result->commands = commands; |
| 733 | return result; |
| 734 | } |
| 735 | |
| 736 | /* Increment reference count. This does nothing if CMD is NULL. */ |
| 737 | |
| 738 | static void |
| 739 | incref_counted_command_line (struct counted_command_line *cmd) |
| 740 | { |
| 741 | if (cmd) |
| 742 | ++cmd->refc; |
| 743 | } |
| 744 | |
| 745 | /* Decrement reference count. If the reference count reaches 0, |
| 746 | destroy the counted_command_line. Sets *CMDP to NULL. This does |
| 747 | nothing if *CMDP is NULL. */ |
| 748 | |
| 749 | static void |
| 750 | decref_counted_command_line (struct counted_command_line **cmdp) |
| 751 | { |
| 752 | if (*cmdp) |
| 753 | { |
| 754 | if (--(*cmdp)->refc == 0) |
| 755 | { |
| 756 | free_command_lines (&(*cmdp)->commands); |
| 757 | xfree (*cmdp); |
| 758 | } |
| 759 | *cmdp = NULL; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | /* A cleanup function that calls decref_counted_command_line. */ |
| 764 | |
| 765 | static void |
| 766 | do_cleanup_counted_command_line (void *arg) |
| 767 | { |
| 768 | decref_counted_command_line (arg); |
| 769 | } |
| 770 | |
| 771 | /* Create a cleanup that calls decref_counted_command_line on the |
| 772 | argument. */ |
| 773 | |
| 774 | static struct cleanup * |
| 775 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) |
| 776 | { |
| 777 | return make_cleanup (do_cleanup_counted_command_line, cmdp); |
| 778 | } |
| 779 | |
| 780 | \f |
| 781 | /* Return the breakpoint with the specified number, or NULL |
| 782 | if the number does not refer to an existing breakpoint. */ |
| 783 | |
| 784 | struct breakpoint * |
| 785 | get_breakpoint (int num) |
| 786 | { |
| 787 | struct breakpoint *b; |
| 788 | |
| 789 | ALL_BREAKPOINTS (b) |
| 790 | if (b->number == num) |
| 791 | return b; |
| 792 | |
| 793 | return NULL; |
| 794 | } |
| 795 | |
| 796 | \f |
| 797 | |
| 798 | /* Mark locations as "conditions have changed" in case the target supports |
| 799 | evaluating conditions on its side. */ |
| 800 | |
| 801 | static void |
| 802 | mark_breakpoint_modified (struct breakpoint *b) |
| 803 | { |
| 804 | struct bp_location *loc; |
| 805 | |
| 806 | /* This is only meaningful if the target is |
| 807 | evaluating conditions and if the user has |
| 808 | opted for condition evaluation on the target's |
| 809 | side. */ |
| 810 | if (gdb_evaluates_breakpoint_condition_p () |
| 811 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 812 | return; |
| 813 | |
| 814 | if (!is_breakpoint (b)) |
| 815 | return; |
| 816 | |
| 817 | for (loc = b->loc; loc; loc = loc->next) |
| 818 | loc->condition_changed = condition_modified; |
| 819 | } |
| 820 | |
| 821 | /* Mark location as "conditions have changed" in case the target supports |
| 822 | evaluating conditions on its side. */ |
| 823 | |
| 824 | static void |
| 825 | mark_breakpoint_location_modified (struct bp_location *loc) |
| 826 | { |
| 827 | /* This is only meaningful if the target is |
| 828 | evaluating conditions and if the user has |
| 829 | opted for condition evaluation on the target's |
| 830 | side. */ |
| 831 | if (gdb_evaluates_breakpoint_condition_p () |
| 832 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 833 | |
| 834 | return; |
| 835 | |
| 836 | if (!is_breakpoint (loc->owner)) |
| 837 | return; |
| 838 | |
| 839 | loc->condition_changed = condition_modified; |
| 840 | } |
| 841 | |
| 842 | /* Sets the condition-evaluation mode using the static global |
| 843 | condition_evaluation_mode. */ |
| 844 | |
| 845 | static void |
| 846 | set_condition_evaluation_mode (char *args, int from_tty, |
| 847 | struct cmd_list_element *c) |
| 848 | { |
| 849 | const char *old_mode, *new_mode; |
| 850 | |
| 851 | if ((condition_evaluation_mode_1 == condition_evaluation_target) |
| 852 | && !target_supports_evaluation_of_breakpoint_conditions ()) |
| 853 | { |
| 854 | condition_evaluation_mode_1 = condition_evaluation_mode; |
| 855 | warning (_("Target does not support breakpoint condition evaluation.\n" |
| 856 | "Using host evaluation mode instead.")); |
| 857 | return; |
| 858 | } |
| 859 | |
| 860 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); |
| 861 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); |
| 862 | |
| 863 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
| 864 | settings was "auto". */ |
| 865 | condition_evaluation_mode = condition_evaluation_mode_1; |
| 866 | |
| 867 | /* Only update the mode if the user picked a different one. */ |
| 868 | if (new_mode != old_mode) |
| 869 | { |
| 870 | struct bp_location *loc, **loc_tmp; |
| 871 | /* If the user switched to a different evaluation mode, we |
| 872 | need to synch the changes with the target as follows: |
| 873 | |
| 874 | "host" -> "target": Send all (valid) conditions to the target. |
| 875 | "target" -> "host": Remove all the conditions from the target. |
| 876 | */ |
| 877 | |
| 878 | if (new_mode == condition_evaluation_target) |
| 879 | { |
| 880 | /* Mark everything modified and synch conditions with the |
| 881 | target. */ |
| 882 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 883 | mark_breakpoint_location_modified (loc); |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | /* Manually mark non-duplicate locations to synch conditions |
| 888 | with the target. We do this to remove all the conditions the |
| 889 | target knows about. */ |
| 890 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 891 | if (is_breakpoint (loc->owner) && loc->inserted) |
| 892 | loc->needs_update = 1; |
| 893 | } |
| 894 | |
| 895 | /* Do the update. */ |
| 896 | update_global_location_list (UGLL_MAY_INSERT); |
| 897 | } |
| 898 | |
| 899 | return; |
| 900 | } |
| 901 | |
| 902 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows |
| 903 | what "auto" is translating to. */ |
| 904 | |
| 905 | static void |
| 906 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, |
| 907 | struct cmd_list_element *c, const char *value) |
| 908 | { |
| 909 | if (condition_evaluation_mode == condition_evaluation_auto) |
| 910 | fprintf_filtered (file, |
| 911 | _("Breakpoint condition evaluation " |
| 912 | "mode is %s (currently %s).\n"), |
| 913 | value, |
| 914 | breakpoint_condition_evaluation_mode ()); |
| 915 | else |
| 916 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), |
| 917 | value); |
| 918 | } |
| 919 | |
| 920 | /* A comparison function for bp_location AP and BP that is used by |
| 921 | bsearch. This comparison function only cares about addresses, unlike |
| 922 | the more general bp_location_compare function. */ |
| 923 | |
| 924 | static int |
| 925 | bp_location_compare_addrs (const void *ap, const void *bp) |
| 926 | { |
| 927 | struct bp_location *a = *(void **) ap; |
| 928 | struct bp_location *b = *(void **) bp; |
| 929 | |
| 930 | if (a->address == b->address) |
| 931 | return 0; |
| 932 | else |
| 933 | return ((a->address > b->address) - (a->address < b->address)); |
| 934 | } |
| 935 | |
| 936 | /* Helper function to skip all bp_locations with addresses |
| 937 | less than ADDRESS. It returns the first bp_location that |
| 938 | is greater than or equal to ADDRESS. If none is found, just |
| 939 | return NULL. */ |
| 940 | |
| 941 | static struct bp_location ** |
| 942 | get_first_locp_gte_addr (CORE_ADDR address) |
| 943 | { |
| 944 | struct bp_location dummy_loc; |
| 945 | struct bp_location *dummy_locp = &dummy_loc; |
| 946 | struct bp_location **locp_found = NULL; |
| 947 | |
| 948 | /* Initialize the dummy location's address field. */ |
| 949 | memset (&dummy_loc, 0, sizeof (struct bp_location)); |
| 950 | dummy_loc.address = address; |
| 951 | |
| 952 | /* Find a close match to the first location at ADDRESS. */ |
| 953 | locp_found = bsearch (&dummy_locp, bp_location, bp_location_count, |
| 954 | sizeof (struct bp_location **), |
| 955 | bp_location_compare_addrs); |
| 956 | |
| 957 | /* Nothing was found, nothing left to do. */ |
| 958 | if (locp_found == NULL) |
| 959 | return NULL; |
| 960 | |
| 961 | /* We may have found a location that is at ADDRESS but is not the first in the |
| 962 | location's list. Go backwards (if possible) and locate the first one. */ |
| 963 | while ((locp_found - 1) >= bp_location |
| 964 | && (*(locp_found - 1))->address == address) |
| 965 | locp_found--; |
| 966 | |
| 967 | return locp_found; |
| 968 | } |
| 969 | |
| 970 | void |
| 971 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
| 972 | int from_tty) |
| 973 | { |
| 974 | xfree (b->cond_string); |
| 975 | b->cond_string = NULL; |
| 976 | |
| 977 | if (is_watchpoint (b)) |
| 978 | { |
| 979 | struct watchpoint *w = (struct watchpoint *) b; |
| 980 | |
| 981 | xfree (w->cond_exp); |
| 982 | w->cond_exp = NULL; |
| 983 | } |
| 984 | else |
| 985 | { |
| 986 | struct bp_location *loc; |
| 987 | |
| 988 | for (loc = b->loc; loc; loc = loc->next) |
| 989 | { |
| 990 | xfree (loc->cond); |
| 991 | loc->cond = NULL; |
| 992 | |
| 993 | /* No need to free the condition agent expression |
| 994 | bytecode (if we have one). We will handle this |
| 995 | when we go through update_global_location_list. */ |
| 996 | } |
| 997 | } |
| 998 | |
| 999 | if (*exp == 0) |
| 1000 | { |
| 1001 | if (from_tty) |
| 1002 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); |
| 1003 | } |
| 1004 | else |
| 1005 | { |
| 1006 | const char *arg = exp; |
| 1007 | |
| 1008 | /* I don't know if it matters whether this is the string the user |
| 1009 | typed in or the decompiled expression. */ |
| 1010 | b->cond_string = xstrdup (arg); |
| 1011 | b->condition_not_parsed = 0; |
| 1012 | |
| 1013 | if (is_watchpoint (b)) |
| 1014 | { |
| 1015 | struct watchpoint *w = (struct watchpoint *) b; |
| 1016 | |
| 1017 | innermost_block = NULL; |
| 1018 | arg = exp; |
| 1019 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0); |
| 1020 | if (*arg) |
| 1021 | error (_("Junk at end of expression")); |
| 1022 | w->cond_exp_valid_block = innermost_block; |
| 1023 | } |
| 1024 | else |
| 1025 | { |
| 1026 | struct bp_location *loc; |
| 1027 | |
| 1028 | for (loc = b->loc; loc; loc = loc->next) |
| 1029 | { |
| 1030 | arg = exp; |
| 1031 | loc->cond = |
| 1032 | parse_exp_1 (&arg, loc->address, |
| 1033 | block_for_pc (loc->address), 0); |
| 1034 | if (*arg) |
| 1035 | error (_("Junk at end of expression")); |
| 1036 | } |
| 1037 | } |
| 1038 | } |
| 1039 | mark_breakpoint_modified (b); |
| 1040 | |
| 1041 | observer_notify_breakpoint_modified (b); |
| 1042 | } |
| 1043 | |
| 1044 | /* Completion for the "condition" command. */ |
| 1045 | |
| 1046 | static VEC (char_ptr) * |
| 1047 | condition_completer (struct cmd_list_element *cmd, |
| 1048 | const char *text, const char *word) |
| 1049 | { |
| 1050 | const char *space; |
| 1051 | |
| 1052 | text = skip_spaces_const (text); |
| 1053 | space = skip_to_space_const (text); |
| 1054 | if (*space == '\0') |
| 1055 | { |
| 1056 | int len; |
| 1057 | struct breakpoint *b; |
| 1058 | VEC (char_ptr) *result = NULL; |
| 1059 | |
| 1060 | if (text[0] == '$') |
| 1061 | { |
| 1062 | /* We don't support completion of history indices. */ |
| 1063 | if (isdigit (text[1])) |
| 1064 | return NULL; |
| 1065 | return complete_internalvar (&text[1]); |
| 1066 | } |
| 1067 | |
| 1068 | /* We're completing the breakpoint number. */ |
| 1069 | len = strlen (text); |
| 1070 | |
| 1071 | ALL_BREAKPOINTS (b) |
| 1072 | { |
| 1073 | char number[50]; |
| 1074 | |
| 1075 | xsnprintf (number, sizeof (number), "%d", b->number); |
| 1076 | |
| 1077 | if (strncmp (number, text, len) == 0) |
| 1078 | VEC_safe_push (char_ptr, result, xstrdup (number)); |
| 1079 | } |
| 1080 | |
| 1081 | return result; |
| 1082 | } |
| 1083 | |
| 1084 | /* We're completing the expression part. */ |
| 1085 | text = skip_spaces_const (space); |
| 1086 | return expression_completer (cmd, text, word); |
| 1087 | } |
| 1088 | |
| 1089 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
| 1090 | |
| 1091 | static void |
| 1092 | condition_command (char *arg, int from_tty) |
| 1093 | { |
| 1094 | struct breakpoint *b; |
| 1095 | char *p; |
| 1096 | int bnum; |
| 1097 | |
| 1098 | if (arg == 0) |
| 1099 | error_no_arg (_("breakpoint number")); |
| 1100 | |
| 1101 | p = arg; |
| 1102 | bnum = get_number (&p); |
| 1103 | if (bnum == 0) |
| 1104 | error (_("Bad breakpoint argument: '%s'"), arg); |
| 1105 | |
| 1106 | ALL_BREAKPOINTS (b) |
| 1107 | if (b->number == bnum) |
| 1108 | { |
| 1109 | /* Check if this breakpoint has a "stop" method implemented in an |
| 1110 | extension language. This method and conditions entered into GDB |
| 1111 | from the CLI are mutually exclusive. */ |
| 1112 | const struct extension_language_defn *extlang |
| 1113 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); |
| 1114 | |
| 1115 | if (extlang != NULL) |
| 1116 | { |
| 1117 | error (_("Only one stop condition allowed. There is currently" |
| 1118 | " a %s stop condition defined for this breakpoint."), |
| 1119 | ext_lang_capitalized_name (extlang)); |
| 1120 | } |
| 1121 | set_breakpoint_condition (b, p, from_tty); |
| 1122 | |
| 1123 | if (is_breakpoint (b)) |
| 1124 | update_global_location_list (UGLL_MAY_INSERT); |
| 1125 | |
| 1126 | return; |
| 1127 | } |
| 1128 | |
| 1129 | error (_("No breakpoint number %d."), bnum); |
| 1130 | } |
| 1131 | |
| 1132 | /* Check that COMMAND do not contain commands that are suitable |
| 1133 | only for tracepoints and not suitable for ordinary breakpoints. |
| 1134 | Throw if any such commands is found. */ |
| 1135 | |
| 1136 | static void |
| 1137 | check_no_tracepoint_commands (struct command_line *commands) |
| 1138 | { |
| 1139 | struct command_line *c; |
| 1140 | |
| 1141 | for (c = commands; c; c = c->next) |
| 1142 | { |
| 1143 | int i; |
| 1144 | |
| 1145 | if (c->control_type == while_stepping_control) |
| 1146 | error (_("The 'while-stepping' command can " |
| 1147 | "only be used for tracepoints")); |
| 1148 | |
| 1149 | for (i = 0; i < c->body_count; ++i) |
| 1150 | check_no_tracepoint_commands ((c->body_list)[i]); |
| 1151 | |
| 1152 | /* Not that command parsing removes leading whitespace and comment |
| 1153 | lines and also empty lines. So, we only need to check for |
| 1154 | command directly. */ |
| 1155 | if (strstr (c->line, "collect ") == c->line) |
| 1156 | error (_("The 'collect' command can only be used for tracepoints")); |
| 1157 | |
| 1158 | if (strstr (c->line, "teval ") == c->line) |
| 1159 | error (_("The 'teval' command can only be used for tracepoints")); |
| 1160 | } |
| 1161 | } |
| 1162 | |
| 1163 | /* Encapsulate tests for different types of tracepoints. */ |
| 1164 | |
| 1165 | static int |
| 1166 | is_tracepoint_type (enum bptype type) |
| 1167 | { |
| 1168 | return (type == bp_tracepoint |
| 1169 | || type == bp_fast_tracepoint |
| 1170 | || type == bp_static_tracepoint); |
| 1171 | } |
| 1172 | |
| 1173 | int |
| 1174 | is_tracepoint (const struct breakpoint *b) |
| 1175 | { |
| 1176 | return is_tracepoint_type (b->type); |
| 1177 | } |
| 1178 | |
| 1179 | /* A helper function that validates that COMMANDS are valid for a |
| 1180 | breakpoint. This function will throw an exception if a problem is |
| 1181 | found. */ |
| 1182 | |
| 1183 | static void |
| 1184 | validate_commands_for_breakpoint (struct breakpoint *b, |
| 1185 | struct command_line *commands) |
| 1186 | { |
| 1187 | if (is_tracepoint (b)) |
| 1188 | { |
| 1189 | struct tracepoint *t = (struct tracepoint *) b; |
| 1190 | struct command_line *c; |
| 1191 | struct command_line *while_stepping = 0; |
| 1192 | |
| 1193 | /* Reset the while-stepping step count. The previous commands |
| 1194 | might have included a while-stepping action, while the new |
| 1195 | ones might not. */ |
| 1196 | t->step_count = 0; |
| 1197 | |
| 1198 | /* We need to verify that each top-level element of commands is |
| 1199 | valid for tracepoints, that there's at most one |
| 1200 | while-stepping element, and that the while-stepping's body |
| 1201 | has valid tracing commands excluding nested while-stepping. |
| 1202 | We also need to validate the tracepoint action line in the |
| 1203 | context of the tracepoint --- validate_actionline actually |
| 1204 | has side effects, like setting the tracepoint's |
| 1205 | while-stepping STEP_COUNT, in addition to checking if the |
| 1206 | collect/teval actions parse and make sense in the |
| 1207 | tracepoint's context. */ |
| 1208 | for (c = commands; c; c = c->next) |
| 1209 | { |
| 1210 | if (c->control_type == while_stepping_control) |
| 1211 | { |
| 1212 | if (b->type == bp_fast_tracepoint) |
| 1213 | error (_("The 'while-stepping' command " |
| 1214 | "cannot be used for fast tracepoint")); |
| 1215 | else if (b->type == bp_static_tracepoint) |
| 1216 | error (_("The 'while-stepping' command " |
| 1217 | "cannot be used for static tracepoint")); |
| 1218 | |
| 1219 | if (while_stepping) |
| 1220 | error (_("The 'while-stepping' command " |
| 1221 | "can be used only once")); |
| 1222 | else |
| 1223 | while_stepping = c; |
| 1224 | } |
| 1225 | |
| 1226 | validate_actionline (c->line, b); |
| 1227 | } |
| 1228 | if (while_stepping) |
| 1229 | { |
| 1230 | struct command_line *c2; |
| 1231 | |
| 1232 | gdb_assert (while_stepping->body_count == 1); |
| 1233 | c2 = while_stepping->body_list[0]; |
| 1234 | for (; c2; c2 = c2->next) |
| 1235 | { |
| 1236 | if (c2->control_type == while_stepping_control) |
| 1237 | error (_("The 'while-stepping' command cannot be nested")); |
| 1238 | } |
| 1239 | } |
| 1240 | } |
| 1241 | else |
| 1242 | { |
| 1243 | check_no_tracepoint_commands (commands); |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1247 | /* Return a vector of all the static tracepoints set at ADDR. The |
| 1248 | caller is responsible for releasing the vector. */ |
| 1249 | |
| 1250 | VEC(breakpoint_p) * |
| 1251 | static_tracepoints_here (CORE_ADDR addr) |
| 1252 | { |
| 1253 | struct breakpoint *b; |
| 1254 | VEC(breakpoint_p) *found = 0; |
| 1255 | struct bp_location *loc; |
| 1256 | |
| 1257 | ALL_BREAKPOINTS (b) |
| 1258 | if (b->type == bp_static_tracepoint) |
| 1259 | { |
| 1260 | for (loc = b->loc; loc; loc = loc->next) |
| 1261 | if (loc->address == addr) |
| 1262 | VEC_safe_push(breakpoint_p, found, b); |
| 1263 | } |
| 1264 | |
| 1265 | return found; |
| 1266 | } |
| 1267 | |
| 1268 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
| 1269 | validate that only allowed commands are included. */ |
| 1270 | |
| 1271 | void |
| 1272 | breakpoint_set_commands (struct breakpoint *b, |
| 1273 | struct command_line *commands) |
| 1274 | { |
| 1275 | validate_commands_for_breakpoint (b, commands); |
| 1276 | |
| 1277 | decref_counted_command_line (&b->commands); |
| 1278 | b->commands = alloc_counted_command_line (commands); |
| 1279 | observer_notify_breakpoint_modified (b); |
| 1280 | } |
| 1281 | |
| 1282 | /* Set the internal `silent' flag on the breakpoint. Note that this |
| 1283 | is not the same as the "silent" that may appear in the breakpoint's |
| 1284 | commands. */ |
| 1285 | |
| 1286 | void |
| 1287 | breakpoint_set_silent (struct breakpoint *b, int silent) |
| 1288 | { |
| 1289 | int old_silent = b->silent; |
| 1290 | |
| 1291 | b->silent = silent; |
| 1292 | if (old_silent != silent) |
| 1293 | observer_notify_breakpoint_modified (b); |
| 1294 | } |
| 1295 | |
| 1296 | /* Set the thread for this breakpoint. If THREAD is -1, make the |
| 1297 | breakpoint work for any thread. */ |
| 1298 | |
| 1299 | void |
| 1300 | breakpoint_set_thread (struct breakpoint *b, int thread) |
| 1301 | { |
| 1302 | int old_thread = b->thread; |
| 1303 | |
| 1304 | b->thread = thread; |
| 1305 | if (old_thread != thread) |
| 1306 | observer_notify_breakpoint_modified (b); |
| 1307 | } |
| 1308 | |
| 1309 | /* Set the task for this breakpoint. If TASK is 0, make the |
| 1310 | breakpoint work for any task. */ |
| 1311 | |
| 1312 | void |
| 1313 | breakpoint_set_task (struct breakpoint *b, int task) |
| 1314 | { |
| 1315 | int old_task = b->task; |
| 1316 | |
| 1317 | b->task = task; |
| 1318 | if (old_task != task) |
| 1319 | observer_notify_breakpoint_modified (b); |
| 1320 | } |
| 1321 | |
| 1322 | void |
| 1323 | check_tracepoint_command (char *line, void *closure) |
| 1324 | { |
| 1325 | struct breakpoint *b = closure; |
| 1326 | |
| 1327 | validate_actionline (line, b); |
| 1328 | } |
| 1329 | |
| 1330 | /* A structure used to pass information through |
| 1331 | map_breakpoint_numbers. */ |
| 1332 | |
| 1333 | struct commands_info |
| 1334 | { |
| 1335 | /* True if the command was typed at a tty. */ |
| 1336 | int from_tty; |
| 1337 | |
| 1338 | /* The breakpoint range spec. */ |
| 1339 | char *arg; |
| 1340 | |
| 1341 | /* Non-NULL if the body of the commands are being read from this |
| 1342 | already-parsed command. */ |
| 1343 | struct command_line *control; |
| 1344 | |
| 1345 | /* The command lines read from the user, or NULL if they have not |
| 1346 | yet been read. */ |
| 1347 | struct counted_command_line *cmd; |
| 1348 | }; |
| 1349 | |
| 1350 | /* A callback for map_breakpoint_numbers that sets the commands for |
| 1351 | commands_command. */ |
| 1352 | |
| 1353 | static void |
| 1354 | do_map_commands_command (struct breakpoint *b, void *data) |
| 1355 | { |
| 1356 | struct commands_info *info = data; |
| 1357 | |
| 1358 | if (info->cmd == NULL) |
| 1359 | { |
| 1360 | struct command_line *l; |
| 1361 | |
| 1362 | if (info->control != NULL) |
| 1363 | l = copy_command_lines (info->control->body_list[0]); |
| 1364 | else |
| 1365 | { |
| 1366 | struct cleanup *old_chain; |
| 1367 | char *str; |
| 1368 | |
| 1369 | str = xstrprintf (_("Type commands for breakpoint(s) " |
| 1370 | "%s, one per line."), |
| 1371 | info->arg); |
| 1372 | |
| 1373 | old_chain = make_cleanup (xfree, str); |
| 1374 | |
| 1375 | l = read_command_lines (str, |
| 1376 | info->from_tty, 1, |
| 1377 | (is_tracepoint (b) |
| 1378 | ? check_tracepoint_command : 0), |
| 1379 | b); |
| 1380 | |
| 1381 | do_cleanups (old_chain); |
| 1382 | } |
| 1383 | |
| 1384 | info->cmd = alloc_counted_command_line (l); |
| 1385 | } |
| 1386 | |
| 1387 | /* If a breakpoint was on the list more than once, we don't need to |
| 1388 | do anything. */ |
| 1389 | if (b->commands != info->cmd) |
| 1390 | { |
| 1391 | validate_commands_for_breakpoint (b, info->cmd->commands); |
| 1392 | incref_counted_command_line (info->cmd); |
| 1393 | decref_counted_command_line (&b->commands); |
| 1394 | b->commands = info->cmd; |
| 1395 | observer_notify_breakpoint_modified (b); |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | static void |
| 1400 | commands_command_1 (char *arg, int from_tty, |
| 1401 | struct command_line *control) |
| 1402 | { |
| 1403 | struct cleanup *cleanups; |
| 1404 | struct commands_info info; |
| 1405 | |
| 1406 | info.from_tty = from_tty; |
| 1407 | info.control = control; |
| 1408 | info.cmd = NULL; |
| 1409 | /* If we read command lines from the user, then `info' will hold an |
| 1410 | extra reference to the commands that we must clean up. */ |
| 1411 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); |
| 1412 | |
| 1413 | if (arg == NULL || !*arg) |
| 1414 | { |
| 1415 | if (breakpoint_count - prev_breakpoint_count > 1) |
| 1416 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
| 1417 | breakpoint_count); |
| 1418 | else if (breakpoint_count > 0) |
| 1419 | arg = xstrprintf ("%d", breakpoint_count); |
| 1420 | else |
| 1421 | { |
| 1422 | /* So that we don't try to free the incoming non-NULL |
| 1423 | argument in the cleanup below. Mapping breakpoint |
| 1424 | numbers will fail in this case. */ |
| 1425 | arg = NULL; |
| 1426 | } |
| 1427 | } |
| 1428 | else |
| 1429 | /* The command loop has some static state, so we need to preserve |
| 1430 | our argument. */ |
| 1431 | arg = xstrdup (arg); |
| 1432 | |
| 1433 | if (arg != NULL) |
| 1434 | make_cleanup (xfree, arg); |
| 1435 | |
| 1436 | info.arg = arg; |
| 1437 | |
| 1438 | map_breakpoint_numbers (arg, do_map_commands_command, &info); |
| 1439 | |
| 1440 | if (info.cmd == NULL) |
| 1441 | error (_("No breakpoints specified.")); |
| 1442 | |
| 1443 | do_cleanups (cleanups); |
| 1444 | } |
| 1445 | |
| 1446 | static void |
| 1447 | commands_command (char *arg, int from_tty) |
| 1448 | { |
| 1449 | commands_command_1 (arg, from_tty, NULL); |
| 1450 | } |
| 1451 | |
| 1452 | /* Like commands_command, but instead of reading the commands from |
| 1453 | input stream, takes them from an already parsed command structure. |
| 1454 | |
| 1455 | This is used by cli-script.c to DTRT with breakpoint commands |
| 1456 | that are part of if and while bodies. */ |
| 1457 | enum command_control_type |
| 1458 | commands_from_control_command (char *arg, struct command_line *cmd) |
| 1459 | { |
| 1460 | commands_command_1 (arg, 0, cmd); |
| 1461 | return simple_control; |
| 1462 | } |
| 1463 | |
| 1464 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ |
| 1465 | |
| 1466 | static int |
| 1467 | bp_location_has_shadow (struct bp_location *bl) |
| 1468 | { |
| 1469 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 1470 | return 0; |
| 1471 | if (!bl->inserted) |
| 1472 | return 0; |
| 1473 | if (bl->target_info.shadow_len == 0) |
| 1474 | /* BL isn't valid, or doesn't shadow memory. */ |
| 1475 | return 0; |
| 1476 | return 1; |
| 1477 | } |
| 1478 | |
| 1479 | /* Update BUF, which is LEN bytes read from the target address |
| 1480 | MEMADDR, by replacing a memory breakpoint with its shadowed |
| 1481 | contents. |
| 1482 | |
| 1483 | If READBUF is not NULL, this buffer must not overlap with the of |
| 1484 | the breakpoint location's shadow_contents buffer. Otherwise, a |
| 1485 | failed assertion internal error will be raised. */ |
| 1486 | |
| 1487 | static void |
| 1488 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
| 1489 | const gdb_byte *writebuf_org, |
| 1490 | ULONGEST memaddr, LONGEST len, |
| 1491 | struct bp_target_info *target_info, |
| 1492 | struct gdbarch *gdbarch) |
| 1493 | { |
| 1494 | /* Now do full processing of the found relevant range of elements. */ |
| 1495 | CORE_ADDR bp_addr = 0; |
| 1496 | int bp_size = 0; |
| 1497 | int bptoffset = 0; |
| 1498 | |
| 1499 | if (!breakpoint_address_match (target_info->placed_address_space, 0, |
| 1500 | current_program_space->aspace, 0)) |
| 1501 | { |
| 1502 | /* The breakpoint is inserted in a different address space. */ |
| 1503 | return; |
| 1504 | } |
| 1505 | |
| 1506 | /* Addresses and length of the part of the breakpoint that |
| 1507 | we need to copy. */ |
| 1508 | bp_addr = target_info->placed_address; |
| 1509 | bp_size = target_info->shadow_len; |
| 1510 | |
| 1511 | if (bp_addr + bp_size <= memaddr) |
| 1512 | { |
| 1513 | /* The breakpoint is entirely before the chunk of memory we are |
| 1514 | reading. */ |
| 1515 | return; |
| 1516 | } |
| 1517 | |
| 1518 | if (bp_addr >= memaddr + len) |
| 1519 | { |
| 1520 | /* The breakpoint is entirely after the chunk of memory we are |
| 1521 | reading. */ |
| 1522 | return; |
| 1523 | } |
| 1524 | |
| 1525 | /* Offset within shadow_contents. */ |
| 1526 | if (bp_addr < memaddr) |
| 1527 | { |
| 1528 | /* Only copy the second part of the breakpoint. */ |
| 1529 | bp_size -= memaddr - bp_addr; |
| 1530 | bptoffset = memaddr - bp_addr; |
| 1531 | bp_addr = memaddr; |
| 1532 | } |
| 1533 | |
| 1534 | if (bp_addr + bp_size > memaddr + len) |
| 1535 | { |
| 1536 | /* Only copy the first part of the breakpoint. */ |
| 1537 | bp_size -= (bp_addr + bp_size) - (memaddr + len); |
| 1538 | } |
| 1539 | |
| 1540 | if (readbuf != NULL) |
| 1541 | { |
| 1542 | /* Verify that the readbuf buffer does not overlap with the |
| 1543 | shadow_contents buffer. */ |
| 1544 | gdb_assert (target_info->shadow_contents >= readbuf + len |
| 1545 | || readbuf >= (target_info->shadow_contents |
| 1546 | + target_info->shadow_len)); |
| 1547 | |
| 1548 | /* Update the read buffer with this inserted breakpoint's |
| 1549 | shadow. */ |
| 1550 | memcpy (readbuf + bp_addr - memaddr, |
| 1551 | target_info->shadow_contents + bptoffset, bp_size); |
| 1552 | } |
| 1553 | else |
| 1554 | { |
| 1555 | const unsigned char *bp; |
| 1556 | CORE_ADDR addr = target_info->reqstd_address; |
| 1557 | int placed_size; |
| 1558 | |
| 1559 | /* Update the shadow with what we want to write to memory. */ |
| 1560 | memcpy (target_info->shadow_contents + bptoffset, |
| 1561 | writebuf_org + bp_addr - memaddr, bp_size); |
| 1562 | |
| 1563 | /* Determine appropriate breakpoint contents and size for this |
| 1564 | address. */ |
| 1565 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
| 1566 | |
| 1567 | /* Update the final write buffer with this inserted |
| 1568 | breakpoint's INSN. */ |
| 1569 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
| 1574 | by replacing any memory breakpoints with their shadowed contents. |
| 1575 | |
| 1576 | If READBUF is not NULL, this buffer must not overlap with any of |
| 1577 | the breakpoint location's shadow_contents buffers. Otherwise, |
| 1578 | a failed assertion internal error will be raised. |
| 1579 | |
| 1580 | The range of shadowed area by each bp_location is: |
| 1581 | bl->address - bp_location_placed_address_before_address_max |
| 1582 | up to bl->address + bp_location_shadow_len_after_address_max |
| 1583 | The range we were requested to resolve shadows for is: |
| 1584 | memaddr ... memaddr + len |
| 1585 | Thus the safe cutoff boundaries for performance optimization are |
| 1586 | memaddr + len <= (bl->address |
| 1587 | - bp_location_placed_address_before_address_max) |
| 1588 | and: |
| 1589 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
| 1590 | |
| 1591 | void |
| 1592 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
| 1593 | const gdb_byte *writebuf_org, |
| 1594 | ULONGEST memaddr, LONGEST len) |
| 1595 | { |
| 1596 | /* Left boundary, right boundary and median element of our binary |
| 1597 | search. */ |
| 1598 | unsigned bc_l, bc_r, bc; |
| 1599 | size_t i; |
| 1600 | |
| 1601 | /* Find BC_L which is a leftmost element which may affect BUF |
| 1602 | content. It is safe to report lower value but a failure to |
| 1603 | report higher one. */ |
| 1604 | |
| 1605 | bc_l = 0; |
| 1606 | bc_r = bp_location_count; |
| 1607 | while (bc_l + 1 < bc_r) |
| 1608 | { |
| 1609 | struct bp_location *bl; |
| 1610 | |
| 1611 | bc = (bc_l + bc_r) / 2; |
| 1612 | bl = bp_location[bc]; |
| 1613 | |
| 1614 | /* Check first BL->ADDRESS will not overflow due to the added |
| 1615 | constant. Then advance the left boundary only if we are sure |
| 1616 | the BC element can in no way affect the BUF content (MEMADDR |
| 1617 | to MEMADDR + LEN range). |
| 1618 | |
| 1619 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
| 1620 | offset so that we cannot miss a breakpoint with its shadow |
| 1621 | range tail still reaching MEMADDR. */ |
| 1622 | |
| 1623 | if ((bl->address + bp_location_shadow_len_after_address_max |
| 1624 | >= bl->address) |
| 1625 | && (bl->address + bp_location_shadow_len_after_address_max |
| 1626 | <= memaddr)) |
| 1627 | bc_l = bc; |
| 1628 | else |
| 1629 | bc_r = bc; |
| 1630 | } |
| 1631 | |
| 1632 | /* Due to the binary search above, we need to make sure we pick the |
| 1633 | first location that's at BC_L's address. E.g., if there are |
| 1634 | multiple locations at the same address, BC_L may end up pointing |
| 1635 | at a duplicate location, and miss the "master"/"inserted" |
| 1636 | location. Say, given locations L1, L2 and L3 at addresses A and |
| 1637 | B: |
| 1638 | |
| 1639 | L1@A, L2@A, L3@B, ... |
| 1640 | |
| 1641 | BC_L could end up pointing at location L2, while the "master" |
| 1642 | location could be L1. Since the `loc->inserted' flag is only set |
| 1643 | on "master" locations, we'd forget to restore the shadow of L1 |
| 1644 | and L2. */ |
| 1645 | while (bc_l > 0 |
| 1646 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) |
| 1647 | bc_l--; |
| 1648 | |
| 1649 | /* Now do full processing of the found relevant range of elements. */ |
| 1650 | |
| 1651 | for (bc = bc_l; bc < bp_location_count; bc++) |
| 1652 | { |
| 1653 | struct bp_location *bl = bp_location[bc]; |
| 1654 | CORE_ADDR bp_addr = 0; |
| 1655 | int bp_size = 0; |
| 1656 | int bptoffset = 0; |
| 1657 | |
| 1658 | /* bp_location array has BL->OWNER always non-NULL. */ |
| 1659 | if (bl->owner->type == bp_none) |
| 1660 | warning (_("reading through apparently deleted breakpoint #%d?"), |
| 1661 | bl->owner->number); |
| 1662 | |
| 1663 | /* Performance optimization: any further element can no longer affect BUF |
| 1664 | content. */ |
| 1665 | |
| 1666 | if (bl->address >= bp_location_placed_address_before_address_max |
| 1667 | && memaddr + len <= (bl->address |
| 1668 | - bp_location_placed_address_before_address_max)) |
| 1669 | break; |
| 1670 | |
| 1671 | if (!bp_location_has_shadow (bl)) |
| 1672 | continue; |
| 1673 | |
| 1674 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
| 1675 | memaddr, len, &bl->target_info, bl->gdbarch); |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | \f |
| 1680 | |
| 1681 | /* Return true if BPT is either a software breakpoint or a hardware |
| 1682 | breakpoint. */ |
| 1683 | |
| 1684 | int |
| 1685 | is_breakpoint (const struct breakpoint *bpt) |
| 1686 | { |
| 1687 | return (bpt->type == bp_breakpoint |
| 1688 | || bpt->type == bp_hardware_breakpoint |
| 1689 | || bpt->type == bp_dprintf); |
| 1690 | } |
| 1691 | |
| 1692 | /* Return true if BPT is of any hardware watchpoint kind. */ |
| 1693 | |
| 1694 | static int |
| 1695 | is_hardware_watchpoint (const struct breakpoint *bpt) |
| 1696 | { |
| 1697 | return (bpt->type == bp_hardware_watchpoint |
| 1698 | || bpt->type == bp_read_watchpoint |
| 1699 | || bpt->type == bp_access_watchpoint); |
| 1700 | } |
| 1701 | |
| 1702 | /* Return true if BPT is of any watchpoint kind, hardware or |
| 1703 | software. */ |
| 1704 | |
| 1705 | int |
| 1706 | is_watchpoint (const struct breakpoint *bpt) |
| 1707 | { |
| 1708 | return (is_hardware_watchpoint (bpt) |
| 1709 | || bpt->type == bp_watchpoint); |
| 1710 | } |
| 1711 | |
| 1712 | /* Returns true if the current thread and its running state are safe |
| 1713 | to evaluate or update watchpoint B. Watchpoints on local |
| 1714 | expressions need to be evaluated in the context of the thread that |
| 1715 | was current when the watchpoint was created, and, that thread needs |
| 1716 | to be stopped to be able to select the correct frame context. |
| 1717 | Watchpoints on global expressions can be evaluated on any thread, |
| 1718 | and in any state. It is presently left to the target allowing |
| 1719 | memory accesses when threads are running. */ |
| 1720 | |
| 1721 | static int |
| 1722 | watchpoint_in_thread_scope (struct watchpoint *b) |
| 1723 | { |
| 1724 | return (b->base.pspace == current_program_space |
| 1725 | && (ptid_equal (b->watchpoint_thread, null_ptid) |
| 1726 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) |
| 1727 | && !is_executing (inferior_ptid)))); |
| 1728 | } |
| 1729 | |
| 1730 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
| 1731 | associated bp_watchpoint_scope breakpoint. */ |
| 1732 | |
| 1733 | static void |
| 1734 | watchpoint_del_at_next_stop (struct watchpoint *w) |
| 1735 | { |
| 1736 | struct breakpoint *b = &w->base; |
| 1737 | |
| 1738 | if (b->related_breakpoint != b) |
| 1739 | { |
| 1740 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); |
| 1741 | gdb_assert (b->related_breakpoint->related_breakpoint == b); |
| 1742 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
| 1743 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; |
| 1744 | b->related_breakpoint = b; |
| 1745 | } |
| 1746 | b->disposition = disp_del_at_next_stop; |
| 1747 | } |
| 1748 | |
| 1749 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
| 1750 | watchpoint W. */ |
| 1751 | |
| 1752 | static struct value * |
| 1753 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) |
| 1754 | { |
| 1755 | struct value *bit_val; |
| 1756 | |
| 1757 | if (val == NULL) |
| 1758 | return NULL; |
| 1759 | |
| 1760 | bit_val = allocate_value (value_type (val)); |
| 1761 | |
| 1762 | unpack_value_bitfield (bit_val, |
| 1763 | w->val_bitpos, |
| 1764 | w->val_bitsize, |
| 1765 | value_contents_for_printing (val), |
| 1766 | value_offset (val), |
| 1767 | val); |
| 1768 | |
| 1769 | return bit_val; |
| 1770 | } |
| 1771 | |
| 1772 | /* Assuming that B is a watchpoint: |
| 1773 | - Reparse watchpoint expression, if REPARSE is non-zero |
| 1774 | - Evaluate expression and store the result in B->val |
| 1775 | - Evaluate the condition if there is one, and store the result |
| 1776 | in b->loc->cond. |
| 1777 | - Update the list of values that must be watched in B->loc. |
| 1778 | |
| 1779 | If the watchpoint disposition is disp_del_at_next_stop, then do |
| 1780 | nothing. If this is local watchpoint that is out of scope, delete |
| 1781 | it. |
| 1782 | |
| 1783 | Even with `set breakpoint always-inserted on' the watchpoints are |
| 1784 | removed + inserted on each stop here. Normal breakpoints must |
| 1785 | never be removed because they might be missed by a running thread |
| 1786 | when debugging in non-stop mode. On the other hand, hardware |
| 1787 | watchpoints (is_hardware_watchpoint; processed here) are specific |
| 1788 | to each LWP since they are stored in each LWP's hardware debug |
| 1789 | registers. Therefore, such LWP must be stopped first in order to |
| 1790 | be able to modify its hardware watchpoints. |
| 1791 | |
| 1792 | Hardware watchpoints must be reset exactly once after being |
| 1793 | presented to the user. It cannot be done sooner, because it would |
| 1794 | reset the data used to present the watchpoint hit to the user. And |
| 1795 | it must not be done later because it could display the same single |
| 1796 | watchpoint hit during multiple GDB stops. Note that the latter is |
| 1797 | relevant only to the hardware watchpoint types bp_read_watchpoint |
| 1798 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is |
| 1799 | not user-visible - its hit is suppressed if the memory content has |
| 1800 | not changed. |
| 1801 | |
| 1802 | The following constraints influence the location where we can reset |
| 1803 | hardware watchpoints: |
| 1804 | |
| 1805 | * target_stopped_by_watchpoint and target_stopped_data_address are |
| 1806 | called several times when GDB stops. |
| 1807 | |
| 1808 | [linux] |
| 1809 | * Multiple hardware watchpoints can be hit at the same time, |
| 1810 | causing GDB to stop. GDB only presents one hardware watchpoint |
| 1811 | hit at a time as the reason for stopping, and all the other hits |
| 1812 | are presented later, one after the other, each time the user |
| 1813 | requests the execution to be resumed. Execution is not resumed |
| 1814 | for the threads still having pending hit event stored in |
| 1815 | LWP_INFO->STATUS. While the watchpoint is already removed from |
| 1816 | the inferior on the first stop the thread hit event is kept being |
| 1817 | reported from its cached value by linux_nat_stopped_data_address |
| 1818 | until the real thread resume happens after the watchpoint gets |
| 1819 | presented and thus its LWP_INFO->STATUS gets reset. |
| 1820 | |
| 1821 | Therefore the hardware watchpoint hit can get safely reset on the |
| 1822 | watchpoint removal from inferior. */ |
| 1823 | |
| 1824 | static void |
| 1825 | update_watchpoint (struct watchpoint *b, int reparse) |
| 1826 | { |
| 1827 | int within_current_scope; |
| 1828 | struct frame_id saved_frame_id; |
| 1829 | int frame_saved; |
| 1830 | |
| 1831 | /* If this is a local watchpoint, we only want to check if the |
| 1832 | watchpoint frame is in scope if the current thread is the thread |
| 1833 | that was used to create the watchpoint. */ |
| 1834 | if (!watchpoint_in_thread_scope (b)) |
| 1835 | return; |
| 1836 | |
| 1837 | if (b->base.disposition == disp_del_at_next_stop) |
| 1838 | return; |
| 1839 | |
| 1840 | frame_saved = 0; |
| 1841 | |
| 1842 | /* Determine if the watchpoint is within scope. */ |
| 1843 | if (b->exp_valid_block == NULL) |
| 1844 | within_current_scope = 1; |
| 1845 | else |
| 1846 | { |
| 1847 | struct frame_info *fi = get_current_frame (); |
| 1848 | struct gdbarch *frame_arch = get_frame_arch (fi); |
| 1849 | CORE_ADDR frame_pc = get_frame_pc (fi); |
| 1850 | |
| 1851 | /* If we're at a point where the stack has been destroyed |
| 1852 | (e.g. in a function epilogue), unwinding may not work |
| 1853 | properly. Do not attempt to recreate locations at this |
| 1854 | point. See similar comments in watchpoint_check. */ |
| 1855 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
| 1856 | return; |
| 1857 | |
| 1858 | /* Save the current frame's ID so we can restore it after |
| 1859 | evaluating the watchpoint expression on its own frame. */ |
| 1860 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
| 1861 | took a frame parameter, so that we didn't have to change the |
| 1862 | selected frame. */ |
| 1863 | frame_saved = 1; |
| 1864 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); |
| 1865 | |
| 1866 | fi = frame_find_by_id (b->watchpoint_frame); |
| 1867 | within_current_scope = (fi != NULL); |
| 1868 | if (within_current_scope) |
| 1869 | select_frame (fi); |
| 1870 | } |
| 1871 | |
| 1872 | /* We don't free locations. They are stored in the bp_location array |
| 1873 | and update_global_location_list will eventually delete them and |
| 1874 | remove breakpoints if needed. */ |
| 1875 | b->base.loc = NULL; |
| 1876 | |
| 1877 | if (within_current_scope && reparse) |
| 1878 | { |
| 1879 | const char *s; |
| 1880 | |
| 1881 | if (b->exp) |
| 1882 | { |
| 1883 | xfree (b->exp); |
| 1884 | b->exp = NULL; |
| 1885 | } |
| 1886 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
| 1887 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
| 1888 | /* If the meaning of expression itself changed, the old value is |
| 1889 | no longer relevant. We don't want to report a watchpoint hit |
| 1890 | to the user when the old value and the new value may actually |
| 1891 | be completely different objects. */ |
| 1892 | value_free (b->val); |
| 1893 | b->val = NULL; |
| 1894 | b->val_valid = 0; |
| 1895 | |
| 1896 | /* Note that unlike with breakpoints, the watchpoint's condition |
| 1897 | expression is stored in the breakpoint object, not in the |
| 1898 | locations (re)created below. */ |
| 1899 | if (b->base.cond_string != NULL) |
| 1900 | { |
| 1901 | if (b->cond_exp != NULL) |
| 1902 | { |
| 1903 | xfree (b->cond_exp); |
| 1904 | b->cond_exp = NULL; |
| 1905 | } |
| 1906 | |
| 1907 | s = b->base.cond_string; |
| 1908 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | /* If we failed to parse the expression, for example because |
| 1913 | it refers to a global variable in a not-yet-loaded shared library, |
| 1914 | don't try to insert watchpoint. We don't automatically delete |
| 1915 | such watchpoint, though, since failure to parse expression |
| 1916 | is different from out-of-scope watchpoint. */ |
| 1917 | if (!target_has_execution) |
| 1918 | { |
| 1919 | /* Without execution, memory can't change. No use to try and |
| 1920 | set watchpoint locations. The watchpoint will be reset when |
| 1921 | the target gains execution, through breakpoint_re_set. */ |
| 1922 | if (!can_use_hw_watchpoints) |
| 1923 | { |
| 1924 | if (b->base.ops->works_in_software_mode (&b->base)) |
| 1925 | b->base.type = bp_watchpoint; |
| 1926 | else |
| 1927 | error (_("Can't set read/access watchpoint when " |
| 1928 | "hardware watchpoints are disabled.")); |
| 1929 | } |
| 1930 | } |
| 1931 | else if (within_current_scope && b->exp) |
| 1932 | { |
| 1933 | int pc = 0; |
| 1934 | struct value *val_chain, *v, *result, *next; |
| 1935 | struct program_space *frame_pspace; |
| 1936 | |
| 1937 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain, 0); |
| 1938 | |
| 1939 | /* Avoid setting b->val if it's already set. The meaning of |
| 1940 | b->val is 'the last value' user saw, and we should update |
| 1941 | it only if we reported that last value to user. As it |
| 1942 | happens, the code that reports it updates b->val directly. |
| 1943 | We don't keep track of the memory value for masked |
| 1944 | watchpoints. */ |
| 1945 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
| 1946 | { |
| 1947 | if (b->val_bitsize != 0) |
| 1948 | { |
| 1949 | v = extract_bitfield_from_watchpoint_value (b, v); |
| 1950 | if (v != NULL) |
| 1951 | release_value (v); |
| 1952 | } |
| 1953 | b->val = v; |
| 1954 | b->val_valid = 1; |
| 1955 | } |
| 1956 | |
| 1957 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
| 1958 | |
| 1959 | /* Look at each value on the value chain. */ |
| 1960 | for (v = val_chain; v; v = value_next (v)) |
| 1961 | { |
| 1962 | /* If it's a memory location, and GDB actually needed |
| 1963 | its contents to evaluate the expression, then we |
| 1964 | must watch it. If the first value returned is |
| 1965 | still lazy, that means an error occurred reading it; |
| 1966 | watch it anyway in case it becomes readable. */ |
| 1967 | if (VALUE_LVAL (v) == lval_memory |
| 1968 | && (v == val_chain || ! value_lazy (v))) |
| 1969 | { |
| 1970 | struct type *vtype = check_typedef (value_type (v)); |
| 1971 | |
| 1972 | /* We only watch structs and arrays if user asked |
| 1973 | for it explicitly, never if they just happen to |
| 1974 | appear in the middle of some value chain. */ |
| 1975 | if (v == result |
| 1976 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 1977 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 1978 | { |
| 1979 | CORE_ADDR addr; |
| 1980 | enum target_hw_bp_type type; |
| 1981 | struct bp_location *loc, **tmp; |
| 1982 | int bitpos = 0, bitsize = 0; |
| 1983 | |
| 1984 | if (value_bitsize (v) != 0) |
| 1985 | { |
| 1986 | /* Extract the bit parameters out from the bitfield |
| 1987 | sub-expression. */ |
| 1988 | bitpos = value_bitpos (v); |
| 1989 | bitsize = value_bitsize (v); |
| 1990 | } |
| 1991 | else if (v == result && b->val_bitsize != 0) |
| 1992 | { |
| 1993 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield |
| 1994 | lvalue whose bit parameters are saved in the fields |
| 1995 | VAL_BITPOS and VAL_BITSIZE. */ |
| 1996 | bitpos = b->val_bitpos; |
| 1997 | bitsize = b->val_bitsize; |
| 1998 | } |
| 1999 | |
| 2000 | addr = value_address (v); |
| 2001 | if (bitsize != 0) |
| 2002 | { |
| 2003 | /* Skip the bytes that don't contain the bitfield. */ |
| 2004 | addr += bitpos / 8; |
| 2005 | } |
| 2006 | |
| 2007 | type = hw_write; |
| 2008 | if (b->base.type == bp_read_watchpoint) |
| 2009 | type = hw_read; |
| 2010 | else if (b->base.type == bp_access_watchpoint) |
| 2011 | type = hw_access; |
| 2012 | |
| 2013 | loc = allocate_bp_location (&b->base); |
| 2014 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) |
| 2015 | ; |
| 2016 | *tmp = loc; |
| 2017 | loc->gdbarch = get_type_arch (value_type (v)); |
| 2018 | |
| 2019 | loc->pspace = frame_pspace; |
| 2020 | loc->address = addr; |
| 2021 | |
| 2022 | if (bitsize != 0) |
| 2023 | { |
| 2024 | /* Just cover the bytes that make up the bitfield. */ |
| 2025 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; |
| 2026 | } |
| 2027 | else |
| 2028 | loc->length = TYPE_LENGTH (value_type (v)); |
| 2029 | |
| 2030 | loc->watchpoint_type = type; |
| 2031 | } |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | /* Change the type of breakpoint between hardware assisted or |
| 2036 | an ordinary watchpoint depending on the hardware support |
| 2037 | and free hardware slots. REPARSE is set when the inferior |
| 2038 | is started. */ |
| 2039 | if (reparse) |
| 2040 | { |
| 2041 | int reg_cnt; |
| 2042 | enum bp_loc_type loc_type; |
| 2043 | struct bp_location *bl; |
| 2044 | |
| 2045 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
| 2046 | |
| 2047 | if (reg_cnt) |
| 2048 | { |
| 2049 | int i, target_resources_ok, other_type_used; |
| 2050 | enum bptype type; |
| 2051 | |
| 2052 | /* Use an exact watchpoint when there's only one memory region to be |
| 2053 | watched, and only one debug register is needed to watch it. */ |
| 2054 | b->exact = target_exact_watchpoints && reg_cnt == 1; |
| 2055 | |
| 2056 | /* We need to determine how many resources are already |
| 2057 | used for all other hardware watchpoints plus this one |
| 2058 | to see if we still have enough resources to also fit |
| 2059 | this watchpoint in as well. */ |
| 2060 | |
| 2061 | /* If this is a software watchpoint, we try to turn it |
| 2062 | to a hardware one -- count resources as if B was of |
| 2063 | hardware watchpoint type. */ |
| 2064 | type = b->base.type; |
| 2065 | if (type == bp_watchpoint) |
| 2066 | type = bp_hardware_watchpoint; |
| 2067 | |
| 2068 | /* This watchpoint may or may not have been placed on |
| 2069 | the list yet at this point (it won't be in the list |
| 2070 | if we're trying to create it for the first time, |
| 2071 | through watch_command), so always account for it |
| 2072 | manually. */ |
| 2073 | |
| 2074 | /* Count resources used by all watchpoints except B. */ |
| 2075 | i = hw_watchpoint_used_count_others (&b->base, type, &other_type_used); |
| 2076 | |
| 2077 | /* Add in the resources needed for B. */ |
| 2078 | i += hw_watchpoint_use_count (&b->base); |
| 2079 | |
| 2080 | target_resources_ok |
| 2081 | = target_can_use_hardware_watchpoint (type, i, other_type_used); |
| 2082 | if (target_resources_ok <= 0) |
| 2083 | { |
| 2084 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
| 2085 | |
| 2086 | if (target_resources_ok == 0 && !sw_mode) |
| 2087 | error (_("Target does not support this type of " |
| 2088 | "hardware watchpoint.")); |
| 2089 | else if (target_resources_ok < 0 && !sw_mode) |
| 2090 | error (_("There are not enough available hardware " |
| 2091 | "resources for this watchpoint.")); |
| 2092 | |
| 2093 | /* Downgrade to software watchpoint. */ |
| 2094 | b->base.type = bp_watchpoint; |
| 2095 | } |
| 2096 | else |
| 2097 | { |
| 2098 | /* If this was a software watchpoint, we've just |
| 2099 | found we have enough resources to turn it to a |
| 2100 | hardware watchpoint. Otherwise, this is a |
| 2101 | nop. */ |
| 2102 | b->base.type = type; |
| 2103 | } |
| 2104 | } |
| 2105 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
| 2106 | { |
| 2107 | if (!can_use_hw_watchpoints) |
| 2108 | error (_("Can't set read/access watchpoint when " |
| 2109 | "hardware watchpoints are disabled.")); |
| 2110 | else |
| 2111 | error (_("Expression cannot be implemented with " |
| 2112 | "read/access watchpoint.")); |
| 2113 | } |
| 2114 | else |
| 2115 | b->base.type = bp_watchpoint; |
| 2116 | |
| 2117 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
| 2118 | : bp_loc_hardware_watchpoint); |
| 2119 | for (bl = b->base.loc; bl; bl = bl->next) |
| 2120 | bl->loc_type = loc_type; |
| 2121 | } |
| 2122 | |
| 2123 | for (v = val_chain; v; v = next) |
| 2124 | { |
| 2125 | next = value_next (v); |
| 2126 | if (v != b->val) |
| 2127 | value_free (v); |
| 2128 | } |
| 2129 | |
| 2130 | /* If a software watchpoint is not watching any memory, then the |
| 2131 | above left it without any location set up. But, |
| 2132 | bpstat_stop_status requires a location to be able to report |
| 2133 | stops, so make sure there's at least a dummy one. */ |
| 2134 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
| 2135 | { |
| 2136 | struct breakpoint *base = &b->base; |
| 2137 | base->loc = allocate_bp_location (base); |
| 2138 | base->loc->pspace = frame_pspace; |
| 2139 | base->loc->address = -1; |
| 2140 | base->loc->length = -1; |
| 2141 | base->loc->watchpoint_type = -1; |
| 2142 | } |
| 2143 | } |
| 2144 | else if (!within_current_scope) |
| 2145 | { |
| 2146 | printf_filtered (_("\ |
| 2147 | Watchpoint %d deleted because the program has left the block\n\ |
| 2148 | in which its expression is valid.\n"), |
| 2149 | b->base.number); |
| 2150 | watchpoint_del_at_next_stop (b); |
| 2151 | } |
| 2152 | |
| 2153 | /* Restore the selected frame. */ |
| 2154 | if (frame_saved) |
| 2155 | select_frame (frame_find_by_id (saved_frame_id)); |
| 2156 | } |
| 2157 | |
| 2158 | |
| 2159 | /* Returns 1 iff breakpoint location should be |
| 2160 | inserted in the inferior. We don't differentiate the type of BL's owner |
| 2161 | (breakpoint vs. tracepoint), although insert_location in tracepoint's |
| 2162 | breakpoint_ops is not defined, because in insert_bp_location, |
| 2163 | tracepoint's insert_location will not be called. */ |
| 2164 | static int |
| 2165 | should_be_inserted (struct bp_location *bl) |
| 2166 | { |
| 2167 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
| 2168 | return 0; |
| 2169 | |
| 2170 | if (bl->owner->disposition == disp_del_at_next_stop) |
| 2171 | return 0; |
| 2172 | |
| 2173 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
| 2174 | return 0; |
| 2175 | |
| 2176 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
| 2177 | return 0; |
| 2178 | |
| 2179 | /* This is set for example, when we're attached to the parent of a |
| 2180 | vfork, and have detached from the child. The child is running |
| 2181 | free, and we expect it to do an exec or exit, at which point the |
| 2182 | OS makes the parent schedulable again (and the target reports |
| 2183 | that the vfork is done). Until the child is done with the shared |
| 2184 | memory region, do not insert breakpoints in the parent, otherwise |
| 2185 | the child could still trip on the parent's breakpoints. Since |
| 2186 | the parent is blocked anyway, it won't miss any breakpoint. */ |
| 2187 | if (bl->pspace->breakpoints_not_allowed) |
| 2188 | return 0; |
| 2189 | |
| 2190 | /* Don't insert a breakpoint if we're trying to step past its |
| 2191 | location. */ |
| 2192 | if ((bl->loc_type == bp_loc_software_breakpoint |
| 2193 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 2194 | && stepping_past_instruction_at (bl->pspace->aspace, |
| 2195 | bl->address)) |
| 2196 | { |
| 2197 | if (debug_infrun) |
| 2198 | { |
| 2199 | fprintf_unfiltered (gdb_stdlog, |
| 2200 | "infrun: skipping breakpoint: " |
| 2201 | "stepping past insn at: %s\n", |
| 2202 | paddress (bl->gdbarch, bl->address)); |
| 2203 | } |
| 2204 | return 0; |
| 2205 | } |
| 2206 | |
| 2207 | /* Don't insert watchpoints if we're trying to step past the |
| 2208 | instruction that triggered one. */ |
| 2209 | if ((bl->loc_type == bp_loc_hardware_watchpoint) |
| 2210 | && stepping_past_nonsteppable_watchpoint ()) |
| 2211 | { |
| 2212 | if (debug_infrun) |
| 2213 | { |
| 2214 | fprintf_unfiltered (gdb_stdlog, |
| 2215 | "infrun: stepping past non-steppable watchpoint. " |
| 2216 | "skipping watchpoint at %s:%d\n", |
| 2217 | paddress (bl->gdbarch, bl->address), |
| 2218 | bl->length); |
| 2219 | } |
| 2220 | return 0; |
| 2221 | } |
| 2222 | |
| 2223 | return 1; |
| 2224 | } |
| 2225 | |
| 2226 | /* Same as should_be_inserted but does the check assuming |
| 2227 | that the location is not duplicated. */ |
| 2228 | |
| 2229 | static int |
| 2230 | unduplicated_should_be_inserted (struct bp_location *bl) |
| 2231 | { |
| 2232 | int result; |
| 2233 | const int save_duplicate = bl->duplicate; |
| 2234 | |
| 2235 | bl->duplicate = 0; |
| 2236 | result = should_be_inserted (bl); |
| 2237 | bl->duplicate = save_duplicate; |
| 2238 | return result; |
| 2239 | } |
| 2240 | |
| 2241 | /* Parses a conditional described by an expression COND into an |
| 2242 | agent expression bytecode suitable for evaluation |
| 2243 | by the bytecode interpreter. Return NULL if there was |
| 2244 | any error during parsing. */ |
| 2245 | |
| 2246 | static struct agent_expr * |
| 2247 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
| 2248 | { |
| 2249 | struct agent_expr *aexpr = NULL; |
| 2250 | |
| 2251 | if (!cond) |
| 2252 | return NULL; |
| 2253 | |
| 2254 | /* We don't want to stop processing, so catch any errors |
| 2255 | that may show up. */ |
| 2256 | TRY |
| 2257 | { |
| 2258 | aexpr = gen_eval_for_expr (scope, cond); |
| 2259 | } |
| 2260 | |
| 2261 | CATCH (ex, RETURN_MASK_ERROR) |
| 2262 | { |
| 2263 | /* If we got here, it means the condition could not be parsed to a valid |
| 2264 | bytecode expression and thus can't be evaluated on the target's side. |
| 2265 | It's no use iterating through the conditions. */ |
| 2266 | return NULL; |
| 2267 | } |
| 2268 | END_CATCH |
| 2269 | |
| 2270 | /* We have a valid agent expression. */ |
| 2271 | return aexpr; |
| 2272 | } |
| 2273 | |
| 2274 | /* Based on location BL, create a list of breakpoint conditions to be |
| 2275 | passed on to the target. If we have duplicated locations with different |
| 2276 | conditions, we will add such conditions to the list. The idea is that the |
| 2277 | target will evaluate the list of conditions and will only notify GDB when |
| 2278 | one of them is true. */ |
| 2279 | |
| 2280 | static void |
| 2281 | build_target_condition_list (struct bp_location *bl) |
| 2282 | { |
| 2283 | struct bp_location **locp = NULL, **loc2p; |
| 2284 | int null_condition_or_parse_error = 0; |
| 2285 | int modified = bl->needs_update; |
| 2286 | struct bp_location *loc; |
| 2287 | |
| 2288 | /* Release conditions left over from a previous insert. */ |
| 2289 | VEC_free (agent_expr_p, bl->target_info.conditions); |
| 2290 | |
| 2291 | /* This is only meaningful if the target is |
| 2292 | evaluating conditions and if the user has |
| 2293 | opted for condition evaluation on the target's |
| 2294 | side. */ |
| 2295 | if (gdb_evaluates_breakpoint_condition_p () |
| 2296 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 2297 | return; |
| 2298 | |
| 2299 | /* Do a first pass to check for locations with no assigned |
| 2300 | conditions or conditions that fail to parse to a valid agent expression |
| 2301 | bytecode. If any of these happen, then it's no use to send conditions |
| 2302 | to the target since this location will always trigger and generate a |
| 2303 | response back to GDB. */ |
| 2304 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2305 | { |
| 2306 | loc = (*loc2p); |
| 2307 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2308 | { |
| 2309 | if (modified) |
| 2310 | { |
| 2311 | struct agent_expr *aexpr; |
| 2312 | |
| 2313 | /* Re-parse the conditions since something changed. In that |
| 2314 | case we already freed the condition bytecodes (see |
| 2315 | force_breakpoint_reinsertion). We just |
| 2316 | need to parse the condition to bytecodes again. */ |
| 2317 | aexpr = parse_cond_to_aexpr (bl->address, loc->cond); |
| 2318 | loc->cond_bytecode = aexpr; |
| 2319 | |
| 2320 | /* Check if we managed to parse the conditional expression |
| 2321 | correctly. If not, we will not send this condition |
| 2322 | to the target. */ |
| 2323 | if (aexpr) |
| 2324 | continue; |
| 2325 | } |
| 2326 | |
| 2327 | /* If we have a NULL bytecode expression, it means something |
| 2328 | went wrong or we have a null condition expression. */ |
| 2329 | if (!loc->cond_bytecode) |
| 2330 | { |
| 2331 | null_condition_or_parse_error = 1; |
| 2332 | break; |
| 2333 | } |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | /* If any of these happened, it means we will have to evaluate the conditions |
| 2338 | for the location's address on gdb's side. It is no use keeping bytecodes |
| 2339 | for all the other duplicate locations, thus we free all of them here. |
| 2340 | |
| 2341 | This is so we have a finer control over which locations' conditions are |
| 2342 | being evaluated by GDB or the remote stub. */ |
| 2343 | if (null_condition_or_parse_error) |
| 2344 | { |
| 2345 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2346 | { |
| 2347 | loc = (*loc2p); |
| 2348 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2349 | { |
| 2350 | /* Only go as far as the first NULL bytecode is |
| 2351 | located. */ |
| 2352 | if (!loc->cond_bytecode) |
| 2353 | return; |
| 2354 | |
| 2355 | free_agent_expr (loc->cond_bytecode); |
| 2356 | loc->cond_bytecode = NULL; |
| 2357 | } |
| 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | /* No NULL conditions or failed bytecode generation. Build a condition list |
| 2362 | for this location's address. */ |
| 2363 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2364 | { |
| 2365 | loc = (*loc2p); |
| 2366 | if (loc->cond |
| 2367 | && is_breakpoint (loc->owner) |
| 2368 | && loc->pspace->num == bl->pspace->num |
| 2369 | && loc->owner->enable_state == bp_enabled |
| 2370 | && loc->enabled) |
| 2371 | /* Add the condition to the vector. This will be used later to send the |
| 2372 | conditions to the target. */ |
| 2373 | VEC_safe_push (agent_expr_p, bl->target_info.conditions, |
| 2374 | loc->cond_bytecode); |
| 2375 | } |
| 2376 | |
| 2377 | return; |
| 2378 | } |
| 2379 | |
| 2380 | /* Parses a command described by string CMD into an agent expression |
| 2381 | bytecode suitable for evaluation by the bytecode interpreter. |
| 2382 | Return NULL if there was any error during parsing. */ |
| 2383 | |
| 2384 | static struct agent_expr * |
| 2385 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
| 2386 | { |
| 2387 | struct cleanup *old_cleanups = 0; |
| 2388 | struct expression *expr, **argvec; |
| 2389 | struct agent_expr *aexpr = NULL; |
| 2390 | const char *cmdrest; |
| 2391 | const char *format_start, *format_end; |
| 2392 | struct format_piece *fpieces; |
| 2393 | int nargs; |
| 2394 | struct gdbarch *gdbarch = get_current_arch (); |
| 2395 | |
| 2396 | if (!cmd) |
| 2397 | return NULL; |
| 2398 | |
| 2399 | cmdrest = cmd; |
| 2400 | |
| 2401 | if (*cmdrest == ',') |
| 2402 | ++cmdrest; |
| 2403 | cmdrest = skip_spaces_const (cmdrest); |
| 2404 | |
| 2405 | if (*cmdrest++ != '"') |
| 2406 | error (_("No format string following the location")); |
| 2407 | |
| 2408 | format_start = cmdrest; |
| 2409 | |
| 2410 | fpieces = parse_format_string (&cmdrest); |
| 2411 | |
| 2412 | old_cleanups = make_cleanup (free_format_pieces_cleanup, &fpieces); |
| 2413 | |
| 2414 | format_end = cmdrest; |
| 2415 | |
| 2416 | if (*cmdrest++ != '"') |
| 2417 | error (_("Bad format string, non-terminated '\"'.")); |
| 2418 | |
| 2419 | cmdrest = skip_spaces_const (cmdrest); |
| 2420 | |
| 2421 | if (!(*cmdrest == ',' || *cmdrest == '\0')) |
| 2422 | error (_("Invalid argument syntax")); |
| 2423 | |
| 2424 | if (*cmdrest == ',') |
| 2425 | cmdrest++; |
| 2426 | cmdrest = skip_spaces_const (cmdrest); |
| 2427 | |
| 2428 | /* For each argument, make an expression. */ |
| 2429 | |
| 2430 | argvec = (struct expression **) alloca (strlen (cmd) |
| 2431 | * sizeof (struct expression *)); |
| 2432 | |
| 2433 | nargs = 0; |
| 2434 | while (*cmdrest != '\0') |
| 2435 | { |
| 2436 | const char *cmd1; |
| 2437 | |
| 2438 | cmd1 = cmdrest; |
| 2439 | expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
| 2440 | argvec[nargs++] = expr; |
| 2441 | cmdrest = cmd1; |
| 2442 | if (*cmdrest == ',') |
| 2443 | ++cmdrest; |
| 2444 | } |
| 2445 | |
| 2446 | /* We don't want to stop processing, so catch any errors |
| 2447 | that may show up. */ |
| 2448 | TRY |
| 2449 | { |
| 2450 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
| 2451 | format_start, format_end - format_start, |
| 2452 | fpieces, nargs, argvec); |
| 2453 | } |
| 2454 | CATCH (ex, RETURN_MASK_ERROR) |
| 2455 | { |
| 2456 | /* If we got here, it means the command could not be parsed to a valid |
| 2457 | bytecode expression and thus can't be evaluated on the target's side. |
| 2458 | It's no use iterating through the other commands. */ |
| 2459 | aexpr = NULL; |
| 2460 | } |
| 2461 | END_CATCH |
| 2462 | |
| 2463 | do_cleanups (old_cleanups); |
| 2464 | |
| 2465 | /* We have a valid agent expression, return it. */ |
| 2466 | return aexpr; |
| 2467 | } |
| 2468 | |
| 2469 | /* Based on location BL, create a list of breakpoint commands to be |
| 2470 | passed on to the target. If we have duplicated locations with |
| 2471 | different commands, we will add any such to the list. */ |
| 2472 | |
| 2473 | static void |
| 2474 | build_target_command_list (struct bp_location *bl) |
| 2475 | { |
| 2476 | struct bp_location **locp = NULL, **loc2p; |
| 2477 | int null_command_or_parse_error = 0; |
| 2478 | int modified = bl->needs_update; |
| 2479 | struct bp_location *loc; |
| 2480 | |
| 2481 | /* Release commands left over from a previous insert. */ |
| 2482 | VEC_free (agent_expr_p, bl->target_info.tcommands); |
| 2483 | |
| 2484 | if (!target_can_run_breakpoint_commands ()) |
| 2485 | return; |
| 2486 | |
| 2487 | /* For now, limit to agent-style dprintf breakpoints. */ |
| 2488 | if (dprintf_style != dprintf_style_agent) |
| 2489 | return; |
| 2490 | |
| 2491 | /* For now, if we have any duplicate location that isn't a dprintf, |
| 2492 | don't install the target-side commands, as that would make the |
| 2493 | breakpoint not be reported to the core, and we'd lose |
| 2494 | control. */ |
| 2495 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2496 | { |
| 2497 | loc = (*loc2p); |
| 2498 | if (is_breakpoint (loc->owner) |
| 2499 | && loc->pspace->num == bl->pspace->num |
| 2500 | && loc->owner->type != bp_dprintf) |
| 2501 | return; |
| 2502 | } |
| 2503 | |
| 2504 | /* Do a first pass to check for locations with no assigned |
| 2505 | conditions or conditions that fail to parse to a valid agent expression |
| 2506 | bytecode. If any of these happen, then it's no use to send conditions |
| 2507 | to the target since this location will always trigger and generate a |
| 2508 | response back to GDB. */ |
| 2509 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2510 | { |
| 2511 | loc = (*loc2p); |
| 2512 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2513 | { |
| 2514 | if (modified) |
| 2515 | { |
| 2516 | struct agent_expr *aexpr; |
| 2517 | |
| 2518 | /* Re-parse the commands since something changed. In that |
| 2519 | case we already freed the command bytecodes (see |
| 2520 | force_breakpoint_reinsertion). We just |
| 2521 | need to parse the command to bytecodes again. */ |
| 2522 | aexpr = parse_cmd_to_aexpr (bl->address, |
| 2523 | loc->owner->extra_string); |
| 2524 | loc->cmd_bytecode = aexpr; |
| 2525 | |
| 2526 | if (!aexpr) |
| 2527 | continue; |
| 2528 | } |
| 2529 | |
| 2530 | /* If we have a NULL bytecode expression, it means something |
| 2531 | went wrong or we have a null command expression. */ |
| 2532 | if (!loc->cmd_bytecode) |
| 2533 | { |
| 2534 | null_command_or_parse_error = 1; |
| 2535 | break; |
| 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | /* If anything failed, then we're not doing target-side commands, |
| 2541 | and so clean up. */ |
| 2542 | if (null_command_or_parse_error) |
| 2543 | { |
| 2544 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2545 | { |
| 2546 | loc = (*loc2p); |
| 2547 | if (is_breakpoint (loc->owner) |
| 2548 | && loc->pspace->num == bl->pspace->num) |
| 2549 | { |
| 2550 | /* Only go as far as the first NULL bytecode is |
| 2551 | located. */ |
| 2552 | if (loc->cmd_bytecode == NULL) |
| 2553 | return; |
| 2554 | |
| 2555 | free_agent_expr (loc->cmd_bytecode); |
| 2556 | loc->cmd_bytecode = NULL; |
| 2557 | } |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | /* No NULL commands or failed bytecode generation. Build a command list |
| 2562 | for this location's address. */ |
| 2563 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2564 | { |
| 2565 | loc = (*loc2p); |
| 2566 | if (loc->owner->extra_string |
| 2567 | && is_breakpoint (loc->owner) |
| 2568 | && loc->pspace->num == bl->pspace->num |
| 2569 | && loc->owner->enable_state == bp_enabled |
| 2570 | && loc->enabled) |
| 2571 | /* Add the command to the vector. This will be used later |
| 2572 | to send the commands to the target. */ |
| 2573 | VEC_safe_push (agent_expr_p, bl->target_info.tcommands, |
| 2574 | loc->cmd_bytecode); |
| 2575 | } |
| 2576 | |
| 2577 | bl->target_info.persist = 0; |
| 2578 | /* Maybe flag this location as persistent. */ |
| 2579 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) |
| 2580 | bl->target_info.persist = 1; |
| 2581 | } |
| 2582 | |
| 2583 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
| 2584 | location. Any error messages are printed to TMP_ERROR_STREAM; and |
| 2585 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
| 2586 | Returns 0 for success, 1 if the bp_location type is not supported or |
| 2587 | -1 for failure. |
| 2588 | |
| 2589 | NOTE drow/2003-09-09: This routine could be broken down to an |
| 2590 | object-style method for each breakpoint or catchpoint type. */ |
| 2591 | static int |
| 2592 | insert_bp_location (struct bp_location *bl, |
| 2593 | struct ui_file *tmp_error_stream, |
| 2594 | int *disabled_breaks, |
| 2595 | int *hw_breakpoint_error, |
| 2596 | int *hw_bp_error_explained_already) |
| 2597 | { |
| 2598 | enum errors bp_err = GDB_NO_ERROR; |
| 2599 | const char *bp_err_message = NULL; |
| 2600 | |
| 2601 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
| 2602 | return 0; |
| 2603 | |
| 2604 | /* Note we don't initialize bl->target_info, as that wipes out |
| 2605 | the breakpoint location's shadow_contents if the breakpoint |
| 2606 | is still inserted at that location. This in turn breaks |
| 2607 | target_read_memory which depends on these buffers when |
| 2608 | a memory read is requested at the breakpoint location: |
| 2609 | Once the target_info has been wiped, we fail to see that |
| 2610 | we have a breakpoint inserted at that address and thus |
| 2611 | read the breakpoint instead of returning the data saved in |
| 2612 | the breakpoint location's shadow contents. */ |
| 2613 | bl->target_info.reqstd_address = bl->address; |
| 2614 | bl->target_info.placed_address_space = bl->pspace->aspace; |
| 2615 | bl->target_info.length = bl->length; |
| 2616 | |
| 2617 | /* When working with target-side conditions, we must pass all the conditions |
| 2618 | for the same breakpoint address down to the target since GDB will not |
| 2619 | insert those locations. With a list of breakpoint conditions, the target |
| 2620 | can decide when to stop and notify GDB. */ |
| 2621 | |
| 2622 | if (is_breakpoint (bl->owner)) |
| 2623 | { |
| 2624 | build_target_condition_list (bl); |
| 2625 | build_target_command_list (bl); |
| 2626 | /* Reset the modification marker. */ |
| 2627 | bl->needs_update = 0; |
| 2628 | } |
| 2629 | |
| 2630 | if (bl->loc_type == bp_loc_software_breakpoint |
| 2631 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 2632 | { |
| 2633 | if (bl->owner->type != bp_hardware_breakpoint) |
| 2634 | { |
| 2635 | /* If the explicitly specified breakpoint type |
| 2636 | is not hardware breakpoint, check the memory map to see |
| 2637 | if the breakpoint address is in read only memory or not. |
| 2638 | |
| 2639 | Two important cases are: |
| 2640 | - location type is not hardware breakpoint, memory |
| 2641 | is readonly. We change the type of the location to |
| 2642 | hardware breakpoint. |
| 2643 | - location type is hardware breakpoint, memory is |
| 2644 | read-write. This means we've previously made the |
| 2645 | location hardware one, but then the memory map changed, |
| 2646 | so we undo. |
| 2647 | |
| 2648 | When breakpoints are removed, remove_breakpoints will use |
| 2649 | location types we've just set here, the only possible |
| 2650 | problem is that memory map has changed during running |
| 2651 | program, but it's not going to work anyway with current |
| 2652 | gdb. */ |
| 2653 | struct mem_region *mr |
| 2654 | = lookup_mem_region (bl->target_info.reqstd_address); |
| 2655 | |
| 2656 | if (mr) |
| 2657 | { |
| 2658 | if (automatic_hardware_breakpoints) |
| 2659 | { |
| 2660 | enum bp_loc_type new_type; |
| 2661 | |
| 2662 | if (mr->attrib.mode != MEM_RW) |
| 2663 | new_type = bp_loc_hardware_breakpoint; |
| 2664 | else |
| 2665 | new_type = bp_loc_software_breakpoint; |
| 2666 | |
| 2667 | if (new_type != bl->loc_type) |
| 2668 | { |
| 2669 | static int said = 0; |
| 2670 | |
| 2671 | bl->loc_type = new_type; |
| 2672 | if (!said) |
| 2673 | { |
| 2674 | fprintf_filtered (gdb_stdout, |
| 2675 | _("Note: automatically using " |
| 2676 | "hardware breakpoints for " |
| 2677 | "read-only addresses.\n")); |
| 2678 | said = 1; |
| 2679 | } |
| 2680 | } |
| 2681 | } |
| 2682 | else if (bl->loc_type == bp_loc_software_breakpoint |
| 2683 | && mr->attrib.mode != MEM_RW) |
| 2684 | { |
| 2685 | fprintf_unfiltered (tmp_error_stream, |
| 2686 | _("Cannot insert breakpoint %d.\n" |
| 2687 | "Cannot set software breakpoint " |
| 2688 | "at read-only address %s\n"), |
| 2689 | bl->owner->number, |
| 2690 | paddress (bl->gdbarch, bl->address)); |
| 2691 | return 1; |
| 2692 | } |
| 2693 | } |
| 2694 | } |
| 2695 | |
| 2696 | /* First check to see if we have to handle an overlay. */ |
| 2697 | if (overlay_debugging == ovly_off |
| 2698 | || bl->section == NULL |
| 2699 | || !(section_is_overlay (bl->section))) |
| 2700 | { |
| 2701 | /* No overlay handling: just set the breakpoint. */ |
| 2702 | TRY |
| 2703 | { |
| 2704 | int val; |
| 2705 | |
| 2706 | val = bl->owner->ops->insert_location (bl); |
| 2707 | if (val) |
| 2708 | bp_err = GENERIC_ERROR; |
| 2709 | } |
| 2710 | CATCH (e, RETURN_MASK_ALL) |
| 2711 | { |
| 2712 | bp_err = e.error; |
| 2713 | bp_err_message = e.message; |
| 2714 | } |
| 2715 | END_CATCH |
| 2716 | } |
| 2717 | else |
| 2718 | { |
| 2719 | /* This breakpoint is in an overlay section. |
| 2720 | Shall we set a breakpoint at the LMA? */ |
| 2721 | if (!overlay_events_enabled) |
| 2722 | { |
| 2723 | /* Yes -- overlay event support is not active, |
| 2724 | so we must try to set a breakpoint at the LMA. |
| 2725 | This will not work for a hardware breakpoint. */ |
| 2726 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 2727 | warning (_("hardware breakpoint %d not supported in overlay!"), |
| 2728 | bl->owner->number); |
| 2729 | else |
| 2730 | { |
| 2731 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
| 2732 | bl->section); |
| 2733 | /* Set a software (trap) breakpoint at the LMA. */ |
| 2734 | bl->overlay_target_info = bl->target_info; |
| 2735 | bl->overlay_target_info.reqstd_address = addr; |
| 2736 | |
| 2737 | /* No overlay handling: just set the breakpoint. */ |
| 2738 | TRY |
| 2739 | { |
| 2740 | int val; |
| 2741 | |
| 2742 | val = target_insert_breakpoint (bl->gdbarch, |
| 2743 | &bl->overlay_target_info); |
| 2744 | if (val) |
| 2745 | bp_err = GENERIC_ERROR; |
| 2746 | } |
| 2747 | CATCH (e, RETURN_MASK_ALL) |
| 2748 | { |
| 2749 | bp_err = e.error; |
| 2750 | bp_err_message = e.message; |
| 2751 | } |
| 2752 | END_CATCH |
| 2753 | |
| 2754 | if (bp_err != GDB_NO_ERROR) |
| 2755 | fprintf_unfiltered (tmp_error_stream, |
| 2756 | "Overlay breakpoint %d " |
| 2757 | "failed: in ROM?\n", |
| 2758 | bl->owner->number); |
| 2759 | } |
| 2760 | } |
| 2761 | /* Shall we set a breakpoint at the VMA? */ |
| 2762 | if (section_is_mapped (bl->section)) |
| 2763 | { |
| 2764 | /* Yes. This overlay section is mapped into memory. */ |
| 2765 | TRY |
| 2766 | { |
| 2767 | int val; |
| 2768 | |
| 2769 | val = bl->owner->ops->insert_location (bl); |
| 2770 | if (val) |
| 2771 | bp_err = GENERIC_ERROR; |
| 2772 | } |
| 2773 | CATCH (e, RETURN_MASK_ALL) |
| 2774 | { |
| 2775 | bp_err = e.error; |
| 2776 | bp_err_message = e.message; |
| 2777 | } |
| 2778 | END_CATCH |
| 2779 | } |
| 2780 | else |
| 2781 | { |
| 2782 | /* No. This breakpoint will not be inserted. |
| 2783 | No error, but do not mark the bp as 'inserted'. */ |
| 2784 | return 0; |
| 2785 | } |
| 2786 | } |
| 2787 | |
| 2788 | if (bp_err != GDB_NO_ERROR) |
| 2789 | { |
| 2790 | /* Can't set the breakpoint. */ |
| 2791 | |
| 2792 | /* In some cases, we might not be able to insert a |
| 2793 | breakpoint in a shared library that has already been |
| 2794 | removed, but we have not yet processed the shlib unload |
| 2795 | event. Unfortunately, some targets that implement |
| 2796 | breakpoint insertion themselves can't tell why the |
| 2797 | breakpoint insertion failed (e.g., the remote target |
| 2798 | doesn't define error codes), so we must treat generic |
| 2799 | errors as memory errors. */ |
| 2800 | if ((bp_err == GENERIC_ERROR || bp_err == MEMORY_ERROR) |
| 2801 | && bl->loc_type == bp_loc_software_breakpoint |
| 2802 | && (solib_name_from_address (bl->pspace, bl->address) |
| 2803 | || shared_objfile_contains_address_p (bl->pspace, |
| 2804 | bl->address))) |
| 2805 | { |
| 2806 | /* See also: disable_breakpoints_in_shlibs. */ |
| 2807 | bl->shlib_disabled = 1; |
| 2808 | observer_notify_breakpoint_modified (bl->owner); |
| 2809 | if (!*disabled_breaks) |
| 2810 | { |
| 2811 | fprintf_unfiltered (tmp_error_stream, |
| 2812 | "Cannot insert breakpoint %d.\n", |
| 2813 | bl->owner->number); |
| 2814 | fprintf_unfiltered (tmp_error_stream, |
| 2815 | "Temporarily disabling shared " |
| 2816 | "library breakpoints:\n"); |
| 2817 | } |
| 2818 | *disabled_breaks = 1; |
| 2819 | fprintf_unfiltered (tmp_error_stream, |
| 2820 | "breakpoint #%d\n", bl->owner->number); |
| 2821 | return 0; |
| 2822 | } |
| 2823 | else |
| 2824 | { |
| 2825 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 2826 | { |
| 2827 | *hw_breakpoint_error = 1; |
| 2828 | *hw_bp_error_explained_already = bp_err_message != NULL; |
| 2829 | fprintf_unfiltered (tmp_error_stream, |
| 2830 | "Cannot insert hardware breakpoint %d%s", |
| 2831 | bl->owner->number, bp_err_message ? ":" : ".\n"); |
| 2832 | if (bp_err_message != NULL) |
| 2833 | fprintf_unfiltered (tmp_error_stream, "%s.\n", bp_err_message); |
| 2834 | } |
| 2835 | else |
| 2836 | { |
| 2837 | if (bp_err_message == NULL) |
| 2838 | { |
| 2839 | char *message |
| 2840 | = memory_error_message (TARGET_XFER_E_IO, |
| 2841 | bl->gdbarch, bl->address); |
| 2842 | struct cleanup *old_chain = make_cleanup (xfree, message); |
| 2843 | |
| 2844 | fprintf_unfiltered (tmp_error_stream, |
| 2845 | "Cannot insert breakpoint %d.\n" |
| 2846 | "%s\n", |
| 2847 | bl->owner->number, message); |
| 2848 | do_cleanups (old_chain); |
| 2849 | } |
| 2850 | else |
| 2851 | { |
| 2852 | fprintf_unfiltered (tmp_error_stream, |
| 2853 | "Cannot insert breakpoint %d: %s\n", |
| 2854 | bl->owner->number, |
| 2855 | bp_err_message); |
| 2856 | } |
| 2857 | } |
| 2858 | return 1; |
| 2859 | |
| 2860 | } |
| 2861 | } |
| 2862 | else |
| 2863 | bl->inserted = 1; |
| 2864 | |
| 2865 | return 0; |
| 2866 | } |
| 2867 | |
| 2868 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
| 2869 | /* NOTE drow/2003-09-08: This state only exists for removing |
| 2870 | watchpoints. It's not clear that it's necessary... */ |
| 2871 | && bl->owner->disposition != disp_del_at_next_stop) |
| 2872 | { |
| 2873 | int val; |
| 2874 | |
| 2875 | gdb_assert (bl->owner->ops != NULL |
| 2876 | && bl->owner->ops->insert_location != NULL); |
| 2877 | |
| 2878 | val = bl->owner->ops->insert_location (bl); |
| 2879 | |
| 2880 | /* If trying to set a read-watchpoint, and it turns out it's not |
| 2881 | supported, try emulating one with an access watchpoint. */ |
| 2882 | if (val == 1 && bl->watchpoint_type == hw_read) |
| 2883 | { |
| 2884 | struct bp_location *loc, **loc_temp; |
| 2885 | |
| 2886 | /* But don't try to insert it, if there's already another |
| 2887 | hw_access location that would be considered a duplicate |
| 2888 | of this one. */ |
| 2889 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 2890 | if (loc != bl |
| 2891 | && loc->watchpoint_type == hw_access |
| 2892 | && watchpoint_locations_match (bl, loc)) |
| 2893 | { |
| 2894 | bl->duplicate = 1; |
| 2895 | bl->inserted = 1; |
| 2896 | bl->target_info = loc->target_info; |
| 2897 | bl->watchpoint_type = hw_access; |
| 2898 | val = 0; |
| 2899 | break; |
| 2900 | } |
| 2901 | |
| 2902 | if (val == 1) |
| 2903 | { |
| 2904 | bl->watchpoint_type = hw_access; |
| 2905 | val = bl->owner->ops->insert_location (bl); |
| 2906 | |
| 2907 | if (val) |
| 2908 | /* Back to the original value. */ |
| 2909 | bl->watchpoint_type = hw_read; |
| 2910 | } |
| 2911 | } |
| 2912 | |
| 2913 | bl->inserted = (val == 0); |
| 2914 | } |
| 2915 | |
| 2916 | else if (bl->owner->type == bp_catchpoint) |
| 2917 | { |
| 2918 | int val; |
| 2919 | |
| 2920 | gdb_assert (bl->owner->ops != NULL |
| 2921 | && bl->owner->ops->insert_location != NULL); |
| 2922 | |
| 2923 | val = bl->owner->ops->insert_location (bl); |
| 2924 | if (val) |
| 2925 | { |
| 2926 | bl->owner->enable_state = bp_disabled; |
| 2927 | |
| 2928 | if (val == 1) |
| 2929 | warning (_("\ |
| 2930 | Error inserting catchpoint %d: Your system does not support this type\n\ |
| 2931 | of catchpoint."), bl->owner->number); |
| 2932 | else |
| 2933 | warning (_("Error inserting catchpoint %d."), bl->owner->number); |
| 2934 | } |
| 2935 | |
| 2936 | bl->inserted = (val == 0); |
| 2937 | |
| 2938 | /* We've already printed an error message if there was a problem |
| 2939 | inserting this catchpoint, and we've disabled the catchpoint, |
| 2940 | so just return success. */ |
| 2941 | return 0; |
| 2942 | } |
| 2943 | |
| 2944 | return 0; |
| 2945 | } |
| 2946 | |
| 2947 | /* This function is called when program space PSPACE is about to be |
| 2948 | deleted. It takes care of updating breakpoints to not reference |
| 2949 | PSPACE anymore. */ |
| 2950 | |
| 2951 | void |
| 2952 | breakpoint_program_space_exit (struct program_space *pspace) |
| 2953 | { |
| 2954 | struct breakpoint *b, *b_temp; |
| 2955 | struct bp_location *loc, **loc_temp; |
| 2956 | |
| 2957 | /* Remove any breakpoint that was set through this program space. */ |
| 2958 | ALL_BREAKPOINTS_SAFE (b, b_temp) |
| 2959 | { |
| 2960 | if (b->pspace == pspace) |
| 2961 | delete_breakpoint (b); |
| 2962 | } |
| 2963 | |
| 2964 | /* Breakpoints set through other program spaces could have locations |
| 2965 | bound to PSPACE as well. Remove those. */ |
| 2966 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 2967 | { |
| 2968 | struct bp_location *tmp; |
| 2969 | |
| 2970 | if (loc->pspace == pspace) |
| 2971 | { |
| 2972 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 2973 | if (loc->owner->loc == loc) |
| 2974 | loc->owner->loc = loc->next; |
| 2975 | else |
| 2976 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) |
| 2977 | if (tmp->next == loc) |
| 2978 | { |
| 2979 | tmp->next = loc->next; |
| 2980 | break; |
| 2981 | } |
| 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | /* Now update the global location list to permanently delete the |
| 2986 | removed locations above. */ |
| 2987 | update_global_location_list (UGLL_DONT_INSERT); |
| 2988 | } |
| 2989 | |
| 2990 | /* Make sure all breakpoints are inserted in inferior. |
| 2991 | Throws exception on any error. |
| 2992 | A breakpoint that is already inserted won't be inserted |
| 2993 | again, so calling this function twice is safe. */ |
| 2994 | void |
| 2995 | insert_breakpoints (void) |
| 2996 | { |
| 2997 | struct breakpoint *bpt; |
| 2998 | |
| 2999 | ALL_BREAKPOINTS (bpt) |
| 3000 | if (is_hardware_watchpoint (bpt)) |
| 3001 | { |
| 3002 | struct watchpoint *w = (struct watchpoint *) bpt; |
| 3003 | |
| 3004 | update_watchpoint (w, 0 /* don't reparse. */); |
| 3005 | } |
| 3006 | |
| 3007 | /* Updating watchpoints creates new locations, so update the global |
| 3008 | location list. Explicitly tell ugll to insert locations and |
| 3009 | ignore breakpoints_always_inserted_mode. */ |
| 3010 | update_global_location_list (UGLL_INSERT); |
| 3011 | } |
| 3012 | |
| 3013 | /* Invoke CALLBACK for each of bp_location. */ |
| 3014 | |
| 3015 | void |
| 3016 | iterate_over_bp_locations (walk_bp_location_callback callback) |
| 3017 | { |
| 3018 | struct bp_location *loc, **loc_tmp; |
| 3019 | |
| 3020 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 3021 | { |
| 3022 | callback (loc, NULL); |
| 3023 | } |
| 3024 | } |
| 3025 | |
| 3026 | /* This is used when we need to synch breakpoint conditions between GDB and the |
| 3027 | target. It is the case with deleting and disabling of breakpoints when using |
| 3028 | always-inserted mode. */ |
| 3029 | |
| 3030 | static void |
| 3031 | update_inserted_breakpoint_locations (void) |
| 3032 | { |
| 3033 | struct bp_location *bl, **blp_tmp; |
| 3034 | int error_flag = 0; |
| 3035 | int val = 0; |
| 3036 | int disabled_breaks = 0; |
| 3037 | int hw_breakpoint_error = 0; |
| 3038 | int hw_bp_details_reported = 0; |
| 3039 | |
| 3040 | struct ui_file *tmp_error_stream = mem_fileopen (); |
| 3041 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
| 3042 | |
| 3043 | /* Explicitly mark the warning -- this will only be printed if |
| 3044 | there was an error. */ |
| 3045 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); |
| 3046 | |
| 3047 | save_current_space_and_thread (); |
| 3048 | |
| 3049 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3050 | { |
| 3051 | /* We only want to update software breakpoints and hardware |
| 3052 | breakpoints. */ |
| 3053 | if (!is_breakpoint (bl->owner)) |
| 3054 | continue; |
| 3055 | |
| 3056 | /* We only want to update locations that are already inserted |
| 3057 | and need updating. This is to avoid unwanted insertion during |
| 3058 | deletion of breakpoints. */ |
| 3059 | if (!bl->inserted || (bl->inserted && !bl->needs_update)) |
| 3060 | continue; |
| 3061 | |
| 3062 | switch_to_program_space_and_thread (bl->pspace); |
| 3063 | |
| 3064 | /* For targets that support global breakpoints, there's no need |
| 3065 | to select an inferior to insert breakpoint to. In fact, even |
| 3066 | if we aren't attached to any process yet, we should still |
| 3067 | insert breakpoints. */ |
| 3068 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 3069 | && ptid_equal (inferior_ptid, null_ptid)) |
| 3070 | continue; |
| 3071 | |
| 3072 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
| 3073 | &hw_breakpoint_error, &hw_bp_details_reported); |
| 3074 | if (val) |
| 3075 | error_flag = val; |
| 3076 | } |
| 3077 | |
| 3078 | if (error_flag) |
| 3079 | { |
| 3080 | target_terminal_ours_for_output (); |
| 3081 | error_stream (tmp_error_stream); |
| 3082 | } |
| 3083 | |
| 3084 | do_cleanups (cleanups); |
| 3085 | } |
| 3086 | |
| 3087 | /* Used when starting or continuing the program. */ |
| 3088 | |
| 3089 | static void |
| 3090 | insert_breakpoint_locations (void) |
| 3091 | { |
| 3092 | struct breakpoint *bpt; |
| 3093 | struct bp_location *bl, **blp_tmp; |
| 3094 | int error_flag = 0; |
| 3095 | int val = 0; |
| 3096 | int disabled_breaks = 0; |
| 3097 | int hw_breakpoint_error = 0; |
| 3098 | int hw_bp_error_explained_already = 0; |
| 3099 | |
| 3100 | struct ui_file *tmp_error_stream = mem_fileopen (); |
| 3101 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
| 3102 | |
| 3103 | /* Explicitly mark the warning -- this will only be printed if |
| 3104 | there was an error. */ |
| 3105 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); |
| 3106 | |
| 3107 | save_current_space_and_thread (); |
| 3108 | |
| 3109 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3110 | { |
| 3111 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
| 3112 | continue; |
| 3113 | |
| 3114 | /* There is no point inserting thread-specific breakpoints if |
| 3115 | the thread no longer exists. ALL_BP_LOCATIONS bp_location |
| 3116 | has BL->OWNER always non-NULL. */ |
| 3117 | if (bl->owner->thread != -1 |
| 3118 | && !valid_thread_id (bl->owner->thread)) |
| 3119 | continue; |
| 3120 | |
| 3121 | switch_to_program_space_and_thread (bl->pspace); |
| 3122 | |
| 3123 | /* For targets that support global breakpoints, there's no need |
| 3124 | to select an inferior to insert breakpoint to. In fact, even |
| 3125 | if we aren't attached to any process yet, we should still |
| 3126 | insert breakpoints. */ |
| 3127 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 3128 | && ptid_equal (inferior_ptid, null_ptid)) |
| 3129 | continue; |
| 3130 | |
| 3131 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
| 3132 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
| 3133 | if (val) |
| 3134 | error_flag = val; |
| 3135 | } |
| 3136 | |
| 3137 | /* If we failed to insert all locations of a watchpoint, remove |
| 3138 | them, as half-inserted watchpoint is of limited use. */ |
| 3139 | ALL_BREAKPOINTS (bpt) |
| 3140 | { |
| 3141 | int some_failed = 0; |
| 3142 | struct bp_location *loc; |
| 3143 | |
| 3144 | if (!is_hardware_watchpoint (bpt)) |
| 3145 | continue; |
| 3146 | |
| 3147 | if (!breakpoint_enabled (bpt)) |
| 3148 | continue; |
| 3149 | |
| 3150 | if (bpt->disposition == disp_del_at_next_stop) |
| 3151 | continue; |
| 3152 | |
| 3153 | for (loc = bpt->loc; loc; loc = loc->next) |
| 3154 | if (!loc->inserted && should_be_inserted (loc)) |
| 3155 | { |
| 3156 | some_failed = 1; |
| 3157 | break; |
| 3158 | } |
| 3159 | if (some_failed) |
| 3160 | { |
| 3161 | for (loc = bpt->loc; loc; loc = loc->next) |
| 3162 | if (loc->inserted) |
| 3163 | remove_breakpoint (loc, mark_uninserted); |
| 3164 | |
| 3165 | hw_breakpoint_error = 1; |
| 3166 | fprintf_unfiltered (tmp_error_stream, |
| 3167 | "Could not insert hardware watchpoint %d.\n", |
| 3168 | bpt->number); |
| 3169 | error_flag = -1; |
| 3170 | } |
| 3171 | } |
| 3172 | |
| 3173 | if (error_flag) |
| 3174 | { |
| 3175 | /* If a hardware breakpoint or watchpoint was inserted, add a |
| 3176 | message about possibly exhausted resources. */ |
| 3177 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
| 3178 | { |
| 3179 | fprintf_unfiltered (tmp_error_stream, |
| 3180 | "Could not insert hardware breakpoints:\n\ |
| 3181 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
| 3182 | } |
| 3183 | target_terminal_ours_for_output (); |
| 3184 | error_stream (tmp_error_stream); |
| 3185 | } |
| 3186 | |
| 3187 | do_cleanups (cleanups); |
| 3188 | } |
| 3189 | |
| 3190 | /* Used when the program stops. |
| 3191 | Returns zero if successful, or non-zero if there was a problem |
| 3192 | removing a breakpoint location. */ |
| 3193 | |
| 3194 | int |
| 3195 | remove_breakpoints (void) |
| 3196 | { |
| 3197 | struct bp_location *bl, **blp_tmp; |
| 3198 | int val = 0; |
| 3199 | |
| 3200 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3201 | { |
| 3202 | if (bl->inserted && !is_tracepoint (bl->owner)) |
| 3203 | val |= remove_breakpoint (bl, mark_uninserted); |
| 3204 | } |
| 3205 | return val; |
| 3206 | } |
| 3207 | |
| 3208 | /* When a thread exits, remove breakpoints that are related to |
| 3209 | that thread. */ |
| 3210 | |
| 3211 | static void |
| 3212 | remove_threaded_breakpoints (struct thread_info *tp, int silent) |
| 3213 | { |
| 3214 | struct breakpoint *b, *b_tmp; |
| 3215 | |
| 3216 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3217 | { |
| 3218 | if (b->thread == tp->num && user_breakpoint_p (b)) |
| 3219 | { |
| 3220 | b->disposition = disp_del_at_next_stop; |
| 3221 | |
| 3222 | printf_filtered (_("\ |
| 3223 | Thread-specific breakpoint %d deleted - thread %d no longer in the thread list.\n"), |
| 3224 | b->number, tp->num); |
| 3225 | |
| 3226 | /* Hide it from the user. */ |
| 3227 | b->number = 0; |
| 3228 | } |
| 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | /* Remove breakpoints of process PID. */ |
| 3233 | |
| 3234 | int |
| 3235 | remove_breakpoints_pid (int pid) |
| 3236 | { |
| 3237 | struct bp_location *bl, **blp_tmp; |
| 3238 | int val; |
| 3239 | struct inferior *inf = find_inferior_pid (pid); |
| 3240 | |
| 3241 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3242 | { |
| 3243 | if (bl->pspace != inf->pspace) |
| 3244 | continue; |
| 3245 | |
| 3246 | if (bl->inserted && !bl->target_info.persist) |
| 3247 | { |
| 3248 | val = remove_breakpoint (bl, mark_uninserted); |
| 3249 | if (val != 0) |
| 3250 | return val; |
| 3251 | } |
| 3252 | } |
| 3253 | return 0; |
| 3254 | } |
| 3255 | |
| 3256 | int |
| 3257 | reattach_breakpoints (int pid) |
| 3258 | { |
| 3259 | struct cleanup *old_chain; |
| 3260 | struct bp_location *bl, **blp_tmp; |
| 3261 | int val; |
| 3262 | struct ui_file *tmp_error_stream; |
| 3263 | int dummy1 = 0, dummy2 = 0, dummy3 = 0; |
| 3264 | struct inferior *inf; |
| 3265 | struct thread_info *tp; |
| 3266 | |
| 3267 | tp = any_live_thread_of_process (pid); |
| 3268 | if (tp == NULL) |
| 3269 | return 1; |
| 3270 | |
| 3271 | inf = find_inferior_pid (pid); |
| 3272 | old_chain = save_inferior_ptid (); |
| 3273 | |
| 3274 | inferior_ptid = tp->ptid; |
| 3275 | |
| 3276 | tmp_error_stream = mem_fileopen (); |
| 3277 | make_cleanup_ui_file_delete (tmp_error_stream); |
| 3278 | |
| 3279 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3280 | { |
| 3281 | if (bl->pspace != inf->pspace) |
| 3282 | continue; |
| 3283 | |
| 3284 | if (bl->inserted) |
| 3285 | { |
| 3286 | bl->inserted = 0; |
| 3287 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2, &dummy3); |
| 3288 | if (val != 0) |
| 3289 | { |
| 3290 | do_cleanups (old_chain); |
| 3291 | return val; |
| 3292 | } |
| 3293 | } |
| 3294 | } |
| 3295 | do_cleanups (old_chain); |
| 3296 | return 0; |
| 3297 | } |
| 3298 | |
| 3299 | static int internal_breakpoint_number = -1; |
| 3300 | |
| 3301 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
| 3302 | If INTERNAL is non-zero, the breakpoint number will be populated |
| 3303 | from internal_breakpoint_number and that variable decremented. |
| 3304 | Otherwise the breakpoint number will be populated from |
| 3305 | breakpoint_count and that value incremented. Internal breakpoints |
| 3306 | do not set the internal var bpnum. */ |
| 3307 | static void |
| 3308 | set_breakpoint_number (int internal, struct breakpoint *b) |
| 3309 | { |
| 3310 | if (internal) |
| 3311 | b->number = internal_breakpoint_number--; |
| 3312 | else |
| 3313 | { |
| 3314 | set_breakpoint_count (breakpoint_count + 1); |
| 3315 | b->number = breakpoint_count; |
| 3316 | } |
| 3317 | } |
| 3318 | |
| 3319 | static struct breakpoint * |
| 3320 | create_internal_breakpoint (struct gdbarch *gdbarch, |
| 3321 | CORE_ADDR address, enum bptype type, |
| 3322 | const struct breakpoint_ops *ops) |
| 3323 | { |
| 3324 | struct symtab_and_line sal; |
| 3325 | struct breakpoint *b; |
| 3326 | |
| 3327 | init_sal (&sal); /* Initialize to zeroes. */ |
| 3328 | |
| 3329 | sal.pc = address; |
| 3330 | sal.section = find_pc_overlay (sal.pc); |
| 3331 | sal.pspace = current_program_space; |
| 3332 | |
| 3333 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
| 3334 | b->number = internal_breakpoint_number--; |
| 3335 | b->disposition = disp_donttouch; |
| 3336 | |
| 3337 | return b; |
| 3338 | } |
| 3339 | |
| 3340 | static const char *const longjmp_names[] = |
| 3341 | { |
| 3342 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" |
| 3343 | }; |
| 3344 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) |
| 3345 | |
| 3346 | /* Per-objfile data private to breakpoint.c. */ |
| 3347 | struct breakpoint_objfile_data |
| 3348 | { |
| 3349 | /* Minimal symbol for "_ovly_debug_event" (if any). */ |
| 3350 | struct bound_minimal_symbol overlay_msym; |
| 3351 | |
| 3352 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ |
| 3353 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES]; |
| 3354 | |
| 3355 | /* True if we have looked for longjmp probes. */ |
| 3356 | int longjmp_searched; |
| 3357 | |
| 3358 | /* SystemTap probe points for longjmp (if any). */ |
| 3359 | VEC (probe_p) *longjmp_probes; |
| 3360 | |
| 3361 | /* Minimal symbol for "std::terminate()" (if any). */ |
| 3362 | struct bound_minimal_symbol terminate_msym; |
| 3363 | |
| 3364 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ |
| 3365 | struct bound_minimal_symbol exception_msym; |
| 3366 | |
| 3367 | /* True if we have looked for exception probes. */ |
| 3368 | int exception_searched; |
| 3369 | |
| 3370 | /* SystemTap probe points for unwinding (if any). */ |
| 3371 | VEC (probe_p) *exception_probes; |
| 3372 | }; |
| 3373 | |
| 3374 | static const struct objfile_data *breakpoint_objfile_key; |
| 3375 | |
| 3376 | /* Minimal symbol not found sentinel. */ |
| 3377 | static struct minimal_symbol msym_not_found; |
| 3378 | |
| 3379 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ |
| 3380 | |
| 3381 | static int |
| 3382 | msym_not_found_p (const struct minimal_symbol *msym) |
| 3383 | { |
| 3384 | return msym == &msym_not_found; |
| 3385 | } |
| 3386 | |
| 3387 | /* Return per-objfile data needed by breakpoint.c. |
| 3388 | Allocate the data if necessary. */ |
| 3389 | |
| 3390 | static struct breakpoint_objfile_data * |
| 3391 | get_breakpoint_objfile_data (struct objfile *objfile) |
| 3392 | { |
| 3393 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3394 | |
| 3395 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); |
| 3396 | if (bp_objfile_data == NULL) |
| 3397 | { |
| 3398 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, |
| 3399 | sizeof (*bp_objfile_data)); |
| 3400 | |
| 3401 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); |
| 3402 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); |
| 3403 | } |
| 3404 | return bp_objfile_data; |
| 3405 | } |
| 3406 | |
| 3407 | static void |
| 3408 | free_breakpoint_probes (struct objfile *obj, void *data) |
| 3409 | { |
| 3410 | struct breakpoint_objfile_data *bp_objfile_data = data; |
| 3411 | |
| 3412 | VEC_free (probe_p, bp_objfile_data->longjmp_probes); |
| 3413 | VEC_free (probe_p, bp_objfile_data->exception_probes); |
| 3414 | } |
| 3415 | |
| 3416 | static void |
| 3417 | create_overlay_event_breakpoint (void) |
| 3418 | { |
| 3419 | struct objfile *objfile; |
| 3420 | const char *const func_name = "_ovly_debug_event"; |
| 3421 | |
| 3422 | ALL_OBJFILES (objfile) |
| 3423 | { |
| 3424 | struct breakpoint *b; |
| 3425 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3426 | CORE_ADDR addr; |
| 3427 | char *p; |
| 3428 | |
| 3429 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3430 | |
| 3431 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
| 3432 | continue; |
| 3433 | |
| 3434 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
| 3435 | { |
| 3436 | struct bound_minimal_symbol m; |
| 3437 | |
| 3438 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 3439 | if (m.minsym == NULL) |
| 3440 | { |
| 3441 | /* Avoid future lookups in this objfile. */ |
| 3442 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
| 3443 | continue; |
| 3444 | } |
| 3445 | bp_objfile_data->overlay_msym = m; |
| 3446 | } |
| 3447 | |
| 3448 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
| 3449 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
| 3450 | bp_overlay_event, |
| 3451 | &internal_breakpoint_ops); |
| 3452 | p = ASTRDUP (func_name); |
| 3453 | b->location = new_linespec_location (&p); |
| 3454 | |
| 3455 | if (overlay_debugging == ovly_auto) |
| 3456 | { |
| 3457 | b->enable_state = bp_enabled; |
| 3458 | overlay_events_enabled = 1; |
| 3459 | } |
| 3460 | else |
| 3461 | { |
| 3462 | b->enable_state = bp_disabled; |
| 3463 | overlay_events_enabled = 0; |
| 3464 | } |
| 3465 | } |
| 3466 | update_global_location_list (UGLL_MAY_INSERT); |
| 3467 | } |
| 3468 | |
| 3469 | static void |
| 3470 | create_longjmp_master_breakpoint (void) |
| 3471 | { |
| 3472 | struct program_space *pspace; |
| 3473 | struct cleanup *old_chain; |
| 3474 | |
| 3475 | old_chain = save_current_program_space (); |
| 3476 | |
| 3477 | ALL_PSPACES (pspace) |
| 3478 | { |
| 3479 | struct objfile *objfile; |
| 3480 | |
| 3481 | set_current_program_space (pspace); |
| 3482 | |
| 3483 | ALL_OBJFILES (objfile) |
| 3484 | { |
| 3485 | int i; |
| 3486 | struct gdbarch *gdbarch; |
| 3487 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3488 | |
| 3489 | gdbarch = get_objfile_arch (objfile); |
| 3490 | |
| 3491 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3492 | |
| 3493 | if (!bp_objfile_data->longjmp_searched) |
| 3494 | { |
| 3495 | VEC (probe_p) *ret; |
| 3496 | |
| 3497 | ret = find_probes_in_objfile (objfile, "libc", "longjmp"); |
| 3498 | if (ret != NULL) |
| 3499 | { |
| 3500 | /* We are only interested in checking one element. */ |
| 3501 | struct probe *p = VEC_index (probe_p, ret, 0); |
| 3502 | |
| 3503 | if (!can_evaluate_probe_arguments (p)) |
| 3504 | { |
| 3505 | /* We cannot use the probe interface here, because it does |
| 3506 | not know how to evaluate arguments. */ |
| 3507 | VEC_free (probe_p, ret); |
| 3508 | ret = NULL; |
| 3509 | } |
| 3510 | } |
| 3511 | bp_objfile_data->longjmp_probes = ret; |
| 3512 | bp_objfile_data->longjmp_searched = 1; |
| 3513 | } |
| 3514 | |
| 3515 | if (bp_objfile_data->longjmp_probes != NULL) |
| 3516 | { |
| 3517 | int i; |
| 3518 | struct probe *probe; |
| 3519 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 3520 | |
| 3521 | for (i = 0; |
| 3522 | VEC_iterate (probe_p, |
| 3523 | bp_objfile_data->longjmp_probes, |
| 3524 | i, probe); |
| 3525 | ++i) |
| 3526 | { |
| 3527 | struct breakpoint *b; |
| 3528 | |
| 3529 | b = create_internal_breakpoint (gdbarch, |
| 3530 | get_probe_address (probe, |
| 3531 | objfile), |
| 3532 | bp_longjmp_master, |
| 3533 | &internal_breakpoint_ops); |
| 3534 | b->location |
| 3535 | = new_probe_location ("-probe-stap libc:longjmp"); |
| 3536 | b->enable_state = bp_disabled; |
| 3537 | } |
| 3538 | |
| 3539 | continue; |
| 3540 | } |
| 3541 | |
| 3542 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
| 3543 | continue; |
| 3544 | |
| 3545 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
| 3546 | { |
| 3547 | struct breakpoint *b; |
| 3548 | const char *func_name; |
| 3549 | CORE_ADDR addr; |
| 3550 | char *p; |
| 3551 | |
| 3552 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
| 3553 | continue; |
| 3554 | |
| 3555 | func_name = longjmp_names[i]; |
| 3556 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
| 3557 | { |
| 3558 | struct bound_minimal_symbol m; |
| 3559 | |
| 3560 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 3561 | if (m.minsym == NULL) |
| 3562 | { |
| 3563 | /* Prevent future lookups in this objfile. */ |
| 3564 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
| 3565 | continue; |
| 3566 | } |
| 3567 | bp_objfile_data->longjmp_msym[i] = m; |
| 3568 | } |
| 3569 | |
| 3570 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
| 3571 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
| 3572 | &internal_breakpoint_ops); |
| 3573 | p = ASTRDUP (func_name); |
| 3574 | b->location = new_linespec_location (&p); |
| 3575 | b->enable_state = bp_disabled; |
| 3576 | } |
| 3577 | } |
| 3578 | } |
| 3579 | update_global_location_list (UGLL_MAY_INSERT); |
| 3580 | |
| 3581 | do_cleanups (old_chain); |
| 3582 | } |
| 3583 | |
| 3584 | /* Create a master std::terminate breakpoint. */ |
| 3585 | static void |
| 3586 | create_std_terminate_master_breakpoint (void) |
| 3587 | { |
| 3588 | struct program_space *pspace; |
| 3589 | struct cleanup *old_chain; |
| 3590 | const char *const func_name = "std::terminate()"; |
| 3591 | |
| 3592 | old_chain = save_current_program_space (); |
| 3593 | |
| 3594 | ALL_PSPACES (pspace) |
| 3595 | { |
| 3596 | struct objfile *objfile; |
| 3597 | CORE_ADDR addr; |
| 3598 | |
| 3599 | set_current_program_space (pspace); |
| 3600 | |
| 3601 | ALL_OBJFILES (objfile) |
| 3602 | { |
| 3603 | struct breakpoint *b; |
| 3604 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3605 | char *p; |
| 3606 | |
| 3607 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3608 | |
| 3609 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
| 3610 | continue; |
| 3611 | |
| 3612 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
| 3613 | { |
| 3614 | struct bound_minimal_symbol m; |
| 3615 | |
| 3616 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
| 3617 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
| 3618 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) |
| 3619 | { |
| 3620 | /* Prevent future lookups in this objfile. */ |
| 3621 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
| 3622 | continue; |
| 3623 | } |
| 3624 | bp_objfile_data->terminate_msym = m; |
| 3625 | } |
| 3626 | |
| 3627 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
| 3628 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
| 3629 | bp_std_terminate_master, |
| 3630 | &internal_breakpoint_ops); |
| 3631 | p = ASTRDUP (func_name); |
| 3632 | b->location = new_linespec_location (&p); |
| 3633 | b->enable_state = bp_disabled; |
| 3634 | } |
| 3635 | } |
| 3636 | |
| 3637 | update_global_location_list (UGLL_MAY_INSERT); |
| 3638 | |
| 3639 | do_cleanups (old_chain); |
| 3640 | } |
| 3641 | |
| 3642 | /* Install a master breakpoint on the unwinder's debug hook. */ |
| 3643 | |
| 3644 | static void |
| 3645 | create_exception_master_breakpoint (void) |
| 3646 | { |
| 3647 | struct objfile *objfile; |
| 3648 | const char *const func_name = "_Unwind_DebugHook"; |
| 3649 | |
| 3650 | ALL_OBJFILES (objfile) |
| 3651 | { |
| 3652 | struct breakpoint *b; |
| 3653 | struct gdbarch *gdbarch; |
| 3654 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3655 | CORE_ADDR addr; |
| 3656 | char *p; |
| 3657 | |
| 3658 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3659 | |
| 3660 | /* We prefer the SystemTap probe point if it exists. */ |
| 3661 | if (!bp_objfile_data->exception_searched) |
| 3662 | { |
| 3663 | VEC (probe_p) *ret; |
| 3664 | |
| 3665 | ret = find_probes_in_objfile (objfile, "libgcc", "unwind"); |
| 3666 | |
| 3667 | if (ret != NULL) |
| 3668 | { |
| 3669 | /* We are only interested in checking one element. */ |
| 3670 | struct probe *p = VEC_index (probe_p, ret, 0); |
| 3671 | |
| 3672 | if (!can_evaluate_probe_arguments (p)) |
| 3673 | { |
| 3674 | /* We cannot use the probe interface here, because it does |
| 3675 | not know how to evaluate arguments. */ |
| 3676 | VEC_free (probe_p, ret); |
| 3677 | ret = NULL; |
| 3678 | } |
| 3679 | } |
| 3680 | bp_objfile_data->exception_probes = ret; |
| 3681 | bp_objfile_data->exception_searched = 1; |
| 3682 | } |
| 3683 | |
| 3684 | if (bp_objfile_data->exception_probes != NULL) |
| 3685 | { |
| 3686 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 3687 | int i; |
| 3688 | struct probe *probe; |
| 3689 | |
| 3690 | for (i = 0; |
| 3691 | VEC_iterate (probe_p, |
| 3692 | bp_objfile_data->exception_probes, |
| 3693 | i, probe); |
| 3694 | ++i) |
| 3695 | { |
| 3696 | struct breakpoint *b; |
| 3697 | |
| 3698 | b = create_internal_breakpoint (gdbarch, |
| 3699 | get_probe_address (probe, |
| 3700 | objfile), |
| 3701 | bp_exception_master, |
| 3702 | &internal_breakpoint_ops); |
| 3703 | b->location |
| 3704 | = new_probe_location ("-probe-stap libgcc:unwind"); |
| 3705 | b->enable_state = bp_disabled; |
| 3706 | } |
| 3707 | |
| 3708 | continue; |
| 3709 | } |
| 3710 | |
| 3711 | /* Otherwise, try the hook function. */ |
| 3712 | |
| 3713 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
| 3714 | continue; |
| 3715 | |
| 3716 | gdbarch = get_objfile_arch (objfile); |
| 3717 | |
| 3718 | if (bp_objfile_data->exception_msym.minsym == NULL) |
| 3719 | { |
| 3720 | struct bound_minimal_symbol debug_hook; |
| 3721 | |
| 3722 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
| 3723 | if (debug_hook.minsym == NULL) |
| 3724 | { |
| 3725 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
| 3726 | continue; |
| 3727 | } |
| 3728 | |
| 3729 | bp_objfile_data->exception_msym = debug_hook; |
| 3730 | } |
| 3731 | |
| 3732 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
| 3733 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
| 3734 | ¤t_target); |
| 3735 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
| 3736 | &internal_breakpoint_ops); |
| 3737 | p = ASTRDUP (func_name); |
| 3738 | b->location = new_linespec_location (&p); |
| 3739 | b->enable_state = bp_disabled; |
| 3740 | } |
| 3741 | |
| 3742 | update_global_location_list (UGLL_MAY_INSERT); |
| 3743 | } |
| 3744 | |
| 3745 | void |
| 3746 | update_breakpoints_after_exec (void) |
| 3747 | { |
| 3748 | struct breakpoint *b, *b_tmp; |
| 3749 | struct bp_location *bploc, **bplocp_tmp; |
| 3750 | |
| 3751 | /* We're about to delete breakpoints from GDB's lists. If the |
| 3752 | INSERTED flag is true, GDB will try to lift the breakpoints by |
| 3753 | writing the breakpoints' "shadow contents" back into memory. The |
| 3754 | "shadow contents" are NOT valid after an exec, so GDB should not |
| 3755 | do that. Instead, the target is responsible from marking |
| 3756 | breakpoints out as soon as it detects an exec. We don't do that |
| 3757 | here instead, because there may be other attempts to delete |
| 3758 | breakpoints after detecting an exec and before reaching here. */ |
| 3759 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
| 3760 | if (bploc->pspace == current_program_space) |
| 3761 | gdb_assert (!bploc->inserted); |
| 3762 | |
| 3763 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3764 | { |
| 3765 | if (b->pspace != current_program_space) |
| 3766 | continue; |
| 3767 | |
| 3768 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
| 3769 | if (b->type == bp_shlib_event) |
| 3770 | { |
| 3771 | delete_breakpoint (b); |
| 3772 | continue; |
| 3773 | } |
| 3774 | |
| 3775 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
| 3776 | if (b->type == bp_jit_event) |
| 3777 | { |
| 3778 | delete_breakpoint (b); |
| 3779 | continue; |
| 3780 | } |
| 3781 | |
| 3782 | /* Thread event breakpoints must be set anew after an exec(), |
| 3783 | as must overlay event and longjmp master breakpoints. */ |
| 3784 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
| 3785 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
| 3786 | || b->type == bp_exception_master) |
| 3787 | { |
| 3788 | delete_breakpoint (b); |
| 3789 | continue; |
| 3790 | } |
| 3791 | |
| 3792 | /* Step-resume breakpoints are meaningless after an exec(). */ |
| 3793 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
| 3794 | { |
| 3795 | delete_breakpoint (b); |
| 3796 | continue; |
| 3797 | } |
| 3798 | |
| 3799 | /* Just like single-step breakpoints. */ |
| 3800 | if (b->type == bp_single_step) |
| 3801 | { |
| 3802 | delete_breakpoint (b); |
| 3803 | continue; |
| 3804 | } |
| 3805 | |
| 3806 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
| 3807 | after an exec. */ |
| 3808 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
| 3809 | || b->type == bp_longjmp_call_dummy |
| 3810 | || b->type == bp_exception || b->type == bp_exception_resume) |
| 3811 | { |
| 3812 | delete_breakpoint (b); |
| 3813 | continue; |
| 3814 | } |
| 3815 | |
| 3816 | if (b->type == bp_catchpoint) |
| 3817 | { |
| 3818 | /* For now, none of the bp_catchpoint breakpoints need to |
| 3819 | do anything at this point. In the future, if some of |
| 3820 | the catchpoints need to something, we will need to add |
| 3821 | a new method, and call this method from here. */ |
| 3822 | continue; |
| 3823 | } |
| 3824 | |
| 3825 | /* bp_finish is a special case. The only way we ought to be able |
| 3826 | to see one of these when an exec() has happened, is if the user |
| 3827 | caught a vfork, and then said "finish". Ordinarily a finish just |
| 3828 | carries them to the call-site of the current callee, by setting |
| 3829 | a temporary bp there and resuming. But in this case, the finish |
| 3830 | will carry them entirely through the vfork & exec. |
| 3831 | |
| 3832 | We don't want to allow a bp_finish to remain inserted now. But |
| 3833 | we can't safely delete it, 'cause finish_command has a handle to |
| 3834 | the bp on a bpstat, and will later want to delete it. There's a |
| 3835 | chance (and I've seen it happen) that if we delete the bp_finish |
| 3836 | here, that its storage will get reused by the time finish_command |
| 3837 | gets 'round to deleting the "use to be a bp_finish" breakpoint. |
| 3838 | We really must allow finish_command to delete a bp_finish. |
| 3839 | |
| 3840 | In the absence of a general solution for the "how do we know |
| 3841 | it's safe to delete something others may have handles to?" |
| 3842 | problem, what we'll do here is just uninsert the bp_finish, and |
| 3843 | let finish_command delete it. |
| 3844 | |
| 3845 | (We know the bp_finish is "doomed" in the sense that it's |
| 3846 | momentary, and will be deleted as soon as finish_command sees |
| 3847 | the inferior stopped. So it doesn't matter that the bp's |
| 3848 | address is probably bogus in the new a.out, unlike e.g., the |
| 3849 | solib breakpoints.) */ |
| 3850 | |
| 3851 | if (b->type == bp_finish) |
| 3852 | { |
| 3853 | continue; |
| 3854 | } |
| 3855 | |
| 3856 | /* Without a symbolic address, we have little hope of the |
| 3857 | pre-exec() address meaning the same thing in the post-exec() |
| 3858 | a.out. */ |
| 3859 | if (event_location_empty_p (b->location)) |
| 3860 | { |
| 3861 | delete_breakpoint (b); |
| 3862 | continue; |
| 3863 | } |
| 3864 | } |
| 3865 | } |
| 3866 | |
| 3867 | int |
| 3868 | detach_breakpoints (ptid_t ptid) |
| 3869 | { |
| 3870 | struct bp_location *bl, **blp_tmp; |
| 3871 | int val = 0; |
| 3872 | struct cleanup *old_chain = save_inferior_ptid (); |
| 3873 | struct inferior *inf = current_inferior (); |
| 3874 | |
| 3875 | if (ptid_get_pid (ptid) == ptid_get_pid (inferior_ptid)) |
| 3876 | error (_("Cannot detach breakpoints of inferior_ptid")); |
| 3877 | |
| 3878 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
| 3879 | inferior_ptid = ptid; |
| 3880 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3881 | { |
| 3882 | if (bl->pspace != inf->pspace) |
| 3883 | continue; |
| 3884 | |
| 3885 | /* This function must physically remove breakpoints locations |
| 3886 | from the specified ptid, without modifying the breakpoint |
| 3887 | package's state. Locations of type bp_loc_other are only |
| 3888 | maintained at GDB side. So, there is no need to remove |
| 3889 | these bp_loc_other locations. Moreover, removing these |
| 3890 | would modify the breakpoint package's state. */ |
| 3891 | if (bl->loc_type == bp_loc_other) |
| 3892 | continue; |
| 3893 | |
| 3894 | if (bl->inserted) |
| 3895 | val |= remove_breakpoint_1 (bl, mark_inserted); |
| 3896 | } |
| 3897 | |
| 3898 | do_cleanups (old_chain); |
| 3899 | return val; |
| 3900 | } |
| 3901 | |
| 3902 | /* Remove the breakpoint location BL from the current address space. |
| 3903 | Note that this is used to detach breakpoints from a child fork. |
| 3904 | When we get here, the child isn't in the inferior list, and neither |
| 3905 | do we have objects to represent its address space --- we should |
| 3906 | *not* look at bl->pspace->aspace here. */ |
| 3907 | |
| 3908 | static int |
| 3909 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
| 3910 | { |
| 3911 | int val; |
| 3912 | |
| 3913 | /* BL is never in moribund_locations by our callers. */ |
| 3914 | gdb_assert (bl->owner != NULL); |
| 3915 | |
| 3916 | /* The type of none suggests that owner is actually deleted. |
| 3917 | This should not ever happen. */ |
| 3918 | gdb_assert (bl->owner->type != bp_none); |
| 3919 | |
| 3920 | if (bl->loc_type == bp_loc_software_breakpoint |
| 3921 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 3922 | { |
| 3923 | /* "Normal" instruction breakpoint: either the standard |
| 3924 | trap-instruction bp (bp_breakpoint), or a |
| 3925 | bp_hardware_breakpoint. */ |
| 3926 | |
| 3927 | /* First check to see if we have to handle an overlay. */ |
| 3928 | if (overlay_debugging == ovly_off |
| 3929 | || bl->section == NULL |
| 3930 | || !(section_is_overlay (bl->section))) |
| 3931 | { |
| 3932 | /* No overlay handling: just remove the breakpoint. */ |
| 3933 | |
| 3934 | /* If we're trying to uninsert a memory breakpoint that we |
| 3935 | know is set in a dynamic object that is marked |
| 3936 | shlib_disabled, then either the dynamic object was |
| 3937 | removed with "remove-symbol-file" or with |
| 3938 | "nosharedlibrary". In the former case, we don't know |
| 3939 | whether another dynamic object might have loaded over the |
| 3940 | breakpoint's address -- the user might well let us know |
| 3941 | about it next with add-symbol-file (the whole point of |
| 3942 | add-symbol-file is letting the user manually maintain a |
| 3943 | list of dynamically loaded objects). If we have the |
| 3944 | breakpoint's shadow memory, that is, this is a software |
| 3945 | breakpoint managed by GDB, check whether the breakpoint |
| 3946 | is still inserted in memory, to avoid overwriting wrong |
| 3947 | code with stale saved shadow contents. Note that HW |
| 3948 | breakpoints don't have shadow memory, as they're |
| 3949 | implemented using a mechanism that is not dependent on |
| 3950 | being able to modify the target's memory, and as such |
| 3951 | they should always be removed. */ |
| 3952 | if (bl->shlib_disabled |
| 3953 | && bl->target_info.shadow_len != 0 |
| 3954 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) |
| 3955 | val = 0; |
| 3956 | else |
| 3957 | val = bl->owner->ops->remove_location (bl); |
| 3958 | } |
| 3959 | else |
| 3960 | { |
| 3961 | /* This breakpoint is in an overlay section. |
| 3962 | Did we set a breakpoint at the LMA? */ |
| 3963 | if (!overlay_events_enabled) |
| 3964 | { |
| 3965 | /* Yes -- overlay event support is not active, so we |
| 3966 | should have set a breakpoint at the LMA. Remove it. |
| 3967 | */ |
| 3968 | /* Ignore any failures: if the LMA is in ROM, we will |
| 3969 | have already warned when we failed to insert it. */ |
| 3970 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 3971 | target_remove_hw_breakpoint (bl->gdbarch, |
| 3972 | &bl->overlay_target_info); |
| 3973 | else |
| 3974 | target_remove_breakpoint (bl->gdbarch, |
| 3975 | &bl->overlay_target_info); |
| 3976 | } |
| 3977 | /* Did we set a breakpoint at the VMA? |
| 3978 | If so, we will have marked the breakpoint 'inserted'. */ |
| 3979 | if (bl->inserted) |
| 3980 | { |
| 3981 | /* Yes -- remove it. Previously we did not bother to |
| 3982 | remove the breakpoint if the section had been |
| 3983 | unmapped, but let's not rely on that being safe. We |
| 3984 | don't know what the overlay manager might do. */ |
| 3985 | |
| 3986 | /* However, we should remove *software* breakpoints only |
| 3987 | if the section is still mapped, or else we overwrite |
| 3988 | wrong code with the saved shadow contents. */ |
| 3989 | if (bl->loc_type == bp_loc_hardware_breakpoint |
| 3990 | || section_is_mapped (bl->section)) |
| 3991 | val = bl->owner->ops->remove_location (bl); |
| 3992 | else |
| 3993 | val = 0; |
| 3994 | } |
| 3995 | else |
| 3996 | { |
| 3997 | /* No -- not inserted, so no need to remove. No error. */ |
| 3998 | val = 0; |
| 3999 | } |
| 4000 | } |
| 4001 | |
| 4002 | /* In some cases, we might not be able to remove a breakpoint in |
| 4003 | a shared library that has already been removed, but we have |
| 4004 | not yet processed the shlib unload event. Similarly for an |
| 4005 | unloaded add-symbol-file object - the user might not yet have |
| 4006 | had the chance to remove-symbol-file it. shlib_disabled will |
| 4007 | be set if the library/object has already been removed, but |
| 4008 | the breakpoint hasn't been uninserted yet, e.g., after |
| 4009 | "nosharedlibrary" or "remove-symbol-file" with breakpoints |
| 4010 | always-inserted mode. */ |
| 4011 | if (val |
| 4012 | && (bl->loc_type == bp_loc_software_breakpoint |
| 4013 | && (bl->shlib_disabled |
| 4014 | || solib_name_from_address (bl->pspace, bl->address) |
| 4015 | || shared_objfile_contains_address_p (bl->pspace, |
| 4016 | bl->address)))) |
| 4017 | val = 0; |
| 4018 | |
| 4019 | if (val) |
| 4020 | return val; |
| 4021 | bl->inserted = (is == mark_inserted); |
| 4022 | } |
| 4023 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
| 4024 | { |
| 4025 | gdb_assert (bl->owner->ops != NULL |
| 4026 | && bl->owner->ops->remove_location != NULL); |
| 4027 | |
| 4028 | bl->inserted = (is == mark_inserted); |
| 4029 | bl->owner->ops->remove_location (bl); |
| 4030 | |
| 4031 | /* Failure to remove any of the hardware watchpoints comes here. */ |
| 4032 | if ((is == mark_uninserted) && (bl->inserted)) |
| 4033 | warning (_("Could not remove hardware watchpoint %d."), |
| 4034 | bl->owner->number); |
| 4035 | } |
| 4036 | else if (bl->owner->type == bp_catchpoint |
| 4037 | && breakpoint_enabled (bl->owner) |
| 4038 | && !bl->duplicate) |
| 4039 | { |
| 4040 | gdb_assert (bl->owner->ops != NULL |
| 4041 | && bl->owner->ops->remove_location != NULL); |
| 4042 | |
| 4043 | val = bl->owner->ops->remove_location (bl); |
| 4044 | if (val) |
| 4045 | return val; |
| 4046 | |
| 4047 | bl->inserted = (is == mark_inserted); |
| 4048 | } |
| 4049 | |
| 4050 | return 0; |
| 4051 | } |
| 4052 | |
| 4053 | static int |
| 4054 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
| 4055 | { |
| 4056 | int ret; |
| 4057 | struct cleanup *old_chain; |
| 4058 | |
| 4059 | /* BL is never in moribund_locations by our callers. */ |
| 4060 | gdb_assert (bl->owner != NULL); |
| 4061 | |
| 4062 | /* The type of none suggests that owner is actually deleted. |
| 4063 | This should not ever happen. */ |
| 4064 | gdb_assert (bl->owner->type != bp_none); |
| 4065 | |
| 4066 | old_chain = save_current_space_and_thread (); |
| 4067 | |
| 4068 | switch_to_program_space_and_thread (bl->pspace); |
| 4069 | |
| 4070 | ret = remove_breakpoint_1 (bl, is); |
| 4071 | |
| 4072 | do_cleanups (old_chain); |
| 4073 | return ret; |
| 4074 | } |
| 4075 | |
| 4076 | /* Clear the "inserted" flag in all breakpoints. */ |
| 4077 | |
| 4078 | void |
| 4079 | mark_breakpoints_out (void) |
| 4080 | { |
| 4081 | struct bp_location *bl, **blp_tmp; |
| 4082 | |
| 4083 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 4084 | if (bl->pspace == current_program_space) |
| 4085 | bl->inserted = 0; |
| 4086 | } |
| 4087 | |
| 4088 | /* Clear the "inserted" flag in all breakpoints and delete any |
| 4089 | breakpoints which should go away between runs of the program. |
| 4090 | |
| 4091 | Plus other such housekeeping that has to be done for breakpoints |
| 4092 | between runs. |
| 4093 | |
| 4094 | Note: this function gets called at the end of a run (by |
| 4095 | generic_mourn_inferior) and when a run begins (by |
| 4096 | init_wait_for_inferior). */ |
| 4097 | |
| 4098 | |
| 4099 | |
| 4100 | void |
| 4101 | breakpoint_init_inferior (enum inf_context context) |
| 4102 | { |
| 4103 | struct breakpoint *b, *b_tmp; |
| 4104 | struct bp_location *bl, **blp_tmp; |
| 4105 | int ix; |
| 4106 | struct program_space *pspace = current_program_space; |
| 4107 | |
| 4108 | /* If breakpoint locations are shared across processes, then there's |
| 4109 | nothing to do. */ |
| 4110 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
| 4111 | return; |
| 4112 | |
| 4113 | mark_breakpoints_out (); |
| 4114 | |
| 4115 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 4116 | { |
| 4117 | if (b->loc && b->loc->pspace != pspace) |
| 4118 | continue; |
| 4119 | |
| 4120 | switch (b->type) |
| 4121 | { |
| 4122 | case bp_call_dummy: |
| 4123 | case bp_longjmp_call_dummy: |
| 4124 | |
| 4125 | /* If the call dummy breakpoint is at the entry point it will |
| 4126 | cause problems when the inferior is rerun, so we better get |
| 4127 | rid of it. */ |
| 4128 | |
| 4129 | case bp_watchpoint_scope: |
| 4130 | |
| 4131 | /* Also get rid of scope breakpoints. */ |
| 4132 | |
| 4133 | case bp_shlib_event: |
| 4134 | |
| 4135 | /* Also remove solib event breakpoints. Their addresses may |
| 4136 | have changed since the last time we ran the program. |
| 4137 | Actually we may now be debugging against different target; |
| 4138 | and so the solib backend that installed this breakpoint may |
| 4139 | not be used in by the target. E.g., |
| 4140 | |
| 4141 | (gdb) file prog-linux |
| 4142 | (gdb) run # native linux target |
| 4143 | ... |
| 4144 | (gdb) kill |
| 4145 | (gdb) file prog-win.exe |
| 4146 | (gdb) tar rem :9999 # remote Windows gdbserver. |
| 4147 | */ |
| 4148 | |
| 4149 | case bp_step_resume: |
| 4150 | |
| 4151 | /* Also remove step-resume breakpoints. */ |
| 4152 | |
| 4153 | case bp_single_step: |
| 4154 | |
| 4155 | /* Also remove single-step breakpoints. */ |
| 4156 | |
| 4157 | delete_breakpoint (b); |
| 4158 | break; |
| 4159 | |
| 4160 | case bp_watchpoint: |
| 4161 | case bp_hardware_watchpoint: |
| 4162 | case bp_read_watchpoint: |
| 4163 | case bp_access_watchpoint: |
| 4164 | { |
| 4165 | struct watchpoint *w = (struct watchpoint *) b; |
| 4166 | |
| 4167 | /* Likewise for watchpoints on local expressions. */ |
| 4168 | if (w->exp_valid_block != NULL) |
| 4169 | delete_breakpoint (b); |
| 4170 | else if (context == inf_starting) |
| 4171 | { |
| 4172 | /* Reset val field to force reread of starting value in |
| 4173 | insert_breakpoints. */ |
| 4174 | if (w->val) |
| 4175 | value_free (w->val); |
| 4176 | w->val = NULL; |
| 4177 | w->val_valid = 0; |
| 4178 | } |
| 4179 | } |
| 4180 | break; |
| 4181 | default: |
| 4182 | break; |
| 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | /* Get rid of the moribund locations. */ |
| 4187 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
| 4188 | decref_bp_location (&bl); |
| 4189 | VEC_free (bp_location_p, moribund_locations); |
| 4190 | } |
| 4191 | |
| 4192 | /* These functions concern about actual breakpoints inserted in the |
| 4193 | target --- to e.g. check if we need to do decr_pc adjustment or if |
| 4194 | we need to hop over the bkpt --- so we check for address space |
| 4195 | match, not program space. */ |
| 4196 | |
| 4197 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
| 4198 | exists at PC. It returns ordinary_breakpoint_here if it's an |
| 4199 | ordinary breakpoint, or permanent_breakpoint_here if it's a |
| 4200 | permanent breakpoint. |
| 4201 | - When continuing from a location with an ordinary breakpoint, we |
| 4202 | actually single step once before calling insert_breakpoints. |
| 4203 | - When continuing from a location with a permanent breakpoint, we |
| 4204 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
| 4205 | the target, to advance the PC past the breakpoint. */ |
| 4206 | |
| 4207 | enum breakpoint_here |
| 4208 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 4209 | { |
| 4210 | struct bp_location *bl, **blp_tmp; |
| 4211 | int any_breakpoint_here = 0; |
| 4212 | |
| 4213 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 4214 | { |
| 4215 | if (bl->loc_type != bp_loc_software_breakpoint |
| 4216 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 4217 | continue; |
| 4218 | |
| 4219 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
| 4220 | if ((breakpoint_enabled (bl->owner) |
| 4221 | || bl->permanent) |
| 4222 | && breakpoint_location_address_match (bl, aspace, pc)) |
| 4223 | { |
| 4224 | if (overlay_debugging |
| 4225 | && section_is_overlay (bl->section) |
| 4226 | && !section_is_mapped (bl->section)) |
| 4227 | continue; /* unmapped overlay -- can't be a match */ |
| 4228 | else if (bl->permanent) |
| 4229 | return permanent_breakpoint_here; |
| 4230 | else |
| 4231 | any_breakpoint_here = 1; |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
| 4236 | } |
| 4237 | |
| 4238 | /* Return true if there's a moribund breakpoint at PC. */ |
| 4239 | |
| 4240 | int |
| 4241 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 4242 | { |
| 4243 | struct bp_location *loc; |
| 4244 | int ix; |
| 4245 | |
| 4246 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 4247 | if (breakpoint_location_address_match (loc, aspace, pc)) |
| 4248 | return 1; |
| 4249 | |
| 4250 | return 0; |
| 4251 | } |
| 4252 | |
| 4253 | /* Returns non-zero iff BL is inserted at PC, in address space |
| 4254 | ASPACE. */ |
| 4255 | |
| 4256 | static int |
| 4257 | bp_location_inserted_here_p (struct bp_location *bl, |
| 4258 | struct address_space *aspace, CORE_ADDR pc) |
| 4259 | { |
| 4260 | if (bl->inserted |
| 4261 | && breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 4262 | aspace, pc)) |
| 4263 | { |
| 4264 | if (overlay_debugging |
| 4265 | && section_is_overlay (bl->section) |
| 4266 | && !section_is_mapped (bl->section)) |
| 4267 | return 0; /* unmapped overlay -- can't be a match */ |
| 4268 | else |
| 4269 | return 1; |
| 4270 | } |
| 4271 | return 0; |
| 4272 | } |
| 4273 | |
| 4274 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
| 4275 | |
| 4276 | int |
| 4277 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
| 4278 | { |
| 4279 | struct bp_location **blp, **blp_tmp = NULL; |
| 4280 | struct bp_location *bl; |
| 4281 | |
| 4282 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4283 | { |
| 4284 | struct bp_location *bl = *blp; |
| 4285 | |
| 4286 | if (bl->loc_type != bp_loc_software_breakpoint |
| 4287 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 4288 | continue; |
| 4289 | |
| 4290 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4291 | return 1; |
| 4292 | } |
| 4293 | return 0; |
| 4294 | } |
| 4295 | |
| 4296 | /* This function returns non-zero iff there is a software breakpoint |
| 4297 | inserted at PC. */ |
| 4298 | |
| 4299 | int |
| 4300 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
| 4301 | CORE_ADDR pc) |
| 4302 | { |
| 4303 | struct bp_location **blp, **blp_tmp = NULL; |
| 4304 | struct bp_location *bl; |
| 4305 | |
| 4306 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4307 | { |
| 4308 | struct bp_location *bl = *blp; |
| 4309 | |
| 4310 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 4311 | continue; |
| 4312 | |
| 4313 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4314 | return 1; |
| 4315 | } |
| 4316 | |
| 4317 | return 0; |
| 4318 | } |
| 4319 | |
| 4320 | /* See breakpoint.h. */ |
| 4321 | |
| 4322 | int |
| 4323 | hardware_breakpoint_inserted_here_p (struct address_space *aspace, |
| 4324 | CORE_ADDR pc) |
| 4325 | { |
| 4326 | struct bp_location **blp, **blp_tmp = NULL; |
| 4327 | struct bp_location *bl; |
| 4328 | |
| 4329 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4330 | { |
| 4331 | struct bp_location *bl = *blp; |
| 4332 | |
| 4333 | if (bl->loc_type != bp_loc_hardware_breakpoint) |
| 4334 | continue; |
| 4335 | |
| 4336 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4337 | return 1; |
| 4338 | } |
| 4339 | |
| 4340 | return 0; |
| 4341 | } |
| 4342 | |
| 4343 | int |
| 4344 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, |
| 4345 | CORE_ADDR addr, ULONGEST len) |
| 4346 | { |
| 4347 | struct breakpoint *bpt; |
| 4348 | |
| 4349 | ALL_BREAKPOINTS (bpt) |
| 4350 | { |
| 4351 | struct bp_location *loc; |
| 4352 | |
| 4353 | if (bpt->type != bp_hardware_watchpoint |
| 4354 | && bpt->type != bp_access_watchpoint) |
| 4355 | continue; |
| 4356 | |
| 4357 | if (!breakpoint_enabled (bpt)) |
| 4358 | continue; |
| 4359 | |
| 4360 | for (loc = bpt->loc; loc; loc = loc->next) |
| 4361 | if (loc->pspace->aspace == aspace && loc->inserted) |
| 4362 | { |
| 4363 | CORE_ADDR l, h; |
| 4364 | |
| 4365 | /* Check for intersection. */ |
| 4366 | l = max (loc->address, addr); |
| 4367 | h = min (loc->address + loc->length, addr + len); |
| 4368 | if (l < h) |
| 4369 | return 1; |
| 4370 | } |
| 4371 | } |
| 4372 | return 0; |
| 4373 | } |
| 4374 | \f |
| 4375 | |
| 4376 | /* bpstat stuff. External routines' interfaces are documented |
| 4377 | in breakpoint.h. */ |
| 4378 | |
| 4379 | int |
| 4380 | is_catchpoint (struct breakpoint *ep) |
| 4381 | { |
| 4382 | return (ep->type == bp_catchpoint); |
| 4383 | } |
| 4384 | |
| 4385 | /* Frees any storage that is part of a bpstat. Does not walk the |
| 4386 | 'next' chain. */ |
| 4387 | |
| 4388 | static void |
| 4389 | bpstat_free (bpstat bs) |
| 4390 | { |
| 4391 | if (bs->old_val != NULL) |
| 4392 | value_free (bs->old_val); |
| 4393 | decref_counted_command_line (&bs->commands); |
| 4394 | decref_bp_location (&bs->bp_location_at); |
| 4395 | xfree (bs); |
| 4396 | } |
| 4397 | |
| 4398 | /* Clear a bpstat so that it says we are not at any breakpoint. |
| 4399 | Also free any storage that is part of a bpstat. */ |
| 4400 | |
| 4401 | void |
| 4402 | bpstat_clear (bpstat *bsp) |
| 4403 | { |
| 4404 | bpstat p; |
| 4405 | bpstat q; |
| 4406 | |
| 4407 | if (bsp == 0) |
| 4408 | return; |
| 4409 | p = *bsp; |
| 4410 | while (p != NULL) |
| 4411 | { |
| 4412 | q = p->next; |
| 4413 | bpstat_free (p); |
| 4414 | p = q; |
| 4415 | } |
| 4416 | *bsp = NULL; |
| 4417 | } |
| 4418 | |
| 4419 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
| 4420 | is part of the bpstat is copied as well. */ |
| 4421 | |
| 4422 | bpstat |
| 4423 | bpstat_copy (bpstat bs) |
| 4424 | { |
| 4425 | bpstat p = NULL; |
| 4426 | bpstat tmp; |
| 4427 | bpstat retval = NULL; |
| 4428 | |
| 4429 | if (bs == NULL) |
| 4430 | return bs; |
| 4431 | |
| 4432 | for (; bs != NULL; bs = bs->next) |
| 4433 | { |
| 4434 | tmp = (bpstat) xmalloc (sizeof (*tmp)); |
| 4435 | memcpy (tmp, bs, sizeof (*tmp)); |
| 4436 | incref_counted_command_line (tmp->commands); |
| 4437 | incref_bp_location (tmp->bp_location_at); |
| 4438 | if (bs->old_val != NULL) |
| 4439 | { |
| 4440 | tmp->old_val = value_copy (bs->old_val); |
| 4441 | release_value (tmp->old_val); |
| 4442 | } |
| 4443 | |
| 4444 | if (p == NULL) |
| 4445 | /* This is the first thing in the chain. */ |
| 4446 | retval = tmp; |
| 4447 | else |
| 4448 | p->next = tmp; |
| 4449 | p = tmp; |
| 4450 | } |
| 4451 | p->next = NULL; |
| 4452 | return retval; |
| 4453 | } |
| 4454 | |
| 4455 | /* Find the bpstat associated with this breakpoint. */ |
| 4456 | |
| 4457 | bpstat |
| 4458 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
| 4459 | { |
| 4460 | if (bsp == NULL) |
| 4461 | return NULL; |
| 4462 | |
| 4463 | for (; bsp != NULL; bsp = bsp->next) |
| 4464 | { |
| 4465 | if (bsp->breakpoint_at == breakpoint) |
| 4466 | return bsp; |
| 4467 | } |
| 4468 | return NULL; |
| 4469 | } |
| 4470 | |
| 4471 | /* See breakpoint.h. */ |
| 4472 | |
| 4473 | int |
| 4474 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
| 4475 | { |
| 4476 | for (; bsp != NULL; bsp = bsp->next) |
| 4477 | { |
| 4478 | if (bsp->breakpoint_at == NULL) |
| 4479 | { |
| 4480 | /* A moribund location can never explain a signal other than |
| 4481 | GDB_SIGNAL_TRAP. */ |
| 4482 | if (sig == GDB_SIGNAL_TRAP) |
| 4483 | return 1; |
| 4484 | } |
| 4485 | else |
| 4486 | { |
| 4487 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, |
| 4488 | sig)) |
| 4489 | return 1; |
| 4490 | } |
| 4491 | } |
| 4492 | |
| 4493 | return 0; |
| 4494 | } |
| 4495 | |
| 4496 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
| 4497 | stopped at. *BSP upon return is a bpstat which points to the |
| 4498 | remaining breakpoints stopped at (but which is not guaranteed to be |
| 4499 | good for anything but further calls to bpstat_num). |
| 4500 | |
| 4501 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
| 4502 | Return -1 if stopped at a breakpoint that has been deleted since |
| 4503 | we set it. |
| 4504 | Return 1 otherwise. */ |
| 4505 | |
| 4506 | int |
| 4507 | bpstat_num (bpstat *bsp, int *num) |
| 4508 | { |
| 4509 | struct breakpoint *b; |
| 4510 | |
| 4511 | if ((*bsp) == NULL) |
| 4512 | return 0; /* No more breakpoint values */ |
| 4513 | |
| 4514 | /* We assume we'll never have several bpstats that correspond to a |
| 4515 | single breakpoint -- otherwise, this function might return the |
| 4516 | same number more than once and this will look ugly. */ |
| 4517 | b = (*bsp)->breakpoint_at; |
| 4518 | *bsp = (*bsp)->next; |
| 4519 | if (b == NULL) |
| 4520 | return -1; /* breakpoint that's been deleted since */ |
| 4521 | |
| 4522 | *num = b->number; /* We have its number */ |
| 4523 | return 1; |
| 4524 | } |
| 4525 | |
| 4526 | /* See breakpoint.h. */ |
| 4527 | |
| 4528 | void |
| 4529 | bpstat_clear_actions (void) |
| 4530 | { |
| 4531 | struct thread_info *tp; |
| 4532 | bpstat bs; |
| 4533 | |
| 4534 | if (ptid_equal (inferior_ptid, null_ptid)) |
| 4535 | return; |
| 4536 | |
| 4537 | tp = find_thread_ptid (inferior_ptid); |
| 4538 | if (tp == NULL) |
| 4539 | return; |
| 4540 | |
| 4541 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
| 4542 | { |
| 4543 | decref_counted_command_line (&bs->commands); |
| 4544 | |
| 4545 | if (bs->old_val != NULL) |
| 4546 | { |
| 4547 | value_free (bs->old_val); |
| 4548 | bs->old_val = NULL; |
| 4549 | } |
| 4550 | } |
| 4551 | } |
| 4552 | |
| 4553 | /* Called when a command is about to proceed the inferior. */ |
| 4554 | |
| 4555 | static void |
| 4556 | breakpoint_about_to_proceed (void) |
| 4557 | { |
| 4558 | if (!ptid_equal (inferior_ptid, null_ptid)) |
| 4559 | { |
| 4560 | struct thread_info *tp = inferior_thread (); |
| 4561 | |
| 4562 | /* Allow inferior function calls in breakpoint commands to not |
| 4563 | interrupt the command list. When the call finishes |
| 4564 | successfully, the inferior will be standing at the same |
| 4565 | breakpoint as if nothing happened. */ |
| 4566 | if (tp->control.in_infcall) |
| 4567 | return; |
| 4568 | } |
| 4569 | |
| 4570 | breakpoint_proceeded = 1; |
| 4571 | } |
| 4572 | |
| 4573 | /* Stub for cleaning up our state if we error-out of a breakpoint |
| 4574 | command. */ |
| 4575 | static void |
| 4576 | cleanup_executing_breakpoints (void *ignore) |
| 4577 | { |
| 4578 | executing_breakpoint_commands = 0; |
| 4579 | } |
| 4580 | |
| 4581 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
| 4582 | or its equivalent. */ |
| 4583 | |
| 4584 | static int |
| 4585 | command_line_is_silent (struct command_line *cmd) |
| 4586 | { |
| 4587 | return cmd && (strcmp ("silent", cmd->line) == 0); |
| 4588 | } |
| 4589 | |
| 4590 | /* Execute all the commands associated with all the breakpoints at |
| 4591 | this location. Any of these commands could cause the process to |
| 4592 | proceed beyond this point, etc. We look out for such changes by |
| 4593 | checking the global "breakpoint_proceeded" after each command. |
| 4594 | |
| 4595 | Returns true if a breakpoint command resumed the inferior. In that |
| 4596 | case, it is the caller's responsibility to recall it again with the |
| 4597 | bpstat of the current thread. */ |
| 4598 | |
| 4599 | static int |
| 4600 | bpstat_do_actions_1 (bpstat *bsp) |
| 4601 | { |
| 4602 | bpstat bs; |
| 4603 | struct cleanup *old_chain; |
| 4604 | int again = 0; |
| 4605 | |
| 4606 | /* Avoid endless recursion if a `source' command is contained |
| 4607 | in bs->commands. */ |
| 4608 | if (executing_breakpoint_commands) |
| 4609 | return 0; |
| 4610 | |
| 4611 | executing_breakpoint_commands = 1; |
| 4612 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); |
| 4613 | |
| 4614 | prevent_dont_repeat (); |
| 4615 | |
| 4616 | /* This pointer will iterate over the list of bpstat's. */ |
| 4617 | bs = *bsp; |
| 4618 | |
| 4619 | breakpoint_proceeded = 0; |
| 4620 | for (; bs != NULL; bs = bs->next) |
| 4621 | { |
| 4622 | struct counted_command_line *ccmd; |
| 4623 | struct command_line *cmd; |
| 4624 | struct cleanup *this_cmd_tree_chain; |
| 4625 | |
| 4626 | /* Take ownership of the BSP's command tree, if it has one. |
| 4627 | |
| 4628 | The command tree could legitimately contain commands like |
| 4629 | 'step' and 'next', which call clear_proceed_status, which |
| 4630 | frees stop_bpstat's command tree. To make sure this doesn't |
| 4631 | free the tree we're executing out from under us, we need to |
| 4632 | take ownership of the tree ourselves. Since a given bpstat's |
| 4633 | commands are only executed once, we don't need to copy it; we |
| 4634 | can clear the pointer in the bpstat, and make sure we free |
| 4635 | the tree when we're done. */ |
| 4636 | ccmd = bs->commands; |
| 4637 | bs->commands = NULL; |
| 4638 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
| 4639 | cmd = ccmd ? ccmd->commands : NULL; |
| 4640 | if (command_line_is_silent (cmd)) |
| 4641 | { |
| 4642 | /* The action has been already done by bpstat_stop_status. */ |
| 4643 | cmd = cmd->next; |
| 4644 | } |
| 4645 | |
| 4646 | while (cmd != NULL) |
| 4647 | { |
| 4648 | execute_control_command (cmd); |
| 4649 | |
| 4650 | if (breakpoint_proceeded) |
| 4651 | break; |
| 4652 | else |
| 4653 | cmd = cmd->next; |
| 4654 | } |
| 4655 | |
| 4656 | /* We can free this command tree now. */ |
| 4657 | do_cleanups (this_cmd_tree_chain); |
| 4658 | |
| 4659 | if (breakpoint_proceeded) |
| 4660 | { |
| 4661 | if (interpreter_async && target_can_async_p ()) |
| 4662 | /* If we are in async mode, then the target might be still |
| 4663 | running, not stopped at any breakpoint, so nothing for |
| 4664 | us to do here -- just return to the event loop. */ |
| 4665 | ; |
| 4666 | else |
| 4667 | /* In sync mode, when execute_control_command returns |
| 4668 | we're already standing on the next breakpoint. |
| 4669 | Breakpoint commands for that stop were not run, since |
| 4670 | execute_command does not run breakpoint commands -- |
| 4671 | only command_line_handler does, but that one is not |
| 4672 | involved in execution of breakpoint commands. So, we |
| 4673 | can now execute breakpoint commands. It should be |
| 4674 | noted that making execute_command do bpstat actions is |
| 4675 | not an option -- in this case we'll have recursive |
| 4676 | invocation of bpstat for each breakpoint with a |
| 4677 | command, and can easily blow up GDB stack. Instead, we |
| 4678 | return true, which will trigger the caller to recall us |
| 4679 | with the new stop_bpstat. */ |
| 4680 | again = 1; |
| 4681 | break; |
| 4682 | } |
| 4683 | } |
| 4684 | do_cleanups (old_chain); |
| 4685 | return again; |
| 4686 | } |
| 4687 | |
| 4688 | void |
| 4689 | bpstat_do_actions (void) |
| 4690 | { |
| 4691 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
| 4692 | |
| 4693 | /* Do any commands attached to breakpoint we are stopped at. */ |
| 4694 | while (!ptid_equal (inferior_ptid, null_ptid) |
| 4695 | && target_has_execution |
| 4696 | && !is_exited (inferior_ptid) |
| 4697 | && !is_executing (inferior_ptid)) |
| 4698 | /* Since in sync mode, bpstat_do_actions may resume the inferior, |
| 4699 | and only return when it is stopped at the next breakpoint, we |
| 4700 | keep doing breakpoint actions until it returns false to |
| 4701 | indicate the inferior was not resumed. */ |
| 4702 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
| 4703 | break; |
| 4704 | |
| 4705 | discard_cleanups (cleanup_if_error); |
| 4706 | } |
| 4707 | |
| 4708 | /* Print out the (old or new) value associated with a watchpoint. */ |
| 4709 | |
| 4710 | static void |
| 4711 | watchpoint_value_print (struct value *val, struct ui_file *stream) |
| 4712 | { |
| 4713 | if (val == NULL) |
| 4714 | fprintf_unfiltered (stream, _("<unreadable>")); |
| 4715 | else |
| 4716 | { |
| 4717 | struct value_print_options opts; |
| 4718 | get_user_print_options (&opts); |
| 4719 | value_print (val, stream, &opts); |
| 4720 | } |
| 4721 | } |
| 4722 | |
| 4723 | /* Generic routine for printing messages indicating why we |
| 4724 | stopped. The behavior of this function depends on the value |
| 4725 | 'print_it' in the bpstat structure. Under some circumstances we |
| 4726 | may decide not to print anything here and delegate the task to |
| 4727 | normal_stop(). */ |
| 4728 | |
| 4729 | static enum print_stop_action |
| 4730 | print_bp_stop_message (bpstat bs) |
| 4731 | { |
| 4732 | switch (bs->print_it) |
| 4733 | { |
| 4734 | case print_it_noop: |
| 4735 | /* Nothing should be printed for this bpstat entry. */ |
| 4736 | return PRINT_UNKNOWN; |
| 4737 | break; |
| 4738 | |
| 4739 | case print_it_done: |
| 4740 | /* We still want to print the frame, but we already printed the |
| 4741 | relevant messages. */ |
| 4742 | return PRINT_SRC_AND_LOC; |
| 4743 | break; |
| 4744 | |
| 4745 | case print_it_normal: |
| 4746 | { |
| 4747 | struct breakpoint *b = bs->breakpoint_at; |
| 4748 | |
| 4749 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
| 4750 | which has since been deleted. */ |
| 4751 | if (b == NULL) |
| 4752 | return PRINT_UNKNOWN; |
| 4753 | |
| 4754 | /* Normal case. Call the breakpoint's print_it method. */ |
| 4755 | return b->ops->print_it (bs); |
| 4756 | } |
| 4757 | break; |
| 4758 | |
| 4759 | default: |
| 4760 | internal_error (__FILE__, __LINE__, |
| 4761 | _("print_bp_stop_message: unrecognized enum value")); |
| 4762 | break; |
| 4763 | } |
| 4764 | } |
| 4765 | |
| 4766 | /* A helper function that prints a shared library stopped event. */ |
| 4767 | |
| 4768 | static void |
| 4769 | print_solib_event (int is_catchpoint) |
| 4770 | { |
| 4771 | int any_deleted |
| 4772 | = !VEC_empty (char_ptr, current_program_space->deleted_solibs); |
| 4773 | int any_added |
| 4774 | = !VEC_empty (so_list_ptr, current_program_space->added_solibs); |
| 4775 | |
| 4776 | if (!is_catchpoint) |
| 4777 | { |
| 4778 | if (any_added || any_deleted) |
| 4779 | ui_out_text (current_uiout, |
| 4780 | _("Stopped due to shared library event:\n")); |
| 4781 | else |
| 4782 | ui_out_text (current_uiout, |
| 4783 | _("Stopped due to shared library event (no " |
| 4784 | "libraries added or removed)\n")); |
| 4785 | } |
| 4786 | |
| 4787 | if (ui_out_is_mi_like_p (current_uiout)) |
| 4788 | ui_out_field_string (current_uiout, "reason", |
| 4789 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); |
| 4790 | |
| 4791 | if (any_deleted) |
| 4792 | { |
| 4793 | struct cleanup *cleanup; |
| 4794 | char *name; |
| 4795 | int ix; |
| 4796 | |
| 4797 | ui_out_text (current_uiout, _(" Inferior unloaded ")); |
| 4798 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, |
| 4799 | "removed"); |
| 4800 | for (ix = 0; |
| 4801 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, |
| 4802 | ix, name); |
| 4803 | ++ix) |
| 4804 | { |
| 4805 | if (ix > 0) |
| 4806 | ui_out_text (current_uiout, " "); |
| 4807 | ui_out_field_string (current_uiout, "library", name); |
| 4808 | ui_out_text (current_uiout, "\n"); |
| 4809 | } |
| 4810 | |
| 4811 | do_cleanups (cleanup); |
| 4812 | } |
| 4813 | |
| 4814 | if (any_added) |
| 4815 | { |
| 4816 | struct so_list *iter; |
| 4817 | int ix; |
| 4818 | struct cleanup *cleanup; |
| 4819 | |
| 4820 | ui_out_text (current_uiout, _(" Inferior loaded ")); |
| 4821 | cleanup = make_cleanup_ui_out_list_begin_end (current_uiout, |
| 4822 | "added"); |
| 4823 | for (ix = 0; |
| 4824 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, |
| 4825 | ix, iter); |
| 4826 | ++ix) |
| 4827 | { |
| 4828 | if (ix > 0) |
| 4829 | ui_out_text (current_uiout, " "); |
| 4830 | ui_out_field_string (current_uiout, "library", iter->so_name); |
| 4831 | ui_out_text (current_uiout, "\n"); |
| 4832 | } |
| 4833 | |
| 4834 | do_cleanups (cleanup); |
| 4835 | } |
| 4836 | } |
| 4837 | |
| 4838 | /* Print a message indicating what happened. This is called from |
| 4839 | normal_stop(). The input to this routine is the head of the bpstat |
| 4840 | list - a list of the eventpoints that caused this stop. KIND is |
| 4841 | the target_waitkind for the stopping event. This |
| 4842 | routine calls the generic print routine for printing a message |
| 4843 | about reasons for stopping. This will print (for example) the |
| 4844 | "Breakpoint n," part of the output. The return value of this |
| 4845 | routine is one of: |
| 4846 | |
| 4847 | PRINT_UNKNOWN: Means we printed nothing. |
| 4848 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
| 4849 | code to print the location. An example is |
| 4850 | "Breakpoint 1, " which should be followed by |
| 4851 | the location. |
| 4852 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
| 4853 | to also print the location part of the message. |
| 4854 | An example is the catch/throw messages, which |
| 4855 | don't require a location appended to the end. |
| 4856 | PRINT_NOTHING: We have done some printing and we don't need any |
| 4857 | further info to be printed. */ |
| 4858 | |
| 4859 | enum print_stop_action |
| 4860 | bpstat_print (bpstat bs, int kind) |
| 4861 | { |
| 4862 | enum print_stop_action val; |
| 4863 | |
| 4864 | /* Maybe another breakpoint in the chain caused us to stop. |
| 4865 | (Currently all watchpoints go on the bpstat whether hit or not. |
| 4866 | That probably could (should) be changed, provided care is taken |
| 4867 | with respect to bpstat_explains_signal). */ |
| 4868 | for (; bs; bs = bs->next) |
| 4869 | { |
| 4870 | val = print_bp_stop_message (bs); |
| 4871 | if (val == PRINT_SRC_ONLY |
| 4872 | || val == PRINT_SRC_AND_LOC |
| 4873 | || val == PRINT_NOTHING) |
| 4874 | return val; |
| 4875 | } |
| 4876 | |
| 4877 | /* If we had hit a shared library event breakpoint, |
| 4878 | print_bp_stop_message would print out this message. If we hit an |
| 4879 | OS-level shared library event, do the same thing. */ |
| 4880 | if (kind == TARGET_WAITKIND_LOADED) |
| 4881 | { |
| 4882 | print_solib_event (0); |
| 4883 | return PRINT_NOTHING; |
| 4884 | } |
| 4885 | |
| 4886 | /* We reached the end of the chain, or we got a null BS to start |
| 4887 | with and nothing was printed. */ |
| 4888 | return PRINT_UNKNOWN; |
| 4889 | } |
| 4890 | |
| 4891 | /* Evaluate the expression EXP and return 1 if value is zero. |
| 4892 | This returns the inverse of the condition because it is called |
| 4893 | from catch_errors which returns 0 if an exception happened, and if an |
| 4894 | exception happens we want execution to stop. |
| 4895 | The argument is a "struct expression *" that has been cast to a |
| 4896 | "void *" to make it pass through catch_errors. */ |
| 4897 | |
| 4898 | static int |
| 4899 | breakpoint_cond_eval (void *exp) |
| 4900 | { |
| 4901 | struct value *mark = value_mark (); |
| 4902 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
| 4903 | |
| 4904 | value_free_to_mark (mark); |
| 4905 | return i; |
| 4906 | } |
| 4907 | |
| 4908 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
| 4909 | |
| 4910 | static bpstat |
| 4911 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
| 4912 | { |
| 4913 | bpstat bs; |
| 4914 | |
| 4915 | bs = (bpstat) xmalloc (sizeof (*bs)); |
| 4916 | bs->next = NULL; |
| 4917 | **bs_link_pointer = bs; |
| 4918 | *bs_link_pointer = &bs->next; |
| 4919 | bs->breakpoint_at = bl->owner; |
| 4920 | bs->bp_location_at = bl; |
| 4921 | incref_bp_location (bl); |
| 4922 | /* If the condition is false, etc., don't do the commands. */ |
| 4923 | bs->commands = NULL; |
| 4924 | bs->old_val = NULL; |
| 4925 | bs->print_it = print_it_normal; |
| 4926 | return bs; |
| 4927 | } |
| 4928 | \f |
| 4929 | /* The target has stopped with waitstatus WS. Check if any hardware |
| 4930 | watchpoints have triggered, according to the target. */ |
| 4931 | |
| 4932 | int |
| 4933 | watchpoints_triggered (struct target_waitstatus *ws) |
| 4934 | { |
| 4935 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
| 4936 | CORE_ADDR addr; |
| 4937 | struct breakpoint *b; |
| 4938 | |
| 4939 | if (!stopped_by_watchpoint) |
| 4940 | { |
| 4941 | /* We were not stopped by a watchpoint. Mark all watchpoints |
| 4942 | as not triggered. */ |
| 4943 | ALL_BREAKPOINTS (b) |
| 4944 | if (is_hardware_watchpoint (b)) |
| 4945 | { |
| 4946 | struct watchpoint *w = (struct watchpoint *) b; |
| 4947 | |
| 4948 | w->watchpoint_triggered = watch_triggered_no; |
| 4949 | } |
| 4950 | |
| 4951 | return 0; |
| 4952 | } |
| 4953 | |
| 4954 | if (!target_stopped_data_address (¤t_target, &addr)) |
| 4955 | { |
| 4956 | /* We were stopped by a watchpoint, but we don't know where. |
| 4957 | Mark all watchpoints as unknown. */ |
| 4958 | ALL_BREAKPOINTS (b) |
| 4959 | if (is_hardware_watchpoint (b)) |
| 4960 | { |
| 4961 | struct watchpoint *w = (struct watchpoint *) b; |
| 4962 | |
| 4963 | w->watchpoint_triggered = watch_triggered_unknown; |
| 4964 | } |
| 4965 | |
| 4966 | return 1; |
| 4967 | } |
| 4968 | |
| 4969 | /* The target could report the data address. Mark watchpoints |
| 4970 | affected by this data address as triggered, and all others as not |
| 4971 | triggered. */ |
| 4972 | |
| 4973 | ALL_BREAKPOINTS (b) |
| 4974 | if (is_hardware_watchpoint (b)) |
| 4975 | { |
| 4976 | struct watchpoint *w = (struct watchpoint *) b; |
| 4977 | struct bp_location *loc; |
| 4978 | |
| 4979 | w->watchpoint_triggered = watch_triggered_no; |
| 4980 | for (loc = b->loc; loc; loc = loc->next) |
| 4981 | { |
| 4982 | if (is_masked_watchpoint (b)) |
| 4983 | { |
| 4984 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
| 4985 | CORE_ADDR start = loc->address & w->hw_wp_mask; |
| 4986 | |
| 4987 | if (newaddr == start) |
| 4988 | { |
| 4989 | w->watchpoint_triggered = watch_triggered_yes; |
| 4990 | break; |
| 4991 | } |
| 4992 | } |
| 4993 | /* Exact match not required. Within range is sufficient. */ |
| 4994 | else if (target_watchpoint_addr_within_range (¤t_target, |
| 4995 | addr, loc->address, |
| 4996 | loc->length)) |
| 4997 | { |
| 4998 | w->watchpoint_triggered = watch_triggered_yes; |
| 4999 | break; |
| 5000 | } |
| 5001 | } |
| 5002 | } |
| 5003 | |
| 5004 | return 1; |
| 5005 | } |
| 5006 | |
| 5007 | /* Possible return values for watchpoint_check (this can't be an enum |
| 5008 | because of check_errors). */ |
| 5009 | /* The watchpoint has been deleted. */ |
| 5010 | #define WP_DELETED 1 |
| 5011 | /* The value has changed. */ |
| 5012 | #define WP_VALUE_CHANGED 2 |
| 5013 | /* The value has not changed. */ |
| 5014 | #define WP_VALUE_NOT_CHANGED 3 |
| 5015 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
| 5016 | #define WP_IGNORE 4 |
| 5017 | |
| 5018 | #define BP_TEMPFLAG 1 |
| 5019 | #define BP_HARDWAREFLAG 2 |
| 5020 | |
| 5021 | /* Evaluate watchpoint condition expression and check if its value |
| 5022 | changed. |
| 5023 | |
| 5024 | P should be a pointer to struct bpstat, but is defined as a void * |
| 5025 | in order for this function to be usable with catch_errors. */ |
| 5026 | |
| 5027 | static int |
| 5028 | watchpoint_check (void *p) |
| 5029 | { |
| 5030 | bpstat bs = (bpstat) p; |
| 5031 | struct watchpoint *b; |
| 5032 | struct frame_info *fr; |
| 5033 | int within_current_scope; |
| 5034 | |
| 5035 | /* BS is built from an existing struct breakpoint. */ |
| 5036 | gdb_assert (bs->breakpoint_at != NULL); |
| 5037 | b = (struct watchpoint *) bs->breakpoint_at; |
| 5038 | |
| 5039 | /* If this is a local watchpoint, we only want to check if the |
| 5040 | watchpoint frame is in scope if the current thread is the thread |
| 5041 | that was used to create the watchpoint. */ |
| 5042 | if (!watchpoint_in_thread_scope (b)) |
| 5043 | return WP_IGNORE; |
| 5044 | |
| 5045 | if (b->exp_valid_block == NULL) |
| 5046 | within_current_scope = 1; |
| 5047 | else |
| 5048 | { |
| 5049 | struct frame_info *frame = get_current_frame (); |
| 5050 | struct gdbarch *frame_arch = get_frame_arch (frame); |
| 5051 | CORE_ADDR frame_pc = get_frame_pc (frame); |
| 5052 | |
| 5053 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
| 5054 | still in the function but the stack frame has already been |
| 5055 | invalidated. Since we can't rely on the values of local |
| 5056 | variables after the stack has been destroyed, we are treating |
| 5057 | the watchpoint in that state as `not changed' without further |
| 5058 | checking. Don't mark watchpoints as changed if the current |
| 5059 | frame is in an epilogue - even if they are in some other |
| 5060 | frame, our view of the stack is likely to be wrong and |
| 5061 | frame_find_by_id could error out. */ |
| 5062 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
| 5063 | return WP_IGNORE; |
| 5064 | |
| 5065 | fr = frame_find_by_id (b->watchpoint_frame); |
| 5066 | within_current_scope = (fr != NULL); |
| 5067 | |
| 5068 | /* If we've gotten confused in the unwinder, we might have |
| 5069 | returned a frame that can't describe this variable. */ |
| 5070 | if (within_current_scope) |
| 5071 | { |
| 5072 | struct symbol *function; |
| 5073 | |
| 5074 | function = get_frame_function (fr); |
| 5075 | if (function == NULL |
| 5076 | || !contained_in (b->exp_valid_block, |
| 5077 | SYMBOL_BLOCK_VALUE (function))) |
| 5078 | within_current_scope = 0; |
| 5079 | } |
| 5080 | |
| 5081 | if (within_current_scope) |
| 5082 | /* If we end up stopping, the current frame will get selected |
| 5083 | in normal_stop. So this call to select_frame won't affect |
| 5084 | the user. */ |
| 5085 | select_frame (fr); |
| 5086 | } |
| 5087 | |
| 5088 | if (within_current_scope) |
| 5089 | { |
| 5090 | /* We use value_{,free_to_}mark because it could be a *long* |
| 5091 | time before we return to the command level and call |
| 5092 | free_all_values. We can't call free_all_values because we |
| 5093 | might be in the middle of evaluating a function call. */ |
| 5094 | |
| 5095 | int pc = 0; |
| 5096 | struct value *mark; |
| 5097 | struct value *new_val; |
| 5098 | |
| 5099 | if (is_masked_watchpoint (&b->base)) |
| 5100 | /* Since we don't know the exact trigger address (from |
| 5101 | stopped_data_address), just tell the user we've triggered |
| 5102 | a mask watchpoint. */ |
| 5103 | return WP_VALUE_CHANGED; |
| 5104 | |
| 5105 | mark = value_mark (); |
| 5106 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL, 0); |
| 5107 | |
| 5108 | if (b->val_bitsize != 0) |
| 5109 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); |
| 5110 | |
| 5111 | /* We use value_equal_contents instead of value_equal because |
| 5112 | the latter coerces an array to a pointer, thus comparing just |
| 5113 | the address of the array instead of its contents. This is |
| 5114 | not what we want. */ |
| 5115 | if ((b->val != NULL) != (new_val != NULL) |
| 5116 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
| 5117 | { |
| 5118 | if (new_val != NULL) |
| 5119 | { |
| 5120 | release_value (new_val); |
| 5121 | value_free_to_mark (mark); |
| 5122 | } |
| 5123 | bs->old_val = b->val; |
| 5124 | b->val = new_val; |
| 5125 | b->val_valid = 1; |
| 5126 | return WP_VALUE_CHANGED; |
| 5127 | } |
| 5128 | else |
| 5129 | { |
| 5130 | /* Nothing changed. */ |
| 5131 | value_free_to_mark (mark); |
| 5132 | return WP_VALUE_NOT_CHANGED; |
| 5133 | } |
| 5134 | } |
| 5135 | else |
| 5136 | { |
| 5137 | struct ui_out *uiout = current_uiout; |
| 5138 | |
| 5139 | /* This seems like the only logical thing to do because |
| 5140 | if we temporarily ignored the watchpoint, then when |
| 5141 | we reenter the block in which it is valid it contains |
| 5142 | garbage (in the case of a function, it may have two |
| 5143 | garbage values, one before and one after the prologue). |
| 5144 | So we can't even detect the first assignment to it and |
| 5145 | watch after that (since the garbage may or may not equal |
| 5146 | the first value assigned). */ |
| 5147 | /* We print all the stop information in |
| 5148 | breakpoint_ops->print_it, but in this case, by the time we |
| 5149 | call breakpoint_ops->print_it this bp will be deleted |
| 5150 | already. So we have no choice but print the information |
| 5151 | here. */ |
| 5152 | if (ui_out_is_mi_like_p (uiout)) |
| 5153 | ui_out_field_string |
| 5154 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); |
| 5155 | ui_out_text (uiout, "\nWatchpoint "); |
| 5156 | ui_out_field_int (uiout, "wpnum", b->base.number); |
| 5157 | ui_out_text (uiout, |
| 5158 | " deleted because the program has left the block in\n\ |
| 5159 | which its expression is valid.\n"); |
| 5160 | |
| 5161 | /* Make sure the watchpoint's commands aren't executed. */ |
| 5162 | decref_counted_command_line (&b->base.commands); |
| 5163 | watchpoint_del_at_next_stop (b); |
| 5164 | |
| 5165 | return WP_DELETED; |
| 5166 | } |
| 5167 | } |
| 5168 | |
| 5169 | /* Return true if it looks like target has stopped due to hitting |
| 5170 | breakpoint location BL. This function does not check if we should |
| 5171 | stop, only if BL explains the stop. */ |
| 5172 | |
| 5173 | static int |
| 5174 | bpstat_check_location (const struct bp_location *bl, |
| 5175 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 5176 | const struct target_waitstatus *ws) |
| 5177 | { |
| 5178 | struct breakpoint *b = bl->owner; |
| 5179 | |
| 5180 | /* BL is from an existing breakpoint. */ |
| 5181 | gdb_assert (b != NULL); |
| 5182 | |
| 5183 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
| 5184 | } |
| 5185 | |
| 5186 | /* Determine if the watched values have actually changed, and we |
| 5187 | should stop. If not, set BS->stop to 0. */ |
| 5188 | |
| 5189 | static void |
| 5190 | bpstat_check_watchpoint (bpstat bs) |
| 5191 | { |
| 5192 | const struct bp_location *bl; |
| 5193 | struct watchpoint *b; |
| 5194 | |
| 5195 | /* BS is built for existing struct breakpoint. */ |
| 5196 | bl = bs->bp_location_at; |
| 5197 | gdb_assert (bl != NULL); |
| 5198 | b = (struct watchpoint *) bs->breakpoint_at; |
| 5199 | gdb_assert (b != NULL); |
| 5200 | |
| 5201 | { |
| 5202 | int must_check_value = 0; |
| 5203 | |
| 5204 | if (b->base.type == bp_watchpoint) |
| 5205 | /* For a software watchpoint, we must always check the |
| 5206 | watched value. */ |
| 5207 | must_check_value = 1; |
| 5208 | else if (b->watchpoint_triggered == watch_triggered_yes) |
| 5209 | /* We have a hardware watchpoint (read, write, or access) |
| 5210 | and the target earlier reported an address watched by |
| 5211 | this watchpoint. */ |
| 5212 | must_check_value = 1; |
| 5213 | else if (b->watchpoint_triggered == watch_triggered_unknown |
| 5214 | && b->base.type == bp_hardware_watchpoint) |
| 5215 | /* We were stopped by a hardware watchpoint, but the target could |
| 5216 | not report the data address. We must check the watchpoint's |
| 5217 | value. Access and read watchpoints are out of luck; without |
| 5218 | a data address, we can't figure it out. */ |
| 5219 | must_check_value = 1; |
| 5220 | |
| 5221 | if (must_check_value) |
| 5222 | { |
| 5223 | char *message |
| 5224 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", |
| 5225 | b->base.number); |
| 5226 | struct cleanup *cleanups = make_cleanup (xfree, message); |
| 5227 | int e = catch_errors (watchpoint_check, bs, message, |
| 5228 | RETURN_MASK_ALL); |
| 5229 | do_cleanups (cleanups); |
| 5230 | switch (e) |
| 5231 | { |
| 5232 | case WP_DELETED: |
| 5233 | /* We've already printed what needs to be printed. */ |
| 5234 | bs->print_it = print_it_done; |
| 5235 | /* Stop. */ |
| 5236 | break; |
| 5237 | case WP_IGNORE: |
| 5238 | bs->print_it = print_it_noop; |
| 5239 | bs->stop = 0; |
| 5240 | break; |
| 5241 | case WP_VALUE_CHANGED: |
| 5242 | if (b->base.type == bp_read_watchpoint) |
| 5243 | { |
| 5244 | /* There are two cases to consider here: |
| 5245 | |
| 5246 | 1. We're watching the triggered memory for reads. |
| 5247 | In that case, trust the target, and always report |
| 5248 | the watchpoint hit to the user. Even though |
| 5249 | reads don't cause value changes, the value may |
| 5250 | have changed since the last time it was read, and |
| 5251 | since we're not trapping writes, we will not see |
| 5252 | those, and as such we should ignore our notion of |
| 5253 | old value. |
| 5254 | |
| 5255 | 2. We're watching the triggered memory for both |
| 5256 | reads and writes. There are two ways this may |
| 5257 | happen: |
| 5258 | |
| 5259 | 2.1. This is a target that can't break on data |
| 5260 | reads only, but can break on accesses (reads or |
| 5261 | writes), such as e.g., x86. We detect this case |
| 5262 | at the time we try to insert read watchpoints. |
| 5263 | |
| 5264 | 2.2. Otherwise, the target supports read |
| 5265 | watchpoints, but, the user set an access or write |
| 5266 | watchpoint watching the same memory as this read |
| 5267 | watchpoint. |
| 5268 | |
| 5269 | If we're watching memory writes as well as reads, |
| 5270 | ignore watchpoint hits when we find that the |
| 5271 | value hasn't changed, as reads don't cause |
| 5272 | changes. This still gives false positives when |
| 5273 | the program writes the same value to memory as |
| 5274 | what there was already in memory (we will confuse |
| 5275 | it for a read), but it's much better than |
| 5276 | nothing. */ |
| 5277 | |
| 5278 | int other_write_watchpoint = 0; |
| 5279 | |
| 5280 | if (bl->watchpoint_type == hw_read) |
| 5281 | { |
| 5282 | struct breakpoint *other_b; |
| 5283 | |
| 5284 | ALL_BREAKPOINTS (other_b) |
| 5285 | if (other_b->type == bp_hardware_watchpoint |
| 5286 | || other_b->type == bp_access_watchpoint) |
| 5287 | { |
| 5288 | struct watchpoint *other_w = |
| 5289 | (struct watchpoint *) other_b; |
| 5290 | |
| 5291 | if (other_w->watchpoint_triggered |
| 5292 | == watch_triggered_yes) |
| 5293 | { |
| 5294 | other_write_watchpoint = 1; |
| 5295 | break; |
| 5296 | } |
| 5297 | } |
| 5298 | } |
| 5299 | |
| 5300 | if (other_write_watchpoint |
| 5301 | || bl->watchpoint_type == hw_access) |
| 5302 | { |
| 5303 | /* We're watching the same memory for writes, |
| 5304 | and the value changed since the last time we |
| 5305 | updated it, so this trap must be for a write. |
| 5306 | Ignore it. */ |
| 5307 | bs->print_it = print_it_noop; |
| 5308 | bs->stop = 0; |
| 5309 | } |
| 5310 | } |
| 5311 | break; |
| 5312 | case WP_VALUE_NOT_CHANGED: |
| 5313 | if (b->base.type == bp_hardware_watchpoint |
| 5314 | || b->base.type == bp_watchpoint) |
| 5315 | { |
| 5316 | /* Don't stop: write watchpoints shouldn't fire if |
| 5317 | the value hasn't changed. */ |
| 5318 | bs->print_it = print_it_noop; |
| 5319 | bs->stop = 0; |
| 5320 | } |
| 5321 | /* Stop. */ |
| 5322 | break; |
| 5323 | default: |
| 5324 | /* Can't happen. */ |
| 5325 | case 0: |
| 5326 | /* Error from catch_errors. */ |
| 5327 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
| 5328 | watchpoint_del_at_next_stop (b); |
| 5329 | /* We've already printed what needs to be printed. */ |
| 5330 | bs->print_it = print_it_done; |
| 5331 | break; |
| 5332 | } |
| 5333 | } |
| 5334 | else /* must_check_value == 0 */ |
| 5335 | { |
| 5336 | /* This is a case where some watchpoint(s) triggered, but |
| 5337 | not at the address of this watchpoint, or else no |
| 5338 | watchpoint triggered after all. So don't print |
| 5339 | anything for this watchpoint. */ |
| 5340 | bs->print_it = print_it_noop; |
| 5341 | bs->stop = 0; |
| 5342 | } |
| 5343 | } |
| 5344 | } |
| 5345 | |
| 5346 | /* For breakpoints that are currently marked as telling gdb to stop, |
| 5347 | check conditions (condition proper, frame, thread and ignore count) |
| 5348 | of breakpoint referred to by BS. If we should not stop for this |
| 5349 | breakpoint, set BS->stop to 0. */ |
| 5350 | |
| 5351 | static void |
| 5352 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) |
| 5353 | { |
| 5354 | const struct bp_location *bl; |
| 5355 | struct breakpoint *b; |
| 5356 | int value_is_zero = 0; |
| 5357 | struct expression *cond; |
| 5358 | |
| 5359 | gdb_assert (bs->stop); |
| 5360 | |
| 5361 | /* BS is built for existing struct breakpoint. */ |
| 5362 | bl = bs->bp_location_at; |
| 5363 | gdb_assert (bl != NULL); |
| 5364 | b = bs->breakpoint_at; |
| 5365 | gdb_assert (b != NULL); |
| 5366 | |
| 5367 | /* Even if the target evaluated the condition on its end and notified GDB, we |
| 5368 | need to do so again since GDB does not know if we stopped due to a |
| 5369 | breakpoint or a single step breakpoint. */ |
| 5370 | |
| 5371 | if (frame_id_p (b->frame_id) |
| 5372 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
| 5373 | { |
| 5374 | bs->stop = 0; |
| 5375 | return; |
| 5376 | } |
| 5377 | |
| 5378 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
| 5379 | evaluating the condition if this isn't the specified |
| 5380 | thread/task. */ |
| 5381 | if ((b->thread != -1 && b->thread != pid_to_thread_id (ptid)) |
| 5382 | || (b->task != 0 && b->task != ada_get_task_number (ptid))) |
| 5383 | |
| 5384 | { |
| 5385 | bs->stop = 0; |
| 5386 | return; |
| 5387 | } |
| 5388 | |
| 5389 | /* Evaluate extension language breakpoints that have a "stop" method |
| 5390 | implemented. */ |
| 5391 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); |
| 5392 | |
| 5393 | if (is_watchpoint (b)) |
| 5394 | { |
| 5395 | struct watchpoint *w = (struct watchpoint *) b; |
| 5396 | |
| 5397 | cond = w->cond_exp; |
| 5398 | } |
| 5399 | else |
| 5400 | cond = bl->cond; |
| 5401 | |
| 5402 | if (cond && b->disposition != disp_del_at_next_stop) |
| 5403 | { |
| 5404 | int within_current_scope = 1; |
| 5405 | struct watchpoint * w; |
| 5406 | |
| 5407 | /* We use value_mark and value_free_to_mark because it could |
| 5408 | be a long time before we return to the command level and |
| 5409 | call free_all_values. We can't call free_all_values |
| 5410 | because we might be in the middle of evaluating a |
| 5411 | function call. */ |
| 5412 | struct value *mark = value_mark (); |
| 5413 | |
| 5414 | if (is_watchpoint (b)) |
| 5415 | w = (struct watchpoint *) b; |
| 5416 | else |
| 5417 | w = NULL; |
| 5418 | |
| 5419 | /* Need to select the frame, with all that implies so that |
| 5420 | the conditions will have the right context. Because we |
| 5421 | use the frame, we will not see an inlined function's |
| 5422 | variables when we arrive at a breakpoint at the start |
| 5423 | of the inlined function; the current frame will be the |
| 5424 | call site. */ |
| 5425 | if (w == NULL || w->cond_exp_valid_block == NULL) |
| 5426 | select_frame (get_current_frame ()); |
| 5427 | else |
| 5428 | { |
| 5429 | struct frame_info *frame; |
| 5430 | |
| 5431 | /* For local watchpoint expressions, which particular |
| 5432 | instance of a local is being watched matters, so we |
| 5433 | keep track of the frame to evaluate the expression |
| 5434 | in. To evaluate the condition however, it doesn't |
| 5435 | really matter which instantiation of the function |
| 5436 | where the condition makes sense triggers the |
| 5437 | watchpoint. This allows an expression like "watch |
| 5438 | global if q > 10" set in `func', catch writes to |
| 5439 | global on all threads that call `func', or catch |
| 5440 | writes on all recursive calls of `func' by a single |
| 5441 | thread. We simply always evaluate the condition in |
| 5442 | the innermost frame that's executing where it makes |
| 5443 | sense to evaluate the condition. It seems |
| 5444 | intuitive. */ |
| 5445 | frame = block_innermost_frame (w->cond_exp_valid_block); |
| 5446 | if (frame != NULL) |
| 5447 | select_frame (frame); |
| 5448 | else |
| 5449 | within_current_scope = 0; |
| 5450 | } |
| 5451 | if (within_current_scope) |
| 5452 | value_is_zero |
| 5453 | = catch_errors (breakpoint_cond_eval, cond, |
| 5454 | "Error in testing breakpoint condition:\n", |
| 5455 | RETURN_MASK_ALL); |
| 5456 | else |
| 5457 | { |
| 5458 | warning (_("Watchpoint condition cannot be tested " |
| 5459 | "in the current scope")); |
| 5460 | /* If we failed to set the right context for this |
| 5461 | watchpoint, unconditionally report it. */ |
| 5462 | value_is_zero = 0; |
| 5463 | } |
| 5464 | /* FIXME-someday, should give breakpoint #. */ |
| 5465 | value_free_to_mark (mark); |
| 5466 | } |
| 5467 | |
| 5468 | if (cond && value_is_zero) |
| 5469 | { |
| 5470 | bs->stop = 0; |
| 5471 | } |
| 5472 | else if (b->ignore_count > 0) |
| 5473 | { |
| 5474 | b->ignore_count--; |
| 5475 | bs->stop = 0; |
| 5476 | /* Increase the hit count even though we don't stop. */ |
| 5477 | ++(b->hit_count); |
| 5478 | observer_notify_breakpoint_modified (b); |
| 5479 | } |
| 5480 | } |
| 5481 | |
| 5482 | /* Returns true if we need to track moribund locations of LOC's type |
| 5483 | on the current target. */ |
| 5484 | |
| 5485 | static int |
| 5486 | need_moribund_for_location_type (struct bp_location *loc) |
| 5487 | { |
| 5488 | return ((loc->loc_type == bp_loc_software_breakpoint |
| 5489 | && !target_supports_stopped_by_sw_breakpoint ()) |
| 5490 | || (loc->loc_type == bp_loc_hardware_breakpoint |
| 5491 | && !target_supports_stopped_by_hw_breakpoint ())); |
| 5492 | } |
| 5493 | |
| 5494 | |
| 5495 | /* Get a bpstat associated with having just stopped at address |
| 5496 | BP_ADDR in thread PTID. |
| 5497 | |
| 5498 | Determine whether we stopped at a breakpoint, etc, or whether we |
| 5499 | don't understand this stop. Result is a chain of bpstat's such |
| 5500 | that: |
| 5501 | |
| 5502 | if we don't understand the stop, the result is a null pointer. |
| 5503 | |
| 5504 | if we understand why we stopped, the result is not null. |
| 5505 | |
| 5506 | Each element of the chain refers to a particular breakpoint or |
| 5507 | watchpoint at which we have stopped. (We may have stopped for |
| 5508 | several reasons concurrently.) |
| 5509 | |
| 5510 | Each element of the chain has valid next, breakpoint_at, |
| 5511 | commands, FIXME??? fields. */ |
| 5512 | |
| 5513 | bpstat |
| 5514 | bpstat_stop_status (struct address_space *aspace, |
| 5515 | CORE_ADDR bp_addr, ptid_t ptid, |
| 5516 | const struct target_waitstatus *ws) |
| 5517 | { |
| 5518 | struct breakpoint *b = NULL; |
| 5519 | struct bp_location *bl; |
| 5520 | struct bp_location *loc; |
| 5521 | /* First item of allocated bpstat's. */ |
| 5522 | bpstat bs_head = NULL, *bs_link = &bs_head; |
| 5523 | /* Pointer to the last thing in the chain currently. */ |
| 5524 | bpstat bs; |
| 5525 | int ix; |
| 5526 | int need_remove_insert; |
| 5527 | int removed_any; |
| 5528 | |
| 5529 | /* First, build the bpstat chain with locations that explain a |
| 5530 | target stop, while being careful to not set the target running, |
| 5531 | as that may invalidate locations (in particular watchpoint |
| 5532 | locations are recreated). Resuming will happen here with |
| 5533 | breakpoint conditions or watchpoint expressions that include |
| 5534 | inferior function calls. */ |
| 5535 | |
| 5536 | ALL_BREAKPOINTS (b) |
| 5537 | { |
| 5538 | if (!breakpoint_enabled (b)) |
| 5539 | continue; |
| 5540 | |
| 5541 | for (bl = b->loc; bl != NULL; bl = bl->next) |
| 5542 | { |
| 5543 | /* For hardware watchpoints, we look only at the first |
| 5544 | location. The watchpoint_check function will work on the |
| 5545 | entire expression, not the individual locations. For |
| 5546 | read watchpoints, the watchpoints_triggered function has |
| 5547 | checked all locations already. */ |
| 5548 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
| 5549 | break; |
| 5550 | |
| 5551 | if (!bl->enabled || bl->shlib_disabled) |
| 5552 | continue; |
| 5553 | |
| 5554 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
| 5555 | continue; |
| 5556 | |
| 5557 | /* Come here if it's a watchpoint, or if the break address |
| 5558 | matches. */ |
| 5559 | |
| 5560 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
| 5561 | explain stop. */ |
| 5562 | |
| 5563 | /* Assume we stop. Should we find a watchpoint that is not |
| 5564 | actually triggered, or if the condition of the breakpoint |
| 5565 | evaluates as false, we'll reset 'stop' to 0. */ |
| 5566 | bs->stop = 1; |
| 5567 | bs->print = 1; |
| 5568 | |
| 5569 | /* If this is a scope breakpoint, mark the associated |
| 5570 | watchpoint as triggered so that we will handle the |
| 5571 | out-of-scope event. We'll get to the watchpoint next |
| 5572 | iteration. */ |
| 5573 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
| 5574 | { |
| 5575 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; |
| 5576 | |
| 5577 | w->watchpoint_triggered = watch_triggered_yes; |
| 5578 | } |
| 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | /* Check if a moribund breakpoint explains the stop. */ |
| 5583 | if (!target_supports_stopped_by_sw_breakpoint () |
| 5584 | || !target_supports_stopped_by_hw_breakpoint ()) |
| 5585 | { |
| 5586 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 5587 | { |
| 5588 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
| 5589 | && need_moribund_for_location_type (loc)) |
| 5590 | { |
| 5591 | bs = bpstat_alloc (loc, &bs_link); |
| 5592 | /* For hits of moribund locations, we should just proceed. */ |
| 5593 | bs->stop = 0; |
| 5594 | bs->print = 0; |
| 5595 | bs->print_it = print_it_noop; |
| 5596 | } |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | /* A bit of special processing for shlib breakpoints. We need to |
| 5601 | process solib loading here, so that the lists of loaded and |
| 5602 | unloaded libraries are correct before we handle "catch load" and |
| 5603 | "catch unload". */ |
| 5604 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5605 | { |
| 5606 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
| 5607 | { |
| 5608 | handle_solib_event (); |
| 5609 | break; |
| 5610 | } |
| 5611 | } |
| 5612 | |
| 5613 | /* Now go through the locations that caused the target to stop, and |
| 5614 | check whether we're interested in reporting this stop to higher |
| 5615 | layers, or whether we should resume the target transparently. */ |
| 5616 | |
| 5617 | removed_any = 0; |
| 5618 | |
| 5619 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5620 | { |
| 5621 | if (!bs->stop) |
| 5622 | continue; |
| 5623 | |
| 5624 | b = bs->breakpoint_at; |
| 5625 | b->ops->check_status (bs); |
| 5626 | if (bs->stop) |
| 5627 | { |
| 5628 | bpstat_check_breakpoint_conditions (bs, ptid); |
| 5629 | |
| 5630 | if (bs->stop) |
| 5631 | { |
| 5632 | ++(b->hit_count); |
| 5633 | observer_notify_breakpoint_modified (b); |
| 5634 | |
| 5635 | /* We will stop here. */ |
| 5636 | if (b->disposition == disp_disable) |
| 5637 | { |
| 5638 | --(b->enable_count); |
| 5639 | if (b->enable_count <= 0) |
| 5640 | b->enable_state = bp_disabled; |
| 5641 | removed_any = 1; |
| 5642 | } |
| 5643 | if (b->silent) |
| 5644 | bs->print = 0; |
| 5645 | bs->commands = b->commands; |
| 5646 | incref_counted_command_line (bs->commands); |
| 5647 | if (command_line_is_silent (bs->commands |
| 5648 | ? bs->commands->commands : NULL)) |
| 5649 | bs->print = 0; |
| 5650 | |
| 5651 | b->ops->after_condition_true (bs); |
| 5652 | } |
| 5653 | |
| 5654 | } |
| 5655 | |
| 5656 | /* Print nothing for this entry if we don't stop or don't |
| 5657 | print. */ |
| 5658 | if (!bs->stop || !bs->print) |
| 5659 | bs->print_it = print_it_noop; |
| 5660 | } |
| 5661 | |
| 5662 | /* If we aren't stopping, the value of some hardware watchpoint may |
| 5663 | not have changed, but the intermediate memory locations we are |
| 5664 | watching may have. Don't bother if we're stopping; this will get |
| 5665 | done later. */ |
| 5666 | need_remove_insert = 0; |
| 5667 | if (! bpstat_causes_stop (bs_head)) |
| 5668 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5669 | if (!bs->stop |
| 5670 | && bs->breakpoint_at |
| 5671 | && is_hardware_watchpoint (bs->breakpoint_at)) |
| 5672 | { |
| 5673 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
| 5674 | |
| 5675 | update_watchpoint (w, 0 /* don't reparse. */); |
| 5676 | need_remove_insert = 1; |
| 5677 | } |
| 5678 | |
| 5679 | if (need_remove_insert) |
| 5680 | update_global_location_list (UGLL_MAY_INSERT); |
| 5681 | else if (removed_any) |
| 5682 | update_global_location_list (UGLL_DONT_INSERT); |
| 5683 | |
| 5684 | return bs_head; |
| 5685 | } |
| 5686 | |
| 5687 | static void |
| 5688 | handle_jit_event (void) |
| 5689 | { |
| 5690 | struct frame_info *frame; |
| 5691 | struct gdbarch *gdbarch; |
| 5692 | |
| 5693 | /* Switch terminal for any messages produced by |
| 5694 | breakpoint_re_set. */ |
| 5695 | target_terminal_ours_for_output (); |
| 5696 | |
| 5697 | frame = get_current_frame (); |
| 5698 | gdbarch = get_frame_arch (frame); |
| 5699 | |
| 5700 | jit_event_handler (gdbarch); |
| 5701 | |
| 5702 | target_terminal_inferior (); |
| 5703 | } |
| 5704 | |
| 5705 | /* Prepare WHAT final decision for infrun. */ |
| 5706 | |
| 5707 | /* Decide what infrun needs to do with this bpstat. */ |
| 5708 | |
| 5709 | struct bpstat_what |
| 5710 | bpstat_what (bpstat bs_head) |
| 5711 | { |
| 5712 | struct bpstat_what retval; |
| 5713 | int jit_event = 0; |
| 5714 | bpstat bs; |
| 5715 | |
| 5716 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5717 | retval.call_dummy = STOP_NONE; |
| 5718 | retval.is_longjmp = 0; |
| 5719 | |
| 5720 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5721 | { |
| 5722 | /* Extract this BS's action. After processing each BS, we check |
| 5723 | if its action overrides all we've seem so far. */ |
| 5724 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5725 | enum bptype bptype; |
| 5726 | |
| 5727 | if (bs->breakpoint_at == NULL) |
| 5728 | { |
| 5729 | /* I suspect this can happen if it was a momentary |
| 5730 | breakpoint which has since been deleted. */ |
| 5731 | bptype = bp_none; |
| 5732 | } |
| 5733 | else |
| 5734 | bptype = bs->breakpoint_at->type; |
| 5735 | |
| 5736 | switch (bptype) |
| 5737 | { |
| 5738 | case bp_none: |
| 5739 | break; |
| 5740 | case bp_breakpoint: |
| 5741 | case bp_hardware_breakpoint: |
| 5742 | case bp_single_step: |
| 5743 | case bp_until: |
| 5744 | case bp_finish: |
| 5745 | case bp_shlib_event: |
| 5746 | if (bs->stop) |
| 5747 | { |
| 5748 | if (bs->print) |
| 5749 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5750 | else |
| 5751 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5752 | } |
| 5753 | else |
| 5754 | this_action = BPSTAT_WHAT_SINGLE; |
| 5755 | break; |
| 5756 | case bp_watchpoint: |
| 5757 | case bp_hardware_watchpoint: |
| 5758 | case bp_read_watchpoint: |
| 5759 | case bp_access_watchpoint: |
| 5760 | if (bs->stop) |
| 5761 | { |
| 5762 | if (bs->print) |
| 5763 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5764 | else |
| 5765 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5766 | } |
| 5767 | else |
| 5768 | { |
| 5769 | /* There was a watchpoint, but we're not stopping. |
| 5770 | This requires no further action. */ |
| 5771 | } |
| 5772 | break; |
| 5773 | case bp_longjmp: |
| 5774 | case bp_longjmp_call_dummy: |
| 5775 | case bp_exception: |
| 5776 | if (bs->stop) |
| 5777 | { |
| 5778 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
| 5779 | retval.is_longjmp = bptype != bp_exception; |
| 5780 | } |
| 5781 | else |
| 5782 | this_action = BPSTAT_WHAT_SINGLE; |
| 5783 | break; |
| 5784 | case bp_longjmp_resume: |
| 5785 | case bp_exception_resume: |
| 5786 | if (bs->stop) |
| 5787 | { |
| 5788 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
| 5789 | retval.is_longjmp = bptype == bp_longjmp_resume; |
| 5790 | } |
| 5791 | else |
| 5792 | this_action = BPSTAT_WHAT_SINGLE; |
| 5793 | break; |
| 5794 | case bp_step_resume: |
| 5795 | if (bs->stop) |
| 5796 | this_action = BPSTAT_WHAT_STEP_RESUME; |
| 5797 | else |
| 5798 | { |
| 5799 | /* It is for the wrong frame. */ |
| 5800 | this_action = BPSTAT_WHAT_SINGLE; |
| 5801 | } |
| 5802 | break; |
| 5803 | case bp_hp_step_resume: |
| 5804 | if (bs->stop) |
| 5805 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; |
| 5806 | else |
| 5807 | { |
| 5808 | /* It is for the wrong frame. */ |
| 5809 | this_action = BPSTAT_WHAT_SINGLE; |
| 5810 | } |
| 5811 | break; |
| 5812 | case bp_watchpoint_scope: |
| 5813 | case bp_thread_event: |
| 5814 | case bp_overlay_event: |
| 5815 | case bp_longjmp_master: |
| 5816 | case bp_std_terminate_master: |
| 5817 | case bp_exception_master: |
| 5818 | this_action = BPSTAT_WHAT_SINGLE; |
| 5819 | break; |
| 5820 | case bp_catchpoint: |
| 5821 | if (bs->stop) |
| 5822 | { |
| 5823 | if (bs->print) |
| 5824 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5825 | else |
| 5826 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5827 | } |
| 5828 | else |
| 5829 | { |
| 5830 | /* There was a catchpoint, but we're not stopping. |
| 5831 | This requires no further action. */ |
| 5832 | } |
| 5833 | break; |
| 5834 | case bp_jit_event: |
| 5835 | jit_event = 1; |
| 5836 | this_action = BPSTAT_WHAT_SINGLE; |
| 5837 | break; |
| 5838 | case bp_call_dummy: |
| 5839 | /* Make sure the action is stop (silent or noisy), |
| 5840 | so infrun.c pops the dummy frame. */ |
| 5841 | retval.call_dummy = STOP_STACK_DUMMY; |
| 5842 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5843 | break; |
| 5844 | case bp_std_terminate: |
| 5845 | /* Make sure the action is stop (silent or noisy), |
| 5846 | so infrun.c pops the dummy frame. */ |
| 5847 | retval.call_dummy = STOP_STD_TERMINATE; |
| 5848 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5849 | break; |
| 5850 | case bp_tracepoint: |
| 5851 | case bp_fast_tracepoint: |
| 5852 | case bp_static_tracepoint: |
| 5853 | /* Tracepoint hits should not be reported back to GDB, and |
| 5854 | if one got through somehow, it should have been filtered |
| 5855 | out already. */ |
| 5856 | internal_error (__FILE__, __LINE__, |
| 5857 | _("bpstat_what: tracepoint encountered")); |
| 5858 | break; |
| 5859 | case bp_gnu_ifunc_resolver: |
| 5860 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ |
| 5861 | this_action = BPSTAT_WHAT_SINGLE; |
| 5862 | break; |
| 5863 | case bp_gnu_ifunc_resolver_return: |
| 5864 | /* The breakpoint will be removed, execution will restart from the |
| 5865 | PC of the former breakpoint. */ |
| 5866 | this_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5867 | break; |
| 5868 | |
| 5869 | case bp_dprintf: |
| 5870 | if (bs->stop) |
| 5871 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5872 | else |
| 5873 | this_action = BPSTAT_WHAT_SINGLE; |
| 5874 | break; |
| 5875 | |
| 5876 | default: |
| 5877 | internal_error (__FILE__, __LINE__, |
| 5878 | _("bpstat_what: unhandled bptype %d"), (int) bptype); |
| 5879 | } |
| 5880 | |
| 5881 | retval.main_action = max (retval.main_action, this_action); |
| 5882 | } |
| 5883 | |
| 5884 | /* These operations may affect the bs->breakpoint_at state so they are |
| 5885 | delayed after MAIN_ACTION is decided above. */ |
| 5886 | |
| 5887 | if (jit_event) |
| 5888 | { |
| 5889 | if (debug_infrun) |
| 5890 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); |
| 5891 | |
| 5892 | handle_jit_event (); |
| 5893 | } |
| 5894 | |
| 5895 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5896 | { |
| 5897 | struct breakpoint *b = bs->breakpoint_at; |
| 5898 | |
| 5899 | if (b == NULL) |
| 5900 | continue; |
| 5901 | switch (b->type) |
| 5902 | { |
| 5903 | case bp_gnu_ifunc_resolver: |
| 5904 | gnu_ifunc_resolver_stop (b); |
| 5905 | break; |
| 5906 | case bp_gnu_ifunc_resolver_return: |
| 5907 | gnu_ifunc_resolver_return_stop (b); |
| 5908 | break; |
| 5909 | } |
| 5910 | } |
| 5911 | |
| 5912 | return retval; |
| 5913 | } |
| 5914 | |
| 5915 | /* Nonzero if we should step constantly (e.g. watchpoints on machines |
| 5916 | without hardware support). This isn't related to a specific bpstat, |
| 5917 | just to things like whether watchpoints are set. */ |
| 5918 | |
| 5919 | int |
| 5920 | bpstat_should_step (void) |
| 5921 | { |
| 5922 | struct breakpoint *b; |
| 5923 | |
| 5924 | ALL_BREAKPOINTS (b) |
| 5925 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
| 5926 | return 1; |
| 5927 | return 0; |
| 5928 | } |
| 5929 | |
| 5930 | int |
| 5931 | bpstat_causes_stop (bpstat bs) |
| 5932 | { |
| 5933 | for (; bs != NULL; bs = bs->next) |
| 5934 | if (bs->stop) |
| 5935 | return 1; |
| 5936 | |
| 5937 | return 0; |
| 5938 | } |
| 5939 | |
| 5940 | \f |
| 5941 | |
| 5942 | /* Compute a string of spaces suitable to indent the next line |
| 5943 | so it starts at the position corresponding to the table column |
| 5944 | named COL_NAME in the currently active table of UIOUT. */ |
| 5945 | |
| 5946 | static char * |
| 5947 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) |
| 5948 | { |
| 5949 | static char wrap_indent[80]; |
| 5950 | int i, total_width, width, align; |
| 5951 | char *text; |
| 5952 | |
| 5953 | total_width = 0; |
| 5954 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) |
| 5955 | { |
| 5956 | if (strcmp (text, col_name) == 0) |
| 5957 | { |
| 5958 | gdb_assert (total_width < sizeof wrap_indent); |
| 5959 | memset (wrap_indent, ' ', total_width); |
| 5960 | wrap_indent[total_width] = 0; |
| 5961 | |
| 5962 | return wrap_indent; |
| 5963 | } |
| 5964 | |
| 5965 | total_width += width + 1; |
| 5966 | } |
| 5967 | |
| 5968 | return NULL; |
| 5969 | } |
| 5970 | |
| 5971 | /* Determine if the locations of this breakpoint will have their conditions |
| 5972 | evaluated by the target, host or a mix of both. Returns the following: |
| 5973 | |
| 5974 | "host": Host evals condition. |
| 5975 | "host or target": Host or Target evals condition. |
| 5976 | "target": Target evals condition. |
| 5977 | */ |
| 5978 | |
| 5979 | static const char * |
| 5980 | bp_condition_evaluator (struct breakpoint *b) |
| 5981 | { |
| 5982 | struct bp_location *bl; |
| 5983 | char host_evals = 0; |
| 5984 | char target_evals = 0; |
| 5985 | |
| 5986 | if (!b) |
| 5987 | return NULL; |
| 5988 | |
| 5989 | if (!is_breakpoint (b)) |
| 5990 | return NULL; |
| 5991 | |
| 5992 | if (gdb_evaluates_breakpoint_condition_p () |
| 5993 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 5994 | return condition_evaluation_host; |
| 5995 | |
| 5996 | for (bl = b->loc; bl; bl = bl->next) |
| 5997 | { |
| 5998 | if (bl->cond_bytecode) |
| 5999 | target_evals++; |
| 6000 | else |
| 6001 | host_evals++; |
| 6002 | } |
| 6003 | |
| 6004 | if (host_evals && target_evals) |
| 6005 | return condition_evaluation_both; |
| 6006 | else if (target_evals) |
| 6007 | return condition_evaluation_target; |
| 6008 | else |
| 6009 | return condition_evaluation_host; |
| 6010 | } |
| 6011 | |
| 6012 | /* Determine the breakpoint location's condition evaluator. This is |
| 6013 | similar to bp_condition_evaluator, but for locations. */ |
| 6014 | |
| 6015 | static const char * |
| 6016 | bp_location_condition_evaluator (struct bp_location *bl) |
| 6017 | { |
| 6018 | if (bl && !is_breakpoint (bl->owner)) |
| 6019 | return NULL; |
| 6020 | |
| 6021 | if (gdb_evaluates_breakpoint_condition_p () |
| 6022 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 6023 | return condition_evaluation_host; |
| 6024 | |
| 6025 | if (bl && bl->cond_bytecode) |
| 6026 | return condition_evaluation_target; |
| 6027 | else |
| 6028 | return condition_evaluation_host; |
| 6029 | } |
| 6030 | |
| 6031 | /* Print the LOC location out of the list of B->LOC locations. */ |
| 6032 | |
| 6033 | static void |
| 6034 | print_breakpoint_location (struct breakpoint *b, |
| 6035 | struct bp_location *loc) |
| 6036 | { |
| 6037 | struct ui_out *uiout = current_uiout; |
| 6038 | struct cleanup *old_chain = save_current_program_space (); |
| 6039 | |
| 6040 | if (loc != NULL && loc->shlib_disabled) |
| 6041 | loc = NULL; |
| 6042 | |
| 6043 | if (loc != NULL) |
| 6044 | set_current_program_space (loc->pspace); |
| 6045 | |
| 6046 | if (b->display_canonical) |
| 6047 | ui_out_field_string (uiout, "what", |
| 6048 | event_location_to_string (b->location)); |
| 6049 | else if (loc && loc->symtab) |
| 6050 | { |
| 6051 | struct symbol *sym |
| 6052 | = find_pc_sect_function (loc->address, loc->section); |
| 6053 | if (sym) |
| 6054 | { |
| 6055 | ui_out_text (uiout, "in "); |
| 6056 | ui_out_field_string (uiout, "func", |
| 6057 | SYMBOL_PRINT_NAME (sym)); |
| 6058 | ui_out_text (uiout, " "); |
| 6059 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); |
| 6060 | ui_out_text (uiout, "at "); |
| 6061 | } |
| 6062 | ui_out_field_string (uiout, "file", |
| 6063 | symtab_to_filename_for_display (loc->symtab)); |
| 6064 | ui_out_text (uiout, ":"); |
| 6065 | |
| 6066 | if (ui_out_is_mi_like_p (uiout)) |
| 6067 | ui_out_field_string (uiout, "fullname", |
| 6068 | symtab_to_fullname (loc->symtab)); |
| 6069 | |
| 6070 | ui_out_field_int (uiout, "line", loc->line_number); |
| 6071 | } |
| 6072 | else if (loc) |
| 6073 | { |
| 6074 | struct ui_file *stb = mem_fileopen (); |
| 6075 | struct cleanup *stb_chain = make_cleanup_ui_file_delete (stb); |
| 6076 | |
| 6077 | print_address_symbolic (loc->gdbarch, loc->address, stb, |
| 6078 | demangle, ""); |
| 6079 | ui_out_field_stream (uiout, "at", stb); |
| 6080 | |
| 6081 | do_cleanups (stb_chain); |
| 6082 | } |
| 6083 | else |
| 6084 | { |
| 6085 | ui_out_field_string (uiout, "pending", |
| 6086 | event_location_to_string (b->location)); |
| 6087 | /* If extra_string is available, it could be holding a condition |
| 6088 | or dprintf arguments. In either case, make sure it is printed, |
| 6089 | too, but only for non-MI streams. */ |
| 6090 | if (!ui_out_is_mi_like_p (uiout) && b->extra_string != NULL) |
| 6091 | { |
| 6092 | if (b->type == bp_dprintf) |
| 6093 | ui_out_text (uiout, ","); |
| 6094 | else |
| 6095 | ui_out_text (uiout, " "); |
| 6096 | ui_out_text (uiout, b->extra_string); |
| 6097 | } |
| 6098 | } |
| 6099 | |
| 6100 | if (loc && is_breakpoint (b) |
| 6101 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target |
| 6102 | && bp_condition_evaluator (b) == condition_evaluation_both) |
| 6103 | { |
| 6104 | ui_out_text (uiout, " ("); |
| 6105 | ui_out_field_string (uiout, "evaluated-by", |
| 6106 | bp_location_condition_evaluator (loc)); |
| 6107 | ui_out_text (uiout, ")"); |
| 6108 | } |
| 6109 | |
| 6110 | do_cleanups (old_chain); |
| 6111 | } |
| 6112 | |
| 6113 | static const char * |
| 6114 | bptype_string (enum bptype type) |
| 6115 | { |
| 6116 | struct ep_type_description |
| 6117 | { |
| 6118 | enum bptype type; |
| 6119 | char *description; |
| 6120 | }; |
| 6121 | static struct ep_type_description bptypes[] = |
| 6122 | { |
| 6123 | {bp_none, "?deleted?"}, |
| 6124 | {bp_breakpoint, "breakpoint"}, |
| 6125 | {bp_hardware_breakpoint, "hw breakpoint"}, |
| 6126 | {bp_single_step, "sw single-step"}, |
| 6127 | {bp_until, "until"}, |
| 6128 | {bp_finish, "finish"}, |
| 6129 | {bp_watchpoint, "watchpoint"}, |
| 6130 | {bp_hardware_watchpoint, "hw watchpoint"}, |
| 6131 | {bp_read_watchpoint, "read watchpoint"}, |
| 6132 | {bp_access_watchpoint, "acc watchpoint"}, |
| 6133 | {bp_longjmp, "longjmp"}, |
| 6134 | {bp_longjmp_resume, "longjmp resume"}, |
| 6135 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
| 6136 | {bp_exception, "exception"}, |
| 6137 | {bp_exception_resume, "exception resume"}, |
| 6138 | {bp_step_resume, "step resume"}, |
| 6139 | {bp_hp_step_resume, "high-priority step resume"}, |
| 6140 | {bp_watchpoint_scope, "watchpoint scope"}, |
| 6141 | {bp_call_dummy, "call dummy"}, |
| 6142 | {bp_std_terminate, "std::terminate"}, |
| 6143 | {bp_shlib_event, "shlib events"}, |
| 6144 | {bp_thread_event, "thread events"}, |
| 6145 | {bp_overlay_event, "overlay events"}, |
| 6146 | {bp_longjmp_master, "longjmp master"}, |
| 6147 | {bp_std_terminate_master, "std::terminate master"}, |
| 6148 | {bp_exception_master, "exception master"}, |
| 6149 | {bp_catchpoint, "catchpoint"}, |
| 6150 | {bp_tracepoint, "tracepoint"}, |
| 6151 | {bp_fast_tracepoint, "fast tracepoint"}, |
| 6152 | {bp_static_tracepoint, "static tracepoint"}, |
| 6153 | {bp_dprintf, "dprintf"}, |
| 6154 | {bp_jit_event, "jit events"}, |
| 6155 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
| 6156 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, |
| 6157 | }; |
| 6158 | |
| 6159 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) |
| 6160 | || ((int) type != bptypes[(int) type].type)) |
| 6161 | internal_error (__FILE__, __LINE__, |
| 6162 | _("bptypes table does not describe type #%d."), |
| 6163 | (int) type); |
| 6164 | |
| 6165 | return bptypes[(int) type].description; |
| 6166 | } |
| 6167 | |
| 6168 | /* For MI, output a field named 'thread-groups' with a list as the value. |
| 6169 | For CLI, prefix the list with the string 'inf'. */ |
| 6170 | |
| 6171 | static void |
| 6172 | output_thread_groups (struct ui_out *uiout, |
| 6173 | const char *field_name, |
| 6174 | VEC(int) *inf_num, |
| 6175 | int mi_only) |
| 6176 | { |
| 6177 | struct cleanup *back_to; |
| 6178 | int is_mi = ui_out_is_mi_like_p (uiout); |
| 6179 | int inf; |
| 6180 | int i; |
| 6181 | |
| 6182 | /* For backward compatibility, don't display inferiors in CLI unless |
| 6183 | there are several. Always display them for MI. */ |
| 6184 | if (!is_mi && mi_only) |
| 6185 | return; |
| 6186 | |
| 6187 | back_to = make_cleanup_ui_out_list_begin_end (uiout, field_name); |
| 6188 | |
| 6189 | for (i = 0; VEC_iterate (int, inf_num, i, inf); ++i) |
| 6190 | { |
| 6191 | if (is_mi) |
| 6192 | { |
| 6193 | char mi_group[10]; |
| 6194 | |
| 6195 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf); |
| 6196 | ui_out_field_string (uiout, NULL, mi_group); |
| 6197 | } |
| 6198 | else |
| 6199 | { |
| 6200 | if (i == 0) |
| 6201 | ui_out_text (uiout, " inf "); |
| 6202 | else |
| 6203 | ui_out_text (uiout, ", "); |
| 6204 | |
| 6205 | ui_out_text (uiout, plongest (inf)); |
| 6206 | } |
| 6207 | } |
| 6208 | |
| 6209 | do_cleanups (back_to); |
| 6210 | } |
| 6211 | |
| 6212 | /* Print B to gdb_stdout. */ |
| 6213 | |
| 6214 | static void |
| 6215 | print_one_breakpoint_location (struct breakpoint *b, |
| 6216 | struct bp_location *loc, |
| 6217 | int loc_number, |
| 6218 | struct bp_location **last_loc, |
| 6219 | int allflag) |
| 6220 | { |
| 6221 | struct command_line *l; |
| 6222 | static char bpenables[] = "nynny"; |
| 6223 | |
| 6224 | struct ui_out *uiout = current_uiout; |
| 6225 | int header_of_multiple = 0; |
| 6226 | int part_of_multiple = (loc != NULL); |
| 6227 | struct value_print_options opts; |
| 6228 | |
| 6229 | get_user_print_options (&opts); |
| 6230 | |
| 6231 | gdb_assert (!loc || loc_number != 0); |
| 6232 | /* See comment in print_one_breakpoint concerning treatment of |
| 6233 | breakpoints with single disabled location. */ |
| 6234 | if (loc == NULL |
| 6235 | && (b->loc != NULL |
| 6236 | && (b->loc->next != NULL || !b->loc->enabled))) |
| 6237 | header_of_multiple = 1; |
| 6238 | if (loc == NULL) |
| 6239 | loc = b->loc; |
| 6240 | |
| 6241 | annotate_record (); |
| 6242 | |
| 6243 | /* 1 */ |
| 6244 | annotate_field (0); |
| 6245 | if (part_of_multiple) |
| 6246 | { |
| 6247 | char *formatted; |
| 6248 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
| 6249 | ui_out_field_string (uiout, "number", formatted); |
| 6250 | xfree (formatted); |
| 6251 | } |
| 6252 | else |
| 6253 | { |
| 6254 | ui_out_field_int (uiout, "number", b->number); |
| 6255 | } |
| 6256 | |
| 6257 | /* 2 */ |
| 6258 | annotate_field (1); |
| 6259 | if (part_of_multiple) |
| 6260 | ui_out_field_skip (uiout, "type"); |
| 6261 | else |
| 6262 | ui_out_field_string (uiout, "type", bptype_string (b->type)); |
| 6263 | |
| 6264 | /* 3 */ |
| 6265 | annotate_field (2); |
| 6266 | if (part_of_multiple) |
| 6267 | ui_out_field_skip (uiout, "disp"); |
| 6268 | else |
| 6269 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 6270 | |
| 6271 | |
| 6272 | /* 4 */ |
| 6273 | annotate_field (3); |
| 6274 | if (part_of_multiple) |
| 6275 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
| 6276 | else |
| 6277 | ui_out_field_fmt (uiout, "enabled", "%c", |
| 6278 | bpenables[(int) b->enable_state]); |
| 6279 | ui_out_spaces (uiout, 2); |
| 6280 | |
| 6281 | |
| 6282 | /* 5 and 6 */ |
| 6283 | if (b->ops != NULL && b->ops->print_one != NULL) |
| 6284 | { |
| 6285 | /* Although the print_one can possibly print all locations, |
| 6286 | calling it here is not likely to get any nice result. So, |
| 6287 | make sure there's just one location. */ |
| 6288 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
| 6289 | b->ops->print_one (b, last_loc); |
| 6290 | } |
| 6291 | else |
| 6292 | switch (b->type) |
| 6293 | { |
| 6294 | case bp_none: |
| 6295 | internal_error (__FILE__, __LINE__, |
| 6296 | _("print_one_breakpoint: bp_none encountered\n")); |
| 6297 | break; |
| 6298 | |
| 6299 | case bp_watchpoint: |
| 6300 | case bp_hardware_watchpoint: |
| 6301 | case bp_read_watchpoint: |
| 6302 | case bp_access_watchpoint: |
| 6303 | { |
| 6304 | struct watchpoint *w = (struct watchpoint *) b; |
| 6305 | |
| 6306 | /* Field 4, the address, is omitted (which makes the columns |
| 6307 | not line up too nicely with the headers, but the effect |
| 6308 | is relatively readable). */ |
| 6309 | if (opts.addressprint) |
| 6310 | ui_out_field_skip (uiout, "addr"); |
| 6311 | annotate_field (5); |
| 6312 | ui_out_field_string (uiout, "what", w->exp_string); |
| 6313 | } |
| 6314 | break; |
| 6315 | |
| 6316 | case bp_breakpoint: |
| 6317 | case bp_hardware_breakpoint: |
| 6318 | case bp_single_step: |
| 6319 | case bp_until: |
| 6320 | case bp_finish: |
| 6321 | case bp_longjmp: |
| 6322 | case bp_longjmp_resume: |
| 6323 | case bp_longjmp_call_dummy: |
| 6324 | case bp_exception: |
| 6325 | case bp_exception_resume: |
| 6326 | case bp_step_resume: |
| 6327 | case bp_hp_step_resume: |
| 6328 | case bp_watchpoint_scope: |
| 6329 | case bp_call_dummy: |
| 6330 | case bp_std_terminate: |
| 6331 | case bp_shlib_event: |
| 6332 | case bp_thread_event: |
| 6333 | case bp_overlay_event: |
| 6334 | case bp_longjmp_master: |
| 6335 | case bp_std_terminate_master: |
| 6336 | case bp_exception_master: |
| 6337 | case bp_tracepoint: |
| 6338 | case bp_fast_tracepoint: |
| 6339 | case bp_static_tracepoint: |
| 6340 | case bp_dprintf: |
| 6341 | case bp_jit_event: |
| 6342 | case bp_gnu_ifunc_resolver: |
| 6343 | case bp_gnu_ifunc_resolver_return: |
| 6344 | if (opts.addressprint) |
| 6345 | { |
| 6346 | annotate_field (4); |
| 6347 | if (header_of_multiple) |
| 6348 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
| 6349 | else if (b->loc == NULL || loc->shlib_disabled) |
| 6350 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
| 6351 | else |
| 6352 | ui_out_field_core_addr (uiout, "addr", |
| 6353 | loc->gdbarch, loc->address); |
| 6354 | } |
| 6355 | annotate_field (5); |
| 6356 | if (!header_of_multiple) |
| 6357 | print_breakpoint_location (b, loc); |
| 6358 | if (b->loc) |
| 6359 | *last_loc = b->loc; |
| 6360 | break; |
| 6361 | } |
| 6362 | |
| 6363 | |
| 6364 | if (loc != NULL && !header_of_multiple) |
| 6365 | { |
| 6366 | struct inferior *inf; |
| 6367 | VEC(int) *inf_num = NULL; |
| 6368 | int mi_only = 1; |
| 6369 | |
| 6370 | ALL_INFERIORS (inf) |
| 6371 | { |
| 6372 | if (inf->pspace == loc->pspace) |
| 6373 | VEC_safe_push (int, inf_num, inf->num); |
| 6374 | } |
| 6375 | |
| 6376 | /* For backward compatibility, don't display inferiors in CLI unless |
| 6377 | there are several. Always display for MI. */ |
| 6378 | if (allflag |
| 6379 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6380 | && (number_of_program_spaces () > 1 |
| 6381 | || number_of_inferiors () > 1) |
| 6382 | /* LOC is for existing B, it cannot be in |
| 6383 | moribund_locations and thus having NULL OWNER. */ |
| 6384 | && loc->owner->type != bp_catchpoint)) |
| 6385 | mi_only = 0; |
| 6386 | output_thread_groups (uiout, "thread-groups", inf_num, mi_only); |
| 6387 | VEC_free (int, inf_num); |
| 6388 | } |
| 6389 | |
| 6390 | if (!part_of_multiple) |
| 6391 | { |
| 6392 | if (b->thread != -1) |
| 6393 | { |
| 6394 | /* FIXME: This seems to be redundant and lost here; see the |
| 6395 | "stop only in" line a little further down. */ |
| 6396 | ui_out_text (uiout, " thread "); |
| 6397 | ui_out_field_int (uiout, "thread", b->thread); |
| 6398 | } |
| 6399 | else if (b->task != 0) |
| 6400 | { |
| 6401 | ui_out_text (uiout, " task "); |
| 6402 | ui_out_field_int (uiout, "task", b->task); |
| 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | ui_out_text (uiout, "\n"); |
| 6407 | |
| 6408 | if (!part_of_multiple) |
| 6409 | b->ops->print_one_detail (b, uiout); |
| 6410 | |
| 6411 | if (part_of_multiple && frame_id_p (b->frame_id)) |
| 6412 | { |
| 6413 | annotate_field (6); |
| 6414 | ui_out_text (uiout, "\tstop only in stack frame at "); |
| 6415 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
| 6416 | the frame ID. */ |
| 6417 | ui_out_field_core_addr (uiout, "frame", |
| 6418 | b->gdbarch, b->frame_id.stack_addr); |
| 6419 | ui_out_text (uiout, "\n"); |
| 6420 | } |
| 6421 | |
| 6422 | if (!part_of_multiple && b->cond_string) |
| 6423 | { |
| 6424 | annotate_field (7); |
| 6425 | if (is_tracepoint (b)) |
| 6426 | ui_out_text (uiout, "\ttrace only if "); |
| 6427 | else |
| 6428 | ui_out_text (uiout, "\tstop only if "); |
| 6429 | ui_out_field_string (uiout, "cond", b->cond_string); |
| 6430 | |
| 6431 | /* Print whether the target is doing the breakpoint's condition |
| 6432 | evaluation. If GDB is doing the evaluation, don't print anything. */ |
| 6433 | if (is_breakpoint (b) |
| 6434 | && breakpoint_condition_evaluation_mode () |
| 6435 | == condition_evaluation_target) |
| 6436 | { |
| 6437 | ui_out_text (uiout, " ("); |
| 6438 | ui_out_field_string (uiout, "evaluated-by", |
| 6439 | bp_condition_evaluator (b)); |
| 6440 | ui_out_text (uiout, " evals)"); |
| 6441 | } |
| 6442 | ui_out_text (uiout, "\n"); |
| 6443 | } |
| 6444 | |
| 6445 | if (!part_of_multiple && b->thread != -1) |
| 6446 | { |
| 6447 | /* FIXME should make an annotation for this. */ |
| 6448 | ui_out_text (uiout, "\tstop only in thread "); |
| 6449 | ui_out_field_int (uiout, "thread", b->thread); |
| 6450 | ui_out_text (uiout, "\n"); |
| 6451 | } |
| 6452 | |
| 6453 | if (!part_of_multiple) |
| 6454 | { |
| 6455 | if (b->hit_count) |
| 6456 | { |
| 6457 | /* FIXME should make an annotation for this. */ |
| 6458 | if (is_catchpoint (b)) |
| 6459 | ui_out_text (uiout, "\tcatchpoint"); |
| 6460 | else if (is_tracepoint (b)) |
| 6461 | ui_out_text (uiout, "\ttracepoint"); |
| 6462 | else |
| 6463 | ui_out_text (uiout, "\tbreakpoint"); |
| 6464 | ui_out_text (uiout, " already hit "); |
| 6465 | ui_out_field_int (uiout, "times", b->hit_count); |
| 6466 | if (b->hit_count == 1) |
| 6467 | ui_out_text (uiout, " time\n"); |
| 6468 | else |
| 6469 | ui_out_text (uiout, " times\n"); |
| 6470 | } |
| 6471 | else |
| 6472 | { |
| 6473 | /* Output the count also if it is zero, but only if this is mi. */ |
| 6474 | if (ui_out_is_mi_like_p (uiout)) |
| 6475 | ui_out_field_int (uiout, "times", b->hit_count); |
| 6476 | } |
| 6477 | } |
| 6478 | |
| 6479 | if (!part_of_multiple && b->ignore_count) |
| 6480 | { |
| 6481 | annotate_field (8); |
| 6482 | ui_out_text (uiout, "\tignore next "); |
| 6483 | ui_out_field_int (uiout, "ignore", b->ignore_count); |
| 6484 | ui_out_text (uiout, " hits\n"); |
| 6485 | } |
| 6486 | |
| 6487 | /* Note that an enable count of 1 corresponds to "enable once" |
| 6488 | behavior, which is reported by the combination of enablement and |
| 6489 | disposition, so we don't need to mention it here. */ |
| 6490 | if (!part_of_multiple && b->enable_count > 1) |
| 6491 | { |
| 6492 | annotate_field (8); |
| 6493 | ui_out_text (uiout, "\tdisable after "); |
| 6494 | /* Tweak the wording to clarify that ignore and enable counts |
| 6495 | are distinct, and have additive effect. */ |
| 6496 | if (b->ignore_count) |
| 6497 | ui_out_text (uiout, "additional "); |
| 6498 | else |
| 6499 | ui_out_text (uiout, "next "); |
| 6500 | ui_out_field_int (uiout, "enable", b->enable_count); |
| 6501 | ui_out_text (uiout, " hits\n"); |
| 6502 | } |
| 6503 | |
| 6504 | if (!part_of_multiple && is_tracepoint (b)) |
| 6505 | { |
| 6506 | struct tracepoint *tp = (struct tracepoint *) b; |
| 6507 | |
| 6508 | if (tp->traceframe_usage) |
| 6509 | { |
| 6510 | ui_out_text (uiout, "\ttrace buffer usage "); |
| 6511 | ui_out_field_int (uiout, "traceframe-usage", tp->traceframe_usage); |
| 6512 | ui_out_text (uiout, " bytes\n"); |
| 6513 | } |
| 6514 | } |
| 6515 | |
| 6516 | l = b->commands ? b->commands->commands : NULL; |
| 6517 | if (!part_of_multiple && l) |
| 6518 | { |
| 6519 | struct cleanup *script_chain; |
| 6520 | |
| 6521 | annotate_field (9); |
| 6522 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
| 6523 | print_command_lines (uiout, l, 4); |
| 6524 | do_cleanups (script_chain); |
| 6525 | } |
| 6526 | |
| 6527 | if (is_tracepoint (b)) |
| 6528 | { |
| 6529 | struct tracepoint *t = (struct tracepoint *) b; |
| 6530 | |
| 6531 | if (!part_of_multiple && t->pass_count) |
| 6532 | { |
| 6533 | annotate_field (10); |
| 6534 | ui_out_text (uiout, "\tpass count "); |
| 6535 | ui_out_field_int (uiout, "pass", t->pass_count); |
| 6536 | ui_out_text (uiout, " \n"); |
| 6537 | } |
| 6538 | |
| 6539 | /* Don't display it when tracepoint or tracepoint location is |
| 6540 | pending. */ |
| 6541 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) |
| 6542 | { |
| 6543 | annotate_field (11); |
| 6544 | |
| 6545 | if (ui_out_is_mi_like_p (uiout)) |
| 6546 | ui_out_field_string (uiout, "installed", |
| 6547 | loc->inserted ? "y" : "n"); |
| 6548 | else |
| 6549 | { |
| 6550 | if (loc->inserted) |
| 6551 | ui_out_text (uiout, "\t"); |
| 6552 | else |
| 6553 | ui_out_text (uiout, "\tnot "); |
| 6554 | ui_out_text (uiout, "installed on target\n"); |
| 6555 | } |
| 6556 | } |
| 6557 | } |
| 6558 | |
| 6559 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
| 6560 | { |
| 6561 | if (is_watchpoint (b)) |
| 6562 | { |
| 6563 | struct watchpoint *w = (struct watchpoint *) b; |
| 6564 | |
| 6565 | ui_out_field_string (uiout, "original-location", w->exp_string); |
| 6566 | } |
| 6567 | else if (b->location != NULL |
| 6568 | && event_location_to_string (b->location) != NULL) |
| 6569 | ui_out_field_string (uiout, "original-location", |
| 6570 | event_location_to_string (b->location)); |
| 6571 | } |
| 6572 | } |
| 6573 | |
| 6574 | static void |
| 6575 | print_one_breakpoint (struct breakpoint *b, |
| 6576 | struct bp_location **last_loc, |
| 6577 | int allflag) |
| 6578 | { |
| 6579 | struct cleanup *bkpt_chain; |
| 6580 | struct ui_out *uiout = current_uiout; |
| 6581 | |
| 6582 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
| 6583 | |
| 6584 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
| 6585 | do_cleanups (bkpt_chain); |
| 6586 | |
| 6587 | /* If this breakpoint has custom print function, |
| 6588 | it's already printed. Otherwise, print individual |
| 6589 | locations, if any. */ |
| 6590 | if (b->ops == NULL || b->ops->print_one == NULL) |
| 6591 | { |
| 6592 | /* If breakpoint has a single location that is disabled, we |
| 6593 | print it as if it had several locations, since otherwise it's |
| 6594 | hard to represent "breakpoint enabled, location disabled" |
| 6595 | situation. |
| 6596 | |
| 6597 | Note that while hardware watchpoints have several locations |
| 6598 | internally, that's not a property exposed to user. */ |
| 6599 | if (b->loc |
| 6600 | && !is_hardware_watchpoint (b) |
| 6601 | && (b->loc->next || !b->loc->enabled)) |
| 6602 | { |
| 6603 | struct bp_location *loc; |
| 6604 | int n = 1; |
| 6605 | |
| 6606 | for (loc = b->loc; loc; loc = loc->next, ++n) |
| 6607 | { |
| 6608 | struct cleanup *inner2 = |
| 6609 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); |
| 6610 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
| 6611 | do_cleanups (inner2); |
| 6612 | } |
| 6613 | } |
| 6614 | } |
| 6615 | } |
| 6616 | |
| 6617 | static int |
| 6618 | breakpoint_address_bits (struct breakpoint *b) |
| 6619 | { |
| 6620 | int print_address_bits = 0; |
| 6621 | struct bp_location *loc; |
| 6622 | |
| 6623 | for (loc = b->loc; loc; loc = loc->next) |
| 6624 | { |
| 6625 | int addr_bit; |
| 6626 | |
| 6627 | /* Software watchpoints that aren't watching memory don't have |
| 6628 | an address to print. */ |
| 6629 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) |
| 6630 | continue; |
| 6631 | |
| 6632 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
| 6633 | if (addr_bit > print_address_bits) |
| 6634 | print_address_bits = addr_bit; |
| 6635 | } |
| 6636 | |
| 6637 | return print_address_bits; |
| 6638 | } |
| 6639 | |
| 6640 | struct captured_breakpoint_query_args |
| 6641 | { |
| 6642 | int bnum; |
| 6643 | }; |
| 6644 | |
| 6645 | static int |
| 6646 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
| 6647 | { |
| 6648 | struct captured_breakpoint_query_args *args = data; |
| 6649 | struct breakpoint *b; |
| 6650 | struct bp_location *dummy_loc = NULL; |
| 6651 | |
| 6652 | ALL_BREAKPOINTS (b) |
| 6653 | { |
| 6654 | if (args->bnum == b->number) |
| 6655 | { |
| 6656 | print_one_breakpoint (b, &dummy_loc, 0); |
| 6657 | return GDB_RC_OK; |
| 6658 | } |
| 6659 | } |
| 6660 | return GDB_RC_NONE; |
| 6661 | } |
| 6662 | |
| 6663 | enum gdb_rc |
| 6664 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
| 6665 | char **error_message) |
| 6666 | { |
| 6667 | struct captured_breakpoint_query_args args; |
| 6668 | |
| 6669 | args.bnum = bnum; |
| 6670 | /* For the moment we don't trust print_one_breakpoint() to not throw |
| 6671 | an error. */ |
| 6672 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
| 6673 | error_message, RETURN_MASK_ALL) < 0) |
| 6674 | return GDB_RC_FAIL; |
| 6675 | else |
| 6676 | return GDB_RC_OK; |
| 6677 | } |
| 6678 | |
| 6679 | /* Return true if this breakpoint was set by the user, false if it is |
| 6680 | internal or momentary. */ |
| 6681 | |
| 6682 | int |
| 6683 | user_breakpoint_p (struct breakpoint *b) |
| 6684 | { |
| 6685 | return b->number > 0; |
| 6686 | } |
| 6687 | |
| 6688 | /* Print information on user settable breakpoint (watchpoint, etc) |
| 6689 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
| 6690 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If |
| 6691 | FILTER is non-NULL, call it on each breakpoint and only include the |
| 6692 | ones for which it returns non-zero. Return the total number of |
| 6693 | breakpoints listed. */ |
| 6694 | |
| 6695 | static int |
| 6696 | breakpoint_1 (char *args, int allflag, |
| 6697 | int (*filter) (const struct breakpoint *)) |
| 6698 | { |
| 6699 | struct breakpoint *b; |
| 6700 | struct bp_location *last_loc = NULL; |
| 6701 | int nr_printable_breakpoints; |
| 6702 | struct cleanup *bkpttbl_chain; |
| 6703 | struct value_print_options opts; |
| 6704 | int print_address_bits = 0; |
| 6705 | int print_type_col_width = 14; |
| 6706 | struct ui_out *uiout = current_uiout; |
| 6707 | |
| 6708 | get_user_print_options (&opts); |
| 6709 | |
| 6710 | /* Compute the number of rows in the table, as well as the size |
| 6711 | required for address fields. */ |
| 6712 | nr_printable_breakpoints = 0; |
| 6713 | ALL_BREAKPOINTS (b) |
| 6714 | { |
| 6715 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 6716 | if (filter && !filter (b)) |
| 6717 | continue; |
| 6718 | |
| 6719 | /* If we have an "args" string, it is a list of breakpoints to |
| 6720 | accept. Skip the others. */ |
| 6721 | if (args != NULL && *args != '\0') |
| 6722 | { |
| 6723 | if (allflag && parse_and_eval_long (args) != b->number) |
| 6724 | continue; |
| 6725 | if (!allflag && !number_is_in_list (args, b->number)) |
| 6726 | continue; |
| 6727 | } |
| 6728 | |
| 6729 | if (allflag || user_breakpoint_p (b)) |
| 6730 | { |
| 6731 | int addr_bit, type_len; |
| 6732 | |
| 6733 | addr_bit = breakpoint_address_bits (b); |
| 6734 | if (addr_bit > print_address_bits) |
| 6735 | print_address_bits = addr_bit; |
| 6736 | |
| 6737 | type_len = strlen (bptype_string (b->type)); |
| 6738 | if (type_len > print_type_col_width) |
| 6739 | print_type_col_width = type_len; |
| 6740 | |
| 6741 | nr_printable_breakpoints++; |
| 6742 | } |
| 6743 | } |
| 6744 | |
| 6745 | if (opts.addressprint) |
| 6746 | bkpttbl_chain |
| 6747 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
| 6748 | nr_printable_breakpoints, |
| 6749 | "BreakpointTable"); |
| 6750 | else |
| 6751 | bkpttbl_chain |
| 6752 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
| 6753 | nr_printable_breakpoints, |
| 6754 | "BreakpointTable"); |
| 6755 | |
| 6756 | if (nr_printable_breakpoints > 0) |
| 6757 | annotate_breakpoints_headers (); |
| 6758 | if (nr_printable_breakpoints > 0) |
| 6759 | annotate_field (0); |
| 6760 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
| 6761 | if (nr_printable_breakpoints > 0) |
| 6762 | annotate_field (1); |
| 6763 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
| 6764 | "type", "Type"); /* 2 */ |
| 6765 | if (nr_printable_breakpoints > 0) |
| 6766 | annotate_field (2); |
| 6767 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
| 6768 | if (nr_printable_breakpoints > 0) |
| 6769 | annotate_field (3); |
| 6770 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
| 6771 | if (opts.addressprint) |
| 6772 | { |
| 6773 | if (nr_printable_breakpoints > 0) |
| 6774 | annotate_field (4); |
| 6775 | if (print_address_bits <= 32) |
| 6776 | ui_out_table_header (uiout, 10, ui_left, |
| 6777 | "addr", "Address"); /* 5 */ |
| 6778 | else |
| 6779 | ui_out_table_header (uiout, 18, ui_left, |
| 6780 | "addr", "Address"); /* 5 */ |
| 6781 | } |
| 6782 | if (nr_printable_breakpoints > 0) |
| 6783 | annotate_field (5); |
| 6784 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ |
| 6785 | ui_out_table_body (uiout); |
| 6786 | if (nr_printable_breakpoints > 0) |
| 6787 | annotate_breakpoints_table (); |
| 6788 | |
| 6789 | ALL_BREAKPOINTS (b) |
| 6790 | { |
| 6791 | QUIT; |
| 6792 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 6793 | if (filter && !filter (b)) |
| 6794 | continue; |
| 6795 | |
| 6796 | /* If we have an "args" string, it is a list of breakpoints to |
| 6797 | accept. Skip the others. */ |
| 6798 | |
| 6799 | if (args != NULL && *args != '\0') |
| 6800 | { |
| 6801 | if (allflag) /* maintenance info breakpoint */ |
| 6802 | { |
| 6803 | if (parse_and_eval_long (args) != b->number) |
| 6804 | continue; |
| 6805 | } |
| 6806 | else /* all others */ |
| 6807 | { |
| 6808 | if (!number_is_in_list (args, b->number)) |
| 6809 | continue; |
| 6810 | } |
| 6811 | } |
| 6812 | /* We only print out user settable breakpoints unless the |
| 6813 | allflag is set. */ |
| 6814 | if (allflag || user_breakpoint_p (b)) |
| 6815 | print_one_breakpoint (b, &last_loc, allflag); |
| 6816 | } |
| 6817 | |
| 6818 | do_cleanups (bkpttbl_chain); |
| 6819 | |
| 6820 | if (nr_printable_breakpoints == 0) |
| 6821 | { |
| 6822 | /* If there's a filter, let the caller decide how to report |
| 6823 | empty list. */ |
| 6824 | if (!filter) |
| 6825 | { |
| 6826 | if (args == NULL || *args == '\0') |
| 6827 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
| 6828 | else |
| 6829 | ui_out_message (uiout, 0, |
| 6830 | "No breakpoint or watchpoint matching '%s'.\n", |
| 6831 | args); |
| 6832 | } |
| 6833 | } |
| 6834 | else |
| 6835 | { |
| 6836 | if (last_loc && !server_command) |
| 6837 | set_next_address (last_loc->gdbarch, last_loc->address); |
| 6838 | } |
| 6839 | |
| 6840 | /* FIXME? Should this be moved up so that it is only called when |
| 6841 | there have been breakpoints? */ |
| 6842 | annotate_breakpoints_table_end (); |
| 6843 | |
| 6844 | return nr_printable_breakpoints; |
| 6845 | } |
| 6846 | |
| 6847 | /* Display the value of default-collect in a way that is generally |
| 6848 | compatible with the breakpoint list. */ |
| 6849 | |
| 6850 | static void |
| 6851 | default_collect_info (void) |
| 6852 | { |
| 6853 | struct ui_out *uiout = current_uiout; |
| 6854 | |
| 6855 | /* If it has no value (which is frequently the case), say nothing; a |
| 6856 | message like "No default-collect." gets in user's face when it's |
| 6857 | not wanted. */ |
| 6858 | if (!*default_collect) |
| 6859 | return; |
| 6860 | |
| 6861 | /* The following phrase lines up nicely with per-tracepoint collect |
| 6862 | actions. */ |
| 6863 | ui_out_text (uiout, "default collect "); |
| 6864 | ui_out_field_string (uiout, "default-collect", default_collect); |
| 6865 | ui_out_text (uiout, " \n"); |
| 6866 | } |
| 6867 | |
| 6868 | static void |
| 6869 | breakpoints_info (char *args, int from_tty) |
| 6870 | { |
| 6871 | breakpoint_1 (args, 0, NULL); |
| 6872 | |
| 6873 | default_collect_info (); |
| 6874 | } |
| 6875 | |
| 6876 | static void |
| 6877 | watchpoints_info (char *args, int from_tty) |
| 6878 | { |
| 6879 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
| 6880 | struct ui_out *uiout = current_uiout; |
| 6881 | |
| 6882 | if (num_printed == 0) |
| 6883 | { |
| 6884 | if (args == NULL || *args == '\0') |
| 6885 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
| 6886 | else |
| 6887 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
| 6888 | } |
| 6889 | } |
| 6890 | |
| 6891 | static void |
| 6892 | maintenance_info_breakpoints (char *args, int from_tty) |
| 6893 | { |
| 6894 | breakpoint_1 (args, 1, NULL); |
| 6895 | |
| 6896 | default_collect_info (); |
| 6897 | } |
| 6898 | |
| 6899 | static int |
| 6900 | breakpoint_has_pc (struct breakpoint *b, |
| 6901 | struct program_space *pspace, |
| 6902 | CORE_ADDR pc, struct obj_section *section) |
| 6903 | { |
| 6904 | struct bp_location *bl = b->loc; |
| 6905 | |
| 6906 | for (; bl; bl = bl->next) |
| 6907 | { |
| 6908 | if (bl->pspace == pspace |
| 6909 | && bl->address == pc |
| 6910 | && (!overlay_debugging || bl->section == section)) |
| 6911 | return 1; |
| 6912 | } |
| 6913 | return 0; |
| 6914 | } |
| 6915 | |
| 6916 | /* Print a message describing any user-breakpoints set at PC. This |
| 6917 | concerns with logical breakpoints, so we match program spaces, not |
| 6918 | address spaces. */ |
| 6919 | |
| 6920 | static void |
| 6921 | describe_other_breakpoints (struct gdbarch *gdbarch, |
| 6922 | struct program_space *pspace, CORE_ADDR pc, |
| 6923 | struct obj_section *section, int thread) |
| 6924 | { |
| 6925 | int others = 0; |
| 6926 | struct breakpoint *b; |
| 6927 | |
| 6928 | ALL_BREAKPOINTS (b) |
| 6929 | others += (user_breakpoint_p (b) |
| 6930 | && breakpoint_has_pc (b, pspace, pc, section)); |
| 6931 | if (others > 0) |
| 6932 | { |
| 6933 | if (others == 1) |
| 6934 | printf_filtered (_("Note: breakpoint ")); |
| 6935 | else /* if (others == ???) */ |
| 6936 | printf_filtered (_("Note: breakpoints ")); |
| 6937 | ALL_BREAKPOINTS (b) |
| 6938 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
| 6939 | { |
| 6940 | others--; |
| 6941 | printf_filtered ("%d", b->number); |
| 6942 | if (b->thread == -1 && thread != -1) |
| 6943 | printf_filtered (" (all threads)"); |
| 6944 | else if (b->thread != -1) |
| 6945 | printf_filtered (" (thread %d)", b->thread); |
| 6946 | printf_filtered ("%s%s ", |
| 6947 | ((b->enable_state == bp_disabled |
| 6948 | || b->enable_state == bp_call_disabled) |
| 6949 | ? " (disabled)" |
| 6950 | : ""), |
| 6951 | (others > 1) ? "," |
| 6952 | : ((others == 1) ? " and" : "")); |
| 6953 | } |
| 6954 | printf_filtered (_("also set at pc ")); |
| 6955 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
| 6956 | printf_filtered (".\n"); |
| 6957 | } |
| 6958 | } |
| 6959 | \f |
| 6960 | |
| 6961 | /* Return true iff it is meaningful to use the address member of |
| 6962 | BPT. For some breakpoint types, the address member is irrelevant |
| 6963 | and it makes no sense to attempt to compare it to other addresses |
| 6964 | (or use it for any other purpose either). |
| 6965 | |
| 6966 | More specifically, each of the following breakpoint types will |
| 6967 | always have a zero valued address and we don't want to mark |
| 6968 | breakpoints of any of these types to be a duplicate of an actual |
| 6969 | breakpoint at address zero: |
| 6970 | |
| 6971 | bp_watchpoint |
| 6972 | bp_catchpoint |
| 6973 | |
| 6974 | */ |
| 6975 | |
| 6976 | static int |
| 6977 | breakpoint_address_is_meaningful (struct breakpoint *bpt) |
| 6978 | { |
| 6979 | enum bptype type = bpt->type; |
| 6980 | |
| 6981 | return (type != bp_watchpoint && type != bp_catchpoint); |
| 6982 | } |
| 6983 | |
| 6984 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns |
| 6985 | true if LOC1 and LOC2 represent the same watchpoint location. */ |
| 6986 | |
| 6987 | static int |
| 6988 | watchpoint_locations_match (struct bp_location *loc1, |
| 6989 | struct bp_location *loc2) |
| 6990 | { |
| 6991 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
| 6992 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; |
| 6993 | |
| 6994 | /* Both of them must exist. */ |
| 6995 | gdb_assert (w1 != NULL); |
| 6996 | gdb_assert (w2 != NULL); |
| 6997 | |
| 6998 | /* If the target can evaluate the condition expression in hardware, |
| 6999 | then we we need to insert both watchpoints even if they are at |
| 7000 | the same place. Otherwise the watchpoint will only trigger when |
| 7001 | the condition of whichever watchpoint was inserted evaluates to |
| 7002 | true, not giving a chance for GDB to check the condition of the |
| 7003 | other watchpoint. */ |
| 7004 | if ((w1->cond_exp |
| 7005 | && target_can_accel_watchpoint_condition (loc1->address, |
| 7006 | loc1->length, |
| 7007 | loc1->watchpoint_type, |
| 7008 | w1->cond_exp)) |
| 7009 | || (w2->cond_exp |
| 7010 | && target_can_accel_watchpoint_condition (loc2->address, |
| 7011 | loc2->length, |
| 7012 | loc2->watchpoint_type, |
| 7013 | w2->cond_exp))) |
| 7014 | return 0; |
| 7015 | |
| 7016 | /* Note that this checks the owner's type, not the location's. In |
| 7017 | case the target does not support read watchpoints, but does |
| 7018 | support access watchpoints, we'll have bp_read_watchpoint |
| 7019 | watchpoints with hw_access locations. Those should be considered |
| 7020 | duplicates of hw_read locations. The hw_read locations will |
| 7021 | become hw_access locations later. */ |
| 7022 | return (loc1->owner->type == loc2->owner->type |
| 7023 | && loc1->pspace->aspace == loc2->pspace->aspace |
| 7024 | && loc1->address == loc2->address |
| 7025 | && loc1->length == loc2->length); |
| 7026 | } |
| 7027 | |
| 7028 | /* See breakpoint.h. */ |
| 7029 | |
| 7030 | int |
| 7031 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, |
| 7032 | struct address_space *aspace2, CORE_ADDR addr2) |
| 7033 | { |
| 7034 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 7035 | || aspace1 == aspace2) |
| 7036 | && addr1 == addr2); |
| 7037 | } |
| 7038 | |
| 7039 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
| 7040 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 |
| 7041 | matches ASPACE2. On targets that have global breakpoints, the address |
| 7042 | space doesn't really matter. */ |
| 7043 | |
| 7044 | static int |
| 7045 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, |
| 7046 | int len1, struct address_space *aspace2, |
| 7047 | CORE_ADDR addr2) |
| 7048 | { |
| 7049 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 7050 | || aspace1 == aspace2) |
| 7051 | && addr2 >= addr1 && addr2 < addr1 + len1); |
| 7052 | } |
| 7053 | |
| 7054 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be |
| 7055 | a ranged breakpoint. In most targets, a match happens only if ASPACE |
| 7056 | matches the breakpoint's address space. On targets that have global |
| 7057 | breakpoints, the address space doesn't really matter. */ |
| 7058 | |
| 7059 | static int |
| 7060 | breakpoint_location_address_match (struct bp_location *bl, |
| 7061 | struct address_space *aspace, |
| 7062 | CORE_ADDR addr) |
| 7063 | { |
| 7064 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 7065 | aspace, addr) |
| 7066 | || (bl->length |
| 7067 | && breakpoint_address_match_range (bl->pspace->aspace, |
| 7068 | bl->address, bl->length, |
| 7069 | aspace, addr))); |
| 7070 | } |
| 7071 | |
| 7072 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
| 7073 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns |
| 7074 | true, otherwise returns false. */ |
| 7075 | |
| 7076 | static int |
| 7077 | tracepoint_locations_match (struct bp_location *loc1, |
| 7078 | struct bp_location *loc2) |
| 7079 | { |
| 7080 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) |
| 7081 | /* Since tracepoint locations are never duplicated with others', tracepoint |
| 7082 | locations at the same address of different tracepoints are regarded as |
| 7083 | different locations. */ |
| 7084 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); |
| 7085 | else |
| 7086 | return 0; |
| 7087 | } |
| 7088 | |
| 7089 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
| 7090 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 |
| 7091 | represent the same location. */ |
| 7092 | |
| 7093 | static int |
| 7094 | breakpoint_locations_match (struct bp_location *loc1, |
| 7095 | struct bp_location *loc2) |
| 7096 | { |
| 7097 | int hw_point1, hw_point2; |
| 7098 | |
| 7099 | /* Both of them must not be in moribund_locations. */ |
| 7100 | gdb_assert (loc1->owner != NULL); |
| 7101 | gdb_assert (loc2->owner != NULL); |
| 7102 | |
| 7103 | hw_point1 = is_hardware_watchpoint (loc1->owner); |
| 7104 | hw_point2 = is_hardware_watchpoint (loc2->owner); |
| 7105 | |
| 7106 | if (hw_point1 != hw_point2) |
| 7107 | return 0; |
| 7108 | else if (hw_point1) |
| 7109 | return watchpoint_locations_match (loc1, loc2); |
| 7110 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
| 7111 | return tracepoint_locations_match (loc1, loc2); |
| 7112 | else |
| 7113 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
| 7114 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
| 7115 | loc2->pspace->aspace, loc2->address) |
| 7116 | && loc1->length == loc2->length); |
| 7117 | } |
| 7118 | |
| 7119 | static void |
| 7120 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, |
| 7121 | int bnum, int have_bnum) |
| 7122 | { |
| 7123 | /* The longest string possibly returned by hex_string_custom |
| 7124 | is 50 chars. These must be at least that big for safety. */ |
| 7125 | char astr1[64]; |
| 7126 | char astr2[64]; |
| 7127 | |
| 7128 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
| 7129 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); |
| 7130 | if (have_bnum) |
| 7131 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
| 7132 | bnum, astr1, astr2); |
| 7133 | else |
| 7134 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
| 7135 | } |
| 7136 | |
| 7137 | /* Adjust a breakpoint's address to account for architectural |
| 7138 | constraints on breakpoint placement. Return the adjusted address. |
| 7139 | Note: Very few targets require this kind of adjustment. For most |
| 7140 | targets, this function is simply the identity function. */ |
| 7141 | |
| 7142 | static CORE_ADDR |
| 7143 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 7144 | CORE_ADDR bpaddr, enum bptype bptype) |
| 7145 | { |
| 7146 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
| 7147 | { |
| 7148 | /* Very few targets need any kind of breakpoint adjustment. */ |
| 7149 | return bpaddr; |
| 7150 | } |
| 7151 | else if (bptype == bp_watchpoint |
| 7152 | || bptype == bp_hardware_watchpoint |
| 7153 | || bptype == bp_read_watchpoint |
| 7154 | || bptype == bp_access_watchpoint |
| 7155 | || bptype == bp_catchpoint) |
| 7156 | { |
| 7157 | /* Watchpoints and the various bp_catch_* eventpoints should not |
| 7158 | have their addresses modified. */ |
| 7159 | return bpaddr; |
| 7160 | } |
| 7161 | else if (bptype == bp_single_step) |
| 7162 | { |
| 7163 | /* Single-step breakpoints should not have their addresses |
| 7164 | modified. If there's any architectural constrain that |
| 7165 | applies to this address, then it should have already been |
| 7166 | taken into account when the breakpoint was created in the |
| 7167 | first place. If we didn't do this, stepping through e.g., |
| 7168 | Thumb-2 IT blocks would break. */ |
| 7169 | return bpaddr; |
| 7170 | } |
| 7171 | else |
| 7172 | { |
| 7173 | CORE_ADDR adjusted_bpaddr; |
| 7174 | |
| 7175 | /* Some targets have architectural constraints on the placement |
| 7176 | of breakpoint instructions. Obtain the adjusted address. */ |
| 7177 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
| 7178 | |
| 7179 | /* An adjusted breakpoint address can significantly alter |
| 7180 | a user's expectations. Print a warning if an adjustment |
| 7181 | is required. */ |
| 7182 | if (adjusted_bpaddr != bpaddr) |
| 7183 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); |
| 7184 | |
| 7185 | return adjusted_bpaddr; |
| 7186 | } |
| 7187 | } |
| 7188 | |
| 7189 | void |
| 7190 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, |
| 7191 | struct breakpoint *owner) |
| 7192 | { |
| 7193 | memset (loc, 0, sizeof (*loc)); |
| 7194 | |
| 7195 | gdb_assert (ops != NULL); |
| 7196 | |
| 7197 | loc->ops = ops; |
| 7198 | loc->owner = owner; |
| 7199 | loc->cond = NULL; |
| 7200 | loc->cond_bytecode = NULL; |
| 7201 | loc->shlib_disabled = 0; |
| 7202 | loc->enabled = 1; |
| 7203 | |
| 7204 | switch (owner->type) |
| 7205 | { |
| 7206 | case bp_breakpoint: |
| 7207 | case bp_single_step: |
| 7208 | case bp_until: |
| 7209 | case bp_finish: |
| 7210 | case bp_longjmp: |
| 7211 | case bp_longjmp_resume: |
| 7212 | case bp_longjmp_call_dummy: |
| 7213 | case bp_exception: |
| 7214 | case bp_exception_resume: |
| 7215 | case bp_step_resume: |
| 7216 | case bp_hp_step_resume: |
| 7217 | case bp_watchpoint_scope: |
| 7218 | case bp_call_dummy: |
| 7219 | case bp_std_terminate: |
| 7220 | case bp_shlib_event: |
| 7221 | case bp_thread_event: |
| 7222 | case bp_overlay_event: |
| 7223 | case bp_jit_event: |
| 7224 | case bp_longjmp_master: |
| 7225 | case bp_std_terminate_master: |
| 7226 | case bp_exception_master: |
| 7227 | case bp_gnu_ifunc_resolver: |
| 7228 | case bp_gnu_ifunc_resolver_return: |
| 7229 | case bp_dprintf: |
| 7230 | loc->loc_type = bp_loc_software_breakpoint; |
| 7231 | mark_breakpoint_location_modified (loc); |
| 7232 | break; |
| 7233 | case bp_hardware_breakpoint: |
| 7234 | loc->loc_type = bp_loc_hardware_breakpoint; |
| 7235 | mark_breakpoint_location_modified (loc); |
| 7236 | break; |
| 7237 | case bp_hardware_watchpoint: |
| 7238 | case bp_read_watchpoint: |
| 7239 | case bp_access_watchpoint: |
| 7240 | loc->loc_type = bp_loc_hardware_watchpoint; |
| 7241 | break; |
| 7242 | case bp_watchpoint: |
| 7243 | case bp_catchpoint: |
| 7244 | case bp_tracepoint: |
| 7245 | case bp_fast_tracepoint: |
| 7246 | case bp_static_tracepoint: |
| 7247 | loc->loc_type = bp_loc_other; |
| 7248 | break; |
| 7249 | default: |
| 7250 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
| 7251 | } |
| 7252 | |
| 7253 | loc->refc = 1; |
| 7254 | } |
| 7255 | |
| 7256 | /* Allocate a struct bp_location. */ |
| 7257 | |
| 7258 | static struct bp_location * |
| 7259 | allocate_bp_location (struct breakpoint *bpt) |
| 7260 | { |
| 7261 | return bpt->ops->allocate_location (bpt); |
| 7262 | } |
| 7263 | |
| 7264 | static void |
| 7265 | free_bp_location (struct bp_location *loc) |
| 7266 | { |
| 7267 | loc->ops->dtor (loc); |
| 7268 | xfree (loc); |
| 7269 | } |
| 7270 | |
| 7271 | /* Increment reference count. */ |
| 7272 | |
| 7273 | static void |
| 7274 | incref_bp_location (struct bp_location *bl) |
| 7275 | { |
| 7276 | ++bl->refc; |
| 7277 | } |
| 7278 | |
| 7279 | /* Decrement reference count. If the reference count reaches 0, |
| 7280 | destroy the bp_location. Sets *BLP to NULL. */ |
| 7281 | |
| 7282 | static void |
| 7283 | decref_bp_location (struct bp_location **blp) |
| 7284 | { |
| 7285 | gdb_assert ((*blp)->refc > 0); |
| 7286 | |
| 7287 | if (--(*blp)->refc == 0) |
| 7288 | free_bp_location (*blp); |
| 7289 | *blp = NULL; |
| 7290 | } |
| 7291 | |
| 7292 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
| 7293 | |
| 7294 | static void |
| 7295 | add_to_breakpoint_chain (struct breakpoint *b) |
| 7296 | { |
| 7297 | struct breakpoint *b1; |
| 7298 | |
| 7299 | /* Add this breakpoint to the end of the chain so that a list of |
| 7300 | breakpoints will come out in order of increasing numbers. */ |
| 7301 | |
| 7302 | b1 = breakpoint_chain; |
| 7303 | if (b1 == 0) |
| 7304 | breakpoint_chain = b; |
| 7305 | else |
| 7306 | { |
| 7307 | while (b1->next) |
| 7308 | b1 = b1->next; |
| 7309 | b1->next = b; |
| 7310 | } |
| 7311 | } |
| 7312 | |
| 7313 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ |
| 7314 | |
| 7315 | static void |
| 7316 | init_raw_breakpoint_without_location (struct breakpoint *b, |
| 7317 | struct gdbarch *gdbarch, |
| 7318 | enum bptype bptype, |
| 7319 | const struct breakpoint_ops *ops) |
| 7320 | { |
| 7321 | memset (b, 0, sizeof (*b)); |
| 7322 | |
| 7323 | gdb_assert (ops != NULL); |
| 7324 | |
| 7325 | b->ops = ops; |
| 7326 | b->type = bptype; |
| 7327 | b->gdbarch = gdbarch; |
| 7328 | b->language = current_language->la_language; |
| 7329 | b->input_radix = input_radix; |
| 7330 | b->thread = -1; |
| 7331 | b->enable_state = bp_enabled; |
| 7332 | b->next = 0; |
| 7333 | b->silent = 0; |
| 7334 | b->ignore_count = 0; |
| 7335 | b->commands = NULL; |
| 7336 | b->frame_id = null_frame_id; |
| 7337 | b->condition_not_parsed = 0; |
| 7338 | b->py_bp_object = NULL; |
| 7339 | b->related_breakpoint = b; |
| 7340 | b->location = NULL; |
| 7341 | } |
| 7342 | |
| 7343 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
| 7344 | that has type BPTYPE and has no locations as yet. */ |
| 7345 | |
| 7346 | static struct breakpoint * |
| 7347 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
| 7348 | enum bptype bptype, |
| 7349 | const struct breakpoint_ops *ops) |
| 7350 | { |
| 7351 | struct breakpoint *b = XNEW (struct breakpoint); |
| 7352 | |
| 7353 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
| 7354 | add_to_breakpoint_chain (b); |
| 7355 | return b; |
| 7356 | } |
| 7357 | |
| 7358 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
| 7359 | resolutions should be made as the user specified the location explicitly |
| 7360 | enough. */ |
| 7361 | |
| 7362 | static void |
| 7363 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
| 7364 | { |
| 7365 | gdb_assert (loc->owner != NULL); |
| 7366 | |
| 7367 | if (loc->owner->type == bp_breakpoint |
| 7368 | || loc->owner->type == bp_hardware_breakpoint |
| 7369 | || is_tracepoint (loc->owner)) |
| 7370 | { |
| 7371 | int is_gnu_ifunc; |
| 7372 | const char *function_name; |
| 7373 | CORE_ADDR func_addr; |
| 7374 | |
| 7375 | find_pc_partial_function_gnu_ifunc (loc->address, &function_name, |
| 7376 | &func_addr, NULL, &is_gnu_ifunc); |
| 7377 | |
| 7378 | if (is_gnu_ifunc && !explicit_loc) |
| 7379 | { |
| 7380 | struct breakpoint *b = loc->owner; |
| 7381 | |
| 7382 | gdb_assert (loc->pspace == current_program_space); |
| 7383 | if (gnu_ifunc_resolve_name (function_name, |
| 7384 | &loc->requested_address)) |
| 7385 | { |
| 7386 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ |
| 7387 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
| 7388 | loc->requested_address, |
| 7389 | b->type); |
| 7390 | } |
| 7391 | else if (b->type == bp_breakpoint && b->loc == loc |
| 7392 | && loc->next == NULL && b->related_breakpoint == b) |
| 7393 | { |
| 7394 | /* Create only the whole new breakpoint of this type but do not |
| 7395 | mess more complicated breakpoints with multiple locations. */ |
| 7396 | b->type = bp_gnu_ifunc_resolver; |
| 7397 | /* Remember the resolver's address for use by the return |
| 7398 | breakpoint. */ |
| 7399 | loc->related_address = func_addr; |
| 7400 | } |
| 7401 | } |
| 7402 | |
| 7403 | if (function_name) |
| 7404 | loc->function_name = xstrdup (function_name); |
| 7405 | } |
| 7406 | } |
| 7407 | |
| 7408 | /* Attempt to determine architecture of location identified by SAL. */ |
| 7409 | struct gdbarch * |
| 7410 | get_sal_arch (struct symtab_and_line sal) |
| 7411 | { |
| 7412 | if (sal.section) |
| 7413 | return get_objfile_arch (sal.section->objfile); |
| 7414 | if (sal.symtab) |
| 7415 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
| 7416 | |
| 7417 | return NULL; |
| 7418 | } |
| 7419 | |
| 7420 | /* Low level routine for partially initializing a breakpoint of type |
| 7421 | BPTYPE. The newly created breakpoint's address, section, source |
| 7422 | file name, and line number are provided by SAL. |
| 7423 | |
| 7424 | It is expected that the caller will complete the initialization of |
| 7425 | the newly created breakpoint struct as well as output any status |
| 7426 | information regarding the creation of a new breakpoint. */ |
| 7427 | |
| 7428 | static void |
| 7429 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, |
| 7430 | struct symtab_and_line sal, enum bptype bptype, |
| 7431 | const struct breakpoint_ops *ops) |
| 7432 | { |
| 7433 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
| 7434 | |
| 7435 | add_location_to_breakpoint (b, &sal); |
| 7436 | |
| 7437 | if (bptype != bp_catchpoint) |
| 7438 | gdb_assert (sal.pspace != NULL); |
| 7439 | |
| 7440 | /* Store the program space that was used to set the breakpoint, |
| 7441 | except for ordinary breakpoints, which are independent of the |
| 7442 | program space. */ |
| 7443 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) |
| 7444 | b->pspace = sal.pspace; |
| 7445 | } |
| 7446 | |
| 7447 | /* set_raw_breakpoint is a low level routine for allocating and |
| 7448 | partially initializing a breakpoint of type BPTYPE. The newly |
| 7449 | created breakpoint's address, section, source file name, and line |
| 7450 | number are provided by SAL. The newly created and partially |
| 7451 | initialized breakpoint is added to the breakpoint chain and |
| 7452 | is also returned as the value of this function. |
| 7453 | |
| 7454 | It is expected that the caller will complete the initialization of |
| 7455 | the newly created breakpoint struct as well as output any status |
| 7456 | information regarding the creation of a new breakpoint. In |
| 7457 | particular, set_raw_breakpoint does NOT set the breakpoint |
| 7458 | number! Care should be taken to not allow an error to occur |
| 7459 | prior to completing the initialization of the breakpoint. If this |
| 7460 | should happen, a bogus breakpoint will be left on the chain. */ |
| 7461 | |
| 7462 | struct breakpoint * |
| 7463 | set_raw_breakpoint (struct gdbarch *gdbarch, |
| 7464 | struct symtab_and_line sal, enum bptype bptype, |
| 7465 | const struct breakpoint_ops *ops) |
| 7466 | { |
| 7467 | struct breakpoint *b = XNEW (struct breakpoint); |
| 7468 | |
| 7469 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
| 7470 | add_to_breakpoint_chain (b); |
| 7471 | return b; |
| 7472 | } |
| 7473 | |
| 7474 | /* Call this routine when stepping and nexting to enable a breakpoint |
| 7475 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
| 7476 | initiated the operation. */ |
| 7477 | |
| 7478 | void |
| 7479 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
| 7480 | { |
| 7481 | struct breakpoint *b, *b_tmp; |
| 7482 | int thread = tp->num; |
| 7483 | |
| 7484 | /* To avoid having to rescan all objfile symbols at every step, |
| 7485 | we maintain a list of continually-inserted but always disabled |
| 7486 | longjmp "master" breakpoints. Here, we simply create momentary |
| 7487 | clones of those and enable them for the requested thread. */ |
| 7488 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7489 | if (b->pspace == current_program_space |
| 7490 | && (b->type == bp_longjmp_master |
| 7491 | || b->type == bp_exception_master)) |
| 7492 | { |
| 7493 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
| 7494 | struct breakpoint *clone; |
| 7495 | |
| 7496 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
| 7497 | after their removal. */ |
| 7498 | clone = momentary_breakpoint_from_master (b, type, |
| 7499 | &longjmp_breakpoint_ops, 1); |
| 7500 | clone->thread = thread; |
| 7501 | } |
| 7502 | |
| 7503 | tp->initiating_frame = frame; |
| 7504 | } |
| 7505 | |
| 7506 | /* Delete all longjmp breakpoints from THREAD. */ |
| 7507 | void |
| 7508 | delete_longjmp_breakpoint (int thread) |
| 7509 | { |
| 7510 | struct breakpoint *b, *b_tmp; |
| 7511 | |
| 7512 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7513 | if (b->type == bp_longjmp || b->type == bp_exception) |
| 7514 | { |
| 7515 | if (b->thread == thread) |
| 7516 | delete_breakpoint (b); |
| 7517 | } |
| 7518 | } |
| 7519 | |
| 7520 | void |
| 7521 | delete_longjmp_breakpoint_at_next_stop (int thread) |
| 7522 | { |
| 7523 | struct breakpoint *b, *b_tmp; |
| 7524 | |
| 7525 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7526 | if (b->type == bp_longjmp || b->type == bp_exception) |
| 7527 | { |
| 7528 | if (b->thread == thread) |
| 7529 | b->disposition = disp_del_at_next_stop; |
| 7530 | } |
| 7531 | } |
| 7532 | |
| 7533 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
| 7534 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return |
| 7535 | pointer to any of them. Return NULL if this system cannot place longjmp |
| 7536 | breakpoints. */ |
| 7537 | |
| 7538 | struct breakpoint * |
| 7539 | set_longjmp_breakpoint_for_call_dummy (void) |
| 7540 | { |
| 7541 | struct breakpoint *b, *retval = NULL; |
| 7542 | |
| 7543 | ALL_BREAKPOINTS (b) |
| 7544 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) |
| 7545 | { |
| 7546 | struct breakpoint *new_b; |
| 7547 | |
| 7548 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, |
| 7549 | &momentary_breakpoint_ops, |
| 7550 | 1); |
| 7551 | new_b->thread = pid_to_thread_id (inferior_ptid); |
| 7552 | |
| 7553 | /* Link NEW_B into the chain of RETVAL breakpoints. */ |
| 7554 | |
| 7555 | gdb_assert (new_b->related_breakpoint == new_b); |
| 7556 | if (retval == NULL) |
| 7557 | retval = new_b; |
| 7558 | new_b->related_breakpoint = retval; |
| 7559 | while (retval->related_breakpoint != new_b->related_breakpoint) |
| 7560 | retval = retval->related_breakpoint; |
| 7561 | retval->related_breakpoint = new_b; |
| 7562 | } |
| 7563 | |
| 7564 | return retval; |
| 7565 | } |
| 7566 | |
| 7567 | /* Verify all existing dummy frames and their associated breakpoints for |
| 7568 | TP. Remove those which can no longer be found in the current frame |
| 7569 | stack. |
| 7570 | |
| 7571 | You should call this function only at places where it is safe to currently |
| 7572 | unwind the whole stack. Failed stack unwind would discard live dummy |
| 7573 | frames. */ |
| 7574 | |
| 7575 | void |
| 7576 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
| 7577 | { |
| 7578 | struct breakpoint *b, *b_tmp; |
| 7579 | |
| 7580 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7581 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->num) |
| 7582 | { |
| 7583 | struct breakpoint *dummy_b = b->related_breakpoint; |
| 7584 | |
| 7585 | while (dummy_b != b && dummy_b->type != bp_call_dummy) |
| 7586 | dummy_b = dummy_b->related_breakpoint; |
| 7587 | if (dummy_b->type != bp_call_dummy |
| 7588 | || frame_find_by_id (dummy_b->frame_id) != NULL) |
| 7589 | continue; |
| 7590 | |
| 7591 | dummy_frame_discard (dummy_b->frame_id, tp->ptid); |
| 7592 | |
| 7593 | while (b->related_breakpoint != b) |
| 7594 | { |
| 7595 | if (b_tmp == b->related_breakpoint) |
| 7596 | b_tmp = b->related_breakpoint->next; |
| 7597 | delete_breakpoint (b->related_breakpoint); |
| 7598 | } |
| 7599 | delete_breakpoint (b); |
| 7600 | } |
| 7601 | } |
| 7602 | |
| 7603 | void |
| 7604 | enable_overlay_breakpoints (void) |
| 7605 | { |
| 7606 | struct breakpoint *b; |
| 7607 | |
| 7608 | ALL_BREAKPOINTS (b) |
| 7609 | if (b->type == bp_overlay_event) |
| 7610 | { |
| 7611 | b->enable_state = bp_enabled; |
| 7612 | update_global_location_list (UGLL_MAY_INSERT); |
| 7613 | overlay_events_enabled = 1; |
| 7614 | } |
| 7615 | } |
| 7616 | |
| 7617 | void |
| 7618 | disable_overlay_breakpoints (void) |
| 7619 | { |
| 7620 | struct breakpoint *b; |
| 7621 | |
| 7622 | ALL_BREAKPOINTS (b) |
| 7623 | if (b->type == bp_overlay_event) |
| 7624 | { |
| 7625 | b->enable_state = bp_disabled; |
| 7626 | update_global_location_list (UGLL_DONT_INSERT); |
| 7627 | overlay_events_enabled = 0; |
| 7628 | } |
| 7629 | } |
| 7630 | |
| 7631 | /* Set an active std::terminate breakpoint for each std::terminate |
| 7632 | master breakpoint. */ |
| 7633 | void |
| 7634 | set_std_terminate_breakpoint (void) |
| 7635 | { |
| 7636 | struct breakpoint *b, *b_tmp; |
| 7637 | |
| 7638 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7639 | if (b->pspace == current_program_space |
| 7640 | && b->type == bp_std_terminate_master) |
| 7641 | { |
| 7642 | momentary_breakpoint_from_master (b, bp_std_terminate, |
| 7643 | &momentary_breakpoint_ops, 1); |
| 7644 | } |
| 7645 | } |
| 7646 | |
| 7647 | /* Delete all the std::terminate breakpoints. */ |
| 7648 | void |
| 7649 | delete_std_terminate_breakpoint (void) |
| 7650 | { |
| 7651 | struct breakpoint *b, *b_tmp; |
| 7652 | |
| 7653 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7654 | if (b->type == bp_std_terminate) |
| 7655 | delete_breakpoint (b); |
| 7656 | } |
| 7657 | |
| 7658 | struct breakpoint * |
| 7659 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7660 | { |
| 7661 | struct breakpoint *b; |
| 7662 | |
| 7663 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
| 7664 | &internal_breakpoint_ops); |
| 7665 | |
| 7666 | b->enable_state = bp_enabled; |
| 7667 | /* location has to be used or breakpoint_re_set will delete me. */ |
| 7668 | b->location = new_address_location (b->loc->address); |
| 7669 | |
| 7670 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 7671 | |
| 7672 | return b; |
| 7673 | } |
| 7674 | |
| 7675 | void |
| 7676 | remove_thread_event_breakpoints (void) |
| 7677 | { |
| 7678 | struct breakpoint *b, *b_tmp; |
| 7679 | |
| 7680 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7681 | if (b->type == bp_thread_event |
| 7682 | && b->loc->pspace == current_program_space) |
| 7683 | delete_breakpoint (b); |
| 7684 | } |
| 7685 | |
| 7686 | struct lang_and_radix |
| 7687 | { |
| 7688 | enum language lang; |
| 7689 | int radix; |
| 7690 | }; |
| 7691 | |
| 7692 | /* Create a breakpoint for JIT code registration and unregistration. */ |
| 7693 | |
| 7694 | struct breakpoint * |
| 7695 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7696 | { |
| 7697 | struct breakpoint *b; |
| 7698 | |
| 7699 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
| 7700 | &internal_breakpoint_ops); |
| 7701 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 7702 | return b; |
| 7703 | } |
| 7704 | |
| 7705 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
| 7706 | |
| 7707 | void |
| 7708 | remove_jit_event_breakpoints (void) |
| 7709 | { |
| 7710 | struct breakpoint *b, *b_tmp; |
| 7711 | |
| 7712 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7713 | if (b->type == bp_jit_event |
| 7714 | && b->loc->pspace == current_program_space) |
| 7715 | delete_breakpoint (b); |
| 7716 | } |
| 7717 | |
| 7718 | void |
| 7719 | remove_solib_event_breakpoints (void) |
| 7720 | { |
| 7721 | struct breakpoint *b, *b_tmp; |
| 7722 | |
| 7723 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7724 | if (b->type == bp_shlib_event |
| 7725 | && b->loc->pspace == current_program_space) |
| 7726 | delete_breakpoint (b); |
| 7727 | } |
| 7728 | |
| 7729 | /* See breakpoint.h. */ |
| 7730 | |
| 7731 | void |
| 7732 | remove_solib_event_breakpoints_at_next_stop (void) |
| 7733 | { |
| 7734 | struct breakpoint *b, *b_tmp; |
| 7735 | |
| 7736 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7737 | if (b->type == bp_shlib_event |
| 7738 | && b->loc->pspace == current_program_space) |
| 7739 | b->disposition = disp_del_at_next_stop; |
| 7740 | } |
| 7741 | |
| 7742 | /* Helper for create_solib_event_breakpoint / |
| 7743 | create_and_insert_solib_event_breakpoint. Allows specifying which |
| 7744 | INSERT_MODE to pass through to update_global_location_list. */ |
| 7745 | |
| 7746 | static struct breakpoint * |
| 7747 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, |
| 7748 | enum ugll_insert_mode insert_mode) |
| 7749 | { |
| 7750 | struct breakpoint *b; |
| 7751 | |
| 7752 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
| 7753 | &internal_breakpoint_ops); |
| 7754 | update_global_location_list_nothrow (insert_mode); |
| 7755 | return b; |
| 7756 | } |
| 7757 | |
| 7758 | struct breakpoint * |
| 7759 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7760 | { |
| 7761 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); |
| 7762 | } |
| 7763 | |
| 7764 | /* See breakpoint.h. */ |
| 7765 | |
| 7766 | struct breakpoint * |
| 7767 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7768 | { |
| 7769 | struct breakpoint *b; |
| 7770 | |
| 7771 | /* Explicitly tell update_global_location_list to insert |
| 7772 | locations. */ |
| 7773 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); |
| 7774 | if (!b->loc->inserted) |
| 7775 | { |
| 7776 | delete_breakpoint (b); |
| 7777 | return NULL; |
| 7778 | } |
| 7779 | return b; |
| 7780 | } |
| 7781 | |
| 7782 | /* Disable any breakpoints that are on code in shared libraries. Only |
| 7783 | apply to enabled breakpoints, disabled ones can just stay disabled. */ |
| 7784 | |
| 7785 | void |
| 7786 | disable_breakpoints_in_shlibs (void) |
| 7787 | { |
| 7788 | struct bp_location *loc, **locp_tmp; |
| 7789 | |
| 7790 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 7791 | { |
| 7792 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 7793 | struct breakpoint *b = loc->owner; |
| 7794 | |
| 7795 | /* We apply the check to all breakpoints, including disabled for |
| 7796 | those with loc->duplicate set. This is so that when breakpoint |
| 7797 | becomes enabled, or the duplicate is removed, gdb will try to |
| 7798 | insert all breakpoints. If we don't set shlib_disabled here, |
| 7799 | we'll try to insert those breakpoints and fail. */ |
| 7800 | if (((b->type == bp_breakpoint) |
| 7801 | || (b->type == bp_jit_event) |
| 7802 | || (b->type == bp_hardware_breakpoint) |
| 7803 | || (is_tracepoint (b))) |
| 7804 | && loc->pspace == current_program_space |
| 7805 | && !loc->shlib_disabled |
| 7806 | && solib_name_from_address (loc->pspace, loc->address) |
| 7807 | ) |
| 7808 | { |
| 7809 | loc->shlib_disabled = 1; |
| 7810 | } |
| 7811 | } |
| 7812 | } |
| 7813 | |
| 7814 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
| 7815 | notification of unloaded_shlib. Only apply to enabled breakpoints, |
| 7816 | disabled ones can just stay disabled. */ |
| 7817 | |
| 7818 | static void |
| 7819 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
| 7820 | { |
| 7821 | struct bp_location *loc, **locp_tmp; |
| 7822 | int disabled_shlib_breaks = 0; |
| 7823 | |
| 7824 | /* SunOS a.out shared libraries are always mapped, so do not |
| 7825 | disable breakpoints; they will only be reported as unloaded |
| 7826 | through clear_solib when GDB discards its shared library |
| 7827 | list. See clear_solib for more information. */ |
| 7828 | if (exec_bfd != NULL |
| 7829 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) |
| 7830 | return; |
| 7831 | |
| 7832 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 7833 | { |
| 7834 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 7835 | struct breakpoint *b = loc->owner; |
| 7836 | |
| 7837 | if (solib->pspace == loc->pspace |
| 7838 | && !loc->shlib_disabled |
| 7839 | && (((b->type == bp_breakpoint |
| 7840 | || b->type == bp_jit_event |
| 7841 | || b->type == bp_hardware_breakpoint) |
| 7842 | && (loc->loc_type == bp_loc_hardware_breakpoint |
| 7843 | || loc->loc_type == bp_loc_software_breakpoint)) |
| 7844 | || is_tracepoint (b)) |
| 7845 | && solib_contains_address_p (solib, loc->address)) |
| 7846 | { |
| 7847 | loc->shlib_disabled = 1; |
| 7848 | /* At this point, we cannot rely on remove_breakpoint |
| 7849 | succeeding so we must mark the breakpoint as not inserted |
| 7850 | to prevent future errors occurring in remove_breakpoints. */ |
| 7851 | loc->inserted = 0; |
| 7852 | |
| 7853 | /* This may cause duplicate notifications for the same breakpoint. */ |
| 7854 | observer_notify_breakpoint_modified (b); |
| 7855 | |
| 7856 | if (!disabled_shlib_breaks) |
| 7857 | { |
| 7858 | target_terminal_ours_for_output (); |
| 7859 | warning (_("Temporarily disabling breakpoints " |
| 7860 | "for unloaded shared library \"%s\""), |
| 7861 | solib->so_name); |
| 7862 | } |
| 7863 | disabled_shlib_breaks = 1; |
| 7864 | } |
| 7865 | } |
| 7866 | } |
| 7867 | |
| 7868 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
| 7869 | notification of free_objfile. Only apply to enabled breakpoints, |
| 7870 | disabled ones can just stay disabled. */ |
| 7871 | |
| 7872 | static void |
| 7873 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) |
| 7874 | { |
| 7875 | struct breakpoint *b; |
| 7876 | |
| 7877 | if (objfile == NULL) |
| 7878 | return; |
| 7879 | |
| 7880 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
| 7881 | managed by the user with add-symbol-file/remove-symbol-file. |
| 7882 | Similarly to how breakpoints in shared libraries are handled in |
| 7883 | response to "nosharedlibrary", mark breakpoints in such modules |
| 7884 | shlib_disabled so they end up uninserted on the next global |
| 7885 | location list update. Shared libraries not loaded by the user |
| 7886 | aren't handled here -- they're already handled in |
| 7887 | disable_breakpoints_in_unloaded_shlib, called by solib.c's |
| 7888 | solib_unloaded observer. We skip objfiles that are not |
| 7889 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
| 7890 | main objfile). */ |
| 7891 | if ((objfile->flags & OBJF_SHARED) == 0 |
| 7892 | || (objfile->flags & OBJF_USERLOADED) == 0) |
| 7893 | return; |
| 7894 | |
| 7895 | ALL_BREAKPOINTS (b) |
| 7896 | { |
| 7897 | struct bp_location *loc; |
| 7898 | int bp_modified = 0; |
| 7899 | |
| 7900 | if (!is_breakpoint (b) && !is_tracepoint (b)) |
| 7901 | continue; |
| 7902 | |
| 7903 | for (loc = b->loc; loc != NULL; loc = loc->next) |
| 7904 | { |
| 7905 | CORE_ADDR loc_addr = loc->address; |
| 7906 | |
| 7907 | if (loc->loc_type != bp_loc_hardware_breakpoint |
| 7908 | && loc->loc_type != bp_loc_software_breakpoint) |
| 7909 | continue; |
| 7910 | |
| 7911 | if (loc->shlib_disabled != 0) |
| 7912 | continue; |
| 7913 | |
| 7914 | if (objfile->pspace != loc->pspace) |
| 7915 | continue; |
| 7916 | |
| 7917 | if (loc->loc_type != bp_loc_hardware_breakpoint |
| 7918 | && loc->loc_type != bp_loc_software_breakpoint) |
| 7919 | continue; |
| 7920 | |
| 7921 | if (is_addr_in_objfile (loc_addr, objfile)) |
| 7922 | { |
| 7923 | loc->shlib_disabled = 1; |
| 7924 | /* At this point, we don't know whether the object was |
| 7925 | unmapped from the inferior or not, so leave the |
| 7926 | inserted flag alone. We'll handle failure to |
| 7927 | uninsert quietly, in case the object was indeed |
| 7928 | unmapped. */ |
| 7929 | |
| 7930 | mark_breakpoint_location_modified (loc); |
| 7931 | |
| 7932 | bp_modified = 1; |
| 7933 | } |
| 7934 | } |
| 7935 | |
| 7936 | if (bp_modified) |
| 7937 | observer_notify_breakpoint_modified (b); |
| 7938 | } |
| 7939 | } |
| 7940 | |
| 7941 | /* FORK & VFORK catchpoints. */ |
| 7942 | |
| 7943 | /* An instance of this type is used to represent a fork or vfork |
| 7944 | catchpoint. It includes a "struct breakpoint" as a kind of base |
| 7945 | class; users downcast to "struct breakpoint *" when needed. A |
| 7946 | breakpoint is really of this type iff its ops pointer points to |
| 7947 | CATCH_FORK_BREAKPOINT_OPS. */ |
| 7948 | |
| 7949 | struct fork_catchpoint |
| 7950 | { |
| 7951 | /* The base class. */ |
| 7952 | struct breakpoint base; |
| 7953 | |
| 7954 | /* Process id of a child process whose forking triggered this |
| 7955 | catchpoint. This field is only valid immediately after this |
| 7956 | catchpoint has triggered. */ |
| 7957 | ptid_t forked_inferior_pid; |
| 7958 | }; |
| 7959 | |
| 7960 | /* Implement the "insert" breakpoint_ops method for fork |
| 7961 | catchpoints. */ |
| 7962 | |
| 7963 | static int |
| 7964 | insert_catch_fork (struct bp_location *bl) |
| 7965 | { |
| 7966 | return target_insert_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
| 7967 | } |
| 7968 | |
| 7969 | /* Implement the "remove" breakpoint_ops method for fork |
| 7970 | catchpoints. */ |
| 7971 | |
| 7972 | static int |
| 7973 | remove_catch_fork (struct bp_location *bl) |
| 7974 | { |
| 7975 | return target_remove_fork_catchpoint (ptid_get_pid (inferior_ptid)); |
| 7976 | } |
| 7977 | |
| 7978 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork |
| 7979 | catchpoints. */ |
| 7980 | |
| 7981 | static int |
| 7982 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
| 7983 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 7984 | const struct target_waitstatus *ws) |
| 7985 | { |
| 7986 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
| 7987 | |
| 7988 | if (ws->kind != TARGET_WAITKIND_FORKED) |
| 7989 | return 0; |
| 7990 | |
| 7991 | c->forked_inferior_pid = ws->value.related_pid; |
| 7992 | return 1; |
| 7993 | } |
| 7994 | |
| 7995 | /* Implement the "print_it" breakpoint_ops method for fork |
| 7996 | catchpoints. */ |
| 7997 | |
| 7998 | static enum print_stop_action |
| 7999 | print_it_catch_fork (bpstat bs) |
| 8000 | { |
| 8001 | struct ui_out *uiout = current_uiout; |
| 8002 | struct breakpoint *b = bs->breakpoint_at; |
| 8003 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; |
| 8004 | |
| 8005 | annotate_catchpoint (b->number); |
| 8006 | if (b->disposition == disp_del) |
| 8007 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8008 | else |
| 8009 | ui_out_text (uiout, "\nCatchpoint "); |
| 8010 | if (ui_out_is_mi_like_p (uiout)) |
| 8011 | { |
| 8012 | ui_out_field_string (uiout, "reason", |
| 8013 | async_reason_lookup (EXEC_ASYNC_FORK)); |
| 8014 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8015 | } |
| 8016 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8017 | ui_out_text (uiout, " (forked process "); |
| 8018 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); |
| 8019 | ui_out_text (uiout, "), "); |
| 8020 | return PRINT_SRC_AND_LOC; |
| 8021 | } |
| 8022 | |
| 8023 | /* Implement the "print_one" breakpoint_ops method for fork |
| 8024 | catchpoints. */ |
| 8025 | |
| 8026 | static void |
| 8027 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
| 8028 | { |
| 8029 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 8030 | struct value_print_options opts; |
| 8031 | struct ui_out *uiout = current_uiout; |
| 8032 | |
| 8033 | get_user_print_options (&opts); |
| 8034 | |
| 8035 | /* Field 4, the address, is omitted (which makes the columns not |
| 8036 | line up too nicely with the headers, but the effect is relatively |
| 8037 | readable). */ |
| 8038 | if (opts.addressprint) |
| 8039 | ui_out_field_skip (uiout, "addr"); |
| 8040 | annotate_field (5); |
| 8041 | ui_out_text (uiout, "fork"); |
| 8042 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
| 8043 | { |
| 8044 | ui_out_text (uiout, ", process "); |
| 8045 | ui_out_field_int (uiout, "what", |
| 8046 | ptid_get_pid (c->forked_inferior_pid)); |
| 8047 | ui_out_spaces (uiout, 1); |
| 8048 | } |
| 8049 | |
| 8050 | if (ui_out_is_mi_like_p (uiout)) |
| 8051 | ui_out_field_string (uiout, "catch-type", "fork"); |
| 8052 | } |
| 8053 | |
| 8054 | /* Implement the "print_mention" breakpoint_ops method for fork |
| 8055 | catchpoints. */ |
| 8056 | |
| 8057 | static void |
| 8058 | print_mention_catch_fork (struct breakpoint *b) |
| 8059 | { |
| 8060 | printf_filtered (_("Catchpoint %d (fork)"), b->number); |
| 8061 | } |
| 8062 | |
| 8063 | /* Implement the "print_recreate" breakpoint_ops method for fork |
| 8064 | catchpoints. */ |
| 8065 | |
| 8066 | static void |
| 8067 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) |
| 8068 | { |
| 8069 | fprintf_unfiltered (fp, "catch fork"); |
| 8070 | print_recreate_thread (b, fp); |
| 8071 | } |
| 8072 | |
| 8073 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
| 8074 | |
| 8075 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
| 8076 | |
| 8077 | /* Implement the "insert" breakpoint_ops method for vfork |
| 8078 | catchpoints. */ |
| 8079 | |
| 8080 | static int |
| 8081 | insert_catch_vfork (struct bp_location *bl) |
| 8082 | { |
| 8083 | return target_insert_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
| 8084 | } |
| 8085 | |
| 8086 | /* Implement the "remove" breakpoint_ops method for vfork |
| 8087 | catchpoints. */ |
| 8088 | |
| 8089 | static int |
| 8090 | remove_catch_vfork (struct bp_location *bl) |
| 8091 | { |
| 8092 | return target_remove_vfork_catchpoint (ptid_get_pid (inferior_ptid)); |
| 8093 | } |
| 8094 | |
| 8095 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork |
| 8096 | catchpoints. */ |
| 8097 | |
| 8098 | static int |
| 8099 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
| 8100 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 8101 | const struct target_waitstatus *ws) |
| 8102 | { |
| 8103 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
| 8104 | |
| 8105 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
| 8106 | return 0; |
| 8107 | |
| 8108 | c->forked_inferior_pid = ws->value.related_pid; |
| 8109 | return 1; |
| 8110 | } |
| 8111 | |
| 8112 | /* Implement the "print_it" breakpoint_ops method for vfork |
| 8113 | catchpoints. */ |
| 8114 | |
| 8115 | static enum print_stop_action |
| 8116 | print_it_catch_vfork (bpstat bs) |
| 8117 | { |
| 8118 | struct ui_out *uiout = current_uiout; |
| 8119 | struct breakpoint *b = bs->breakpoint_at; |
| 8120 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 8121 | |
| 8122 | annotate_catchpoint (b->number); |
| 8123 | if (b->disposition == disp_del) |
| 8124 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8125 | else |
| 8126 | ui_out_text (uiout, "\nCatchpoint "); |
| 8127 | if (ui_out_is_mi_like_p (uiout)) |
| 8128 | { |
| 8129 | ui_out_field_string (uiout, "reason", |
| 8130 | async_reason_lookup (EXEC_ASYNC_VFORK)); |
| 8131 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8132 | } |
| 8133 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8134 | ui_out_text (uiout, " (vforked process "); |
| 8135 | ui_out_field_int (uiout, "newpid", ptid_get_pid (c->forked_inferior_pid)); |
| 8136 | ui_out_text (uiout, "), "); |
| 8137 | return PRINT_SRC_AND_LOC; |
| 8138 | } |
| 8139 | |
| 8140 | /* Implement the "print_one" breakpoint_ops method for vfork |
| 8141 | catchpoints. */ |
| 8142 | |
| 8143 | static void |
| 8144 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
| 8145 | { |
| 8146 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 8147 | struct value_print_options opts; |
| 8148 | struct ui_out *uiout = current_uiout; |
| 8149 | |
| 8150 | get_user_print_options (&opts); |
| 8151 | /* Field 4, the address, is omitted (which makes the columns not |
| 8152 | line up too nicely with the headers, but the effect is relatively |
| 8153 | readable). */ |
| 8154 | if (opts.addressprint) |
| 8155 | ui_out_field_skip (uiout, "addr"); |
| 8156 | annotate_field (5); |
| 8157 | ui_out_text (uiout, "vfork"); |
| 8158 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
| 8159 | { |
| 8160 | ui_out_text (uiout, ", process "); |
| 8161 | ui_out_field_int (uiout, "what", |
| 8162 | ptid_get_pid (c->forked_inferior_pid)); |
| 8163 | ui_out_spaces (uiout, 1); |
| 8164 | } |
| 8165 | |
| 8166 | if (ui_out_is_mi_like_p (uiout)) |
| 8167 | ui_out_field_string (uiout, "catch-type", "vfork"); |
| 8168 | } |
| 8169 | |
| 8170 | /* Implement the "print_mention" breakpoint_ops method for vfork |
| 8171 | catchpoints. */ |
| 8172 | |
| 8173 | static void |
| 8174 | print_mention_catch_vfork (struct breakpoint *b) |
| 8175 | { |
| 8176 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); |
| 8177 | } |
| 8178 | |
| 8179 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
| 8180 | catchpoints. */ |
| 8181 | |
| 8182 | static void |
| 8183 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) |
| 8184 | { |
| 8185 | fprintf_unfiltered (fp, "catch vfork"); |
| 8186 | print_recreate_thread (b, fp); |
| 8187 | } |
| 8188 | |
| 8189 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
| 8190 | |
| 8191 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
| 8192 | |
| 8193 | /* An instance of this type is used to represent an solib catchpoint. |
| 8194 | It includes a "struct breakpoint" as a kind of base class; users |
| 8195 | downcast to "struct breakpoint *" when needed. A breakpoint is |
| 8196 | really of this type iff its ops pointer points to |
| 8197 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
| 8198 | |
| 8199 | struct solib_catchpoint |
| 8200 | { |
| 8201 | /* The base class. */ |
| 8202 | struct breakpoint base; |
| 8203 | |
| 8204 | /* True for "catch load", false for "catch unload". */ |
| 8205 | unsigned char is_load; |
| 8206 | |
| 8207 | /* Regular expression to match, if any. COMPILED is only valid when |
| 8208 | REGEX is non-NULL. */ |
| 8209 | char *regex; |
| 8210 | regex_t compiled; |
| 8211 | }; |
| 8212 | |
| 8213 | static void |
| 8214 | dtor_catch_solib (struct breakpoint *b) |
| 8215 | { |
| 8216 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8217 | |
| 8218 | if (self->regex) |
| 8219 | regfree (&self->compiled); |
| 8220 | xfree (self->regex); |
| 8221 | |
| 8222 | base_breakpoint_ops.dtor (b); |
| 8223 | } |
| 8224 | |
| 8225 | static int |
| 8226 | insert_catch_solib (struct bp_location *ignore) |
| 8227 | { |
| 8228 | return 0; |
| 8229 | } |
| 8230 | |
| 8231 | static int |
| 8232 | remove_catch_solib (struct bp_location *ignore) |
| 8233 | { |
| 8234 | return 0; |
| 8235 | } |
| 8236 | |
| 8237 | static int |
| 8238 | breakpoint_hit_catch_solib (const struct bp_location *bl, |
| 8239 | struct address_space *aspace, |
| 8240 | CORE_ADDR bp_addr, |
| 8241 | const struct target_waitstatus *ws) |
| 8242 | { |
| 8243 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; |
| 8244 | struct breakpoint *other; |
| 8245 | |
| 8246 | if (ws->kind == TARGET_WAITKIND_LOADED) |
| 8247 | return 1; |
| 8248 | |
| 8249 | ALL_BREAKPOINTS (other) |
| 8250 | { |
| 8251 | struct bp_location *other_bl; |
| 8252 | |
| 8253 | if (other == bl->owner) |
| 8254 | continue; |
| 8255 | |
| 8256 | if (other->type != bp_shlib_event) |
| 8257 | continue; |
| 8258 | |
| 8259 | if (self->base.pspace != NULL && other->pspace != self->base.pspace) |
| 8260 | continue; |
| 8261 | |
| 8262 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) |
| 8263 | { |
| 8264 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) |
| 8265 | return 1; |
| 8266 | } |
| 8267 | } |
| 8268 | |
| 8269 | return 0; |
| 8270 | } |
| 8271 | |
| 8272 | static void |
| 8273 | check_status_catch_solib (struct bpstats *bs) |
| 8274 | { |
| 8275 | struct solib_catchpoint *self |
| 8276 | = (struct solib_catchpoint *) bs->breakpoint_at; |
| 8277 | int ix; |
| 8278 | |
| 8279 | if (self->is_load) |
| 8280 | { |
| 8281 | struct so_list *iter; |
| 8282 | |
| 8283 | for (ix = 0; |
| 8284 | VEC_iterate (so_list_ptr, current_program_space->added_solibs, |
| 8285 | ix, iter); |
| 8286 | ++ix) |
| 8287 | { |
| 8288 | if (!self->regex |
| 8289 | || regexec (&self->compiled, iter->so_name, 0, NULL, 0) == 0) |
| 8290 | return; |
| 8291 | } |
| 8292 | } |
| 8293 | else |
| 8294 | { |
| 8295 | char *iter; |
| 8296 | |
| 8297 | for (ix = 0; |
| 8298 | VEC_iterate (char_ptr, current_program_space->deleted_solibs, |
| 8299 | ix, iter); |
| 8300 | ++ix) |
| 8301 | { |
| 8302 | if (!self->regex |
| 8303 | || regexec (&self->compiled, iter, 0, NULL, 0) == 0) |
| 8304 | return; |
| 8305 | } |
| 8306 | } |
| 8307 | |
| 8308 | bs->stop = 0; |
| 8309 | bs->print_it = print_it_noop; |
| 8310 | } |
| 8311 | |
| 8312 | static enum print_stop_action |
| 8313 | print_it_catch_solib (bpstat bs) |
| 8314 | { |
| 8315 | struct breakpoint *b = bs->breakpoint_at; |
| 8316 | struct ui_out *uiout = current_uiout; |
| 8317 | |
| 8318 | annotate_catchpoint (b->number); |
| 8319 | if (b->disposition == disp_del) |
| 8320 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8321 | else |
| 8322 | ui_out_text (uiout, "\nCatchpoint "); |
| 8323 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8324 | ui_out_text (uiout, "\n"); |
| 8325 | if (ui_out_is_mi_like_p (uiout)) |
| 8326 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8327 | print_solib_event (1); |
| 8328 | return PRINT_SRC_AND_LOC; |
| 8329 | } |
| 8330 | |
| 8331 | static void |
| 8332 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) |
| 8333 | { |
| 8334 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8335 | struct value_print_options opts; |
| 8336 | struct ui_out *uiout = current_uiout; |
| 8337 | char *msg; |
| 8338 | |
| 8339 | get_user_print_options (&opts); |
| 8340 | /* Field 4, the address, is omitted (which makes the columns not |
| 8341 | line up too nicely with the headers, but the effect is relatively |
| 8342 | readable). */ |
| 8343 | if (opts.addressprint) |
| 8344 | { |
| 8345 | annotate_field (4); |
| 8346 | ui_out_field_skip (uiout, "addr"); |
| 8347 | } |
| 8348 | |
| 8349 | annotate_field (5); |
| 8350 | if (self->is_load) |
| 8351 | { |
| 8352 | if (self->regex) |
| 8353 | msg = xstrprintf (_("load of library matching %s"), self->regex); |
| 8354 | else |
| 8355 | msg = xstrdup (_("load of library")); |
| 8356 | } |
| 8357 | else |
| 8358 | { |
| 8359 | if (self->regex) |
| 8360 | msg = xstrprintf (_("unload of library matching %s"), self->regex); |
| 8361 | else |
| 8362 | msg = xstrdup (_("unload of library")); |
| 8363 | } |
| 8364 | ui_out_field_string (uiout, "what", msg); |
| 8365 | xfree (msg); |
| 8366 | |
| 8367 | if (ui_out_is_mi_like_p (uiout)) |
| 8368 | ui_out_field_string (uiout, "catch-type", |
| 8369 | self->is_load ? "load" : "unload"); |
| 8370 | } |
| 8371 | |
| 8372 | static void |
| 8373 | print_mention_catch_solib (struct breakpoint *b) |
| 8374 | { |
| 8375 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8376 | |
| 8377 | printf_filtered (_("Catchpoint %d (%s)"), b->number, |
| 8378 | self->is_load ? "load" : "unload"); |
| 8379 | } |
| 8380 | |
| 8381 | static void |
| 8382 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) |
| 8383 | { |
| 8384 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8385 | |
| 8386 | fprintf_unfiltered (fp, "%s %s", |
| 8387 | b->disposition == disp_del ? "tcatch" : "catch", |
| 8388 | self->is_load ? "load" : "unload"); |
| 8389 | if (self->regex) |
| 8390 | fprintf_unfiltered (fp, " %s", self->regex); |
| 8391 | fprintf_unfiltered (fp, "\n"); |
| 8392 | } |
| 8393 | |
| 8394 | static struct breakpoint_ops catch_solib_breakpoint_ops; |
| 8395 | |
| 8396 | /* Shared helper function (MI and CLI) for creating and installing |
| 8397 | a shared object event catchpoint. If IS_LOAD is non-zero then |
| 8398 | the events to be caught are load events, otherwise they are |
| 8399 | unload events. If IS_TEMP is non-zero the catchpoint is a |
| 8400 | temporary one. If ENABLED is non-zero the catchpoint is |
| 8401 | created in an enabled state. */ |
| 8402 | |
| 8403 | void |
| 8404 | add_solib_catchpoint (char *arg, int is_load, int is_temp, int enabled) |
| 8405 | { |
| 8406 | struct solib_catchpoint *c; |
| 8407 | struct gdbarch *gdbarch = get_current_arch (); |
| 8408 | struct cleanup *cleanup; |
| 8409 | |
| 8410 | if (!arg) |
| 8411 | arg = ""; |
| 8412 | arg = skip_spaces (arg); |
| 8413 | |
| 8414 | c = XCNEW (struct solib_catchpoint); |
| 8415 | cleanup = make_cleanup (xfree, c); |
| 8416 | |
| 8417 | if (*arg != '\0') |
| 8418 | { |
| 8419 | int errcode; |
| 8420 | |
| 8421 | errcode = regcomp (&c->compiled, arg, REG_NOSUB); |
| 8422 | if (errcode != 0) |
| 8423 | { |
| 8424 | char *err = get_regcomp_error (errcode, &c->compiled); |
| 8425 | |
| 8426 | make_cleanup (xfree, err); |
| 8427 | error (_("Invalid regexp (%s): %s"), err, arg); |
| 8428 | } |
| 8429 | c->regex = xstrdup (arg); |
| 8430 | } |
| 8431 | |
| 8432 | c->is_load = is_load; |
| 8433 | init_catchpoint (&c->base, gdbarch, is_temp, NULL, |
| 8434 | &catch_solib_breakpoint_ops); |
| 8435 | |
| 8436 | c->base.enable_state = enabled ? bp_enabled : bp_disabled; |
| 8437 | |
| 8438 | discard_cleanups (cleanup); |
| 8439 | install_breakpoint (0, &c->base, 1); |
| 8440 | } |
| 8441 | |
| 8442 | /* A helper function that does all the work for "catch load" and |
| 8443 | "catch unload". */ |
| 8444 | |
| 8445 | static void |
| 8446 | catch_load_or_unload (char *arg, int from_tty, int is_load, |
| 8447 | struct cmd_list_element *command) |
| 8448 | { |
| 8449 | int tempflag; |
| 8450 | const int enabled = 1; |
| 8451 | |
| 8452 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8453 | |
| 8454 | add_solib_catchpoint (arg, is_load, tempflag, enabled); |
| 8455 | } |
| 8456 | |
| 8457 | static void |
| 8458 | catch_load_command_1 (char *arg, int from_tty, |
| 8459 | struct cmd_list_element *command) |
| 8460 | { |
| 8461 | catch_load_or_unload (arg, from_tty, 1, command); |
| 8462 | } |
| 8463 | |
| 8464 | static void |
| 8465 | catch_unload_command_1 (char *arg, int from_tty, |
| 8466 | struct cmd_list_element *command) |
| 8467 | { |
| 8468 | catch_load_or_unload (arg, from_tty, 0, command); |
| 8469 | } |
| 8470 | |
| 8471 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
| 8472 | is non-zero, then make the breakpoint temporary. If COND_STRING is |
| 8473 | not NULL, then store it in the breakpoint. OPS, if not NULL, is |
| 8474 | the breakpoint_ops structure associated to the catchpoint. */ |
| 8475 | |
| 8476 | void |
| 8477 | init_catchpoint (struct breakpoint *b, |
| 8478 | struct gdbarch *gdbarch, int tempflag, |
| 8479 | char *cond_string, |
| 8480 | const struct breakpoint_ops *ops) |
| 8481 | { |
| 8482 | struct symtab_and_line sal; |
| 8483 | |
| 8484 | init_sal (&sal); |
| 8485 | sal.pspace = current_program_space; |
| 8486 | |
| 8487 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
| 8488 | |
| 8489 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
| 8490 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 8491 | } |
| 8492 | |
| 8493 | void |
| 8494 | install_breakpoint (int internal, struct breakpoint *b, int update_gll) |
| 8495 | { |
| 8496 | add_to_breakpoint_chain (b); |
| 8497 | set_breakpoint_number (internal, b); |
| 8498 | if (is_tracepoint (b)) |
| 8499 | set_tracepoint_count (breakpoint_count); |
| 8500 | if (!internal) |
| 8501 | mention (b); |
| 8502 | observer_notify_breakpoint_created (b); |
| 8503 | |
| 8504 | if (update_gll) |
| 8505 | update_global_location_list (UGLL_MAY_INSERT); |
| 8506 | } |
| 8507 | |
| 8508 | static void |
| 8509 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
| 8510 | int tempflag, char *cond_string, |
| 8511 | const struct breakpoint_ops *ops) |
| 8512 | { |
| 8513 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
| 8514 | |
| 8515 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
| 8516 | |
| 8517 | c->forked_inferior_pid = null_ptid; |
| 8518 | |
| 8519 | install_breakpoint (0, &c->base, 1); |
| 8520 | } |
| 8521 | |
| 8522 | /* Exec catchpoints. */ |
| 8523 | |
| 8524 | /* An instance of this type is used to represent an exec catchpoint. |
| 8525 | It includes a "struct breakpoint" as a kind of base class; users |
| 8526 | downcast to "struct breakpoint *" when needed. A breakpoint is |
| 8527 | really of this type iff its ops pointer points to |
| 8528 | CATCH_EXEC_BREAKPOINT_OPS. */ |
| 8529 | |
| 8530 | struct exec_catchpoint |
| 8531 | { |
| 8532 | /* The base class. */ |
| 8533 | struct breakpoint base; |
| 8534 | |
| 8535 | /* Filename of a program whose exec triggered this catchpoint. |
| 8536 | This field is only valid immediately after this catchpoint has |
| 8537 | triggered. */ |
| 8538 | char *exec_pathname; |
| 8539 | }; |
| 8540 | |
| 8541 | /* Implement the "dtor" breakpoint_ops method for exec |
| 8542 | catchpoints. */ |
| 8543 | |
| 8544 | static void |
| 8545 | dtor_catch_exec (struct breakpoint *b) |
| 8546 | { |
| 8547 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8548 | |
| 8549 | xfree (c->exec_pathname); |
| 8550 | |
| 8551 | base_breakpoint_ops.dtor (b); |
| 8552 | } |
| 8553 | |
| 8554 | static int |
| 8555 | insert_catch_exec (struct bp_location *bl) |
| 8556 | { |
| 8557 | return target_insert_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
| 8558 | } |
| 8559 | |
| 8560 | static int |
| 8561 | remove_catch_exec (struct bp_location *bl) |
| 8562 | { |
| 8563 | return target_remove_exec_catchpoint (ptid_get_pid (inferior_ptid)); |
| 8564 | } |
| 8565 | |
| 8566 | static int |
| 8567 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
| 8568 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 8569 | const struct target_waitstatus *ws) |
| 8570 | { |
| 8571 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
| 8572 | |
| 8573 | if (ws->kind != TARGET_WAITKIND_EXECD) |
| 8574 | return 0; |
| 8575 | |
| 8576 | c->exec_pathname = xstrdup (ws->value.execd_pathname); |
| 8577 | return 1; |
| 8578 | } |
| 8579 | |
| 8580 | static enum print_stop_action |
| 8581 | print_it_catch_exec (bpstat bs) |
| 8582 | { |
| 8583 | struct ui_out *uiout = current_uiout; |
| 8584 | struct breakpoint *b = bs->breakpoint_at; |
| 8585 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8586 | |
| 8587 | annotate_catchpoint (b->number); |
| 8588 | if (b->disposition == disp_del) |
| 8589 | ui_out_text (uiout, "\nTemporary catchpoint "); |
| 8590 | else |
| 8591 | ui_out_text (uiout, "\nCatchpoint "); |
| 8592 | if (ui_out_is_mi_like_p (uiout)) |
| 8593 | { |
| 8594 | ui_out_field_string (uiout, "reason", |
| 8595 | async_reason_lookup (EXEC_ASYNC_EXEC)); |
| 8596 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 8597 | } |
| 8598 | ui_out_field_int (uiout, "bkptno", b->number); |
| 8599 | ui_out_text (uiout, " (exec'd "); |
| 8600 | ui_out_field_string (uiout, "new-exec", c->exec_pathname); |
| 8601 | ui_out_text (uiout, "), "); |
| 8602 | |
| 8603 | return PRINT_SRC_AND_LOC; |
| 8604 | } |
| 8605 | |
| 8606 | static void |
| 8607 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
| 8608 | { |
| 8609 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8610 | struct value_print_options opts; |
| 8611 | struct ui_out *uiout = current_uiout; |
| 8612 | |
| 8613 | get_user_print_options (&opts); |
| 8614 | |
| 8615 | /* Field 4, the address, is omitted (which makes the columns |
| 8616 | not line up too nicely with the headers, but the effect |
| 8617 | is relatively readable). */ |
| 8618 | if (opts.addressprint) |
| 8619 | ui_out_field_skip (uiout, "addr"); |
| 8620 | annotate_field (5); |
| 8621 | ui_out_text (uiout, "exec"); |
| 8622 | if (c->exec_pathname != NULL) |
| 8623 | { |
| 8624 | ui_out_text (uiout, ", program \""); |
| 8625 | ui_out_field_string (uiout, "what", c->exec_pathname); |
| 8626 | ui_out_text (uiout, "\" "); |
| 8627 | } |
| 8628 | |
| 8629 | if (ui_out_is_mi_like_p (uiout)) |
| 8630 | ui_out_field_string (uiout, "catch-type", "exec"); |
| 8631 | } |
| 8632 | |
| 8633 | static void |
| 8634 | print_mention_catch_exec (struct breakpoint *b) |
| 8635 | { |
| 8636 | printf_filtered (_("Catchpoint %d (exec)"), b->number); |
| 8637 | } |
| 8638 | |
| 8639 | /* Implement the "print_recreate" breakpoint_ops method for exec |
| 8640 | catchpoints. */ |
| 8641 | |
| 8642 | static void |
| 8643 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) |
| 8644 | { |
| 8645 | fprintf_unfiltered (fp, "catch exec"); |
| 8646 | print_recreate_thread (b, fp); |
| 8647 | } |
| 8648 | |
| 8649 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
| 8650 | |
| 8651 | static int |
| 8652 | hw_breakpoint_used_count (void) |
| 8653 | { |
| 8654 | int i = 0; |
| 8655 | struct breakpoint *b; |
| 8656 | struct bp_location *bl; |
| 8657 | |
| 8658 | ALL_BREAKPOINTS (b) |
| 8659 | { |
| 8660 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
| 8661 | for (bl = b->loc; bl; bl = bl->next) |
| 8662 | { |
| 8663 | /* Special types of hardware breakpoints may use more than |
| 8664 | one register. */ |
| 8665 | i += b->ops->resources_needed (bl); |
| 8666 | } |
| 8667 | } |
| 8668 | |
| 8669 | return i; |
| 8670 | } |
| 8671 | |
| 8672 | /* Returns the resources B would use if it were a hardware |
| 8673 | watchpoint. */ |
| 8674 | |
| 8675 | static int |
| 8676 | hw_watchpoint_use_count (struct breakpoint *b) |
| 8677 | { |
| 8678 | int i = 0; |
| 8679 | struct bp_location *bl; |
| 8680 | |
| 8681 | if (!breakpoint_enabled (b)) |
| 8682 | return 0; |
| 8683 | |
| 8684 | for (bl = b->loc; bl; bl = bl->next) |
| 8685 | { |
| 8686 | /* Special types of hardware watchpoints may use more than |
| 8687 | one register. */ |
| 8688 | i += b->ops->resources_needed (bl); |
| 8689 | } |
| 8690 | |
| 8691 | return i; |
| 8692 | } |
| 8693 | |
| 8694 | /* Returns the sum the used resources of all hardware watchpoints of |
| 8695 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED |
| 8696 | the sum of the used resources of all hardware watchpoints of other |
| 8697 | types _not_ TYPE. */ |
| 8698 | |
| 8699 | static int |
| 8700 | hw_watchpoint_used_count_others (struct breakpoint *except, |
| 8701 | enum bptype type, int *other_type_used) |
| 8702 | { |
| 8703 | int i = 0; |
| 8704 | struct breakpoint *b; |
| 8705 | |
| 8706 | *other_type_used = 0; |
| 8707 | ALL_BREAKPOINTS (b) |
| 8708 | { |
| 8709 | if (b == except) |
| 8710 | continue; |
| 8711 | if (!breakpoint_enabled (b)) |
| 8712 | continue; |
| 8713 | |
| 8714 | if (b->type == type) |
| 8715 | i += hw_watchpoint_use_count (b); |
| 8716 | else if (is_hardware_watchpoint (b)) |
| 8717 | *other_type_used = 1; |
| 8718 | } |
| 8719 | |
| 8720 | return i; |
| 8721 | } |
| 8722 | |
| 8723 | void |
| 8724 | disable_watchpoints_before_interactive_call_start (void) |
| 8725 | { |
| 8726 | struct breakpoint *b; |
| 8727 | |
| 8728 | ALL_BREAKPOINTS (b) |
| 8729 | { |
| 8730 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
| 8731 | { |
| 8732 | b->enable_state = bp_call_disabled; |
| 8733 | update_global_location_list (UGLL_DONT_INSERT); |
| 8734 | } |
| 8735 | } |
| 8736 | } |
| 8737 | |
| 8738 | void |
| 8739 | enable_watchpoints_after_interactive_call_stop (void) |
| 8740 | { |
| 8741 | struct breakpoint *b; |
| 8742 | |
| 8743 | ALL_BREAKPOINTS (b) |
| 8744 | { |
| 8745 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
| 8746 | { |
| 8747 | b->enable_state = bp_enabled; |
| 8748 | update_global_location_list (UGLL_MAY_INSERT); |
| 8749 | } |
| 8750 | } |
| 8751 | } |
| 8752 | |
| 8753 | void |
| 8754 | disable_breakpoints_before_startup (void) |
| 8755 | { |
| 8756 | current_program_space->executing_startup = 1; |
| 8757 | update_global_location_list (UGLL_DONT_INSERT); |
| 8758 | } |
| 8759 | |
| 8760 | void |
| 8761 | enable_breakpoints_after_startup (void) |
| 8762 | { |
| 8763 | current_program_space->executing_startup = 0; |
| 8764 | breakpoint_re_set (); |
| 8765 | } |
| 8766 | |
| 8767 | /* Create a new single-step breakpoint for thread THREAD, with no |
| 8768 | locations. */ |
| 8769 | |
| 8770 | static struct breakpoint * |
| 8771 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) |
| 8772 | { |
| 8773 | struct breakpoint *b = XNEW (struct breakpoint); |
| 8774 | |
| 8775 | init_raw_breakpoint_without_location (b, gdbarch, bp_single_step, |
| 8776 | &momentary_breakpoint_ops); |
| 8777 | |
| 8778 | b->disposition = disp_donttouch; |
| 8779 | b->frame_id = null_frame_id; |
| 8780 | |
| 8781 | b->thread = thread; |
| 8782 | gdb_assert (b->thread != 0); |
| 8783 | |
| 8784 | add_to_breakpoint_chain (b); |
| 8785 | |
| 8786 | return b; |
| 8787 | } |
| 8788 | |
| 8789 | /* Set a momentary breakpoint of type TYPE at address specified by |
| 8790 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that |
| 8791 | frame. */ |
| 8792 | |
| 8793 | struct breakpoint * |
| 8794 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
| 8795 | struct frame_id frame_id, enum bptype type) |
| 8796 | { |
| 8797 | struct breakpoint *b; |
| 8798 | |
| 8799 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
| 8800 | tail-called one. */ |
| 8801 | gdb_assert (!frame_id_artificial_p (frame_id)); |
| 8802 | |
| 8803 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
| 8804 | b->enable_state = bp_enabled; |
| 8805 | b->disposition = disp_donttouch; |
| 8806 | b->frame_id = frame_id; |
| 8807 | |
| 8808 | /* If we're debugging a multi-threaded program, then we want |
| 8809 | momentary breakpoints to be active in only a single thread of |
| 8810 | control. */ |
| 8811 | if (in_thread_list (inferior_ptid)) |
| 8812 | b->thread = pid_to_thread_id (inferior_ptid); |
| 8813 | |
| 8814 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 8815 | |
| 8816 | return b; |
| 8817 | } |
| 8818 | |
| 8819 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
| 8820 | The new breakpoint will have type TYPE, use OPS as its |
| 8821 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ |
| 8822 | |
| 8823 | static struct breakpoint * |
| 8824 | momentary_breakpoint_from_master (struct breakpoint *orig, |
| 8825 | enum bptype type, |
| 8826 | const struct breakpoint_ops *ops, |
| 8827 | int loc_enabled) |
| 8828 | { |
| 8829 | struct breakpoint *copy; |
| 8830 | |
| 8831 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
| 8832 | copy->loc = allocate_bp_location (copy); |
| 8833 | set_breakpoint_location_function (copy->loc, 1); |
| 8834 | |
| 8835 | copy->loc->gdbarch = orig->loc->gdbarch; |
| 8836 | copy->loc->requested_address = orig->loc->requested_address; |
| 8837 | copy->loc->address = orig->loc->address; |
| 8838 | copy->loc->section = orig->loc->section; |
| 8839 | copy->loc->pspace = orig->loc->pspace; |
| 8840 | copy->loc->probe = orig->loc->probe; |
| 8841 | copy->loc->line_number = orig->loc->line_number; |
| 8842 | copy->loc->symtab = orig->loc->symtab; |
| 8843 | copy->loc->enabled = loc_enabled; |
| 8844 | copy->frame_id = orig->frame_id; |
| 8845 | copy->thread = orig->thread; |
| 8846 | copy->pspace = orig->pspace; |
| 8847 | |
| 8848 | copy->enable_state = bp_enabled; |
| 8849 | copy->disposition = disp_donttouch; |
| 8850 | copy->number = internal_breakpoint_number--; |
| 8851 | |
| 8852 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
| 8853 | return copy; |
| 8854 | } |
| 8855 | |
| 8856 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
| 8857 | ORIG is NULL. */ |
| 8858 | |
| 8859 | struct breakpoint * |
| 8860 | clone_momentary_breakpoint (struct breakpoint *orig) |
| 8861 | { |
| 8862 | /* If there's nothing to clone, then return nothing. */ |
| 8863 | if (orig == NULL) |
| 8864 | return NULL; |
| 8865 | |
| 8866 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
| 8867 | } |
| 8868 | |
| 8869 | struct breakpoint * |
| 8870 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 8871 | enum bptype type) |
| 8872 | { |
| 8873 | struct symtab_and_line sal; |
| 8874 | |
| 8875 | sal = find_pc_line (pc, 0); |
| 8876 | sal.pc = pc; |
| 8877 | sal.section = find_pc_overlay (pc); |
| 8878 | sal.explicit_pc = 1; |
| 8879 | |
| 8880 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
| 8881 | } |
| 8882 | \f |
| 8883 | |
| 8884 | /* Tell the user we have just set a breakpoint B. */ |
| 8885 | |
| 8886 | static void |
| 8887 | mention (struct breakpoint *b) |
| 8888 | { |
| 8889 | b->ops->print_mention (b); |
| 8890 | if (ui_out_is_mi_like_p (current_uiout)) |
| 8891 | return; |
| 8892 | printf_filtered ("\n"); |
| 8893 | } |
| 8894 | \f |
| 8895 | |
| 8896 | static int bp_loc_is_permanent (struct bp_location *loc); |
| 8897 | |
| 8898 | static struct bp_location * |
| 8899 | add_location_to_breakpoint (struct breakpoint *b, |
| 8900 | const struct symtab_and_line *sal) |
| 8901 | { |
| 8902 | struct bp_location *loc, **tmp; |
| 8903 | CORE_ADDR adjusted_address; |
| 8904 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); |
| 8905 | |
| 8906 | if (loc_gdbarch == NULL) |
| 8907 | loc_gdbarch = b->gdbarch; |
| 8908 | |
| 8909 | /* Adjust the breakpoint's address prior to allocating a location. |
| 8910 | Once we call allocate_bp_location(), that mostly uninitialized |
| 8911 | location will be placed on the location chain. Adjustment of the |
| 8912 | breakpoint may cause target_read_memory() to be called and we do |
| 8913 | not want its scan of the location chain to find a breakpoint and |
| 8914 | location that's only been partially initialized. */ |
| 8915 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
| 8916 | sal->pc, b->type); |
| 8917 | |
| 8918 | /* Sort the locations by their ADDRESS. */ |
| 8919 | loc = allocate_bp_location (b); |
| 8920 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
| 8921 | tmp = &((*tmp)->next)) |
| 8922 | ; |
| 8923 | loc->next = *tmp; |
| 8924 | *tmp = loc; |
| 8925 | |
| 8926 | loc->requested_address = sal->pc; |
| 8927 | loc->address = adjusted_address; |
| 8928 | loc->pspace = sal->pspace; |
| 8929 | loc->probe.probe = sal->probe; |
| 8930 | loc->probe.objfile = sal->objfile; |
| 8931 | gdb_assert (loc->pspace != NULL); |
| 8932 | loc->section = sal->section; |
| 8933 | loc->gdbarch = loc_gdbarch; |
| 8934 | loc->line_number = sal->line; |
| 8935 | loc->symtab = sal->symtab; |
| 8936 | |
| 8937 | set_breakpoint_location_function (loc, |
| 8938 | sal->explicit_pc || sal->explicit_line); |
| 8939 | |
| 8940 | /* While by definition, permanent breakpoints are already present in the |
| 8941 | code, we don't mark the location as inserted. Normally one would expect |
| 8942 | that GDB could rely on that breakpoint instruction to stop the program, |
| 8943 | thus removing the need to insert its own breakpoint, except that executing |
| 8944 | the breakpoint instruction can kill the target instead of reporting a |
| 8945 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the |
| 8946 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies |
| 8947 | with "Trap 0x02 while interrupts disabled, Error state". Letting the |
| 8948 | breakpoint be inserted normally results in QEMU knowing about the GDB |
| 8949 | breakpoint, and thus trap before the breakpoint instruction is executed. |
| 8950 | (If GDB later needs to continue execution past the permanent breakpoint, |
| 8951 | it manually increments the PC, thus avoiding executing the breakpoint |
| 8952 | instruction.) */ |
| 8953 | if (bp_loc_is_permanent (loc)) |
| 8954 | loc->permanent = 1; |
| 8955 | |
| 8956 | return loc; |
| 8957 | } |
| 8958 | \f |
| 8959 | |
| 8960 | /* See breakpoint.h. */ |
| 8961 | |
| 8962 | int |
| 8963 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) |
| 8964 | { |
| 8965 | int len; |
| 8966 | CORE_ADDR addr; |
| 8967 | const gdb_byte *bpoint; |
| 8968 | gdb_byte *target_mem; |
| 8969 | struct cleanup *cleanup; |
| 8970 | int retval = 0; |
| 8971 | |
| 8972 | addr = address; |
| 8973 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); |
| 8974 | |
| 8975 | /* Software breakpoints unsupported? */ |
| 8976 | if (bpoint == NULL) |
| 8977 | return 0; |
| 8978 | |
| 8979 | target_mem = alloca (len); |
| 8980 | |
| 8981 | /* Enable the automatic memory restoration from breakpoints while |
| 8982 | we read the memory. Otherwise we could say about our temporary |
| 8983 | breakpoints they are permanent. */ |
| 8984 | cleanup = make_show_memory_breakpoints_cleanup (0); |
| 8985 | |
| 8986 | if (target_read_memory (address, target_mem, len) == 0 |
| 8987 | && memcmp (target_mem, bpoint, len) == 0) |
| 8988 | retval = 1; |
| 8989 | |
| 8990 | do_cleanups (cleanup); |
| 8991 | |
| 8992 | return retval; |
| 8993 | } |
| 8994 | |
| 8995 | /* Return 1 if LOC is pointing to a permanent breakpoint, |
| 8996 | return 0 otherwise. */ |
| 8997 | |
| 8998 | static int |
| 8999 | bp_loc_is_permanent (struct bp_location *loc) |
| 9000 | { |
| 9001 | struct cleanup *cleanup; |
| 9002 | int retval; |
| 9003 | |
| 9004 | gdb_assert (loc != NULL); |
| 9005 | |
| 9006 | cleanup = save_current_space_and_thread (); |
| 9007 | switch_to_program_space_and_thread (loc->pspace); |
| 9008 | |
| 9009 | retval = program_breakpoint_here_p (loc->gdbarch, loc->address); |
| 9010 | |
| 9011 | do_cleanups (cleanup); |
| 9012 | |
| 9013 | return retval; |
| 9014 | } |
| 9015 | |
| 9016 | /* Build a command list for the dprintf corresponding to the current |
| 9017 | settings of the dprintf style options. */ |
| 9018 | |
| 9019 | static void |
| 9020 | update_dprintf_command_list (struct breakpoint *b) |
| 9021 | { |
| 9022 | char *dprintf_args = b->extra_string; |
| 9023 | char *printf_line = NULL; |
| 9024 | |
| 9025 | if (!dprintf_args) |
| 9026 | return; |
| 9027 | |
| 9028 | dprintf_args = skip_spaces (dprintf_args); |
| 9029 | |
| 9030 | /* Allow a comma, as it may have terminated a location, but don't |
| 9031 | insist on it. */ |
| 9032 | if (*dprintf_args == ',') |
| 9033 | ++dprintf_args; |
| 9034 | dprintf_args = skip_spaces (dprintf_args); |
| 9035 | |
| 9036 | if (*dprintf_args != '"') |
| 9037 | error (_("Bad format string, missing '\"'.")); |
| 9038 | |
| 9039 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
| 9040 | printf_line = xstrprintf ("printf %s", dprintf_args); |
| 9041 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
| 9042 | { |
| 9043 | if (!dprintf_function) |
| 9044 | error (_("No function supplied for dprintf call")); |
| 9045 | |
| 9046 | if (dprintf_channel && strlen (dprintf_channel) > 0) |
| 9047 | printf_line = xstrprintf ("call (void) %s (%s,%s)", |
| 9048 | dprintf_function, |
| 9049 | dprintf_channel, |
| 9050 | dprintf_args); |
| 9051 | else |
| 9052 | printf_line = xstrprintf ("call (void) %s (%s)", |
| 9053 | dprintf_function, |
| 9054 | dprintf_args); |
| 9055 | } |
| 9056 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
| 9057 | { |
| 9058 | if (target_can_run_breakpoint_commands ()) |
| 9059 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); |
| 9060 | else |
| 9061 | { |
| 9062 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); |
| 9063 | printf_line = xstrprintf ("printf %s", dprintf_args); |
| 9064 | } |
| 9065 | } |
| 9066 | else |
| 9067 | internal_error (__FILE__, __LINE__, |
| 9068 | _("Invalid dprintf style.")); |
| 9069 | |
| 9070 | gdb_assert (printf_line != NULL); |
| 9071 | /* Manufacture a printf sequence. */ |
| 9072 | { |
| 9073 | struct command_line *printf_cmd_line |
| 9074 | = xmalloc (sizeof (struct command_line)); |
| 9075 | |
| 9076 | printf_cmd_line->control_type = simple_control; |
| 9077 | printf_cmd_line->body_count = 0; |
| 9078 | printf_cmd_line->body_list = NULL; |
| 9079 | printf_cmd_line->next = NULL; |
| 9080 | printf_cmd_line->line = printf_line; |
| 9081 | |
| 9082 | breakpoint_set_commands (b, printf_cmd_line); |
| 9083 | } |
| 9084 | } |
| 9085 | |
| 9086 | /* Update all dprintf commands, making their command lists reflect |
| 9087 | current style settings. */ |
| 9088 | |
| 9089 | static void |
| 9090 | update_dprintf_commands (char *args, int from_tty, |
| 9091 | struct cmd_list_element *c) |
| 9092 | { |
| 9093 | struct breakpoint *b; |
| 9094 | |
| 9095 | ALL_BREAKPOINTS (b) |
| 9096 | { |
| 9097 | if (b->type == bp_dprintf) |
| 9098 | update_dprintf_command_list (b); |
| 9099 | } |
| 9100 | } |
| 9101 | |
| 9102 | /* Create a breakpoint with SAL as location. Use LOCATION |
| 9103 | as a description of the location, and COND_STRING |
| 9104 | as condition expression. */ |
| 9105 | |
| 9106 | static void |
| 9107 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
| 9108 | struct symtabs_and_lines sals, |
| 9109 | struct event_location *location, |
| 9110 | char *filter, char *cond_string, |
| 9111 | char *extra_string, |
| 9112 | enum bptype type, enum bpdisp disposition, |
| 9113 | int thread, int task, int ignore_count, |
| 9114 | const struct breakpoint_ops *ops, int from_tty, |
| 9115 | int enabled, int internal, unsigned flags, |
| 9116 | int display_canonical) |
| 9117 | { |
| 9118 | int i; |
| 9119 | |
| 9120 | if (type == bp_hardware_breakpoint) |
| 9121 | { |
| 9122 | int target_resources_ok; |
| 9123 | |
| 9124 | i = hw_breakpoint_used_count (); |
| 9125 | target_resources_ok = |
| 9126 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 9127 | i + 1, 0); |
| 9128 | if (target_resources_ok == 0) |
| 9129 | error (_("No hardware breakpoint support in the target.")); |
| 9130 | else if (target_resources_ok < 0) |
| 9131 | error (_("Hardware breakpoints used exceeds limit.")); |
| 9132 | } |
| 9133 | |
| 9134 | gdb_assert (sals.nelts > 0); |
| 9135 | |
| 9136 | for (i = 0; i < sals.nelts; ++i) |
| 9137 | { |
| 9138 | struct symtab_and_line sal = sals.sals[i]; |
| 9139 | struct bp_location *loc; |
| 9140 | |
| 9141 | if (from_tty) |
| 9142 | { |
| 9143 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 9144 | if (!loc_gdbarch) |
| 9145 | loc_gdbarch = gdbarch; |
| 9146 | |
| 9147 | describe_other_breakpoints (loc_gdbarch, |
| 9148 | sal.pspace, sal.pc, sal.section, thread); |
| 9149 | } |
| 9150 | |
| 9151 | if (i == 0) |
| 9152 | { |
| 9153 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
| 9154 | b->thread = thread; |
| 9155 | b->task = task; |
| 9156 | |
| 9157 | b->cond_string = cond_string; |
| 9158 | b->extra_string = extra_string; |
| 9159 | b->ignore_count = ignore_count; |
| 9160 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 9161 | b->disposition = disposition; |
| 9162 | |
| 9163 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
| 9164 | b->loc->inserted = 1; |
| 9165 | |
| 9166 | if (type == bp_static_tracepoint) |
| 9167 | { |
| 9168 | struct tracepoint *t = (struct tracepoint *) b; |
| 9169 | struct static_tracepoint_marker marker; |
| 9170 | |
| 9171 | if (strace_marker_p (b)) |
| 9172 | { |
| 9173 | /* We already know the marker exists, otherwise, we |
| 9174 | wouldn't see a sal for it. */ |
| 9175 | const char *p = &event_location_to_string (b->location)[3]; |
| 9176 | const char *endp; |
| 9177 | char *marker_str; |
| 9178 | |
| 9179 | p = skip_spaces_const (p); |
| 9180 | |
| 9181 | endp = skip_to_space_const (p); |
| 9182 | |
| 9183 | marker_str = savestring (p, endp - p); |
| 9184 | t->static_trace_marker_id = marker_str; |
| 9185 | |
| 9186 | printf_filtered (_("Probed static tracepoint " |
| 9187 | "marker \"%s\"\n"), |
| 9188 | t->static_trace_marker_id); |
| 9189 | } |
| 9190 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) |
| 9191 | { |
| 9192 | t->static_trace_marker_id = xstrdup (marker.str_id); |
| 9193 | release_static_tracepoint_marker (&marker); |
| 9194 | |
| 9195 | printf_filtered (_("Probed static tracepoint " |
| 9196 | "marker \"%s\"\n"), |
| 9197 | t->static_trace_marker_id); |
| 9198 | } |
| 9199 | else |
| 9200 | warning (_("Couldn't determine the static " |
| 9201 | "tracepoint marker to probe")); |
| 9202 | } |
| 9203 | |
| 9204 | loc = b->loc; |
| 9205 | } |
| 9206 | else |
| 9207 | { |
| 9208 | loc = add_location_to_breakpoint (b, &sal); |
| 9209 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
| 9210 | loc->inserted = 1; |
| 9211 | } |
| 9212 | |
| 9213 | if (b->cond_string) |
| 9214 | { |
| 9215 | const char *arg = b->cond_string; |
| 9216 | |
| 9217 | loc->cond = parse_exp_1 (&arg, loc->address, |
| 9218 | block_for_pc (loc->address), 0); |
| 9219 | if (*arg) |
| 9220 | error (_("Garbage '%s' follows condition"), arg); |
| 9221 | } |
| 9222 | |
| 9223 | /* Dynamic printf requires and uses additional arguments on the |
| 9224 | command line, otherwise it's an error. */ |
| 9225 | if (type == bp_dprintf) |
| 9226 | { |
| 9227 | if (b->extra_string) |
| 9228 | update_dprintf_command_list (b); |
| 9229 | else |
| 9230 | error (_("Format string required")); |
| 9231 | } |
| 9232 | else if (b->extra_string) |
| 9233 | error (_("Garbage '%s' at end of command"), b->extra_string); |
| 9234 | } |
| 9235 | |
| 9236 | b->display_canonical = display_canonical; |
| 9237 | if (location != NULL) |
| 9238 | b->location = location; |
| 9239 | else |
| 9240 | b->location = new_address_location (b->loc->address); |
| 9241 | b->filter = filter; |
| 9242 | } |
| 9243 | |
| 9244 | static void |
| 9245 | create_breakpoint_sal (struct gdbarch *gdbarch, |
| 9246 | struct symtabs_and_lines sals, |
| 9247 | struct event_location *location, |
| 9248 | char *filter, char *cond_string, |
| 9249 | char *extra_string, |
| 9250 | enum bptype type, enum bpdisp disposition, |
| 9251 | int thread, int task, int ignore_count, |
| 9252 | const struct breakpoint_ops *ops, int from_tty, |
| 9253 | int enabled, int internal, unsigned flags, |
| 9254 | int display_canonical) |
| 9255 | { |
| 9256 | struct breakpoint *b; |
| 9257 | struct cleanup *old_chain; |
| 9258 | |
| 9259 | if (is_tracepoint_type (type)) |
| 9260 | { |
| 9261 | struct tracepoint *t; |
| 9262 | |
| 9263 | t = XCNEW (struct tracepoint); |
| 9264 | b = &t->base; |
| 9265 | } |
| 9266 | else |
| 9267 | b = XNEW (struct breakpoint); |
| 9268 | |
| 9269 | old_chain = make_cleanup (xfree, b); |
| 9270 | |
| 9271 | init_breakpoint_sal (b, gdbarch, |
| 9272 | sals, location, |
| 9273 | filter, cond_string, extra_string, |
| 9274 | type, disposition, |
| 9275 | thread, task, ignore_count, |
| 9276 | ops, from_tty, |
| 9277 | enabled, internal, flags, |
| 9278 | display_canonical); |
| 9279 | discard_cleanups (old_chain); |
| 9280 | |
| 9281 | install_breakpoint (internal, b, 0); |
| 9282 | } |
| 9283 | |
| 9284 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
| 9285 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] |
| 9286 | value. COND_STRING, if not NULL, specified the condition to be |
| 9287 | used for all breakpoints. Essentially the only case where |
| 9288 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded |
| 9289 | function. In that case, it's still not possible to specify |
| 9290 | separate conditions for different overloaded functions, so |
| 9291 | we take just a single condition string. |
| 9292 | |
| 9293 | NOTE: If the function succeeds, the caller is expected to cleanup |
| 9294 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
| 9295 | array contents). If the function fails (error() is called), the |
| 9296 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, |
| 9297 | COND and SALS arrays and each of those arrays contents. */ |
| 9298 | |
| 9299 | static void |
| 9300 | create_breakpoints_sal (struct gdbarch *gdbarch, |
| 9301 | struct linespec_result *canonical, |
| 9302 | char *cond_string, char *extra_string, |
| 9303 | enum bptype type, enum bpdisp disposition, |
| 9304 | int thread, int task, int ignore_count, |
| 9305 | const struct breakpoint_ops *ops, int from_tty, |
| 9306 | int enabled, int internal, unsigned flags) |
| 9307 | { |
| 9308 | int i; |
| 9309 | struct linespec_sals *lsal; |
| 9310 | |
| 9311 | if (canonical->pre_expanded) |
| 9312 | gdb_assert (VEC_length (linespec_sals, canonical->sals) == 1); |
| 9313 | |
| 9314 | for (i = 0; VEC_iterate (linespec_sals, canonical->sals, i, lsal); ++i) |
| 9315 | { |
| 9316 | /* Note that 'location' can be NULL in the case of a plain |
| 9317 | 'break', without arguments. */ |
| 9318 | struct event_location *location |
| 9319 | = (canonical->location != NULL |
| 9320 | ? copy_event_location (canonical->location) : NULL); |
| 9321 | char *filter_string = lsal->canonical ? xstrdup (lsal->canonical) : NULL; |
| 9322 | struct cleanup *inner = make_cleanup_delete_event_location (location); |
| 9323 | |
| 9324 | make_cleanup (xfree, filter_string); |
| 9325 | create_breakpoint_sal (gdbarch, lsal->sals, |
| 9326 | location, |
| 9327 | filter_string, |
| 9328 | cond_string, extra_string, |
| 9329 | type, disposition, |
| 9330 | thread, task, ignore_count, ops, |
| 9331 | from_tty, enabled, internal, flags, |
| 9332 | canonical->special_display); |
| 9333 | discard_cleanups (inner); |
| 9334 | } |
| 9335 | } |
| 9336 | |
| 9337 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
| 9338 | followed by conditionals. On return, SALS contains an array of SAL |
| 9339 | addresses found. LOCATION points to the end of the SAL (for |
| 9340 | linespec locations). |
| 9341 | |
| 9342 | The array and the line spec strings are allocated on the heap, it is |
| 9343 | the caller's responsibility to free them. */ |
| 9344 | |
| 9345 | static void |
| 9346 | parse_breakpoint_sals (const struct event_location *location, |
| 9347 | struct linespec_result *canonical) |
| 9348 | { |
| 9349 | struct symtab_and_line cursal; |
| 9350 | |
| 9351 | if (event_location_type (location) == LINESPEC_LOCATION) |
| 9352 | { |
| 9353 | const char *address = get_linespec_location (location); |
| 9354 | |
| 9355 | if (address == NULL) |
| 9356 | { |
| 9357 | /* The last displayed codepoint, if it's valid, is our default |
| 9358 | breakpoint address. */ |
| 9359 | if (last_displayed_sal_is_valid ()) |
| 9360 | { |
| 9361 | struct linespec_sals lsal; |
| 9362 | struct symtab_and_line sal; |
| 9363 | CORE_ADDR pc; |
| 9364 | |
| 9365 | init_sal (&sal); /* Initialize to zeroes. */ |
| 9366 | lsal.sals.sals = (struct symtab_and_line *) |
| 9367 | xmalloc (sizeof (struct symtab_and_line)); |
| 9368 | |
| 9369 | /* Set sal's pspace, pc, symtab, and line to the values |
| 9370 | corresponding to the last call to print_frame_info. |
| 9371 | Be sure to reinitialize LINE with NOTCURRENT == 0 |
| 9372 | as the breakpoint line number is inappropriate otherwise. |
| 9373 | find_pc_line would adjust PC, re-set it back. */ |
| 9374 | get_last_displayed_sal (&sal); |
| 9375 | pc = sal.pc; |
| 9376 | sal = find_pc_line (pc, 0); |
| 9377 | |
| 9378 | /* "break" without arguments is equivalent to "break *PC" |
| 9379 | where PC is the last displayed codepoint's address. So |
| 9380 | make sure to set sal.explicit_pc to prevent GDB from |
| 9381 | trying to expand the list of sals to include all other |
| 9382 | instances with the same symtab and line. */ |
| 9383 | sal.pc = pc; |
| 9384 | sal.explicit_pc = 1; |
| 9385 | |
| 9386 | lsal.sals.sals[0] = sal; |
| 9387 | lsal.sals.nelts = 1; |
| 9388 | lsal.canonical = NULL; |
| 9389 | |
| 9390 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
| 9391 | return; |
| 9392 | } |
| 9393 | else |
| 9394 | error (_("No default breakpoint address now.")); |
| 9395 | } |
| 9396 | } |
| 9397 | |
| 9398 | /* Force almost all breakpoints to be in terms of the |
| 9399 | current_source_symtab (which is decode_line_1's default). |
| 9400 | This should produce the results we want almost all of the |
| 9401 | time while leaving default_breakpoint_* alone. |
| 9402 | |
| 9403 | ObjC: However, don't match an Objective-C method name which |
| 9404 | may have a '+' or '-' succeeded by a '['. */ |
| 9405 | cursal = get_current_source_symtab_and_line (); |
| 9406 | if (last_displayed_sal_is_valid ()) |
| 9407 | { |
| 9408 | const char *address = NULL; |
| 9409 | |
| 9410 | if (event_location_type (location) == LINESPEC_LOCATION) |
| 9411 | address = get_linespec_location (location); |
| 9412 | |
| 9413 | if (!cursal.symtab |
| 9414 | || (address != NULL |
| 9415 | && strchr ("+-", address[0]) != NULL |
| 9416 | && address[1] != '[')) |
| 9417 | { |
| 9418 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, |
| 9419 | get_last_displayed_symtab (), |
| 9420 | get_last_displayed_line (), |
| 9421 | canonical, NULL, NULL); |
| 9422 | return; |
| 9423 | } |
| 9424 | } |
| 9425 | |
| 9426 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, |
| 9427 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
| 9428 | } |
| 9429 | |
| 9430 | |
| 9431 | /* Convert each SAL into a real PC. Verify that the PC can be |
| 9432 | inserted as a breakpoint. If it can't throw an error. */ |
| 9433 | |
| 9434 | static void |
| 9435 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
| 9436 | { |
| 9437 | int i; |
| 9438 | |
| 9439 | for (i = 0; i < sals->nelts; i++) |
| 9440 | resolve_sal_pc (&sals->sals[i]); |
| 9441 | } |
| 9442 | |
| 9443 | /* Fast tracepoints may have restrictions on valid locations. For |
| 9444 | instance, a fast tracepoint using a jump instead of a trap will |
| 9445 | likely have to overwrite more bytes than a trap would, and so can |
| 9446 | only be placed where the instruction is longer than the jump, or a |
| 9447 | multi-instruction sequence does not have a jump into the middle of |
| 9448 | it, etc. */ |
| 9449 | |
| 9450 | static void |
| 9451 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, |
| 9452 | struct symtabs_and_lines *sals) |
| 9453 | { |
| 9454 | int i, rslt; |
| 9455 | struct symtab_and_line *sal; |
| 9456 | char *msg; |
| 9457 | struct cleanup *old_chain; |
| 9458 | |
| 9459 | for (i = 0; i < sals->nelts; i++) |
| 9460 | { |
| 9461 | struct gdbarch *sarch; |
| 9462 | |
| 9463 | sal = &sals->sals[i]; |
| 9464 | |
| 9465 | sarch = get_sal_arch (*sal); |
| 9466 | /* We fall back to GDBARCH if there is no architecture |
| 9467 | associated with SAL. */ |
| 9468 | if (sarch == NULL) |
| 9469 | sarch = gdbarch; |
| 9470 | rslt = gdbarch_fast_tracepoint_valid_at (sarch, sal->pc, &msg); |
| 9471 | old_chain = make_cleanup (xfree, msg); |
| 9472 | |
| 9473 | if (!rslt) |
| 9474 | error (_("May not have a fast tracepoint at 0x%s%s"), |
| 9475 | paddress (sarch, sal->pc), (msg ? msg : "")); |
| 9476 | |
| 9477 | do_cleanups (old_chain); |
| 9478 | } |
| 9479 | } |
| 9480 | |
| 9481 | /* Issue an invalid thread ID error. */ |
| 9482 | |
| 9483 | static void ATTRIBUTE_NORETURN |
| 9484 | invalid_thread_id_error (int id) |
| 9485 | { |
| 9486 | error (_("Unknown thread %d."), id); |
| 9487 | } |
| 9488 | |
| 9489 | /* Given TOK, a string specification of condition and thread, as |
| 9490 | accepted by the 'break' command, extract the condition |
| 9491 | string and thread number and set *COND_STRING and *THREAD. |
| 9492 | PC identifies the context at which the condition should be parsed. |
| 9493 | If no condition is found, *COND_STRING is set to NULL. |
| 9494 | If no thread is found, *THREAD is set to -1. */ |
| 9495 | |
| 9496 | static void |
| 9497 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
| 9498 | char **cond_string, int *thread, int *task, |
| 9499 | char **rest) |
| 9500 | { |
| 9501 | *cond_string = NULL; |
| 9502 | *thread = -1; |
| 9503 | *task = 0; |
| 9504 | *rest = NULL; |
| 9505 | |
| 9506 | while (tok && *tok) |
| 9507 | { |
| 9508 | const char *end_tok; |
| 9509 | int toklen; |
| 9510 | const char *cond_start = NULL; |
| 9511 | const char *cond_end = NULL; |
| 9512 | |
| 9513 | tok = skip_spaces_const (tok); |
| 9514 | |
| 9515 | if ((*tok == '"' || *tok == ',') && rest) |
| 9516 | { |
| 9517 | *rest = savestring (tok, strlen (tok)); |
| 9518 | return; |
| 9519 | } |
| 9520 | |
| 9521 | end_tok = skip_to_space_const (tok); |
| 9522 | |
| 9523 | toklen = end_tok - tok; |
| 9524 | |
| 9525 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 9526 | { |
| 9527 | struct expression *expr; |
| 9528 | |
| 9529 | tok = cond_start = end_tok + 1; |
| 9530 | expr = parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
| 9531 | xfree (expr); |
| 9532 | cond_end = tok; |
| 9533 | *cond_string = savestring (cond_start, cond_end - cond_start); |
| 9534 | } |
| 9535 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 9536 | { |
| 9537 | char *tmptok; |
| 9538 | |
| 9539 | tok = end_tok + 1; |
| 9540 | *thread = strtol (tok, &tmptok, 0); |
| 9541 | if (tok == tmptok) |
| 9542 | error (_("Junk after thread keyword.")); |
| 9543 | if (!valid_thread_id (*thread)) |
| 9544 | invalid_thread_id_error (*thread); |
| 9545 | tok = tmptok; |
| 9546 | } |
| 9547 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
| 9548 | { |
| 9549 | char *tmptok; |
| 9550 | |
| 9551 | tok = end_tok + 1; |
| 9552 | *task = strtol (tok, &tmptok, 0); |
| 9553 | if (tok == tmptok) |
| 9554 | error (_("Junk after task keyword.")); |
| 9555 | if (!valid_task_id (*task)) |
| 9556 | error (_("Unknown task %d."), *task); |
| 9557 | tok = tmptok; |
| 9558 | } |
| 9559 | else if (rest) |
| 9560 | { |
| 9561 | *rest = savestring (tok, strlen (tok)); |
| 9562 | return; |
| 9563 | } |
| 9564 | else |
| 9565 | error (_("Junk at end of arguments.")); |
| 9566 | } |
| 9567 | } |
| 9568 | |
| 9569 | /* Decode a static tracepoint marker spec. */ |
| 9570 | |
| 9571 | static struct symtabs_and_lines |
| 9572 | decode_static_tracepoint_spec (const char **arg_p) |
| 9573 | { |
| 9574 | VEC(static_tracepoint_marker_p) *markers = NULL; |
| 9575 | struct symtabs_and_lines sals; |
| 9576 | struct cleanup *old_chain; |
| 9577 | const char *p = &(*arg_p)[3]; |
| 9578 | const char *endp; |
| 9579 | char *marker_str; |
| 9580 | int i; |
| 9581 | |
| 9582 | p = skip_spaces_const (p); |
| 9583 | |
| 9584 | endp = skip_to_space_const (p); |
| 9585 | |
| 9586 | marker_str = savestring (p, endp - p); |
| 9587 | old_chain = make_cleanup (xfree, marker_str); |
| 9588 | |
| 9589 | markers = target_static_tracepoint_markers_by_strid (marker_str); |
| 9590 | if (VEC_empty(static_tracepoint_marker_p, markers)) |
| 9591 | error (_("No known static tracepoint marker named %s"), marker_str); |
| 9592 | |
| 9593 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); |
| 9594 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); |
| 9595 | |
| 9596 | for (i = 0; i < sals.nelts; i++) |
| 9597 | { |
| 9598 | struct static_tracepoint_marker *marker; |
| 9599 | |
| 9600 | marker = VEC_index (static_tracepoint_marker_p, markers, i); |
| 9601 | |
| 9602 | init_sal (&sals.sals[i]); |
| 9603 | |
| 9604 | sals.sals[i] = find_pc_line (marker->address, 0); |
| 9605 | sals.sals[i].pc = marker->address; |
| 9606 | |
| 9607 | release_static_tracepoint_marker (marker); |
| 9608 | } |
| 9609 | |
| 9610 | do_cleanups (old_chain); |
| 9611 | |
| 9612 | *arg_p = endp; |
| 9613 | return sals; |
| 9614 | } |
| 9615 | |
| 9616 | /* See breakpoint.h. */ |
| 9617 | |
| 9618 | int |
| 9619 | create_breakpoint (struct gdbarch *gdbarch, |
| 9620 | const struct event_location *location, char *cond_string, |
| 9621 | int thread, char *extra_string, |
| 9622 | int parse_extra, |
| 9623 | int tempflag, enum bptype type_wanted, |
| 9624 | int ignore_count, |
| 9625 | enum auto_boolean pending_break_support, |
| 9626 | const struct breakpoint_ops *ops, |
| 9627 | int from_tty, int enabled, int internal, |
| 9628 | unsigned flags) |
| 9629 | { |
| 9630 | struct linespec_result canonical; |
| 9631 | struct cleanup *old_chain; |
| 9632 | struct cleanup *bkpt_chain = NULL; |
| 9633 | int pending = 0; |
| 9634 | int task = 0; |
| 9635 | int prev_bkpt_count = breakpoint_count; |
| 9636 | |
| 9637 | gdb_assert (ops != NULL); |
| 9638 | |
| 9639 | /* If extra_string isn't useful, set it to NULL. */ |
| 9640 | if (extra_string != NULL && *extra_string == '\0') |
| 9641 | extra_string = NULL; |
| 9642 | |
| 9643 | init_linespec_result (&canonical); |
| 9644 | |
| 9645 | TRY |
| 9646 | { |
| 9647 | ops->create_sals_from_location (location, &canonical, type_wanted); |
| 9648 | } |
| 9649 | CATCH (e, RETURN_MASK_ERROR) |
| 9650 | { |
| 9651 | /* If caller is interested in rc value from parse, set |
| 9652 | value. */ |
| 9653 | if (e.error == NOT_FOUND_ERROR) |
| 9654 | { |
| 9655 | /* If pending breakpoint support is turned off, throw |
| 9656 | error. */ |
| 9657 | |
| 9658 | if (pending_break_support == AUTO_BOOLEAN_FALSE) |
| 9659 | throw_exception (e); |
| 9660 | |
| 9661 | exception_print (gdb_stderr, e); |
| 9662 | |
| 9663 | /* If pending breakpoint support is auto query and the user |
| 9664 | selects no, then simply return the error code. */ |
| 9665 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
| 9666 | && !nquery (_("Make %s pending on future shared library load? "), |
| 9667 | bptype_string (type_wanted))) |
| 9668 | return 0; |
| 9669 | |
| 9670 | /* At this point, either the user was queried about setting |
| 9671 | a pending breakpoint and selected yes, or pending |
| 9672 | breakpoint behavior is on and thus a pending breakpoint |
| 9673 | is defaulted on behalf of the user. */ |
| 9674 | pending = 1; |
| 9675 | } |
| 9676 | else |
| 9677 | throw_exception (e); |
| 9678 | } |
| 9679 | END_CATCH |
| 9680 | |
| 9681 | if (!pending && VEC_empty (linespec_sals, canonical.sals)) |
| 9682 | return 0; |
| 9683 | |
| 9684 | /* Create a chain of things that always need to be cleaned up. */ |
| 9685 | old_chain = make_cleanup_destroy_linespec_result (&canonical); |
| 9686 | |
| 9687 | /* ----------------------------- SNIP ----------------------------- |
| 9688 | Anything added to the cleanup chain beyond this point is assumed |
| 9689 | to be part of a breakpoint. If the breakpoint create succeeds |
| 9690 | then the memory is not reclaimed. */ |
| 9691 | bkpt_chain = make_cleanup (null_cleanup, 0); |
| 9692 | |
| 9693 | /* Resolve all line numbers to PC's and verify that the addresses |
| 9694 | are ok for the target. */ |
| 9695 | if (!pending) |
| 9696 | { |
| 9697 | int ix; |
| 9698 | struct linespec_sals *iter; |
| 9699 | |
| 9700 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) |
| 9701 | breakpoint_sals_to_pc (&iter->sals); |
| 9702 | } |
| 9703 | |
| 9704 | /* Fast tracepoints may have additional restrictions on location. */ |
| 9705 | if (!pending && type_wanted == bp_fast_tracepoint) |
| 9706 | { |
| 9707 | int ix; |
| 9708 | struct linespec_sals *iter; |
| 9709 | |
| 9710 | for (ix = 0; VEC_iterate (linespec_sals, canonical.sals, ix, iter); ++ix) |
| 9711 | check_fast_tracepoint_sals (gdbarch, &iter->sals); |
| 9712 | } |
| 9713 | |
| 9714 | /* Verify that condition can be parsed, before setting any |
| 9715 | breakpoints. Allocate a separate condition expression for each |
| 9716 | breakpoint. */ |
| 9717 | if (!pending) |
| 9718 | { |
| 9719 | if (parse_extra) |
| 9720 | { |
| 9721 | char *rest; |
| 9722 | struct linespec_sals *lsal; |
| 9723 | |
| 9724 | lsal = VEC_index (linespec_sals, canonical.sals, 0); |
| 9725 | |
| 9726 | /* Here we only parse 'arg' to separate condition |
| 9727 | from thread number, so parsing in context of first |
| 9728 | sal is OK. When setting the breakpoint we'll |
| 9729 | re-parse it in context of each sal. */ |
| 9730 | |
| 9731 | find_condition_and_thread (extra_string, lsal->sals.sals[0].pc, |
| 9732 | &cond_string, &thread, &task, &rest); |
| 9733 | if (cond_string) |
| 9734 | make_cleanup (xfree, cond_string); |
| 9735 | if (rest) |
| 9736 | make_cleanup (xfree, rest); |
| 9737 | if (rest) |
| 9738 | extra_string = rest; |
| 9739 | else |
| 9740 | extra_string = NULL; |
| 9741 | } |
| 9742 | else |
| 9743 | { |
| 9744 | if (type_wanted != bp_dprintf |
| 9745 | && extra_string != NULL && *extra_string != '\0') |
| 9746 | error (_("Garbage '%s' at end of location"), extra_string); |
| 9747 | |
| 9748 | /* Create a private copy of condition string. */ |
| 9749 | if (cond_string) |
| 9750 | { |
| 9751 | cond_string = xstrdup (cond_string); |
| 9752 | make_cleanup (xfree, cond_string); |
| 9753 | } |
| 9754 | /* Create a private copy of any extra string. */ |
| 9755 | if (extra_string) |
| 9756 | { |
| 9757 | extra_string = xstrdup (extra_string); |
| 9758 | make_cleanup (xfree, extra_string); |
| 9759 | } |
| 9760 | } |
| 9761 | |
| 9762 | ops->create_breakpoints_sal (gdbarch, &canonical, |
| 9763 | cond_string, extra_string, type_wanted, |
| 9764 | tempflag ? disp_del : disp_donttouch, |
| 9765 | thread, task, ignore_count, ops, |
| 9766 | from_tty, enabled, internal, flags); |
| 9767 | } |
| 9768 | else |
| 9769 | { |
| 9770 | struct breakpoint *b; |
| 9771 | |
| 9772 | if (is_tracepoint_type (type_wanted)) |
| 9773 | { |
| 9774 | struct tracepoint *t; |
| 9775 | |
| 9776 | t = XCNEW (struct tracepoint); |
| 9777 | b = &t->base; |
| 9778 | } |
| 9779 | else |
| 9780 | b = XNEW (struct breakpoint); |
| 9781 | |
| 9782 | init_raw_breakpoint_without_location (b, gdbarch, type_wanted, ops); |
| 9783 | b->location = copy_event_location (location); |
| 9784 | |
| 9785 | if (parse_extra) |
| 9786 | b->cond_string = NULL; |
| 9787 | else |
| 9788 | { |
| 9789 | /* Create a private copy of condition string. */ |
| 9790 | if (cond_string) |
| 9791 | { |
| 9792 | cond_string = xstrdup (cond_string); |
| 9793 | make_cleanup (xfree, cond_string); |
| 9794 | } |
| 9795 | b->cond_string = cond_string; |
| 9796 | b->thread = thread; |
| 9797 | } |
| 9798 | |
| 9799 | /* Create a private copy of any extra string. */ |
| 9800 | if (extra_string != NULL) |
| 9801 | { |
| 9802 | extra_string = xstrdup (extra_string); |
| 9803 | make_cleanup (xfree, extra_string); |
| 9804 | } |
| 9805 | b->extra_string = extra_string; |
| 9806 | b->ignore_count = ignore_count; |
| 9807 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 9808 | b->condition_not_parsed = 1; |
| 9809 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 9810 | if ((type_wanted != bp_breakpoint |
| 9811 | && type_wanted != bp_hardware_breakpoint) || thread != -1) |
| 9812 | b->pspace = current_program_space; |
| 9813 | |
| 9814 | install_breakpoint (internal, b, 0); |
| 9815 | } |
| 9816 | |
| 9817 | if (VEC_length (linespec_sals, canonical.sals) > 1) |
| 9818 | { |
| 9819 | warning (_("Multiple breakpoints were set.\nUse the " |
| 9820 | "\"delete\" command to delete unwanted breakpoints.")); |
| 9821 | prev_breakpoint_count = prev_bkpt_count; |
| 9822 | } |
| 9823 | |
| 9824 | /* That's it. Discard the cleanups for data inserted into the |
| 9825 | breakpoint. */ |
| 9826 | discard_cleanups (bkpt_chain); |
| 9827 | /* But cleanup everything else. */ |
| 9828 | do_cleanups (old_chain); |
| 9829 | |
| 9830 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
| 9831 | update_global_location_list (UGLL_MAY_INSERT); |
| 9832 | |
| 9833 | return 1; |
| 9834 | } |
| 9835 | |
| 9836 | /* Set a breakpoint. |
| 9837 | ARG is a string describing breakpoint address, |
| 9838 | condition, and thread. |
| 9839 | FLAG specifies if a breakpoint is hardware on, |
| 9840 | and if breakpoint is temporary, using BP_HARDWARE_FLAG |
| 9841 | and BP_TEMPFLAG. */ |
| 9842 | |
| 9843 | static void |
| 9844 | break_command_1 (char *arg, int flag, int from_tty) |
| 9845 | { |
| 9846 | int tempflag = flag & BP_TEMPFLAG; |
| 9847 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
| 9848 | ? bp_hardware_breakpoint |
| 9849 | : bp_breakpoint); |
| 9850 | struct breakpoint_ops *ops; |
| 9851 | struct event_location *location; |
| 9852 | struct cleanup *cleanup; |
| 9853 | |
| 9854 | location = string_to_event_location (&arg, current_language); |
| 9855 | cleanup = make_cleanup_delete_event_location (location); |
| 9856 | |
| 9857 | /* Matching breakpoints on probes. */ |
| 9858 | if (location != NULL |
| 9859 | && event_location_type (location) == PROBE_LOCATION) |
| 9860 | ops = &bkpt_probe_breakpoint_ops; |
| 9861 | else |
| 9862 | ops = &bkpt_breakpoint_ops; |
| 9863 | |
| 9864 | create_breakpoint (get_current_arch (), |
| 9865 | location, |
| 9866 | NULL, 0, arg, 1 /* parse arg */, |
| 9867 | tempflag, type_wanted, |
| 9868 | 0 /* Ignore count */, |
| 9869 | pending_break_support, |
| 9870 | ops, |
| 9871 | from_tty, |
| 9872 | 1 /* enabled */, |
| 9873 | 0 /* internal */, |
| 9874 | 0); |
| 9875 | do_cleanups (cleanup); |
| 9876 | } |
| 9877 | |
| 9878 | /* Helper function for break_command_1 and disassemble_command. */ |
| 9879 | |
| 9880 | void |
| 9881 | resolve_sal_pc (struct symtab_and_line *sal) |
| 9882 | { |
| 9883 | CORE_ADDR pc; |
| 9884 | |
| 9885 | if (sal->pc == 0 && sal->symtab != NULL) |
| 9886 | { |
| 9887 | if (!find_line_pc (sal->symtab, sal->line, &pc)) |
| 9888 | error (_("No line %d in file \"%s\"."), |
| 9889 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
| 9890 | sal->pc = pc; |
| 9891 | |
| 9892 | /* If this SAL corresponds to a breakpoint inserted using a line |
| 9893 | number, then skip the function prologue if necessary. */ |
| 9894 | if (sal->explicit_line) |
| 9895 | skip_prologue_sal (sal); |
| 9896 | } |
| 9897 | |
| 9898 | if (sal->section == 0 && sal->symtab != NULL) |
| 9899 | { |
| 9900 | const struct blockvector *bv; |
| 9901 | const struct block *b; |
| 9902 | struct symbol *sym; |
| 9903 | |
| 9904 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
| 9905 | SYMTAB_COMPUNIT (sal->symtab)); |
| 9906 | if (bv != NULL) |
| 9907 | { |
| 9908 | sym = block_linkage_function (b); |
| 9909 | if (sym != NULL) |
| 9910 | { |
| 9911 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
| 9912 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), |
| 9913 | sym); |
| 9914 | } |
| 9915 | else |
| 9916 | { |
| 9917 | /* It really is worthwhile to have the section, so we'll |
| 9918 | just have to look harder. This case can be executed |
| 9919 | if we have line numbers but no functions (as can |
| 9920 | happen in assembly source). */ |
| 9921 | |
| 9922 | struct bound_minimal_symbol msym; |
| 9923 | struct cleanup *old_chain = save_current_space_and_thread (); |
| 9924 | |
| 9925 | switch_to_program_space_and_thread (sal->pspace); |
| 9926 | |
| 9927 | msym = lookup_minimal_symbol_by_pc (sal->pc); |
| 9928 | if (msym.minsym) |
| 9929 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
| 9930 | |
| 9931 | do_cleanups (old_chain); |
| 9932 | } |
| 9933 | } |
| 9934 | } |
| 9935 | } |
| 9936 | |
| 9937 | void |
| 9938 | break_command (char *arg, int from_tty) |
| 9939 | { |
| 9940 | break_command_1 (arg, 0, from_tty); |
| 9941 | } |
| 9942 | |
| 9943 | void |
| 9944 | tbreak_command (char *arg, int from_tty) |
| 9945 | { |
| 9946 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
| 9947 | } |
| 9948 | |
| 9949 | static void |
| 9950 | hbreak_command (char *arg, int from_tty) |
| 9951 | { |
| 9952 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
| 9953 | } |
| 9954 | |
| 9955 | static void |
| 9956 | thbreak_command (char *arg, int from_tty) |
| 9957 | { |
| 9958 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
| 9959 | } |
| 9960 | |
| 9961 | static void |
| 9962 | stop_command (char *arg, int from_tty) |
| 9963 | { |
| 9964 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
| 9965 | Usage: stop in <function | address>\n\ |
| 9966 | stop at <line>\n")); |
| 9967 | } |
| 9968 | |
| 9969 | static void |
| 9970 | stopin_command (char *arg, int from_tty) |
| 9971 | { |
| 9972 | int badInput = 0; |
| 9973 | |
| 9974 | if (arg == (char *) NULL) |
| 9975 | badInput = 1; |
| 9976 | else if (*arg != '*') |
| 9977 | { |
| 9978 | char *argptr = arg; |
| 9979 | int hasColon = 0; |
| 9980 | |
| 9981 | /* Look for a ':'. If this is a line number specification, then |
| 9982 | say it is bad, otherwise, it should be an address or |
| 9983 | function/method name. */ |
| 9984 | while (*argptr && !hasColon) |
| 9985 | { |
| 9986 | hasColon = (*argptr == ':'); |
| 9987 | argptr++; |
| 9988 | } |
| 9989 | |
| 9990 | if (hasColon) |
| 9991 | badInput = (*argptr != ':'); /* Not a class::method */ |
| 9992 | else |
| 9993 | badInput = isdigit (*arg); /* a simple line number */ |
| 9994 | } |
| 9995 | |
| 9996 | if (badInput) |
| 9997 | printf_filtered (_("Usage: stop in <function | address>\n")); |
| 9998 | else |
| 9999 | break_command_1 (arg, 0, from_tty); |
| 10000 | } |
| 10001 | |
| 10002 | static void |
| 10003 | stopat_command (char *arg, int from_tty) |
| 10004 | { |
| 10005 | int badInput = 0; |
| 10006 | |
| 10007 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
| 10008 | badInput = 1; |
| 10009 | else |
| 10010 | { |
| 10011 | char *argptr = arg; |
| 10012 | int hasColon = 0; |
| 10013 | |
| 10014 | /* Look for a ':'. If there is a '::' then get out, otherwise |
| 10015 | it is probably a line number. */ |
| 10016 | while (*argptr && !hasColon) |
| 10017 | { |
| 10018 | hasColon = (*argptr == ':'); |
| 10019 | argptr++; |
| 10020 | } |
| 10021 | |
| 10022 | if (hasColon) |
| 10023 | badInput = (*argptr == ':'); /* we have class::method */ |
| 10024 | else |
| 10025 | badInput = !isdigit (*arg); /* not a line number */ |
| 10026 | } |
| 10027 | |
| 10028 | if (badInput) |
| 10029 | printf_filtered (_("Usage: stop at <line>\n")); |
| 10030 | else |
| 10031 | break_command_1 (arg, 0, from_tty); |
| 10032 | } |
| 10033 | |
| 10034 | /* The dynamic printf command is mostly like a regular breakpoint, but |
| 10035 | with a prewired command list consisting of a single output command, |
| 10036 | built from extra arguments supplied on the dprintf command |
| 10037 | line. */ |
| 10038 | |
| 10039 | static void |
| 10040 | dprintf_command (char *arg, int from_tty) |
| 10041 | { |
| 10042 | struct event_location *location; |
| 10043 | struct cleanup *cleanup; |
| 10044 | |
| 10045 | location = string_to_event_location (&arg, current_language); |
| 10046 | cleanup = make_cleanup_delete_event_location (location); |
| 10047 | |
| 10048 | /* If non-NULL, ARG should have been advanced past the location; |
| 10049 | the next character must be ','. */ |
| 10050 | if (arg != NULL) |
| 10051 | { |
| 10052 | if (arg[0] != ',' || arg[1] == '\0') |
| 10053 | error (_("Format string required")); |
| 10054 | else |
| 10055 | { |
| 10056 | /* Skip the comma. */ |
| 10057 | ++arg; |
| 10058 | } |
| 10059 | } |
| 10060 | |
| 10061 | create_breakpoint (get_current_arch (), |
| 10062 | location, |
| 10063 | NULL, 0, arg, 1 /* parse arg */, |
| 10064 | 0, bp_dprintf, |
| 10065 | 0 /* Ignore count */, |
| 10066 | pending_break_support, |
| 10067 | &dprintf_breakpoint_ops, |
| 10068 | from_tty, |
| 10069 | 1 /* enabled */, |
| 10070 | 0 /* internal */, |
| 10071 | 0); |
| 10072 | do_cleanups (cleanup); |
| 10073 | } |
| 10074 | |
| 10075 | static void |
| 10076 | agent_printf_command (char *arg, int from_tty) |
| 10077 | { |
| 10078 | error (_("May only run agent-printf on the target")); |
| 10079 | } |
| 10080 | |
| 10081 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
| 10082 | ranged breakpoints. */ |
| 10083 | |
| 10084 | static int |
| 10085 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, |
| 10086 | struct address_space *aspace, |
| 10087 | CORE_ADDR bp_addr, |
| 10088 | const struct target_waitstatus *ws) |
| 10089 | { |
| 10090 | if (ws->kind != TARGET_WAITKIND_STOPPED |
| 10091 | || ws->value.sig != GDB_SIGNAL_TRAP) |
| 10092 | return 0; |
| 10093 | |
| 10094 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
| 10095 | bl->length, aspace, bp_addr); |
| 10096 | } |
| 10097 | |
| 10098 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10099 | ranged breakpoints. */ |
| 10100 | |
| 10101 | static int |
| 10102 | resources_needed_ranged_breakpoint (const struct bp_location *bl) |
| 10103 | { |
| 10104 | return target_ranged_break_num_registers (); |
| 10105 | } |
| 10106 | |
| 10107 | /* Implement the "print_it" breakpoint_ops method for |
| 10108 | ranged breakpoints. */ |
| 10109 | |
| 10110 | static enum print_stop_action |
| 10111 | print_it_ranged_breakpoint (bpstat bs) |
| 10112 | { |
| 10113 | struct breakpoint *b = bs->breakpoint_at; |
| 10114 | struct bp_location *bl = b->loc; |
| 10115 | struct ui_out *uiout = current_uiout; |
| 10116 | |
| 10117 | gdb_assert (b->type == bp_hardware_breakpoint); |
| 10118 | |
| 10119 | /* Ranged breakpoints have only one location. */ |
| 10120 | gdb_assert (bl && bl->next == NULL); |
| 10121 | |
| 10122 | annotate_breakpoint (b->number); |
| 10123 | if (b->disposition == disp_del) |
| 10124 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); |
| 10125 | else |
| 10126 | ui_out_text (uiout, "\nRanged breakpoint "); |
| 10127 | if (ui_out_is_mi_like_p (uiout)) |
| 10128 | { |
| 10129 | ui_out_field_string (uiout, "reason", |
| 10130 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 10131 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 10132 | } |
| 10133 | ui_out_field_int (uiout, "bkptno", b->number); |
| 10134 | ui_out_text (uiout, ", "); |
| 10135 | |
| 10136 | return PRINT_SRC_AND_LOC; |
| 10137 | } |
| 10138 | |
| 10139 | /* Implement the "print_one" breakpoint_ops method for |
| 10140 | ranged breakpoints. */ |
| 10141 | |
| 10142 | static void |
| 10143 | print_one_ranged_breakpoint (struct breakpoint *b, |
| 10144 | struct bp_location **last_loc) |
| 10145 | { |
| 10146 | struct bp_location *bl = b->loc; |
| 10147 | struct value_print_options opts; |
| 10148 | struct ui_out *uiout = current_uiout; |
| 10149 | |
| 10150 | /* Ranged breakpoints have only one location. */ |
| 10151 | gdb_assert (bl && bl->next == NULL); |
| 10152 | |
| 10153 | get_user_print_options (&opts); |
| 10154 | |
| 10155 | if (opts.addressprint) |
| 10156 | /* We don't print the address range here, it will be printed later |
| 10157 | by print_one_detail_ranged_breakpoint. */ |
| 10158 | ui_out_field_skip (uiout, "addr"); |
| 10159 | annotate_field (5); |
| 10160 | print_breakpoint_location (b, bl); |
| 10161 | *last_loc = bl; |
| 10162 | } |
| 10163 | |
| 10164 | /* Implement the "print_one_detail" breakpoint_ops method for |
| 10165 | ranged breakpoints. */ |
| 10166 | |
| 10167 | static void |
| 10168 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, |
| 10169 | struct ui_out *uiout) |
| 10170 | { |
| 10171 | CORE_ADDR address_start, address_end; |
| 10172 | struct bp_location *bl = b->loc; |
| 10173 | struct ui_file *stb = mem_fileopen (); |
| 10174 | struct cleanup *cleanup = make_cleanup_ui_file_delete (stb); |
| 10175 | |
| 10176 | gdb_assert (bl); |
| 10177 | |
| 10178 | address_start = bl->address; |
| 10179 | address_end = address_start + bl->length - 1; |
| 10180 | |
| 10181 | ui_out_text (uiout, "\taddress range: "); |
| 10182 | fprintf_unfiltered (stb, "[%s, %s]", |
| 10183 | print_core_address (bl->gdbarch, address_start), |
| 10184 | print_core_address (bl->gdbarch, address_end)); |
| 10185 | ui_out_field_stream (uiout, "addr", stb); |
| 10186 | ui_out_text (uiout, "\n"); |
| 10187 | |
| 10188 | do_cleanups (cleanup); |
| 10189 | } |
| 10190 | |
| 10191 | /* Implement the "print_mention" breakpoint_ops method for |
| 10192 | ranged breakpoints. */ |
| 10193 | |
| 10194 | static void |
| 10195 | print_mention_ranged_breakpoint (struct breakpoint *b) |
| 10196 | { |
| 10197 | struct bp_location *bl = b->loc; |
| 10198 | struct ui_out *uiout = current_uiout; |
| 10199 | |
| 10200 | gdb_assert (bl); |
| 10201 | gdb_assert (b->type == bp_hardware_breakpoint); |
| 10202 | |
| 10203 | if (ui_out_is_mi_like_p (uiout)) |
| 10204 | return; |
| 10205 | |
| 10206 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
| 10207 | b->number, paddress (bl->gdbarch, bl->address), |
| 10208 | paddress (bl->gdbarch, bl->address + bl->length - 1)); |
| 10209 | } |
| 10210 | |
| 10211 | /* Implement the "print_recreate" breakpoint_ops method for |
| 10212 | ranged breakpoints. */ |
| 10213 | |
| 10214 | static void |
| 10215 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) |
| 10216 | { |
| 10217 | fprintf_unfiltered (fp, "break-range %s, %s", |
| 10218 | event_location_to_string (b->location), |
| 10219 | event_location_to_string (b->location_range_end)); |
| 10220 | print_recreate_thread (b, fp); |
| 10221 | } |
| 10222 | |
| 10223 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ |
| 10224 | |
| 10225 | static struct breakpoint_ops ranged_breakpoint_ops; |
| 10226 | |
| 10227 | /* Find the address where the end of the breakpoint range should be |
| 10228 | placed, given the SAL of the end of the range. This is so that if |
| 10229 | the user provides a line number, the end of the range is set to the |
| 10230 | last instruction of the given line. */ |
| 10231 | |
| 10232 | static CORE_ADDR |
| 10233 | find_breakpoint_range_end (struct symtab_and_line sal) |
| 10234 | { |
| 10235 | CORE_ADDR end; |
| 10236 | |
| 10237 | /* If the user provided a PC value, use it. Otherwise, |
| 10238 | find the address of the end of the given location. */ |
| 10239 | if (sal.explicit_pc) |
| 10240 | end = sal.pc; |
| 10241 | else |
| 10242 | { |
| 10243 | int ret; |
| 10244 | CORE_ADDR start; |
| 10245 | |
| 10246 | ret = find_line_pc_range (sal, &start, &end); |
| 10247 | if (!ret) |
| 10248 | error (_("Could not find location of the end of the range.")); |
| 10249 | |
| 10250 | /* find_line_pc_range returns the start of the next line. */ |
| 10251 | end--; |
| 10252 | } |
| 10253 | |
| 10254 | return end; |
| 10255 | } |
| 10256 | |
| 10257 | /* Implement the "break-range" CLI command. */ |
| 10258 | |
| 10259 | static void |
| 10260 | break_range_command (char *arg, int from_tty) |
| 10261 | { |
| 10262 | char *arg_start, *addr_string_start, *addr_string_end; |
| 10263 | struct linespec_result canonical_start, canonical_end; |
| 10264 | int bp_count, can_use_bp, length; |
| 10265 | CORE_ADDR end; |
| 10266 | struct breakpoint *b; |
| 10267 | struct symtab_and_line sal_start, sal_end; |
| 10268 | struct cleanup *cleanup_bkpt; |
| 10269 | struct linespec_sals *lsal_start, *lsal_end; |
| 10270 | struct event_location *start_location, *end_location; |
| 10271 | |
| 10272 | /* We don't support software ranged breakpoints. */ |
| 10273 | if (target_ranged_break_num_registers () < 0) |
| 10274 | error (_("This target does not support hardware ranged breakpoints.")); |
| 10275 | |
| 10276 | bp_count = hw_breakpoint_used_count (); |
| 10277 | bp_count += target_ranged_break_num_registers (); |
| 10278 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 10279 | bp_count, 0); |
| 10280 | if (can_use_bp < 0) |
| 10281 | error (_("Hardware breakpoints used exceeds limit.")); |
| 10282 | |
| 10283 | arg = skip_spaces (arg); |
| 10284 | if (arg == NULL || arg[0] == '\0') |
| 10285 | error(_("No address range specified.")); |
| 10286 | |
| 10287 | init_linespec_result (&canonical_start); |
| 10288 | |
| 10289 | arg_start = arg; |
| 10290 | start_location = string_to_event_location (&arg, current_language); |
| 10291 | cleanup_bkpt = make_cleanup_delete_event_location (start_location); |
| 10292 | parse_breakpoint_sals (start_location, &canonical_start); |
| 10293 | make_cleanup_destroy_linespec_result (&canonical_start); |
| 10294 | |
| 10295 | if (arg[0] != ',') |
| 10296 | error (_("Too few arguments.")); |
| 10297 | else if (VEC_empty (linespec_sals, canonical_start.sals)) |
| 10298 | error (_("Could not find location of the beginning of the range.")); |
| 10299 | |
| 10300 | lsal_start = VEC_index (linespec_sals, canonical_start.sals, 0); |
| 10301 | |
| 10302 | if (VEC_length (linespec_sals, canonical_start.sals) > 1 |
| 10303 | || lsal_start->sals.nelts != 1) |
| 10304 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
| 10305 | |
| 10306 | sal_start = lsal_start->sals.sals[0]; |
| 10307 | addr_string_start = savestring (arg_start, arg - arg_start); |
| 10308 | make_cleanup (xfree, addr_string_start); |
| 10309 | |
| 10310 | arg++; /* Skip the comma. */ |
| 10311 | arg = skip_spaces (arg); |
| 10312 | |
| 10313 | /* Parse the end location. */ |
| 10314 | |
| 10315 | init_linespec_result (&canonical_end); |
| 10316 | arg_start = arg; |
| 10317 | |
| 10318 | /* We call decode_line_full directly here instead of using |
| 10319 | parse_breakpoint_sals because we need to specify the start location's |
| 10320 | symtab and line as the default symtab and line for the end of the |
| 10321 | range. This makes it possible to have ranges like "foo.c:27, +14", |
| 10322 | where +14 means 14 lines from the start location. */ |
| 10323 | end_location = string_to_event_location (&arg, current_language); |
| 10324 | make_cleanup_delete_event_location (end_location); |
| 10325 | decode_line_full (end_location, DECODE_LINE_FUNFIRSTLINE, |
| 10326 | sal_start.symtab, sal_start.line, |
| 10327 | &canonical_end, NULL, NULL); |
| 10328 | |
| 10329 | make_cleanup_destroy_linespec_result (&canonical_end); |
| 10330 | |
| 10331 | if (VEC_empty (linespec_sals, canonical_end.sals)) |
| 10332 | error (_("Could not find location of the end of the range.")); |
| 10333 | |
| 10334 | lsal_end = VEC_index (linespec_sals, canonical_end.sals, 0); |
| 10335 | if (VEC_length (linespec_sals, canonical_end.sals) > 1 |
| 10336 | || lsal_end->sals.nelts != 1) |
| 10337 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
| 10338 | |
| 10339 | sal_end = lsal_end->sals.sals[0]; |
| 10340 | |
| 10341 | end = find_breakpoint_range_end (sal_end); |
| 10342 | if (sal_start.pc > end) |
| 10343 | error (_("Invalid address range, end precedes start.")); |
| 10344 | |
| 10345 | length = end - sal_start.pc + 1; |
| 10346 | if (length < 0) |
| 10347 | /* Length overflowed. */ |
| 10348 | error (_("Address range too large.")); |
| 10349 | else if (length == 1) |
| 10350 | { |
| 10351 | /* This range is simple enough to be handled by |
| 10352 | the `hbreak' command. */ |
| 10353 | hbreak_command (addr_string_start, 1); |
| 10354 | |
| 10355 | do_cleanups (cleanup_bkpt); |
| 10356 | |
| 10357 | return; |
| 10358 | } |
| 10359 | |
| 10360 | /* Now set up the breakpoint. */ |
| 10361 | b = set_raw_breakpoint (get_current_arch (), sal_start, |
| 10362 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
| 10363 | set_breakpoint_count (breakpoint_count + 1); |
| 10364 | b->number = breakpoint_count; |
| 10365 | b->disposition = disp_donttouch; |
| 10366 | b->location = copy_event_location (start_location); |
| 10367 | b->location_range_end = copy_event_location (end_location); |
| 10368 | b->loc->length = length; |
| 10369 | |
| 10370 | do_cleanups (cleanup_bkpt); |
| 10371 | |
| 10372 | mention (b); |
| 10373 | observer_notify_breakpoint_created (b); |
| 10374 | update_global_location_list (UGLL_MAY_INSERT); |
| 10375 | } |
| 10376 | |
| 10377 | /* Return non-zero if EXP is verified as constant. Returned zero |
| 10378 | means EXP is variable. Also the constant detection may fail for |
| 10379 | some constant expressions and in such case still falsely return |
| 10380 | zero. */ |
| 10381 | |
| 10382 | static int |
| 10383 | watchpoint_exp_is_const (const struct expression *exp) |
| 10384 | { |
| 10385 | int i = exp->nelts; |
| 10386 | |
| 10387 | while (i > 0) |
| 10388 | { |
| 10389 | int oplenp, argsp; |
| 10390 | |
| 10391 | /* We are only interested in the descriptor of each element. */ |
| 10392 | operator_length (exp, i, &oplenp, &argsp); |
| 10393 | i -= oplenp; |
| 10394 | |
| 10395 | switch (exp->elts[i].opcode) |
| 10396 | { |
| 10397 | case BINOP_ADD: |
| 10398 | case BINOP_SUB: |
| 10399 | case BINOP_MUL: |
| 10400 | case BINOP_DIV: |
| 10401 | case BINOP_REM: |
| 10402 | case BINOP_MOD: |
| 10403 | case BINOP_LSH: |
| 10404 | case BINOP_RSH: |
| 10405 | case BINOP_LOGICAL_AND: |
| 10406 | case BINOP_LOGICAL_OR: |
| 10407 | case BINOP_BITWISE_AND: |
| 10408 | case BINOP_BITWISE_IOR: |
| 10409 | case BINOP_BITWISE_XOR: |
| 10410 | case BINOP_EQUAL: |
| 10411 | case BINOP_NOTEQUAL: |
| 10412 | case BINOP_LESS: |
| 10413 | case BINOP_GTR: |
| 10414 | case BINOP_LEQ: |
| 10415 | case BINOP_GEQ: |
| 10416 | case BINOP_REPEAT: |
| 10417 | case BINOP_COMMA: |
| 10418 | case BINOP_EXP: |
| 10419 | case BINOP_MIN: |
| 10420 | case BINOP_MAX: |
| 10421 | case BINOP_INTDIV: |
| 10422 | case BINOP_CONCAT: |
| 10423 | case TERNOP_COND: |
| 10424 | case TERNOP_SLICE: |
| 10425 | |
| 10426 | case OP_LONG: |
| 10427 | case OP_DOUBLE: |
| 10428 | case OP_DECFLOAT: |
| 10429 | case OP_LAST: |
| 10430 | case OP_COMPLEX: |
| 10431 | case OP_STRING: |
| 10432 | case OP_ARRAY: |
| 10433 | case OP_TYPE: |
| 10434 | case OP_TYPEOF: |
| 10435 | case OP_DECLTYPE: |
| 10436 | case OP_TYPEID: |
| 10437 | case OP_NAME: |
| 10438 | case OP_OBJC_NSSTRING: |
| 10439 | |
| 10440 | case UNOP_NEG: |
| 10441 | case UNOP_LOGICAL_NOT: |
| 10442 | case UNOP_COMPLEMENT: |
| 10443 | case UNOP_ADDR: |
| 10444 | case UNOP_HIGH: |
| 10445 | case UNOP_CAST: |
| 10446 | |
| 10447 | case UNOP_CAST_TYPE: |
| 10448 | case UNOP_REINTERPRET_CAST: |
| 10449 | case UNOP_DYNAMIC_CAST: |
| 10450 | /* Unary, binary and ternary operators: We have to check |
| 10451 | their operands. If they are constant, then so is the |
| 10452 | result of that operation. For instance, if A and B are |
| 10453 | determined to be constants, then so is "A + B". |
| 10454 | |
| 10455 | UNOP_IND is one exception to the rule above, because the |
| 10456 | value of *ADDR is not necessarily a constant, even when |
| 10457 | ADDR is. */ |
| 10458 | break; |
| 10459 | |
| 10460 | case OP_VAR_VALUE: |
| 10461 | /* Check whether the associated symbol is a constant. |
| 10462 | |
| 10463 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
| 10464 | possible that a buggy compiler could mark a variable as |
| 10465 | constant even when it is not, and TYPE_CONST would return |
| 10466 | true in this case, while SYMBOL_CLASS wouldn't. |
| 10467 | |
| 10468 | We also have to check for function symbols because they |
| 10469 | are always constant. */ |
| 10470 | { |
| 10471 | struct symbol *s = exp->elts[i + 2].symbol; |
| 10472 | |
| 10473 | if (SYMBOL_CLASS (s) != LOC_BLOCK |
| 10474 | && SYMBOL_CLASS (s) != LOC_CONST |
| 10475 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) |
| 10476 | return 0; |
| 10477 | break; |
| 10478 | } |
| 10479 | |
| 10480 | /* The default action is to return 0 because we are using |
| 10481 | the optimistic approach here: If we don't know something, |
| 10482 | then it is not a constant. */ |
| 10483 | default: |
| 10484 | return 0; |
| 10485 | } |
| 10486 | } |
| 10487 | |
| 10488 | return 1; |
| 10489 | } |
| 10490 | |
| 10491 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
| 10492 | |
| 10493 | static void |
| 10494 | dtor_watchpoint (struct breakpoint *self) |
| 10495 | { |
| 10496 | struct watchpoint *w = (struct watchpoint *) self; |
| 10497 | |
| 10498 | xfree (w->cond_exp); |
| 10499 | xfree (w->exp); |
| 10500 | xfree (w->exp_string); |
| 10501 | xfree (w->exp_string_reparse); |
| 10502 | value_free (w->val); |
| 10503 | |
| 10504 | base_breakpoint_ops.dtor (self); |
| 10505 | } |
| 10506 | |
| 10507 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
| 10508 | |
| 10509 | static void |
| 10510 | re_set_watchpoint (struct breakpoint *b) |
| 10511 | { |
| 10512 | struct watchpoint *w = (struct watchpoint *) b; |
| 10513 | |
| 10514 | /* Watchpoint can be either on expression using entirely global |
| 10515 | variables, or it can be on local variables. |
| 10516 | |
| 10517 | Watchpoints of the first kind are never auto-deleted, and even |
| 10518 | persist across program restarts. Since they can use variables |
| 10519 | from shared libraries, we need to reparse expression as libraries |
| 10520 | are loaded and unloaded. |
| 10521 | |
| 10522 | Watchpoints on local variables can also change meaning as result |
| 10523 | of solib event. For example, if a watchpoint uses both a local |
| 10524 | and a global variables in expression, it's a local watchpoint, |
| 10525 | but unloading of a shared library will make the expression |
| 10526 | invalid. This is not a very common use case, but we still |
| 10527 | re-evaluate expression, to avoid surprises to the user. |
| 10528 | |
| 10529 | Note that for local watchpoints, we re-evaluate it only if |
| 10530 | watchpoints frame id is still valid. If it's not, it means the |
| 10531 | watchpoint is out of scope and will be deleted soon. In fact, |
| 10532 | I'm not sure we'll ever be called in this case. |
| 10533 | |
| 10534 | If a local watchpoint's frame id is still valid, then |
| 10535 | w->exp_valid_block is likewise valid, and we can safely use it. |
| 10536 | |
| 10537 | Don't do anything about disabled watchpoints, since they will be |
| 10538 | reevaluated again when enabled. */ |
| 10539 | update_watchpoint (w, 1 /* reparse */); |
| 10540 | } |
| 10541 | |
| 10542 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
| 10543 | |
| 10544 | static int |
| 10545 | insert_watchpoint (struct bp_location *bl) |
| 10546 | { |
| 10547 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10548 | int length = w->exact ? 1 : bl->length; |
| 10549 | |
| 10550 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, |
| 10551 | w->cond_exp); |
| 10552 | } |
| 10553 | |
| 10554 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ |
| 10555 | |
| 10556 | static int |
| 10557 | remove_watchpoint (struct bp_location *bl) |
| 10558 | { |
| 10559 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10560 | int length = w->exact ? 1 : bl->length; |
| 10561 | |
| 10562 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, |
| 10563 | w->cond_exp); |
| 10564 | } |
| 10565 | |
| 10566 | static int |
| 10567 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
| 10568 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 10569 | const struct target_waitstatus *ws) |
| 10570 | { |
| 10571 | struct breakpoint *b = bl->owner; |
| 10572 | struct watchpoint *w = (struct watchpoint *) b; |
| 10573 | |
| 10574 | /* Continuable hardware watchpoints are treated as non-existent if the |
| 10575 | reason we stopped wasn't a hardware watchpoint (we didn't stop on |
| 10576 | some data address). Otherwise gdb won't stop on a break instruction |
| 10577 | in the code (not from a breakpoint) when a hardware watchpoint has |
| 10578 | been defined. Also skip watchpoints which we know did not trigger |
| 10579 | (did not match the data address). */ |
| 10580 | if (is_hardware_watchpoint (b) |
| 10581 | && w->watchpoint_triggered == watch_triggered_no) |
| 10582 | return 0; |
| 10583 | |
| 10584 | return 1; |
| 10585 | } |
| 10586 | |
| 10587 | static void |
| 10588 | check_status_watchpoint (bpstat bs) |
| 10589 | { |
| 10590 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
| 10591 | |
| 10592 | bpstat_check_watchpoint (bs); |
| 10593 | } |
| 10594 | |
| 10595 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10596 | hardware watchpoints. */ |
| 10597 | |
| 10598 | static int |
| 10599 | resources_needed_watchpoint (const struct bp_location *bl) |
| 10600 | { |
| 10601 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10602 | int length = w->exact? 1 : bl->length; |
| 10603 | |
| 10604 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
| 10605 | } |
| 10606 | |
| 10607 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
| 10608 | hardware watchpoints. */ |
| 10609 | |
| 10610 | static int |
| 10611 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
| 10612 | { |
| 10613 | /* Read and access watchpoints only work with hardware support. */ |
| 10614 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; |
| 10615 | } |
| 10616 | |
| 10617 | static enum print_stop_action |
| 10618 | print_it_watchpoint (bpstat bs) |
| 10619 | { |
| 10620 | struct cleanup *old_chain; |
| 10621 | struct breakpoint *b; |
| 10622 | struct ui_file *stb; |
| 10623 | enum print_stop_action result; |
| 10624 | struct watchpoint *w; |
| 10625 | struct ui_out *uiout = current_uiout; |
| 10626 | |
| 10627 | gdb_assert (bs->bp_location_at != NULL); |
| 10628 | |
| 10629 | b = bs->breakpoint_at; |
| 10630 | w = (struct watchpoint *) b; |
| 10631 | |
| 10632 | stb = mem_fileopen (); |
| 10633 | old_chain = make_cleanup_ui_file_delete (stb); |
| 10634 | |
| 10635 | switch (b->type) |
| 10636 | { |
| 10637 | case bp_watchpoint: |
| 10638 | case bp_hardware_watchpoint: |
| 10639 | annotate_watchpoint (b->number); |
| 10640 | if (ui_out_is_mi_like_p (uiout)) |
| 10641 | ui_out_field_string |
| 10642 | (uiout, "reason", |
| 10643 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 10644 | mention (b); |
| 10645 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 10646 | ui_out_text (uiout, "\nOld value = "); |
| 10647 | watchpoint_value_print (bs->old_val, stb); |
| 10648 | ui_out_field_stream (uiout, "old", stb); |
| 10649 | ui_out_text (uiout, "\nNew value = "); |
| 10650 | watchpoint_value_print (w->val, stb); |
| 10651 | ui_out_field_stream (uiout, "new", stb); |
| 10652 | ui_out_text (uiout, "\n"); |
| 10653 | /* More than one watchpoint may have been triggered. */ |
| 10654 | result = PRINT_UNKNOWN; |
| 10655 | break; |
| 10656 | |
| 10657 | case bp_read_watchpoint: |
| 10658 | if (ui_out_is_mi_like_p (uiout)) |
| 10659 | ui_out_field_string |
| 10660 | (uiout, "reason", |
| 10661 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 10662 | mention (b); |
| 10663 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 10664 | ui_out_text (uiout, "\nValue = "); |
| 10665 | watchpoint_value_print (w->val, stb); |
| 10666 | ui_out_field_stream (uiout, "value", stb); |
| 10667 | ui_out_text (uiout, "\n"); |
| 10668 | result = PRINT_UNKNOWN; |
| 10669 | break; |
| 10670 | |
| 10671 | case bp_access_watchpoint: |
| 10672 | if (bs->old_val != NULL) |
| 10673 | { |
| 10674 | annotate_watchpoint (b->number); |
| 10675 | if (ui_out_is_mi_like_p (uiout)) |
| 10676 | ui_out_field_string |
| 10677 | (uiout, "reason", |
| 10678 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10679 | mention (b); |
| 10680 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 10681 | ui_out_text (uiout, "\nOld value = "); |
| 10682 | watchpoint_value_print (bs->old_val, stb); |
| 10683 | ui_out_field_stream (uiout, "old", stb); |
| 10684 | ui_out_text (uiout, "\nNew value = "); |
| 10685 | } |
| 10686 | else |
| 10687 | { |
| 10688 | mention (b); |
| 10689 | if (ui_out_is_mi_like_p (uiout)) |
| 10690 | ui_out_field_string |
| 10691 | (uiout, "reason", |
| 10692 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10693 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
| 10694 | ui_out_text (uiout, "\nValue = "); |
| 10695 | } |
| 10696 | watchpoint_value_print (w->val, stb); |
| 10697 | ui_out_field_stream (uiout, "new", stb); |
| 10698 | ui_out_text (uiout, "\n"); |
| 10699 | result = PRINT_UNKNOWN; |
| 10700 | break; |
| 10701 | default: |
| 10702 | result = PRINT_UNKNOWN; |
| 10703 | } |
| 10704 | |
| 10705 | do_cleanups (old_chain); |
| 10706 | return result; |
| 10707 | } |
| 10708 | |
| 10709 | /* Implement the "print_mention" breakpoint_ops method for hardware |
| 10710 | watchpoints. */ |
| 10711 | |
| 10712 | static void |
| 10713 | print_mention_watchpoint (struct breakpoint *b) |
| 10714 | { |
| 10715 | struct cleanup *ui_out_chain; |
| 10716 | struct watchpoint *w = (struct watchpoint *) b; |
| 10717 | struct ui_out *uiout = current_uiout; |
| 10718 | |
| 10719 | switch (b->type) |
| 10720 | { |
| 10721 | case bp_watchpoint: |
| 10722 | ui_out_text (uiout, "Watchpoint "); |
| 10723 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 10724 | break; |
| 10725 | case bp_hardware_watchpoint: |
| 10726 | ui_out_text (uiout, "Hardware watchpoint "); |
| 10727 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 10728 | break; |
| 10729 | case bp_read_watchpoint: |
| 10730 | ui_out_text (uiout, "Hardware read watchpoint "); |
| 10731 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
| 10732 | break; |
| 10733 | case bp_access_watchpoint: |
| 10734 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); |
| 10735 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
| 10736 | break; |
| 10737 | default: |
| 10738 | internal_error (__FILE__, __LINE__, |
| 10739 | _("Invalid hardware watchpoint type.")); |
| 10740 | } |
| 10741 | |
| 10742 | ui_out_field_int (uiout, "number", b->number); |
| 10743 | ui_out_text (uiout, ": "); |
| 10744 | ui_out_field_string (uiout, "exp", w->exp_string); |
| 10745 | do_cleanups (ui_out_chain); |
| 10746 | } |
| 10747 | |
| 10748 | /* Implement the "print_recreate" breakpoint_ops method for |
| 10749 | watchpoints. */ |
| 10750 | |
| 10751 | static void |
| 10752 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) |
| 10753 | { |
| 10754 | struct watchpoint *w = (struct watchpoint *) b; |
| 10755 | |
| 10756 | switch (b->type) |
| 10757 | { |
| 10758 | case bp_watchpoint: |
| 10759 | case bp_hardware_watchpoint: |
| 10760 | fprintf_unfiltered (fp, "watch"); |
| 10761 | break; |
| 10762 | case bp_read_watchpoint: |
| 10763 | fprintf_unfiltered (fp, "rwatch"); |
| 10764 | break; |
| 10765 | case bp_access_watchpoint: |
| 10766 | fprintf_unfiltered (fp, "awatch"); |
| 10767 | break; |
| 10768 | default: |
| 10769 | internal_error (__FILE__, __LINE__, |
| 10770 | _("Invalid watchpoint type.")); |
| 10771 | } |
| 10772 | |
| 10773 | fprintf_unfiltered (fp, " %s", w->exp_string); |
| 10774 | print_recreate_thread (b, fp); |
| 10775 | } |
| 10776 | |
| 10777 | /* Implement the "explains_signal" breakpoint_ops method for |
| 10778 | watchpoints. */ |
| 10779 | |
| 10780 | static int |
| 10781 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
| 10782 | { |
| 10783 | /* A software watchpoint cannot cause a signal other than |
| 10784 | GDB_SIGNAL_TRAP. */ |
| 10785 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) |
| 10786 | return 0; |
| 10787 | |
| 10788 | return 1; |
| 10789 | } |
| 10790 | |
| 10791 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
| 10792 | |
| 10793 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
| 10794 | |
| 10795 | /* Implement the "insert" breakpoint_ops method for |
| 10796 | masked hardware watchpoints. */ |
| 10797 | |
| 10798 | static int |
| 10799 | insert_masked_watchpoint (struct bp_location *bl) |
| 10800 | { |
| 10801 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10802 | |
| 10803 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, |
| 10804 | bl->watchpoint_type); |
| 10805 | } |
| 10806 | |
| 10807 | /* Implement the "remove" breakpoint_ops method for |
| 10808 | masked hardware watchpoints. */ |
| 10809 | |
| 10810 | static int |
| 10811 | remove_masked_watchpoint (struct bp_location *bl) |
| 10812 | { |
| 10813 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10814 | |
| 10815 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, |
| 10816 | bl->watchpoint_type); |
| 10817 | } |
| 10818 | |
| 10819 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10820 | masked hardware watchpoints. */ |
| 10821 | |
| 10822 | static int |
| 10823 | resources_needed_masked_watchpoint (const struct bp_location *bl) |
| 10824 | { |
| 10825 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10826 | |
| 10827 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); |
| 10828 | } |
| 10829 | |
| 10830 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
| 10831 | masked hardware watchpoints. */ |
| 10832 | |
| 10833 | static int |
| 10834 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) |
| 10835 | { |
| 10836 | return 0; |
| 10837 | } |
| 10838 | |
| 10839 | /* Implement the "print_it" breakpoint_ops method for |
| 10840 | masked hardware watchpoints. */ |
| 10841 | |
| 10842 | static enum print_stop_action |
| 10843 | print_it_masked_watchpoint (bpstat bs) |
| 10844 | { |
| 10845 | struct breakpoint *b = bs->breakpoint_at; |
| 10846 | struct ui_out *uiout = current_uiout; |
| 10847 | |
| 10848 | /* Masked watchpoints have only one location. */ |
| 10849 | gdb_assert (b->loc && b->loc->next == NULL); |
| 10850 | |
| 10851 | switch (b->type) |
| 10852 | { |
| 10853 | case bp_hardware_watchpoint: |
| 10854 | annotate_watchpoint (b->number); |
| 10855 | if (ui_out_is_mi_like_p (uiout)) |
| 10856 | ui_out_field_string |
| 10857 | (uiout, "reason", |
| 10858 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 10859 | break; |
| 10860 | |
| 10861 | case bp_read_watchpoint: |
| 10862 | if (ui_out_is_mi_like_p (uiout)) |
| 10863 | ui_out_field_string |
| 10864 | (uiout, "reason", |
| 10865 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 10866 | break; |
| 10867 | |
| 10868 | case bp_access_watchpoint: |
| 10869 | if (ui_out_is_mi_like_p (uiout)) |
| 10870 | ui_out_field_string |
| 10871 | (uiout, "reason", |
| 10872 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10873 | break; |
| 10874 | default: |
| 10875 | internal_error (__FILE__, __LINE__, |
| 10876 | _("Invalid hardware watchpoint type.")); |
| 10877 | } |
| 10878 | |
| 10879 | mention (b); |
| 10880 | ui_out_text (uiout, _("\n\ |
| 10881 | Check the underlying instruction at PC for the memory\n\ |
| 10882 | address and value which triggered this watchpoint.\n")); |
| 10883 | ui_out_text (uiout, "\n"); |
| 10884 | |
| 10885 | /* More than one watchpoint may have been triggered. */ |
| 10886 | return PRINT_UNKNOWN; |
| 10887 | } |
| 10888 | |
| 10889 | /* Implement the "print_one_detail" breakpoint_ops method for |
| 10890 | masked hardware watchpoints. */ |
| 10891 | |
| 10892 | static void |
| 10893 | print_one_detail_masked_watchpoint (const struct breakpoint *b, |
| 10894 | struct ui_out *uiout) |
| 10895 | { |
| 10896 | struct watchpoint *w = (struct watchpoint *) b; |
| 10897 | |
| 10898 | /* Masked watchpoints have only one location. */ |
| 10899 | gdb_assert (b->loc && b->loc->next == NULL); |
| 10900 | |
| 10901 | ui_out_text (uiout, "\tmask "); |
| 10902 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
| 10903 | ui_out_text (uiout, "\n"); |
| 10904 | } |
| 10905 | |
| 10906 | /* Implement the "print_mention" breakpoint_ops method for |
| 10907 | masked hardware watchpoints. */ |
| 10908 | |
| 10909 | static void |
| 10910 | print_mention_masked_watchpoint (struct breakpoint *b) |
| 10911 | { |
| 10912 | struct watchpoint *w = (struct watchpoint *) b; |
| 10913 | struct ui_out *uiout = current_uiout; |
| 10914 | struct cleanup *ui_out_chain; |
| 10915 | |
| 10916 | switch (b->type) |
| 10917 | { |
| 10918 | case bp_hardware_watchpoint: |
| 10919 | ui_out_text (uiout, "Masked hardware watchpoint "); |
| 10920 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); |
| 10921 | break; |
| 10922 | case bp_read_watchpoint: |
| 10923 | ui_out_text (uiout, "Masked hardware read watchpoint "); |
| 10924 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); |
| 10925 | break; |
| 10926 | case bp_access_watchpoint: |
| 10927 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); |
| 10928 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); |
| 10929 | break; |
| 10930 | default: |
| 10931 | internal_error (__FILE__, __LINE__, |
| 10932 | _("Invalid hardware watchpoint type.")); |
| 10933 | } |
| 10934 | |
| 10935 | ui_out_field_int (uiout, "number", b->number); |
| 10936 | ui_out_text (uiout, ": "); |
| 10937 | ui_out_field_string (uiout, "exp", w->exp_string); |
| 10938 | do_cleanups (ui_out_chain); |
| 10939 | } |
| 10940 | |
| 10941 | /* Implement the "print_recreate" breakpoint_ops method for |
| 10942 | masked hardware watchpoints. */ |
| 10943 | |
| 10944 | static void |
| 10945 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) |
| 10946 | { |
| 10947 | struct watchpoint *w = (struct watchpoint *) b; |
| 10948 | char tmp[40]; |
| 10949 | |
| 10950 | switch (b->type) |
| 10951 | { |
| 10952 | case bp_hardware_watchpoint: |
| 10953 | fprintf_unfiltered (fp, "watch"); |
| 10954 | break; |
| 10955 | case bp_read_watchpoint: |
| 10956 | fprintf_unfiltered (fp, "rwatch"); |
| 10957 | break; |
| 10958 | case bp_access_watchpoint: |
| 10959 | fprintf_unfiltered (fp, "awatch"); |
| 10960 | break; |
| 10961 | default: |
| 10962 | internal_error (__FILE__, __LINE__, |
| 10963 | _("Invalid hardware watchpoint type.")); |
| 10964 | } |
| 10965 | |
| 10966 | sprintf_vma (tmp, w->hw_wp_mask); |
| 10967 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); |
| 10968 | print_recreate_thread (b, fp); |
| 10969 | } |
| 10970 | |
| 10971 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ |
| 10972 | |
| 10973 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
| 10974 | |
| 10975 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ |
| 10976 | |
| 10977 | static int |
| 10978 | is_masked_watchpoint (const struct breakpoint *b) |
| 10979 | { |
| 10980 | return b->ops == &masked_watchpoint_breakpoint_ops; |
| 10981 | } |
| 10982 | |
| 10983 | /* accessflag: hw_write: watch write, |
| 10984 | hw_read: watch read, |
| 10985 | hw_access: watch access (read or write) */ |
| 10986 | static void |
| 10987 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
| 10988 | int just_location, int internal) |
| 10989 | { |
| 10990 | struct breakpoint *b, *scope_breakpoint = NULL; |
| 10991 | struct expression *exp; |
| 10992 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
| 10993 | struct value *val, *mark, *result; |
| 10994 | int saved_bitpos = 0, saved_bitsize = 0; |
| 10995 | struct frame_info *frame; |
| 10996 | const char *exp_start = NULL; |
| 10997 | const char *exp_end = NULL; |
| 10998 | const char *tok, *end_tok; |
| 10999 | int toklen = -1; |
| 11000 | const char *cond_start = NULL; |
| 11001 | const char *cond_end = NULL; |
| 11002 | enum bptype bp_type; |
| 11003 | int thread = -1; |
| 11004 | int pc = 0; |
| 11005 | /* Flag to indicate whether we are going to use masks for |
| 11006 | the hardware watchpoint. */ |
| 11007 | int use_mask = 0; |
| 11008 | CORE_ADDR mask = 0; |
| 11009 | struct watchpoint *w; |
| 11010 | char *expression; |
| 11011 | struct cleanup *back_to; |
| 11012 | |
| 11013 | /* Make sure that we actually have parameters to parse. */ |
| 11014 | if (arg != NULL && arg[0] != '\0') |
| 11015 | { |
| 11016 | const char *value_start; |
| 11017 | |
| 11018 | exp_end = arg + strlen (arg); |
| 11019 | |
| 11020 | /* Look for "parameter value" pairs at the end |
| 11021 | of the arguments string. */ |
| 11022 | for (tok = exp_end - 1; tok > arg; tok--) |
| 11023 | { |
| 11024 | /* Skip whitespace at the end of the argument list. */ |
| 11025 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 11026 | tok--; |
| 11027 | |
| 11028 | /* Find the beginning of the last token. |
| 11029 | This is the value of the parameter. */ |
| 11030 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 11031 | tok--; |
| 11032 | value_start = tok + 1; |
| 11033 | |
| 11034 | /* Skip whitespace. */ |
| 11035 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 11036 | tok--; |
| 11037 | |
| 11038 | end_tok = tok; |
| 11039 | |
| 11040 | /* Find the beginning of the second to last token. |
| 11041 | This is the parameter itself. */ |
| 11042 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 11043 | tok--; |
| 11044 | tok++; |
| 11045 | toklen = end_tok - tok + 1; |
| 11046 | |
| 11047 | if (toklen == 6 && startswith (tok, "thread")) |
| 11048 | { |
| 11049 | /* At this point we've found a "thread" token, which means |
| 11050 | the user is trying to set a watchpoint that triggers |
| 11051 | only in a specific thread. */ |
| 11052 | char *endp; |
| 11053 | |
| 11054 | if (thread != -1) |
| 11055 | error(_("You can specify only one thread.")); |
| 11056 | |
| 11057 | /* Extract the thread ID from the next token. */ |
| 11058 | thread = strtol (value_start, &endp, 0); |
| 11059 | |
| 11060 | /* Check if the user provided a valid numeric value for the |
| 11061 | thread ID. */ |
| 11062 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
| 11063 | error (_("Invalid thread ID specification %s."), value_start); |
| 11064 | |
| 11065 | /* Check if the thread actually exists. */ |
| 11066 | if (!valid_thread_id (thread)) |
| 11067 | invalid_thread_id_error (thread); |
| 11068 | } |
| 11069 | else if (toklen == 4 && startswith (tok, "mask")) |
| 11070 | { |
| 11071 | /* We've found a "mask" token, which means the user wants to |
| 11072 | create a hardware watchpoint that is going to have the mask |
| 11073 | facility. */ |
| 11074 | struct value *mask_value, *mark; |
| 11075 | |
| 11076 | if (use_mask) |
| 11077 | error(_("You can specify only one mask.")); |
| 11078 | |
| 11079 | use_mask = just_location = 1; |
| 11080 | |
| 11081 | mark = value_mark (); |
| 11082 | mask_value = parse_to_comma_and_eval (&value_start); |
| 11083 | mask = value_as_address (mask_value); |
| 11084 | value_free_to_mark (mark); |
| 11085 | } |
| 11086 | else |
| 11087 | /* We didn't recognize what we found. We should stop here. */ |
| 11088 | break; |
| 11089 | |
| 11090 | /* Truncate the string and get rid of the "parameter value" pair before |
| 11091 | the arguments string is parsed by the parse_exp_1 function. */ |
| 11092 | exp_end = tok; |
| 11093 | } |
| 11094 | } |
| 11095 | else |
| 11096 | exp_end = arg; |
| 11097 | |
| 11098 | /* Parse the rest of the arguments. From here on out, everything |
| 11099 | is in terms of a newly allocated string instead of the original |
| 11100 | ARG. */ |
| 11101 | innermost_block = NULL; |
| 11102 | expression = savestring (arg, exp_end - arg); |
| 11103 | back_to = make_cleanup (xfree, expression); |
| 11104 | exp_start = arg = expression; |
| 11105 | exp = parse_exp_1 (&arg, 0, 0, 0); |
| 11106 | exp_end = arg; |
| 11107 | /* Remove trailing whitespace from the expression before saving it. |
| 11108 | This makes the eventual display of the expression string a bit |
| 11109 | prettier. */ |
| 11110 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) |
| 11111 | --exp_end; |
| 11112 | |
| 11113 | /* Checking if the expression is not constant. */ |
| 11114 | if (watchpoint_exp_is_const (exp)) |
| 11115 | { |
| 11116 | int len; |
| 11117 | |
| 11118 | len = exp_end - exp_start; |
| 11119 | while (len > 0 && isspace (exp_start[len - 1])) |
| 11120 | len--; |
| 11121 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); |
| 11122 | } |
| 11123 | |
| 11124 | exp_valid_block = innermost_block; |
| 11125 | mark = value_mark (); |
| 11126 | fetch_subexp_value (exp, &pc, &val, &result, NULL, just_location); |
| 11127 | |
| 11128 | if (val != NULL && just_location) |
| 11129 | { |
| 11130 | saved_bitpos = value_bitpos (val); |
| 11131 | saved_bitsize = value_bitsize (val); |
| 11132 | } |
| 11133 | |
| 11134 | if (just_location) |
| 11135 | { |
| 11136 | int ret; |
| 11137 | |
| 11138 | exp_valid_block = NULL; |
| 11139 | val = value_addr (result); |
| 11140 | release_value (val); |
| 11141 | value_free_to_mark (mark); |
| 11142 | |
| 11143 | if (use_mask) |
| 11144 | { |
| 11145 | ret = target_masked_watch_num_registers (value_as_address (val), |
| 11146 | mask); |
| 11147 | if (ret == -1) |
| 11148 | error (_("This target does not support masked watchpoints.")); |
| 11149 | else if (ret == -2) |
| 11150 | error (_("Invalid mask or memory region.")); |
| 11151 | } |
| 11152 | } |
| 11153 | else if (val != NULL) |
| 11154 | release_value (val); |
| 11155 | |
| 11156 | tok = skip_spaces_const (arg); |
| 11157 | end_tok = skip_to_space_const (tok); |
| 11158 | |
| 11159 | toklen = end_tok - tok; |
| 11160 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 11161 | { |
| 11162 | struct expression *cond; |
| 11163 | |
| 11164 | innermost_block = NULL; |
| 11165 | tok = cond_start = end_tok + 1; |
| 11166 | cond = parse_exp_1 (&tok, 0, 0, 0); |
| 11167 | |
| 11168 | /* The watchpoint expression may not be local, but the condition |
| 11169 | may still be. E.g.: `watch global if local > 0'. */ |
| 11170 | cond_exp_valid_block = innermost_block; |
| 11171 | |
| 11172 | xfree (cond); |
| 11173 | cond_end = tok; |
| 11174 | } |
| 11175 | if (*tok) |
| 11176 | error (_("Junk at end of command.")); |
| 11177 | |
| 11178 | frame = block_innermost_frame (exp_valid_block); |
| 11179 | |
| 11180 | /* If the expression is "local", then set up a "watchpoint scope" |
| 11181 | breakpoint at the point where we've left the scope of the watchpoint |
| 11182 | expression. Create the scope breakpoint before the watchpoint, so |
| 11183 | that we will encounter it first in bpstat_stop_status. */ |
| 11184 | if (exp_valid_block && frame) |
| 11185 | { |
| 11186 | if (frame_id_p (frame_unwind_caller_id (frame))) |
| 11187 | { |
| 11188 | scope_breakpoint |
| 11189 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
| 11190 | frame_unwind_caller_pc (frame), |
| 11191 | bp_watchpoint_scope, |
| 11192 | &momentary_breakpoint_ops); |
| 11193 | |
| 11194 | scope_breakpoint->enable_state = bp_enabled; |
| 11195 | |
| 11196 | /* Automatically delete the breakpoint when it hits. */ |
| 11197 | scope_breakpoint->disposition = disp_del; |
| 11198 | |
| 11199 | /* Only break in the proper frame (help with recursion). */ |
| 11200 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); |
| 11201 | |
| 11202 | /* Set the address at which we will stop. */ |
| 11203 | scope_breakpoint->loc->gdbarch |
| 11204 | = frame_unwind_caller_arch (frame); |
| 11205 | scope_breakpoint->loc->requested_address |
| 11206 | = frame_unwind_caller_pc (frame); |
| 11207 | scope_breakpoint->loc->address |
| 11208 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
| 11209 | scope_breakpoint->loc->requested_address, |
| 11210 | scope_breakpoint->type); |
| 11211 | } |
| 11212 | } |
| 11213 | |
| 11214 | /* Now set up the breakpoint. We create all watchpoints as hardware |
| 11215 | watchpoints here even if hardware watchpoints are turned off, a call |
| 11216 | to update_watchpoint later in this function will cause the type to |
| 11217 | drop back to bp_watchpoint (software watchpoint) if required. */ |
| 11218 | |
| 11219 | if (accessflag == hw_read) |
| 11220 | bp_type = bp_read_watchpoint; |
| 11221 | else if (accessflag == hw_access) |
| 11222 | bp_type = bp_access_watchpoint; |
| 11223 | else |
| 11224 | bp_type = bp_hardware_watchpoint; |
| 11225 | |
| 11226 | w = XCNEW (struct watchpoint); |
| 11227 | b = &w->base; |
| 11228 | if (use_mask) |
| 11229 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
| 11230 | &masked_watchpoint_breakpoint_ops); |
| 11231 | else |
| 11232 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
| 11233 | &watchpoint_breakpoint_ops); |
| 11234 | b->thread = thread; |
| 11235 | b->disposition = disp_donttouch; |
| 11236 | b->pspace = current_program_space; |
| 11237 | w->exp = exp; |
| 11238 | w->exp_valid_block = exp_valid_block; |
| 11239 | w->cond_exp_valid_block = cond_exp_valid_block; |
| 11240 | if (just_location) |
| 11241 | { |
| 11242 | struct type *t = value_type (val); |
| 11243 | CORE_ADDR addr = value_as_address (val); |
| 11244 | char *name; |
| 11245 | |
| 11246 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); |
| 11247 | name = type_to_string (t); |
| 11248 | |
| 11249 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
| 11250 | core_addr_to_string (addr)); |
| 11251 | xfree (name); |
| 11252 | |
| 11253 | w->exp_string = xstrprintf ("-location %.*s", |
| 11254 | (int) (exp_end - exp_start), exp_start); |
| 11255 | |
| 11256 | /* The above expression is in C. */ |
| 11257 | b->language = language_c; |
| 11258 | } |
| 11259 | else |
| 11260 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
| 11261 | |
| 11262 | if (use_mask) |
| 11263 | { |
| 11264 | w->hw_wp_mask = mask; |
| 11265 | } |
| 11266 | else |
| 11267 | { |
| 11268 | w->val = val; |
| 11269 | w->val_bitpos = saved_bitpos; |
| 11270 | w->val_bitsize = saved_bitsize; |
| 11271 | w->val_valid = 1; |
| 11272 | } |
| 11273 | |
| 11274 | if (cond_start) |
| 11275 | b->cond_string = savestring (cond_start, cond_end - cond_start); |
| 11276 | else |
| 11277 | b->cond_string = 0; |
| 11278 | |
| 11279 | if (frame) |
| 11280 | { |
| 11281 | w->watchpoint_frame = get_frame_id (frame); |
| 11282 | w->watchpoint_thread = inferior_ptid; |
| 11283 | } |
| 11284 | else |
| 11285 | { |
| 11286 | w->watchpoint_frame = null_frame_id; |
| 11287 | w->watchpoint_thread = null_ptid; |
| 11288 | } |
| 11289 | |
| 11290 | if (scope_breakpoint != NULL) |
| 11291 | { |
| 11292 | /* The scope breakpoint is related to the watchpoint. We will |
| 11293 | need to act on them together. */ |
| 11294 | b->related_breakpoint = scope_breakpoint; |
| 11295 | scope_breakpoint->related_breakpoint = b; |
| 11296 | } |
| 11297 | |
| 11298 | if (!just_location) |
| 11299 | value_free_to_mark (mark); |
| 11300 | |
| 11301 | TRY |
| 11302 | { |
| 11303 | /* Finally update the new watchpoint. This creates the locations |
| 11304 | that should be inserted. */ |
| 11305 | update_watchpoint (w, 1); |
| 11306 | } |
| 11307 | CATCH (e, RETURN_MASK_ALL) |
| 11308 | { |
| 11309 | delete_breakpoint (b); |
| 11310 | throw_exception (e); |
| 11311 | } |
| 11312 | END_CATCH |
| 11313 | |
| 11314 | install_breakpoint (internal, b, 1); |
| 11315 | do_cleanups (back_to); |
| 11316 | } |
| 11317 | |
| 11318 | /* Return count of debug registers needed to watch the given expression. |
| 11319 | If the watchpoint cannot be handled in hardware return zero. */ |
| 11320 | |
| 11321 | static int |
| 11322 | can_use_hardware_watchpoint (struct value *v) |
| 11323 | { |
| 11324 | int found_memory_cnt = 0; |
| 11325 | struct value *head = v; |
| 11326 | |
| 11327 | /* Did the user specifically forbid us to use hardware watchpoints? */ |
| 11328 | if (!can_use_hw_watchpoints) |
| 11329 | return 0; |
| 11330 | |
| 11331 | /* Make sure that the value of the expression depends only upon |
| 11332 | memory contents, and values computed from them within GDB. If we |
| 11333 | find any register references or function calls, we can't use a |
| 11334 | hardware watchpoint. |
| 11335 | |
| 11336 | The idea here is that evaluating an expression generates a series |
| 11337 | of values, one holding the value of every subexpression. (The |
| 11338 | expression a*b+c has five subexpressions: a, b, a*b, c, and |
| 11339 | a*b+c.) GDB's values hold almost enough information to establish |
| 11340 | the criteria given above --- they identify memory lvalues, |
| 11341 | register lvalues, computed values, etcetera. So we can evaluate |
| 11342 | the expression, and then scan the chain of values that leaves |
| 11343 | behind to decide whether we can detect any possible change to the |
| 11344 | expression's final value using only hardware watchpoints. |
| 11345 | |
| 11346 | However, I don't think that the values returned by inferior |
| 11347 | function calls are special in any way. So this function may not |
| 11348 | notice that an expression involving an inferior function call |
| 11349 | can't be watched with hardware watchpoints. FIXME. */ |
| 11350 | for (; v; v = value_next (v)) |
| 11351 | { |
| 11352 | if (VALUE_LVAL (v) == lval_memory) |
| 11353 | { |
| 11354 | if (v != head && value_lazy (v)) |
| 11355 | /* A lazy memory lvalue in the chain is one that GDB never |
| 11356 | needed to fetch; we either just used its address (e.g., |
| 11357 | `a' in `a.b') or we never needed it at all (e.g., `a' |
| 11358 | in `a,b'). This doesn't apply to HEAD; if that is |
| 11359 | lazy then it was not readable, but watch it anyway. */ |
| 11360 | ; |
| 11361 | else |
| 11362 | { |
| 11363 | /* Ahh, memory we actually used! Check if we can cover |
| 11364 | it with hardware watchpoints. */ |
| 11365 | struct type *vtype = check_typedef (value_type (v)); |
| 11366 | |
| 11367 | /* We only watch structs and arrays if user asked for it |
| 11368 | explicitly, never if they just happen to appear in a |
| 11369 | middle of some value chain. */ |
| 11370 | if (v == head |
| 11371 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 11372 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 11373 | { |
| 11374 | CORE_ADDR vaddr = value_address (v); |
| 11375 | int len; |
| 11376 | int num_regs; |
| 11377 | |
| 11378 | len = (target_exact_watchpoints |
| 11379 | && is_scalar_type_recursive (vtype))? |
| 11380 | 1 : TYPE_LENGTH (value_type (v)); |
| 11381 | |
| 11382 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
| 11383 | if (!num_regs) |
| 11384 | return 0; |
| 11385 | else |
| 11386 | found_memory_cnt += num_regs; |
| 11387 | } |
| 11388 | } |
| 11389 | } |
| 11390 | else if (VALUE_LVAL (v) != not_lval |
| 11391 | && deprecated_value_modifiable (v) == 0) |
| 11392 | return 0; /* These are values from the history (e.g., $1). */ |
| 11393 | else if (VALUE_LVAL (v) == lval_register) |
| 11394 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
| 11395 | } |
| 11396 | |
| 11397 | /* The expression itself looks suitable for using a hardware |
| 11398 | watchpoint, but give the target machine a chance to reject it. */ |
| 11399 | return found_memory_cnt; |
| 11400 | } |
| 11401 | |
| 11402 | void |
| 11403 | watch_command_wrapper (char *arg, int from_tty, int internal) |
| 11404 | { |
| 11405 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
| 11406 | } |
| 11407 | |
| 11408 | /* A helper function that looks for the "-location" argument and then |
| 11409 | calls watch_command_1. */ |
| 11410 | |
| 11411 | static void |
| 11412 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) |
| 11413 | { |
| 11414 | int just_location = 0; |
| 11415 | |
| 11416 | if (arg |
| 11417 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) |
| 11418 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) |
| 11419 | { |
| 11420 | arg = skip_spaces (arg); |
| 11421 | just_location = 1; |
| 11422 | } |
| 11423 | |
| 11424 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
| 11425 | } |
| 11426 | |
| 11427 | static void |
| 11428 | watch_command (char *arg, int from_tty) |
| 11429 | { |
| 11430 | watch_maybe_just_location (arg, hw_write, from_tty); |
| 11431 | } |
| 11432 | |
| 11433 | void |
| 11434 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
| 11435 | { |
| 11436 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
| 11437 | } |
| 11438 | |
| 11439 | static void |
| 11440 | rwatch_command (char *arg, int from_tty) |
| 11441 | { |
| 11442 | watch_maybe_just_location (arg, hw_read, from_tty); |
| 11443 | } |
| 11444 | |
| 11445 | void |
| 11446 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
| 11447 | { |
| 11448 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
| 11449 | } |
| 11450 | |
| 11451 | static void |
| 11452 | awatch_command (char *arg, int from_tty) |
| 11453 | { |
| 11454 | watch_maybe_just_location (arg, hw_access, from_tty); |
| 11455 | } |
| 11456 | \f |
| 11457 | |
| 11458 | /* Helper routines for the until_command routine in infcmd.c. Here |
| 11459 | because it uses the mechanisms of breakpoints. */ |
| 11460 | |
| 11461 | struct until_break_command_continuation_args |
| 11462 | { |
| 11463 | struct breakpoint *breakpoint; |
| 11464 | struct breakpoint *breakpoint2; |
| 11465 | int thread_num; |
| 11466 | }; |
| 11467 | |
| 11468 | /* This function is called by fetch_inferior_event via the |
| 11469 | cmd_continuation pointer, to complete the until command. It takes |
| 11470 | care of cleaning up the temporary breakpoints set up by the until |
| 11471 | command. */ |
| 11472 | static void |
| 11473 | until_break_command_continuation (void *arg, int err) |
| 11474 | { |
| 11475 | struct until_break_command_continuation_args *a = arg; |
| 11476 | |
| 11477 | delete_breakpoint (a->breakpoint); |
| 11478 | if (a->breakpoint2) |
| 11479 | delete_breakpoint (a->breakpoint2); |
| 11480 | delete_longjmp_breakpoint (a->thread_num); |
| 11481 | } |
| 11482 | |
| 11483 | void |
| 11484 | until_break_command (char *arg, int from_tty, int anywhere) |
| 11485 | { |
| 11486 | struct symtabs_and_lines sals; |
| 11487 | struct symtab_and_line sal; |
| 11488 | struct frame_info *frame; |
| 11489 | struct gdbarch *frame_gdbarch; |
| 11490 | struct frame_id stack_frame_id; |
| 11491 | struct frame_id caller_frame_id; |
| 11492 | struct breakpoint *breakpoint; |
| 11493 | struct breakpoint *breakpoint2 = NULL; |
| 11494 | struct cleanup *old_chain, *cleanup; |
| 11495 | int thread; |
| 11496 | struct thread_info *tp; |
| 11497 | struct event_location *location; |
| 11498 | |
| 11499 | clear_proceed_status (0); |
| 11500 | |
| 11501 | /* Set a breakpoint where the user wants it and at return from |
| 11502 | this function. */ |
| 11503 | |
| 11504 | location = string_to_event_location (&arg, current_language); |
| 11505 | cleanup = make_cleanup_delete_event_location (location); |
| 11506 | |
| 11507 | if (last_displayed_sal_is_valid ()) |
| 11508 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
| 11509 | get_last_displayed_symtab (), |
| 11510 | get_last_displayed_line ()); |
| 11511 | else |
| 11512 | sals = decode_line_1 (location, DECODE_LINE_FUNFIRSTLINE, |
| 11513 | (struct symtab *) NULL, 0); |
| 11514 | |
| 11515 | if (sals.nelts != 1) |
| 11516 | error (_("Couldn't get information on specified line.")); |
| 11517 | |
| 11518 | sal = sals.sals[0]; |
| 11519 | xfree (sals.sals); /* malloc'd, so freed. */ |
| 11520 | |
| 11521 | if (*arg) |
| 11522 | error (_("Junk at end of arguments.")); |
| 11523 | |
| 11524 | resolve_sal_pc (&sal); |
| 11525 | |
| 11526 | tp = inferior_thread (); |
| 11527 | thread = tp->num; |
| 11528 | |
| 11529 | old_chain = make_cleanup (null_cleanup, NULL); |
| 11530 | |
| 11531 | /* Note linespec handling above invalidates the frame chain. |
| 11532 | Installing a breakpoint also invalidates the frame chain (as it |
| 11533 | may need to switch threads), so do any frame handling before |
| 11534 | that. */ |
| 11535 | |
| 11536 | frame = get_selected_frame (NULL); |
| 11537 | frame_gdbarch = get_frame_arch (frame); |
| 11538 | stack_frame_id = get_stack_frame_id (frame); |
| 11539 | caller_frame_id = frame_unwind_caller_id (frame); |
| 11540 | |
| 11541 | /* Keep within the current frame, or in frames called by the current |
| 11542 | one. */ |
| 11543 | |
| 11544 | if (frame_id_p (caller_frame_id)) |
| 11545 | { |
| 11546 | struct symtab_and_line sal2; |
| 11547 | |
| 11548 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); |
| 11549 | sal2.pc = frame_unwind_caller_pc (frame); |
| 11550 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
| 11551 | sal2, |
| 11552 | caller_frame_id, |
| 11553 | bp_until); |
| 11554 | make_cleanup_delete_breakpoint (breakpoint2); |
| 11555 | |
| 11556 | set_longjmp_breakpoint (tp, caller_frame_id); |
| 11557 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); |
| 11558 | } |
| 11559 | |
| 11560 | /* set_momentary_breakpoint could invalidate FRAME. */ |
| 11561 | frame = NULL; |
| 11562 | |
| 11563 | if (anywhere) |
| 11564 | /* If the user told us to continue until a specified location, |
| 11565 | we don't specify a frame at which we need to stop. */ |
| 11566 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
| 11567 | null_frame_id, bp_until); |
| 11568 | else |
| 11569 | /* Otherwise, specify the selected frame, because we want to stop |
| 11570 | only at the very same frame. */ |
| 11571 | breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
| 11572 | stack_frame_id, bp_until); |
| 11573 | make_cleanup_delete_breakpoint (breakpoint); |
| 11574 | |
| 11575 | proceed (-1, GDB_SIGNAL_DEFAULT); |
| 11576 | |
| 11577 | /* If we are running asynchronously, and proceed call above has |
| 11578 | actually managed to start the target, arrange for breakpoints to |
| 11579 | be deleted when the target stops. Otherwise, we're already |
| 11580 | stopped and delete breakpoints via cleanup chain. */ |
| 11581 | |
| 11582 | if (target_can_async_p () && is_running (inferior_ptid)) |
| 11583 | { |
| 11584 | struct until_break_command_continuation_args *args; |
| 11585 | args = xmalloc (sizeof (*args)); |
| 11586 | |
| 11587 | args->breakpoint = breakpoint; |
| 11588 | args->breakpoint2 = breakpoint2; |
| 11589 | args->thread_num = thread; |
| 11590 | |
| 11591 | discard_cleanups (old_chain); |
| 11592 | add_continuation (inferior_thread (), |
| 11593 | until_break_command_continuation, args, |
| 11594 | xfree); |
| 11595 | } |
| 11596 | else |
| 11597 | do_cleanups (old_chain); |
| 11598 | |
| 11599 | do_cleanups (cleanup); |
| 11600 | } |
| 11601 | |
| 11602 | /* This function attempts to parse an optional "if <cond>" clause |
| 11603 | from the arg string. If one is not found, it returns NULL. |
| 11604 | |
| 11605 | Else, it returns a pointer to the condition string. (It does not |
| 11606 | attempt to evaluate the string against a particular block.) And, |
| 11607 | it updates arg to point to the first character following the parsed |
| 11608 | if clause in the arg string. */ |
| 11609 | |
| 11610 | char * |
| 11611 | ep_parse_optional_if_clause (char **arg) |
| 11612 | { |
| 11613 | char *cond_string; |
| 11614 | |
| 11615 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) |
| 11616 | return NULL; |
| 11617 | |
| 11618 | /* Skip the "if" keyword. */ |
| 11619 | (*arg) += 2; |
| 11620 | |
| 11621 | /* Skip any extra leading whitespace, and record the start of the |
| 11622 | condition string. */ |
| 11623 | *arg = skip_spaces (*arg); |
| 11624 | cond_string = *arg; |
| 11625 | |
| 11626 | /* Assume that the condition occupies the remainder of the arg |
| 11627 | string. */ |
| 11628 | (*arg) += strlen (cond_string); |
| 11629 | |
| 11630 | return cond_string; |
| 11631 | } |
| 11632 | |
| 11633 | /* Commands to deal with catching events, such as signals, exceptions, |
| 11634 | process start/exit, etc. */ |
| 11635 | |
| 11636 | typedef enum |
| 11637 | { |
| 11638 | catch_fork_temporary, catch_vfork_temporary, |
| 11639 | catch_fork_permanent, catch_vfork_permanent |
| 11640 | } |
| 11641 | catch_fork_kind; |
| 11642 | |
| 11643 | static void |
| 11644 | catch_fork_command_1 (char *arg, int from_tty, |
| 11645 | struct cmd_list_element *command) |
| 11646 | { |
| 11647 | struct gdbarch *gdbarch = get_current_arch (); |
| 11648 | char *cond_string = NULL; |
| 11649 | catch_fork_kind fork_kind; |
| 11650 | int tempflag; |
| 11651 | |
| 11652 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); |
| 11653 | tempflag = (fork_kind == catch_fork_temporary |
| 11654 | || fork_kind == catch_vfork_temporary); |
| 11655 | |
| 11656 | if (!arg) |
| 11657 | arg = ""; |
| 11658 | arg = skip_spaces (arg); |
| 11659 | |
| 11660 | /* The allowed syntax is: |
| 11661 | catch [v]fork |
| 11662 | catch [v]fork if <cond> |
| 11663 | |
| 11664 | First, check if there's an if clause. */ |
| 11665 | cond_string = ep_parse_optional_if_clause (&arg); |
| 11666 | |
| 11667 | if ((*arg != '\0') && !isspace (*arg)) |
| 11668 | error (_("Junk at end of arguments.")); |
| 11669 | |
| 11670 | /* If this target supports it, create a fork or vfork catchpoint |
| 11671 | and enable reporting of such events. */ |
| 11672 | switch (fork_kind) |
| 11673 | { |
| 11674 | case catch_fork_temporary: |
| 11675 | case catch_fork_permanent: |
| 11676 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 11677 | &catch_fork_breakpoint_ops); |
| 11678 | break; |
| 11679 | case catch_vfork_temporary: |
| 11680 | case catch_vfork_permanent: |
| 11681 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 11682 | &catch_vfork_breakpoint_ops); |
| 11683 | break; |
| 11684 | default: |
| 11685 | error (_("unsupported or unknown fork kind; cannot catch it")); |
| 11686 | break; |
| 11687 | } |
| 11688 | } |
| 11689 | |
| 11690 | static void |
| 11691 | catch_exec_command_1 (char *arg, int from_tty, |
| 11692 | struct cmd_list_element *command) |
| 11693 | { |
| 11694 | struct exec_catchpoint *c; |
| 11695 | struct gdbarch *gdbarch = get_current_arch (); |
| 11696 | int tempflag; |
| 11697 | char *cond_string = NULL; |
| 11698 | |
| 11699 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 11700 | |
| 11701 | if (!arg) |
| 11702 | arg = ""; |
| 11703 | arg = skip_spaces (arg); |
| 11704 | |
| 11705 | /* The allowed syntax is: |
| 11706 | catch exec |
| 11707 | catch exec if <cond> |
| 11708 | |
| 11709 | First, check if there's an if clause. */ |
| 11710 | cond_string = ep_parse_optional_if_clause (&arg); |
| 11711 | |
| 11712 | if ((*arg != '\0') && !isspace (*arg)) |
| 11713 | error (_("Junk at end of arguments.")); |
| 11714 | |
| 11715 | c = XNEW (struct exec_catchpoint); |
| 11716 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, |
| 11717 | &catch_exec_breakpoint_ops); |
| 11718 | c->exec_pathname = NULL; |
| 11719 | |
| 11720 | install_breakpoint (0, &c->base, 1); |
| 11721 | } |
| 11722 | |
| 11723 | void |
| 11724 | init_ada_exception_breakpoint (struct breakpoint *b, |
| 11725 | struct gdbarch *gdbarch, |
| 11726 | struct symtab_and_line sal, |
| 11727 | char *addr_string, |
| 11728 | const struct breakpoint_ops *ops, |
| 11729 | int tempflag, |
| 11730 | int enabled, |
| 11731 | int from_tty) |
| 11732 | { |
| 11733 | if (from_tty) |
| 11734 | { |
| 11735 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 11736 | if (!loc_gdbarch) |
| 11737 | loc_gdbarch = gdbarch; |
| 11738 | |
| 11739 | describe_other_breakpoints (loc_gdbarch, |
| 11740 | sal.pspace, sal.pc, sal.section, -1); |
| 11741 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
| 11742 | version for exception catchpoints, because two catchpoints |
| 11743 | used for different exception names will use the same address. |
| 11744 | In this case, a "breakpoint ... also set at..." warning is |
| 11745 | unproductive. Besides, the warning phrasing is also a bit |
| 11746 | inappropriate, we should use the word catchpoint, and tell |
| 11747 | the user what type of catchpoint it is. The above is good |
| 11748 | enough for now, though. */ |
| 11749 | } |
| 11750 | |
| 11751 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
| 11752 | |
| 11753 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 11754 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 11755 | b->location = string_to_event_location (&addr_string, |
| 11756 | language_def (language_ada)); |
| 11757 | b->language = language_ada; |
| 11758 | } |
| 11759 | |
| 11760 | static void |
| 11761 | catch_command (char *arg, int from_tty) |
| 11762 | { |
| 11763 | error (_("Catch requires an event name.")); |
| 11764 | } |
| 11765 | \f |
| 11766 | |
| 11767 | static void |
| 11768 | tcatch_command (char *arg, int from_tty) |
| 11769 | { |
| 11770 | error (_("Catch requires an event name.")); |
| 11771 | } |
| 11772 | |
| 11773 | /* A qsort comparison function that sorts breakpoints in order. */ |
| 11774 | |
| 11775 | static int |
| 11776 | compare_breakpoints (const void *a, const void *b) |
| 11777 | { |
| 11778 | const breakpoint_p *ba = a; |
| 11779 | uintptr_t ua = (uintptr_t) *ba; |
| 11780 | const breakpoint_p *bb = b; |
| 11781 | uintptr_t ub = (uintptr_t) *bb; |
| 11782 | |
| 11783 | if ((*ba)->number < (*bb)->number) |
| 11784 | return -1; |
| 11785 | else if ((*ba)->number > (*bb)->number) |
| 11786 | return 1; |
| 11787 | |
| 11788 | /* Now sort by address, in case we see, e..g, two breakpoints with |
| 11789 | the number 0. */ |
| 11790 | if (ua < ub) |
| 11791 | return -1; |
| 11792 | return ua > ub ? 1 : 0; |
| 11793 | } |
| 11794 | |
| 11795 | /* Delete breakpoints by address or line. */ |
| 11796 | |
| 11797 | static void |
| 11798 | clear_command (char *arg, int from_tty) |
| 11799 | { |
| 11800 | struct breakpoint *b, *prev; |
| 11801 | VEC(breakpoint_p) *found = 0; |
| 11802 | int ix; |
| 11803 | int default_match; |
| 11804 | struct symtabs_and_lines sals; |
| 11805 | struct symtab_and_line sal; |
| 11806 | int i; |
| 11807 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
| 11808 | |
| 11809 | if (arg) |
| 11810 | { |
| 11811 | sals = decode_line_with_current_source (arg, |
| 11812 | (DECODE_LINE_FUNFIRSTLINE |
| 11813 | | DECODE_LINE_LIST_MODE)); |
| 11814 | make_cleanup (xfree, sals.sals); |
| 11815 | default_match = 0; |
| 11816 | } |
| 11817 | else |
| 11818 | { |
| 11819 | sals.sals = (struct symtab_and_line *) |
| 11820 | xmalloc (sizeof (struct symtab_and_line)); |
| 11821 | make_cleanup (xfree, sals.sals); |
| 11822 | init_sal (&sal); /* Initialize to zeroes. */ |
| 11823 | |
| 11824 | /* Set sal's line, symtab, pc, and pspace to the values |
| 11825 | corresponding to the last call to print_frame_info. If the |
| 11826 | codepoint is not valid, this will set all the fields to 0. */ |
| 11827 | get_last_displayed_sal (&sal); |
| 11828 | if (sal.symtab == 0) |
| 11829 | error (_("No source file specified.")); |
| 11830 | |
| 11831 | sals.sals[0] = sal; |
| 11832 | sals.nelts = 1; |
| 11833 | |
| 11834 | default_match = 1; |
| 11835 | } |
| 11836 | |
| 11837 | /* We don't call resolve_sal_pc here. That's not as bad as it |
| 11838 | seems, because all existing breakpoints typically have both |
| 11839 | file/line and pc set. So, if clear is given file/line, we can |
| 11840 | match this to existing breakpoint without obtaining pc at all. |
| 11841 | |
| 11842 | We only support clearing given the address explicitly |
| 11843 | present in breakpoint table. Say, we've set breakpoint |
| 11844 | at file:line. There were several PC values for that file:line, |
| 11845 | due to optimization, all in one block. |
| 11846 | |
| 11847 | We've picked one PC value. If "clear" is issued with another |
| 11848 | PC corresponding to the same file:line, the breakpoint won't |
| 11849 | be cleared. We probably can still clear the breakpoint, but |
| 11850 | since the other PC value is never presented to user, user |
| 11851 | can only find it by guessing, and it does not seem important |
| 11852 | to support that. */ |
| 11853 | |
| 11854 | /* For each line spec given, delete bps which correspond to it. Do |
| 11855 | it in two passes, solely to preserve the current behavior that |
| 11856 | from_tty is forced true if we delete more than one |
| 11857 | breakpoint. */ |
| 11858 | |
| 11859 | found = NULL; |
| 11860 | make_cleanup (VEC_cleanup (breakpoint_p), &found); |
| 11861 | for (i = 0; i < sals.nelts; i++) |
| 11862 | { |
| 11863 | const char *sal_fullname; |
| 11864 | |
| 11865 | /* If exact pc given, clear bpts at that pc. |
| 11866 | If line given (pc == 0), clear all bpts on specified line. |
| 11867 | If defaulting, clear all bpts on default line |
| 11868 | or at default pc. |
| 11869 | |
| 11870 | defaulting sal.pc != 0 tests to do |
| 11871 | |
| 11872 | 0 1 pc |
| 11873 | 1 1 pc _and_ line |
| 11874 | 0 0 line |
| 11875 | 1 0 <can't happen> */ |
| 11876 | |
| 11877 | sal = sals.sals[i]; |
| 11878 | sal_fullname = (sal.symtab == NULL |
| 11879 | ? NULL : symtab_to_fullname (sal.symtab)); |
| 11880 | |
| 11881 | /* Find all matching breakpoints and add them to 'found'. */ |
| 11882 | ALL_BREAKPOINTS (b) |
| 11883 | { |
| 11884 | int match = 0; |
| 11885 | /* Are we going to delete b? */ |
| 11886 | if (b->type != bp_none && !is_watchpoint (b)) |
| 11887 | { |
| 11888 | struct bp_location *loc = b->loc; |
| 11889 | for (; loc; loc = loc->next) |
| 11890 | { |
| 11891 | /* If the user specified file:line, don't allow a PC |
| 11892 | match. This matches historical gdb behavior. */ |
| 11893 | int pc_match = (!sal.explicit_line |
| 11894 | && sal.pc |
| 11895 | && (loc->pspace == sal.pspace) |
| 11896 | && (loc->address == sal.pc) |
| 11897 | && (!section_is_overlay (loc->section) |
| 11898 | || loc->section == sal.section)); |
| 11899 | int line_match = 0; |
| 11900 | |
| 11901 | if ((default_match || sal.explicit_line) |
| 11902 | && loc->symtab != NULL |
| 11903 | && sal_fullname != NULL |
| 11904 | && sal.pspace == loc->pspace |
| 11905 | && loc->line_number == sal.line |
| 11906 | && filename_cmp (symtab_to_fullname (loc->symtab), |
| 11907 | sal_fullname) == 0) |
| 11908 | line_match = 1; |
| 11909 | |
| 11910 | if (pc_match || line_match) |
| 11911 | { |
| 11912 | match = 1; |
| 11913 | break; |
| 11914 | } |
| 11915 | } |
| 11916 | } |
| 11917 | |
| 11918 | if (match) |
| 11919 | VEC_safe_push(breakpoint_p, found, b); |
| 11920 | } |
| 11921 | } |
| 11922 | |
| 11923 | /* Now go thru the 'found' chain and delete them. */ |
| 11924 | if (VEC_empty(breakpoint_p, found)) |
| 11925 | { |
| 11926 | if (arg) |
| 11927 | error (_("No breakpoint at %s."), arg); |
| 11928 | else |
| 11929 | error (_("No breakpoint at this line.")); |
| 11930 | } |
| 11931 | |
| 11932 | /* Remove duplicates from the vec. */ |
| 11933 | qsort (VEC_address (breakpoint_p, found), |
| 11934 | VEC_length (breakpoint_p, found), |
| 11935 | sizeof (breakpoint_p), |
| 11936 | compare_breakpoints); |
| 11937 | prev = VEC_index (breakpoint_p, found, 0); |
| 11938 | for (ix = 1; VEC_iterate (breakpoint_p, found, ix, b); ++ix) |
| 11939 | { |
| 11940 | if (b == prev) |
| 11941 | { |
| 11942 | VEC_ordered_remove (breakpoint_p, found, ix); |
| 11943 | --ix; |
| 11944 | } |
| 11945 | } |
| 11946 | |
| 11947 | if (VEC_length(breakpoint_p, found) > 1) |
| 11948 | from_tty = 1; /* Always report if deleted more than one. */ |
| 11949 | if (from_tty) |
| 11950 | { |
| 11951 | if (VEC_length(breakpoint_p, found) == 1) |
| 11952 | printf_unfiltered (_("Deleted breakpoint ")); |
| 11953 | else |
| 11954 | printf_unfiltered (_("Deleted breakpoints ")); |
| 11955 | } |
| 11956 | |
| 11957 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) |
| 11958 | { |
| 11959 | if (from_tty) |
| 11960 | printf_unfiltered ("%d ", b->number); |
| 11961 | delete_breakpoint (b); |
| 11962 | } |
| 11963 | if (from_tty) |
| 11964 | putchar_unfiltered ('\n'); |
| 11965 | |
| 11966 | do_cleanups (cleanups); |
| 11967 | } |
| 11968 | \f |
| 11969 | /* Delete breakpoint in BS if they are `delete' breakpoints and |
| 11970 | all breakpoints that are marked for deletion, whether hit or not. |
| 11971 | This is called after any breakpoint is hit, or after errors. */ |
| 11972 | |
| 11973 | void |
| 11974 | breakpoint_auto_delete (bpstat bs) |
| 11975 | { |
| 11976 | struct breakpoint *b, *b_tmp; |
| 11977 | |
| 11978 | for (; bs; bs = bs->next) |
| 11979 | if (bs->breakpoint_at |
| 11980 | && bs->breakpoint_at->disposition == disp_del |
| 11981 | && bs->stop) |
| 11982 | delete_breakpoint (bs->breakpoint_at); |
| 11983 | |
| 11984 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 11985 | { |
| 11986 | if (b->disposition == disp_del_at_next_stop) |
| 11987 | delete_breakpoint (b); |
| 11988 | } |
| 11989 | } |
| 11990 | |
| 11991 | /* A comparison function for bp_location AP and BP being interfaced to |
| 11992 | qsort. Sort elements primarily by their ADDRESS (no matter what |
| 11993 | does breakpoint_address_is_meaningful say for its OWNER), |
| 11994 | secondarily by ordering first permanent elements and |
| 11995 | terciarily just ensuring the array is sorted stable way despite |
| 11996 | qsort being an unstable algorithm. */ |
| 11997 | |
| 11998 | static int |
| 11999 | bp_location_compare (const void *ap, const void *bp) |
| 12000 | { |
| 12001 | struct bp_location *a = *(void **) ap; |
| 12002 | struct bp_location *b = *(void **) bp; |
| 12003 | |
| 12004 | if (a->address != b->address) |
| 12005 | return (a->address > b->address) - (a->address < b->address); |
| 12006 | |
| 12007 | /* Sort locations at the same address by their pspace number, keeping |
| 12008 | locations of the same inferior (in a multi-inferior environment) |
| 12009 | grouped. */ |
| 12010 | |
| 12011 | if (a->pspace->num != b->pspace->num) |
| 12012 | return ((a->pspace->num > b->pspace->num) |
| 12013 | - (a->pspace->num < b->pspace->num)); |
| 12014 | |
| 12015 | /* Sort permanent breakpoints first. */ |
| 12016 | if (a->permanent != b->permanent) |
| 12017 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); |
| 12018 | |
| 12019 | /* Make the internal GDB representation stable across GDB runs |
| 12020 | where A and B memory inside GDB can differ. Breakpoint locations of |
| 12021 | the same type at the same address can be sorted in arbitrary order. */ |
| 12022 | |
| 12023 | if (a->owner->number != b->owner->number) |
| 12024 | return ((a->owner->number > b->owner->number) |
| 12025 | - (a->owner->number < b->owner->number)); |
| 12026 | |
| 12027 | return (a > b) - (a < b); |
| 12028 | } |
| 12029 | |
| 12030 | /* Set bp_location_placed_address_before_address_max and |
| 12031 | bp_location_shadow_len_after_address_max according to the current |
| 12032 | content of the bp_location array. */ |
| 12033 | |
| 12034 | static void |
| 12035 | bp_location_target_extensions_update (void) |
| 12036 | { |
| 12037 | struct bp_location *bl, **blp_tmp; |
| 12038 | |
| 12039 | bp_location_placed_address_before_address_max = 0; |
| 12040 | bp_location_shadow_len_after_address_max = 0; |
| 12041 | |
| 12042 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 12043 | { |
| 12044 | CORE_ADDR start, end, addr; |
| 12045 | |
| 12046 | if (!bp_location_has_shadow (bl)) |
| 12047 | continue; |
| 12048 | |
| 12049 | start = bl->target_info.placed_address; |
| 12050 | end = start + bl->target_info.shadow_len; |
| 12051 | |
| 12052 | gdb_assert (bl->address >= start); |
| 12053 | addr = bl->address - start; |
| 12054 | if (addr > bp_location_placed_address_before_address_max) |
| 12055 | bp_location_placed_address_before_address_max = addr; |
| 12056 | |
| 12057 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ |
| 12058 | |
| 12059 | gdb_assert (bl->address < end); |
| 12060 | addr = end - bl->address; |
| 12061 | if (addr > bp_location_shadow_len_after_address_max) |
| 12062 | bp_location_shadow_len_after_address_max = addr; |
| 12063 | } |
| 12064 | } |
| 12065 | |
| 12066 | /* Download tracepoint locations if they haven't been. */ |
| 12067 | |
| 12068 | static void |
| 12069 | download_tracepoint_locations (void) |
| 12070 | { |
| 12071 | struct breakpoint *b; |
| 12072 | struct cleanup *old_chain; |
| 12073 | |
| 12074 | if (!target_can_download_tracepoint ()) |
| 12075 | return; |
| 12076 | |
| 12077 | old_chain = save_current_space_and_thread (); |
| 12078 | |
| 12079 | ALL_TRACEPOINTS (b) |
| 12080 | { |
| 12081 | struct bp_location *bl; |
| 12082 | struct tracepoint *t; |
| 12083 | int bp_location_downloaded = 0; |
| 12084 | |
| 12085 | if ((b->type == bp_fast_tracepoint |
| 12086 | ? !may_insert_fast_tracepoints |
| 12087 | : !may_insert_tracepoints)) |
| 12088 | continue; |
| 12089 | |
| 12090 | for (bl = b->loc; bl; bl = bl->next) |
| 12091 | { |
| 12092 | /* In tracepoint, locations are _never_ duplicated, so |
| 12093 | should_be_inserted is equivalent to |
| 12094 | unduplicated_should_be_inserted. */ |
| 12095 | if (!should_be_inserted (bl) || bl->inserted) |
| 12096 | continue; |
| 12097 | |
| 12098 | switch_to_program_space_and_thread (bl->pspace); |
| 12099 | |
| 12100 | target_download_tracepoint (bl); |
| 12101 | |
| 12102 | bl->inserted = 1; |
| 12103 | bp_location_downloaded = 1; |
| 12104 | } |
| 12105 | t = (struct tracepoint *) b; |
| 12106 | t->number_on_target = b->number; |
| 12107 | if (bp_location_downloaded) |
| 12108 | observer_notify_breakpoint_modified (b); |
| 12109 | } |
| 12110 | |
| 12111 | do_cleanups (old_chain); |
| 12112 | } |
| 12113 | |
| 12114 | /* Swap the insertion/duplication state between two locations. */ |
| 12115 | |
| 12116 | static void |
| 12117 | swap_insertion (struct bp_location *left, struct bp_location *right) |
| 12118 | { |
| 12119 | const int left_inserted = left->inserted; |
| 12120 | const int left_duplicate = left->duplicate; |
| 12121 | const int left_needs_update = left->needs_update; |
| 12122 | const struct bp_target_info left_target_info = left->target_info; |
| 12123 | |
| 12124 | /* Locations of tracepoints can never be duplicated. */ |
| 12125 | if (is_tracepoint (left->owner)) |
| 12126 | gdb_assert (!left->duplicate); |
| 12127 | if (is_tracepoint (right->owner)) |
| 12128 | gdb_assert (!right->duplicate); |
| 12129 | |
| 12130 | left->inserted = right->inserted; |
| 12131 | left->duplicate = right->duplicate; |
| 12132 | left->needs_update = right->needs_update; |
| 12133 | left->target_info = right->target_info; |
| 12134 | right->inserted = left_inserted; |
| 12135 | right->duplicate = left_duplicate; |
| 12136 | right->needs_update = left_needs_update; |
| 12137 | right->target_info = left_target_info; |
| 12138 | } |
| 12139 | |
| 12140 | /* Force the re-insertion of the locations at ADDRESS. This is called |
| 12141 | once a new/deleted/modified duplicate location is found and we are evaluating |
| 12142 | conditions on the target's side. Such conditions need to be updated on |
| 12143 | the target. */ |
| 12144 | |
| 12145 | static void |
| 12146 | force_breakpoint_reinsertion (struct bp_location *bl) |
| 12147 | { |
| 12148 | struct bp_location **locp = NULL, **loc2p; |
| 12149 | struct bp_location *loc; |
| 12150 | CORE_ADDR address = 0; |
| 12151 | int pspace_num; |
| 12152 | |
| 12153 | address = bl->address; |
| 12154 | pspace_num = bl->pspace->num; |
| 12155 | |
| 12156 | /* This is only meaningful if the target is |
| 12157 | evaluating conditions and if the user has |
| 12158 | opted for condition evaluation on the target's |
| 12159 | side. */ |
| 12160 | if (gdb_evaluates_breakpoint_condition_p () |
| 12161 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 12162 | return; |
| 12163 | |
| 12164 | /* Flag all breakpoint locations with this address and |
| 12165 | the same program space as the location |
| 12166 | as "its condition has changed". We need to |
| 12167 | update the conditions on the target's side. */ |
| 12168 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) |
| 12169 | { |
| 12170 | loc = *loc2p; |
| 12171 | |
| 12172 | if (!is_breakpoint (loc->owner) |
| 12173 | || pspace_num != loc->pspace->num) |
| 12174 | continue; |
| 12175 | |
| 12176 | /* Flag the location appropriately. We use a different state to |
| 12177 | let everyone know that we already updated the set of locations |
| 12178 | with addr bl->address and program space bl->pspace. This is so |
| 12179 | we don't have to keep calling these functions just to mark locations |
| 12180 | that have already been marked. */ |
| 12181 | loc->condition_changed = condition_updated; |
| 12182 | |
| 12183 | /* Free the agent expression bytecode as well. We will compute |
| 12184 | it later on. */ |
| 12185 | if (loc->cond_bytecode) |
| 12186 | { |
| 12187 | free_agent_expr (loc->cond_bytecode); |
| 12188 | loc->cond_bytecode = NULL; |
| 12189 | } |
| 12190 | } |
| 12191 | } |
| 12192 | /* Called whether new breakpoints are created, or existing breakpoints |
| 12193 | deleted, to update the global location list and recompute which |
| 12194 | locations are duplicate of which. |
| 12195 | |
| 12196 | The INSERT_MODE flag determines whether locations may not, may, or |
| 12197 | shall be inserted now. See 'enum ugll_insert_mode' for more |
| 12198 | info. */ |
| 12199 | |
| 12200 | static void |
| 12201 | update_global_location_list (enum ugll_insert_mode insert_mode) |
| 12202 | { |
| 12203 | struct breakpoint *b; |
| 12204 | struct bp_location **locp, *loc; |
| 12205 | struct cleanup *cleanups; |
| 12206 | /* Last breakpoint location address that was marked for update. */ |
| 12207 | CORE_ADDR last_addr = 0; |
| 12208 | /* Last breakpoint location program space that was marked for update. */ |
| 12209 | int last_pspace_num = -1; |
| 12210 | |
| 12211 | /* Used in the duplicates detection below. When iterating over all |
| 12212 | bp_locations, points to the first bp_location of a given address. |
| 12213 | Breakpoints and watchpoints of different types are never |
| 12214 | duplicates of each other. Keep one pointer for each type of |
| 12215 | breakpoint/watchpoint, so we only need to loop over all locations |
| 12216 | once. */ |
| 12217 | struct bp_location *bp_loc_first; /* breakpoint */ |
| 12218 | struct bp_location *wp_loc_first; /* hardware watchpoint */ |
| 12219 | struct bp_location *awp_loc_first; /* access watchpoint */ |
| 12220 | struct bp_location *rwp_loc_first; /* read watchpoint */ |
| 12221 | |
| 12222 | /* Saved former bp_location array which we compare against the newly |
| 12223 | built bp_location from the current state of ALL_BREAKPOINTS. */ |
| 12224 | struct bp_location **old_location, **old_locp; |
| 12225 | unsigned old_location_count; |
| 12226 | |
| 12227 | old_location = bp_location; |
| 12228 | old_location_count = bp_location_count; |
| 12229 | bp_location = NULL; |
| 12230 | bp_location_count = 0; |
| 12231 | cleanups = make_cleanup (xfree, old_location); |
| 12232 | |
| 12233 | ALL_BREAKPOINTS (b) |
| 12234 | for (loc = b->loc; loc; loc = loc->next) |
| 12235 | bp_location_count++; |
| 12236 | |
| 12237 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); |
| 12238 | locp = bp_location; |
| 12239 | ALL_BREAKPOINTS (b) |
| 12240 | for (loc = b->loc; loc; loc = loc->next) |
| 12241 | *locp++ = loc; |
| 12242 | qsort (bp_location, bp_location_count, sizeof (*bp_location), |
| 12243 | bp_location_compare); |
| 12244 | |
| 12245 | bp_location_target_extensions_update (); |
| 12246 | |
| 12247 | /* Identify bp_location instances that are no longer present in the |
| 12248 | new list, and therefore should be freed. Note that it's not |
| 12249 | necessary that those locations should be removed from inferior -- |
| 12250 | if there's another location at the same address (previously |
| 12251 | marked as duplicate), we don't need to remove/insert the |
| 12252 | location. |
| 12253 | |
| 12254 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
| 12255 | and former bp_location array state respectively. */ |
| 12256 | |
| 12257 | locp = bp_location; |
| 12258 | for (old_locp = old_location; old_locp < old_location + old_location_count; |
| 12259 | old_locp++) |
| 12260 | { |
| 12261 | struct bp_location *old_loc = *old_locp; |
| 12262 | struct bp_location **loc2p; |
| 12263 | |
| 12264 | /* Tells if 'old_loc' is found among the new locations. If |
| 12265 | not, we have to free it. */ |
| 12266 | int found_object = 0; |
| 12267 | /* Tells if the location should remain inserted in the target. */ |
| 12268 | int keep_in_target = 0; |
| 12269 | int removed = 0; |
| 12270 | |
| 12271 | /* Skip LOCP entries which will definitely never be needed. |
| 12272 | Stop either at or being the one matching OLD_LOC. */ |
| 12273 | while (locp < bp_location + bp_location_count |
| 12274 | && (*locp)->address < old_loc->address) |
| 12275 | locp++; |
| 12276 | |
| 12277 | for (loc2p = locp; |
| 12278 | (loc2p < bp_location + bp_location_count |
| 12279 | && (*loc2p)->address == old_loc->address); |
| 12280 | loc2p++) |
| 12281 | { |
| 12282 | /* Check if this is a new/duplicated location or a duplicated |
| 12283 | location that had its condition modified. If so, we want to send |
| 12284 | its condition to the target if evaluation of conditions is taking |
| 12285 | place there. */ |
| 12286 | if ((*loc2p)->condition_changed == condition_modified |
| 12287 | && (last_addr != old_loc->address |
| 12288 | || last_pspace_num != old_loc->pspace->num)) |
| 12289 | { |
| 12290 | force_breakpoint_reinsertion (*loc2p); |
| 12291 | last_pspace_num = old_loc->pspace->num; |
| 12292 | } |
| 12293 | |
| 12294 | if (*loc2p == old_loc) |
| 12295 | found_object = 1; |
| 12296 | } |
| 12297 | |
| 12298 | /* We have already handled this address, update it so that we don't |
| 12299 | have to go through updates again. */ |
| 12300 | last_addr = old_loc->address; |
| 12301 | |
| 12302 | /* Target-side condition evaluation: Handle deleted locations. */ |
| 12303 | if (!found_object) |
| 12304 | force_breakpoint_reinsertion (old_loc); |
| 12305 | |
| 12306 | /* If this location is no longer present, and inserted, look if |
| 12307 | there's maybe a new location at the same address. If so, |
| 12308 | mark that one inserted, and don't remove this one. This is |
| 12309 | needed so that we don't have a time window where a breakpoint |
| 12310 | at certain location is not inserted. */ |
| 12311 | |
| 12312 | if (old_loc->inserted) |
| 12313 | { |
| 12314 | /* If the location is inserted now, we might have to remove |
| 12315 | it. */ |
| 12316 | |
| 12317 | if (found_object && should_be_inserted (old_loc)) |
| 12318 | { |
| 12319 | /* The location is still present in the location list, |
| 12320 | and still should be inserted. Don't do anything. */ |
| 12321 | keep_in_target = 1; |
| 12322 | } |
| 12323 | else |
| 12324 | { |
| 12325 | /* This location still exists, but it won't be kept in the |
| 12326 | target since it may have been disabled. We proceed to |
| 12327 | remove its target-side condition. */ |
| 12328 | |
| 12329 | /* The location is either no longer present, or got |
| 12330 | disabled. See if there's another location at the |
| 12331 | same address, in which case we don't need to remove |
| 12332 | this one from the target. */ |
| 12333 | |
| 12334 | /* OLD_LOC comes from existing struct breakpoint. */ |
| 12335 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
| 12336 | { |
| 12337 | for (loc2p = locp; |
| 12338 | (loc2p < bp_location + bp_location_count |
| 12339 | && (*loc2p)->address == old_loc->address); |
| 12340 | loc2p++) |
| 12341 | { |
| 12342 | struct bp_location *loc2 = *loc2p; |
| 12343 | |
| 12344 | if (breakpoint_locations_match (loc2, old_loc)) |
| 12345 | { |
| 12346 | /* Read watchpoint locations are switched to |
| 12347 | access watchpoints, if the former are not |
| 12348 | supported, but the latter are. */ |
| 12349 | if (is_hardware_watchpoint (old_loc->owner)) |
| 12350 | { |
| 12351 | gdb_assert (is_hardware_watchpoint (loc2->owner)); |
| 12352 | loc2->watchpoint_type = old_loc->watchpoint_type; |
| 12353 | } |
| 12354 | |
| 12355 | /* loc2 is a duplicated location. We need to check |
| 12356 | if it should be inserted in case it will be |
| 12357 | unduplicated. */ |
| 12358 | if (loc2 != old_loc |
| 12359 | && unduplicated_should_be_inserted (loc2)) |
| 12360 | { |
| 12361 | swap_insertion (old_loc, loc2); |
| 12362 | keep_in_target = 1; |
| 12363 | break; |
| 12364 | } |
| 12365 | } |
| 12366 | } |
| 12367 | } |
| 12368 | } |
| 12369 | |
| 12370 | if (!keep_in_target) |
| 12371 | { |
| 12372 | if (remove_breakpoint (old_loc, mark_uninserted)) |
| 12373 | { |
| 12374 | /* This is just about all we can do. We could keep |
| 12375 | this location on the global list, and try to |
| 12376 | remove it next time, but there's no particular |
| 12377 | reason why we will succeed next time. |
| 12378 | |
| 12379 | Note that at this point, old_loc->owner is still |
| 12380 | valid, as delete_breakpoint frees the breakpoint |
| 12381 | only after calling us. */ |
| 12382 | printf_filtered (_("warning: Error removing " |
| 12383 | "breakpoint %d\n"), |
| 12384 | old_loc->owner->number); |
| 12385 | } |
| 12386 | removed = 1; |
| 12387 | } |
| 12388 | } |
| 12389 | |
| 12390 | if (!found_object) |
| 12391 | { |
| 12392 | if (removed && target_is_non_stop_p () |
| 12393 | && need_moribund_for_location_type (old_loc)) |
| 12394 | { |
| 12395 | /* This location was removed from the target. In |
| 12396 | non-stop mode, a race condition is possible where |
| 12397 | we've removed a breakpoint, but stop events for that |
| 12398 | breakpoint are already queued and will arrive later. |
| 12399 | We apply an heuristic to be able to distinguish such |
| 12400 | SIGTRAPs from other random SIGTRAPs: we keep this |
| 12401 | breakpoint location for a bit, and will retire it |
| 12402 | after we see some number of events. The theory here |
| 12403 | is that reporting of events should, "on the average", |
| 12404 | be fair, so after a while we'll see events from all |
| 12405 | threads that have anything of interest, and no longer |
| 12406 | need to keep this breakpoint location around. We |
| 12407 | don't hold locations forever so to reduce chances of |
| 12408 | mistaking a non-breakpoint SIGTRAP for a breakpoint |
| 12409 | SIGTRAP. |
| 12410 | |
| 12411 | The heuristic failing can be disastrous on |
| 12412 | decr_pc_after_break targets. |
| 12413 | |
| 12414 | On decr_pc_after_break targets, like e.g., x86-linux, |
| 12415 | if we fail to recognize a late breakpoint SIGTRAP, |
| 12416 | because events_till_retirement has reached 0 too |
| 12417 | soon, we'll fail to do the PC adjustment, and report |
| 12418 | a random SIGTRAP to the user. When the user resumes |
| 12419 | the inferior, it will most likely immediately crash |
| 12420 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
| 12421 | corrupted, because of being resumed e.g., in the |
| 12422 | middle of a multi-byte instruction, or skipped a |
| 12423 | one-byte instruction. This was actually seen happen |
| 12424 | on native x86-linux, and should be less rare on |
| 12425 | targets that do not support new thread events, like |
| 12426 | remote, due to the heuristic depending on |
| 12427 | thread_count. |
| 12428 | |
| 12429 | Mistaking a random SIGTRAP for a breakpoint trap |
| 12430 | causes similar symptoms (PC adjustment applied when |
| 12431 | it shouldn't), but then again, playing with SIGTRAPs |
| 12432 | behind the debugger's back is asking for trouble. |
| 12433 | |
| 12434 | Since hardware watchpoint traps are always |
| 12435 | distinguishable from other traps, so we don't need to |
| 12436 | apply keep hardware watchpoint moribund locations |
| 12437 | around. We simply always ignore hardware watchpoint |
| 12438 | traps we can no longer explain. */ |
| 12439 | |
| 12440 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
| 12441 | old_loc->owner = NULL; |
| 12442 | |
| 12443 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
| 12444 | } |
| 12445 | else |
| 12446 | { |
| 12447 | old_loc->owner = NULL; |
| 12448 | decref_bp_location (&old_loc); |
| 12449 | } |
| 12450 | } |
| 12451 | } |
| 12452 | |
| 12453 | /* Rescan breakpoints at the same address and section, marking the |
| 12454 | first one as "first" and any others as "duplicates". This is so |
| 12455 | that the bpt instruction is only inserted once. If we have a |
| 12456 | permanent breakpoint at the same place as BPT, make that one the |
| 12457 | official one, and the rest as duplicates. Permanent breakpoints |
| 12458 | are sorted first for the same address. |
| 12459 | |
| 12460 | Do the same for hardware watchpoints, but also considering the |
| 12461 | watchpoint's type (regular/access/read) and length. */ |
| 12462 | |
| 12463 | bp_loc_first = NULL; |
| 12464 | wp_loc_first = NULL; |
| 12465 | awp_loc_first = NULL; |
| 12466 | rwp_loc_first = NULL; |
| 12467 | ALL_BP_LOCATIONS (loc, locp) |
| 12468 | { |
| 12469 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
| 12470 | non-NULL. */ |
| 12471 | struct bp_location **loc_first_p; |
| 12472 | b = loc->owner; |
| 12473 | |
| 12474 | if (!unduplicated_should_be_inserted (loc) |
| 12475 | || !breakpoint_address_is_meaningful (b) |
| 12476 | /* Don't detect duplicate for tracepoint locations because they are |
| 12477 | never duplicated. See the comments in field `duplicate' of |
| 12478 | `struct bp_location'. */ |
| 12479 | || is_tracepoint (b)) |
| 12480 | { |
| 12481 | /* Clear the condition modification flag. */ |
| 12482 | loc->condition_changed = condition_unchanged; |
| 12483 | continue; |
| 12484 | } |
| 12485 | |
| 12486 | if (b->type == bp_hardware_watchpoint) |
| 12487 | loc_first_p = &wp_loc_first; |
| 12488 | else if (b->type == bp_read_watchpoint) |
| 12489 | loc_first_p = &rwp_loc_first; |
| 12490 | else if (b->type == bp_access_watchpoint) |
| 12491 | loc_first_p = &awp_loc_first; |
| 12492 | else |
| 12493 | loc_first_p = &bp_loc_first; |
| 12494 | |
| 12495 | if (*loc_first_p == NULL |
| 12496 | || (overlay_debugging && loc->section != (*loc_first_p)->section) |
| 12497 | || !breakpoint_locations_match (loc, *loc_first_p)) |
| 12498 | { |
| 12499 | *loc_first_p = loc; |
| 12500 | loc->duplicate = 0; |
| 12501 | |
| 12502 | if (is_breakpoint (loc->owner) && loc->condition_changed) |
| 12503 | { |
| 12504 | loc->needs_update = 1; |
| 12505 | /* Clear the condition modification flag. */ |
| 12506 | loc->condition_changed = condition_unchanged; |
| 12507 | } |
| 12508 | continue; |
| 12509 | } |
| 12510 | |
| 12511 | |
| 12512 | /* This and the above ensure the invariant that the first location |
| 12513 | is not duplicated, and is the inserted one. |
| 12514 | All following are marked as duplicated, and are not inserted. */ |
| 12515 | if (loc->inserted) |
| 12516 | swap_insertion (loc, *loc_first_p); |
| 12517 | loc->duplicate = 1; |
| 12518 | |
| 12519 | /* Clear the condition modification flag. */ |
| 12520 | loc->condition_changed = condition_unchanged; |
| 12521 | } |
| 12522 | |
| 12523 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
| 12524 | { |
| 12525 | if (insert_mode != UGLL_DONT_INSERT) |
| 12526 | insert_breakpoint_locations (); |
| 12527 | else |
| 12528 | { |
| 12529 | /* Even though the caller told us to not insert new |
| 12530 | locations, we may still need to update conditions on the |
| 12531 | target's side of breakpoints that were already inserted |
| 12532 | if the target is evaluating breakpoint conditions. We |
| 12533 | only update conditions for locations that are marked |
| 12534 | "needs_update". */ |
| 12535 | update_inserted_breakpoint_locations (); |
| 12536 | } |
| 12537 | } |
| 12538 | |
| 12539 | if (insert_mode != UGLL_DONT_INSERT) |
| 12540 | download_tracepoint_locations (); |
| 12541 | |
| 12542 | do_cleanups (cleanups); |
| 12543 | } |
| 12544 | |
| 12545 | void |
| 12546 | breakpoint_retire_moribund (void) |
| 12547 | { |
| 12548 | struct bp_location *loc; |
| 12549 | int ix; |
| 12550 | |
| 12551 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
| 12552 | if (--(loc->events_till_retirement) == 0) |
| 12553 | { |
| 12554 | decref_bp_location (&loc); |
| 12555 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
| 12556 | --ix; |
| 12557 | } |
| 12558 | } |
| 12559 | |
| 12560 | static void |
| 12561 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
| 12562 | { |
| 12563 | |
| 12564 | TRY |
| 12565 | { |
| 12566 | update_global_location_list (insert_mode); |
| 12567 | } |
| 12568 | CATCH (e, RETURN_MASK_ERROR) |
| 12569 | { |
| 12570 | } |
| 12571 | END_CATCH |
| 12572 | } |
| 12573 | |
| 12574 | /* Clear BKP from a BPS. */ |
| 12575 | |
| 12576 | static void |
| 12577 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
| 12578 | { |
| 12579 | bpstat bs; |
| 12580 | |
| 12581 | for (bs = bps; bs; bs = bs->next) |
| 12582 | if (bs->breakpoint_at == bpt) |
| 12583 | { |
| 12584 | bs->breakpoint_at = NULL; |
| 12585 | bs->old_val = NULL; |
| 12586 | /* bs->commands will be freed later. */ |
| 12587 | } |
| 12588 | } |
| 12589 | |
| 12590 | /* Callback for iterate_over_threads. */ |
| 12591 | static int |
| 12592 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
| 12593 | { |
| 12594 | struct breakpoint *bpt = data; |
| 12595 | |
| 12596 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
| 12597 | return 0; |
| 12598 | } |
| 12599 | |
| 12600 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention |
| 12601 | callbacks. */ |
| 12602 | |
| 12603 | static void |
| 12604 | say_where (struct breakpoint *b) |
| 12605 | { |
| 12606 | struct value_print_options opts; |
| 12607 | |
| 12608 | get_user_print_options (&opts); |
| 12609 | |
| 12610 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
| 12611 | single string. */ |
| 12612 | if (b->loc == NULL) |
| 12613 | { |
| 12614 | /* For pending locations, the output differs slightly based |
| 12615 | on b->extra_string. If this is non-NULL, it contains either |
| 12616 | a condition or dprintf arguments. */ |
| 12617 | if (b->extra_string == NULL) |
| 12618 | { |
| 12619 | printf_filtered (_(" (%s) pending."), |
| 12620 | event_location_to_string (b->location)); |
| 12621 | } |
| 12622 | else if (b->type == bp_dprintf) |
| 12623 | { |
| 12624 | printf_filtered (_(" (%s,%s) pending."), |
| 12625 | event_location_to_string (b->location), |
| 12626 | b->extra_string); |
| 12627 | } |
| 12628 | else |
| 12629 | { |
| 12630 | printf_filtered (_(" (%s %s) pending."), |
| 12631 | event_location_to_string (b->location), |
| 12632 | b->extra_string); |
| 12633 | } |
| 12634 | } |
| 12635 | else |
| 12636 | { |
| 12637 | if (opts.addressprint || b->loc->symtab == NULL) |
| 12638 | { |
| 12639 | printf_filtered (" at "); |
| 12640 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
| 12641 | gdb_stdout); |
| 12642 | } |
| 12643 | if (b->loc->symtab != NULL) |
| 12644 | { |
| 12645 | /* If there is a single location, we can print the location |
| 12646 | more nicely. */ |
| 12647 | if (b->loc->next == NULL) |
| 12648 | printf_filtered (": file %s, line %d.", |
| 12649 | symtab_to_filename_for_display (b->loc->symtab), |
| 12650 | b->loc->line_number); |
| 12651 | else |
| 12652 | /* This is not ideal, but each location may have a |
| 12653 | different file name, and this at least reflects the |
| 12654 | real situation somewhat. */ |
| 12655 | printf_filtered (": %s.", |
| 12656 | event_location_to_string (b->location)); |
| 12657 | } |
| 12658 | |
| 12659 | if (b->loc->next) |
| 12660 | { |
| 12661 | struct bp_location *loc = b->loc; |
| 12662 | int n = 0; |
| 12663 | for (; loc; loc = loc->next) |
| 12664 | ++n; |
| 12665 | printf_filtered (" (%d locations)", n); |
| 12666 | } |
| 12667 | } |
| 12668 | } |
| 12669 | |
| 12670 | /* Default bp_location_ops methods. */ |
| 12671 | |
| 12672 | static void |
| 12673 | bp_location_dtor (struct bp_location *self) |
| 12674 | { |
| 12675 | xfree (self->cond); |
| 12676 | if (self->cond_bytecode) |
| 12677 | free_agent_expr (self->cond_bytecode); |
| 12678 | xfree (self->function_name); |
| 12679 | |
| 12680 | VEC_free (agent_expr_p, self->target_info.conditions); |
| 12681 | VEC_free (agent_expr_p, self->target_info.tcommands); |
| 12682 | } |
| 12683 | |
| 12684 | static const struct bp_location_ops bp_location_ops = |
| 12685 | { |
| 12686 | bp_location_dtor |
| 12687 | }; |
| 12688 | |
| 12689 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
| 12690 | inherit from. */ |
| 12691 | |
| 12692 | static void |
| 12693 | base_breakpoint_dtor (struct breakpoint *self) |
| 12694 | { |
| 12695 | decref_counted_command_line (&self->commands); |
| 12696 | xfree (self->cond_string); |
| 12697 | xfree (self->extra_string); |
| 12698 | xfree (self->filter); |
| 12699 | delete_event_location (self->location); |
| 12700 | delete_event_location (self->location_range_end); |
| 12701 | } |
| 12702 | |
| 12703 | static struct bp_location * |
| 12704 | base_breakpoint_allocate_location (struct breakpoint *self) |
| 12705 | { |
| 12706 | struct bp_location *loc; |
| 12707 | |
| 12708 | loc = XNEW (struct bp_location); |
| 12709 | init_bp_location (loc, &bp_location_ops, self); |
| 12710 | return loc; |
| 12711 | } |
| 12712 | |
| 12713 | static void |
| 12714 | base_breakpoint_re_set (struct breakpoint *b) |
| 12715 | { |
| 12716 | /* Nothing to re-set. */ |
| 12717 | } |
| 12718 | |
| 12719 | #define internal_error_pure_virtual_called() \ |
| 12720 | gdb_assert_not_reached ("pure virtual function called") |
| 12721 | |
| 12722 | static int |
| 12723 | base_breakpoint_insert_location (struct bp_location *bl) |
| 12724 | { |
| 12725 | internal_error_pure_virtual_called (); |
| 12726 | } |
| 12727 | |
| 12728 | static int |
| 12729 | base_breakpoint_remove_location (struct bp_location *bl) |
| 12730 | { |
| 12731 | internal_error_pure_virtual_called (); |
| 12732 | } |
| 12733 | |
| 12734 | static int |
| 12735 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, |
| 12736 | struct address_space *aspace, |
| 12737 | CORE_ADDR bp_addr, |
| 12738 | const struct target_waitstatus *ws) |
| 12739 | { |
| 12740 | internal_error_pure_virtual_called (); |
| 12741 | } |
| 12742 | |
| 12743 | static void |
| 12744 | base_breakpoint_check_status (bpstat bs) |
| 12745 | { |
| 12746 | /* Always stop. */ |
| 12747 | } |
| 12748 | |
| 12749 | /* A "works_in_software_mode" breakpoint_ops method that just internal |
| 12750 | errors. */ |
| 12751 | |
| 12752 | static int |
| 12753 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) |
| 12754 | { |
| 12755 | internal_error_pure_virtual_called (); |
| 12756 | } |
| 12757 | |
| 12758 | /* A "resources_needed" breakpoint_ops method that just internal |
| 12759 | errors. */ |
| 12760 | |
| 12761 | static int |
| 12762 | base_breakpoint_resources_needed (const struct bp_location *bl) |
| 12763 | { |
| 12764 | internal_error_pure_virtual_called (); |
| 12765 | } |
| 12766 | |
| 12767 | static enum print_stop_action |
| 12768 | base_breakpoint_print_it (bpstat bs) |
| 12769 | { |
| 12770 | internal_error_pure_virtual_called (); |
| 12771 | } |
| 12772 | |
| 12773 | static void |
| 12774 | base_breakpoint_print_one_detail (const struct breakpoint *self, |
| 12775 | struct ui_out *uiout) |
| 12776 | { |
| 12777 | /* nothing */ |
| 12778 | } |
| 12779 | |
| 12780 | static void |
| 12781 | base_breakpoint_print_mention (struct breakpoint *b) |
| 12782 | { |
| 12783 | internal_error_pure_virtual_called (); |
| 12784 | } |
| 12785 | |
| 12786 | static void |
| 12787 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) |
| 12788 | { |
| 12789 | internal_error_pure_virtual_called (); |
| 12790 | } |
| 12791 | |
| 12792 | static void |
| 12793 | base_breakpoint_create_sals_from_location |
| 12794 | (const struct event_location *location, |
| 12795 | struct linespec_result *canonical, |
| 12796 | enum bptype type_wanted) |
| 12797 | { |
| 12798 | internal_error_pure_virtual_called (); |
| 12799 | } |
| 12800 | |
| 12801 | static void |
| 12802 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12803 | struct linespec_result *c, |
| 12804 | char *cond_string, |
| 12805 | char *extra_string, |
| 12806 | enum bptype type_wanted, |
| 12807 | enum bpdisp disposition, |
| 12808 | int thread, |
| 12809 | int task, int ignore_count, |
| 12810 | const struct breakpoint_ops *o, |
| 12811 | int from_tty, int enabled, |
| 12812 | int internal, unsigned flags) |
| 12813 | { |
| 12814 | internal_error_pure_virtual_called (); |
| 12815 | } |
| 12816 | |
| 12817 | static void |
| 12818 | base_breakpoint_decode_location (struct breakpoint *b, |
| 12819 | const struct event_location *location, |
| 12820 | struct symtabs_and_lines *sals) |
| 12821 | { |
| 12822 | internal_error_pure_virtual_called (); |
| 12823 | } |
| 12824 | |
| 12825 | /* The default 'explains_signal' method. */ |
| 12826 | |
| 12827 | static int |
| 12828 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
| 12829 | { |
| 12830 | return 1; |
| 12831 | } |
| 12832 | |
| 12833 | /* The default "after_condition_true" method. */ |
| 12834 | |
| 12835 | static void |
| 12836 | base_breakpoint_after_condition_true (struct bpstats *bs) |
| 12837 | { |
| 12838 | /* Nothing to do. */ |
| 12839 | } |
| 12840 | |
| 12841 | struct breakpoint_ops base_breakpoint_ops = |
| 12842 | { |
| 12843 | base_breakpoint_dtor, |
| 12844 | base_breakpoint_allocate_location, |
| 12845 | base_breakpoint_re_set, |
| 12846 | base_breakpoint_insert_location, |
| 12847 | base_breakpoint_remove_location, |
| 12848 | base_breakpoint_breakpoint_hit, |
| 12849 | base_breakpoint_check_status, |
| 12850 | base_breakpoint_resources_needed, |
| 12851 | base_breakpoint_works_in_software_mode, |
| 12852 | base_breakpoint_print_it, |
| 12853 | NULL, |
| 12854 | base_breakpoint_print_one_detail, |
| 12855 | base_breakpoint_print_mention, |
| 12856 | base_breakpoint_print_recreate, |
| 12857 | base_breakpoint_create_sals_from_location, |
| 12858 | base_breakpoint_create_breakpoints_sal, |
| 12859 | base_breakpoint_decode_location, |
| 12860 | base_breakpoint_explains_signal, |
| 12861 | base_breakpoint_after_condition_true, |
| 12862 | }; |
| 12863 | |
| 12864 | /* Default breakpoint_ops methods. */ |
| 12865 | |
| 12866 | static void |
| 12867 | bkpt_re_set (struct breakpoint *b) |
| 12868 | { |
| 12869 | /* FIXME: is this still reachable? */ |
| 12870 | if (event_location_empty_p (b->location)) |
| 12871 | { |
| 12872 | /* Anything without a location can't be re-set. */ |
| 12873 | delete_breakpoint (b); |
| 12874 | return; |
| 12875 | } |
| 12876 | |
| 12877 | breakpoint_re_set_default (b); |
| 12878 | } |
| 12879 | |
| 12880 | static int |
| 12881 | bkpt_insert_location (struct bp_location *bl) |
| 12882 | { |
| 12883 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 12884 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
| 12885 | else |
| 12886 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
| 12887 | } |
| 12888 | |
| 12889 | static int |
| 12890 | bkpt_remove_location (struct bp_location *bl) |
| 12891 | { |
| 12892 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 12893 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); |
| 12894 | else |
| 12895 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
| 12896 | } |
| 12897 | |
| 12898 | static int |
| 12899 | bkpt_breakpoint_hit (const struct bp_location *bl, |
| 12900 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 12901 | const struct target_waitstatus *ws) |
| 12902 | { |
| 12903 | if (ws->kind != TARGET_WAITKIND_STOPPED |
| 12904 | || ws->value.sig != GDB_SIGNAL_TRAP) |
| 12905 | return 0; |
| 12906 | |
| 12907 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 12908 | aspace, bp_addr)) |
| 12909 | return 0; |
| 12910 | |
| 12911 | if (overlay_debugging /* unmapped overlay section */ |
| 12912 | && section_is_overlay (bl->section) |
| 12913 | && !section_is_mapped (bl->section)) |
| 12914 | return 0; |
| 12915 | |
| 12916 | return 1; |
| 12917 | } |
| 12918 | |
| 12919 | static int |
| 12920 | dprintf_breakpoint_hit (const struct bp_location *bl, |
| 12921 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 12922 | const struct target_waitstatus *ws) |
| 12923 | { |
| 12924 | if (dprintf_style == dprintf_style_agent |
| 12925 | && target_can_run_breakpoint_commands ()) |
| 12926 | { |
| 12927 | /* An agent-style dprintf never causes a stop. If we see a trap |
| 12928 | for this address it must be for a breakpoint that happens to |
| 12929 | be set at the same address. */ |
| 12930 | return 0; |
| 12931 | } |
| 12932 | |
| 12933 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); |
| 12934 | } |
| 12935 | |
| 12936 | static int |
| 12937 | bkpt_resources_needed (const struct bp_location *bl) |
| 12938 | { |
| 12939 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); |
| 12940 | |
| 12941 | return 1; |
| 12942 | } |
| 12943 | |
| 12944 | static enum print_stop_action |
| 12945 | bkpt_print_it (bpstat bs) |
| 12946 | { |
| 12947 | struct breakpoint *b; |
| 12948 | const struct bp_location *bl; |
| 12949 | int bp_temp; |
| 12950 | struct ui_out *uiout = current_uiout; |
| 12951 | |
| 12952 | gdb_assert (bs->bp_location_at != NULL); |
| 12953 | |
| 12954 | bl = bs->bp_location_at; |
| 12955 | b = bs->breakpoint_at; |
| 12956 | |
| 12957 | bp_temp = b->disposition == disp_del; |
| 12958 | if (bl->address != bl->requested_address) |
| 12959 | breakpoint_adjustment_warning (bl->requested_address, |
| 12960 | bl->address, |
| 12961 | b->number, 1); |
| 12962 | annotate_breakpoint (b->number); |
| 12963 | if (bp_temp) |
| 12964 | ui_out_text (uiout, "\nTemporary breakpoint "); |
| 12965 | else |
| 12966 | ui_out_text (uiout, "\nBreakpoint "); |
| 12967 | if (ui_out_is_mi_like_p (uiout)) |
| 12968 | { |
| 12969 | ui_out_field_string (uiout, "reason", |
| 12970 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 12971 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
| 12972 | } |
| 12973 | ui_out_field_int (uiout, "bkptno", b->number); |
| 12974 | ui_out_text (uiout, ", "); |
| 12975 | |
| 12976 | return PRINT_SRC_AND_LOC; |
| 12977 | } |
| 12978 | |
| 12979 | static void |
| 12980 | bkpt_print_mention (struct breakpoint *b) |
| 12981 | { |
| 12982 | if (ui_out_is_mi_like_p (current_uiout)) |
| 12983 | return; |
| 12984 | |
| 12985 | switch (b->type) |
| 12986 | { |
| 12987 | case bp_breakpoint: |
| 12988 | case bp_gnu_ifunc_resolver: |
| 12989 | if (b->disposition == disp_del) |
| 12990 | printf_filtered (_("Temporary breakpoint")); |
| 12991 | else |
| 12992 | printf_filtered (_("Breakpoint")); |
| 12993 | printf_filtered (_(" %d"), b->number); |
| 12994 | if (b->type == bp_gnu_ifunc_resolver) |
| 12995 | printf_filtered (_(" at gnu-indirect-function resolver")); |
| 12996 | break; |
| 12997 | case bp_hardware_breakpoint: |
| 12998 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
| 12999 | break; |
| 13000 | case bp_dprintf: |
| 13001 | printf_filtered (_("Dprintf %d"), b->number); |
| 13002 | break; |
| 13003 | } |
| 13004 | |
| 13005 | say_where (b); |
| 13006 | } |
| 13007 | |
| 13008 | static void |
| 13009 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
| 13010 | { |
| 13011 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) |
| 13012 | fprintf_unfiltered (fp, "tbreak"); |
| 13013 | else if (tp->type == bp_breakpoint) |
| 13014 | fprintf_unfiltered (fp, "break"); |
| 13015 | else if (tp->type == bp_hardware_breakpoint |
| 13016 | && tp->disposition == disp_del) |
| 13017 | fprintf_unfiltered (fp, "thbreak"); |
| 13018 | else if (tp->type == bp_hardware_breakpoint) |
| 13019 | fprintf_unfiltered (fp, "hbreak"); |
| 13020 | else |
| 13021 | internal_error (__FILE__, __LINE__, |
| 13022 | _("unhandled breakpoint type %d"), (int) tp->type); |
| 13023 | |
| 13024 | fprintf_unfiltered (fp, " %s", |
| 13025 | event_location_to_string (tp->location)); |
| 13026 | |
| 13027 | /* Print out extra_string if this breakpoint is pending. It might |
| 13028 | contain, for example, conditions that were set by the user. */ |
| 13029 | if (tp->loc == NULL && tp->extra_string != NULL) |
| 13030 | fprintf_unfiltered (fp, " %s", tp->extra_string); |
| 13031 | |
| 13032 | print_recreate_thread (tp, fp); |
| 13033 | } |
| 13034 | |
| 13035 | static void |
| 13036 | bkpt_create_sals_from_location (const struct event_location *location, |
| 13037 | struct linespec_result *canonical, |
| 13038 | enum bptype type_wanted) |
| 13039 | { |
| 13040 | create_sals_from_location_default (location, canonical, type_wanted); |
| 13041 | } |
| 13042 | |
| 13043 | static void |
| 13044 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 13045 | struct linespec_result *canonical, |
| 13046 | char *cond_string, |
| 13047 | char *extra_string, |
| 13048 | enum bptype type_wanted, |
| 13049 | enum bpdisp disposition, |
| 13050 | int thread, |
| 13051 | int task, int ignore_count, |
| 13052 | const struct breakpoint_ops *ops, |
| 13053 | int from_tty, int enabled, |
| 13054 | int internal, unsigned flags) |
| 13055 | { |
| 13056 | create_breakpoints_sal_default (gdbarch, canonical, |
| 13057 | cond_string, extra_string, |
| 13058 | type_wanted, |
| 13059 | disposition, thread, task, |
| 13060 | ignore_count, ops, from_tty, |
| 13061 | enabled, internal, flags); |
| 13062 | } |
| 13063 | |
| 13064 | static void |
| 13065 | bkpt_decode_location (struct breakpoint *b, |
| 13066 | const struct event_location *location, |
| 13067 | struct symtabs_and_lines *sals) |
| 13068 | { |
| 13069 | decode_location_default (b, location, sals); |
| 13070 | } |
| 13071 | |
| 13072 | /* Virtual table for internal breakpoints. */ |
| 13073 | |
| 13074 | static void |
| 13075 | internal_bkpt_re_set (struct breakpoint *b) |
| 13076 | { |
| 13077 | switch (b->type) |
| 13078 | { |
| 13079 | /* Delete overlay event and longjmp master breakpoints; they |
| 13080 | will be reset later by breakpoint_re_set. */ |
| 13081 | case bp_overlay_event: |
| 13082 | case bp_longjmp_master: |
| 13083 | case bp_std_terminate_master: |
| 13084 | case bp_exception_master: |
| 13085 | delete_breakpoint (b); |
| 13086 | break; |
| 13087 | |
| 13088 | /* This breakpoint is special, it's set up when the inferior |
| 13089 | starts and we really don't want to touch it. */ |
| 13090 | case bp_shlib_event: |
| 13091 | |
| 13092 | /* Like bp_shlib_event, this breakpoint type is special. Once |
| 13093 | it is set up, we do not want to touch it. */ |
| 13094 | case bp_thread_event: |
| 13095 | break; |
| 13096 | } |
| 13097 | } |
| 13098 | |
| 13099 | static void |
| 13100 | internal_bkpt_check_status (bpstat bs) |
| 13101 | { |
| 13102 | if (bs->breakpoint_at->type == bp_shlib_event) |
| 13103 | { |
| 13104 | /* If requested, stop when the dynamic linker notifies GDB of |
| 13105 | events. This allows the user to get control and place |
| 13106 | breakpoints in initializer routines for dynamically loaded |
| 13107 | objects (among other things). */ |
| 13108 | bs->stop = stop_on_solib_events; |
| 13109 | bs->print = stop_on_solib_events; |
| 13110 | } |
| 13111 | else |
| 13112 | bs->stop = 0; |
| 13113 | } |
| 13114 | |
| 13115 | static enum print_stop_action |
| 13116 | internal_bkpt_print_it (bpstat bs) |
| 13117 | { |
| 13118 | struct breakpoint *b; |
| 13119 | |
| 13120 | b = bs->breakpoint_at; |
| 13121 | |
| 13122 | switch (b->type) |
| 13123 | { |
| 13124 | case bp_shlib_event: |
| 13125 | /* Did we stop because the user set the stop_on_solib_events |
| 13126 | variable? (If so, we report this as a generic, "Stopped due |
| 13127 | to shlib event" message.) */ |
| 13128 | print_solib_event (0); |
| 13129 | break; |
| 13130 | |
| 13131 | case bp_thread_event: |
| 13132 | /* Not sure how we will get here. |
| 13133 | GDB should not stop for these breakpoints. */ |
| 13134 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
| 13135 | break; |
| 13136 | |
| 13137 | case bp_overlay_event: |
| 13138 | /* By analogy with the thread event, GDB should not stop for these. */ |
| 13139 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
| 13140 | break; |
| 13141 | |
| 13142 | case bp_longjmp_master: |
| 13143 | /* These should never be enabled. */ |
| 13144 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); |
| 13145 | break; |
| 13146 | |
| 13147 | case bp_std_terminate_master: |
| 13148 | /* These should never be enabled. */ |
| 13149 | printf_filtered (_("std::terminate Master Breakpoint: " |
| 13150 | "gdb should not stop!\n")); |
| 13151 | break; |
| 13152 | |
| 13153 | case bp_exception_master: |
| 13154 | /* These should never be enabled. */ |
| 13155 | printf_filtered (_("Exception Master Breakpoint: " |
| 13156 | "gdb should not stop!\n")); |
| 13157 | break; |
| 13158 | } |
| 13159 | |
| 13160 | return PRINT_NOTHING; |
| 13161 | } |
| 13162 | |
| 13163 | static void |
| 13164 | internal_bkpt_print_mention (struct breakpoint *b) |
| 13165 | { |
| 13166 | /* Nothing to mention. These breakpoints are internal. */ |
| 13167 | } |
| 13168 | |
| 13169 | /* Virtual table for momentary breakpoints */ |
| 13170 | |
| 13171 | static void |
| 13172 | momentary_bkpt_re_set (struct breakpoint *b) |
| 13173 | { |
| 13174 | /* Keep temporary breakpoints, which can be encountered when we step |
| 13175 | over a dlopen call and solib_add is resetting the breakpoints. |
| 13176 | Otherwise these should have been blown away via the cleanup chain |
| 13177 | or by breakpoint_init_inferior when we rerun the executable. */ |
| 13178 | } |
| 13179 | |
| 13180 | static void |
| 13181 | momentary_bkpt_check_status (bpstat bs) |
| 13182 | { |
| 13183 | /* Nothing. The point of these breakpoints is causing a stop. */ |
| 13184 | } |
| 13185 | |
| 13186 | static enum print_stop_action |
| 13187 | momentary_bkpt_print_it (bpstat bs) |
| 13188 | { |
| 13189 | struct ui_out *uiout = current_uiout; |
| 13190 | |
| 13191 | if (ui_out_is_mi_like_p (uiout)) |
| 13192 | { |
| 13193 | struct breakpoint *b = bs->breakpoint_at; |
| 13194 | |
| 13195 | switch (b->type) |
| 13196 | { |
| 13197 | case bp_finish: |
| 13198 | ui_out_field_string |
| 13199 | (uiout, "reason", |
| 13200 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); |
| 13201 | break; |
| 13202 | |
| 13203 | case bp_until: |
| 13204 | ui_out_field_string |
| 13205 | (uiout, "reason", |
| 13206 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); |
| 13207 | break; |
| 13208 | } |
| 13209 | } |
| 13210 | |
| 13211 | return PRINT_UNKNOWN; |
| 13212 | } |
| 13213 | |
| 13214 | static void |
| 13215 | momentary_bkpt_print_mention (struct breakpoint *b) |
| 13216 | { |
| 13217 | /* Nothing to mention. These breakpoints are internal. */ |
| 13218 | } |
| 13219 | |
| 13220 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
| 13221 | |
| 13222 | It gets cleared already on the removal of the first one of such placed |
| 13223 | breakpoints. This is OK as they get all removed altogether. */ |
| 13224 | |
| 13225 | static void |
| 13226 | longjmp_bkpt_dtor (struct breakpoint *self) |
| 13227 | { |
| 13228 | struct thread_info *tp = find_thread_id (self->thread); |
| 13229 | |
| 13230 | if (tp) |
| 13231 | tp->initiating_frame = null_frame_id; |
| 13232 | |
| 13233 | momentary_breakpoint_ops.dtor (self); |
| 13234 | } |
| 13235 | |
| 13236 | /* Specific methods for probe breakpoints. */ |
| 13237 | |
| 13238 | static int |
| 13239 | bkpt_probe_insert_location (struct bp_location *bl) |
| 13240 | { |
| 13241 | int v = bkpt_insert_location (bl); |
| 13242 | |
| 13243 | if (v == 0) |
| 13244 | { |
| 13245 | /* The insertion was successful, now let's set the probe's semaphore |
| 13246 | if needed. */ |
| 13247 | if (bl->probe.probe->pops->set_semaphore != NULL) |
| 13248 | bl->probe.probe->pops->set_semaphore (bl->probe.probe, |
| 13249 | bl->probe.objfile, |
| 13250 | bl->gdbarch); |
| 13251 | } |
| 13252 | |
| 13253 | return v; |
| 13254 | } |
| 13255 | |
| 13256 | static int |
| 13257 | bkpt_probe_remove_location (struct bp_location *bl) |
| 13258 | { |
| 13259 | /* Let's clear the semaphore before removing the location. */ |
| 13260 | if (bl->probe.probe->pops->clear_semaphore != NULL) |
| 13261 | bl->probe.probe->pops->clear_semaphore (bl->probe.probe, |
| 13262 | bl->probe.objfile, |
| 13263 | bl->gdbarch); |
| 13264 | |
| 13265 | return bkpt_remove_location (bl); |
| 13266 | } |
| 13267 | |
| 13268 | static void |
| 13269 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
| 13270 | struct linespec_result *canonical, |
| 13271 | enum bptype type_wanted) |
| 13272 | { |
| 13273 | struct linespec_sals lsal; |
| 13274 | |
| 13275 | lsal.sals = parse_probes (location, canonical); |
| 13276 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
| 13277 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
| 13278 | } |
| 13279 | |
| 13280 | static void |
| 13281 | bkpt_probe_decode_location (struct breakpoint *b, |
| 13282 | const struct event_location *location, |
| 13283 | struct symtabs_and_lines *sals) |
| 13284 | { |
| 13285 | *sals = parse_probes (location, NULL); |
| 13286 | if (!sals->sals) |
| 13287 | error (_("probe not found")); |
| 13288 | } |
| 13289 | |
| 13290 | /* The breakpoint_ops structure to be used in tracepoints. */ |
| 13291 | |
| 13292 | static void |
| 13293 | tracepoint_re_set (struct breakpoint *b) |
| 13294 | { |
| 13295 | breakpoint_re_set_default (b); |
| 13296 | } |
| 13297 | |
| 13298 | static int |
| 13299 | tracepoint_breakpoint_hit (const struct bp_location *bl, |
| 13300 | struct address_space *aspace, CORE_ADDR bp_addr, |
| 13301 | const struct target_waitstatus *ws) |
| 13302 | { |
| 13303 | /* By definition, the inferior does not report stops at |
| 13304 | tracepoints. */ |
| 13305 | return 0; |
| 13306 | } |
| 13307 | |
| 13308 | static void |
| 13309 | tracepoint_print_one_detail (const struct breakpoint *self, |
| 13310 | struct ui_out *uiout) |
| 13311 | { |
| 13312 | struct tracepoint *tp = (struct tracepoint *) self; |
| 13313 | if (tp->static_trace_marker_id) |
| 13314 | { |
| 13315 | gdb_assert (self->type == bp_static_tracepoint); |
| 13316 | |
| 13317 | ui_out_text (uiout, "\tmarker id is "); |
| 13318 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", |
| 13319 | tp->static_trace_marker_id); |
| 13320 | ui_out_text (uiout, "\n"); |
| 13321 | } |
| 13322 | } |
| 13323 | |
| 13324 | static void |
| 13325 | tracepoint_print_mention (struct breakpoint *b) |
| 13326 | { |
| 13327 | if (ui_out_is_mi_like_p (current_uiout)) |
| 13328 | return; |
| 13329 | |
| 13330 | switch (b->type) |
| 13331 | { |
| 13332 | case bp_tracepoint: |
| 13333 | printf_filtered (_("Tracepoint")); |
| 13334 | printf_filtered (_(" %d"), b->number); |
| 13335 | break; |
| 13336 | case bp_fast_tracepoint: |
| 13337 | printf_filtered (_("Fast tracepoint")); |
| 13338 | printf_filtered (_(" %d"), b->number); |
| 13339 | break; |
| 13340 | case bp_static_tracepoint: |
| 13341 | printf_filtered (_("Static tracepoint")); |
| 13342 | printf_filtered (_(" %d"), b->number); |
| 13343 | break; |
| 13344 | default: |
| 13345 | internal_error (__FILE__, __LINE__, |
| 13346 | _("unhandled tracepoint type %d"), (int) b->type); |
| 13347 | } |
| 13348 | |
| 13349 | say_where (b); |
| 13350 | } |
| 13351 | |
| 13352 | static void |
| 13353 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
| 13354 | { |
| 13355 | struct tracepoint *tp = (struct tracepoint *) self; |
| 13356 | |
| 13357 | if (self->type == bp_fast_tracepoint) |
| 13358 | fprintf_unfiltered (fp, "ftrace"); |
| 13359 | if (self->type == bp_static_tracepoint) |
| 13360 | fprintf_unfiltered (fp, "strace"); |
| 13361 | else if (self->type == bp_tracepoint) |
| 13362 | fprintf_unfiltered (fp, "trace"); |
| 13363 | else |
| 13364 | internal_error (__FILE__, __LINE__, |
| 13365 | _("unhandled tracepoint type %d"), (int) self->type); |
| 13366 | |
| 13367 | fprintf_unfiltered (fp, " %s", |
| 13368 | event_location_to_string (self->location)); |
| 13369 | print_recreate_thread (self, fp); |
| 13370 | |
| 13371 | if (tp->pass_count) |
| 13372 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
| 13373 | } |
| 13374 | |
| 13375 | static void |
| 13376 | tracepoint_create_sals_from_location (const struct event_location *location, |
| 13377 | struct linespec_result *canonical, |
| 13378 | enum bptype type_wanted) |
| 13379 | { |
| 13380 | create_sals_from_location_default (location, canonical, type_wanted); |
| 13381 | } |
| 13382 | |
| 13383 | static void |
| 13384 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 13385 | struct linespec_result *canonical, |
| 13386 | char *cond_string, |
| 13387 | char *extra_string, |
| 13388 | enum bptype type_wanted, |
| 13389 | enum bpdisp disposition, |
| 13390 | int thread, |
| 13391 | int task, int ignore_count, |
| 13392 | const struct breakpoint_ops *ops, |
| 13393 | int from_tty, int enabled, |
| 13394 | int internal, unsigned flags) |
| 13395 | { |
| 13396 | create_breakpoints_sal_default (gdbarch, canonical, |
| 13397 | cond_string, extra_string, |
| 13398 | type_wanted, |
| 13399 | disposition, thread, task, |
| 13400 | ignore_count, ops, from_tty, |
| 13401 | enabled, internal, flags); |
| 13402 | } |
| 13403 | |
| 13404 | static void |
| 13405 | tracepoint_decode_location (struct breakpoint *b, |
| 13406 | const struct event_location *location, |
| 13407 | struct symtabs_and_lines *sals) |
| 13408 | { |
| 13409 | decode_location_default (b, location, sals); |
| 13410 | } |
| 13411 | |
| 13412 | struct breakpoint_ops tracepoint_breakpoint_ops; |
| 13413 | |
| 13414 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
| 13415 | static probe. */ |
| 13416 | |
| 13417 | static void |
| 13418 | tracepoint_probe_create_sals_from_location |
| 13419 | (const struct event_location *location, |
| 13420 | struct linespec_result *canonical, |
| 13421 | enum bptype type_wanted) |
| 13422 | { |
| 13423 | /* We use the same method for breakpoint on probes. */ |
| 13424 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
| 13425 | } |
| 13426 | |
| 13427 | static void |
| 13428 | tracepoint_probe_decode_location (struct breakpoint *b, |
| 13429 | const struct event_location *location, |
| 13430 | struct symtabs_and_lines *sals) |
| 13431 | { |
| 13432 | /* We use the same method for breakpoint on probes. */ |
| 13433 | bkpt_probe_decode_location (b, location, sals); |
| 13434 | } |
| 13435 | |
| 13436 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; |
| 13437 | |
| 13438 | /* Dprintf breakpoint_ops methods. */ |
| 13439 | |
| 13440 | static void |
| 13441 | dprintf_re_set (struct breakpoint *b) |
| 13442 | { |
| 13443 | breakpoint_re_set_default (b); |
| 13444 | |
| 13445 | /* extra_string should never be non-NULL for dprintf. */ |
| 13446 | gdb_assert (b->extra_string != NULL); |
| 13447 | |
| 13448 | /* 1 - connect to target 1, that can run breakpoint commands. |
| 13449 | 2 - create a dprintf, which resolves fine. |
| 13450 | 3 - disconnect from target 1 |
| 13451 | 4 - connect to target 2, that can NOT run breakpoint commands. |
| 13452 | |
| 13453 | After steps #3/#4, you'll want the dprintf command list to |
| 13454 | be updated, because target 1 and 2 may well return different |
| 13455 | answers for target_can_run_breakpoint_commands(). |
| 13456 | Given absence of finer grained resetting, we get to do |
| 13457 | it all the time. */ |
| 13458 | if (b->extra_string != NULL) |
| 13459 | update_dprintf_command_list (b); |
| 13460 | } |
| 13461 | |
| 13462 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
| 13463 | |
| 13464 | static void |
| 13465 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
| 13466 | { |
| 13467 | fprintf_unfiltered (fp, "dprintf %s,%s", |
| 13468 | event_location_to_string (tp->location), |
| 13469 | tp->extra_string); |
| 13470 | print_recreate_thread (tp, fp); |
| 13471 | } |
| 13472 | |
| 13473 | /* Implement the "after_condition_true" breakpoint_ops method for |
| 13474 | dprintf. |
| 13475 | |
| 13476 | dprintf's are implemented with regular commands in their command |
| 13477 | list, but we run the commands here instead of before presenting the |
| 13478 | stop to the user, as dprintf's don't actually cause a stop. This |
| 13479 | also makes it so that the commands of multiple dprintfs at the same |
| 13480 | address are all handled. */ |
| 13481 | |
| 13482 | static void |
| 13483 | dprintf_after_condition_true (struct bpstats *bs) |
| 13484 | { |
| 13485 | struct cleanup *old_chain; |
| 13486 | struct bpstats tmp_bs = { NULL }; |
| 13487 | struct bpstats *tmp_bs_p = &tmp_bs; |
| 13488 | |
| 13489 | /* dprintf's never cause a stop. This wasn't set in the |
| 13490 | check_status hook instead because that would make the dprintf's |
| 13491 | condition not be evaluated. */ |
| 13492 | bs->stop = 0; |
| 13493 | |
| 13494 | /* Run the command list here. Take ownership of it instead of |
| 13495 | copying. We never want these commands to run later in |
| 13496 | bpstat_do_actions, if a breakpoint that causes a stop happens to |
| 13497 | be set at same address as this dprintf, or even if running the |
| 13498 | commands here throws. */ |
| 13499 | tmp_bs.commands = bs->commands; |
| 13500 | bs->commands = NULL; |
| 13501 | old_chain = make_cleanup_decref_counted_command_line (&tmp_bs.commands); |
| 13502 | |
| 13503 | bpstat_do_actions_1 (&tmp_bs_p); |
| 13504 | |
| 13505 | /* 'tmp_bs.commands' will usually be NULL by now, but |
| 13506 | bpstat_do_actions_1 may return early without processing the whole |
| 13507 | list. */ |
| 13508 | do_cleanups (old_chain); |
| 13509 | } |
| 13510 | |
| 13511 | /* The breakpoint_ops structure to be used on static tracepoints with |
| 13512 | markers (`-m'). */ |
| 13513 | |
| 13514 | static void |
| 13515 | strace_marker_create_sals_from_location (const struct event_location *location, |
| 13516 | struct linespec_result *canonical, |
| 13517 | enum bptype type_wanted) |
| 13518 | { |
| 13519 | struct linespec_sals lsal; |
| 13520 | const char *arg_start, *arg; |
| 13521 | char *str; |
| 13522 | struct cleanup *cleanup; |
| 13523 | |
| 13524 | arg = arg_start = get_linespec_location (location); |
| 13525 | lsal.sals = decode_static_tracepoint_spec (&arg); |
| 13526 | |
| 13527 | str = savestring (arg_start, arg - arg_start); |
| 13528 | cleanup = make_cleanup (xfree, str); |
| 13529 | canonical->location = new_linespec_location (&str); |
| 13530 | do_cleanups (cleanup); |
| 13531 | |
| 13532 | lsal.canonical = xstrdup (event_location_to_string (canonical->location)); |
| 13533 | VEC_safe_push (linespec_sals, canonical->sals, &lsal); |
| 13534 | } |
| 13535 | |
| 13536 | static void |
| 13537 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 13538 | struct linespec_result *canonical, |
| 13539 | char *cond_string, |
| 13540 | char *extra_string, |
| 13541 | enum bptype type_wanted, |
| 13542 | enum bpdisp disposition, |
| 13543 | int thread, |
| 13544 | int task, int ignore_count, |
| 13545 | const struct breakpoint_ops *ops, |
| 13546 | int from_tty, int enabled, |
| 13547 | int internal, unsigned flags) |
| 13548 | { |
| 13549 | int i; |
| 13550 | struct linespec_sals *lsal = VEC_index (linespec_sals, |
| 13551 | canonical->sals, 0); |
| 13552 | |
| 13553 | /* If the user is creating a static tracepoint by marker id |
| 13554 | (strace -m MARKER_ID), then store the sals index, so that |
| 13555 | breakpoint_re_set can try to match up which of the newly |
| 13556 | found markers corresponds to this one, and, don't try to |
| 13557 | expand multiple locations for each sal, given than SALS |
| 13558 | already should contain all sals for MARKER_ID. */ |
| 13559 | |
| 13560 | for (i = 0; i < lsal->sals.nelts; ++i) |
| 13561 | { |
| 13562 | struct symtabs_and_lines expanded; |
| 13563 | struct tracepoint *tp; |
| 13564 | struct cleanup *old_chain; |
| 13565 | struct event_location *location; |
| 13566 | |
| 13567 | expanded.nelts = 1; |
| 13568 | expanded.sals = &lsal->sals.sals[i]; |
| 13569 | |
| 13570 | location = copy_event_location (canonical->location); |
| 13571 | old_chain = make_cleanup_delete_event_location (location); |
| 13572 | |
| 13573 | tp = XCNEW (struct tracepoint); |
| 13574 | init_breakpoint_sal (&tp->base, gdbarch, expanded, |
| 13575 | location, NULL, |
| 13576 | cond_string, extra_string, |
| 13577 | type_wanted, disposition, |
| 13578 | thread, task, ignore_count, ops, |
| 13579 | from_tty, enabled, internal, flags, |
| 13580 | canonical->special_display); |
| 13581 | /* Given that its possible to have multiple markers with |
| 13582 | the same string id, if the user is creating a static |
| 13583 | tracepoint by marker id ("strace -m MARKER_ID"), then |
| 13584 | store the sals index, so that breakpoint_re_set can |
| 13585 | try to match up which of the newly found markers |
| 13586 | corresponds to this one */ |
| 13587 | tp->static_trace_marker_id_idx = i; |
| 13588 | |
| 13589 | install_breakpoint (internal, &tp->base, 0); |
| 13590 | |
| 13591 | discard_cleanups (old_chain); |
| 13592 | } |
| 13593 | } |
| 13594 | |
| 13595 | static void |
| 13596 | strace_marker_decode_location (struct breakpoint *b, |
| 13597 | const struct event_location *location, |
| 13598 | struct symtabs_and_lines *sals) |
| 13599 | { |
| 13600 | struct tracepoint *tp = (struct tracepoint *) b; |
| 13601 | const char *s = get_linespec_location (location); |
| 13602 | |
| 13603 | *sals = decode_static_tracepoint_spec (&s); |
| 13604 | if (sals->nelts > tp->static_trace_marker_id_idx) |
| 13605 | { |
| 13606 | sals->sals[0] = sals->sals[tp->static_trace_marker_id_idx]; |
| 13607 | sals->nelts = 1; |
| 13608 | } |
| 13609 | else |
| 13610 | error (_("marker %s not found"), tp->static_trace_marker_id); |
| 13611 | } |
| 13612 | |
| 13613 | static struct breakpoint_ops strace_marker_breakpoint_ops; |
| 13614 | |
| 13615 | static int |
| 13616 | strace_marker_p (struct breakpoint *b) |
| 13617 | { |
| 13618 | return b->ops == &strace_marker_breakpoint_ops; |
| 13619 | } |
| 13620 | |
| 13621 | /* Delete a breakpoint and clean up all traces of it in the data |
| 13622 | structures. */ |
| 13623 | |
| 13624 | void |
| 13625 | delete_breakpoint (struct breakpoint *bpt) |
| 13626 | { |
| 13627 | struct breakpoint *b; |
| 13628 | |
| 13629 | gdb_assert (bpt != NULL); |
| 13630 | |
| 13631 | /* Has this bp already been deleted? This can happen because |
| 13632 | multiple lists can hold pointers to bp's. bpstat lists are |
| 13633 | especial culprits. |
| 13634 | |
| 13635 | One example of this happening is a watchpoint's scope bp. When |
| 13636 | the scope bp triggers, we notice that the watchpoint is out of |
| 13637 | scope, and delete it. We also delete its scope bp. But the |
| 13638 | scope bp is marked "auto-deleting", and is already on a bpstat. |
| 13639 | That bpstat is then checked for auto-deleting bp's, which are |
| 13640 | deleted. |
| 13641 | |
| 13642 | A real solution to this problem might involve reference counts in |
| 13643 | bp's, and/or giving them pointers back to their referencing |
| 13644 | bpstat's, and teaching delete_breakpoint to only free a bp's |
| 13645 | storage when no more references were extent. A cheaper bandaid |
| 13646 | was chosen. */ |
| 13647 | if (bpt->type == bp_none) |
| 13648 | return; |
| 13649 | |
| 13650 | /* At least avoid this stale reference until the reference counting |
| 13651 | of breakpoints gets resolved. */ |
| 13652 | if (bpt->related_breakpoint != bpt) |
| 13653 | { |
| 13654 | struct breakpoint *related; |
| 13655 | struct watchpoint *w; |
| 13656 | |
| 13657 | if (bpt->type == bp_watchpoint_scope) |
| 13658 | w = (struct watchpoint *) bpt->related_breakpoint; |
| 13659 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
| 13660 | w = (struct watchpoint *) bpt; |
| 13661 | else |
| 13662 | w = NULL; |
| 13663 | if (w != NULL) |
| 13664 | watchpoint_del_at_next_stop (w); |
| 13665 | |
| 13666 | /* Unlink bpt from the bpt->related_breakpoint ring. */ |
| 13667 | for (related = bpt; related->related_breakpoint != bpt; |
| 13668 | related = related->related_breakpoint); |
| 13669 | related->related_breakpoint = bpt->related_breakpoint; |
| 13670 | bpt->related_breakpoint = bpt; |
| 13671 | } |
| 13672 | |
| 13673 | /* watch_command_1 creates a watchpoint but only sets its number if |
| 13674 | update_watchpoint succeeds in creating its bp_locations. If there's |
| 13675 | a problem in that process, we'll be asked to delete the half-created |
| 13676 | watchpoint. In that case, don't announce the deletion. */ |
| 13677 | if (bpt->number) |
| 13678 | observer_notify_breakpoint_deleted (bpt); |
| 13679 | |
| 13680 | if (breakpoint_chain == bpt) |
| 13681 | breakpoint_chain = bpt->next; |
| 13682 | |
| 13683 | ALL_BREAKPOINTS (b) |
| 13684 | if (b->next == bpt) |
| 13685 | { |
| 13686 | b->next = bpt->next; |
| 13687 | break; |
| 13688 | } |
| 13689 | |
| 13690 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
| 13691 | been freed. */ |
| 13692 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat |
| 13693 | in all threads for now. Note that we cannot just remove bpstats |
| 13694 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
| 13695 | commands are associated with the bpstat; if we remove it here, |
| 13696 | then the later call to bpstat_do_actions (&stop_bpstat); in |
| 13697 | event-top.c won't do anything, and temporary breakpoints with |
| 13698 | commands won't work. */ |
| 13699 | |
| 13700 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
| 13701 | |
| 13702 | /* Now that breakpoint is removed from breakpoint list, update the |
| 13703 | global location list. This will remove locations that used to |
| 13704 | belong to this breakpoint. Do this before freeing the breakpoint |
| 13705 | itself, since remove_breakpoint looks at location's owner. It |
| 13706 | might be better design to have location completely |
| 13707 | self-contained, but it's not the case now. */ |
| 13708 | update_global_location_list (UGLL_DONT_INSERT); |
| 13709 | |
| 13710 | bpt->ops->dtor (bpt); |
| 13711 | /* On the chance that someone will soon try again to delete this |
| 13712 | same bp, we mark it as deleted before freeing its storage. */ |
| 13713 | bpt->type = bp_none; |
| 13714 | xfree (bpt); |
| 13715 | } |
| 13716 | |
| 13717 | static void |
| 13718 | do_delete_breakpoint_cleanup (void *b) |
| 13719 | { |
| 13720 | delete_breakpoint (b); |
| 13721 | } |
| 13722 | |
| 13723 | struct cleanup * |
| 13724 | make_cleanup_delete_breakpoint (struct breakpoint *b) |
| 13725 | { |
| 13726 | return make_cleanup (do_delete_breakpoint_cleanup, b); |
| 13727 | } |
| 13728 | |
| 13729 | /* Iterator function to call a user-provided callback function once |
| 13730 | for each of B and its related breakpoints. */ |
| 13731 | |
| 13732 | static void |
| 13733 | iterate_over_related_breakpoints (struct breakpoint *b, |
| 13734 | void (*function) (struct breakpoint *, |
| 13735 | void *), |
| 13736 | void *data) |
| 13737 | { |
| 13738 | struct breakpoint *related; |
| 13739 | |
| 13740 | related = b; |
| 13741 | do |
| 13742 | { |
| 13743 | struct breakpoint *next; |
| 13744 | |
| 13745 | /* FUNCTION may delete RELATED. */ |
| 13746 | next = related->related_breakpoint; |
| 13747 | |
| 13748 | if (next == related) |
| 13749 | { |
| 13750 | /* RELATED is the last ring entry. */ |
| 13751 | function (related, data); |
| 13752 | |
| 13753 | /* FUNCTION may have deleted it, so we'd never reach back to |
| 13754 | B. There's nothing left to do anyway, so just break |
| 13755 | out. */ |
| 13756 | break; |
| 13757 | } |
| 13758 | else |
| 13759 | function (related, data); |
| 13760 | |
| 13761 | related = next; |
| 13762 | } |
| 13763 | while (related != b); |
| 13764 | } |
| 13765 | |
| 13766 | static void |
| 13767 | do_delete_breakpoint (struct breakpoint *b, void *ignore) |
| 13768 | { |
| 13769 | delete_breakpoint (b); |
| 13770 | } |
| 13771 | |
| 13772 | /* A callback for map_breakpoint_numbers that calls |
| 13773 | delete_breakpoint. */ |
| 13774 | |
| 13775 | static void |
| 13776 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) |
| 13777 | { |
| 13778 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); |
| 13779 | } |
| 13780 | |
| 13781 | void |
| 13782 | delete_command (char *arg, int from_tty) |
| 13783 | { |
| 13784 | struct breakpoint *b, *b_tmp; |
| 13785 | |
| 13786 | dont_repeat (); |
| 13787 | |
| 13788 | if (arg == 0) |
| 13789 | { |
| 13790 | int breaks_to_delete = 0; |
| 13791 | |
| 13792 | /* Delete all breakpoints if no argument. Do not delete |
| 13793 | internal breakpoints, these have to be deleted with an |
| 13794 | explicit breakpoint number argument. */ |
| 13795 | ALL_BREAKPOINTS (b) |
| 13796 | if (user_breakpoint_p (b)) |
| 13797 | { |
| 13798 | breaks_to_delete = 1; |
| 13799 | break; |
| 13800 | } |
| 13801 | |
| 13802 | /* Ask user only if there are some breakpoints to delete. */ |
| 13803 | if (!from_tty |
| 13804 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
| 13805 | { |
| 13806 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 13807 | if (user_breakpoint_p (b)) |
| 13808 | delete_breakpoint (b); |
| 13809 | } |
| 13810 | } |
| 13811 | else |
| 13812 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
| 13813 | } |
| 13814 | |
| 13815 | static int |
| 13816 | all_locations_are_pending (struct bp_location *loc) |
| 13817 | { |
| 13818 | for (; loc; loc = loc->next) |
| 13819 | if (!loc->shlib_disabled |
| 13820 | && !loc->pspace->executing_startup) |
| 13821 | return 0; |
| 13822 | return 1; |
| 13823 | } |
| 13824 | |
| 13825 | /* Subroutine of update_breakpoint_locations to simplify it. |
| 13826 | Return non-zero if multiple fns in list LOC have the same name. |
| 13827 | Null names are ignored. */ |
| 13828 | |
| 13829 | static int |
| 13830 | ambiguous_names_p (struct bp_location *loc) |
| 13831 | { |
| 13832 | struct bp_location *l; |
| 13833 | htab_t htab = htab_create_alloc (13, htab_hash_string, |
| 13834 | (int (*) (const void *, |
| 13835 | const void *)) streq, |
| 13836 | NULL, xcalloc, xfree); |
| 13837 | |
| 13838 | for (l = loc; l != NULL; l = l->next) |
| 13839 | { |
| 13840 | const char **slot; |
| 13841 | const char *name = l->function_name; |
| 13842 | |
| 13843 | /* Allow for some names to be NULL, ignore them. */ |
| 13844 | if (name == NULL) |
| 13845 | continue; |
| 13846 | |
| 13847 | slot = (const char **) htab_find_slot (htab, (const void *) name, |
| 13848 | INSERT); |
| 13849 | /* NOTE: We can assume slot != NULL here because xcalloc never |
| 13850 | returns NULL. */ |
| 13851 | if (*slot != NULL) |
| 13852 | { |
| 13853 | htab_delete (htab); |
| 13854 | return 1; |
| 13855 | } |
| 13856 | *slot = name; |
| 13857 | } |
| 13858 | |
| 13859 | htab_delete (htab); |
| 13860 | return 0; |
| 13861 | } |
| 13862 | |
| 13863 | /* When symbols change, it probably means the sources changed as well, |
| 13864 | and it might mean the static tracepoint markers are no longer at |
| 13865 | the same address or line numbers they used to be at last we |
| 13866 | checked. Losing your static tracepoints whenever you rebuild is |
| 13867 | undesirable. This function tries to resync/rematch gdb static |
| 13868 | tracepoints with the markers on the target, for static tracepoints |
| 13869 | that have not been set by marker id. Static tracepoint that have |
| 13870 | been set by marker id are reset by marker id in breakpoint_re_set. |
| 13871 | The heuristic is: |
| 13872 | |
| 13873 | 1) For a tracepoint set at a specific address, look for a marker at |
| 13874 | the old PC. If one is found there, assume to be the same marker. |
| 13875 | If the name / string id of the marker found is different from the |
| 13876 | previous known name, assume that means the user renamed the marker |
| 13877 | in the sources, and output a warning. |
| 13878 | |
| 13879 | 2) For a tracepoint set at a given line number, look for a marker |
| 13880 | at the new address of the old line number. If one is found there, |
| 13881 | assume to be the same marker. If the name / string id of the |
| 13882 | marker found is different from the previous known name, assume that |
| 13883 | means the user renamed the marker in the sources, and output a |
| 13884 | warning. |
| 13885 | |
| 13886 | 3) If a marker is no longer found at the same address or line, it |
| 13887 | may mean the marker no longer exists. But it may also just mean |
| 13888 | the code changed a bit. Maybe the user added a few lines of code |
| 13889 | that made the marker move up or down (in line number terms). Ask |
| 13890 | the target for info about the marker with the string id as we knew |
| 13891 | it. If found, update line number and address in the matching |
| 13892 | static tracepoint. This will get confused if there's more than one |
| 13893 | marker with the same ID (possible in UST, although unadvised |
| 13894 | precisely because it confuses tools). */ |
| 13895 | |
| 13896 | static struct symtab_and_line |
| 13897 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) |
| 13898 | { |
| 13899 | struct tracepoint *tp = (struct tracepoint *) b; |
| 13900 | struct static_tracepoint_marker marker; |
| 13901 | CORE_ADDR pc; |
| 13902 | |
| 13903 | pc = sal.pc; |
| 13904 | if (sal.line) |
| 13905 | find_line_pc (sal.symtab, sal.line, &pc); |
| 13906 | |
| 13907 | if (target_static_tracepoint_marker_at (pc, &marker)) |
| 13908 | { |
| 13909 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
| 13910 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
| 13911 | b->number, |
| 13912 | tp->static_trace_marker_id, marker.str_id); |
| 13913 | |
| 13914 | xfree (tp->static_trace_marker_id); |
| 13915 | tp->static_trace_marker_id = xstrdup (marker.str_id); |
| 13916 | release_static_tracepoint_marker (&marker); |
| 13917 | |
| 13918 | return sal; |
| 13919 | } |
| 13920 | |
| 13921 | /* Old marker wasn't found on target at lineno. Try looking it up |
| 13922 | by string ID. */ |
| 13923 | if (!sal.explicit_pc |
| 13924 | && sal.line != 0 |
| 13925 | && sal.symtab != NULL |
| 13926 | && tp->static_trace_marker_id != NULL) |
| 13927 | { |
| 13928 | VEC(static_tracepoint_marker_p) *markers; |
| 13929 | |
| 13930 | markers |
| 13931 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
| 13932 | |
| 13933 | if (!VEC_empty(static_tracepoint_marker_p, markers)) |
| 13934 | { |
| 13935 | char *p, *tmp; |
| 13936 | struct symtab_and_line sal2; |
| 13937 | struct symbol *sym; |
| 13938 | struct static_tracepoint_marker *tpmarker; |
| 13939 | struct ui_out *uiout = current_uiout; |
| 13940 | struct cleanup *cleanup; |
| 13941 | |
| 13942 | tpmarker = VEC_index (static_tracepoint_marker_p, markers, 0); |
| 13943 | |
| 13944 | xfree (tp->static_trace_marker_id); |
| 13945 | tp->static_trace_marker_id = xstrdup (tpmarker->str_id); |
| 13946 | |
| 13947 | warning (_("marker for static tracepoint %d (%s) not " |
| 13948 | "found at previous line number"), |
| 13949 | b->number, tp->static_trace_marker_id); |
| 13950 | |
| 13951 | init_sal (&sal2); |
| 13952 | |
| 13953 | sal2.pc = tpmarker->address; |
| 13954 | |
| 13955 | sal2 = find_pc_line (tpmarker->address, 0); |
| 13956 | sym = find_pc_sect_function (tpmarker->address, NULL); |
| 13957 | ui_out_text (uiout, "Now in "); |
| 13958 | if (sym) |
| 13959 | { |
| 13960 | ui_out_field_string (uiout, "func", |
| 13961 | SYMBOL_PRINT_NAME (sym)); |
| 13962 | ui_out_text (uiout, " at "); |
| 13963 | } |
| 13964 | ui_out_field_string (uiout, "file", |
| 13965 | symtab_to_filename_for_display (sal2.symtab)); |
| 13966 | ui_out_text (uiout, ":"); |
| 13967 | |
| 13968 | if (ui_out_is_mi_like_p (uiout)) |
| 13969 | { |
| 13970 | const char *fullname = symtab_to_fullname (sal2.symtab); |
| 13971 | |
| 13972 | ui_out_field_string (uiout, "fullname", fullname); |
| 13973 | } |
| 13974 | |
| 13975 | ui_out_field_int (uiout, "line", sal2.line); |
| 13976 | ui_out_text (uiout, "\n"); |
| 13977 | |
| 13978 | b->loc->line_number = sal2.line; |
| 13979 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
| 13980 | |
| 13981 | delete_event_location (b->location); |
| 13982 | p = tmp = xstrprintf ("%s:%d", |
| 13983 | symtab_to_filename_for_display (sal2.symtab), |
| 13984 | b->loc->line_number); |
| 13985 | cleanup = make_cleanup (xfree, tmp); |
| 13986 | b->location = new_linespec_location (&tmp); |
| 13987 | do_cleanups (cleanup); |
| 13988 | |
| 13989 | /* Might be nice to check if function changed, and warn if |
| 13990 | so. */ |
| 13991 | |
| 13992 | release_static_tracepoint_marker (tpmarker); |
| 13993 | } |
| 13994 | } |
| 13995 | return sal; |
| 13996 | } |
| 13997 | |
| 13998 | /* Returns 1 iff locations A and B are sufficiently same that |
| 13999 | we don't need to report breakpoint as changed. */ |
| 14000 | |
| 14001 | static int |
| 14002 | locations_are_equal (struct bp_location *a, struct bp_location *b) |
| 14003 | { |
| 14004 | while (a && b) |
| 14005 | { |
| 14006 | if (a->address != b->address) |
| 14007 | return 0; |
| 14008 | |
| 14009 | if (a->shlib_disabled != b->shlib_disabled) |
| 14010 | return 0; |
| 14011 | |
| 14012 | if (a->enabled != b->enabled) |
| 14013 | return 0; |
| 14014 | |
| 14015 | a = a->next; |
| 14016 | b = b->next; |
| 14017 | } |
| 14018 | |
| 14019 | if ((a == NULL) != (b == NULL)) |
| 14020 | return 0; |
| 14021 | |
| 14022 | return 1; |
| 14023 | } |
| 14024 | |
| 14025 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
| 14026 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is |
| 14027 | a ranged breakpoint. */ |
| 14028 | |
| 14029 | void |
| 14030 | update_breakpoint_locations (struct breakpoint *b, |
| 14031 | struct symtabs_and_lines sals, |
| 14032 | struct symtabs_and_lines sals_end) |
| 14033 | { |
| 14034 | int i; |
| 14035 | struct bp_location *existing_locations = b->loc; |
| 14036 | |
| 14037 | if (sals_end.nelts != 0 && (sals.nelts != 1 || sals_end.nelts != 1)) |
| 14038 | { |
| 14039 | /* Ranged breakpoints have only one start location and one end |
| 14040 | location. */ |
| 14041 | b->enable_state = bp_disabled; |
| 14042 | update_global_location_list (UGLL_MAY_INSERT); |
| 14043 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
| 14044 | "multiple locations found\n"), |
| 14045 | b->number); |
| 14046 | return; |
| 14047 | } |
| 14048 | |
| 14049 | /* If there's no new locations, and all existing locations are |
| 14050 | pending, don't do anything. This optimizes the common case where |
| 14051 | all locations are in the same shared library, that was unloaded. |
| 14052 | We'd like to retain the location, so that when the library is |
| 14053 | loaded again, we don't loose the enabled/disabled status of the |
| 14054 | individual locations. */ |
| 14055 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
| 14056 | return; |
| 14057 | |
| 14058 | b->loc = NULL; |
| 14059 | |
| 14060 | for (i = 0; i < sals.nelts; ++i) |
| 14061 | { |
| 14062 | struct bp_location *new_loc; |
| 14063 | |
| 14064 | switch_to_program_space_and_thread (sals.sals[i].pspace); |
| 14065 | |
| 14066 | new_loc = add_location_to_breakpoint (b, &(sals.sals[i])); |
| 14067 | |
| 14068 | /* Reparse conditions, they might contain references to the |
| 14069 | old symtab. */ |
| 14070 | if (b->cond_string != NULL) |
| 14071 | { |
| 14072 | const char *s; |
| 14073 | |
| 14074 | s = b->cond_string; |
| 14075 | TRY |
| 14076 | { |
| 14077 | new_loc->cond = parse_exp_1 (&s, sals.sals[i].pc, |
| 14078 | block_for_pc (sals.sals[i].pc), |
| 14079 | 0); |
| 14080 | } |
| 14081 | CATCH (e, RETURN_MASK_ERROR) |
| 14082 | { |
| 14083 | warning (_("failed to reevaluate condition " |
| 14084 | "for breakpoint %d: %s"), |
| 14085 | b->number, e.message); |
| 14086 | new_loc->enabled = 0; |
| 14087 | } |
| 14088 | END_CATCH |
| 14089 | } |
| 14090 | |
| 14091 | if (sals_end.nelts) |
| 14092 | { |
| 14093 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); |
| 14094 | |
| 14095 | new_loc->length = end - sals.sals[0].pc + 1; |
| 14096 | } |
| 14097 | } |
| 14098 | |
| 14099 | /* If possible, carry over 'disable' status from existing |
| 14100 | breakpoints. */ |
| 14101 | { |
| 14102 | struct bp_location *e = existing_locations; |
| 14103 | /* If there are multiple breakpoints with the same function name, |
| 14104 | e.g. for inline functions, comparing function names won't work. |
| 14105 | Instead compare pc addresses; this is just a heuristic as things |
| 14106 | may have moved, but in practice it gives the correct answer |
| 14107 | often enough until a better solution is found. */ |
| 14108 | int have_ambiguous_names = ambiguous_names_p (b->loc); |
| 14109 | |
| 14110 | for (; e; e = e->next) |
| 14111 | { |
| 14112 | if (!e->enabled && e->function_name) |
| 14113 | { |
| 14114 | struct bp_location *l = b->loc; |
| 14115 | if (have_ambiguous_names) |
| 14116 | { |
| 14117 | for (; l; l = l->next) |
| 14118 | if (breakpoint_locations_match (e, l)) |
| 14119 | { |
| 14120 | l->enabled = 0; |
| 14121 | break; |
| 14122 | } |
| 14123 | } |
| 14124 | else |
| 14125 | { |
| 14126 | for (; l; l = l->next) |
| 14127 | if (l->function_name |
| 14128 | && strcmp (e->function_name, l->function_name) == 0) |
| 14129 | { |
| 14130 | l->enabled = 0; |
| 14131 | break; |
| 14132 | } |
| 14133 | } |
| 14134 | } |
| 14135 | } |
| 14136 | } |
| 14137 | |
| 14138 | if (!locations_are_equal (existing_locations, b->loc)) |
| 14139 | observer_notify_breakpoint_modified (b); |
| 14140 | |
| 14141 | update_global_location_list (UGLL_MAY_INSERT); |
| 14142 | } |
| 14143 | |
| 14144 | /* Find the SaL locations corresponding to the given LOCATION. |
| 14145 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
| 14146 | |
| 14147 | static struct symtabs_and_lines |
| 14148 | location_to_sals (struct breakpoint *b, struct event_location *location, |
| 14149 | int *found) |
| 14150 | { |
| 14151 | struct symtabs_and_lines sals = {0}; |
| 14152 | struct gdb_exception exception = exception_none; |
| 14153 | |
| 14154 | gdb_assert (b->ops != NULL); |
| 14155 | |
| 14156 | TRY |
| 14157 | { |
| 14158 | b->ops->decode_location (b, location, &sals); |
| 14159 | } |
| 14160 | CATCH (e, RETURN_MASK_ERROR) |
| 14161 | { |
| 14162 | int not_found_and_ok = 0; |
| 14163 | |
| 14164 | exception = e; |
| 14165 | |
| 14166 | /* For pending breakpoints, it's expected that parsing will |
| 14167 | fail until the right shared library is loaded. User has |
| 14168 | already told to create pending breakpoints and don't need |
| 14169 | extra messages. If breakpoint is in bp_shlib_disabled |
| 14170 | state, then user already saw the message about that |
| 14171 | breakpoint being disabled, and don't want to see more |
| 14172 | errors. */ |
| 14173 | if (e.error == NOT_FOUND_ERROR |
| 14174 | && (b->condition_not_parsed |
| 14175 | || (b->loc && b->loc->shlib_disabled) |
| 14176 | || (b->loc && b->loc->pspace->executing_startup) |
| 14177 | || b->enable_state == bp_disabled)) |
| 14178 | not_found_and_ok = 1; |
| 14179 | |
| 14180 | if (!not_found_and_ok) |
| 14181 | { |
| 14182 | /* We surely don't want to warn about the same breakpoint |
| 14183 | 10 times. One solution, implemented here, is disable |
| 14184 | the breakpoint on error. Another solution would be to |
| 14185 | have separate 'warning emitted' flag. Since this |
| 14186 | happens only when a binary has changed, I don't know |
| 14187 | which approach is better. */ |
| 14188 | b->enable_state = bp_disabled; |
| 14189 | throw_exception (e); |
| 14190 | } |
| 14191 | } |
| 14192 | END_CATCH |
| 14193 | |
| 14194 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
| 14195 | { |
| 14196 | int i; |
| 14197 | |
| 14198 | for (i = 0; i < sals.nelts; ++i) |
| 14199 | resolve_sal_pc (&sals.sals[i]); |
| 14200 | if (b->condition_not_parsed && b->extra_string != NULL) |
| 14201 | { |
| 14202 | char *cond_string, *extra_string; |
| 14203 | int thread, task; |
| 14204 | |
| 14205 | find_condition_and_thread (b->extra_string, sals.sals[0].pc, |
| 14206 | &cond_string, &thread, &task, |
| 14207 | &extra_string); |
| 14208 | gdb_assert (b->cond_string == NULL); |
| 14209 | if (cond_string) |
| 14210 | b->cond_string = cond_string; |
| 14211 | b->thread = thread; |
| 14212 | b->task = task; |
| 14213 | if (extra_string) |
| 14214 | { |
| 14215 | xfree (b->extra_string); |
| 14216 | b->extra_string = extra_string; |
| 14217 | } |
| 14218 | b->condition_not_parsed = 0; |
| 14219 | } |
| 14220 | |
| 14221 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
| 14222 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); |
| 14223 | |
| 14224 | *found = 1; |
| 14225 | } |
| 14226 | else |
| 14227 | *found = 0; |
| 14228 | |
| 14229 | return sals; |
| 14230 | } |
| 14231 | |
| 14232 | /* The default re_set method, for typical hardware or software |
| 14233 | breakpoints. Reevaluate the breakpoint and recreate its |
| 14234 | locations. */ |
| 14235 | |
| 14236 | static void |
| 14237 | breakpoint_re_set_default (struct breakpoint *b) |
| 14238 | { |
| 14239 | int found; |
| 14240 | struct symtabs_and_lines sals, sals_end; |
| 14241 | struct symtabs_and_lines expanded = {0}; |
| 14242 | struct symtabs_and_lines expanded_end = {0}; |
| 14243 | |
| 14244 | sals = location_to_sals (b, b->location, &found); |
| 14245 | if (found) |
| 14246 | { |
| 14247 | make_cleanup (xfree, sals.sals); |
| 14248 | expanded = sals; |
| 14249 | } |
| 14250 | |
| 14251 | if (b->location_range_end != NULL) |
| 14252 | { |
| 14253 | sals_end = location_to_sals (b, b->location_range_end, &found); |
| 14254 | if (found) |
| 14255 | { |
| 14256 | make_cleanup (xfree, sals_end.sals); |
| 14257 | expanded_end = sals_end; |
| 14258 | } |
| 14259 | } |
| 14260 | |
| 14261 | update_breakpoint_locations (b, expanded, expanded_end); |
| 14262 | } |
| 14263 | |
| 14264 | /* Default method for creating SALs from an address string. It basically |
| 14265 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ |
| 14266 | |
| 14267 | static void |
| 14268 | create_sals_from_location_default (const struct event_location *location, |
| 14269 | struct linespec_result *canonical, |
| 14270 | enum bptype type_wanted) |
| 14271 | { |
| 14272 | parse_breakpoint_sals (location, canonical); |
| 14273 | } |
| 14274 | |
| 14275 | /* Call create_breakpoints_sal for the given arguments. This is the default |
| 14276 | function for the `create_breakpoints_sal' method of |
| 14277 | breakpoint_ops. */ |
| 14278 | |
| 14279 | static void |
| 14280 | create_breakpoints_sal_default (struct gdbarch *gdbarch, |
| 14281 | struct linespec_result *canonical, |
| 14282 | char *cond_string, |
| 14283 | char *extra_string, |
| 14284 | enum bptype type_wanted, |
| 14285 | enum bpdisp disposition, |
| 14286 | int thread, |
| 14287 | int task, int ignore_count, |
| 14288 | const struct breakpoint_ops *ops, |
| 14289 | int from_tty, int enabled, |
| 14290 | int internal, unsigned flags) |
| 14291 | { |
| 14292 | create_breakpoints_sal (gdbarch, canonical, cond_string, |
| 14293 | extra_string, |
| 14294 | type_wanted, disposition, |
| 14295 | thread, task, ignore_count, ops, from_tty, |
| 14296 | enabled, internal, flags); |
| 14297 | } |
| 14298 | |
| 14299 | /* Decode the line represented by S by calling decode_line_full. This is the |
| 14300 | default function for the `decode_location' method of breakpoint_ops. */ |
| 14301 | |
| 14302 | static void |
| 14303 | decode_location_default (struct breakpoint *b, |
| 14304 | const struct event_location *location, |
| 14305 | struct symtabs_and_lines *sals) |
| 14306 | { |
| 14307 | struct linespec_result canonical; |
| 14308 | |
| 14309 | init_linespec_result (&canonical); |
| 14310 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, |
| 14311 | (struct symtab *) NULL, 0, |
| 14312 | &canonical, multiple_symbols_all, |
| 14313 | b->filter); |
| 14314 | |
| 14315 | /* We should get 0 or 1 resulting SALs. */ |
| 14316 | gdb_assert (VEC_length (linespec_sals, canonical.sals) < 2); |
| 14317 | |
| 14318 | if (VEC_length (linespec_sals, canonical.sals) > 0) |
| 14319 | { |
| 14320 | struct linespec_sals *lsal; |
| 14321 | |
| 14322 | lsal = VEC_index (linespec_sals, canonical.sals, 0); |
| 14323 | *sals = lsal->sals; |
| 14324 | /* Arrange it so the destructor does not free the |
| 14325 | contents. */ |
| 14326 | lsal->sals.sals = NULL; |
| 14327 | } |
| 14328 | |
| 14329 | destroy_linespec_result (&canonical); |
| 14330 | } |
| 14331 | |
| 14332 | /* Prepare the global context for a re-set of breakpoint B. */ |
| 14333 | |
| 14334 | static struct cleanup * |
| 14335 | prepare_re_set_context (struct breakpoint *b) |
| 14336 | { |
| 14337 | struct cleanup *cleanups; |
| 14338 | |
| 14339 | input_radix = b->input_radix; |
| 14340 | cleanups = save_current_space_and_thread (); |
| 14341 | if (b->pspace != NULL) |
| 14342 | switch_to_program_space_and_thread (b->pspace); |
| 14343 | set_language (b->language); |
| 14344 | |
| 14345 | return cleanups; |
| 14346 | } |
| 14347 | |
| 14348 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
| 14349 | The value we return ends up being the return value from catch_errors. |
| 14350 | Unused in this case. */ |
| 14351 | |
| 14352 | static int |
| 14353 | breakpoint_re_set_one (void *bint) |
| 14354 | { |
| 14355 | /* Get past catch_errs. */ |
| 14356 | struct breakpoint *b = (struct breakpoint *) bint; |
| 14357 | struct cleanup *cleanups; |
| 14358 | |
| 14359 | cleanups = prepare_re_set_context (b); |
| 14360 | b->ops->re_set (b); |
| 14361 | do_cleanups (cleanups); |
| 14362 | return 0; |
| 14363 | } |
| 14364 | |
| 14365 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
| 14366 | void |
| 14367 | breakpoint_re_set (void) |
| 14368 | { |
| 14369 | struct breakpoint *b, *b_tmp; |
| 14370 | enum language save_language; |
| 14371 | int save_input_radix; |
| 14372 | struct cleanup *old_chain; |
| 14373 | |
| 14374 | save_language = current_language->la_language; |
| 14375 | save_input_radix = input_radix; |
| 14376 | old_chain = save_current_program_space (); |
| 14377 | |
| 14378 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 14379 | { |
| 14380 | /* Format possible error msg. */ |
| 14381 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
| 14382 | b->number); |
| 14383 | struct cleanup *cleanups = make_cleanup (xfree, message); |
| 14384 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
| 14385 | do_cleanups (cleanups); |
| 14386 | } |
| 14387 | set_language (save_language); |
| 14388 | input_radix = save_input_radix; |
| 14389 | |
| 14390 | jit_breakpoint_re_set (); |
| 14391 | |
| 14392 | do_cleanups (old_chain); |
| 14393 | |
| 14394 | create_overlay_event_breakpoint (); |
| 14395 | create_longjmp_master_breakpoint (); |
| 14396 | create_std_terminate_master_breakpoint (); |
| 14397 | create_exception_master_breakpoint (); |
| 14398 | } |
| 14399 | \f |
| 14400 | /* Reset the thread number of this breakpoint: |
| 14401 | |
| 14402 | - If the breakpoint is for all threads, leave it as-is. |
| 14403 | - Else, reset it to the current thread for inferior_ptid. */ |
| 14404 | void |
| 14405 | breakpoint_re_set_thread (struct breakpoint *b) |
| 14406 | { |
| 14407 | if (b->thread != -1) |
| 14408 | { |
| 14409 | if (in_thread_list (inferior_ptid)) |
| 14410 | b->thread = pid_to_thread_id (inferior_ptid); |
| 14411 | |
| 14412 | /* We're being called after following a fork. The new fork is |
| 14413 | selected as current, and unless this was a vfork will have a |
| 14414 | different program space from the original thread. Reset that |
| 14415 | as well. */ |
| 14416 | b->loc->pspace = current_program_space; |
| 14417 | } |
| 14418 | } |
| 14419 | |
| 14420 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 14421 | If from_tty is nonzero, it prints a message to that effect, |
| 14422 | which ends with a period (no newline). */ |
| 14423 | |
| 14424 | void |
| 14425 | set_ignore_count (int bptnum, int count, int from_tty) |
| 14426 | { |
| 14427 | struct breakpoint *b; |
| 14428 | |
| 14429 | if (count < 0) |
| 14430 | count = 0; |
| 14431 | |
| 14432 | ALL_BREAKPOINTS (b) |
| 14433 | if (b->number == bptnum) |
| 14434 | { |
| 14435 | if (is_tracepoint (b)) |
| 14436 | { |
| 14437 | if (from_tty && count != 0) |
| 14438 | printf_filtered (_("Ignore count ignored for tracepoint %d."), |
| 14439 | bptnum); |
| 14440 | return; |
| 14441 | } |
| 14442 | |
| 14443 | b->ignore_count = count; |
| 14444 | if (from_tty) |
| 14445 | { |
| 14446 | if (count == 0) |
| 14447 | printf_filtered (_("Will stop next time " |
| 14448 | "breakpoint %d is reached."), |
| 14449 | bptnum); |
| 14450 | else if (count == 1) |
| 14451 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
| 14452 | bptnum); |
| 14453 | else |
| 14454 | printf_filtered (_("Will ignore next %d " |
| 14455 | "crossings of breakpoint %d."), |
| 14456 | count, bptnum); |
| 14457 | } |
| 14458 | observer_notify_breakpoint_modified (b); |
| 14459 | return; |
| 14460 | } |
| 14461 | |
| 14462 | error (_("No breakpoint number %d."), bptnum); |
| 14463 | } |
| 14464 | |
| 14465 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
| 14466 | |
| 14467 | static void |
| 14468 | ignore_command (char *args, int from_tty) |
| 14469 | { |
| 14470 | char *p = args; |
| 14471 | int num; |
| 14472 | |
| 14473 | if (p == 0) |
| 14474 | error_no_arg (_("a breakpoint number")); |
| 14475 | |
| 14476 | num = get_number (&p); |
| 14477 | if (num == 0) |
| 14478 | error (_("bad breakpoint number: '%s'"), args); |
| 14479 | if (*p == 0) |
| 14480 | error (_("Second argument (specified ignore-count) is missing.")); |
| 14481 | |
| 14482 | set_ignore_count (num, |
| 14483 | longest_to_int (value_as_long (parse_and_eval (p))), |
| 14484 | from_tty); |
| 14485 | if (from_tty) |
| 14486 | printf_filtered ("\n"); |
| 14487 | } |
| 14488 | \f |
| 14489 | /* Call FUNCTION on each of the breakpoints |
| 14490 | whose numbers are given in ARGS. */ |
| 14491 | |
| 14492 | static void |
| 14493 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
| 14494 | void *), |
| 14495 | void *data) |
| 14496 | { |
| 14497 | int num; |
| 14498 | struct breakpoint *b, *tmp; |
| 14499 | int match; |
| 14500 | struct get_number_or_range_state state; |
| 14501 | |
| 14502 | if (args == 0 || *args == '\0') |
| 14503 | error_no_arg (_("one or more breakpoint numbers")); |
| 14504 | |
| 14505 | init_number_or_range (&state, args); |
| 14506 | |
| 14507 | while (!state.finished) |
| 14508 | { |
| 14509 | const char *p = state.string; |
| 14510 | |
| 14511 | match = 0; |
| 14512 | |
| 14513 | num = get_number_or_range (&state); |
| 14514 | if (num == 0) |
| 14515 | { |
| 14516 | warning (_("bad breakpoint number at or near '%s'"), p); |
| 14517 | } |
| 14518 | else |
| 14519 | { |
| 14520 | ALL_BREAKPOINTS_SAFE (b, tmp) |
| 14521 | if (b->number == num) |
| 14522 | { |
| 14523 | match = 1; |
| 14524 | function (b, data); |
| 14525 | break; |
| 14526 | } |
| 14527 | if (match == 0) |
| 14528 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
| 14529 | } |
| 14530 | } |
| 14531 | } |
| 14532 | |
| 14533 | static struct bp_location * |
| 14534 | find_location_by_number (char *number) |
| 14535 | { |
| 14536 | char *dot = strchr (number, '.'); |
| 14537 | char *p1; |
| 14538 | int bp_num; |
| 14539 | int loc_num; |
| 14540 | struct breakpoint *b; |
| 14541 | struct bp_location *loc; |
| 14542 | |
| 14543 | *dot = '\0'; |
| 14544 | |
| 14545 | p1 = number; |
| 14546 | bp_num = get_number (&p1); |
| 14547 | if (bp_num == 0) |
| 14548 | error (_("Bad breakpoint number '%s'"), number); |
| 14549 | |
| 14550 | ALL_BREAKPOINTS (b) |
| 14551 | if (b->number == bp_num) |
| 14552 | { |
| 14553 | break; |
| 14554 | } |
| 14555 | |
| 14556 | if (!b || b->number != bp_num) |
| 14557 | error (_("Bad breakpoint number '%s'"), number); |
| 14558 | |
| 14559 | p1 = dot+1; |
| 14560 | loc_num = get_number (&p1); |
| 14561 | if (loc_num == 0) |
| 14562 | error (_("Bad breakpoint location number '%s'"), number); |
| 14563 | |
| 14564 | --loc_num; |
| 14565 | loc = b->loc; |
| 14566 | for (;loc_num && loc; --loc_num, loc = loc->next) |
| 14567 | ; |
| 14568 | if (!loc) |
| 14569 | error (_("Bad breakpoint location number '%s'"), dot+1); |
| 14570 | |
| 14571 | return loc; |
| 14572 | } |
| 14573 | |
| 14574 | |
| 14575 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 14576 | If from_tty is nonzero, it prints a message to that effect, |
| 14577 | which ends with a period (no newline). */ |
| 14578 | |
| 14579 | void |
| 14580 | disable_breakpoint (struct breakpoint *bpt) |
| 14581 | { |
| 14582 | /* Never disable a watchpoint scope breakpoint; we want to |
| 14583 | hit them when we leave scope so we can delete both the |
| 14584 | watchpoint and its scope breakpoint at that time. */ |
| 14585 | if (bpt->type == bp_watchpoint_scope) |
| 14586 | return; |
| 14587 | |
| 14588 | bpt->enable_state = bp_disabled; |
| 14589 | |
| 14590 | /* Mark breakpoint locations modified. */ |
| 14591 | mark_breakpoint_modified (bpt); |
| 14592 | |
| 14593 | if (target_supports_enable_disable_tracepoint () |
| 14594 | && current_trace_status ()->running && is_tracepoint (bpt)) |
| 14595 | { |
| 14596 | struct bp_location *location; |
| 14597 | |
| 14598 | for (location = bpt->loc; location; location = location->next) |
| 14599 | target_disable_tracepoint (location); |
| 14600 | } |
| 14601 | |
| 14602 | update_global_location_list (UGLL_DONT_INSERT); |
| 14603 | |
| 14604 | observer_notify_breakpoint_modified (bpt); |
| 14605 | } |
| 14606 | |
| 14607 | /* A callback for iterate_over_related_breakpoints. */ |
| 14608 | |
| 14609 | static void |
| 14610 | do_disable_breakpoint (struct breakpoint *b, void *ignore) |
| 14611 | { |
| 14612 | disable_breakpoint (b); |
| 14613 | } |
| 14614 | |
| 14615 | /* A callback for map_breakpoint_numbers that calls |
| 14616 | disable_breakpoint. */ |
| 14617 | |
| 14618 | static void |
| 14619 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) |
| 14620 | { |
| 14621 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
| 14622 | } |
| 14623 | |
| 14624 | static void |
| 14625 | disable_command (char *args, int from_tty) |
| 14626 | { |
| 14627 | if (args == 0) |
| 14628 | { |
| 14629 | struct breakpoint *bpt; |
| 14630 | |
| 14631 | ALL_BREAKPOINTS (bpt) |
| 14632 | if (user_breakpoint_p (bpt)) |
| 14633 | disable_breakpoint (bpt); |
| 14634 | } |
| 14635 | else |
| 14636 | { |
| 14637 | char *num = extract_arg (&args); |
| 14638 | |
| 14639 | while (num) |
| 14640 | { |
| 14641 | if (strchr (num, '.')) |
| 14642 | { |
| 14643 | struct bp_location *loc = find_location_by_number (num); |
| 14644 | |
| 14645 | if (loc) |
| 14646 | { |
| 14647 | if (loc->enabled) |
| 14648 | { |
| 14649 | loc->enabled = 0; |
| 14650 | mark_breakpoint_location_modified (loc); |
| 14651 | } |
| 14652 | if (target_supports_enable_disable_tracepoint () |
| 14653 | && current_trace_status ()->running && loc->owner |
| 14654 | && is_tracepoint (loc->owner)) |
| 14655 | target_disable_tracepoint (loc); |
| 14656 | } |
| 14657 | update_global_location_list (UGLL_DONT_INSERT); |
| 14658 | } |
| 14659 | else |
| 14660 | map_breakpoint_numbers (num, do_map_disable_breakpoint, NULL); |
| 14661 | num = extract_arg (&args); |
| 14662 | } |
| 14663 | } |
| 14664 | } |
| 14665 | |
| 14666 | static void |
| 14667 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
| 14668 | int count) |
| 14669 | { |
| 14670 | int target_resources_ok; |
| 14671 | |
| 14672 | if (bpt->type == bp_hardware_breakpoint) |
| 14673 | { |
| 14674 | int i; |
| 14675 | i = hw_breakpoint_used_count (); |
| 14676 | target_resources_ok = |
| 14677 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 14678 | i + 1, 0); |
| 14679 | if (target_resources_ok == 0) |
| 14680 | error (_("No hardware breakpoint support in the target.")); |
| 14681 | else if (target_resources_ok < 0) |
| 14682 | error (_("Hardware breakpoints used exceeds limit.")); |
| 14683 | } |
| 14684 | |
| 14685 | if (is_watchpoint (bpt)) |
| 14686 | { |
| 14687 | /* Initialize it just to avoid a GCC false warning. */ |
| 14688 | enum enable_state orig_enable_state = bp_disabled; |
| 14689 | |
| 14690 | TRY |
| 14691 | { |
| 14692 | struct watchpoint *w = (struct watchpoint *) bpt; |
| 14693 | |
| 14694 | orig_enable_state = bpt->enable_state; |
| 14695 | bpt->enable_state = bp_enabled; |
| 14696 | update_watchpoint (w, 1 /* reparse */); |
| 14697 | } |
| 14698 | CATCH (e, RETURN_MASK_ALL) |
| 14699 | { |
| 14700 | bpt->enable_state = orig_enable_state; |
| 14701 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
| 14702 | bpt->number); |
| 14703 | return; |
| 14704 | } |
| 14705 | END_CATCH |
| 14706 | } |
| 14707 | |
| 14708 | bpt->enable_state = bp_enabled; |
| 14709 | |
| 14710 | /* Mark breakpoint locations modified. */ |
| 14711 | mark_breakpoint_modified (bpt); |
| 14712 | |
| 14713 | if (target_supports_enable_disable_tracepoint () |
| 14714 | && current_trace_status ()->running && is_tracepoint (bpt)) |
| 14715 | { |
| 14716 | struct bp_location *location; |
| 14717 | |
| 14718 | for (location = bpt->loc; location; location = location->next) |
| 14719 | target_enable_tracepoint (location); |
| 14720 | } |
| 14721 | |
| 14722 | bpt->disposition = disposition; |
| 14723 | bpt->enable_count = count; |
| 14724 | update_global_location_list (UGLL_MAY_INSERT); |
| 14725 | |
| 14726 | observer_notify_breakpoint_modified (bpt); |
| 14727 | } |
| 14728 | |
| 14729 | |
| 14730 | void |
| 14731 | enable_breakpoint (struct breakpoint *bpt) |
| 14732 | { |
| 14733 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
| 14734 | } |
| 14735 | |
| 14736 | static void |
| 14737 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) |
| 14738 | { |
| 14739 | enable_breakpoint (bpt); |
| 14740 | } |
| 14741 | |
| 14742 | /* A callback for map_breakpoint_numbers that calls |
| 14743 | enable_breakpoint. */ |
| 14744 | |
| 14745 | static void |
| 14746 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) |
| 14747 | { |
| 14748 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
| 14749 | } |
| 14750 | |
| 14751 | /* The enable command enables the specified breakpoints (or all defined |
| 14752 | breakpoints) so they once again become (or continue to be) effective |
| 14753 | in stopping the inferior. */ |
| 14754 | |
| 14755 | static void |
| 14756 | enable_command (char *args, int from_tty) |
| 14757 | { |
| 14758 | if (args == 0) |
| 14759 | { |
| 14760 | struct breakpoint *bpt; |
| 14761 | |
| 14762 | ALL_BREAKPOINTS (bpt) |
| 14763 | if (user_breakpoint_p (bpt)) |
| 14764 | enable_breakpoint (bpt); |
| 14765 | } |
| 14766 | else |
| 14767 | { |
| 14768 | char *num = extract_arg (&args); |
| 14769 | |
| 14770 | while (num) |
| 14771 | { |
| 14772 | if (strchr (num, '.')) |
| 14773 | { |
| 14774 | struct bp_location *loc = find_location_by_number (num); |
| 14775 | |
| 14776 | if (loc) |
| 14777 | { |
| 14778 | if (!loc->enabled) |
| 14779 | { |
| 14780 | loc->enabled = 1; |
| 14781 | mark_breakpoint_location_modified (loc); |
| 14782 | } |
| 14783 | if (target_supports_enable_disable_tracepoint () |
| 14784 | && current_trace_status ()->running && loc->owner |
| 14785 | && is_tracepoint (loc->owner)) |
| 14786 | target_enable_tracepoint (loc); |
| 14787 | } |
| 14788 | update_global_location_list (UGLL_MAY_INSERT); |
| 14789 | } |
| 14790 | else |
| 14791 | map_breakpoint_numbers (num, do_map_enable_breakpoint, NULL); |
| 14792 | num = extract_arg (&args); |
| 14793 | } |
| 14794 | } |
| 14795 | } |
| 14796 | |
| 14797 | /* This struct packages up disposition data for application to multiple |
| 14798 | breakpoints. */ |
| 14799 | |
| 14800 | struct disp_data |
| 14801 | { |
| 14802 | enum bpdisp disp; |
| 14803 | int count; |
| 14804 | }; |
| 14805 | |
| 14806 | static void |
| 14807 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
| 14808 | { |
| 14809 | struct disp_data disp_data = *(struct disp_data *) arg; |
| 14810 | |
| 14811 | enable_breakpoint_disp (bpt, disp_data.disp, disp_data.count); |
| 14812 | } |
| 14813 | |
| 14814 | static void |
| 14815 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
| 14816 | { |
| 14817 | struct disp_data disp = { disp_disable, 1 }; |
| 14818 | |
| 14819 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); |
| 14820 | } |
| 14821 | |
| 14822 | static void |
| 14823 | enable_once_command (char *args, int from_tty) |
| 14824 | { |
| 14825 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
| 14826 | } |
| 14827 | |
| 14828 | static void |
| 14829 | do_map_enable_count_breakpoint (struct breakpoint *bpt, void *countptr) |
| 14830 | { |
| 14831 | struct disp_data disp = { disp_disable, *(int *) countptr }; |
| 14832 | |
| 14833 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); |
| 14834 | } |
| 14835 | |
| 14836 | static void |
| 14837 | enable_count_command (char *args, int from_tty) |
| 14838 | { |
| 14839 | int count; |
| 14840 | |
| 14841 | if (args == NULL) |
| 14842 | error_no_arg (_("hit count")); |
| 14843 | |
| 14844 | count = get_number (&args); |
| 14845 | |
| 14846 | map_breakpoint_numbers (args, do_map_enable_count_breakpoint, &count); |
| 14847 | } |
| 14848 | |
| 14849 | static void |
| 14850 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
| 14851 | { |
| 14852 | struct disp_data disp = { disp_del, 1 }; |
| 14853 | |
| 14854 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); |
| 14855 | } |
| 14856 | |
| 14857 | static void |
| 14858 | enable_delete_command (char *args, int from_tty) |
| 14859 | { |
| 14860 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
| 14861 | } |
| 14862 | \f |
| 14863 | static void |
| 14864 | set_breakpoint_cmd (char *args, int from_tty) |
| 14865 | { |
| 14866 | } |
| 14867 | |
| 14868 | static void |
| 14869 | show_breakpoint_cmd (char *args, int from_tty) |
| 14870 | { |
| 14871 | } |
| 14872 | |
| 14873 | /* Invalidate last known value of any hardware watchpoint if |
| 14874 | the memory which that value represents has been written to by |
| 14875 | GDB itself. */ |
| 14876 | |
| 14877 | static void |
| 14878 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
| 14879 | CORE_ADDR addr, ssize_t len, |
| 14880 | const bfd_byte *data) |
| 14881 | { |
| 14882 | struct breakpoint *bp; |
| 14883 | |
| 14884 | ALL_BREAKPOINTS (bp) |
| 14885 | if (bp->enable_state == bp_enabled |
| 14886 | && bp->type == bp_hardware_watchpoint) |
| 14887 | { |
| 14888 | struct watchpoint *wp = (struct watchpoint *) bp; |
| 14889 | |
| 14890 | if (wp->val_valid && wp->val) |
| 14891 | { |
| 14892 | struct bp_location *loc; |
| 14893 | |
| 14894 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
| 14895 | if (loc->loc_type == bp_loc_hardware_watchpoint |
| 14896 | && loc->address + loc->length > addr |
| 14897 | && addr + len > loc->address) |
| 14898 | { |
| 14899 | value_free (wp->val); |
| 14900 | wp->val = NULL; |
| 14901 | wp->val_valid = 0; |
| 14902 | } |
| 14903 | } |
| 14904 | } |
| 14905 | } |
| 14906 | |
| 14907 | /* Create and insert a breakpoint for software single step. */ |
| 14908 | |
| 14909 | void |
| 14910 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
| 14911 | struct address_space *aspace, |
| 14912 | CORE_ADDR next_pc) |
| 14913 | { |
| 14914 | struct thread_info *tp = inferior_thread (); |
| 14915 | struct symtab_and_line sal; |
| 14916 | CORE_ADDR pc = next_pc; |
| 14917 | |
| 14918 | if (tp->control.single_step_breakpoints == NULL) |
| 14919 | { |
| 14920 | tp->control.single_step_breakpoints |
| 14921 | = new_single_step_breakpoint (tp->num, gdbarch); |
| 14922 | } |
| 14923 | |
| 14924 | sal = find_pc_line (pc, 0); |
| 14925 | sal.pc = pc; |
| 14926 | sal.section = find_pc_overlay (pc); |
| 14927 | sal.explicit_pc = 1; |
| 14928 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
| 14929 | |
| 14930 | update_global_location_list (UGLL_INSERT); |
| 14931 | } |
| 14932 | |
| 14933 | /* See breakpoint.h. */ |
| 14934 | |
| 14935 | int |
| 14936 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
| 14937 | struct address_space *aspace, |
| 14938 | CORE_ADDR pc) |
| 14939 | { |
| 14940 | struct bp_location *loc; |
| 14941 | |
| 14942 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
| 14943 | if (loc->inserted |
| 14944 | && breakpoint_location_address_match (loc, aspace, pc)) |
| 14945 | return 1; |
| 14946 | |
| 14947 | return 0; |
| 14948 | } |
| 14949 | |
| 14950 | /* Check whether a software single-step breakpoint is inserted at |
| 14951 | PC. */ |
| 14952 | |
| 14953 | int |
| 14954 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
| 14955 | CORE_ADDR pc) |
| 14956 | { |
| 14957 | struct breakpoint *bpt; |
| 14958 | |
| 14959 | ALL_BREAKPOINTS (bpt) |
| 14960 | { |
| 14961 | if (bpt->type == bp_single_step |
| 14962 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) |
| 14963 | return 1; |
| 14964 | } |
| 14965 | return 0; |
| 14966 | } |
| 14967 | |
| 14968 | /* Tracepoint-specific operations. */ |
| 14969 | |
| 14970 | /* Set tracepoint count to NUM. */ |
| 14971 | static void |
| 14972 | set_tracepoint_count (int num) |
| 14973 | { |
| 14974 | tracepoint_count = num; |
| 14975 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
| 14976 | } |
| 14977 | |
| 14978 | static void |
| 14979 | trace_command (char *arg, int from_tty) |
| 14980 | { |
| 14981 | struct breakpoint_ops *ops; |
| 14982 | struct event_location *location; |
| 14983 | struct cleanup *back_to; |
| 14984 | |
| 14985 | location = string_to_event_location (&arg, current_language); |
| 14986 | back_to = make_cleanup_delete_event_location (location); |
| 14987 | if (location != NULL |
| 14988 | && event_location_type (location) == PROBE_LOCATION) |
| 14989 | ops = &tracepoint_probe_breakpoint_ops; |
| 14990 | else |
| 14991 | ops = &tracepoint_breakpoint_ops; |
| 14992 | |
| 14993 | create_breakpoint (get_current_arch (), |
| 14994 | location, |
| 14995 | NULL, 0, arg, 1 /* parse arg */, |
| 14996 | 0 /* tempflag */, |
| 14997 | bp_tracepoint /* type_wanted */, |
| 14998 | 0 /* Ignore count */, |
| 14999 | pending_break_support, |
| 15000 | ops, |
| 15001 | from_tty, |
| 15002 | 1 /* enabled */, |
| 15003 | 0 /* internal */, 0); |
| 15004 | do_cleanups (back_to); |
| 15005 | } |
| 15006 | |
| 15007 | static void |
| 15008 | ftrace_command (char *arg, int from_tty) |
| 15009 | { |
| 15010 | struct event_location *location; |
| 15011 | struct cleanup *back_to; |
| 15012 | |
| 15013 | location = string_to_event_location (&arg, current_language); |
| 15014 | back_to = make_cleanup_delete_event_location (location); |
| 15015 | create_breakpoint (get_current_arch (), |
| 15016 | location, |
| 15017 | NULL, 0, arg, 1 /* parse arg */, |
| 15018 | 0 /* tempflag */, |
| 15019 | bp_fast_tracepoint /* type_wanted */, |
| 15020 | 0 /* Ignore count */, |
| 15021 | pending_break_support, |
| 15022 | &tracepoint_breakpoint_ops, |
| 15023 | from_tty, |
| 15024 | 1 /* enabled */, |
| 15025 | 0 /* internal */, 0); |
| 15026 | do_cleanups (back_to); |
| 15027 | } |
| 15028 | |
| 15029 | /* strace command implementation. Creates a static tracepoint. */ |
| 15030 | |
| 15031 | static void |
| 15032 | strace_command (char *arg, int from_tty) |
| 15033 | { |
| 15034 | struct breakpoint_ops *ops; |
| 15035 | struct event_location *location; |
| 15036 | struct cleanup *back_to; |
| 15037 | |
| 15038 | /* Decide if we are dealing with a static tracepoint marker (`-m'), |
| 15039 | or with a normal static tracepoint. */ |
| 15040 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
| 15041 | { |
| 15042 | ops = &strace_marker_breakpoint_ops; |
| 15043 | location = new_linespec_location (&arg); |
| 15044 | } |
| 15045 | else |
| 15046 | { |
| 15047 | ops = &tracepoint_breakpoint_ops; |
| 15048 | location = string_to_event_location (&arg, current_language); |
| 15049 | } |
| 15050 | |
| 15051 | back_to = make_cleanup_delete_event_location (location); |
| 15052 | create_breakpoint (get_current_arch (), |
| 15053 | location, |
| 15054 | NULL, 0, arg, 1 /* parse arg */, |
| 15055 | 0 /* tempflag */, |
| 15056 | bp_static_tracepoint /* type_wanted */, |
| 15057 | 0 /* Ignore count */, |
| 15058 | pending_break_support, |
| 15059 | ops, |
| 15060 | from_tty, |
| 15061 | 1 /* enabled */, |
| 15062 | 0 /* internal */, 0); |
| 15063 | do_cleanups (back_to); |
| 15064 | } |
| 15065 | |
| 15066 | /* Set up a fake reader function that gets command lines from a linked |
| 15067 | list that was acquired during tracepoint uploading. */ |
| 15068 | |
| 15069 | static struct uploaded_tp *this_utp; |
| 15070 | static int next_cmd; |
| 15071 | |
| 15072 | static char * |
| 15073 | read_uploaded_action (void) |
| 15074 | { |
| 15075 | char *rslt; |
| 15076 | |
| 15077 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
| 15078 | |
| 15079 | next_cmd++; |
| 15080 | |
| 15081 | return rslt; |
| 15082 | } |
| 15083 | |
| 15084 | /* Given information about a tracepoint as recorded on a target (which |
| 15085 | can be either a live system or a trace file), attempt to create an |
| 15086 | equivalent GDB tracepoint. This is not a reliable process, since |
| 15087 | the target does not necessarily have all the information used when |
| 15088 | the tracepoint was originally defined. */ |
| 15089 | |
| 15090 | struct tracepoint * |
| 15091 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
| 15092 | { |
| 15093 | char *addr_str, small_buf[100]; |
| 15094 | struct tracepoint *tp; |
| 15095 | struct event_location *location; |
| 15096 | struct cleanup *cleanup; |
| 15097 | |
| 15098 | if (utp->at_string) |
| 15099 | addr_str = utp->at_string; |
| 15100 | else |
| 15101 | { |
| 15102 | /* In the absence of a source location, fall back to raw |
| 15103 | address. Since there is no way to confirm that the address |
| 15104 | means the same thing as when the trace was started, warn the |
| 15105 | user. */ |
| 15106 | warning (_("Uploaded tracepoint %d has no " |
| 15107 | "source location, using raw address"), |
| 15108 | utp->number); |
| 15109 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
| 15110 | addr_str = small_buf; |
| 15111 | } |
| 15112 | |
| 15113 | /* There's not much we can do with a sequence of bytecodes. */ |
| 15114 | if (utp->cond && !utp->cond_string) |
| 15115 | warning (_("Uploaded tracepoint %d condition " |
| 15116 | "has no source form, ignoring it"), |
| 15117 | utp->number); |
| 15118 | |
| 15119 | location = string_to_event_location (&addr_str, current_language); |
| 15120 | cleanup = make_cleanup_delete_event_location (location); |
| 15121 | if (!create_breakpoint (get_current_arch (), |
| 15122 | location, |
| 15123 | utp->cond_string, -1, addr_str, |
| 15124 | 0 /* parse cond/thread */, |
| 15125 | 0 /* tempflag */, |
| 15126 | utp->type /* type_wanted */, |
| 15127 | 0 /* Ignore count */, |
| 15128 | pending_break_support, |
| 15129 | &tracepoint_breakpoint_ops, |
| 15130 | 0 /* from_tty */, |
| 15131 | utp->enabled /* enabled */, |
| 15132 | 0 /* internal */, |
| 15133 | CREATE_BREAKPOINT_FLAGS_INSERTED)) |
| 15134 | { |
| 15135 | do_cleanups (cleanup); |
| 15136 | return NULL; |
| 15137 | } |
| 15138 | |
| 15139 | do_cleanups (cleanup); |
| 15140 | |
| 15141 | /* Get the tracepoint we just created. */ |
| 15142 | tp = get_tracepoint (tracepoint_count); |
| 15143 | gdb_assert (tp != NULL); |
| 15144 | |
| 15145 | if (utp->pass > 0) |
| 15146 | { |
| 15147 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
| 15148 | tp->base.number); |
| 15149 | |
| 15150 | trace_pass_command (small_buf, 0); |
| 15151 | } |
| 15152 | |
| 15153 | /* If we have uploaded versions of the original commands, set up a |
| 15154 | special-purpose "reader" function and call the usual command line |
| 15155 | reader, then pass the result to the breakpoint command-setting |
| 15156 | function. */ |
| 15157 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
| 15158 | { |
| 15159 | struct command_line *cmd_list; |
| 15160 | |
| 15161 | this_utp = utp; |
| 15162 | next_cmd = 0; |
| 15163 | |
| 15164 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
| 15165 | |
| 15166 | breakpoint_set_commands (&tp->base, cmd_list); |
| 15167 | } |
| 15168 | else if (!VEC_empty (char_ptr, utp->actions) |
| 15169 | || !VEC_empty (char_ptr, utp->step_actions)) |
| 15170 | warning (_("Uploaded tracepoint %d actions " |
| 15171 | "have no source form, ignoring them"), |
| 15172 | utp->number); |
| 15173 | |
| 15174 | /* Copy any status information that might be available. */ |
| 15175 | tp->base.hit_count = utp->hit_count; |
| 15176 | tp->traceframe_usage = utp->traceframe_usage; |
| 15177 | |
| 15178 | return tp; |
| 15179 | } |
| 15180 | |
| 15181 | /* Print information on tracepoint number TPNUM_EXP, or all if |
| 15182 | omitted. */ |
| 15183 | |
| 15184 | static void |
| 15185 | tracepoints_info (char *args, int from_tty) |
| 15186 | { |
| 15187 | struct ui_out *uiout = current_uiout; |
| 15188 | int num_printed; |
| 15189 | |
| 15190 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
| 15191 | |
| 15192 | if (num_printed == 0) |
| 15193 | { |
| 15194 | if (args == NULL || *args == '\0') |
| 15195 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
| 15196 | else |
| 15197 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
| 15198 | } |
| 15199 | |
| 15200 | default_collect_info (); |
| 15201 | } |
| 15202 | |
| 15203 | /* The 'enable trace' command enables tracepoints. |
| 15204 | Not supported by all targets. */ |
| 15205 | static void |
| 15206 | enable_trace_command (char *args, int from_tty) |
| 15207 | { |
| 15208 | enable_command (args, from_tty); |
| 15209 | } |
| 15210 | |
| 15211 | /* The 'disable trace' command disables tracepoints. |
| 15212 | Not supported by all targets. */ |
| 15213 | static void |
| 15214 | disable_trace_command (char *args, int from_tty) |
| 15215 | { |
| 15216 | disable_command (args, from_tty); |
| 15217 | } |
| 15218 | |
| 15219 | /* Remove a tracepoint (or all if no argument). */ |
| 15220 | static void |
| 15221 | delete_trace_command (char *arg, int from_tty) |
| 15222 | { |
| 15223 | struct breakpoint *b, *b_tmp; |
| 15224 | |
| 15225 | dont_repeat (); |
| 15226 | |
| 15227 | if (arg == 0) |
| 15228 | { |
| 15229 | int breaks_to_delete = 0; |
| 15230 | |
| 15231 | /* Delete all breakpoints if no argument. |
| 15232 | Do not delete internal or call-dummy breakpoints, these |
| 15233 | have to be deleted with an explicit breakpoint number |
| 15234 | argument. */ |
| 15235 | ALL_TRACEPOINTS (b) |
| 15236 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
| 15237 | { |
| 15238 | breaks_to_delete = 1; |
| 15239 | break; |
| 15240 | } |
| 15241 | |
| 15242 | /* Ask user only if there are some breakpoints to delete. */ |
| 15243 | if (!from_tty |
| 15244 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) |
| 15245 | { |
| 15246 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 15247 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
| 15248 | delete_breakpoint (b); |
| 15249 | } |
| 15250 | } |
| 15251 | else |
| 15252 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
| 15253 | } |
| 15254 | |
| 15255 | /* Helper function for trace_pass_command. */ |
| 15256 | |
| 15257 | static void |
| 15258 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
| 15259 | { |
| 15260 | tp->pass_count = count; |
| 15261 | observer_notify_breakpoint_modified (&tp->base); |
| 15262 | if (from_tty) |
| 15263 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), |
| 15264 | tp->base.number, count); |
| 15265 | } |
| 15266 | |
| 15267 | /* Set passcount for tracepoint. |
| 15268 | |
| 15269 | First command argument is passcount, second is tracepoint number. |
| 15270 | If tracepoint number omitted, apply to most recently defined. |
| 15271 | Also accepts special argument "all". */ |
| 15272 | |
| 15273 | static void |
| 15274 | trace_pass_command (char *args, int from_tty) |
| 15275 | { |
| 15276 | struct tracepoint *t1; |
| 15277 | unsigned int count; |
| 15278 | |
| 15279 | if (args == 0 || *args == 0) |
| 15280 | error (_("passcount command requires an " |
| 15281 | "argument (count + optional TP num)")); |
| 15282 | |
| 15283 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
| 15284 | |
| 15285 | args = skip_spaces (args); |
| 15286 | if (*args && strncasecmp (args, "all", 3) == 0) |
| 15287 | { |
| 15288 | struct breakpoint *b; |
| 15289 | |
| 15290 | args += 3; /* Skip special argument "all". */ |
| 15291 | if (*args) |
| 15292 | error (_("Junk at end of arguments.")); |
| 15293 | |
| 15294 | ALL_TRACEPOINTS (b) |
| 15295 | { |
| 15296 | t1 = (struct tracepoint *) b; |
| 15297 | trace_pass_set_count (t1, count, from_tty); |
| 15298 | } |
| 15299 | } |
| 15300 | else if (*args == '\0') |
| 15301 | { |
| 15302 | t1 = get_tracepoint_by_number (&args, NULL); |
| 15303 | if (t1) |
| 15304 | trace_pass_set_count (t1, count, from_tty); |
| 15305 | } |
| 15306 | else |
| 15307 | { |
| 15308 | struct get_number_or_range_state state; |
| 15309 | |
| 15310 | init_number_or_range (&state, args); |
| 15311 | while (!state.finished) |
| 15312 | { |
| 15313 | t1 = get_tracepoint_by_number (&args, &state); |
| 15314 | if (t1) |
| 15315 | trace_pass_set_count (t1, count, from_tty); |
| 15316 | } |
| 15317 | } |
| 15318 | } |
| 15319 | |
| 15320 | struct tracepoint * |
| 15321 | get_tracepoint (int num) |
| 15322 | { |
| 15323 | struct breakpoint *t; |
| 15324 | |
| 15325 | ALL_TRACEPOINTS (t) |
| 15326 | if (t->number == num) |
| 15327 | return (struct tracepoint *) t; |
| 15328 | |
| 15329 | return NULL; |
| 15330 | } |
| 15331 | |
| 15332 | /* Find the tracepoint with the given target-side number (which may be |
| 15333 | different from the tracepoint number after disconnecting and |
| 15334 | reconnecting). */ |
| 15335 | |
| 15336 | struct tracepoint * |
| 15337 | get_tracepoint_by_number_on_target (int num) |
| 15338 | { |
| 15339 | struct breakpoint *b; |
| 15340 | |
| 15341 | ALL_TRACEPOINTS (b) |
| 15342 | { |
| 15343 | struct tracepoint *t = (struct tracepoint *) b; |
| 15344 | |
| 15345 | if (t->number_on_target == num) |
| 15346 | return t; |
| 15347 | } |
| 15348 | |
| 15349 | return NULL; |
| 15350 | } |
| 15351 | |
| 15352 | /* Utility: parse a tracepoint number and look it up in the list. |
| 15353 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
| 15354 | If the argument is missing, the most recent tracepoint |
| 15355 | (tracepoint_count) is returned. */ |
| 15356 | |
| 15357 | struct tracepoint * |
| 15358 | get_tracepoint_by_number (char **arg, |
| 15359 | struct get_number_or_range_state *state) |
| 15360 | { |
| 15361 | struct breakpoint *t; |
| 15362 | int tpnum; |
| 15363 | char *instring = arg == NULL ? NULL : *arg; |
| 15364 | |
| 15365 | if (state) |
| 15366 | { |
| 15367 | gdb_assert (!state->finished); |
| 15368 | tpnum = get_number_or_range (state); |
| 15369 | } |
| 15370 | else if (arg == NULL || *arg == NULL || ! **arg) |
| 15371 | tpnum = tracepoint_count; |
| 15372 | else |
| 15373 | tpnum = get_number (arg); |
| 15374 | |
| 15375 | if (tpnum <= 0) |
| 15376 | { |
| 15377 | if (instring && *instring) |
| 15378 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), |
| 15379 | instring); |
| 15380 | else |
| 15381 | printf_filtered (_("No previous tracepoint\n")); |
| 15382 | return NULL; |
| 15383 | } |
| 15384 | |
| 15385 | ALL_TRACEPOINTS (t) |
| 15386 | if (t->number == tpnum) |
| 15387 | { |
| 15388 | return (struct tracepoint *) t; |
| 15389 | } |
| 15390 | |
| 15391 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
| 15392 | return NULL; |
| 15393 | } |
| 15394 | |
| 15395 | void |
| 15396 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) |
| 15397 | { |
| 15398 | if (b->thread != -1) |
| 15399 | fprintf_unfiltered (fp, " thread %d", b->thread); |
| 15400 | |
| 15401 | if (b->task != 0) |
| 15402 | fprintf_unfiltered (fp, " task %d", b->task); |
| 15403 | |
| 15404 | fprintf_unfiltered (fp, "\n"); |
| 15405 | } |
| 15406 | |
| 15407 | /* Save information on user settable breakpoints (watchpoints, etc) to |
| 15408 | a new script file named FILENAME. If FILTER is non-NULL, call it |
| 15409 | on each breakpoint and only include the ones for which it returns |
| 15410 | non-zero. */ |
| 15411 | |
| 15412 | static void |
| 15413 | save_breakpoints (char *filename, int from_tty, |
| 15414 | int (*filter) (const struct breakpoint *)) |
| 15415 | { |
| 15416 | struct breakpoint *tp; |
| 15417 | int any = 0; |
| 15418 | struct cleanup *cleanup; |
| 15419 | struct ui_file *fp; |
| 15420 | int extra_trace_bits = 0; |
| 15421 | |
| 15422 | if (filename == 0 || *filename == 0) |
| 15423 | error (_("Argument required (file name in which to save)")); |
| 15424 | |
| 15425 | /* See if we have anything to save. */ |
| 15426 | ALL_BREAKPOINTS (tp) |
| 15427 | { |
| 15428 | /* Skip internal and momentary breakpoints. */ |
| 15429 | if (!user_breakpoint_p (tp)) |
| 15430 | continue; |
| 15431 | |
| 15432 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 15433 | if (filter && !filter (tp)) |
| 15434 | continue; |
| 15435 | |
| 15436 | any = 1; |
| 15437 | |
| 15438 | if (is_tracepoint (tp)) |
| 15439 | { |
| 15440 | extra_trace_bits = 1; |
| 15441 | |
| 15442 | /* We can stop searching. */ |
| 15443 | break; |
| 15444 | } |
| 15445 | } |
| 15446 | |
| 15447 | if (!any) |
| 15448 | { |
| 15449 | warning (_("Nothing to save.")); |
| 15450 | return; |
| 15451 | } |
| 15452 | |
| 15453 | filename = tilde_expand (filename); |
| 15454 | cleanup = make_cleanup (xfree, filename); |
| 15455 | fp = gdb_fopen (filename, "w"); |
| 15456 | if (!fp) |
| 15457 | error (_("Unable to open file '%s' for saving (%s)"), |
| 15458 | filename, safe_strerror (errno)); |
| 15459 | make_cleanup_ui_file_delete (fp); |
| 15460 | |
| 15461 | if (extra_trace_bits) |
| 15462 | save_trace_state_variables (fp); |
| 15463 | |
| 15464 | ALL_BREAKPOINTS (tp) |
| 15465 | { |
| 15466 | /* Skip internal and momentary breakpoints. */ |
| 15467 | if (!user_breakpoint_p (tp)) |
| 15468 | continue; |
| 15469 | |
| 15470 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 15471 | if (filter && !filter (tp)) |
| 15472 | continue; |
| 15473 | |
| 15474 | tp->ops->print_recreate (tp, fp); |
| 15475 | |
| 15476 | /* Note, we can't rely on tp->number for anything, as we can't |
| 15477 | assume the recreated breakpoint numbers will match. Use $bpnum |
| 15478 | instead. */ |
| 15479 | |
| 15480 | if (tp->cond_string) |
| 15481 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); |
| 15482 | |
| 15483 | if (tp->ignore_count) |
| 15484 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); |
| 15485 | |
| 15486 | if (tp->type != bp_dprintf && tp->commands) |
| 15487 | { |
| 15488 | struct gdb_exception exception; |
| 15489 | |
| 15490 | fprintf_unfiltered (fp, " commands\n"); |
| 15491 | |
| 15492 | ui_out_redirect (current_uiout, fp); |
| 15493 | TRY |
| 15494 | { |
| 15495 | print_command_lines (current_uiout, tp->commands->commands, 2); |
| 15496 | } |
| 15497 | CATCH (ex, RETURN_MASK_ALL) |
| 15498 | { |
| 15499 | ui_out_redirect (current_uiout, NULL); |
| 15500 | throw_exception (ex); |
| 15501 | } |
| 15502 | END_CATCH |
| 15503 | |
| 15504 | ui_out_redirect (current_uiout, NULL); |
| 15505 | fprintf_unfiltered (fp, " end\n"); |
| 15506 | } |
| 15507 | |
| 15508 | if (tp->enable_state == bp_disabled) |
| 15509 | fprintf_unfiltered (fp, "disable $bpnum\n"); |
| 15510 | |
| 15511 | /* If this is a multi-location breakpoint, check if the locations |
| 15512 | should be individually disabled. Watchpoint locations are |
| 15513 | special, and not user visible. */ |
| 15514 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) |
| 15515 | { |
| 15516 | struct bp_location *loc; |
| 15517 | int n = 1; |
| 15518 | |
| 15519 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) |
| 15520 | if (!loc->enabled) |
| 15521 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); |
| 15522 | } |
| 15523 | } |
| 15524 | |
| 15525 | if (extra_trace_bits && *default_collect) |
| 15526 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
| 15527 | |
| 15528 | if (from_tty) |
| 15529 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
| 15530 | do_cleanups (cleanup); |
| 15531 | } |
| 15532 | |
| 15533 | /* The `save breakpoints' command. */ |
| 15534 | |
| 15535 | static void |
| 15536 | save_breakpoints_command (char *args, int from_tty) |
| 15537 | { |
| 15538 | save_breakpoints (args, from_tty, NULL); |
| 15539 | } |
| 15540 | |
| 15541 | /* The `save tracepoints' command. */ |
| 15542 | |
| 15543 | static void |
| 15544 | save_tracepoints_command (char *args, int from_tty) |
| 15545 | { |
| 15546 | save_breakpoints (args, from_tty, is_tracepoint); |
| 15547 | } |
| 15548 | |
| 15549 | /* Create a vector of all tracepoints. */ |
| 15550 | |
| 15551 | VEC(breakpoint_p) * |
| 15552 | all_tracepoints (void) |
| 15553 | { |
| 15554 | VEC(breakpoint_p) *tp_vec = 0; |
| 15555 | struct breakpoint *tp; |
| 15556 | |
| 15557 | ALL_TRACEPOINTS (tp) |
| 15558 | { |
| 15559 | VEC_safe_push (breakpoint_p, tp_vec, tp); |
| 15560 | } |
| 15561 | |
| 15562 | return tp_vec; |
| 15563 | } |
| 15564 | |
| 15565 | \f |
| 15566 | /* This help string is used for the break, hbreak, tbreak and thbreak |
| 15567 | commands. It is defined as a macro to prevent duplication. |
| 15568 | COMMAND should be a string constant containing the name of the |
| 15569 | command. */ |
| 15570 | #define BREAK_ARGS_HELP(command) \ |
| 15571 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
| 15572 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ |
| 15573 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ |
| 15574 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
| 15575 | `-probe-dtrace' (for a DTrace probe).\n\ |
| 15576 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ |
| 15577 | If a line number is specified, break at start of code for that line.\n\ |
| 15578 | If a function is specified, break at start of code for that function.\n\ |
| 15579 | If an address is specified, break at that exact address.\n\ |
| 15580 | With no LOCATION, uses current execution address of the selected\n\ |
| 15581 | stack frame. This is useful for breaking on return to a stack frame.\n\ |
| 15582 | \n\ |
| 15583 | THREADNUM is the number from \"info threads\".\n\ |
| 15584 | CONDITION is a boolean expression.\n\ |
| 15585 | \n\ |
| 15586 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
| 15587 | conditions are different.\n\ |
| 15588 | \n\ |
| 15589 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." |
| 15590 | |
| 15591 | /* List of subcommands for "catch". */ |
| 15592 | static struct cmd_list_element *catch_cmdlist; |
| 15593 | |
| 15594 | /* List of subcommands for "tcatch". */ |
| 15595 | static struct cmd_list_element *tcatch_cmdlist; |
| 15596 | |
| 15597 | void |
| 15598 | add_catch_command (char *name, char *docstring, |
| 15599 | cmd_sfunc_ftype *sfunc, |
| 15600 | completer_ftype *completer, |
| 15601 | void *user_data_catch, |
| 15602 | void *user_data_tcatch) |
| 15603 | { |
| 15604 | struct cmd_list_element *command; |
| 15605 | |
| 15606 | command = add_cmd (name, class_breakpoint, NULL, docstring, |
| 15607 | &catch_cmdlist); |
| 15608 | set_cmd_sfunc (command, sfunc); |
| 15609 | set_cmd_context (command, user_data_catch); |
| 15610 | set_cmd_completer (command, completer); |
| 15611 | |
| 15612 | command = add_cmd (name, class_breakpoint, NULL, docstring, |
| 15613 | &tcatch_cmdlist); |
| 15614 | set_cmd_sfunc (command, sfunc); |
| 15615 | set_cmd_context (command, user_data_tcatch); |
| 15616 | set_cmd_completer (command, completer); |
| 15617 | } |
| 15618 | |
| 15619 | static void |
| 15620 | save_command (char *arg, int from_tty) |
| 15621 | { |
| 15622 | printf_unfiltered (_("\"save\" must be followed by " |
| 15623 | "the name of a save subcommand.\n")); |
| 15624 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
| 15625 | } |
| 15626 | |
| 15627 | struct breakpoint * |
| 15628 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), |
| 15629 | void *data) |
| 15630 | { |
| 15631 | struct breakpoint *b, *b_tmp; |
| 15632 | |
| 15633 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 15634 | { |
| 15635 | if ((*callback) (b, data)) |
| 15636 | return b; |
| 15637 | } |
| 15638 | |
| 15639 | return NULL; |
| 15640 | } |
| 15641 | |
| 15642 | /* Zero if any of the breakpoint's locations could be a location where |
| 15643 | functions have been inlined, nonzero otherwise. */ |
| 15644 | |
| 15645 | static int |
| 15646 | is_non_inline_function (struct breakpoint *b) |
| 15647 | { |
| 15648 | /* The shared library event breakpoint is set on the address of a |
| 15649 | non-inline function. */ |
| 15650 | if (b->type == bp_shlib_event) |
| 15651 | return 1; |
| 15652 | |
| 15653 | return 0; |
| 15654 | } |
| 15655 | |
| 15656 | /* Nonzero if the specified PC cannot be a location where functions |
| 15657 | have been inlined. */ |
| 15658 | |
| 15659 | int |
| 15660 | pc_at_non_inline_function (struct address_space *aspace, CORE_ADDR pc, |
| 15661 | const struct target_waitstatus *ws) |
| 15662 | { |
| 15663 | struct breakpoint *b; |
| 15664 | struct bp_location *bl; |
| 15665 | |
| 15666 | ALL_BREAKPOINTS (b) |
| 15667 | { |
| 15668 | if (!is_non_inline_function (b)) |
| 15669 | continue; |
| 15670 | |
| 15671 | for (bl = b->loc; bl != NULL; bl = bl->next) |
| 15672 | { |
| 15673 | if (!bl->shlib_disabled |
| 15674 | && bpstat_check_location (bl, aspace, pc, ws)) |
| 15675 | return 1; |
| 15676 | } |
| 15677 | } |
| 15678 | |
| 15679 | return 0; |
| 15680 | } |
| 15681 | |
| 15682 | /* Remove any references to OBJFILE which is going to be freed. */ |
| 15683 | |
| 15684 | void |
| 15685 | breakpoint_free_objfile (struct objfile *objfile) |
| 15686 | { |
| 15687 | struct bp_location **locp, *loc; |
| 15688 | |
| 15689 | ALL_BP_LOCATIONS (loc, locp) |
| 15690 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
| 15691 | loc->symtab = NULL; |
| 15692 | } |
| 15693 | |
| 15694 | void |
| 15695 | initialize_breakpoint_ops (void) |
| 15696 | { |
| 15697 | static int initialized = 0; |
| 15698 | |
| 15699 | struct breakpoint_ops *ops; |
| 15700 | |
| 15701 | if (initialized) |
| 15702 | return; |
| 15703 | initialized = 1; |
| 15704 | |
| 15705 | /* The breakpoint_ops structure to be inherit by all kinds of |
| 15706 | breakpoints (real breakpoints, i.e., user "break" breakpoints, |
| 15707 | internal and momentary breakpoints, etc.). */ |
| 15708 | ops = &bkpt_base_breakpoint_ops; |
| 15709 | *ops = base_breakpoint_ops; |
| 15710 | ops->re_set = bkpt_re_set; |
| 15711 | ops->insert_location = bkpt_insert_location; |
| 15712 | ops->remove_location = bkpt_remove_location; |
| 15713 | ops->breakpoint_hit = bkpt_breakpoint_hit; |
| 15714 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
| 15715 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
| 15716 | ops->decode_location = bkpt_decode_location; |
| 15717 | |
| 15718 | /* The breakpoint_ops structure to be used in regular breakpoints. */ |
| 15719 | ops = &bkpt_breakpoint_ops; |
| 15720 | *ops = bkpt_base_breakpoint_ops; |
| 15721 | ops->re_set = bkpt_re_set; |
| 15722 | ops->resources_needed = bkpt_resources_needed; |
| 15723 | ops->print_it = bkpt_print_it; |
| 15724 | ops->print_mention = bkpt_print_mention; |
| 15725 | ops->print_recreate = bkpt_print_recreate; |
| 15726 | |
| 15727 | /* Ranged breakpoints. */ |
| 15728 | ops = &ranged_breakpoint_ops; |
| 15729 | *ops = bkpt_breakpoint_ops; |
| 15730 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; |
| 15731 | ops->resources_needed = resources_needed_ranged_breakpoint; |
| 15732 | ops->print_it = print_it_ranged_breakpoint; |
| 15733 | ops->print_one = print_one_ranged_breakpoint; |
| 15734 | ops->print_one_detail = print_one_detail_ranged_breakpoint; |
| 15735 | ops->print_mention = print_mention_ranged_breakpoint; |
| 15736 | ops->print_recreate = print_recreate_ranged_breakpoint; |
| 15737 | |
| 15738 | /* Internal breakpoints. */ |
| 15739 | ops = &internal_breakpoint_ops; |
| 15740 | *ops = bkpt_base_breakpoint_ops; |
| 15741 | ops->re_set = internal_bkpt_re_set; |
| 15742 | ops->check_status = internal_bkpt_check_status; |
| 15743 | ops->print_it = internal_bkpt_print_it; |
| 15744 | ops->print_mention = internal_bkpt_print_mention; |
| 15745 | |
| 15746 | /* Momentary breakpoints. */ |
| 15747 | ops = &momentary_breakpoint_ops; |
| 15748 | *ops = bkpt_base_breakpoint_ops; |
| 15749 | ops->re_set = momentary_bkpt_re_set; |
| 15750 | ops->check_status = momentary_bkpt_check_status; |
| 15751 | ops->print_it = momentary_bkpt_print_it; |
| 15752 | ops->print_mention = momentary_bkpt_print_mention; |
| 15753 | |
| 15754 | /* Momentary breakpoints for bp_longjmp and bp_exception. */ |
| 15755 | ops = &longjmp_breakpoint_ops; |
| 15756 | *ops = momentary_breakpoint_ops; |
| 15757 | ops->dtor = longjmp_bkpt_dtor; |
| 15758 | |
| 15759 | /* Probe breakpoints. */ |
| 15760 | ops = &bkpt_probe_breakpoint_ops; |
| 15761 | *ops = bkpt_breakpoint_ops; |
| 15762 | ops->insert_location = bkpt_probe_insert_location; |
| 15763 | ops->remove_location = bkpt_probe_remove_location; |
| 15764 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
| 15765 | ops->decode_location = bkpt_probe_decode_location; |
| 15766 | |
| 15767 | /* Watchpoints. */ |
| 15768 | ops = &watchpoint_breakpoint_ops; |
| 15769 | *ops = base_breakpoint_ops; |
| 15770 | ops->dtor = dtor_watchpoint; |
| 15771 | ops->re_set = re_set_watchpoint; |
| 15772 | ops->insert_location = insert_watchpoint; |
| 15773 | ops->remove_location = remove_watchpoint; |
| 15774 | ops->breakpoint_hit = breakpoint_hit_watchpoint; |
| 15775 | ops->check_status = check_status_watchpoint; |
| 15776 | ops->resources_needed = resources_needed_watchpoint; |
| 15777 | ops->works_in_software_mode = works_in_software_mode_watchpoint; |
| 15778 | ops->print_it = print_it_watchpoint; |
| 15779 | ops->print_mention = print_mention_watchpoint; |
| 15780 | ops->print_recreate = print_recreate_watchpoint; |
| 15781 | ops->explains_signal = explains_signal_watchpoint; |
| 15782 | |
| 15783 | /* Masked watchpoints. */ |
| 15784 | ops = &masked_watchpoint_breakpoint_ops; |
| 15785 | *ops = watchpoint_breakpoint_ops; |
| 15786 | ops->insert_location = insert_masked_watchpoint; |
| 15787 | ops->remove_location = remove_masked_watchpoint; |
| 15788 | ops->resources_needed = resources_needed_masked_watchpoint; |
| 15789 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; |
| 15790 | ops->print_it = print_it_masked_watchpoint; |
| 15791 | ops->print_one_detail = print_one_detail_masked_watchpoint; |
| 15792 | ops->print_mention = print_mention_masked_watchpoint; |
| 15793 | ops->print_recreate = print_recreate_masked_watchpoint; |
| 15794 | |
| 15795 | /* Tracepoints. */ |
| 15796 | ops = &tracepoint_breakpoint_ops; |
| 15797 | *ops = base_breakpoint_ops; |
| 15798 | ops->re_set = tracepoint_re_set; |
| 15799 | ops->breakpoint_hit = tracepoint_breakpoint_hit; |
| 15800 | ops->print_one_detail = tracepoint_print_one_detail; |
| 15801 | ops->print_mention = tracepoint_print_mention; |
| 15802 | ops->print_recreate = tracepoint_print_recreate; |
| 15803 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
| 15804 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
| 15805 | ops->decode_location = tracepoint_decode_location; |
| 15806 | |
| 15807 | /* Probe tracepoints. */ |
| 15808 | ops = &tracepoint_probe_breakpoint_ops; |
| 15809 | *ops = tracepoint_breakpoint_ops; |
| 15810 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
| 15811 | ops->decode_location = tracepoint_probe_decode_location; |
| 15812 | |
| 15813 | /* Static tracepoints with marker (`-m'). */ |
| 15814 | ops = &strace_marker_breakpoint_ops; |
| 15815 | *ops = tracepoint_breakpoint_ops; |
| 15816 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
| 15817 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
| 15818 | ops->decode_location = strace_marker_decode_location; |
| 15819 | |
| 15820 | /* Fork catchpoints. */ |
| 15821 | ops = &catch_fork_breakpoint_ops; |
| 15822 | *ops = base_breakpoint_ops; |
| 15823 | ops->insert_location = insert_catch_fork; |
| 15824 | ops->remove_location = remove_catch_fork; |
| 15825 | ops->breakpoint_hit = breakpoint_hit_catch_fork; |
| 15826 | ops->print_it = print_it_catch_fork; |
| 15827 | ops->print_one = print_one_catch_fork; |
| 15828 | ops->print_mention = print_mention_catch_fork; |
| 15829 | ops->print_recreate = print_recreate_catch_fork; |
| 15830 | |
| 15831 | /* Vfork catchpoints. */ |
| 15832 | ops = &catch_vfork_breakpoint_ops; |
| 15833 | *ops = base_breakpoint_ops; |
| 15834 | ops->insert_location = insert_catch_vfork; |
| 15835 | ops->remove_location = remove_catch_vfork; |
| 15836 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; |
| 15837 | ops->print_it = print_it_catch_vfork; |
| 15838 | ops->print_one = print_one_catch_vfork; |
| 15839 | ops->print_mention = print_mention_catch_vfork; |
| 15840 | ops->print_recreate = print_recreate_catch_vfork; |
| 15841 | |
| 15842 | /* Exec catchpoints. */ |
| 15843 | ops = &catch_exec_breakpoint_ops; |
| 15844 | *ops = base_breakpoint_ops; |
| 15845 | ops->dtor = dtor_catch_exec; |
| 15846 | ops->insert_location = insert_catch_exec; |
| 15847 | ops->remove_location = remove_catch_exec; |
| 15848 | ops->breakpoint_hit = breakpoint_hit_catch_exec; |
| 15849 | ops->print_it = print_it_catch_exec; |
| 15850 | ops->print_one = print_one_catch_exec; |
| 15851 | ops->print_mention = print_mention_catch_exec; |
| 15852 | ops->print_recreate = print_recreate_catch_exec; |
| 15853 | |
| 15854 | /* Solib-related catchpoints. */ |
| 15855 | ops = &catch_solib_breakpoint_ops; |
| 15856 | *ops = base_breakpoint_ops; |
| 15857 | ops->dtor = dtor_catch_solib; |
| 15858 | ops->insert_location = insert_catch_solib; |
| 15859 | ops->remove_location = remove_catch_solib; |
| 15860 | ops->breakpoint_hit = breakpoint_hit_catch_solib; |
| 15861 | ops->check_status = check_status_catch_solib; |
| 15862 | ops->print_it = print_it_catch_solib; |
| 15863 | ops->print_one = print_one_catch_solib; |
| 15864 | ops->print_mention = print_mention_catch_solib; |
| 15865 | ops->print_recreate = print_recreate_catch_solib; |
| 15866 | |
| 15867 | ops = &dprintf_breakpoint_ops; |
| 15868 | *ops = bkpt_base_breakpoint_ops; |
| 15869 | ops->re_set = dprintf_re_set; |
| 15870 | ops->resources_needed = bkpt_resources_needed; |
| 15871 | ops->print_it = bkpt_print_it; |
| 15872 | ops->print_mention = bkpt_print_mention; |
| 15873 | ops->print_recreate = dprintf_print_recreate; |
| 15874 | ops->after_condition_true = dprintf_after_condition_true; |
| 15875 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
| 15876 | } |
| 15877 | |
| 15878 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
| 15879 | |
| 15880 | static struct cmd_list_element *enablebreaklist = NULL; |
| 15881 | |
| 15882 | void |
| 15883 | _initialize_breakpoint (void) |
| 15884 | { |
| 15885 | struct cmd_list_element *c; |
| 15886 | |
| 15887 | initialize_breakpoint_ops (); |
| 15888 | |
| 15889 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
| 15890 | observer_attach_free_objfile (disable_breakpoints_in_freed_objfile); |
| 15891 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
| 15892 | |
| 15893 | breakpoint_objfile_key |
| 15894 | = register_objfile_data_with_cleanup (NULL, free_breakpoint_probes); |
| 15895 | |
| 15896 | breakpoint_chain = 0; |
| 15897 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful |
| 15898 | before a breakpoint is set. */ |
| 15899 | breakpoint_count = 0; |
| 15900 | |
| 15901 | tracepoint_count = 0; |
| 15902 | |
| 15903 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
| 15904 | Set ignore-count of breakpoint number N to COUNT.\n\ |
| 15905 | Usage is `ignore N COUNT'.")); |
| 15906 | |
| 15907 | add_com ("commands", class_breakpoint, commands_command, _("\ |
| 15908 | Set commands to be executed when a breakpoint is hit.\n\ |
| 15909 | Give breakpoint number as argument after \"commands\".\n\ |
| 15910 | With no argument, the targeted breakpoint is the last one set.\n\ |
| 15911 | The commands themselves follow starting on the next line.\n\ |
| 15912 | Type a line containing \"end\" to indicate the end of them.\n\ |
| 15913 | Give \"silent\" as the first line to make the breakpoint silent;\n\ |
| 15914 | then no output is printed when it is hit, except what the commands print.")); |
| 15915 | |
| 15916 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
| 15917 | Specify breakpoint number N to break only if COND is true.\n\ |
| 15918 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
| 15919 | expression to be evaluated whenever breakpoint N is reached.")); |
| 15920 | set_cmd_completer (c, condition_completer); |
| 15921 | |
| 15922 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
| 15923 | Set a temporary breakpoint.\n\ |
| 15924 | Like \"break\" except the breakpoint is only temporary,\n\ |
| 15925 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ |
| 15926 | by using \"enable delete\" on the breakpoint number.\n\ |
| 15927 | \n" |
| 15928 | BREAK_ARGS_HELP ("tbreak"))); |
| 15929 | set_cmd_completer (c, location_completer); |
| 15930 | |
| 15931 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
| 15932 | Set a hardware assisted breakpoint.\n\ |
| 15933 | Like \"break\" except the breakpoint requires hardware support,\n\ |
| 15934 | some target hardware may not have this support.\n\ |
| 15935 | \n" |
| 15936 | BREAK_ARGS_HELP ("hbreak"))); |
| 15937 | set_cmd_completer (c, location_completer); |
| 15938 | |
| 15939 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
| 15940 | Set a temporary hardware assisted breakpoint.\n\ |
| 15941 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
| 15942 | so it will be deleted when hit.\n\ |
| 15943 | \n" |
| 15944 | BREAK_ARGS_HELP ("thbreak"))); |
| 15945 | set_cmd_completer (c, location_completer); |
| 15946 | |
| 15947 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
| 15948 | Enable some breakpoints.\n\ |
| 15949 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 15950 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 15951 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 15952 | With a subcommand you can enable temporarily."), |
| 15953 | &enablelist, "enable ", 1, &cmdlist); |
| 15954 | |
| 15955 | add_com_alias ("en", "enable", class_breakpoint, 1); |
| 15956 | |
| 15957 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
| 15958 | Enable some breakpoints.\n\ |
| 15959 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 15960 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 15961 | May be abbreviated to simply \"enable\".\n"), |
| 15962 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
| 15963 | |
| 15964 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 15965 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 15966 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 15967 | &enablebreaklist); |
| 15968 | |
| 15969 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 15970 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 15971 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 15972 | &enablebreaklist); |
| 15973 | |
| 15974 | add_cmd ("count", no_class, enable_count_command, _("\ |
| 15975 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ |
| 15976 | If a breakpoint is hit while enabled in this fashion,\n\ |
| 15977 | the count is decremented; when it reaches zero, the breakpoint is disabled."), |
| 15978 | &enablebreaklist); |
| 15979 | |
| 15980 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 15981 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 15982 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 15983 | &enablelist); |
| 15984 | |
| 15985 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 15986 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 15987 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 15988 | &enablelist); |
| 15989 | |
| 15990 | add_cmd ("count", no_class, enable_count_command, _("\ |
| 15991 | Enable breakpoints for COUNT hits. Give count and then breakpoint numbers.\n\ |
| 15992 | If a breakpoint is hit while enabled in this fashion,\n\ |
| 15993 | the count is decremented; when it reaches zero, the breakpoint is disabled."), |
| 15994 | &enablelist); |
| 15995 | |
| 15996 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
| 15997 | Disable some breakpoints.\n\ |
| 15998 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15999 | To disable all breakpoints, give no argument.\n\ |
| 16000 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
| 16001 | &disablelist, "disable ", 1, &cmdlist); |
| 16002 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
| 16003 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
| 16004 | |
| 16005 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
| 16006 | Disable some breakpoints.\n\ |
| 16007 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16008 | To disable all breakpoints, give no argument.\n\ |
| 16009 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
| 16010 | This command may be abbreviated \"disable\"."), |
| 16011 | &disablelist); |
| 16012 | |
| 16013 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
| 16014 | Delete some breakpoints or auto-display expressions.\n\ |
| 16015 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16016 | To delete all breakpoints, give no argument.\n\ |
| 16017 | \n\ |
| 16018 | Also a prefix command for deletion of other GDB objects.\n\ |
| 16019 | The \"unset\" command is also an alias for \"delete\"."), |
| 16020 | &deletelist, "delete ", 1, &cmdlist); |
| 16021 | add_com_alias ("d", "delete", class_breakpoint, 1); |
| 16022 | add_com_alias ("del", "delete", class_breakpoint, 1); |
| 16023 | |
| 16024 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
| 16025 | Delete some breakpoints or auto-display expressions.\n\ |
| 16026 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 16027 | To delete all breakpoints, give no argument.\n\ |
| 16028 | This command may be abbreviated \"delete\"."), |
| 16029 | &deletelist); |
| 16030 | |
| 16031 | add_com ("clear", class_breakpoint, clear_command, _("\ |
| 16032 | Clear breakpoint at specified line or function.\n\ |
| 16033 | Argument may be line number, function name, or \"*\" and an address.\n\ |
| 16034 | If line number is specified, all breakpoints in that line are cleared.\n\ |
| 16035 | If function is specified, breakpoints at beginning of function are cleared.\n\ |
| 16036 | If an address is specified, breakpoints at that address are cleared.\n\ |
| 16037 | \n\ |
| 16038 | With no argument, clears all breakpoints in the line that the selected frame\n\ |
| 16039 | is executing in.\n\ |
| 16040 | \n\ |
| 16041 | See also the \"delete\" command which clears breakpoints by number.")); |
| 16042 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
| 16043 | |
| 16044 | c = add_com ("break", class_breakpoint, break_command, _("\ |
| 16045 | Set breakpoint at specified line or function.\n" |
| 16046 | BREAK_ARGS_HELP ("break"))); |
| 16047 | set_cmd_completer (c, location_completer); |
| 16048 | |
| 16049 | add_com_alias ("b", "break", class_run, 1); |
| 16050 | add_com_alias ("br", "break", class_run, 1); |
| 16051 | add_com_alias ("bre", "break", class_run, 1); |
| 16052 | add_com_alias ("brea", "break", class_run, 1); |
| 16053 | |
| 16054 | if (dbx_commands) |
| 16055 | { |
| 16056 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
| 16057 | Break in function/address or break at a line in the current file."), |
| 16058 | &stoplist, "stop ", 1, &cmdlist); |
| 16059 | add_cmd ("in", class_breakpoint, stopin_command, |
| 16060 | _("Break in function or address."), &stoplist); |
| 16061 | add_cmd ("at", class_breakpoint, stopat_command, |
| 16062 | _("Break at a line in the current file."), &stoplist); |
| 16063 | add_com ("status", class_info, breakpoints_info, _("\ |
| 16064 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 16065 | The \"Type\" column indicates one of:\n\ |
| 16066 | \tbreakpoint - normal breakpoint\n\ |
| 16067 | \twatchpoint - watchpoint\n\ |
| 16068 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 16069 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 16070 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 16071 | address and file/line number respectively.\n\ |
| 16072 | \n\ |
| 16073 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 16074 | are set to the address of the last breakpoint listed unless the command\n\ |
| 16075 | is prefixed with \"server \".\n\n\ |
| 16076 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 16077 | breakpoint set.")); |
| 16078 | } |
| 16079 | |
| 16080 | add_info ("breakpoints", breakpoints_info, _("\ |
| 16081 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
| 16082 | The \"Type\" column indicates one of:\n\ |
| 16083 | \tbreakpoint - normal breakpoint\n\ |
| 16084 | \twatchpoint - watchpoint\n\ |
| 16085 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 16086 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 16087 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 16088 | address and file/line number respectively.\n\ |
| 16089 | \n\ |
| 16090 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 16091 | are set to the address of the last breakpoint listed unless the command\n\ |
| 16092 | is prefixed with \"server \".\n\n\ |
| 16093 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 16094 | breakpoint set.")); |
| 16095 | |
| 16096 | add_info_alias ("b", "breakpoints", 1); |
| 16097 | |
| 16098 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
| 16099 | Status of all breakpoints, or breakpoint number NUMBER.\n\ |
| 16100 | The \"Type\" column indicates one of:\n\ |
| 16101 | \tbreakpoint - normal breakpoint\n\ |
| 16102 | \twatchpoint - watchpoint\n\ |
| 16103 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ |
| 16104 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ |
| 16105 | \tuntil - internal breakpoint used by the \"until\" command\n\ |
| 16106 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
| 16107 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 16108 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 16109 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 16110 | address and file/line number respectively.\n\ |
| 16111 | \n\ |
| 16112 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 16113 | are set to the address of the last breakpoint listed unless the command\n\ |
| 16114 | is prefixed with \"server \".\n\n\ |
| 16115 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 16116 | breakpoint set."), |
| 16117 | &maintenanceinfolist); |
| 16118 | |
| 16119 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
| 16120 | Set catchpoints to catch events."), |
| 16121 | &catch_cmdlist, "catch ", |
| 16122 | 0/*allow-unknown*/, &cmdlist); |
| 16123 | |
| 16124 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ |
| 16125 | Set temporary catchpoints to catch events."), |
| 16126 | &tcatch_cmdlist, "tcatch ", |
| 16127 | 0/*allow-unknown*/, &cmdlist); |
| 16128 | |
| 16129 | add_catch_command ("fork", _("Catch calls to fork."), |
| 16130 | catch_fork_command_1, |
| 16131 | NULL, |
| 16132 | (void *) (uintptr_t) catch_fork_permanent, |
| 16133 | (void *) (uintptr_t) catch_fork_temporary); |
| 16134 | add_catch_command ("vfork", _("Catch calls to vfork."), |
| 16135 | catch_fork_command_1, |
| 16136 | NULL, |
| 16137 | (void *) (uintptr_t) catch_vfork_permanent, |
| 16138 | (void *) (uintptr_t) catch_vfork_temporary); |
| 16139 | add_catch_command ("exec", _("Catch calls to exec."), |
| 16140 | catch_exec_command_1, |
| 16141 | NULL, |
| 16142 | CATCH_PERMANENT, |
| 16143 | CATCH_TEMPORARY); |
| 16144 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
| 16145 | Usage: catch load [REGEX]\n\ |
| 16146 | If REGEX is given, only stop for libraries matching the regular expression."), |
| 16147 | catch_load_command_1, |
| 16148 | NULL, |
| 16149 | CATCH_PERMANENT, |
| 16150 | CATCH_TEMPORARY); |
| 16151 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ |
| 16152 | Usage: catch unload [REGEX]\n\ |
| 16153 | If REGEX is given, only stop for libraries matching the regular expression."), |
| 16154 | catch_unload_command_1, |
| 16155 | NULL, |
| 16156 | CATCH_PERMANENT, |
| 16157 | CATCH_TEMPORARY); |
| 16158 | |
| 16159 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
| 16160 | Set a watchpoint for an expression.\n\ |
| 16161 | Usage: watch [-l|-location] EXPRESSION\n\ |
| 16162 | A watchpoint stops execution of your program whenever the value of\n\ |
| 16163 | an expression changes.\n\ |
| 16164 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 16165 | the memory to which it refers.")); |
| 16166 | set_cmd_completer (c, expression_completer); |
| 16167 | |
| 16168 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
| 16169 | Set a read watchpoint for an expression.\n\ |
| 16170 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
| 16171 | A watchpoint stops execution of your program whenever the value of\n\ |
| 16172 | an expression is read.\n\ |
| 16173 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 16174 | the memory to which it refers.")); |
| 16175 | set_cmd_completer (c, expression_completer); |
| 16176 | |
| 16177 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
| 16178 | Set a watchpoint for an expression.\n\ |
| 16179 | Usage: awatch [-l|-location] EXPRESSION\n\ |
| 16180 | A watchpoint stops execution of your program whenever the value of\n\ |
| 16181 | an expression is either read or written.\n\ |
| 16182 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 16183 | the memory to which it refers.")); |
| 16184 | set_cmd_completer (c, expression_completer); |
| 16185 | |
| 16186 | add_info ("watchpoints", watchpoints_info, _("\ |
| 16187 | Status of specified watchpoints (all watchpoints if no argument).")); |
| 16188 | |
| 16189 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
| 16190 | respond to changes - contrary to the description. */ |
| 16191 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
| 16192 | &can_use_hw_watchpoints, _("\ |
| 16193 | Set debugger's willingness to use watchpoint hardware."), _("\ |
| 16194 | Show debugger's willingness to use watchpoint hardware."), _("\ |
| 16195 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
| 16196 | such is available. (However, any hardware watchpoints that were\n\ |
| 16197 | created before setting this to nonzero, will continue to use watchpoint\n\ |
| 16198 | hardware.)"), |
| 16199 | NULL, |
| 16200 | show_can_use_hw_watchpoints, |
| 16201 | &setlist, &showlist); |
| 16202 | |
| 16203 | can_use_hw_watchpoints = 1; |
| 16204 | |
| 16205 | /* Tracepoint manipulation commands. */ |
| 16206 | |
| 16207 | c = add_com ("trace", class_breakpoint, trace_command, _("\ |
| 16208 | Set a tracepoint at specified line or function.\n\ |
| 16209 | \n" |
| 16210 | BREAK_ARGS_HELP ("trace") "\n\ |
| 16211 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 16212 | set_cmd_completer (c, location_completer); |
| 16213 | |
| 16214 | add_com_alias ("tp", "trace", class_alias, 0); |
| 16215 | add_com_alias ("tr", "trace", class_alias, 1); |
| 16216 | add_com_alias ("tra", "trace", class_alias, 1); |
| 16217 | add_com_alias ("trac", "trace", class_alias, 1); |
| 16218 | |
| 16219 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
| 16220 | Set a fast tracepoint at specified line or function.\n\ |
| 16221 | \n" |
| 16222 | BREAK_ARGS_HELP ("ftrace") "\n\ |
| 16223 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 16224 | set_cmd_completer (c, location_completer); |
| 16225 | |
| 16226 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
| 16227 | Set a static tracepoint at specified line, function or marker.\n\ |
| 16228 | \n\ |
| 16229 | strace [LOCATION] [if CONDITION]\n\ |
| 16230 | LOCATION may be a line number, function name, \"*\" and an address,\n\ |
| 16231 | or -m MARKER_ID.\n\ |
| 16232 | If a line number is specified, probe the marker at start of code\n\ |
| 16233 | for that line. If a function is specified, probe the marker at start\n\ |
| 16234 | of code for that function. If an address is specified, probe the marker\n\ |
| 16235 | at that exact address. If a marker id is specified, probe the marker\n\ |
| 16236 | with that name. With no LOCATION, uses current execution address of\n\ |
| 16237 | the selected stack frame.\n\ |
| 16238 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
| 16239 | This collects arbitrary user data passed in the probe point call to the\n\ |
| 16240 | tracing library. You can inspect it when analyzing the trace buffer,\n\ |
| 16241 | by printing the $_sdata variable like any other convenience variable.\n\ |
| 16242 | \n\ |
| 16243 | CONDITION is a boolean expression.\n\ |
| 16244 | \n\ |
| 16245 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
| 16246 | conditions are different.\n\ |
| 16247 | \n\ |
| 16248 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ |
| 16249 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 16250 | set_cmd_completer (c, location_completer); |
| 16251 | |
| 16252 | add_info ("tracepoints", tracepoints_info, _("\ |
| 16253 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
| 16254 | Convenience variable \"$tpnum\" contains the number of the\n\ |
| 16255 | last tracepoint set.")); |
| 16256 | |
| 16257 | add_info_alias ("tp", "tracepoints", 1); |
| 16258 | |
| 16259 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ |
| 16260 | Delete specified tracepoints.\n\ |
| 16261 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 16262 | No argument means delete all tracepoints."), |
| 16263 | &deletelist); |
| 16264 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
| 16265 | |
| 16266 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ |
| 16267 | Disable specified tracepoints.\n\ |
| 16268 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 16269 | No argument means disable all tracepoints."), |
| 16270 | &disablelist); |
| 16271 | deprecate_cmd (c, "disable"); |
| 16272 | |
| 16273 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ |
| 16274 | Enable specified tracepoints.\n\ |
| 16275 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 16276 | No argument means enable all tracepoints."), |
| 16277 | &enablelist); |
| 16278 | deprecate_cmd (c, "enable"); |
| 16279 | |
| 16280 | add_com ("passcount", class_trace, trace_pass_command, _("\ |
| 16281 | Set the passcount for a tracepoint.\n\ |
| 16282 | The trace will end when the tracepoint has been passed 'count' times.\n\ |
| 16283 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ |
| 16284 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); |
| 16285 | |
| 16286 | add_prefix_cmd ("save", class_breakpoint, save_command, |
| 16287 | _("Save breakpoint definitions as a script."), |
| 16288 | &save_cmdlist, "save ", |
| 16289 | 0/*allow-unknown*/, &cmdlist); |
| 16290 | |
| 16291 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ |
| 16292 | Save current breakpoint definitions as a script.\n\ |
| 16293 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
| 16294 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
| 16295 | session to restore them."), |
| 16296 | &save_cmdlist); |
| 16297 | set_cmd_completer (c, filename_completer); |
| 16298 | |
| 16299 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ |
| 16300 | Save current tracepoint definitions as a script.\n\ |
| 16301 | Use the 'source' command in another debug session to restore them."), |
| 16302 | &save_cmdlist); |
| 16303 | set_cmd_completer (c, filename_completer); |
| 16304 | |
| 16305 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
| 16306 | deprecate_cmd (c, "save tracepoints"); |
| 16307 | |
| 16308 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
| 16309 | Breakpoint specific settings\n\ |
| 16310 | Configure various breakpoint-specific variables such as\n\ |
| 16311 | pending breakpoint behavior"), |
| 16312 | &breakpoint_set_cmdlist, "set breakpoint ", |
| 16313 | 0/*allow-unknown*/, &setlist); |
| 16314 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
| 16315 | Breakpoint specific settings\n\ |
| 16316 | Configure various breakpoint-specific variables such as\n\ |
| 16317 | pending breakpoint behavior"), |
| 16318 | &breakpoint_show_cmdlist, "show breakpoint ", |
| 16319 | 0/*allow-unknown*/, &showlist); |
| 16320 | |
| 16321 | add_setshow_auto_boolean_cmd ("pending", no_class, |
| 16322 | &pending_break_support, _("\ |
| 16323 | Set debugger's behavior regarding pending breakpoints."), _("\ |
| 16324 | Show debugger's behavior regarding pending breakpoints."), _("\ |
| 16325 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
| 16326 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ |
| 16327 | an error. If auto, an unrecognized breakpoint location results in a\n\ |
| 16328 | user-query to see if a pending breakpoint should be created."), |
| 16329 | NULL, |
| 16330 | show_pending_break_support, |
| 16331 | &breakpoint_set_cmdlist, |
| 16332 | &breakpoint_show_cmdlist); |
| 16333 | |
| 16334 | pending_break_support = AUTO_BOOLEAN_AUTO; |
| 16335 | |
| 16336 | add_setshow_boolean_cmd ("auto-hw", no_class, |
| 16337 | &automatic_hardware_breakpoints, _("\ |
| 16338 | Set automatic usage of hardware breakpoints."), _("\ |
| 16339 | Show automatic usage of hardware breakpoints."), _("\ |
| 16340 | If set, the debugger will automatically use hardware breakpoints for\n\ |
| 16341 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ |
| 16342 | a warning will be emitted for such breakpoints."), |
| 16343 | NULL, |
| 16344 | show_automatic_hardware_breakpoints, |
| 16345 | &breakpoint_set_cmdlist, |
| 16346 | &breakpoint_show_cmdlist); |
| 16347 | |
| 16348 | add_setshow_boolean_cmd ("always-inserted", class_support, |
| 16349 | &always_inserted_mode, _("\ |
| 16350 | Set mode for inserting breakpoints."), _("\ |
| 16351 | Show mode for inserting breakpoints."), _("\ |
| 16352 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
| 16353 | they're created, kept inserted even when execution stops, and removed\n\ |
| 16354 | only when the user deletes them. When this mode is off (the default),\n\ |
| 16355 | breakpoints are inserted only when execution continues, and removed\n\ |
| 16356 | when execution stops."), |
| 16357 | NULL, |
| 16358 | &show_always_inserted_mode, |
| 16359 | &breakpoint_set_cmdlist, |
| 16360 | &breakpoint_show_cmdlist); |
| 16361 | |
| 16362 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
| 16363 | condition_evaluation_enums, |
| 16364 | &condition_evaluation_mode_1, _("\ |
| 16365 | Set mode of breakpoint condition evaluation."), _("\ |
| 16366 | Show mode of breakpoint condition evaluation."), _("\ |
| 16367 | When this is set to \"host\", breakpoint conditions will be\n\ |
| 16368 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
| 16369 | breakpoint conditions will be downloaded to the target (if the target\n\ |
| 16370 | supports such feature) and conditions will be evaluated on the target's side.\n\ |
| 16371 | If this is set to \"auto\" (default), this will be automatically set to\n\ |
| 16372 | \"target\" if it supports condition evaluation, otherwise it will\n\ |
| 16373 | be set to \"gdb\""), |
| 16374 | &set_condition_evaluation_mode, |
| 16375 | &show_condition_evaluation_mode, |
| 16376 | &breakpoint_set_cmdlist, |
| 16377 | &breakpoint_show_cmdlist); |
| 16378 | |
| 16379 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
| 16380 | Set a breakpoint for an address range.\n\ |
| 16381 | break-range START-LOCATION, END-LOCATION\n\ |
| 16382 | where START-LOCATION and END-LOCATION can be one of the following:\n\ |
| 16383 | LINENUM, for that line in the current file,\n\ |
| 16384 | FILE:LINENUM, for that line in that file,\n\ |
| 16385 | +OFFSET, for that number of lines after the current line\n\ |
| 16386 | or the start of the range\n\ |
| 16387 | FUNCTION, for the first line in that function,\n\ |
| 16388 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ |
| 16389 | *ADDRESS, for the instruction at that address.\n\ |
| 16390 | \n\ |
| 16391 | The breakpoint will stop execution of the inferior whenever it executes\n\ |
| 16392 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ |
| 16393 | range (including START-LOCATION and END-LOCATION).")); |
| 16394 | |
| 16395 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
| 16396 | Set a dynamic printf at specified line or function.\n\ |
| 16397 | dprintf location,format string,arg1,arg2,...\n\ |
| 16398 | location may be a line number, function name, or \"*\" and an address.\n\ |
| 16399 | If a line number is specified, break at start of code for that line.\n\ |
| 16400 | If a function is specified, break at start of code for that function.")); |
| 16401 | set_cmd_completer (c, location_completer); |
| 16402 | |
| 16403 | add_setshow_enum_cmd ("dprintf-style", class_support, |
| 16404 | dprintf_style_enums, &dprintf_style, _("\ |
| 16405 | Set the style of usage for dynamic printf."), _("\ |
| 16406 | Show the style of usage for dynamic printf."), _("\ |
| 16407 | This setting chooses how GDB will do a dynamic printf.\n\ |
| 16408 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ |
| 16409 | console, as with the \"printf\" command.\n\ |
| 16410 | If the value is \"call\", the print is done by calling a function in your\n\ |
| 16411 | program; by default printf(), but you can choose a different function or\n\ |
| 16412 | output stream by setting dprintf-function and dprintf-channel."), |
| 16413 | update_dprintf_commands, NULL, |
| 16414 | &setlist, &showlist); |
| 16415 | |
| 16416 | dprintf_function = xstrdup ("printf"); |
| 16417 | add_setshow_string_cmd ("dprintf-function", class_support, |
| 16418 | &dprintf_function, _("\ |
| 16419 | Set the function to use for dynamic printf"), _("\ |
| 16420 | Show the function to use for dynamic printf"), NULL, |
| 16421 | update_dprintf_commands, NULL, |
| 16422 | &setlist, &showlist); |
| 16423 | |
| 16424 | dprintf_channel = xstrdup (""); |
| 16425 | add_setshow_string_cmd ("dprintf-channel", class_support, |
| 16426 | &dprintf_channel, _("\ |
| 16427 | Set the channel to use for dynamic printf"), _("\ |
| 16428 | Show the channel to use for dynamic printf"), NULL, |
| 16429 | update_dprintf_commands, NULL, |
| 16430 | &setlist, &showlist); |
| 16431 | |
| 16432 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
| 16433 | &disconnected_dprintf, _("\ |
| 16434 | Set whether dprintf continues after GDB disconnects."), _("\ |
| 16435 | Show whether dprintf continues after GDB disconnects."), _("\ |
| 16436 | Use this to let dprintf commands continue to hit and produce output\n\ |
| 16437 | even if GDB disconnects or detaches from the target."), |
| 16438 | NULL, |
| 16439 | NULL, |
| 16440 | &setlist, &showlist); |
| 16441 | |
| 16442 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ |
| 16443 | agent-printf \"printf format string\", arg1, arg2, arg3, ..., argn\n\ |
| 16444 | (target agent only) This is useful for formatted output in user-defined commands.")); |
| 16445 | |
| 16446 | automatic_hardware_breakpoints = 1; |
| 16447 | |
| 16448 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); |
| 16449 | observer_attach_thread_exit (remove_threaded_breakpoints); |
| 16450 | } |