| 1 | /* Everything about breakpoints, for GDB. |
| 2 | |
| 3 | Copyright (C) 1986-2020 Free Software Foundation, Inc. |
| 4 | Copyright (C) 2019-2020 Advanced Micro Devices, Inc. All rights reserved. |
| 5 | |
| 6 | This file is part of GDB. |
| 7 | |
| 8 | This program is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 3 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | This program is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include "arch-utils.h" |
| 23 | #include <ctype.h> |
| 24 | #include "hashtab.h" |
| 25 | #include "symtab.h" |
| 26 | #include "frame.h" |
| 27 | #include "breakpoint.h" |
| 28 | #include "tracepoint.h" |
| 29 | #include "gdbtypes.h" |
| 30 | #include "expression.h" |
| 31 | #include "gdbcore.h" |
| 32 | #include "gdbcmd.h" |
| 33 | #include "value.h" |
| 34 | #include "command.h" |
| 35 | #include "inferior.h" |
| 36 | #include "infrun.h" |
| 37 | #include "gdbthread.h" |
| 38 | #include "target.h" |
| 39 | #include "language.h" |
| 40 | #include "gdb-demangle.h" |
| 41 | #include "filenames.h" |
| 42 | #include "annotate.h" |
| 43 | #include "symfile.h" |
| 44 | #include "objfiles.h" |
| 45 | #include "source.h" |
| 46 | #include "linespec.h" |
| 47 | #include "completer.h" |
| 48 | #include "ui-out.h" |
| 49 | #include "cli/cli-script.h" |
| 50 | #include "block.h" |
| 51 | #include "solib.h" |
| 52 | #include "solist.h" |
| 53 | #include "observable.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 "stack.h" |
| 64 | #include "ax-gdb.h" |
| 65 | #include "dummy-frame.h" |
| 66 | #include "interps.h" |
| 67 | #include "gdbsupport/format.h" |
| 68 | #include "thread-fsm.h" |
| 69 | #include "tid-parse.h" |
| 70 | #include "cli/cli-style.h" |
| 71 | |
| 72 | /* readline include files */ |
| 73 | #include "readline/tilde.h" |
| 74 | |
| 75 | /* readline defines this. */ |
| 76 | #undef savestring |
| 77 | |
| 78 | #include "mi/mi-common.h" |
| 79 | #include "extension.h" |
| 80 | #include <algorithm> |
| 81 | #include "progspace-and-thread.h" |
| 82 | #include "gdbsupport/array-view.h" |
| 83 | #include "gdbsupport/gdb_optional.h" |
| 84 | |
| 85 | /* Prototypes for local functions. */ |
| 86 | |
| 87 | static void map_breakpoint_numbers (const char *, |
| 88 | gdb::function_view<void (breakpoint *)>); |
| 89 | |
| 90 | static void breakpoint_re_set_default (struct breakpoint *); |
| 91 | |
| 92 | static void |
| 93 | create_sals_from_location_default (const struct event_location *location, |
| 94 | struct linespec_result *canonical, |
| 95 | enum bptype type_wanted); |
| 96 | |
| 97 | static void create_breakpoints_sal_default (struct gdbarch *, |
| 98 | struct linespec_result *, |
| 99 | gdb::unique_xmalloc_ptr<char>, |
| 100 | gdb::unique_xmalloc_ptr<char>, |
| 101 | enum bptype, |
| 102 | enum bpdisp, int, int, |
| 103 | int, |
| 104 | const struct breakpoint_ops *, |
| 105 | int, int, int, unsigned); |
| 106 | |
| 107 | static std::vector<symtab_and_line> decode_location_default |
| 108 | (struct breakpoint *b, const struct event_location *location, |
| 109 | struct program_space *search_pspace); |
| 110 | |
| 111 | static int can_use_hardware_watchpoint |
| 112 | (const std::vector<value_ref_ptr> &vals); |
| 113 | |
| 114 | static void mention (struct breakpoint *); |
| 115 | |
| 116 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
| 117 | enum bptype, |
| 118 | const struct breakpoint_ops *); |
| 119 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
| 120 | const struct symtab_and_line *); |
| 121 | |
| 122 | /* This function is used in gdbtk sources and thus can not be made |
| 123 | static. */ |
| 124 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
| 125 | struct symtab_and_line, |
| 126 | enum bptype, |
| 127 | const struct breakpoint_ops *); |
| 128 | |
| 129 | static struct breakpoint * |
| 130 | momentary_breakpoint_from_master (struct breakpoint *orig, |
| 131 | enum bptype type, |
| 132 | const struct breakpoint_ops *ops, |
| 133 | int loc_enabled); |
| 134 | |
| 135 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
| 136 | |
| 137 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 138 | CORE_ADDR bpaddr, |
| 139 | enum bptype bptype); |
| 140 | |
| 141 | static void describe_other_breakpoints (struct gdbarch *, |
| 142 | struct program_space *, CORE_ADDR, |
| 143 | struct obj_section *, int); |
| 144 | |
| 145 | static int watchpoint_locations_match (struct bp_location *loc1, |
| 146 | struct bp_location *loc2); |
| 147 | |
| 148 | static int breakpoint_location_address_match (struct bp_location *bl, |
| 149 | const struct address_space *aspace, |
| 150 | CORE_ADDR addr); |
| 151 | |
| 152 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
| 153 | const address_space *, |
| 154 | CORE_ADDR, int); |
| 155 | |
| 156 | static int remove_breakpoint (struct bp_location *); |
| 157 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
| 158 | |
| 159 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
| 160 | |
| 161 | static int hw_breakpoint_used_count (void); |
| 162 | |
| 163 | static int hw_watchpoint_use_count (struct breakpoint *); |
| 164 | |
| 165 | static int hw_watchpoint_used_count_others (struct breakpoint *except, |
| 166 | enum bptype type, |
| 167 | int *other_type_used); |
| 168 | |
| 169 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
| 170 | int count); |
| 171 | |
| 172 | static void free_bp_location (struct bp_location *loc); |
| 173 | static void incref_bp_location (struct bp_location *loc); |
| 174 | static void decref_bp_location (struct bp_location **loc); |
| 175 | |
| 176 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
| 177 | |
| 178 | /* update_global_location_list's modes of operation wrt to whether to |
| 179 | insert locations now. */ |
| 180 | enum ugll_insert_mode |
| 181 | { |
| 182 | /* Don't insert any breakpoint locations into the inferior, only |
| 183 | remove already-inserted locations that no longer should be |
| 184 | inserted. Functions that delete a breakpoint or breakpoints |
| 185 | should specify this mode, so that deleting a breakpoint doesn't |
| 186 | have the side effect of inserting the locations of other |
| 187 | breakpoints that are marked not-inserted, but should_be_inserted |
| 188 | returns true on them. |
| 189 | |
| 190 | This behavior is useful is situations close to tear-down -- e.g., |
| 191 | after an exec, while the target still has execution, but |
| 192 | breakpoint shadows of the previous executable image should *NOT* |
| 193 | be restored to the new image; or before detaching, where the |
| 194 | target still has execution and wants to delete breakpoints from |
| 195 | GDB's lists, and all breakpoints had already been removed from |
| 196 | the inferior. */ |
| 197 | UGLL_DONT_INSERT, |
| 198 | |
| 199 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
| 200 | claims breakpoints should be inserted now. */ |
| 201 | UGLL_MAY_INSERT, |
| 202 | |
| 203 | /* Insert locations now, irrespective of |
| 204 | breakpoints_should_be_inserted_now. E.g., say all threads are |
| 205 | stopped right now, and the user did "continue". We need to |
| 206 | insert breakpoints _before_ resuming the target, but |
| 207 | UGLL_MAY_INSERT wouldn't insert them, because |
| 208 | breakpoints_should_be_inserted_now returns false at that point, |
| 209 | as no thread is running yet. */ |
| 210 | UGLL_INSERT |
| 211 | }; |
| 212 | |
| 213 | static void update_global_location_list (enum ugll_insert_mode); |
| 214 | |
| 215 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
| 216 | |
| 217 | static void insert_breakpoint_locations (void); |
| 218 | |
| 219 | static void trace_pass_command (const char *, int); |
| 220 | |
| 221 | static void set_tracepoint_count (int num); |
| 222 | |
| 223 | static bool is_masked_watchpoint (const struct breakpoint *b); |
| 224 | |
| 225 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
| 226 | |
| 227 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
| 228 | otherwise. */ |
| 229 | |
| 230 | static int strace_marker_p (struct breakpoint *b); |
| 231 | |
| 232 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
| 233 | that are implemented on top of software or hardware breakpoints |
| 234 | (user breakpoints, internal and momentary breakpoints, etc.). */ |
| 235 | static struct breakpoint_ops bkpt_base_breakpoint_ops; |
| 236 | |
| 237 | /* Internal breakpoints class type. */ |
| 238 | static struct breakpoint_ops internal_breakpoint_ops; |
| 239 | |
| 240 | /* Momentary breakpoints class type. */ |
| 241 | static struct breakpoint_ops momentary_breakpoint_ops; |
| 242 | |
| 243 | /* The breakpoint_ops structure to be used in regular user created |
| 244 | breakpoints. */ |
| 245 | struct breakpoint_ops bkpt_breakpoint_ops; |
| 246 | |
| 247 | /* Breakpoints set on probes. */ |
| 248 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; |
| 249 | |
| 250 | /* Tracepoints set on probes. */ |
| 251 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; |
| 252 | |
| 253 | /* Dynamic printf class type. */ |
| 254 | struct breakpoint_ops dprintf_breakpoint_ops; |
| 255 | |
| 256 | /* The style in which to perform a dynamic printf. This is a user |
| 257 | option because different output options have different tradeoffs; |
| 258 | if GDB does the printing, there is better error handling if there |
| 259 | is a problem with any of the arguments, but using an inferior |
| 260 | function lets you have special-purpose printers and sending of |
| 261 | output to the same place as compiled-in print functions. */ |
| 262 | |
| 263 | static const char dprintf_style_gdb[] = "gdb"; |
| 264 | static const char dprintf_style_call[] = "call"; |
| 265 | static const char dprintf_style_agent[] = "agent"; |
| 266 | static const char *const dprintf_style_enums[] = { |
| 267 | dprintf_style_gdb, |
| 268 | dprintf_style_call, |
| 269 | dprintf_style_agent, |
| 270 | NULL |
| 271 | }; |
| 272 | static const char *dprintf_style = dprintf_style_gdb; |
| 273 | |
| 274 | /* The function to use for dynamic printf if the preferred style is to |
| 275 | call into the inferior. The value is simply a string that is |
| 276 | copied into the command, so it can be anything that GDB can |
| 277 | evaluate to a callable address, not necessarily a function name. */ |
| 278 | |
| 279 | static char *dprintf_function; |
| 280 | |
| 281 | /* The channel to use for dynamic printf if the preferred style is to |
| 282 | call into the inferior; if a nonempty string, it will be passed to |
| 283 | the call as the first argument, with the format string as the |
| 284 | second. As with the dprintf function, this can be anything that |
| 285 | GDB knows how to evaluate, so in addition to common choices like |
| 286 | "stderr", this could be an app-specific expression like |
| 287 | "mystreams[curlogger]". */ |
| 288 | |
| 289 | static char *dprintf_channel; |
| 290 | |
| 291 | /* True if dprintf commands should continue to operate even if GDB |
| 292 | has disconnected. */ |
| 293 | static bool disconnected_dprintf = true; |
| 294 | |
| 295 | struct command_line * |
| 296 | breakpoint_commands (struct breakpoint *b) |
| 297 | { |
| 298 | return b->commands ? b->commands.get () : NULL; |
| 299 | } |
| 300 | |
| 301 | /* Flag indicating that a command has proceeded the inferior past the |
| 302 | current breakpoint. */ |
| 303 | |
| 304 | static bool breakpoint_proceeded; |
| 305 | |
| 306 | const char * |
| 307 | bpdisp_text (enum bpdisp disp) |
| 308 | { |
| 309 | /* NOTE: the following values are a part of MI protocol and |
| 310 | represent values of 'disp' field returned when inferior stops at |
| 311 | a breakpoint. */ |
| 312 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
| 313 | |
| 314 | return bpdisps[(int) disp]; |
| 315 | } |
| 316 | |
| 317 | /* Prototypes for exported functions. */ |
| 318 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
| 319 | if such is available. */ |
| 320 | static int can_use_hw_watchpoints; |
| 321 | |
| 322 | static void |
| 323 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, |
| 324 | struct cmd_list_element *c, |
| 325 | const char *value) |
| 326 | { |
| 327 | fprintf_filtered (file, |
| 328 | _("Debugger's willingness to use " |
| 329 | "watchpoint hardware is %s.\n"), |
| 330 | value); |
| 331 | } |
| 332 | |
| 333 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
| 334 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints |
| 335 | for unrecognized breakpoint locations. |
| 336 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
| 337 | static enum auto_boolean pending_break_support; |
| 338 | static void |
| 339 | show_pending_break_support (struct ui_file *file, int from_tty, |
| 340 | struct cmd_list_element *c, |
| 341 | const char *value) |
| 342 | { |
| 343 | fprintf_filtered (file, |
| 344 | _("Debugger's behavior regarding " |
| 345 | "pending breakpoints is %s.\n"), |
| 346 | value); |
| 347 | } |
| 348 | |
| 349 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
| 350 | set with "break" but falling in read-only memory. |
| 351 | If false, gdb will warn about such breakpoints, but won't automatically |
| 352 | use hardware breakpoints. */ |
| 353 | static bool automatic_hardware_breakpoints; |
| 354 | static void |
| 355 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, |
| 356 | struct cmd_list_element *c, |
| 357 | const char *value) |
| 358 | { |
| 359 | fprintf_filtered (file, |
| 360 | _("Automatic usage of hardware breakpoints is %s.\n"), |
| 361 | value); |
| 362 | } |
| 363 | |
| 364 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
| 365 | stopped, and immediately inserts any new breakpoints as soon as |
| 366 | they're created. If off (default), GDB keeps breakpoints off of |
| 367 | the target as long as possible. That is, it delays inserting |
| 368 | breakpoints until the next resume, and removes them again when the |
| 369 | target fully stops. This is a bit safer in case GDB crashes while |
| 370 | processing user input. */ |
| 371 | /* FIXME: this is a temporary workaround to make sure waves created while |
| 372 | all known threads are stopped, and the gdb prompt is presented, do not |
| 373 | execute past the enabled breakpoints. */ |
| 374 | static bool always_inserted_mode = true; |
| 375 | |
| 376 | static void |
| 377 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
| 378 | struct cmd_list_element *c, const char *value) |
| 379 | { |
| 380 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
| 381 | value); |
| 382 | } |
| 383 | |
| 384 | /* See breakpoint.h. */ |
| 385 | |
| 386 | int |
| 387 | breakpoints_should_be_inserted_now (void) |
| 388 | { |
| 389 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
| 390 | { |
| 391 | /* If breakpoints are global, they should be inserted even if no |
| 392 | thread under gdb's control is running, or even if there are |
| 393 | no threads under GDB's control yet. */ |
| 394 | return 1; |
| 395 | } |
| 396 | else |
| 397 | { |
| 398 | if (always_inserted_mode) |
| 399 | { |
| 400 | /* The user wants breakpoints inserted even if all threads |
| 401 | are stopped. */ |
| 402 | return 1; |
| 403 | } |
| 404 | |
| 405 | for (inferior *inf : all_inferiors ()) |
| 406 | if (inf->has_execution () |
| 407 | && threads_are_executing (inf->process_target ())) |
| 408 | return 1; |
| 409 | |
| 410 | /* Don't remove breakpoints yet if, even though all threads are |
| 411 | stopped, we still have events to process. */ |
| 412 | for (thread_info *tp : all_non_exited_threads ()) |
| 413 | if (tp->resumed |
| 414 | && tp->suspend.waitstatus_pending_p) |
| 415 | return 1; |
| 416 | } |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | static const char condition_evaluation_both[] = "host or target"; |
| 421 | |
| 422 | /* Modes for breakpoint condition evaluation. */ |
| 423 | static const char condition_evaluation_auto[] = "auto"; |
| 424 | static const char condition_evaluation_host[] = "host"; |
| 425 | static const char condition_evaluation_target[] = "target"; |
| 426 | static const char *const condition_evaluation_enums[] = { |
| 427 | condition_evaluation_auto, |
| 428 | condition_evaluation_host, |
| 429 | condition_evaluation_target, |
| 430 | NULL |
| 431 | }; |
| 432 | |
| 433 | /* Global that holds the current mode for breakpoint condition evaluation. */ |
| 434 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; |
| 435 | |
| 436 | /* Global that we use to display information to the user (gets its value from |
| 437 | condition_evaluation_mode_1. */ |
| 438 | static const char *condition_evaluation_mode = condition_evaluation_auto; |
| 439 | |
| 440 | /* Translate a condition evaluation mode MODE into either "host" |
| 441 | or "target". This is used mostly to translate from "auto" to the |
| 442 | real setting that is being used. It returns the translated |
| 443 | evaluation mode. */ |
| 444 | |
| 445 | static const char * |
| 446 | translate_condition_evaluation_mode (const char *mode) |
| 447 | { |
| 448 | if (mode == condition_evaluation_auto) |
| 449 | { |
| 450 | if (target_supports_evaluation_of_breakpoint_conditions ()) |
| 451 | return condition_evaluation_target; |
| 452 | else |
| 453 | return condition_evaluation_host; |
| 454 | } |
| 455 | else |
| 456 | return mode; |
| 457 | } |
| 458 | |
| 459 | /* Discovers what condition_evaluation_auto translates to. */ |
| 460 | |
| 461 | static const char * |
| 462 | breakpoint_condition_evaluation_mode (void) |
| 463 | { |
| 464 | return translate_condition_evaluation_mode (condition_evaluation_mode); |
| 465 | } |
| 466 | |
| 467 | /* Return true if GDB should evaluate breakpoint conditions or false |
| 468 | otherwise. */ |
| 469 | |
| 470 | static int |
| 471 | gdb_evaluates_breakpoint_condition_p (void) |
| 472 | { |
| 473 | const char *mode = breakpoint_condition_evaluation_mode (); |
| 474 | |
| 475 | return (mode == condition_evaluation_host); |
| 476 | } |
| 477 | |
| 478 | /* Are we executing breakpoint commands? */ |
| 479 | static int executing_breakpoint_commands; |
| 480 | |
| 481 | /* Are overlay event breakpoints enabled? */ |
| 482 | static int overlay_events_enabled; |
| 483 | |
| 484 | /* See description in breakpoint.h. */ |
| 485 | bool target_exact_watchpoints = false; |
| 486 | |
| 487 | /* Walk the following statement or block through all breakpoints. |
| 488 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
| 489 | current breakpoint. */ |
| 490 | |
| 491 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
| 492 | |
| 493 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
| 494 | for (B = breakpoint_chain; \ |
| 495 | B ? (TMP=B->next, 1): 0; \ |
| 496 | B = TMP) |
| 497 | |
| 498 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
| 499 | not provided so update_global_location_list must not be called |
| 500 | while executing the block of ALL_BP_LOCATIONS. */ |
| 501 | |
| 502 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
| 503 | for (BP_TMP = bp_locations; \ |
| 504 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ |
| 505 | BP_TMP++) |
| 506 | |
| 507 | /* Iterates through locations with address ADDRESS for the currently selected |
| 508 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points |
| 509 | to where the loop should start from. |
| 510 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the |
| 511 | appropriate location to start with. */ |
| 512 | |
| 513 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ |
| 514 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ |
| 515 | BP_LOCP_TMP = BP_LOCP_START; \ |
| 516 | BP_LOCP_START \ |
| 517 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
| 518 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
| 519 | BP_LOCP_TMP++) |
| 520 | |
| 521 | /* Iterator for tracepoints only. */ |
| 522 | |
| 523 | #define ALL_TRACEPOINTS(B) \ |
| 524 | for (B = breakpoint_chain; B; B = B->next) \ |
| 525 | if (is_tracepoint (B)) |
| 526 | |
| 527 | /* Chains of all breakpoints defined. */ |
| 528 | |
| 529 | static struct breakpoint *breakpoint_chain; |
| 530 | |
| 531 | /* Array is sorted by bp_location_is_less_than - primarily by the ADDRESS. */ |
| 532 | |
| 533 | static struct bp_location **bp_locations; |
| 534 | |
| 535 | /* Number of elements of BP_LOCATIONS. */ |
| 536 | |
| 537 | static unsigned bp_locations_count; |
| 538 | |
| 539 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
| 540 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
| 541 | result from bp_location_has_shadow. You can use it for roughly |
| 542 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
| 543 | an address you need to read. */ |
| 544 | |
| 545 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
| 546 | |
| 547 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
| 548 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of |
| 549 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
| 550 | You can use it for roughly limiting the subrange of BP_LOCATIONS to |
| 551 | scan for shadow bytes for an address you need to read. */ |
| 552 | |
| 553 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
| 554 | |
| 555 | /* The locations that no longer correspond to any breakpoint, unlinked |
| 556 | from the bp_locations array, but for which a hit may still be |
| 557 | reported by a target. */ |
| 558 | static std::vector<bp_location *> moribund_locations; |
| 559 | |
| 560 | /* Number of last breakpoint made. */ |
| 561 | |
| 562 | static int breakpoint_count; |
| 563 | |
| 564 | /* The value of `breakpoint_count' before the last command that |
| 565 | created breakpoints. If the last (break-like) command created more |
| 566 | than one breakpoint, then the difference between BREAKPOINT_COUNT |
| 567 | and PREV_BREAKPOINT_COUNT is more than one. */ |
| 568 | static int prev_breakpoint_count; |
| 569 | |
| 570 | /* Number of last tracepoint made. */ |
| 571 | |
| 572 | static int tracepoint_count; |
| 573 | |
| 574 | static struct cmd_list_element *breakpoint_set_cmdlist; |
| 575 | static struct cmd_list_element *breakpoint_show_cmdlist; |
| 576 | struct cmd_list_element *save_cmdlist; |
| 577 | |
| 578 | /* See declaration at breakpoint.h. */ |
| 579 | |
| 580 | struct breakpoint * |
| 581 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), |
| 582 | void *user_data) |
| 583 | { |
| 584 | struct breakpoint *b = NULL; |
| 585 | |
| 586 | ALL_BREAKPOINTS (b) |
| 587 | { |
| 588 | if (func (b, user_data) != 0) |
| 589 | break; |
| 590 | } |
| 591 | |
| 592 | return b; |
| 593 | } |
| 594 | |
| 595 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
| 596 | static int |
| 597 | breakpoint_enabled (struct breakpoint *b) |
| 598 | { |
| 599 | return (b->enable_state == bp_enabled); |
| 600 | } |
| 601 | |
| 602 | /* Set breakpoint count to NUM. */ |
| 603 | |
| 604 | static void |
| 605 | set_breakpoint_count (int num) |
| 606 | { |
| 607 | prev_breakpoint_count = breakpoint_count; |
| 608 | breakpoint_count = num; |
| 609 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
| 610 | } |
| 611 | |
| 612 | /* Used by `start_rbreak_breakpoints' below, to record the current |
| 613 | breakpoint count before "rbreak" creates any breakpoint. */ |
| 614 | static int rbreak_start_breakpoint_count; |
| 615 | |
| 616 | /* Called at the start an "rbreak" command to record the first |
| 617 | breakpoint made. */ |
| 618 | |
| 619 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
| 620 | { |
| 621 | rbreak_start_breakpoint_count = breakpoint_count; |
| 622 | } |
| 623 | |
| 624 | /* Called at the end of an "rbreak" command to record the last |
| 625 | breakpoint made. */ |
| 626 | |
| 627 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
| 628 | { |
| 629 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
| 630 | } |
| 631 | |
| 632 | /* Used in run_command to zero the hit count when a new run starts. */ |
| 633 | |
| 634 | void |
| 635 | clear_breakpoint_hit_counts (void) |
| 636 | { |
| 637 | struct breakpoint *b; |
| 638 | |
| 639 | ALL_BREAKPOINTS (b) |
| 640 | b->hit_count = 0; |
| 641 | } |
| 642 | |
| 643 | \f |
| 644 | /* Return the breakpoint with the specified number, or NULL |
| 645 | if the number does not refer to an existing breakpoint. */ |
| 646 | |
| 647 | struct breakpoint * |
| 648 | get_breakpoint (int num) |
| 649 | { |
| 650 | struct breakpoint *b; |
| 651 | |
| 652 | ALL_BREAKPOINTS (b) |
| 653 | if (b->number == num) |
| 654 | return b; |
| 655 | |
| 656 | return NULL; |
| 657 | } |
| 658 | |
| 659 | \f |
| 660 | |
| 661 | /* Mark locations as "conditions have changed" in case the target supports |
| 662 | evaluating conditions on its side. */ |
| 663 | |
| 664 | static void |
| 665 | mark_breakpoint_modified (struct breakpoint *b) |
| 666 | { |
| 667 | struct bp_location *loc; |
| 668 | |
| 669 | /* This is only meaningful if the target is |
| 670 | evaluating conditions and if the user has |
| 671 | opted for condition evaluation on the target's |
| 672 | side. */ |
| 673 | if (gdb_evaluates_breakpoint_condition_p () |
| 674 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 675 | return; |
| 676 | |
| 677 | if (!is_breakpoint (b)) |
| 678 | return; |
| 679 | |
| 680 | for (loc = b->loc; loc; loc = loc->next) |
| 681 | loc->condition_changed = condition_modified; |
| 682 | } |
| 683 | |
| 684 | /* Mark location as "conditions have changed" in case the target supports |
| 685 | evaluating conditions on its side. */ |
| 686 | |
| 687 | static void |
| 688 | mark_breakpoint_location_modified (struct bp_location *loc) |
| 689 | { |
| 690 | /* This is only meaningful if the target is |
| 691 | evaluating conditions and if the user has |
| 692 | opted for condition evaluation on the target's |
| 693 | side. */ |
| 694 | if (gdb_evaluates_breakpoint_condition_p () |
| 695 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 696 | |
| 697 | return; |
| 698 | |
| 699 | if (!is_breakpoint (loc->owner)) |
| 700 | return; |
| 701 | |
| 702 | loc->condition_changed = condition_modified; |
| 703 | } |
| 704 | |
| 705 | /* Sets the condition-evaluation mode using the static global |
| 706 | condition_evaluation_mode. */ |
| 707 | |
| 708 | static void |
| 709 | set_condition_evaluation_mode (const char *args, int from_tty, |
| 710 | struct cmd_list_element *c) |
| 711 | { |
| 712 | const char *old_mode, *new_mode; |
| 713 | |
| 714 | if ((condition_evaluation_mode_1 == condition_evaluation_target) |
| 715 | && !target_supports_evaluation_of_breakpoint_conditions ()) |
| 716 | { |
| 717 | condition_evaluation_mode_1 = condition_evaluation_mode; |
| 718 | warning (_("Target does not support breakpoint condition evaluation.\n" |
| 719 | "Using host evaluation mode instead.")); |
| 720 | return; |
| 721 | } |
| 722 | |
| 723 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); |
| 724 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); |
| 725 | |
| 726 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
| 727 | settings was "auto". */ |
| 728 | condition_evaluation_mode = condition_evaluation_mode_1; |
| 729 | |
| 730 | /* Only update the mode if the user picked a different one. */ |
| 731 | if (new_mode != old_mode) |
| 732 | { |
| 733 | struct bp_location *loc, **loc_tmp; |
| 734 | /* If the user switched to a different evaluation mode, we |
| 735 | need to synch the changes with the target as follows: |
| 736 | |
| 737 | "host" -> "target": Send all (valid) conditions to the target. |
| 738 | "target" -> "host": Remove all the conditions from the target. |
| 739 | */ |
| 740 | |
| 741 | if (new_mode == condition_evaluation_target) |
| 742 | { |
| 743 | /* Mark everything modified and synch conditions with the |
| 744 | target. */ |
| 745 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 746 | mark_breakpoint_location_modified (loc); |
| 747 | } |
| 748 | else |
| 749 | { |
| 750 | /* Manually mark non-duplicate locations to synch conditions |
| 751 | with the target. We do this to remove all the conditions the |
| 752 | target knows about. */ |
| 753 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 754 | if (is_breakpoint (loc->owner) && loc->inserted) |
| 755 | loc->needs_update = 1; |
| 756 | } |
| 757 | |
| 758 | /* Do the update. */ |
| 759 | update_global_location_list (UGLL_MAY_INSERT); |
| 760 | } |
| 761 | |
| 762 | return; |
| 763 | } |
| 764 | |
| 765 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows |
| 766 | what "auto" is translating to. */ |
| 767 | |
| 768 | static void |
| 769 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, |
| 770 | struct cmd_list_element *c, const char *value) |
| 771 | { |
| 772 | if (condition_evaluation_mode == condition_evaluation_auto) |
| 773 | fprintf_filtered (file, |
| 774 | _("Breakpoint condition evaluation " |
| 775 | "mode is %s (currently %s).\n"), |
| 776 | value, |
| 777 | breakpoint_condition_evaluation_mode ()); |
| 778 | else |
| 779 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), |
| 780 | value); |
| 781 | } |
| 782 | |
| 783 | /* A comparison function for bp_location AP and BP that is used by |
| 784 | bsearch. This comparison function only cares about addresses, unlike |
| 785 | the more general bp_location_is_less_than function. */ |
| 786 | |
| 787 | static int |
| 788 | bp_locations_compare_addrs (const void *ap, const void *bp) |
| 789 | { |
| 790 | const struct bp_location *a = *(const struct bp_location **) ap; |
| 791 | const struct bp_location *b = *(const struct bp_location **) bp; |
| 792 | |
| 793 | if (a->address == b->address) |
| 794 | return 0; |
| 795 | else |
| 796 | return ((a->address > b->address) - (a->address < b->address)); |
| 797 | } |
| 798 | |
| 799 | /* Helper function to skip all bp_locations with addresses |
| 800 | less than ADDRESS. It returns the first bp_location that |
| 801 | is greater than or equal to ADDRESS. If none is found, just |
| 802 | return NULL. */ |
| 803 | |
| 804 | static struct bp_location ** |
| 805 | get_first_locp_gte_addr (CORE_ADDR address) |
| 806 | { |
| 807 | struct bp_location dummy_loc; |
| 808 | struct bp_location *dummy_locp = &dummy_loc; |
| 809 | struct bp_location **locp_found = NULL; |
| 810 | |
| 811 | /* Initialize the dummy location's address field. */ |
| 812 | dummy_loc.address = address; |
| 813 | |
| 814 | /* Find a close match to the first location at ADDRESS. */ |
| 815 | locp_found = ((struct bp_location **) |
| 816 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
| 817 | sizeof (struct bp_location **), |
| 818 | bp_locations_compare_addrs)); |
| 819 | |
| 820 | /* Nothing was found, nothing left to do. */ |
| 821 | if (locp_found == NULL) |
| 822 | return NULL; |
| 823 | |
| 824 | /* We may have found a location that is at ADDRESS but is not the first in the |
| 825 | location's list. Go backwards (if possible) and locate the first one. */ |
| 826 | while ((locp_found - 1) >= bp_locations |
| 827 | && (*(locp_found - 1))->address == address) |
| 828 | locp_found--; |
| 829 | |
| 830 | return locp_found; |
| 831 | } |
| 832 | |
| 833 | void |
| 834 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
| 835 | int from_tty) |
| 836 | { |
| 837 | xfree (b->cond_string); |
| 838 | b->cond_string = NULL; |
| 839 | |
| 840 | if (is_watchpoint (b)) |
| 841 | { |
| 842 | struct watchpoint *w = (struct watchpoint *) b; |
| 843 | |
| 844 | w->cond_exp.reset (); |
| 845 | } |
| 846 | else |
| 847 | { |
| 848 | struct bp_location *loc; |
| 849 | |
| 850 | for (loc = b->loc; loc; loc = loc->next) |
| 851 | { |
| 852 | loc->cond.reset (); |
| 853 | |
| 854 | /* No need to free the condition agent expression |
| 855 | bytecode (if we have one). We will handle this |
| 856 | when we go through update_global_location_list. */ |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | if (*exp == 0) |
| 861 | { |
| 862 | if (from_tty) |
| 863 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); |
| 864 | } |
| 865 | else |
| 866 | { |
| 867 | const char *arg = exp; |
| 868 | |
| 869 | /* I don't know if it matters whether this is the string the user |
| 870 | typed in or the decompiled expression. */ |
| 871 | b->cond_string = xstrdup (arg); |
| 872 | b->condition_not_parsed = 0; |
| 873 | |
| 874 | if (is_watchpoint (b)) |
| 875 | { |
| 876 | struct watchpoint *w = (struct watchpoint *) b; |
| 877 | |
| 878 | innermost_block_tracker tracker; |
| 879 | arg = exp; |
| 880 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
| 881 | if (*arg) |
| 882 | error (_("Junk at end of expression")); |
| 883 | w->cond_exp_valid_block = tracker.block (); |
| 884 | } |
| 885 | else |
| 886 | { |
| 887 | struct bp_location *loc; |
| 888 | |
| 889 | for (loc = b->loc; loc; loc = loc->next) |
| 890 | { |
| 891 | arg = exp; |
| 892 | loc->cond = |
| 893 | parse_exp_1 (&arg, loc->address, |
| 894 | block_for_pc (loc->address), 0); |
| 895 | if (*arg) |
| 896 | error (_("Junk at end of expression")); |
| 897 | } |
| 898 | } |
| 899 | } |
| 900 | mark_breakpoint_modified (b); |
| 901 | |
| 902 | gdb::observers::breakpoint_modified.notify (b); |
| 903 | } |
| 904 | |
| 905 | /* Completion for the "condition" command. */ |
| 906 | |
| 907 | static void |
| 908 | condition_completer (struct cmd_list_element *cmd, |
| 909 | completion_tracker &tracker, |
| 910 | const char *text, const char *word) |
| 911 | { |
| 912 | const char *space; |
| 913 | |
| 914 | text = skip_spaces (text); |
| 915 | space = skip_to_space (text); |
| 916 | if (*space == '\0') |
| 917 | { |
| 918 | int len; |
| 919 | struct breakpoint *b; |
| 920 | |
| 921 | if (text[0] == '$') |
| 922 | { |
| 923 | /* We don't support completion of history indices. */ |
| 924 | if (!isdigit (text[1])) |
| 925 | complete_internalvar (tracker, &text[1]); |
| 926 | return; |
| 927 | } |
| 928 | |
| 929 | /* We're completing the breakpoint number. */ |
| 930 | len = strlen (text); |
| 931 | |
| 932 | ALL_BREAKPOINTS (b) |
| 933 | { |
| 934 | char number[50]; |
| 935 | |
| 936 | xsnprintf (number, sizeof (number), "%d", b->number); |
| 937 | |
| 938 | if (strncmp (number, text, len) == 0) |
| 939 | tracker.add_completion (make_unique_xstrdup (number)); |
| 940 | } |
| 941 | |
| 942 | return; |
| 943 | } |
| 944 | |
| 945 | /* We're completing the expression part. */ |
| 946 | text = skip_spaces (space); |
| 947 | expression_completer (cmd, tracker, text, word); |
| 948 | } |
| 949 | |
| 950 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
| 951 | |
| 952 | static void |
| 953 | condition_command (const char *arg, int from_tty) |
| 954 | { |
| 955 | struct breakpoint *b; |
| 956 | const char *p; |
| 957 | int bnum; |
| 958 | |
| 959 | if (arg == 0) |
| 960 | error_no_arg (_("breakpoint number")); |
| 961 | |
| 962 | p = arg; |
| 963 | bnum = get_number (&p); |
| 964 | if (bnum == 0) |
| 965 | error (_("Bad breakpoint argument: '%s'"), arg); |
| 966 | |
| 967 | ALL_BREAKPOINTS (b) |
| 968 | if (b->number == bnum) |
| 969 | { |
| 970 | /* Check if this breakpoint has a "stop" method implemented in an |
| 971 | extension language. This method and conditions entered into GDB |
| 972 | from the CLI are mutually exclusive. */ |
| 973 | const struct extension_language_defn *extlang |
| 974 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); |
| 975 | |
| 976 | if (extlang != NULL) |
| 977 | { |
| 978 | error (_("Only one stop condition allowed. There is currently" |
| 979 | " a %s stop condition defined for this breakpoint."), |
| 980 | ext_lang_capitalized_name (extlang)); |
| 981 | } |
| 982 | set_breakpoint_condition (b, p, from_tty); |
| 983 | |
| 984 | if (is_breakpoint (b)) |
| 985 | update_global_location_list (UGLL_MAY_INSERT); |
| 986 | |
| 987 | return; |
| 988 | } |
| 989 | |
| 990 | error (_("No breakpoint number %d."), bnum); |
| 991 | } |
| 992 | |
| 993 | /* Check that COMMAND do not contain commands that are suitable |
| 994 | only for tracepoints and not suitable for ordinary breakpoints. |
| 995 | Throw if any such commands is found. */ |
| 996 | |
| 997 | static void |
| 998 | check_no_tracepoint_commands (struct command_line *commands) |
| 999 | { |
| 1000 | struct command_line *c; |
| 1001 | |
| 1002 | for (c = commands; c; c = c->next) |
| 1003 | { |
| 1004 | if (c->control_type == while_stepping_control) |
| 1005 | error (_("The 'while-stepping' command can " |
| 1006 | "only be used for tracepoints")); |
| 1007 | |
| 1008 | check_no_tracepoint_commands (c->body_list_0.get ()); |
| 1009 | check_no_tracepoint_commands (c->body_list_1.get ()); |
| 1010 | |
| 1011 | /* Not that command parsing removes leading whitespace and comment |
| 1012 | lines and also empty lines. So, we only need to check for |
| 1013 | command directly. */ |
| 1014 | if (strstr (c->line, "collect ") == c->line) |
| 1015 | error (_("The 'collect' command can only be used for tracepoints")); |
| 1016 | |
| 1017 | if (strstr (c->line, "teval ") == c->line) |
| 1018 | error (_("The 'teval' command can only be used for tracepoints")); |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | struct longjmp_breakpoint : public breakpoint |
| 1023 | { |
| 1024 | ~longjmp_breakpoint () override; |
| 1025 | }; |
| 1026 | |
| 1027 | /* Encapsulate tests for different types of tracepoints. */ |
| 1028 | |
| 1029 | static bool |
| 1030 | is_tracepoint_type (bptype type) |
| 1031 | { |
| 1032 | return (type == bp_tracepoint |
| 1033 | || type == bp_fast_tracepoint |
| 1034 | || type == bp_static_tracepoint); |
| 1035 | } |
| 1036 | |
| 1037 | static bool |
| 1038 | is_longjmp_type (bptype type) |
| 1039 | { |
| 1040 | return type == bp_longjmp || type == bp_exception; |
| 1041 | } |
| 1042 | |
| 1043 | /* See breakpoint.h. */ |
| 1044 | |
| 1045 | bool |
| 1046 | is_tracepoint (const struct breakpoint *b) |
| 1047 | { |
| 1048 | return is_tracepoint_type (b->type); |
| 1049 | } |
| 1050 | |
| 1051 | /* Factory function to create an appropriate instance of breakpoint given |
| 1052 | TYPE. */ |
| 1053 | |
| 1054 | static std::unique_ptr<breakpoint> |
| 1055 | new_breakpoint_from_type (bptype type) |
| 1056 | { |
| 1057 | breakpoint *b; |
| 1058 | |
| 1059 | if (is_tracepoint_type (type)) |
| 1060 | b = new tracepoint (); |
| 1061 | else if (is_longjmp_type (type)) |
| 1062 | b = new longjmp_breakpoint (); |
| 1063 | else |
| 1064 | b = new breakpoint (); |
| 1065 | |
| 1066 | return std::unique_ptr<breakpoint> (b); |
| 1067 | } |
| 1068 | |
| 1069 | /* A helper function that validates that COMMANDS are valid for a |
| 1070 | breakpoint. This function will throw an exception if a problem is |
| 1071 | found. */ |
| 1072 | |
| 1073 | static void |
| 1074 | validate_commands_for_breakpoint (struct breakpoint *b, |
| 1075 | struct command_line *commands) |
| 1076 | { |
| 1077 | if (is_tracepoint (b)) |
| 1078 | { |
| 1079 | struct tracepoint *t = (struct tracepoint *) b; |
| 1080 | struct command_line *c; |
| 1081 | struct command_line *while_stepping = 0; |
| 1082 | |
| 1083 | /* Reset the while-stepping step count. The previous commands |
| 1084 | might have included a while-stepping action, while the new |
| 1085 | ones might not. */ |
| 1086 | t->step_count = 0; |
| 1087 | |
| 1088 | /* We need to verify that each top-level element of commands is |
| 1089 | valid for tracepoints, that there's at most one |
| 1090 | while-stepping element, and that the while-stepping's body |
| 1091 | has valid tracing commands excluding nested while-stepping. |
| 1092 | We also need to validate the tracepoint action line in the |
| 1093 | context of the tracepoint --- validate_actionline actually |
| 1094 | has side effects, like setting the tracepoint's |
| 1095 | while-stepping STEP_COUNT, in addition to checking if the |
| 1096 | collect/teval actions parse and make sense in the |
| 1097 | tracepoint's context. */ |
| 1098 | for (c = commands; c; c = c->next) |
| 1099 | { |
| 1100 | if (c->control_type == while_stepping_control) |
| 1101 | { |
| 1102 | if (b->type == bp_fast_tracepoint) |
| 1103 | error (_("The 'while-stepping' command " |
| 1104 | "cannot be used for fast tracepoint")); |
| 1105 | else if (b->type == bp_static_tracepoint) |
| 1106 | error (_("The 'while-stepping' command " |
| 1107 | "cannot be used for static tracepoint")); |
| 1108 | |
| 1109 | if (while_stepping) |
| 1110 | error (_("The 'while-stepping' command " |
| 1111 | "can be used only once")); |
| 1112 | else |
| 1113 | while_stepping = c; |
| 1114 | } |
| 1115 | |
| 1116 | validate_actionline (c->line, b); |
| 1117 | } |
| 1118 | if (while_stepping) |
| 1119 | { |
| 1120 | struct command_line *c2; |
| 1121 | |
| 1122 | gdb_assert (while_stepping->body_list_1 == nullptr); |
| 1123 | c2 = while_stepping->body_list_0.get (); |
| 1124 | for (; c2; c2 = c2->next) |
| 1125 | { |
| 1126 | if (c2->control_type == while_stepping_control) |
| 1127 | error (_("The 'while-stepping' command cannot be nested")); |
| 1128 | } |
| 1129 | } |
| 1130 | } |
| 1131 | else |
| 1132 | { |
| 1133 | check_no_tracepoint_commands (commands); |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | /* Return a vector of all the static tracepoints set at ADDR. The |
| 1138 | caller is responsible for releasing the vector. */ |
| 1139 | |
| 1140 | std::vector<breakpoint *> |
| 1141 | static_tracepoints_here (CORE_ADDR addr) |
| 1142 | { |
| 1143 | struct breakpoint *b; |
| 1144 | std::vector<breakpoint *> found; |
| 1145 | struct bp_location *loc; |
| 1146 | |
| 1147 | ALL_BREAKPOINTS (b) |
| 1148 | if (b->type == bp_static_tracepoint) |
| 1149 | { |
| 1150 | for (loc = b->loc; loc; loc = loc->next) |
| 1151 | if (loc->address == addr) |
| 1152 | found.push_back (b); |
| 1153 | } |
| 1154 | |
| 1155 | return found; |
| 1156 | } |
| 1157 | |
| 1158 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
| 1159 | validate that only allowed commands are included. */ |
| 1160 | |
| 1161 | void |
| 1162 | breakpoint_set_commands (struct breakpoint *b, |
| 1163 | counted_command_line &&commands) |
| 1164 | { |
| 1165 | validate_commands_for_breakpoint (b, commands.get ()); |
| 1166 | |
| 1167 | b->commands = std::move (commands); |
| 1168 | gdb::observers::breakpoint_modified.notify (b); |
| 1169 | } |
| 1170 | |
| 1171 | /* Set the internal `silent' flag on the breakpoint. Note that this |
| 1172 | is not the same as the "silent" that may appear in the breakpoint's |
| 1173 | commands. */ |
| 1174 | |
| 1175 | void |
| 1176 | breakpoint_set_silent (struct breakpoint *b, int silent) |
| 1177 | { |
| 1178 | int old_silent = b->silent; |
| 1179 | |
| 1180 | b->silent = silent; |
| 1181 | if (old_silent != silent) |
| 1182 | gdb::observers::breakpoint_modified.notify (b); |
| 1183 | } |
| 1184 | |
| 1185 | /* Set the thread for this breakpoint. If THREAD is -1, make the |
| 1186 | breakpoint work for any thread. */ |
| 1187 | |
| 1188 | void |
| 1189 | breakpoint_set_thread (struct breakpoint *b, int thread) |
| 1190 | { |
| 1191 | int old_thread = b->thread; |
| 1192 | |
| 1193 | b->thread = thread; |
| 1194 | if (old_thread != thread) |
| 1195 | gdb::observers::breakpoint_modified.notify (b); |
| 1196 | } |
| 1197 | |
| 1198 | /* Set the task for this breakpoint. If TASK is 0, make the |
| 1199 | breakpoint work for any task. */ |
| 1200 | |
| 1201 | void |
| 1202 | breakpoint_set_task (struct breakpoint *b, int task) |
| 1203 | { |
| 1204 | int old_task = b->task; |
| 1205 | |
| 1206 | b->task = task; |
| 1207 | if (old_task != task) |
| 1208 | gdb::observers::breakpoint_modified.notify (b); |
| 1209 | } |
| 1210 | |
| 1211 | static void |
| 1212 | commands_command_1 (const char *arg, int from_tty, |
| 1213 | struct command_line *control) |
| 1214 | { |
| 1215 | counted_command_line cmd; |
| 1216 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
| 1217 | NULL after the call to read_command_lines if the user provides an empty |
| 1218 | list of command by just typing "end". */ |
| 1219 | bool cmd_read = false; |
| 1220 | |
| 1221 | std::string new_arg; |
| 1222 | |
| 1223 | if (arg == NULL || !*arg) |
| 1224 | { |
| 1225 | if (breakpoint_count - prev_breakpoint_count > 1) |
| 1226 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
| 1227 | breakpoint_count); |
| 1228 | else if (breakpoint_count > 0) |
| 1229 | new_arg = string_printf ("%d", breakpoint_count); |
| 1230 | arg = new_arg.c_str (); |
| 1231 | } |
| 1232 | |
| 1233 | map_breakpoint_numbers |
| 1234 | (arg, [&] (breakpoint *b) |
| 1235 | { |
| 1236 | if (!cmd_read) |
| 1237 | { |
| 1238 | gdb_assert (cmd == NULL); |
| 1239 | if (control != NULL) |
| 1240 | cmd = control->body_list_0; |
| 1241 | else |
| 1242 | { |
| 1243 | std::string str |
| 1244 | = string_printf (_("Type commands for breakpoint(s) " |
| 1245 | "%s, one per line."), |
| 1246 | arg); |
| 1247 | |
| 1248 | auto do_validate = [=] (const char *line) |
| 1249 | { |
| 1250 | validate_actionline (line, b); |
| 1251 | }; |
| 1252 | gdb::function_view<void (const char *)> validator; |
| 1253 | if (is_tracepoint (b)) |
| 1254 | validator = do_validate; |
| 1255 | |
| 1256 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); |
| 1257 | } |
| 1258 | cmd_read = true; |
| 1259 | } |
| 1260 | |
| 1261 | /* If a breakpoint was on the list more than once, we don't need to |
| 1262 | do anything. */ |
| 1263 | if (b->commands != cmd) |
| 1264 | { |
| 1265 | validate_commands_for_breakpoint (b, cmd.get ()); |
| 1266 | b->commands = cmd; |
| 1267 | gdb::observers::breakpoint_modified.notify (b); |
| 1268 | } |
| 1269 | }); |
| 1270 | } |
| 1271 | |
| 1272 | static void |
| 1273 | commands_command (const char *arg, int from_tty) |
| 1274 | { |
| 1275 | commands_command_1 (arg, from_tty, NULL); |
| 1276 | } |
| 1277 | |
| 1278 | /* Like commands_command, but instead of reading the commands from |
| 1279 | input stream, takes them from an already parsed command structure. |
| 1280 | |
| 1281 | This is used by cli-script.c to DTRT with breakpoint commands |
| 1282 | that are part of if and while bodies. */ |
| 1283 | enum command_control_type |
| 1284 | commands_from_control_command (const char *arg, struct command_line *cmd) |
| 1285 | { |
| 1286 | commands_command_1 (arg, 0, cmd); |
| 1287 | return simple_control; |
| 1288 | } |
| 1289 | |
| 1290 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ |
| 1291 | |
| 1292 | static int |
| 1293 | bp_location_has_shadow (struct bp_location *bl) |
| 1294 | { |
| 1295 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 1296 | return 0; |
| 1297 | if (!bl->inserted) |
| 1298 | return 0; |
| 1299 | if (bl->target_info.shadow_len == 0) |
| 1300 | /* BL isn't valid, or doesn't shadow memory. */ |
| 1301 | return 0; |
| 1302 | return 1; |
| 1303 | } |
| 1304 | |
| 1305 | /* Update BUF, which is LEN bytes read from the target address |
| 1306 | MEMADDR, by replacing a memory breakpoint with its shadowed |
| 1307 | contents. |
| 1308 | |
| 1309 | If READBUF is not NULL, this buffer must not overlap with the of |
| 1310 | the breakpoint location's shadow_contents buffer. Otherwise, a |
| 1311 | failed assertion internal error will be raised. */ |
| 1312 | |
| 1313 | static void |
| 1314 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
| 1315 | const gdb_byte *writebuf_org, |
| 1316 | ULONGEST memaddr, LONGEST len, |
| 1317 | struct bp_target_info *target_info, |
| 1318 | struct gdbarch *gdbarch) |
| 1319 | { |
| 1320 | /* Now do full processing of the found relevant range of elements. */ |
| 1321 | CORE_ADDR bp_addr = 0; |
| 1322 | int bp_size = 0; |
| 1323 | int bptoffset = 0; |
| 1324 | |
| 1325 | if (!breakpoint_address_match (target_info->placed_address_space, 0, |
| 1326 | current_program_space->aspace, 0)) |
| 1327 | { |
| 1328 | /* The breakpoint is inserted in a different address space. */ |
| 1329 | return; |
| 1330 | } |
| 1331 | |
| 1332 | /* Addresses and length of the part of the breakpoint that |
| 1333 | we need to copy. */ |
| 1334 | bp_addr = target_info->placed_address; |
| 1335 | bp_size = target_info->shadow_len; |
| 1336 | |
| 1337 | if (bp_addr + bp_size <= memaddr) |
| 1338 | { |
| 1339 | /* The breakpoint is entirely before the chunk of memory we are |
| 1340 | reading. */ |
| 1341 | return; |
| 1342 | } |
| 1343 | |
| 1344 | if (bp_addr >= memaddr + len) |
| 1345 | { |
| 1346 | /* The breakpoint is entirely after the chunk of memory we are |
| 1347 | reading. */ |
| 1348 | return; |
| 1349 | } |
| 1350 | |
| 1351 | /* Offset within shadow_contents. */ |
| 1352 | if (bp_addr < memaddr) |
| 1353 | { |
| 1354 | /* Only copy the second part of the breakpoint. */ |
| 1355 | bp_size -= memaddr - bp_addr; |
| 1356 | bptoffset = memaddr - bp_addr; |
| 1357 | bp_addr = memaddr; |
| 1358 | } |
| 1359 | |
| 1360 | if (bp_addr + bp_size > memaddr + len) |
| 1361 | { |
| 1362 | /* Only copy the first part of the breakpoint. */ |
| 1363 | bp_size -= (bp_addr + bp_size) - (memaddr + len); |
| 1364 | } |
| 1365 | |
| 1366 | if (readbuf != NULL) |
| 1367 | { |
| 1368 | /* Verify that the readbuf buffer does not overlap with the |
| 1369 | shadow_contents buffer. */ |
| 1370 | gdb_assert (target_info->shadow_contents >= readbuf + len |
| 1371 | || readbuf >= (target_info->shadow_contents |
| 1372 | + target_info->shadow_len)); |
| 1373 | |
| 1374 | /* Update the read buffer with this inserted breakpoint's |
| 1375 | shadow. */ |
| 1376 | memcpy (readbuf + bp_addr - memaddr, |
| 1377 | target_info->shadow_contents + bptoffset, bp_size); |
| 1378 | } |
| 1379 | else |
| 1380 | { |
| 1381 | const unsigned char *bp; |
| 1382 | CORE_ADDR addr = target_info->reqstd_address; |
| 1383 | int placed_size; |
| 1384 | |
| 1385 | /* Update the shadow with what we want to write to memory. */ |
| 1386 | memcpy (target_info->shadow_contents + bptoffset, |
| 1387 | writebuf_org + bp_addr - memaddr, bp_size); |
| 1388 | |
| 1389 | /* Determine appropriate breakpoint contents and size for this |
| 1390 | address. */ |
| 1391 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
| 1392 | |
| 1393 | /* Update the final write buffer with this inserted |
| 1394 | breakpoint's INSN. */ |
| 1395 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); |
| 1396 | } |
| 1397 | } |
| 1398 | |
| 1399 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
| 1400 | by replacing any memory breakpoints with their shadowed contents. |
| 1401 | |
| 1402 | If READBUF is not NULL, this buffer must not overlap with any of |
| 1403 | the breakpoint location's shadow_contents buffers. Otherwise, |
| 1404 | a failed assertion internal error will be raised. |
| 1405 | |
| 1406 | The range of shadowed area by each bp_location is: |
| 1407 | bl->address - bp_locations_placed_address_before_address_max |
| 1408 | up to bl->address + bp_locations_shadow_len_after_address_max |
| 1409 | The range we were requested to resolve shadows for is: |
| 1410 | memaddr ... memaddr + len |
| 1411 | Thus the safe cutoff boundaries for performance optimization are |
| 1412 | memaddr + len <= (bl->address |
| 1413 | - bp_locations_placed_address_before_address_max) |
| 1414 | and: |
| 1415 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
| 1416 | |
| 1417 | void |
| 1418 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
| 1419 | const gdb_byte *writebuf_org, |
| 1420 | ULONGEST memaddr, LONGEST len) |
| 1421 | { |
| 1422 | /* Left boundary, right boundary and median element of our binary |
| 1423 | search. */ |
| 1424 | unsigned bc_l, bc_r, bc; |
| 1425 | |
| 1426 | /* Find BC_L which is a leftmost element which may affect BUF |
| 1427 | content. It is safe to report lower value but a failure to |
| 1428 | report higher one. */ |
| 1429 | |
| 1430 | bc_l = 0; |
| 1431 | bc_r = bp_locations_count; |
| 1432 | while (bc_l + 1 < bc_r) |
| 1433 | { |
| 1434 | struct bp_location *bl; |
| 1435 | |
| 1436 | bc = (bc_l + bc_r) / 2; |
| 1437 | bl = bp_locations[bc]; |
| 1438 | |
| 1439 | /* Check first BL->ADDRESS will not overflow due to the added |
| 1440 | constant. Then advance the left boundary only if we are sure |
| 1441 | the BC element can in no way affect the BUF content (MEMADDR |
| 1442 | to MEMADDR + LEN range). |
| 1443 | |
| 1444 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
| 1445 | offset so that we cannot miss a breakpoint with its shadow |
| 1446 | range tail still reaching MEMADDR. */ |
| 1447 | |
| 1448 | if ((bl->address + bp_locations_shadow_len_after_address_max |
| 1449 | >= bl->address) |
| 1450 | && (bl->address + bp_locations_shadow_len_after_address_max |
| 1451 | <= memaddr)) |
| 1452 | bc_l = bc; |
| 1453 | else |
| 1454 | bc_r = bc; |
| 1455 | } |
| 1456 | |
| 1457 | /* Due to the binary search above, we need to make sure we pick the |
| 1458 | first location that's at BC_L's address. E.g., if there are |
| 1459 | multiple locations at the same address, BC_L may end up pointing |
| 1460 | at a duplicate location, and miss the "master"/"inserted" |
| 1461 | location. Say, given locations L1, L2 and L3 at addresses A and |
| 1462 | B: |
| 1463 | |
| 1464 | L1@A, L2@A, L3@B, ... |
| 1465 | |
| 1466 | BC_L could end up pointing at location L2, while the "master" |
| 1467 | location could be L1. Since the `loc->inserted' flag is only set |
| 1468 | on "master" locations, we'd forget to restore the shadow of L1 |
| 1469 | and L2. */ |
| 1470 | while (bc_l > 0 |
| 1471 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
| 1472 | bc_l--; |
| 1473 | |
| 1474 | /* Now do full processing of the found relevant range of elements. */ |
| 1475 | |
| 1476 | for (bc = bc_l; bc < bp_locations_count; bc++) |
| 1477 | { |
| 1478 | struct bp_location *bl = bp_locations[bc]; |
| 1479 | |
| 1480 | /* bp_location array has BL->OWNER always non-NULL. */ |
| 1481 | if (bl->owner->type == bp_none) |
| 1482 | warning (_("reading through apparently deleted breakpoint #%d?"), |
| 1483 | bl->owner->number); |
| 1484 | |
| 1485 | /* Performance optimization: any further element can no longer affect BUF |
| 1486 | content. */ |
| 1487 | |
| 1488 | if (bl->address >= bp_locations_placed_address_before_address_max |
| 1489 | && memaddr + len <= (bl->address |
| 1490 | - bp_locations_placed_address_before_address_max)) |
| 1491 | break; |
| 1492 | |
| 1493 | if (!bp_location_has_shadow (bl)) |
| 1494 | continue; |
| 1495 | |
| 1496 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
| 1497 | memaddr, len, &bl->target_info, bl->gdbarch); |
| 1498 | } |
| 1499 | } |
| 1500 | |
| 1501 | /* See breakpoint.h. */ |
| 1502 | |
| 1503 | bool |
| 1504 | is_breakpoint (const struct breakpoint *bpt) |
| 1505 | { |
| 1506 | return (bpt->type == bp_breakpoint |
| 1507 | || bpt->type == bp_hardware_breakpoint |
| 1508 | || bpt->type == bp_dprintf); |
| 1509 | } |
| 1510 | |
| 1511 | /* Return true if BPT is of any hardware watchpoint kind. */ |
| 1512 | |
| 1513 | static bool |
| 1514 | is_hardware_watchpoint (const struct breakpoint *bpt) |
| 1515 | { |
| 1516 | return (bpt->type == bp_hardware_watchpoint |
| 1517 | || bpt->type == bp_read_watchpoint |
| 1518 | || bpt->type == bp_access_watchpoint); |
| 1519 | } |
| 1520 | |
| 1521 | /* See breakpoint.h. */ |
| 1522 | |
| 1523 | bool |
| 1524 | is_watchpoint (const struct breakpoint *bpt) |
| 1525 | { |
| 1526 | return (is_hardware_watchpoint (bpt) |
| 1527 | || bpt->type == bp_watchpoint); |
| 1528 | } |
| 1529 | |
| 1530 | /* Returns true if the current thread and its running state are safe |
| 1531 | to evaluate or update watchpoint B. Watchpoints on local |
| 1532 | expressions need to be evaluated in the context of the thread that |
| 1533 | was current when the watchpoint was created, and, that thread needs |
| 1534 | to be stopped to be able to select the correct frame context. |
| 1535 | Watchpoints on global expressions can be evaluated on any thread, |
| 1536 | and in any state. It is presently left to the target allowing |
| 1537 | memory accesses when threads are running. */ |
| 1538 | |
| 1539 | static int |
| 1540 | watchpoint_in_thread_scope (struct watchpoint *b) |
| 1541 | { |
| 1542 | return (b->pspace == current_program_space |
| 1543 | && (b->watchpoint_thread == null_ptid |
| 1544 | || (inferior_ptid == b->watchpoint_thread |
| 1545 | && !inferior_thread ()->executing))); |
| 1546 | } |
| 1547 | |
| 1548 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
| 1549 | associated bp_watchpoint_scope breakpoint. */ |
| 1550 | |
| 1551 | static void |
| 1552 | watchpoint_del_at_next_stop (struct watchpoint *w) |
| 1553 | { |
| 1554 | if (w->related_breakpoint != w) |
| 1555 | { |
| 1556 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
| 1557 | gdb_assert (w->related_breakpoint->related_breakpoint == w); |
| 1558 | w->related_breakpoint->disposition = disp_del_at_next_stop; |
| 1559 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; |
| 1560 | w->related_breakpoint = w; |
| 1561 | } |
| 1562 | w->disposition = disp_del_at_next_stop; |
| 1563 | } |
| 1564 | |
| 1565 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
| 1566 | watchpoint W. */ |
| 1567 | |
| 1568 | static struct value * |
| 1569 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) |
| 1570 | { |
| 1571 | struct value *bit_val; |
| 1572 | |
| 1573 | if (val == NULL) |
| 1574 | return NULL; |
| 1575 | |
| 1576 | bit_val = allocate_value (value_type (val)); |
| 1577 | |
| 1578 | unpack_value_bitfield (bit_val, |
| 1579 | w->val_bitpos, |
| 1580 | w->val_bitsize, |
| 1581 | value_contents_for_printing (val), |
| 1582 | value_offset (val), |
| 1583 | val); |
| 1584 | |
| 1585 | return bit_val; |
| 1586 | } |
| 1587 | |
| 1588 | /* Allocate a dummy location and add it to B, which must be a software |
| 1589 | watchpoint. This is required because even if a software watchpoint |
| 1590 | is not watching any memory, bpstat_stop_status requires a location |
| 1591 | to be able to report stops. */ |
| 1592 | |
| 1593 | static void |
| 1594 | software_watchpoint_add_no_memory_location (struct breakpoint *b, |
| 1595 | struct program_space *pspace) |
| 1596 | { |
| 1597 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); |
| 1598 | |
| 1599 | b->loc = allocate_bp_location (b); |
| 1600 | b->loc->pspace = pspace; |
| 1601 | b->loc->address = -1; |
| 1602 | b->loc->length = -1; |
| 1603 | } |
| 1604 | |
| 1605 | /* Returns true if B is a software watchpoint that is not watching any |
| 1606 | memory (e.g., "watch $pc"). */ |
| 1607 | |
| 1608 | static bool |
| 1609 | is_no_memory_software_watchpoint (struct breakpoint *b) |
| 1610 | { |
| 1611 | return (b->type == bp_watchpoint |
| 1612 | && b->loc != NULL |
| 1613 | && b->loc->next == NULL |
| 1614 | && b->loc->address == -1 |
| 1615 | && b->loc->length == -1); |
| 1616 | } |
| 1617 | |
| 1618 | /* Assuming that B is a watchpoint: |
| 1619 | - Reparse watchpoint expression, if REPARSE is non-zero |
| 1620 | - Evaluate expression and store the result in B->val |
| 1621 | - Evaluate the condition if there is one, and store the result |
| 1622 | in b->loc->cond. |
| 1623 | - Update the list of values that must be watched in B->loc. |
| 1624 | |
| 1625 | If the watchpoint disposition is disp_del_at_next_stop, then do |
| 1626 | nothing. If this is local watchpoint that is out of scope, delete |
| 1627 | it. |
| 1628 | |
| 1629 | Even with `set breakpoint always-inserted on' the watchpoints are |
| 1630 | removed + inserted on each stop here. Normal breakpoints must |
| 1631 | never be removed because they might be missed by a running thread |
| 1632 | when debugging in non-stop mode. On the other hand, hardware |
| 1633 | watchpoints (is_hardware_watchpoint; processed here) are specific |
| 1634 | to each LWP since they are stored in each LWP's hardware debug |
| 1635 | registers. Therefore, such LWP must be stopped first in order to |
| 1636 | be able to modify its hardware watchpoints. |
| 1637 | |
| 1638 | Hardware watchpoints must be reset exactly once after being |
| 1639 | presented to the user. It cannot be done sooner, because it would |
| 1640 | reset the data used to present the watchpoint hit to the user. And |
| 1641 | it must not be done later because it could display the same single |
| 1642 | watchpoint hit during multiple GDB stops. Note that the latter is |
| 1643 | relevant only to the hardware watchpoint types bp_read_watchpoint |
| 1644 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is |
| 1645 | not user-visible - its hit is suppressed if the memory content has |
| 1646 | not changed. |
| 1647 | |
| 1648 | The following constraints influence the location where we can reset |
| 1649 | hardware watchpoints: |
| 1650 | |
| 1651 | * target_stopped_by_watchpoint and target_stopped_data_address are |
| 1652 | called several times when GDB stops. |
| 1653 | |
| 1654 | [linux] |
| 1655 | * Multiple hardware watchpoints can be hit at the same time, |
| 1656 | causing GDB to stop. GDB only presents one hardware watchpoint |
| 1657 | hit at a time as the reason for stopping, and all the other hits |
| 1658 | are presented later, one after the other, each time the user |
| 1659 | requests the execution to be resumed. Execution is not resumed |
| 1660 | for the threads still having pending hit event stored in |
| 1661 | LWP_INFO->STATUS. While the watchpoint is already removed from |
| 1662 | the inferior on the first stop the thread hit event is kept being |
| 1663 | reported from its cached value by linux_nat_stopped_data_address |
| 1664 | until the real thread resume happens after the watchpoint gets |
| 1665 | presented and thus its LWP_INFO->STATUS gets reset. |
| 1666 | |
| 1667 | Therefore the hardware watchpoint hit can get safely reset on the |
| 1668 | watchpoint removal from inferior. */ |
| 1669 | |
| 1670 | static void |
| 1671 | update_watchpoint (struct watchpoint *b, int reparse) |
| 1672 | { |
| 1673 | int within_current_scope; |
| 1674 | struct frame_id saved_frame_id; |
| 1675 | int frame_saved; |
| 1676 | |
| 1677 | /* If this is a local watchpoint, we only want to check if the |
| 1678 | watchpoint frame is in scope if the current thread is the thread |
| 1679 | that was used to create the watchpoint. */ |
| 1680 | if (!watchpoint_in_thread_scope (b)) |
| 1681 | return; |
| 1682 | |
| 1683 | if (b->disposition == disp_del_at_next_stop) |
| 1684 | return; |
| 1685 | |
| 1686 | frame_saved = 0; |
| 1687 | |
| 1688 | /* Determine if the watchpoint is within scope. */ |
| 1689 | if (b->exp_valid_block == NULL) |
| 1690 | within_current_scope = 1; |
| 1691 | else |
| 1692 | { |
| 1693 | struct frame_info *fi = get_current_frame (); |
| 1694 | struct gdbarch *frame_arch = get_frame_arch (fi); |
| 1695 | CORE_ADDR frame_pc = get_frame_pc (fi); |
| 1696 | |
| 1697 | /* If we're at a point where the stack has been destroyed |
| 1698 | (e.g. in a function epilogue), unwinding may not work |
| 1699 | properly. Do not attempt to recreate locations at this |
| 1700 | point. See similar comments in watchpoint_check. */ |
| 1701 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
| 1702 | return; |
| 1703 | |
| 1704 | /* Save the current frame's ID so we can restore it after |
| 1705 | evaluating the watchpoint expression on its own frame. */ |
| 1706 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
| 1707 | took a frame parameter, so that we didn't have to change the |
| 1708 | selected frame. */ |
| 1709 | frame_saved = 1; |
| 1710 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); |
| 1711 | |
| 1712 | fi = frame_find_by_id (b->watchpoint_frame); |
| 1713 | within_current_scope = (fi != NULL); |
| 1714 | if (within_current_scope) |
| 1715 | select_frame (fi); |
| 1716 | } |
| 1717 | |
| 1718 | /* We don't free locations. They are stored in the bp_location array |
| 1719 | and update_global_location_list will eventually delete them and |
| 1720 | remove breakpoints if needed. */ |
| 1721 | b->loc = NULL; |
| 1722 | |
| 1723 | if (within_current_scope && reparse) |
| 1724 | { |
| 1725 | const char *s; |
| 1726 | |
| 1727 | b->exp.reset (); |
| 1728 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
| 1729 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
| 1730 | /* If the meaning of expression itself changed, the old value is |
| 1731 | no longer relevant. We don't want to report a watchpoint hit |
| 1732 | to the user when the old value and the new value may actually |
| 1733 | be completely different objects. */ |
| 1734 | b->val = NULL; |
| 1735 | b->val_valid = false; |
| 1736 | |
| 1737 | /* Note that unlike with breakpoints, the watchpoint's condition |
| 1738 | expression is stored in the breakpoint object, not in the |
| 1739 | locations (re)created below. */ |
| 1740 | if (b->cond_string != NULL) |
| 1741 | { |
| 1742 | b->cond_exp.reset (); |
| 1743 | |
| 1744 | s = b->cond_string; |
| 1745 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
| 1746 | } |
| 1747 | } |
| 1748 | |
| 1749 | /* If we failed to parse the expression, for example because |
| 1750 | it refers to a global variable in a not-yet-loaded shared library, |
| 1751 | don't try to insert watchpoint. We don't automatically delete |
| 1752 | such watchpoint, though, since failure to parse expression |
| 1753 | is different from out-of-scope watchpoint. */ |
| 1754 | if (!target_has_execution) |
| 1755 | { |
| 1756 | /* Without execution, memory can't change. No use to try and |
| 1757 | set watchpoint locations. The watchpoint will be reset when |
| 1758 | the target gains execution, through breakpoint_re_set. */ |
| 1759 | if (!can_use_hw_watchpoints) |
| 1760 | { |
| 1761 | if (b->ops->works_in_software_mode (b)) |
| 1762 | b->type = bp_watchpoint; |
| 1763 | else |
| 1764 | error (_("Can't set read/access watchpoint when " |
| 1765 | "hardware watchpoints are disabled.")); |
| 1766 | } |
| 1767 | } |
| 1768 | else if (within_current_scope && b->exp) |
| 1769 | { |
| 1770 | int pc = 0; |
| 1771 | std::vector<value_ref_ptr> val_chain; |
| 1772 | struct value *v, *result; |
| 1773 | struct program_space *frame_pspace; |
| 1774 | |
| 1775 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
| 1776 | |
| 1777 | /* Avoid setting b->val if it's already set. The meaning of |
| 1778 | b->val is 'the last value' user saw, and we should update |
| 1779 | it only if we reported that last value to user. As it |
| 1780 | happens, the code that reports it updates b->val directly. |
| 1781 | We don't keep track of the memory value for masked |
| 1782 | watchpoints. */ |
| 1783 | if (!b->val_valid && !is_masked_watchpoint (b)) |
| 1784 | { |
| 1785 | if (b->val_bitsize != 0) |
| 1786 | v = extract_bitfield_from_watchpoint_value (b, v); |
| 1787 | b->val = release_value (v); |
| 1788 | b->val_valid = true; |
| 1789 | } |
| 1790 | |
| 1791 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
| 1792 | |
| 1793 | /* Look at each value on the value chain. */ |
| 1794 | gdb_assert (!val_chain.empty ()); |
| 1795 | for (const value_ref_ptr &iter : val_chain) |
| 1796 | { |
| 1797 | v = iter.get (); |
| 1798 | |
| 1799 | /* If it's a memory location, and GDB actually needed |
| 1800 | its contents to evaluate the expression, then we |
| 1801 | must watch it. If the first value returned is |
| 1802 | still lazy, that means an error occurred reading it; |
| 1803 | watch it anyway in case it becomes readable. */ |
| 1804 | if (VALUE_LVAL (v) == lval_memory |
| 1805 | && (v == val_chain[0] || ! value_lazy (v))) |
| 1806 | { |
| 1807 | struct type *vtype = check_typedef (value_type (v)); |
| 1808 | |
| 1809 | /* We only watch structs and arrays if user asked |
| 1810 | for it explicitly, never if they just happen to |
| 1811 | appear in the middle of some value chain. */ |
| 1812 | if (v == result |
| 1813 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 1814 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 1815 | { |
| 1816 | CORE_ADDR addr; |
| 1817 | enum target_hw_bp_type type; |
| 1818 | struct bp_location *loc, **tmp; |
| 1819 | int bitpos = 0, bitsize = 0; |
| 1820 | |
| 1821 | if (value_bitsize (v) != 0) |
| 1822 | { |
| 1823 | /* Extract the bit parameters out from the bitfield |
| 1824 | sub-expression. */ |
| 1825 | bitpos = value_bitpos (v); |
| 1826 | bitsize = value_bitsize (v); |
| 1827 | } |
| 1828 | else if (v == result && b->val_bitsize != 0) |
| 1829 | { |
| 1830 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield |
| 1831 | lvalue whose bit parameters are saved in the fields |
| 1832 | VAL_BITPOS and VAL_BITSIZE. */ |
| 1833 | bitpos = b->val_bitpos; |
| 1834 | bitsize = b->val_bitsize; |
| 1835 | } |
| 1836 | |
| 1837 | addr = value_address (v); |
| 1838 | if (bitsize != 0) |
| 1839 | { |
| 1840 | /* Skip the bytes that don't contain the bitfield. */ |
| 1841 | addr += bitpos / 8; |
| 1842 | } |
| 1843 | |
| 1844 | type = hw_write; |
| 1845 | if (b->type == bp_read_watchpoint) |
| 1846 | type = hw_read; |
| 1847 | else if (b->type == bp_access_watchpoint) |
| 1848 | type = hw_access; |
| 1849 | |
| 1850 | loc = allocate_bp_location (b); |
| 1851 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
| 1852 | ; |
| 1853 | *tmp = loc; |
| 1854 | loc->gdbarch = get_type_arch (value_type (v)); |
| 1855 | |
| 1856 | loc->pspace = frame_pspace; |
| 1857 | loc->address = address_significant (loc->gdbarch, addr); |
| 1858 | |
| 1859 | if (bitsize != 0) |
| 1860 | { |
| 1861 | /* Just cover the bytes that make up the bitfield. */ |
| 1862 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; |
| 1863 | } |
| 1864 | else |
| 1865 | loc->length = TYPE_LENGTH (value_type (v)); |
| 1866 | |
| 1867 | loc->watchpoint_type = type; |
| 1868 | } |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | /* Change the type of breakpoint between hardware assisted or |
| 1873 | an ordinary watchpoint depending on the hardware support |
| 1874 | and free hardware slots. REPARSE is set when the inferior |
| 1875 | is started. */ |
| 1876 | if (reparse) |
| 1877 | { |
| 1878 | int reg_cnt; |
| 1879 | enum bp_loc_type loc_type; |
| 1880 | struct bp_location *bl; |
| 1881 | |
| 1882 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
| 1883 | |
| 1884 | if (reg_cnt) |
| 1885 | { |
| 1886 | int i, target_resources_ok, other_type_used; |
| 1887 | enum bptype type; |
| 1888 | |
| 1889 | /* Use an exact watchpoint when there's only one memory region to be |
| 1890 | watched, and only one debug register is needed to watch it. */ |
| 1891 | b->exact = target_exact_watchpoints && reg_cnt == 1; |
| 1892 | |
| 1893 | /* We need to determine how many resources are already |
| 1894 | used for all other hardware watchpoints plus this one |
| 1895 | to see if we still have enough resources to also fit |
| 1896 | this watchpoint in as well. */ |
| 1897 | |
| 1898 | /* If this is a software watchpoint, we try to turn it |
| 1899 | to a hardware one -- count resources as if B was of |
| 1900 | hardware watchpoint type. */ |
| 1901 | type = b->type; |
| 1902 | if (type == bp_watchpoint) |
| 1903 | type = bp_hardware_watchpoint; |
| 1904 | |
| 1905 | /* This watchpoint may or may not have been placed on |
| 1906 | the list yet at this point (it won't be in the list |
| 1907 | if we're trying to create it for the first time, |
| 1908 | through watch_command), so always account for it |
| 1909 | manually. */ |
| 1910 | |
| 1911 | /* Count resources used by all watchpoints except B. */ |
| 1912 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
| 1913 | |
| 1914 | /* Add in the resources needed for B. */ |
| 1915 | i += hw_watchpoint_use_count (b); |
| 1916 | |
| 1917 | target_resources_ok |
| 1918 | = target_can_use_hardware_watchpoint (type, i, other_type_used); |
| 1919 | if (target_resources_ok <= 0) |
| 1920 | { |
| 1921 | int sw_mode = b->ops->works_in_software_mode (b); |
| 1922 | |
| 1923 | if (target_resources_ok == 0 && !sw_mode) |
| 1924 | error (_("Target does not support this type of " |
| 1925 | "hardware watchpoint.")); |
| 1926 | else if (target_resources_ok < 0 && !sw_mode) |
| 1927 | error (_("There are not enough available hardware " |
| 1928 | "resources for this watchpoint.")); |
| 1929 | |
| 1930 | /* Downgrade to software watchpoint. */ |
| 1931 | b->type = bp_watchpoint; |
| 1932 | } |
| 1933 | else |
| 1934 | { |
| 1935 | /* If this was a software watchpoint, we've just |
| 1936 | found we have enough resources to turn it to a |
| 1937 | hardware watchpoint. Otherwise, this is a |
| 1938 | nop. */ |
| 1939 | b->type = type; |
| 1940 | } |
| 1941 | } |
| 1942 | else if (!b->ops->works_in_software_mode (b)) |
| 1943 | { |
| 1944 | if (!can_use_hw_watchpoints) |
| 1945 | error (_("Can't set read/access watchpoint when " |
| 1946 | "hardware watchpoints are disabled.")); |
| 1947 | else |
| 1948 | error (_("Expression cannot be implemented with " |
| 1949 | "read/access watchpoint.")); |
| 1950 | } |
| 1951 | else |
| 1952 | b->type = bp_watchpoint; |
| 1953 | |
| 1954 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
| 1955 | : bp_loc_hardware_watchpoint); |
| 1956 | for (bl = b->loc; bl; bl = bl->next) |
| 1957 | bl->loc_type = loc_type; |
| 1958 | } |
| 1959 | |
| 1960 | /* If a software watchpoint is not watching any memory, then the |
| 1961 | above left it without any location set up. But, |
| 1962 | bpstat_stop_status requires a location to be able to report |
| 1963 | stops, so make sure there's at least a dummy one. */ |
| 1964 | if (b->type == bp_watchpoint && b->loc == NULL) |
| 1965 | software_watchpoint_add_no_memory_location (b, frame_pspace); |
| 1966 | } |
| 1967 | else if (!within_current_scope) |
| 1968 | { |
| 1969 | printf_filtered (_("\ |
| 1970 | Watchpoint %d deleted because the program has left the block\n\ |
| 1971 | in which its expression is valid.\n"), |
| 1972 | b->number); |
| 1973 | watchpoint_del_at_next_stop (b); |
| 1974 | } |
| 1975 | |
| 1976 | /* Restore the selected frame. */ |
| 1977 | if (frame_saved) |
| 1978 | select_frame (frame_find_by_id (saved_frame_id)); |
| 1979 | } |
| 1980 | |
| 1981 | |
| 1982 | /* Returns 1 iff breakpoint location should be |
| 1983 | inserted in the inferior. We don't differentiate the type of BL's owner |
| 1984 | (breakpoint vs. tracepoint), although insert_location in tracepoint's |
| 1985 | breakpoint_ops is not defined, because in insert_bp_location, |
| 1986 | tracepoint's insert_location will not be called. */ |
| 1987 | static int |
| 1988 | should_be_inserted (struct bp_location *bl) |
| 1989 | { |
| 1990 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
| 1991 | return 0; |
| 1992 | |
| 1993 | if (bl->owner->disposition == disp_del_at_next_stop) |
| 1994 | return 0; |
| 1995 | |
| 1996 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
| 1997 | return 0; |
| 1998 | |
| 1999 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
| 2000 | return 0; |
| 2001 | |
| 2002 | /* This is set for example, when we're attached to the parent of a |
| 2003 | vfork, and have detached from the child. The child is running |
| 2004 | free, and we expect it to do an exec or exit, at which point the |
| 2005 | OS makes the parent schedulable again (and the target reports |
| 2006 | that the vfork is done). Until the child is done with the shared |
| 2007 | memory region, do not insert breakpoints in the parent, otherwise |
| 2008 | the child could still trip on the parent's breakpoints. Since |
| 2009 | the parent is blocked anyway, it won't miss any breakpoint. */ |
| 2010 | if (bl->pspace->breakpoints_not_allowed) |
| 2011 | return 0; |
| 2012 | |
| 2013 | /* Don't insert a breakpoint if we're trying to step past its |
| 2014 | location, except if the breakpoint is a single-step breakpoint, |
| 2015 | and the breakpoint's thread is the thread which is stepping past |
| 2016 | a breakpoint. */ |
| 2017 | if ((bl->loc_type == bp_loc_software_breakpoint |
| 2018 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 2019 | && stepping_past_instruction_at (bl->pspace->aspace, |
| 2020 | bl->address) |
| 2021 | /* The single-step breakpoint may be inserted at the location |
| 2022 | we're trying to step if the instruction branches to itself. |
| 2023 | However, the instruction won't be executed at all and it may |
| 2024 | break the semantics of the instruction, for example, the |
| 2025 | instruction is a conditional branch or updates some flags. |
| 2026 | We can't fix it unless GDB is able to emulate the instruction |
| 2027 | or switch to displaced stepping. */ |
| 2028 | && !(bl->owner->type == bp_single_step |
| 2029 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) |
| 2030 | { |
| 2031 | if (debug_infrun) |
| 2032 | { |
| 2033 | fprintf_unfiltered (gdb_stdlog, |
| 2034 | "infrun: skipping breakpoint: " |
| 2035 | "stepping past insn at: %s\n", |
| 2036 | paddress (bl->gdbarch, bl->address)); |
| 2037 | } |
| 2038 | return 0; |
| 2039 | } |
| 2040 | |
| 2041 | /* Don't insert watchpoints if we're trying to step past the |
| 2042 | instruction that triggered one. */ |
| 2043 | if ((bl->loc_type == bp_loc_hardware_watchpoint) |
| 2044 | && stepping_past_nonsteppable_watchpoint ()) |
| 2045 | { |
| 2046 | if (debug_infrun) |
| 2047 | { |
| 2048 | fprintf_unfiltered (gdb_stdlog, |
| 2049 | "infrun: stepping past non-steppable watchpoint. " |
| 2050 | "skipping watchpoint at %s:%d\n", |
| 2051 | paddress (bl->gdbarch, bl->address), |
| 2052 | bl->length); |
| 2053 | } |
| 2054 | return 0; |
| 2055 | } |
| 2056 | |
| 2057 | return 1; |
| 2058 | } |
| 2059 | |
| 2060 | /* Same as should_be_inserted but does the check assuming |
| 2061 | that the location is not duplicated. */ |
| 2062 | |
| 2063 | static int |
| 2064 | unduplicated_should_be_inserted (struct bp_location *bl) |
| 2065 | { |
| 2066 | int result; |
| 2067 | const int save_duplicate = bl->duplicate; |
| 2068 | |
| 2069 | bl->duplicate = 0; |
| 2070 | result = should_be_inserted (bl); |
| 2071 | bl->duplicate = save_duplicate; |
| 2072 | return result; |
| 2073 | } |
| 2074 | |
| 2075 | /* Parses a conditional described by an expression COND into an |
| 2076 | agent expression bytecode suitable for evaluation |
| 2077 | by the bytecode interpreter. Return NULL if there was |
| 2078 | any error during parsing. */ |
| 2079 | |
| 2080 | static agent_expr_up |
| 2081 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
| 2082 | { |
| 2083 | if (cond == NULL) |
| 2084 | return NULL; |
| 2085 | |
| 2086 | agent_expr_up aexpr; |
| 2087 | |
| 2088 | /* We don't want to stop processing, so catch any errors |
| 2089 | that may show up. */ |
| 2090 | try |
| 2091 | { |
| 2092 | aexpr = gen_eval_for_expr (scope, cond); |
| 2093 | } |
| 2094 | |
| 2095 | catch (const gdb_exception_error &ex) |
| 2096 | { |
| 2097 | /* If we got here, it means the condition could not be parsed to a valid |
| 2098 | bytecode expression and thus can't be evaluated on the target's side. |
| 2099 | It's no use iterating through the conditions. */ |
| 2100 | } |
| 2101 | |
| 2102 | /* We have a valid agent expression. */ |
| 2103 | return aexpr; |
| 2104 | } |
| 2105 | |
| 2106 | /* Based on location BL, create a list of breakpoint conditions to be |
| 2107 | passed on to the target. If we have duplicated locations with different |
| 2108 | conditions, we will add such conditions to the list. The idea is that the |
| 2109 | target will evaluate the list of conditions and will only notify GDB when |
| 2110 | one of them is true. */ |
| 2111 | |
| 2112 | static void |
| 2113 | build_target_condition_list (struct bp_location *bl) |
| 2114 | { |
| 2115 | struct bp_location **locp = NULL, **loc2p; |
| 2116 | int null_condition_or_parse_error = 0; |
| 2117 | int modified = bl->needs_update; |
| 2118 | struct bp_location *loc; |
| 2119 | |
| 2120 | /* Release conditions left over from a previous insert. */ |
| 2121 | bl->target_info.conditions.clear (); |
| 2122 | |
| 2123 | /* This is only meaningful if the target is |
| 2124 | evaluating conditions and if the user has |
| 2125 | opted for condition evaluation on the target's |
| 2126 | side. */ |
| 2127 | if (gdb_evaluates_breakpoint_condition_p () |
| 2128 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 2129 | return; |
| 2130 | |
| 2131 | /* Do a first pass to check for locations with no assigned |
| 2132 | conditions or conditions that fail to parse to a valid agent expression |
| 2133 | bytecode. If any of these happen, then it's no use to send conditions |
| 2134 | to the target since this location will always trigger and generate a |
| 2135 | response back to GDB. */ |
| 2136 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2137 | { |
| 2138 | loc = (*loc2p); |
| 2139 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2140 | { |
| 2141 | if (modified) |
| 2142 | { |
| 2143 | /* Re-parse the conditions since something changed. In that |
| 2144 | case we already freed the condition bytecodes (see |
| 2145 | force_breakpoint_reinsertion). We just |
| 2146 | need to parse the condition to bytecodes again. */ |
| 2147 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
| 2148 | loc->cond.get ()); |
| 2149 | } |
| 2150 | |
| 2151 | /* If we have a NULL bytecode expression, it means something |
| 2152 | went wrong or we have a null condition expression. */ |
| 2153 | if (!loc->cond_bytecode) |
| 2154 | { |
| 2155 | null_condition_or_parse_error = 1; |
| 2156 | break; |
| 2157 | } |
| 2158 | } |
| 2159 | } |
| 2160 | |
| 2161 | /* If any of these happened, it means we will have to evaluate the conditions |
| 2162 | for the location's address on gdb's side. It is no use keeping bytecodes |
| 2163 | for all the other duplicate locations, thus we free all of them here. |
| 2164 | |
| 2165 | This is so we have a finer control over which locations' conditions are |
| 2166 | being evaluated by GDB or the remote stub. */ |
| 2167 | if (null_condition_or_parse_error) |
| 2168 | { |
| 2169 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2170 | { |
| 2171 | loc = (*loc2p); |
| 2172 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2173 | { |
| 2174 | /* Only go as far as the first NULL bytecode is |
| 2175 | located. */ |
| 2176 | if (!loc->cond_bytecode) |
| 2177 | return; |
| 2178 | |
| 2179 | loc->cond_bytecode.reset (); |
| 2180 | } |
| 2181 | } |
| 2182 | } |
| 2183 | |
| 2184 | /* No NULL conditions or failed bytecode generation. Build a condition list |
| 2185 | for this location's address. */ |
| 2186 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2187 | { |
| 2188 | loc = (*loc2p); |
| 2189 | if (loc->cond |
| 2190 | && is_breakpoint (loc->owner) |
| 2191 | && loc->pspace->num == bl->pspace->num |
| 2192 | && loc->owner->enable_state == bp_enabled |
| 2193 | && loc->enabled) |
| 2194 | { |
| 2195 | /* Add the condition to the vector. This will be used later |
| 2196 | to send the conditions to the target. */ |
| 2197 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); |
| 2198 | } |
| 2199 | } |
| 2200 | |
| 2201 | return; |
| 2202 | } |
| 2203 | |
| 2204 | /* Parses a command described by string CMD into an agent expression |
| 2205 | bytecode suitable for evaluation by the bytecode interpreter. |
| 2206 | Return NULL if there was any error during parsing. */ |
| 2207 | |
| 2208 | static agent_expr_up |
| 2209 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
| 2210 | { |
| 2211 | const char *cmdrest; |
| 2212 | const char *format_start, *format_end; |
| 2213 | struct gdbarch *gdbarch = get_current_arch (); |
| 2214 | |
| 2215 | if (cmd == NULL) |
| 2216 | return NULL; |
| 2217 | |
| 2218 | cmdrest = cmd; |
| 2219 | |
| 2220 | if (*cmdrest == ',') |
| 2221 | ++cmdrest; |
| 2222 | cmdrest = skip_spaces (cmdrest); |
| 2223 | |
| 2224 | if (*cmdrest++ != '"') |
| 2225 | error (_("No format string following the location")); |
| 2226 | |
| 2227 | format_start = cmdrest; |
| 2228 | |
| 2229 | format_pieces fpieces (&cmdrest); |
| 2230 | |
| 2231 | format_end = cmdrest; |
| 2232 | |
| 2233 | if (*cmdrest++ != '"') |
| 2234 | error (_("Bad format string, non-terminated '\"'.")); |
| 2235 | |
| 2236 | cmdrest = skip_spaces (cmdrest); |
| 2237 | |
| 2238 | if (!(*cmdrest == ',' || *cmdrest == '\0')) |
| 2239 | error (_("Invalid argument syntax")); |
| 2240 | |
| 2241 | if (*cmdrest == ',') |
| 2242 | cmdrest++; |
| 2243 | cmdrest = skip_spaces (cmdrest); |
| 2244 | |
| 2245 | /* For each argument, make an expression. */ |
| 2246 | |
| 2247 | std::vector<struct expression *> argvec; |
| 2248 | while (*cmdrest != '\0') |
| 2249 | { |
| 2250 | const char *cmd1; |
| 2251 | |
| 2252 | cmd1 = cmdrest; |
| 2253 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
| 2254 | argvec.push_back (expr.release ()); |
| 2255 | cmdrest = cmd1; |
| 2256 | if (*cmdrest == ',') |
| 2257 | ++cmdrest; |
| 2258 | } |
| 2259 | |
| 2260 | agent_expr_up aexpr; |
| 2261 | |
| 2262 | /* We don't want to stop processing, so catch any errors |
| 2263 | that may show up. */ |
| 2264 | try |
| 2265 | { |
| 2266 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
| 2267 | format_start, format_end - format_start, |
| 2268 | argvec.size (), argvec.data ()); |
| 2269 | } |
| 2270 | catch (const gdb_exception_error &ex) |
| 2271 | { |
| 2272 | /* If we got here, it means the command could not be parsed to a valid |
| 2273 | bytecode expression and thus can't be evaluated on the target's side. |
| 2274 | It's no use iterating through the other commands. */ |
| 2275 | } |
| 2276 | |
| 2277 | /* We have a valid agent expression, return it. */ |
| 2278 | return aexpr; |
| 2279 | } |
| 2280 | |
| 2281 | /* Based on location BL, create a list of breakpoint commands to be |
| 2282 | passed on to the target. If we have duplicated locations with |
| 2283 | different commands, we will add any such to the list. */ |
| 2284 | |
| 2285 | static void |
| 2286 | build_target_command_list (struct bp_location *bl) |
| 2287 | { |
| 2288 | struct bp_location **locp = NULL, **loc2p; |
| 2289 | int null_command_or_parse_error = 0; |
| 2290 | int modified = bl->needs_update; |
| 2291 | struct bp_location *loc; |
| 2292 | |
| 2293 | /* Clear commands left over from a previous insert. */ |
| 2294 | bl->target_info.tcommands.clear (); |
| 2295 | |
| 2296 | if (!target_can_run_breakpoint_commands ()) |
| 2297 | return; |
| 2298 | |
| 2299 | /* For now, limit to agent-style dprintf breakpoints. */ |
| 2300 | if (dprintf_style != dprintf_style_agent) |
| 2301 | return; |
| 2302 | |
| 2303 | /* For now, if we have any duplicate location that isn't a dprintf, |
| 2304 | don't install the target-side commands, as that would make the |
| 2305 | breakpoint not be reported to the core, and we'd lose |
| 2306 | control. */ |
| 2307 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2308 | { |
| 2309 | loc = (*loc2p); |
| 2310 | if (is_breakpoint (loc->owner) |
| 2311 | && loc->pspace->num == bl->pspace->num |
| 2312 | && loc->owner->type != bp_dprintf) |
| 2313 | return; |
| 2314 | } |
| 2315 | |
| 2316 | /* Do a first pass to check for locations with no assigned |
| 2317 | conditions or conditions that fail to parse to a valid agent expression |
| 2318 | bytecode. If any of these happen, then it's no use to send conditions |
| 2319 | to the target since this location will always trigger and generate a |
| 2320 | response back to GDB. */ |
| 2321 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2322 | { |
| 2323 | loc = (*loc2p); |
| 2324 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2325 | { |
| 2326 | if (modified) |
| 2327 | { |
| 2328 | /* Re-parse the commands since something changed. In that |
| 2329 | case we already freed the command bytecodes (see |
| 2330 | force_breakpoint_reinsertion). We just |
| 2331 | need to parse the command to bytecodes again. */ |
| 2332 | loc->cmd_bytecode |
| 2333 | = parse_cmd_to_aexpr (bl->address, |
| 2334 | loc->owner->extra_string); |
| 2335 | } |
| 2336 | |
| 2337 | /* If we have a NULL bytecode expression, it means something |
| 2338 | went wrong or we have a null command expression. */ |
| 2339 | if (!loc->cmd_bytecode) |
| 2340 | { |
| 2341 | null_command_or_parse_error = 1; |
| 2342 | break; |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | /* If anything failed, then we're not doing target-side commands, |
| 2348 | and so clean up. */ |
| 2349 | if (null_command_or_parse_error) |
| 2350 | { |
| 2351 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2352 | { |
| 2353 | loc = (*loc2p); |
| 2354 | if (is_breakpoint (loc->owner) |
| 2355 | && loc->pspace->num == bl->pspace->num) |
| 2356 | { |
| 2357 | /* Only go as far as the first NULL bytecode is |
| 2358 | located. */ |
| 2359 | if (loc->cmd_bytecode == NULL) |
| 2360 | return; |
| 2361 | |
| 2362 | loc->cmd_bytecode.reset (); |
| 2363 | } |
| 2364 | } |
| 2365 | } |
| 2366 | |
| 2367 | /* No NULL commands or failed bytecode generation. Build a command list |
| 2368 | for this location's address. */ |
| 2369 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2370 | { |
| 2371 | loc = (*loc2p); |
| 2372 | if (loc->owner->extra_string |
| 2373 | && is_breakpoint (loc->owner) |
| 2374 | && loc->pspace->num == bl->pspace->num |
| 2375 | && loc->owner->enable_state == bp_enabled |
| 2376 | && loc->enabled) |
| 2377 | { |
| 2378 | /* Add the command to the vector. This will be used later |
| 2379 | to send the commands to the target. */ |
| 2380 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | bl->target_info.persist = 0; |
| 2385 | /* Maybe flag this location as persistent. */ |
| 2386 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) |
| 2387 | bl->target_info.persist = 1; |
| 2388 | } |
| 2389 | |
| 2390 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
| 2391 | of breakpoint according to ADDR except single-step breakpoint. |
| 2392 | Get the kind of single-step breakpoint according to the current |
| 2393 | registers state. */ |
| 2394 | |
| 2395 | static int |
| 2396 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) |
| 2397 | { |
| 2398 | if (bl->owner->type == bp_single_step) |
| 2399 | { |
| 2400 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); |
| 2401 | struct regcache *regcache; |
| 2402 | |
| 2403 | regcache = get_thread_regcache (thr); |
| 2404 | |
| 2405 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, |
| 2406 | regcache, addr); |
| 2407 | } |
| 2408 | else |
| 2409 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); |
| 2410 | } |
| 2411 | |
| 2412 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
| 2413 | location. Any error messages are printed to TMP_ERROR_STREAM; and |
| 2414 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
| 2415 | Returns 0 for success, 1 if the bp_location type is not supported or |
| 2416 | -1 for failure. |
| 2417 | |
| 2418 | NOTE drow/2003-09-09: This routine could be broken down to an |
| 2419 | object-style method for each breakpoint or catchpoint type. */ |
| 2420 | static int |
| 2421 | insert_bp_location (struct bp_location *bl, |
| 2422 | struct ui_file *tmp_error_stream, |
| 2423 | int *disabled_breaks, |
| 2424 | int *hw_breakpoint_error, |
| 2425 | int *hw_bp_error_explained_already) |
| 2426 | { |
| 2427 | gdb_exception bp_excpt; |
| 2428 | |
| 2429 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
| 2430 | return 0; |
| 2431 | |
| 2432 | /* Note we don't initialize bl->target_info, as that wipes out |
| 2433 | the breakpoint location's shadow_contents if the breakpoint |
| 2434 | is still inserted at that location. This in turn breaks |
| 2435 | target_read_memory which depends on these buffers when |
| 2436 | a memory read is requested at the breakpoint location: |
| 2437 | Once the target_info has been wiped, we fail to see that |
| 2438 | we have a breakpoint inserted at that address and thus |
| 2439 | read the breakpoint instead of returning the data saved in |
| 2440 | the breakpoint location's shadow contents. */ |
| 2441 | bl->target_info.reqstd_address = bl->address; |
| 2442 | bl->target_info.placed_address_space = bl->pspace->aspace; |
| 2443 | bl->target_info.length = bl->length; |
| 2444 | |
| 2445 | /* When working with target-side conditions, we must pass all the conditions |
| 2446 | for the same breakpoint address down to the target since GDB will not |
| 2447 | insert those locations. With a list of breakpoint conditions, the target |
| 2448 | can decide when to stop and notify GDB. */ |
| 2449 | |
| 2450 | if (is_breakpoint (bl->owner)) |
| 2451 | { |
| 2452 | build_target_condition_list (bl); |
| 2453 | build_target_command_list (bl); |
| 2454 | /* Reset the modification marker. */ |
| 2455 | bl->needs_update = 0; |
| 2456 | } |
| 2457 | |
| 2458 | if (bl->loc_type == bp_loc_software_breakpoint |
| 2459 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 2460 | { |
| 2461 | if (bl->owner->type != bp_hardware_breakpoint) |
| 2462 | { |
| 2463 | /* If the explicitly specified breakpoint type |
| 2464 | is not hardware breakpoint, check the memory map to see |
| 2465 | if the breakpoint address is in read only memory or not. |
| 2466 | |
| 2467 | Two important cases are: |
| 2468 | - location type is not hardware breakpoint, memory |
| 2469 | is readonly. We change the type of the location to |
| 2470 | hardware breakpoint. |
| 2471 | - location type is hardware breakpoint, memory is |
| 2472 | read-write. This means we've previously made the |
| 2473 | location hardware one, but then the memory map changed, |
| 2474 | so we undo. |
| 2475 | |
| 2476 | When breakpoints are removed, remove_breakpoints will use |
| 2477 | location types we've just set here, the only possible |
| 2478 | problem is that memory map has changed during running |
| 2479 | program, but it's not going to work anyway with current |
| 2480 | gdb. */ |
| 2481 | struct mem_region *mr |
| 2482 | = lookup_mem_region (bl->target_info.reqstd_address); |
| 2483 | |
| 2484 | if (mr) |
| 2485 | { |
| 2486 | if (automatic_hardware_breakpoints) |
| 2487 | { |
| 2488 | enum bp_loc_type new_type; |
| 2489 | |
| 2490 | if (mr->attrib.mode != MEM_RW) |
| 2491 | new_type = bp_loc_hardware_breakpoint; |
| 2492 | else |
| 2493 | new_type = bp_loc_software_breakpoint; |
| 2494 | |
| 2495 | if (new_type != bl->loc_type) |
| 2496 | { |
| 2497 | static int said = 0; |
| 2498 | |
| 2499 | bl->loc_type = new_type; |
| 2500 | if (!said) |
| 2501 | { |
| 2502 | fprintf_filtered (gdb_stdout, |
| 2503 | _("Note: automatically using " |
| 2504 | "hardware breakpoints for " |
| 2505 | "read-only addresses.\n")); |
| 2506 | said = 1; |
| 2507 | } |
| 2508 | } |
| 2509 | } |
| 2510 | else if (bl->loc_type == bp_loc_software_breakpoint |
| 2511 | && mr->attrib.mode != MEM_RW) |
| 2512 | { |
| 2513 | fprintf_unfiltered (tmp_error_stream, |
| 2514 | _("Cannot insert breakpoint %d.\n" |
| 2515 | "Cannot set software breakpoint " |
| 2516 | "at read-only address %s\n"), |
| 2517 | bl->owner->number, |
| 2518 | paddress (bl->gdbarch, bl->address)); |
| 2519 | return 1; |
| 2520 | } |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | /* First check to see if we have to handle an overlay. */ |
| 2525 | if (overlay_debugging == ovly_off |
| 2526 | || bl->section == NULL |
| 2527 | || !(section_is_overlay (bl->section))) |
| 2528 | { |
| 2529 | /* No overlay handling: just set the breakpoint. */ |
| 2530 | try |
| 2531 | { |
| 2532 | int val; |
| 2533 | |
| 2534 | val = bl->owner->ops->insert_location (bl); |
| 2535 | if (val) |
| 2536 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
| 2537 | } |
| 2538 | catch (gdb_exception &e) |
| 2539 | { |
| 2540 | bp_excpt = std::move (e); |
| 2541 | } |
| 2542 | } |
| 2543 | else |
| 2544 | { |
| 2545 | /* This breakpoint is in an overlay section. |
| 2546 | Shall we set a breakpoint at the LMA? */ |
| 2547 | if (!overlay_events_enabled) |
| 2548 | { |
| 2549 | /* Yes -- overlay event support is not active, |
| 2550 | so we must try to set a breakpoint at the LMA. |
| 2551 | This will not work for a hardware breakpoint. */ |
| 2552 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 2553 | warning (_("hardware breakpoint %d not supported in overlay!"), |
| 2554 | bl->owner->number); |
| 2555 | else |
| 2556 | { |
| 2557 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
| 2558 | bl->section); |
| 2559 | /* Set a software (trap) breakpoint at the LMA. */ |
| 2560 | bl->overlay_target_info = bl->target_info; |
| 2561 | bl->overlay_target_info.reqstd_address = addr; |
| 2562 | |
| 2563 | /* No overlay handling: just set the breakpoint. */ |
| 2564 | try |
| 2565 | { |
| 2566 | int val; |
| 2567 | |
| 2568 | bl->overlay_target_info.kind |
| 2569 | = breakpoint_kind (bl, &addr); |
| 2570 | bl->overlay_target_info.placed_address = addr; |
| 2571 | val = target_insert_breakpoint (bl->gdbarch, |
| 2572 | &bl->overlay_target_info); |
| 2573 | if (val) |
| 2574 | bp_excpt |
| 2575 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
| 2576 | } |
| 2577 | catch (gdb_exception &e) |
| 2578 | { |
| 2579 | bp_excpt = std::move (e); |
| 2580 | } |
| 2581 | |
| 2582 | if (bp_excpt.reason != 0) |
| 2583 | fprintf_unfiltered (tmp_error_stream, |
| 2584 | "Overlay breakpoint %d " |
| 2585 | "failed: in ROM?\n", |
| 2586 | bl->owner->number); |
| 2587 | } |
| 2588 | } |
| 2589 | /* Shall we set a breakpoint at the VMA? */ |
| 2590 | if (section_is_mapped (bl->section)) |
| 2591 | { |
| 2592 | /* Yes. This overlay section is mapped into memory. */ |
| 2593 | try |
| 2594 | { |
| 2595 | int val; |
| 2596 | |
| 2597 | val = bl->owner->ops->insert_location (bl); |
| 2598 | if (val) |
| 2599 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
| 2600 | } |
| 2601 | catch (gdb_exception &e) |
| 2602 | { |
| 2603 | bp_excpt = std::move (e); |
| 2604 | } |
| 2605 | } |
| 2606 | else |
| 2607 | { |
| 2608 | /* No. This breakpoint will not be inserted. |
| 2609 | No error, but do not mark the bp as 'inserted'. */ |
| 2610 | return 0; |
| 2611 | } |
| 2612 | } |
| 2613 | |
| 2614 | if (bp_excpt.reason != 0) |
| 2615 | { |
| 2616 | /* Can't set the breakpoint. */ |
| 2617 | |
| 2618 | /* In some cases, we might not be able to insert a |
| 2619 | breakpoint in a shared library that has already been |
| 2620 | removed, but we have not yet processed the shlib unload |
| 2621 | event. Unfortunately, some targets that implement |
| 2622 | breakpoint insertion themselves can't tell why the |
| 2623 | breakpoint insertion failed (e.g., the remote target |
| 2624 | doesn't define error codes), so we must treat generic |
| 2625 | errors as memory errors. */ |
| 2626 | if (bp_excpt.reason == RETURN_ERROR |
| 2627 | && (bp_excpt.error == GENERIC_ERROR |
| 2628 | || bp_excpt.error == MEMORY_ERROR) |
| 2629 | && bl->loc_type == bp_loc_software_breakpoint |
| 2630 | && (solib_name_from_address (bl->pspace, bl->address) |
| 2631 | || shared_objfile_contains_address_p (bl->pspace, |
| 2632 | bl->address))) |
| 2633 | { |
| 2634 | /* See also: disable_breakpoints_in_shlibs. */ |
| 2635 | bl->shlib_disabled = 1; |
| 2636 | gdb::observers::breakpoint_modified.notify (bl->owner); |
| 2637 | if (!*disabled_breaks) |
| 2638 | { |
| 2639 | fprintf_unfiltered (tmp_error_stream, |
| 2640 | "Cannot insert breakpoint %d.\n", |
| 2641 | bl->owner->number); |
| 2642 | fprintf_unfiltered (tmp_error_stream, |
| 2643 | "Temporarily disabling shared " |
| 2644 | "library breakpoints:\n"); |
| 2645 | } |
| 2646 | *disabled_breaks = 1; |
| 2647 | fprintf_unfiltered (tmp_error_stream, |
| 2648 | "breakpoint #%d\n", bl->owner->number); |
| 2649 | return 0; |
| 2650 | } |
| 2651 | else |
| 2652 | { |
| 2653 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 2654 | { |
| 2655 | *hw_breakpoint_error = 1; |
| 2656 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
| 2657 | fprintf_unfiltered (tmp_error_stream, |
| 2658 | "Cannot insert hardware breakpoint %d%s", |
| 2659 | bl->owner->number, |
| 2660 | bp_excpt.message ? ":" : ".\n"); |
| 2661 | if (bp_excpt.message != NULL) |
| 2662 | fprintf_unfiltered (tmp_error_stream, "%s.\n", |
| 2663 | bp_excpt.what ()); |
| 2664 | } |
| 2665 | else |
| 2666 | { |
| 2667 | if (bp_excpt.message == NULL) |
| 2668 | { |
| 2669 | std::string message |
| 2670 | = memory_error_message (TARGET_XFER_E_IO, |
| 2671 | bl->gdbarch, bl->address); |
| 2672 | |
| 2673 | fprintf_unfiltered (tmp_error_stream, |
| 2674 | "Cannot insert breakpoint %d.\n" |
| 2675 | "%s\n", |
| 2676 | bl->owner->number, message.c_str ()); |
| 2677 | } |
| 2678 | else |
| 2679 | { |
| 2680 | fprintf_unfiltered (tmp_error_stream, |
| 2681 | "Cannot insert breakpoint %d: %s\n", |
| 2682 | bl->owner->number, |
| 2683 | bp_excpt.what ()); |
| 2684 | } |
| 2685 | } |
| 2686 | return 1; |
| 2687 | |
| 2688 | } |
| 2689 | } |
| 2690 | else |
| 2691 | bl->inserted = 1; |
| 2692 | |
| 2693 | return 0; |
| 2694 | } |
| 2695 | |
| 2696 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
| 2697 | /* NOTE drow/2003-09-08: This state only exists for removing |
| 2698 | watchpoints. It's not clear that it's necessary... */ |
| 2699 | && bl->owner->disposition != disp_del_at_next_stop) |
| 2700 | { |
| 2701 | int val; |
| 2702 | |
| 2703 | gdb_assert (bl->owner->ops != NULL |
| 2704 | && bl->owner->ops->insert_location != NULL); |
| 2705 | |
| 2706 | val = bl->owner->ops->insert_location (bl); |
| 2707 | |
| 2708 | /* If trying to set a read-watchpoint, and it turns out it's not |
| 2709 | supported, try emulating one with an access watchpoint. */ |
| 2710 | if (val == 1 && bl->watchpoint_type == hw_read) |
| 2711 | { |
| 2712 | struct bp_location *loc, **loc_temp; |
| 2713 | |
| 2714 | /* But don't try to insert it, if there's already another |
| 2715 | hw_access location that would be considered a duplicate |
| 2716 | of this one. */ |
| 2717 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 2718 | if (loc != bl |
| 2719 | && loc->watchpoint_type == hw_access |
| 2720 | && watchpoint_locations_match (bl, loc)) |
| 2721 | { |
| 2722 | bl->duplicate = 1; |
| 2723 | bl->inserted = 1; |
| 2724 | bl->target_info = loc->target_info; |
| 2725 | bl->watchpoint_type = hw_access; |
| 2726 | val = 0; |
| 2727 | break; |
| 2728 | } |
| 2729 | |
| 2730 | if (val == 1) |
| 2731 | { |
| 2732 | bl->watchpoint_type = hw_access; |
| 2733 | val = bl->owner->ops->insert_location (bl); |
| 2734 | |
| 2735 | if (val) |
| 2736 | /* Back to the original value. */ |
| 2737 | bl->watchpoint_type = hw_read; |
| 2738 | } |
| 2739 | } |
| 2740 | |
| 2741 | bl->inserted = (val == 0); |
| 2742 | } |
| 2743 | |
| 2744 | else if (bl->owner->type == bp_catchpoint) |
| 2745 | { |
| 2746 | int val; |
| 2747 | |
| 2748 | gdb_assert (bl->owner->ops != NULL |
| 2749 | && bl->owner->ops->insert_location != NULL); |
| 2750 | |
| 2751 | val = bl->owner->ops->insert_location (bl); |
| 2752 | if (val) |
| 2753 | { |
| 2754 | bl->owner->enable_state = bp_disabled; |
| 2755 | |
| 2756 | if (val == 1) |
| 2757 | warning (_("\ |
| 2758 | Error inserting catchpoint %d: Your system does not support this type\n\ |
| 2759 | of catchpoint."), bl->owner->number); |
| 2760 | else |
| 2761 | warning (_("Error inserting catchpoint %d."), bl->owner->number); |
| 2762 | } |
| 2763 | |
| 2764 | bl->inserted = (val == 0); |
| 2765 | |
| 2766 | /* We've already printed an error message if there was a problem |
| 2767 | inserting this catchpoint, and we've disabled the catchpoint, |
| 2768 | so just return success. */ |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
| 2772 | return 0; |
| 2773 | } |
| 2774 | |
| 2775 | /* This function is called when program space PSPACE is about to be |
| 2776 | deleted. It takes care of updating breakpoints to not reference |
| 2777 | PSPACE anymore. */ |
| 2778 | |
| 2779 | void |
| 2780 | breakpoint_program_space_exit (struct program_space *pspace) |
| 2781 | { |
| 2782 | struct breakpoint *b, *b_temp; |
| 2783 | struct bp_location *loc, **loc_temp; |
| 2784 | |
| 2785 | /* Remove any breakpoint that was set through this program space. */ |
| 2786 | ALL_BREAKPOINTS_SAFE (b, b_temp) |
| 2787 | { |
| 2788 | if (b->pspace == pspace) |
| 2789 | delete_breakpoint (b); |
| 2790 | } |
| 2791 | |
| 2792 | /* Breakpoints set through other program spaces could have locations |
| 2793 | bound to PSPACE as well. Remove those. */ |
| 2794 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 2795 | { |
| 2796 | struct bp_location *tmp; |
| 2797 | |
| 2798 | if (loc->pspace == pspace) |
| 2799 | { |
| 2800 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 2801 | if (loc->owner->loc == loc) |
| 2802 | loc->owner->loc = loc->next; |
| 2803 | else |
| 2804 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) |
| 2805 | if (tmp->next == loc) |
| 2806 | { |
| 2807 | tmp->next = loc->next; |
| 2808 | break; |
| 2809 | } |
| 2810 | } |
| 2811 | } |
| 2812 | |
| 2813 | /* Now update the global location list to permanently delete the |
| 2814 | removed locations above. */ |
| 2815 | update_global_location_list (UGLL_DONT_INSERT); |
| 2816 | } |
| 2817 | |
| 2818 | /* Make sure all breakpoints are inserted in inferior. |
| 2819 | Throws exception on any error. |
| 2820 | A breakpoint that is already inserted won't be inserted |
| 2821 | again, so calling this function twice is safe. */ |
| 2822 | void |
| 2823 | insert_breakpoints (void) |
| 2824 | { |
| 2825 | struct breakpoint *bpt; |
| 2826 | |
| 2827 | ALL_BREAKPOINTS (bpt) |
| 2828 | if (is_hardware_watchpoint (bpt)) |
| 2829 | { |
| 2830 | struct watchpoint *w = (struct watchpoint *) bpt; |
| 2831 | |
| 2832 | update_watchpoint (w, 0 /* don't reparse. */); |
| 2833 | } |
| 2834 | |
| 2835 | /* Updating watchpoints creates new locations, so update the global |
| 2836 | location list. Explicitly tell ugll to insert locations and |
| 2837 | ignore breakpoints_always_inserted_mode. */ |
| 2838 | update_global_location_list (UGLL_INSERT); |
| 2839 | } |
| 2840 | |
| 2841 | /* Invoke CALLBACK for each of bp_location. */ |
| 2842 | |
| 2843 | void |
| 2844 | iterate_over_bp_locations (walk_bp_location_callback callback) |
| 2845 | { |
| 2846 | struct bp_location *loc, **loc_tmp; |
| 2847 | |
| 2848 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 2849 | { |
| 2850 | callback (loc, NULL); |
| 2851 | } |
| 2852 | } |
| 2853 | |
| 2854 | /* This is used when we need to synch breakpoint conditions between GDB and the |
| 2855 | target. It is the case with deleting and disabling of breakpoints when using |
| 2856 | always-inserted mode. */ |
| 2857 | |
| 2858 | static void |
| 2859 | update_inserted_breakpoint_locations (void) |
| 2860 | { |
| 2861 | struct bp_location *bl, **blp_tmp; |
| 2862 | int error_flag = 0; |
| 2863 | int val = 0; |
| 2864 | int disabled_breaks = 0; |
| 2865 | int hw_breakpoint_error = 0; |
| 2866 | int hw_bp_details_reported = 0; |
| 2867 | |
| 2868 | string_file tmp_error_stream; |
| 2869 | |
| 2870 | /* Explicitly mark the warning -- this will only be printed if |
| 2871 | there was an error. */ |
| 2872 | tmp_error_stream.puts ("Warning:\n"); |
| 2873 | |
| 2874 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 2875 | |
| 2876 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 2877 | { |
| 2878 | /* We only want to update software breakpoints and hardware |
| 2879 | breakpoints. */ |
| 2880 | if (!is_breakpoint (bl->owner)) |
| 2881 | continue; |
| 2882 | |
| 2883 | /* We only want to update locations that are already inserted |
| 2884 | and need updating. This is to avoid unwanted insertion during |
| 2885 | deletion of breakpoints. */ |
| 2886 | if (!bl->inserted || !bl->needs_update) |
| 2887 | continue; |
| 2888 | |
| 2889 | switch_to_program_space_and_thread (bl->pspace); |
| 2890 | |
| 2891 | /* For targets that support global breakpoints, there's no need |
| 2892 | to select an inferior to insert breakpoint to. In fact, even |
| 2893 | if we aren't attached to any process yet, we should still |
| 2894 | insert breakpoints. */ |
| 2895 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 2896 | && (inferior_ptid == null_ptid || !target_has_execution)) |
| 2897 | continue; |
| 2898 | |
| 2899 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
| 2900 | &hw_breakpoint_error, &hw_bp_details_reported); |
| 2901 | if (val) |
| 2902 | error_flag = val; |
| 2903 | } |
| 2904 | |
| 2905 | if (error_flag) |
| 2906 | { |
| 2907 | target_terminal::ours_for_output (); |
| 2908 | error_stream (tmp_error_stream); |
| 2909 | } |
| 2910 | } |
| 2911 | |
| 2912 | /* Used when starting or continuing the program. */ |
| 2913 | |
| 2914 | static void |
| 2915 | insert_breakpoint_locations (void) |
| 2916 | { |
| 2917 | struct breakpoint *bpt; |
| 2918 | struct bp_location *bl, **blp_tmp; |
| 2919 | int error_flag = 0; |
| 2920 | int val = 0; |
| 2921 | int disabled_breaks = 0; |
| 2922 | int hw_breakpoint_error = 0; |
| 2923 | int hw_bp_error_explained_already = 0; |
| 2924 | |
| 2925 | string_file tmp_error_stream; |
| 2926 | |
| 2927 | /* Explicitly mark the warning -- this will only be printed if |
| 2928 | there was an error. */ |
| 2929 | tmp_error_stream.puts ("Warning:\n"); |
| 2930 | |
| 2931 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 2932 | |
| 2933 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 2934 | { |
| 2935 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
| 2936 | continue; |
| 2937 | |
| 2938 | /* There is no point inserting thread-specific breakpoints if |
| 2939 | the thread no longer exists. ALL_BP_LOCATIONS bp_location |
| 2940 | has BL->OWNER always non-NULL. */ |
| 2941 | if (bl->owner->thread != -1 |
| 2942 | && !valid_global_thread_id (bl->owner->thread)) |
| 2943 | continue; |
| 2944 | |
| 2945 | switch_to_program_space_and_thread (bl->pspace); |
| 2946 | |
| 2947 | /* For targets that support global breakpoints, there's no need |
| 2948 | to select an inferior to insert breakpoint to. In fact, even |
| 2949 | if we aren't attached to any process yet, we should still |
| 2950 | insert breakpoints. */ |
| 2951 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 2952 | && (inferior_ptid == null_ptid || !target_has_execution)) |
| 2953 | continue; |
| 2954 | |
| 2955 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
| 2956 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
| 2957 | if (val) |
| 2958 | error_flag = val; |
| 2959 | } |
| 2960 | |
| 2961 | /* If we failed to insert all locations of a watchpoint, remove |
| 2962 | them, as half-inserted watchpoint is of limited use. */ |
| 2963 | ALL_BREAKPOINTS (bpt) |
| 2964 | { |
| 2965 | int some_failed = 0; |
| 2966 | struct bp_location *loc; |
| 2967 | |
| 2968 | if (!is_hardware_watchpoint (bpt)) |
| 2969 | continue; |
| 2970 | |
| 2971 | if (!breakpoint_enabled (bpt)) |
| 2972 | continue; |
| 2973 | |
| 2974 | if (bpt->disposition == disp_del_at_next_stop) |
| 2975 | continue; |
| 2976 | |
| 2977 | for (loc = bpt->loc; loc; loc = loc->next) |
| 2978 | if (!loc->inserted && should_be_inserted (loc)) |
| 2979 | { |
| 2980 | some_failed = 1; |
| 2981 | break; |
| 2982 | } |
| 2983 | if (some_failed) |
| 2984 | { |
| 2985 | for (loc = bpt->loc; loc; loc = loc->next) |
| 2986 | if (loc->inserted) |
| 2987 | remove_breakpoint (loc); |
| 2988 | |
| 2989 | hw_breakpoint_error = 1; |
| 2990 | tmp_error_stream.printf ("Could not insert " |
| 2991 | "hardware watchpoint %d.\n", |
| 2992 | bpt->number); |
| 2993 | error_flag = -1; |
| 2994 | } |
| 2995 | } |
| 2996 | |
| 2997 | if (error_flag) |
| 2998 | { |
| 2999 | /* If a hardware breakpoint or watchpoint was inserted, add a |
| 3000 | message about possibly exhausted resources. */ |
| 3001 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
| 3002 | { |
| 3003 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
| 3004 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
| 3005 | } |
| 3006 | target_terminal::ours_for_output (); |
| 3007 | error_stream (tmp_error_stream); |
| 3008 | } |
| 3009 | } |
| 3010 | |
| 3011 | /* Used when the program stops. |
| 3012 | Returns zero if successful, or non-zero if there was a problem |
| 3013 | removing a breakpoint location. */ |
| 3014 | |
| 3015 | int |
| 3016 | remove_breakpoints (void) |
| 3017 | { |
| 3018 | struct bp_location *bl, **blp_tmp; |
| 3019 | int val = 0; |
| 3020 | |
| 3021 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3022 | { |
| 3023 | if (bl->inserted && !is_tracepoint (bl->owner)) |
| 3024 | val |= remove_breakpoint (bl); |
| 3025 | } |
| 3026 | return val; |
| 3027 | } |
| 3028 | |
| 3029 | /* When a thread exits, remove breakpoints that are related to |
| 3030 | that thread. */ |
| 3031 | |
| 3032 | static void |
| 3033 | remove_threaded_breakpoints (struct thread_info *tp, int silent) |
| 3034 | { |
| 3035 | struct breakpoint *b, *b_tmp; |
| 3036 | |
| 3037 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3038 | { |
| 3039 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
| 3040 | { |
| 3041 | b->disposition = disp_del_at_next_stop; |
| 3042 | |
| 3043 | printf_filtered (_("\ |
| 3044 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
| 3045 | b->number, print_thread_id (tp)); |
| 3046 | |
| 3047 | /* Hide it from the user. */ |
| 3048 | b->number = 0; |
| 3049 | } |
| 3050 | } |
| 3051 | } |
| 3052 | |
| 3053 | /* See breakpoint.h. */ |
| 3054 | |
| 3055 | void |
| 3056 | remove_breakpoints_inf (inferior *inf) |
| 3057 | { |
| 3058 | struct bp_location *bl, **blp_tmp; |
| 3059 | int val; |
| 3060 | |
| 3061 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3062 | { |
| 3063 | if (bl->pspace != inf->pspace) |
| 3064 | continue; |
| 3065 | |
| 3066 | if (bl->inserted && !bl->target_info.persist) |
| 3067 | { |
| 3068 | val = remove_breakpoint (bl); |
| 3069 | if (val != 0) |
| 3070 | return; |
| 3071 | } |
| 3072 | } |
| 3073 | } |
| 3074 | |
| 3075 | static int internal_breakpoint_number = -1; |
| 3076 | |
| 3077 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
| 3078 | If INTERNAL is non-zero, the breakpoint number will be populated |
| 3079 | from internal_breakpoint_number and that variable decremented. |
| 3080 | Otherwise the breakpoint number will be populated from |
| 3081 | breakpoint_count and that value incremented. Internal breakpoints |
| 3082 | do not set the internal var bpnum. */ |
| 3083 | static void |
| 3084 | set_breakpoint_number (int internal, struct breakpoint *b) |
| 3085 | { |
| 3086 | if (internal) |
| 3087 | b->number = internal_breakpoint_number--; |
| 3088 | else |
| 3089 | { |
| 3090 | set_breakpoint_count (breakpoint_count + 1); |
| 3091 | b->number = breakpoint_count; |
| 3092 | } |
| 3093 | } |
| 3094 | |
| 3095 | static struct breakpoint * |
| 3096 | create_internal_breakpoint (struct gdbarch *gdbarch, |
| 3097 | CORE_ADDR address, enum bptype type, |
| 3098 | const struct breakpoint_ops *ops) |
| 3099 | { |
| 3100 | symtab_and_line sal; |
| 3101 | sal.pc = address; |
| 3102 | sal.section = find_pc_overlay (sal.pc); |
| 3103 | sal.pspace = current_program_space; |
| 3104 | |
| 3105 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
| 3106 | b->number = internal_breakpoint_number--; |
| 3107 | b->disposition = disp_donttouch; |
| 3108 | |
| 3109 | return b; |
| 3110 | } |
| 3111 | |
| 3112 | static const char *const longjmp_names[] = |
| 3113 | { |
| 3114 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" |
| 3115 | }; |
| 3116 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) |
| 3117 | |
| 3118 | /* Per-objfile data private to breakpoint.c. */ |
| 3119 | struct breakpoint_objfile_data |
| 3120 | { |
| 3121 | /* Minimal symbol for "_ovly_debug_event" (if any). */ |
| 3122 | struct bound_minimal_symbol overlay_msym {}; |
| 3123 | |
| 3124 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ |
| 3125 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
| 3126 | |
| 3127 | /* True if we have looked for longjmp probes. */ |
| 3128 | int longjmp_searched = 0; |
| 3129 | |
| 3130 | /* SystemTap probe points for longjmp (if any). These are non-owning |
| 3131 | references. */ |
| 3132 | std::vector<probe *> longjmp_probes; |
| 3133 | |
| 3134 | /* Minimal symbol for "std::terminate()" (if any). */ |
| 3135 | struct bound_minimal_symbol terminate_msym {}; |
| 3136 | |
| 3137 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ |
| 3138 | struct bound_minimal_symbol exception_msym {}; |
| 3139 | |
| 3140 | /* True if we have looked for exception probes. */ |
| 3141 | int exception_searched = 0; |
| 3142 | |
| 3143 | /* SystemTap probe points for unwinding (if any). These are non-owning |
| 3144 | references. */ |
| 3145 | std::vector<probe *> exception_probes; |
| 3146 | }; |
| 3147 | |
| 3148 | static const struct objfile_key<breakpoint_objfile_data> |
| 3149 | breakpoint_objfile_key; |
| 3150 | |
| 3151 | /* Minimal symbol not found sentinel. */ |
| 3152 | static struct minimal_symbol msym_not_found; |
| 3153 | |
| 3154 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ |
| 3155 | |
| 3156 | static int |
| 3157 | msym_not_found_p (const struct minimal_symbol *msym) |
| 3158 | { |
| 3159 | return msym == &msym_not_found; |
| 3160 | } |
| 3161 | |
| 3162 | /* Return per-objfile data needed by breakpoint.c. |
| 3163 | Allocate the data if necessary. */ |
| 3164 | |
| 3165 | static struct breakpoint_objfile_data * |
| 3166 | get_breakpoint_objfile_data (struct objfile *objfile) |
| 3167 | { |
| 3168 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3169 | |
| 3170 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
| 3171 | if (bp_objfile_data == NULL) |
| 3172 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
| 3173 | return bp_objfile_data; |
| 3174 | } |
| 3175 | |
| 3176 | static void |
| 3177 | create_overlay_event_breakpoint (void) |
| 3178 | { |
| 3179 | const char *const func_name = "_ovly_debug_event"; |
| 3180 | |
| 3181 | for (objfile *objfile : current_program_space->objfiles ()) |
| 3182 | { |
| 3183 | struct breakpoint *b; |
| 3184 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3185 | CORE_ADDR addr; |
| 3186 | struct explicit_location explicit_loc; |
| 3187 | |
| 3188 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3189 | |
| 3190 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
| 3191 | continue; |
| 3192 | |
| 3193 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
| 3194 | { |
| 3195 | struct bound_minimal_symbol m; |
| 3196 | |
| 3197 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 3198 | if (m.minsym == NULL) |
| 3199 | { |
| 3200 | /* Avoid future lookups in this objfile. */ |
| 3201 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
| 3202 | continue; |
| 3203 | } |
| 3204 | bp_objfile_data->overlay_msym = m; |
| 3205 | } |
| 3206 | |
| 3207 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
| 3208 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
| 3209 | bp_overlay_event, |
| 3210 | &internal_breakpoint_ops); |
| 3211 | initialize_explicit_location (&explicit_loc); |
| 3212 | explicit_loc.function_name = ASTRDUP (func_name); |
| 3213 | b->location = new_explicit_location (&explicit_loc); |
| 3214 | |
| 3215 | if (overlay_debugging == ovly_auto) |
| 3216 | { |
| 3217 | b->enable_state = bp_enabled; |
| 3218 | overlay_events_enabled = 1; |
| 3219 | } |
| 3220 | else |
| 3221 | { |
| 3222 | b->enable_state = bp_disabled; |
| 3223 | overlay_events_enabled = 0; |
| 3224 | } |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | static void |
| 3229 | create_longjmp_master_breakpoint (void) |
| 3230 | { |
| 3231 | struct program_space *pspace; |
| 3232 | |
| 3233 | scoped_restore_current_program_space restore_pspace; |
| 3234 | |
| 3235 | ALL_PSPACES (pspace) |
| 3236 | { |
| 3237 | set_current_program_space (pspace); |
| 3238 | |
| 3239 | for (objfile *objfile : current_program_space->objfiles ()) |
| 3240 | { |
| 3241 | int i; |
| 3242 | struct gdbarch *gdbarch; |
| 3243 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3244 | |
| 3245 | gdbarch = get_objfile_arch (objfile); |
| 3246 | |
| 3247 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3248 | |
| 3249 | if (!bp_objfile_data->longjmp_searched) |
| 3250 | { |
| 3251 | std::vector<probe *> ret |
| 3252 | = find_probes_in_objfile (objfile, "libc", "longjmp"); |
| 3253 | |
| 3254 | if (!ret.empty ()) |
| 3255 | { |
| 3256 | /* We are only interested in checking one element. */ |
| 3257 | probe *p = ret[0]; |
| 3258 | |
| 3259 | if (!p->can_evaluate_arguments ()) |
| 3260 | { |
| 3261 | /* We cannot use the probe interface here, because it does |
| 3262 | not know how to evaluate arguments. */ |
| 3263 | ret.clear (); |
| 3264 | } |
| 3265 | } |
| 3266 | bp_objfile_data->longjmp_probes = ret; |
| 3267 | bp_objfile_data->longjmp_searched = 1; |
| 3268 | } |
| 3269 | |
| 3270 | if (!bp_objfile_data->longjmp_probes.empty ()) |
| 3271 | { |
| 3272 | for (probe *p : bp_objfile_data->longjmp_probes) |
| 3273 | { |
| 3274 | struct breakpoint *b; |
| 3275 | |
| 3276 | b = create_internal_breakpoint (gdbarch, |
| 3277 | p->get_relocated_address (objfile), |
| 3278 | bp_longjmp_master, |
| 3279 | &internal_breakpoint_ops); |
| 3280 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
| 3281 | b->enable_state = bp_disabled; |
| 3282 | } |
| 3283 | |
| 3284 | continue; |
| 3285 | } |
| 3286 | |
| 3287 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
| 3288 | continue; |
| 3289 | |
| 3290 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
| 3291 | { |
| 3292 | struct breakpoint *b; |
| 3293 | const char *func_name; |
| 3294 | CORE_ADDR addr; |
| 3295 | struct explicit_location explicit_loc; |
| 3296 | |
| 3297 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
| 3298 | continue; |
| 3299 | |
| 3300 | func_name = longjmp_names[i]; |
| 3301 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
| 3302 | { |
| 3303 | struct bound_minimal_symbol m; |
| 3304 | |
| 3305 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 3306 | if (m.minsym == NULL) |
| 3307 | { |
| 3308 | /* Prevent future lookups in this objfile. */ |
| 3309 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
| 3310 | continue; |
| 3311 | } |
| 3312 | bp_objfile_data->longjmp_msym[i] = m; |
| 3313 | } |
| 3314 | |
| 3315 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
| 3316 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
| 3317 | &internal_breakpoint_ops); |
| 3318 | initialize_explicit_location (&explicit_loc); |
| 3319 | explicit_loc.function_name = ASTRDUP (func_name); |
| 3320 | b->location = new_explicit_location (&explicit_loc); |
| 3321 | b->enable_state = bp_disabled; |
| 3322 | } |
| 3323 | } |
| 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | /* Create a master std::terminate breakpoint. */ |
| 3328 | static void |
| 3329 | create_std_terminate_master_breakpoint (void) |
| 3330 | { |
| 3331 | struct program_space *pspace; |
| 3332 | const char *const func_name = "std::terminate()"; |
| 3333 | |
| 3334 | scoped_restore_current_program_space restore_pspace; |
| 3335 | |
| 3336 | ALL_PSPACES (pspace) |
| 3337 | { |
| 3338 | CORE_ADDR addr; |
| 3339 | |
| 3340 | set_current_program_space (pspace); |
| 3341 | |
| 3342 | for (objfile *objfile : current_program_space->objfiles ()) |
| 3343 | { |
| 3344 | struct breakpoint *b; |
| 3345 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3346 | struct explicit_location explicit_loc; |
| 3347 | |
| 3348 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3349 | |
| 3350 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
| 3351 | continue; |
| 3352 | |
| 3353 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
| 3354 | { |
| 3355 | struct bound_minimal_symbol m; |
| 3356 | |
| 3357 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
| 3358 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
| 3359 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) |
| 3360 | { |
| 3361 | /* Prevent future lookups in this objfile. */ |
| 3362 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
| 3363 | continue; |
| 3364 | } |
| 3365 | bp_objfile_data->terminate_msym = m; |
| 3366 | } |
| 3367 | |
| 3368 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
| 3369 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
| 3370 | bp_std_terminate_master, |
| 3371 | &internal_breakpoint_ops); |
| 3372 | initialize_explicit_location (&explicit_loc); |
| 3373 | explicit_loc.function_name = ASTRDUP (func_name); |
| 3374 | b->location = new_explicit_location (&explicit_loc); |
| 3375 | b->enable_state = bp_disabled; |
| 3376 | } |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | /* Install a master breakpoint on the unwinder's debug hook. */ |
| 3381 | |
| 3382 | static void |
| 3383 | create_exception_master_breakpoint (void) |
| 3384 | { |
| 3385 | const char *const func_name = "_Unwind_DebugHook"; |
| 3386 | |
| 3387 | for (objfile *objfile : current_program_space->objfiles ()) |
| 3388 | { |
| 3389 | struct breakpoint *b; |
| 3390 | struct gdbarch *gdbarch; |
| 3391 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3392 | CORE_ADDR addr; |
| 3393 | struct explicit_location explicit_loc; |
| 3394 | |
| 3395 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3396 | |
| 3397 | /* We prefer the SystemTap probe point if it exists. */ |
| 3398 | if (!bp_objfile_data->exception_searched) |
| 3399 | { |
| 3400 | std::vector<probe *> ret |
| 3401 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); |
| 3402 | |
| 3403 | if (!ret.empty ()) |
| 3404 | { |
| 3405 | /* We are only interested in checking one element. */ |
| 3406 | probe *p = ret[0]; |
| 3407 | |
| 3408 | if (!p->can_evaluate_arguments ()) |
| 3409 | { |
| 3410 | /* We cannot use the probe interface here, because it does |
| 3411 | not know how to evaluate arguments. */ |
| 3412 | ret.clear (); |
| 3413 | } |
| 3414 | } |
| 3415 | bp_objfile_data->exception_probes = ret; |
| 3416 | bp_objfile_data->exception_searched = 1; |
| 3417 | } |
| 3418 | |
| 3419 | if (!bp_objfile_data->exception_probes.empty ()) |
| 3420 | { |
| 3421 | gdbarch = get_objfile_arch (objfile); |
| 3422 | |
| 3423 | for (probe *p : bp_objfile_data->exception_probes) |
| 3424 | { |
| 3425 | b = create_internal_breakpoint (gdbarch, |
| 3426 | p->get_relocated_address (objfile), |
| 3427 | bp_exception_master, |
| 3428 | &internal_breakpoint_ops); |
| 3429 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
| 3430 | b->enable_state = bp_disabled; |
| 3431 | } |
| 3432 | |
| 3433 | continue; |
| 3434 | } |
| 3435 | |
| 3436 | /* Otherwise, try the hook function. */ |
| 3437 | |
| 3438 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
| 3439 | continue; |
| 3440 | |
| 3441 | gdbarch = get_objfile_arch (objfile); |
| 3442 | |
| 3443 | if (bp_objfile_data->exception_msym.minsym == NULL) |
| 3444 | { |
| 3445 | struct bound_minimal_symbol debug_hook; |
| 3446 | |
| 3447 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
| 3448 | if (debug_hook.minsym == NULL) |
| 3449 | { |
| 3450 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
| 3451 | continue; |
| 3452 | } |
| 3453 | |
| 3454 | bp_objfile_data->exception_msym = debug_hook; |
| 3455 | } |
| 3456 | |
| 3457 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
| 3458 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
| 3459 | current_top_target ()); |
| 3460 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
| 3461 | &internal_breakpoint_ops); |
| 3462 | initialize_explicit_location (&explicit_loc); |
| 3463 | explicit_loc.function_name = ASTRDUP (func_name); |
| 3464 | b->location = new_explicit_location (&explicit_loc); |
| 3465 | b->enable_state = bp_disabled; |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | /* Does B have a location spec? */ |
| 3470 | |
| 3471 | static int |
| 3472 | breakpoint_event_location_empty_p (const struct breakpoint *b) |
| 3473 | { |
| 3474 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
| 3475 | } |
| 3476 | |
| 3477 | void |
| 3478 | update_breakpoints_after_exec (void) |
| 3479 | { |
| 3480 | struct breakpoint *b, *b_tmp; |
| 3481 | struct bp_location *bploc, **bplocp_tmp; |
| 3482 | |
| 3483 | /* We're about to delete breakpoints from GDB's lists. If the |
| 3484 | INSERTED flag is true, GDB will try to lift the breakpoints by |
| 3485 | writing the breakpoints' "shadow contents" back into memory. The |
| 3486 | "shadow contents" are NOT valid after an exec, so GDB should not |
| 3487 | do that. Instead, the target is responsible from marking |
| 3488 | breakpoints out as soon as it detects an exec. We don't do that |
| 3489 | here instead, because there may be other attempts to delete |
| 3490 | breakpoints after detecting an exec and before reaching here. */ |
| 3491 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
| 3492 | if (bploc->pspace == current_program_space) |
| 3493 | gdb_assert (!bploc->inserted); |
| 3494 | |
| 3495 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3496 | { |
| 3497 | if (b->pspace != current_program_space) |
| 3498 | continue; |
| 3499 | |
| 3500 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
| 3501 | if (b->type == bp_shlib_event) |
| 3502 | { |
| 3503 | delete_breakpoint (b); |
| 3504 | continue; |
| 3505 | } |
| 3506 | |
| 3507 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
| 3508 | if (b->type == bp_jit_event) |
| 3509 | { |
| 3510 | delete_breakpoint (b); |
| 3511 | continue; |
| 3512 | } |
| 3513 | |
| 3514 | /* Thread event breakpoints must be set anew after an exec(), |
| 3515 | as must overlay event and longjmp master breakpoints. */ |
| 3516 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
| 3517 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
| 3518 | || b->type == bp_exception_master) |
| 3519 | { |
| 3520 | delete_breakpoint (b); |
| 3521 | continue; |
| 3522 | } |
| 3523 | |
| 3524 | /* Step-resume breakpoints are meaningless after an exec(). */ |
| 3525 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
| 3526 | { |
| 3527 | delete_breakpoint (b); |
| 3528 | continue; |
| 3529 | } |
| 3530 | |
| 3531 | /* Just like single-step breakpoints. */ |
| 3532 | if (b->type == bp_single_step) |
| 3533 | { |
| 3534 | delete_breakpoint (b); |
| 3535 | continue; |
| 3536 | } |
| 3537 | |
| 3538 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
| 3539 | after an exec. */ |
| 3540 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
| 3541 | || b->type == bp_longjmp_call_dummy |
| 3542 | || b->type == bp_exception || b->type == bp_exception_resume) |
| 3543 | { |
| 3544 | delete_breakpoint (b); |
| 3545 | continue; |
| 3546 | } |
| 3547 | |
| 3548 | if (b->type == bp_catchpoint) |
| 3549 | { |
| 3550 | /* For now, none of the bp_catchpoint breakpoints need to |
| 3551 | do anything at this point. In the future, if some of |
| 3552 | the catchpoints need to something, we will need to add |
| 3553 | a new method, and call this method from here. */ |
| 3554 | continue; |
| 3555 | } |
| 3556 | |
| 3557 | /* bp_finish is a special case. The only way we ought to be able |
| 3558 | to see one of these when an exec() has happened, is if the user |
| 3559 | caught a vfork, and then said "finish". Ordinarily a finish just |
| 3560 | carries them to the call-site of the current callee, by setting |
| 3561 | a temporary bp there and resuming. But in this case, the finish |
| 3562 | will carry them entirely through the vfork & exec. |
| 3563 | |
| 3564 | We don't want to allow a bp_finish to remain inserted now. But |
| 3565 | we can't safely delete it, 'cause finish_command has a handle to |
| 3566 | the bp on a bpstat, and will later want to delete it. There's a |
| 3567 | chance (and I've seen it happen) that if we delete the bp_finish |
| 3568 | here, that its storage will get reused by the time finish_command |
| 3569 | gets 'round to deleting the "use to be a bp_finish" breakpoint. |
| 3570 | We really must allow finish_command to delete a bp_finish. |
| 3571 | |
| 3572 | In the absence of a general solution for the "how do we know |
| 3573 | it's safe to delete something others may have handles to?" |
| 3574 | problem, what we'll do here is just uninsert the bp_finish, and |
| 3575 | let finish_command delete it. |
| 3576 | |
| 3577 | (We know the bp_finish is "doomed" in the sense that it's |
| 3578 | momentary, and will be deleted as soon as finish_command sees |
| 3579 | the inferior stopped. So it doesn't matter that the bp's |
| 3580 | address is probably bogus in the new a.out, unlike e.g., the |
| 3581 | solib breakpoints.) */ |
| 3582 | |
| 3583 | if (b->type == bp_finish) |
| 3584 | { |
| 3585 | continue; |
| 3586 | } |
| 3587 | |
| 3588 | /* Without a symbolic address, we have little hope of the |
| 3589 | pre-exec() address meaning the same thing in the post-exec() |
| 3590 | a.out. */ |
| 3591 | if (breakpoint_event_location_empty_p (b)) |
| 3592 | { |
| 3593 | delete_breakpoint (b); |
| 3594 | continue; |
| 3595 | } |
| 3596 | } |
| 3597 | } |
| 3598 | |
| 3599 | int |
| 3600 | detach_breakpoints (ptid_t ptid) |
| 3601 | { |
| 3602 | struct bp_location *bl, **blp_tmp; |
| 3603 | int val = 0; |
| 3604 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
| 3605 | struct inferior *inf = current_inferior (); |
| 3606 | |
| 3607 | if (ptid.pid () == inferior_ptid.pid ()) |
| 3608 | error (_("Cannot detach breakpoints of inferior_ptid")); |
| 3609 | |
| 3610 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
| 3611 | inferior_ptid = ptid; |
| 3612 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3613 | { |
| 3614 | if (bl->pspace != inf->pspace) |
| 3615 | continue; |
| 3616 | |
| 3617 | /* This function must physically remove breakpoints locations |
| 3618 | from the specified ptid, without modifying the breakpoint |
| 3619 | package's state. Locations of type bp_loc_other are only |
| 3620 | maintained at GDB side. So, there is no need to remove |
| 3621 | these bp_loc_other locations. Moreover, removing these |
| 3622 | would modify the breakpoint package's state. */ |
| 3623 | if (bl->loc_type == bp_loc_other) |
| 3624 | continue; |
| 3625 | |
| 3626 | if (bl->inserted) |
| 3627 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
| 3628 | } |
| 3629 | |
| 3630 | return val; |
| 3631 | } |
| 3632 | |
| 3633 | /* Remove the breakpoint location BL from the current address space. |
| 3634 | Note that this is used to detach breakpoints from a child fork. |
| 3635 | When we get here, the child isn't in the inferior list, and neither |
| 3636 | do we have objects to represent its address space --- we should |
| 3637 | *not* look at bl->pspace->aspace here. */ |
| 3638 | |
| 3639 | static int |
| 3640 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
| 3641 | { |
| 3642 | int val; |
| 3643 | |
| 3644 | /* BL is never in moribund_locations by our callers. */ |
| 3645 | gdb_assert (bl->owner != NULL); |
| 3646 | |
| 3647 | /* The type of none suggests that owner is actually deleted. |
| 3648 | This should not ever happen. */ |
| 3649 | gdb_assert (bl->owner->type != bp_none); |
| 3650 | |
| 3651 | if (bl->loc_type == bp_loc_software_breakpoint |
| 3652 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 3653 | { |
| 3654 | /* "Normal" instruction breakpoint: either the standard |
| 3655 | trap-instruction bp (bp_breakpoint), or a |
| 3656 | bp_hardware_breakpoint. */ |
| 3657 | |
| 3658 | /* First check to see if we have to handle an overlay. */ |
| 3659 | if (overlay_debugging == ovly_off |
| 3660 | || bl->section == NULL |
| 3661 | || !(section_is_overlay (bl->section))) |
| 3662 | { |
| 3663 | /* No overlay handling: just remove the breakpoint. */ |
| 3664 | |
| 3665 | /* If we're trying to uninsert a memory breakpoint that we |
| 3666 | know is set in a dynamic object that is marked |
| 3667 | shlib_disabled, then either the dynamic object was |
| 3668 | removed with "remove-symbol-file" or with |
| 3669 | "nosharedlibrary". In the former case, we don't know |
| 3670 | whether another dynamic object might have loaded over the |
| 3671 | breakpoint's address -- the user might well let us know |
| 3672 | about it next with add-symbol-file (the whole point of |
| 3673 | add-symbol-file is letting the user manually maintain a |
| 3674 | list of dynamically loaded objects). If we have the |
| 3675 | breakpoint's shadow memory, that is, this is a software |
| 3676 | breakpoint managed by GDB, check whether the breakpoint |
| 3677 | is still inserted in memory, to avoid overwriting wrong |
| 3678 | code with stale saved shadow contents. Note that HW |
| 3679 | breakpoints don't have shadow memory, as they're |
| 3680 | implemented using a mechanism that is not dependent on |
| 3681 | being able to modify the target's memory, and as such |
| 3682 | they should always be removed. */ |
| 3683 | if (bl->shlib_disabled |
| 3684 | && bl->target_info.shadow_len != 0 |
| 3685 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) |
| 3686 | val = 0; |
| 3687 | else |
| 3688 | val = bl->owner->ops->remove_location (bl, reason); |
| 3689 | } |
| 3690 | else |
| 3691 | { |
| 3692 | /* This breakpoint is in an overlay section. |
| 3693 | Did we set a breakpoint at the LMA? */ |
| 3694 | if (!overlay_events_enabled) |
| 3695 | { |
| 3696 | /* Yes -- overlay event support is not active, so we |
| 3697 | should have set a breakpoint at the LMA. Remove it. |
| 3698 | */ |
| 3699 | /* Ignore any failures: if the LMA is in ROM, we will |
| 3700 | have already warned when we failed to insert it. */ |
| 3701 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 3702 | target_remove_hw_breakpoint (bl->gdbarch, |
| 3703 | &bl->overlay_target_info); |
| 3704 | else |
| 3705 | target_remove_breakpoint (bl->gdbarch, |
| 3706 | &bl->overlay_target_info, |
| 3707 | reason); |
| 3708 | } |
| 3709 | /* Did we set a breakpoint at the VMA? |
| 3710 | If so, we will have marked the breakpoint 'inserted'. */ |
| 3711 | if (bl->inserted) |
| 3712 | { |
| 3713 | /* Yes -- remove it. Previously we did not bother to |
| 3714 | remove the breakpoint if the section had been |
| 3715 | unmapped, but let's not rely on that being safe. We |
| 3716 | don't know what the overlay manager might do. */ |
| 3717 | |
| 3718 | /* However, we should remove *software* breakpoints only |
| 3719 | if the section is still mapped, or else we overwrite |
| 3720 | wrong code with the saved shadow contents. */ |
| 3721 | if (bl->loc_type == bp_loc_hardware_breakpoint |
| 3722 | || section_is_mapped (bl->section)) |
| 3723 | val = bl->owner->ops->remove_location (bl, reason); |
| 3724 | else |
| 3725 | val = 0; |
| 3726 | } |
| 3727 | else |
| 3728 | { |
| 3729 | /* No -- not inserted, so no need to remove. No error. */ |
| 3730 | val = 0; |
| 3731 | } |
| 3732 | } |
| 3733 | |
| 3734 | /* In some cases, we might not be able to remove a breakpoint in |
| 3735 | a shared library that has already been removed, but we have |
| 3736 | not yet processed the shlib unload event. Similarly for an |
| 3737 | unloaded add-symbol-file object - the user might not yet have |
| 3738 | had the chance to remove-symbol-file it. shlib_disabled will |
| 3739 | be set if the library/object has already been removed, but |
| 3740 | the breakpoint hasn't been uninserted yet, e.g., after |
| 3741 | "nosharedlibrary" or "remove-symbol-file" with breakpoints |
| 3742 | always-inserted mode. */ |
| 3743 | if (val |
| 3744 | && (bl->loc_type == bp_loc_software_breakpoint |
| 3745 | && (bl->shlib_disabled |
| 3746 | || solib_name_from_address (bl->pspace, bl->address) |
| 3747 | || shared_objfile_contains_address_p (bl->pspace, |
| 3748 | bl->address)))) |
| 3749 | val = 0; |
| 3750 | |
| 3751 | if (val) |
| 3752 | return val; |
| 3753 | bl->inserted = (reason == DETACH_BREAKPOINT); |
| 3754 | } |
| 3755 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
| 3756 | { |
| 3757 | gdb_assert (bl->owner->ops != NULL |
| 3758 | && bl->owner->ops->remove_location != NULL); |
| 3759 | |
| 3760 | bl->inserted = (reason == DETACH_BREAKPOINT); |
| 3761 | bl->owner->ops->remove_location (bl, reason); |
| 3762 | |
| 3763 | /* Failure to remove any of the hardware watchpoints comes here. */ |
| 3764 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
| 3765 | warning (_("Could not remove hardware watchpoint %d."), |
| 3766 | bl->owner->number); |
| 3767 | } |
| 3768 | else if (bl->owner->type == bp_catchpoint |
| 3769 | && breakpoint_enabled (bl->owner) |
| 3770 | && !bl->duplicate) |
| 3771 | { |
| 3772 | gdb_assert (bl->owner->ops != NULL |
| 3773 | && bl->owner->ops->remove_location != NULL); |
| 3774 | |
| 3775 | val = bl->owner->ops->remove_location (bl, reason); |
| 3776 | if (val) |
| 3777 | return val; |
| 3778 | |
| 3779 | bl->inserted = (reason == DETACH_BREAKPOINT); |
| 3780 | } |
| 3781 | |
| 3782 | return 0; |
| 3783 | } |
| 3784 | |
| 3785 | static int |
| 3786 | remove_breakpoint (struct bp_location *bl) |
| 3787 | { |
| 3788 | /* BL is never in moribund_locations by our callers. */ |
| 3789 | gdb_assert (bl->owner != NULL); |
| 3790 | |
| 3791 | /* The type of none suggests that owner is actually deleted. |
| 3792 | This should not ever happen. */ |
| 3793 | gdb_assert (bl->owner->type != bp_none); |
| 3794 | |
| 3795 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 3796 | |
| 3797 | switch_to_program_space_and_thread (bl->pspace); |
| 3798 | |
| 3799 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
| 3800 | } |
| 3801 | |
| 3802 | /* Clear the "inserted" flag in all breakpoints. */ |
| 3803 | |
| 3804 | void |
| 3805 | mark_breakpoints_out (void) |
| 3806 | { |
| 3807 | struct bp_location *bl, **blp_tmp; |
| 3808 | |
| 3809 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3810 | if (bl->pspace == current_program_space) |
| 3811 | bl->inserted = 0; |
| 3812 | } |
| 3813 | |
| 3814 | /* Clear the "inserted" flag in all breakpoints and delete any |
| 3815 | breakpoints which should go away between runs of the program. |
| 3816 | |
| 3817 | Plus other such housekeeping that has to be done for breakpoints |
| 3818 | between runs. |
| 3819 | |
| 3820 | Note: this function gets called at the end of a run (by |
| 3821 | generic_mourn_inferior) and when a run begins (by |
| 3822 | init_wait_for_inferior). */ |
| 3823 | |
| 3824 | |
| 3825 | |
| 3826 | void |
| 3827 | breakpoint_init_inferior (enum inf_context context) |
| 3828 | { |
| 3829 | struct breakpoint *b, *b_tmp; |
| 3830 | struct program_space *pspace = current_program_space; |
| 3831 | |
| 3832 | /* If breakpoint locations are shared across processes, then there's |
| 3833 | nothing to do. */ |
| 3834 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
| 3835 | return; |
| 3836 | |
| 3837 | mark_breakpoints_out (); |
| 3838 | |
| 3839 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3840 | { |
| 3841 | if (b->loc && b->loc->pspace != pspace) |
| 3842 | continue; |
| 3843 | |
| 3844 | switch (b->type) |
| 3845 | { |
| 3846 | case bp_call_dummy: |
| 3847 | case bp_longjmp_call_dummy: |
| 3848 | |
| 3849 | /* If the call dummy breakpoint is at the entry point it will |
| 3850 | cause problems when the inferior is rerun, so we better get |
| 3851 | rid of it. */ |
| 3852 | |
| 3853 | case bp_watchpoint_scope: |
| 3854 | |
| 3855 | /* Also get rid of scope breakpoints. */ |
| 3856 | |
| 3857 | case bp_shlib_event: |
| 3858 | |
| 3859 | /* Also remove solib event breakpoints. Their addresses may |
| 3860 | have changed since the last time we ran the program. |
| 3861 | Actually we may now be debugging against different target; |
| 3862 | and so the solib backend that installed this breakpoint may |
| 3863 | not be used in by the target. E.g., |
| 3864 | |
| 3865 | (gdb) file prog-linux |
| 3866 | (gdb) run # native linux target |
| 3867 | ... |
| 3868 | (gdb) kill |
| 3869 | (gdb) file prog-win.exe |
| 3870 | (gdb) tar rem :9999 # remote Windows gdbserver. |
| 3871 | */ |
| 3872 | |
| 3873 | case bp_step_resume: |
| 3874 | |
| 3875 | /* Also remove step-resume breakpoints. */ |
| 3876 | |
| 3877 | case bp_single_step: |
| 3878 | |
| 3879 | /* Also remove single-step breakpoints. */ |
| 3880 | |
| 3881 | delete_breakpoint (b); |
| 3882 | break; |
| 3883 | |
| 3884 | case bp_watchpoint: |
| 3885 | case bp_hardware_watchpoint: |
| 3886 | case bp_read_watchpoint: |
| 3887 | case bp_access_watchpoint: |
| 3888 | { |
| 3889 | struct watchpoint *w = (struct watchpoint *) b; |
| 3890 | |
| 3891 | /* Likewise for watchpoints on local expressions. */ |
| 3892 | if (w->exp_valid_block != NULL) |
| 3893 | delete_breakpoint (b); |
| 3894 | else |
| 3895 | { |
| 3896 | /* Get rid of existing locations, which are no longer |
| 3897 | valid. New ones will be created in |
| 3898 | update_watchpoint, when the inferior is restarted. |
| 3899 | The next update_global_location_list call will |
| 3900 | garbage collect them. */ |
| 3901 | b->loc = NULL; |
| 3902 | |
| 3903 | if (context == inf_starting) |
| 3904 | { |
| 3905 | /* Reset val field to force reread of starting value in |
| 3906 | insert_breakpoints. */ |
| 3907 | w->val.reset (nullptr); |
| 3908 | w->val_valid = false; |
| 3909 | } |
| 3910 | } |
| 3911 | } |
| 3912 | break; |
| 3913 | default: |
| 3914 | break; |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | /* Get rid of the moribund locations. */ |
| 3919 | for (bp_location *bl : moribund_locations) |
| 3920 | decref_bp_location (&bl); |
| 3921 | moribund_locations.clear (); |
| 3922 | } |
| 3923 | |
| 3924 | /* These functions concern about actual breakpoints inserted in the |
| 3925 | target --- to e.g. check if we need to do decr_pc adjustment or if |
| 3926 | we need to hop over the bkpt --- so we check for address space |
| 3927 | match, not program space. */ |
| 3928 | |
| 3929 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
| 3930 | exists at PC. It returns ordinary_breakpoint_here if it's an |
| 3931 | ordinary breakpoint, or permanent_breakpoint_here if it's a |
| 3932 | permanent breakpoint. |
| 3933 | - When continuing from a location with an ordinary breakpoint, we |
| 3934 | actually single step once before calling insert_breakpoints. |
| 3935 | - When continuing from a location with a permanent breakpoint, we |
| 3936 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
| 3937 | the target, to advance the PC past the breakpoint. */ |
| 3938 | |
| 3939 | enum breakpoint_here |
| 3940 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
| 3941 | { |
| 3942 | struct bp_location *bl, **blp_tmp; |
| 3943 | int any_breakpoint_here = 0; |
| 3944 | |
| 3945 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3946 | { |
| 3947 | if (bl->loc_type != bp_loc_software_breakpoint |
| 3948 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 3949 | continue; |
| 3950 | |
| 3951 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
| 3952 | if ((breakpoint_enabled (bl->owner) |
| 3953 | || bl->permanent) |
| 3954 | && breakpoint_location_address_match (bl, aspace, pc)) |
| 3955 | { |
| 3956 | if (overlay_debugging |
| 3957 | && section_is_overlay (bl->section) |
| 3958 | && !section_is_mapped (bl->section)) |
| 3959 | continue; /* unmapped overlay -- can't be a match */ |
| 3960 | else if (bl->permanent) |
| 3961 | return permanent_breakpoint_here; |
| 3962 | else |
| 3963 | any_breakpoint_here = 1; |
| 3964 | } |
| 3965 | } |
| 3966 | |
| 3967 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
| 3968 | } |
| 3969 | |
| 3970 | /* See breakpoint.h. */ |
| 3971 | |
| 3972 | int |
| 3973 | breakpoint_in_range_p (const address_space *aspace, |
| 3974 | CORE_ADDR addr, ULONGEST len) |
| 3975 | { |
| 3976 | struct bp_location *bl, **blp_tmp; |
| 3977 | |
| 3978 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3979 | { |
| 3980 | if (bl->loc_type != bp_loc_software_breakpoint |
| 3981 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 3982 | continue; |
| 3983 | |
| 3984 | if ((breakpoint_enabled (bl->owner) |
| 3985 | || bl->permanent) |
| 3986 | && breakpoint_location_address_range_overlap (bl, aspace, |
| 3987 | addr, len)) |
| 3988 | { |
| 3989 | if (overlay_debugging |
| 3990 | && section_is_overlay (bl->section) |
| 3991 | && !section_is_mapped (bl->section)) |
| 3992 | { |
| 3993 | /* Unmapped overlay -- can't be a match. */ |
| 3994 | continue; |
| 3995 | } |
| 3996 | |
| 3997 | return 1; |
| 3998 | } |
| 3999 | } |
| 4000 | |
| 4001 | return 0; |
| 4002 | } |
| 4003 | |
| 4004 | /* Return true if there's a moribund breakpoint at PC. */ |
| 4005 | |
| 4006 | int |
| 4007 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
| 4008 | { |
| 4009 | for (bp_location *loc : moribund_locations) |
| 4010 | if (breakpoint_location_address_match (loc, aspace, pc)) |
| 4011 | return 1; |
| 4012 | |
| 4013 | return 0; |
| 4014 | } |
| 4015 | |
| 4016 | /* Returns non-zero iff BL is inserted at PC, in address space |
| 4017 | ASPACE. */ |
| 4018 | |
| 4019 | static int |
| 4020 | bp_location_inserted_here_p (struct bp_location *bl, |
| 4021 | const address_space *aspace, CORE_ADDR pc) |
| 4022 | { |
| 4023 | if (bl->inserted |
| 4024 | && breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 4025 | aspace, pc)) |
| 4026 | { |
| 4027 | if (overlay_debugging |
| 4028 | && section_is_overlay (bl->section) |
| 4029 | && !section_is_mapped (bl->section)) |
| 4030 | return 0; /* unmapped overlay -- can't be a match */ |
| 4031 | else |
| 4032 | return 1; |
| 4033 | } |
| 4034 | return 0; |
| 4035 | } |
| 4036 | |
| 4037 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
| 4038 | |
| 4039 | int |
| 4040 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
| 4041 | { |
| 4042 | struct bp_location **blp, **blp_tmp = NULL; |
| 4043 | |
| 4044 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4045 | { |
| 4046 | struct bp_location *bl = *blp; |
| 4047 | |
| 4048 | if (bl->loc_type != bp_loc_software_breakpoint |
| 4049 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 4050 | continue; |
| 4051 | |
| 4052 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4053 | return 1; |
| 4054 | } |
| 4055 | return 0; |
| 4056 | } |
| 4057 | |
| 4058 | /* This function returns non-zero iff there is a software breakpoint |
| 4059 | inserted at PC. */ |
| 4060 | |
| 4061 | int |
| 4062 | software_breakpoint_inserted_here_p (const address_space *aspace, |
| 4063 | CORE_ADDR pc) |
| 4064 | { |
| 4065 | struct bp_location **blp, **blp_tmp = NULL; |
| 4066 | |
| 4067 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4068 | { |
| 4069 | struct bp_location *bl = *blp; |
| 4070 | |
| 4071 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 4072 | continue; |
| 4073 | |
| 4074 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4075 | return 1; |
| 4076 | } |
| 4077 | |
| 4078 | return 0; |
| 4079 | } |
| 4080 | |
| 4081 | /* See breakpoint.h. */ |
| 4082 | |
| 4083 | int |
| 4084 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
| 4085 | CORE_ADDR pc) |
| 4086 | { |
| 4087 | struct bp_location **blp, **blp_tmp = NULL; |
| 4088 | |
| 4089 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4090 | { |
| 4091 | struct bp_location *bl = *blp; |
| 4092 | |
| 4093 | if (bl->loc_type != bp_loc_hardware_breakpoint) |
| 4094 | continue; |
| 4095 | |
| 4096 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4097 | return 1; |
| 4098 | } |
| 4099 | |
| 4100 | return 0; |
| 4101 | } |
| 4102 | |
| 4103 | int |
| 4104 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
| 4105 | CORE_ADDR addr, ULONGEST len) |
| 4106 | { |
| 4107 | struct breakpoint *bpt; |
| 4108 | |
| 4109 | ALL_BREAKPOINTS (bpt) |
| 4110 | { |
| 4111 | struct bp_location *loc; |
| 4112 | |
| 4113 | if (bpt->type != bp_hardware_watchpoint |
| 4114 | && bpt->type != bp_access_watchpoint) |
| 4115 | continue; |
| 4116 | |
| 4117 | if (!breakpoint_enabled (bpt)) |
| 4118 | continue; |
| 4119 | |
| 4120 | for (loc = bpt->loc; loc; loc = loc->next) |
| 4121 | if (loc->pspace->aspace == aspace && loc->inserted) |
| 4122 | { |
| 4123 | CORE_ADDR l, h; |
| 4124 | |
| 4125 | /* Check for intersection. */ |
| 4126 | l = std::max<CORE_ADDR> (loc->address, addr); |
| 4127 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); |
| 4128 | if (l < h) |
| 4129 | return 1; |
| 4130 | } |
| 4131 | } |
| 4132 | return 0; |
| 4133 | } |
| 4134 | |
| 4135 | /* See breakpoint.h. */ |
| 4136 | |
| 4137 | bool |
| 4138 | is_catchpoint (struct breakpoint *b) |
| 4139 | { |
| 4140 | return (b->type == bp_catchpoint); |
| 4141 | } |
| 4142 | |
| 4143 | /* Frees any storage that is part of a bpstat. Does not walk the |
| 4144 | 'next' chain. */ |
| 4145 | |
| 4146 | bpstats::~bpstats () |
| 4147 | { |
| 4148 | if (bp_location_at != NULL) |
| 4149 | decref_bp_location (&bp_location_at); |
| 4150 | } |
| 4151 | |
| 4152 | /* Clear a bpstat so that it says we are not at any breakpoint. |
| 4153 | Also free any storage that is part of a bpstat. */ |
| 4154 | |
| 4155 | void |
| 4156 | bpstat_clear (bpstat *bsp) |
| 4157 | { |
| 4158 | bpstat p; |
| 4159 | bpstat q; |
| 4160 | |
| 4161 | if (bsp == 0) |
| 4162 | return; |
| 4163 | p = *bsp; |
| 4164 | while (p != NULL) |
| 4165 | { |
| 4166 | q = p->next; |
| 4167 | delete p; |
| 4168 | p = q; |
| 4169 | } |
| 4170 | *bsp = NULL; |
| 4171 | } |
| 4172 | |
| 4173 | bpstats::bpstats (const bpstats &other) |
| 4174 | : next (NULL), |
| 4175 | bp_location_at (other.bp_location_at), |
| 4176 | breakpoint_at (other.breakpoint_at), |
| 4177 | commands (other.commands), |
| 4178 | print (other.print), |
| 4179 | stop (other.stop), |
| 4180 | print_it (other.print_it) |
| 4181 | { |
| 4182 | if (other.old_val != NULL) |
| 4183 | old_val = release_value (value_copy (other.old_val.get ())); |
| 4184 | incref_bp_location (bp_location_at); |
| 4185 | } |
| 4186 | |
| 4187 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
| 4188 | is part of the bpstat is copied as well. */ |
| 4189 | |
| 4190 | bpstat |
| 4191 | bpstat_copy (bpstat bs) |
| 4192 | { |
| 4193 | bpstat p = NULL; |
| 4194 | bpstat tmp; |
| 4195 | bpstat retval = NULL; |
| 4196 | |
| 4197 | if (bs == NULL) |
| 4198 | return bs; |
| 4199 | |
| 4200 | for (; bs != NULL; bs = bs->next) |
| 4201 | { |
| 4202 | tmp = new bpstats (*bs); |
| 4203 | |
| 4204 | if (p == NULL) |
| 4205 | /* This is the first thing in the chain. */ |
| 4206 | retval = tmp; |
| 4207 | else |
| 4208 | p->next = tmp; |
| 4209 | p = tmp; |
| 4210 | } |
| 4211 | p->next = NULL; |
| 4212 | return retval; |
| 4213 | } |
| 4214 | |
| 4215 | /* Find the bpstat associated with this breakpoint. */ |
| 4216 | |
| 4217 | bpstat |
| 4218 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
| 4219 | { |
| 4220 | if (bsp == NULL) |
| 4221 | return NULL; |
| 4222 | |
| 4223 | for (; bsp != NULL; bsp = bsp->next) |
| 4224 | { |
| 4225 | if (bsp->breakpoint_at == breakpoint) |
| 4226 | return bsp; |
| 4227 | } |
| 4228 | return NULL; |
| 4229 | } |
| 4230 | |
| 4231 | /* See breakpoint.h. */ |
| 4232 | |
| 4233 | bool |
| 4234 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
| 4235 | { |
| 4236 | for (; bsp != NULL; bsp = bsp->next) |
| 4237 | { |
| 4238 | if (bsp->breakpoint_at == NULL) |
| 4239 | { |
| 4240 | /* A moribund location can never explain a signal other than |
| 4241 | GDB_SIGNAL_TRAP. */ |
| 4242 | if (sig == GDB_SIGNAL_TRAP) |
| 4243 | return true; |
| 4244 | } |
| 4245 | else |
| 4246 | { |
| 4247 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, |
| 4248 | sig)) |
| 4249 | return true; |
| 4250 | } |
| 4251 | } |
| 4252 | |
| 4253 | return false; |
| 4254 | } |
| 4255 | |
| 4256 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
| 4257 | stopped at. *BSP upon return is a bpstat which points to the |
| 4258 | remaining breakpoints stopped at (but which is not guaranteed to be |
| 4259 | good for anything but further calls to bpstat_num). |
| 4260 | |
| 4261 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
| 4262 | Return -1 if stopped at a breakpoint that has been deleted since |
| 4263 | we set it. |
| 4264 | Return 1 otherwise. */ |
| 4265 | |
| 4266 | int |
| 4267 | bpstat_num (bpstat *bsp, int *num) |
| 4268 | { |
| 4269 | struct breakpoint *b; |
| 4270 | |
| 4271 | if ((*bsp) == NULL) |
| 4272 | return 0; /* No more breakpoint values */ |
| 4273 | |
| 4274 | /* We assume we'll never have several bpstats that correspond to a |
| 4275 | single breakpoint -- otherwise, this function might return the |
| 4276 | same number more than once and this will look ugly. */ |
| 4277 | b = (*bsp)->breakpoint_at; |
| 4278 | *bsp = (*bsp)->next; |
| 4279 | if (b == NULL) |
| 4280 | return -1; /* breakpoint that's been deleted since */ |
| 4281 | |
| 4282 | *num = b->number; /* We have its number */ |
| 4283 | return 1; |
| 4284 | } |
| 4285 | |
| 4286 | /* See breakpoint.h. */ |
| 4287 | |
| 4288 | void |
| 4289 | bpstat_clear_actions (void) |
| 4290 | { |
| 4291 | bpstat bs; |
| 4292 | |
| 4293 | if (inferior_ptid == null_ptid) |
| 4294 | return; |
| 4295 | |
| 4296 | thread_info *tp = inferior_thread (); |
| 4297 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
| 4298 | { |
| 4299 | bs->commands = NULL; |
| 4300 | bs->old_val.reset (nullptr); |
| 4301 | } |
| 4302 | } |
| 4303 | |
| 4304 | /* Called when a command is about to proceed the inferior. */ |
| 4305 | |
| 4306 | static void |
| 4307 | breakpoint_about_to_proceed (void) |
| 4308 | { |
| 4309 | if (inferior_ptid != null_ptid) |
| 4310 | { |
| 4311 | struct thread_info *tp = inferior_thread (); |
| 4312 | |
| 4313 | /* Allow inferior function calls in breakpoint commands to not |
| 4314 | interrupt the command list. When the call finishes |
| 4315 | successfully, the inferior will be standing at the same |
| 4316 | breakpoint as if nothing happened. */ |
| 4317 | if (tp->control.in_infcall) |
| 4318 | return; |
| 4319 | } |
| 4320 | |
| 4321 | breakpoint_proceeded = 1; |
| 4322 | } |
| 4323 | |
| 4324 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
| 4325 | or its equivalent. */ |
| 4326 | |
| 4327 | static int |
| 4328 | command_line_is_silent (struct command_line *cmd) |
| 4329 | { |
| 4330 | return cmd && (strcmp ("silent", cmd->line) == 0); |
| 4331 | } |
| 4332 | |
| 4333 | /* Execute all the commands associated with all the breakpoints at |
| 4334 | this location. Any of these commands could cause the process to |
| 4335 | proceed beyond this point, etc. We look out for such changes by |
| 4336 | checking the global "breakpoint_proceeded" after each command. |
| 4337 | |
| 4338 | Returns true if a breakpoint command resumed the inferior. In that |
| 4339 | case, it is the caller's responsibility to recall it again with the |
| 4340 | bpstat of the current thread. */ |
| 4341 | |
| 4342 | static int |
| 4343 | bpstat_do_actions_1 (bpstat *bsp) |
| 4344 | { |
| 4345 | bpstat bs; |
| 4346 | int again = 0; |
| 4347 | |
| 4348 | /* Avoid endless recursion if a `source' command is contained |
| 4349 | in bs->commands. */ |
| 4350 | if (executing_breakpoint_commands) |
| 4351 | return 0; |
| 4352 | |
| 4353 | scoped_restore save_executing |
| 4354 | = make_scoped_restore (&executing_breakpoint_commands, 1); |
| 4355 | |
| 4356 | scoped_restore preventer = prevent_dont_repeat (); |
| 4357 | |
| 4358 | /* This pointer will iterate over the list of bpstat's. */ |
| 4359 | bs = *bsp; |
| 4360 | |
| 4361 | breakpoint_proceeded = 0; |
| 4362 | for (; bs != NULL; bs = bs->next) |
| 4363 | { |
| 4364 | struct command_line *cmd = NULL; |
| 4365 | |
| 4366 | /* Take ownership of the BSP's command tree, if it has one. |
| 4367 | |
| 4368 | The command tree could legitimately contain commands like |
| 4369 | 'step' and 'next', which call clear_proceed_status, which |
| 4370 | frees stop_bpstat's command tree. To make sure this doesn't |
| 4371 | free the tree we're executing out from under us, we need to |
| 4372 | take ownership of the tree ourselves. Since a given bpstat's |
| 4373 | commands are only executed once, we don't need to copy it; we |
| 4374 | can clear the pointer in the bpstat, and make sure we free |
| 4375 | the tree when we're done. */ |
| 4376 | counted_command_line ccmd = bs->commands; |
| 4377 | bs->commands = NULL; |
| 4378 | if (ccmd != NULL) |
| 4379 | cmd = ccmd.get (); |
| 4380 | if (command_line_is_silent (cmd)) |
| 4381 | { |
| 4382 | /* The action has been already done by bpstat_stop_status. */ |
| 4383 | cmd = cmd->next; |
| 4384 | } |
| 4385 | |
| 4386 | while (cmd != NULL) |
| 4387 | { |
| 4388 | execute_control_command (cmd); |
| 4389 | |
| 4390 | if (breakpoint_proceeded) |
| 4391 | break; |
| 4392 | else |
| 4393 | cmd = cmd->next; |
| 4394 | } |
| 4395 | |
| 4396 | if (breakpoint_proceeded) |
| 4397 | { |
| 4398 | if (current_ui->async) |
| 4399 | /* If we are in async mode, then the target might be still |
| 4400 | running, not stopped at any breakpoint, so nothing for |
| 4401 | us to do here -- just return to the event loop. */ |
| 4402 | ; |
| 4403 | else |
| 4404 | /* In sync mode, when execute_control_command returns |
| 4405 | we're already standing on the next breakpoint. |
| 4406 | Breakpoint commands for that stop were not run, since |
| 4407 | execute_command does not run breakpoint commands -- |
| 4408 | only command_line_handler does, but that one is not |
| 4409 | involved in execution of breakpoint commands. So, we |
| 4410 | can now execute breakpoint commands. It should be |
| 4411 | noted that making execute_command do bpstat actions is |
| 4412 | not an option -- in this case we'll have recursive |
| 4413 | invocation of bpstat for each breakpoint with a |
| 4414 | command, and can easily blow up GDB stack. Instead, we |
| 4415 | return true, which will trigger the caller to recall us |
| 4416 | with the new stop_bpstat. */ |
| 4417 | again = 1; |
| 4418 | break; |
| 4419 | } |
| 4420 | } |
| 4421 | return again; |
| 4422 | } |
| 4423 | |
| 4424 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
| 4425 | one, is alive and has execution. Return NULL otherwise. */ |
| 4426 | |
| 4427 | static thread_info * |
| 4428 | get_bpstat_thread () |
| 4429 | { |
| 4430 | if (inferior_ptid == null_ptid || !target_has_execution) |
| 4431 | return NULL; |
| 4432 | |
| 4433 | thread_info *tp = inferior_thread (); |
| 4434 | if (tp->state == THREAD_EXITED || tp->executing) |
| 4435 | return NULL; |
| 4436 | return tp; |
| 4437 | } |
| 4438 | |
| 4439 | void |
| 4440 | bpstat_do_actions (void) |
| 4441 | { |
| 4442 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
| 4443 | thread_info *tp; |
| 4444 | |
| 4445 | /* Do any commands attached to breakpoint we are stopped at. */ |
| 4446 | while ((tp = get_bpstat_thread ()) != NULL) |
| 4447 | { |
| 4448 | /* Since in sync mode, bpstat_do_actions may resume the |
| 4449 | inferior, and only return when it is stopped at the next |
| 4450 | breakpoint, we keep doing breakpoint actions until it returns |
| 4451 | false to indicate the inferior was not resumed. */ |
| 4452 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) |
| 4453 | break; |
| 4454 | } |
| 4455 | |
| 4456 | cleanup_if_error.release (); |
| 4457 | } |
| 4458 | |
| 4459 | /* Print out the (old or new) value associated with a watchpoint. */ |
| 4460 | |
| 4461 | static void |
| 4462 | watchpoint_value_print (struct value *val, struct ui_file *stream) |
| 4463 | { |
| 4464 | if (val == NULL) |
| 4465 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
| 4466 | else |
| 4467 | { |
| 4468 | struct value_print_options opts; |
| 4469 | get_user_print_options (&opts); |
| 4470 | value_print (val, stream, &opts); |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
| 4475 | debugging multiple threads. */ |
| 4476 | |
| 4477 | void |
| 4478 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) |
| 4479 | { |
| 4480 | if (uiout->is_mi_like_p ()) |
| 4481 | return; |
| 4482 | |
| 4483 | uiout->text ("\n"); |
| 4484 | |
| 4485 | if (show_thread_that_caused_stop ()) |
| 4486 | { |
| 4487 | const char *name; |
| 4488 | struct thread_info *thr = inferior_thread (); |
| 4489 | |
| 4490 | uiout->text ("Thread "); |
| 4491 | uiout->field_string ("thread-id", print_thread_id (thr)); |
| 4492 | |
| 4493 | name = thr->name != NULL ? thr->name : target_thread_name (thr); |
| 4494 | if (name != NULL) |
| 4495 | { |
| 4496 | uiout->text (" \""); |
| 4497 | uiout->field_string ("name", name); |
| 4498 | uiout->text ("\""); |
| 4499 | } |
| 4500 | |
| 4501 | uiout->text (" hit "); |
| 4502 | } |
| 4503 | } |
| 4504 | |
| 4505 | /* Generic routine for printing messages indicating why we |
| 4506 | stopped. The behavior of this function depends on the value |
| 4507 | 'print_it' in the bpstat structure. Under some circumstances we |
| 4508 | may decide not to print anything here and delegate the task to |
| 4509 | normal_stop(). */ |
| 4510 | |
| 4511 | static enum print_stop_action |
| 4512 | print_bp_stop_message (bpstat bs) |
| 4513 | { |
| 4514 | switch (bs->print_it) |
| 4515 | { |
| 4516 | case print_it_noop: |
| 4517 | /* Nothing should be printed for this bpstat entry. */ |
| 4518 | return PRINT_UNKNOWN; |
| 4519 | break; |
| 4520 | |
| 4521 | case print_it_done: |
| 4522 | /* We still want to print the frame, but we already printed the |
| 4523 | relevant messages. */ |
| 4524 | return PRINT_SRC_AND_LOC; |
| 4525 | break; |
| 4526 | |
| 4527 | case print_it_normal: |
| 4528 | { |
| 4529 | struct breakpoint *b = bs->breakpoint_at; |
| 4530 | |
| 4531 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
| 4532 | which has since been deleted. */ |
| 4533 | if (b == NULL) |
| 4534 | return PRINT_UNKNOWN; |
| 4535 | |
| 4536 | /* Normal case. Call the breakpoint's print_it method. */ |
| 4537 | return b->ops->print_it (bs); |
| 4538 | } |
| 4539 | break; |
| 4540 | |
| 4541 | default: |
| 4542 | internal_error (__FILE__, __LINE__, |
| 4543 | _("print_bp_stop_message: unrecognized enum value")); |
| 4544 | break; |
| 4545 | } |
| 4546 | } |
| 4547 | |
| 4548 | /* A helper function that prints a shared library stopped event. */ |
| 4549 | |
| 4550 | static void |
| 4551 | print_solib_event (int is_catchpoint) |
| 4552 | { |
| 4553 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
| 4554 | bool any_added = !current_program_space->added_solibs.empty (); |
| 4555 | |
| 4556 | if (!is_catchpoint) |
| 4557 | { |
| 4558 | if (any_added || any_deleted) |
| 4559 | current_uiout->text (_("Stopped due to shared library event:\n")); |
| 4560 | else |
| 4561 | current_uiout->text (_("Stopped due to shared library event (no " |
| 4562 | "libraries added or removed)\n")); |
| 4563 | } |
| 4564 | |
| 4565 | if (current_uiout->is_mi_like_p ()) |
| 4566 | current_uiout->field_string ("reason", |
| 4567 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); |
| 4568 | |
| 4569 | if (any_deleted) |
| 4570 | { |
| 4571 | current_uiout->text (_(" Inferior unloaded ")); |
| 4572 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
| 4573 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
| 4574 | { |
| 4575 | const std::string &name = current_program_space->deleted_solibs[ix]; |
| 4576 | |
| 4577 | if (ix > 0) |
| 4578 | current_uiout->text (" "); |
| 4579 | current_uiout->field_string ("library", name); |
| 4580 | current_uiout->text ("\n"); |
| 4581 | } |
| 4582 | } |
| 4583 | |
| 4584 | if (any_added) |
| 4585 | { |
| 4586 | current_uiout->text (_(" Inferior loaded ")); |
| 4587 | ui_out_emit_list list_emitter (current_uiout, "added"); |
| 4588 | bool first = true; |
| 4589 | for (so_list *iter : current_program_space->added_solibs) |
| 4590 | { |
| 4591 | if (!first) |
| 4592 | current_uiout->text (" "); |
| 4593 | first = false; |
| 4594 | current_uiout->field_string ("library", iter->so_name); |
| 4595 | current_uiout->text ("\n"); |
| 4596 | } |
| 4597 | } |
| 4598 | } |
| 4599 | |
| 4600 | /* Print a message indicating what happened. This is called from |
| 4601 | normal_stop(). The input to this routine is the head of the bpstat |
| 4602 | list - a list of the eventpoints that caused this stop. KIND is |
| 4603 | the target_waitkind for the stopping event. This |
| 4604 | routine calls the generic print routine for printing a message |
| 4605 | about reasons for stopping. This will print (for example) the |
| 4606 | "Breakpoint n," part of the output. The return value of this |
| 4607 | routine is one of: |
| 4608 | |
| 4609 | PRINT_UNKNOWN: Means we printed nothing. |
| 4610 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
| 4611 | code to print the location. An example is |
| 4612 | "Breakpoint 1, " which should be followed by |
| 4613 | the location. |
| 4614 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
| 4615 | to also print the location part of the message. |
| 4616 | An example is the catch/throw messages, which |
| 4617 | don't require a location appended to the end. |
| 4618 | PRINT_NOTHING: We have done some printing and we don't need any |
| 4619 | further info to be printed. */ |
| 4620 | |
| 4621 | enum print_stop_action |
| 4622 | bpstat_print (bpstat bs, int kind) |
| 4623 | { |
| 4624 | enum print_stop_action val; |
| 4625 | |
| 4626 | /* Maybe another breakpoint in the chain caused us to stop. |
| 4627 | (Currently all watchpoints go on the bpstat whether hit or not. |
| 4628 | That probably could (should) be changed, provided care is taken |
| 4629 | with respect to bpstat_explains_signal). */ |
| 4630 | for (; bs; bs = bs->next) |
| 4631 | { |
| 4632 | val = print_bp_stop_message (bs); |
| 4633 | if (val == PRINT_SRC_ONLY |
| 4634 | || val == PRINT_SRC_AND_LOC |
| 4635 | || val == PRINT_NOTHING) |
| 4636 | return val; |
| 4637 | } |
| 4638 | |
| 4639 | /* If we had hit a shared library event breakpoint, |
| 4640 | print_bp_stop_message would print out this message. If we hit an |
| 4641 | OS-level shared library event, do the same thing. */ |
| 4642 | if (kind == TARGET_WAITKIND_LOADED) |
| 4643 | { |
| 4644 | print_solib_event (0); |
| 4645 | return PRINT_NOTHING; |
| 4646 | } |
| 4647 | |
| 4648 | /* We reached the end of the chain, or we got a null BS to start |
| 4649 | with and nothing was printed. */ |
| 4650 | return PRINT_UNKNOWN; |
| 4651 | } |
| 4652 | |
| 4653 | /* Evaluate the boolean expression EXP and return the result. */ |
| 4654 | |
| 4655 | static bool |
| 4656 | breakpoint_cond_eval (expression *exp) |
| 4657 | { |
| 4658 | struct value *mark = value_mark (); |
| 4659 | bool res = value_true (evaluate_expression (exp)); |
| 4660 | |
| 4661 | value_free_to_mark (mark); |
| 4662 | return res; |
| 4663 | } |
| 4664 | |
| 4665 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
| 4666 | |
| 4667 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
| 4668 | : next (NULL), |
| 4669 | bp_location_at (bl), |
| 4670 | breakpoint_at (bl->owner), |
| 4671 | commands (NULL), |
| 4672 | print (0), |
| 4673 | stop (0), |
| 4674 | print_it (print_it_normal) |
| 4675 | { |
| 4676 | incref_bp_location (bl); |
| 4677 | **bs_link_pointer = this; |
| 4678 | *bs_link_pointer = &next; |
| 4679 | } |
| 4680 | |
| 4681 | bpstats::bpstats () |
| 4682 | : next (NULL), |
| 4683 | bp_location_at (NULL), |
| 4684 | breakpoint_at (NULL), |
| 4685 | commands (NULL), |
| 4686 | print (0), |
| 4687 | stop (0), |
| 4688 | print_it (print_it_normal) |
| 4689 | { |
| 4690 | } |
| 4691 | \f |
| 4692 | /* The target has stopped with waitstatus WS. Check if any hardware |
| 4693 | watchpoints have triggered, according to the target. */ |
| 4694 | |
| 4695 | int |
| 4696 | watchpoints_triggered (struct target_waitstatus *ws) |
| 4697 | { |
| 4698 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
| 4699 | CORE_ADDR addr; |
| 4700 | struct breakpoint *b; |
| 4701 | |
| 4702 | if (!stopped_by_watchpoint) |
| 4703 | { |
| 4704 | /* We were not stopped by a watchpoint. Mark all watchpoints |
| 4705 | as not triggered. */ |
| 4706 | ALL_BREAKPOINTS (b) |
| 4707 | if (is_hardware_watchpoint (b)) |
| 4708 | { |
| 4709 | struct watchpoint *w = (struct watchpoint *) b; |
| 4710 | |
| 4711 | w->watchpoint_triggered = watch_triggered_no; |
| 4712 | } |
| 4713 | |
| 4714 | return 0; |
| 4715 | } |
| 4716 | |
| 4717 | if (!target_stopped_data_address (current_top_target (), &addr)) |
| 4718 | { |
| 4719 | /* We were stopped by a watchpoint, but we don't know where. |
| 4720 | Mark all watchpoints as unknown. */ |
| 4721 | ALL_BREAKPOINTS (b) |
| 4722 | if (is_hardware_watchpoint (b)) |
| 4723 | { |
| 4724 | struct watchpoint *w = (struct watchpoint *) b; |
| 4725 | |
| 4726 | w->watchpoint_triggered = watch_triggered_unknown; |
| 4727 | } |
| 4728 | |
| 4729 | return 1; |
| 4730 | } |
| 4731 | |
| 4732 | /* The target could report the data address. Mark watchpoints |
| 4733 | affected by this data address as triggered, and all others as not |
| 4734 | triggered. */ |
| 4735 | |
| 4736 | ALL_BREAKPOINTS (b) |
| 4737 | if (is_hardware_watchpoint (b)) |
| 4738 | { |
| 4739 | struct watchpoint *w = (struct watchpoint *) b; |
| 4740 | struct bp_location *loc; |
| 4741 | |
| 4742 | w->watchpoint_triggered = watch_triggered_no; |
| 4743 | for (loc = b->loc; loc; loc = loc->next) |
| 4744 | { |
| 4745 | if (is_masked_watchpoint (b)) |
| 4746 | { |
| 4747 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
| 4748 | CORE_ADDR start = loc->address & w->hw_wp_mask; |
| 4749 | |
| 4750 | if (newaddr == start) |
| 4751 | { |
| 4752 | w->watchpoint_triggered = watch_triggered_yes; |
| 4753 | break; |
| 4754 | } |
| 4755 | } |
| 4756 | /* Exact match not required. Within range is sufficient. */ |
| 4757 | else if (target_watchpoint_addr_within_range (current_top_target (), |
| 4758 | addr, loc->address, |
| 4759 | loc->length)) |
| 4760 | { |
| 4761 | w->watchpoint_triggered = watch_triggered_yes; |
| 4762 | break; |
| 4763 | } |
| 4764 | } |
| 4765 | } |
| 4766 | |
| 4767 | return 1; |
| 4768 | } |
| 4769 | |
| 4770 | /* Possible return values for watchpoint_check. */ |
| 4771 | enum wp_check_result |
| 4772 | { |
| 4773 | /* The watchpoint has been deleted. */ |
| 4774 | WP_DELETED = 1, |
| 4775 | |
| 4776 | /* The value has changed. */ |
| 4777 | WP_VALUE_CHANGED = 2, |
| 4778 | |
| 4779 | /* The value has not changed. */ |
| 4780 | WP_VALUE_NOT_CHANGED = 3, |
| 4781 | |
| 4782 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
| 4783 | WP_IGNORE = 4, |
| 4784 | }; |
| 4785 | |
| 4786 | #define BP_TEMPFLAG 1 |
| 4787 | #define BP_HARDWAREFLAG 2 |
| 4788 | |
| 4789 | /* Evaluate watchpoint condition expression and check if its value |
| 4790 | changed. */ |
| 4791 | |
| 4792 | static wp_check_result |
| 4793 | watchpoint_check (bpstat bs) |
| 4794 | { |
| 4795 | struct watchpoint *b; |
| 4796 | struct frame_info *fr; |
| 4797 | int within_current_scope; |
| 4798 | |
| 4799 | /* BS is built from an existing struct breakpoint. */ |
| 4800 | gdb_assert (bs->breakpoint_at != NULL); |
| 4801 | b = (struct watchpoint *) bs->breakpoint_at; |
| 4802 | |
| 4803 | /* If this is a local watchpoint, we only want to check if the |
| 4804 | watchpoint frame is in scope if the current thread is the thread |
| 4805 | that was used to create the watchpoint. */ |
| 4806 | if (!watchpoint_in_thread_scope (b)) |
| 4807 | return WP_IGNORE; |
| 4808 | |
| 4809 | if (b->exp_valid_block == NULL) |
| 4810 | within_current_scope = 1; |
| 4811 | else |
| 4812 | { |
| 4813 | struct frame_info *frame = get_current_frame (); |
| 4814 | struct gdbarch *frame_arch = get_frame_arch (frame); |
| 4815 | CORE_ADDR frame_pc = get_frame_pc (frame); |
| 4816 | |
| 4817 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
| 4818 | still in the function but the stack frame has already been |
| 4819 | invalidated. Since we can't rely on the values of local |
| 4820 | variables after the stack has been destroyed, we are treating |
| 4821 | the watchpoint in that state as `not changed' without further |
| 4822 | checking. Don't mark watchpoints as changed if the current |
| 4823 | frame is in an epilogue - even if they are in some other |
| 4824 | frame, our view of the stack is likely to be wrong and |
| 4825 | frame_find_by_id could error out. */ |
| 4826 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
| 4827 | return WP_IGNORE; |
| 4828 | |
| 4829 | fr = frame_find_by_id (b->watchpoint_frame); |
| 4830 | within_current_scope = (fr != NULL); |
| 4831 | |
| 4832 | /* If we've gotten confused in the unwinder, we might have |
| 4833 | returned a frame that can't describe this variable. */ |
| 4834 | if (within_current_scope) |
| 4835 | { |
| 4836 | struct symbol *function; |
| 4837 | |
| 4838 | function = get_frame_function (fr); |
| 4839 | if (function == NULL |
| 4840 | || !contained_in (b->exp_valid_block, |
| 4841 | SYMBOL_BLOCK_VALUE (function))) |
| 4842 | within_current_scope = 0; |
| 4843 | } |
| 4844 | |
| 4845 | if (within_current_scope) |
| 4846 | /* If we end up stopping, the current frame will get selected |
| 4847 | in normal_stop. So this call to select_frame won't affect |
| 4848 | the user. */ |
| 4849 | select_frame (fr); |
| 4850 | } |
| 4851 | |
| 4852 | if (within_current_scope) |
| 4853 | { |
| 4854 | /* We use value_{,free_to_}mark because it could be a *long* |
| 4855 | time before we return to the command level and call |
| 4856 | free_all_values. We can't call free_all_values because we |
| 4857 | might be in the middle of evaluating a function call. */ |
| 4858 | |
| 4859 | int pc = 0; |
| 4860 | struct value *mark; |
| 4861 | struct value *new_val; |
| 4862 | |
| 4863 | if (is_masked_watchpoint (b)) |
| 4864 | /* Since we don't know the exact trigger address (from |
| 4865 | stopped_data_address), just tell the user we've triggered |
| 4866 | a mask watchpoint. */ |
| 4867 | return WP_VALUE_CHANGED; |
| 4868 | |
| 4869 | mark = value_mark (); |
| 4870 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
| 4871 | |
| 4872 | if (b->val_bitsize != 0) |
| 4873 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); |
| 4874 | |
| 4875 | /* We use value_equal_contents instead of value_equal because |
| 4876 | the latter coerces an array to a pointer, thus comparing just |
| 4877 | the address of the array instead of its contents. This is |
| 4878 | not what we want. */ |
| 4879 | if ((b->val != NULL) != (new_val != NULL) |
| 4880 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
| 4881 | new_val))) |
| 4882 | { |
| 4883 | bs->old_val = b->val; |
| 4884 | b->val = release_value (new_val); |
| 4885 | b->val_valid = true; |
| 4886 | if (new_val != NULL) |
| 4887 | value_free_to_mark (mark); |
| 4888 | return WP_VALUE_CHANGED; |
| 4889 | } |
| 4890 | else |
| 4891 | { |
| 4892 | /* Nothing changed. */ |
| 4893 | value_free_to_mark (mark); |
| 4894 | return WP_VALUE_NOT_CHANGED; |
| 4895 | } |
| 4896 | } |
| 4897 | else |
| 4898 | { |
| 4899 | /* This seems like the only logical thing to do because |
| 4900 | if we temporarily ignored the watchpoint, then when |
| 4901 | we reenter the block in which it is valid it contains |
| 4902 | garbage (in the case of a function, it may have two |
| 4903 | garbage values, one before and one after the prologue). |
| 4904 | So we can't even detect the first assignment to it and |
| 4905 | watch after that (since the garbage may or may not equal |
| 4906 | the first value assigned). */ |
| 4907 | /* We print all the stop information in |
| 4908 | breakpoint_ops->print_it, but in this case, by the time we |
| 4909 | call breakpoint_ops->print_it this bp will be deleted |
| 4910 | already. So we have no choice but print the information |
| 4911 | here. */ |
| 4912 | |
| 4913 | SWITCH_THRU_ALL_UIS () |
| 4914 | { |
| 4915 | struct ui_out *uiout = current_uiout; |
| 4916 | |
| 4917 | if (uiout->is_mi_like_p ()) |
| 4918 | uiout->field_string |
| 4919 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); |
| 4920 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
| 4921 | "left the block in\n" |
| 4922 | "which its expression is valid.\n", |
| 4923 | signed_field ("wpnum", b->number)); |
| 4924 | } |
| 4925 | |
| 4926 | /* Make sure the watchpoint's commands aren't executed. */ |
| 4927 | b->commands = NULL; |
| 4928 | watchpoint_del_at_next_stop (b); |
| 4929 | |
| 4930 | return WP_DELETED; |
| 4931 | } |
| 4932 | } |
| 4933 | |
| 4934 | /* Return true if it looks like target has stopped due to hitting |
| 4935 | breakpoint location BL. This function does not check if we should |
| 4936 | stop, only if BL explains the stop. */ |
| 4937 | |
| 4938 | static int |
| 4939 | bpstat_check_location (const struct bp_location *bl, |
| 4940 | const address_space *aspace, CORE_ADDR bp_addr, |
| 4941 | const struct target_waitstatus *ws) |
| 4942 | { |
| 4943 | struct breakpoint *b = bl->owner; |
| 4944 | |
| 4945 | /* BL is from an existing breakpoint. */ |
| 4946 | gdb_assert (b != NULL); |
| 4947 | |
| 4948 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
| 4949 | } |
| 4950 | |
| 4951 | /* Determine if the watched values have actually changed, and we |
| 4952 | should stop. If not, set BS->stop to 0. */ |
| 4953 | |
| 4954 | static void |
| 4955 | bpstat_check_watchpoint (bpstat bs) |
| 4956 | { |
| 4957 | const struct bp_location *bl; |
| 4958 | struct watchpoint *b; |
| 4959 | |
| 4960 | /* BS is built for existing struct breakpoint. */ |
| 4961 | bl = bs->bp_location_at; |
| 4962 | gdb_assert (bl != NULL); |
| 4963 | b = (struct watchpoint *) bs->breakpoint_at; |
| 4964 | gdb_assert (b != NULL); |
| 4965 | |
| 4966 | { |
| 4967 | int must_check_value = 0; |
| 4968 | |
| 4969 | if (b->type == bp_watchpoint) |
| 4970 | /* For a software watchpoint, we must always check the |
| 4971 | watched value. */ |
| 4972 | must_check_value = 1; |
| 4973 | else if (b->watchpoint_triggered == watch_triggered_yes) |
| 4974 | /* We have a hardware watchpoint (read, write, or access) |
| 4975 | and the target earlier reported an address watched by |
| 4976 | this watchpoint. */ |
| 4977 | must_check_value = 1; |
| 4978 | else if (b->watchpoint_triggered == watch_triggered_unknown |
| 4979 | && b->type == bp_hardware_watchpoint) |
| 4980 | /* We were stopped by a hardware watchpoint, but the target could |
| 4981 | not report the data address. We must check the watchpoint's |
| 4982 | value. Access and read watchpoints are out of luck; without |
| 4983 | a data address, we can't figure it out. */ |
| 4984 | must_check_value = 1; |
| 4985 | |
| 4986 | if (must_check_value) |
| 4987 | { |
| 4988 | wp_check_result e; |
| 4989 | |
| 4990 | try |
| 4991 | { |
| 4992 | e = watchpoint_check (bs); |
| 4993 | } |
| 4994 | catch (const gdb_exception &ex) |
| 4995 | { |
| 4996 | exception_fprintf (gdb_stderr, ex, |
| 4997 | "Error evaluating expression " |
| 4998 | "for watchpoint %d\n", |
| 4999 | b->number); |
| 5000 | |
| 5001 | SWITCH_THRU_ALL_UIS () |
| 5002 | { |
| 5003 | printf_filtered (_("Watchpoint %d deleted.\n"), |
| 5004 | b->number); |
| 5005 | } |
| 5006 | watchpoint_del_at_next_stop (b); |
| 5007 | e = WP_DELETED; |
| 5008 | } |
| 5009 | |
| 5010 | switch (e) |
| 5011 | { |
| 5012 | case WP_DELETED: |
| 5013 | /* We've already printed what needs to be printed. */ |
| 5014 | bs->print_it = print_it_done; |
| 5015 | /* Stop. */ |
| 5016 | break; |
| 5017 | case WP_IGNORE: |
| 5018 | bs->print_it = print_it_noop; |
| 5019 | bs->stop = 0; |
| 5020 | break; |
| 5021 | case WP_VALUE_CHANGED: |
| 5022 | if (b->type == bp_read_watchpoint) |
| 5023 | { |
| 5024 | /* There are two cases to consider here: |
| 5025 | |
| 5026 | 1. We're watching the triggered memory for reads. |
| 5027 | In that case, trust the target, and always report |
| 5028 | the watchpoint hit to the user. Even though |
| 5029 | reads don't cause value changes, the value may |
| 5030 | have changed since the last time it was read, and |
| 5031 | since we're not trapping writes, we will not see |
| 5032 | those, and as such we should ignore our notion of |
| 5033 | old value. |
| 5034 | |
| 5035 | 2. We're watching the triggered memory for both |
| 5036 | reads and writes. There are two ways this may |
| 5037 | happen: |
| 5038 | |
| 5039 | 2.1. This is a target that can't break on data |
| 5040 | reads only, but can break on accesses (reads or |
| 5041 | writes), such as e.g., x86. We detect this case |
| 5042 | at the time we try to insert read watchpoints. |
| 5043 | |
| 5044 | 2.2. Otherwise, the target supports read |
| 5045 | watchpoints, but, the user set an access or write |
| 5046 | watchpoint watching the same memory as this read |
| 5047 | watchpoint. |
| 5048 | |
| 5049 | If we're watching memory writes as well as reads, |
| 5050 | ignore watchpoint hits when we find that the |
| 5051 | value hasn't changed, as reads don't cause |
| 5052 | changes. This still gives false positives when |
| 5053 | the program writes the same value to memory as |
| 5054 | what there was already in memory (we will confuse |
| 5055 | it for a read), but it's much better than |
| 5056 | nothing. */ |
| 5057 | |
| 5058 | int other_write_watchpoint = 0; |
| 5059 | |
| 5060 | if (bl->watchpoint_type == hw_read) |
| 5061 | { |
| 5062 | struct breakpoint *other_b; |
| 5063 | |
| 5064 | ALL_BREAKPOINTS (other_b) |
| 5065 | if (other_b->type == bp_hardware_watchpoint |
| 5066 | || other_b->type == bp_access_watchpoint) |
| 5067 | { |
| 5068 | struct watchpoint *other_w = |
| 5069 | (struct watchpoint *) other_b; |
| 5070 | |
| 5071 | if (other_w->watchpoint_triggered |
| 5072 | == watch_triggered_yes) |
| 5073 | { |
| 5074 | other_write_watchpoint = 1; |
| 5075 | break; |
| 5076 | } |
| 5077 | } |
| 5078 | } |
| 5079 | |
| 5080 | if (other_write_watchpoint |
| 5081 | || bl->watchpoint_type == hw_access) |
| 5082 | { |
| 5083 | /* We're watching the same memory for writes, |
| 5084 | and the value changed since the last time we |
| 5085 | updated it, so this trap must be for a write. |
| 5086 | Ignore it. */ |
| 5087 | bs->print_it = print_it_noop; |
| 5088 | bs->stop = 0; |
| 5089 | } |
| 5090 | } |
| 5091 | break; |
| 5092 | case WP_VALUE_NOT_CHANGED: |
| 5093 | if (b->type == bp_hardware_watchpoint |
| 5094 | || b->type == bp_watchpoint) |
| 5095 | { |
| 5096 | /* Don't stop: write watchpoints shouldn't fire if |
| 5097 | the value hasn't changed. */ |
| 5098 | bs->print_it = print_it_noop; |
| 5099 | bs->stop = 0; |
| 5100 | } |
| 5101 | /* Stop. */ |
| 5102 | break; |
| 5103 | default: |
| 5104 | /* Can't happen. */ |
| 5105 | break; |
| 5106 | } |
| 5107 | } |
| 5108 | else /* must_check_value == 0 */ |
| 5109 | { |
| 5110 | /* This is a case where some watchpoint(s) triggered, but |
| 5111 | not at the address of this watchpoint, or else no |
| 5112 | watchpoint triggered after all. So don't print |
| 5113 | anything for this watchpoint. */ |
| 5114 | bs->print_it = print_it_noop; |
| 5115 | bs->stop = 0; |
| 5116 | } |
| 5117 | } |
| 5118 | } |
| 5119 | |
| 5120 | /* For breakpoints that are currently marked as telling gdb to stop, |
| 5121 | check conditions (condition proper, frame, thread and ignore count) |
| 5122 | of breakpoint referred to by BS. If we should not stop for this |
| 5123 | breakpoint, set BS->stop to 0. */ |
| 5124 | |
| 5125 | static void |
| 5126 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
| 5127 | { |
| 5128 | const struct bp_location *bl; |
| 5129 | struct breakpoint *b; |
| 5130 | /* Assume stop. */ |
| 5131 | bool condition_result = true; |
| 5132 | struct expression *cond; |
| 5133 | |
| 5134 | gdb_assert (bs->stop); |
| 5135 | |
| 5136 | /* BS is built for existing struct breakpoint. */ |
| 5137 | bl = bs->bp_location_at; |
| 5138 | gdb_assert (bl != NULL); |
| 5139 | b = bs->breakpoint_at; |
| 5140 | gdb_assert (b != NULL); |
| 5141 | |
| 5142 | /* Even if the target evaluated the condition on its end and notified GDB, we |
| 5143 | need to do so again since GDB does not know if we stopped due to a |
| 5144 | breakpoint or a single step breakpoint. */ |
| 5145 | |
| 5146 | if (frame_id_p (b->frame_id) |
| 5147 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
| 5148 | { |
| 5149 | bs->stop = 0; |
| 5150 | return; |
| 5151 | } |
| 5152 | |
| 5153 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
| 5154 | evaluating the condition if this isn't the specified |
| 5155 | thread/task. */ |
| 5156 | if ((b->thread != -1 && b->thread != thread->global_num) |
| 5157 | || (b->task != 0 && b->task != ada_get_task_number (thread))) |
| 5158 | { |
| 5159 | bs->stop = 0; |
| 5160 | return; |
| 5161 | } |
| 5162 | |
| 5163 | /* Evaluate extension language breakpoints that have a "stop" method |
| 5164 | implemented. */ |
| 5165 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); |
| 5166 | |
| 5167 | if (is_watchpoint (b)) |
| 5168 | { |
| 5169 | struct watchpoint *w = (struct watchpoint *) b; |
| 5170 | |
| 5171 | cond = w->cond_exp.get (); |
| 5172 | } |
| 5173 | else |
| 5174 | cond = bl->cond.get (); |
| 5175 | |
| 5176 | if (cond && b->disposition != disp_del_at_next_stop) |
| 5177 | { |
| 5178 | int within_current_scope = 1; |
| 5179 | struct watchpoint * w; |
| 5180 | |
| 5181 | /* We use value_mark and value_free_to_mark because it could |
| 5182 | be a long time before we return to the command level and |
| 5183 | call free_all_values. We can't call free_all_values |
| 5184 | because we might be in the middle of evaluating a |
| 5185 | function call. */ |
| 5186 | struct value *mark = value_mark (); |
| 5187 | |
| 5188 | if (is_watchpoint (b)) |
| 5189 | w = (struct watchpoint *) b; |
| 5190 | else |
| 5191 | w = NULL; |
| 5192 | |
| 5193 | /* Need to select the frame, with all that implies so that |
| 5194 | the conditions will have the right context. Because we |
| 5195 | use the frame, we will not see an inlined function's |
| 5196 | variables when we arrive at a breakpoint at the start |
| 5197 | of the inlined function; the current frame will be the |
| 5198 | call site. */ |
| 5199 | if (w == NULL || w->cond_exp_valid_block == NULL) |
| 5200 | select_frame (get_current_frame ()); |
| 5201 | else |
| 5202 | { |
| 5203 | struct frame_info *frame; |
| 5204 | |
| 5205 | /* For local watchpoint expressions, which particular |
| 5206 | instance of a local is being watched matters, so we |
| 5207 | keep track of the frame to evaluate the expression |
| 5208 | in. To evaluate the condition however, it doesn't |
| 5209 | really matter which instantiation of the function |
| 5210 | where the condition makes sense triggers the |
| 5211 | watchpoint. This allows an expression like "watch |
| 5212 | global if q > 10" set in `func', catch writes to |
| 5213 | global on all threads that call `func', or catch |
| 5214 | writes on all recursive calls of `func' by a single |
| 5215 | thread. We simply always evaluate the condition in |
| 5216 | the innermost frame that's executing where it makes |
| 5217 | sense to evaluate the condition. It seems |
| 5218 | intuitive. */ |
| 5219 | frame = block_innermost_frame (w->cond_exp_valid_block); |
| 5220 | if (frame != NULL) |
| 5221 | select_frame (frame); |
| 5222 | else |
| 5223 | within_current_scope = 0; |
| 5224 | } |
| 5225 | if (within_current_scope) |
| 5226 | { |
| 5227 | try |
| 5228 | { |
| 5229 | condition_result = breakpoint_cond_eval (cond); |
| 5230 | } |
| 5231 | catch (const gdb_exception &ex) |
| 5232 | { |
| 5233 | exception_fprintf (gdb_stderr, ex, |
| 5234 | "Error in testing breakpoint condition:\n"); |
| 5235 | } |
| 5236 | } |
| 5237 | else |
| 5238 | { |
| 5239 | warning (_("Watchpoint condition cannot be tested " |
| 5240 | "in the current scope")); |
| 5241 | /* If we failed to set the right context for this |
| 5242 | watchpoint, unconditionally report it. */ |
| 5243 | } |
| 5244 | /* FIXME-someday, should give breakpoint #. */ |
| 5245 | value_free_to_mark (mark); |
| 5246 | } |
| 5247 | |
| 5248 | if (cond && !condition_result) |
| 5249 | { |
| 5250 | bs->stop = 0; |
| 5251 | } |
| 5252 | else if (b->ignore_count > 0) |
| 5253 | { |
| 5254 | b->ignore_count--; |
| 5255 | bs->stop = 0; |
| 5256 | /* Increase the hit count even though we don't stop. */ |
| 5257 | ++(b->hit_count); |
| 5258 | gdb::observers::breakpoint_modified.notify (b); |
| 5259 | } |
| 5260 | } |
| 5261 | |
| 5262 | /* Returns true if we need to track moribund locations of LOC's type |
| 5263 | on the current target. */ |
| 5264 | |
| 5265 | static int |
| 5266 | need_moribund_for_location_type (struct bp_location *loc) |
| 5267 | { |
| 5268 | return ((loc->loc_type == bp_loc_software_breakpoint |
| 5269 | && !target_supports_stopped_by_sw_breakpoint ()) |
| 5270 | || (loc->loc_type == bp_loc_hardware_breakpoint |
| 5271 | && !target_supports_stopped_by_hw_breakpoint ())); |
| 5272 | } |
| 5273 | |
| 5274 | /* See breakpoint.h. */ |
| 5275 | |
| 5276 | bpstat |
| 5277 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
| 5278 | const struct target_waitstatus *ws) |
| 5279 | { |
| 5280 | struct breakpoint *b; |
| 5281 | bpstat bs_head = NULL, *bs_link = &bs_head; |
| 5282 | |
| 5283 | ALL_BREAKPOINTS (b) |
| 5284 | { |
| 5285 | if (!breakpoint_enabled (b)) |
| 5286 | continue; |
| 5287 | |
| 5288 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
| 5289 | { |
| 5290 | /* For hardware watchpoints, we look only at the first |
| 5291 | location. The watchpoint_check function will work on the |
| 5292 | entire expression, not the individual locations. For |
| 5293 | read watchpoints, the watchpoints_triggered function has |
| 5294 | checked all locations already. */ |
| 5295 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
| 5296 | break; |
| 5297 | |
| 5298 | if (!bl->enabled || bl->shlib_disabled) |
| 5299 | continue; |
| 5300 | |
| 5301 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
| 5302 | continue; |
| 5303 | |
| 5304 | /* Come here if it's a watchpoint, or if the break address |
| 5305 | matches. */ |
| 5306 | |
| 5307 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
| 5308 | explain stop. */ |
| 5309 | |
| 5310 | /* Assume we stop. Should we find a watchpoint that is not |
| 5311 | actually triggered, or if the condition of the breakpoint |
| 5312 | evaluates as false, we'll reset 'stop' to 0. */ |
| 5313 | bs->stop = 1; |
| 5314 | bs->print = 1; |
| 5315 | |
| 5316 | /* If this is a scope breakpoint, mark the associated |
| 5317 | watchpoint as triggered so that we will handle the |
| 5318 | out-of-scope event. We'll get to the watchpoint next |
| 5319 | iteration. */ |
| 5320 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
| 5321 | { |
| 5322 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; |
| 5323 | |
| 5324 | w->watchpoint_triggered = watch_triggered_yes; |
| 5325 | } |
| 5326 | } |
| 5327 | } |
| 5328 | |
| 5329 | /* Check if a moribund breakpoint explains the stop. */ |
| 5330 | if (!target_supports_stopped_by_sw_breakpoint () |
| 5331 | || !target_supports_stopped_by_hw_breakpoint ()) |
| 5332 | { |
| 5333 | for (bp_location *loc : moribund_locations) |
| 5334 | { |
| 5335 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
| 5336 | && need_moribund_for_location_type (loc)) |
| 5337 | { |
| 5338 | bpstat bs = new bpstats (loc, &bs_link); |
| 5339 | /* For hits of moribund locations, we should just proceed. */ |
| 5340 | bs->stop = 0; |
| 5341 | bs->print = 0; |
| 5342 | bs->print_it = print_it_noop; |
| 5343 | } |
| 5344 | } |
| 5345 | } |
| 5346 | |
| 5347 | return bs_head; |
| 5348 | } |
| 5349 | |
| 5350 | /* See breakpoint.h. */ |
| 5351 | |
| 5352 | bpstat |
| 5353 | bpstat_stop_status (const address_space *aspace, |
| 5354 | CORE_ADDR bp_addr, thread_info *thread, |
| 5355 | const struct target_waitstatus *ws, |
| 5356 | bpstat stop_chain) |
| 5357 | { |
| 5358 | struct breakpoint *b = NULL; |
| 5359 | /* First item of allocated bpstat's. */ |
| 5360 | bpstat bs_head = stop_chain; |
| 5361 | bpstat bs; |
| 5362 | int need_remove_insert; |
| 5363 | int removed_any; |
| 5364 | |
| 5365 | /* First, build the bpstat chain with locations that explain a |
| 5366 | target stop, while being careful to not set the target running, |
| 5367 | as that may invalidate locations (in particular watchpoint |
| 5368 | locations are recreated). Resuming will happen here with |
| 5369 | breakpoint conditions or watchpoint expressions that include |
| 5370 | inferior function calls. */ |
| 5371 | if (bs_head == NULL) |
| 5372 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); |
| 5373 | |
| 5374 | /* A bit of special processing for shlib breakpoints. We need to |
| 5375 | process solib loading here, so that the lists of loaded and |
| 5376 | unloaded libraries are correct before we handle "catch load" and |
| 5377 | "catch unload". */ |
| 5378 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5379 | { |
| 5380 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
| 5381 | { |
| 5382 | handle_solib_event (); |
| 5383 | break; |
| 5384 | } |
| 5385 | } |
| 5386 | |
| 5387 | /* Now go through the locations that caused the target to stop, and |
| 5388 | check whether we're interested in reporting this stop to higher |
| 5389 | layers, or whether we should resume the target transparently. */ |
| 5390 | |
| 5391 | removed_any = 0; |
| 5392 | |
| 5393 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5394 | { |
| 5395 | if (!bs->stop) |
| 5396 | continue; |
| 5397 | |
| 5398 | b = bs->breakpoint_at; |
| 5399 | b->ops->check_status (bs); |
| 5400 | if (bs->stop) |
| 5401 | { |
| 5402 | bpstat_check_breakpoint_conditions (bs, thread); |
| 5403 | |
| 5404 | if (bs->stop) |
| 5405 | { |
| 5406 | ++(b->hit_count); |
| 5407 | gdb::observers::breakpoint_modified.notify (b); |
| 5408 | |
| 5409 | /* We will stop here. */ |
| 5410 | if (b->disposition == disp_disable) |
| 5411 | { |
| 5412 | --(b->enable_count); |
| 5413 | if (b->enable_count <= 0) |
| 5414 | b->enable_state = bp_disabled; |
| 5415 | removed_any = 1; |
| 5416 | } |
| 5417 | if (b->silent) |
| 5418 | bs->print = 0; |
| 5419 | bs->commands = b->commands; |
| 5420 | if (command_line_is_silent (bs->commands |
| 5421 | ? bs->commands.get () : NULL)) |
| 5422 | bs->print = 0; |
| 5423 | |
| 5424 | b->ops->after_condition_true (bs); |
| 5425 | } |
| 5426 | |
| 5427 | } |
| 5428 | |
| 5429 | /* Print nothing for this entry if we don't stop or don't |
| 5430 | print. */ |
| 5431 | if (!bs->stop || !bs->print) |
| 5432 | bs->print_it = print_it_noop; |
| 5433 | } |
| 5434 | |
| 5435 | /* If we aren't stopping, the value of some hardware watchpoint may |
| 5436 | not have changed, but the intermediate memory locations we are |
| 5437 | watching may have. Don't bother if we're stopping; this will get |
| 5438 | done later. */ |
| 5439 | need_remove_insert = 0; |
| 5440 | if (! bpstat_causes_stop (bs_head)) |
| 5441 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5442 | if (!bs->stop |
| 5443 | && bs->breakpoint_at |
| 5444 | && is_hardware_watchpoint (bs->breakpoint_at)) |
| 5445 | { |
| 5446 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
| 5447 | |
| 5448 | update_watchpoint (w, 0 /* don't reparse. */); |
| 5449 | need_remove_insert = 1; |
| 5450 | } |
| 5451 | |
| 5452 | if (need_remove_insert) |
| 5453 | update_global_location_list (UGLL_MAY_INSERT); |
| 5454 | else if (removed_any) |
| 5455 | update_global_location_list (UGLL_DONT_INSERT); |
| 5456 | |
| 5457 | return bs_head; |
| 5458 | } |
| 5459 | |
| 5460 | static void |
| 5461 | handle_jit_event (void) |
| 5462 | { |
| 5463 | struct frame_info *frame; |
| 5464 | struct gdbarch *gdbarch; |
| 5465 | |
| 5466 | if (debug_infrun) |
| 5467 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); |
| 5468 | |
| 5469 | /* Switch terminal for any messages produced by |
| 5470 | breakpoint_re_set. */ |
| 5471 | target_terminal::ours_for_output (); |
| 5472 | |
| 5473 | frame = get_current_frame (); |
| 5474 | gdbarch = get_frame_arch (frame); |
| 5475 | |
| 5476 | jit_event_handler (gdbarch); |
| 5477 | |
| 5478 | target_terminal::inferior (); |
| 5479 | } |
| 5480 | |
| 5481 | /* Prepare WHAT final decision for infrun. */ |
| 5482 | |
| 5483 | /* Decide what infrun needs to do with this bpstat. */ |
| 5484 | |
| 5485 | struct bpstat_what |
| 5486 | bpstat_what (bpstat bs_head) |
| 5487 | { |
| 5488 | struct bpstat_what retval; |
| 5489 | bpstat bs; |
| 5490 | |
| 5491 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5492 | retval.call_dummy = STOP_NONE; |
| 5493 | retval.is_longjmp = false; |
| 5494 | |
| 5495 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5496 | { |
| 5497 | /* Extract this BS's action. After processing each BS, we check |
| 5498 | if its action overrides all we've seem so far. */ |
| 5499 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5500 | enum bptype bptype; |
| 5501 | |
| 5502 | if (bs->breakpoint_at == NULL) |
| 5503 | { |
| 5504 | /* I suspect this can happen if it was a momentary |
| 5505 | breakpoint which has since been deleted. */ |
| 5506 | bptype = bp_none; |
| 5507 | } |
| 5508 | else |
| 5509 | bptype = bs->breakpoint_at->type; |
| 5510 | |
| 5511 | switch (bptype) |
| 5512 | { |
| 5513 | case bp_none: |
| 5514 | break; |
| 5515 | case bp_breakpoint: |
| 5516 | case bp_hardware_breakpoint: |
| 5517 | case bp_single_step: |
| 5518 | case bp_until: |
| 5519 | case bp_finish: |
| 5520 | case bp_shlib_event: |
| 5521 | if (bs->stop) |
| 5522 | { |
| 5523 | if (bs->print) |
| 5524 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5525 | else |
| 5526 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5527 | } |
| 5528 | else |
| 5529 | this_action = BPSTAT_WHAT_SINGLE; |
| 5530 | break; |
| 5531 | case bp_watchpoint: |
| 5532 | case bp_hardware_watchpoint: |
| 5533 | case bp_read_watchpoint: |
| 5534 | case bp_access_watchpoint: |
| 5535 | if (bs->stop) |
| 5536 | { |
| 5537 | if (bs->print) |
| 5538 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5539 | else |
| 5540 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5541 | } |
| 5542 | else |
| 5543 | { |
| 5544 | /* There was a watchpoint, but we're not stopping. |
| 5545 | This requires no further action. */ |
| 5546 | } |
| 5547 | break; |
| 5548 | case bp_longjmp: |
| 5549 | case bp_longjmp_call_dummy: |
| 5550 | case bp_exception: |
| 5551 | if (bs->stop) |
| 5552 | { |
| 5553 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
| 5554 | retval.is_longjmp = bptype != bp_exception; |
| 5555 | } |
| 5556 | else |
| 5557 | this_action = BPSTAT_WHAT_SINGLE; |
| 5558 | break; |
| 5559 | case bp_longjmp_resume: |
| 5560 | case bp_exception_resume: |
| 5561 | if (bs->stop) |
| 5562 | { |
| 5563 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
| 5564 | retval.is_longjmp = bptype == bp_longjmp_resume; |
| 5565 | } |
| 5566 | else |
| 5567 | this_action = BPSTAT_WHAT_SINGLE; |
| 5568 | break; |
| 5569 | case bp_step_resume: |
| 5570 | if (bs->stop) |
| 5571 | this_action = BPSTAT_WHAT_STEP_RESUME; |
| 5572 | else |
| 5573 | { |
| 5574 | /* It is for the wrong frame. */ |
| 5575 | this_action = BPSTAT_WHAT_SINGLE; |
| 5576 | } |
| 5577 | break; |
| 5578 | case bp_hp_step_resume: |
| 5579 | if (bs->stop) |
| 5580 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; |
| 5581 | else |
| 5582 | { |
| 5583 | /* It is for the wrong frame. */ |
| 5584 | this_action = BPSTAT_WHAT_SINGLE; |
| 5585 | } |
| 5586 | break; |
| 5587 | case bp_watchpoint_scope: |
| 5588 | case bp_thread_event: |
| 5589 | case bp_overlay_event: |
| 5590 | case bp_longjmp_master: |
| 5591 | case bp_std_terminate_master: |
| 5592 | case bp_exception_master: |
| 5593 | this_action = BPSTAT_WHAT_SINGLE; |
| 5594 | break; |
| 5595 | case bp_catchpoint: |
| 5596 | if (bs->stop) |
| 5597 | { |
| 5598 | if (bs->print) |
| 5599 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5600 | else |
| 5601 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5602 | } |
| 5603 | else |
| 5604 | { |
| 5605 | /* Some catchpoints are implemented with breakpoints. |
| 5606 | For those, we need to step over the breakpoint. */ |
| 5607 | if (bs->bp_location_at->loc_type != bp_loc_other) |
| 5608 | this_action = BPSTAT_WHAT_SINGLE; |
| 5609 | } |
| 5610 | break; |
| 5611 | case bp_jit_event: |
| 5612 | this_action = BPSTAT_WHAT_SINGLE; |
| 5613 | break; |
| 5614 | case bp_call_dummy: |
| 5615 | /* Make sure the action is stop (silent or noisy), |
| 5616 | so infrun.c pops the dummy frame. */ |
| 5617 | retval.call_dummy = STOP_STACK_DUMMY; |
| 5618 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5619 | break; |
| 5620 | case bp_std_terminate: |
| 5621 | /* Make sure the action is stop (silent or noisy), |
| 5622 | so infrun.c pops the dummy frame. */ |
| 5623 | retval.call_dummy = STOP_STD_TERMINATE; |
| 5624 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5625 | break; |
| 5626 | case bp_tracepoint: |
| 5627 | case bp_fast_tracepoint: |
| 5628 | case bp_static_tracepoint: |
| 5629 | /* Tracepoint hits should not be reported back to GDB, and |
| 5630 | if one got through somehow, it should have been filtered |
| 5631 | out already. */ |
| 5632 | internal_error (__FILE__, __LINE__, |
| 5633 | _("bpstat_what: tracepoint encountered")); |
| 5634 | break; |
| 5635 | case bp_gnu_ifunc_resolver: |
| 5636 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ |
| 5637 | this_action = BPSTAT_WHAT_SINGLE; |
| 5638 | break; |
| 5639 | case bp_gnu_ifunc_resolver_return: |
| 5640 | /* The breakpoint will be removed, execution will restart from the |
| 5641 | PC of the former breakpoint. */ |
| 5642 | this_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5643 | break; |
| 5644 | |
| 5645 | case bp_dprintf: |
| 5646 | if (bs->stop) |
| 5647 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5648 | else |
| 5649 | this_action = BPSTAT_WHAT_SINGLE; |
| 5650 | break; |
| 5651 | |
| 5652 | default: |
| 5653 | internal_error (__FILE__, __LINE__, |
| 5654 | _("bpstat_what: unhandled bptype %d"), (int) bptype); |
| 5655 | } |
| 5656 | |
| 5657 | retval.main_action = std::max (retval.main_action, this_action); |
| 5658 | } |
| 5659 | |
| 5660 | return retval; |
| 5661 | } |
| 5662 | |
| 5663 | void |
| 5664 | bpstat_run_callbacks (bpstat bs_head) |
| 5665 | { |
| 5666 | bpstat bs; |
| 5667 | |
| 5668 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5669 | { |
| 5670 | struct breakpoint *b = bs->breakpoint_at; |
| 5671 | |
| 5672 | if (b == NULL) |
| 5673 | continue; |
| 5674 | switch (b->type) |
| 5675 | { |
| 5676 | case bp_jit_event: |
| 5677 | handle_jit_event (); |
| 5678 | break; |
| 5679 | case bp_gnu_ifunc_resolver: |
| 5680 | gnu_ifunc_resolver_stop (b); |
| 5681 | break; |
| 5682 | case bp_gnu_ifunc_resolver_return: |
| 5683 | gnu_ifunc_resolver_return_stop (b); |
| 5684 | break; |
| 5685 | } |
| 5686 | } |
| 5687 | } |
| 5688 | |
| 5689 | /* See breakpoint.h. */ |
| 5690 | |
| 5691 | bool |
| 5692 | bpstat_should_step () |
| 5693 | { |
| 5694 | struct breakpoint *b; |
| 5695 | |
| 5696 | ALL_BREAKPOINTS (b) |
| 5697 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
| 5698 | return true; |
| 5699 | return false; |
| 5700 | } |
| 5701 | |
| 5702 | /* See breakpoint.h. */ |
| 5703 | |
| 5704 | bool |
| 5705 | bpstat_causes_stop (bpstat bs) |
| 5706 | { |
| 5707 | for (; bs != NULL; bs = bs->next) |
| 5708 | if (bs->stop) |
| 5709 | return true; |
| 5710 | |
| 5711 | return false; |
| 5712 | } |
| 5713 | |
| 5714 | \f |
| 5715 | |
| 5716 | /* Compute a string of spaces suitable to indent the next line |
| 5717 | so it starts at the position corresponding to the table column |
| 5718 | named COL_NAME in the currently active table of UIOUT. */ |
| 5719 | |
| 5720 | static char * |
| 5721 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) |
| 5722 | { |
| 5723 | static char wrap_indent[80]; |
| 5724 | int i, total_width, width, align; |
| 5725 | const char *text; |
| 5726 | |
| 5727 | total_width = 0; |
| 5728 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
| 5729 | { |
| 5730 | if (strcmp (text, col_name) == 0) |
| 5731 | { |
| 5732 | gdb_assert (total_width < sizeof wrap_indent); |
| 5733 | memset (wrap_indent, ' ', total_width); |
| 5734 | wrap_indent[total_width] = 0; |
| 5735 | |
| 5736 | return wrap_indent; |
| 5737 | } |
| 5738 | |
| 5739 | total_width += width + 1; |
| 5740 | } |
| 5741 | |
| 5742 | return NULL; |
| 5743 | } |
| 5744 | |
| 5745 | /* Determine if the locations of this breakpoint will have their conditions |
| 5746 | evaluated by the target, host or a mix of both. Returns the following: |
| 5747 | |
| 5748 | "host": Host evals condition. |
| 5749 | "host or target": Host or Target evals condition. |
| 5750 | "target": Target evals condition. |
| 5751 | */ |
| 5752 | |
| 5753 | static const char * |
| 5754 | bp_condition_evaluator (struct breakpoint *b) |
| 5755 | { |
| 5756 | struct bp_location *bl; |
| 5757 | char host_evals = 0; |
| 5758 | char target_evals = 0; |
| 5759 | |
| 5760 | if (!b) |
| 5761 | return NULL; |
| 5762 | |
| 5763 | if (!is_breakpoint (b)) |
| 5764 | return NULL; |
| 5765 | |
| 5766 | if (gdb_evaluates_breakpoint_condition_p () |
| 5767 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 5768 | return condition_evaluation_host; |
| 5769 | |
| 5770 | for (bl = b->loc; bl; bl = bl->next) |
| 5771 | { |
| 5772 | if (bl->cond_bytecode) |
| 5773 | target_evals++; |
| 5774 | else |
| 5775 | host_evals++; |
| 5776 | } |
| 5777 | |
| 5778 | if (host_evals && target_evals) |
| 5779 | return condition_evaluation_both; |
| 5780 | else if (target_evals) |
| 5781 | return condition_evaluation_target; |
| 5782 | else |
| 5783 | return condition_evaluation_host; |
| 5784 | } |
| 5785 | |
| 5786 | /* Determine the breakpoint location's condition evaluator. This is |
| 5787 | similar to bp_condition_evaluator, but for locations. */ |
| 5788 | |
| 5789 | static const char * |
| 5790 | bp_location_condition_evaluator (struct bp_location *bl) |
| 5791 | { |
| 5792 | if (bl && !is_breakpoint (bl->owner)) |
| 5793 | return NULL; |
| 5794 | |
| 5795 | if (gdb_evaluates_breakpoint_condition_p () |
| 5796 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 5797 | return condition_evaluation_host; |
| 5798 | |
| 5799 | if (bl && bl->cond_bytecode) |
| 5800 | return condition_evaluation_target; |
| 5801 | else |
| 5802 | return condition_evaluation_host; |
| 5803 | } |
| 5804 | |
| 5805 | /* Print the LOC location out of the list of B->LOC locations. */ |
| 5806 | |
| 5807 | static void |
| 5808 | print_breakpoint_location (struct breakpoint *b, |
| 5809 | struct bp_location *loc) |
| 5810 | { |
| 5811 | struct ui_out *uiout = current_uiout; |
| 5812 | |
| 5813 | scoped_restore_current_program_space restore_pspace; |
| 5814 | |
| 5815 | if (loc != NULL && loc->shlib_disabled) |
| 5816 | loc = NULL; |
| 5817 | |
| 5818 | if (loc != NULL) |
| 5819 | set_current_program_space (loc->pspace); |
| 5820 | |
| 5821 | if (b->display_canonical) |
| 5822 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
| 5823 | else if (loc && loc->symtab) |
| 5824 | { |
| 5825 | const struct symbol *sym = loc->symbol; |
| 5826 | |
| 5827 | if (sym) |
| 5828 | { |
| 5829 | uiout->text ("in "); |
| 5830 | uiout->field_string ("func", sym->print_name (), |
| 5831 | function_name_style.style ()); |
| 5832 | uiout->text (" "); |
| 5833 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); |
| 5834 | uiout->text ("at "); |
| 5835 | } |
| 5836 | uiout->field_string ("file", |
| 5837 | symtab_to_filename_for_display (loc->symtab), |
| 5838 | file_name_style.style ()); |
| 5839 | uiout->text (":"); |
| 5840 | |
| 5841 | if (uiout->is_mi_like_p ()) |
| 5842 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); |
| 5843 | |
| 5844 | uiout->field_signed ("line", loc->line_number); |
| 5845 | } |
| 5846 | else if (loc) |
| 5847 | { |
| 5848 | string_file stb; |
| 5849 | |
| 5850 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
| 5851 | demangle, ""); |
| 5852 | uiout->field_stream ("at", stb); |
| 5853 | } |
| 5854 | else |
| 5855 | { |
| 5856 | uiout->field_string ("pending", |
| 5857 | event_location_to_string (b->location.get ())); |
| 5858 | /* If extra_string is available, it could be holding a condition |
| 5859 | or dprintf arguments. In either case, make sure it is printed, |
| 5860 | too, but only for non-MI streams. */ |
| 5861 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
| 5862 | { |
| 5863 | if (b->type == bp_dprintf) |
| 5864 | uiout->text (","); |
| 5865 | else |
| 5866 | uiout->text (" "); |
| 5867 | uiout->text (b->extra_string); |
| 5868 | } |
| 5869 | } |
| 5870 | |
| 5871 | if (loc && is_breakpoint (b) |
| 5872 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target |
| 5873 | && bp_condition_evaluator (b) == condition_evaluation_both) |
| 5874 | { |
| 5875 | uiout->text (" ("); |
| 5876 | uiout->field_string ("evaluated-by", |
| 5877 | bp_location_condition_evaluator (loc)); |
| 5878 | uiout->text (")"); |
| 5879 | } |
| 5880 | } |
| 5881 | |
| 5882 | static const char * |
| 5883 | bptype_string (enum bptype type) |
| 5884 | { |
| 5885 | struct ep_type_description |
| 5886 | { |
| 5887 | enum bptype type; |
| 5888 | const char *description; |
| 5889 | }; |
| 5890 | static struct ep_type_description bptypes[] = |
| 5891 | { |
| 5892 | {bp_none, "?deleted?"}, |
| 5893 | {bp_breakpoint, "breakpoint"}, |
| 5894 | {bp_hardware_breakpoint, "hw breakpoint"}, |
| 5895 | {bp_single_step, "sw single-step"}, |
| 5896 | {bp_until, "until"}, |
| 5897 | {bp_finish, "finish"}, |
| 5898 | {bp_watchpoint, "watchpoint"}, |
| 5899 | {bp_hardware_watchpoint, "hw watchpoint"}, |
| 5900 | {bp_read_watchpoint, "read watchpoint"}, |
| 5901 | {bp_access_watchpoint, "acc watchpoint"}, |
| 5902 | {bp_longjmp, "longjmp"}, |
| 5903 | {bp_longjmp_resume, "longjmp resume"}, |
| 5904 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
| 5905 | {bp_exception, "exception"}, |
| 5906 | {bp_exception_resume, "exception resume"}, |
| 5907 | {bp_step_resume, "step resume"}, |
| 5908 | {bp_hp_step_resume, "high-priority step resume"}, |
| 5909 | {bp_watchpoint_scope, "watchpoint scope"}, |
| 5910 | {bp_call_dummy, "call dummy"}, |
| 5911 | {bp_std_terminate, "std::terminate"}, |
| 5912 | {bp_shlib_event, "shlib events"}, |
| 5913 | {bp_thread_event, "thread events"}, |
| 5914 | {bp_overlay_event, "overlay events"}, |
| 5915 | {bp_longjmp_master, "longjmp master"}, |
| 5916 | {bp_std_terminate_master, "std::terminate master"}, |
| 5917 | {bp_exception_master, "exception master"}, |
| 5918 | {bp_catchpoint, "catchpoint"}, |
| 5919 | {bp_tracepoint, "tracepoint"}, |
| 5920 | {bp_fast_tracepoint, "fast tracepoint"}, |
| 5921 | {bp_static_tracepoint, "static tracepoint"}, |
| 5922 | {bp_dprintf, "dprintf"}, |
| 5923 | {bp_jit_event, "jit events"}, |
| 5924 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
| 5925 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, |
| 5926 | }; |
| 5927 | |
| 5928 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) |
| 5929 | || ((int) type != bptypes[(int) type].type)) |
| 5930 | internal_error (__FILE__, __LINE__, |
| 5931 | _("bptypes table does not describe type #%d."), |
| 5932 | (int) type); |
| 5933 | |
| 5934 | return bptypes[(int) type].description; |
| 5935 | } |
| 5936 | |
| 5937 | /* For MI, output a field named 'thread-groups' with a list as the value. |
| 5938 | For CLI, prefix the list with the string 'inf'. */ |
| 5939 | |
| 5940 | static void |
| 5941 | output_thread_groups (struct ui_out *uiout, |
| 5942 | const char *field_name, |
| 5943 | const std::vector<int> &inf_nums, |
| 5944 | int mi_only) |
| 5945 | { |
| 5946 | int is_mi = uiout->is_mi_like_p (); |
| 5947 | |
| 5948 | /* For backward compatibility, don't display inferiors in CLI unless |
| 5949 | there are several. Always display them for MI. */ |
| 5950 | if (!is_mi && mi_only) |
| 5951 | return; |
| 5952 | |
| 5953 | ui_out_emit_list list_emitter (uiout, field_name); |
| 5954 | |
| 5955 | for (size_t i = 0; i < inf_nums.size (); i++) |
| 5956 | { |
| 5957 | if (is_mi) |
| 5958 | { |
| 5959 | char mi_group[10]; |
| 5960 | |
| 5961 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
| 5962 | uiout->field_string (NULL, mi_group); |
| 5963 | } |
| 5964 | else |
| 5965 | { |
| 5966 | if (i == 0) |
| 5967 | uiout->text (" inf "); |
| 5968 | else |
| 5969 | uiout->text (", "); |
| 5970 | |
| 5971 | uiout->text (plongest (inf_nums[i])); |
| 5972 | } |
| 5973 | } |
| 5974 | } |
| 5975 | |
| 5976 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
| 5977 | instead of going via breakpoint_ops::print_one. This makes "maint |
| 5978 | info breakpoints" show the software breakpoint locations of |
| 5979 | catchpoints, which are considered internal implementation |
| 5980 | detail. */ |
| 5981 | |
| 5982 | static void |
| 5983 | print_one_breakpoint_location (struct breakpoint *b, |
| 5984 | struct bp_location *loc, |
| 5985 | int loc_number, |
| 5986 | struct bp_location **last_loc, |
| 5987 | int allflag, bool raw_loc) |
| 5988 | { |
| 5989 | struct command_line *l; |
| 5990 | static char bpenables[] = "nynny"; |
| 5991 | |
| 5992 | struct ui_out *uiout = current_uiout; |
| 5993 | int header_of_multiple = 0; |
| 5994 | int part_of_multiple = (loc != NULL); |
| 5995 | struct value_print_options opts; |
| 5996 | |
| 5997 | get_user_print_options (&opts); |
| 5998 | |
| 5999 | gdb_assert (!loc || loc_number != 0); |
| 6000 | /* See comment in print_one_breakpoint concerning treatment of |
| 6001 | breakpoints with single disabled location. */ |
| 6002 | if (loc == NULL |
| 6003 | && (b->loc != NULL |
| 6004 | && (b->loc->next != NULL || !b->loc->enabled))) |
| 6005 | header_of_multiple = 1; |
| 6006 | if (loc == NULL) |
| 6007 | loc = b->loc; |
| 6008 | |
| 6009 | annotate_record (); |
| 6010 | |
| 6011 | /* 1 */ |
| 6012 | annotate_field (0); |
| 6013 | if (part_of_multiple) |
| 6014 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
| 6015 | else |
| 6016 | uiout->field_signed ("number", b->number); |
| 6017 | |
| 6018 | /* 2 */ |
| 6019 | annotate_field (1); |
| 6020 | if (part_of_multiple) |
| 6021 | uiout->field_skip ("type"); |
| 6022 | else |
| 6023 | uiout->field_string ("type", bptype_string (b->type)); |
| 6024 | |
| 6025 | /* 3 */ |
| 6026 | annotate_field (2); |
| 6027 | if (part_of_multiple) |
| 6028 | uiout->field_skip ("disp"); |
| 6029 | else |
| 6030 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 6031 | |
| 6032 | /* 4 */ |
| 6033 | annotate_field (3); |
| 6034 | if (part_of_multiple) |
| 6035 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
| 6036 | else |
| 6037 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
| 6038 | |
| 6039 | /* 5 and 6 */ |
| 6040 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
| 6041 | b->ops->print_one (b, last_loc); |
| 6042 | else |
| 6043 | { |
| 6044 | if (is_watchpoint (b)) |
| 6045 | { |
| 6046 | struct watchpoint *w = (struct watchpoint *) b; |
| 6047 | |
| 6048 | /* Field 4, the address, is omitted (which makes the columns |
| 6049 | not line up too nicely with the headers, but the effect |
| 6050 | is relatively readable). */ |
| 6051 | if (opts.addressprint) |
| 6052 | uiout->field_skip ("addr"); |
| 6053 | annotate_field (5); |
| 6054 | uiout->field_string ("what", w->exp_string); |
| 6055 | } |
| 6056 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
| 6057 | || is_ada_exception_catchpoint (b)) |
| 6058 | { |
| 6059 | if (opts.addressprint) |
| 6060 | { |
| 6061 | annotate_field (4); |
| 6062 | if (header_of_multiple) |
| 6063 | uiout->field_string ("addr", "<MULTIPLE>", |
| 6064 | metadata_style.style ()); |
| 6065 | else if (b->loc == NULL || loc->shlib_disabled) |
| 6066 | uiout->field_string ("addr", "<PENDING>", |
| 6067 | metadata_style.style ()); |
| 6068 | else |
| 6069 | uiout->field_core_addr ("addr", |
| 6070 | loc->gdbarch, loc->address); |
| 6071 | } |
| 6072 | annotate_field (5); |
| 6073 | if (!header_of_multiple) |
| 6074 | print_breakpoint_location (b, loc); |
| 6075 | if (b->loc) |
| 6076 | *last_loc = b->loc; |
| 6077 | } |
| 6078 | } |
| 6079 | |
| 6080 | if (loc != NULL && !header_of_multiple) |
| 6081 | { |
| 6082 | std::vector<int> inf_nums; |
| 6083 | int mi_only = 1; |
| 6084 | |
| 6085 | for (inferior *inf : all_inferiors ()) |
| 6086 | { |
| 6087 | if (inf->pspace == loc->pspace) |
| 6088 | inf_nums.push_back (inf->num); |
| 6089 | } |
| 6090 | |
| 6091 | /* For backward compatibility, don't display inferiors in CLI unless |
| 6092 | there are several. Always display for MI. */ |
| 6093 | if (allflag |
| 6094 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6095 | && (number_of_program_spaces () > 1 |
| 6096 | || number_of_inferiors () > 1) |
| 6097 | /* LOC is for existing B, it cannot be in |
| 6098 | moribund_locations and thus having NULL OWNER. */ |
| 6099 | && loc->owner->type != bp_catchpoint)) |
| 6100 | mi_only = 0; |
| 6101 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
| 6102 | } |
| 6103 | |
| 6104 | if (!part_of_multiple) |
| 6105 | { |
| 6106 | if (b->thread != -1) |
| 6107 | { |
| 6108 | /* FIXME: This seems to be redundant and lost here; see the |
| 6109 | "stop only in" line a little further down. */ |
| 6110 | uiout->text (" thread "); |
| 6111 | uiout->field_signed ("thread", b->thread); |
| 6112 | } |
| 6113 | else if (b->task != 0) |
| 6114 | { |
| 6115 | uiout->text (" task "); |
| 6116 | uiout->field_signed ("task", b->task); |
| 6117 | } |
| 6118 | } |
| 6119 | |
| 6120 | uiout->text ("\n"); |
| 6121 | |
| 6122 | if (!part_of_multiple) |
| 6123 | b->ops->print_one_detail (b, uiout); |
| 6124 | |
| 6125 | if (part_of_multiple && frame_id_p (b->frame_id)) |
| 6126 | { |
| 6127 | annotate_field (6); |
| 6128 | uiout->text ("\tstop only in stack frame at "); |
| 6129 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
| 6130 | the frame ID. */ |
| 6131 | uiout->field_core_addr ("frame", |
| 6132 | b->gdbarch, b->frame_id.stack_addr); |
| 6133 | uiout->text ("\n"); |
| 6134 | } |
| 6135 | |
| 6136 | if (!part_of_multiple && b->cond_string) |
| 6137 | { |
| 6138 | annotate_field (7); |
| 6139 | if (is_tracepoint (b)) |
| 6140 | uiout->text ("\ttrace only if "); |
| 6141 | else |
| 6142 | uiout->text ("\tstop only if "); |
| 6143 | uiout->field_string ("cond", b->cond_string); |
| 6144 | |
| 6145 | /* Print whether the target is doing the breakpoint's condition |
| 6146 | evaluation. If GDB is doing the evaluation, don't print anything. */ |
| 6147 | if (is_breakpoint (b) |
| 6148 | && breakpoint_condition_evaluation_mode () |
| 6149 | == condition_evaluation_target) |
| 6150 | { |
| 6151 | uiout->message (" (%pF evals)", |
| 6152 | string_field ("evaluated-by", |
| 6153 | bp_condition_evaluator (b))); |
| 6154 | } |
| 6155 | uiout->text ("\n"); |
| 6156 | } |
| 6157 | |
| 6158 | if (!part_of_multiple && b->thread != -1) |
| 6159 | { |
| 6160 | /* FIXME should make an annotation for this. */ |
| 6161 | uiout->text ("\tstop only in thread "); |
| 6162 | if (uiout->is_mi_like_p ()) |
| 6163 | uiout->field_signed ("thread", b->thread); |
| 6164 | else |
| 6165 | { |
| 6166 | struct thread_info *thr = find_thread_global_id (b->thread); |
| 6167 | |
| 6168 | uiout->field_string ("thread", print_thread_id (thr)); |
| 6169 | } |
| 6170 | uiout->text ("\n"); |
| 6171 | } |
| 6172 | |
| 6173 | if (!part_of_multiple) |
| 6174 | { |
| 6175 | if (b->hit_count) |
| 6176 | { |
| 6177 | /* FIXME should make an annotation for this. */ |
| 6178 | if (is_catchpoint (b)) |
| 6179 | uiout->text ("\tcatchpoint"); |
| 6180 | else if (is_tracepoint (b)) |
| 6181 | uiout->text ("\ttracepoint"); |
| 6182 | else |
| 6183 | uiout->text ("\tbreakpoint"); |
| 6184 | uiout->text (" already hit "); |
| 6185 | uiout->field_signed ("times", b->hit_count); |
| 6186 | if (b->hit_count == 1) |
| 6187 | uiout->text (" time\n"); |
| 6188 | else |
| 6189 | uiout->text (" times\n"); |
| 6190 | } |
| 6191 | else |
| 6192 | { |
| 6193 | /* Output the count also if it is zero, but only if this is mi. */ |
| 6194 | if (uiout->is_mi_like_p ()) |
| 6195 | uiout->field_signed ("times", b->hit_count); |
| 6196 | } |
| 6197 | } |
| 6198 | |
| 6199 | if (!part_of_multiple && b->ignore_count) |
| 6200 | { |
| 6201 | annotate_field (8); |
| 6202 | uiout->message ("\tignore next %pF hits\n", |
| 6203 | signed_field ("ignore", b->ignore_count)); |
| 6204 | } |
| 6205 | |
| 6206 | /* Note that an enable count of 1 corresponds to "enable once" |
| 6207 | behavior, which is reported by the combination of enablement and |
| 6208 | disposition, so we don't need to mention it here. */ |
| 6209 | if (!part_of_multiple && b->enable_count > 1) |
| 6210 | { |
| 6211 | annotate_field (8); |
| 6212 | uiout->text ("\tdisable after "); |
| 6213 | /* Tweak the wording to clarify that ignore and enable counts |
| 6214 | are distinct, and have additive effect. */ |
| 6215 | if (b->ignore_count) |
| 6216 | uiout->text ("additional "); |
| 6217 | else |
| 6218 | uiout->text ("next "); |
| 6219 | uiout->field_signed ("enable", b->enable_count); |
| 6220 | uiout->text (" hits\n"); |
| 6221 | } |
| 6222 | |
| 6223 | if (!part_of_multiple && is_tracepoint (b)) |
| 6224 | { |
| 6225 | struct tracepoint *tp = (struct tracepoint *) b; |
| 6226 | |
| 6227 | if (tp->traceframe_usage) |
| 6228 | { |
| 6229 | uiout->text ("\ttrace buffer usage "); |
| 6230 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
| 6231 | uiout->text (" bytes\n"); |
| 6232 | } |
| 6233 | } |
| 6234 | |
| 6235 | l = b->commands ? b->commands.get () : NULL; |
| 6236 | if (!part_of_multiple && l) |
| 6237 | { |
| 6238 | annotate_field (9); |
| 6239 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
| 6240 | print_command_lines (uiout, l, 4); |
| 6241 | } |
| 6242 | |
| 6243 | if (is_tracepoint (b)) |
| 6244 | { |
| 6245 | struct tracepoint *t = (struct tracepoint *) b; |
| 6246 | |
| 6247 | if (!part_of_multiple && t->pass_count) |
| 6248 | { |
| 6249 | annotate_field (10); |
| 6250 | uiout->text ("\tpass count "); |
| 6251 | uiout->field_signed ("pass", t->pass_count); |
| 6252 | uiout->text (" \n"); |
| 6253 | } |
| 6254 | |
| 6255 | /* Don't display it when tracepoint or tracepoint location is |
| 6256 | pending. */ |
| 6257 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) |
| 6258 | { |
| 6259 | annotate_field (11); |
| 6260 | |
| 6261 | if (uiout->is_mi_like_p ()) |
| 6262 | uiout->field_string ("installed", |
| 6263 | loc->inserted ? "y" : "n"); |
| 6264 | else |
| 6265 | { |
| 6266 | if (loc->inserted) |
| 6267 | uiout->text ("\t"); |
| 6268 | else |
| 6269 | uiout->text ("\tnot "); |
| 6270 | uiout->text ("installed on target\n"); |
| 6271 | } |
| 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | if (uiout->is_mi_like_p () && !part_of_multiple) |
| 6276 | { |
| 6277 | if (is_watchpoint (b)) |
| 6278 | { |
| 6279 | struct watchpoint *w = (struct watchpoint *) b; |
| 6280 | |
| 6281 | uiout->field_string ("original-location", w->exp_string); |
| 6282 | } |
| 6283 | else if (b->location != NULL |
| 6284 | && event_location_to_string (b->location.get ()) != NULL) |
| 6285 | uiout->field_string ("original-location", |
| 6286 | event_location_to_string (b->location.get ())); |
| 6287 | } |
| 6288 | } |
| 6289 | |
| 6290 | /* See breakpoint.h. */ |
| 6291 | |
| 6292 | bool fix_multi_location_breakpoint_output_globally = false; |
| 6293 | |
| 6294 | static void |
| 6295 | print_one_breakpoint (struct breakpoint *b, |
| 6296 | struct bp_location **last_loc, |
| 6297 | int allflag) |
| 6298 | { |
| 6299 | struct ui_out *uiout = current_uiout; |
| 6300 | bool use_fixed_output |
| 6301 | = (uiout->test_flags (fix_multi_location_breakpoint_output) |
| 6302 | || fix_multi_location_breakpoint_output_globally); |
| 6303 | |
| 6304 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
| 6305 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
| 6306 | |
| 6307 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
| 6308 | are outside. */ |
| 6309 | if (!use_fixed_output) |
| 6310 | bkpt_tuple_emitter.reset (); |
| 6311 | |
| 6312 | /* If this breakpoint has custom print function, |
| 6313 | it's already printed. Otherwise, print individual |
| 6314 | locations, if any. */ |
| 6315 | if (b->ops == NULL |
| 6316 | || b->ops->print_one == NULL |
| 6317 | || allflag) |
| 6318 | { |
| 6319 | /* If breakpoint has a single location that is disabled, we |
| 6320 | print it as if it had several locations, since otherwise it's |
| 6321 | hard to represent "breakpoint enabled, location disabled" |
| 6322 | situation. |
| 6323 | |
| 6324 | Note that while hardware watchpoints have several locations |
| 6325 | internally, that's not a property exposed to users. |
| 6326 | |
| 6327 | Likewise, while catchpoints may be implemented with |
| 6328 | breakpoints (e.g., catch throw), that's not a property |
| 6329 | exposed to users. We do however display the internal |
| 6330 | breakpoint locations with "maint info breakpoints". */ |
| 6331 | if (!is_hardware_watchpoint (b) |
| 6332 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
| 6333 | || is_ada_exception_catchpoint (b)) |
| 6334 | && (allflag |
| 6335 | || (b->loc && (b->loc->next || !b->loc->enabled)))) |
| 6336 | { |
| 6337 | gdb::optional<ui_out_emit_list> locations_list; |
| 6338 | |
| 6339 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid |
| 6340 | MI record. For later versions, place breakpoint locations in a |
| 6341 | list. */ |
| 6342 | if (uiout->is_mi_like_p () && use_fixed_output) |
| 6343 | locations_list.emplace (uiout, "locations"); |
| 6344 | |
| 6345 | int n = 1; |
| 6346 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) |
| 6347 | { |
| 6348 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
| 6349 | print_one_breakpoint_location (b, loc, n, last_loc, |
| 6350 | allflag, allflag); |
| 6351 | } |
| 6352 | } |
| 6353 | } |
| 6354 | } |
| 6355 | |
| 6356 | static int |
| 6357 | breakpoint_address_bits (struct breakpoint *b) |
| 6358 | { |
| 6359 | int print_address_bits = 0; |
| 6360 | struct bp_location *loc; |
| 6361 | |
| 6362 | /* Software watchpoints that aren't watching memory don't have an |
| 6363 | address to print. */ |
| 6364 | if (is_no_memory_software_watchpoint (b)) |
| 6365 | return 0; |
| 6366 | |
| 6367 | for (loc = b->loc; loc; loc = loc->next) |
| 6368 | { |
| 6369 | int addr_bit; |
| 6370 | |
| 6371 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
| 6372 | if (addr_bit > print_address_bits) |
| 6373 | print_address_bits = addr_bit; |
| 6374 | } |
| 6375 | |
| 6376 | return print_address_bits; |
| 6377 | } |
| 6378 | |
| 6379 | /* See breakpoint.h. */ |
| 6380 | |
| 6381 | void |
| 6382 | print_breakpoint (breakpoint *b) |
| 6383 | { |
| 6384 | struct bp_location *dummy_loc = NULL; |
| 6385 | print_one_breakpoint (b, &dummy_loc, 0); |
| 6386 | } |
| 6387 | |
| 6388 | /* Return true if this breakpoint was set by the user, false if it is |
| 6389 | internal or momentary. */ |
| 6390 | |
| 6391 | int |
| 6392 | user_breakpoint_p (struct breakpoint *b) |
| 6393 | { |
| 6394 | return b->number > 0; |
| 6395 | } |
| 6396 | |
| 6397 | /* See breakpoint.h. */ |
| 6398 | |
| 6399 | int |
| 6400 | pending_breakpoint_p (struct breakpoint *b) |
| 6401 | { |
| 6402 | return b->loc == NULL; |
| 6403 | } |
| 6404 | |
| 6405 | /* Print information on breakpoints (including watchpoints and tracepoints). |
| 6406 | |
| 6407 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as |
| 6408 | understood by number_or_range_parser. Only breakpoints included in this |
| 6409 | list are then printed. |
| 6410 | |
| 6411 | If SHOW_INTERNAL is true, print internal breakpoints. |
| 6412 | |
| 6413 | If FILTER is non-NULL, call it on each breakpoint and only include the |
| 6414 | ones for which it returns true. |
| 6415 | |
| 6416 | Return the total number of breakpoints listed. */ |
| 6417 | |
| 6418 | static int |
| 6419 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
| 6420 | bool (*filter) (const struct breakpoint *)) |
| 6421 | { |
| 6422 | struct breakpoint *b; |
| 6423 | struct bp_location *last_loc = NULL; |
| 6424 | int nr_printable_breakpoints; |
| 6425 | struct value_print_options opts; |
| 6426 | int print_address_bits = 0; |
| 6427 | int print_type_col_width = 14; |
| 6428 | struct ui_out *uiout = current_uiout; |
| 6429 | |
| 6430 | get_user_print_options (&opts); |
| 6431 | |
| 6432 | /* Compute the number of rows in the table, as well as the size |
| 6433 | required for address fields. */ |
| 6434 | nr_printable_breakpoints = 0; |
| 6435 | ALL_BREAKPOINTS (b) |
| 6436 | { |
| 6437 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 6438 | if (filter && !filter (b)) |
| 6439 | continue; |
| 6440 | |
| 6441 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
| 6442 | accept. Skip the others. */ |
| 6443 | if (bp_num_list != NULL && *bp_num_list != '\0') |
| 6444 | { |
| 6445 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
| 6446 | continue; |
| 6447 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
| 6448 | continue; |
| 6449 | } |
| 6450 | |
| 6451 | if (show_internal || user_breakpoint_p (b)) |
| 6452 | { |
| 6453 | int addr_bit, type_len; |
| 6454 | |
| 6455 | addr_bit = breakpoint_address_bits (b); |
| 6456 | if (addr_bit > print_address_bits) |
| 6457 | print_address_bits = addr_bit; |
| 6458 | |
| 6459 | type_len = strlen (bptype_string (b->type)); |
| 6460 | if (type_len > print_type_col_width) |
| 6461 | print_type_col_width = type_len; |
| 6462 | |
| 6463 | nr_printable_breakpoints++; |
| 6464 | } |
| 6465 | } |
| 6466 | |
| 6467 | { |
| 6468 | ui_out_emit_table table_emitter (uiout, |
| 6469 | opts.addressprint ? 6 : 5, |
| 6470 | nr_printable_breakpoints, |
| 6471 | "BreakpointTable"); |
| 6472 | |
| 6473 | if (nr_printable_breakpoints > 0) |
| 6474 | annotate_breakpoints_headers (); |
| 6475 | if (nr_printable_breakpoints > 0) |
| 6476 | annotate_field (0); |
| 6477 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ |
| 6478 | if (nr_printable_breakpoints > 0) |
| 6479 | annotate_field (1); |
| 6480 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ |
| 6481 | if (nr_printable_breakpoints > 0) |
| 6482 | annotate_field (2); |
| 6483 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ |
| 6484 | if (nr_printable_breakpoints > 0) |
| 6485 | annotate_field (3); |
| 6486 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ |
| 6487 | if (opts.addressprint) |
| 6488 | { |
| 6489 | if (nr_printable_breakpoints > 0) |
| 6490 | annotate_field (4); |
| 6491 | if (print_address_bits <= 32) |
| 6492 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ |
| 6493 | else |
| 6494 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ |
| 6495 | } |
| 6496 | if (nr_printable_breakpoints > 0) |
| 6497 | annotate_field (5); |
| 6498 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ |
| 6499 | uiout->table_body (); |
| 6500 | if (nr_printable_breakpoints > 0) |
| 6501 | annotate_breakpoints_table (); |
| 6502 | |
| 6503 | ALL_BREAKPOINTS (b) |
| 6504 | { |
| 6505 | QUIT; |
| 6506 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 6507 | if (filter && !filter (b)) |
| 6508 | continue; |
| 6509 | |
| 6510 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
| 6511 | accept. Skip the others. */ |
| 6512 | |
| 6513 | if (bp_num_list != NULL && *bp_num_list != '\0') |
| 6514 | { |
| 6515 | if (show_internal) /* maintenance info breakpoint */ |
| 6516 | { |
| 6517 | if (parse_and_eval_long (bp_num_list) != b->number) |
| 6518 | continue; |
| 6519 | } |
| 6520 | else /* all others */ |
| 6521 | { |
| 6522 | if (!number_is_in_list (bp_num_list, b->number)) |
| 6523 | continue; |
| 6524 | } |
| 6525 | } |
| 6526 | /* We only print out user settable breakpoints unless the |
| 6527 | show_internal is set. */ |
| 6528 | if (show_internal || user_breakpoint_p (b)) |
| 6529 | print_one_breakpoint (b, &last_loc, show_internal); |
| 6530 | } |
| 6531 | } |
| 6532 | |
| 6533 | if (nr_printable_breakpoints == 0) |
| 6534 | { |
| 6535 | /* If there's a filter, let the caller decide how to report |
| 6536 | empty list. */ |
| 6537 | if (!filter) |
| 6538 | { |
| 6539 | if (bp_num_list == NULL || *bp_num_list == '\0') |
| 6540 | uiout->message ("No breakpoints or watchpoints.\n"); |
| 6541 | else |
| 6542 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
| 6543 | bp_num_list); |
| 6544 | } |
| 6545 | } |
| 6546 | else |
| 6547 | { |
| 6548 | if (last_loc && !server_command) |
| 6549 | set_next_address (last_loc->gdbarch, last_loc->address); |
| 6550 | } |
| 6551 | |
| 6552 | /* FIXME? Should this be moved up so that it is only called when |
| 6553 | there have been breakpoints? */ |
| 6554 | annotate_breakpoints_table_end (); |
| 6555 | |
| 6556 | return nr_printable_breakpoints; |
| 6557 | } |
| 6558 | |
| 6559 | /* Display the value of default-collect in a way that is generally |
| 6560 | compatible with the breakpoint list. */ |
| 6561 | |
| 6562 | static void |
| 6563 | default_collect_info (void) |
| 6564 | { |
| 6565 | struct ui_out *uiout = current_uiout; |
| 6566 | |
| 6567 | /* If it has no value (which is frequently the case), say nothing; a |
| 6568 | message like "No default-collect." gets in user's face when it's |
| 6569 | not wanted. */ |
| 6570 | if (!*default_collect) |
| 6571 | return; |
| 6572 | |
| 6573 | /* The following phrase lines up nicely with per-tracepoint collect |
| 6574 | actions. */ |
| 6575 | uiout->text ("default collect "); |
| 6576 | uiout->field_string ("default-collect", default_collect); |
| 6577 | uiout->text (" \n"); |
| 6578 | } |
| 6579 | |
| 6580 | static void |
| 6581 | info_breakpoints_command (const char *args, int from_tty) |
| 6582 | { |
| 6583 | breakpoint_1 (args, false, NULL); |
| 6584 | |
| 6585 | default_collect_info (); |
| 6586 | } |
| 6587 | |
| 6588 | static void |
| 6589 | info_watchpoints_command (const char *args, int from_tty) |
| 6590 | { |
| 6591 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
| 6592 | struct ui_out *uiout = current_uiout; |
| 6593 | |
| 6594 | if (num_printed == 0) |
| 6595 | { |
| 6596 | if (args == NULL || *args == '\0') |
| 6597 | uiout->message ("No watchpoints.\n"); |
| 6598 | else |
| 6599 | uiout->message ("No watchpoint matching '%s'.\n", args); |
| 6600 | } |
| 6601 | } |
| 6602 | |
| 6603 | static void |
| 6604 | maintenance_info_breakpoints (const char *args, int from_tty) |
| 6605 | { |
| 6606 | breakpoint_1 (args, true, NULL); |
| 6607 | |
| 6608 | default_collect_info (); |
| 6609 | } |
| 6610 | |
| 6611 | static int |
| 6612 | breakpoint_has_pc (struct breakpoint *b, |
| 6613 | struct program_space *pspace, |
| 6614 | CORE_ADDR pc, struct obj_section *section) |
| 6615 | { |
| 6616 | struct bp_location *bl = b->loc; |
| 6617 | |
| 6618 | for (; bl; bl = bl->next) |
| 6619 | { |
| 6620 | if (bl->pspace == pspace |
| 6621 | && bl->address == pc |
| 6622 | && (!overlay_debugging || bl->section == section)) |
| 6623 | return 1; |
| 6624 | } |
| 6625 | return 0; |
| 6626 | } |
| 6627 | |
| 6628 | /* Print a message describing any user-breakpoints set at PC. This |
| 6629 | concerns with logical breakpoints, so we match program spaces, not |
| 6630 | address spaces. */ |
| 6631 | |
| 6632 | static void |
| 6633 | describe_other_breakpoints (struct gdbarch *gdbarch, |
| 6634 | struct program_space *pspace, CORE_ADDR pc, |
| 6635 | struct obj_section *section, int thread) |
| 6636 | { |
| 6637 | int others = 0; |
| 6638 | struct breakpoint *b; |
| 6639 | |
| 6640 | ALL_BREAKPOINTS (b) |
| 6641 | others += (user_breakpoint_p (b) |
| 6642 | && breakpoint_has_pc (b, pspace, pc, section)); |
| 6643 | if (others > 0) |
| 6644 | { |
| 6645 | if (others == 1) |
| 6646 | printf_filtered (_("Note: breakpoint ")); |
| 6647 | else /* if (others == ???) */ |
| 6648 | printf_filtered (_("Note: breakpoints ")); |
| 6649 | ALL_BREAKPOINTS (b) |
| 6650 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
| 6651 | { |
| 6652 | others--; |
| 6653 | printf_filtered ("%d", b->number); |
| 6654 | if (b->thread == -1 && thread != -1) |
| 6655 | printf_filtered (" (all threads)"); |
| 6656 | else if (b->thread != -1) |
| 6657 | printf_filtered (" (thread %d)", b->thread); |
| 6658 | printf_filtered ("%s%s ", |
| 6659 | ((b->enable_state == bp_disabled |
| 6660 | || b->enable_state == bp_call_disabled) |
| 6661 | ? " (disabled)" |
| 6662 | : ""), |
| 6663 | (others > 1) ? "," |
| 6664 | : ((others == 1) ? " and" : "")); |
| 6665 | } |
| 6666 | current_uiout->message (_("also set at pc %ps.\n"), |
| 6667 | styled_string (address_style.style (), |
| 6668 | paddress (gdbarch, pc))); |
| 6669 | } |
| 6670 | } |
| 6671 | \f |
| 6672 | |
| 6673 | /* Return true iff it is meaningful to use the address member of LOC. |
| 6674 | For some breakpoint types, the locations' address members are |
| 6675 | irrelevant and it makes no sense to attempt to compare them to |
| 6676 | other addresses (or use them for any other purpose either). |
| 6677 | |
| 6678 | More specifically, software watchpoints and catchpoints that are |
| 6679 | not backed by breakpoints always have a zero valued location |
| 6680 | address and we don't want to mark breakpoints of any of these types |
| 6681 | to be a duplicate of an actual breakpoint location at address |
| 6682 | zero. */ |
| 6683 | |
| 6684 | static bool |
| 6685 | bl_address_is_meaningful (bp_location *loc) |
| 6686 | { |
| 6687 | return loc->loc_type != bp_loc_other; |
| 6688 | } |
| 6689 | |
| 6690 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns |
| 6691 | true if LOC1 and LOC2 represent the same watchpoint location. */ |
| 6692 | |
| 6693 | static int |
| 6694 | watchpoint_locations_match (struct bp_location *loc1, |
| 6695 | struct bp_location *loc2) |
| 6696 | { |
| 6697 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
| 6698 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; |
| 6699 | |
| 6700 | /* Both of them must exist. */ |
| 6701 | gdb_assert (w1 != NULL); |
| 6702 | gdb_assert (w2 != NULL); |
| 6703 | |
| 6704 | /* If the target can evaluate the condition expression in hardware, |
| 6705 | then we we need to insert both watchpoints even if they are at |
| 6706 | the same place. Otherwise the watchpoint will only trigger when |
| 6707 | the condition of whichever watchpoint was inserted evaluates to |
| 6708 | true, not giving a chance for GDB to check the condition of the |
| 6709 | other watchpoint. */ |
| 6710 | if ((w1->cond_exp |
| 6711 | && target_can_accel_watchpoint_condition (loc1->address, |
| 6712 | loc1->length, |
| 6713 | loc1->watchpoint_type, |
| 6714 | w1->cond_exp.get ())) |
| 6715 | || (w2->cond_exp |
| 6716 | && target_can_accel_watchpoint_condition (loc2->address, |
| 6717 | loc2->length, |
| 6718 | loc2->watchpoint_type, |
| 6719 | w2->cond_exp.get ()))) |
| 6720 | return 0; |
| 6721 | |
| 6722 | /* Note that this checks the owner's type, not the location's. In |
| 6723 | case the target does not support read watchpoints, but does |
| 6724 | support access watchpoints, we'll have bp_read_watchpoint |
| 6725 | watchpoints with hw_access locations. Those should be considered |
| 6726 | duplicates of hw_read locations. The hw_read locations will |
| 6727 | become hw_access locations later. */ |
| 6728 | return (loc1->owner->type == loc2->owner->type |
| 6729 | && loc1->pspace->aspace == loc2->pspace->aspace |
| 6730 | && loc1->address == loc2->address |
| 6731 | && loc1->length == loc2->length); |
| 6732 | } |
| 6733 | |
| 6734 | /* See breakpoint.h. */ |
| 6735 | |
| 6736 | int |
| 6737 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
| 6738 | const address_space *aspace2, CORE_ADDR addr2) |
| 6739 | { |
| 6740 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6741 | || aspace1 == aspace2) |
| 6742 | && addr1 == addr2); |
| 6743 | } |
| 6744 | |
| 6745 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
| 6746 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 |
| 6747 | matches ASPACE2. On targets that have global breakpoints, the address |
| 6748 | space doesn't really matter. */ |
| 6749 | |
| 6750 | static int |
| 6751 | breakpoint_address_match_range (const address_space *aspace1, |
| 6752 | CORE_ADDR addr1, |
| 6753 | int len1, const address_space *aspace2, |
| 6754 | CORE_ADDR addr2) |
| 6755 | { |
| 6756 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6757 | || aspace1 == aspace2) |
| 6758 | && addr2 >= addr1 && addr2 < addr1 + len1); |
| 6759 | } |
| 6760 | |
| 6761 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be |
| 6762 | a ranged breakpoint. In most targets, a match happens only if ASPACE |
| 6763 | matches the breakpoint's address space. On targets that have global |
| 6764 | breakpoints, the address space doesn't really matter. */ |
| 6765 | |
| 6766 | static int |
| 6767 | breakpoint_location_address_match (struct bp_location *bl, |
| 6768 | const address_space *aspace, |
| 6769 | CORE_ADDR addr) |
| 6770 | { |
| 6771 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 6772 | aspace, addr) |
| 6773 | || (bl->length |
| 6774 | && breakpoint_address_match_range (bl->pspace->aspace, |
| 6775 | bl->address, bl->length, |
| 6776 | aspace, addr))); |
| 6777 | } |
| 6778 | |
| 6779 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
| 6780 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a |
| 6781 | match happens only if ASPACE matches the breakpoint's address |
| 6782 | space. On targets that have global breakpoints, the address space |
| 6783 | doesn't really matter. */ |
| 6784 | |
| 6785 | static int |
| 6786 | breakpoint_location_address_range_overlap (struct bp_location *bl, |
| 6787 | const address_space *aspace, |
| 6788 | CORE_ADDR addr, int len) |
| 6789 | { |
| 6790 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6791 | || bl->pspace->aspace == aspace) |
| 6792 | { |
| 6793 | int bl_len = bl->length != 0 ? bl->length : 1; |
| 6794 | |
| 6795 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) |
| 6796 | return 1; |
| 6797 | } |
| 6798 | return 0; |
| 6799 | } |
| 6800 | |
| 6801 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
| 6802 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns |
| 6803 | true, otherwise returns false. */ |
| 6804 | |
| 6805 | static int |
| 6806 | tracepoint_locations_match (struct bp_location *loc1, |
| 6807 | struct bp_location *loc2) |
| 6808 | { |
| 6809 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) |
| 6810 | /* Since tracepoint locations are never duplicated with others', tracepoint |
| 6811 | locations at the same address of different tracepoints are regarded as |
| 6812 | different locations. */ |
| 6813 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); |
| 6814 | else |
| 6815 | return 0; |
| 6816 | } |
| 6817 | |
| 6818 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
| 6819 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
| 6820 | the same location. */ |
| 6821 | |
| 6822 | static int |
| 6823 | breakpoint_locations_match (struct bp_location *loc1, |
| 6824 | struct bp_location *loc2) |
| 6825 | { |
| 6826 | int hw_point1, hw_point2; |
| 6827 | |
| 6828 | /* Both of them must not be in moribund_locations. */ |
| 6829 | gdb_assert (loc1->owner != NULL); |
| 6830 | gdb_assert (loc2->owner != NULL); |
| 6831 | |
| 6832 | hw_point1 = is_hardware_watchpoint (loc1->owner); |
| 6833 | hw_point2 = is_hardware_watchpoint (loc2->owner); |
| 6834 | |
| 6835 | if (hw_point1 != hw_point2) |
| 6836 | return 0; |
| 6837 | else if (hw_point1) |
| 6838 | return watchpoint_locations_match (loc1, loc2); |
| 6839 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
| 6840 | return tracepoint_locations_match (loc1, loc2); |
| 6841 | else |
| 6842 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
| 6843 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
| 6844 | loc2->pspace->aspace, loc2->address) |
| 6845 | && loc1->length == loc2->length); |
| 6846 | } |
| 6847 | |
| 6848 | static void |
| 6849 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, |
| 6850 | int bnum, int have_bnum) |
| 6851 | { |
| 6852 | /* The longest string possibly returned by hex_string_custom |
| 6853 | is 50 chars. These must be at least that big for safety. */ |
| 6854 | char astr1[64]; |
| 6855 | char astr2[64]; |
| 6856 | |
| 6857 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
| 6858 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); |
| 6859 | if (have_bnum) |
| 6860 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
| 6861 | bnum, astr1, astr2); |
| 6862 | else |
| 6863 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
| 6864 | } |
| 6865 | |
| 6866 | /* Adjust a breakpoint's address to account for architectural |
| 6867 | constraints on breakpoint placement. Return the adjusted address. |
| 6868 | Note: Very few targets require this kind of adjustment. For most |
| 6869 | targets, this function is simply the identity function. */ |
| 6870 | |
| 6871 | static CORE_ADDR |
| 6872 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 6873 | CORE_ADDR bpaddr, enum bptype bptype) |
| 6874 | { |
| 6875 | if (bptype == bp_watchpoint |
| 6876 | || bptype == bp_hardware_watchpoint |
| 6877 | || bptype == bp_read_watchpoint |
| 6878 | || bptype == bp_access_watchpoint |
| 6879 | || bptype == bp_catchpoint) |
| 6880 | { |
| 6881 | /* Watchpoints and the various bp_catch_* eventpoints should not |
| 6882 | have their addresses modified. */ |
| 6883 | return bpaddr; |
| 6884 | } |
| 6885 | else if (bptype == bp_single_step) |
| 6886 | { |
| 6887 | /* Single-step breakpoints should not have their addresses |
| 6888 | modified. If there's any architectural constrain that |
| 6889 | applies to this address, then it should have already been |
| 6890 | taken into account when the breakpoint was created in the |
| 6891 | first place. If we didn't do this, stepping through e.g., |
| 6892 | Thumb-2 IT blocks would break. */ |
| 6893 | return bpaddr; |
| 6894 | } |
| 6895 | else |
| 6896 | { |
| 6897 | CORE_ADDR adjusted_bpaddr = bpaddr; |
| 6898 | |
| 6899 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) |
| 6900 | { |
| 6901 | /* Some targets have architectural constraints on the placement |
| 6902 | of breakpoint instructions. Obtain the adjusted address. */ |
| 6903 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
| 6904 | } |
| 6905 | |
| 6906 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
| 6907 | |
| 6908 | /* An adjusted breakpoint address can significantly alter |
| 6909 | a user's expectations. Print a warning if an adjustment |
| 6910 | is required. */ |
| 6911 | if (adjusted_bpaddr != bpaddr) |
| 6912 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); |
| 6913 | |
| 6914 | return adjusted_bpaddr; |
| 6915 | } |
| 6916 | } |
| 6917 | |
| 6918 | static bp_loc_type |
| 6919 | bp_location_from_bp_type (bptype type) |
| 6920 | { |
| 6921 | switch (type) |
| 6922 | { |
| 6923 | case bp_breakpoint: |
| 6924 | case bp_single_step: |
| 6925 | case bp_until: |
| 6926 | case bp_finish: |
| 6927 | case bp_longjmp: |
| 6928 | case bp_longjmp_resume: |
| 6929 | case bp_longjmp_call_dummy: |
| 6930 | case bp_exception: |
| 6931 | case bp_exception_resume: |
| 6932 | case bp_step_resume: |
| 6933 | case bp_hp_step_resume: |
| 6934 | case bp_watchpoint_scope: |
| 6935 | case bp_call_dummy: |
| 6936 | case bp_std_terminate: |
| 6937 | case bp_shlib_event: |
| 6938 | case bp_thread_event: |
| 6939 | case bp_overlay_event: |
| 6940 | case bp_jit_event: |
| 6941 | case bp_longjmp_master: |
| 6942 | case bp_std_terminate_master: |
| 6943 | case bp_exception_master: |
| 6944 | case bp_gnu_ifunc_resolver: |
| 6945 | case bp_gnu_ifunc_resolver_return: |
| 6946 | case bp_dprintf: |
| 6947 | return bp_loc_software_breakpoint; |
| 6948 | case bp_hardware_breakpoint: |
| 6949 | return bp_loc_hardware_breakpoint; |
| 6950 | case bp_hardware_watchpoint: |
| 6951 | case bp_read_watchpoint: |
| 6952 | case bp_access_watchpoint: |
| 6953 | return bp_loc_hardware_watchpoint; |
| 6954 | case bp_watchpoint: |
| 6955 | case bp_catchpoint: |
| 6956 | case bp_tracepoint: |
| 6957 | case bp_fast_tracepoint: |
| 6958 | case bp_static_tracepoint: |
| 6959 | return bp_loc_other; |
| 6960 | default: |
| 6961 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
| 6962 | } |
| 6963 | } |
| 6964 | |
| 6965 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) |
| 6966 | { |
| 6967 | this->owner = owner; |
| 6968 | this->cond_bytecode = NULL; |
| 6969 | this->shlib_disabled = 0; |
| 6970 | this->enabled = 1; |
| 6971 | |
| 6972 | this->loc_type = type; |
| 6973 | |
| 6974 | if (this->loc_type == bp_loc_software_breakpoint |
| 6975 | || this->loc_type == bp_loc_hardware_breakpoint) |
| 6976 | mark_breakpoint_location_modified (this); |
| 6977 | |
| 6978 | this->refc = 1; |
| 6979 | } |
| 6980 | |
| 6981 | bp_location::bp_location (breakpoint *owner) |
| 6982 | : bp_location::bp_location (owner, |
| 6983 | bp_location_from_bp_type (owner->type)) |
| 6984 | { |
| 6985 | } |
| 6986 | |
| 6987 | /* Allocate a struct bp_location. */ |
| 6988 | |
| 6989 | static struct bp_location * |
| 6990 | allocate_bp_location (struct breakpoint *bpt) |
| 6991 | { |
| 6992 | return bpt->ops->allocate_location (bpt); |
| 6993 | } |
| 6994 | |
| 6995 | static void |
| 6996 | free_bp_location (struct bp_location *loc) |
| 6997 | { |
| 6998 | delete loc; |
| 6999 | } |
| 7000 | |
| 7001 | /* Increment reference count. */ |
| 7002 | |
| 7003 | static void |
| 7004 | incref_bp_location (struct bp_location *bl) |
| 7005 | { |
| 7006 | ++bl->refc; |
| 7007 | } |
| 7008 | |
| 7009 | /* Decrement reference count. If the reference count reaches 0, |
| 7010 | destroy the bp_location. Sets *BLP to NULL. */ |
| 7011 | |
| 7012 | static void |
| 7013 | decref_bp_location (struct bp_location **blp) |
| 7014 | { |
| 7015 | gdb_assert ((*blp)->refc > 0); |
| 7016 | |
| 7017 | if (--(*blp)->refc == 0) |
| 7018 | free_bp_location (*blp); |
| 7019 | *blp = NULL; |
| 7020 | } |
| 7021 | |
| 7022 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
| 7023 | |
| 7024 | static breakpoint * |
| 7025 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) |
| 7026 | { |
| 7027 | struct breakpoint *b1; |
| 7028 | struct breakpoint *result = b.get (); |
| 7029 | |
| 7030 | /* Add this breakpoint to the end of the chain so that a list of |
| 7031 | breakpoints will come out in order of increasing numbers. */ |
| 7032 | |
| 7033 | b1 = breakpoint_chain; |
| 7034 | if (b1 == 0) |
| 7035 | breakpoint_chain = b.release (); |
| 7036 | else |
| 7037 | { |
| 7038 | while (b1->next) |
| 7039 | b1 = b1->next; |
| 7040 | b1->next = b.release (); |
| 7041 | } |
| 7042 | |
| 7043 | return result; |
| 7044 | } |
| 7045 | |
| 7046 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ |
| 7047 | |
| 7048 | static void |
| 7049 | init_raw_breakpoint_without_location (struct breakpoint *b, |
| 7050 | struct gdbarch *gdbarch, |
| 7051 | enum bptype bptype, |
| 7052 | const struct breakpoint_ops *ops) |
| 7053 | { |
| 7054 | gdb_assert (ops != NULL); |
| 7055 | |
| 7056 | b->ops = ops; |
| 7057 | b->type = bptype; |
| 7058 | b->gdbarch = gdbarch; |
| 7059 | b->language = current_language->la_language; |
| 7060 | b->input_radix = input_radix; |
| 7061 | b->related_breakpoint = b; |
| 7062 | } |
| 7063 | |
| 7064 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
| 7065 | that has type BPTYPE and has no locations as yet. */ |
| 7066 | |
| 7067 | static struct breakpoint * |
| 7068 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
| 7069 | enum bptype bptype, |
| 7070 | const struct breakpoint_ops *ops) |
| 7071 | { |
| 7072 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
| 7073 | |
| 7074 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
| 7075 | return add_to_breakpoint_chain (std::move (b)); |
| 7076 | } |
| 7077 | |
| 7078 | /* Initialize loc->function_name. */ |
| 7079 | |
| 7080 | static void |
| 7081 | set_breakpoint_location_function (struct bp_location *loc) |
| 7082 | { |
| 7083 | gdb_assert (loc->owner != NULL); |
| 7084 | |
| 7085 | if (loc->owner->type == bp_breakpoint |
| 7086 | || loc->owner->type == bp_hardware_breakpoint |
| 7087 | || is_tracepoint (loc->owner)) |
| 7088 | { |
| 7089 | const char *function_name; |
| 7090 | |
| 7091 | if (loc->msymbol != NULL |
| 7092 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
| 7093 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
| 7094 | { |
| 7095 | struct breakpoint *b = loc->owner; |
| 7096 | |
| 7097 | function_name = loc->msymbol->linkage_name (); |
| 7098 | |
| 7099 | if (b->type == bp_breakpoint && b->loc == loc |
| 7100 | && loc->next == NULL && b->related_breakpoint == b) |
| 7101 | { |
| 7102 | /* Create only the whole new breakpoint of this type but do not |
| 7103 | mess more complicated breakpoints with multiple locations. */ |
| 7104 | b->type = bp_gnu_ifunc_resolver; |
| 7105 | /* Remember the resolver's address for use by the return |
| 7106 | breakpoint. */ |
| 7107 | loc->related_address = loc->address; |
| 7108 | } |
| 7109 | } |
| 7110 | else |
| 7111 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); |
| 7112 | |
| 7113 | if (function_name) |
| 7114 | loc->function_name = xstrdup (function_name); |
| 7115 | } |
| 7116 | } |
| 7117 | |
| 7118 | /* Attempt to determine architecture of location identified by SAL. */ |
| 7119 | struct gdbarch * |
| 7120 | get_sal_arch (struct symtab_and_line sal) |
| 7121 | { |
| 7122 | if (sal.section) |
| 7123 | return get_objfile_arch (sal.section->objfile); |
| 7124 | if (sal.symtab) |
| 7125 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
| 7126 | |
| 7127 | return NULL; |
| 7128 | } |
| 7129 | |
| 7130 | /* Low level routine for partially initializing a breakpoint of type |
| 7131 | BPTYPE. The newly created breakpoint's address, section, source |
| 7132 | file name, and line number are provided by SAL. |
| 7133 | |
| 7134 | It is expected that the caller will complete the initialization of |
| 7135 | the newly created breakpoint struct as well as output any status |
| 7136 | information regarding the creation of a new breakpoint. */ |
| 7137 | |
| 7138 | static void |
| 7139 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, |
| 7140 | struct symtab_and_line sal, enum bptype bptype, |
| 7141 | const struct breakpoint_ops *ops) |
| 7142 | { |
| 7143 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
| 7144 | |
| 7145 | add_location_to_breakpoint (b, &sal); |
| 7146 | |
| 7147 | if (bptype != bp_catchpoint) |
| 7148 | gdb_assert (sal.pspace != NULL); |
| 7149 | |
| 7150 | /* Store the program space that was used to set the breakpoint, |
| 7151 | except for ordinary breakpoints, which are independent of the |
| 7152 | program space. */ |
| 7153 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) |
| 7154 | b->pspace = sal.pspace; |
| 7155 | } |
| 7156 | |
| 7157 | /* set_raw_breakpoint is a low level routine for allocating and |
| 7158 | partially initializing a breakpoint of type BPTYPE. The newly |
| 7159 | created breakpoint's address, section, source file name, and line |
| 7160 | number are provided by SAL. The newly created and partially |
| 7161 | initialized breakpoint is added to the breakpoint chain and |
| 7162 | is also returned as the value of this function. |
| 7163 | |
| 7164 | It is expected that the caller will complete the initialization of |
| 7165 | the newly created breakpoint struct as well as output any status |
| 7166 | information regarding the creation of a new breakpoint. In |
| 7167 | particular, set_raw_breakpoint does NOT set the breakpoint |
| 7168 | number! Care should be taken to not allow an error to occur |
| 7169 | prior to completing the initialization of the breakpoint. If this |
| 7170 | should happen, a bogus breakpoint will be left on the chain. */ |
| 7171 | |
| 7172 | struct breakpoint * |
| 7173 | set_raw_breakpoint (struct gdbarch *gdbarch, |
| 7174 | struct symtab_and_line sal, enum bptype bptype, |
| 7175 | const struct breakpoint_ops *ops) |
| 7176 | { |
| 7177 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
| 7178 | |
| 7179 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
| 7180 | return add_to_breakpoint_chain (std::move (b)); |
| 7181 | } |
| 7182 | |
| 7183 | /* Call this routine when stepping and nexting to enable a breakpoint |
| 7184 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
| 7185 | initiated the operation. */ |
| 7186 | |
| 7187 | void |
| 7188 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
| 7189 | { |
| 7190 | struct breakpoint *b, *b_tmp; |
| 7191 | int thread = tp->global_num; |
| 7192 | |
| 7193 | /* To avoid having to rescan all objfile symbols at every step, |
| 7194 | we maintain a list of continually-inserted but always disabled |
| 7195 | longjmp "master" breakpoints. Here, we simply create momentary |
| 7196 | clones of those and enable them for the requested thread. */ |
| 7197 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7198 | if (b->pspace == current_program_space |
| 7199 | && (b->type == bp_longjmp_master |
| 7200 | || b->type == bp_exception_master)) |
| 7201 | { |
| 7202 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
| 7203 | struct breakpoint *clone; |
| 7204 | |
| 7205 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
| 7206 | after their removal. */ |
| 7207 | clone = momentary_breakpoint_from_master (b, type, |
| 7208 | &momentary_breakpoint_ops, 1); |
| 7209 | clone->thread = thread; |
| 7210 | } |
| 7211 | |
| 7212 | tp->initiating_frame = frame; |
| 7213 | } |
| 7214 | |
| 7215 | /* Delete all longjmp breakpoints from THREAD. */ |
| 7216 | void |
| 7217 | delete_longjmp_breakpoint (int thread) |
| 7218 | { |
| 7219 | struct breakpoint *b, *b_tmp; |
| 7220 | |
| 7221 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7222 | if (b->type == bp_longjmp || b->type == bp_exception) |
| 7223 | { |
| 7224 | if (b->thread == thread) |
| 7225 | delete_breakpoint (b); |
| 7226 | } |
| 7227 | } |
| 7228 | |
| 7229 | void |
| 7230 | delete_longjmp_breakpoint_at_next_stop (int thread) |
| 7231 | { |
| 7232 | struct breakpoint *b, *b_tmp; |
| 7233 | |
| 7234 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7235 | if (b->type == bp_longjmp || b->type == bp_exception) |
| 7236 | { |
| 7237 | if (b->thread == thread) |
| 7238 | b->disposition = disp_del_at_next_stop; |
| 7239 | } |
| 7240 | } |
| 7241 | |
| 7242 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
| 7243 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return |
| 7244 | pointer to any of them. Return NULL if this system cannot place longjmp |
| 7245 | breakpoints. */ |
| 7246 | |
| 7247 | struct breakpoint * |
| 7248 | set_longjmp_breakpoint_for_call_dummy (void) |
| 7249 | { |
| 7250 | struct breakpoint *b, *retval = NULL; |
| 7251 | |
| 7252 | ALL_BREAKPOINTS (b) |
| 7253 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) |
| 7254 | { |
| 7255 | struct breakpoint *new_b; |
| 7256 | |
| 7257 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, |
| 7258 | &momentary_breakpoint_ops, |
| 7259 | 1); |
| 7260 | new_b->thread = inferior_thread ()->global_num; |
| 7261 | |
| 7262 | /* Link NEW_B into the chain of RETVAL breakpoints. */ |
| 7263 | |
| 7264 | gdb_assert (new_b->related_breakpoint == new_b); |
| 7265 | if (retval == NULL) |
| 7266 | retval = new_b; |
| 7267 | new_b->related_breakpoint = retval; |
| 7268 | while (retval->related_breakpoint != new_b->related_breakpoint) |
| 7269 | retval = retval->related_breakpoint; |
| 7270 | retval->related_breakpoint = new_b; |
| 7271 | } |
| 7272 | |
| 7273 | return retval; |
| 7274 | } |
| 7275 | |
| 7276 | /* Verify all existing dummy frames and their associated breakpoints for |
| 7277 | TP. Remove those which can no longer be found in the current frame |
| 7278 | stack. |
| 7279 | |
| 7280 | You should call this function only at places where it is safe to currently |
| 7281 | unwind the whole stack. Failed stack unwind would discard live dummy |
| 7282 | frames. */ |
| 7283 | |
| 7284 | void |
| 7285 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
| 7286 | { |
| 7287 | struct breakpoint *b, *b_tmp; |
| 7288 | |
| 7289 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7290 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
| 7291 | { |
| 7292 | struct breakpoint *dummy_b = b->related_breakpoint; |
| 7293 | |
| 7294 | while (dummy_b != b && dummy_b->type != bp_call_dummy) |
| 7295 | dummy_b = dummy_b->related_breakpoint; |
| 7296 | if (dummy_b->type != bp_call_dummy |
| 7297 | || frame_find_by_id (dummy_b->frame_id) != NULL) |
| 7298 | continue; |
| 7299 | |
| 7300 | dummy_frame_discard (dummy_b->frame_id, tp); |
| 7301 | |
| 7302 | while (b->related_breakpoint != b) |
| 7303 | { |
| 7304 | if (b_tmp == b->related_breakpoint) |
| 7305 | b_tmp = b->related_breakpoint->next; |
| 7306 | delete_breakpoint (b->related_breakpoint); |
| 7307 | } |
| 7308 | delete_breakpoint (b); |
| 7309 | } |
| 7310 | } |
| 7311 | |
| 7312 | void |
| 7313 | enable_overlay_breakpoints (void) |
| 7314 | { |
| 7315 | struct breakpoint *b; |
| 7316 | |
| 7317 | ALL_BREAKPOINTS (b) |
| 7318 | if (b->type == bp_overlay_event) |
| 7319 | { |
| 7320 | b->enable_state = bp_enabled; |
| 7321 | update_global_location_list (UGLL_MAY_INSERT); |
| 7322 | overlay_events_enabled = 1; |
| 7323 | } |
| 7324 | } |
| 7325 | |
| 7326 | void |
| 7327 | disable_overlay_breakpoints (void) |
| 7328 | { |
| 7329 | struct breakpoint *b; |
| 7330 | |
| 7331 | ALL_BREAKPOINTS (b) |
| 7332 | if (b->type == bp_overlay_event) |
| 7333 | { |
| 7334 | b->enable_state = bp_disabled; |
| 7335 | update_global_location_list (UGLL_DONT_INSERT); |
| 7336 | overlay_events_enabled = 0; |
| 7337 | } |
| 7338 | } |
| 7339 | |
| 7340 | /* Set an active std::terminate breakpoint for each std::terminate |
| 7341 | master breakpoint. */ |
| 7342 | void |
| 7343 | set_std_terminate_breakpoint (void) |
| 7344 | { |
| 7345 | struct breakpoint *b, *b_tmp; |
| 7346 | |
| 7347 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7348 | if (b->pspace == current_program_space |
| 7349 | && b->type == bp_std_terminate_master) |
| 7350 | { |
| 7351 | momentary_breakpoint_from_master (b, bp_std_terminate, |
| 7352 | &momentary_breakpoint_ops, 1); |
| 7353 | } |
| 7354 | } |
| 7355 | |
| 7356 | /* Delete all the std::terminate breakpoints. */ |
| 7357 | void |
| 7358 | delete_std_terminate_breakpoint (void) |
| 7359 | { |
| 7360 | struct breakpoint *b, *b_tmp; |
| 7361 | |
| 7362 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7363 | if (b->type == bp_std_terminate) |
| 7364 | delete_breakpoint (b); |
| 7365 | } |
| 7366 | |
| 7367 | struct breakpoint * |
| 7368 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7369 | { |
| 7370 | struct breakpoint *b; |
| 7371 | |
| 7372 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
| 7373 | &internal_breakpoint_ops); |
| 7374 | |
| 7375 | b->enable_state = bp_enabled; |
| 7376 | /* location has to be used or breakpoint_re_set will delete me. */ |
| 7377 | b->location = new_address_location (b->loc->address, NULL, 0); |
| 7378 | |
| 7379 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 7380 | |
| 7381 | return b; |
| 7382 | } |
| 7383 | |
| 7384 | struct lang_and_radix |
| 7385 | { |
| 7386 | enum language lang; |
| 7387 | int radix; |
| 7388 | }; |
| 7389 | |
| 7390 | /* Create a breakpoint for JIT code registration and unregistration. */ |
| 7391 | |
| 7392 | struct breakpoint * |
| 7393 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7394 | { |
| 7395 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
| 7396 | &internal_breakpoint_ops); |
| 7397 | } |
| 7398 | |
| 7399 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
| 7400 | |
| 7401 | void |
| 7402 | remove_jit_event_breakpoints (void) |
| 7403 | { |
| 7404 | struct breakpoint *b, *b_tmp; |
| 7405 | |
| 7406 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7407 | if (b->type == bp_jit_event |
| 7408 | && b->loc->pspace == current_program_space) |
| 7409 | delete_breakpoint (b); |
| 7410 | } |
| 7411 | |
| 7412 | void |
| 7413 | remove_solib_event_breakpoints (void) |
| 7414 | { |
| 7415 | struct breakpoint *b, *b_tmp; |
| 7416 | |
| 7417 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7418 | if (b->type == bp_shlib_event |
| 7419 | && b->loc->pspace == current_program_space) |
| 7420 | delete_breakpoint (b); |
| 7421 | } |
| 7422 | |
| 7423 | /* See breakpoint.h. */ |
| 7424 | |
| 7425 | void |
| 7426 | remove_solib_event_breakpoints_at_next_stop (void) |
| 7427 | { |
| 7428 | struct breakpoint *b, *b_tmp; |
| 7429 | |
| 7430 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7431 | if (b->type == bp_shlib_event |
| 7432 | && b->loc->pspace == current_program_space) |
| 7433 | b->disposition = disp_del_at_next_stop; |
| 7434 | } |
| 7435 | |
| 7436 | /* Helper for create_solib_event_breakpoint / |
| 7437 | create_and_insert_solib_event_breakpoint. Allows specifying which |
| 7438 | INSERT_MODE to pass through to update_global_location_list. */ |
| 7439 | |
| 7440 | static struct breakpoint * |
| 7441 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, |
| 7442 | enum ugll_insert_mode insert_mode) |
| 7443 | { |
| 7444 | struct breakpoint *b; |
| 7445 | |
| 7446 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
| 7447 | &internal_breakpoint_ops); |
| 7448 | update_global_location_list_nothrow (insert_mode); |
| 7449 | return b; |
| 7450 | } |
| 7451 | |
| 7452 | struct breakpoint * |
| 7453 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7454 | { |
| 7455 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); |
| 7456 | } |
| 7457 | |
| 7458 | /* See breakpoint.h. */ |
| 7459 | |
| 7460 | struct breakpoint * |
| 7461 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7462 | { |
| 7463 | struct breakpoint *b; |
| 7464 | |
| 7465 | /* Explicitly tell update_global_location_list to insert |
| 7466 | locations. */ |
| 7467 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); |
| 7468 | if (!b->loc->inserted) |
| 7469 | { |
| 7470 | delete_breakpoint (b); |
| 7471 | return NULL; |
| 7472 | } |
| 7473 | return b; |
| 7474 | } |
| 7475 | |
| 7476 | /* Disable any breakpoints that are on code in shared libraries. Only |
| 7477 | apply to enabled breakpoints, disabled ones can just stay disabled. */ |
| 7478 | |
| 7479 | void |
| 7480 | disable_breakpoints_in_shlibs (void) |
| 7481 | { |
| 7482 | struct bp_location *loc, **locp_tmp; |
| 7483 | |
| 7484 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 7485 | { |
| 7486 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 7487 | struct breakpoint *b = loc->owner; |
| 7488 | |
| 7489 | /* We apply the check to all breakpoints, including disabled for |
| 7490 | those with loc->duplicate set. This is so that when breakpoint |
| 7491 | becomes enabled, or the duplicate is removed, gdb will try to |
| 7492 | insert all breakpoints. If we don't set shlib_disabled here, |
| 7493 | we'll try to insert those breakpoints and fail. */ |
| 7494 | if (((b->type == bp_breakpoint) |
| 7495 | || (b->type == bp_jit_event) |
| 7496 | || (b->type == bp_hardware_breakpoint) |
| 7497 | || (is_tracepoint (b))) |
| 7498 | && loc->pspace == current_program_space |
| 7499 | && !loc->shlib_disabled |
| 7500 | && solib_name_from_address (loc->pspace, loc->address) |
| 7501 | ) |
| 7502 | { |
| 7503 | loc->shlib_disabled = 1; |
| 7504 | } |
| 7505 | } |
| 7506 | } |
| 7507 | |
| 7508 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
| 7509 | notification of unloaded_shlib. Only apply to enabled breakpoints, |
| 7510 | disabled ones can just stay disabled. */ |
| 7511 | |
| 7512 | static void |
| 7513 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
| 7514 | { |
| 7515 | struct bp_location *loc, **locp_tmp; |
| 7516 | int disabled_shlib_breaks = 0; |
| 7517 | |
| 7518 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 7519 | { |
| 7520 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 7521 | struct breakpoint *b = loc->owner; |
| 7522 | |
| 7523 | if (solib->pspace == loc->pspace |
| 7524 | && !loc->shlib_disabled |
| 7525 | && (((b->type == bp_breakpoint |
| 7526 | || b->type == bp_jit_event |
| 7527 | || b->type == bp_hardware_breakpoint) |
| 7528 | && (loc->loc_type == bp_loc_hardware_breakpoint |
| 7529 | || loc->loc_type == bp_loc_software_breakpoint)) |
| 7530 | || is_tracepoint (b)) |
| 7531 | && solib_contains_address_p (solib, loc->address)) |
| 7532 | { |
| 7533 | loc->shlib_disabled = 1; |
| 7534 | /* At this point, we cannot rely on remove_breakpoint |
| 7535 | succeeding so we must mark the breakpoint as not inserted |
| 7536 | to prevent future errors occurring in remove_breakpoints. */ |
| 7537 | loc->inserted = 0; |
| 7538 | |
| 7539 | /* This may cause duplicate notifications for the same breakpoint. */ |
| 7540 | gdb::observers::breakpoint_modified.notify (b); |
| 7541 | |
| 7542 | if (!disabled_shlib_breaks) |
| 7543 | { |
| 7544 | target_terminal::ours_for_output (); |
| 7545 | warning (_("Temporarily disabling breakpoints " |
| 7546 | "for unloaded shared library \"%s\""), |
| 7547 | solib->so_name); |
| 7548 | } |
| 7549 | disabled_shlib_breaks = 1; |
| 7550 | } |
| 7551 | } |
| 7552 | } |
| 7553 | |
| 7554 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
| 7555 | notification of free_objfile. Only apply to enabled breakpoints, |
| 7556 | disabled ones can just stay disabled. */ |
| 7557 | |
| 7558 | static void |
| 7559 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) |
| 7560 | { |
| 7561 | struct breakpoint *b; |
| 7562 | |
| 7563 | if (objfile == NULL) |
| 7564 | return; |
| 7565 | |
| 7566 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
| 7567 | managed by the user with add-symbol-file/remove-symbol-file. |
| 7568 | Similarly to how breakpoints in shared libraries are handled in |
| 7569 | response to "nosharedlibrary", mark breakpoints in such modules |
| 7570 | shlib_disabled so they end up uninserted on the next global |
| 7571 | location list update. Shared libraries not loaded by the user |
| 7572 | aren't handled here -- they're already handled in |
| 7573 | disable_breakpoints_in_unloaded_shlib, called by solib.c's |
| 7574 | solib_unloaded observer. We skip objfiles that are not |
| 7575 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
| 7576 | main objfile). */ |
| 7577 | if ((objfile->flags & OBJF_SHARED) == 0 |
| 7578 | || (objfile->flags & OBJF_USERLOADED) == 0) |
| 7579 | return; |
| 7580 | |
| 7581 | ALL_BREAKPOINTS (b) |
| 7582 | { |
| 7583 | struct bp_location *loc; |
| 7584 | int bp_modified = 0; |
| 7585 | |
| 7586 | if (!is_breakpoint (b) && !is_tracepoint (b)) |
| 7587 | continue; |
| 7588 | |
| 7589 | for (loc = b->loc; loc != NULL; loc = loc->next) |
| 7590 | { |
| 7591 | CORE_ADDR loc_addr = loc->address; |
| 7592 | |
| 7593 | if (loc->loc_type != bp_loc_hardware_breakpoint |
| 7594 | && loc->loc_type != bp_loc_software_breakpoint) |
| 7595 | continue; |
| 7596 | |
| 7597 | if (loc->shlib_disabled != 0) |
| 7598 | continue; |
| 7599 | |
| 7600 | if (objfile->pspace != loc->pspace) |
| 7601 | continue; |
| 7602 | |
| 7603 | if (loc->loc_type != bp_loc_hardware_breakpoint |
| 7604 | && loc->loc_type != bp_loc_software_breakpoint) |
| 7605 | continue; |
| 7606 | |
| 7607 | if (is_addr_in_objfile (loc_addr, objfile)) |
| 7608 | { |
| 7609 | loc->shlib_disabled = 1; |
| 7610 | /* At this point, we don't know whether the object was |
| 7611 | unmapped from the inferior or not, so leave the |
| 7612 | inserted flag alone. We'll handle failure to |
| 7613 | uninsert quietly, in case the object was indeed |
| 7614 | unmapped. */ |
| 7615 | |
| 7616 | mark_breakpoint_location_modified (loc); |
| 7617 | |
| 7618 | bp_modified = 1; |
| 7619 | } |
| 7620 | } |
| 7621 | |
| 7622 | if (bp_modified) |
| 7623 | gdb::observers::breakpoint_modified.notify (b); |
| 7624 | } |
| 7625 | } |
| 7626 | |
| 7627 | /* FORK & VFORK catchpoints. */ |
| 7628 | |
| 7629 | /* An instance of this type is used to represent a fork or vfork |
| 7630 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
| 7631 | to CATCH_FORK_BREAKPOINT_OPS. */ |
| 7632 | |
| 7633 | struct fork_catchpoint : public breakpoint |
| 7634 | { |
| 7635 | /* Process id of a child process whose forking triggered this |
| 7636 | catchpoint. This field is only valid immediately after this |
| 7637 | catchpoint has triggered. */ |
| 7638 | ptid_t forked_inferior_pid; |
| 7639 | }; |
| 7640 | |
| 7641 | /* Implement the "insert" breakpoint_ops method for fork |
| 7642 | catchpoints. */ |
| 7643 | |
| 7644 | static int |
| 7645 | insert_catch_fork (struct bp_location *bl) |
| 7646 | { |
| 7647 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
| 7648 | } |
| 7649 | |
| 7650 | /* Implement the "remove" breakpoint_ops method for fork |
| 7651 | catchpoints. */ |
| 7652 | |
| 7653 | static int |
| 7654 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
| 7655 | { |
| 7656 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
| 7657 | } |
| 7658 | |
| 7659 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork |
| 7660 | catchpoints. */ |
| 7661 | |
| 7662 | static int |
| 7663 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
| 7664 | const address_space *aspace, CORE_ADDR bp_addr, |
| 7665 | const struct target_waitstatus *ws) |
| 7666 | { |
| 7667 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
| 7668 | |
| 7669 | if (ws->kind != TARGET_WAITKIND_FORKED) |
| 7670 | return 0; |
| 7671 | |
| 7672 | c->forked_inferior_pid = ws->value.related_pid; |
| 7673 | return 1; |
| 7674 | } |
| 7675 | |
| 7676 | /* Implement the "print_it" breakpoint_ops method for fork |
| 7677 | catchpoints. */ |
| 7678 | |
| 7679 | static enum print_stop_action |
| 7680 | print_it_catch_fork (bpstat bs) |
| 7681 | { |
| 7682 | struct ui_out *uiout = current_uiout; |
| 7683 | struct breakpoint *b = bs->breakpoint_at; |
| 7684 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; |
| 7685 | |
| 7686 | annotate_catchpoint (b->number); |
| 7687 | maybe_print_thread_hit_breakpoint (uiout); |
| 7688 | if (b->disposition == disp_del) |
| 7689 | uiout->text ("Temporary catchpoint "); |
| 7690 | else |
| 7691 | uiout->text ("Catchpoint "); |
| 7692 | if (uiout->is_mi_like_p ()) |
| 7693 | { |
| 7694 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
| 7695 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 7696 | } |
| 7697 | uiout->field_signed ("bkptno", b->number); |
| 7698 | uiout->text (" (forked process "); |
| 7699 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
| 7700 | uiout->text ("), "); |
| 7701 | return PRINT_SRC_AND_LOC; |
| 7702 | } |
| 7703 | |
| 7704 | /* Implement the "print_one" breakpoint_ops method for fork |
| 7705 | catchpoints. */ |
| 7706 | |
| 7707 | static void |
| 7708 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
| 7709 | { |
| 7710 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 7711 | struct value_print_options opts; |
| 7712 | struct ui_out *uiout = current_uiout; |
| 7713 | |
| 7714 | get_user_print_options (&opts); |
| 7715 | |
| 7716 | /* Field 4, the address, is omitted (which makes the columns not |
| 7717 | line up too nicely with the headers, but the effect is relatively |
| 7718 | readable). */ |
| 7719 | if (opts.addressprint) |
| 7720 | uiout->field_skip ("addr"); |
| 7721 | annotate_field (5); |
| 7722 | uiout->text ("fork"); |
| 7723 | if (c->forked_inferior_pid != null_ptid) |
| 7724 | { |
| 7725 | uiout->text (", process "); |
| 7726 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
| 7727 | uiout->spaces (1); |
| 7728 | } |
| 7729 | |
| 7730 | if (uiout->is_mi_like_p ()) |
| 7731 | uiout->field_string ("catch-type", "fork"); |
| 7732 | } |
| 7733 | |
| 7734 | /* Implement the "print_mention" breakpoint_ops method for fork |
| 7735 | catchpoints. */ |
| 7736 | |
| 7737 | static void |
| 7738 | print_mention_catch_fork (struct breakpoint *b) |
| 7739 | { |
| 7740 | printf_filtered (_("Catchpoint %d (fork)"), b->number); |
| 7741 | } |
| 7742 | |
| 7743 | /* Implement the "print_recreate" breakpoint_ops method for fork |
| 7744 | catchpoints. */ |
| 7745 | |
| 7746 | static void |
| 7747 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) |
| 7748 | { |
| 7749 | fprintf_unfiltered (fp, "catch fork"); |
| 7750 | print_recreate_thread (b, fp); |
| 7751 | } |
| 7752 | |
| 7753 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
| 7754 | |
| 7755 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
| 7756 | |
| 7757 | /* Implement the "insert" breakpoint_ops method for vfork |
| 7758 | catchpoints. */ |
| 7759 | |
| 7760 | static int |
| 7761 | insert_catch_vfork (struct bp_location *bl) |
| 7762 | { |
| 7763 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
| 7764 | } |
| 7765 | |
| 7766 | /* Implement the "remove" breakpoint_ops method for vfork |
| 7767 | catchpoints. */ |
| 7768 | |
| 7769 | static int |
| 7770 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
| 7771 | { |
| 7772 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
| 7773 | } |
| 7774 | |
| 7775 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork |
| 7776 | catchpoints. */ |
| 7777 | |
| 7778 | static int |
| 7779 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
| 7780 | const address_space *aspace, CORE_ADDR bp_addr, |
| 7781 | const struct target_waitstatus *ws) |
| 7782 | { |
| 7783 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
| 7784 | |
| 7785 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
| 7786 | return 0; |
| 7787 | |
| 7788 | c->forked_inferior_pid = ws->value.related_pid; |
| 7789 | return 1; |
| 7790 | } |
| 7791 | |
| 7792 | /* Implement the "print_it" breakpoint_ops method for vfork |
| 7793 | catchpoints. */ |
| 7794 | |
| 7795 | static enum print_stop_action |
| 7796 | print_it_catch_vfork (bpstat bs) |
| 7797 | { |
| 7798 | struct ui_out *uiout = current_uiout; |
| 7799 | struct breakpoint *b = bs->breakpoint_at; |
| 7800 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 7801 | |
| 7802 | annotate_catchpoint (b->number); |
| 7803 | maybe_print_thread_hit_breakpoint (uiout); |
| 7804 | if (b->disposition == disp_del) |
| 7805 | uiout->text ("Temporary catchpoint "); |
| 7806 | else |
| 7807 | uiout->text ("Catchpoint "); |
| 7808 | if (uiout->is_mi_like_p ()) |
| 7809 | { |
| 7810 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
| 7811 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 7812 | } |
| 7813 | uiout->field_signed ("bkptno", b->number); |
| 7814 | uiout->text (" (vforked process "); |
| 7815 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
| 7816 | uiout->text ("), "); |
| 7817 | return PRINT_SRC_AND_LOC; |
| 7818 | } |
| 7819 | |
| 7820 | /* Implement the "print_one" breakpoint_ops method for vfork |
| 7821 | catchpoints. */ |
| 7822 | |
| 7823 | static void |
| 7824 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
| 7825 | { |
| 7826 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 7827 | struct value_print_options opts; |
| 7828 | struct ui_out *uiout = current_uiout; |
| 7829 | |
| 7830 | get_user_print_options (&opts); |
| 7831 | /* Field 4, the address, is omitted (which makes the columns not |
| 7832 | line up too nicely with the headers, but the effect is relatively |
| 7833 | readable). */ |
| 7834 | if (opts.addressprint) |
| 7835 | uiout->field_skip ("addr"); |
| 7836 | annotate_field (5); |
| 7837 | uiout->text ("vfork"); |
| 7838 | if (c->forked_inferior_pid != null_ptid) |
| 7839 | { |
| 7840 | uiout->text (", process "); |
| 7841 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
| 7842 | uiout->spaces (1); |
| 7843 | } |
| 7844 | |
| 7845 | if (uiout->is_mi_like_p ()) |
| 7846 | uiout->field_string ("catch-type", "vfork"); |
| 7847 | } |
| 7848 | |
| 7849 | /* Implement the "print_mention" breakpoint_ops method for vfork |
| 7850 | catchpoints. */ |
| 7851 | |
| 7852 | static void |
| 7853 | print_mention_catch_vfork (struct breakpoint *b) |
| 7854 | { |
| 7855 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); |
| 7856 | } |
| 7857 | |
| 7858 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
| 7859 | catchpoints. */ |
| 7860 | |
| 7861 | static void |
| 7862 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) |
| 7863 | { |
| 7864 | fprintf_unfiltered (fp, "catch vfork"); |
| 7865 | print_recreate_thread (b, fp); |
| 7866 | } |
| 7867 | |
| 7868 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
| 7869 | |
| 7870 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
| 7871 | |
| 7872 | /* An instance of this type is used to represent an solib catchpoint. |
| 7873 | A breakpoint is really of this type iff its ops pointer points to |
| 7874 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
| 7875 | |
| 7876 | struct solib_catchpoint : public breakpoint |
| 7877 | { |
| 7878 | ~solib_catchpoint () override; |
| 7879 | |
| 7880 | /* True for "catch load", false for "catch unload". */ |
| 7881 | unsigned char is_load; |
| 7882 | |
| 7883 | /* Regular expression to match, if any. COMPILED is only valid when |
| 7884 | REGEX is non-NULL. */ |
| 7885 | char *regex; |
| 7886 | std::unique_ptr<compiled_regex> compiled; |
| 7887 | }; |
| 7888 | |
| 7889 | solib_catchpoint::~solib_catchpoint () |
| 7890 | { |
| 7891 | xfree (this->regex); |
| 7892 | } |
| 7893 | |
| 7894 | static int |
| 7895 | insert_catch_solib (struct bp_location *ignore) |
| 7896 | { |
| 7897 | return 0; |
| 7898 | } |
| 7899 | |
| 7900 | static int |
| 7901 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
| 7902 | { |
| 7903 | return 0; |
| 7904 | } |
| 7905 | |
| 7906 | static int |
| 7907 | breakpoint_hit_catch_solib (const struct bp_location *bl, |
| 7908 | const address_space *aspace, |
| 7909 | CORE_ADDR bp_addr, |
| 7910 | const struct target_waitstatus *ws) |
| 7911 | { |
| 7912 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; |
| 7913 | struct breakpoint *other; |
| 7914 | |
| 7915 | if (ws->kind == TARGET_WAITKIND_LOADED) |
| 7916 | return 1; |
| 7917 | |
| 7918 | ALL_BREAKPOINTS (other) |
| 7919 | { |
| 7920 | struct bp_location *other_bl; |
| 7921 | |
| 7922 | if (other == bl->owner) |
| 7923 | continue; |
| 7924 | |
| 7925 | if (other->type != bp_shlib_event) |
| 7926 | continue; |
| 7927 | |
| 7928 | if (self->pspace != NULL && other->pspace != self->pspace) |
| 7929 | continue; |
| 7930 | |
| 7931 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) |
| 7932 | { |
| 7933 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) |
| 7934 | return 1; |
| 7935 | } |
| 7936 | } |
| 7937 | |
| 7938 | return 0; |
| 7939 | } |
| 7940 | |
| 7941 | static void |
| 7942 | check_status_catch_solib (struct bpstats *bs) |
| 7943 | { |
| 7944 | struct solib_catchpoint *self |
| 7945 | = (struct solib_catchpoint *) bs->breakpoint_at; |
| 7946 | |
| 7947 | if (self->is_load) |
| 7948 | { |
| 7949 | for (so_list *iter : current_program_space->added_solibs) |
| 7950 | { |
| 7951 | if (!self->regex |
| 7952 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
| 7953 | return; |
| 7954 | } |
| 7955 | } |
| 7956 | else |
| 7957 | { |
| 7958 | for (const std::string &iter : current_program_space->deleted_solibs) |
| 7959 | { |
| 7960 | if (!self->regex |
| 7961 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
| 7962 | return; |
| 7963 | } |
| 7964 | } |
| 7965 | |
| 7966 | bs->stop = 0; |
| 7967 | bs->print_it = print_it_noop; |
| 7968 | } |
| 7969 | |
| 7970 | static enum print_stop_action |
| 7971 | print_it_catch_solib (bpstat bs) |
| 7972 | { |
| 7973 | struct breakpoint *b = bs->breakpoint_at; |
| 7974 | struct ui_out *uiout = current_uiout; |
| 7975 | |
| 7976 | annotate_catchpoint (b->number); |
| 7977 | maybe_print_thread_hit_breakpoint (uiout); |
| 7978 | if (b->disposition == disp_del) |
| 7979 | uiout->text ("Temporary catchpoint "); |
| 7980 | else |
| 7981 | uiout->text ("Catchpoint "); |
| 7982 | uiout->field_signed ("bkptno", b->number); |
| 7983 | uiout->text ("\n"); |
| 7984 | if (uiout->is_mi_like_p ()) |
| 7985 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 7986 | print_solib_event (1); |
| 7987 | return PRINT_SRC_AND_LOC; |
| 7988 | } |
| 7989 | |
| 7990 | static void |
| 7991 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) |
| 7992 | { |
| 7993 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 7994 | struct value_print_options opts; |
| 7995 | struct ui_out *uiout = current_uiout; |
| 7996 | |
| 7997 | get_user_print_options (&opts); |
| 7998 | /* Field 4, the address, is omitted (which makes the columns not |
| 7999 | line up too nicely with the headers, but the effect is relatively |
| 8000 | readable). */ |
| 8001 | if (opts.addressprint) |
| 8002 | { |
| 8003 | annotate_field (4); |
| 8004 | uiout->field_skip ("addr"); |
| 8005 | } |
| 8006 | |
| 8007 | std::string msg; |
| 8008 | annotate_field (5); |
| 8009 | if (self->is_load) |
| 8010 | { |
| 8011 | if (self->regex) |
| 8012 | msg = string_printf (_("load of library matching %s"), self->regex); |
| 8013 | else |
| 8014 | msg = _("load of library"); |
| 8015 | } |
| 8016 | else |
| 8017 | { |
| 8018 | if (self->regex) |
| 8019 | msg = string_printf (_("unload of library matching %s"), self->regex); |
| 8020 | else |
| 8021 | msg = _("unload of library"); |
| 8022 | } |
| 8023 | uiout->field_string ("what", msg); |
| 8024 | |
| 8025 | if (uiout->is_mi_like_p ()) |
| 8026 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); |
| 8027 | } |
| 8028 | |
| 8029 | static void |
| 8030 | print_mention_catch_solib (struct breakpoint *b) |
| 8031 | { |
| 8032 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8033 | |
| 8034 | printf_filtered (_("Catchpoint %d (%s)"), b->number, |
| 8035 | self->is_load ? "load" : "unload"); |
| 8036 | } |
| 8037 | |
| 8038 | static void |
| 8039 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) |
| 8040 | { |
| 8041 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8042 | |
| 8043 | fprintf_unfiltered (fp, "%s %s", |
| 8044 | b->disposition == disp_del ? "tcatch" : "catch", |
| 8045 | self->is_load ? "load" : "unload"); |
| 8046 | if (self->regex) |
| 8047 | fprintf_unfiltered (fp, " %s", self->regex); |
| 8048 | fprintf_unfiltered (fp, "\n"); |
| 8049 | } |
| 8050 | |
| 8051 | static struct breakpoint_ops catch_solib_breakpoint_ops; |
| 8052 | |
| 8053 | /* Shared helper function (MI and CLI) for creating and installing |
| 8054 | a shared object event catchpoint. If IS_LOAD is non-zero then |
| 8055 | the events to be caught are load events, otherwise they are |
| 8056 | unload events. If IS_TEMP is non-zero the catchpoint is a |
| 8057 | temporary one. If ENABLED is non-zero the catchpoint is |
| 8058 | created in an enabled state. */ |
| 8059 | |
| 8060 | void |
| 8061 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
| 8062 | { |
| 8063 | struct gdbarch *gdbarch = get_current_arch (); |
| 8064 | |
| 8065 | if (!arg) |
| 8066 | arg = ""; |
| 8067 | arg = skip_spaces (arg); |
| 8068 | |
| 8069 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
| 8070 | |
| 8071 | if (*arg != '\0') |
| 8072 | { |
| 8073 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
| 8074 | _("Invalid regexp"))); |
| 8075 | c->regex = xstrdup (arg); |
| 8076 | } |
| 8077 | |
| 8078 | c->is_load = is_load; |
| 8079 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
| 8080 | &catch_solib_breakpoint_ops); |
| 8081 | |
| 8082 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
| 8083 | |
| 8084 | install_breakpoint (0, std::move (c), 1); |
| 8085 | } |
| 8086 | |
| 8087 | /* A helper function that does all the work for "catch load" and |
| 8088 | "catch unload". */ |
| 8089 | |
| 8090 | static void |
| 8091 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
| 8092 | struct cmd_list_element *command) |
| 8093 | { |
| 8094 | int tempflag; |
| 8095 | const int enabled = 1; |
| 8096 | |
| 8097 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8098 | |
| 8099 | add_solib_catchpoint (arg, is_load, tempflag, enabled); |
| 8100 | } |
| 8101 | |
| 8102 | static void |
| 8103 | catch_load_command_1 (const char *arg, int from_tty, |
| 8104 | struct cmd_list_element *command) |
| 8105 | { |
| 8106 | catch_load_or_unload (arg, from_tty, 1, command); |
| 8107 | } |
| 8108 | |
| 8109 | static void |
| 8110 | catch_unload_command_1 (const char *arg, int from_tty, |
| 8111 | struct cmd_list_element *command) |
| 8112 | { |
| 8113 | catch_load_or_unload (arg, from_tty, 0, command); |
| 8114 | } |
| 8115 | |
| 8116 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
| 8117 | is non-zero, then make the breakpoint temporary. If COND_STRING is |
| 8118 | not NULL, then store it in the breakpoint. OPS, if not NULL, is |
| 8119 | the breakpoint_ops structure associated to the catchpoint. */ |
| 8120 | |
| 8121 | void |
| 8122 | init_catchpoint (struct breakpoint *b, |
| 8123 | struct gdbarch *gdbarch, int tempflag, |
| 8124 | const char *cond_string, |
| 8125 | const struct breakpoint_ops *ops) |
| 8126 | { |
| 8127 | symtab_and_line sal; |
| 8128 | sal.pspace = current_program_space; |
| 8129 | |
| 8130 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
| 8131 | |
| 8132 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
| 8133 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 8134 | } |
| 8135 | |
| 8136 | void |
| 8137 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
| 8138 | { |
| 8139 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
| 8140 | set_breakpoint_number (internal, b); |
| 8141 | if (is_tracepoint (b)) |
| 8142 | set_tracepoint_count (breakpoint_count); |
| 8143 | if (!internal) |
| 8144 | mention (b); |
| 8145 | gdb::observers::breakpoint_created.notify (b); |
| 8146 | |
| 8147 | if (update_gll) |
| 8148 | update_global_location_list (UGLL_MAY_INSERT); |
| 8149 | } |
| 8150 | |
| 8151 | static void |
| 8152 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
| 8153 | int tempflag, const char *cond_string, |
| 8154 | const struct breakpoint_ops *ops) |
| 8155 | { |
| 8156 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
| 8157 | |
| 8158 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
| 8159 | |
| 8160 | c->forked_inferior_pid = null_ptid; |
| 8161 | |
| 8162 | install_breakpoint (0, std::move (c), 1); |
| 8163 | } |
| 8164 | |
| 8165 | /* Exec catchpoints. */ |
| 8166 | |
| 8167 | /* An instance of this type is used to represent an exec catchpoint. |
| 8168 | A breakpoint is really of this type iff its ops pointer points to |
| 8169 | CATCH_EXEC_BREAKPOINT_OPS. */ |
| 8170 | |
| 8171 | struct exec_catchpoint : public breakpoint |
| 8172 | { |
| 8173 | ~exec_catchpoint () override; |
| 8174 | |
| 8175 | /* Filename of a program whose exec triggered this catchpoint. |
| 8176 | This field is only valid immediately after this catchpoint has |
| 8177 | triggered. */ |
| 8178 | char *exec_pathname; |
| 8179 | }; |
| 8180 | |
| 8181 | /* Exec catchpoint destructor. */ |
| 8182 | |
| 8183 | exec_catchpoint::~exec_catchpoint () |
| 8184 | { |
| 8185 | xfree (this->exec_pathname); |
| 8186 | } |
| 8187 | |
| 8188 | static int |
| 8189 | insert_catch_exec (struct bp_location *bl) |
| 8190 | { |
| 8191 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
| 8192 | } |
| 8193 | |
| 8194 | static int |
| 8195 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
| 8196 | { |
| 8197 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
| 8198 | } |
| 8199 | |
| 8200 | static int |
| 8201 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
| 8202 | const address_space *aspace, CORE_ADDR bp_addr, |
| 8203 | const struct target_waitstatus *ws) |
| 8204 | { |
| 8205 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
| 8206 | |
| 8207 | if (ws->kind != TARGET_WAITKIND_EXECD) |
| 8208 | return 0; |
| 8209 | |
| 8210 | c->exec_pathname = xstrdup (ws->value.execd_pathname); |
| 8211 | return 1; |
| 8212 | } |
| 8213 | |
| 8214 | static enum print_stop_action |
| 8215 | print_it_catch_exec (bpstat bs) |
| 8216 | { |
| 8217 | struct ui_out *uiout = current_uiout; |
| 8218 | struct breakpoint *b = bs->breakpoint_at; |
| 8219 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8220 | |
| 8221 | annotate_catchpoint (b->number); |
| 8222 | maybe_print_thread_hit_breakpoint (uiout); |
| 8223 | if (b->disposition == disp_del) |
| 8224 | uiout->text ("Temporary catchpoint "); |
| 8225 | else |
| 8226 | uiout->text ("Catchpoint "); |
| 8227 | if (uiout->is_mi_like_p ()) |
| 8228 | { |
| 8229 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
| 8230 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 8231 | } |
| 8232 | uiout->field_signed ("bkptno", b->number); |
| 8233 | uiout->text (" (exec'd "); |
| 8234 | uiout->field_string ("new-exec", c->exec_pathname); |
| 8235 | uiout->text ("), "); |
| 8236 | |
| 8237 | return PRINT_SRC_AND_LOC; |
| 8238 | } |
| 8239 | |
| 8240 | static void |
| 8241 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
| 8242 | { |
| 8243 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8244 | struct value_print_options opts; |
| 8245 | struct ui_out *uiout = current_uiout; |
| 8246 | |
| 8247 | get_user_print_options (&opts); |
| 8248 | |
| 8249 | /* Field 4, the address, is omitted (which makes the columns |
| 8250 | not line up too nicely with the headers, but the effect |
| 8251 | is relatively readable). */ |
| 8252 | if (opts.addressprint) |
| 8253 | uiout->field_skip ("addr"); |
| 8254 | annotate_field (5); |
| 8255 | uiout->text ("exec"); |
| 8256 | if (c->exec_pathname != NULL) |
| 8257 | { |
| 8258 | uiout->text (", program \""); |
| 8259 | uiout->field_string ("what", c->exec_pathname); |
| 8260 | uiout->text ("\" "); |
| 8261 | } |
| 8262 | |
| 8263 | if (uiout->is_mi_like_p ()) |
| 8264 | uiout->field_string ("catch-type", "exec"); |
| 8265 | } |
| 8266 | |
| 8267 | static void |
| 8268 | print_mention_catch_exec (struct breakpoint *b) |
| 8269 | { |
| 8270 | printf_filtered (_("Catchpoint %d (exec)"), b->number); |
| 8271 | } |
| 8272 | |
| 8273 | /* Implement the "print_recreate" breakpoint_ops method for exec |
| 8274 | catchpoints. */ |
| 8275 | |
| 8276 | static void |
| 8277 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) |
| 8278 | { |
| 8279 | fprintf_unfiltered (fp, "catch exec"); |
| 8280 | print_recreate_thread (b, fp); |
| 8281 | } |
| 8282 | |
| 8283 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
| 8284 | |
| 8285 | static int |
| 8286 | hw_breakpoint_used_count (void) |
| 8287 | { |
| 8288 | int i = 0; |
| 8289 | struct breakpoint *b; |
| 8290 | struct bp_location *bl; |
| 8291 | |
| 8292 | ALL_BREAKPOINTS (b) |
| 8293 | { |
| 8294 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
| 8295 | for (bl = b->loc; bl; bl = bl->next) |
| 8296 | { |
| 8297 | /* Special types of hardware breakpoints may use more than |
| 8298 | one register. */ |
| 8299 | i += b->ops->resources_needed (bl); |
| 8300 | } |
| 8301 | } |
| 8302 | |
| 8303 | return i; |
| 8304 | } |
| 8305 | |
| 8306 | /* Returns the resources B would use if it were a hardware |
| 8307 | watchpoint. */ |
| 8308 | |
| 8309 | static int |
| 8310 | hw_watchpoint_use_count (struct breakpoint *b) |
| 8311 | { |
| 8312 | int i = 0; |
| 8313 | struct bp_location *bl; |
| 8314 | |
| 8315 | if (!breakpoint_enabled (b)) |
| 8316 | return 0; |
| 8317 | |
| 8318 | for (bl = b->loc; bl; bl = bl->next) |
| 8319 | { |
| 8320 | /* Special types of hardware watchpoints may use more than |
| 8321 | one register. */ |
| 8322 | i += b->ops->resources_needed (bl); |
| 8323 | } |
| 8324 | |
| 8325 | return i; |
| 8326 | } |
| 8327 | |
| 8328 | /* Returns the sum the used resources of all hardware watchpoints of |
| 8329 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED |
| 8330 | the sum of the used resources of all hardware watchpoints of other |
| 8331 | types _not_ TYPE. */ |
| 8332 | |
| 8333 | static int |
| 8334 | hw_watchpoint_used_count_others (struct breakpoint *except, |
| 8335 | enum bptype type, int *other_type_used) |
| 8336 | { |
| 8337 | int i = 0; |
| 8338 | struct breakpoint *b; |
| 8339 | |
| 8340 | *other_type_used = 0; |
| 8341 | ALL_BREAKPOINTS (b) |
| 8342 | { |
| 8343 | if (b == except) |
| 8344 | continue; |
| 8345 | if (!breakpoint_enabled (b)) |
| 8346 | continue; |
| 8347 | |
| 8348 | if (b->type == type) |
| 8349 | i += hw_watchpoint_use_count (b); |
| 8350 | else if (is_hardware_watchpoint (b)) |
| 8351 | *other_type_used = 1; |
| 8352 | } |
| 8353 | |
| 8354 | return i; |
| 8355 | } |
| 8356 | |
| 8357 | void |
| 8358 | disable_watchpoints_before_interactive_call_start (void) |
| 8359 | { |
| 8360 | struct breakpoint *b; |
| 8361 | |
| 8362 | ALL_BREAKPOINTS (b) |
| 8363 | { |
| 8364 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
| 8365 | { |
| 8366 | b->enable_state = bp_call_disabled; |
| 8367 | update_global_location_list (UGLL_DONT_INSERT); |
| 8368 | } |
| 8369 | } |
| 8370 | } |
| 8371 | |
| 8372 | void |
| 8373 | enable_watchpoints_after_interactive_call_stop (void) |
| 8374 | { |
| 8375 | struct breakpoint *b; |
| 8376 | |
| 8377 | ALL_BREAKPOINTS (b) |
| 8378 | { |
| 8379 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
| 8380 | { |
| 8381 | b->enable_state = bp_enabled; |
| 8382 | update_global_location_list (UGLL_MAY_INSERT); |
| 8383 | } |
| 8384 | } |
| 8385 | } |
| 8386 | |
| 8387 | void |
| 8388 | disable_breakpoints_before_startup (void) |
| 8389 | { |
| 8390 | current_program_space->executing_startup = 1; |
| 8391 | update_global_location_list (UGLL_DONT_INSERT); |
| 8392 | } |
| 8393 | |
| 8394 | void |
| 8395 | enable_breakpoints_after_startup (void) |
| 8396 | { |
| 8397 | current_program_space->executing_startup = 0; |
| 8398 | breakpoint_re_set (); |
| 8399 | } |
| 8400 | |
| 8401 | /* Create a new single-step breakpoint for thread THREAD, with no |
| 8402 | locations. */ |
| 8403 | |
| 8404 | static struct breakpoint * |
| 8405 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) |
| 8406 | { |
| 8407 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
| 8408 | |
| 8409 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
| 8410 | &momentary_breakpoint_ops); |
| 8411 | |
| 8412 | b->disposition = disp_donttouch; |
| 8413 | b->frame_id = null_frame_id; |
| 8414 | |
| 8415 | b->thread = thread; |
| 8416 | gdb_assert (b->thread != 0); |
| 8417 | |
| 8418 | return add_to_breakpoint_chain (std::move (b)); |
| 8419 | } |
| 8420 | |
| 8421 | /* Set a momentary breakpoint of type TYPE at address specified by |
| 8422 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that |
| 8423 | frame. */ |
| 8424 | |
| 8425 | breakpoint_up |
| 8426 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
| 8427 | struct frame_id frame_id, enum bptype type) |
| 8428 | { |
| 8429 | struct breakpoint *b; |
| 8430 | |
| 8431 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
| 8432 | tail-called one. */ |
| 8433 | gdb_assert (!frame_id_artificial_p (frame_id)); |
| 8434 | |
| 8435 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
| 8436 | b->enable_state = bp_enabled; |
| 8437 | b->disposition = disp_donttouch; |
| 8438 | b->frame_id = frame_id; |
| 8439 | |
| 8440 | b->thread = inferior_thread ()->global_num; |
| 8441 | |
| 8442 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 8443 | |
| 8444 | return breakpoint_up (b); |
| 8445 | } |
| 8446 | |
| 8447 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
| 8448 | The new breakpoint will have type TYPE, use OPS as its |
| 8449 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ |
| 8450 | |
| 8451 | static struct breakpoint * |
| 8452 | momentary_breakpoint_from_master (struct breakpoint *orig, |
| 8453 | enum bptype type, |
| 8454 | const struct breakpoint_ops *ops, |
| 8455 | int loc_enabled) |
| 8456 | { |
| 8457 | struct breakpoint *copy; |
| 8458 | |
| 8459 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
| 8460 | copy->loc = allocate_bp_location (copy); |
| 8461 | set_breakpoint_location_function (copy->loc); |
| 8462 | |
| 8463 | copy->loc->gdbarch = orig->loc->gdbarch; |
| 8464 | copy->loc->requested_address = orig->loc->requested_address; |
| 8465 | copy->loc->address = orig->loc->address; |
| 8466 | copy->loc->section = orig->loc->section; |
| 8467 | copy->loc->pspace = orig->loc->pspace; |
| 8468 | copy->loc->probe = orig->loc->probe; |
| 8469 | copy->loc->line_number = orig->loc->line_number; |
| 8470 | copy->loc->symtab = orig->loc->symtab; |
| 8471 | copy->loc->enabled = loc_enabled; |
| 8472 | copy->frame_id = orig->frame_id; |
| 8473 | copy->thread = orig->thread; |
| 8474 | copy->pspace = orig->pspace; |
| 8475 | |
| 8476 | copy->enable_state = bp_enabled; |
| 8477 | copy->disposition = disp_donttouch; |
| 8478 | copy->number = internal_breakpoint_number--; |
| 8479 | |
| 8480 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
| 8481 | return copy; |
| 8482 | } |
| 8483 | |
| 8484 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
| 8485 | ORIG is NULL. */ |
| 8486 | |
| 8487 | struct breakpoint * |
| 8488 | clone_momentary_breakpoint (struct breakpoint *orig) |
| 8489 | { |
| 8490 | /* If there's nothing to clone, then return nothing. */ |
| 8491 | if (orig == NULL) |
| 8492 | return NULL; |
| 8493 | |
| 8494 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
| 8495 | } |
| 8496 | |
| 8497 | breakpoint_up |
| 8498 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 8499 | enum bptype type) |
| 8500 | { |
| 8501 | struct symtab_and_line sal; |
| 8502 | |
| 8503 | sal = find_pc_line (pc, 0); |
| 8504 | sal.pc = pc; |
| 8505 | sal.section = find_pc_overlay (pc); |
| 8506 | sal.explicit_pc = 1; |
| 8507 | |
| 8508 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
| 8509 | } |
| 8510 | \f |
| 8511 | |
| 8512 | /* Tell the user we have just set a breakpoint B. */ |
| 8513 | |
| 8514 | static void |
| 8515 | mention (struct breakpoint *b) |
| 8516 | { |
| 8517 | b->ops->print_mention (b); |
| 8518 | if (current_uiout->is_mi_like_p ()) |
| 8519 | return; |
| 8520 | printf_filtered ("\n"); |
| 8521 | } |
| 8522 | \f |
| 8523 | |
| 8524 | static int bp_loc_is_permanent (struct bp_location *loc); |
| 8525 | |
| 8526 | static struct bp_location * |
| 8527 | add_location_to_breakpoint (struct breakpoint *b, |
| 8528 | const struct symtab_and_line *sal) |
| 8529 | { |
| 8530 | struct bp_location *loc, **tmp; |
| 8531 | CORE_ADDR adjusted_address; |
| 8532 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); |
| 8533 | |
| 8534 | if (loc_gdbarch == NULL) |
| 8535 | loc_gdbarch = b->gdbarch; |
| 8536 | |
| 8537 | /* Adjust the breakpoint's address prior to allocating a location. |
| 8538 | Once we call allocate_bp_location(), that mostly uninitialized |
| 8539 | location will be placed on the location chain. Adjustment of the |
| 8540 | breakpoint may cause target_read_memory() to be called and we do |
| 8541 | not want its scan of the location chain to find a breakpoint and |
| 8542 | location that's only been partially initialized. */ |
| 8543 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
| 8544 | sal->pc, b->type); |
| 8545 | |
| 8546 | /* Sort the locations by their ADDRESS. */ |
| 8547 | loc = allocate_bp_location (b); |
| 8548 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
| 8549 | tmp = &((*tmp)->next)) |
| 8550 | ; |
| 8551 | loc->next = *tmp; |
| 8552 | *tmp = loc; |
| 8553 | |
| 8554 | loc->requested_address = sal->pc; |
| 8555 | loc->address = adjusted_address; |
| 8556 | loc->pspace = sal->pspace; |
| 8557 | loc->probe.prob = sal->prob; |
| 8558 | loc->probe.objfile = sal->objfile; |
| 8559 | gdb_assert (loc->pspace != NULL); |
| 8560 | loc->section = sal->section; |
| 8561 | loc->gdbarch = loc_gdbarch; |
| 8562 | loc->line_number = sal->line; |
| 8563 | loc->symtab = sal->symtab; |
| 8564 | loc->symbol = sal->symbol; |
| 8565 | loc->msymbol = sal->msymbol; |
| 8566 | loc->objfile = sal->objfile; |
| 8567 | |
| 8568 | set_breakpoint_location_function (loc); |
| 8569 | |
| 8570 | /* While by definition, permanent breakpoints are already present in the |
| 8571 | code, we don't mark the location as inserted. Normally one would expect |
| 8572 | that GDB could rely on that breakpoint instruction to stop the program, |
| 8573 | thus removing the need to insert its own breakpoint, except that executing |
| 8574 | the breakpoint instruction can kill the target instead of reporting a |
| 8575 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the |
| 8576 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies |
| 8577 | with "Trap 0x02 while interrupts disabled, Error state". Letting the |
| 8578 | breakpoint be inserted normally results in QEMU knowing about the GDB |
| 8579 | breakpoint, and thus trap before the breakpoint instruction is executed. |
| 8580 | (If GDB later needs to continue execution past the permanent breakpoint, |
| 8581 | it manually increments the PC, thus avoiding executing the breakpoint |
| 8582 | instruction.) */ |
| 8583 | if (bp_loc_is_permanent (loc)) |
| 8584 | loc->permanent = 1; |
| 8585 | |
| 8586 | return loc; |
| 8587 | } |
| 8588 | \f |
| 8589 | |
| 8590 | /* See breakpoint.h. */ |
| 8591 | |
| 8592 | int |
| 8593 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) |
| 8594 | { |
| 8595 | int len; |
| 8596 | CORE_ADDR addr; |
| 8597 | const gdb_byte *bpoint; |
| 8598 | gdb_byte *target_mem; |
| 8599 | |
| 8600 | addr = address; |
| 8601 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); |
| 8602 | |
| 8603 | /* Software breakpoints unsupported? */ |
| 8604 | if (bpoint == NULL) |
| 8605 | return 0; |
| 8606 | |
| 8607 | target_mem = (gdb_byte *) alloca (len); |
| 8608 | |
| 8609 | /* Enable the automatic memory restoration from breakpoints while |
| 8610 | we read the memory. Otherwise we could say about our temporary |
| 8611 | breakpoints they are permanent. */ |
| 8612 | scoped_restore restore_memory |
| 8613 | = make_scoped_restore_show_memory_breakpoints (0); |
| 8614 | |
| 8615 | if (target_read_memory (address, target_mem, len) == 0 |
| 8616 | && memcmp (target_mem, bpoint, len) == 0) |
| 8617 | return 1; |
| 8618 | |
| 8619 | return 0; |
| 8620 | } |
| 8621 | |
| 8622 | /* Return 1 if LOC is pointing to a permanent breakpoint, |
| 8623 | return 0 otherwise. */ |
| 8624 | |
| 8625 | static int |
| 8626 | bp_loc_is_permanent (struct bp_location *loc) |
| 8627 | { |
| 8628 | gdb_assert (loc != NULL); |
| 8629 | |
| 8630 | /* If we have a non-breakpoint-backed catchpoint or a software |
| 8631 | watchpoint, just return 0. We should not attempt to read from |
| 8632 | the addresses the locations of these breakpoint types point to. |
| 8633 | program_breakpoint_here_p, below, will attempt to read |
| 8634 | memory. */ |
| 8635 | if (!bl_address_is_meaningful (loc)) |
| 8636 | return 0; |
| 8637 | |
| 8638 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 8639 | switch_to_program_space_and_thread (loc->pspace); |
| 8640 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
| 8641 | } |
| 8642 | |
| 8643 | /* Build a command list for the dprintf corresponding to the current |
| 8644 | settings of the dprintf style options. */ |
| 8645 | |
| 8646 | static void |
| 8647 | update_dprintf_command_list (struct breakpoint *b) |
| 8648 | { |
| 8649 | char *dprintf_args = b->extra_string; |
| 8650 | char *printf_line = NULL; |
| 8651 | |
| 8652 | if (!dprintf_args) |
| 8653 | return; |
| 8654 | |
| 8655 | dprintf_args = skip_spaces (dprintf_args); |
| 8656 | |
| 8657 | /* Allow a comma, as it may have terminated a location, but don't |
| 8658 | insist on it. */ |
| 8659 | if (*dprintf_args == ',') |
| 8660 | ++dprintf_args; |
| 8661 | dprintf_args = skip_spaces (dprintf_args); |
| 8662 | |
| 8663 | if (*dprintf_args != '"') |
| 8664 | error (_("Bad format string, missing '\"'.")); |
| 8665 | |
| 8666 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
| 8667 | printf_line = xstrprintf ("printf %s", dprintf_args); |
| 8668 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
| 8669 | { |
| 8670 | if (!dprintf_function) |
| 8671 | error (_("No function supplied for dprintf call")); |
| 8672 | |
| 8673 | if (dprintf_channel && strlen (dprintf_channel) > 0) |
| 8674 | printf_line = xstrprintf ("call (void) %s (%s,%s)", |
| 8675 | dprintf_function, |
| 8676 | dprintf_channel, |
| 8677 | dprintf_args); |
| 8678 | else |
| 8679 | printf_line = xstrprintf ("call (void) %s (%s)", |
| 8680 | dprintf_function, |
| 8681 | dprintf_args); |
| 8682 | } |
| 8683 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
| 8684 | { |
| 8685 | if (target_can_run_breakpoint_commands ()) |
| 8686 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); |
| 8687 | else |
| 8688 | { |
| 8689 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); |
| 8690 | printf_line = xstrprintf ("printf %s", dprintf_args); |
| 8691 | } |
| 8692 | } |
| 8693 | else |
| 8694 | internal_error (__FILE__, __LINE__, |
| 8695 | _("Invalid dprintf style.")); |
| 8696 | |
| 8697 | gdb_assert (printf_line != NULL); |
| 8698 | |
| 8699 | /* Manufacture a printf sequence. */ |
| 8700 | struct command_line *printf_cmd_line |
| 8701 | = new struct command_line (simple_control, printf_line); |
| 8702 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, |
| 8703 | command_lines_deleter ())); |
| 8704 | } |
| 8705 | |
| 8706 | /* Update all dprintf commands, making their command lists reflect |
| 8707 | current style settings. */ |
| 8708 | |
| 8709 | static void |
| 8710 | update_dprintf_commands (const char *args, int from_tty, |
| 8711 | struct cmd_list_element *c) |
| 8712 | { |
| 8713 | struct breakpoint *b; |
| 8714 | |
| 8715 | ALL_BREAKPOINTS (b) |
| 8716 | { |
| 8717 | if (b->type == bp_dprintf) |
| 8718 | update_dprintf_command_list (b); |
| 8719 | } |
| 8720 | } |
| 8721 | |
| 8722 | /* Create a breakpoint with SAL as location. Use LOCATION |
| 8723 | as a description of the location, and COND_STRING |
| 8724 | as condition expression. If LOCATION is NULL then create an |
| 8725 | "address location" from the address in the SAL. */ |
| 8726 | |
| 8727 | static void |
| 8728 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
| 8729 | gdb::array_view<const symtab_and_line> sals, |
| 8730 | event_location_up &&location, |
| 8731 | gdb::unique_xmalloc_ptr<char> filter, |
| 8732 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 8733 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 8734 | enum bptype type, enum bpdisp disposition, |
| 8735 | int thread, int task, int ignore_count, |
| 8736 | const struct breakpoint_ops *ops, int from_tty, |
| 8737 | int enabled, int internal, unsigned flags, |
| 8738 | int display_canonical) |
| 8739 | { |
| 8740 | int i; |
| 8741 | |
| 8742 | if (type == bp_hardware_breakpoint) |
| 8743 | { |
| 8744 | int target_resources_ok; |
| 8745 | |
| 8746 | i = hw_breakpoint_used_count (); |
| 8747 | target_resources_ok = |
| 8748 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 8749 | i + 1, 0); |
| 8750 | if (target_resources_ok == 0) |
| 8751 | error (_("No hardware breakpoint support in the target.")); |
| 8752 | else if (target_resources_ok < 0) |
| 8753 | error (_("Hardware breakpoints used exceeds limit.")); |
| 8754 | } |
| 8755 | |
| 8756 | gdb_assert (!sals.empty ()); |
| 8757 | |
| 8758 | for (const auto &sal : sals) |
| 8759 | { |
| 8760 | struct bp_location *loc; |
| 8761 | |
| 8762 | if (from_tty) |
| 8763 | { |
| 8764 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 8765 | if (!loc_gdbarch) |
| 8766 | loc_gdbarch = gdbarch; |
| 8767 | |
| 8768 | describe_other_breakpoints (loc_gdbarch, |
| 8769 | sal.pspace, sal.pc, sal.section, thread); |
| 8770 | } |
| 8771 | |
| 8772 | if (&sal == &sals[0]) |
| 8773 | { |
| 8774 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
| 8775 | b->thread = thread; |
| 8776 | b->task = task; |
| 8777 | |
| 8778 | b->cond_string = cond_string.release (); |
| 8779 | b->extra_string = extra_string.release (); |
| 8780 | b->ignore_count = ignore_count; |
| 8781 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 8782 | b->disposition = disposition; |
| 8783 | |
| 8784 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
| 8785 | b->loc->inserted = 1; |
| 8786 | |
| 8787 | if (type == bp_static_tracepoint) |
| 8788 | { |
| 8789 | struct tracepoint *t = (struct tracepoint *) b; |
| 8790 | struct static_tracepoint_marker marker; |
| 8791 | |
| 8792 | if (strace_marker_p (b)) |
| 8793 | { |
| 8794 | /* We already know the marker exists, otherwise, we |
| 8795 | wouldn't see a sal for it. */ |
| 8796 | const char *p |
| 8797 | = &event_location_to_string (b->location.get ())[3]; |
| 8798 | const char *endp; |
| 8799 | |
| 8800 | p = skip_spaces (p); |
| 8801 | |
| 8802 | endp = skip_to_space (p); |
| 8803 | |
| 8804 | t->static_trace_marker_id.assign (p, endp - p); |
| 8805 | |
| 8806 | printf_filtered (_("Probed static tracepoint " |
| 8807 | "marker \"%s\"\n"), |
| 8808 | t->static_trace_marker_id.c_str ()); |
| 8809 | } |
| 8810 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) |
| 8811 | { |
| 8812 | t->static_trace_marker_id = std::move (marker.str_id); |
| 8813 | |
| 8814 | printf_filtered (_("Probed static tracepoint " |
| 8815 | "marker \"%s\"\n"), |
| 8816 | t->static_trace_marker_id.c_str ()); |
| 8817 | } |
| 8818 | else |
| 8819 | warning (_("Couldn't determine the static " |
| 8820 | "tracepoint marker to probe")); |
| 8821 | } |
| 8822 | |
| 8823 | loc = b->loc; |
| 8824 | } |
| 8825 | else |
| 8826 | { |
| 8827 | loc = add_location_to_breakpoint (b, &sal); |
| 8828 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
| 8829 | loc->inserted = 1; |
| 8830 | } |
| 8831 | |
| 8832 | if (b->cond_string) |
| 8833 | { |
| 8834 | const char *arg = b->cond_string; |
| 8835 | |
| 8836 | loc->cond = parse_exp_1 (&arg, loc->address, |
| 8837 | block_for_pc (loc->address), 0); |
| 8838 | if (*arg) |
| 8839 | error (_("Garbage '%s' follows condition"), arg); |
| 8840 | } |
| 8841 | |
| 8842 | /* Dynamic printf requires and uses additional arguments on the |
| 8843 | command line, otherwise it's an error. */ |
| 8844 | if (type == bp_dprintf) |
| 8845 | { |
| 8846 | if (b->extra_string) |
| 8847 | update_dprintf_command_list (b); |
| 8848 | else |
| 8849 | error (_("Format string required")); |
| 8850 | } |
| 8851 | else if (b->extra_string) |
| 8852 | error (_("Garbage '%s' at end of command"), b->extra_string); |
| 8853 | } |
| 8854 | |
| 8855 | b->display_canonical = display_canonical; |
| 8856 | if (location != NULL) |
| 8857 | b->location = std::move (location); |
| 8858 | else |
| 8859 | b->location = new_address_location (b->loc->address, NULL, 0); |
| 8860 | b->filter = std::move (filter); |
| 8861 | } |
| 8862 | |
| 8863 | static void |
| 8864 | create_breakpoint_sal (struct gdbarch *gdbarch, |
| 8865 | gdb::array_view<const symtab_and_line> sals, |
| 8866 | event_location_up &&location, |
| 8867 | gdb::unique_xmalloc_ptr<char> filter, |
| 8868 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 8869 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 8870 | enum bptype type, enum bpdisp disposition, |
| 8871 | int thread, int task, int ignore_count, |
| 8872 | const struct breakpoint_ops *ops, int from_tty, |
| 8873 | int enabled, int internal, unsigned flags, |
| 8874 | int display_canonical) |
| 8875 | { |
| 8876 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
| 8877 | |
| 8878 | init_breakpoint_sal (b.get (), gdbarch, |
| 8879 | sals, std::move (location), |
| 8880 | std::move (filter), |
| 8881 | std::move (cond_string), |
| 8882 | std::move (extra_string), |
| 8883 | type, disposition, |
| 8884 | thread, task, ignore_count, |
| 8885 | ops, from_tty, |
| 8886 | enabled, internal, flags, |
| 8887 | display_canonical); |
| 8888 | |
| 8889 | install_breakpoint (internal, std::move (b), 0); |
| 8890 | } |
| 8891 | |
| 8892 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
| 8893 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] |
| 8894 | value. COND_STRING, if not NULL, specified the condition to be |
| 8895 | used for all breakpoints. Essentially the only case where |
| 8896 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded |
| 8897 | function. In that case, it's still not possible to specify |
| 8898 | separate conditions for different overloaded functions, so |
| 8899 | we take just a single condition string. |
| 8900 | |
| 8901 | NOTE: If the function succeeds, the caller is expected to cleanup |
| 8902 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
| 8903 | array contents). If the function fails (error() is called), the |
| 8904 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, |
| 8905 | COND and SALS arrays and each of those arrays contents. */ |
| 8906 | |
| 8907 | static void |
| 8908 | create_breakpoints_sal (struct gdbarch *gdbarch, |
| 8909 | struct linespec_result *canonical, |
| 8910 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 8911 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 8912 | enum bptype type, enum bpdisp disposition, |
| 8913 | int thread, int task, int ignore_count, |
| 8914 | const struct breakpoint_ops *ops, int from_tty, |
| 8915 | int enabled, int internal, unsigned flags) |
| 8916 | { |
| 8917 | if (canonical->pre_expanded) |
| 8918 | gdb_assert (canonical->lsals.size () == 1); |
| 8919 | |
| 8920 | for (const auto &lsal : canonical->lsals) |
| 8921 | { |
| 8922 | /* Note that 'location' can be NULL in the case of a plain |
| 8923 | 'break', without arguments. */ |
| 8924 | event_location_up location |
| 8925 | = (canonical->location != NULL |
| 8926 | ? copy_event_location (canonical->location.get ()) : NULL); |
| 8927 | gdb::unique_xmalloc_ptr<char> filter_string |
| 8928 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
| 8929 | |
| 8930 | create_breakpoint_sal (gdbarch, lsal.sals, |
| 8931 | std::move (location), |
| 8932 | std::move (filter_string), |
| 8933 | std::move (cond_string), |
| 8934 | std::move (extra_string), |
| 8935 | type, disposition, |
| 8936 | thread, task, ignore_count, ops, |
| 8937 | from_tty, enabled, internal, flags, |
| 8938 | canonical->special_display); |
| 8939 | } |
| 8940 | } |
| 8941 | |
| 8942 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
| 8943 | followed by conditionals. On return, SALS contains an array of SAL |
| 8944 | addresses found. LOCATION points to the end of the SAL (for |
| 8945 | linespec locations). |
| 8946 | |
| 8947 | The array and the line spec strings are allocated on the heap, it is |
| 8948 | the caller's responsibility to free them. */ |
| 8949 | |
| 8950 | static void |
| 8951 | parse_breakpoint_sals (const struct event_location *location, |
| 8952 | struct linespec_result *canonical) |
| 8953 | { |
| 8954 | struct symtab_and_line cursal; |
| 8955 | |
| 8956 | if (event_location_type (location) == LINESPEC_LOCATION) |
| 8957 | { |
| 8958 | const char *spec = get_linespec_location (location)->spec_string; |
| 8959 | |
| 8960 | if (spec == NULL) |
| 8961 | { |
| 8962 | /* The last displayed codepoint, if it's valid, is our default |
| 8963 | breakpoint address. */ |
| 8964 | if (last_displayed_sal_is_valid ()) |
| 8965 | { |
| 8966 | /* Set sal's pspace, pc, symtab, and line to the values |
| 8967 | corresponding to the last call to print_frame_info. |
| 8968 | Be sure to reinitialize LINE with NOTCURRENT == 0 |
| 8969 | as the breakpoint line number is inappropriate otherwise. |
| 8970 | find_pc_line would adjust PC, re-set it back. */ |
| 8971 | symtab_and_line sal = get_last_displayed_sal (); |
| 8972 | CORE_ADDR pc = sal.pc; |
| 8973 | |
| 8974 | sal = find_pc_line (pc, 0); |
| 8975 | |
| 8976 | /* "break" without arguments is equivalent to "break *PC" |
| 8977 | where PC is the last displayed codepoint's address. So |
| 8978 | make sure to set sal.explicit_pc to prevent GDB from |
| 8979 | trying to expand the list of sals to include all other |
| 8980 | instances with the same symtab and line. */ |
| 8981 | sal.pc = pc; |
| 8982 | sal.explicit_pc = 1; |
| 8983 | |
| 8984 | struct linespec_sals lsal; |
| 8985 | lsal.sals = {sal}; |
| 8986 | lsal.canonical = NULL; |
| 8987 | |
| 8988 | canonical->lsals.push_back (std::move (lsal)); |
| 8989 | return; |
| 8990 | } |
| 8991 | else |
| 8992 | error (_("No default breakpoint address now.")); |
| 8993 | } |
| 8994 | } |
| 8995 | |
| 8996 | /* Force almost all breakpoints to be in terms of the |
| 8997 | current_source_symtab (which is decode_line_1's default). |
| 8998 | This should produce the results we want almost all of the |
| 8999 | time while leaving default_breakpoint_* alone. |
| 9000 | |
| 9001 | ObjC: However, don't match an Objective-C method name which |
| 9002 | may have a '+' or '-' succeeded by a '['. */ |
| 9003 | cursal = get_current_source_symtab_and_line (); |
| 9004 | if (last_displayed_sal_is_valid ()) |
| 9005 | { |
| 9006 | const char *spec = NULL; |
| 9007 | |
| 9008 | if (event_location_type (location) == LINESPEC_LOCATION) |
| 9009 | spec = get_linespec_location (location)->spec_string; |
| 9010 | |
| 9011 | if (!cursal.symtab |
| 9012 | || (spec != NULL |
| 9013 | && strchr ("+-", spec[0]) != NULL |
| 9014 | && spec[1] != '[')) |
| 9015 | { |
| 9016 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
| 9017 | get_last_displayed_symtab (), |
| 9018 | get_last_displayed_line (), |
| 9019 | canonical, NULL, NULL); |
| 9020 | return; |
| 9021 | } |
| 9022 | } |
| 9023 | |
| 9024 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
| 9025 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
| 9026 | } |
| 9027 | |
| 9028 | |
| 9029 | /* Convert each SAL into a real PC. Verify that the PC can be |
| 9030 | inserted as a breakpoint. If it can't throw an error. */ |
| 9031 | |
| 9032 | static void |
| 9033 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
| 9034 | { |
| 9035 | for (auto &sal : sals) |
| 9036 | resolve_sal_pc (&sal); |
| 9037 | } |
| 9038 | |
| 9039 | /* Fast tracepoints may have restrictions on valid locations. For |
| 9040 | instance, a fast tracepoint using a jump instead of a trap will |
| 9041 | likely have to overwrite more bytes than a trap would, and so can |
| 9042 | only be placed where the instruction is longer than the jump, or a |
| 9043 | multi-instruction sequence does not have a jump into the middle of |
| 9044 | it, etc. */ |
| 9045 | |
| 9046 | static void |
| 9047 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, |
| 9048 | gdb::array_view<const symtab_and_line> sals) |
| 9049 | { |
| 9050 | for (const auto &sal : sals) |
| 9051 | { |
| 9052 | struct gdbarch *sarch; |
| 9053 | |
| 9054 | sarch = get_sal_arch (sal); |
| 9055 | /* We fall back to GDBARCH if there is no architecture |
| 9056 | associated with SAL. */ |
| 9057 | if (sarch == NULL) |
| 9058 | sarch = gdbarch; |
| 9059 | std::string msg; |
| 9060 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) |
| 9061 | error (_("May not have a fast tracepoint at %s%s"), |
| 9062 | paddress (sarch, sal.pc), msg.c_str ()); |
| 9063 | } |
| 9064 | } |
| 9065 | |
| 9066 | /* Given TOK, a string specification of condition and thread, as |
| 9067 | accepted by the 'break' command, extract the condition |
| 9068 | string and thread number and set *COND_STRING and *THREAD. |
| 9069 | PC identifies the context at which the condition should be parsed. |
| 9070 | If no condition is found, *COND_STRING is set to NULL. |
| 9071 | If no thread is found, *THREAD is set to -1. */ |
| 9072 | |
| 9073 | static void |
| 9074 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
| 9075 | char **cond_string, int *thread, int *task, |
| 9076 | char **rest) |
| 9077 | { |
| 9078 | *cond_string = NULL; |
| 9079 | *thread = -1; |
| 9080 | *task = 0; |
| 9081 | *rest = NULL; |
| 9082 | |
| 9083 | while (tok && *tok) |
| 9084 | { |
| 9085 | const char *end_tok; |
| 9086 | int toklen; |
| 9087 | const char *cond_start = NULL; |
| 9088 | const char *cond_end = NULL; |
| 9089 | |
| 9090 | tok = skip_spaces (tok); |
| 9091 | |
| 9092 | if ((*tok == '"' || *tok == ',') && rest) |
| 9093 | { |
| 9094 | *rest = savestring (tok, strlen (tok)); |
| 9095 | return; |
| 9096 | } |
| 9097 | |
| 9098 | end_tok = skip_to_space (tok); |
| 9099 | |
| 9100 | toklen = end_tok - tok; |
| 9101 | |
| 9102 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 9103 | { |
| 9104 | tok = cond_start = end_tok + 1; |
| 9105 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
| 9106 | cond_end = tok; |
| 9107 | *cond_string = savestring (cond_start, cond_end - cond_start); |
| 9108 | } |
| 9109 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 9110 | { |
| 9111 | const char *tmptok; |
| 9112 | struct thread_info *thr; |
| 9113 | |
| 9114 | tok = end_tok + 1; |
| 9115 | thr = parse_thread_id (tok, &tmptok); |
| 9116 | if (tok == tmptok) |
| 9117 | error (_("Junk after thread keyword.")); |
| 9118 | *thread = thr->global_num; |
| 9119 | tok = tmptok; |
| 9120 | } |
| 9121 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
| 9122 | { |
| 9123 | char *tmptok; |
| 9124 | |
| 9125 | tok = end_tok + 1; |
| 9126 | *task = strtol (tok, &tmptok, 0); |
| 9127 | if (tok == tmptok) |
| 9128 | error (_("Junk after task keyword.")); |
| 9129 | if (!valid_task_id (*task)) |
| 9130 | error (_("Unknown task %d."), *task); |
| 9131 | tok = tmptok; |
| 9132 | } |
| 9133 | else if (rest) |
| 9134 | { |
| 9135 | *rest = savestring (tok, strlen (tok)); |
| 9136 | return; |
| 9137 | } |
| 9138 | else |
| 9139 | error (_("Junk at end of arguments.")); |
| 9140 | } |
| 9141 | } |
| 9142 | |
| 9143 | /* Decode a static tracepoint marker spec. */ |
| 9144 | |
| 9145 | static std::vector<symtab_and_line> |
| 9146 | decode_static_tracepoint_spec (const char **arg_p) |
| 9147 | { |
| 9148 | const char *p = &(*arg_p)[3]; |
| 9149 | const char *endp; |
| 9150 | |
| 9151 | p = skip_spaces (p); |
| 9152 | |
| 9153 | endp = skip_to_space (p); |
| 9154 | |
| 9155 | std::string marker_str (p, endp - p); |
| 9156 | |
| 9157 | std::vector<static_tracepoint_marker> markers |
| 9158 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); |
| 9159 | if (markers.empty ()) |
| 9160 | error (_("No known static tracepoint marker named %s"), |
| 9161 | marker_str.c_str ()); |
| 9162 | |
| 9163 | std::vector<symtab_and_line> sals; |
| 9164 | sals.reserve (markers.size ()); |
| 9165 | |
| 9166 | for (const static_tracepoint_marker &marker : markers) |
| 9167 | { |
| 9168 | symtab_and_line sal = find_pc_line (marker.address, 0); |
| 9169 | sal.pc = marker.address; |
| 9170 | sals.push_back (sal); |
| 9171 | } |
| 9172 | |
| 9173 | *arg_p = endp; |
| 9174 | return sals; |
| 9175 | } |
| 9176 | |
| 9177 | /* Returns the breakpoint ops appropriate for use with with LOCATION_TYPE and |
| 9178 | according to IS_TRACEPOINT. */ |
| 9179 | |
| 9180 | static const struct breakpoint_ops * |
| 9181 | breakpoint_ops_for_event_location_type (enum event_location_type location_type, |
| 9182 | bool is_tracepoint) |
| 9183 | { |
| 9184 | if (is_tracepoint) |
| 9185 | { |
| 9186 | if (location_type == PROBE_LOCATION) |
| 9187 | return &tracepoint_probe_breakpoint_ops; |
| 9188 | else |
| 9189 | return &tracepoint_breakpoint_ops; |
| 9190 | } |
| 9191 | else |
| 9192 | { |
| 9193 | if (location_type == PROBE_LOCATION) |
| 9194 | return &bkpt_probe_breakpoint_ops; |
| 9195 | else |
| 9196 | return &bkpt_breakpoint_ops; |
| 9197 | } |
| 9198 | } |
| 9199 | |
| 9200 | /* See breakpoint.h. */ |
| 9201 | |
| 9202 | const struct breakpoint_ops * |
| 9203 | breakpoint_ops_for_event_location (const struct event_location *location, |
| 9204 | bool is_tracepoint) |
| 9205 | { |
| 9206 | if (location != nullptr) |
| 9207 | return breakpoint_ops_for_event_location_type |
| 9208 | (event_location_type (location), is_tracepoint); |
| 9209 | return is_tracepoint ? &tracepoint_breakpoint_ops : &bkpt_breakpoint_ops; |
| 9210 | } |
| 9211 | |
| 9212 | /* See breakpoint.h. */ |
| 9213 | |
| 9214 | int |
| 9215 | create_breakpoint (struct gdbarch *gdbarch, |
| 9216 | const struct event_location *location, |
| 9217 | const char *cond_string, |
| 9218 | int thread, const char *extra_string, |
| 9219 | int parse_extra, |
| 9220 | int tempflag, enum bptype type_wanted, |
| 9221 | int ignore_count, |
| 9222 | enum auto_boolean pending_break_support, |
| 9223 | const struct breakpoint_ops *ops, |
| 9224 | int from_tty, int enabled, int internal, |
| 9225 | unsigned flags) |
| 9226 | { |
| 9227 | struct linespec_result canonical; |
| 9228 | int pending = 0; |
| 9229 | int task = 0; |
| 9230 | int prev_bkpt_count = breakpoint_count; |
| 9231 | |
| 9232 | gdb_assert (ops != NULL); |
| 9233 | |
| 9234 | /* If extra_string isn't useful, set it to NULL. */ |
| 9235 | if (extra_string != NULL && *extra_string == '\0') |
| 9236 | extra_string = NULL; |
| 9237 | |
| 9238 | try |
| 9239 | { |
| 9240 | ops->create_sals_from_location (location, &canonical, type_wanted); |
| 9241 | } |
| 9242 | catch (const gdb_exception_error &e) |
| 9243 | { |
| 9244 | /* If caller is interested in rc value from parse, set |
| 9245 | value. */ |
| 9246 | if (e.error == NOT_FOUND_ERROR) |
| 9247 | { |
| 9248 | /* If pending breakpoint support is turned off, throw |
| 9249 | error. */ |
| 9250 | |
| 9251 | if (pending_break_support == AUTO_BOOLEAN_FALSE) |
| 9252 | throw; |
| 9253 | |
| 9254 | exception_print (gdb_stderr, e); |
| 9255 | |
| 9256 | /* If pending breakpoint support is auto query and the user |
| 9257 | selects no, then simply return the error code. */ |
| 9258 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
| 9259 | && !nquery (_("Make %s pending on future shared library load? "), |
| 9260 | bptype_string (type_wanted))) |
| 9261 | return 0; |
| 9262 | |
| 9263 | /* At this point, either the user was queried about setting |
| 9264 | a pending breakpoint and selected yes, or pending |
| 9265 | breakpoint behavior is on and thus a pending breakpoint |
| 9266 | is defaulted on behalf of the user. */ |
| 9267 | pending = 1; |
| 9268 | } |
| 9269 | else |
| 9270 | throw; |
| 9271 | } |
| 9272 | |
| 9273 | if (!pending && canonical.lsals.empty ()) |
| 9274 | return 0; |
| 9275 | |
| 9276 | /* Resolve all line numbers to PC's and verify that the addresses |
| 9277 | are ok for the target. */ |
| 9278 | if (!pending) |
| 9279 | { |
| 9280 | for (auto &lsal : canonical.lsals) |
| 9281 | breakpoint_sals_to_pc (lsal.sals); |
| 9282 | } |
| 9283 | |
| 9284 | /* Fast tracepoints may have additional restrictions on location. */ |
| 9285 | if (!pending && type_wanted == bp_fast_tracepoint) |
| 9286 | { |
| 9287 | for (const auto &lsal : canonical.lsals) |
| 9288 | check_fast_tracepoint_sals (gdbarch, lsal.sals); |
| 9289 | } |
| 9290 | |
| 9291 | /* Verify that condition can be parsed, before setting any |
| 9292 | breakpoints. Allocate a separate condition expression for each |
| 9293 | breakpoint. */ |
| 9294 | if (!pending) |
| 9295 | { |
| 9296 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
| 9297 | gdb::unique_xmalloc_ptr<char> extra_string_copy; |
| 9298 | |
| 9299 | if (parse_extra) |
| 9300 | { |
| 9301 | char *rest; |
| 9302 | char *cond; |
| 9303 | |
| 9304 | const linespec_sals &lsal = canonical.lsals[0]; |
| 9305 | |
| 9306 | /* Here we only parse 'arg' to separate condition |
| 9307 | from thread number, so parsing in context of first |
| 9308 | sal is OK. When setting the breakpoint we'll |
| 9309 | re-parse it in context of each sal. */ |
| 9310 | |
| 9311 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
| 9312 | &cond, &thread, &task, &rest); |
| 9313 | cond_string_copy.reset (cond); |
| 9314 | extra_string_copy.reset (rest); |
| 9315 | } |
| 9316 | else |
| 9317 | { |
| 9318 | if (type_wanted != bp_dprintf |
| 9319 | && extra_string != NULL && *extra_string != '\0') |
| 9320 | error (_("Garbage '%s' at end of location"), extra_string); |
| 9321 | |
| 9322 | /* Create a private copy of condition string. */ |
| 9323 | if (cond_string) |
| 9324 | cond_string_copy.reset (xstrdup (cond_string)); |
| 9325 | /* Create a private copy of any extra string. */ |
| 9326 | if (extra_string) |
| 9327 | extra_string_copy.reset (xstrdup (extra_string)); |
| 9328 | } |
| 9329 | |
| 9330 | ops->create_breakpoints_sal (gdbarch, &canonical, |
| 9331 | std::move (cond_string_copy), |
| 9332 | std::move (extra_string_copy), |
| 9333 | type_wanted, |
| 9334 | tempflag ? disp_del : disp_donttouch, |
| 9335 | thread, task, ignore_count, ops, |
| 9336 | from_tty, enabled, internal, flags); |
| 9337 | } |
| 9338 | else |
| 9339 | { |
| 9340 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
| 9341 | |
| 9342 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
| 9343 | b->location = copy_event_location (location); |
| 9344 | |
| 9345 | if (parse_extra) |
| 9346 | b->cond_string = NULL; |
| 9347 | else |
| 9348 | { |
| 9349 | /* Create a private copy of condition string. */ |
| 9350 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
| 9351 | b->thread = thread; |
| 9352 | } |
| 9353 | |
| 9354 | /* Create a private copy of any extra string. */ |
| 9355 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
| 9356 | b->ignore_count = ignore_count; |
| 9357 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 9358 | b->condition_not_parsed = 1; |
| 9359 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 9360 | if ((type_wanted != bp_breakpoint |
| 9361 | && type_wanted != bp_hardware_breakpoint) || thread != -1) |
| 9362 | b->pspace = current_program_space; |
| 9363 | |
| 9364 | install_breakpoint (internal, std::move (b), 0); |
| 9365 | } |
| 9366 | |
| 9367 | if (canonical.lsals.size () > 1) |
| 9368 | { |
| 9369 | warning (_("Multiple breakpoints were set.\nUse the " |
| 9370 | "\"delete\" command to delete unwanted breakpoints.")); |
| 9371 | prev_breakpoint_count = prev_bkpt_count; |
| 9372 | } |
| 9373 | |
| 9374 | update_global_location_list (UGLL_MAY_INSERT); |
| 9375 | |
| 9376 | return 1; |
| 9377 | } |
| 9378 | |
| 9379 | /* Set a breakpoint. |
| 9380 | ARG is a string describing breakpoint address, |
| 9381 | condition, and thread. |
| 9382 | FLAG specifies if a breakpoint is hardware on, |
| 9383 | and if breakpoint is temporary, using BP_HARDWARE_FLAG |
| 9384 | and BP_TEMPFLAG. */ |
| 9385 | |
| 9386 | static void |
| 9387 | break_command_1 (const char *arg, int flag, int from_tty) |
| 9388 | { |
| 9389 | int tempflag = flag & BP_TEMPFLAG; |
| 9390 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
| 9391 | ? bp_hardware_breakpoint |
| 9392 | : bp_breakpoint); |
| 9393 | |
| 9394 | event_location_up location = string_to_event_location (&arg, current_language); |
| 9395 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
| 9396 | (location.get (), false /* is_tracepoint */); |
| 9397 | |
| 9398 | create_breakpoint (get_current_arch (), |
| 9399 | location.get (), |
| 9400 | NULL, 0, arg, 1 /* parse arg */, |
| 9401 | tempflag, type_wanted, |
| 9402 | 0 /* Ignore count */, |
| 9403 | pending_break_support, |
| 9404 | ops, |
| 9405 | from_tty, |
| 9406 | 1 /* enabled */, |
| 9407 | 0 /* internal */, |
| 9408 | 0); |
| 9409 | } |
| 9410 | |
| 9411 | /* Helper function for break_command_1 and disassemble_command. */ |
| 9412 | |
| 9413 | void |
| 9414 | resolve_sal_pc (struct symtab_and_line *sal) |
| 9415 | { |
| 9416 | CORE_ADDR pc; |
| 9417 | |
| 9418 | if (sal->pc == 0 && sal->symtab != NULL) |
| 9419 | { |
| 9420 | if (!find_line_pc (sal->symtab, sal->line, &pc)) |
| 9421 | error (_("No line %d in file \"%s\"."), |
| 9422 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
| 9423 | sal->pc = pc; |
| 9424 | |
| 9425 | /* If this SAL corresponds to a breakpoint inserted using a line |
| 9426 | number, then skip the function prologue if necessary. */ |
| 9427 | if (sal->explicit_line) |
| 9428 | skip_prologue_sal (sal); |
| 9429 | } |
| 9430 | |
| 9431 | if (sal->section == 0 && sal->symtab != NULL) |
| 9432 | { |
| 9433 | const struct blockvector *bv; |
| 9434 | const struct block *b; |
| 9435 | struct symbol *sym; |
| 9436 | |
| 9437 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
| 9438 | SYMTAB_COMPUNIT (sal->symtab)); |
| 9439 | if (bv != NULL) |
| 9440 | { |
| 9441 | sym = block_linkage_function (b); |
| 9442 | if (sym != NULL) |
| 9443 | { |
| 9444 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
| 9445 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), |
| 9446 | sym); |
| 9447 | } |
| 9448 | else |
| 9449 | { |
| 9450 | /* It really is worthwhile to have the section, so we'll |
| 9451 | just have to look harder. This case can be executed |
| 9452 | if we have line numbers but no functions (as can |
| 9453 | happen in assembly source). */ |
| 9454 | |
| 9455 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 9456 | switch_to_program_space_and_thread (sal->pspace); |
| 9457 | |
| 9458 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
| 9459 | if (msym.minsym) |
| 9460 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
| 9461 | } |
| 9462 | } |
| 9463 | } |
| 9464 | } |
| 9465 | |
| 9466 | void |
| 9467 | break_command (const char *arg, int from_tty) |
| 9468 | { |
| 9469 | break_command_1 (arg, 0, from_tty); |
| 9470 | } |
| 9471 | |
| 9472 | void |
| 9473 | tbreak_command (const char *arg, int from_tty) |
| 9474 | { |
| 9475 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
| 9476 | } |
| 9477 | |
| 9478 | static void |
| 9479 | hbreak_command (const char *arg, int from_tty) |
| 9480 | { |
| 9481 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
| 9482 | } |
| 9483 | |
| 9484 | static void |
| 9485 | thbreak_command (const char *arg, int from_tty) |
| 9486 | { |
| 9487 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
| 9488 | } |
| 9489 | |
| 9490 | static void |
| 9491 | stop_command (const char *arg, int from_tty) |
| 9492 | { |
| 9493 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
| 9494 | Usage: stop in <function | address>\n\ |
| 9495 | stop at <line>\n")); |
| 9496 | } |
| 9497 | |
| 9498 | static void |
| 9499 | stopin_command (const char *arg, int from_tty) |
| 9500 | { |
| 9501 | int badInput = 0; |
| 9502 | |
| 9503 | if (arg == NULL) |
| 9504 | badInput = 1; |
| 9505 | else if (*arg != '*') |
| 9506 | { |
| 9507 | const char *argptr = arg; |
| 9508 | int hasColon = 0; |
| 9509 | |
| 9510 | /* Look for a ':'. If this is a line number specification, then |
| 9511 | say it is bad, otherwise, it should be an address or |
| 9512 | function/method name. */ |
| 9513 | while (*argptr && !hasColon) |
| 9514 | { |
| 9515 | hasColon = (*argptr == ':'); |
| 9516 | argptr++; |
| 9517 | } |
| 9518 | |
| 9519 | if (hasColon) |
| 9520 | badInput = (*argptr != ':'); /* Not a class::method */ |
| 9521 | else |
| 9522 | badInput = isdigit (*arg); /* a simple line number */ |
| 9523 | } |
| 9524 | |
| 9525 | if (badInput) |
| 9526 | printf_filtered (_("Usage: stop in <function | address>\n")); |
| 9527 | else |
| 9528 | break_command_1 (arg, 0, from_tty); |
| 9529 | } |
| 9530 | |
| 9531 | static void |
| 9532 | stopat_command (const char *arg, int from_tty) |
| 9533 | { |
| 9534 | int badInput = 0; |
| 9535 | |
| 9536 | if (arg == NULL || *arg == '*') /* no line number */ |
| 9537 | badInput = 1; |
| 9538 | else |
| 9539 | { |
| 9540 | const char *argptr = arg; |
| 9541 | int hasColon = 0; |
| 9542 | |
| 9543 | /* Look for a ':'. If there is a '::' then get out, otherwise |
| 9544 | it is probably a line number. */ |
| 9545 | while (*argptr && !hasColon) |
| 9546 | { |
| 9547 | hasColon = (*argptr == ':'); |
| 9548 | argptr++; |
| 9549 | } |
| 9550 | |
| 9551 | if (hasColon) |
| 9552 | badInput = (*argptr == ':'); /* we have class::method */ |
| 9553 | else |
| 9554 | badInput = !isdigit (*arg); /* not a line number */ |
| 9555 | } |
| 9556 | |
| 9557 | if (badInput) |
| 9558 | printf_filtered (_("Usage: stop at LINE\n")); |
| 9559 | else |
| 9560 | break_command_1 (arg, 0, from_tty); |
| 9561 | } |
| 9562 | |
| 9563 | /* The dynamic printf command is mostly like a regular breakpoint, but |
| 9564 | with a prewired command list consisting of a single output command, |
| 9565 | built from extra arguments supplied on the dprintf command |
| 9566 | line. */ |
| 9567 | |
| 9568 | static void |
| 9569 | dprintf_command (const char *arg, int from_tty) |
| 9570 | { |
| 9571 | event_location_up location = string_to_event_location (&arg, current_language); |
| 9572 | |
| 9573 | /* If non-NULL, ARG should have been advanced past the location; |
| 9574 | the next character must be ','. */ |
| 9575 | if (arg != NULL) |
| 9576 | { |
| 9577 | if (arg[0] != ',' || arg[1] == '\0') |
| 9578 | error (_("Format string required")); |
| 9579 | else |
| 9580 | { |
| 9581 | /* Skip the comma. */ |
| 9582 | ++arg; |
| 9583 | } |
| 9584 | } |
| 9585 | |
| 9586 | create_breakpoint (get_current_arch (), |
| 9587 | location.get (), |
| 9588 | NULL, 0, arg, 1 /* parse arg */, |
| 9589 | 0, bp_dprintf, |
| 9590 | 0 /* Ignore count */, |
| 9591 | pending_break_support, |
| 9592 | &dprintf_breakpoint_ops, |
| 9593 | from_tty, |
| 9594 | 1 /* enabled */, |
| 9595 | 0 /* internal */, |
| 9596 | 0); |
| 9597 | } |
| 9598 | |
| 9599 | static void |
| 9600 | agent_printf_command (const char *arg, int from_tty) |
| 9601 | { |
| 9602 | error (_("May only run agent-printf on the target")); |
| 9603 | } |
| 9604 | |
| 9605 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
| 9606 | ranged breakpoints. */ |
| 9607 | |
| 9608 | static int |
| 9609 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, |
| 9610 | const address_space *aspace, |
| 9611 | CORE_ADDR bp_addr, |
| 9612 | const struct target_waitstatus *ws) |
| 9613 | { |
| 9614 | if (ws->kind != TARGET_WAITKIND_STOPPED |
| 9615 | || ws->value.sig != GDB_SIGNAL_TRAP) |
| 9616 | return 0; |
| 9617 | |
| 9618 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
| 9619 | bl->length, aspace, bp_addr); |
| 9620 | } |
| 9621 | |
| 9622 | /* Implement the "resources_needed" breakpoint_ops method for |
| 9623 | ranged breakpoints. */ |
| 9624 | |
| 9625 | static int |
| 9626 | resources_needed_ranged_breakpoint (const struct bp_location *bl) |
| 9627 | { |
| 9628 | return target_ranged_break_num_registers (); |
| 9629 | } |
| 9630 | |
| 9631 | /* Implement the "print_it" breakpoint_ops method for |
| 9632 | ranged breakpoints. */ |
| 9633 | |
| 9634 | static enum print_stop_action |
| 9635 | print_it_ranged_breakpoint (bpstat bs) |
| 9636 | { |
| 9637 | struct breakpoint *b = bs->breakpoint_at; |
| 9638 | struct bp_location *bl = b->loc; |
| 9639 | struct ui_out *uiout = current_uiout; |
| 9640 | |
| 9641 | gdb_assert (b->type == bp_hardware_breakpoint); |
| 9642 | |
| 9643 | /* Ranged breakpoints have only one location. */ |
| 9644 | gdb_assert (bl && bl->next == NULL); |
| 9645 | |
| 9646 | annotate_breakpoint (b->number); |
| 9647 | |
| 9648 | maybe_print_thread_hit_breakpoint (uiout); |
| 9649 | |
| 9650 | if (b->disposition == disp_del) |
| 9651 | uiout->text ("Temporary ranged breakpoint "); |
| 9652 | else |
| 9653 | uiout->text ("Ranged breakpoint "); |
| 9654 | if (uiout->is_mi_like_p ()) |
| 9655 | { |
| 9656 | uiout->field_string ("reason", |
| 9657 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 9658 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 9659 | } |
| 9660 | uiout->field_signed ("bkptno", b->number); |
| 9661 | uiout->text (", "); |
| 9662 | |
| 9663 | return PRINT_SRC_AND_LOC; |
| 9664 | } |
| 9665 | |
| 9666 | /* Implement the "print_one" breakpoint_ops method for |
| 9667 | ranged breakpoints. */ |
| 9668 | |
| 9669 | static void |
| 9670 | print_one_ranged_breakpoint (struct breakpoint *b, |
| 9671 | struct bp_location **last_loc) |
| 9672 | { |
| 9673 | struct bp_location *bl = b->loc; |
| 9674 | struct value_print_options opts; |
| 9675 | struct ui_out *uiout = current_uiout; |
| 9676 | |
| 9677 | /* Ranged breakpoints have only one location. */ |
| 9678 | gdb_assert (bl && bl->next == NULL); |
| 9679 | |
| 9680 | get_user_print_options (&opts); |
| 9681 | |
| 9682 | if (opts.addressprint) |
| 9683 | /* We don't print the address range here, it will be printed later |
| 9684 | by print_one_detail_ranged_breakpoint. */ |
| 9685 | uiout->field_skip ("addr"); |
| 9686 | annotate_field (5); |
| 9687 | print_breakpoint_location (b, bl); |
| 9688 | *last_loc = bl; |
| 9689 | } |
| 9690 | |
| 9691 | /* Implement the "print_one_detail" breakpoint_ops method for |
| 9692 | ranged breakpoints. */ |
| 9693 | |
| 9694 | static void |
| 9695 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, |
| 9696 | struct ui_out *uiout) |
| 9697 | { |
| 9698 | CORE_ADDR address_start, address_end; |
| 9699 | struct bp_location *bl = b->loc; |
| 9700 | string_file stb; |
| 9701 | |
| 9702 | gdb_assert (bl); |
| 9703 | |
| 9704 | address_start = bl->address; |
| 9705 | address_end = address_start + bl->length - 1; |
| 9706 | |
| 9707 | uiout->text ("\taddress range: "); |
| 9708 | stb.printf ("[%s, %s]", |
| 9709 | print_core_address (bl->gdbarch, address_start), |
| 9710 | print_core_address (bl->gdbarch, address_end)); |
| 9711 | uiout->field_stream ("addr", stb); |
| 9712 | uiout->text ("\n"); |
| 9713 | } |
| 9714 | |
| 9715 | /* Implement the "print_mention" breakpoint_ops method for |
| 9716 | ranged breakpoints. */ |
| 9717 | |
| 9718 | static void |
| 9719 | print_mention_ranged_breakpoint (struct breakpoint *b) |
| 9720 | { |
| 9721 | struct bp_location *bl = b->loc; |
| 9722 | struct ui_out *uiout = current_uiout; |
| 9723 | |
| 9724 | gdb_assert (bl); |
| 9725 | gdb_assert (b->type == bp_hardware_breakpoint); |
| 9726 | |
| 9727 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
| 9728 | b->number, paddress (bl->gdbarch, bl->address), |
| 9729 | paddress (bl->gdbarch, bl->address + bl->length - 1)); |
| 9730 | } |
| 9731 | |
| 9732 | /* Implement the "print_recreate" breakpoint_ops method for |
| 9733 | ranged breakpoints. */ |
| 9734 | |
| 9735 | static void |
| 9736 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) |
| 9737 | { |
| 9738 | fprintf_unfiltered (fp, "break-range %s, %s", |
| 9739 | event_location_to_string (b->location.get ()), |
| 9740 | event_location_to_string (b->location_range_end.get ())); |
| 9741 | print_recreate_thread (b, fp); |
| 9742 | } |
| 9743 | |
| 9744 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ |
| 9745 | |
| 9746 | static struct breakpoint_ops ranged_breakpoint_ops; |
| 9747 | |
| 9748 | /* Find the address where the end of the breakpoint range should be |
| 9749 | placed, given the SAL of the end of the range. This is so that if |
| 9750 | the user provides a line number, the end of the range is set to the |
| 9751 | last instruction of the given line. */ |
| 9752 | |
| 9753 | static CORE_ADDR |
| 9754 | find_breakpoint_range_end (struct symtab_and_line sal) |
| 9755 | { |
| 9756 | CORE_ADDR end; |
| 9757 | |
| 9758 | /* If the user provided a PC value, use it. Otherwise, |
| 9759 | find the address of the end of the given location. */ |
| 9760 | if (sal.explicit_pc) |
| 9761 | end = sal.pc; |
| 9762 | else |
| 9763 | { |
| 9764 | int ret; |
| 9765 | CORE_ADDR start; |
| 9766 | |
| 9767 | ret = find_line_pc_range (sal, &start, &end); |
| 9768 | if (!ret) |
| 9769 | error (_("Could not find location of the end of the range.")); |
| 9770 | |
| 9771 | /* find_line_pc_range returns the start of the next line. */ |
| 9772 | end--; |
| 9773 | } |
| 9774 | |
| 9775 | return end; |
| 9776 | } |
| 9777 | |
| 9778 | /* Implement the "break-range" CLI command. */ |
| 9779 | |
| 9780 | static void |
| 9781 | break_range_command (const char *arg, int from_tty) |
| 9782 | { |
| 9783 | const char *arg_start; |
| 9784 | struct linespec_result canonical_start, canonical_end; |
| 9785 | int bp_count, can_use_bp, length; |
| 9786 | CORE_ADDR end; |
| 9787 | struct breakpoint *b; |
| 9788 | |
| 9789 | /* We don't support software ranged breakpoints. */ |
| 9790 | if (target_ranged_break_num_registers () < 0) |
| 9791 | error (_("This target does not support hardware ranged breakpoints.")); |
| 9792 | |
| 9793 | bp_count = hw_breakpoint_used_count (); |
| 9794 | bp_count += target_ranged_break_num_registers (); |
| 9795 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 9796 | bp_count, 0); |
| 9797 | if (can_use_bp < 0) |
| 9798 | error (_("Hardware breakpoints used exceeds limit.")); |
| 9799 | |
| 9800 | arg = skip_spaces (arg); |
| 9801 | if (arg == NULL || arg[0] == '\0') |
| 9802 | error(_("No address range specified.")); |
| 9803 | |
| 9804 | arg_start = arg; |
| 9805 | event_location_up start_location = string_to_event_location (&arg, |
| 9806 | current_language); |
| 9807 | parse_breakpoint_sals (start_location.get (), &canonical_start); |
| 9808 | |
| 9809 | if (arg[0] != ',') |
| 9810 | error (_("Too few arguments.")); |
| 9811 | else if (canonical_start.lsals.empty ()) |
| 9812 | error (_("Could not find location of the beginning of the range.")); |
| 9813 | |
| 9814 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
| 9815 | |
| 9816 | if (canonical_start.lsals.size () > 1 |
| 9817 | || lsal_start.sals.size () != 1) |
| 9818 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
| 9819 | |
| 9820 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
| 9821 | std::string addr_string_start (arg_start, arg - arg_start); |
| 9822 | |
| 9823 | arg++; /* Skip the comma. */ |
| 9824 | arg = skip_spaces (arg); |
| 9825 | |
| 9826 | /* Parse the end location. */ |
| 9827 | |
| 9828 | arg_start = arg; |
| 9829 | |
| 9830 | /* We call decode_line_full directly here instead of using |
| 9831 | parse_breakpoint_sals because we need to specify the start location's |
| 9832 | symtab and line as the default symtab and line for the end of the |
| 9833 | range. This makes it possible to have ranges like "foo.c:27, +14", |
| 9834 | where +14 means 14 lines from the start location. */ |
| 9835 | event_location_up end_location = string_to_event_location (&arg, |
| 9836 | current_language); |
| 9837 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, |
| 9838 | sal_start.symtab, sal_start.line, |
| 9839 | &canonical_end, NULL, NULL); |
| 9840 | |
| 9841 | if (canonical_end.lsals.empty ()) |
| 9842 | error (_("Could not find location of the end of the range.")); |
| 9843 | |
| 9844 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
| 9845 | if (canonical_end.lsals.size () > 1 |
| 9846 | || lsal_end.sals.size () != 1) |
| 9847 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
| 9848 | |
| 9849 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
| 9850 | |
| 9851 | end = find_breakpoint_range_end (sal_end); |
| 9852 | if (sal_start.pc > end) |
| 9853 | error (_("Invalid address range, end precedes start.")); |
| 9854 | |
| 9855 | length = end - sal_start.pc + 1; |
| 9856 | if (length < 0) |
| 9857 | /* Length overflowed. */ |
| 9858 | error (_("Address range too large.")); |
| 9859 | else if (length == 1) |
| 9860 | { |
| 9861 | /* This range is simple enough to be handled by |
| 9862 | the `hbreak' command. */ |
| 9863 | hbreak_command (&addr_string_start[0], 1); |
| 9864 | |
| 9865 | return; |
| 9866 | } |
| 9867 | |
| 9868 | /* Now set up the breakpoint. */ |
| 9869 | b = set_raw_breakpoint (get_current_arch (), sal_start, |
| 9870 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
| 9871 | set_breakpoint_count (breakpoint_count + 1); |
| 9872 | b->number = breakpoint_count; |
| 9873 | b->disposition = disp_donttouch; |
| 9874 | b->location = std::move (start_location); |
| 9875 | b->location_range_end = std::move (end_location); |
| 9876 | b->loc->length = length; |
| 9877 | |
| 9878 | mention (b); |
| 9879 | gdb::observers::breakpoint_created.notify (b); |
| 9880 | update_global_location_list (UGLL_MAY_INSERT); |
| 9881 | } |
| 9882 | |
| 9883 | /* Return non-zero if EXP is verified as constant. Returned zero |
| 9884 | means EXP is variable. Also the constant detection may fail for |
| 9885 | some constant expressions and in such case still falsely return |
| 9886 | zero. */ |
| 9887 | |
| 9888 | static int |
| 9889 | watchpoint_exp_is_const (const struct expression *exp) |
| 9890 | { |
| 9891 | int i = exp->nelts; |
| 9892 | |
| 9893 | while (i > 0) |
| 9894 | { |
| 9895 | int oplenp, argsp; |
| 9896 | |
| 9897 | /* We are only interested in the descriptor of each element. */ |
| 9898 | operator_length (exp, i, &oplenp, &argsp); |
| 9899 | i -= oplenp; |
| 9900 | |
| 9901 | switch (exp->elts[i].opcode) |
| 9902 | { |
| 9903 | case BINOP_ADD: |
| 9904 | case BINOP_SUB: |
| 9905 | case BINOP_MUL: |
| 9906 | case BINOP_DIV: |
| 9907 | case BINOP_REM: |
| 9908 | case BINOP_MOD: |
| 9909 | case BINOP_LSH: |
| 9910 | case BINOP_RSH: |
| 9911 | case BINOP_LOGICAL_AND: |
| 9912 | case BINOP_LOGICAL_OR: |
| 9913 | case BINOP_BITWISE_AND: |
| 9914 | case BINOP_BITWISE_IOR: |
| 9915 | case BINOP_BITWISE_XOR: |
| 9916 | case BINOP_EQUAL: |
| 9917 | case BINOP_NOTEQUAL: |
| 9918 | case BINOP_LESS: |
| 9919 | case BINOP_GTR: |
| 9920 | case BINOP_LEQ: |
| 9921 | case BINOP_GEQ: |
| 9922 | case BINOP_REPEAT: |
| 9923 | case BINOP_COMMA: |
| 9924 | case BINOP_EXP: |
| 9925 | case BINOP_MIN: |
| 9926 | case BINOP_MAX: |
| 9927 | case BINOP_INTDIV: |
| 9928 | case BINOP_CONCAT: |
| 9929 | case TERNOP_COND: |
| 9930 | case TERNOP_SLICE: |
| 9931 | |
| 9932 | case OP_LONG: |
| 9933 | case OP_FLOAT: |
| 9934 | case OP_LAST: |
| 9935 | case OP_COMPLEX: |
| 9936 | case OP_STRING: |
| 9937 | case OP_ARRAY: |
| 9938 | case OP_TYPE: |
| 9939 | case OP_TYPEOF: |
| 9940 | case OP_DECLTYPE: |
| 9941 | case OP_TYPEID: |
| 9942 | case OP_NAME: |
| 9943 | case OP_OBJC_NSSTRING: |
| 9944 | |
| 9945 | case UNOP_NEG: |
| 9946 | case UNOP_LOGICAL_NOT: |
| 9947 | case UNOP_COMPLEMENT: |
| 9948 | case UNOP_ADDR: |
| 9949 | case UNOP_HIGH: |
| 9950 | case UNOP_CAST: |
| 9951 | |
| 9952 | case UNOP_CAST_TYPE: |
| 9953 | case UNOP_REINTERPRET_CAST: |
| 9954 | case UNOP_DYNAMIC_CAST: |
| 9955 | /* Unary, binary and ternary operators: We have to check |
| 9956 | their operands. If they are constant, then so is the |
| 9957 | result of that operation. For instance, if A and B are |
| 9958 | determined to be constants, then so is "A + B". |
| 9959 | |
| 9960 | UNOP_IND is one exception to the rule above, because the |
| 9961 | value of *ADDR is not necessarily a constant, even when |
| 9962 | ADDR is. */ |
| 9963 | break; |
| 9964 | |
| 9965 | case OP_VAR_VALUE: |
| 9966 | /* Check whether the associated symbol is a constant. |
| 9967 | |
| 9968 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
| 9969 | possible that a buggy compiler could mark a variable as |
| 9970 | constant even when it is not, and TYPE_CONST would return |
| 9971 | true in this case, while SYMBOL_CLASS wouldn't. |
| 9972 | |
| 9973 | We also have to check for function symbols because they |
| 9974 | are always constant. */ |
| 9975 | { |
| 9976 | struct symbol *s = exp->elts[i + 2].symbol; |
| 9977 | |
| 9978 | if (SYMBOL_CLASS (s) != LOC_BLOCK |
| 9979 | && SYMBOL_CLASS (s) != LOC_CONST |
| 9980 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) |
| 9981 | return 0; |
| 9982 | break; |
| 9983 | } |
| 9984 | |
| 9985 | /* The default action is to return 0 because we are using |
| 9986 | the optimistic approach here: If we don't know something, |
| 9987 | then it is not a constant. */ |
| 9988 | default: |
| 9989 | return 0; |
| 9990 | } |
| 9991 | } |
| 9992 | |
| 9993 | return 1; |
| 9994 | } |
| 9995 | |
| 9996 | /* Watchpoint destructor. */ |
| 9997 | |
| 9998 | watchpoint::~watchpoint () |
| 9999 | { |
| 10000 | xfree (this->exp_string); |
| 10001 | xfree (this->exp_string_reparse); |
| 10002 | } |
| 10003 | |
| 10004 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
| 10005 | |
| 10006 | static void |
| 10007 | re_set_watchpoint (struct breakpoint *b) |
| 10008 | { |
| 10009 | struct watchpoint *w = (struct watchpoint *) b; |
| 10010 | |
| 10011 | /* Watchpoint can be either on expression using entirely global |
| 10012 | variables, or it can be on local variables. |
| 10013 | |
| 10014 | Watchpoints of the first kind are never auto-deleted, and even |
| 10015 | persist across program restarts. Since they can use variables |
| 10016 | from shared libraries, we need to reparse expression as libraries |
| 10017 | are loaded and unloaded. |
| 10018 | |
| 10019 | Watchpoints on local variables can also change meaning as result |
| 10020 | of solib event. For example, if a watchpoint uses both a local |
| 10021 | and a global variables in expression, it's a local watchpoint, |
| 10022 | but unloading of a shared library will make the expression |
| 10023 | invalid. This is not a very common use case, but we still |
| 10024 | re-evaluate expression, to avoid surprises to the user. |
| 10025 | |
| 10026 | Note that for local watchpoints, we re-evaluate it only if |
| 10027 | watchpoints frame id is still valid. If it's not, it means the |
| 10028 | watchpoint is out of scope and will be deleted soon. In fact, |
| 10029 | I'm not sure we'll ever be called in this case. |
| 10030 | |
| 10031 | If a local watchpoint's frame id is still valid, then |
| 10032 | w->exp_valid_block is likewise valid, and we can safely use it. |
| 10033 | |
| 10034 | Don't do anything about disabled watchpoints, since they will be |
| 10035 | reevaluated again when enabled. */ |
| 10036 | update_watchpoint (w, 1 /* reparse */); |
| 10037 | } |
| 10038 | |
| 10039 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
| 10040 | |
| 10041 | static int |
| 10042 | insert_watchpoint (struct bp_location *bl) |
| 10043 | { |
| 10044 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10045 | int length = w->exact ? 1 : bl->length; |
| 10046 | |
| 10047 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, |
| 10048 | w->cond_exp.get ()); |
| 10049 | } |
| 10050 | |
| 10051 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ |
| 10052 | |
| 10053 | static int |
| 10054 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
| 10055 | { |
| 10056 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10057 | int length = w->exact ? 1 : bl->length; |
| 10058 | |
| 10059 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, |
| 10060 | w->cond_exp.get ()); |
| 10061 | } |
| 10062 | |
| 10063 | static int |
| 10064 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
| 10065 | const address_space *aspace, CORE_ADDR bp_addr, |
| 10066 | const struct target_waitstatus *ws) |
| 10067 | { |
| 10068 | struct breakpoint *b = bl->owner; |
| 10069 | struct watchpoint *w = (struct watchpoint *) b; |
| 10070 | |
| 10071 | /* Continuable hardware watchpoints are treated as non-existent if the |
| 10072 | reason we stopped wasn't a hardware watchpoint (we didn't stop on |
| 10073 | some data address). Otherwise gdb won't stop on a break instruction |
| 10074 | in the code (not from a breakpoint) when a hardware watchpoint has |
| 10075 | been defined. Also skip watchpoints which we know did not trigger |
| 10076 | (did not match the data address). */ |
| 10077 | if (is_hardware_watchpoint (b) |
| 10078 | && w->watchpoint_triggered == watch_triggered_no) |
| 10079 | return 0; |
| 10080 | |
| 10081 | return 1; |
| 10082 | } |
| 10083 | |
| 10084 | static void |
| 10085 | check_status_watchpoint (bpstat bs) |
| 10086 | { |
| 10087 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
| 10088 | |
| 10089 | bpstat_check_watchpoint (bs); |
| 10090 | } |
| 10091 | |
| 10092 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10093 | hardware watchpoints. */ |
| 10094 | |
| 10095 | static int |
| 10096 | resources_needed_watchpoint (const struct bp_location *bl) |
| 10097 | { |
| 10098 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10099 | int length = w->exact? 1 : bl->length; |
| 10100 | |
| 10101 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
| 10102 | } |
| 10103 | |
| 10104 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
| 10105 | hardware watchpoints. */ |
| 10106 | |
| 10107 | static int |
| 10108 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
| 10109 | { |
| 10110 | /* Read and access watchpoints only work with hardware support. */ |
| 10111 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; |
| 10112 | } |
| 10113 | |
| 10114 | static enum print_stop_action |
| 10115 | print_it_watchpoint (bpstat bs) |
| 10116 | { |
| 10117 | struct breakpoint *b; |
| 10118 | enum print_stop_action result; |
| 10119 | struct watchpoint *w; |
| 10120 | struct ui_out *uiout = current_uiout; |
| 10121 | |
| 10122 | gdb_assert (bs->bp_location_at != NULL); |
| 10123 | |
| 10124 | b = bs->breakpoint_at; |
| 10125 | w = (struct watchpoint *) b; |
| 10126 | |
| 10127 | annotate_watchpoint (b->number); |
| 10128 | maybe_print_thread_hit_breakpoint (uiout); |
| 10129 | |
| 10130 | string_file stb; |
| 10131 | |
| 10132 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
| 10133 | switch (b->type) |
| 10134 | { |
| 10135 | case bp_watchpoint: |
| 10136 | case bp_hardware_watchpoint: |
| 10137 | if (uiout->is_mi_like_p ()) |
| 10138 | uiout->field_string |
| 10139 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 10140 | mention (b); |
| 10141 | tuple_emitter.emplace (uiout, "value"); |
| 10142 | uiout->text ("\nOld value = "); |
| 10143 | watchpoint_value_print (bs->old_val.get (), &stb); |
| 10144 | uiout->field_stream ("old", stb); |
| 10145 | uiout->text ("\nNew value = "); |
| 10146 | watchpoint_value_print (w->val.get (), &stb); |
| 10147 | uiout->field_stream ("new", stb); |
| 10148 | uiout->text ("\n"); |
| 10149 | /* More than one watchpoint may have been triggered. */ |
| 10150 | result = PRINT_UNKNOWN; |
| 10151 | break; |
| 10152 | |
| 10153 | case bp_read_watchpoint: |
| 10154 | if (uiout->is_mi_like_p ()) |
| 10155 | uiout->field_string |
| 10156 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 10157 | mention (b); |
| 10158 | tuple_emitter.emplace (uiout, "value"); |
| 10159 | uiout->text ("\nValue = "); |
| 10160 | watchpoint_value_print (w->val.get (), &stb); |
| 10161 | uiout->field_stream ("value", stb); |
| 10162 | uiout->text ("\n"); |
| 10163 | result = PRINT_UNKNOWN; |
| 10164 | break; |
| 10165 | |
| 10166 | case bp_access_watchpoint: |
| 10167 | if (bs->old_val != NULL) |
| 10168 | { |
| 10169 | if (uiout->is_mi_like_p ()) |
| 10170 | uiout->field_string |
| 10171 | ("reason", |
| 10172 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10173 | mention (b); |
| 10174 | tuple_emitter.emplace (uiout, "value"); |
| 10175 | uiout->text ("\nOld value = "); |
| 10176 | watchpoint_value_print (bs->old_val.get (), &stb); |
| 10177 | uiout->field_stream ("old", stb); |
| 10178 | uiout->text ("\nNew value = "); |
| 10179 | } |
| 10180 | else |
| 10181 | { |
| 10182 | mention (b); |
| 10183 | if (uiout->is_mi_like_p ()) |
| 10184 | uiout->field_string |
| 10185 | ("reason", |
| 10186 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10187 | tuple_emitter.emplace (uiout, "value"); |
| 10188 | uiout->text ("\nValue = "); |
| 10189 | } |
| 10190 | watchpoint_value_print (w->val.get (), &stb); |
| 10191 | uiout->field_stream ("new", stb); |
| 10192 | uiout->text ("\n"); |
| 10193 | result = PRINT_UNKNOWN; |
| 10194 | break; |
| 10195 | default: |
| 10196 | result = PRINT_UNKNOWN; |
| 10197 | } |
| 10198 | |
| 10199 | return result; |
| 10200 | } |
| 10201 | |
| 10202 | /* Implement the "print_mention" breakpoint_ops method for hardware |
| 10203 | watchpoints. */ |
| 10204 | |
| 10205 | static void |
| 10206 | print_mention_watchpoint (struct breakpoint *b) |
| 10207 | { |
| 10208 | struct watchpoint *w = (struct watchpoint *) b; |
| 10209 | struct ui_out *uiout = current_uiout; |
| 10210 | const char *tuple_name; |
| 10211 | |
| 10212 | switch (b->type) |
| 10213 | { |
| 10214 | case bp_watchpoint: |
| 10215 | uiout->text ("Watchpoint "); |
| 10216 | tuple_name = "wpt"; |
| 10217 | break; |
| 10218 | case bp_hardware_watchpoint: |
| 10219 | uiout->text ("Hardware watchpoint "); |
| 10220 | tuple_name = "wpt"; |
| 10221 | break; |
| 10222 | case bp_read_watchpoint: |
| 10223 | uiout->text ("Hardware read watchpoint "); |
| 10224 | tuple_name = "hw-rwpt"; |
| 10225 | break; |
| 10226 | case bp_access_watchpoint: |
| 10227 | uiout->text ("Hardware access (read/write) watchpoint "); |
| 10228 | tuple_name = "hw-awpt"; |
| 10229 | break; |
| 10230 | default: |
| 10231 | internal_error (__FILE__, __LINE__, |
| 10232 | _("Invalid hardware watchpoint type.")); |
| 10233 | } |
| 10234 | |
| 10235 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
| 10236 | uiout->field_signed ("number", b->number); |
| 10237 | uiout->text (": "); |
| 10238 | uiout->field_string ("exp", w->exp_string); |
| 10239 | } |
| 10240 | |
| 10241 | /* Implement the "print_recreate" breakpoint_ops method for |
| 10242 | watchpoints. */ |
| 10243 | |
| 10244 | static void |
| 10245 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) |
| 10246 | { |
| 10247 | struct watchpoint *w = (struct watchpoint *) b; |
| 10248 | |
| 10249 | switch (b->type) |
| 10250 | { |
| 10251 | case bp_watchpoint: |
| 10252 | case bp_hardware_watchpoint: |
| 10253 | fprintf_unfiltered (fp, "watch"); |
| 10254 | break; |
| 10255 | case bp_read_watchpoint: |
| 10256 | fprintf_unfiltered (fp, "rwatch"); |
| 10257 | break; |
| 10258 | case bp_access_watchpoint: |
| 10259 | fprintf_unfiltered (fp, "awatch"); |
| 10260 | break; |
| 10261 | default: |
| 10262 | internal_error (__FILE__, __LINE__, |
| 10263 | _("Invalid watchpoint type.")); |
| 10264 | } |
| 10265 | |
| 10266 | fprintf_unfiltered (fp, " %s", w->exp_string); |
| 10267 | print_recreate_thread (b, fp); |
| 10268 | } |
| 10269 | |
| 10270 | /* Implement the "explains_signal" breakpoint_ops method for |
| 10271 | watchpoints. */ |
| 10272 | |
| 10273 | static int |
| 10274 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
| 10275 | { |
| 10276 | /* A software watchpoint cannot cause a signal other than |
| 10277 | GDB_SIGNAL_TRAP. */ |
| 10278 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) |
| 10279 | return 0; |
| 10280 | |
| 10281 | return 1; |
| 10282 | } |
| 10283 | |
| 10284 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
| 10285 | |
| 10286 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
| 10287 | |
| 10288 | /* Implement the "insert" breakpoint_ops method for |
| 10289 | masked hardware watchpoints. */ |
| 10290 | |
| 10291 | static int |
| 10292 | insert_masked_watchpoint (struct bp_location *bl) |
| 10293 | { |
| 10294 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10295 | |
| 10296 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, |
| 10297 | bl->watchpoint_type); |
| 10298 | } |
| 10299 | |
| 10300 | /* Implement the "remove" breakpoint_ops method for |
| 10301 | masked hardware watchpoints. */ |
| 10302 | |
| 10303 | static int |
| 10304 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
| 10305 | { |
| 10306 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10307 | |
| 10308 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, |
| 10309 | bl->watchpoint_type); |
| 10310 | } |
| 10311 | |
| 10312 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10313 | masked hardware watchpoints. */ |
| 10314 | |
| 10315 | static int |
| 10316 | resources_needed_masked_watchpoint (const struct bp_location *bl) |
| 10317 | { |
| 10318 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10319 | |
| 10320 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); |
| 10321 | } |
| 10322 | |
| 10323 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
| 10324 | masked hardware watchpoints. */ |
| 10325 | |
| 10326 | static int |
| 10327 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) |
| 10328 | { |
| 10329 | return 0; |
| 10330 | } |
| 10331 | |
| 10332 | /* Implement the "print_it" breakpoint_ops method for |
| 10333 | masked hardware watchpoints. */ |
| 10334 | |
| 10335 | static enum print_stop_action |
| 10336 | print_it_masked_watchpoint (bpstat bs) |
| 10337 | { |
| 10338 | struct breakpoint *b = bs->breakpoint_at; |
| 10339 | struct ui_out *uiout = current_uiout; |
| 10340 | |
| 10341 | /* Masked watchpoints have only one location. */ |
| 10342 | gdb_assert (b->loc && b->loc->next == NULL); |
| 10343 | |
| 10344 | annotate_watchpoint (b->number); |
| 10345 | maybe_print_thread_hit_breakpoint (uiout); |
| 10346 | |
| 10347 | switch (b->type) |
| 10348 | { |
| 10349 | case bp_hardware_watchpoint: |
| 10350 | if (uiout->is_mi_like_p ()) |
| 10351 | uiout->field_string |
| 10352 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 10353 | break; |
| 10354 | |
| 10355 | case bp_read_watchpoint: |
| 10356 | if (uiout->is_mi_like_p ()) |
| 10357 | uiout->field_string |
| 10358 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 10359 | break; |
| 10360 | |
| 10361 | case bp_access_watchpoint: |
| 10362 | if (uiout->is_mi_like_p ()) |
| 10363 | uiout->field_string |
| 10364 | ("reason", |
| 10365 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10366 | break; |
| 10367 | default: |
| 10368 | internal_error (__FILE__, __LINE__, |
| 10369 | _("Invalid hardware watchpoint type.")); |
| 10370 | } |
| 10371 | |
| 10372 | mention (b); |
| 10373 | uiout->text (_("\n\ |
| 10374 | Check the underlying instruction at PC for the memory\n\ |
| 10375 | address and value which triggered this watchpoint.\n")); |
| 10376 | uiout->text ("\n"); |
| 10377 | |
| 10378 | /* More than one watchpoint may have been triggered. */ |
| 10379 | return PRINT_UNKNOWN; |
| 10380 | } |
| 10381 | |
| 10382 | /* Implement the "print_one_detail" breakpoint_ops method for |
| 10383 | masked hardware watchpoints. */ |
| 10384 | |
| 10385 | static void |
| 10386 | print_one_detail_masked_watchpoint (const struct breakpoint *b, |
| 10387 | struct ui_out *uiout) |
| 10388 | { |
| 10389 | struct watchpoint *w = (struct watchpoint *) b; |
| 10390 | |
| 10391 | /* Masked watchpoints have only one location. */ |
| 10392 | gdb_assert (b->loc && b->loc->next == NULL); |
| 10393 | |
| 10394 | uiout->text ("\tmask "); |
| 10395 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); |
| 10396 | uiout->text ("\n"); |
| 10397 | } |
| 10398 | |
| 10399 | /* Implement the "print_mention" breakpoint_ops method for |
| 10400 | masked hardware watchpoints. */ |
| 10401 | |
| 10402 | static void |
| 10403 | print_mention_masked_watchpoint (struct breakpoint *b) |
| 10404 | { |
| 10405 | struct watchpoint *w = (struct watchpoint *) b; |
| 10406 | struct ui_out *uiout = current_uiout; |
| 10407 | const char *tuple_name; |
| 10408 | |
| 10409 | switch (b->type) |
| 10410 | { |
| 10411 | case bp_hardware_watchpoint: |
| 10412 | uiout->text ("Masked hardware watchpoint "); |
| 10413 | tuple_name = "wpt"; |
| 10414 | break; |
| 10415 | case bp_read_watchpoint: |
| 10416 | uiout->text ("Masked hardware read watchpoint "); |
| 10417 | tuple_name = "hw-rwpt"; |
| 10418 | break; |
| 10419 | case bp_access_watchpoint: |
| 10420 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
| 10421 | tuple_name = "hw-awpt"; |
| 10422 | break; |
| 10423 | default: |
| 10424 | internal_error (__FILE__, __LINE__, |
| 10425 | _("Invalid hardware watchpoint type.")); |
| 10426 | } |
| 10427 | |
| 10428 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
| 10429 | uiout->field_signed ("number", b->number); |
| 10430 | uiout->text (": "); |
| 10431 | uiout->field_string ("exp", w->exp_string); |
| 10432 | } |
| 10433 | |
| 10434 | /* Implement the "print_recreate" breakpoint_ops method for |
| 10435 | masked hardware watchpoints. */ |
| 10436 | |
| 10437 | static void |
| 10438 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) |
| 10439 | { |
| 10440 | struct watchpoint *w = (struct watchpoint *) b; |
| 10441 | char tmp[40]; |
| 10442 | |
| 10443 | switch (b->type) |
| 10444 | { |
| 10445 | case bp_hardware_watchpoint: |
| 10446 | fprintf_unfiltered (fp, "watch"); |
| 10447 | break; |
| 10448 | case bp_read_watchpoint: |
| 10449 | fprintf_unfiltered (fp, "rwatch"); |
| 10450 | break; |
| 10451 | case bp_access_watchpoint: |
| 10452 | fprintf_unfiltered (fp, "awatch"); |
| 10453 | break; |
| 10454 | default: |
| 10455 | internal_error (__FILE__, __LINE__, |
| 10456 | _("Invalid hardware watchpoint type.")); |
| 10457 | } |
| 10458 | |
| 10459 | sprintf_vma (tmp, w->hw_wp_mask); |
| 10460 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); |
| 10461 | print_recreate_thread (b, fp); |
| 10462 | } |
| 10463 | |
| 10464 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ |
| 10465 | |
| 10466 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
| 10467 | |
| 10468 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ |
| 10469 | |
| 10470 | static bool |
| 10471 | is_masked_watchpoint (const struct breakpoint *b) |
| 10472 | { |
| 10473 | return b->ops == &masked_watchpoint_breakpoint_ops; |
| 10474 | } |
| 10475 | |
| 10476 | /* accessflag: hw_write: watch write, |
| 10477 | hw_read: watch read, |
| 10478 | hw_access: watch access (read or write) */ |
| 10479 | static void |
| 10480 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
| 10481 | int just_location, int internal) |
| 10482 | { |
| 10483 | struct breakpoint *scope_breakpoint = NULL; |
| 10484 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
| 10485 | struct value *result; |
| 10486 | int saved_bitpos = 0, saved_bitsize = 0; |
| 10487 | const char *exp_start = NULL; |
| 10488 | const char *exp_end = NULL; |
| 10489 | const char *tok, *end_tok; |
| 10490 | int toklen = -1; |
| 10491 | const char *cond_start = NULL; |
| 10492 | const char *cond_end = NULL; |
| 10493 | enum bptype bp_type; |
| 10494 | int thread = -1; |
| 10495 | int pc = 0; |
| 10496 | /* Flag to indicate whether we are going to use masks for |
| 10497 | the hardware watchpoint. */ |
| 10498 | int use_mask = 0; |
| 10499 | CORE_ADDR mask = 0; |
| 10500 | |
| 10501 | /* Make sure that we actually have parameters to parse. */ |
| 10502 | if (arg != NULL && arg[0] != '\0') |
| 10503 | { |
| 10504 | const char *value_start; |
| 10505 | |
| 10506 | exp_end = arg + strlen (arg); |
| 10507 | |
| 10508 | /* Look for "parameter value" pairs at the end |
| 10509 | of the arguments string. */ |
| 10510 | for (tok = exp_end - 1; tok > arg; tok--) |
| 10511 | { |
| 10512 | /* Skip whitespace at the end of the argument list. */ |
| 10513 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 10514 | tok--; |
| 10515 | |
| 10516 | /* Find the beginning of the last token. |
| 10517 | This is the value of the parameter. */ |
| 10518 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 10519 | tok--; |
| 10520 | value_start = tok + 1; |
| 10521 | |
| 10522 | /* Skip whitespace. */ |
| 10523 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 10524 | tok--; |
| 10525 | |
| 10526 | end_tok = tok; |
| 10527 | |
| 10528 | /* Find the beginning of the second to last token. |
| 10529 | This is the parameter itself. */ |
| 10530 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 10531 | tok--; |
| 10532 | tok++; |
| 10533 | toklen = end_tok - tok + 1; |
| 10534 | |
| 10535 | if (toklen == 6 && startswith (tok, "thread")) |
| 10536 | { |
| 10537 | struct thread_info *thr; |
| 10538 | /* At this point we've found a "thread" token, which means |
| 10539 | the user is trying to set a watchpoint that triggers |
| 10540 | only in a specific thread. */ |
| 10541 | const char *endp; |
| 10542 | |
| 10543 | if (thread != -1) |
| 10544 | error(_("You can specify only one thread.")); |
| 10545 | |
| 10546 | /* Extract the thread ID from the next token. */ |
| 10547 | thr = parse_thread_id (value_start, &endp); |
| 10548 | |
| 10549 | /* Check if the user provided a valid thread ID. */ |
| 10550 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
| 10551 | invalid_thread_id_error (value_start); |
| 10552 | |
| 10553 | thread = thr->global_num; |
| 10554 | } |
| 10555 | else if (toklen == 4 && startswith (tok, "mask")) |
| 10556 | { |
| 10557 | /* We've found a "mask" token, which means the user wants to |
| 10558 | create a hardware watchpoint that is going to have the mask |
| 10559 | facility. */ |
| 10560 | struct value *mask_value, *mark; |
| 10561 | |
| 10562 | if (use_mask) |
| 10563 | error(_("You can specify only one mask.")); |
| 10564 | |
| 10565 | use_mask = just_location = 1; |
| 10566 | |
| 10567 | mark = value_mark (); |
| 10568 | mask_value = parse_to_comma_and_eval (&value_start); |
| 10569 | mask = value_as_address (mask_value); |
| 10570 | value_free_to_mark (mark); |
| 10571 | } |
| 10572 | else |
| 10573 | /* We didn't recognize what we found. We should stop here. */ |
| 10574 | break; |
| 10575 | |
| 10576 | /* Truncate the string and get rid of the "parameter value" pair before |
| 10577 | the arguments string is parsed by the parse_exp_1 function. */ |
| 10578 | exp_end = tok; |
| 10579 | } |
| 10580 | } |
| 10581 | else |
| 10582 | exp_end = arg; |
| 10583 | |
| 10584 | /* Parse the rest of the arguments. From here on out, everything |
| 10585 | is in terms of a newly allocated string instead of the original |
| 10586 | ARG. */ |
| 10587 | std::string expression (arg, exp_end - arg); |
| 10588 | exp_start = arg = expression.c_str (); |
| 10589 | innermost_block_tracker tracker; |
| 10590 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
| 10591 | exp_end = arg; |
| 10592 | /* Remove trailing whitespace from the expression before saving it. |
| 10593 | This makes the eventual display of the expression string a bit |
| 10594 | prettier. */ |
| 10595 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) |
| 10596 | --exp_end; |
| 10597 | |
| 10598 | /* Checking if the expression is not constant. */ |
| 10599 | if (watchpoint_exp_is_const (exp.get ())) |
| 10600 | { |
| 10601 | int len; |
| 10602 | |
| 10603 | len = exp_end - exp_start; |
| 10604 | while (len > 0 && isspace (exp_start[len - 1])) |
| 10605 | len--; |
| 10606 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); |
| 10607 | } |
| 10608 | |
| 10609 | exp_valid_block = tracker.block (); |
| 10610 | struct value *mark = value_mark (); |
| 10611 | struct value *val_as_value = nullptr; |
| 10612 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, |
| 10613 | just_location); |
| 10614 | |
| 10615 | if (val_as_value != NULL && just_location) |
| 10616 | { |
| 10617 | saved_bitpos = value_bitpos (val_as_value); |
| 10618 | saved_bitsize = value_bitsize (val_as_value); |
| 10619 | } |
| 10620 | |
| 10621 | value_ref_ptr val; |
| 10622 | if (just_location) |
| 10623 | { |
| 10624 | int ret; |
| 10625 | |
| 10626 | exp_valid_block = NULL; |
| 10627 | val = release_value (value_addr (result)); |
| 10628 | value_free_to_mark (mark); |
| 10629 | |
| 10630 | if (use_mask) |
| 10631 | { |
| 10632 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
| 10633 | mask); |
| 10634 | if (ret == -1) |
| 10635 | error (_("This target does not support masked watchpoints.")); |
| 10636 | else if (ret == -2) |
| 10637 | error (_("Invalid mask or memory region.")); |
| 10638 | } |
| 10639 | } |
| 10640 | else if (val_as_value != NULL) |
| 10641 | val = release_value (val_as_value); |
| 10642 | |
| 10643 | tok = skip_spaces (arg); |
| 10644 | end_tok = skip_to_space (tok); |
| 10645 | |
| 10646 | toklen = end_tok - tok; |
| 10647 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 10648 | { |
| 10649 | tok = cond_start = end_tok + 1; |
| 10650 | innermost_block_tracker if_tracker; |
| 10651 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); |
| 10652 | |
| 10653 | /* The watchpoint expression may not be local, but the condition |
| 10654 | may still be. E.g.: `watch global if local > 0'. */ |
| 10655 | cond_exp_valid_block = if_tracker.block (); |
| 10656 | |
| 10657 | cond_end = tok; |
| 10658 | } |
| 10659 | if (*tok) |
| 10660 | error (_("Junk at end of command.")); |
| 10661 | |
| 10662 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
| 10663 | |
| 10664 | /* Save this because create_internal_breakpoint below invalidates |
| 10665 | 'wp_frame'. */ |
| 10666 | frame_id watchpoint_frame = get_frame_id (wp_frame); |
| 10667 | |
| 10668 | /* If the expression is "local", then set up a "watchpoint scope" |
| 10669 | breakpoint at the point where we've left the scope of the watchpoint |
| 10670 | expression. Create the scope breakpoint before the watchpoint, so |
| 10671 | that we will encounter it first in bpstat_stop_status. */ |
| 10672 | if (exp_valid_block != NULL && wp_frame != NULL) |
| 10673 | { |
| 10674 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
| 10675 | |
| 10676 | if (frame_id_p (caller_frame_id)) |
| 10677 | { |
| 10678 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
| 10679 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); |
| 10680 | |
| 10681 | scope_breakpoint |
| 10682 | = create_internal_breakpoint (caller_arch, caller_pc, |
| 10683 | bp_watchpoint_scope, |
| 10684 | &momentary_breakpoint_ops); |
| 10685 | |
| 10686 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
| 10687 | wp_frame = NULL; |
| 10688 | |
| 10689 | scope_breakpoint->enable_state = bp_enabled; |
| 10690 | |
| 10691 | /* Automatically delete the breakpoint when it hits. */ |
| 10692 | scope_breakpoint->disposition = disp_del; |
| 10693 | |
| 10694 | /* Only break in the proper frame (help with recursion). */ |
| 10695 | scope_breakpoint->frame_id = caller_frame_id; |
| 10696 | |
| 10697 | /* Set the address at which we will stop. */ |
| 10698 | scope_breakpoint->loc->gdbarch = caller_arch; |
| 10699 | scope_breakpoint->loc->requested_address = caller_pc; |
| 10700 | scope_breakpoint->loc->address |
| 10701 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
| 10702 | scope_breakpoint->loc->requested_address, |
| 10703 | scope_breakpoint->type); |
| 10704 | } |
| 10705 | } |
| 10706 | |
| 10707 | /* Now set up the breakpoint. We create all watchpoints as hardware |
| 10708 | watchpoints here even if hardware watchpoints are turned off, a call |
| 10709 | to update_watchpoint later in this function will cause the type to |
| 10710 | drop back to bp_watchpoint (software watchpoint) if required. */ |
| 10711 | |
| 10712 | if (accessflag == hw_read) |
| 10713 | bp_type = bp_read_watchpoint; |
| 10714 | else if (accessflag == hw_access) |
| 10715 | bp_type = bp_access_watchpoint; |
| 10716 | else |
| 10717 | bp_type = bp_hardware_watchpoint; |
| 10718 | |
| 10719 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
| 10720 | |
| 10721 | if (use_mask) |
| 10722 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
| 10723 | &masked_watchpoint_breakpoint_ops); |
| 10724 | else |
| 10725 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
| 10726 | &watchpoint_breakpoint_ops); |
| 10727 | w->thread = thread; |
| 10728 | w->disposition = disp_donttouch; |
| 10729 | w->pspace = current_program_space; |
| 10730 | w->exp = std::move (exp); |
| 10731 | w->exp_valid_block = exp_valid_block; |
| 10732 | w->cond_exp_valid_block = cond_exp_valid_block; |
| 10733 | if (just_location) |
| 10734 | { |
| 10735 | struct type *t = value_type (val.get ()); |
| 10736 | CORE_ADDR addr = value_as_address (val.get ()); |
| 10737 | |
| 10738 | w->exp_string_reparse |
| 10739 | = current_language->la_watch_location_expression (t, addr).release (); |
| 10740 | |
| 10741 | w->exp_string = xstrprintf ("-location %.*s", |
| 10742 | (int) (exp_end - exp_start), exp_start); |
| 10743 | } |
| 10744 | else |
| 10745 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
| 10746 | |
| 10747 | if (use_mask) |
| 10748 | { |
| 10749 | w->hw_wp_mask = mask; |
| 10750 | } |
| 10751 | else |
| 10752 | { |
| 10753 | w->val = val; |
| 10754 | w->val_bitpos = saved_bitpos; |
| 10755 | w->val_bitsize = saved_bitsize; |
| 10756 | w->val_valid = true; |
| 10757 | } |
| 10758 | |
| 10759 | if (cond_start) |
| 10760 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
| 10761 | else |
| 10762 | w->cond_string = 0; |
| 10763 | |
| 10764 | if (frame_id_p (watchpoint_frame)) |
| 10765 | { |
| 10766 | w->watchpoint_frame = watchpoint_frame; |
| 10767 | w->watchpoint_thread = inferior_ptid; |
| 10768 | } |
| 10769 | else |
| 10770 | { |
| 10771 | w->watchpoint_frame = null_frame_id; |
| 10772 | w->watchpoint_thread = null_ptid; |
| 10773 | } |
| 10774 | |
| 10775 | if (scope_breakpoint != NULL) |
| 10776 | { |
| 10777 | /* The scope breakpoint is related to the watchpoint. We will |
| 10778 | need to act on them together. */ |
| 10779 | w->related_breakpoint = scope_breakpoint; |
| 10780 | scope_breakpoint->related_breakpoint = w.get (); |
| 10781 | } |
| 10782 | |
| 10783 | if (!just_location) |
| 10784 | value_free_to_mark (mark); |
| 10785 | |
| 10786 | /* Finally update the new watchpoint. This creates the locations |
| 10787 | that should be inserted. */ |
| 10788 | update_watchpoint (w.get (), 1); |
| 10789 | |
| 10790 | install_breakpoint (internal, std::move (w), 1); |
| 10791 | } |
| 10792 | |
| 10793 | /* Return count of debug registers needed to watch the given expression. |
| 10794 | If the watchpoint cannot be handled in hardware return zero. */ |
| 10795 | |
| 10796 | static int |
| 10797 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
| 10798 | { |
| 10799 | int found_memory_cnt = 0; |
| 10800 | |
| 10801 | /* Did the user specifically forbid us to use hardware watchpoints? */ |
| 10802 | if (!can_use_hw_watchpoints) |
| 10803 | return 0; |
| 10804 | |
| 10805 | gdb_assert (!vals.empty ()); |
| 10806 | struct value *head = vals[0].get (); |
| 10807 | |
| 10808 | /* Make sure that the value of the expression depends only upon |
| 10809 | memory contents, and values computed from them within GDB. If we |
| 10810 | find any register references or function calls, we can't use a |
| 10811 | hardware watchpoint. |
| 10812 | |
| 10813 | The idea here is that evaluating an expression generates a series |
| 10814 | of values, one holding the value of every subexpression. (The |
| 10815 | expression a*b+c has five subexpressions: a, b, a*b, c, and |
| 10816 | a*b+c.) GDB's values hold almost enough information to establish |
| 10817 | the criteria given above --- they identify memory lvalues, |
| 10818 | register lvalues, computed values, etcetera. So we can evaluate |
| 10819 | the expression, and then scan the chain of values that leaves |
| 10820 | behind to decide whether we can detect any possible change to the |
| 10821 | expression's final value using only hardware watchpoints. |
| 10822 | |
| 10823 | However, I don't think that the values returned by inferior |
| 10824 | function calls are special in any way. So this function may not |
| 10825 | notice that an expression involving an inferior function call |
| 10826 | can't be watched with hardware watchpoints. FIXME. */ |
| 10827 | for (const value_ref_ptr &iter : vals) |
| 10828 | { |
| 10829 | struct value *v = iter.get (); |
| 10830 | |
| 10831 | if (VALUE_LVAL (v) == lval_memory) |
| 10832 | { |
| 10833 | if (v != head && value_lazy (v)) |
| 10834 | /* A lazy memory lvalue in the chain is one that GDB never |
| 10835 | needed to fetch; we either just used its address (e.g., |
| 10836 | `a' in `a.b') or we never needed it at all (e.g., `a' |
| 10837 | in `a,b'). This doesn't apply to HEAD; if that is |
| 10838 | lazy then it was not readable, but watch it anyway. */ |
| 10839 | ; |
| 10840 | else |
| 10841 | { |
| 10842 | /* Ahh, memory we actually used! Check if we can cover |
| 10843 | it with hardware watchpoints. */ |
| 10844 | struct type *vtype = check_typedef (value_type (v)); |
| 10845 | |
| 10846 | /* We only watch structs and arrays if user asked for it |
| 10847 | explicitly, never if they just happen to appear in a |
| 10848 | middle of some value chain. */ |
| 10849 | if (v == head |
| 10850 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 10851 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 10852 | { |
| 10853 | CORE_ADDR vaddr = value_address (v); |
| 10854 | int len; |
| 10855 | int num_regs; |
| 10856 | |
| 10857 | len = (target_exact_watchpoints |
| 10858 | && is_scalar_type_recursive (vtype))? |
| 10859 | 1 : TYPE_LENGTH (value_type (v)); |
| 10860 | |
| 10861 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
| 10862 | if (!num_regs) |
| 10863 | return 0; |
| 10864 | else |
| 10865 | found_memory_cnt += num_regs; |
| 10866 | } |
| 10867 | } |
| 10868 | } |
| 10869 | else if (VALUE_LVAL (v) != not_lval |
| 10870 | && deprecated_value_modifiable (v) == 0) |
| 10871 | return 0; /* These are values from the history (e.g., $1). */ |
| 10872 | else if (VALUE_LVAL (v) == lval_register) |
| 10873 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
| 10874 | } |
| 10875 | |
| 10876 | /* The expression itself looks suitable for using a hardware |
| 10877 | watchpoint, but give the target machine a chance to reject it. */ |
| 10878 | return found_memory_cnt; |
| 10879 | } |
| 10880 | |
| 10881 | void |
| 10882 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
| 10883 | { |
| 10884 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
| 10885 | } |
| 10886 | |
| 10887 | /* A helper function that looks for the "-location" argument and then |
| 10888 | calls watch_command_1. */ |
| 10889 | |
| 10890 | static void |
| 10891 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
| 10892 | { |
| 10893 | int just_location = 0; |
| 10894 | |
| 10895 | if (arg |
| 10896 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) |
| 10897 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) |
| 10898 | just_location = 1; |
| 10899 | |
| 10900 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
| 10901 | } |
| 10902 | |
| 10903 | static void |
| 10904 | watch_command (const char *arg, int from_tty) |
| 10905 | { |
| 10906 | watch_maybe_just_location (arg, hw_write, from_tty); |
| 10907 | } |
| 10908 | |
| 10909 | void |
| 10910 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
| 10911 | { |
| 10912 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
| 10913 | } |
| 10914 | |
| 10915 | static void |
| 10916 | rwatch_command (const char *arg, int from_tty) |
| 10917 | { |
| 10918 | watch_maybe_just_location (arg, hw_read, from_tty); |
| 10919 | } |
| 10920 | |
| 10921 | void |
| 10922 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
| 10923 | { |
| 10924 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
| 10925 | } |
| 10926 | |
| 10927 | static void |
| 10928 | awatch_command (const char *arg, int from_tty) |
| 10929 | { |
| 10930 | watch_maybe_just_location (arg, hw_access, from_tty); |
| 10931 | } |
| 10932 | \f |
| 10933 | |
| 10934 | /* Data for the FSM that manages the until(location)/advance commands |
| 10935 | in infcmd.c. Here because it uses the mechanisms of |
| 10936 | breakpoints. */ |
| 10937 | |
| 10938 | struct until_break_fsm : public thread_fsm |
| 10939 | { |
| 10940 | /* The thread that was current when the command was executed. */ |
| 10941 | int thread; |
| 10942 | |
| 10943 | /* The breakpoint set at the destination location. */ |
| 10944 | breakpoint_up location_breakpoint; |
| 10945 | |
| 10946 | /* Breakpoint set at the return address in the caller frame. May be |
| 10947 | NULL. */ |
| 10948 | breakpoint_up caller_breakpoint; |
| 10949 | |
| 10950 | until_break_fsm (struct interp *cmd_interp, int thread, |
| 10951 | breakpoint_up &&location_breakpoint, |
| 10952 | breakpoint_up &&caller_breakpoint) |
| 10953 | : thread_fsm (cmd_interp), |
| 10954 | thread (thread), |
| 10955 | location_breakpoint (std::move (location_breakpoint)), |
| 10956 | caller_breakpoint (std::move (caller_breakpoint)) |
| 10957 | { |
| 10958 | } |
| 10959 | |
| 10960 | void clean_up (struct thread_info *thread) override; |
| 10961 | bool should_stop (struct thread_info *thread) override; |
| 10962 | enum async_reply_reason do_async_reply_reason () override; |
| 10963 | }; |
| 10964 | |
| 10965 | /* Implementation of the 'should_stop' FSM method for the |
| 10966 | until(location)/advance commands. */ |
| 10967 | |
| 10968 | bool |
| 10969 | until_break_fsm::should_stop (struct thread_info *tp) |
| 10970 | { |
| 10971 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, |
| 10972 | location_breakpoint.get ()) != NULL |
| 10973 | || (caller_breakpoint != NULL |
| 10974 | && bpstat_find_breakpoint (tp->control.stop_bpstat, |
| 10975 | caller_breakpoint.get ()) != NULL)) |
| 10976 | set_finished (); |
| 10977 | |
| 10978 | return true; |
| 10979 | } |
| 10980 | |
| 10981 | /* Implementation of the 'clean_up' FSM method for the |
| 10982 | until(location)/advance commands. */ |
| 10983 | |
| 10984 | void |
| 10985 | until_break_fsm::clean_up (struct thread_info *) |
| 10986 | { |
| 10987 | /* Clean up our temporary breakpoints. */ |
| 10988 | location_breakpoint.reset (); |
| 10989 | caller_breakpoint.reset (); |
| 10990 | delete_longjmp_breakpoint (thread); |
| 10991 | } |
| 10992 | |
| 10993 | /* Implementation of the 'async_reply_reason' FSM method for the |
| 10994 | until(location)/advance commands. */ |
| 10995 | |
| 10996 | enum async_reply_reason |
| 10997 | until_break_fsm::do_async_reply_reason () |
| 10998 | { |
| 10999 | return EXEC_ASYNC_LOCATION_REACHED; |
| 11000 | } |
| 11001 | |
| 11002 | void |
| 11003 | until_break_command (const char *arg, int from_tty, int anywhere) |
| 11004 | { |
| 11005 | struct frame_info *frame; |
| 11006 | struct gdbarch *frame_gdbarch; |
| 11007 | struct frame_id stack_frame_id; |
| 11008 | struct frame_id caller_frame_id; |
| 11009 | int thread; |
| 11010 | struct thread_info *tp; |
| 11011 | |
| 11012 | clear_proceed_status (0); |
| 11013 | |
| 11014 | /* Set a breakpoint where the user wants it and at return from |
| 11015 | this function. */ |
| 11016 | |
| 11017 | event_location_up location = string_to_event_location (&arg, current_language); |
| 11018 | |
| 11019 | std::vector<symtab_and_line> sals |
| 11020 | = (last_displayed_sal_is_valid () |
| 11021 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, |
| 11022 | get_last_displayed_symtab (), |
| 11023 | get_last_displayed_line ()) |
| 11024 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, |
| 11025 | NULL, NULL, 0)); |
| 11026 | |
| 11027 | if (sals.size () != 1) |
| 11028 | error (_("Couldn't get information on specified line.")); |
| 11029 | |
| 11030 | symtab_and_line &sal = sals[0]; |
| 11031 | |
| 11032 | if (*arg) |
| 11033 | error (_("Junk at end of arguments.")); |
| 11034 | |
| 11035 | resolve_sal_pc (&sal); |
| 11036 | |
| 11037 | tp = inferior_thread (); |
| 11038 | thread = tp->global_num; |
| 11039 | |
| 11040 | /* Note linespec handling above invalidates the frame chain. |
| 11041 | Installing a breakpoint also invalidates the frame chain (as it |
| 11042 | may need to switch threads), so do any frame handling before |
| 11043 | that. */ |
| 11044 | |
| 11045 | frame = get_selected_frame (NULL); |
| 11046 | frame_gdbarch = get_frame_arch (frame); |
| 11047 | stack_frame_id = get_stack_frame_id (frame); |
| 11048 | caller_frame_id = frame_unwind_caller_id (frame); |
| 11049 | |
| 11050 | /* Keep within the current frame, or in frames called by the current |
| 11051 | one. */ |
| 11052 | |
| 11053 | breakpoint_up caller_breakpoint; |
| 11054 | |
| 11055 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; |
| 11056 | |
| 11057 | if (frame_id_p (caller_frame_id)) |
| 11058 | { |
| 11059 | struct symtab_and_line sal2; |
| 11060 | struct gdbarch *caller_gdbarch; |
| 11061 | |
| 11062 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); |
| 11063 | sal2.pc = frame_unwind_caller_pc (frame); |
| 11064 | caller_gdbarch = frame_unwind_caller_arch (frame); |
| 11065 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, |
| 11066 | sal2, |
| 11067 | caller_frame_id, |
| 11068 | bp_until); |
| 11069 | |
| 11070 | set_longjmp_breakpoint (tp, caller_frame_id); |
| 11071 | lj_deleter.emplace (thread); |
| 11072 | } |
| 11073 | |
| 11074 | /* set_momentary_breakpoint could invalidate FRAME. */ |
| 11075 | frame = NULL; |
| 11076 | |
| 11077 | breakpoint_up location_breakpoint; |
| 11078 | if (anywhere) |
| 11079 | /* If the user told us to continue until a specified location, |
| 11080 | we don't specify a frame at which we need to stop. */ |
| 11081 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
| 11082 | null_frame_id, bp_until); |
| 11083 | else |
| 11084 | /* Otherwise, specify the selected frame, because we want to stop |
| 11085 | only at the very same frame. */ |
| 11086 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
| 11087 | stack_frame_id, bp_until); |
| 11088 | |
| 11089 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
| 11090 | std::move (location_breakpoint), |
| 11091 | std::move (caller_breakpoint)); |
| 11092 | |
| 11093 | if (lj_deleter) |
| 11094 | lj_deleter->release (); |
| 11095 | |
| 11096 | proceed (-1, GDB_SIGNAL_DEFAULT); |
| 11097 | } |
| 11098 | |
| 11099 | /* This function attempts to parse an optional "if <cond>" clause |
| 11100 | from the arg string. If one is not found, it returns NULL. |
| 11101 | |
| 11102 | Else, it returns a pointer to the condition string. (It does not |
| 11103 | attempt to evaluate the string against a particular block.) And, |
| 11104 | it updates arg to point to the first character following the parsed |
| 11105 | if clause in the arg string. */ |
| 11106 | |
| 11107 | const char * |
| 11108 | ep_parse_optional_if_clause (const char **arg) |
| 11109 | { |
| 11110 | const char *cond_string; |
| 11111 | |
| 11112 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) |
| 11113 | return NULL; |
| 11114 | |
| 11115 | /* Skip the "if" keyword. */ |
| 11116 | (*arg) += 2; |
| 11117 | |
| 11118 | /* Skip any extra leading whitespace, and record the start of the |
| 11119 | condition string. */ |
| 11120 | *arg = skip_spaces (*arg); |
| 11121 | cond_string = *arg; |
| 11122 | |
| 11123 | /* Assume that the condition occupies the remainder of the arg |
| 11124 | string. */ |
| 11125 | (*arg) += strlen (cond_string); |
| 11126 | |
| 11127 | return cond_string; |
| 11128 | } |
| 11129 | |
| 11130 | /* Commands to deal with catching events, such as signals, exceptions, |
| 11131 | process start/exit, etc. */ |
| 11132 | |
| 11133 | typedef enum |
| 11134 | { |
| 11135 | catch_fork_temporary, catch_vfork_temporary, |
| 11136 | catch_fork_permanent, catch_vfork_permanent |
| 11137 | } |
| 11138 | catch_fork_kind; |
| 11139 | |
| 11140 | static void |
| 11141 | catch_fork_command_1 (const char *arg, int from_tty, |
| 11142 | struct cmd_list_element *command) |
| 11143 | { |
| 11144 | struct gdbarch *gdbarch = get_current_arch (); |
| 11145 | const char *cond_string = NULL; |
| 11146 | catch_fork_kind fork_kind; |
| 11147 | int tempflag; |
| 11148 | |
| 11149 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); |
| 11150 | tempflag = (fork_kind == catch_fork_temporary |
| 11151 | || fork_kind == catch_vfork_temporary); |
| 11152 | |
| 11153 | if (!arg) |
| 11154 | arg = ""; |
| 11155 | arg = skip_spaces (arg); |
| 11156 | |
| 11157 | /* The allowed syntax is: |
| 11158 | catch [v]fork |
| 11159 | catch [v]fork if <cond> |
| 11160 | |
| 11161 | First, check if there's an if clause. */ |
| 11162 | cond_string = ep_parse_optional_if_clause (&arg); |
| 11163 | |
| 11164 | if ((*arg != '\0') && !isspace (*arg)) |
| 11165 | error (_("Junk at end of arguments.")); |
| 11166 | |
| 11167 | /* If this target supports it, create a fork or vfork catchpoint |
| 11168 | and enable reporting of such events. */ |
| 11169 | switch (fork_kind) |
| 11170 | { |
| 11171 | case catch_fork_temporary: |
| 11172 | case catch_fork_permanent: |
| 11173 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 11174 | &catch_fork_breakpoint_ops); |
| 11175 | break; |
| 11176 | case catch_vfork_temporary: |
| 11177 | case catch_vfork_permanent: |
| 11178 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 11179 | &catch_vfork_breakpoint_ops); |
| 11180 | break; |
| 11181 | default: |
| 11182 | error (_("unsupported or unknown fork kind; cannot catch it")); |
| 11183 | break; |
| 11184 | } |
| 11185 | } |
| 11186 | |
| 11187 | static void |
| 11188 | catch_exec_command_1 (const char *arg, int from_tty, |
| 11189 | struct cmd_list_element *command) |
| 11190 | { |
| 11191 | struct gdbarch *gdbarch = get_current_arch (); |
| 11192 | int tempflag; |
| 11193 | const char *cond_string = NULL; |
| 11194 | |
| 11195 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 11196 | |
| 11197 | if (!arg) |
| 11198 | arg = ""; |
| 11199 | arg = skip_spaces (arg); |
| 11200 | |
| 11201 | /* The allowed syntax is: |
| 11202 | catch exec |
| 11203 | catch exec if <cond> |
| 11204 | |
| 11205 | First, check if there's an if clause. */ |
| 11206 | cond_string = ep_parse_optional_if_clause (&arg); |
| 11207 | |
| 11208 | if ((*arg != '\0') && !isspace (*arg)) |
| 11209 | error (_("Junk at end of arguments.")); |
| 11210 | |
| 11211 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
| 11212 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, |
| 11213 | &catch_exec_breakpoint_ops); |
| 11214 | c->exec_pathname = NULL; |
| 11215 | |
| 11216 | install_breakpoint (0, std::move (c), 1); |
| 11217 | } |
| 11218 | |
| 11219 | void |
| 11220 | init_ada_exception_breakpoint (struct breakpoint *b, |
| 11221 | struct gdbarch *gdbarch, |
| 11222 | struct symtab_and_line sal, |
| 11223 | const char *addr_string, |
| 11224 | const struct breakpoint_ops *ops, |
| 11225 | int tempflag, |
| 11226 | int enabled, |
| 11227 | int from_tty) |
| 11228 | { |
| 11229 | if (from_tty) |
| 11230 | { |
| 11231 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 11232 | if (!loc_gdbarch) |
| 11233 | loc_gdbarch = gdbarch; |
| 11234 | |
| 11235 | describe_other_breakpoints (loc_gdbarch, |
| 11236 | sal.pspace, sal.pc, sal.section, -1); |
| 11237 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
| 11238 | version for exception catchpoints, because two catchpoints |
| 11239 | used for different exception names will use the same address. |
| 11240 | In this case, a "breakpoint ... also set at..." warning is |
| 11241 | unproductive. Besides, the warning phrasing is also a bit |
| 11242 | inappropriate, we should use the word catchpoint, and tell |
| 11243 | the user what type of catchpoint it is. The above is good |
| 11244 | enough for now, though. */ |
| 11245 | } |
| 11246 | |
| 11247 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
| 11248 | |
| 11249 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 11250 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 11251 | b->location = string_to_event_location (&addr_string, |
| 11252 | language_def (language_ada)); |
| 11253 | b->language = language_ada; |
| 11254 | } |
| 11255 | |
| 11256 | static void |
| 11257 | catch_command (const char *arg, int from_tty) |
| 11258 | { |
| 11259 | error (_("Catch requires an event name.")); |
| 11260 | } |
| 11261 | \f |
| 11262 | |
| 11263 | static void |
| 11264 | tcatch_command (const char *arg, int from_tty) |
| 11265 | { |
| 11266 | error (_("Catch requires an event name.")); |
| 11267 | } |
| 11268 | |
| 11269 | /* Compare two breakpoints and return a strcmp-like result. */ |
| 11270 | |
| 11271 | static int |
| 11272 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
| 11273 | { |
| 11274 | uintptr_t ua = (uintptr_t) a; |
| 11275 | uintptr_t ub = (uintptr_t) b; |
| 11276 | |
| 11277 | if (a->number < b->number) |
| 11278 | return -1; |
| 11279 | else if (a->number > b->number) |
| 11280 | return 1; |
| 11281 | |
| 11282 | /* Now sort by address, in case we see, e..g, two breakpoints with |
| 11283 | the number 0. */ |
| 11284 | if (ua < ub) |
| 11285 | return -1; |
| 11286 | return ua > ub ? 1 : 0; |
| 11287 | } |
| 11288 | |
| 11289 | /* Delete breakpoints by address or line. */ |
| 11290 | |
| 11291 | static void |
| 11292 | clear_command (const char *arg, int from_tty) |
| 11293 | { |
| 11294 | struct breakpoint *b; |
| 11295 | int default_match; |
| 11296 | |
| 11297 | std::vector<symtab_and_line> decoded_sals; |
| 11298 | symtab_and_line last_sal; |
| 11299 | gdb::array_view<symtab_and_line> sals; |
| 11300 | if (arg) |
| 11301 | { |
| 11302 | decoded_sals |
| 11303 | = decode_line_with_current_source (arg, |
| 11304 | (DECODE_LINE_FUNFIRSTLINE |
| 11305 | | DECODE_LINE_LIST_MODE)); |
| 11306 | default_match = 0; |
| 11307 | sals = decoded_sals; |
| 11308 | } |
| 11309 | else |
| 11310 | { |
| 11311 | /* Set sal's line, symtab, pc, and pspace to the values |
| 11312 | corresponding to the last call to print_frame_info. If the |
| 11313 | codepoint is not valid, this will set all the fields to 0. */ |
| 11314 | last_sal = get_last_displayed_sal (); |
| 11315 | if (last_sal.symtab == 0) |
| 11316 | error (_("No source file specified.")); |
| 11317 | |
| 11318 | default_match = 1; |
| 11319 | sals = last_sal; |
| 11320 | } |
| 11321 | |
| 11322 | /* We don't call resolve_sal_pc here. That's not as bad as it |
| 11323 | seems, because all existing breakpoints typically have both |
| 11324 | file/line and pc set. So, if clear is given file/line, we can |
| 11325 | match this to existing breakpoint without obtaining pc at all. |
| 11326 | |
| 11327 | We only support clearing given the address explicitly |
| 11328 | present in breakpoint table. Say, we've set breakpoint |
| 11329 | at file:line. There were several PC values for that file:line, |
| 11330 | due to optimization, all in one block. |
| 11331 | |
| 11332 | We've picked one PC value. If "clear" is issued with another |
| 11333 | PC corresponding to the same file:line, the breakpoint won't |
| 11334 | be cleared. We probably can still clear the breakpoint, but |
| 11335 | since the other PC value is never presented to user, user |
| 11336 | can only find it by guessing, and it does not seem important |
| 11337 | to support that. */ |
| 11338 | |
| 11339 | /* For each line spec given, delete bps which correspond to it. Do |
| 11340 | it in two passes, solely to preserve the current behavior that |
| 11341 | from_tty is forced true if we delete more than one |
| 11342 | breakpoint. */ |
| 11343 | |
| 11344 | std::vector<struct breakpoint *> found; |
| 11345 | for (const auto &sal : sals) |
| 11346 | { |
| 11347 | const char *sal_fullname; |
| 11348 | |
| 11349 | /* If exact pc given, clear bpts at that pc. |
| 11350 | If line given (pc == 0), clear all bpts on specified line. |
| 11351 | If defaulting, clear all bpts on default line |
| 11352 | or at default pc. |
| 11353 | |
| 11354 | defaulting sal.pc != 0 tests to do |
| 11355 | |
| 11356 | 0 1 pc |
| 11357 | 1 1 pc _and_ line |
| 11358 | 0 0 line |
| 11359 | 1 0 <can't happen> */ |
| 11360 | |
| 11361 | sal_fullname = (sal.symtab == NULL |
| 11362 | ? NULL : symtab_to_fullname (sal.symtab)); |
| 11363 | |
| 11364 | /* Find all matching breakpoints and add them to 'found'. */ |
| 11365 | ALL_BREAKPOINTS (b) |
| 11366 | { |
| 11367 | int match = 0; |
| 11368 | /* Are we going to delete b? */ |
| 11369 | if (b->type != bp_none && !is_watchpoint (b)) |
| 11370 | { |
| 11371 | struct bp_location *loc = b->loc; |
| 11372 | for (; loc; loc = loc->next) |
| 11373 | { |
| 11374 | /* If the user specified file:line, don't allow a PC |
| 11375 | match. This matches historical gdb behavior. */ |
| 11376 | int pc_match = (!sal.explicit_line |
| 11377 | && sal.pc |
| 11378 | && (loc->pspace == sal.pspace) |
| 11379 | && (loc->address == sal.pc) |
| 11380 | && (!section_is_overlay (loc->section) |
| 11381 | || loc->section == sal.section)); |
| 11382 | int line_match = 0; |
| 11383 | |
| 11384 | if ((default_match || sal.explicit_line) |
| 11385 | && loc->symtab != NULL |
| 11386 | && sal_fullname != NULL |
| 11387 | && sal.pspace == loc->pspace |
| 11388 | && loc->line_number == sal.line |
| 11389 | && filename_cmp (symtab_to_fullname (loc->symtab), |
| 11390 | sal_fullname) == 0) |
| 11391 | line_match = 1; |
| 11392 | |
| 11393 | if (pc_match || line_match) |
| 11394 | { |
| 11395 | match = 1; |
| 11396 | break; |
| 11397 | } |
| 11398 | } |
| 11399 | } |
| 11400 | |
| 11401 | if (match) |
| 11402 | found.push_back (b); |
| 11403 | } |
| 11404 | } |
| 11405 | |
| 11406 | /* Now go thru the 'found' chain and delete them. */ |
| 11407 | if (found.empty ()) |
| 11408 | { |
| 11409 | if (arg) |
| 11410 | error (_("No breakpoint at %s."), arg); |
| 11411 | else |
| 11412 | error (_("No breakpoint at this line.")); |
| 11413 | } |
| 11414 | |
| 11415 | /* Remove duplicates from the vec. */ |
| 11416 | std::sort (found.begin (), found.end (), |
| 11417 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
| 11418 | { |
| 11419 | return compare_breakpoints (bp_a, bp_b) < 0; |
| 11420 | }); |
| 11421 | found.erase (std::unique (found.begin (), found.end (), |
| 11422 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
| 11423 | { |
| 11424 | return compare_breakpoints (bp_a, bp_b) == 0; |
| 11425 | }), |
| 11426 | found.end ()); |
| 11427 | |
| 11428 | if (found.size () > 1) |
| 11429 | from_tty = 1; /* Always report if deleted more than one. */ |
| 11430 | if (from_tty) |
| 11431 | { |
| 11432 | if (found.size () == 1) |
| 11433 | printf_unfiltered (_("Deleted breakpoint ")); |
| 11434 | else |
| 11435 | printf_unfiltered (_("Deleted breakpoints ")); |
| 11436 | } |
| 11437 | |
| 11438 | for (breakpoint *iter : found) |
| 11439 | { |
| 11440 | if (from_tty) |
| 11441 | printf_unfiltered ("%d ", iter->number); |
| 11442 | delete_breakpoint (iter); |
| 11443 | } |
| 11444 | if (from_tty) |
| 11445 | putchar_unfiltered ('\n'); |
| 11446 | } |
| 11447 | \f |
| 11448 | /* Delete breakpoint in BS if they are `delete' breakpoints and |
| 11449 | all breakpoints that are marked for deletion, whether hit or not. |
| 11450 | This is called after any breakpoint is hit, or after errors. */ |
| 11451 | |
| 11452 | void |
| 11453 | breakpoint_auto_delete (bpstat bs) |
| 11454 | { |
| 11455 | struct breakpoint *b, *b_tmp; |
| 11456 | |
| 11457 | for (; bs; bs = bs->next) |
| 11458 | if (bs->breakpoint_at |
| 11459 | && bs->breakpoint_at->disposition == disp_del |
| 11460 | && bs->stop) |
| 11461 | delete_breakpoint (bs->breakpoint_at); |
| 11462 | |
| 11463 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 11464 | { |
| 11465 | if (b->disposition == disp_del_at_next_stop) |
| 11466 | delete_breakpoint (b); |
| 11467 | } |
| 11468 | } |
| 11469 | |
| 11470 | /* A comparison function for bp_location AP and BP being interfaced to |
| 11471 | std::sort. Sort elements primarily by their ADDRESS (no matter what |
| 11472 | bl_address_is_meaningful says), secondarily by ordering first |
| 11473 | permanent elements and terciarily just ensuring the array is sorted |
| 11474 | stable way despite std::sort being an unstable algorithm. */ |
| 11475 | |
| 11476 | static int |
| 11477 | bp_location_is_less_than (const bp_location *a, const bp_location *b) |
| 11478 | { |
| 11479 | if (a->address != b->address) |
| 11480 | return a->address < b->address; |
| 11481 | |
| 11482 | /* Sort locations at the same address by their pspace number, keeping |
| 11483 | locations of the same inferior (in a multi-inferior environment) |
| 11484 | grouped. */ |
| 11485 | |
| 11486 | if (a->pspace->num != b->pspace->num) |
| 11487 | return a->pspace->num < b->pspace->num; |
| 11488 | |
| 11489 | /* Sort permanent breakpoints first. */ |
| 11490 | if (a->permanent != b->permanent) |
| 11491 | return a->permanent > b->permanent; |
| 11492 | |
| 11493 | /* Make the internal GDB representation stable across GDB runs |
| 11494 | where A and B memory inside GDB can differ. Breakpoint locations of |
| 11495 | the same type at the same address can be sorted in arbitrary order. */ |
| 11496 | |
| 11497 | if (a->owner->number != b->owner->number) |
| 11498 | return a->owner->number < b->owner->number; |
| 11499 | |
| 11500 | return a < b; |
| 11501 | } |
| 11502 | |
| 11503 | /* Set bp_locations_placed_address_before_address_max and |
| 11504 | bp_locations_shadow_len_after_address_max according to the current |
| 11505 | content of the bp_locations array. */ |
| 11506 | |
| 11507 | static void |
| 11508 | bp_locations_target_extensions_update (void) |
| 11509 | { |
| 11510 | struct bp_location *bl, **blp_tmp; |
| 11511 | |
| 11512 | bp_locations_placed_address_before_address_max = 0; |
| 11513 | bp_locations_shadow_len_after_address_max = 0; |
| 11514 | |
| 11515 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 11516 | { |
| 11517 | CORE_ADDR start, end, addr; |
| 11518 | |
| 11519 | if (!bp_location_has_shadow (bl)) |
| 11520 | continue; |
| 11521 | |
| 11522 | start = bl->target_info.placed_address; |
| 11523 | end = start + bl->target_info.shadow_len; |
| 11524 | |
| 11525 | gdb_assert (bl->address >= start); |
| 11526 | addr = bl->address - start; |
| 11527 | if (addr > bp_locations_placed_address_before_address_max) |
| 11528 | bp_locations_placed_address_before_address_max = addr; |
| 11529 | |
| 11530 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ |
| 11531 | |
| 11532 | gdb_assert (bl->address < end); |
| 11533 | addr = end - bl->address; |
| 11534 | if (addr > bp_locations_shadow_len_after_address_max) |
| 11535 | bp_locations_shadow_len_after_address_max = addr; |
| 11536 | } |
| 11537 | } |
| 11538 | |
| 11539 | /* Download tracepoint locations if they haven't been. */ |
| 11540 | |
| 11541 | static void |
| 11542 | download_tracepoint_locations (void) |
| 11543 | { |
| 11544 | struct breakpoint *b; |
| 11545 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
| 11546 | |
| 11547 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 11548 | |
| 11549 | ALL_TRACEPOINTS (b) |
| 11550 | { |
| 11551 | struct bp_location *bl; |
| 11552 | struct tracepoint *t; |
| 11553 | int bp_location_downloaded = 0; |
| 11554 | |
| 11555 | if ((b->type == bp_fast_tracepoint |
| 11556 | ? !may_insert_fast_tracepoints |
| 11557 | : !may_insert_tracepoints)) |
| 11558 | continue; |
| 11559 | |
| 11560 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
| 11561 | { |
| 11562 | if (target_can_download_tracepoint ()) |
| 11563 | can_download_tracepoint = TRIBOOL_TRUE; |
| 11564 | else |
| 11565 | can_download_tracepoint = TRIBOOL_FALSE; |
| 11566 | } |
| 11567 | |
| 11568 | if (can_download_tracepoint == TRIBOOL_FALSE) |
| 11569 | break; |
| 11570 | |
| 11571 | for (bl = b->loc; bl; bl = bl->next) |
| 11572 | { |
| 11573 | /* In tracepoint, locations are _never_ duplicated, so |
| 11574 | should_be_inserted is equivalent to |
| 11575 | unduplicated_should_be_inserted. */ |
| 11576 | if (!should_be_inserted (bl) || bl->inserted) |
| 11577 | continue; |
| 11578 | |
| 11579 | switch_to_program_space_and_thread (bl->pspace); |
| 11580 | |
| 11581 | target_download_tracepoint (bl); |
| 11582 | |
| 11583 | bl->inserted = 1; |
| 11584 | bp_location_downloaded = 1; |
| 11585 | } |
| 11586 | t = (struct tracepoint *) b; |
| 11587 | t->number_on_target = b->number; |
| 11588 | if (bp_location_downloaded) |
| 11589 | gdb::observers::breakpoint_modified.notify (b); |
| 11590 | } |
| 11591 | } |
| 11592 | |
| 11593 | /* Swap the insertion/duplication state between two locations. */ |
| 11594 | |
| 11595 | static void |
| 11596 | swap_insertion (struct bp_location *left, struct bp_location *right) |
| 11597 | { |
| 11598 | const int left_inserted = left->inserted; |
| 11599 | const int left_duplicate = left->duplicate; |
| 11600 | const int left_needs_update = left->needs_update; |
| 11601 | const struct bp_target_info left_target_info = left->target_info; |
| 11602 | |
| 11603 | /* Locations of tracepoints can never be duplicated. */ |
| 11604 | if (is_tracepoint (left->owner)) |
| 11605 | gdb_assert (!left->duplicate); |
| 11606 | if (is_tracepoint (right->owner)) |
| 11607 | gdb_assert (!right->duplicate); |
| 11608 | |
| 11609 | left->inserted = right->inserted; |
| 11610 | left->duplicate = right->duplicate; |
| 11611 | left->needs_update = right->needs_update; |
| 11612 | left->target_info = right->target_info; |
| 11613 | right->inserted = left_inserted; |
| 11614 | right->duplicate = left_duplicate; |
| 11615 | right->needs_update = left_needs_update; |
| 11616 | right->target_info = left_target_info; |
| 11617 | } |
| 11618 | |
| 11619 | /* Force the re-insertion of the locations at ADDRESS. This is called |
| 11620 | once a new/deleted/modified duplicate location is found and we are evaluating |
| 11621 | conditions on the target's side. Such conditions need to be updated on |
| 11622 | the target. */ |
| 11623 | |
| 11624 | static void |
| 11625 | force_breakpoint_reinsertion (struct bp_location *bl) |
| 11626 | { |
| 11627 | struct bp_location **locp = NULL, **loc2p; |
| 11628 | struct bp_location *loc; |
| 11629 | CORE_ADDR address = 0; |
| 11630 | int pspace_num; |
| 11631 | |
| 11632 | address = bl->address; |
| 11633 | pspace_num = bl->pspace->num; |
| 11634 | |
| 11635 | /* This is only meaningful if the target is |
| 11636 | evaluating conditions and if the user has |
| 11637 | opted for condition evaluation on the target's |
| 11638 | side. */ |
| 11639 | if (gdb_evaluates_breakpoint_condition_p () |
| 11640 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 11641 | return; |
| 11642 | |
| 11643 | /* Flag all breakpoint locations with this address and |
| 11644 | the same program space as the location |
| 11645 | as "its condition has changed". We need to |
| 11646 | update the conditions on the target's side. */ |
| 11647 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) |
| 11648 | { |
| 11649 | loc = *loc2p; |
| 11650 | |
| 11651 | if (!is_breakpoint (loc->owner) |
| 11652 | || pspace_num != loc->pspace->num) |
| 11653 | continue; |
| 11654 | |
| 11655 | /* Flag the location appropriately. We use a different state to |
| 11656 | let everyone know that we already updated the set of locations |
| 11657 | with addr bl->address and program space bl->pspace. This is so |
| 11658 | we don't have to keep calling these functions just to mark locations |
| 11659 | that have already been marked. */ |
| 11660 | loc->condition_changed = condition_updated; |
| 11661 | |
| 11662 | /* Free the agent expression bytecode as well. We will compute |
| 11663 | it later on. */ |
| 11664 | loc->cond_bytecode.reset (); |
| 11665 | } |
| 11666 | } |
| 11667 | /* Called whether new breakpoints are created, or existing breakpoints |
| 11668 | deleted, to update the global location list and recompute which |
| 11669 | locations are duplicate of which. |
| 11670 | |
| 11671 | The INSERT_MODE flag determines whether locations may not, may, or |
| 11672 | shall be inserted now. See 'enum ugll_insert_mode' for more |
| 11673 | info. */ |
| 11674 | |
| 11675 | static void |
| 11676 | update_global_location_list (enum ugll_insert_mode insert_mode) |
| 11677 | { |
| 11678 | struct breakpoint *b; |
| 11679 | struct bp_location **locp, *loc; |
| 11680 | /* Last breakpoint location address that was marked for update. */ |
| 11681 | CORE_ADDR last_addr = 0; |
| 11682 | /* Last breakpoint location program space that was marked for update. */ |
| 11683 | int last_pspace_num = -1; |
| 11684 | |
| 11685 | /* Used in the duplicates detection below. When iterating over all |
| 11686 | bp_locations, points to the first bp_location of a given address. |
| 11687 | Breakpoints and watchpoints of different types are never |
| 11688 | duplicates of each other. Keep one pointer for each type of |
| 11689 | breakpoint/watchpoint, so we only need to loop over all locations |
| 11690 | once. */ |
| 11691 | struct bp_location *bp_loc_first; /* breakpoint */ |
| 11692 | struct bp_location *wp_loc_first; /* hardware watchpoint */ |
| 11693 | struct bp_location *awp_loc_first; /* access watchpoint */ |
| 11694 | struct bp_location *rwp_loc_first; /* read watchpoint */ |
| 11695 | |
| 11696 | /* Saved former bp_locations array which we compare against the newly |
| 11697 | built bp_locations from the current state of ALL_BREAKPOINTS. */ |
| 11698 | struct bp_location **old_locp; |
| 11699 | unsigned old_locations_count; |
| 11700 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
| 11701 | |
| 11702 | old_locations_count = bp_locations_count; |
| 11703 | bp_locations = NULL; |
| 11704 | bp_locations_count = 0; |
| 11705 | |
| 11706 | ALL_BREAKPOINTS (b) |
| 11707 | for (loc = b->loc; loc; loc = loc->next) |
| 11708 | bp_locations_count++; |
| 11709 | |
| 11710 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
| 11711 | locp = bp_locations; |
| 11712 | ALL_BREAKPOINTS (b) |
| 11713 | for (loc = b->loc; loc; loc = loc->next) |
| 11714 | *locp++ = loc; |
| 11715 | std::sort (bp_locations, bp_locations + bp_locations_count, |
| 11716 | bp_location_is_less_than); |
| 11717 | |
| 11718 | bp_locations_target_extensions_update (); |
| 11719 | |
| 11720 | /* Identify bp_location instances that are no longer present in the |
| 11721 | new list, and therefore should be freed. Note that it's not |
| 11722 | necessary that those locations should be removed from inferior -- |
| 11723 | if there's another location at the same address (previously |
| 11724 | marked as duplicate), we don't need to remove/insert the |
| 11725 | location. |
| 11726 | |
| 11727 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
| 11728 | and former bp_location array state respectively. */ |
| 11729 | |
| 11730 | locp = bp_locations; |
| 11731 | for (old_locp = old_locations.get (); |
| 11732 | old_locp < old_locations.get () + old_locations_count; |
| 11733 | old_locp++) |
| 11734 | { |
| 11735 | struct bp_location *old_loc = *old_locp; |
| 11736 | struct bp_location **loc2p; |
| 11737 | |
| 11738 | /* Tells if 'old_loc' is found among the new locations. If |
| 11739 | not, we have to free it. */ |
| 11740 | int found_object = 0; |
| 11741 | /* Tells if the location should remain inserted in the target. */ |
| 11742 | int keep_in_target = 0; |
| 11743 | int removed = 0; |
| 11744 | |
| 11745 | /* Skip LOCP entries which will definitely never be needed. |
| 11746 | Stop either at or being the one matching OLD_LOC. */ |
| 11747 | while (locp < bp_locations + bp_locations_count |
| 11748 | && (*locp)->address < old_loc->address) |
| 11749 | locp++; |
| 11750 | |
| 11751 | for (loc2p = locp; |
| 11752 | (loc2p < bp_locations + bp_locations_count |
| 11753 | && (*loc2p)->address == old_loc->address); |
| 11754 | loc2p++) |
| 11755 | { |
| 11756 | /* Check if this is a new/duplicated location or a duplicated |
| 11757 | location that had its condition modified. If so, we want to send |
| 11758 | its condition to the target if evaluation of conditions is taking |
| 11759 | place there. */ |
| 11760 | if ((*loc2p)->condition_changed == condition_modified |
| 11761 | && (last_addr != old_loc->address |
| 11762 | || last_pspace_num != old_loc->pspace->num)) |
| 11763 | { |
| 11764 | force_breakpoint_reinsertion (*loc2p); |
| 11765 | last_pspace_num = old_loc->pspace->num; |
| 11766 | } |
| 11767 | |
| 11768 | if (*loc2p == old_loc) |
| 11769 | found_object = 1; |
| 11770 | } |
| 11771 | |
| 11772 | /* We have already handled this address, update it so that we don't |
| 11773 | have to go through updates again. */ |
| 11774 | last_addr = old_loc->address; |
| 11775 | |
| 11776 | /* Target-side condition evaluation: Handle deleted locations. */ |
| 11777 | if (!found_object) |
| 11778 | force_breakpoint_reinsertion (old_loc); |
| 11779 | |
| 11780 | /* If this location is no longer present, and inserted, look if |
| 11781 | there's maybe a new location at the same address. If so, |
| 11782 | mark that one inserted, and don't remove this one. This is |
| 11783 | needed so that we don't have a time window where a breakpoint |
| 11784 | at certain location is not inserted. */ |
| 11785 | |
| 11786 | if (old_loc->inserted) |
| 11787 | { |
| 11788 | /* If the location is inserted now, we might have to remove |
| 11789 | it. */ |
| 11790 | |
| 11791 | if (found_object && should_be_inserted (old_loc)) |
| 11792 | { |
| 11793 | /* The location is still present in the location list, |
| 11794 | and still should be inserted. Don't do anything. */ |
| 11795 | keep_in_target = 1; |
| 11796 | } |
| 11797 | else |
| 11798 | { |
| 11799 | /* This location still exists, but it won't be kept in the |
| 11800 | target since it may have been disabled. We proceed to |
| 11801 | remove its target-side condition. */ |
| 11802 | |
| 11803 | /* The location is either no longer present, or got |
| 11804 | disabled. See if there's another location at the |
| 11805 | same address, in which case we don't need to remove |
| 11806 | this one from the target. */ |
| 11807 | |
| 11808 | /* OLD_LOC comes from existing struct breakpoint. */ |
| 11809 | if (bl_address_is_meaningful (old_loc)) |
| 11810 | { |
| 11811 | for (loc2p = locp; |
| 11812 | (loc2p < bp_locations + bp_locations_count |
| 11813 | && (*loc2p)->address == old_loc->address); |
| 11814 | loc2p++) |
| 11815 | { |
| 11816 | struct bp_location *loc2 = *loc2p; |
| 11817 | |
| 11818 | if (breakpoint_locations_match (loc2, old_loc)) |
| 11819 | { |
| 11820 | /* Read watchpoint locations are switched to |
| 11821 | access watchpoints, if the former are not |
| 11822 | supported, but the latter are. */ |
| 11823 | if (is_hardware_watchpoint (old_loc->owner)) |
| 11824 | { |
| 11825 | gdb_assert (is_hardware_watchpoint (loc2->owner)); |
| 11826 | loc2->watchpoint_type = old_loc->watchpoint_type; |
| 11827 | } |
| 11828 | |
| 11829 | /* loc2 is a duplicated location. We need to check |
| 11830 | if it should be inserted in case it will be |
| 11831 | unduplicated. */ |
| 11832 | if (loc2 != old_loc |
| 11833 | && unduplicated_should_be_inserted (loc2)) |
| 11834 | { |
| 11835 | swap_insertion (old_loc, loc2); |
| 11836 | keep_in_target = 1; |
| 11837 | break; |
| 11838 | } |
| 11839 | } |
| 11840 | } |
| 11841 | } |
| 11842 | } |
| 11843 | |
| 11844 | if (!keep_in_target) |
| 11845 | { |
| 11846 | if (remove_breakpoint (old_loc)) |
| 11847 | { |
| 11848 | /* This is just about all we can do. We could keep |
| 11849 | this location on the global list, and try to |
| 11850 | remove it next time, but there's no particular |
| 11851 | reason why we will succeed next time. |
| 11852 | |
| 11853 | Note that at this point, old_loc->owner is still |
| 11854 | valid, as delete_breakpoint frees the breakpoint |
| 11855 | only after calling us. */ |
| 11856 | printf_filtered (_("warning: Error removing " |
| 11857 | "breakpoint %d\n"), |
| 11858 | old_loc->owner->number); |
| 11859 | } |
| 11860 | removed = 1; |
| 11861 | } |
| 11862 | } |
| 11863 | |
| 11864 | if (!found_object) |
| 11865 | { |
| 11866 | if (removed && target_is_non_stop_p () |
| 11867 | && need_moribund_for_location_type (old_loc)) |
| 11868 | { |
| 11869 | /* This location was removed from the target. In |
| 11870 | non-stop mode, a race condition is possible where |
| 11871 | we've removed a breakpoint, but stop events for that |
| 11872 | breakpoint are already queued and will arrive later. |
| 11873 | We apply an heuristic to be able to distinguish such |
| 11874 | SIGTRAPs from other random SIGTRAPs: we keep this |
| 11875 | breakpoint location for a bit, and will retire it |
| 11876 | after we see some number of events. The theory here |
| 11877 | is that reporting of events should, "on the average", |
| 11878 | be fair, so after a while we'll see events from all |
| 11879 | threads that have anything of interest, and no longer |
| 11880 | need to keep this breakpoint location around. We |
| 11881 | don't hold locations forever so to reduce chances of |
| 11882 | mistaking a non-breakpoint SIGTRAP for a breakpoint |
| 11883 | SIGTRAP. |
| 11884 | |
| 11885 | The heuristic failing can be disastrous on |
| 11886 | decr_pc_after_break targets. |
| 11887 | |
| 11888 | On decr_pc_after_break targets, like e.g., x86-linux, |
| 11889 | if we fail to recognize a late breakpoint SIGTRAP, |
| 11890 | because events_till_retirement has reached 0 too |
| 11891 | soon, we'll fail to do the PC adjustment, and report |
| 11892 | a random SIGTRAP to the user. When the user resumes |
| 11893 | the inferior, it will most likely immediately crash |
| 11894 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
| 11895 | corrupted, because of being resumed e.g., in the |
| 11896 | middle of a multi-byte instruction, or skipped a |
| 11897 | one-byte instruction. This was actually seen happen |
| 11898 | on native x86-linux, and should be less rare on |
| 11899 | targets that do not support new thread events, like |
| 11900 | remote, due to the heuristic depending on |
| 11901 | thread_count. |
| 11902 | |
| 11903 | Mistaking a random SIGTRAP for a breakpoint trap |
| 11904 | causes similar symptoms (PC adjustment applied when |
| 11905 | it shouldn't), but then again, playing with SIGTRAPs |
| 11906 | behind the debugger's back is asking for trouble. |
| 11907 | |
| 11908 | Since hardware watchpoint traps are always |
| 11909 | distinguishable from other traps, so we don't need to |
| 11910 | apply keep hardware watchpoint moribund locations |
| 11911 | around. We simply always ignore hardware watchpoint |
| 11912 | traps we can no longer explain. */ |
| 11913 | |
| 11914 | process_stratum_target *proc_target = nullptr; |
| 11915 | for (inferior *inf : all_inferiors ()) |
| 11916 | if (inf->pspace == old_loc->pspace) |
| 11917 | { |
| 11918 | proc_target = inf->process_target (); |
| 11919 | break; |
| 11920 | } |
| 11921 | if (proc_target != nullptr) |
| 11922 | old_loc->events_till_retirement |
| 11923 | = 3 * (thread_count (proc_target) + 1); |
| 11924 | else |
| 11925 | old_loc->events_till_retirement = 1; |
| 11926 | old_loc->owner = NULL; |
| 11927 | |
| 11928 | moribund_locations.push_back (old_loc); |
| 11929 | } |
| 11930 | else |
| 11931 | { |
| 11932 | old_loc->owner = NULL; |
| 11933 | decref_bp_location (&old_loc); |
| 11934 | } |
| 11935 | } |
| 11936 | } |
| 11937 | |
| 11938 | /* Rescan breakpoints at the same address and section, marking the |
| 11939 | first one as "first" and any others as "duplicates". This is so |
| 11940 | that the bpt instruction is only inserted once. If we have a |
| 11941 | permanent breakpoint at the same place as BPT, make that one the |
| 11942 | official one, and the rest as duplicates. Permanent breakpoints |
| 11943 | are sorted first for the same address. |
| 11944 | |
| 11945 | Do the same for hardware watchpoints, but also considering the |
| 11946 | watchpoint's type (regular/access/read) and length. */ |
| 11947 | |
| 11948 | bp_loc_first = NULL; |
| 11949 | wp_loc_first = NULL; |
| 11950 | awp_loc_first = NULL; |
| 11951 | rwp_loc_first = NULL; |
| 11952 | ALL_BP_LOCATIONS (loc, locp) |
| 11953 | { |
| 11954 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
| 11955 | non-NULL. */ |
| 11956 | struct bp_location **loc_first_p; |
| 11957 | b = loc->owner; |
| 11958 | |
| 11959 | if (!unduplicated_should_be_inserted (loc) |
| 11960 | || !bl_address_is_meaningful (loc) |
| 11961 | /* Don't detect duplicate for tracepoint locations because they are |
| 11962 | never duplicated. See the comments in field `duplicate' of |
| 11963 | `struct bp_location'. */ |
| 11964 | || is_tracepoint (b)) |
| 11965 | { |
| 11966 | /* Clear the condition modification flag. */ |
| 11967 | loc->condition_changed = condition_unchanged; |
| 11968 | continue; |
| 11969 | } |
| 11970 | |
| 11971 | if (b->type == bp_hardware_watchpoint) |
| 11972 | loc_first_p = &wp_loc_first; |
| 11973 | else if (b->type == bp_read_watchpoint) |
| 11974 | loc_first_p = &rwp_loc_first; |
| 11975 | else if (b->type == bp_access_watchpoint) |
| 11976 | loc_first_p = &awp_loc_first; |
| 11977 | else |
| 11978 | loc_first_p = &bp_loc_first; |
| 11979 | |
| 11980 | if (*loc_first_p == NULL |
| 11981 | || (overlay_debugging && loc->section != (*loc_first_p)->section) |
| 11982 | || !breakpoint_locations_match (loc, *loc_first_p)) |
| 11983 | { |
| 11984 | *loc_first_p = loc; |
| 11985 | loc->duplicate = 0; |
| 11986 | |
| 11987 | if (is_breakpoint (loc->owner) && loc->condition_changed) |
| 11988 | { |
| 11989 | loc->needs_update = 1; |
| 11990 | /* Clear the condition modification flag. */ |
| 11991 | loc->condition_changed = condition_unchanged; |
| 11992 | } |
| 11993 | continue; |
| 11994 | } |
| 11995 | |
| 11996 | |
| 11997 | /* This and the above ensure the invariant that the first location |
| 11998 | is not duplicated, and is the inserted one. |
| 11999 | All following are marked as duplicated, and are not inserted. */ |
| 12000 | if (loc->inserted) |
| 12001 | swap_insertion (loc, *loc_first_p); |
| 12002 | loc->duplicate = 1; |
| 12003 | |
| 12004 | /* Clear the condition modification flag. */ |
| 12005 | loc->condition_changed = condition_unchanged; |
| 12006 | } |
| 12007 | |
| 12008 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
| 12009 | { |
| 12010 | if (insert_mode != UGLL_DONT_INSERT) |
| 12011 | insert_breakpoint_locations (); |
| 12012 | else |
| 12013 | { |
| 12014 | /* Even though the caller told us to not insert new |
| 12015 | locations, we may still need to update conditions on the |
| 12016 | target's side of breakpoints that were already inserted |
| 12017 | if the target is evaluating breakpoint conditions. We |
| 12018 | only update conditions for locations that are marked |
| 12019 | "needs_update". */ |
| 12020 | update_inserted_breakpoint_locations (); |
| 12021 | } |
| 12022 | } |
| 12023 | |
| 12024 | if (insert_mode != UGLL_DONT_INSERT) |
| 12025 | download_tracepoint_locations (); |
| 12026 | } |
| 12027 | |
| 12028 | void |
| 12029 | breakpoint_retire_moribund (void) |
| 12030 | { |
| 12031 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
| 12032 | { |
| 12033 | struct bp_location *loc = moribund_locations[ix]; |
| 12034 | if (--(loc->events_till_retirement) == 0) |
| 12035 | { |
| 12036 | decref_bp_location (&loc); |
| 12037 | unordered_remove (moribund_locations, ix); |
| 12038 | --ix; |
| 12039 | } |
| 12040 | } |
| 12041 | } |
| 12042 | |
| 12043 | static void |
| 12044 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
| 12045 | { |
| 12046 | |
| 12047 | try |
| 12048 | { |
| 12049 | update_global_location_list (insert_mode); |
| 12050 | } |
| 12051 | catch (const gdb_exception_error &e) |
| 12052 | { |
| 12053 | } |
| 12054 | } |
| 12055 | |
| 12056 | /* Clear BKP from a BPS. */ |
| 12057 | |
| 12058 | static void |
| 12059 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
| 12060 | { |
| 12061 | bpstat bs; |
| 12062 | |
| 12063 | for (bs = bps; bs; bs = bs->next) |
| 12064 | if (bs->breakpoint_at == bpt) |
| 12065 | { |
| 12066 | bs->breakpoint_at = NULL; |
| 12067 | bs->old_val = NULL; |
| 12068 | /* bs->commands will be freed later. */ |
| 12069 | } |
| 12070 | } |
| 12071 | |
| 12072 | /* Callback for iterate_over_threads. */ |
| 12073 | static int |
| 12074 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
| 12075 | { |
| 12076 | struct breakpoint *bpt = (struct breakpoint *) data; |
| 12077 | |
| 12078 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
| 12079 | return 0; |
| 12080 | } |
| 12081 | |
| 12082 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention |
| 12083 | callbacks. */ |
| 12084 | |
| 12085 | static void |
| 12086 | say_where (struct breakpoint *b) |
| 12087 | { |
| 12088 | struct value_print_options opts; |
| 12089 | |
| 12090 | get_user_print_options (&opts); |
| 12091 | |
| 12092 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
| 12093 | single string. */ |
| 12094 | if (b->loc == NULL) |
| 12095 | { |
| 12096 | /* For pending locations, the output differs slightly based |
| 12097 | on b->extra_string. If this is non-NULL, it contains either |
| 12098 | a condition or dprintf arguments. */ |
| 12099 | if (b->extra_string == NULL) |
| 12100 | { |
| 12101 | printf_filtered (_(" (%s) pending."), |
| 12102 | event_location_to_string (b->location.get ())); |
| 12103 | } |
| 12104 | else if (b->type == bp_dprintf) |
| 12105 | { |
| 12106 | printf_filtered (_(" (%s,%s) pending."), |
| 12107 | event_location_to_string (b->location.get ()), |
| 12108 | b->extra_string); |
| 12109 | } |
| 12110 | else |
| 12111 | { |
| 12112 | printf_filtered (_(" (%s %s) pending."), |
| 12113 | event_location_to_string (b->location.get ()), |
| 12114 | b->extra_string); |
| 12115 | } |
| 12116 | } |
| 12117 | else |
| 12118 | { |
| 12119 | if (opts.addressprint || b->loc->symtab == NULL) |
| 12120 | printf_filtered (" at %ps", |
| 12121 | styled_string (address_style.style (), |
| 12122 | paddress (b->loc->gdbarch, |
| 12123 | b->loc->address))); |
| 12124 | if (b->loc->symtab != NULL) |
| 12125 | { |
| 12126 | /* If there is a single location, we can print the location |
| 12127 | more nicely. */ |
| 12128 | if (b->loc->next == NULL) |
| 12129 | { |
| 12130 | const char *filename |
| 12131 | = symtab_to_filename_for_display (b->loc->symtab); |
| 12132 | printf_filtered (": file %ps, line %d.", |
| 12133 | styled_string (file_name_style.style (), |
| 12134 | filename), |
| 12135 | b->loc->line_number); |
| 12136 | } |
| 12137 | else |
| 12138 | /* This is not ideal, but each location may have a |
| 12139 | different file name, and this at least reflects the |
| 12140 | real situation somewhat. */ |
| 12141 | printf_filtered (": %s.", |
| 12142 | event_location_to_string (b->location.get ())); |
| 12143 | } |
| 12144 | |
| 12145 | if (b->loc->next) |
| 12146 | { |
| 12147 | struct bp_location *loc = b->loc; |
| 12148 | int n = 0; |
| 12149 | for (; loc; loc = loc->next) |
| 12150 | ++n; |
| 12151 | printf_filtered (" (%d locations)", n); |
| 12152 | } |
| 12153 | } |
| 12154 | } |
| 12155 | |
| 12156 | bp_location::~bp_location () |
| 12157 | { |
| 12158 | xfree (function_name); |
| 12159 | } |
| 12160 | |
| 12161 | /* Destructor for the breakpoint base class. */ |
| 12162 | |
| 12163 | breakpoint::~breakpoint () |
| 12164 | { |
| 12165 | xfree (this->cond_string); |
| 12166 | xfree (this->extra_string); |
| 12167 | } |
| 12168 | |
| 12169 | static struct bp_location * |
| 12170 | base_breakpoint_allocate_location (struct breakpoint *self) |
| 12171 | { |
| 12172 | return new bp_location (self); |
| 12173 | } |
| 12174 | |
| 12175 | static void |
| 12176 | base_breakpoint_re_set (struct breakpoint *b) |
| 12177 | { |
| 12178 | /* Nothing to re-set. */ |
| 12179 | } |
| 12180 | |
| 12181 | #define internal_error_pure_virtual_called() \ |
| 12182 | gdb_assert_not_reached ("pure virtual function called") |
| 12183 | |
| 12184 | static int |
| 12185 | base_breakpoint_insert_location (struct bp_location *bl) |
| 12186 | { |
| 12187 | internal_error_pure_virtual_called (); |
| 12188 | } |
| 12189 | |
| 12190 | static int |
| 12191 | base_breakpoint_remove_location (struct bp_location *bl, |
| 12192 | enum remove_bp_reason reason) |
| 12193 | { |
| 12194 | internal_error_pure_virtual_called (); |
| 12195 | } |
| 12196 | |
| 12197 | static int |
| 12198 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, |
| 12199 | const address_space *aspace, |
| 12200 | CORE_ADDR bp_addr, |
| 12201 | const struct target_waitstatus *ws) |
| 12202 | { |
| 12203 | internal_error_pure_virtual_called (); |
| 12204 | } |
| 12205 | |
| 12206 | static void |
| 12207 | base_breakpoint_check_status (bpstat bs) |
| 12208 | { |
| 12209 | /* Always stop. */ |
| 12210 | } |
| 12211 | |
| 12212 | /* A "works_in_software_mode" breakpoint_ops method that just internal |
| 12213 | errors. */ |
| 12214 | |
| 12215 | static int |
| 12216 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) |
| 12217 | { |
| 12218 | internal_error_pure_virtual_called (); |
| 12219 | } |
| 12220 | |
| 12221 | /* A "resources_needed" breakpoint_ops method that just internal |
| 12222 | errors. */ |
| 12223 | |
| 12224 | static int |
| 12225 | base_breakpoint_resources_needed (const struct bp_location *bl) |
| 12226 | { |
| 12227 | internal_error_pure_virtual_called (); |
| 12228 | } |
| 12229 | |
| 12230 | static enum print_stop_action |
| 12231 | base_breakpoint_print_it (bpstat bs) |
| 12232 | { |
| 12233 | internal_error_pure_virtual_called (); |
| 12234 | } |
| 12235 | |
| 12236 | static void |
| 12237 | base_breakpoint_print_one_detail (const struct breakpoint *self, |
| 12238 | struct ui_out *uiout) |
| 12239 | { |
| 12240 | /* nothing */ |
| 12241 | } |
| 12242 | |
| 12243 | static void |
| 12244 | base_breakpoint_print_mention (struct breakpoint *b) |
| 12245 | { |
| 12246 | internal_error_pure_virtual_called (); |
| 12247 | } |
| 12248 | |
| 12249 | static void |
| 12250 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) |
| 12251 | { |
| 12252 | internal_error_pure_virtual_called (); |
| 12253 | } |
| 12254 | |
| 12255 | static void |
| 12256 | base_breakpoint_create_sals_from_location |
| 12257 | (const struct event_location *location, |
| 12258 | struct linespec_result *canonical, |
| 12259 | enum bptype type_wanted) |
| 12260 | { |
| 12261 | internal_error_pure_virtual_called (); |
| 12262 | } |
| 12263 | |
| 12264 | static void |
| 12265 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12266 | struct linespec_result *c, |
| 12267 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 12268 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 12269 | enum bptype type_wanted, |
| 12270 | enum bpdisp disposition, |
| 12271 | int thread, |
| 12272 | int task, int ignore_count, |
| 12273 | const struct breakpoint_ops *o, |
| 12274 | int from_tty, int enabled, |
| 12275 | int internal, unsigned flags) |
| 12276 | { |
| 12277 | internal_error_pure_virtual_called (); |
| 12278 | } |
| 12279 | |
| 12280 | static std::vector<symtab_and_line> |
| 12281 | base_breakpoint_decode_location (struct breakpoint *b, |
| 12282 | const struct event_location *location, |
| 12283 | struct program_space *search_pspace) |
| 12284 | { |
| 12285 | internal_error_pure_virtual_called (); |
| 12286 | } |
| 12287 | |
| 12288 | /* The default 'explains_signal' method. */ |
| 12289 | |
| 12290 | static int |
| 12291 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
| 12292 | { |
| 12293 | return 1; |
| 12294 | } |
| 12295 | |
| 12296 | /* The default "after_condition_true" method. */ |
| 12297 | |
| 12298 | static void |
| 12299 | base_breakpoint_after_condition_true (struct bpstats *bs) |
| 12300 | { |
| 12301 | /* Nothing to do. */ |
| 12302 | } |
| 12303 | |
| 12304 | struct breakpoint_ops base_breakpoint_ops = |
| 12305 | { |
| 12306 | base_breakpoint_allocate_location, |
| 12307 | base_breakpoint_re_set, |
| 12308 | base_breakpoint_insert_location, |
| 12309 | base_breakpoint_remove_location, |
| 12310 | base_breakpoint_breakpoint_hit, |
| 12311 | base_breakpoint_check_status, |
| 12312 | base_breakpoint_resources_needed, |
| 12313 | base_breakpoint_works_in_software_mode, |
| 12314 | base_breakpoint_print_it, |
| 12315 | NULL, |
| 12316 | base_breakpoint_print_one_detail, |
| 12317 | base_breakpoint_print_mention, |
| 12318 | base_breakpoint_print_recreate, |
| 12319 | base_breakpoint_create_sals_from_location, |
| 12320 | base_breakpoint_create_breakpoints_sal, |
| 12321 | base_breakpoint_decode_location, |
| 12322 | base_breakpoint_explains_signal, |
| 12323 | base_breakpoint_after_condition_true, |
| 12324 | }; |
| 12325 | |
| 12326 | /* Default breakpoint_ops methods. */ |
| 12327 | |
| 12328 | static void |
| 12329 | bkpt_re_set (struct breakpoint *b) |
| 12330 | { |
| 12331 | /* FIXME: is this still reachable? */ |
| 12332 | if (breakpoint_event_location_empty_p (b)) |
| 12333 | { |
| 12334 | /* Anything without a location can't be re-set. */ |
| 12335 | delete_breakpoint (b); |
| 12336 | return; |
| 12337 | } |
| 12338 | |
| 12339 | breakpoint_re_set_default (b); |
| 12340 | } |
| 12341 | |
| 12342 | static int |
| 12343 | bkpt_insert_location (struct bp_location *bl) |
| 12344 | { |
| 12345 | CORE_ADDR addr = bl->target_info.reqstd_address; |
| 12346 | |
| 12347 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
| 12348 | bl->target_info.placed_address = addr; |
| 12349 | |
| 12350 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 12351 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
| 12352 | else |
| 12353 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
| 12354 | } |
| 12355 | |
| 12356 | static int |
| 12357 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
| 12358 | { |
| 12359 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 12360 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); |
| 12361 | else |
| 12362 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
| 12363 | } |
| 12364 | |
| 12365 | static int |
| 12366 | bkpt_breakpoint_hit (const struct bp_location *bl, |
| 12367 | const address_space *aspace, CORE_ADDR bp_addr, |
| 12368 | const struct target_waitstatus *ws) |
| 12369 | { |
| 12370 | if (ws->kind != TARGET_WAITKIND_STOPPED |
| 12371 | || ws->value.sig != GDB_SIGNAL_TRAP) |
| 12372 | return 0; |
| 12373 | |
| 12374 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 12375 | aspace, bp_addr)) |
| 12376 | return 0; |
| 12377 | |
| 12378 | if (overlay_debugging /* unmapped overlay section */ |
| 12379 | && section_is_overlay (bl->section) |
| 12380 | && !section_is_mapped (bl->section)) |
| 12381 | return 0; |
| 12382 | |
| 12383 | return 1; |
| 12384 | } |
| 12385 | |
| 12386 | static int |
| 12387 | dprintf_breakpoint_hit (const struct bp_location *bl, |
| 12388 | const address_space *aspace, CORE_ADDR bp_addr, |
| 12389 | const struct target_waitstatus *ws) |
| 12390 | { |
| 12391 | if (dprintf_style == dprintf_style_agent |
| 12392 | && target_can_run_breakpoint_commands ()) |
| 12393 | { |
| 12394 | /* An agent-style dprintf never causes a stop. If we see a trap |
| 12395 | for this address it must be for a breakpoint that happens to |
| 12396 | be set at the same address. */ |
| 12397 | return 0; |
| 12398 | } |
| 12399 | |
| 12400 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); |
| 12401 | } |
| 12402 | |
| 12403 | static int |
| 12404 | bkpt_resources_needed (const struct bp_location *bl) |
| 12405 | { |
| 12406 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); |
| 12407 | |
| 12408 | return 1; |
| 12409 | } |
| 12410 | |
| 12411 | static enum print_stop_action |
| 12412 | bkpt_print_it (bpstat bs) |
| 12413 | { |
| 12414 | struct breakpoint *b; |
| 12415 | const struct bp_location *bl; |
| 12416 | int bp_temp; |
| 12417 | struct ui_out *uiout = current_uiout; |
| 12418 | |
| 12419 | gdb_assert (bs->bp_location_at != NULL); |
| 12420 | |
| 12421 | bl = bs->bp_location_at; |
| 12422 | b = bs->breakpoint_at; |
| 12423 | |
| 12424 | bp_temp = b->disposition == disp_del; |
| 12425 | if (bl->address != bl->requested_address) |
| 12426 | breakpoint_adjustment_warning (bl->requested_address, |
| 12427 | bl->address, |
| 12428 | b->number, 1); |
| 12429 | annotate_breakpoint (b->number); |
| 12430 | maybe_print_thread_hit_breakpoint (uiout); |
| 12431 | |
| 12432 | if (uiout->is_mi_like_p ()) |
| 12433 | { |
| 12434 | uiout->field_string ("reason", |
| 12435 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 12436 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 12437 | } |
| 12438 | if (bp_temp) |
| 12439 | uiout->message ("Temporary breakpoint %pF, ", |
| 12440 | signed_field ("bkptno", b->number)); |
| 12441 | else |
| 12442 | uiout->message ("Breakpoint %pF, ", |
| 12443 | signed_field ("bkptno", b->number)); |
| 12444 | |
| 12445 | return PRINT_SRC_AND_LOC; |
| 12446 | } |
| 12447 | |
| 12448 | static void |
| 12449 | bkpt_print_mention (struct breakpoint *b) |
| 12450 | { |
| 12451 | if (current_uiout->is_mi_like_p ()) |
| 12452 | return; |
| 12453 | |
| 12454 | switch (b->type) |
| 12455 | { |
| 12456 | case bp_breakpoint: |
| 12457 | case bp_gnu_ifunc_resolver: |
| 12458 | if (b->disposition == disp_del) |
| 12459 | printf_filtered (_("Temporary breakpoint")); |
| 12460 | else |
| 12461 | printf_filtered (_("Breakpoint")); |
| 12462 | printf_filtered (_(" %d"), b->number); |
| 12463 | if (b->type == bp_gnu_ifunc_resolver) |
| 12464 | printf_filtered (_(" at gnu-indirect-function resolver")); |
| 12465 | break; |
| 12466 | case bp_hardware_breakpoint: |
| 12467 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
| 12468 | break; |
| 12469 | case bp_dprintf: |
| 12470 | printf_filtered (_("Dprintf %d"), b->number); |
| 12471 | break; |
| 12472 | } |
| 12473 | |
| 12474 | say_where (b); |
| 12475 | } |
| 12476 | |
| 12477 | static void |
| 12478 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
| 12479 | { |
| 12480 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) |
| 12481 | fprintf_unfiltered (fp, "tbreak"); |
| 12482 | else if (tp->type == bp_breakpoint) |
| 12483 | fprintf_unfiltered (fp, "break"); |
| 12484 | else if (tp->type == bp_hardware_breakpoint |
| 12485 | && tp->disposition == disp_del) |
| 12486 | fprintf_unfiltered (fp, "thbreak"); |
| 12487 | else if (tp->type == bp_hardware_breakpoint) |
| 12488 | fprintf_unfiltered (fp, "hbreak"); |
| 12489 | else |
| 12490 | internal_error (__FILE__, __LINE__, |
| 12491 | _("unhandled breakpoint type %d"), (int) tp->type); |
| 12492 | |
| 12493 | fprintf_unfiltered (fp, " %s", |
| 12494 | event_location_to_string (tp->location.get ())); |
| 12495 | |
| 12496 | /* Print out extra_string if this breakpoint is pending. It might |
| 12497 | contain, for example, conditions that were set by the user. */ |
| 12498 | if (tp->loc == NULL && tp->extra_string != NULL) |
| 12499 | fprintf_unfiltered (fp, " %s", tp->extra_string); |
| 12500 | |
| 12501 | print_recreate_thread (tp, fp); |
| 12502 | } |
| 12503 | |
| 12504 | static void |
| 12505 | bkpt_create_sals_from_location (const struct event_location *location, |
| 12506 | struct linespec_result *canonical, |
| 12507 | enum bptype type_wanted) |
| 12508 | { |
| 12509 | create_sals_from_location_default (location, canonical, type_wanted); |
| 12510 | } |
| 12511 | |
| 12512 | static void |
| 12513 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12514 | struct linespec_result *canonical, |
| 12515 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 12516 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 12517 | enum bptype type_wanted, |
| 12518 | enum bpdisp disposition, |
| 12519 | int thread, |
| 12520 | int task, int ignore_count, |
| 12521 | const struct breakpoint_ops *ops, |
| 12522 | int from_tty, int enabled, |
| 12523 | int internal, unsigned flags) |
| 12524 | { |
| 12525 | create_breakpoints_sal_default (gdbarch, canonical, |
| 12526 | std::move (cond_string), |
| 12527 | std::move (extra_string), |
| 12528 | type_wanted, |
| 12529 | disposition, thread, task, |
| 12530 | ignore_count, ops, from_tty, |
| 12531 | enabled, internal, flags); |
| 12532 | } |
| 12533 | |
| 12534 | static std::vector<symtab_and_line> |
| 12535 | bkpt_decode_location (struct breakpoint *b, |
| 12536 | const struct event_location *location, |
| 12537 | struct program_space *search_pspace) |
| 12538 | { |
| 12539 | return decode_location_default (b, location, search_pspace); |
| 12540 | } |
| 12541 | |
| 12542 | /* Virtual table for internal breakpoints. */ |
| 12543 | |
| 12544 | static void |
| 12545 | internal_bkpt_re_set (struct breakpoint *b) |
| 12546 | { |
| 12547 | switch (b->type) |
| 12548 | { |
| 12549 | /* Delete overlay event and longjmp master breakpoints; they |
| 12550 | will be reset later by breakpoint_re_set. */ |
| 12551 | case bp_overlay_event: |
| 12552 | case bp_longjmp_master: |
| 12553 | case bp_std_terminate_master: |
| 12554 | case bp_exception_master: |
| 12555 | delete_breakpoint (b); |
| 12556 | break; |
| 12557 | |
| 12558 | /* This breakpoint is special, it's set up when the inferior |
| 12559 | starts and we really don't want to touch it. */ |
| 12560 | case bp_shlib_event: |
| 12561 | |
| 12562 | /* Like bp_shlib_event, this breakpoint type is special. Once |
| 12563 | it is set up, we do not want to touch it. */ |
| 12564 | case bp_thread_event: |
| 12565 | break; |
| 12566 | } |
| 12567 | } |
| 12568 | |
| 12569 | static void |
| 12570 | internal_bkpt_check_status (bpstat bs) |
| 12571 | { |
| 12572 | if (bs->breakpoint_at->type == bp_shlib_event) |
| 12573 | { |
| 12574 | /* If requested, stop when the dynamic linker notifies GDB of |
| 12575 | events. This allows the user to get control and place |
| 12576 | breakpoints in initializer routines for dynamically loaded |
| 12577 | objects (among other things). */ |
| 12578 | bs->stop = stop_on_solib_events; |
| 12579 | bs->print = stop_on_solib_events; |
| 12580 | } |
| 12581 | else |
| 12582 | bs->stop = 0; |
| 12583 | } |
| 12584 | |
| 12585 | static enum print_stop_action |
| 12586 | internal_bkpt_print_it (bpstat bs) |
| 12587 | { |
| 12588 | struct breakpoint *b; |
| 12589 | |
| 12590 | b = bs->breakpoint_at; |
| 12591 | |
| 12592 | switch (b->type) |
| 12593 | { |
| 12594 | case bp_shlib_event: |
| 12595 | /* Did we stop because the user set the stop_on_solib_events |
| 12596 | variable? (If so, we report this as a generic, "Stopped due |
| 12597 | to shlib event" message.) */ |
| 12598 | print_solib_event (0); |
| 12599 | break; |
| 12600 | |
| 12601 | case bp_thread_event: |
| 12602 | /* Not sure how we will get here. |
| 12603 | GDB should not stop for these breakpoints. */ |
| 12604 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
| 12605 | break; |
| 12606 | |
| 12607 | case bp_overlay_event: |
| 12608 | /* By analogy with the thread event, GDB should not stop for these. */ |
| 12609 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
| 12610 | break; |
| 12611 | |
| 12612 | case bp_longjmp_master: |
| 12613 | /* These should never be enabled. */ |
| 12614 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); |
| 12615 | break; |
| 12616 | |
| 12617 | case bp_std_terminate_master: |
| 12618 | /* These should never be enabled. */ |
| 12619 | printf_filtered (_("std::terminate Master Breakpoint: " |
| 12620 | "gdb should not stop!\n")); |
| 12621 | break; |
| 12622 | |
| 12623 | case bp_exception_master: |
| 12624 | /* These should never be enabled. */ |
| 12625 | printf_filtered (_("Exception Master Breakpoint: " |
| 12626 | "gdb should not stop!\n")); |
| 12627 | break; |
| 12628 | } |
| 12629 | |
| 12630 | return PRINT_NOTHING; |
| 12631 | } |
| 12632 | |
| 12633 | static void |
| 12634 | internal_bkpt_print_mention (struct breakpoint *b) |
| 12635 | { |
| 12636 | /* Nothing to mention. These breakpoints are internal. */ |
| 12637 | } |
| 12638 | |
| 12639 | /* Virtual table for momentary breakpoints */ |
| 12640 | |
| 12641 | static void |
| 12642 | momentary_bkpt_re_set (struct breakpoint *b) |
| 12643 | { |
| 12644 | /* Keep temporary breakpoints, which can be encountered when we step |
| 12645 | over a dlopen call and solib_add is resetting the breakpoints. |
| 12646 | Otherwise these should have been blown away via the cleanup chain |
| 12647 | or by breakpoint_init_inferior when we rerun the executable. */ |
| 12648 | } |
| 12649 | |
| 12650 | static void |
| 12651 | momentary_bkpt_check_status (bpstat bs) |
| 12652 | { |
| 12653 | /* Nothing. The point of these breakpoints is causing a stop. */ |
| 12654 | } |
| 12655 | |
| 12656 | static enum print_stop_action |
| 12657 | momentary_bkpt_print_it (bpstat bs) |
| 12658 | { |
| 12659 | return PRINT_UNKNOWN; |
| 12660 | } |
| 12661 | |
| 12662 | static void |
| 12663 | momentary_bkpt_print_mention (struct breakpoint *b) |
| 12664 | { |
| 12665 | /* Nothing to mention. These breakpoints are internal. */ |
| 12666 | } |
| 12667 | |
| 12668 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
| 12669 | |
| 12670 | It gets cleared already on the removal of the first one of such placed |
| 12671 | breakpoints. This is OK as they get all removed altogether. */ |
| 12672 | |
| 12673 | longjmp_breakpoint::~longjmp_breakpoint () |
| 12674 | { |
| 12675 | thread_info *tp = find_thread_global_id (this->thread); |
| 12676 | |
| 12677 | if (tp != NULL) |
| 12678 | tp->initiating_frame = null_frame_id; |
| 12679 | } |
| 12680 | |
| 12681 | /* Specific methods for probe breakpoints. */ |
| 12682 | |
| 12683 | static int |
| 12684 | bkpt_probe_insert_location (struct bp_location *bl) |
| 12685 | { |
| 12686 | int v = bkpt_insert_location (bl); |
| 12687 | |
| 12688 | if (v == 0) |
| 12689 | { |
| 12690 | /* The insertion was successful, now let's set the probe's semaphore |
| 12691 | if needed. */ |
| 12692 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
| 12693 | } |
| 12694 | |
| 12695 | return v; |
| 12696 | } |
| 12697 | |
| 12698 | static int |
| 12699 | bkpt_probe_remove_location (struct bp_location *bl, |
| 12700 | enum remove_bp_reason reason) |
| 12701 | { |
| 12702 | /* Let's clear the semaphore before removing the location. */ |
| 12703 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
| 12704 | |
| 12705 | return bkpt_remove_location (bl, reason); |
| 12706 | } |
| 12707 | |
| 12708 | static void |
| 12709 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
| 12710 | struct linespec_result *canonical, |
| 12711 | enum bptype type_wanted) |
| 12712 | { |
| 12713 | struct linespec_sals lsal; |
| 12714 | |
| 12715 | lsal.sals = parse_probes (location, NULL, canonical); |
| 12716 | lsal.canonical |
| 12717 | = xstrdup (event_location_to_string (canonical->location.get ())); |
| 12718 | canonical->lsals.push_back (std::move (lsal)); |
| 12719 | } |
| 12720 | |
| 12721 | static std::vector<symtab_and_line> |
| 12722 | bkpt_probe_decode_location (struct breakpoint *b, |
| 12723 | const struct event_location *location, |
| 12724 | struct program_space *search_pspace) |
| 12725 | { |
| 12726 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
| 12727 | if (sals.empty ()) |
| 12728 | error (_("probe not found")); |
| 12729 | return sals; |
| 12730 | } |
| 12731 | |
| 12732 | /* The breakpoint_ops structure to be used in tracepoints. */ |
| 12733 | |
| 12734 | static void |
| 12735 | tracepoint_re_set (struct breakpoint *b) |
| 12736 | { |
| 12737 | breakpoint_re_set_default (b); |
| 12738 | } |
| 12739 | |
| 12740 | static int |
| 12741 | tracepoint_breakpoint_hit (const struct bp_location *bl, |
| 12742 | const address_space *aspace, CORE_ADDR bp_addr, |
| 12743 | const struct target_waitstatus *ws) |
| 12744 | { |
| 12745 | /* By definition, the inferior does not report stops at |
| 12746 | tracepoints. */ |
| 12747 | return 0; |
| 12748 | } |
| 12749 | |
| 12750 | static void |
| 12751 | tracepoint_print_one_detail (const struct breakpoint *self, |
| 12752 | struct ui_out *uiout) |
| 12753 | { |
| 12754 | struct tracepoint *tp = (struct tracepoint *) self; |
| 12755 | if (!tp->static_trace_marker_id.empty ()) |
| 12756 | { |
| 12757 | gdb_assert (self->type == bp_static_tracepoint); |
| 12758 | |
| 12759 | uiout->message ("\tmarker id is %pF\n", |
| 12760 | string_field ("static-tracepoint-marker-string-id", |
| 12761 | tp->static_trace_marker_id.c_str ())); |
| 12762 | } |
| 12763 | } |
| 12764 | |
| 12765 | static void |
| 12766 | tracepoint_print_mention (struct breakpoint *b) |
| 12767 | { |
| 12768 | if (current_uiout->is_mi_like_p ()) |
| 12769 | return; |
| 12770 | |
| 12771 | switch (b->type) |
| 12772 | { |
| 12773 | case bp_tracepoint: |
| 12774 | printf_filtered (_("Tracepoint")); |
| 12775 | printf_filtered (_(" %d"), b->number); |
| 12776 | break; |
| 12777 | case bp_fast_tracepoint: |
| 12778 | printf_filtered (_("Fast tracepoint")); |
| 12779 | printf_filtered (_(" %d"), b->number); |
| 12780 | break; |
| 12781 | case bp_static_tracepoint: |
| 12782 | printf_filtered (_("Static tracepoint")); |
| 12783 | printf_filtered (_(" %d"), b->number); |
| 12784 | break; |
| 12785 | default: |
| 12786 | internal_error (__FILE__, __LINE__, |
| 12787 | _("unhandled tracepoint type %d"), (int) b->type); |
| 12788 | } |
| 12789 | |
| 12790 | say_where (b); |
| 12791 | } |
| 12792 | |
| 12793 | static void |
| 12794 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
| 12795 | { |
| 12796 | struct tracepoint *tp = (struct tracepoint *) self; |
| 12797 | |
| 12798 | if (self->type == bp_fast_tracepoint) |
| 12799 | fprintf_unfiltered (fp, "ftrace"); |
| 12800 | else if (self->type == bp_static_tracepoint) |
| 12801 | fprintf_unfiltered (fp, "strace"); |
| 12802 | else if (self->type == bp_tracepoint) |
| 12803 | fprintf_unfiltered (fp, "trace"); |
| 12804 | else |
| 12805 | internal_error (__FILE__, __LINE__, |
| 12806 | _("unhandled tracepoint type %d"), (int) self->type); |
| 12807 | |
| 12808 | fprintf_unfiltered (fp, " %s", |
| 12809 | event_location_to_string (self->location.get ())); |
| 12810 | print_recreate_thread (self, fp); |
| 12811 | |
| 12812 | if (tp->pass_count) |
| 12813 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
| 12814 | } |
| 12815 | |
| 12816 | static void |
| 12817 | tracepoint_create_sals_from_location (const struct event_location *location, |
| 12818 | struct linespec_result *canonical, |
| 12819 | enum bptype type_wanted) |
| 12820 | { |
| 12821 | create_sals_from_location_default (location, canonical, type_wanted); |
| 12822 | } |
| 12823 | |
| 12824 | static void |
| 12825 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12826 | struct linespec_result *canonical, |
| 12827 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 12828 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 12829 | enum bptype type_wanted, |
| 12830 | enum bpdisp disposition, |
| 12831 | int thread, |
| 12832 | int task, int ignore_count, |
| 12833 | const struct breakpoint_ops *ops, |
| 12834 | int from_tty, int enabled, |
| 12835 | int internal, unsigned flags) |
| 12836 | { |
| 12837 | create_breakpoints_sal_default (gdbarch, canonical, |
| 12838 | std::move (cond_string), |
| 12839 | std::move (extra_string), |
| 12840 | type_wanted, |
| 12841 | disposition, thread, task, |
| 12842 | ignore_count, ops, from_tty, |
| 12843 | enabled, internal, flags); |
| 12844 | } |
| 12845 | |
| 12846 | static std::vector<symtab_and_line> |
| 12847 | tracepoint_decode_location (struct breakpoint *b, |
| 12848 | const struct event_location *location, |
| 12849 | struct program_space *search_pspace) |
| 12850 | { |
| 12851 | return decode_location_default (b, location, search_pspace); |
| 12852 | } |
| 12853 | |
| 12854 | struct breakpoint_ops tracepoint_breakpoint_ops; |
| 12855 | |
| 12856 | /* Virtual table for tracepoints on static probes. */ |
| 12857 | |
| 12858 | static void |
| 12859 | tracepoint_probe_create_sals_from_location |
| 12860 | (const struct event_location *location, |
| 12861 | struct linespec_result *canonical, |
| 12862 | enum bptype type_wanted) |
| 12863 | { |
| 12864 | /* We use the same method for breakpoint on probes. */ |
| 12865 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
| 12866 | } |
| 12867 | |
| 12868 | static std::vector<symtab_and_line> |
| 12869 | tracepoint_probe_decode_location (struct breakpoint *b, |
| 12870 | const struct event_location *location, |
| 12871 | struct program_space *search_pspace) |
| 12872 | { |
| 12873 | /* We use the same method for breakpoint on probes. */ |
| 12874 | return bkpt_probe_decode_location (b, location, search_pspace); |
| 12875 | } |
| 12876 | |
| 12877 | /* Dprintf breakpoint_ops methods. */ |
| 12878 | |
| 12879 | static void |
| 12880 | dprintf_re_set (struct breakpoint *b) |
| 12881 | { |
| 12882 | breakpoint_re_set_default (b); |
| 12883 | |
| 12884 | /* extra_string should never be non-NULL for dprintf. */ |
| 12885 | gdb_assert (b->extra_string != NULL); |
| 12886 | |
| 12887 | /* 1 - connect to target 1, that can run breakpoint commands. |
| 12888 | 2 - create a dprintf, which resolves fine. |
| 12889 | 3 - disconnect from target 1 |
| 12890 | 4 - connect to target 2, that can NOT run breakpoint commands. |
| 12891 | |
| 12892 | After steps #3/#4, you'll want the dprintf command list to |
| 12893 | be updated, because target 1 and 2 may well return different |
| 12894 | answers for target_can_run_breakpoint_commands(). |
| 12895 | Given absence of finer grained resetting, we get to do |
| 12896 | it all the time. */ |
| 12897 | if (b->extra_string != NULL) |
| 12898 | update_dprintf_command_list (b); |
| 12899 | } |
| 12900 | |
| 12901 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
| 12902 | |
| 12903 | static void |
| 12904 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
| 12905 | { |
| 12906 | fprintf_unfiltered (fp, "dprintf %s,%s", |
| 12907 | event_location_to_string (tp->location.get ()), |
| 12908 | tp->extra_string); |
| 12909 | print_recreate_thread (tp, fp); |
| 12910 | } |
| 12911 | |
| 12912 | /* Implement the "after_condition_true" breakpoint_ops method for |
| 12913 | dprintf. |
| 12914 | |
| 12915 | dprintf's are implemented with regular commands in their command |
| 12916 | list, but we run the commands here instead of before presenting the |
| 12917 | stop to the user, as dprintf's don't actually cause a stop. This |
| 12918 | also makes it so that the commands of multiple dprintfs at the same |
| 12919 | address are all handled. */ |
| 12920 | |
| 12921 | static void |
| 12922 | dprintf_after_condition_true (struct bpstats *bs) |
| 12923 | { |
| 12924 | struct bpstats tmp_bs; |
| 12925 | struct bpstats *tmp_bs_p = &tmp_bs; |
| 12926 | |
| 12927 | /* dprintf's never cause a stop. This wasn't set in the |
| 12928 | check_status hook instead because that would make the dprintf's |
| 12929 | condition not be evaluated. */ |
| 12930 | bs->stop = 0; |
| 12931 | |
| 12932 | /* Run the command list here. Take ownership of it instead of |
| 12933 | copying. We never want these commands to run later in |
| 12934 | bpstat_do_actions, if a breakpoint that causes a stop happens to |
| 12935 | be set at same address as this dprintf, or even if running the |
| 12936 | commands here throws. */ |
| 12937 | tmp_bs.commands = bs->commands; |
| 12938 | bs->commands = NULL; |
| 12939 | |
| 12940 | bpstat_do_actions_1 (&tmp_bs_p); |
| 12941 | |
| 12942 | /* 'tmp_bs.commands' will usually be NULL by now, but |
| 12943 | bpstat_do_actions_1 may return early without processing the whole |
| 12944 | list. */ |
| 12945 | } |
| 12946 | |
| 12947 | /* The breakpoint_ops structure to be used on static tracepoints with |
| 12948 | markers (`-m'). */ |
| 12949 | |
| 12950 | static void |
| 12951 | strace_marker_create_sals_from_location (const struct event_location *location, |
| 12952 | struct linespec_result *canonical, |
| 12953 | enum bptype type_wanted) |
| 12954 | { |
| 12955 | struct linespec_sals lsal; |
| 12956 | const char *arg_start, *arg; |
| 12957 | |
| 12958 | arg = arg_start = get_linespec_location (location)->spec_string; |
| 12959 | lsal.sals = decode_static_tracepoint_spec (&arg); |
| 12960 | |
| 12961 | std::string str (arg_start, arg - arg_start); |
| 12962 | const char *ptr = str.c_str (); |
| 12963 | canonical->location |
| 12964 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); |
| 12965 | |
| 12966 | lsal.canonical |
| 12967 | = xstrdup (event_location_to_string (canonical->location.get ())); |
| 12968 | canonical->lsals.push_back (std::move (lsal)); |
| 12969 | } |
| 12970 | |
| 12971 | static void |
| 12972 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12973 | struct linespec_result *canonical, |
| 12974 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 12975 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 12976 | enum bptype type_wanted, |
| 12977 | enum bpdisp disposition, |
| 12978 | int thread, |
| 12979 | int task, int ignore_count, |
| 12980 | const struct breakpoint_ops *ops, |
| 12981 | int from_tty, int enabled, |
| 12982 | int internal, unsigned flags) |
| 12983 | { |
| 12984 | const linespec_sals &lsal = canonical->lsals[0]; |
| 12985 | |
| 12986 | /* If the user is creating a static tracepoint by marker id |
| 12987 | (strace -m MARKER_ID), then store the sals index, so that |
| 12988 | breakpoint_re_set can try to match up which of the newly |
| 12989 | found markers corresponds to this one, and, don't try to |
| 12990 | expand multiple locations for each sal, given than SALS |
| 12991 | already should contain all sals for MARKER_ID. */ |
| 12992 | |
| 12993 | for (size_t i = 0; i < lsal.sals.size (); i++) |
| 12994 | { |
| 12995 | event_location_up location |
| 12996 | = copy_event_location (canonical->location.get ()); |
| 12997 | |
| 12998 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
| 12999 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
| 13000 | std::move (location), NULL, |
| 13001 | std::move (cond_string), |
| 13002 | std::move (extra_string), |
| 13003 | type_wanted, disposition, |
| 13004 | thread, task, ignore_count, ops, |
| 13005 | from_tty, enabled, internal, flags, |
| 13006 | canonical->special_display); |
| 13007 | /* Given that its possible to have multiple markers with |
| 13008 | the same string id, if the user is creating a static |
| 13009 | tracepoint by marker id ("strace -m MARKER_ID"), then |
| 13010 | store the sals index, so that breakpoint_re_set can |
| 13011 | try to match up which of the newly found markers |
| 13012 | corresponds to this one */ |
| 13013 | tp->static_trace_marker_id_idx = i; |
| 13014 | |
| 13015 | install_breakpoint (internal, std::move (tp), 0); |
| 13016 | } |
| 13017 | } |
| 13018 | |
| 13019 | static std::vector<symtab_and_line> |
| 13020 | strace_marker_decode_location (struct breakpoint *b, |
| 13021 | const struct event_location *location, |
| 13022 | struct program_space *search_pspace) |
| 13023 | { |
| 13024 | struct tracepoint *tp = (struct tracepoint *) b; |
| 13025 | const char *s = get_linespec_location (location)->spec_string; |
| 13026 | |
| 13027 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
| 13028 | if (sals.size () > tp->static_trace_marker_id_idx) |
| 13029 | { |
| 13030 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
| 13031 | sals.resize (1); |
| 13032 | return sals; |
| 13033 | } |
| 13034 | else |
| 13035 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
| 13036 | } |
| 13037 | |
| 13038 | static struct breakpoint_ops strace_marker_breakpoint_ops; |
| 13039 | |
| 13040 | static int |
| 13041 | strace_marker_p (struct breakpoint *b) |
| 13042 | { |
| 13043 | return b->ops == &strace_marker_breakpoint_ops; |
| 13044 | } |
| 13045 | |
| 13046 | /* Delete a breakpoint and clean up all traces of it in the data |
| 13047 | structures. */ |
| 13048 | |
| 13049 | void |
| 13050 | delete_breakpoint (struct breakpoint *bpt) |
| 13051 | { |
| 13052 | struct breakpoint *b; |
| 13053 | |
| 13054 | gdb_assert (bpt != NULL); |
| 13055 | |
| 13056 | /* Has this bp already been deleted? This can happen because |
| 13057 | multiple lists can hold pointers to bp's. bpstat lists are |
| 13058 | especial culprits. |
| 13059 | |
| 13060 | One example of this happening is a watchpoint's scope bp. When |
| 13061 | the scope bp triggers, we notice that the watchpoint is out of |
| 13062 | scope, and delete it. We also delete its scope bp. But the |
| 13063 | scope bp is marked "auto-deleting", and is already on a bpstat. |
| 13064 | That bpstat is then checked for auto-deleting bp's, which are |
| 13065 | deleted. |
| 13066 | |
| 13067 | A real solution to this problem might involve reference counts in |
| 13068 | bp's, and/or giving them pointers back to their referencing |
| 13069 | bpstat's, and teaching delete_breakpoint to only free a bp's |
| 13070 | storage when no more references were extent. A cheaper bandaid |
| 13071 | was chosen. */ |
| 13072 | if (bpt->type == bp_none) |
| 13073 | return; |
| 13074 | |
| 13075 | /* At least avoid this stale reference until the reference counting |
| 13076 | of breakpoints gets resolved. */ |
| 13077 | if (bpt->related_breakpoint != bpt) |
| 13078 | { |
| 13079 | struct breakpoint *related; |
| 13080 | struct watchpoint *w; |
| 13081 | |
| 13082 | if (bpt->type == bp_watchpoint_scope) |
| 13083 | w = (struct watchpoint *) bpt->related_breakpoint; |
| 13084 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
| 13085 | w = (struct watchpoint *) bpt; |
| 13086 | else |
| 13087 | w = NULL; |
| 13088 | if (w != NULL) |
| 13089 | watchpoint_del_at_next_stop (w); |
| 13090 | |
| 13091 | /* Unlink bpt from the bpt->related_breakpoint ring. */ |
| 13092 | for (related = bpt; related->related_breakpoint != bpt; |
| 13093 | related = related->related_breakpoint); |
| 13094 | related->related_breakpoint = bpt->related_breakpoint; |
| 13095 | bpt->related_breakpoint = bpt; |
| 13096 | } |
| 13097 | |
| 13098 | /* watch_command_1 creates a watchpoint but only sets its number if |
| 13099 | update_watchpoint succeeds in creating its bp_locations. If there's |
| 13100 | a problem in that process, we'll be asked to delete the half-created |
| 13101 | watchpoint. In that case, don't announce the deletion. */ |
| 13102 | if (bpt->number) |
| 13103 | gdb::observers::breakpoint_deleted.notify (bpt); |
| 13104 | |
| 13105 | if (breakpoint_chain == bpt) |
| 13106 | breakpoint_chain = bpt->next; |
| 13107 | |
| 13108 | ALL_BREAKPOINTS (b) |
| 13109 | if (b->next == bpt) |
| 13110 | { |
| 13111 | b->next = bpt->next; |
| 13112 | break; |
| 13113 | } |
| 13114 | |
| 13115 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
| 13116 | been freed. */ |
| 13117 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat |
| 13118 | in all threads for now. Note that we cannot just remove bpstats |
| 13119 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
| 13120 | commands are associated with the bpstat; if we remove it here, |
| 13121 | then the later call to bpstat_do_actions (&stop_bpstat); in |
| 13122 | event-top.c won't do anything, and temporary breakpoints with |
| 13123 | commands won't work. */ |
| 13124 | |
| 13125 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
| 13126 | |
| 13127 | /* Now that breakpoint is removed from breakpoint list, update the |
| 13128 | global location list. This will remove locations that used to |
| 13129 | belong to this breakpoint. Do this before freeing the breakpoint |
| 13130 | itself, since remove_breakpoint looks at location's owner. It |
| 13131 | might be better design to have location completely |
| 13132 | self-contained, but it's not the case now. */ |
| 13133 | update_global_location_list (UGLL_DONT_INSERT); |
| 13134 | |
| 13135 | /* On the chance that someone will soon try again to delete this |
| 13136 | same bp, we mark it as deleted before freeing its storage. */ |
| 13137 | bpt->type = bp_none; |
| 13138 | delete bpt; |
| 13139 | } |
| 13140 | |
| 13141 | /* Iterator function to call a user-provided callback function once |
| 13142 | for each of B and its related breakpoints. */ |
| 13143 | |
| 13144 | static void |
| 13145 | iterate_over_related_breakpoints (struct breakpoint *b, |
| 13146 | gdb::function_view<void (breakpoint *)> function) |
| 13147 | { |
| 13148 | struct breakpoint *related; |
| 13149 | |
| 13150 | related = b; |
| 13151 | do |
| 13152 | { |
| 13153 | struct breakpoint *next; |
| 13154 | |
| 13155 | /* FUNCTION may delete RELATED. */ |
| 13156 | next = related->related_breakpoint; |
| 13157 | |
| 13158 | if (next == related) |
| 13159 | { |
| 13160 | /* RELATED is the last ring entry. */ |
| 13161 | function (related); |
| 13162 | |
| 13163 | /* FUNCTION may have deleted it, so we'd never reach back to |
| 13164 | B. There's nothing left to do anyway, so just break |
| 13165 | out. */ |
| 13166 | break; |
| 13167 | } |
| 13168 | else |
| 13169 | function (related); |
| 13170 | |
| 13171 | related = next; |
| 13172 | } |
| 13173 | while (related != b); |
| 13174 | } |
| 13175 | |
| 13176 | static void |
| 13177 | delete_command (const char *arg, int from_tty) |
| 13178 | { |
| 13179 | struct breakpoint *b, *b_tmp; |
| 13180 | |
| 13181 | dont_repeat (); |
| 13182 | |
| 13183 | if (arg == 0) |
| 13184 | { |
| 13185 | int breaks_to_delete = 0; |
| 13186 | |
| 13187 | /* Delete all breakpoints if no argument. Do not delete |
| 13188 | internal breakpoints, these have to be deleted with an |
| 13189 | explicit breakpoint number argument. */ |
| 13190 | ALL_BREAKPOINTS (b) |
| 13191 | if (user_breakpoint_p (b)) |
| 13192 | { |
| 13193 | breaks_to_delete = 1; |
| 13194 | break; |
| 13195 | } |
| 13196 | |
| 13197 | /* Ask user only if there are some breakpoints to delete. */ |
| 13198 | if (!from_tty |
| 13199 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
| 13200 | { |
| 13201 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 13202 | if (user_breakpoint_p (b)) |
| 13203 | delete_breakpoint (b); |
| 13204 | } |
| 13205 | } |
| 13206 | else |
| 13207 | map_breakpoint_numbers |
| 13208 | (arg, [&] (breakpoint *br) |
| 13209 | { |
| 13210 | iterate_over_related_breakpoints (br, delete_breakpoint); |
| 13211 | }); |
| 13212 | } |
| 13213 | |
| 13214 | /* Return true if all locations of B bound to PSPACE are pending. If |
| 13215 | PSPACE is NULL, all locations of all program spaces are |
| 13216 | considered. */ |
| 13217 | |
| 13218 | static int |
| 13219 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
| 13220 | { |
| 13221 | struct bp_location *loc; |
| 13222 | |
| 13223 | for (loc = b->loc; loc != NULL; loc = loc->next) |
| 13224 | if ((pspace == NULL |
| 13225 | || loc->pspace == pspace) |
| 13226 | && !loc->shlib_disabled |
| 13227 | && !loc->pspace->executing_startup) |
| 13228 | return 0; |
| 13229 | return 1; |
| 13230 | } |
| 13231 | |
| 13232 | /* Subroutine of update_breakpoint_locations to simplify it. |
| 13233 | Return non-zero if multiple fns in list LOC have the same name. |
| 13234 | Null names are ignored. */ |
| 13235 | |
| 13236 | static int |
| 13237 | ambiguous_names_p (struct bp_location *loc) |
| 13238 | { |
| 13239 | struct bp_location *l; |
| 13240 | htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
| 13241 | xcalloc, xfree); |
| 13242 | |
| 13243 | for (l = loc; l != NULL; l = l->next) |
| 13244 | { |
| 13245 | const char **slot; |
| 13246 | const char *name = l->function_name; |
| 13247 | |
| 13248 | /* Allow for some names to be NULL, ignore them. */ |
| 13249 | if (name == NULL) |
| 13250 | continue; |
| 13251 | |
| 13252 | slot = (const char **) htab_find_slot (htab, (const void *) name, |
| 13253 | INSERT); |
| 13254 | /* NOTE: We can assume slot != NULL here because xcalloc never |
| 13255 | returns NULL. */ |
| 13256 | if (*slot != NULL) |
| 13257 | { |
| 13258 | htab_delete (htab); |
| 13259 | return 1; |
| 13260 | } |
| 13261 | *slot = name; |
| 13262 | } |
| 13263 | |
| 13264 | htab_delete (htab); |
| 13265 | return 0; |
| 13266 | } |
| 13267 | |
| 13268 | /* When symbols change, it probably means the sources changed as well, |
| 13269 | and it might mean the static tracepoint markers are no longer at |
| 13270 | the same address or line numbers they used to be at last we |
| 13271 | checked. Losing your static tracepoints whenever you rebuild is |
| 13272 | undesirable. This function tries to resync/rematch gdb static |
| 13273 | tracepoints with the markers on the target, for static tracepoints |
| 13274 | that have not been set by marker id. Static tracepoint that have |
| 13275 | been set by marker id are reset by marker id in breakpoint_re_set. |
| 13276 | The heuristic is: |
| 13277 | |
| 13278 | 1) For a tracepoint set at a specific address, look for a marker at |
| 13279 | the old PC. If one is found there, assume to be the same marker. |
| 13280 | If the name / string id of the marker found is different from the |
| 13281 | previous known name, assume that means the user renamed the marker |
| 13282 | in the sources, and output a warning. |
| 13283 | |
| 13284 | 2) For a tracepoint set at a given line number, look for a marker |
| 13285 | at the new address of the old line number. If one is found there, |
| 13286 | assume to be the same marker. If the name / string id of the |
| 13287 | marker found is different from the previous known name, assume that |
| 13288 | means the user renamed the marker in the sources, and output a |
| 13289 | warning. |
| 13290 | |
| 13291 | 3) If a marker is no longer found at the same address or line, it |
| 13292 | may mean the marker no longer exists. But it may also just mean |
| 13293 | the code changed a bit. Maybe the user added a few lines of code |
| 13294 | that made the marker move up or down (in line number terms). Ask |
| 13295 | the target for info about the marker with the string id as we knew |
| 13296 | it. If found, update line number and address in the matching |
| 13297 | static tracepoint. This will get confused if there's more than one |
| 13298 | marker with the same ID (possible in UST, although unadvised |
| 13299 | precisely because it confuses tools). */ |
| 13300 | |
| 13301 | static struct symtab_and_line |
| 13302 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) |
| 13303 | { |
| 13304 | struct tracepoint *tp = (struct tracepoint *) b; |
| 13305 | struct static_tracepoint_marker marker; |
| 13306 | CORE_ADDR pc; |
| 13307 | |
| 13308 | pc = sal.pc; |
| 13309 | if (sal.line) |
| 13310 | find_line_pc (sal.symtab, sal.line, &pc); |
| 13311 | |
| 13312 | if (target_static_tracepoint_marker_at (pc, &marker)) |
| 13313 | { |
| 13314 | if (tp->static_trace_marker_id != marker.str_id) |
| 13315 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
| 13316 | b->number, tp->static_trace_marker_id.c_str (), |
| 13317 | marker.str_id.c_str ()); |
| 13318 | |
| 13319 | tp->static_trace_marker_id = std::move (marker.str_id); |
| 13320 | |
| 13321 | return sal; |
| 13322 | } |
| 13323 | |
| 13324 | /* Old marker wasn't found on target at lineno. Try looking it up |
| 13325 | by string ID. */ |
| 13326 | if (!sal.explicit_pc |
| 13327 | && sal.line != 0 |
| 13328 | && sal.symtab != NULL |
| 13329 | && !tp->static_trace_marker_id.empty ()) |
| 13330 | { |
| 13331 | std::vector<static_tracepoint_marker> markers |
| 13332 | = target_static_tracepoint_markers_by_strid |
| 13333 | (tp->static_trace_marker_id.c_str ()); |
| 13334 | |
| 13335 | if (!markers.empty ()) |
| 13336 | { |
| 13337 | struct symbol *sym; |
| 13338 | struct static_tracepoint_marker *tpmarker; |
| 13339 | struct ui_out *uiout = current_uiout; |
| 13340 | struct explicit_location explicit_loc; |
| 13341 | |
| 13342 | tpmarker = &markers[0]; |
| 13343 | |
| 13344 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
| 13345 | |
| 13346 | warning (_("marker for static tracepoint %d (%s) not " |
| 13347 | "found at previous line number"), |
| 13348 | b->number, tp->static_trace_marker_id.c_str ()); |
| 13349 | |
| 13350 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
| 13351 | sym = find_pc_sect_function (tpmarker->address, NULL); |
| 13352 | uiout->text ("Now in "); |
| 13353 | if (sym) |
| 13354 | { |
| 13355 | uiout->field_string ("func", sym->print_name (), |
| 13356 | function_name_style.style ()); |
| 13357 | uiout->text (" at "); |
| 13358 | } |
| 13359 | uiout->field_string ("file", |
| 13360 | symtab_to_filename_for_display (sal2.symtab), |
| 13361 | file_name_style.style ()); |
| 13362 | uiout->text (":"); |
| 13363 | |
| 13364 | if (uiout->is_mi_like_p ()) |
| 13365 | { |
| 13366 | const char *fullname = symtab_to_fullname (sal2.symtab); |
| 13367 | |
| 13368 | uiout->field_string ("fullname", fullname); |
| 13369 | } |
| 13370 | |
| 13371 | uiout->field_signed ("line", sal2.line); |
| 13372 | uiout->text ("\n"); |
| 13373 | |
| 13374 | b->loc->line_number = sal2.line; |
| 13375 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
| 13376 | |
| 13377 | b->location.reset (NULL); |
| 13378 | initialize_explicit_location (&explicit_loc); |
| 13379 | explicit_loc.source_filename |
| 13380 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
| 13381 | explicit_loc.line_offset.offset = b->loc->line_number; |
| 13382 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; |
| 13383 | b->location = new_explicit_location (&explicit_loc); |
| 13384 | |
| 13385 | /* Might be nice to check if function changed, and warn if |
| 13386 | so. */ |
| 13387 | } |
| 13388 | } |
| 13389 | return sal; |
| 13390 | } |
| 13391 | |
| 13392 | /* Returns 1 iff locations A and B are sufficiently same that |
| 13393 | we don't need to report breakpoint as changed. */ |
| 13394 | |
| 13395 | static int |
| 13396 | locations_are_equal (struct bp_location *a, struct bp_location *b) |
| 13397 | { |
| 13398 | while (a && b) |
| 13399 | { |
| 13400 | if (a->address != b->address) |
| 13401 | return 0; |
| 13402 | |
| 13403 | if (a->shlib_disabled != b->shlib_disabled) |
| 13404 | return 0; |
| 13405 | |
| 13406 | if (a->enabled != b->enabled) |
| 13407 | return 0; |
| 13408 | |
| 13409 | a = a->next; |
| 13410 | b = b->next; |
| 13411 | } |
| 13412 | |
| 13413 | if ((a == NULL) != (b == NULL)) |
| 13414 | return 0; |
| 13415 | |
| 13416 | return 1; |
| 13417 | } |
| 13418 | |
| 13419 | /* Split all locations of B that are bound to PSPACE out of B's |
| 13420 | location list to a separate list and return that list's head. If |
| 13421 | PSPACE is NULL, hoist out all locations of B. */ |
| 13422 | |
| 13423 | static struct bp_location * |
| 13424 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) |
| 13425 | { |
| 13426 | struct bp_location head; |
| 13427 | struct bp_location *i = b->loc; |
| 13428 | struct bp_location **i_link = &b->loc; |
| 13429 | struct bp_location *hoisted = &head; |
| 13430 | |
| 13431 | if (pspace == NULL) |
| 13432 | { |
| 13433 | i = b->loc; |
| 13434 | b->loc = NULL; |
| 13435 | return i; |
| 13436 | } |
| 13437 | |
| 13438 | head.next = NULL; |
| 13439 | |
| 13440 | while (i != NULL) |
| 13441 | { |
| 13442 | if (i->pspace == pspace) |
| 13443 | { |
| 13444 | *i_link = i->next; |
| 13445 | i->next = NULL; |
| 13446 | hoisted->next = i; |
| 13447 | hoisted = i; |
| 13448 | } |
| 13449 | else |
| 13450 | i_link = &i->next; |
| 13451 | i = *i_link; |
| 13452 | } |
| 13453 | |
| 13454 | return head.next; |
| 13455 | } |
| 13456 | |
| 13457 | /* Create new breakpoint locations for B (a hardware or software |
| 13458 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not |
| 13459 | zero, then B is a ranged breakpoint. Only recreates locations for |
| 13460 | FILTER_PSPACE. Locations of other program spaces are left |
| 13461 | untouched. */ |
| 13462 | |
| 13463 | void |
| 13464 | update_breakpoint_locations (struct breakpoint *b, |
| 13465 | struct program_space *filter_pspace, |
| 13466 | gdb::array_view<const symtab_and_line> sals, |
| 13467 | gdb::array_view<const symtab_and_line> sals_end) |
| 13468 | { |
| 13469 | struct bp_location *existing_locations; |
| 13470 | |
| 13471 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
| 13472 | { |
| 13473 | /* Ranged breakpoints have only one start location and one end |
| 13474 | location. */ |
| 13475 | b->enable_state = bp_disabled; |
| 13476 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
| 13477 | "multiple locations found\n"), |
| 13478 | b->number); |
| 13479 | return; |
| 13480 | } |
| 13481 | |
| 13482 | /* If there's no new locations, and all existing locations are |
| 13483 | pending, don't do anything. This optimizes the common case where |
| 13484 | all locations are in the same shared library, that was unloaded. |
| 13485 | We'd like to retain the location, so that when the library is |
| 13486 | loaded again, we don't loose the enabled/disabled status of the |
| 13487 | individual locations. */ |
| 13488 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
| 13489 | return; |
| 13490 | |
| 13491 | existing_locations = hoist_existing_locations (b, filter_pspace); |
| 13492 | |
| 13493 | for (const auto &sal : sals) |
| 13494 | { |
| 13495 | struct bp_location *new_loc; |
| 13496 | |
| 13497 | switch_to_program_space_and_thread (sal.pspace); |
| 13498 | |
| 13499 | new_loc = add_location_to_breakpoint (b, &sal); |
| 13500 | |
| 13501 | /* Reparse conditions, they might contain references to the |
| 13502 | old symtab. */ |
| 13503 | if (b->cond_string != NULL) |
| 13504 | { |
| 13505 | const char *s; |
| 13506 | |
| 13507 | s = b->cond_string; |
| 13508 | try |
| 13509 | { |
| 13510 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
| 13511 | block_for_pc (sal.pc), |
| 13512 | 0); |
| 13513 | } |
| 13514 | catch (const gdb_exception_error &e) |
| 13515 | { |
| 13516 | warning (_("failed to reevaluate condition " |
| 13517 | "for breakpoint %d: %s"), |
| 13518 | b->number, e.what ()); |
| 13519 | new_loc->enabled = 0; |
| 13520 | } |
| 13521 | } |
| 13522 | |
| 13523 | if (!sals_end.empty ()) |
| 13524 | { |
| 13525 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
| 13526 | |
| 13527 | new_loc->length = end - sals[0].pc + 1; |
| 13528 | } |
| 13529 | } |
| 13530 | |
| 13531 | /* If possible, carry over 'disable' status from existing |
| 13532 | breakpoints. */ |
| 13533 | { |
| 13534 | struct bp_location *e = existing_locations; |
| 13535 | /* If there are multiple breakpoints with the same function name, |
| 13536 | e.g. for inline functions, comparing function names won't work. |
| 13537 | Instead compare pc addresses; this is just a heuristic as things |
| 13538 | may have moved, but in practice it gives the correct answer |
| 13539 | often enough until a better solution is found. */ |
| 13540 | int have_ambiguous_names = ambiguous_names_p (b->loc); |
| 13541 | |
| 13542 | for (; e; e = e->next) |
| 13543 | { |
| 13544 | if (!e->enabled && e->function_name) |
| 13545 | { |
| 13546 | struct bp_location *l = b->loc; |
| 13547 | if (have_ambiguous_names) |
| 13548 | { |
| 13549 | for (; l; l = l->next) |
| 13550 | if (breakpoint_locations_match (e, l)) |
| 13551 | { |
| 13552 | l->enabled = 0; |
| 13553 | break; |
| 13554 | } |
| 13555 | } |
| 13556 | else |
| 13557 | { |
| 13558 | for (; l; l = l->next) |
| 13559 | if (l->function_name |
| 13560 | && strcmp (e->function_name, l->function_name) == 0) |
| 13561 | { |
| 13562 | l->enabled = 0; |
| 13563 | break; |
| 13564 | } |
| 13565 | } |
| 13566 | } |
| 13567 | } |
| 13568 | } |
| 13569 | |
| 13570 | if (!locations_are_equal (existing_locations, b->loc)) |
| 13571 | gdb::observers::breakpoint_modified.notify (b); |
| 13572 | } |
| 13573 | |
| 13574 | /* Find the SaL locations corresponding to the given LOCATION. |
| 13575 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
| 13576 | |
| 13577 | static std::vector<symtab_and_line> |
| 13578 | location_to_sals (struct breakpoint *b, struct event_location *location, |
| 13579 | struct program_space *search_pspace, int *found) |
| 13580 | { |
| 13581 | struct gdb_exception exception; |
| 13582 | |
| 13583 | gdb_assert (b->ops != NULL); |
| 13584 | |
| 13585 | std::vector<symtab_and_line> sals; |
| 13586 | |
| 13587 | try |
| 13588 | { |
| 13589 | sals = b->ops->decode_location (b, location, search_pspace); |
| 13590 | } |
| 13591 | catch (gdb_exception_error &e) |
| 13592 | { |
| 13593 | int not_found_and_ok = 0; |
| 13594 | |
| 13595 | /* For pending breakpoints, it's expected that parsing will |
| 13596 | fail until the right shared library is loaded. User has |
| 13597 | already told to create pending breakpoints and don't need |
| 13598 | extra messages. If breakpoint is in bp_shlib_disabled |
| 13599 | state, then user already saw the message about that |
| 13600 | breakpoint being disabled, and don't want to see more |
| 13601 | errors. */ |
| 13602 | if (e.error == NOT_FOUND_ERROR |
| 13603 | && (b->condition_not_parsed |
| 13604 | || (b->loc != NULL |
| 13605 | && search_pspace != NULL |
| 13606 | && b->loc->pspace != search_pspace) |
| 13607 | || (b->loc && b->loc->shlib_disabled) |
| 13608 | || (b->loc && b->loc->pspace->executing_startup) |
| 13609 | || b->enable_state == bp_disabled)) |
| 13610 | not_found_and_ok = 1; |
| 13611 | |
| 13612 | if (!not_found_and_ok) |
| 13613 | { |
| 13614 | /* We surely don't want to warn about the same breakpoint |
| 13615 | 10 times. One solution, implemented here, is disable |
| 13616 | the breakpoint on error. Another solution would be to |
| 13617 | have separate 'warning emitted' flag. Since this |
| 13618 | happens only when a binary has changed, I don't know |
| 13619 | which approach is better. */ |
| 13620 | b->enable_state = bp_disabled; |
| 13621 | throw; |
| 13622 | } |
| 13623 | |
| 13624 | exception = std::move (e); |
| 13625 | } |
| 13626 | |
| 13627 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
| 13628 | { |
| 13629 | for (auto &sal : sals) |
| 13630 | resolve_sal_pc (&sal); |
| 13631 | if (b->condition_not_parsed && b->extra_string != NULL) |
| 13632 | { |
| 13633 | char *cond_string, *extra_string; |
| 13634 | int thread, task; |
| 13635 | |
| 13636 | find_condition_and_thread (b->extra_string, sals[0].pc, |
| 13637 | &cond_string, &thread, &task, |
| 13638 | &extra_string); |
| 13639 | gdb_assert (b->cond_string == NULL); |
| 13640 | if (cond_string) |
| 13641 | b->cond_string = cond_string; |
| 13642 | b->thread = thread; |
| 13643 | b->task = task; |
| 13644 | if (extra_string) |
| 13645 | { |
| 13646 | xfree (b->extra_string); |
| 13647 | b->extra_string = extra_string; |
| 13648 | } |
| 13649 | b->condition_not_parsed = 0; |
| 13650 | } |
| 13651 | |
| 13652 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
| 13653 | sals[0] = update_static_tracepoint (b, sals[0]); |
| 13654 | |
| 13655 | *found = 1; |
| 13656 | } |
| 13657 | else |
| 13658 | *found = 0; |
| 13659 | |
| 13660 | return sals; |
| 13661 | } |
| 13662 | |
| 13663 | /* The default re_set method, for typical hardware or software |
| 13664 | breakpoints. Reevaluate the breakpoint and recreate its |
| 13665 | locations. */ |
| 13666 | |
| 13667 | static void |
| 13668 | breakpoint_re_set_default (struct breakpoint *b) |
| 13669 | { |
| 13670 | struct program_space *filter_pspace = current_program_space; |
| 13671 | std::vector<symtab_and_line> expanded, expanded_end; |
| 13672 | |
| 13673 | int found; |
| 13674 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), |
| 13675 | filter_pspace, &found); |
| 13676 | if (found) |
| 13677 | expanded = std::move (sals); |
| 13678 | |
| 13679 | if (b->location_range_end != NULL) |
| 13680 | { |
| 13681 | std::vector<symtab_and_line> sals_end |
| 13682 | = location_to_sals (b, b->location_range_end.get (), |
| 13683 | filter_pspace, &found); |
| 13684 | if (found) |
| 13685 | expanded_end = std::move (sals_end); |
| 13686 | } |
| 13687 | |
| 13688 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
| 13689 | } |
| 13690 | |
| 13691 | /* Default method for creating SALs from an address string. It basically |
| 13692 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ |
| 13693 | |
| 13694 | static void |
| 13695 | create_sals_from_location_default (const struct event_location *location, |
| 13696 | struct linespec_result *canonical, |
| 13697 | enum bptype type_wanted) |
| 13698 | { |
| 13699 | parse_breakpoint_sals (location, canonical); |
| 13700 | } |
| 13701 | |
| 13702 | /* Call create_breakpoints_sal for the given arguments. This is the default |
| 13703 | function for the `create_breakpoints_sal' method of |
| 13704 | breakpoint_ops. */ |
| 13705 | |
| 13706 | static void |
| 13707 | create_breakpoints_sal_default (struct gdbarch *gdbarch, |
| 13708 | struct linespec_result *canonical, |
| 13709 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 13710 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 13711 | enum bptype type_wanted, |
| 13712 | enum bpdisp disposition, |
| 13713 | int thread, |
| 13714 | int task, int ignore_count, |
| 13715 | const struct breakpoint_ops *ops, |
| 13716 | int from_tty, int enabled, |
| 13717 | int internal, unsigned flags) |
| 13718 | { |
| 13719 | create_breakpoints_sal (gdbarch, canonical, |
| 13720 | std::move (cond_string), |
| 13721 | std::move (extra_string), |
| 13722 | type_wanted, disposition, |
| 13723 | thread, task, ignore_count, ops, from_tty, |
| 13724 | enabled, internal, flags); |
| 13725 | } |
| 13726 | |
| 13727 | /* Decode the line represented by S by calling decode_line_full. This is the |
| 13728 | default function for the `decode_location' method of breakpoint_ops. */ |
| 13729 | |
| 13730 | static std::vector<symtab_and_line> |
| 13731 | decode_location_default (struct breakpoint *b, |
| 13732 | const struct event_location *location, |
| 13733 | struct program_space *search_pspace) |
| 13734 | { |
| 13735 | struct linespec_result canonical; |
| 13736 | |
| 13737 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
| 13738 | NULL, 0, &canonical, multiple_symbols_all, |
| 13739 | b->filter.get ()); |
| 13740 | |
| 13741 | /* We should get 0 or 1 resulting SALs. */ |
| 13742 | gdb_assert (canonical.lsals.size () < 2); |
| 13743 | |
| 13744 | if (!canonical.lsals.empty ()) |
| 13745 | { |
| 13746 | const linespec_sals &lsal = canonical.lsals[0]; |
| 13747 | return std::move (lsal.sals); |
| 13748 | } |
| 13749 | return {}; |
| 13750 | } |
| 13751 | |
| 13752 | /* Reset a breakpoint. */ |
| 13753 | |
| 13754 | static void |
| 13755 | breakpoint_re_set_one (breakpoint *b) |
| 13756 | { |
| 13757 | input_radix = b->input_radix; |
| 13758 | set_language (b->language); |
| 13759 | |
| 13760 | b->ops->re_set (b); |
| 13761 | } |
| 13762 | |
| 13763 | /* Re-set breakpoint locations for the current program space. |
| 13764 | Locations bound to other program spaces are left untouched. */ |
| 13765 | |
| 13766 | void |
| 13767 | breakpoint_re_set (void) |
| 13768 | { |
| 13769 | struct breakpoint *b, *b_tmp; |
| 13770 | |
| 13771 | { |
| 13772 | scoped_restore_current_language save_language; |
| 13773 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); |
| 13774 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 13775 | |
| 13776 | /* breakpoint_re_set_one sets the current_language to the language |
| 13777 | of the breakpoint it is resetting (see prepare_re_set_context) |
| 13778 | before re-evaluating the breakpoint's location. This change can |
| 13779 | unfortunately get undone by accident if the language_mode is set |
| 13780 | to auto, and we either switch frames, or more likely in this context, |
| 13781 | we select the current frame. |
| 13782 | |
| 13783 | We prevent this by temporarily turning the language_mode to |
| 13784 | language_mode_manual. We restore it once all breakpoints |
| 13785 | have been reset. */ |
| 13786 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); |
| 13787 | language_mode = language_mode_manual; |
| 13788 | |
| 13789 | /* Note: we must not try to insert locations until after all |
| 13790 | breakpoints have been re-set. Otherwise, e.g., when re-setting |
| 13791 | breakpoint 1, we'd insert the locations of breakpoint 2, which |
| 13792 | hadn't been re-set yet, and thus may have stale locations. */ |
| 13793 | |
| 13794 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 13795 | { |
| 13796 | try |
| 13797 | { |
| 13798 | breakpoint_re_set_one (b); |
| 13799 | } |
| 13800 | catch (const gdb_exception &ex) |
| 13801 | { |
| 13802 | exception_fprintf (gdb_stderr, ex, |
| 13803 | "Error in re-setting breakpoint %d: ", |
| 13804 | b->number); |
| 13805 | } |
| 13806 | } |
| 13807 | |
| 13808 | jit_breakpoint_re_set (); |
| 13809 | } |
| 13810 | |
| 13811 | create_overlay_event_breakpoint (); |
| 13812 | create_longjmp_master_breakpoint (); |
| 13813 | create_std_terminate_master_breakpoint (); |
| 13814 | create_exception_master_breakpoint (); |
| 13815 | |
| 13816 | /* Now we can insert. */ |
| 13817 | update_global_location_list (UGLL_MAY_INSERT); |
| 13818 | } |
| 13819 | \f |
| 13820 | /* Reset the thread number of this breakpoint: |
| 13821 | |
| 13822 | - If the breakpoint is for all threads, leave it as-is. |
| 13823 | - Else, reset it to the current thread for inferior_ptid. */ |
| 13824 | void |
| 13825 | breakpoint_re_set_thread (struct breakpoint *b) |
| 13826 | { |
| 13827 | if (b->thread != -1) |
| 13828 | { |
| 13829 | b->thread = inferior_thread ()->global_num; |
| 13830 | |
| 13831 | /* We're being called after following a fork. The new fork is |
| 13832 | selected as current, and unless this was a vfork will have a |
| 13833 | different program space from the original thread. Reset that |
| 13834 | as well. */ |
| 13835 | b->loc->pspace = current_program_space; |
| 13836 | } |
| 13837 | } |
| 13838 | |
| 13839 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 13840 | If from_tty is nonzero, it prints a message to that effect, |
| 13841 | which ends with a period (no newline). */ |
| 13842 | |
| 13843 | void |
| 13844 | set_ignore_count (int bptnum, int count, int from_tty) |
| 13845 | { |
| 13846 | struct breakpoint *b; |
| 13847 | |
| 13848 | if (count < 0) |
| 13849 | count = 0; |
| 13850 | |
| 13851 | ALL_BREAKPOINTS (b) |
| 13852 | if (b->number == bptnum) |
| 13853 | { |
| 13854 | if (is_tracepoint (b)) |
| 13855 | { |
| 13856 | if (from_tty && count != 0) |
| 13857 | printf_filtered (_("Ignore count ignored for tracepoint %d."), |
| 13858 | bptnum); |
| 13859 | return; |
| 13860 | } |
| 13861 | |
| 13862 | b->ignore_count = count; |
| 13863 | if (from_tty) |
| 13864 | { |
| 13865 | if (count == 0) |
| 13866 | printf_filtered (_("Will stop next time " |
| 13867 | "breakpoint %d is reached."), |
| 13868 | bptnum); |
| 13869 | else if (count == 1) |
| 13870 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
| 13871 | bptnum); |
| 13872 | else |
| 13873 | printf_filtered (_("Will ignore next %d " |
| 13874 | "crossings of breakpoint %d."), |
| 13875 | count, bptnum); |
| 13876 | } |
| 13877 | gdb::observers::breakpoint_modified.notify (b); |
| 13878 | return; |
| 13879 | } |
| 13880 | |
| 13881 | error (_("No breakpoint number %d."), bptnum); |
| 13882 | } |
| 13883 | |
| 13884 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
| 13885 | |
| 13886 | static void |
| 13887 | ignore_command (const char *args, int from_tty) |
| 13888 | { |
| 13889 | const char *p = args; |
| 13890 | int num; |
| 13891 | |
| 13892 | if (p == 0) |
| 13893 | error_no_arg (_("a breakpoint number")); |
| 13894 | |
| 13895 | num = get_number (&p); |
| 13896 | if (num == 0) |
| 13897 | error (_("bad breakpoint number: '%s'"), args); |
| 13898 | if (*p == 0) |
| 13899 | error (_("Second argument (specified ignore-count) is missing.")); |
| 13900 | |
| 13901 | set_ignore_count (num, |
| 13902 | longest_to_int (value_as_long (parse_and_eval (p))), |
| 13903 | from_tty); |
| 13904 | if (from_tty) |
| 13905 | printf_filtered ("\n"); |
| 13906 | } |
| 13907 | \f |
| 13908 | |
| 13909 | /* Call FUNCTION on each of the breakpoints with numbers in the range |
| 13910 | defined by BP_NUM_RANGE (an inclusive range). */ |
| 13911 | |
| 13912 | static void |
| 13913 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
| 13914 | gdb::function_view<void (breakpoint *)> function) |
| 13915 | { |
| 13916 | if (bp_num_range.first == 0) |
| 13917 | { |
| 13918 | warning (_("bad breakpoint number at or near '%d'"), |
| 13919 | bp_num_range.first); |
| 13920 | } |
| 13921 | else |
| 13922 | { |
| 13923 | struct breakpoint *b, *tmp; |
| 13924 | |
| 13925 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
| 13926 | { |
| 13927 | bool match = false; |
| 13928 | |
| 13929 | ALL_BREAKPOINTS_SAFE (b, tmp) |
| 13930 | if (b->number == i) |
| 13931 | { |
| 13932 | match = true; |
| 13933 | function (b); |
| 13934 | break; |
| 13935 | } |
| 13936 | if (!match) |
| 13937 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
| 13938 | } |
| 13939 | } |
| 13940 | } |
| 13941 | |
| 13942 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
| 13943 | ARGS. */ |
| 13944 | |
| 13945 | static void |
| 13946 | map_breakpoint_numbers (const char *args, |
| 13947 | gdb::function_view<void (breakpoint *)> function) |
| 13948 | { |
| 13949 | if (args == NULL || *args == '\0') |
| 13950 | error_no_arg (_("one or more breakpoint numbers")); |
| 13951 | |
| 13952 | number_or_range_parser parser (args); |
| 13953 | |
| 13954 | while (!parser.finished ()) |
| 13955 | { |
| 13956 | int num = parser.get_number (); |
| 13957 | map_breakpoint_number_range (std::make_pair (num, num), function); |
| 13958 | } |
| 13959 | } |
| 13960 | |
| 13961 | /* Return the breakpoint location structure corresponding to the |
| 13962 | BP_NUM and LOC_NUM values. */ |
| 13963 | |
| 13964 | static struct bp_location * |
| 13965 | find_location_by_number (int bp_num, int loc_num) |
| 13966 | { |
| 13967 | struct breakpoint *b; |
| 13968 | |
| 13969 | ALL_BREAKPOINTS (b) |
| 13970 | if (b->number == bp_num) |
| 13971 | { |
| 13972 | break; |
| 13973 | } |
| 13974 | |
| 13975 | if (!b || b->number != bp_num) |
| 13976 | error (_("Bad breakpoint number '%d'"), bp_num); |
| 13977 | |
| 13978 | if (loc_num == 0) |
| 13979 | error (_("Bad breakpoint location number '%d'"), loc_num); |
| 13980 | |
| 13981 | int n = 0; |
| 13982 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) |
| 13983 | if (++n == loc_num) |
| 13984 | return loc; |
| 13985 | |
| 13986 | error (_("Bad breakpoint location number '%d'"), loc_num); |
| 13987 | } |
| 13988 | |
| 13989 | /* Modes of operation for extract_bp_num. */ |
| 13990 | enum class extract_bp_kind |
| 13991 | { |
| 13992 | /* Extracting a breakpoint number. */ |
| 13993 | bp, |
| 13994 | |
| 13995 | /* Extracting a location number. */ |
| 13996 | loc, |
| 13997 | }; |
| 13998 | |
| 13999 | /* Extract a breakpoint or location number (as determined by KIND) |
| 14000 | from the string starting at START. TRAILER is a character which |
| 14001 | can be found after the number. If you don't want a trailer, use |
| 14002 | '\0'. If END_OUT is not NULL, it is set to point after the parsed |
| 14003 | string. This always returns a positive integer. */ |
| 14004 | |
| 14005 | static int |
| 14006 | extract_bp_num (extract_bp_kind kind, const char *start, |
| 14007 | int trailer, const char **end_out = NULL) |
| 14008 | { |
| 14009 | const char *end = start; |
| 14010 | int num = get_number_trailer (&end, trailer); |
| 14011 | if (num < 0) |
| 14012 | error (kind == extract_bp_kind::bp |
| 14013 | ? _("Negative breakpoint number '%.*s'") |
| 14014 | : _("Negative breakpoint location number '%.*s'"), |
| 14015 | int (end - start), start); |
| 14016 | if (num == 0) |
| 14017 | error (kind == extract_bp_kind::bp |
| 14018 | ? _("Bad breakpoint number '%.*s'") |
| 14019 | : _("Bad breakpoint location number '%.*s'"), |
| 14020 | int (end - start), start); |
| 14021 | |
| 14022 | if (end_out != NULL) |
| 14023 | *end_out = end; |
| 14024 | return num; |
| 14025 | } |
| 14026 | |
| 14027 | /* Extract a breakpoint or location range (as determined by KIND) in |
| 14028 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair |
| 14029 | representing the (inclusive) range. The returned pair's elements |
| 14030 | are always positive integers. */ |
| 14031 | |
| 14032 | static std::pair<int, int> |
| 14033 | extract_bp_or_bp_range (extract_bp_kind kind, |
| 14034 | const std::string &arg, |
| 14035 | std::string::size_type arg_offset) |
| 14036 | { |
| 14037 | std::pair<int, int> range; |
| 14038 | const char *bp_loc = &arg[arg_offset]; |
| 14039 | std::string::size_type dash = arg.find ('-', arg_offset); |
| 14040 | if (dash != std::string::npos) |
| 14041 | { |
| 14042 | /* bp_loc is a range (x-z). */ |
| 14043 | if (arg.length () == dash + 1) |
| 14044 | error (kind == extract_bp_kind::bp |
| 14045 | ? _("Bad breakpoint number at or near: '%s'") |
| 14046 | : _("Bad breakpoint location number at or near: '%s'"), |
| 14047 | bp_loc); |
| 14048 | |
| 14049 | const char *end; |
| 14050 | const char *start_first = bp_loc; |
| 14051 | const char *start_second = &arg[dash + 1]; |
| 14052 | range.first = extract_bp_num (kind, start_first, '-'); |
| 14053 | range.second = extract_bp_num (kind, start_second, '\0', &end); |
| 14054 | |
| 14055 | if (range.first > range.second) |
| 14056 | error (kind == extract_bp_kind::bp |
| 14057 | ? _("Inverted breakpoint range at '%.*s'") |
| 14058 | : _("Inverted breakpoint location range at '%.*s'"), |
| 14059 | int (end - start_first), start_first); |
| 14060 | } |
| 14061 | else |
| 14062 | { |
| 14063 | /* bp_loc is a single value. */ |
| 14064 | range.first = extract_bp_num (kind, bp_loc, '\0'); |
| 14065 | range.second = range.first; |
| 14066 | } |
| 14067 | return range; |
| 14068 | } |
| 14069 | |
| 14070 | /* Extract the breakpoint/location range specified by ARG. Returns |
| 14071 | the breakpoint range in BP_NUM_RANGE, and the location range in |
| 14072 | BP_LOC_RANGE. |
| 14073 | |
| 14074 | ARG may be in any of the following forms: |
| 14075 | |
| 14076 | x where 'x' is a breakpoint number. |
| 14077 | x-y where 'x' and 'y' specify a breakpoint numbers range. |
| 14078 | x.y where 'x' is a breakpoint number and 'y' a location number. |
| 14079 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a |
| 14080 | location number range. |
| 14081 | */ |
| 14082 | |
| 14083 | static void |
| 14084 | extract_bp_number_and_location (const std::string &arg, |
| 14085 | std::pair<int, int> &bp_num_range, |
| 14086 | std::pair<int, int> &bp_loc_range) |
| 14087 | { |
| 14088 | std::string::size_type dot = arg.find ('.'); |
| 14089 | |
| 14090 | if (dot != std::string::npos) |
| 14091 | { |
| 14092 | /* Handle 'x.y' and 'x.y-z' cases. */ |
| 14093 | |
| 14094 | if (arg.length () == dot + 1 || dot == 0) |
| 14095 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
| 14096 | |
| 14097 | bp_num_range.first |
| 14098 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); |
| 14099 | bp_num_range.second = bp_num_range.first; |
| 14100 | |
| 14101 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
| 14102 | arg, dot + 1); |
| 14103 | } |
| 14104 | else |
| 14105 | { |
| 14106 | /* Handle x and x-y cases. */ |
| 14107 | |
| 14108 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
| 14109 | bp_loc_range.first = 0; |
| 14110 | bp_loc_range.second = 0; |
| 14111 | } |
| 14112 | } |
| 14113 | |
| 14114 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE |
| 14115 | specifies whether to enable or disable. */ |
| 14116 | |
| 14117 | static void |
| 14118 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) |
| 14119 | { |
| 14120 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); |
| 14121 | if (loc != NULL) |
| 14122 | { |
| 14123 | if (loc->enabled != enable) |
| 14124 | { |
| 14125 | loc->enabled = enable; |
| 14126 | mark_breakpoint_location_modified (loc); |
| 14127 | } |
| 14128 | if (target_supports_enable_disable_tracepoint () |
| 14129 | && current_trace_status ()->running && loc->owner |
| 14130 | && is_tracepoint (loc->owner)) |
| 14131 | target_disable_tracepoint (loc); |
| 14132 | } |
| 14133 | update_global_location_list (UGLL_DONT_INSERT); |
| 14134 | |
| 14135 | gdb::observers::breakpoint_modified.notify (loc->owner); |
| 14136 | } |
| 14137 | |
| 14138 | /* Enable or disable a range of breakpoint locations. BP_NUM is the |
| 14139 | number of the breakpoint, and BP_LOC_RANGE specifies the |
| 14140 | (inclusive) range of location numbers of that breakpoint to |
| 14141 | enable/disable. ENABLE specifies whether to enable or disable the |
| 14142 | location. */ |
| 14143 | |
| 14144 | static void |
| 14145 | enable_disable_breakpoint_location_range (int bp_num, |
| 14146 | std::pair<int, int> &bp_loc_range, |
| 14147 | bool enable) |
| 14148 | { |
| 14149 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) |
| 14150 | enable_disable_bp_num_loc (bp_num, i, enable); |
| 14151 | } |
| 14152 | |
| 14153 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 14154 | If from_tty is nonzero, it prints a message to that effect, |
| 14155 | which ends with a period (no newline). */ |
| 14156 | |
| 14157 | void |
| 14158 | disable_breakpoint (struct breakpoint *bpt) |
| 14159 | { |
| 14160 | /* Never disable a watchpoint scope breakpoint; we want to |
| 14161 | hit them when we leave scope so we can delete both the |
| 14162 | watchpoint and its scope breakpoint at that time. */ |
| 14163 | if (bpt->type == bp_watchpoint_scope) |
| 14164 | return; |
| 14165 | |
| 14166 | bpt->enable_state = bp_disabled; |
| 14167 | |
| 14168 | /* Mark breakpoint locations modified. */ |
| 14169 | mark_breakpoint_modified (bpt); |
| 14170 | |
| 14171 | if (target_supports_enable_disable_tracepoint () |
| 14172 | && current_trace_status ()->running && is_tracepoint (bpt)) |
| 14173 | { |
| 14174 | struct bp_location *location; |
| 14175 | |
| 14176 | for (location = bpt->loc; location; location = location->next) |
| 14177 | target_disable_tracepoint (location); |
| 14178 | } |
| 14179 | |
| 14180 | update_global_location_list (UGLL_DONT_INSERT); |
| 14181 | |
| 14182 | gdb::observers::breakpoint_modified.notify (bpt); |
| 14183 | } |
| 14184 | |
| 14185 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
| 14186 | specified in ARGS. ARGS may be in any of the formats handled by |
| 14187 | extract_bp_number_and_location. ENABLE specifies whether to enable |
| 14188 | or disable the breakpoints/locations. */ |
| 14189 | |
| 14190 | static void |
| 14191 | enable_disable_command (const char *args, int from_tty, bool enable) |
| 14192 | { |
| 14193 | if (args == 0) |
| 14194 | { |
| 14195 | struct breakpoint *bpt; |
| 14196 | |
| 14197 | ALL_BREAKPOINTS (bpt) |
| 14198 | if (user_breakpoint_p (bpt)) |
| 14199 | { |
| 14200 | if (enable) |
| 14201 | enable_breakpoint (bpt); |
| 14202 | else |
| 14203 | disable_breakpoint (bpt); |
| 14204 | } |
| 14205 | } |
| 14206 | else |
| 14207 | { |
| 14208 | std::string num = extract_arg (&args); |
| 14209 | |
| 14210 | while (!num.empty ()) |
| 14211 | { |
| 14212 | std::pair<int, int> bp_num_range, bp_loc_range; |
| 14213 | |
| 14214 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
| 14215 | |
| 14216 | if (bp_loc_range.first == bp_loc_range.second |
| 14217 | && bp_loc_range.first == 0) |
| 14218 | { |
| 14219 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
| 14220 | map_breakpoint_number_range (bp_num_range, |
| 14221 | enable |
| 14222 | ? enable_breakpoint |
| 14223 | : disable_breakpoint); |
| 14224 | } |
| 14225 | else |
| 14226 | { |
| 14227 | /* Handle breakpoint ids with formats 'x.y' or |
| 14228 | 'x.y-z'. */ |
| 14229 | enable_disable_breakpoint_location_range |
| 14230 | (bp_num_range.first, bp_loc_range, enable); |
| 14231 | } |
| 14232 | num = extract_arg (&args); |
| 14233 | } |
| 14234 | } |
| 14235 | } |
| 14236 | |
| 14237 | /* The disable command disables the specified breakpoints/locations |
| 14238 | (or all defined breakpoints) so they're no longer effective in |
| 14239 | stopping the inferior. ARGS may be in any of the forms defined in |
| 14240 | extract_bp_number_and_location. */ |
| 14241 | |
| 14242 | static void |
| 14243 | disable_command (const char *args, int from_tty) |
| 14244 | { |
| 14245 | enable_disable_command (args, from_tty, false); |
| 14246 | } |
| 14247 | |
| 14248 | static void |
| 14249 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
| 14250 | int count) |
| 14251 | { |
| 14252 | int target_resources_ok; |
| 14253 | |
| 14254 | if (bpt->type == bp_hardware_breakpoint) |
| 14255 | { |
| 14256 | int i; |
| 14257 | i = hw_breakpoint_used_count (); |
| 14258 | target_resources_ok = |
| 14259 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 14260 | i + 1, 0); |
| 14261 | if (target_resources_ok == 0) |
| 14262 | error (_("No hardware breakpoint support in the target.")); |
| 14263 | else if (target_resources_ok < 0) |
| 14264 | error (_("Hardware breakpoints used exceeds limit.")); |
| 14265 | } |
| 14266 | |
| 14267 | if (is_watchpoint (bpt)) |
| 14268 | { |
| 14269 | /* Initialize it just to avoid a GCC false warning. */ |
| 14270 | enum enable_state orig_enable_state = bp_disabled; |
| 14271 | |
| 14272 | try |
| 14273 | { |
| 14274 | struct watchpoint *w = (struct watchpoint *) bpt; |
| 14275 | |
| 14276 | orig_enable_state = bpt->enable_state; |
| 14277 | bpt->enable_state = bp_enabled; |
| 14278 | update_watchpoint (w, 1 /* reparse */); |
| 14279 | } |
| 14280 | catch (const gdb_exception &e) |
| 14281 | { |
| 14282 | bpt->enable_state = orig_enable_state; |
| 14283 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
| 14284 | bpt->number); |
| 14285 | return; |
| 14286 | } |
| 14287 | } |
| 14288 | |
| 14289 | bpt->enable_state = bp_enabled; |
| 14290 | |
| 14291 | /* Mark breakpoint locations modified. */ |
| 14292 | mark_breakpoint_modified (bpt); |
| 14293 | |
| 14294 | if (target_supports_enable_disable_tracepoint () |
| 14295 | && current_trace_status ()->running && is_tracepoint (bpt)) |
| 14296 | { |
| 14297 | struct bp_location *location; |
| 14298 | |
| 14299 | for (location = bpt->loc; location; location = location->next) |
| 14300 | target_enable_tracepoint (location); |
| 14301 | } |
| 14302 | |
| 14303 | bpt->disposition = disposition; |
| 14304 | bpt->enable_count = count; |
| 14305 | update_global_location_list (UGLL_MAY_INSERT); |
| 14306 | |
| 14307 | gdb::observers::breakpoint_modified.notify (bpt); |
| 14308 | } |
| 14309 | |
| 14310 | |
| 14311 | void |
| 14312 | enable_breakpoint (struct breakpoint *bpt) |
| 14313 | { |
| 14314 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
| 14315 | } |
| 14316 | |
| 14317 | /* The enable command enables the specified breakpoints/locations (or |
| 14318 | all defined breakpoints) so they once again become (or continue to |
| 14319 | be) effective in stopping the inferior. ARGS may be in any of the |
| 14320 | forms defined in extract_bp_number_and_location. */ |
| 14321 | |
| 14322 | static void |
| 14323 | enable_command (const char *args, int from_tty) |
| 14324 | { |
| 14325 | enable_disable_command (args, from_tty, true); |
| 14326 | } |
| 14327 | |
| 14328 | static void |
| 14329 | enable_once_command (const char *args, int from_tty) |
| 14330 | { |
| 14331 | map_breakpoint_numbers |
| 14332 | (args, [&] (breakpoint *b) |
| 14333 | { |
| 14334 | iterate_over_related_breakpoints |
| 14335 | (b, [&] (breakpoint *bpt) |
| 14336 | { |
| 14337 | enable_breakpoint_disp (bpt, disp_disable, 1); |
| 14338 | }); |
| 14339 | }); |
| 14340 | } |
| 14341 | |
| 14342 | static void |
| 14343 | enable_count_command (const char *args, int from_tty) |
| 14344 | { |
| 14345 | int count; |
| 14346 | |
| 14347 | if (args == NULL) |
| 14348 | error_no_arg (_("hit count")); |
| 14349 | |
| 14350 | count = get_number (&args); |
| 14351 | |
| 14352 | map_breakpoint_numbers |
| 14353 | (args, [&] (breakpoint *b) |
| 14354 | { |
| 14355 | iterate_over_related_breakpoints |
| 14356 | (b, [&] (breakpoint *bpt) |
| 14357 | { |
| 14358 | enable_breakpoint_disp (bpt, disp_disable, count); |
| 14359 | }); |
| 14360 | }); |
| 14361 | } |
| 14362 | |
| 14363 | static void |
| 14364 | enable_delete_command (const char *args, int from_tty) |
| 14365 | { |
| 14366 | map_breakpoint_numbers |
| 14367 | (args, [&] (breakpoint *b) |
| 14368 | { |
| 14369 | iterate_over_related_breakpoints |
| 14370 | (b, [&] (breakpoint *bpt) |
| 14371 | { |
| 14372 | enable_breakpoint_disp (bpt, disp_del, 1); |
| 14373 | }); |
| 14374 | }); |
| 14375 | } |
| 14376 | \f |
| 14377 | static void |
| 14378 | set_breakpoint_cmd (const char *args, int from_tty) |
| 14379 | { |
| 14380 | } |
| 14381 | |
| 14382 | static void |
| 14383 | show_breakpoint_cmd (const char *args, int from_tty) |
| 14384 | { |
| 14385 | } |
| 14386 | |
| 14387 | /* Invalidate last known value of any hardware watchpoint if |
| 14388 | the memory which that value represents has been written to by |
| 14389 | GDB itself. */ |
| 14390 | |
| 14391 | static void |
| 14392 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
| 14393 | CORE_ADDR addr, ssize_t len, |
| 14394 | const bfd_byte *data) |
| 14395 | { |
| 14396 | struct breakpoint *bp; |
| 14397 | |
| 14398 | ALL_BREAKPOINTS (bp) |
| 14399 | if (bp->enable_state == bp_enabled |
| 14400 | && bp->type == bp_hardware_watchpoint) |
| 14401 | { |
| 14402 | struct watchpoint *wp = (struct watchpoint *) bp; |
| 14403 | |
| 14404 | if (wp->val_valid && wp->val != nullptr) |
| 14405 | { |
| 14406 | struct bp_location *loc; |
| 14407 | |
| 14408 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
| 14409 | if (loc->loc_type == bp_loc_hardware_watchpoint |
| 14410 | && loc->address + loc->length > addr |
| 14411 | && addr + len > loc->address) |
| 14412 | { |
| 14413 | wp->val = NULL; |
| 14414 | wp->val_valid = false; |
| 14415 | } |
| 14416 | } |
| 14417 | } |
| 14418 | } |
| 14419 | |
| 14420 | /* Create and insert a breakpoint for software single step. */ |
| 14421 | |
| 14422 | void |
| 14423 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
| 14424 | const address_space *aspace, |
| 14425 | CORE_ADDR next_pc) |
| 14426 | { |
| 14427 | struct thread_info *tp = inferior_thread (); |
| 14428 | struct symtab_and_line sal; |
| 14429 | CORE_ADDR pc = next_pc; |
| 14430 | |
| 14431 | if (tp->control.single_step_breakpoints == NULL) |
| 14432 | { |
| 14433 | tp->control.single_step_breakpoints |
| 14434 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
| 14435 | } |
| 14436 | |
| 14437 | sal = find_pc_line (pc, 0); |
| 14438 | sal.pc = pc; |
| 14439 | sal.section = find_pc_overlay (pc); |
| 14440 | sal.explicit_pc = 1; |
| 14441 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
| 14442 | |
| 14443 | update_global_location_list (UGLL_INSERT); |
| 14444 | } |
| 14445 | |
| 14446 | /* Insert single step breakpoints according to the current state. */ |
| 14447 | |
| 14448 | int |
| 14449 | insert_single_step_breakpoints (struct gdbarch *gdbarch) |
| 14450 | { |
| 14451 | struct regcache *regcache = get_current_regcache (); |
| 14452 | std::vector<CORE_ADDR> next_pcs; |
| 14453 | |
| 14454 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
| 14455 | |
| 14456 | if (!next_pcs.empty ()) |
| 14457 | { |
| 14458 | struct frame_info *frame = get_current_frame (); |
| 14459 | const address_space *aspace = get_frame_address_space (frame); |
| 14460 | |
| 14461 | for (CORE_ADDR pc : next_pcs) |
| 14462 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
| 14463 | |
| 14464 | return 1; |
| 14465 | } |
| 14466 | else |
| 14467 | return 0; |
| 14468 | } |
| 14469 | |
| 14470 | /* See breakpoint.h. */ |
| 14471 | |
| 14472 | int |
| 14473 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
| 14474 | const address_space *aspace, |
| 14475 | CORE_ADDR pc) |
| 14476 | { |
| 14477 | struct bp_location *loc; |
| 14478 | |
| 14479 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
| 14480 | if (loc->inserted |
| 14481 | && breakpoint_location_address_match (loc, aspace, pc)) |
| 14482 | return 1; |
| 14483 | |
| 14484 | return 0; |
| 14485 | } |
| 14486 | |
| 14487 | /* Check whether a software single-step breakpoint is inserted at |
| 14488 | PC. */ |
| 14489 | |
| 14490 | int |
| 14491 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
| 14492 | CORE_ADDR pc) |
| 14493 | { |
| 14494 | struct breakpoint *bpt; |
| 14495 | |
| 14496 | ALL_BREAKPOINTS (bpt) |
| 14497 | { |
| 14498 | if (bpt->type == bp_single_step |
| 14499 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) |
| 14500 | return 1; |
| 14501 | } |
| 14502 | return 0; |
| 14503 | } |
| 14504 | |
| 14505 | /* Tracepoint-specific operations. */ |
| 14506 | |
| 14507 | /* Set tracepoint count to NUM. */ |
| 14508 | static void |
| 14509 | set_tracepoint_count (int num) |
| 14510 | { |
| 14511 | tracepoint_count = num; |
| 14512 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
| 14513 | } |
| 14514 | |
| 14515 | static void |
| 14516 | trace_command (const char *arg, int from_tty) |
| 14517 | { |
| 14518 | event_location_up location = string_to_event_location (&arg, |
| 14519 | current_language); |
| 14520 | const struct breakpoint_ops *ops = breakpoint_ops_for_event_location |
| 14521 | (location.get (), true /* is_tracepoint */); |
| 14522 | |
| 14523 | create_breakpoint (get_current_arch (), |
| 14524 | location.get (), |
| 14525 | NULL, 0, arg, 1 /* parse arg */, |
| 14526 | 0 /* tempflag */, |
| 14527 | bp_tracepoint /* type_wanted */, |
| 14528 | 0 /* Ignore count */, |
| 14529 | pending_break_support, |
| 14530 | ops, |
| 14531 | from_tty, |
| 14532 | 1 /* enabled */, |
| 14533 | 0 /* internal */, 0); |
| 14534 | } |
| 14535 | |
| 14536 | static void |
| 14537 | ftrace_command (const char *arg, int from_tty) |
| 14538 | { |
| 14539 | event_location_up location = string_to_event_location (&arg, |
| 14540 | current_language); |
| 14541 | create_breakpoint (get_current_arch (), |
| 14542 | location.get (), |
| 14543 | NULL, 0, arg, 1 /* parse arg */, |
| 14544 | 0 /* tempflag */, |
| 14545 | bp_fast_tracepoint /* type_wanted */, |
| 14546 | 0 /* Ignore count */, |
| 14547 | pending_break_support, |
| 14548 | &tracepoint_breakpoint_ops, |
| 14549 | from_tty, |
| 14550 | 1 /* enabled */, |
| 14551 | 0 /* internal */, 0); |
| 14552 | } |
| 14553 | |
| 14554 | /* strace command implementation. Creates a static tracepoint. */ |
| 14555 | |
| 14556 | static void |
| 14557 | strace_command (const char *arg, int from_tty) |
| 14558 | { |
| 14559 | struct breakpoint_ops *ops; |
| 14560 | event_location_up location; |
| 14561 | |
| 14562 | /* Decide if we are dealing with a static tracepoint marker (`-m'), |
| 14563 | or with a normal static tracepoint. */ |
| 14564 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
| 14565 | { |
| 14566 | ops = &strace_marker_breakpoint_ops; |
| 14567 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
| 14568 | } |
| 14569 | else |
| 14570 | { |
| 14571 | ops = &tracepoint_breakpoint_ops; |
| 14572 | location = string_to_event_location (&arg, current_language); |
| 14573 | } |
| 14574 | |
| 14575 | create_breakpoint (get_current_arch (), |
| 14576 | location.get (), |
| 14577 | NULL, 0, arg, 1 /* parse arg */, |
| 14578 | 0 /* tempflag */, |
| 14579 | bp_static_tracepoint /* type_wanted */, |
| 14580 | 0 /* Ignore count */, |
| 14581 | pending_break_support, |
| 14582 | ops, |
| 14583 | from_tty, |
| 14584 | 1 /* enabled */, |
| 14585 | 0 /* internal */, 0); |
| 14586 | } |
| 14587 | |
| 14588 | /* Set up a fake reader function that gets command lines from a linked |
| 14589 | list that was acquired during tracepoint uploading. */ |
| 14590 | |
| 14591 | static struct uploaded_tp *this_utp; |
| 14592 | static int next_cmd; |
| 14593 | |
| 14594 | static char * |
| 14595 | read_uploaded_action (void) |
| 14596 | { |
| 14597 | char *rslt = nullptr; |
| 14598 | |
| 14599 | if (next_cmd < this_utp->cmd_strings.size ()) |
| 14600 | { |
| 14601 | rslt = this_utp->cmd_strings[next_cmd].get (); |
| 14602 | next_cmd++; |
| 14603 | } |
| 14604 | |
| 14605 | return rslt; |
| 14606 | } |
| 14607 | |
| 14608 | /* Given information about a tracepoint as recorded on a target (which |
| 14609 | can be either a live system or a trace file), attempt to create an |
| 14610 | equivalent GDB tracepoint. This is not a reliable process, since |
| 14611 | the target does not necessarily have all the information used when |
| 14612 | the tracepoint was originally defined. */ |
| 14613 | |
| 14614 | struct tracepoint * |
| 14615 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
| 14616 | { |
| 14617 | const char *addr_str; |
| 14618 | char small_buf[100]; |
| 14619 | struct tracepoint *tp; |
| 14620 | |
| 14621 | if (utp->at_string) |
| 14622 | addr_str = utp->at_string.get (); |
| 14623 | else |
| 14624 | { |
| 14625 | /* In the absence of a source location, fall back to raw |
| 14626 | address. Since there is no way to confirm that the address |
| 14627 | means the same thing as when the trace was started, warn the |
| 14628 | user. */ |
| 14629 | warning (_("Uploaded tracepoint %d has no " |
| 14630 | "source location, using raw address"), |
| 14631 | utp->number); |
| 14632 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
| 14633 | addr_str = small_buf; |
| 14634 | } |
| 14635 | |
| 14636 | /* There's not much we can do with a sequence of bytecodes. */ |
| 14637 | if (utp->cond && !utp->cond_string) |
| 14638 | warning (_("Uploaded tracepoint %d condition " |
| 14639 | "has no source form, ignoring it"), |
| 14640 | utp->number); |
| 14641 | |
| 14642 | event_location_up location = string_to_event_location (&addr_str, |
| 14643 | current_language); |
| 14644 | if (!create_breakpoint (get_current_arch (), |
| 14645 | location.get (), |
| 14646 | utp->cond_string.get (), -1, addr_str, |
| 14647 | 0 /* parse cond/thread */, |
| 14648 | 0 /* tempflag */, |
| 14649 | utp->type /* type_wanted */, |
| 14650 | 0 /* Ignore count */, |
| 14651 | pending_break_support, |
| 14652 | &tracepoint_breakpoint_ops, |
| 14653 | 0 /* from_tty */, |
| 14654 | utp->enabled /* enabled */, |
| 14655 | 0 /* internal */, |
| 14656 | CREATE_BREAKPOINT_FLAGS_INSERTED)) |
| 14657 | return NULL; |
| 14658 | |
| 14659 | /* Get the tracepoint we just created. */ |
| 14660 | tp = get_tracepoint (tracepoint_count); |
| 14661 | gdb_assert (tp != NULL); |
| 14662 | |
| 14663 | if (utp->pass > 0) |
| 14664 | { |
| 14665 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
| 14666 | tp->number); |
| 14667 | |
| 14668 | trace_pass_command (small_buf, 0); |
| 14669 | } |
| 14670 | |
| 14671 | /* If we have uploaded versions of the original commands, set up a |
| 14672 | special-purpose "reader" function and call the usual command line |
| 14673 | reader, then pass the result to the breakpoint command-setting |
| 14674 | function. */ |
| 14675 | if (!utp->cmd_strings.empty ()) |
| 14676 | { |
| 14677 | counted_command_line cmd_list; |
| 14678 | |
| 14679 | this_utp = utp; |
| 14680 | next_cmd = 0; |
| 14681 | |
| 14682 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
| 14683 | |
| 14684 | breakpoint_set_commands (tp, std::move (cmd_list)); |
| 14685 | } |
| 14686 | else if (!utp->actions.empty () |
| 14687 | || !utp->step_actions.empty ()) |
| 14688 | warning (_("Uploaded tracepoint %d actions " |
| 14689 | "have no source form, ignoring them"), |
| 14690 | utp->number); |
| 14691 | |
| 14692 | /* Copy any status information that might be available. */ |
| 14693 | tp->hit_count = utp->hit_count; |
| 14694 | tp->traceframe_usage = utp->traceframe_usage; |
| 14695 | |
| 14696 | return tp; |
| 14697 | } |
| 14698 | |
| 14699 | /* Print information on tracepoint number TPNUM_EXP, or all if |
| 14700 | omitted. */ |
| 14701 | |
| 14702 | static void |
| 14703 | info_tracepoints_command (const char *args, int from_tty) |
| 14704 | { |
| 14705 | struct ui_out *uiout = current_uiout; |
| 14706 | int num_printed; |
| 14707 | |
| 14708 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
| 14709 | |
| 14710 | if (num_printed == 0) |
| 14711 | { |
| 14712 | if (args == NULL || *args == '\0') |
| 14713 | uiout->message ("No tracepoints.\n"); |
| 14714 | else |
| 14715 | uiout->message ("No tracepoint matching '%s'.\n", args); |
| 14716 | } |
| 14717 | |
| 14718 | default_collect_info (); |
| 14719 | } |
| 14720 | |
| 14721 | /* The 'enable trace' command enables tracepoints. |
| 14722 | Not supported by all targets. */ |
| 14723 | static void |
| 14724 | enable_trace_command (const char *args, int from_tty) |
| 14725 | { |
| 14726 | enable_command (args, from_tty); |
| 14727 | } |
| 14728 | |
| 14729 | /* The 'disable trace' command disables tracepoints. |
| 14730 | Not supported by all targets. */ |
| 14731 | static void |
| 14732 | disable_trace_command (const char *args, int from_tty) |
| 14733 | { |
| 14734 | disable_command (args, from_tty); |
| 14735 | } |
| 14736 | |
| 14737 | /* Remove a tracepoint (or all if no argument). */ |
| 14738 | static void |
| 14739 | delete_trace_command (const char *arg, int from_tty) |
| 14740 | { |
| 14741 | struct breakpoint *b, *b_tmp; |
| 14742 | |
| 14743 | dont_repeat (); |
| 14744 | |
| 14745 | if (arg == 0) |
| 14746 | { |
| 14747 | int breaks_to_delete = 0; |
| 14748 | |
| 14749 | /* Delete all breakpoints if no argument. |
| 14750 | Do not delete internal or call-dummy breakpoints, these |
| 14751 | have to be deleted with an explicit breakpoint number |
| 14752 | argument. */ |
| 14753 | ALL_TRACEPOINTS (b) |
| 14754 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
| 14755 | { |
| 14756 | breaks_to_delete = 1; |
| 14757 | break; |
| 14758 | } |
| 14759 | |
| 14760 | /* Ask user only if there are some breakpoints to delete. */ |
| 14761 | if (!from_tty |
| 14762 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) |
| 14763 | { |
| 14764 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 14765 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
| 14766 | delete_breakpoint (b); |
| 14767 | } |
| 14768 | } |
| 14769 | else |
| 14770 | map_breakpoint_numbers |
| 14771 | (arg, [&] (breakpoint *br) |
| 14772 | { |
| 14773 | iterate_over_related_breakpoints (br, delete_breakpoint); |
| 14774 | }); |
| 14775 | } |
| 14776 | |
| 14777 | /* Helper function for trace_pass_command. */ |
| 14778 | |
| 14779 | static void |
| 14780 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
| 14781 | { |
| 14782 | tp->pass_count = count; |
| 14783 | gdb::observers::breakpoint_modified.notify (tp); |
| 14784 | if (from_tty) |
| 14785 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), |
| 14786 | tp->number, count); |
| 14787 | } |
| 14788 | |
| 14789 | /* Set passcount for tracepoint. |
| 14790 | |
| 14791 | First command argument is passcount, second is tracepoint number. |
| 14792 | If tracepoint number omitted, apply to most recently defined. |
| 14793 | Also accepts special argument "all". */ |
| 14794 | |
| 14795 | static void |
| 14796 | trace_pass_command (const char *args, int from_tty) |
| 14797 | { |
| 14798 | struct tracepoint *t1; |
| 14799 | ULONGEST count; |
| 14800 | |
| 14801 | if (args == 0 || *args == 0) |
| 14802 | error (_("passcount command requires an " |
| 14803 | "argument (count + optional TP num)")); |
| 14804 | |
| 14805 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
| 14806 | |
| 14807 | args = skip_spaces (args); |
| 14808 | if (*args && strncasecmp (args, "all", 3) == 0) |
| 14809 | { |
| 14810 | struct breakpoint *b; |
| 14811 | |
| 14812 | args += 3; /* Skip special argument "all". */ |
| 14813 | if (*args) |
| 14814 | error (_("Junk at end of arguments.")); |
| 14815 | |
| 14816 | ALL_TRACEPOINTS (b) |
| 14817 | { |
| 14818 | t1 = (struct tracepoint *) b; |
| 14819 | trace_pass_set_count (t1, count, from_tty); |
| 14820 | } |
| 14821 | } |
| 14822 | else if (*args == '\0') |
| 14823 | { |
| 14824 | t1 = get_tracepoint_by_number (&args, NULL); |
| 14825 | if (t1) |
| 14826 | trace_pass_set_count (t1, count, from_tty); |
| 14827 | } |
| 14828 | else |
| 14829 | { |
| 14830 | number_or_range_parser parser (args); |
| 14831 | while (!parser.finished ()) |
| 14832 | { |
| 14833 | t1 = get_tracepoint_by_number (&args, &parser); |
| 14834 | if (t1) |
| 14835 | trace_pass_set_count (t1, count, from_tty); |
| 14836 | } |
| 14837 | } |
| 14838 | } |
| 14839 | |
| 14840 | struct tracepoint * |
| 14841 | get_tracepoint (int num) |
| 14842 | { |
| 14843 | struct breakpoint *t; |
| 14844 | |
| 14845 | ALL_TRACEPOINTS (t) |
| 14846 | if (t->number == num) |
| 14847 | return (struct tracepoint *) t; |
| 14848 | |
| 14849 | return NULL; |
| 14850 | } |
| 14851 | |
| 14852 | /* Find the tracepoint with the given target-side number (which may be |
| 14853 | different from the tracepoint number after disconnecting and |
| 14854 | reconnecting). */ |
| 14855 | |
| 14856 | struct tracepoint * |
| 14857 | get_tracepoint_by_number_on_target (int num) |
| 14858 | { |
| 14859 | struct breakpoint *b; |
| 14860 | |
| 14861 | ALL_TRACEPOINTS (b) |
| 14862 | { |
| 14863 | struct tracepoint *t = (struct tracepoint *) b; |
| 14864 | |
| 14865 | if (t->number_on_target == num) |
| 14866 | return t; |
| 14867 | } |
| 14868 | |
| 14869 | return NULL; |
| 14870 | } |
| 14871 | |
| 14872 | /* Utility: parse a tracepoint number and look it up in the list. |
| 14873 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
| 14874 | If the argument is missing, the most recent tracepoint |
| 14875 | (tracepoint_count) is returned. */ |
| 14876 | |
| 14877 | struct tracepoint * |
| 14878 | get_tracepoint_by_number (const char **arg, |
| 14879 | number_or_range_parser *parser) |
| 14880 | { |
| 14881 | struct breakpoint *t; |
| 14882 | int tpnum; |
| 14883 | const char *instring = arg == NULL ? NULL : *arg; |
| 14884 | |
| 14885 | if (parser != NULL) |
| 14886 | { |
| 14887 | gdb_assert (!parser->finished ()); |
| 14888 | tpnum = parser->get_number (); |
| 14889 | } |
| 14890 | else if (arg == NULL || *arg == NULL || ! **arg) |
| 14891 | tpnum = tracepoint_count; |
| 14892 | else |
| 14893 | tpnum = get_number (arg); |
| 14894 | |
| 14895 | if (tpnum <= 0) |
| 14896 | { |
| 14897 | if (instring && *instring) |
| 14898 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), |
| 14899 | instring); |
| 14900 | else |
| 14901 | printf_filtered (_("No previous tracepoint\n")); |
| 14902 | return NULL; |
| 14903 | } |
| 14904 | |
| 14905 | ALL_TRACEPOINTS (t) |
| 14906 | if (t->number == tpnum) |
| 14907 | { |
| 14908 | return (struct tracepoint *) t; |
| 14909 | } |
| 14910 | |
| 14911 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
| 14912 | return NULL; |
| 14913 | } |
| 14914 | |
| 14915 | void |
| 14916 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) |
| 14917 | { |
| 14918 | if (b->thread != -1) |
| 14919 | fprintf_unfiltered (fp, " thread %d", b->thread); |
| 14920 | |
| 14921 | if (b->task != 0) |
| 14922 | fprintf_unfiltered (fp, " task %d", b->task); |
| 14923 | |
| 14924 | fprintf_unfiltered (fp, "\n"); |
| 14925 | } |
| 14926 | |
| 14927 | /* Save information on user settable breakpoints (watchpoints, etc) to |
| 14928 | a new script file named FILENAME. If FILTER is non-NULL, call it |
| 14929 | on each breakpoint and only include the ones for which it returns |
| 14930 | true. */ |
| 14931 | |
| 14932 | static void |
| 14933 | save_breakpoints (const char *filename, int from_tty, |
| 14934 | bool (*filter) (const struct breakpoint *)) |
| 14935 | { |
| 14936 | struct breakpoint *tp; |
| 14937 | int any = 0; |
| 14938 | int extra_trace_bits = 0; |
| 14939 | |
| 14940 | if (filename == 0 || *filename == 0) |
| 14941 | error (_("Argument required (file name in which to save)")); |
| 14942 | |
| 14943 | /* See if we have anything to save. */ |
| 14944 | ALL_BREAKPOINTS (tp) |
| 14945 | { |
| 14946 | /* Skip internal and momentary breakpoints. */ |
| 14947 | if (!user_breakpoint_p (tp)) |
| 14948 | continue; |
| 14949 | |
| 14950 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 14951 | if (filter && !filter (tp)) |
| 14952 | continue; |
| 14953 | |
| 14954 | any = 1; |
| 14955 | |
| 14956 | if (is_tracepoint (tp)) |
| 14957 | { |
| 14958 | extra_trace_bits = 1; |
| 14959 | |
| 14960 | /* We can stop searching. */ |
| 14961 | break; |
| 14962 | } |
| 14963 | } |
| 14964 | |
| 14965 | if (!any) |
| 14966 | { |
| 14967 | warning (_("Nothing to save.")); |
| 14968 | return; |
| 14969 | } |
| 14970 | |
| 14971 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
| 14972 | |
| 14973 | stdio_file fp; |
| 14974 | |
| 14975 | if (!fp.open (expanded_filename.get (), "w")) |
| 14976 | error (_("Unable to open file '%s' for saving (%s)"), |
| 14977 | expanded_filename.get (), safe_strerror (errno)); |
| 14978 | |
| 14979 | if (extra_trace_bits) |
| 14980 | save_trace_state_variables (&fp); |
| 14981 | |
| 14982 | ALL_BREAKPOINTS (tp) |
| 14983 | { |
| 14984 | /* Skip internal and momentary breakpoints. */ |
| 14985 | if (!user_breakpoint_p (tp)) |
| 14986 | continue; |
| 14987 | |
| 14988 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 14989 | if (filter && !filter (tp)) |
| 14990 | continue; |
| 14991 | |
| 14992 | tp->ops->print_recreate (tp, &fp); |
| 14993 | |
| 14994 | /* Note, we can't rely on tp->number for anything, as we can't |
| 14995 | assume the recreated breakpoint numbers will match. Use $bpnum |
| 14996 | instead. */ |
| 14997 | |
| 14998 | if (tp->cond_string) |
| 14999 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
| 15000 | |
| 15001 | if (tp->ignore_count) |
| 15002 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
| 15003 | |
| 15004 | if (tp->type != bp_dprintf && tp->commands) |
| 15005 | { |
| 15006 | fp.puts (" commands\n"); |
| 15007 | |
| 15008 | current_uiout->redirect (&fp); |
| 15009 | try |
| 15010 | { |
| 15011 | print_command_lines (current_uiout, tp->commands.get (), 2); |
| 15012 | } |
| 15013 | catch (const gdb_exception &ex) |
| 15014 | { |
| 15015 | current_uiout->redirect (NULL); |
| 15016 | throw; |
| 15017 | } |
| 15018 | |
| 15019 | current_uiout->redirect (NULL); |
| 15020 | fp.puts (" end\n"); |
| 15021 | } |
| 15022 | |
| 15023 | if (tp->enable_state == bp_disabled) |
| 15024 | fp.puts ("disable $bpnum\n"); |
| 15025 | |
| 15026 | /* If this is a multi-location breakpoint, check if the locations |
| 15027 | should be individually disabled. Watchpoint locations are |
| 15028 | special, and not user visible. */ |
| 15029 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) |
| 15030 | { |
| 15031 | struct bp_location *loc; |
| 15032 | int n = 1; |
| 15033 | |
| 15034 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) |
| 15035 | if (!loc->enabled) |
| 15036 | fp.printf ("disable $bpnum.%d\n", n); |
| 15037 | } |
| 15038 | } |
| 15039 | |
| 15040 | if (extra_trace_bits && *default_collect) |
| 15041 | fp.printf ("set default-collect %s\n", default_collect); |
| 15042 | |
| 15043 | if (from_tty) |
| 15044 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
| 15045 | } |
| 15046 | |
| 15047 | /* The `save breakpoints' command. */ |
| 15048 | |
| 15049 | static void |
| 15050 | save_breakpoints_command (const char *args, int from_tty) |
| 15051 | { |
| 15052 | save_breakpoints (args, from_tty, NULL); |
| 15053 | } |
| 15054 | |
| 15055 | /* The `save tracepoints' command. */ |
| 15056 | |
| 15057 | static void |
| 15058 | save_tracepoints_command (const char *args, int from_tty) |
| 15059 | { |
| 15060 | save_breakpoints (args, from_tty, is_tracepoint); |
| 15061 | } |
| 15062 | |
| 15063 | /* Create a vector of all tracepoints. */ |
| 15064 | |
| 15065 | std::vector<breakpoint *> |
| 15066 | all_tracepoints (void) |
| 15067 | { |
| 15068 | std::vector<breakpoint *> tp_vec; |
| 15069 | struct breakpoint *tp; |
| 15070 | |
| 15071 | ALL_TRACEPOINTS (tp) |
| 15072 | { |
| 15073 | tp_vec.push_back (tp); |
| 15074 | } |
| 15075 | |
| 15076 | return tp_vec; |
| 15077 | } |
| 15078 | |
| 15079 | \f |
| 15080 | /* This help string is used to consolidate all the help string for specifying |
| 15081 | locations used by several commands. */ |
| 15082 | |
| 15083 | #define LOCATION_HELP_STRING \ |
| 15084 | "Linespecs are colon-separated lists of location parameters, such as\n\ |
| 15085 | source filename, function name, label name, and line number.\n\ |
| 15086 | Example: To specify the start of a label named \"the_top\" in the\n\ |
| 15087 | function \"fact\" in the file \"factorial.c\", use\n\ |
| 15088 | \"factorial.c:fact:the_top\".\n\ |
| 15089 | \n\ |
| 15090 | Address locations begin with \"*\" and specify an exact address in the\n\ |
| 15091 | program. Example: To specify the fourth byte past the start function\n\ |
| 15092 | \"main\", use \"*main + 4\".\n\ |
| 15093 | \n\ |
| 15094 | Explicit locations are similar to linespecs but use an option/argument\n\ |
| 15095 | syntax to specify location parameters.\n\ |
| 15096 | Example: To specify the start of the label named \"the_top\" in the\n\ |
| 15097 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ |
| 15098 | -function fact -label the_top\".\n\ |
| 15099 | \n\ |
| 15100 | By default, a specified function is matched against the program's\n\ |
| 15101 | functions in all scopes. For C++, this means in all namespaces and\n\ |
| 15102 | classes. For Ada, this means in all packages. E.g., in C++,\n\ |
| 15103 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ |
| 15104 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ |
| 15105 | specified name as a complete fully-qualified name instead." |
| 15106 | |
| 15107 | /* This help string is used for the break, hbreak, tbreak and thbreak |
| 15108 | commands. It is defined as a macro to prevent duplication. |
| 15109 | COMMAND should be a string constant containing the name of the |
| 15110 | command. */ |
| 15111 | |
| 15112 | #define BREAK_ARGS_HELP(command) \ |
| 15113 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
| 15114 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ |
| 15115 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ |
| 15116 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
| 15117 | `-probe-dtrace' (for a DTrace probe).\n\ |
| 15118 | LOCATION may be a linespec, address, or explicit location as described\n\ |
| 15119 | below.\n\ |
| 15120 | \n\ |
| 15121 | With no LOCATION, uses current execution address of the selected\n\ |
| 15122 | stack frame. This is useful for breaking on return to a stack frame.\n\ |
| 15123 | \n\ |
| 15124 | THREADNUM is the number from \"info threads\".\n\ |
| 15125 | CONDITION is a boolean expression.\n\ |
| 15126 | \n" LOCATION_HELP_STRING "\n\n\ |
| 15127 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
| 15128 | conditions are different.\n\ |
| 15129 | \n\ |
| 15130 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." |
| 15131 | |
| 15132 | /* List of subcommands for "catch". */ |
| 15133 | static struct cmd_list_element *catch_cmdlist; |
| 15134 | |
| 15135 | /* List of subcommands for "tcatch". */ |
| 15136 | static struct cmd_list_element *tcatch_cmdlist; |
| 15137 | |
| 15138 | void |
| 15139 | add_catch_command (const char *name, const char *docstring, |
| 15140 | cmd_const_sfunc_ftype *sfunc, |
| 15141 | completer_ftype *completer, |
| 15142 | void *user_data_catch, |
| 15143 | void *user_data_tcatch) |
| 15144 | { |
| 15145 | struct cmd_list_element *command; |
| 15146 | |
| 15147 | command = add_cmd (name, class_breakpoint, docstring, |
| 15148 | &catch_cmdlist); |
| 15149 | set_cmd_sfunc (command, sfunc); |
| 15150 | set_cmd_context (command, user_data_catch); |
| 15151 | set_cmd_completer (command, completer); |
| 15152 | |
| 15153 | command = add_cmd (name, class_breakpoint, docstring, |
| 15154 | &tcatch_cmdlist); |
| 15155 | set_cmd_sfunc (command, sfunc); |
| 15156 | set_cmd_context (command, user_data_tcatch); |
| 15157 | set_cmd_completer (command, completer); |
| 15158 | } |
| 15159 | |
| 15160 | static void |
| 15161 | save_command (const char *arg, int from_tty) |
| 15162 | { |
| 15163 | printf_unfiltered (_("\"save\" must be followed by " |
| 15164 | "the name of a save subcommand.\n")); |
| 15165 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
| 15166 | } |
| 15167 | |
| 15168 | struct breakpoint * |
| 15169 | iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback) |
| 15170 | { |
| 15171 | struct breakpoint *b, *b_tmp; |
| 15172 | |
| 15173 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 15174 | { |
| 15175 | if (callback (b)) |
| 15176 | return b; |
| 15177 | } |
| 15178 | |
| 15179 | return NULL; |
| 15180 | } |
| 15181 | |
| 15182 | /* Zero if any of the breakpoint's locations could be a location where |
| 15183 | functions have been inlined, nonzero otherwise. */ |
| 15184 | |
| 15185 | static int |
| 15186 | is_non_inline_function (struct breakpoint *b) |
| 15187 | { |
| 15188 | /* The shared library event breakpoint is set on the address of a |
| 15189 | non-inline function. */ |
| 15190 | if (b->type == bp_shlib_event) |
| 15191 | return 1; |
| 15192 | |
| 15193 | return 0; |
| 15194 | } |
| 15195 | |
| 15196 | /* Nonzero if the specified PC cannot be a location where functions |
| 15197 | have been inlined. */ |
| 15198 | |
| 15199 | int |
| 15200 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
| 15201 | const struct target_waitstatus *ws) |
| 15202 | { |
| 15203 | struct breakpoint *b; |
| 15204 | struct bp_location *bl; |
| 15205 | |
| 15206 | ALL_BREAKPOINTS (b) |
| 15207 | { |
| 15208 | if (!is_non_inline_function (b)) |
| 15209 | continue; |
| 15210 | |
| 15211 | for (bl = b->loc; bl != NULL; bl = bl->next) |
| 15212 | { |
| 15213 | if (!bl->shlib_disabled |
| 15214 | && bpstat_check_location (bl, aspace, pc, ws)) |
| 15215 | return 1; |
| 15216 | } |
| 15217 | } |
| 15218 | |
| 15219 | return 0; |
| 15220 | } |
| 15221 | |
| 15222 | /* Remove any references to OBJFILE which is going to be freed. */ |
| 15223 | |
| 15224 | void |
| 15225 | breakpoint_free_objfile (struct objfile *objfile) |
| 15226 | { |
| 15227 | struct bp_location **locp, *loc; |
| 15228 | |
| 15229 | ALL_BP_LOCATIONS (loc, locp) |
| 15230 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
| 15231 | loc->symtab = NULL; |
| 15232 | } |
| 15233 | |
| 15234 | void |
| 15235 | initialize_breakpoint_ops (void) |
| 15236 | { |
| 15237 | static int initialized = 0; |
| 15238 | |
| 15239 | struct breakpoint_ops *ops; |
| 15240 | |
| 15241 | if (initialized) |
| 15242 | return; |
| 15243 | initialized = 1; |
| 15244 | |
| 15245 | /* The breakpoint_ops structure to be inherit by all kinds of |
| 15246 | breakpoints (real breakpoints, i.e., user "break" breakpoints, |
| 15247 | internal and momentary breakpoints, etc.). */ |
| 15248 | ops = &bkpt_base_breakpoint_ops; |
| 15249 | *ops = base_breakpoint_ops; |
| 15250 | ops->re_set = bkpt_re_set; |
| 15251 | ops->insert_location = bkpt_insert_location; |
| 15252 | ops->remove_location = bkpt_remove_location; |
| 15253 | ops->breakpoint_hit = bkpt_breakpoint_hit; |
| 15254 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
| 15255 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
| 15256 | ops->decode_location = bkpt_decode_location; |
| 15257 | |
| 15258 | /* The breakpoint_ops structure to be used in regular breakpoints. */ |
| 15259 | ops = &bkpt_breakpoint_ops; |
| 15260 | *ops = bkpt_base_breakpoint_ops; |
| 15261 | ops->re_set = bkpt_re_set; |
| 15262 | ops->resources_needed = bkpt_resources_needed; |
| 15263 | ops->print_it = bkpt_print_it; |
| 15264 | ops->print_mention = bkpt_print_mention; |
| 15265 | ops->print_recreate = bkpt_print_recreate; |
| 15266 | |
| 15267 | /* Ranged breakpoints. */ |
| 15268 | ops = &ranged_breakpoint_ops; |
| 15269 | *ops = bkpt_breakpoint_ops; |
| 15270 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; |
| 15271 | ops->resources_needed = resources_needed_ranged_breakpoint; |
| 15272 | ops->print_it = print_it_ranged_breakpoint; |
| 15273 | ops->print_one = print_one_ranged_breakpoint; |
| 15274 | ops->print_one_detail = print_one_detail_ranged_breakpoint; |
| 15275 | ops->print_mention = print_mention_ranged_breakpoint; |
| 15276 | ops->print_recreate = print_recreate_ranged_breakpoint; |
| 15277 | |
| 15278 | /* Internal breakpoints. */ |
| 15279 | ops = &internal_breakpoint_ops; |
| 15280 | *ops = bkpt_base_breakpoint_ops; |
| 15281 | ops->re_set = internal_bkpt_re_set; |
| 15282 | ops->check_status = internal_bkpt_check_status; |
| 15283 | ops->print_it = internal_bkpt_print_it; |
| 15284 | ops->print_mention = internal_bkpt_print_mention; |
| 15285 | |
| 15286 | /* Momentary breakpoints. */ |
| 15287 | ops = &momentary_breakpoint_ops; |
| 15288 | *ops = bkpt_base_breakpoint_ops; |
| 15289 | ops->re_set = momentary_bkpt_re_set; |
| 15290 | ops->check_status = momentary_bkpt_check_status; |
| 15291 | ops->print_it = momentary_bkpt_print_it; |
| 15292 | ops->print_mention = momentary_bkpt_print_mention; |
| 15293 | |
| 15294 | /* Probe breakpoints. */ |
| 15295 | ops = &bkpt_probe_breakpoint_ops; |
| 15296 | *ops = bkpt_breakpoint_ops; |
| 15297 | ops->insert_location = bkpt_probe_insert_location; |
| 15298 | ops->remove_location = bkpt_probe_remove_location; |
| 15299 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
| 15300 | ops->decode_location = bkpt_probe_decode_location; |
| 15301 | |
| 15302 | /* Watchpoints. */ |
| 15303 | ops = &watchpoint_breakpoint_ops; |
| 15304 | *ops = base_breakpoint_ops; |
| 15305 | ops->re_set = re_set_watchpoint; |
| 15306 | ops->insert_location = insert_watchpoint; |
| 15307 | ops->remove_location = remove_watchpoint; |
| 15308 | ops->breakpoint_hit = breakpoint_hit_watchpoint; |
| 15309 | ops->check_status = check_status_watchpoint; |
| 15310 | ops->resources_needed = resources_needed_watchpoint; |
| 15311 | ops->works_in_software_mode = works_in_software_mode_watchpoint; |
| 15312 | ops->print_it = print_it_watchpoint; |
| 15313 | ops->print_mention = print_mention_watchpoint; |
| 15314 | ops->print_recreate = print_recreate_watchpoint; |
| 15315 | ops->explains_signal = explains_signal_watchpoint; |
| 15316 | |
| 15317 | /* Masked watchpoints. */ |
| 15318 | ops = &masked_watchpoint_breakpoint_ops; |
| 15319 | *ops = watchpoint_breakpoint_ops; |
| 15320 | ops->insert_location = insert_masked_watchpoint; |
| 15321 | ops->remove_location = remove_masked_watchpoint; |
| 15322 | ops->resources_needed = resources_needed_masked_watchpoint; |
| 15323 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; |
| 15324 | ops->print_it = print_it_masked_watchpoint; |
| 15325 | ops->print_one_detail = print_one_detail_masked_watchpoint; |
| 15326 | ops->print_mention = print_mention_masked_watchpoint; |
| 15327 | ops->print_recreate = print_recreate_masked_watchpoint; |
| 15328 | |
| 15329 | /* Tracepoints. */ |
| 15330 | ops = &tracepoint_breakpoint_ops; |
| 15331 | *ops = base_breakpoint_ops; |
| 15332 | ops->re_set = tracepoint_re_set; |
| 15333 | ops->breakpoint_hit = tracepoint_breakpoint_hit; |
| 15334 | ops->print_one_detail = tracepoint_print_one_detail; |
| 15335 | ops->print_mention = tracepoint_print_mention; |
| 15336 | ops->print_recreate = tracepoint_print_recreate; |
| 15337 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
| 15338 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
| 15339 | ops->decode_location = tracepoint_decode_location; |
| 15340 | |
| 15341 | /* Probe tracepoints. */ |
| 15342 | ops = &tracepoint_probe_breakpoint_ops; |
| 15343 | *ops = tracepoint_breakpoint_ops; |
| 15344 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
| 15345 | ops->decode_location = tracepoint_probe_decode_location; |
| 15346 | |
| 15347 | /* Static tracepoints with marker (`-m'). */ |
| 15348 | ops = &strace_marker_breakpoint_ops; |
| 15349 | *ops = tracepoint_breakpoint_ops; |
| 15350 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
| 15351 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
| 15352 | ops->decode_location = strace_marker_decode_location; |
| 15353 | |
| 15354 | /* Fork catchpoints. */ |
| 15355 | ops = &catch_fork_breakpoint_ops; |
| 15356 | *ops = base_breakpoint_ops; |
| 15357 | ops->insert_location = insert_catch_fork; |
| 15358 | ops->remove_location = remove_catch_fork; |
| 15359 | ops->breakpoint_hit = breakpoint_hit_catch_fork; |
| 15360 | ops->print_it = print_it_catch_fork; |
| 15361 | ops->print_one = print_one_catch_fork; |
| 15362 | ops->print_mention = print_mention_catch_fork; |
| 15363 | ops->print_recreate = print_recreate_catch_fork; |
| 15364 | |
| 15365 | /* Vfork catchpoints. */ |
| 15366 | ops = &catch_vfork_breakpoint_ops; |
| 15367 | *ops = base_breakpoint_ops; |
| 15368 | ops->insert_location = insert_catch_vfork; |
| 15369 | ops->remove_location = remove_catch_vfork; |
| 15370 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; |
| 15371 | ops->print_it = print_it_catch_vfork; |
| 15372 | ops->print_one = print_one_catch_vfork; |
| 15373 | ops->print_mention = print_mention_catch_vfork; |
| 15374 | ops->print_recreate = print_recreate_catch_vfork; |
| 15375 | |
| 15376 | /* Exec catchpoints. */ |
| 15377 | ops = &catch_exec_breakpoint_ops; |
| 15378 | *ops = base_breakpoint_ops; |
| 15379 | ops->insert_location = insert_catch_exec; |
| 15380 | ops->remove_location = remove_catch_exec; |
| 15381 | ops->breakpoint_hit = breakpoint_hit_catch_exec; |
| 15382 | ops->print_it = print_it_catch_exec; |
| 15383 | ops->print_one = print_one_catch_exec; |
| 15384 | ops->print_mention = print_mention_catch_exec; |
| 15385 | ops->print_recreate = print_recreate_catch_exec; |
| 15386 | |
| 15387 | /* Solib-related catchpoints. */ |
| 15388 | ops = &catch_solib_breakpoint_ops; |
| 15389 | *ops = base_breakpoint_ops; |
| 15390 | ops->insert_location = insert_catch_solib; |
| 15391 | ops->remove_location = remove_catch_solib; |
| 15392 | ops->breakpoint_hit = breakpoint_hit_catch_solib; |
| 15393 | ops->check_status = check_status_catch_solib; |
| 15394 | ops->print_it = print_it_catch_solib; |
| 15395 | ops->print_one = print_one_catch_solib; |
| 15396 | ops->print_mention = print_mention_catch_solib; |
| 15397 | ops->print_recreate = print_recreate_catch_solib; |
| 15398 | |
| 15399 | ops = &dprintf_breakpoint_ops; |
| 15400 | *ops = bkpt_base_breakpoint_ops; |
| 15401 | ops->re_set = dprintf_re_set; |
| 15402 | ops->resources_needed = bkpt_resources_needed; |
| 15403 | ops->print_it = bkpt_print_it; |
| 15404 | ops->print_mention = bkpt_print_mention; |
| 15405 | ops->print_recreate = dprintf_print_recreate; |
| 15406 | ops->after_condition_true = dprintf_after_condition_true; |
| 15407 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
| 15408 | } |
| 15409 | |
| 15410 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
| 15411 | |
| 15412 | static struct cmd_list_element *enablebreaklist = NULL; |
| 15413 | |
| 15414 | /* See breakpoint.h. */ |
| 15415 | |
| 15416 | cmd_list_element *commands_cmd_element = nullptr; |
| 15417 | |
| 15418 | void |
| 15419 | _initialize_breakpoint (void) |
| 15420 | { |
| 15421 | struct cmd_list_element *c; |
| 15422 | |
| 15423 | initialize_breakpoint_ops (); |
| 15424 | |
| 15425 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
| 15426 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); |
| 15427 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); |
| 15428 | |
| 15429 | breakpoint_chain = 0; |
| 15430 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful |
| 15431 | before a breakpoint is set. */ |
| 15432 | breakpoint_count = 0; |
| 15433 | |
| 15434 | tracepoint_count = 0; |
| 15435 | |
| 15436 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
| 15437 | Set ignore-count of breakpoint number N to COUNT.\n\ |
| 15438 | Usage is `ignore N COUNT'.")); |
| 15439 | |
| 15440 | commands_cmd_element = add_com ("commands", class_breakpoint, |
| 15441 | commands_command, _("\ |
| 15442 | Set commands to be executed when the given breakpoints are hit.\n\ |
| 15443 | Give a space-separated breakpoint list as argument after \"commands\".\n\ |
| 15444 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ |
| 15445 | (e.g. `5-7').\n\ |
| 15446 | With no argument, the targeted breakpoint is the last one set.\n\ |
| 15447 | The commands themselves follow starting on the next line.\n\ |
| 15448 | Type a line containing \"end\" to indicate the end of them.\n\ |
| 15449 | Give \"silent\" as the first line to make the breakpoint silent;\n\ |
| 15450 | then no output is printed when it is hit, except what the commands print.")); |
| 15451 | |
| 15452 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
| 15453 | Specify breakpoint number N to break only if COND is true.\n\ |
| 15454 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
| 15455 | expression to be evaluated whenever breakpoint N is reached.")); |
| 15456 | set_cmd_completer (c, condition_completer); |
| 15457 | |
| 15458 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
| 15459 | Set a temporary breakpoint.\n\ |
| 15460 | Like \"break\" except the breakpoint is only temporary,\n\ |
| 15461 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ |
| 15462 | by using \"enable delete\" on the breakpoint number.\n\ |
| 15463 | \n" |
| 15464 | BREAK_ARGS_HELP ("tbreak"))); |
| 15465 | set_cmd_completer (c, location_completer); |
| 15466 | |
| 15467 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
| 15468 | Set a hardware assisted breakpoint.\n\ |
| 15469 | Like \"break\" except the breakpoint requires hardware support,\n\ |
| 15470 | some target hardware may not have this support.\n\ |
| 15471 | \n" |
| 15472 | BREAK_ARGS_HELP ("hbreak"))); |
| 15473 | set_cmd_completer (c, location_completer); |
| 15474 | |
| 15475 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
| 15476 | Set a temporary hardware assisted breakpoint.\n\ |
| 15477 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
| 15478 | so it will be deleted when hit.\n\ |
| 15479 | \n" |
| 15480 | BREAK_ARGS_HELP ("thbreak"))); |
| 15481 | set_cmd_completer (c, location_completer); |
| 15482 | |
| 15483 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
| 15484 | Enable all or some breakpoints.\n\ |
| 15485 | Usage: enable [BREAKPOINTNUM]...\n\ |
| 15486 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 15487 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 15488 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 15489 | With a subcommand you can enable temporarily."), |
| 15490 | &enablelist, "enable ", 1, &cmdlist); |
| 15491 | |
| 15492 | add_com_alias ("en", "enable", class_breakpoint, 1); |
| 15493 | |
| 15494 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
| 15495 | Enable all or some breakpoints.\n\ |
| 15496 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ |
| 15497 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 15498 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 15499 | May be abbreviated to simply \"enable\"."), |
| 15500 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
| 15501 | |
| 15502 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 15503 | Enable some breakpoints for one hit.\n\ |
| 15504 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ |
| 15505 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 15506 | &enablebreaklist); |
| 15507 | |
| 15508 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 15509 | Enable some breakpoints and delete when hit.\n\ |
| 15510 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ |
| 15511 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 15512 | &enablebreaklist); |
| 15513 | |
| 15514 | add_cmd ("count", no_class, enable_count_command, _("\ |
| 15515 | Enable some breakpoints for COUNT hits.\n\ |
| 15516 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ |
| 15517 | If a breakpoint is hit while enabled in this fashion,\n\ |
| 15518 | the count is decremented; when it reaches zero, the breakpoint is disabled."), |
| 15519 | &enablebreaklist); |
| 15520 | |
| 15521 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 15522 | Enable some breakpoints and delete when hit.\n\ |
| 15523 | Usage: enable delete BREAKPOINTNUM...\n\ |
| 15524 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 15525 | &enablelist); |
| 15526 | |
| 15527 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 15528 | Enable some breakpoints for one hit.\n\ |
| 15529 | Usage: enable once BREAKPOINTNUM...\n\ |
| 15530 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 15531 | &enablelist); |
| 15532 | |
| 15533 | add_cmd ("count", no_class, enable_count_command, _("\ |
| 15534 | Enable some breakpoints for COUNT hits.\n\ |
| 15535 | Usage: enable count COUNT BREAKPOINTNUM...\n\ |
| 15536 | If a breakpoint is hit while enabled in this fashion,\n\ |
| 15537 | the count is decremented; when it reaches zero, the breakpoint is disabled."), |
| 15538 | &enablelist); |
| 15539 | |
| 15540 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
| 15541 | Disable all or some breakpoints.\n\ |
| 15542 | Usage: disable [BREAKPOINTNUM]...\n\ |
| 15543 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15544 | To disable all breakpoints, give no argument.\n\ |
| 15545 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
| 15546 | &disablelist, "disable ", 1, &cmdlist); |
| 15547 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
| 15548 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
| 15549 | |
| 15550 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
| 15551 | Disable all or some breakpoints.\n\ |
| 15552 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ |
| 15553 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15554 | To disable all breakpoints, give no argument.\n\ |
| 15555 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
| 15556 | This command may be abbreviated \"disable\"."), |
| 15557 | &disablelist); |
| 15558 | |
| 15559 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
| 15560 | Delete all or some breakpoints.\n\ |
| 15561 | Usage: delete [BREAKPOINTNUM]...\n\ |
| 15562 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15563 | To delete all breakpoints, give no argument.\n\ |
| 15564 | \n\ |
| 15565 | Also a prefix command for deletion of other GDB objects."), |
| 15566 | &deletelist, "delete ", 1, &cmdlist); |
| 15567 | add_com_alias ("d", "delete", class_breakpoint, 1); |
| 15568 | add_com_alias ("del", "delete", class_breakpoint, 1); |
| 15569 | |
| 15570 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
| 15571 | Delete all or some breakpoints or auto-display expressions.\n\ |
| 15572 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ |
| 15573 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15574 | To delete all breakpoints, give no argument.\n\ |
| 15575 | This command may be abbreviated \"delete\"."), |
| 15576 | &deletelist); |
| 15577 | |
| 15578 | add_com ("clear", class_breakpoint, clear_command, _("\ |
| 15579 | Clear breakpoint at specified location.\n\ |
| 15580 | Argument may be a linespec, explicit, or address location as described below.\n\ |
| 15581 | \n\ |
| 15582 | With no argument, clears all breakpoints in the line that the selected frame\n\ |
| 15583 | is executing in.\n" |
| 15584 | "\n" LOCATION_HELP_STRING "\n\n\ |
| 15585 | See also the \"delete\" command which clears breakpoints by number.")); |
| 15586 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
| 15587 | |
| 15588 | c = add_com ("break", class_breakpoint, break_command, _("\ |
| 15589 | Set breakpoint at specified location.\n" |
| 15590 | BREAK_ARGS_HELP ("break"))); |
| 15591 | set_cmd_completer (c, location_completer); |
| 15592 | |
| 15593 | add_com_alias ("b", "break", class_run, 1); |
| 15594 | add_com_alias ("br", "break", class_run, 1); |
| 15595 | add_com_alias ("bre", "break", class_run, 1); |
| 15596 | add_com_alias ("brea", "break", class_run, 1); |
| 15597 | |
| 15598 | if (dbx_commands) |
| 15599 | { |
| 15600 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
| 15601 | Break in function/address or break at a line in the current file."), |
| 15602 | &stoplist, "stop ", 1, &cmdlist); |
| 15603 | add_cmd ("in", class_breakpoint, stopin_command, |
| 15604 | _("Break in function or address."), &stoplist); |
| 15605 | add_cmd ("at", class_breakpoint, stopat_command, |
| 15606 | _("Break at a line in the current file."), &stoplist); |
| 15607 | add_com ("status", class_info, info_breakpoints_command, _("\ |
| 15608 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 15609 | The \"Type\" column indicates one of:\n\ |
| 15610 | \tbreakpoint - normal breakpoint\n\ |
| 15611 | \twatchpoint - watchpoint\n\ |
| 15612 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 15613 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 15614 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 15615 | address and file/line number respectively.\n\ |
| 15616 | \n\ |
| 15617 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 15618 | are set to the address of the last breakpoint listed unless the command\n\ |
| 15619 | is prefixed with \"server \".\n\n\ |
| 15620 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 15621 | breakpoint set.")); |
| 15622 | } |
| 15623 | |
| 15624 | add_info ("breakpoints", info_breakpoints_command, _("\ |
| 15625 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
| 15626 | The \"Type\" column indicates one of:\n\ |
| 15627 | \tbreakpoint - normal breakpoint\n\ |
| 15628 | \twatchpoint - watchpoint\n\ |
| 15629 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 15630 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 15631 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 15632 | address and file/line number respectively.\n\ |
| 15633 | \n\ |
| 15634 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 15635 | are set to the address of the last breakpoint listed unless the command\n\ |
| 15636 | is prefixed with \"server \".\n\n\ |
| 15637 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 15638 | breakpoint set.")); |
| 15639 | |
| 15640 | add_info_alias ("b", "breakpoints", 1); |
| 15641 | |
| 15642 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
| 15643 | Status of all breakpoints, or breakpoint number NUMBER.\n\ |
| 15644 | The \"Type\" column indicates one of:\n\ |
| 15645 | \tbreakpoint - normal breakpoint\n\ |
| 15646 | \twatchpoint - watchpoint\n\ |
| 15647 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ |
| 15648 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ |
| 15649 | \tuntil - internal breakpoint used by the \"until\" command\n\ |
| 15650 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
| 15651 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 15652 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 15653 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 15654 | address and file/line number respectively.\n\ |
| 15655 | \n\ |
| 15656 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 15657 | are set to the address of the last breakpoint listed unless the command\n\ |
| 15658 | is prefixed with \"server \".\n\n\ |
| 15659 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 15660 | breakpoint set."), |
| 15661 | &maintenanceinfolist); |
| 15662 | |
| 15663 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
| 15664 | Set catchpoints to catch events."), |
| 15665 | &catch_cmdlist, "catch ", |
| 15666 | 0/*allow-unknown*/, &cmdlist); |
| 15667 | |
| 15668 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ |
| 15669 | Set temporary catchpoints to catch events."), |
| 15670 | &tcatch_cmdlist, "tcatch ", |
| 15671 | 0/*allow-unknown*/, &cmdlist); |
| 15672 | |
| 15673 | add_catch_command ("fork", _("Catch calls to fork."), |
| 15674 | catch_fork_command_1, |
| 15675 | NULL, |
| 15676 | (void *) (uintptr_t) catch_fork_permanent, |
| 15677 | (void *) (uintptr_t) catch_fork_temporary); |
| 15678 | add_catch_command ("vfork", _("Catch calls to vfork."), |
| 15679 | catch_fork_command_1, |
| 15680 | NULL, |
| 15681 | (void *) (uintptr_t) catch_vfork_permanent, |
| 15682 | (void *) (uintptr_t) catch_vfork_temporary); |
| 15683 | add_catch_command ("exec", _("Catch calls to exec."), |
| 15684 | catch_exec_command_1, |
| 15685 | NULL, |
| 15686 | CATCH_PERMANENT, |
| 15687 | CATCH_TEMPORARY); |
| 15688 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
| 15689 | Usage: catch load [REGEX]\n\ |
| 15690 | If REGEX is given, only stop for libraries matching the regular expression."), |
| 15691 | catch_load_command_1, |
| 15692 | NULL, |
| 15693 | CATCH_PERMANENT, |
| 15694 | CATCH_TEMPORARY); |
| 15695 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ |
| 15696 | Usage: catch unload [REGEX]\n\ |
| 15697 | If REGEX is given, only stop for libraries matching the regular expression."), |
| 15698 | catch_unload_command_1, |
| 15699 | NULL, |
| 15700 | CATCH_PERMANENT, |
| 15701 | CATCH_TEMPORARY); |
| 15702 | |
| 15703 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
| 15704 | Set a watchpoint for an expression.\n\ |
| 15705 | Usage: watch [-l|-location] EXPRESSION\n\ |
| 15706 | A watchpoint stops execution of your program whenever the value of\n\ |
| 15707 | an expression changes.\n\ |
| 15708 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 15709 | the memory to which it refers.")); |
| 15710 | set_cmd_completer (c, expression_completer); |
| 15711 | |
| 15712 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
| 15713 | Set a read watchpoint for an expression.\n\ |
| 15714 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
| 15715 | A watchpoint stops execution of your program whenever the value of\n\ |
| 15716 | an expression is read.\n\ |
| 15717 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 15718 | the memory to which it refers.")); |
| 15719 | set_cmd_completer (c, expression_completer); |
| 15720 | |
| 15721 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
| 15722 | Set a watchpoint for an expression.\n\ |
| 15723 | Usage: awatch [-l|-location] EXPRESSION\n\ |
| 15724 | A watchpoint stops execution of your program whenever the value of\n\ |
| 15725 | an expression is either read or written.\n\ |
| 15726 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 15727 | the memory to which it refers.")); |
| 15728 | set_cmd_completer (c, expression_completer); |
| 15729 | |
| 15730 | add_info ("watchpoints", info_watchpoints_command, _("\ |
| 15731 | Status of specified watchpoints (all watchpoints if no argument).")); |
| 15732 | |
| 15733 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
| 15734 | respond to changes - contrary to the description. */ |
| 15735 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
| 15736 | &can_use_hw_watchpoints, _("\ |
| 15737 | Set debugger's willingness to use watchpoint hardware."), _("\ |
| 15738 | Show debugger's willingness to use watchpoint hardware."), _("\ |
| 15739 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
| 15740 | such is available. (However, any hardware watchpoints that were\n\ |
| 15741 | created before setting this to nonzero, will continue to use watchpoint\n\ |
| 15742 | hardware.)"), |
| 15743 | NULL, |
| 15744 | show_can_use_hw_watchpoints, |
| 15745 | &setlist, &showlist); |
| 15746 | |
| 15747 | can_use_hw_watchpoints = 1; |
| 15748 | |
| 15749 | /* Tracepoint manipulation commands. */ |
| 15750 | |
| 15751 | c = add_com ("trace", class_breakpoint, trace_command, _("\ |
| 15752 | Set a tracepoint at specified location.\n\ |
| 15753 | \n" |
| 15754 | BREAK_ARGS_HELP ("trace") "\n\ |
| 15755 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 15756 | set_cmd_completer (c, location_completer); |
| 15757 | |
| 15758 | add_com_alias ("tp", "trace", class_alias, 0); |
| 15759 | add_com_alias ("tr", "trace", class_alias, 1); |
| 15760 | add_com_alias ("tra", "trace", class_alias, 1); |
| 15761 | add_com_alias ("trac", "trace", class_alias, 1); |
| 15762 | |
| 15763 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
| 15764 | Set a fast tracepoint at specified location.\n\ |
| 15765 | \n" |
| 15766 | BREAK_ARGS_HELP ("ftrace") "\n\ |
| 15767 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 15768 | set_cmd_completer (c, location_completer); |
| 15769 | |
| 15770 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
| 15771 | Set a static tracepoint at location or marker.\n\ |
| 15772 | \n\ |
| 15773 | strace [LOCATION] [if CONDITION]\n\ |
| 15774 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
| 15775 | or -m MARKER_ID.\n\n\ |
| 15776 | If a marker id is specified, probe the marker with that name. With\n\ |
| 15777 | no LOCATION, uses current execution address of the selected stack frame.\n\ |
| 15778 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
| 15779 | This collects arbitrary user data passed in the probe point call to the\n\ |
| 15780 | tracing library. You can inspect it when analyzing the trace buffer,\n\ |
| 15781 | by printing the $_sdata variable like any other convenience variable.\n\ |
| 15782 | \n\ |
| 15783 | CONDITION is a boolean expression.\n\ |
| 15784 | \n" LOCATION_HELP_STRING "\n\n\ |
| 15785 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
| 15786 | conditions are different.\n\ |
| 15787 | \n\ |
| 15788 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ |
| 15789 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 15790 | set_cmd_completer (c, location_completer); |
| 15791 | |
| 15792 | add_info ("tracepoints", info_tracepoints_command, _("\ |
| 15793 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
| 15794 | Convenience variable \"$tpnum\" contains the number of the\n\ |
| 15795 | last tracepoint set.")); |
| 15796 | |
| 15797 | add_info_alias ("tp", "tracepoints", 1); |
| 15798 | |
| 15799 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ |
| 15800 | Delete specified tracepoints.\n\ |
| 15801 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 15802 | No argument means delete all tracepoints."), |
| 15803 | &deletelist); |
| 15804 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
| 15805 | |
| 15806 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ |
| 15807 | Disable specified tracepoints.\n\ |
| 15808 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 15809 | No argument means disable all tracepoints."), |
| 15810 | &disablelist); |
| 15811 | deprecate_cmd (c, "disable"); |
| 15812 | |
| 15813 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ |
| 15814 | Enable specified tracepoints.\n\ |
| 15815 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 15816 | No argument means enable all tracepoints."), |
| 15817 | &enablelist); |
| 15818 | deprecate_cmd (c, "enable"); |
| 15819 | |
| 15820 | add_com ("passcount", class_trace, trace_pass_command, _("\ |
| 15821 | Set the passcount for a tracepoint.\n\ |
| 15822 | The trace will end when the tracepoint has been passed 'count' times.\n\ |
| 15823 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ |
| 15824 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); |
| 15825 | |
| 15826 | add_prefix_cmd ("save", class_breakpoint, save_command, |
| 15827 | _("Save breakpoint definitions as a script."), |
| 15828 | &save_cmdlist, "save ", |
| 15829 | 0/*allow-unknown*/, &cmdlist); |
| 15830 | |
| 15831 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ |
| 15832 | Save current breakpoint definitions as a script.\n\ |
| 15833 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
| 15834 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
| 15835 | session to restore them."), |
| 15836 | &save_cmdlist); |
| 15837 | set_cmd_completer (c, filename_completer); |
| 15838 | |
| 15839 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ |
| 15840 | Save current tracepoint definitions as a script.\n\ |
| 15841 | Use the 'source' command in another debug session to restore them."), |
| 15842 | &save_cmdlist); |
| 15843 | set_cmd_completer (c, filename_completer); |
| 15844 | |
| 15845 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
| 15846 | deprecate_cmd (c, "save tracepoints"); |
| 15847 | |
| 15848 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
| 15849 | Breakpoint specific settings.\n\ |
| 15850 | Configure various breakpoint-specific variables such as\n\ |
| 15851 | pending breakpoint behavior."), |
| 15852 | &breakpoint_set_cmdlist, "set breakpoint ", |
| 15853 | 0/*allow-unknown*/, &setlist); |
| 15854 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
| 15855 | Breakpoint specific settings.\n\ |
| 15856 | Configure various breakpoint-specific variables such as\n\ |
| 15857 | pending breakpoint behavior."), |
| 15858 | &breakpoint_show_cmdlist, "show breakpoint ", |
| 15859 | 0/*allow-unknown*/, &showlist); |
| 15860 | |
| 15861 | add_setshow_auto_boolean_cmd ("pending", no_class, |
| 15862 | &pending_break_support, _("\ |
| 15863 | Set debugger's behavior regarding pending breakpoints."), _("\ |
| 15864 | Show debugger's behavior regarding pending breakpoints."), _("\ |
| 15865 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
| 15866 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ |
| 15867 | an error. If auto, an unrecognized breakpoint location results in a\n\ |
| 15868 | user-query to see if a pending breakpoint should be created."), |
| 15869 | NULL, |
| 15870 | show_pending_break_support, |
| 15871 | &breakpoint_set_cmdlist, |
| 15872 | &breakpoint_show_cmdlist); |
| 15873 | |
| 15874 | pending_break_support = AUTO_BOOLEAN_AUTO; |
| 15875 | |
| 15876 | add_setshow_boolean_cmd ("auto-hw", no_class, |
| 15877 | &automatic_hardware_breakpoints, _("\ |
| 15878 | Set automatic usage of hardware breakpoints."), _("\ |
| 15879 | Show automatic usage of hardware breakpoints."), _("\ |
| 15880 | If set, the debugger will automatically use hardware breakpoints for\n\ |
| 15881 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ |
| 15882 | a warning will be emitted for such breakpoints."), |
| 15883 | NULL, |
| 15884 | show_automatic_hardware_breakpoints, |
| 15885 | &breakpoint_set_cmdlist, |
| 15886 | &breakpoint_show_cmdlist); |
| 15887 | |
| 15888 | add_setshow_boolean_cmd ("always-inserted", class_support, |
| 15889 | &always_inserted_mode, _("\ |
| 15890 | Set mode for inserting breakpoints."), _("\ |
| 15891 | Show mode for inserting breakpoints."), _("\ |
| 15892 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
| 15893 | they're created, kept inserted even when execution stops, and removed\n\ |
| 15894 | only when the user deletes them. When this mode is off (the default),\n\ |
| 15895 | breakpoints are inserted only when execution continues, and removed\n\ |
| 15896 | when execution stops."), |
| 15897 | NULL, |
| 15898 | &show_always_inserted_mode, |
| 15899 | &breakpoint_set_cmdlist, |
| 15900 | &breakpoint_show_cmdlist); |
| 15901 | |
| 15902 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
| 15903 | condition_evaluation_enums, |
| 15904 | &condition_evaluation_mode_1, _("\ |
| 15905 | Set mode of breakpoint condition evaluation."), _("\ |
| 15906 | Show mode of breakpoint condition evaluation."), _("\ |
| 15907 | When this is set to \"host\", breakpoint conditions will be\n\ |
| 15908 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
| 15909 | breakpoint conditions will be downloaded to the target (if the target\n\ |
| 15910 | supports such feature) and conditions will be evaluated on the target's side.\n\ |
| 15911 | If this is set to \"auto\" (default), this will be automatically set to\n\ |
| 15912 | \"target\" if it supports condition evaluation, otherwise it will\n\ |
| 15913 | be set to \"gdb\""), |
| 15914 | &set_condition_evaluation_mode, |
| 15915 | &show_condition_evaluation_mode, |
| 15916 | &breakpoint_set_cmdlist, |
| 15917 | &breakpoint_show_cmdlist); |
| 15918 | |
| 15919 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
| 15920 | Set a breakpoint for an address range.\n\ |
| 15921 | break-range START-LOCATION, END-LOCATION\n\ |
| 15922 | where START-LOCATION and END-LOCATION can be one of the following:\n\ |
| 15923 | LINENUM, for that line in the current file,\n\ |
| 15924 | FILE:LINENUM, for that line in that file,\n\ |
| 15925 | +OFFSET, for that number of lines after the current line\n\ |
| 15926 | or the start of the range\n\ |
| 15927 | FUNCTION, for the first line in that function,\n\ |
| 15928 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ |
| 15929 | *ADDRESS, for the instruction at that address.\n\ |
| 15930 | \n\ |
| 15931 | The breakpoint will stop execution of the inferior whenever it executes\n\ |
| 15932 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ |
| 15933 | range (including START-LOCATION and END-LOCATION).")); |
| 15934 | |
| 15935 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
| 15936 | Set a dynamic printf at specified location.\n\ |
| 15937 | dprintf location,format string,arg1,arg2,...\n\ |
| 15938 | location may be a linespec, explicit, or address location.\n" |
| 15939 | "\n" LOCATION_HELP_STRING)); |
| 15940 | set_cmd_completer (c, location_completer); |
| 15941 | |
| 15942 | add_setshow_enum_cmd ("dprintf-style", class_support, |
| 15943 | dprintf_style_enums, &dprintf_style, _("\ |
| 15944 | Set the style of usage for dynamic printf."), _("\ |
| 15945 | Show the style of usage for dynamic printf."), _("\ |
| 15946 | This setting chooses how GDB will do a dynamic printf.\n\ |
| 15947 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ |
| 15948 | console, as with the \"printf\" command.\n\ |
| 15949 | If the value is \"call\", the print is done by calling a function in your\n\ |
| 15950 | program; by default printf(), but you can choose a different function or\n\ |
| 15951 | output stream by setting dprintf-function and dprintf-channel."), |
| 15952 | update_dprintf_commands, NULL, |
| 15953 | &setlist, &showlist); |
| 15954 | |
| 15955 | dprintf_function = xstrdup ("printf"); |
| 15956 | add_setshow_string_cmd ("dprintf-function", class_support, |
| 15957 | &dprintf_function, _("\ |
| 15958 | Set the function to use for dynamic printf."), _("\ |
| 15959 | Show the function to use for dynamic printf."), NULL, |
| 15960 | update_dprintf_commands, NULL, |
| 15961 | &setlist, &showlist); |
| 15962 | |
| 15963 | dprintf_channel = xstrdup (""); |
| 15964 | add_setshow_string_cmd ("dprintf-channel", class_support, |
| 15965 | &dprintf_channel, _("\ |
| 15966 | Set the channel to use for dynamic printf."), _("\ |
| 15967 | Show the channel to use for dynamic printf."), NULL, |
| 15968 | update_dprintf_commands, NULL, |
| 15969 | &setlist, &showlist); |
| 15970 | |
| 15971 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
| 15972 | &disconnected_dprintf, _("\ |
| 15973 | Set whether dprintf continues after GDB disconnects."), _("\ |
| 15974 | Show whether dprintf continues after GDB disconnects."), _("\ |
| 15975 | Use this to let dprintf commands continue to hit and produce output\n\ |
| 15976 | even if GDB disconnects or detaches from the target."), |
| 15977 | NULL, |
| 15978 | NULL, |
| 15979 | &setlist, &showlist); |
| 15980 | |
| 15981 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ |
| 15982 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
| 15983 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ |
| 15984 | This supports most C printf format specifications, like %s, %d, etc.\n\ |
| 15985 | This is useful for formatted output in user-defined commands.")); |
| 15986 | |
| 15987 | automatic_hardware_breakpoints = true; |
| 15988 | |
| 15989 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
| 15990 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); |
| 15991 | } |