| 1 | /* Everything about breakpoints, for GDB. |
| 2 | |
| 3 | Copyright (C) 1986-2019 Free Software Foundation, Inc. |
| 4 | |
| 5 | This file is part of GDB. |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 3 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 | |
| 20 | #include "defs.h" |
| 21 | #include "arch-utils.h" |
| 22 | #include <ctype.h> |
| 23 | #include "hashtab.h" |
| 24 | #include "symtab.h" |
| 25 | #include "frame.h" |
| 26 | #include "breakpoint.h" |
| 27 | #include "tracepoint.h" |
| 28 | #include "gdbtypes.h" |
| 29 | #include "expression.h" |
| 30 | #include "gdbcore.h" |
| 31 | #include "gdbcmd.h" |
| 32 | #include "value.h" |
| 33 | #include "command.h" |
| 34 | #include "inferior.h" |
| 35 | #include "infrun.h" |
| 36 | #include "gdbthread.h" |
| 37 | #include "target.h" |
| 38 | #include "language.h" |
| 39 | #include "gdb-demangle.h" |
| 40 | #include "filenames.h" |
| 41 | #include "annotate.h" |
| 42 | #include "symfile.h" |
| 43 | #include "objfiles.h" |
| 44 | #include "source.h" |
| 45 | #include "linespec.h" |
| 46 | #include "completer.h" |
| 47 | #include "ui-out.h" |
| 48 | #include "cli/cli-script.h" |
| 49 | #include "block.h" |
| 50 | #include "solib.h" |
| 51 | #include "solist.h" |
| 52 | #include "observable.h" |
| 53 | #include "memattr.h" |
| 54 | #include "ada-lang.h" |
| 55 | #include "top.h" |
| 56 | #include "valprint.h" |
| 57 | #include "jit.h" |
| 58 | #include "parser-defs.h" |
| 59 | #include "gdb_regex.h" |
| 60 | #include "probe.h" |
| 61 | #include "cli/cli-utils.h" |
| 62 | #include "stack.h" |
| 63 | #include "ax-gdb.h" |
| 64 | #include "dummy-frame.h" |
| 65 | #include "interps.h" |
| 66 | #include "gdbsupport/format.h" |
| 67 | #include "thread-fsm.h" |
| 68 | #include "tid-parse.h" |
| 69 | #include "cli/cli-style.h" |
| 70 | |
| 71 | /* readline include files */ |
| 72 | #include "readline/tilde.h" |
| 73 | |
| 74 | /* readline defines this. */ |
| 75 | #undef savestring |
| 76 | |
| 77 | #include "mi/mi-common.h" |
| 78 | #include "extension.h" |
| 79 | #include <algorithm> |
| 80 | #include "progspace-and-thread.h" |
| 81 | #include "gdbsupport/array-view.h" |
| 82 | #include "gdbsupport/gdb_optional.h" |
| 83 | |
| 84 | /* Prototypes for local functions. */ |
| 85 | |
| 86 | static void map_breakpoint_numbers (const char *, |
| 87 | gdb::function_view<void (breakpoint *)>); |
| 88 | |
| 89 | static void breakpoint_re_set_default (struct breakpoint *); |
| 90 | |
| 91 | static void |
| 92 | create_sals_from_location_default (const struct event_location *location, |
| 93 | struct linespec_result *canonical, |
| 94 | enum bptype type_wanted); |
| 95 | |
| 96 | static void create_breakpoints_sal_default (struct gdbarch *, |
| 97 | struct linespec_result *, |
| 98 | gdb::unique_xmalloc_ptr<char>, |
| 99 | gdb::unique_xmalloc_ptr<char>, |
| 100 | enum bptype, |
| 101 | enum bpdisp, int, int, |
| 102 | int, |
| 103 | const struct breakpoint_ops *, |
| 104 | int, int, int, unsigned); |
| 105 | |
| 106 | static std::vector<symtab_and_line> decode_location_default |
| 107 | (struct breakpoint *b, const struct event_location *location, |
| 108 | struct program_space *search_pspace); |
| 109 | |
| 110 | static int can_use_hardware_watchpoint |
| 111 | (const std::vector<value_ref_ptr> &vals); |
| 112 | |
| 113 | static void mention (struct breakpoint *); |
| 114 | |
| 115 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
| 116 | enum bptype, |
| 117 | const struct breakpoint_ops *); |
| 118 | static struct bp_location *add_location_to_breakpoint (struct breakpoint *, |
| 119 | const struct symtab_and_line *); |
| 120 | |
| 121 | /* This function is used in gdbtk sources and thus can not be made |
| 122 | static. */ |
| 123 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
| 124 | struct symtab_and_line, |
| 125 | enum bptype, |
| 126 | const struct breakpoint_ops *); |
| 127 | |
| 128 | static struct breakpoint * |
| 129 | momentary_breakpoint_from_master (struct breakpoint *orig, |
| 130 | enum bptype type, |
| 131 | const struct breakpoint_ops *ops, |
| 132 | int loc_enabled); |
| 133 | |
| 134 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
| 135 | |
| 136 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 137 | CORE_ADDR bpaddr, |
| 138 | enum bptype bptype); |
| 139 | |
| 140 | static void describe_other_breakpoints (struct gdbarch *, |
| 141 | struct program_space *, CORE_ADDR, |
| 142 | struct obj_section *, int); |
| 143 | |
| 144 | static int watchpoint_locations_match (struct bp_location *loc1, |
| 145 | struct bp_location *loc2); |
| 146 | |
| 147 | static int breakpoint_location_address_match (struct bp_location *bl, |
| 148 | const struct address_space *aspace, |
| 149 | CORE_ADDR addr); |
| 150 | |
| 151 | static int breakpoint_location_address_range_overlap (struct bp_location *, |
| 152 | const address_space *, |
| 153 | CORE_ADDR, int); |
| 154 | |
| 155 | static int remove_breakpoint (struct bp_location *); |
| 156 | static int remove_breakpoint_1 (struct bp_location *, enum remove_bp_reason); |
| 157 | |
| 158 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
| 159 | |
| 160 | static int hw_breakpoint_used_count (void); |
| 161 | |
| 162 | static int hw_watchpoint_use_count (struct breakpoint *); |
| 163 | |
| 164 | static int hw_watchpoint_used_count_others (struct breakpoint *except, |
| 165 | enum bptype type, |
| 166 | int *other_type_used); |
| 167 | |
| 168 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp, |
| 169 | int count); |
| 170 | |
| 171 | static void free_bp_location (struct bp_location *loc); |
| 172 | static void incref_bp_location (struct bp_location *loc); |
| 173 | static void decref_bp_location (struct bp_location **loc); |
| 174 | |
| 175 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
| 176 | |
| 177 | /* update_global_location_list's modes of operation wrt to whether to |
| 178 | insert locations now. */ |
| 179 | enum ugll_insert_mode |
| 180 | { |
| 181 | /* Don't insert any breakpoint locations into the inferior, only |
| 182 | remove already-inserted locations that no longer should be |
| 183 | inserted. Functions that delete a breakpoint or breakpoints |
| 184 | should specify this mode, so that deleting a breakpoint doesn't |
| 185 | have the side effect of inserting the locations of other |
| 186 | breakpoints that are marked not-inserted, but should_be_inserted |
| 187 | returns true on them. |
| 188 | |
| 189 | This behavior is useful is situations close to tear-down -- e.g., |
| 190 | after an exec, while the target still has execution, but |
| 191 | breakpoint shadows of the previous executable image should *NOT* |
| 192 | be restored to the new image; or before detaching, where the |
| 193 | target still has execution and wants to delete breakpoints from |
| 194 | GDB's lists, and all breakpoints had already been removed from |
| 195 | the inferior. */ |
| 196 | UGLL_DONT_INSERT, |
| 197 | |
| 198 | /* May insert breakpoints iff breakpoints_should_be_inserted_now |
| 199 | claims breakpoints should be inserted now. */ |
| 200 | UGLL_MAY_INSERT, |
| 201 | |
| 202 | /* Insert locations now, irrespective of |
| 203 | breakpoints_should_be_inserted_now. E.g., say all threads are |
| 204 | stopped right now, and the user did "continue". We need to |
| 205 | insert breakpoints _before_ resuming the target, but |
| 206 | UGLL_MAY_INSERT wouldn't insert them, because |
| 207 | breakpoints_should_be_inserted_now returns false at that point, |
| 208 | as no thread is running yet. */ |
| 209 | UGLL_INSERT |
| 210 | }; |
| 211 | |
| 212 | static void update_global_location_list (enum ugll_insert_mode); |
| 213 | |
| 214 | static void update_global_location_list_nothrow (enum ugll_insert_mode); |
| 215 | |
| 216 | static void insert_breakpoint_locations (void); |
| 217 | |
| 218 | static void trace_pass_command (const char *, int); |
| 219 | |
| 220 | static void set_tracepoint_count (int num); |
| 221 | |
| 222 | static bool is_masked_watchpoint (const struct breakpoint *b); |
| 223 | |
| 224 | static struct bp_location **get_first_locp_gte_addr (CORE_ADDR address); |
| 225 | |
| 226 | /* Return 1 if B refers to a static tracepoint set by marker ("-m"), zero |
| 227 | otherwise. */ |
| 228 | |
| 229 | static int strace_marker_p (struct breakpoint *b); |
| 230 | |
| 231 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops |
| 232 | that are implemented on top of software or hardware breakpoints |
| 233 | (user breakpoints, internal and momentary breakpoints, etc.). */ |
| 234 | static struct breakpoint_ops bkpt_base_breakpoint_ops; |
| 235 | |
| 236 | /* Internal breakpoints class type. */ |
| 237 | static struct breakpoint_ops internal_breakpoint_ops; |
| 238 | |
| 239 | /* Momentary breakpoints class type. */ |
| 240 | static struct breakpoint_ops momentary_breakpoint_ops; |
| 241 | |
| 242 | /* The breakpoint_ops structure to be used in regular user created |
| 243 | breakpoints. */ |
| 244 | struct breakpoint_ops bkpt_breakpoint_ops; |
| 245 | |
| 246 | /* Breakpoints set on probes. */ |
| 247 | static struct breakpoint_ops bkpt_probe_breakpoint_ops; |
| 248 | |
| 249 | /* Dynamic printf class type. */ |
| 250 | struct breakpoint_ops dprintf_breakpoint_ops; |
| 251 | |
| 252 | /* The style in which to perform a dynamic printf. This is a user |
| 253 | option because different output options have different tradeoffs; |
| 254 | if GDB does the printing, there is better error handling if there |
| 255 | is a problem with any of the arguments, but using an inferior |
| 256 | function lets you have special-purpose printers and sending of |
| 257 | output to the same place as compiled-in print functions. */ |
| 258 | |
| 259 | static const char dprintf_style_gdb[] = "gdb"; |
| 260 | static const char dprintf_style_call[] = "call"; |
| 261 | static const char dprintf_style_agent[] = "agent"; |
| 262 | static const char *const dprintf_style_enums[] = { |
| 263 | dprintf_style_gdb, |
| 264 | dprintf_style_call, |
| 265 | dprintf_style_agent, |
| 266 | NULL |
| 267 | }; |
| 268 | static const char *dprintf_style = dprintf_style_gdb; |
| 269 | |
| 270 | /* The function to use for dynamic printf if the preferred style is to |
| 271 | call into the inferior. The value is simply a string that is |
| 272 | copied into the command, so it can be anything that GDB can |
| 273 | evaluate to a callable address, not necessarily a function name. */ |
| 274 | |
| 275 | static char *dprintf_function; |
| 276 | |
| 277 | /* The channel to use for dynamic printf if the preferred style is to |
| 278 | call into the inferior; if a nonempty string, it will be passed to |
| 279 | the call as the first argument, with the format string as the |
| 280 | second. As with the dprintf function, this can be anything that |
| 281 | GDB knows how to evaluate, so in addition to common choices like |
| 282 | "stderr", this could be an app-specific expression like |
| 283 | "mystreams[curlogger]". */ |
| 284 | |
| 285 | static char *dprintf_channel; |
| 286 | |
| 287 | /* True if dprintf commands should continue to operate even if GDB |
| 288 | has disconnected. */ |
| 289 | static bool disconnected_dprintf = true; |
| 290 | |
| 291 | struct command_line * |
| 292 | breakpoint_commands (struct breakpoint *b) |
| 293 | { |
| 294 | return b->commands ? b->commands.get () : NULL; |
| 295 | } |
| 296 | |
| 297 | /* Flag indicating that a command has proceeded the inferior past the |
| 298 | current breakpoint. */ |
| 299 | |
| 300 | static bool breakpoint_proceeded; |
| 301 | |
| 302 | const char * |
| 303 | bpdisp_text (enum bpdisp disp) |
| 304 | { |
| 305 | /* NOTE: the following values are a part of MI protocol and |
| 306 | represent values of 'disp' field returned when inferior stops at |
| 307 | a breakpoint. */ |
| 308 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
| 309 | |
| 310 | return bpdisps[(int) disp]; |
| 311 | } |
| 312 | |
| 313 | /* Prototypes for exported functions. */ |
| 314 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
| 315 | if such is available. */ |
| 316 | static int can_use_hw_watchpoints; |
| 317 | |
| 318 | static void |
| 319 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, |
| 320 | struct cmd_list_element *c, |
| 321 | const char *value) |
| 322 | { |
| 323 | fprintf_filtered (file, |
| 324 | _("Debugger's willingness to use " |
| 325 | "watchpoint hardware is %s.\n"), |
| 326 | value); |
| 327 | } |
| 328 | |
| 329 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
| 330 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints |
| 331 | for unrecognized breakpoint locations. |
| 332 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
| 333 | static enum auto_boolean pending_break_support; |
| 334 | static void |
| 335 | show_pending_break_support (struct ui_file *file, int from_tty, |
| 336 | struct cmd_list_element *c, |
| 337 | const char *value) |
| 338 | { |
| 339 | fprintf_filtered (file, |
| 340 | _("Debugger's behavior regarding " |
| 341 | "pending breakpoints is %s.\n"), |
| 342 | value); |
| 343 | } |
| 344 | |
| 345 | /* If true, gdb will automatically use hardware breakpoints for breakpoints |
| 346 | set with "break" but falling in read-only memory. |
| 347 | If false, gdb will warn about such breakpoints, but won't automatically |
| 348 | use hardware breakpoints. */ |
| 349 | static bool automatic_hardware_breakpoints; |
| 350 | static void |
| 351 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, |
| 352 | struct cmd_list_element *c, |
| 353 | const char *value) |
| 354 | { |
| 355 | fprintf_filtered (file, |
| 356 | _("Automatic usage of hardware breakpoints is %s.\n"), |
| 357 | value); |
| 358 | } |
| 359 | |
| 360 | /* If on, GDB keeps breakpoints inserted even if the inferior is |
| 361 | stopped, and immediately inserts any new breakpoints as soon as |
| 362 | they're created. If off (default), GDB keeps breakpoints off of |
| 363 | the target as long as possible. That is, it delays inserting |
| 364 | breakpoints until the next resume, and removes them again when the |
| 365 | target fully stops. This is a bit safer in case GDB crashes while |
| 366 | processing user input. */ |
| 367 | static bool always_inserted_mode = false; |
| 368 | |
| 369 | static void |
| 370 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
| 371 | struct cmd_list_element *c, const char *value) |
| 372 | { |
| 373 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
| 374 | value); |
| 375 | } |
| 376 | |
| 377 | /* See breakpoint.h. */ |
| 378 | |
| 379 | int |
| 380 | breakpoints_should_be_inserted_now (void) |
| 381 | { |
| 382 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
| 383 | { |
| 384 | /* If breakpoints are global, they should be inserted even if no |
| 385 | thread under gdb's control is running, or even if there are |
| 386 | no threads under GDB's control yet. */ |
| 387 | return 1; |
| 388 | } |
| 389 | else if (target_has_execution) |
| 390 | { |
| 391 | if (always_inserted_mode) |
| 392 | { |
| 393 | /* The user wants breakpoints inserted even if all threads |
| 394 | are stopped. */ |
| 395 | return 1; |
| 396 | } |
| 397 | |
| 398 | if (threads_are_executing ()) |
| 399 | return 1; |
| 400 | |
| 401 | /* Don't remove breakpoints yet if, even though all threads are |
| 402 | stopped, we still have events to process. */ |
| 403 | for (thread_info *tp : all_non_exited_threads ()) |
| 404 | if (tp->resumed |
| 405 | && tp->suspend.waitstatus_pending_p) |
| 406 | return 1; |
| 407 | } |
| 408 | return 0; |
| 409 | } |
| 410 | |
| 411 | static const char condition_evaluation_both[] = "host or target"; |
| 412 | |
| 413 | /* Modes for breakpoint condition evaluation. */ |
| 414 | static const char condition_evaluation_auto[] = "auto"; |
| 415 | static const char condition_evaluation_host[] = "host"; |
| 416 | static const char condition_evaluation_target[] = "target"; |
| 417 | static const char *const condition_evaluation_enums[] = { |
| 418 | condition_evaluation_auto, |
| 419 | condition_evaluation_host, |
| 420 | condition_evaluation_target, |
| 421 | NULL |
| 422 | }; |
| 423 | |
| 424 | /* Global that holds the current mode for breakpoint condition evaluation. */ |
| 425 | static const char *condition_evaluation_mode_1 = condition_evaluation_auto; |
| 426 | |
| 427 | /* Global that we use to display information to the user (gets its value from |
| 428 | condition_evaluation_mode_1. */ |
| 429 | static const char *condition_evaluation_mode = condition_evaluation_auto; |
| 430 | |
| 431 | /* Translate a condition evaluation mode MODE into either "host" |
| 432 | or "target". This is used mostly to translate from "auto" to the |
| 433 | real setting that is being used. It returns the translated |
| 434 | evaluation mode. */ |
| 435 | |
| 436 | static const char * |
| 437 | translate_condition_evaluation_mode (const char *mode) |
| 438 | { |
| 439 | if (mode == condition_evaluation_auto) |
| 440 | { |
| 441 | if (target_supports_evaluation_of_breakpoint_conditions ()) |
| 442 | return condition_evaluation_target; |
| 443 | else |
| 444 | return condition_evaluation_host; |
| 445 | } |
| 446 | else |
| 447 | return mode; |
| 448 | } |
| 449 | |
| 450 | /* Discovers what condition_evaluation_auto translates to. */ |
| 451 | |
| 452 | static const char * |
| 453 | breakpoint_condition_evaluation_mode (void) |
| 454 | { |
| 455 | return translate_condition_evaluation_mode (condition_evaluation_mode); |
| 456 | } |
| 457 | |
| 458 | /* Return true if GDB should evaluate breakpoint conditions or false |
| 459 | otherwise. */ |
| 460 | |
| 461 | static int |
| 462 | gdb_evaluates_breakpoint_condition_p (void) |
| 463 | { |
| 464 | const char *mode = breakpoint_condition_evaluation_mode (); |
| 465 | |
| 466 | return (mode == condition_evaluation_host); |
| 467 | } |
| 468 | |
| 469 | /* Are we executing breakpoint commands? */ |
| 470 | static int executing_breakpoint_commands; |
| 471 | |
| 472 | /* Are overlay event breakpoints enabled? */ |
| 473 | static int overlay_events_enabled; |
| 474 | |
| 475 | /* See description in breakpoint.h. */ |
| 476 | bool target_exact_watchpoints = false; |
| 477 | |
| 478 | /* Walk the following statement or block through all breakpoints. |
| 479 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
| 480 | current breakpoint. */ |
| 481 | |
| 482 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
| 483 | |
| 484 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
| 485 | for (B = breakpoint_chain; \ |
| 486 | B ? (TMP=B->next, 1): 0; \ |
| 487 | B = TMP) |
| 488 | |
| 489 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
| 490 | not provided so update_global_location_list must not be called |
| 491 | while executing the block of ALL_BP_LOCATIONS. */ |
| 492 | |
| 493 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
| 494 | for (BP_TMP = bp_locations; \ |
| 495 | BP_TMP < bp_locations + bp_locations_count && (B = *BP_TMP);\ |
| 496 | BP_TMP++) |
| 497 | |
| 498 | /* Iterates through locations with address ADDRESS for the currently selected |
| 499 | program space. BP_LOCP_TMP points to each object. BP_LOCP_START points |
| 500 | to where the loop should start from. |
| 501 | If BP_LOCP_START is a NULL pointer, the macro automatically seeks the |
| 502 | appropriate location to start with. */ |
| 503 | |
| 504 | #define ALL_BP_LOCATIONS_AT_ADDR(BP_LOCP_TMP, BP_LOCP_START, ADDRESS) \ |
| 505 | for (BP_LOCP_START = BP_LOCP_START == NULL ? get_first_locp_gte_addr (ADDRESS) : BP_LOCP_START, \ |
| 506 | BP_LOCP_TMP = BP_LOCP_START; \ |
| 507 | BP_LOCP_START \ |
| 508 | && (BP_LOCP_TMP < bp_locations + bp_locations_count \ |
| 509 | && (*BP_LOCP_TMP)->address == ADDRESS); \ |
| 510 | BP_LOCP_TMP++) |
| 511 | |
| 512 | /* Iterator for tracepoints only. */ |
| 513 | |
| 514 | #define ALL_TRACEPOINTS(B) \ |
| 515 | for (B = breakpoint_chain; B; B = B->next) \ |
| 516 | if (is_tracepoint (B)) |
| 517 | |
| 518 | /* Chains of all breakpoints defined. */ |
| 519 | |
| 520 | static struct breakpoint *breakpoint_chain; |
| 521 | |
| 522 | /* Array is sorted by bp_locations_compare - primarily by the ADDRESS. */ |
| 523 | |
| 524 | static struct bp_location **bp_locations; |
| 525 | |
| 526 | /* Number of elements of BP_LOCATIONS. */ |
| 527 | |
| 528 | static unsigned bp_locations_count; |
| 529 | |
| 530 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
| 531 | ADDRESS for the current elements of BP_LOCATIONS which get a valid |
| 532 | result from bp_location_has_shadow. You can use it for roughly |
| 533 | limiting the subrange of BP_LOCATIONS to scan for shadow bytes for |
| 534 | an address you need to read. */ |
| 535 | |
| 536 | static CORE_ADDR bp_locations_placed_address_before_address_max; |
| 537 | |
| 538 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
| 539 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of |
| 540 | BP_LOCATIONS which get a valid result from bp_location_has_shadow. |
| 541 | You can use it for roughly limiting the subrange of BP_LOCATIONS to |
| 542 | scan for shadow bytes for an address you need to read. */ |
| 543 | |
| 544 | static CORE_ADDR bp_locations_shadow_len_after_address_max; |
| 545 | |
| 546 | /* The locations that no longer correspond to any breakpoint, unlinked |
| 547 | from the bp_locations array, but for which a hit may still be |
| 548 | reported by a target. */ |
| 549 | static std::vector<bp_location *> moribund_locations; |
| 550 | |
| 551 | /* Number of last breakpoint made. */ |
| 552 | |
| 553 | static int breakpoint_count; |
| 554 | |
| 555 | /* The value of `breakpoint_count' before the last command that |
| 556 | created breakpoints. If the last (break-like) command created more |
| 557 | than one breakpoint, then the difference between BREAKPOINT_COUNT |
| 558 | and PREV_BREAKPOINT_COUNT is more than one. */ |
| 559 | static int prev_breakpoint_count; |
| 560 | |
| 561 | /* Number of last tracepoint made. */ |
| 562 | |
| 563 | static int tracepoint_count; |
| 564 | |
| 565 | static struct cmd_list_element *breakpoint_set_cmdlist; |
| 566 | static struct cmd_list_element *breakpoint_show_cmdlist; |
| 567 | struct cmd_list_element *save_cmdlist; |
| 568 | |
| 569 | /* See declaration at breakpoint.h. */ |
| 570 | |
| 571 | struct breakpoint * |
| 572 | breakpoint_find_if (int (*func) (struct breakpoint *b, void *d), |
| 573 | void *user_data) |
| 574 | { |
| 575 | struct breakpoint *b = NULL; |
| 576 | |
| 577 | ALL_BREAKPOINTS (b) |
| 578 | { |
| 579 | if (func (b, user_data) != 0) |
| 580 | break; |
| 581 | } |
| 582 | |
| 583 | return b; |
| 584 | } |
| 585 | |
| 586 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
| 587 | static int |
| 588 | breakpoint_enabled (struct breakpoint *b) |
| 589 | { |
| 590 | return (b->enable_state == bp_enabled); |
| 591 | } |
| 592 | |
| 593 | /* Set breakpoint count to NUM. */ |
| 594 | |
| 595 | static void |
| 596 | set_breakpoint_count (int num) |
| 597 | { |
| 598 | prev_breakpoint_count = breakpoint_count; |
| 599 | breakpoint_count = num; |
| 600 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
| 601 | } |
| 602 | |
| 603 | /* Used by `start_rbreak_breakpoints' below, to record the current |
| 604 | breakpoint count before "rbreak" creates any breakpoint. */ |
| 605 | static int rbreak_start_breakpoint_count; |
| 606 | |
| 607 | /* Called at the start an "rbreak" command to record the first |
| 608 | breakpoint made. */ |
| 609 | |
| 610 | scoped_rbreak_breakpoints::scoped_rbreak_breakpoints () |
| 611 | { |
| 612 | rbreak_start_breakpoint_count = breakpoint_count; |
| 613 | } |
| 614 | |
| 615 | /* Called at the end of an "rbreak" command to record the last |
| 616 | breakpoint made. */ |
| 617 | |
| 618 | scoped_rbreak_breakpoints::~scoped_rbreak_breakpoints () |
| 619 | { |
| 620 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
| 621 | } |
| 622 | |
| 623 | /* Used in run_command to zero the hit count when a new run starts. */ |
| 624 | |
| 625 | void |
| 626 | clear_breakpoint_hit_counts (void) |
| 627 | { |
| 628 | struct breakpoint *b; |
| 629 | |
| 630 | ALL_BREAKPOINTS (b) |
| 631 | b->hit_count = 0; |
| 632 | } |
| 633 | |
| 634 | \f |
| 635 | /* Return the breakpoint with the specified number, or NULL |
| 636 | if the number does not refer to an existing breakpoint. */ |
| 637 | |
| 638 | struct breakpoint * |
| 639 | get_breakpoint (int num) |
| 640 | { |
| 641 | struct breakpoint *b; |
| 642 | |
| 643 | ALL_BREAKPOINTS (b) |
| 644 | if (b->number == num) |
| 645 | return b; |
| 646 | |
| 647 | return NULL; |
| 648 | } |
| 649 | |
| 650 | \f |
| 651 | |
| 652 | /* Mark locations as "conditions have changed" in case the target supports |
| 653 | evaluating conditions on its side. */ |
| 654 | |
| 655 | static void |
| 656 | mark_breakpoint_modified (struct breakpoint *b) |
| 657 | { |
| 658 | struct bp_location *loc; |
| 659 | |
| 660 | /* This is only meaningful if the target is |
| 661 | evaluating conditions and if the user has |
| 662 | opted for condition evaluation on the target's |
| 663 | side. */ |
| 664 | if (gdb_evaluates_breakpoint_condition_p () |
| 665 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 666 | return; |
| 667 | |
| 668 | if (!is_breakpoint (b)) |
| 669 | return; |
| 670 | |
| 671 | for (loc = b->loc; loc; loc = loc->next) |
| 672 | loc->condition_changed = condition_modified; |
| 673 | } |
| 674 | |
| 675 | /* Mark location as "conditions have changed" in case the target supports |
| 676 | evaluating conditions on its side. */ |
| 677 | |
| 678 | static void |
| 679 | mark_breakpoint_location_modified (struct bp_location *loc) |
| 680 | { |
| 681 | /* This is only meaningful if the target is |
| 682 | evaluating conditions and if the user has |
| 683 | opted for condition evaluation on the target's |
| 684 | side. */ |
| 685 | if (gdb_evaluates_breakpoint_condition_p () |
| 686 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 687 | |
| 688 | return; |
| 689 | |
| 690 | if (!is_breakpoint (loc->owner)) |
| 691 | return; |
| 692 | |
| 693 | loc->condition_changed = condition_modified; |
| 694 | } |
| 695 | |
| 696 | /* Sets the condition-evaluation mode using the static global |
| 697 | condition_evaluation_mode. */ |
| 698 | |
| 699 | static void |
| 700 | set_condition_evaluation_mode (const char *args, int from_tty, |
| 701 | struct cmd_list_element *c) |
| 702 | { |
| 703 | const char *old_mode, *new_mode; |
| 704 | |
| 705 | if ((condition_evaluation_mode_1 == condition_evaluation_target) |
| 706 | && !target_supports_evaluation_of_breakpoint_conditions ()) |
| 707 | { |
| 708 | condition_evaluation_mode_1 = condition_evaluation_mode; |
| 709 | warning (_("Target does not support breakpoint condition evaluation.\n" |
| 710 | "Using host evaluation mode instead.")); |
| 711 | return; |
| 712 | } |
| 713 | |
| 714 | new_mode = translate_condition_evaluation_mode (condition_evaluation_mode_1); |
| 715 | old_mode = translate_condition_evaluation_mode (condition_evaluation_mode); |
| 716 | |
| 717 | /* Flip the switch. Flip it even if OLD_MODE == NEW_MODE as one of the |
| 718 | settings was "auto". */ |
| 719 | condition_evaluation_mode = condition_evaluation_mode_1; |
| 720 | |
| 721 | /* Only update the mode if the user picked a different one. */ |
| 722 | if (new_mode != old_mode) |
| 723 | { |
| 724 | struct bp_location *loc, **loc_tmp; |
| 725 | /* If the user switched to a different evaluation mode, we |
| 726 | need to synch the changes with the target as follows: |
| 727 | |
| 728 | "host" -> "target": Send all (valid) conditions to the target. |
| 729 | "target" -> "host": Remove all the conditions from the target. |
| 730 | */ |
| 731 | |
| 732 | if (new_mode == condition_evaluation_target) |
| 733 | { |
| 734 | /* Mark everything modified and synch conditions with the |
| 735 | target. */ |
| 736 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 737 | mark_breakpoint_location_modified (loc); |
| 738 | } |
| 739 | else |
| 740 | { |
| 741 | /* Manually mark non-duplicate locations to synch conditions |
| 742 | with the target. We do this to remove all the conditions the |
| 743 | target knows about. */ |
| 744 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 745 | if (is_breakpoint (loc->owner) && loc->inserted) |
| 746 | loc->needs_update = 1; |
| 747 | } |
| 748 | |
| 749 | /* Do the update. */ |
| 750 | update_global_location_list (UGLL_MAY_INSERT); |
| 751 | } |
| 752 | |
| 753 | return; |
| 754 | } |
| 755 | |
| 756 | /* Shows the current mode of breakpoint condition evaluation. Explicitly shows |
| 757 | what "auto" is translating to. */ |
| 758 | |
| 759 | static void |
| 760 | show_condition_evaluation_mode (struct ui_file *file, int from_tty, |
| 761 | struct cmd_list_element *c, const char *value) |
| 762 | { |
| 763 | if (condition_evaluation_mode == condition_evaluation_auto) |
| 764 | fprintf_filtered (file, |
| 765 | _("Breakpoint condition evaluation " |
| 766 | "mode is %s (currently %s).\n"), |
| 767 | value, |
| 768 | breakpoint_condition_evaluation_mode ()); |
| 769 | else |
| 770 | fprintf_filtered (file, _("Breakpoint condition evaluation mode is %s.\n"), |
| 771 | value); |
| 772 | } |
| 773 | |
| 774 | /* A comparison function for bp_location AP and BP that is used by |
| 775 | bsearch. This comparison function only cares about addresses, unlike |
| 776 | the more general bp_locations_compare function. */ |
| 777 | |
| 778 | static int |
| 779 | bp_locations_compare_addrs (const void *ap, const void *bp) |
| 780 | { |
| 781 | const struct bp_location *a = *(const struct bp_location **) ap; |
| 782 | const struct bp_location *b = *(const struct bp_location **) bp; |
| 783 | |
| 784 | if (a->address == b->address) |
| 785 | return 0; |
| 786 | else |
| 787 | return ((a->address > b->address) - (a->address < b->address)); |
| 788 | } |
| 789 | |
| 790 | /* Helper function to skip all bp_locations with addresses |
| 791 | less than ADDRESS. It returns the first bp_location that |
| 792 | is greater than or equal to ADDRESS. If none is found, just |
| 793 | return NULL. */ |
| 794 | |
| 795 | static struct bp_location ** |
| 796 | get_first_locp_gte_addr (CORE_ADDR address) |
| 797 | { |
| 798 | struct bp_location dummy_loc; |
| 799 | struct bp_location *dummy_locp = &dummy_loc; |
| 800 | struct bp_location **locp_found = NULL; |
| 801 | |
| 802 | /* Initialize the dummy location's address field. */ |
| 803 | dummy_loc.address = address; |
| 804 | |
| 805 | /* Find a close match to the first location at ADDRESS. */ |
| 806 | locp_found = ((struct bp_location **) |
| 807 | bsearch (&dummy_locp, bp_locations, bp_locations_count, |
| 808 | sizeof (struct bp_location **), |
| 809 | bp_locations_compare_addrs)); |
| 810 | |
| 811 | /* Nothing was found, nothing left to do. */ |
| 812 | if (locp_found == NULL) |
| 813 | return NULL; |
| 814 | |
| 815 | /* We may have found a location that is at ADDRESS but is not the first in the |
| 816 | location's list. Go backwards (if possible) and locate the first one. */ |
| 817 | while ((locp_found - 1) >= bp_locations |
| 818 | && (*(locp_found - 1))->address == address) |
| 819 | locp_found--; |
| 820 | |
| 821 | return locp_found; |
| 822 | } |
| 823 | |
| 824 | void |
| 825 | set_breakpoint_condition (struct breakpoint *b, const char *exp, |
| 826 | int from_tty) |
| 827 | { |
| 828 | xfree (b->cond_string); |
| 829 | b->cond_string = NULL; |
| 830 | |
| 831 | if (is_watchpoint (b)) |
| 832 | { |
| 833 | struct watchpoint *w = (struct watchpoint *) b; |
| 834 | |
| 835 | w->cond_exp.reset (); |
| 836 | } |
| 837 | else |
| 838 | { |
| 839 | struct bp_location *loc; |
| 840 | |
| 841 | for (loc = b->loc; loc; loc = loc->next) |
| 842 | { |
| 843 | loc->cond.reset (); |
| 844 | |
| 845 | /* No need to free the condition agent expression |
| 846 | bytecode (if we have one). We will handle this |
| 847 | when we go through update_global_location_list. */ |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | if (*exp == 0) |
| 852 | { |
| 853 | if (from_tty) |
| 854 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); |
| 855 | } |
| 856 | else |
| 857 | { |
| 858 | const char *arg = exp; |
| 859 | |
| 860 | /* I don't know if it matters whether this is the string the user |
| 861 | typed in or the decompiled expression. */ |
| 862 | b->cond_string = xstrdup (arg); |
| 863 | b->condition_not_parsed = 0; |
| 864 | |
| 865 | if (is_watchpoint (b)) |
| 866 | { |
| 867 | struct watchpoint *w = (struct watchpoint *) b; |
| 868 | |
| 869 | innermost_block_tracker tracker; |
| 870 | arg = exp; |
| 871 | w->cond_exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
| 872 | if (*arg) |
| 873 | error (_("Junk at end of expression")); |
| 874 | w->cond_exp_valid_block = tracker.block (); |
| 875 | } |
| 876 | else |
| 877 | { |
| 878 | struct bp_location *loc; |
| 879 | |
| 880 | for (loc = b->loc; loc; loc = loc->next) |
| 881 | { |
| 882 | arg = exp; |
| 883 | loc->cond = |
| 884 | parse_exp_1 (&arg, loc->address, |
| 885 | block_for_pc (loc->address), 0); |
| 886 | if (*arg) |
| 887 | error (_("Junk at end of expression")); |
| 888 | } |
| 889 | } |
| 890 | } |
| 891 | mark_breakpoint_modified (b); |
| 892 | |
| 893 | gdb::observers::breakpoint_modified.notify (b); |
| 894 | } |
| 895 | |
| 896 | /* Completion for the "condition" command. */ |
| 897 | |
| 898 | static void |
| 899 | condition_completer (struct cmd_list_element *cmd, |
| 900 | completion_tracker &tracker, |
| 901 | const char *text, const char *word) |
| 902 | { |
| 903 | const char *space; |
| 904 | |
| 905 | text = skip_spaces (text); |
| 906 | space = skip_to_space (text); |
| 907 | if (*space == '\0') |
| 908 | { |
| 909 | int len; |
| 910 | struct breakpoint *b; |
| 911 | |
| 912 | if (text[0] == '$') |
| 913 | { |
| 914 | /* We don't support completion of history indices. */ |
| 915 | if (!isdigit (text[1])) |
| 916 | complete_internalvar (tracker, &text[1]); |
| 917 | return; |
| 918 | } |
| 919 | |
| 920 | /* We're completing the breakpoint number. */ |
| 921 | len = strlen (text); |
| 922 | |
| 923 | ALL_BREAKPOINTS (b) |
| 924 | { |
| 925 | char number[50]; |
| 926 | |
| 927 | xsnprintf (number, sizeof (number), "%d", b->number); |
| 928 | |
| 929 | if (strncmp (number, text, len) == 0) |
| 930 | tracker.add_completion (make_unique_xstrdup (number)); |
| 931 | } |
| 932 | |
| 933 | return; |
| 934 | } |
| 935 | |
| 936 | /* We're completing the expression part. */ |
| 937 | text = skip_spaces (space); |
| 938 | expression_completer (cmd, tracker, text, word); |
| 939 | } |
| 940 | |
| 941 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
| 942 | |
| 943 | static void |
| 944 | condition_command (const char *arg, int from_tty) |
| 945 | { |
| 946 | struct breakpoint *b; |
| 947 | const char *p; |
| 948 | int bnum; |
| 949 | |
| 950 | if (arg == 0) |
| 951 | error_no_arg (_("breakpoint number")); |
| 952 | |
| 953 | p = arg; |
| 954 | bnum = get_number (&p); |
| 955 | if (bnum == 0) |
| 956 | error (_("Bad breakpoint argument: '%s'"), arg); |
| 957 | |
| 958 | ALL_BREAKPOINTS (b) |
| 959 | if (b->number == bnum) |
| 960 | { |
| 961 | /* Check if this breakpoint has a "stop" method implemented in an |
| 962 | extension language. This method and conditions entered into GDB |
| 963 | from the CLI are mutually exclusive. */ |
| 964 | const struct extension_language_defn *extlang |
| 965 | = get_breakpoint_cond_ext_lang (b, EXT_LANG_NONE); |
| 966 | |
| 967 | if (extlang != NULL) |
| 968 | { |
| 969 | error (_("Only one stop condition allowed. There is currently" |
| 970 | " a %s stop condition defined for this breakpoint."), |
| 971 | ext_lang_capitalized_name (extlang)); |
| 972 | } |
| 973 | set_breakpoint_condition (b, p, from_tty); |
| 974 | |
| 975 | if (is_breakpoint (b)) |
| 976 | update_global_location_list (UGLL_MAY_INSERT); |
| 977 | |
| 978 | return; |
| 979 | } |
| 980 | |
| 981 | error (_("No breakpoint number %d."), bnum); |
| 982 | } |
| 983 | |
| 984 | /* Check that COMMAND do not contain commands that are suitable |
| 985 | only for tracepoints and not suitable for ordinary breakpoints. |
| 986 | Throw if any such commands is found. */ |
| 987 | |
| 988 | static void |
| 989 | check_no_tracepoint_commands (struct command_line *commands) |
| 990 | { |
| 991 | struct command_line *c; |
| 992 | |
| 993 | for (c = commands; c; c = c->next) |
| 994 | { |
| 995 | if (c->control_type == while_stepping_control) |
| 996 | error (_("The 'while-stepping' command can " |
| 997 | "only be used for tracepoints")); |
| 998 | |
| 999 | check_no_tracepoint_commands (c->body_list_0.get ()); |
| 1000 | check_no_tracepoint_commands (c->body_list_1.get ()); |
| 1001 | |
| 1002 | /* Not that command parsing removes leading whitespace and comment |
| 1003 | lines and also empty lines. So, we only need to check for |
| 1004 | command directly. */ |
| 1005 | if (strstr (c->line, "collect ") == c->line) |
| 1006 | error (_("The 'collect' command can only be used for tracepoints")); |
| 1007 | |
| 1008 | if (strstr (c->line, "teval ") == c->line) |
| 1009 | error (_("The 'teval' command can only be used for tracepoints")); |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | struct longjmp_breakpoint : public breakpoint |
| 1014 | { |
| 1015 | ~longjmp_breakpoint () override; |
| 1016 | }; |
| 1017 | |
| 1018 | /* Encapsulate tests for different types of tracepoints. */ |
| 1019 | |
| 1020 | static bool |
| 1021 | is_tracepoint_type (bptype type) |
| 1022 | { |
| 1023 | return (type == bp_tracepoint |
| 1024 | || type == bp_fast_tracepoint |
| 1025 | || type == bp_static_tracepoint); |
| 1026 | } |
| 1027 | |
| 1028 | static bool |
| 1029 | is_longjmp_type (bptype type) |
| 1030 | { |
| 1031 | return type == bp_longjmp || type == bp_exception; |
| 1032 | } |
| 1033 | |
| 1034 | /* See breakpoint.h. */ |
| 1035 | |
| 1036 | bool |
| 1037 | is_tracepoint (const struct breakpoint *b) |
| 1038 | { |
| 1039 | return is_tracepoint_type (b->type); |
| 1040 | } |
| 1041 | |
| 1042 | /* Factory function to create an appropriate instance of breakpoint given |
| 1043 | TYPE. */ |
| 1044 | |
| 1045 | static std::unique_ptr<breakpoint> |
| 1046 | new_breakpoint_from_type (bptype type) |
| 1047 | { |
| 1048 | breakpoint *b; |
| 1049 | |
| 1050 | if (is_tracepoint_type (type)) |
| 1051 | b = new tracepoint (); |
| 1052 | else if (is_longjmp_type (type)) |
| 1053 | b = new longjmp_breakpoint (); |
| 1054 | else |
| 1055 | b = new breakpoint (); |
| 1056 | |
| 1057 | return std::unique_ptr<breakpoint> (b); |
| 1058 | } |
| 1059 | |
| 1060 | /* A helper function that validates that COMMANDS are valid for a |
| 1061 | breakpoint. This function will throw an exception if a problem is |
| 1062 | found. */ |
| 1063 | |
| 1064 | static void |
| 1065 | validate_commands_for_breakpoint (struct breakpoint *b, |
| 1066 | struct command_line *commands) |
| 1067 | { |
| 1068 | if (is_tracepoint (b)) |
| 1069 | { |
| 1070 | struct tracepoint *t = (struct tracepoint *) b; |
| 1071 | struct command_line *c; |
| 1072 | struct command_line *while_stepping = 0; |
| 1073 | |
| 1074 | /* Reset the while-stepping step count. The previous commands |
| 1075 | might have included a while-stepping action, while the new |
| 1076 | ones might not. */ |
| 1077 | t->step_count = 0; |
| 1078 | |
| 1079 | /* We need to verify that each top-level element of commands is |
| 1080 | valid for tracepoints, that there's at most one |
| 1081 | while-stepping element, and that the while-stepping's body |
| 1082 | has valid tracing commands excluding nested while-stepping. |
| 1083 | We also need to validate the tracepoint action line in the |
| 1084 | context of the tracepoint --- validate_actionline actually |
| 1085 | has side effects, like setting the tracepoint's |
| 1086 | while-stepping STEP_COUNT, in addition to checking if the |
| 1087 | collect/teval actions parse and make sense in the |
| 1088 | tracepoint's context. */ |
| 1089 | for (c = commands; c; c = c->next) |
| 1090 | { |
| 1091 | if (c->control_type == while_stepping_control) |
| 1092 | { |
| 1093 | if (b->type == bp_fast_tracepoint) |
| 1094 | error (_("The 'while-stepping' command " |
| 1095 | "cannot be used for fast tracepoint")); |
| 1096 | else if (b->type == bp_static_tracepoint) |
| 1097 | error (_("The 'while-stepping' command " |
| 1098 | "cannot be used for static tracepoint")); |
| 1099 | |
| 1100 | if (while_stepping) |
| 1101 | error (_("The 'while-stepping' command " |
| 1102 | "can be used only once")); |
| 1103 | else |
| 1104 | while_stepping = c; |
| 1105 | } |
| 1106 | |
| 1107 | validate_actionline (c->line, b); |
| 1108 | } |
| 1109 | if (while_stepping) |
| 1110 | { |
| 1111 | struct command_line *c2; |
| 1112 | |
| 1113 | gdb_assert (while_stepping->body_list_1 == nullptr); |
| 1114 | c2 = while_stepping->body_list_0.get (); |
| 1115 | for (; c2; c2 = c2->next) |
| 1116 | { |
| 1117 | if (c2->control_type == while_stepping_control) |
| 1118 | error (_("The 'while-stepping' command cannot be nested")); |
| 1119 | } |
| 1120 | } |
| 1121 | } |
| 1122 | else |
| 1123 | { |
| 1124 | check_no_tracepoint_commands (commands); |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | /* Return a vector of all the static tracepoints set at ADDR. The |
| 1129 | caller is responsible for releasing the vector. */ |
| 1130 | |
| 1131 | std::vector<breakpoint *> |
| 1132 | static_tracepoints_here (CORE_ADDR addr) |
| 1133 | { |
| 1134 | struct breakpoint *b; |
| 1135 | std::vector<breakpoint *> found; |
| 1136 | struct bp_location *loc; |
| 1137 | |
| 1138 | ALL_BREAKPOINTS (b) |
| 1139 | if (b->type == bp_static_tracepoint) |
| 1140 | { |
| 1141 | for (loc = b->loc; loc; loc = loc->next) |
| 1142 | if (loc->address == addr) |
| 1143 | found.push_back (b); |
| 1144 | } |
| 1145 | |
| 1146 | return found; |
| 1147 | } |
| 1148 | |
| 1149 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
| 1150 | validate that only allowed commands are included. */ |
| 1151 | |
| 1152 | void |
| 1153 | breakpoint_set_commands (struct breakpoint *b, |
| 1154 | counted_command_line &&commands) |
| 1155 | { |
| 1156 | validate_commands_for_breakpoint (b, commands.get ()); |
| 1157 | |
| 1158 | b->commands = std::move (commands); |
| 1159 | gdb::observers::breakpoint_modified.notify (b); |
| 1160 | } |
| 1161 | |
| 1162 | /* Set the internal `silent' flag on the breakpoint. Note that this |
| 1163 | is not the same as the "silent" that may appear in the breakpoint's |
| 1164 | commands. */ |
| 1165 | |
| 1166 | void |
| 1167 | breakpoint_set_silent (struct breakpoint *b, int silent) |
| 1168 | { |
| 1169 | int old_silent = b->silent; |
| 1170 | |
| 1171 | b->silent = silent; |
| 1172 | if (old_silent != silent) |
| 1173 | gdb::observers::breakpoint_modified.notify (b); |
| 1174 | } |
| 1175 | |
| 1176 | /* Set the thread for this breakpoint. If THREAD is -1, make the |
| 1177 | breakpoint work for any thread. */ |
| 1178 | |
| 1179 | void |
| 1180 | breakpoint_set_thread (struct breakpoint *b, int thread) |
| 1181 | { |
| 1182 | int old_thread = b->thread; |
| 1183 | |
| 1184 | b->thread = thread; |
| 1185 | if (old_thread != thread) |
| 1186 | gdb::observers::breakpoint_modified.notify (b); |
| 1187 | } |
| 1188 | |
| 1189 | /* Set the task for this breakpoint. If TASK is 0, make the |
| 1190 | breakpoint work for any task. */ |
| 1191 | |
| 1192 | void |
| 1193 | breakpoint_set_task (struct breakpoint *b, int task) |
| 1194 | { |
| 1195 | int old_task = b->task; |
| 1196 | |
| 1197 | b->task = task; |
| 1198 | if (old_task != task) |
| 1199 | gdb::observers::breakpoint_modified.notify (b); |
| 1200 | } |
| 1201 | |
| 1202 | static void |
| 1203 | commands_command_1 (const char *arg, int from_tty, |
| 1204 | struct command_line *control) |
| 1205 | { |
| 1206 | counted_command_line cmd; |
| 1207 | /* cmd_read will be true once we have read cmd. Note that cmd might still be |
| 1208 | NULL after the call to read_command_lines if the user provides an empty |
| 1209 | list of command by just typing "end". */ |
| 1210 | bool cmd_read = false; |
| 1211 | |
| 1212 | std::string new_arg; |
| 1213 | |
| 1214 | if (arg == NULL || !*arg) |
| 1215 | { |
| 1216 | if (breakpoint_count - prev_breakpoint_count > 1) |
| 1217 | new_arg = string_printf ("%d-%d", prev_breakpoint_count + 1, |
| 1218 | breakpoint_count); |
| 1219 | else if (breakpoint_count > 0) |
| 1220 | new_arg = string_printf ("%d", breakpoint_count); |
| 1221 | arg = new_arg.c_str (); |
| 1222 | } |
| 1223 | |
| 1224 | map_breakpoint_numbers |
| 1225 | (arg, [&] (breakpoint *b) |
| 1226 | { |
| 1227 | if (!cmd_read) |
| 1228 | { |
| 1229 | gdb_assert (cmd == NULL); |
| 1230 | if (control != NULL) |
| 1231 | cmd = control->body_list_0; |
| 1232 | else |
| 1233 | { |
| 1234 | std::string str |
| 1235 | = string_printf (_("Type commands for breakpoint(s) " |
| 1236 | "%s, one per line."), |
| 1237 | arg); |
| 1238 | |
| 1239 | auto do_validate = [=] (const char *line) |
| 1240 | { |
| 1241 | validate_actionline (line, b); |
| 1242 | }; |
| 1243 | gdb::function_view<void (const char *)> validator; |
| 1244 | if (is_tracepoint (b)) |
| 1245 | validator = do_validate; |
| 1246 | |
| 1247 | cmd = read_command_lines (str.c_str (), from_tty, 1, validator); |
| 1248 | } |
| 1249 | cmd_read = true; |
| 1250 | } |
| 1251 | |
| 1252 | /* If a breakpoint was on the list more than once, we don't need to |
| 1253 | do anything. */ |
| 1254 | if (b->commands != cmd) |
| 1255 | { |
| 1256 | validate_commands_for_breakpoint (b, cmd.get ()); |
| 1257 | b->commands = cmd; |
| 1258 | gdb::observers::breakpoint_modified.notify (b); |
| 1259 | } |
| 1260 | }); |
| 1261 | } |
| 1262 | |
| 1263 | static void |
| 1264 | commands_command (const char *arg, int from_tty) |
| 1265 | { |
| 1266 | commands_command_1 (arg, from_tty, NULL); |
| 1267 | } |
| 1268 | |
| 1269 | /* Like commands_command, but instead of reading the commands from |
| 1270 | input stream, takes them from an already parsed command structure. |
| 1271 | |
| 1272 | This is used by cli-script.c to DTRT with breakpoint commands |
| 1273 | that are part of if and while bodies. */ |
| 1274 | enum command_control_type |
| 1275 | commands_from_control_command (const char *arg, struct command_line *cmd) |
| 1276 | { |
| 1277 | commands_command_1 (arg, 0, cmd); |
| 1278 | return simple_control; |
| 1279 | } |
| 1280 | |
| 1281 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ |
| 1282 | |
| 1283 | static int |
| 1284 | bp_location_has_shadow (struct bp_location *bl) |
| 1285 | { |
| 1286 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 1287 | return 0; |
| 1288 | if (!bl->inserted) |
| 1289 | return 0; |
| 1290 | if (bl->target_info.shadow_len == 0) |
| 1291 | /* BL isn't valid, or doesn't shadow memory. */ |
| 1292 | return 0; |
| 1293 | return 1; |
| 1294 | } |
| 1295 | |
| 1296 | /* Update BUF, which is LEN bytes read from the target address |
| 1297 | MEMADDR, by replacing a memory breakpoint with its shadowed |
| 1298 | contents. |
| 1299 | |
| 1300 | If READBUF is not NULL, this buffer must not overlap with the of |
| 1301 | the breakpoint location's shadow_contents buffer. Otherwise, a |
| 1302 | failed assertion internal error will be raised. */ |
| 1303 | |
| 1304 | static void |
| 1305 | one_breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
| 1306 | const gdb_byte *writebuf_org, |
| 1307 | ULONGEST memaddr, LONGEST len, |
| 1308 | struct bp_target_info *target_info, |
| 1309 | struct gdbarch *gdbarch) |
| 1310 | { |
| 1311 | /* Now do full processing of the found relevant range of elements. */ |
| 1312 | CORE_ADDR bp_addr = 0; |
| 1313 | int bp_size = 0; |
| 1314 | int bptoffset = 0; |
| 1315 | |
| 1316 | if (!breakpoint_address_match (target_info->placed_address_space, 0, |
| 1317 | current_program_space->aspace, 0)) |
| 1318 | { |
| 1319 | /* The breakpoint is inserted in a different address space. */ |
| 1320 | return; |
| 1321 | } |
| 1322 | |
| 1323 | /* Addresses and length of the part of the breakpoint that |
| 1324 | we need to copy. */ |
| 1325 | bp_addr = target_info->placed_address; |
| 1326 | bp_size = target_info->shadow_len; |
| 1327 | |
| 1328 | if (bp_addr + bp_size <= memaddr) |
| 1329 | { |
| 1330 | /* The breakpoint is entirely before the chunk of memory we are |
| 1331 | reading. */ |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | if (bp_addr >= memaddr + len) |
| 1336 | { |
| 1337 | /* The breakpoint is entirely after the chunk of memory we are |
| 1338 | reading. */ |
| 1339 | return; |
| 1340 | } |
| 1341 | |
| 1342 | /* Offset within shadow_contents. */ |
| 1343 | if (bp_addr < memaddr) |
| 1344 | { |
| 1345 | /* Only copy the second part of the breakpoint. */ |
| 1346 | bp_size -= memaddr - bp_addr; |
| 1347 | bptoffset = memaddr - bp_addr; |
| 1348 | bp_addr = memaddr; |
| 1349 | } |
| 1350 | |
| 1351 | if (bp_addr + bp_size > memaddr + len) |
| 1352 | { |
| 1353 | /* Only copy the first part of the breakpoint. */ |
| 1354 | bp_size -= (bp_addr + bp_size) - (memaddr + len); |
| 1355 | } |
| 1356 | |
| 1357 | if (readbuf != NULL) |
| 1358 | { |
| 1359 | /* Verify that the readbuf buffer does not overlap with the |
| 1360 | shadow_contents buffer. */ |
| 1361 | gdb_assert (target_info->shadow_contents >= readbuf + len |
| 1362 | || readbuf >= (target_info->shadow_contents |
| 1363 | + target_info->shadow_len)); |
| 1364 | |
| 1365 | /* Update the read buffer with this inserted breakpoint's |
| 1366 | shadow. */ |
| 1367 | memcpy (readbuf + bp_addr - memaddr, |
| 1368 | target_info->shadow_contents + bptoffset, bp_size); |
| 1369 | } |
| 1370 | else |
| 1371 | { |
| 1372 | const unsigned char *bp; |
| 1373 | CORE_ADDR addr = target_info->reqstd_address; |
| 1374 | int placed_size; |
| 1375 | |
| 1376 | /* Update the shadow with what we want to write to memory. */ |
| 1377 | memcpy (target_info->shadow_contents + bptoffset, |
| 1378 | writebuf_org + bp_addr - memaddr, bp_size); |
| 1379 | |
| 1380 | /* Determine appropriate breakpoint contents and size for this |
| 1381 | address. */ |
| 1382 | bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &placed_size); |
| 1383 | |
| 1384 | /* Update the final write buffer with this inserted |
| 1385 | breakpoint's INSN. */ |
| 1386 | memcpy (writebuf + bp_addr - memaddr, bp + bptoffset, bp_size); |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
| 1391 | by replacing any memory breakpoints with their shadowed contents. |
| 1392 | |
| 1393 | If READBUF is not NULL, this buffer must not overlap with any of |
| 1394 | the breakpoint location's shadow_contents buffers. Otherwise, |
| 1395 | a failed assertion internal error will be raised. |
| 1396 | |
| 1397 | The range of shadowed area by each bp_location is: |
| 1398 | bl->address - bp_locations_placed_address_before_address_max |
| 1399 | up to bl->address + bp_locations_shadow_len_after_address_max |
| 1400 | The range we were requested to resolve shadows for is: |
| 1401 | memaddr ... memaddr + len |
| 1402 | Thus the safe cutoff boundaries for performance optimization are |
| 1403 | memaddr + len <= (bl->address |
| 1404 | - bp_locations_placed_address_before_address_max) |
| 1405 | and: |
| 1406 | bl->address + bp_locations_shadow_len_after_address_max <= memaddr */ |
| 1407 | |
| 1408 | void |
| 1409 | breakpoint_xfer_memory (gdb_byte *readbuf, gdb_byte *writebuf, |
| 1410 | const gdb_byte *writebuf_org, |
| 1411 | ULONGEST memaddr, LONGEST len) |
| 1412 | { |
| 1413 | /* Left boundary, right boundary and median element of our binary |
| 1414 | search. */ |
| 1415 | unsigned bc_l, bc_r, bc; |
| 1416 | |
| 1417 | /* Find BC_L which is a leftmost element which may affect BUF |
| 1418 | content. It is safe to report lower value but a failure to |
| 1419 | report higher one. */ |
| 1420 | |
| 1421 | bc_l = 0; |
| 1422 | bc_r = bp_locations_count; |
| 1423 | while (bc_l + 1 < bc_r) |
| 1424 | { |
| 1425 | struct bp_location *bl; |
| 1426 | |
| 1427 | bc = (bc_l + bc_r) / 2; |
| 1428 | bl = bp_locations[bc]; |
| 1429 | |
| 1430 | /* Check first BL->ADDRESS will not overflow due to the added |
| 1431 | constant. Then advance the left boundary only if we are sure |
| 1432 | the BC element can in no way affect the BUF content (MEMADDR |
| 1433 | to MEMADDR + LEN range). |
| 1434 | |
| 1435 | Use the BP_LOCATIONS_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
| 1436 | offset so that we cannot miss a breakpoint with its shadow |
| 1437 | range tail still reaching MEMADDR. */ |
| 1438 | |
| 1439 | if ((bl->address + bp_locations_shadow_len_after_address_max |
| 1440 | >= bl->address) |
| 1441 | && (bl->address + bp_locations_shadow_len_after_address_max |
| 1442 | <= memaddr)) |
| 1443 | bc_l = bc; |
| 1444 | else |
| 1445 | bc_r = bc; |
| 1446 | } |
| 1447 | |
| 1448 | /* Due to the binary search above, we need to make sure we pick the |
| 1449 | first location that's at BC_L's address. E.g., if there are |
| 1450 | multiple locations at the same address, BC_L may end up pointing |
| 1451 | at a duplicate location, and miss the "master"/"inserted" |
| 1452 | location. Say, given locations L1, L2 and L3 at addresses A and |
| 1453 | B: |
| 1454 | |
| 1455 | L1@A, L2@A, L3@B, ... |
| 1456 | |
| 1457 | BC_L could end up pointing at location L2, while the "master" |
| 1458 | location could be L1. Since the `loc->inserted' flag is only set |
| 1459 | on "master" locations, we'd forget to restore the shadow of L1 |
| 1460 | and L2. */ |
| 1461 | while (bc_l > 0 |
| 1462 | && bp_locations[bc_l]->address == bp_locations[bc_l - 1]->address) |
| 1463 | bc_l--; |
| 1464 | |
| 1465 | /* Now do full processing of the found relevant range of elements. */ |
| 1466 | |
| 1467 | for (bc = bc_l; bc < bp_locations_count; bc++) |
| 1468 | { |
| 1469 | struct bp_location *bl = bp_locations[bc]; |
| 1470 | |
| 1471 | /* bp_location array has BL->OWNER always non-NULL. */ |
| 1472 | if (bl->owner->type == bp_none) |
| 1473 | warning (_("reading through apparently deleted breakpoint #%d?"), |
| 1474 | bl->owner->number); |
| 1475 | |
| 1476 | /* Performance optimization: any further element can no longer affect BUF |
| 1477 | content. */ |
| 1478 | |
| 1479 | if (bl->address >= bp_locations_placed_address_before_address_max |
| 1480 | && memaddr + len <= (bl->address |
| 1481 | - bp_locations_placed_address_before_address_max)) |
| 1482 | break; |
| 1483 | |
| 1484 | if (!bp_location_has_shadow (bl)) |
| 1485 | continue; |
| 1486 | |
| 1487 | one_breakpoint_xfer_memory (readbuf, writebuf, writebuf_org, |
| 1488 | memaddr, len, &bl->target_info, bl->gdbarch); |
| 1489 | } |
| 1490 | } |
| 1491 | |
| 1492 | /* See breakpoint.h. */ |
| 1493 | |
| 1494 | bool |
| 1495 | is_breakpoint (const struct breakpoint *bpt) |
| 1496 | { |
| 1497 | return (bpt->type == bp_breakpoint |
| 1498 | || bpt->type == bp_hardware_breakpoint |
| 1499 | || bpt->type == bp_dprintf); |
| 1500 | } |
| 1501 | |
| 1502 | /* Return true if BPT is of any hardware watchpoint kind. */ |
| 1503 | |
| 1504 | static bool |
| 1505 | is_hardware_watchpoint (const struct breakpoint *bpt) |
| 1506 | { |
| 1507 | return (bpt->type == bp_hardware_watchpoint |
| 1508 | || bpt->type == bp_read_watchpoint |
| 1509 | || bpt->type == bp_access_watchpoint); |
| 1510 | } |
| 1511 | |
| 1512 | /* See breakpoint.h. */ |
| 1513 | |
| 1514 | bool |
| 1515 | is_watchpoint (const struct breakpoint *bpt) |
| 1516 | { |
| 1517 | return (is_hardware_watchpoint (bpt) |
| 1518 | || bpt->type == bp_watchpoint); |
| 1519 | } |
| 1520 | |
| 1521 | /* Returns true if the current thread and its running state are safe |
| 1522 | to evaluate or update watchpoint B. Watchpoints on local |
| 1523 | expressions need to be evaluated in the context of the thread that |
| 1524 | was current when the watchpoint was created, and, that thread needs |
| 1525 | to be stopped to be able to select the correct frame context. |
| 1526 | Watchpoints on global expressions can be evaluated on any thread, |
| 1527 | and in any state. It is presently left to the target allowing |
| 1528 | memory accesses when threads are running. */ |
| 1529 | |
| 1530 | static int |
| 1531 | watchpoint_in_thread_scope (struct watchpoint *b) |
| 1532 | { |
| 1533 | return (b->pspace == current_program_space |
| 1534 | && (b->watchpoint_thread == null_ptid |
| 1535 | || (inferior_ptid == b->watchpoint_thread |
| 1536 | && !inferior_thread ()->executing))); |
| 1537 | } |
| 1538 | |
| 1539 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
| 1540 | associated bp_watchpoint_scope breakpoint. */ |
| 1541 | |
| 1542 | static void |
| 1543 | watchpoint_del_at_next_stop (struct watchpoint *w) |
| 1544 | { |
| 1545 | if (w->related_breakpoint != w) |
| 1546 | { |
| 1547 | gdb_assert (w->related_breakpoint->type == bp_watchpoint_scope); |
| 1548 | gdb_assert (w->related_breakpoint->related_breakpoint == w); |
| 1549 | w->related_breakpoint->disposition = disp_del_at_next_stop; |
| 1550 | w->related_breakpoint->related_breakpoint = w->related_breakpoint; |
| 1551 | w->related_breakpoint = w; |
| 1552 | } |
| 1553 | w->disposition = disp_del_at_next_stop; |
| 1554 | } |
| 1555 | |
| 1556 | /* Extract a bitfield value from value VAL using the bit parameters contained in |
| 1557 | watchpoint W. */ |
| 1558 | |
| 1559 | static struct value * |
| 1560 | extract_bitfield_from_watchpoint_value (struct watchpoint *w, struct value *val) |
| 1561 | { |
| 1562 | struct value *bit_val; |
| 1563 | |
| 1564 | if (val == NULL) |
| 1565 | return NULL; |
| 1566 | |
| 1567 | bit_val = allocate_value (value_type (val)); |
| 1568 | |
| 1569 | unpack_value_bitfield (bit_val, |
| 1570 | w->val_bitpos, |
| 1571 | w->val_bitsize, |
| 1572 | value_contents_for_printing (val), |
| 1573 | value_offset (val), |
| 1574 | val); |
| 1575 | |
| 1576 | return bit_val; |
| 1577 | } |
| 1578 | |
| 1579 | /* Allocate a dummy location and add it to B, which must be a software |
| 1580 | watchpoint. This is required because even if a software watchpoint |
| 1581 | is not watching any memory, bpstat_stop_status requires a location |
| 1582 | to be able to report stops. */ |
| 1583 | |
| 1584 | static void |
| 1585 | software_watchpoint_add_no_memory_location (struct breakpoint *b, |
| 1586 | struct program_space *pspace) |
| 1587 | { |
| 1588 | gdb_assert (b->type == bp_watchpoint && b->loc == NULL); |
| 1589 | |
| 1590 | b->loc = allocate_bp_location (b); |
| 1591 | b->loc->pspace = pspace; |
| 1592 | b->loc->address = -1; |
| 1593 | b->loc->length = -1; |
| 1594 | } |
| 1595 | |
| 1596 | /* Returns true if B is a software watchpoint that is not watching any |
| 1597 | memory (e.g., "watch $pc"). */ |
| 1598 | |
| 1599 | static bool |
| 1600 | is_no_memory_software_watchpoint (struct breakpoint *b) |
| 1601 | { |
| 1602 | return (b->type == bp_watchpoint |
| 1603 | && b->loc != NULL |
| 1604 | && b->loc->next == NULL |
| 1605 | && b->loc->address == -1 |
| 1606 | && b->loc->length == -1); |
| 1607 | } |
| 1608 | |
| 1609 | /* Assuming that B is a watchpoint: |
| 1610 | - Reparse watchpoint expression, if REPARSE is non-zero |
| 1611 | - Evaluate expression and store the result in B->val |
| 1612 | - Evaluate the condition if there is one, and store the result |
| 1613 | in b->loc->cond. |
| 1614 | - Update the list of values that must be watched in B->loc. |
| 1615 | |
| 1616 | If the watchpoint disposition is disp_del_at_next_stop, then do |
| 1617 | nothing. If this is local watchpoint that is out of scope, delete |
| 1618 | it. |
| 1619 | |
| 1620 | Even with `set breakpoint always-inserted on' the watchpoints are |
| 1621 | removed + inserted on each stop here. Normal breakpoints must |
| 1622 | never be removed because they might be missed by a running thread |
| 1623 | when debugging in non-stop mode. On the other hand, hardware |
| 1624 | watchpoints (is_hardware_watchpoint; processed here) are specific |
| 1625 | to each LWP since they are stored in each LWP's hardware debug |
| 1626 | registers. Therefore, such LWP must be stopped first in order to |
| 1627 | be able to modify its hardware watchpoints. |
| 1628 | |
| 1629 | Hardware watchpoints must be reset exactly once after being |
| 1630 | presented to the user. It cannot be done sooner, because it would |
| 1631 | reset the data used to present the watchpoint hit to the user. And |
| 1632 | it must not be done later because it could display the same single |
| 1633 | watchpoint hit during multiple GDB stops. Note that the latter is |
| 1634 | relevant only to the hardware watchpoint types bp_read_watchpoint |
| 1635 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is |
| 1636 | not user-visible - its hit is suppressed if the memory content has |
| 1637 | not changed. |
| 1638 | |
| 1639 | The following constraints influence the location where we can reset |
| 1640 | hardware watchpoints: |
| 1641 | |
| 1642 | * target_stopped_by_watchpoint and target_stopped_data_address are |
| 1643 | called several times when GDB stops. |
| 1644 | |
| 1645 | [linux] |
| 1646 | * Multiple hardware watchpoints can be hit at the same time, |
| 1647 | causing GDB to stop. GDB only presents one hardware watchpoint |
| 1648 | hit at a time as the reason for stopping, and all the other hits |
| 1649 | are presented later, one after the other, each time the user |
| 1650 | requests the execution to be resumed. Execution is not resumed |
| 1651 | for the threads still having pending hit event stored in |
| 1652 | LWP_INFO->STATUS. While the watchpoint is already removed from |
| 1653 | the inferior on the first stop the thread hit event is kept being |
| 1654 | reported from its cached value by linux_nat_stopped_data_address |
| 1655 | until the real thread resume happens after the watchpoint gets |
| 1656 | presented and thus its LWP_INFO->STATUS gets reset. |
| 1657 | |
| 1658 | Therefore the hardware watchpoint hit can get safely reset on the |
| 1659 | watchpoint removal from inferior. */ |
| 1660 | |
| 1661 | static void |
| 1662 | update_watchpoint (struct watchpoint *b, int reparse) |
| 1663 | { |
| 1664 | int within_current_scope; |
| 1665 | struct frame_id saved_frame_id; |
| 1666 | int frame_saved; |
| 1667 | |
| 1668 | /* If this is a local watchpoint, we only want to check if the |
| 1669 | watchpoint frame is in scope if the current thread is the thread |
| 1670 | that was used to create the watchpoint. */ |
| 1671 | if (!watchpoint_in_thread_scope (b)) |
| 1672 | return; |
| 1673 | |
| 1674 | if (b->disposition == disp_del_at_next_stop) |
| 1675 | return; |
| 1676 | |
| 1677 | frame_saved = 0; |
| 1678 | |
| 1679 | /* Determine if the watchpoint is within scope. */ |
| 1680 | if (b->exp_valid_block == NULL) |
| 1681 | within_current_scope = 1; |
| 1682 | else |
| 1683 | { |
| 1684 | struct frame_info *fi = get_current_frame (); |
| 1685 | struct gdbarch *frame_arch = get_frame_arch (fi); |
| 1686 | CORE_ADDR frame_pc = get_frame_pc (fi); |
| 1687 | |
| 1688 | /* If we're at a point where the stack has been destroyed |
| 1689 | (e.g. in a function epilogue), unwinding may not work |
| 1690 | properly. Do not attempt to recreate locations at this |
| 1691 | point. See similar comments in watchpoint_check. */ |
| 1692 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
| 1693 | return; |
| 1694 | |
| 1695 | /* Save the current frame's ID so we can restore it after |
| 1696 | evaluating the watchpoint expression on its own frame. */ |
| 1697 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression |
| 1698 | took a frame parameter, so that we didn't have to change the |
| 1699 | selected frame. */ |
| 1700 | frame_saved = 1; |
| 1701 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); |
| 1702 | |
| 1703 | fi = frame_find_by_id (b->watchpoint_frame); |
| 1704 | within_current_scope = (fi != NULL); |
| 1705 | if (within_current_scope) |
| 1706 | select_frame (fi); |
| 1707 | } |
| 1708 | |
| 1709 | /* We don't free locations. They are stored in the bp_location array |
| 1710 | and update_global_location_list will eventually delete them and |
| 1711 | remove breakpoints if needed. */ |
| 1712 | b->loc = NULL; |
| 1713 | |
| 1714 | if (within_current_scope && reparse) |
| 1715 | { |
| 1716 | const char *s; |
| 1717 | |
| 1718 | b->exp.reset (); |
| 1719 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
| 1720 | b->exp = parse_exp_1 (&s, 0, b->exp_valid_block, 0); |
| 1721 | /* If the meaning of expression itself changed, the old value is |
| 1722 | no longer relevant. We don't want to report a watchpoint hit |
| 1723 | to the user when the old value and the new value may actually |
| 1724 | be completely different objects. */ |
| 1725 | b->val = NULL; |
| 1726 | b->val_valid = false; |
| 1727 | |
| 1728 | /* Note that unlike with breakpoints, the watchpoint's condition |
| 1729 | expression is stored in the breakpoint object, not in the |
| 1730 | locations (re)created below. */ |
| 1731 | if (b->cond_string != NULL) |
| 1732 | { |
| 1733 | b->cond_exp.reset (); |
| 1734 | |
| 1735 | s = b->cond_string; |
| 1736 | b->cond_exp = parse_exp_1 (&s, 0, b->cond_exp_valid_block, 0); |
| 1737 | } |
| 1738 | } |
| 1739 | |
| 1740 | /* If we failed to parse the expression, for example because |
| 1741 | it refers to a global variable in a not-yet-loaded shared library, |
| 1742 | don't try to insert watchpoint. We don't automatically delete |
| 1743 | such watchpoint, though, since failure to parse expression |
| 1744 | is different from out-of-scope watchpoint. */ |
| 1745 | if (!target_has_execution) |
| 1746 | { |
| 1747 | /* Without execution, memory can't change. No use to try and |
| 1748 | set watchpoint locations. The watchpoint will be reset when |
| 1749 | the target gains execution, through breakpoint_re_set. */ |
| 1750 | if (!can_use_hw_watchpoints) |
| 1751 | { |
| 1752 | if (b->ops->works_in_software_mode (b)) |
| 1753 | b->type = bp_watchpoint; |
| 1754 | else |
| 1755 | error (_("Can't set read/access watchpoint when " |
| 1756 | "hardware watchpoints are disabled.")); |
| 1757 | } |
| 1758 | } |
| 1759 | else if (within_current_scope && b->exp) |
| 1760 | { |
| 1761 | int pc = 0; |
| 1762 | std::vector<value_ref_ptr> val_chain; |
| 1763 | struct value *v, *result; |
| 1764 | struct program_space *frame_pspace; |
| 1765 | |
| 1766 | fetch_subexp_value (b->exp.get (), &pc, &v, &result, &val_chain, 0); |
| 1767 | |
| 1768 | /* Avoid setting b->val if it's already set. The meaning of |
| 1769 | b->val is 'the last value' user saw, and we should update |
| 1770 | it only if we reported that last value to user. As it |
| 1771 | happens, the code that reports it updates b->val directly. |
| 1772 | We don't keep track of the memory value for masked |
| 1773 | watchpoints. */ |
| 1774 | if (!b->val_valid && !is_masked_watchpoint (b)) |
| 1775 | { |
| 1776 | if (b->val_bitsize != 0) |
| 1777 | v = extract_bitfield_from_watchpoint_value (b, v); |
| 1778 | b->val = release_value (v); |
| 1779 | b->val_valid = true; |
| 1780 | } |
| 1781 | |
| 1782 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
| 1783 | |
| 1784 | /* Look at each value on the value chain. */ |
| 1785 | gdb_assert (!val_chain.empty ()); |
| 1786 | for (const value_ref_ptr &iter : val_chain) |
| 1787 | { |
| 1788 | v = iter.get (); |
| 1789 | |
| 1790 | /* If it's a memory location, and GDB actually needed |
| 1791 | its contents to evaluate the expression, then we |
| 1792 | must watch it. If the first value returned is |
| 1793 | still lazy, that means an error occurred reading it; |
| 1794 | watch it anyway in case it becomes readable. */ |
| 1795 | if (VALUE_LVAL (v) == lval_memory |
| 1796 | && (v == val_chain[0] || ! value_lazy (v))) |
| 1797 | { |
| 1798 | struct type *vtype = check_typedef (value_type (v)); |
| 1799 | |
| 1800 | /* We only watch structs and arrays if user asked |
| 1801 | for it explicitly, never if they just happen to |
| 1802 | appear in the middle of some value chain. */ |
| 1803 | if (v == result |
| 1804 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 1805 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 1806 | { |
| 1807 | CORE_ADDR addr; |
| 1808 | enum target_hw_bp_type type; |
| 1809 | struct bp_location *loc, **tmp; |
| 1810 | int bitpos = 0, bitsize = 0; |
| 1811 | |
| 1812 | if (value_bitsize (v) != 0) |
| 1813 | { |
| 1814 | /* Extract the bit parameters out from the bitfield |
| 1815 | sub-expression. */ |
| 1816 | bitpos = value_bitpos (v); |
| 1817 | bitsize = value_bitsize (v); |
| 1818 | } |
| 1819 | else if (v == result && b->val_bitsize != 0) |
| 1820 | { |
| 1821 | /* If VAL_BITSIZE != 0 then RESULT is actually a bitfield |
| 1822 | lvalue whose bit parameters are saved in the fields |
| 1823 | VAL_BITPOS and VAL_BITSIZE. */ |
| 1824 | bitpos = b->val_bitpos; |
| 1825 | bitsize = b->val_bitsize; |
| 1826 | } |
| 1827 | |
| 1828 | addr = value_address (v); |
| 1829 | if (bitsize != 0) |
| 1830 | { |
| 1831 | /* Skip the bytes that don't contain the bitfield. */ |
| 1832 | addr += bitpos / 8; |
| 1833 | } |
| 1834 | |
| 1835 | type = hw_write; |
| 1836 | if (b->type == bp_read_watchpoint) |
| 1837 | type = hw_read; |
| 1838 | else if (b->type == bp_access_watchpoint) |
| 1839 | type = hw_access; |
| 1840 | |
| 1841 | loc = allocate_bp_location (b); |
| 1842 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
| 1843 | ; |
| 1844 | *tmp = loc; |
| 1845 | loc->gdbarch = get_type_arch (value_type (v)); |
| 1846 | |
| 1847 | loc->pspace = frame_pspace; |
| 1848 | loc->address = address_significant (loc->gdbarch, addr); |
| 1849 | |
| 1850 | if (bitsize != 0) |
| 1851 | { |
| 1852 | /* Just cover the bytes that make up the bitfield. */ |
| 1853 | loc->length = ((bitpos % 8) + bitsize + 7) / 8; |
| 1854 | } |
| 1855 | else |
| 1856 | loc->length = TYPE_LENGTH (value_type (v)); |
| 1857 | |
| 1858 | loc->watchpoint_type = type; |
| 1859 | } |
| 1860 | } |
| 1861 | } |
| 1862 | |
| 1863 | /* Change the type of breakpoint between hardware assisted or |
| 1864 | an ordinary watchpoint depending on the hardware support |
| 1865 | and free hardware slots. REPARSE is set when the inferior |
| 1866 | is started. */ |
| 1867 | if (reparse) |
| 1868 | { |
| 1869 | int reg_cnt; |
| 1870 | enum bp_loc_type loc_type; |
| 1871 | struct bp_location *bl; |
| 1872 | |
| 1873 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
| 1874 | |
| 1875 | if (reg_cnt) |
| 1876 | { |
| 1877 | int i, target_resources_ok, other_type_used; |
| 1878 | enum bptype type; |
| 1879 | |
| 1880 | /* Use an exact watchpoint when there's only one memory region to be |
| 1881 | watched, and only one debug register is needed to watch it. */ |
| 1882 | b->exact = target_exact_watchpoints && reg_cnt == 1; |
| 1883 | |
| 1884 | /* We need to determine how many resources are already |
| 1885 | used for all other hardware watchpoints plus this one |
| 1886 | to see if we still have enough resources to also fit |
| 1887 | this watchpoint in as well. */ |
| 1888 | |
| 1889 | /* If this is a software watchpoint, we try to turn it |
| 1890 | to a hardware one -- count resources as if B was of |
| 1891 | hardware watchpoint type. */ |
| 1892 | type = b->type; |
| 1893 | if (type == bp_watchpoint) |
| 1894 | type = bp_hardware_watchpoint; |
| 1895 | |
| 1896 | /* This watchpoint may or may not have been placed on |
| 1897 | the list yet at this point (it won't be in the list |
| 1898 | if we're trying to create it for the first time, |
| 1899 | through watch_command), so always account for it |
| 1900 | manually. */ |
| 1901 | |
| 1902 | /* Count resources used by all watchpoints except B. */ |
| 1903 | i = hw_watchpoint_used_count_others (b, type, &other_type_used); |
| 1904 | |
| 1905 | /* Add in the resources needed for B. */ |
| 1906 | i += hw_watchpoint_use_count (b); |
| 1907 | |
| 1908 | target_resources_ok |
| 1909 | = target_can_use_hardware_watchpoint (type, i, other_type_used); |
| 1910 | if (target_resources_ok <= 0) |
| 1911 | { |
| 1912 | int sw_mode = b->ops->works_in_software_mode (b); |
| 1913 | |
| 1914 | if (target_resources_ok == 0 && !sw_mode) |
| 1915 | error (_("Target does not support this type of " |
| 1916 | "hardware watchpoint.")); |
| 1917 | else if (target_resources_ok < 0 && !sw_mode) |
| 1918 | error (_("There are not enough available hardware " |
| 1919 | "resources for this watchpoint.")); |
| 1920 | |
| 1921 | /* Downgrade to software watchpoint. */ |
| 1922 | b->type = bp_watchpoint; |
| 1923 | } |
| 1924 | else |
| 1925 | { |
| 1926 | /* If this was a software watchpoint, we've just |
| 1927 | found we have enough resources to turn it to a |
| 1928 | hardware watchpoint. Otherwise, this is a |
| 1929 | nop. */ |
| 1930 | b->type = type; |
| 1931 | } |
| 1932 | } |
| 1933 | else if (!b->ops->works_in_software_mode (b)) |
| 1934 | { |
| 1935 | if (!can_use_hw_watchpoints) |
| 1936 | error (_("Can't set read/access watchpoint when " |
| 1937 | "hardware watchpoints are disabled.")); |
| 1938 | else |
| 1939 | error (_("Expression cannot be implemented with " |
| 1940 | "read/access watchpoint.")); |
| 1941 | } |
| 1942 | else |
| 1943 | b->type = bp_watchpoint; |
| 1944 | |
| 1945 | loc_type = (b->type == bp_watchpoint? bp_loc_other |
| 1946 | : bp_loc_hardware_watchpoint); |
| 1947 | for (bl = b->loc; bl; bl = bl->next) |
| 1948 | bl->loc_type = loc_type; |
| 1949 | } |
| 1950 | |
| 1951 | /* If a software watchpoint is not watching any memory, then the |
| 1952 | above left it without any location set up. But, |
| 1953 | bpstat_stop_status requires a location to be able to report |
| 1954 | stops, so make sure there's at least a dummy one. */ |
| 1955 | if (b->type == bp_watchpoint && b->loc == NULL) |
| 1956 | software_watchpoint_add_no_memory_location (b, frame_pspace); |
| 1957 | } |
| 1958 | else if (!within_current_scope) |
| 1959 | { |
| 1960 | printf_filtered (_("\ |
| 1961 | Watchpoint %d deleted because the program has left the block\n\ |
| 1962 | in which its expression is valid.\n"), |
| 1963 | b->number); |
| 1964 | watchpoint_del_at_next_stop (b); |
| 1965 | } |
| 1966 | |
| 1967 | /* Restore the selected frame. */ |
| 1968 | if (frame_saved) |
| 1969 | select_frame (frame_find_by_id (saved_frame_id)); |
| 1970 | } |
| 1971 | |
| 1972 | |
| 1973 | /* Returns 1 iff breakpoint location should be |
| 1974 | inserted in the inferior. We don't differentiate the type of BL's owner |
| 1975 | (breakpoint vs. tracepoint), although insert_location in tracepoint's |
| 1976 | breakpoint_ops is not defined, because in insert_bp_location, |
| 1977 | tracepoint's insert_location will not be called. */ |
| 1978 | static int |
| 1979 | should_be_inserted (struct bp_location *bl) |
| 1980 | { |
| 1981 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
| 1982 | return 0; |
| 1983 | |
| 1984 | if (bl->owner->disposition == disp_del_at_next_stop) |
| 1985 | return 0; |
| 1986 | |
| 1987 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
| 1988 | return 0; |
| 1989 | |
| 1990 | if (user_breakpoint_p (bl->owner) && bl->pspace->executing_startup) |
| 1991 | return 0; |
| 1992 | |
| 1993 | /* This is set for example, when we're attached to the parent of a |
| 1994 | vfork, and have detached from the child. The child is running |
| 1995 | free, and we expect it to do an exec or exit, at which point the |
| 1996 | OS makes the parent schedulable again (and the target reports |
| 1997 | that the vfork is done). Until the child is done with the shared |
| 1998 | memory region, do not insert breakpoints in the parent, otherwise |
| 1999 | the child could still trip on the parent's breakpoints. Since |
| 2000 | the parent is blocked anyway, it won't miss any breakpoint. */ |
| 2001 | if (bl->pspace->breakpoints_not_allowed) |
| 2002 | return 0; |
| 2003 | |
| 2004 | /* Don't insert a breakpoint if we're trying to step past its |
| 2005 | location, except if the breakpoint is a single-step breakpoint, |
| 2006 | and the breakpoint's thread is the thread which is stepping past |
| 2007 | a breakpoint. */ |
| 2008 | if ((bl->loc_type == bp_loc_software_breakpoint |
| 2009 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 2010 | && stepping_past_instruction_at (bl->pspace->aspace, |
| 2011 | bl->address) |
| 2012 | /* The single-step breakpoint may be inserted at the location |
| 2013 | we're trying to step if the instruction branches to itself. |
| 2014 | However, the instruction won't be executed at all and it may |
| 2015 | break the semantics of the instruction, for example, the |
| 2016 | instruction is a conditional branch or updates some flags. |
| 2017 | We can't fix it unless GDB is able to emulate the instruction |
| 2018 | or switch to displaced stepping. */ |
| 2019 | && !(bl->owner->type == bp_single_step |
| 2020 | && thread_is_stepping_over_breakpoint (bl->owner->thread))) |
| 2021 | { |
| 2022 | if (debug_infrun) |
| 2023 | { |
| 2024 | fprintf_unfiltered (gdb_stdlog, |
| 2025 | "infrun: skipping breakpoint: " |
| 2026 | "stepping past insn at: %s\n", |
| 2027 | paddress (bl->gdbarch, bl->address)); |
| 2028 | } |
| 2029 | return 0; |
| 2030 | } |
| 2031 | |
| 2032 | /* Don't insert watchpoints if we're trying to step past the |
| 2033 | instruction that triggered one. */ |
| 2034 | if ((bl->loc_type == bp_loc_hardware_watchpoint) |
| 2035 | && stepping_past_nonsteppable_watchpoint ()) |
| 2036 | { |
| 2037 | if (debug_infrun) |
| 2038 | { |
| 2039 | fprintf_unfiltered (gdb_stdlog, |
| 2040 | "infrun: stepping past non-steppable watchpoint. " |
| 2041 | "skipping watchpoint at %s:%d\n", |
| 2042 | paddress (bl->gdbarch, bl->address), |
| 2043 | bl->length); |
| 2044 | } |
| 2045 | return 0; |
| 2046 | } |
| 2047 | |
| 2048 | return 1; |
| 2049 | } |
| 2050 | |
| 2051 | /* Same as should_be_inserted but does the check assuming |
| 2052 | that the location is not duplicated. */ |
| 2053 | |
| 2054 | static int |
| 2055 | unduplicated_should_be_inserted (struct bp_location *bl) |
| 2056 | { |
| 2057 | int result; |
| 2058 | const int save_duplicate = bl->duplicate; |
| 2059 | |
| 2060 | bl->duplicate = 0; |
| 2061 | result = should_be_inserted (bl); |
| 2062 | bl->duplicate = save_duplicate; |
| 2063 | return result; |
| 2064 | } |
| 2065 | |
| 2066 | /* Parses a conditional described by an expression COND into an |
| 2067 | agent expression bytecode suitable for evaluation |
| 2068 | by the bytecode interpreter. Return NULL if there was |
| 2069 | any error during parsing. */ |
| 2070 | |
| 2071 | static agent_expr_up |
| 2072 | parse_cond_to_aexpr (CORE_ADDR scope, struct expression *cond) |
| 2073 | { |
| 2074 | if (cond == NULL) |
| 2075 | return NULL; |
| 2076 | |
| 2077 | agent_expr_up aexpr; |
| 2078 | |
| 2079 | /* We don't want to stop processing, so catch any errors |
| 2080 | that may show up. */ |
| 2081 | try |
| 2082 | { |
| 2083 | aexpr = gen_eval_for_expr (scope, cond); |
| 2084 | } |
| 2085 | |
| 2086 | catch (const gdb_exception_error &ex) |
| 2087 | { |
| 2088 | /* If we got here, it means the condition could not be parsed to a valid |
| 2089 | bytecode expression and thus can't be evaluated on the target's side. |
| 2090 | It's no use iterating through the conditions. */ |
| 2091 | } |
| 2092 | |
| 2093 | /* We have a valid agent expression. */ |
| 2094 | return aexpr; |
| 2095 | } |
| 2096 | |
| 2097 | /* Based on location BL, create a list of breakpoint conditions to be |
| 2098 | passed on to the target. If we have duplicated locations with different |
| 2099 | conditions, we will add such conditions to the list. The idea is that the |
| 2100 | target will evaluate the list of conditions and will only notify GDB when |
| 2101 | one of them is true. */ |
| 2102 | |
| 2103 | static void |
| 2104 | build_target_condition_list (struct bp_location *bl) |
| 2105 | { |
| 2106 | struct bp_location **locp = NULL, **loc2p; |
| 2107 | int null_condition_or_parse_error = 0; |
| 2108 | int modified = bl->needs_update; |
| 2109 | struct bp_location *loc; |
| 2110 | |
| 2111 | /* Release conditions left over from a previous insert. */ |
| 2112 | bl->target_info.conditions.clear (); |
| 2113 | |
| 2114 | /* This is only meaningful if the target is |
| 2115 | evaluating conditions and if the user has |
| 2116 | opted for condition evaluation on the target's |
| 2117 | side. */ |
| 2118 | if (gdb_evaluates_breakpoint_condition_p () |
| 2119 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 2120 | return; |
| 2121 | |
| 2122 | /* Do a first pass to check for locations with no assigned |
| 2123 | conditions or conditions that fail to parse to a valid agent expression |
| 2124 | bytecode. If any of these happen, then it's no use to send conditions |
| 2125 | to the target since this location will always trigger and generate a |
| 2126 | response back to GDB. */ |
| 2127 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2128 | { |
| 2129 | loc = (*loc2p); |
| 2130 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2131 | { |
| 2132 | if (modified) |
| 2133 | { |
| 2134 | /* Re-parse the conditions since something changed. In that |
| 2135 | case we already freed the condition bytecodes (see |
| 2136 | force_breakpoint_reinsertion). We just |
| 2137 | need to parse the condition to bytecodes again. */ |
| 2138 | loc->cond_bytecode = parse_cond_to_aexpr (bl->address, |
| 2139 | loc->cond.get ()); |
| 2140 | } |
| 2141 | |
| 2142 | /* If we have a NULL bytecode expression, it means something |
| 2143 | went wrong or we have a null condition expression. */ |
| 2144 | if (!loc->cond_bytecode) |
| 2145 | { |
| 2146 | null_condition_or_parse_error = 1; |
| 2147 | break; |
| 2148 | } |
| 2149 | } |
| 2150 | } |
| 2151 | |
| 2152 | /* If any of these happened, it means we will have to evaluate the conditions |
| 2153 | for the location's address on gdb's side. It is no use keeping bytecodes |
| 2154 | for all the other duplicate locations, thus we free all of them here. |
| 2155 | |
| 2156 | This is so we have a finer control over which locations' conditions are |
| 2157 | being evaluated by GDB or the remote stub. */ |
| 2158 | if (null_condition_or_parse_error) |
| 2159 | { |
| 2160 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2161 | { |
| 2162 | loc = (*loc2p); |
| 2163 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2164 | { |
| 2165 | /* Only go as far as the first NULL bytecode is |
| 2166 | located. */ |
| 2167 | if (!loc->cond_bytecode) |
| 2168 | return; |
| 2169 | |
| 2170 | loc->cond_bytecode.reset (); |
| 2171 | } |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | /* No NULL conditions or failed bytecode generation. Build a condition list |
| 2176 | for this location's address. */ |
| 2177 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2178 | { |
| 2179 | loc = (*loc2p); |
| 2180 | if (loc->cond |
| 2181 | && is_breakpoint (loc->owner) |
| 2182 | && loc->pspace->num == bl->pspace->num |
| 2183 | && loc->owner->enable_state == bp_enabled |
| 2184 | && loc->enabled) |
| 2185 | { |
| 2186 | /* Add the condition to the vector. This will be used later |
| 2187 | to send the conditions to the target. */ |
| 2188 | bl->target_info.conditions.push_back (loc->cond_bytecode.get ()); |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | return; |
| 2193 | } |
| 2194 | |
| 2195 | /* Parses a command described by string CMD into an agent expression |
| 2196 | bytecode suitable for evaluation by the bytecode interpreter. |
| 2197 | Return NULL if there was any error during parsing. */ |
| 2198 | |
| 2199 | static agent_expr_up |
| 2200 | parse_cmd_to_aexpr (CORE_ADDR scope, char *cmd) |
| 2201 | { |
| 2202 | const char *cmdrest; |
| 2203 | const char *format_start, *format_end; |
| 2204 | struct gdbarch *gdbarch = get_current_arch (); |
| 2205 | |
| 2206 | if (cmd == NULL) |
| 2207 | return NULL; |
| 2208 | |
| 2209 | cmdrest = cmd; |
| 2210 | |
| 2211 | if (*cmdrest == ',') |
| 2212 | ++cmdrest; |
| 2213 | cmdrest = skip_spaces (cmdrest); |
| 2214 | |
| 2215 | if (*cmdrest++ != '"') |
| 2216 | error (_("No format string following the location")); |
| 2217 | |
| 2218 | format_start = cmdrest; |
| 2219 | |
| 2220 | format_pieces fpieces (&cmdrest); |
| 2221 | |
| 2222 | format_end = cmdrest; |
| 2223 | |
| 2224 | if (*cmdrest++ != '"') |
| 2225 | error (_("Bad format string, non-terminated '\"'.")); |
| 2226 | |
| 2227 | cmdrest = skip_spaces (cmdrest); |
| 2228 | |
| 2229 | if (!(*cmdrest == ',' || *cmdrest == '\0')) |
| 2230 | error (_("Invalid argument syntax")); |
| 2231 | |
| 2232 | if (*cmdrest == ',') |
| 2233 | cmdrest++; |
| 2234 | cmdrest = skip_spaces (cmdrest); |
| 2235 | |
| 2236 | /* For each argument, make an expression. */ |
| 2237 | |
| 2238 | std::vector<struct expression *> argvec; |
| 2239 | while (*cmdrest != '\0') |
| 2240 | { |
| 2241 | const char *cmd1; |
| 2242 | |
| 2243 | cmd1 = cmdrest; |
| 2244 | expression_up expr = parse_exp_1 (&cmd1, scope, block_for_pc (scope), 1); |
| 2245 | argvec.push_back (expr.release ()); |
| 2246 | cmdrest = cmd1; |
| 2247 | if (*cmdrest == ',') |
| 2248 | ++cmdrest; |
| 2249 | } |
| 2250 | |
| 2251 | agent_expr_up aexpr; |
| 2252 | |
| 2253 | /* We don't want to stop processing, so catch any errors |
| 2254 | that may show up. */ |
| 2255 | try |
| 2256 | { |
| 2257 | aexpr = gen_printf (scope, gdbarch, 0, 0, |
| 2258 | format_start, format_end - format_start, |
| 2259 | argvec.size (), argvec.data ()); |
| 2260 | } |
| 2261 | catch (const gdb_exception_error &ex) |
| 2262 | { |
| 2263 | /* If we got here, it means the command could not be parsed to a valid |
| 2264 | bytecode expression and thus can't be evaluated on the target's side. |
| 2265 | It's no use iterating through the other commands. */ |
| 2266 | } |
| 2267 | |
| 2268 | /* We have a valid agent expression, return it. */ |
| 2269 | return aexpr; |
| 2270 | } |
| 2271 | |
| 2272 | /* Based on location BL, create a list of breakpoint commands to be |
| 2273 | passed on to the target. If we have duplicated locations with |
| 2274 | different commands, we will add any such to the list. */ |
| 2275 | |
| 2276 | static void |
| 2277 | build_target_command_list (struct bp_location *bl) |
| 2278 | { |
| 2279 | struct bp_location **locp = NULL, **loc2p; |
| 2280 | int null_command_or_parse_error = 0; |
| 2281 | int modified = bl->needs_update; |
| 2282 | struct bp_location *loc; |
| 2283 | |
| 2284 | /* Clear commands left over from a previous insert. */ |
| 2285 | bl->target_info.tcommands.clear (); |
| 2286 | |
| 2287 | if (!target_can_run_breakpoint_commands ()) |
| 2288 | return; |
| 2289 | |
| 2290 | /* For now, limit to agent-style dprintf breakpoints. */ |
| 2291 | if (dprintf_style != dprintf_style_agent) |
| 2292 | return; |
| 2293 | |
| 2294 | /* For now, if we have any duplicate location that isn't a dprintf, |
| 2295 | don't install the target-side commands, as that would make the |
| 2296 | breakpoint not be reported to the core, and we'd lose |
| 2297 | control. */ |
| 2298 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2299 | { |
| 2300 | loc = (*loc2p); |
| 2301 | if (is_breakpoint (loc->owner) |
| 2302 | && loc->pspace->num == bl->pspace->num |
| 2303 | && loc->owner->type != bp_dprintf) |
| 2304 | return; |
| 2305 | } |
| 2306 | |
| 2307 | /* Do a first pass to check for locations with no assigned |
| 2308 | conditions or conditions that fail to parse to a valid agent expression |
| 2309 | bytecode. If any of these happen, then it's no use to send conditions |
| 2310 | to the target since this location will always trigger and generate a |
| 2311 | response back to GDB. */ |
| 2312 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2313 | { |
| 2314 | loc = (*loc2p); |
| 2315 | if (is_breakpoint (loc->owner) && loc->pspace->num == bl->pspace->num) |
| 2316 | { |
| 2317 | if (modified) |
| 2318 | { |
| 2319 | /* Re-parse the commands since something changed. In that |
| 2320 | case we already freed the command bytecodes (see |
| 2321 | force_breakpoint_reinsertion). We just |
| 2322 | need to parse the command to bytecodes again. */ |
| 2323 | loc->cmd_bytecode |
| 2324 | = parse_cmd_to_aexpr (bl->address, |
| 2325 | loc->owner->extra_string); |
| 2326 | } |
| 2327 | |
| 2328 | /* If we have a NULL bytecode expression, it means something |
| 2329 | went wrong or we have a null command expression. */ |
| 2330 | if (!loc->cmd_bytecode) |
| 2331 | { |
| 2332 | null_command_or_parse_error = 1; |
| 2333 | break; |
| 2334 | } |
| 2335 | } |
| 2336 | } |
| 2337 | |
| 2338 | /* If anything failed, then we're not doing target-side commands, |
| 2339 | and so clean up. */ |
| 2340 | if (null_command_or_parse_error) |
| 2341 | { |
| 2342 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2343 | { |
| 2344 | loc = (*loc2p); |
| 2345 | if (is_breakpoint (loc->owner) |
| 2346 | && loc->pspace->num == bl->pspace->num) |
| 2347 | { |
| 2348 | /* Only go as far as the first NULL bytecode is |
| 2349 | located. */ |
| 2350 | if (loc->cmd_bytecode == NULL) |
| 2351 | return; |
| 2352 | |
| 2353 | loc->cmd_bytecode.reset (); |
| 2354 | } |
| 2355 | } |
| 2356 | } |
| 2357 | |
| 2358 | /* No NULL commands or failed bytecode generation. Build a command list |
| 2359 | for this location's address. */ |
| 2360 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, bl->address) |
| 2361 | { |
| 2362 | loc = (*loc2p); |
| 2363 | if (loc->owner->extra_string |
| 2364 | && is_breakpoint (loc->owner) |
| 2365 | && loc->pspace->num == bl->pspace->num |
| 2366 | && loc->owner->enable_state == bp_enabled |
| 2367 | && loc->enabled) |
| 2368 | { |
| 2369 | /* Add the command to the vector. This will be used later |
| 2370 | to send the commands to the target. */ |
| 2371 | bl->target_info.tcommands.push_back (loc->cmd_bytecode.get ()); |
| 2372 | } |
| 2373 | } |
| 2374 | |
| 2375 | bl->target_info.persist = 0; |
| 2376 | /* Maybe flag this location as persistent. */ |
| 2377 | if (bl->owner->type == bp_dprintf && disconnected_dprintf) |
| 2378 | bl->target_info.persist = 1; |
| 2379 | } |
| 2380 | |
| 2381 | /* Return the kind of breakpoint on address *ADDR. Get the kind |
| 2382 | of breakpoint according to ADDR except single-step breakpoint. |
| 2383 | Get the kind of single-step breakpoint according to the current |
| 2384 | registers state. */ |
| 2385 | |
| 2386 | static int |
| 2387 | breakpoint_kind (struct bp_location *bl, CORE_ADDR *addr) |
| 2388 | { |
| 2389 | if (bl->owner->type == bp_single_step) |
| 2390 | { |
| 2391 | struct thread_info *thr = find_thread_global_id (bl->owner->thread); |
| 2392 | struct regcache *regcache; |
| 2393 | |
| 2394 | regcache = get_thread_regcache (thr); |
| 2395 | |
| 2396 | return gdbarch_breakpoint_kind_from_current_state (bl->gdbarch, |
| 2397 | regcache, addr); |
| 2398 | } |
| 2399 | else |
| 2400 | return gdbarch_breakpoint_kind_from_pc (bl->gdbarch, addr); |
| 2401 | } |
| 2402 | |
| 2403 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
| 2404 | location. Any error messages are printed to TMP_ERROR_STREAM; and |
| 2405 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
| 2406 | Returns 0 for success, 1 if the bp_location type is not supported or |
| 2407 | -1 for failure. |
| 2408 | |
| 2409 | NOTE drow/2003-09-09: This routine could be broken down to an |
| 2410 | object-style method for each breakpoint or catchpoint type. */ |
| 2411 | static int |
| 2412 | insert_bp_location (struct bp_location *bl, |
| 2413 | struct ui_file *tmp_error_stream, |
| 2414 | int *disabled_breaks, |
| 2415 | int *hw_breakpoint_error, |
| 2416 | int *hw_bp_error_explained_already) |
| 2417 | { |
| 2418 | gdb_exception bp_excpt; |
| 2419 | |
| 2420 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
| 2421 | return 0; |
| 2422 | |
| 2423 | /* Note we don't initialize bl->target_info, as that wipes out |
| 2424 | the breakpoint location's shadow_contents if the breakpoint |
| 2425 | is still inserted at that location. This in turn breaks |
| 2426 | target_read_memory which depends on these buffers when |
| 2427 | a memory read is requested at the breakpoint location: |
| 2428 | Once the target_info has been wiped, we fail to see that |
| 2429 | we have a breakpoint inserted at that address and thus |
| 2430 | read the breakpoint instead of returning the data saved in |
| 2431 | the breakpoint location's shadow contents. */ |
| 2432 | bl->target_info.reqstd_address = bl->address; |
| 2433 | bl->target_info.placed_address_space = bl->pspace->aspace; |
| 2434 | bl->target_info.length = bl->length; |
| 2435 | |
| 2436 | /* When working with target-side conditions, we must pass all the conditions |
| 2437 | for the same breakpoint address down to the target since GDB will not |
| 2438 | insert those locations. With a list of breakpoint conditions, the target |
| 2439 | can decide when to stop and notify GDB. */ |
| 2440 | |
| 2441 | if (is_breakpoint (bl->owner)) |
| 2442 | { |
| 2443 | build_target_condition_list (bl); |
| 2444 | build_target_command_list (bl); |
| 2445 | /* Reset the modification marker. */ |
| 2446 | bl->needs_update = 0; |
| 2447 | } |
| 2448 | |
| 2449 | if (bl->loc_type == bp_loc_software_breakpoint |
| 2450 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 2451 | { |
| 2452 | if (bl->owner->type != bp_hardware_breakpoint) |
| 2453 | { |
| 2454 | /* If the explicitly specified breakpoint type |
| 2455 | is not hardware breakpoint, check the memory map to see |
| 2456 | if the breakpoint address is in read only memory or not. |
| 2457 | |
| 2458 | Two important cases are: |
| 2459 | - location type is not hardware breakpoint, memory |
| 2460 | is readonly. We change the type of the location to |
| 2461 | hardware breakpoint. |
| 2462 | - location type is hardware breakpoint, memory is |
| 2463 | read-write. This means we've previously made the |
| 2464 | location hardware one, but then the memory map changed, |
| 2465 | so we undo. |
| 2466 | |
| 2467 | When breakpoints are removed, remove_breakpoints will use |
| 2468 | location types we've just set here, the only possible |
| 2469 | problem is that memory map has changed during running |
| 2470 | program, but it's not going to work anyway with current |
| 2471 | gdb. */ |
| 2472 | struct mem_region *mr |
| 2473 | = lookup_mem_region (bl->target_info.reqstd_address); |
| 2474 | |
| 2475 | if (mr) |
| 2476 | { |
| 2477 | if (automatic_hardware_breakpoints) |
| 2478 | { |
| 2479 | enum bp_loc_type new_type; |
| 2480 | |
| 2481 | if (mr->attrib.mode != MEM_RW) |
| 2482 | new_type = bp_loc_hardware_breakpoint; |
| 2483 | else |
| 2484 | new_type = bp_loc_software_breakpoint; |
| 2485 | |
| 2486 | if (new_type != bl->loc_type) |
| 2487 | { |
| 2488 | static int said = 0; |
| 2489 | |
| 2490 | bl->loc_type = new_type; |
| 2491 | if (!said) |
| 2492 | { |
| 2493 | fprintf_filtered (gdb_stdout, |
| 2494 | _("Note: automatically using " |
| 2495 | "hardware breakpoints for " |
| 2496 | "read-only addresses.\n")); |
| 2497 | said = 1; |
| 2498 | } |
| 2499 | } |
| 2500 | } |
| 2501 | else if (bl->loc_type == bp_loc_software_breakpoint |
| 2502 | && mr->attrib.mode != MEM_RW) |
| 2503 | { |
| 2504 | fprintf_unfiltered (tmp_error_stream, |
| 2505 | _("Cannot insert breakpoint %d.\n" |
| 2506 | "Cannot set software breakpoint " |
| 2507 | "at read-only address %s\n"), |
| 2508 | bl->owner->number, |
| 2509 | paddress (bl->gdbarch, bl->address)); |
| 2510 | return 1; |
| 2511 | } |
| 2512 | } |
| 2513 | } |
| 2514 | |
| 2515 | /* First check to see if we have to handle an overlay. */ |
| 2516 | if (overlay_debugging == ovly_off |
| 2517 | || bl->section == NULL |
| 2518 | || !(section_is_overlay (bl->section))) |
| 2519 | { |
| 2520 | /* No overlay handling: just set the breakpoint. */ |
| 2521 | try |
| 2522 | { |
| 2523 | int val; |
| 2524 | |
| 2525 | val = bl->owner->ops->insert_location (bl); |
| 2526 | if (val) |
| 2527 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
| 2528 | } |
| 2529 | catch (gdb_exception &e) |
| 2530 | { |
| 2531 | bp_excpt = std::move (e); |
| 2532 | } |
| 2533 | } |
| 2534 | else |
| 2535 | { |
| 2536 | /* This breakpoint is in an overlay section. |
| 2537 | Shall we set a breakpoint at the LMA? */ |
| 2538 | if (!overlay_events_enabled) |
| 2539 | { |
| 2540 | /* Yes -- overlay event support is not active, |
| 2541 | so we must try to set a breakpoint at the LMA. |
| 2542 | This will not work for a hardware breakpoint. */ |
| 2543 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 2544 | warning (_("hardware breakpoint %d not supported in overlay!"), |
| 2545 | bl->owner->number); |
| 2546 | else |
| 2547 | { |
| 2548 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
| 2549 | bl->section); |
| 2550 | /* Set a software (trap) breakpoint at the LMA. */ |
| 2551 | bl->overlay_target_info = bl->target_info; |
| 2552 | bl->overlay_target_info.reqstd_address = addr; |
| 2553 | |
| 2554 | /* No overlay handling: just set the breakpoint. */ |
| 2555 | try |
| 2556 | { |
| 2557 | int val; |
| 2558 | |
| 2559 | bl->overlay_target_info.kind |
| 2560 | = breakpoint_kind (bl, &addr); |
| 2561 | bl->overlay_target_info.placed_address = addr; |
| 2562 | val = target_insert_breakpoint (bl->gdbarch, |
| 2563 | &bl->overlay_target_info); |
| 2564 | if (val) |
| 2565 | bp_excpt |
| 2566 | = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
| 2567 | } |
| 2568 | catch (gdb_exception &e) |
| 2569 | { |
| 2570 | bp_excpt = std::move (e); |
| 2571 | } |
| 2572 | |
| 2573 | if (bp_excpt.reason != 0) |
| 2574 | fprintf_unfiltered (tmp_error_stream, |
| 2575 | "Overlay breakpoint %d " |
| 2576 | "failed: in ROM?\n", |
| 2577 | bl->owner->number); |
| 2578 | } |
| 2579 | } |
| 2580 | /* Shall we set a breakpoint at the VMA? */ |
| 2581 | if (section_is_mapped (bl->section)) |
| 2582 | { |
| 2583 | /* Yes. This overlay section is mapped into memory. */ |
| 2584 | try |
| 2585 | { |
| 2586 | int val; |
| 2587 | |
| 2588 | val = bl->owner->ops->insert_location (bl); |
| 2589 | if (val) |
| 2590 | bp_excpt = gdb_exception {RETURN_ERROR, GENERIC_ERROR}; |
| 2591 | } |
| 2592 | catch (gdb_exception &e) |
| 2593 | { |
| 2594 | bp_excpt = std::move (e); |
| 2595 | } |
| 2596 | } |
| 2597 | else |
| 2598 | { |
| 2599 | /* No. This breakpoint will not be inserted. |
| 2600 | No error, but do not mark the bp as 'inserted'. */ |
| 2601 | return 0; |
| 2602 | } |
| 2603 | } |
| 2604 | |
| 2605 | if (bp_excpt.reason != 0) |
| 2606 | { |
| 2607 | /* Can't set the breakpoint. */ |
| 2608 | |
| 2609 | /* In some cases, we might not be able to insert a |
| 2610 | breakpoint in a shared library that has already been |
| 2611 | removed, but we have not yet processed the shlib unload |
| 2612 | event. Unfortunately, some targets that implement |
| 2613 | breakpoint insertion themselves can't tell why the |
| 2614 | breakpoint insertion failed (e.g., the remote target |
| 2615 | doesn't define error codes), so we must treat generic |
| 2616 | errors as memory errors. */ |
| 2617 | if (bp_excpt.reason == RETURN_ERROR |
| 2618 | && (bp_excpt.error == GENERIC_ERROR |
| 2619 | || bp_excpt.error == MEMORY_ERROR) |
| 2620 | && bl->loc_type == bp_loc_software_breakpoint |
| 2621 | && (solib_name_from_address (bl->pspace, bl->address) |
| 2622 | || shared_objfile_contains_address_p (bl->pspace, |
| 2623 | bl->address))) |
| 2624 | { |
| 2625 | /* See also: disable_breakpoints_in_shlibs. */ |
| 2626 | bl->shlib_disabled = 1; |
| 2627 | gdb::observers::breakpoint_modified.notify (bl->owner); |
| 2628 | if (!*disabled_breaks) |
| 2629 | { |
| 2630 | fprintf_unfiltered (tmp_error_stream, |
| 2631 | "Cannot insert breakpoint %d.\n", |
| 2632 | bl->owner->number); |
| 2633 | fprintf_unfiltered (tmp_error_stream, |
| 2634 | "Temporarily disabling shared " |
| 2635 | "library breakpoints:\n"); |
| 2636 | } |
| 2637 | *disabled_breaks = 1; |
| 2638 | fprintf_unfiltered (tmp_error_stream, |
| 2639 | "breakpoint #%d\n", bl->owner->number); |
| 2640 | return 0; |
| 2641 | } |
| 2642 | else |
| 2643 | { |
| 2644 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 2645 | { |
| 2646 | *hw_breakpoint_error = 1; |
| 2647 | *hw_bp_error_explained_already = bp_excpt.message != NULL; |
| 2648 | fprintf_unfiltered (tmp_error_stream, |
| 2649 | "Cannot insert hardware breakpoint %d%s", |
| 2650 | bl->owner->number, |
| 2651 | bp_excpt.message ? ":" : ".\n"); |
| 2652 | if (bp_excpt.message != NULL) |
| 2653 | fprintf_unfiltered (tmp_error_stream, "%s.\n", |
| 2654 | bp_excpt.what ()); |
| 2655 | } |
| 2656 | else |
| 2657 | { |
| 2658 | if (bp_excpt.message == NULL) |
| 2659 | { |
| 2660 | std::string message |
| 2661 | = memory_error_message (TARGET_XFER_E_IO, |
| 2662 | bl->gdbarch, bl->address); |
| 2663 | |
| 2664 | fprintf_unfiltered (tmp_error_stream, |
| 2665 | "Cannot insert breakpoint %d.\n" |
| 2666 | "%s\n", |
| 2667 | bl->owner->number, message.c_str ()); |
| 2668 | } |
| 2669 | else |
| 2670 | { |
| 2671 | fprintf_unfiltered (tmp_error_stream, |
| 2672 | "Cannot insert breakpoint %d: %s\n", |
| 2673 | bl->owner->number, |
| 2674 | bp_excpt.what ()); |
| 2675 | } |
| 2676 | } |
| 2677 | return 1; |
| 2678 | |
| 2679 | } |
| 2680 | } |
| 2681 | else |
| 2682 | bl->inserted = 1; |
| 2683 | |
| 2684 | return 0; |
| 2685 | } |
| 2686 | |
| 2687 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
| 2688 | /* NOTE drow/2003-09-08: This state only exists for removing |
| 2689 | watchpoints. It's not clear that it's necessary... */ |
| 2690 | && bl->owner->disposition != disp_del_at_next_stop) |
| 2691 | { |
| 2692 | int val; |
| 2693 | |
| 2694 | gdb_assert (bl->owner->ops != NULL |
| 2695 | && bl->owner->ops->insert_location != NULL); |
| 2696 | |
| 2697 | val = bl->owner->ops->insert_location (bl); |
| 2698 | |
| 2699 | /* If trying to set a read-watchpoint, and it turns out it's not |
| 2700 | supported, try emulating one with an access watchpoint. */ |
| 2701 | if (val == 1 && bl->watchpoint_type == hw_read) |
| 2702 | { |
| 2703 | struct bp_location *loc, **loc_temp; |
| 2704 | |
| 2705 | /* But don't try to insert it, if there's already another |
| 2706 | hw_access location that would be considered a duplicate |
| 2707 | of this one. */ |
| 2708 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 2709 | if (loc != bl |
| 2710 | && loc->watchpoint_type == hw_access |
| 2711 | && watchpoint_locations_match (bl, loc)) |
| 2712 | { |
| 2713 | bl->duplicate = 1; |
| 2714 | bl->inserted = 1; |
| 2715 | bl->target_info = loc->target_info; |
| 2716 | bl->watchpoint_type = hw_access; |
| 2717 | val = 0; |
| 2718 | break; |
| 2719 | } |
| 2720 | |
| 2721 | if (val == 1) |
| 2722 | { |
| 2723 | bl->watchpoint_type = hw_access; |
| 2724 | val = bl->owner->ops->insert_location (bl); |
| 2725 | |
| 2726 | if (val) |
| 2727 | /* Back to the original value. */ |
| 2728 | bl->watchpoint_type = hw_read; |
| 2729 | } |
| 2730 | } |
| 2731 | |
| 2732 | bl->inserted = (val == 0); |
| 2733 | } |
| 2734 | |
| 2735 | else if (bl->owner->type == bp_catchpoint) |
| 2736 | { |
| 2737 | int val; |
| 2738 | |
| 2739 | gdb_assert (bl->owner->ops != NULL |
| 2740 | && bl->owner->ops->insert_location != NULL); |
| 2741 | |
| 2742 | val = bl->owner->ops->insert_location (bl); |
| 2743 | if (val) |
| 2744 | { |
| 2745 | bl->owner->enable_state = bp_disabled; |
| 2746 | |
| 2747 | if (val == 1) |
| 2748 | warning (_("\ |
| 2749 | Error inserting catchpoint %d: Your system does not support this type\n\ |
| 2750 | of catchpoint."), bl->owner->number); |
| 2751 | else |
| 2752 | warning (_("Error inserting catchpoint %d."), bl->owner->number); |
| 2753 | } |
| 2754 | |
| 2755 | bl->inserted = (val == 0); |
| 2756 | |
| 2757 | /* We've already printed an error message if there was a problem |
| 2758 | inserting this catchpoint, and we've disabled the catchpoint, |
| 2759 | so just return success. */ |
| 2760 | return 0; |
| 2761 | } |
| 2762 | |
| 2763 | return 0; |
| 2764 | } |
| 2765 | |
| 2766 | /* This function is called when program space PSPACE is about to be |
| 2767 | deleted. It takes care of updating breakpoints to not reference |
| 2768 | PSPACE anymore. */ |
| 2769 | |
| 2770 | void |
| 2771 | breakpoint_program_space_exit (struct program_space *pspace) |
| 2772 | { |
| 2773 | struct breakpoint *b, *b_temp; |
| 2774 | struct bp_location *loc, **loc_temp; |
| 2775 | |
| 2776 | /* Remove any breakpoint that was set through this program space. */ |
| 2777 | ALL_BREAKPOINTS_SAFE (b, b_temp) |
| 2778 | { |
| 2779 | if (b->pspace == pspace) |
| 2780 | delete_breakpoint (b); |
| 2781 | } |
| 2782 | |
| 2783 | /* Breakpoints set through other program spaces could have locations |
| 2784 | bound to PSPACE as well. Remove those. */ |
| 2785 | ALL_BP_LOCATIONS (loc, loc_temp) |
| 2786 | { |
| 2787 | struct bp_location *tmp; |
| 2788 | |
| 2789 | if (loc->pspace == pspace) |
| 2790 | { |
| 2791 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 2792 | if (loc->owner->loc == loc) |
| 2793 | loc->owner->loc = loc->next; |
| 2794 | else |
| 2795 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) |
| 2796 | if (tmp->next == loc) |
| 2797 | { |
| 2798 | tmp->next = loc->next; |
| 2799 | break; |
| 2800 | } |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | /* Now update the global location list to permanently delete the |
| 2805 | removed locations above. */ |
| 2806 | update_global_location_list (UGLL_DONT_INSERT); |
| 2807 | } |
| 2808 | |
| 2809 | /* Make sure all breakpoints are inserted in inferior. |
| 2810 | Throws exception on any error. |
| 2811 | A breakpoint that is already inserted won't be inserted |
| 2812 | again, so calling this function twice is safe. */ |
| 2813 | void |
| 2814 | insert_breakpoints (void) |
| 2815 | { |
| 2816 | struct breakpoint *bpt; |
| 2817 | |
| 2818 | ALL_BREAKPOINTS (bpt) |
| 2819 | if (is_hardware_watchpoint (bpt)) |
| 2820 | { |
| 2821 | struct watchpoint *w = (struct watchpoint *) bpt; |
| 2822 | |
| 2823 | update_watchpoint (w, 0 /* don't reparse. */); |
| 2824 | } |
| 2825 | |
| 2826 | /* Updating watchpoints creates new locations, so update the global |
| 2827 | location list. Explicitly tell ugll to insert locations and |
| 2828 | ignore breakpoints_always_inserted_mode. */ |
| 2829 | update_global_location_list (UGLL_INSERT); |
| 2830 | } |
| 2831 | |
| 2832 | /* Invoke CALLBACK for each of bp_location. */ |
| 2833 | |
| 2834 | void |
| 2835 | iterate_over_bp_locations (walk_bp_location_callback callback) |
| 2836 | { |
| 2837 | struct bp_location *loc, **loc_tmp; |
| 2838 | |
| 2839 | ALL_BP_LOCATIONS (loc, loc_tmp) |
| 2840 | { |
| 2841 | callback (loc, NULL); |
| 2842 | } |
| 2843 | } |
| 2844 | |
| 2845 | /* This is used when we need to synch breakpoint conditions between GDB and the |
| 2846 | target. It is the case with deleting and disabling of breakpoints when using |
| 2847 | always-inserted mode. */ |
| 2848 | |
| 2849 | static void |
| 2850 | update_inserted_breakpoint_locations (void) |
| 2851 | { |
| 2852 | struct bp_location *bl, **blp_tmp; |
| 2853 | int error_flag = 0; |
| 2854 | int val = 0; |
| 2855 | int disabled_breaks = 0; |
| 2856 | int hw_breakpoint_error = 0; |
| 2857 | int hw_bp_details_reported = 0; |
| 2858 | |
| 2859 | string_file tmp_error_stream; |
| 2860 | |
| 2861 | /* Explicitly mark the warning -- this will only be printed if |
| 2862 | there was an error. */ |
| 2863 | tmp_error_stream.puts ("Warning:\n"); |
| 2864 | |
| 2865 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 2866 | |
| 2867 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 2868 | { |
| 2869 | /* We only want to update software breakpoints and hardware |
| 2870 | breakpoints. */ |
| 2871 | if (!is_breakpoint (bl->owner)) |
| 2872 | continue; |
| 2873 | |
| 2874 | /* We only want to update locations that are already inserted |
| 2875 | and need updating. This is to avoid unwanted insertion during |
| 2876 | deletion of breakpoints. */ |
| 2877 | if (!bl->inserted || !bl->needs_update) |
| 2878 | continue; |
| 2879 | |
| 2880 | switch_to_program_space_and_thread (bl->pspace); |
| 2881 | |
| 2882 | /* For targets that support global breakpoints, there's no need |
| 2883 | to select an inferior to insert breakpoint to. In fact, even |
| 2884 | if we aren't attached to any process yet, we should still |
| 2885 | insert breakpoints. */ |
| 2886 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 2887 | && inferior_ptid == null_ptid) |
| 2888 | continue; |
| 2889 | |
| 2890 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
| 2891 | &hw_breakpoint_error, &hw_bp_details_reported); |
| 2892 | if (val) |
| 2893 | error_flag = val; |
| 2894 | } |
| 2895 | |
| 2896 | if (error_flag) |
| 2897 | { |
| 2898 | target_terminal::ours_for_output (); |
| 2899 | error_stream (tmp_error_stream); |
| 2900 | } |
| 2901 | } |
| 2902 | |
| 2903 | /* Used when starting or continuing the program. */ |
| 2904 | |
| 2905 | static void |
| 2906 | insert_breakpoint_locations (void) |
| 2907 | { |
| 2908 | struct breakpoint *bpt; |
| 2909 | struct bp_location *bl, **blp_tmp; |
| 2910 | int error_flag = 0; |
| 2911 | int val = 0; |
| 2912 | int disabled_breaks = 0; |
| 2913 | int hw_breakpoint_error = 0; |
| 2914 | int hw_bp_error_explained_already = 0; |
| 2915 | |
| 2916 | string_file tmp_error_stream; |
| 2917 | |
| 2918 | /* Explicitly mark the warning -- this will only be printed if |
| 2919 | there was an error. */ |
| 2920 | tmp_error_stream.puts ("Warning:\n"); |
| 2921 | |
| 2922 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 2923 | |
| 2924 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 2925 | { |
| 2926 | if (!should_be_inserted (bl) || (bl->inserted && !bl->needs_update)) |
| 2927 | continue; |
| 2928 | |
| 2929 | /* There is no point inserting thread-specific breakpoints if |
| 2930 | the thread no longer exists. ALL_BP_LOCATIONS bp_location |
| 2931 | has BL->OWNER always non-NULL. */ |
| 2932 | if (bl->owner->thread != -1 |
| 2933 | && !valid_global_thread_id (bl->owner->thread)) |
| 2934 | continue; |
| 2935 | |
| 2936 | switch_to_program_space_and_thread (bl->pspace); |
| 2937 | |
| 2938 | /* For targets that support global breakpoints, there's no need |
| 2939 | to select an inferior to insert breakpoint to. In fact, even |
| 2940 | if we aren't attached to any process yet, we should still |
| 2941 | insert breakpoints. */ |
| 2942 | if (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 2943 | && inferior_ptid == null_ptid) |
| 2944 | continue; |
| 2945 | |
| 2946 | val = insert_bp_location (bl, &tmp_error_stream, &disabled_breaks, |
| 2947 | &hw_breakpoint_error, &hw_bp_error_explained_already); |
| 2948 | if (val) |
| 2949 | error_flag = val; |
| 2950 | } |
| 2951 | |
| 2952 | /* If we failed to insert all locations of a watchpoint, remove |
| 2953 | them, as half-inserted watchpoint is of limited use. */ |
| 2954 | ALL_BREAKPOINTS (bpt) |
| 2955 | { |
| 2956 | int some_failed = 0; |
| 2957 | struct bp_location *loc; |
| 2958 | |
| 2959 | if (!is_hardware_watchpoint (bpt)) |
| 2960 | continue; |
| 2961 | |
| 2962 | if (!breakpoint_enabled (bpt)) |
| 2963 | continue; |
| 2964 | |
| 2965 | if (bpt->disposition == disp_del_at_next_stop) |
| 2966 | continue; |
| 2967 | |
| 2968 | for (loc = bpt->loc; loc; loc = loc->next) |
| 2969 | if (!loc->inserted && should_be_inserted (loc)) |
| 2970 | { |
| 2971 | some_failed = 1; |
| 2972 | break; |
| 2973 | } |
| 2974 | if (some_failed) |
| 2975 | { |
| 2976 | for (loc = bpt->loc; loc; loc = loc->next) |
| 2977 | if (loc->inserted) |
| 2978 | remove_breakpoint (loc); |
| 2979 | |
| 2980 | hw_breakpoint_error = 1; |
| 2981 | tmp_error_stream.printf ("Could not insert " |
| 2982 | "hardware watchpoint %d.\n", |
| 2983 | bpt->number); |
| 2984 | error_flag = -1; |
| 2985 | } |
| 2986 | } |
| 2987 | |
| 2988 | if (error_flag) |
| 2989 | { |
| 2990 | /* If a hardware breakpoint or watchpoint was inserted, add a |
| 2991 | message about possibly exhausted resources. */ |
| 2992 | if (hw_breakpoint_error && !hw_bp_error_explained_already) |
| 2993 | { |
| 2994 | tmp_error_stream.printf ("Could not insert hardware breakpoints:\n\ |
| 2995 | You may have requested too many hardware breakpoints/watchpoints.\n"); |
| 2996 | } |
| 2997 | target_terminal::ours_for_output (); |
| 2998 | error_stream (tmp_error_stream); |
| 2999 | } |
| 3000 | } |
| 3001 | |
| 3002 | /* Used when the program stops. |
| 3003 | Returns zero if successful, or non-zero if there was a problem |
| 3004 | removing a breakpoint location. */ |
| 3005 | |
| 3006 | int |
| 3007 | remove_breakpoints (void) |
| 3008 | { |
| 3009 | struct bp_location *bl, **blp_tmp; |
| 3010 | int val = 0; |
| 3011 | |
| 3012 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3013 | { |
| 3014 | if (bl->inserted && !is_tracepoint (bl->owner)) |
| 3015 | val |= remove_breakpoint (bl); |
| 3016 | } |
| 3017 | return val; |
| 3018 | } |
| 3019 | |
| 3020 | /* When a thread exits, remove breakpoints that are related to |
| 3021 | that thread. */ |
| 3022 | |
| 3023 | static void |
| 3024 | remove_threaded_breakpoints (struct thread_info *tp, int silent) |
| 3025 | { |
| 3026 | struct breakpoint *b, *b_tmp; |
| 3027 | |
| 3028 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3029 | { |
| 3030 | if (b->thread == tp->global_num && user_breakpoint_p (b)) |
| 3031 | { |
| 3032 | b->disposition = disp_del_at_next_stop; |
| 3033 | |
| 3034 | printf_filtered (_("\ |
| 3035 | Thread-specific breakpoint %d deleted - thread %s no longer in the thread list.\n"), |
| 3036 | b->number, print_thread_id (tp)); |
| 3037 | |
| 3038 | /* Hide it from the user. */ |
| 3039 | b->number = 0; |
| 3040 | } |
| 3041 | } |
| 3042 | } |
| 3043 | |
| 3044 | /* See breakpoint.h. */ |
| 3045 | |
| 3046 | void |
| 3047 | remove_breakpoints_inf (inferior *inf) |
| 3048 | { |
| 3049 | struct bp_location *bl, **blp_tmp; |
| 3050 | int val; |
| 3051 | |
| 3052 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3053 | { |
| 3054 | if (bl->pspace != inf->pspace) |
| 3055 | continue; |
| 3056 | |
| 3057 | if (bl->inserted && !bl->target_info.persist) |
| 3058 | { |
| 3059 | val = remove_breakpoint (bl); |
| 3060 | if (val != 0) |
| 3061 | return; |
| 3062 | } |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | static int internal_breakpoint_number = -1; |
| 3067 | |
| 3068 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
| 3069 | If INTERNAL is non-zero, the breakpoint number will be populated |
| 3070 | from internal_breakpoint_number and that variable decremented. |
| 3071 | Otherwise the breakpoint number will be populated from |
| 3072 | breakpoint_count and that value incremented. Internal breakpoints |
| 3073 | do not set the internal var bpnum. */ |
| 3074 | static void |
| 3075 | set_breakpoint_number (int internal, struct breakpoint *b) |
| 3076 | { |
| 3077 | if (internal) |
| 3078 | b->number = internal_breakpoint_number--; |
| 3079 | else |
| 3080 | { |
| 3081 | set_breakpoint_count (breakpoint_count + 1); |
| 3082 | b->number = breakpoint_count; |
| 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | static struct breakpoint * |
| 3087 | create_internal_breakpoint (struct gdbarch *gdbarch, |
| 3088 | CORE_ADDR address, enum bptype type, |
| 3089 | const struct breakpoint_ops *ops) |
| 3090 | { |
| 3091 | symtab_and_line sal; |
| 3092 | sal.pc = address; |
| 3093 | sal.section = find_pc_overlay (sal.pc); |
| 3094 | sal.pspace = current_program_space; |
| 3095 | |
| 3096 | breakpoint *b = set_raw_breakpoint (gdbarch, sal, type, ops); |
| 3097 | b->number = internal_breakpoint_number--; |
| 3098 | b->disposition = disp_donttouch; |
| 3099 | |
| 3100 | return b; |
| 3101 | } |
| 3102 | |
| 3103 | static const char *const longjmp_names[] = |
| 3104 | { |
| 3105 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" |
| 3106 | }; |
| 3107 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) |
| 3108 | |
| 3109 | /* Per-objfile data private to breakpoint.c. */ |
| 3110 | struct breakpoint_objfile_data |
| 3111 | { |
| 3112 | /* Minimal symbol for "_ovly_debug_event" (if any). */ |
| 3113 | struct bound_minimal_symbol overlay_msym {}; |
| 3114 | |
| 3115 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ |
| 3116 | struct bound_minimal_symbol longjmp_msym[NUM_LONGJMP_NAMES] {}; |
| 3117 | |
| 3118 | /* True if we have looked for longjmp probes. */ |
| 3119 | int longjmp_searched = 0; |
| 3120 | |
| 3121 | /* SystemTap probe points for longjmp (if any). These are non-owning |
| 3122 | references. */ |
| 3123 | std::vector<probe *> longjmp_probes; |
| 3124 | |
| 3125 | /* Minimal symbol for "std::terminate()" (if any). */ |
| 3126 | struct bound_minimal_symbol terminate_msym {}; |
| 3127 | |
| 3128 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ |
| 3129 | struct bound_minimal_symbol exception_msym {}; |
| 3130 | |
| 3131 | /* True if we have looked for exception probes. */ |
| 3132 | int exception_searched = 0; |
| 3133 | |
| 3134 | /* SystemTap probe points for unwinding (if any). These are non-owning |
| 3135 | references. */ |
| 3136 | std::vector<probe *> exception_probes; |
| 3137 | }; |
| 3138 | |
| 3139 | static const struct objfile_key<breakpoint_objfile_data> |
| 3140 | breakpoint_objfile_key; |
| 3141 | |
| 3142 | /* Minimal symbol not found sentinel. */ |
| 3143 | static struct minimal_symbol msym_not_found; |
| 3144 | |
| 3145 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ |
| 3146 | |
| 3147 | static int |
| 3148 | msym_not_found_p (const struct minimal_symbol *msym) |
| 3149 | { |
| 3150 | return msym == &msym_not_found; |
| 3151 | } |
| 3152 | |
| 3153 | /* Return per-objfile data needed by breakpoint.c. |
| 3154 | Allocate the data if necessary. */ |
| 3155 | |
| 3156 | static struct breakpoint_objfile_data * |
| 3157 | get_breakpoint_objfile_data (struct objfile *objfile) |
| 3158 | { |
| 3159 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3160 | |
| 3161 | bp_objfile_data = breakpoint_objfile_key.get (objfile); |
| 3162 | if (bp_objfile_data == NULL) |
| 3163 | bp_objfile_data = breakpoint_objfile_key.emplace (objfile); |
| 3164 | return bp_objfile_data; |
| 3165 | } |
| 3166 | |
| 3167 | static void |
| 3168 | create_overlay_event_breakpoint (void) |
| 3169 | { |
| 3170 | const char *const func_name = "_ovly_debug_event"; |
| 3171 | |
| 3172 | for (objfile *objfile : current_program_space->objfiles ()) |
| 3173 | { |
| 3174 | struct breakpoint *b; |
| 3175 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3176 | CORE_ADDR addr; |
| 3177 | struct explicit_location explicit_loc; |
| 3178 | |
| 3179 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3180 | |
| 3181 | if (msym_not_found_p (bp_objfile_data->overlay_msym.minsym)) |
| 3182 | continue; |
| 3183 | |
| 3184 | if (bp_objfile_data->overlay_msym.minsym == NULL) |
| 3185 | { |
| 3186 | struct bound_minimal_symbol m; |
| 3187 | |
| 3188 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 3189 | if (m.minsym == NULL) |
| 3190 | { |
| 3191 | /* Avoid future lookups in this objfile. */ |
| 3192 | bp_objfile_data->overlay_msym.minsym = &msym_not_found; |
| 3193 | continue; |
| 3194 | } |
| 3195 | bp_objfile_data->overlay_msym = m; |
| 3196 | } |
| 3197 | |
| 3198 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
| 3199 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
| 3200 | bp_overlay_event, |
| 3201 | &internal_breakpoint_ops); |
| 3202 | initialize_explicit_location (&explicit_loc); |
| 3203 | explicit_loc.function_name = ASTRDUP (func_name); |
| 3204 | b->location = new_explicit_location (&explicit_loc); |
| 3205 | |
| 3206 | if (overlay_debugging == ovly_auto) |
| 3207 | { |
| 3208 | b->enable_state = bp_enabled; |
| 3209 | overlay_events_enabled = 1; |
| 3210 | } |
| 3211 | else |
| 3212 | { |
| 3213 | b->enable_state = bp_disabled; |
| 3214 | overlay_events_enabled = 0; |
| 3215 | } |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | static void |
| 3220 | create_longjmp_master_breakpoint (void) |
| 3221 | { |
| 3222 | struct program_space *pspace; |
| 3223 | |
| 3224 | scoped_restore_current_program_space restore_pspace; |
| 3225 | |
| 3226 | ALL_PSPACES (pspace) |
| 3227 | { |
| 3228 | set_current_program_space (pspace); |
| 3229 | |
| 3230 | for (objfile *objfile : current_program_space->objfiles ()) |
| 3231 | { |
| 3232 | int i; |
| 3233 | struct gdbarch *gdbarch; |
| 3234 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3235 | |
| 3236 | gdbarch = get_objfile_arch (objfile); |
| 3237 | |
| 3238 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3239 | |
| 3240 | if (!bp_objfile_data->longjmp_searched) |
| 3241 | { |
| 3242 | std::vector<probe *> ret |
| 3243 | = find_probes_in_objfile (objfile, "libc", "longjmp"); |
| 3244 | |
| 3245 | if (!ret.empty ()) |
| 3246 | { |
| 3247 | /* We are only interested in checking one element. */ |
| 3248 | probe *p = ret[0]; |
| 3249 | |
| 3250 | if (!p->can_evaluate_arguments ()) |
| 3251 | { |
| 3252 | /* We cannot use the probe interface here, because it does |
| 3253 | not know how to evaluate arguments. */ |
| 3254 | ret.clear (); |
| 3255 | } |
| 3256 | } |
| 3257 | bp_objfile_data->longjmp_probes = ret; |
| 3258 | bp_objfile_data->longjmp_searched = 1; |
| 3259 | } |
| 3260 | |
| 3261 | if (!bp_objfile_data->longjmp_probes.empty ()) |
| 3262 | { |
| 3263 | for (probe *p : bp_objfile_data->longjmp_probes) |
| 3264 | { |
| 3265 | struct breakpoint *b; |
| 3266 | |
| 3267 | b = create_internal_breakpoint (gdbarch, |
| 3268 | p->get_relocated_address (objfile), |
| 3269 | bp_longjmp_master, |
| 3270 | &internal_breakpoint_ops); |
| 3271 | b->location = new_probe_location ("-probe-stap libc:longjmp"); |
| 3272 | b->enable_state = bp_disabled; |
| 3273 | } |
| 3274 | |
| 3275 | continue; |
| 3276 | } |
| 3277 | |
| 3278 | if (!gdbarch_get_longjmp_target_p (gdbarch)) |
| 3279 | continue; |
| 3280 | |
| 3281 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) |
| 3282 | { |
| 3283 | struct breakpoint *b; |
| 3284 | const char *func_name; |
| 3285 | CORE_ADDR addr; |
| 3286 | struct explicit_location explicit_loc; |
| 3287 | |
| 3288 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i].minsym)) |
| 3289 | continue; |
| 3290 | |
| 3291 | func_name = longjmp_names[i]; |
| 3292 | if (bp_objfile_data->longjmp_msym[i].minsym == NULL) |
| 3293 | { |
| 3294 | struct bound_minimal_symbol m; |
| 3295 | |
| 3296 | m = lookup_minimal_symbol_text (func_name, objfile); |
| 3297 | if (m.minsym == NULL) |
| 3298 | { |
| 3299 | /* Prevent future lookups in this objfile. */ |
| 3300 | bp_objfile_data->longjmp_msym[i].minsym = &msym_not_found; |
| 3301 | continue; |
| 3302 | } |
| 3303 | bp_objfile_data->longjmp_msym[i] = m; |
| 3304 | } |
| 3305 | |
| 3306 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); |
| 3307 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
| 3308 | &internal_breakpoint_ops); |
| 3309 | initialize_explicit_location (&explicit_loc); |
| 3310 | explicit_loc.function_name = ASTRDUP (func_name); |
| 3311 | b->location = new_explicit_location (&explicit_loc); |
| 3312 | b->enable_state = bp_disabled; |
| 3313 | } |
| 3314 | } |
| 3315 | } |
| 3316 | } |
| 3317 | |
| 3318 | /* Create a master std::terminate breakpoint. */ |
| 3319 | static void |
| 3320 | create_std_terminate_master_breakpoint (void) |
| 3321 | { |
| 3322 | struct program_space *pspace; |
| 3323 | const char *const func_name = "std::terminate()"; |
| 3324 | |
| 3325 | scoped_restore_current_program_space restore_pspace; |
| 3326 | |
| 3327 | ALL_PSPACES (pspace) |
| 3328 | { |
| 3329 | CORE_ADDR addr; |
| 3330 | |
| 3331 | set_current_program_space (pspace); |
| 3332 | |
| 3333 | for (objfile *objfile : current_program_space->objfiles ()) |
| 3334 | { |
| 3335 | struct breakpoint *b; |
| 3336 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3337 | struct explicit_location explicit_loc; |
| 3338 | |
| 3339 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3340 | |
| 3341 | if (msym_not_found_p (bp_objfile_data->terminate_msym.minsym)) |
| 3342 | continue; |
| 3343 | |
| 3344 | if (bp_objfile_data->terminate_msym.minsym == NULL) |
| 3345 | { |
| 3346 | struct bound_minimal_symbol m; |
| 3347 | |
| 3348 | m = lookup_minimal_symbol (func_name, NULL, objfile); |
| 3349 | if (m.minsym == NULL || (MSYMBOL_TYPE (m.minsym) != mst_text |
| 3350 | && MSYMBOL_TYPE (m.minsym) != mst_file_text)) |
| 3351 | { |
| 3352 | /* Prevent future lookups in this objfile. */ |
| 3353 | bp_objfile_data->terminate_msym.minsym = &msym_not_found; |
| 3354 | continue; |
| 3355 | } |
| 3356 | bp_objfile_data->terminate_msym = m; |
| 3357 | } |
| 3358 | |
| 3359 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
| 3360 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, |
| 3361 | bp_std_terminate_master, |
| 3362 | &internal_breakpoint_ops); |
| 3363 | initialize_explicit_location (&explicit_loc); |
| 3364 | explicit_loc.function_name = ASTRDUP (func_name); |
| 3365 | b->location = new_explicit_location (&explicit_loc); |
| 3366 | b->enable_state = bp_disabled; |
| 3367 | } |
| 3368 | } |
| 3369 | } |
| 3370 | |
| 3371 | /* Install a master breakpoint on the unwinder's debug hook. */ |
| 3372 | |
| 3373 | static void |
| 3374 | create_exception_master_breakpoint (void) |
| 3375 | { |
| 3376 | const char *const func_name = "_Unwind_DebugHook"; |
| 3377 | |
| 3378 | for (objfile *objfile : current_program_space->objfiles ()) |
| 3379 | { |
| 3380 | struct breakpoint *b; |
| 3381 | struct gdbarch *gdbarch; |
| 3382 | struct breakpoint_objfile_data *bp_objfile_data; |
| 3383 | CORE_ADDR addr; |
| 3384 | struct explicit_location explicit_loc; |
| 3385 | |
| 3386 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
| 3387 | |
| 3388 | /* We prefer the SystemTap probe point if it exists. */ |
| 3389 | if (!bp_objfile_data->exception_searched) |
| 3390 | { |
| 3391 | std::vector<probe *> ret |
| 3392 | = find_probes_in_objfile (objfile, "libgcc", "unwind"); |
| 3393 | |
| 3394 | if (!ret.empty ()) |
| 3395 | { |
| 3396 | /* We are only interested in checking one element. */ |
| 3397 | probe *p = ret[0]; |
| 3398 | |
| 3399 | if (!p->can_evaluate_arguments ()) |
| 3400 | { |
| 3401 | /* We cannot use the probe interface here, because it does |
| 3402 | not know how to evaluate arguments. */ |
| 3403 | ret.clear (); |
| 3404 | } |
| 3405 | } |
| 3406 | bp_objfile_data->exception_probes = ret; |
| 3407 | bp_objfile_data->exception_searched = 1; |
| 3408 | } |
| 3409 | |
| 3410 | if (!bp_objfile_data->exception_probes.empty ()) |
| 3411 | { |
| 3412 | gdbarch = get_objfile_arch (objfile); |
| 3413 | |
| 3414 | for (probe *p : bp_objfile_data->exception_probes) |
| 3415 | { |
| 3416 | b = create_internal_breakpoint (gdbarch, |
| 3417 | p->get_relocated_address (objfile), |
| 3418 | bp_exception_master, |
| 3419 | &internal_breakpoint_ops); |
| 3420 | b->location = new_probe_location ("-probe-stap libgcc:unwind"); |
| 3421 | b->enable_state = bp_disabled; |
| 3422 | } |
| 3423 | |
| 3424 | continue; |
| 3425 | } |
| 3426 | |
| 3427 | /* Otherwise, try the hook function. */ |
| 3428 | |
| 3429 | if (msym_not_found_p (bp_objfile_data->exception_msym.minsym)) |
| 3430 | continue; |
| 3431 | |
| 3432 | gdbarch = get_objfile_arch (objfile); |
| 3433 | |
| 3434 | if (bp_objfile_data->exception_msym.minsym == NULL) |
| 3435 | { |
| 3436 | struct bound_minimal_symbol debug_hook; |
| 3437 | |
| 3438 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
| 3439 | if (debug_hook.minsym == NULL) |
| 3440 | { |
| 3441 | bp_objfile_data->exception_msym.minsym = &msym_not_found; |
| 3442 | continue; |
| 3443 | } |
| 3444 | |
| 3445 | bp_objfile_data->exception_msym = debug_hook; |
| 3446 | } |
| 3447 | |
| 3448 | addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); |
| 3449 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, |
| 3450 | current_top_target ()); |
| 3451 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
| 3452 | &internal_breakpoint_ops); |
| 3453 | initialize_explicit_location (&explicit_loc); |
| 3454 | explicit_loc.function_name = ASTRDUP (func_name); |
| 3455 | b->location = new_explicit_location (&explicit_loc); |
| 3456 | b->enable_state = bp_disabled; |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | /* Does B have a location spec? */ |
| 3461 | |
| 3462 | static int |
| 3463 | breakpoint_event_location_empty_p (const struct breakpoint *b) |
| 3464 | { |
| 3465 | return b->location != NULL && event_location_empty_p (b->location.get ()); |
| 3466 | } |
| 3467 | |
| 3468 | void |
| 3469 | update_breakpoints_after_exec (void) |
| 3470 | { |
| 3471 | struct breakpoint *b, *b_tmp; |
| 3472 | struct bp_location *bploc, **bplocp_tmp; |
| 3473 | |
| 3474 | /* We're about to delete breakpoints from GDB's lists. If the |
| 3475 | INSERTED flag is true, GDB will try to lift the breakpoints by |
| 3476 | writing the breakpoints' "shadow contents" back into memory. The |
| 3477 | "shadow contents" are NOT valid after an exec, so GDB should not |
| 3478 | do that. Instead, the target is responsible from marking |
| 3479 | breakpoints out as soon as it detects an exec. We don't do that |
| 3480 | here instead, because there may be other attempts to delete |
| 3481 | breakpoints after detecting an exec and before reaching here. */ |
| 3482 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
| 3483 | if (bploc->pspace == current_program_space) |
| 3484 | gdb_assert (!bploc->inserted); |
| 3485 | |
| 3486 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3487 | { |
| 3488 | if (b->pspace != current_program_space) |
| 3489 | continue; |
| 3490 | |
| 3491 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
| 3492 | if (b->type == bp_shlib_event) |
| 3493 | { |
| 3494 | delete_breakpoint (b); |
| 3495 | continue; |
| 3496 | } |
| 3497 | |
| 3498 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
| 3499 | if (b->type == bp_jit_event) |
| 3500 | { |
| 3501 | delete_breakpoint (b); |
| 3502 | continue; |
| 3503 | } |
| 3504 | |
| 3505 | /* Thread event breakpoints must be set anew after an exec(), |
| 3506 | as must overlay event and longjmp master breakpoints. */ |
| 3507 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
| 3508 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
| 3509 | || b->type == bp_exception_master) |
| 3510 | { |
| 3511 | delete_breakpoint (b); |
| 3512 | continue; |
| 3513 | } |
| 3514 | |
| 3515 | /* Step-resume breakpoints are meaningless after an exec(). */ |
| 3516 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
| 3517 | { |
| 3518 | delete_breakpoint (b); |
| 3519 | continue; |
| 3520 | } |
| 3521 | |
| 3522 | /* Just like single-step breakpoints. */ |
| 3523 | if (b->type == bp_single_step) |
| 3524 | { |
| 3525 | delete_breakpoint (b); |
| 3526 | continue; |
| 3527 | } |
| 3528 | |
| 3529 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
| 3530 | after an exec. */ |
| 3531 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
| 3532 | || b->type == bp_longjmp_call_dummy |
| 3533 | || b->type == bp_exception || b->type == bp_exception_resume) |
| 3534 | { |
| 3535 | delete_breakpoint (b); |
| 3536 | continue; |
| 3537 | } |
| 3538 | |
| 3539 | if (b->type == bp_catchpoint) |
| 3540 | { |
| 3541 | /* For now, none of the bp_catchpoint breakpoints need to |
| 3542 | do anything at this point. In the future, if some of |
| 3543 | the catchpoints need to something, we will need to add |
| 3544 | a new method, and call this method from here. */ |
| 3545 | continue; |
| 3546 | } |
| 3547 | |
| 3548 | /* bp_finish is a special case. The only way we ought to be able |
| 3549 | to see one of these when an exec() has happened, is if the user |
| 3550 | caught a vfork, and then said "finish". Ordinarily a finish just |
| 3551 | carries them to the call-site of the current callee, by setting |
| 3552 | a temporary bp there and resuming. But in this case, the finish |
| 3553 | will carry them entirely through the vfork & exec. |
| 3554 | |
| 3555 | We don't want to allow a bp_finish to remain inserted now. But |
| 3556 | we can't safely delete it, 'cause finish_command has a handle to |
| 3557 | the bp on a bpstat, and will later want to delete it. There's a |
| 3558 | chance (and I've seen it happen) that if we delete the bp_finish |
| 3559 | here, that its storage will get reused by the time finish_command |
| 3560 | gets 'round to deleting the "use to be a bp_finish" breakpoint. |
| 3561 | We really must allow finish_command to delete a bp_finish. |
| 3562 | |
| 3563 | In the absence of a general solution for the "how do we know |
| 3564 | it's safe to delete something others may have handles to?" |
| 3565 | problem, what we'll do here is just uninsert the bp_finish, and |
| 3566 | let finish_command delete it. |
| 3567 | |
| 3568 | (We know the bp_finish is "doomed" in the sense that it's |
| 3569 | momentary, and will be deleted as soon as finish_command sees |
| 3570 | the inferior stopped. So it doesn't matter that the bp's |
| 3571 | address is probably bogus in the new a.out, unlike e.g., the |
| 3572 | solib breakpoints.) */ |
| 3573 | |
| 3574 | if (b->type == bp_finish) |
| 3575 | { |
| 3576 | continue; |
| 3577 | } |
| 3578 | |
| 3579 | /* Without a symbolic address, we have little hope of the |
| 3580 | pre-exec() address meaning the same thing in the post-exec() |
| 3581 | a.out. */ |
| 3582 | if (breakpoint_event_location_empty_p (b)) |
| 3583 | { |
| 3584 | delete_breakpoint (b); |
| 3585 | continue; |
| 3586 | } |
| 3587 | } |
| 3588 | } |
| 3589 | |
| 3590 | int |
| 3591 | detach_breakpoints (ptid_t ptid) |
| 3592 | { |
| 3593 | struct bp_location *bl, **blp_tmp; |
| 3594 | int val = 0; |
| 3595 | scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid); |
| 3596 | struct inferior *inf = current_inferior (); |
| 3597 | |
| 3598 | if (ptid.pid () == inferior_ptid.pid ()) |
| 3599 | error (_("Cannot detach breakpoints of inferior_ptid")); |
| 3600 | |
| 3601 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
| 3602 | inferior_ptid = ptid; |
| 3603 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3604 | { |
| 3605 | if (bl->pspace != inf->pspace) |
| 3606 | continue; |
| 3607 | |
| 3608 | /* This function must physically remove breakpoints locations |
| 3609 | from the specified ptid, without modifying the breakpoint |
| 3610 | package's state. Locations of type bp_loc_other are only |
| 3611 | maintained at GDB side. So, there is no need to remove |
| 3612 | these bp_loc_other locations. Moreover, removing these |
| 3613 | would modify the breakpoint package's state. */ |
| 3614 | if (bl->loc_type == bp_loc_other) |
| 3615 | continue; |
| 3616 | |
| 3617 | if (bl->inserted) |
| 3618 | val |= remove_breakpoint_1 (bl, DETACH_BREAKPOINT); |
| 3619 | } |
| 3620 | |
| 3621 | return val; |
| 3622 | } |
| 3623 | |
| 3624 | /* Remove the breakpoint location BL from the current address space. |
| 3625 | Note that this is used to detach breakpoints from a child fork. |
| 3626 | When we get here, the child isn't in the inferior list, and neither |
| 3627 | do we have objects to represent its address space --- we should |
| 3628 | *not* look at bl->pspace->aspace here. */ |
| 3629 | |
| 3630 | static int |
| 3631 | remove_breakpoint_1 (struct bp_location *bl, enum remove_bp_reason reason) |
| 3632 | { |
| 3633 | int val; |
| 3634 | |
| 3635 | /* BL is never in moribund_locations by our callers. */ |
| 3636 | gdb_assert (bl->owner != NULL); |
| 3637 | |
| 3638 | /* The type of none suggests that owner is actually deleted. |
| 3639 | This should not ever happen. */ |
| 3640 | gdb_assert (bl->owner->type != bp_none); |
| 3641 | |
| 3642 | if (bl->loc_type == bp_loc_software_breakpoint |
| 3643 | || bl->loc_type == bp_loc_hardware_breakpoint) |
| 3644 | { |
| 3645 | /* "Normal" instruction breakpoint: either the standard |
| 3646 | trap-instruction bp (bp_breakpoint), or a |
| 3647 | bp_hardware_breakpoint. */ |
| 3648 | |
| 3649 | /* First check to see if we have to handle an overlay. */ |
| 3650 | if (overlay_debugging == ovly_off |
| 3651 | || bl->section == NULL |
| 3652 | || !(section_is_overlay (bl->section))) |
| 3653 | { |
| 3654 | /* No overlay handling: just remove the breakpoint. */ |
| 3655 | |
| 3656 | /* If we're trying to uninsert a memory breakpoint that we |
| 3657 | know is set in a dynamic object that is marked |
| 3658 | shlib_disabled, then either the dynamic object was |
| 3659 | removed with "remove-symbol-file" or with |
| 3660 | "nosharedlibrary". In the former case, we don't know |
| 3661 | whether another dynamic object might have loaded over the |
| 3662 | breakpoint's address -- the user might well let us know |
| 3663 | about it next with add-symbol-file (the whole point of |
| 3664 | add-symbol-file is letting the user manually maintain a |
| 3665 | list of dynamically loaded objects). If we have the |
| 3666 | breakpoint's shadow memory, that is, this is a software |
| 3667 | breakpoint managed by GDB, check whether the breakpoint |
| 3668 | is still inserted in memory, to avoid overwriting wrong |
| 3669 | code with stale saved shadow contents. Note that HW |
| 3670 | breakpoints don't have shadow memory, as they're |
| 3671 | implemented using a mechanism that is not dependent on |
| 3672 | being able to modify the target's memory, and as such |
| 3673 | they should always be removed. */ |
| 3674 | if (bl->shlib_disabled |
| 3675 | && bl->target_info.shadow_len != 0 |
| 3676 | && !memory_validate_breakpoint (bl->gdbarch, &bl->target_info)) |
| 3677 | val = 0; |
| 3678 | else |
| 3679 | val = bl->owner->ops->remove_location (bl, reason); |
| 3680 | } |
| 3681 | else |
| 3682 | { |
| 3683 | /* This breakpoint is in an overlay section. |
| 3684 | Did we set a breakpoint at the LMA? */ |
| 3685 | if (!overlay_events_enabled) |
| 3686 | { |
| 3687 | /* Yes -- overlay event support is not active, so we |
| 3688 | should have set a breakpoint at the LMA. Remove it. |
| 3689 | */ |
| 3690 | /* Ignore any failures: if the LMA is in ROM, we will |
| 3691 | have already warned when we failed to insert it. */ |
| 3692 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 3693 | target_remove_hw_breakpoint (bl->gdbarch, |
| 3694 | &bl->overlay_target_info); |
| 3695 | else |
| 3696 | target_remove_breakpoint (bl->gdbarch, |
| 3697 | &bl->overlay_target_info, |
| 3698 | reason); |
| 3699 | } |
| 3700 | /* Did we set a breakpoint at the VMA? |
| 3701 | If so, we will have marked the breakpoint 'inserted'. */ |
| 3702 | if (bl->inserted) |
| 3703 | { |
| 3704 | /* Yes -- remove it. Previously we did not bother to |
| 3705 | remove the breakpoint if the section had been |
| 3706 | unmapped, but let's not rely on that being safe. We |
| 3707 | don't know what the overlay manager might do. */ |
| 3708 | |
| 3709 | /* However, we should remove *software* breakpoints only |
| 3710 | if the section is still mapped, or else we overwrite |
| 3711 | wrong code with the saved shadow contents. */ |
| 3712 | if (bl->loc_type == bp_loc_hardware_breakpoint |
| 3713 | || section_is_mapped (bl->section)) |
| 3714 | val = bl->owner->ops->remove_location (bl, reason); |
| 3715 | else |
| 3716 | val = 0; |
| 3717 | } |
| 3718 | else |
| 3719 | { |
| 3720 | /* No -- not inserted, so no need to remove. No error. */ |
| 3721 | val = 0; |
| 3722 | } |
| 3723 | } |
| 3724 | |
| 3725 | /* In some cases, we might not be able to remove a breakpoint in |
| 3726 | a shared library that has already been removed, but we have |
| 3727 | not yet processed the shlib unload event. Similarly for an |
| 3728 | unloaded add-symbol-file object - the user might not yet have |
| 3729 | had the chance to remove-symbol-file it. shlib_disabled will |
| 3730 | be set if the library/object has already been removed, but |
| 3731 | the breakpoint hasn't been uninserted yet, e.g., after |
| 3732 | "nosharedlibrary" or "remove-symbol-file" with breakpoints |
| 3733 | always-inserted mode. */ |
| 3734 | if (val |
| 3735 | && (bl->loc_type == bp_loc_software_breakpoint |
| 3736 | && (bl->shlib_disabled |
| 3737 | || solib_name_from_address (bl->pspace, bl->address) |
| 3738 | || shared_objfile_contains_address_p (bl->pspace, |
| 3739 | bl->address)))) |
| 3740 | val = 0; |
| 3741 | |
| 3742 | if (val) |
| 3743 | return val; |
| 3744 | bl->inserted = (reason == DETACH_BREAKPOINT); |
| 3745 | } |
| 3746 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
| 3747 | { |
| 3748 | gdb_assert (bl->owner->ops != NULL |
| 3749 | && bl->owner->ops->remove_location != NULL); |
| 3750 | |
| 3751 | bl->inserted = (reason == DETACH_BREAKPOINT); |
| 3752 | bl->owner->ops->remove_location (bl, reason); |
| 3753 | |
| 3754 | /* Failure to remove any of the hardware watchpoints comes here. */ |
| 3755 | if (reason == REMOVE_BREAKPOINT && bl->inserted) |
| 3756 | warning (_("Could not remove hardware watchpoint %d."), |
| 3757 | bl->owner->number); |
| 3758 | } |
| 3759 | else if (bl->owner->type == bp_catchpoint |
| 3760 | && breakpoint_enabled (bl->owner) |
| 3761 | && !bl->duplicate) |
| 3762 | { |
| 3763 | gdb_assert (bl->owner->ops != NULL |
| 3764 | && bl->owner->ops->remove_location != NULL); |
| 3765 | |
| 3766 | val = bl->owner->ops->remove_location (bl, reason); |
| 3767 | if (val) |
| 3768 | return val; |
| 3769 | |
| 3770 | bl->inserted = (reason == DETACH_BREAKPOINT); |
| 3771 | } |
| 3772 | |
| 3773 | return 0; |
| 3774 | } |
| 3775 | |
| 3776 | static int |
| 3777 | remove_breakpoint (struct bp_location *bl) |
| 3778 | { |
| 3779 | /* BL is never in moribund_locations by our callers. */ |
| 3780 | gdb_assert (bl->owner != NULL); |
| 3781 | |
| 3782 | /* The type of none suggests that owner is actually deleted. |
| 3783 | This should not ever happen. */ |
| 3784 | gdb_assert (bl->owner->type != bp_none); |
| 3785 | |
| 3786 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 3787 | |
| 3788 | switch_to_program_space_and_thread (bl->pspace); |
| 3789 | |
| 3790 | return remove_breakpoint_1 (bl, REMOVE_BREAKPOINT); |
| 3791 | } |
| 3792 | |
| 3793 | /* Clear the "inserted" flag in all breakpoints. */ |
| 3794 | |
| 3795 | void |
| 3796 | mark_breakpoints_out (void) |
| 3797 | { |
| 3798 | struct bp_location *bl, **blp_tmp; |
| 3799 | |
| 3800 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3801 | if (bl->pspace == current_program_space) |
| 3802 | bl->inserted = 0; |
| 3803 | } |
| 3804 | |
| 3805 | /* Clear the "inserted" flag in all breakpoints and delete any |
| 3806 | breakpoints which should go away between runs of the program. |
| 3807 | |
| 3808 | Plus other such housekeeping that has to be done for breakpoints |
| 3809 | between runs. |
| 3810 | |
| 3811 | Note: this function gets called at the end of a run (by |
| 3812 | generic_mourn_inferior) and when a run begins (by |
| 3813 | init_wait_for_inferior). */ |
| 3814 | |
| 3815 | |
| 3816 | |
| 3817 | void |
| 3818 | breakpoint_init_inferior (enum inf_context context) |
| 3819 | { |
| 3820 | struct breakpoint *b, *b_tmp; |
| 3821 | struct program_space *pspace = current_program_space; |
| 3822 | |
| 3823 | /* If breakpoint locations are shared across processes, then there's |
| 3824 | nothing to do. */ |
| 3825 | if (gdbarch_has_global_breakpoints (target_gdbarch ())) |
| 3826 | return; |
| 3827 | |
| 3828 | mark_breakpoints_out (); |
| 3829 | |
| 3830 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 3831 | { |
| 3832 | if (b->loc && b->loc->pspace != pspace) |
| 3833 | continue; |
| 3834 | |
| 3835 | switch (b->type) |
| 3836 | { |
| 3837 | case bp_call_dummy: |
| 3838 | case bp_longjmp_call_dummy: |
| 3839 | |
| 3840 | /* If the call dummy breakpoint is at the entry point it will |
| 3841 | cause problems when the inferior is rerun, so we better get |
| 3842 | rid of it. */ |
| 3843 | |
| 3844 | case bp_watchpoint_scope: |
| 3845 | |
| 3846 | /* Also get rid of scope breakpoints. */ |
| 3847 | |
| 3848 | case bp_shlib_event: |
| 3849 | |
| 3850 | /* Also remove solib event breakpoints. Their addresses may |
| 3851 | have changed since the last time we ran the program. |
| 3852 | Actually we may now be debugging against different target; |
| 3853 | and so the solib backend that installed this breakpoint may |
| 3854 | not be used in by the target. E.g., |
| 3855 | |
| 3856 | (gdb) file prog-linux |
| 3857 | (gdb) run # native linux target |
| 3858 | ... |
| 3859 | (gdb) kill |
| 3860 | (gdb) file prog-win.exe |
| 3861 | (gdb) tar rem :9999 # remote Windows gdbserver. |
| 3862 | */ |
| 3863 | |
| 3864 | case bp_step_resume: |
| 3865 | |
| 3866 | /* Also remove step-resume breakpoints. */ |
| 3867 | |
| 3868 | case bp_single_step: |
| 3869 | |
| 3870 | /* Also remove single-step breakpoints. */ |
| 3871 | |
| 3872 | delete_breakpoint (b); |
| 3873 | break; |
| 3874 | |
| 3875 | case bp_watchpoint: |
| 3876 | case bp_hardware_watchpoint: |
| 3877 | case bp_read_watchpoint: |
| 3878 | case bp_access_watchpoint: |
| 3879 | { |
| 3880 | struct watchpoint *w = (struct watchpoint *) b; |
| 3881 | |
| 3882 | /* Likewise for watchpoints on local expressions. */ |
| 3883 | if (w->exp_valid_block != NULL) |
| 3884 | delete_breakpoint (b); |
| 3885 | else |
| 3886 | { |
| 3887 | /* Get rid of existing locations, which are no longer |
| 3888 | valid. New ones will be created in |
| 3889 | update_watchpoint, when the inferior is restarted. |
| 3890 | The next update_global_location_list call will |
| 3891 | garbage collect them. */ |
| 3892 | b->loc = NULL; |
| 3893 | |
| 3894 | if (context == inf_starting) |
| 3895 | { |
| 3896 | /* Reset val field to force reread of starting value in |
| 3897 | insert_breakpoints. */ |
| 3898 | w->val.reset (nullptr); |
| 3899 | w->val_valid = false; |
| 3900 | } |
| 3901 | } |
| 3902 | } |
| 3903 | break; |
| 3904 | default: |
| 3905 | break; |
| 3906 | } |
| 3907 | } |
| 3908 | |
| 3909 | /* Get rid of the moribund locations. */ |
| 3910 | for (bp_location *bl : moribund_locations) |
| 3911 | decref_bp_location (&bl); |
| 3912 | moribund_locations.clear (); |
| 3913 | } |
| 3914 | |
| 3915 | /* These functions concern about actual breakpoints inserted in the |
| 3916 | target --- to e.g. check if we need to do decr_pc adjustment or if |
| 3917 | we need to hop over the bkpt --- so we check for address space |
| 3918 | match, not program space. */ |
| 3919 | |
| 3920 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
| 3921 | exists at PC. It returns ordinary_breakpoint_here if it's an |
| 3922 | ordinary breakpoint, or permanent_breakpoint_here if it's a |
| 3923 | permanent breakpoint. |
| 3924 | - When continuing from a location with an ordinary breakpoint, we |
| 3925 | actually single step once before calling insert_breakpoints. |
| 3926 | - When continuing from a location with a permanent breakpoint, we |
| 3927 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
| 3928 | the target, to advance the PC past the breakpoint. */ |
| 3929 | |
| 3930 | enum breakpoint_here |
| 3931 | breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
| 3932 | { |
| 3933 | struct bp_location *bl, **blp_tmp; |
| 3934 | int any_breakpoint_here = 0; |
| 3935 | |
| 3936 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3937 | { |
| 3938 | if (bl->loc_type != bp_loc_software_breakpoint |
| 3939 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 3940 | continue; |
| 3941 | |
| 3942 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
| 3943 | if ((breakpoint_enabled (bl->owner) |
| 3944 | || bl->permanent) |
| 3945 | && breakpoint_location_address_match (bl, aspace, pc)) |
| 3946 | { |
| 3947 | if (overlay_debugging |
| 3948 | && section_is_overlay (bl->section) |
| 3949 | && !section_is_mapped (bl->section)) |
| 3950 | continue; /* unmapped overlay -- can't be a match */ |
| 3951 | else if (bl->permanent) |
| 3952 | return permanent_breakpoint_here; |
| 3953 | else |
| 3954 | any_breakpoint_here = 1; |
| 3955 | } |
| 3956 | } |
| 3957 | |
| 3958 | return any_breakpoint_here ? ordinary_breakpoint_here : no_breakpoint_here; |
| 3959 | } |
| 3960 | |
| 3961 | /* See breakpoint.h. */ |
| 3962 | |
| 3963 | int |
| 3964 | breakpoint_in_range_p (const address_space *aspace, |
| 3965 | CORE_ADDR addr, ULONGEST len) |
| 3966 | { |
| 3967 | struct bp_location *bl, **blp_tmp; |
| 3968 | |
| 3969 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 3970 | { |
| 3971 | if (bl->loc_type != bp_loc_software_breakpoint |
| 3972 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 3973 | continue; |
| 3974 | |
| 3975 | if ((breakpoint_enabled (bl->owner) |
| 3976 | || bl->permanent) |
| 3977 | && breakpoint_location_address_range_overlap (bl, aspace, |
| 3978 | addr, len)) |
| 3979 | { |
| 3980 | if (overlay_debugging |
| 3981 | && section_is_overlay (bl->section) |
| 3982 | && !section_is_mapped (bl->section)) |
| 3983 | { |
| 3984 | /* Unmapped overlay -- can't be a match. */ |
| 3985 | continue; |
| 3986 | } |
| 3987 | |
| 3988 | return 1; |
| 3989 | } |
| 3990 | } |
| 3991 | |
| 3992 | return 0; |
| 3993 | } |
| 3994 | |
| 3995 | /* Return true if there's a moribund breakpoint at PC. */ |
| 3996 | |
| 3997 | int |
| 3998 | moribund_breakpoint_here_p (const address_space *aspace, CORE_ADDR pc) |
| 3999 | { |
| 4000 | for (bp_location *loc : moribund_locations) |
| 4001 | if (breakpoint_location_address_match (loc, aspace, pc)) |
| 4002 | return 1; |
| 4003 | |
| 4004 | return 0; |
| 4005 | } |
| 4006 | |
| 4007 | /* Returns non-zero iff BL is inserted at PC, in address space |
| 4008 | ASPACE. */ |
| 4009 | |
| 4010 | static int |
| 4011 | bp_location_inserted_here_p (struct bp_location *bl, |
| 4012 | const address_space *aspace, CORE_ADDR pc) |
| 4013 | { |
| 4014 | if (bl->inserted |
| 4015 | && breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 4016 | aspace, pc)) |
| 4017 | { |
| 4018 | if (overlay_debugging |
| 4019 | && section_is_overlay (bl->section) |
| 4020 | && !section_is_mapped (bl->section)) |
| 4021 | return 0; /* unmapped overlay -- can't be a match */ |
| 4022 | else |
| 4023 | return 1; |
| 4024 | } |
| 4025 | return 0; |
| 4026 | } |
| 4027 | |
| 4028 | /* Returns non-zero iff there's a breakpoint inserted at PC. */ |
| 4029 | |
| 4030 | int |
| 4031 | breakpoint_inserted_here_p (const address_space *aspace, CORE_ADDR pc) |
| 4032 | { |
| 4033 | struct bp_location **blp, **blp_tmp = NULL; |
| 4034 | |
| 4035 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4036 | { |
| 4037 | struct bp_location *bl = *blp; |
| 4038 | |
| 4039 | if (bl->loc_type != bp_loc_software_breakpoint |
| 4040 | && bl->loc_type != bp_loc_hardware_breakpoint) |
| 4041 | continue; |
| 4042 | |
| 4043 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4044 | return 1; |
| 4045 | } |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
| 4049 | /* This function returns non-zero iff there is a software breakpoint |
| 4050 | inserted at PC. */ |
| 4051 | |
| 4052 | int |
| 4053 | software_breakpoint_inserted_here_p (const address_space *aspace, |
| 4054 | CORE_ADDR pc) |
| 4055 | { |
| 4056 | struct bp_location **blp, **blp_tmp = NULL; |
| 4057 | |
| 4058 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4059 | { |
| 4060 | struct bp_location *bl = *blp; |
| 4061 | |
| 4062 | if (bl->loc_type != bp_loc_software_breakpoint) |
| 4063 | continue; |
| 4064 | |
| 4065 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4066 | return 1; |
| 4067 | } |
| 4068 | |
| 4069 | return 0; |
| 4070 | } |
| 4071 | |
| 4072 | /* See breakpoint.h. */ |
| 4073 | |
| 4074 | int |
| 4075 | hardware_breakpoint_inserted_here_p (const address_space *aspace, |
| 4076 | CORE_ADDR pc) |
| 4077 | { |
| 4078 | struct bp_location **blp, **blp_tmp = NULL; |
| 4079 | |
| 4080 | ALL_BP_LOCATIONS_AT_ADDR (blp, blp_tmp, pc) |
| 4081 | { |
| 4082 | struct bp_location *bl = *blp; |
| 4083 | |
| 4084 | if (bl->loc_type != bp_loc_hardware_breakpoint) |
| 4085 | continue; |
| 4086 | |
| 4087 | if (bp_location_inserted_here_p (bl, aspace, pc)) |
| 4088 | return 1; |
| 4089 | } |
| 4090 | |
| 4091 | return 0; |
| 4092 | } |
| 4093 | |
| 4094 | int |
| 4095 | hardware_watchpoint_inserted_in_range (const address_space *aspace, |
| 4096 | CORE_ADDR addr, ULONGEST len) |
| 4097 | { |
| 4098 | struct breakpoint *bpt; |
| 4099 | |
| 4100 | ALL_BREAKPOINTS (bpt) |
| 4101 | { |
| 4102 | struct bp_location *loc; |
| 4103 | |
| 4104 | if (bpt->type != bp_hardware_watchpoint |
| 4105 | && bpt->type != bp_access_watchpoint) |
| 4106 | continue; |
| 4107 | |
| 4108 | if (!breakpoint_enabled (bpt)) |
| 4109 | continue; |
| 4110 | |
| 4111 | for (loc = bpt->loc; loc; loc = loc->next) |
| 4112 | if (loc->pspace->aspace == aspace && loc->inserted) |
| 4113 | { |
| 4114 | CORE_ADDR l, h; |
| 4115 | |
| 4116 | /* Check for intersection. */ |
| 4117 | l = std::max<CORE_ADDR> (loc->address, addr); |
| 4118 | h = std::min<CORE_ADDR> (loc->address + loc->length, addr + len); |
| 4119 | if (l < h) |
| 4120 | return 1; |
| 4121 | } |
| 4122 | } |
| 4123 | return 0; |
| 4124 | } |
| 4125 | |
| 4126 | /* See breakpoint.h. */ |
| 4127 | |
| 4128 | bool |
| 4129 | is_catchpoint (struct breakpoint *b) |
| 4130 | { |
| 4131 | return (b->type == bp_catchpoint); |
| 4132 | } |
| 4133 | |
| 4134 | /* Frees any storage that is part of a bpstat. Does not walk the |
| 4135 | 'next' chain. */ |
| 4136 | |
| 4137 | bpstats::~bpstats () |
| 4138 | { |
| 4139 | if (bp_location_at != NULL) |
| 4140 | decref_bp_location (&bp_location_at); |
| 4141 | } |
| 4142 | |
| 4143 | /* Clear a bpstat so that it says we are not at any breakpoint. |
| 4144 | Also free any storage that is part of a bpstat. */ |
| 4145 | |
| 4146 | void |
| 4147 | bpstat_clear (bpstat *bsp) |
| 4148 | { |
| 4149 | bpstat p; |
| 4150 | bpstat q; |
| 4151 | |
| 4152 | if (bsp == 0) |
| 4153 | return; |
| 4154 | p = *bsp; |
| 4155 | while (p != NULL) |
| 4156 | { |
| 4157 | q = p->next; |
| 4158 | delete p; |
| 4159 | p = q; |
| 4160 | } |
| 4161 | *bsp = NULL; |
| 4162 | } |
| 4163 | |
| 4164 | bpstats::bpstats (const bpstats &other) |
| 4165 | : next (NULL), |
| 4166 | bp_location_at (other.bp_location_at), |
| 4167 | breakpoint_at (other.breakpoint_at), |
| 4168 | commands (other.commands), |
| 4169 | print (other.print), |
| 4170 | stop (other.stop), |
| 4171 | print_it (other.print_it) |
| 4172 | { |
| 4173 | if (other.old_val != NULL) |
| 4174 | old_val = release_value (value_copy (other.old_val.get ())); |
| 4175 | incref_bp_location (bp_location_at); |
| 4176 | } |
| 4177 | |
| 4178 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
| 4179 | is part of the bpstat is copied as well. */ |
| 4180 | |
| 4181 | bpstat |
| 4182 | bpstat_copy (bpstat bs) |
| 4183 | { |
| 4184 | bpstat p = NULL; |
| 4185 | bpstat tmp; |
| 4186 | bpstat retval = NULL; |
| 4187 | |
| 4188 | if (bs == NULL) |
| 4189 | return bs; |
| 4190 | |
| 4191 | for (; bs != NULL; bs = bs->next) |
| 4192 | { |
| 4193 | tmp = new bpstats (*bs); |
| 4194 | |
| 4195 | if (p == NULL) |
| 4196 | /* This is the first thing in the chain. */ |
| 4197 | retval = tmp; |
| 4198 | else |
| 4199 | p->next = tmp; |
| 4200 | p = tmp; |
| 4201 | } |
| 4202 | p->next = NULL; |
| 4203 | return retval; |
| 4204 | } |
| 4205 | |
| 4206 | /* Find the bpstat associated with this breakpoint. */ |
| 4207 | |
| 4208 | bpstat |
| 4209 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
| 4210 | { |
| 4211 | if (bsp == NULL) |
| 4212 | return NULL; |
| 4213 | |
| 4214 | for (; bsp != NULL; bsp = bsp->next) |
| 4215 | { |
| 4216 | if (bsp->breakpoint_at == breakpoint) |
| 4217 | return bsp; |
| 4218 | } |
| 4219 | return NULL; |
| 4220 | } |
| 4221 | |
| 4222 | /* See breakpoint.h. */ |
| 4223 | |
| 4224 | bool |
| 4225 | bpstat_explains_signal (bpstat bsp, enum gdb_signal sig) |
| 4226 | { |
| 4227 | for (; bsp != NULL; bsp = bsp->next) |
| 4228 | { |
| 4229 | if (bsp->breakpoint_at == NULL) |
| 4230 | { |
| 4231 | /* A moribund location can never explain a signal other than |
| 4232 | GDB_SIGNAL_TRAP. */ |
| 4233 | if (sig == GDB_SIGNAL_TRAP) |
| 4234 | return true; |
| 4235 | } |
| 4236 | else |
| 4237 | { |
| 4238 | if (bsp->breakpoint_at->ops->explains_signal (bsp->breakpoint_at, |
| 4239 | sig)) |
| 4240 | return true; |
| 4241 | } |
| 4242 | } |
| 4243 | |
| 4244 | return false; |
| 4245 | } |
| 4246 | |
| 4247 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
| 4248 | stopped at. *BSP upon return is a bpstat which points to the |
| 4249 | remaining breakpoints stopped at (but which is not guaranteed to be |
| 4250 | good for anything but further calls to bpstat_num). |
| 4251 | |
| 4252 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
| 4253 | Return -1 if stopped at a breakpoint that has been deleted since |
| 4254 | we set it. |
| 4255 | Return 1 otherwise. */ |
| 4256 | |
| 4257 | int |
| 4258 | bpstat_num (bpstat *bsp, int *num) |
| 4259 | { |
| 4260 | struct breakpoint *b; |
| 4261 | |
| 4262 | if ((*bsp) == NULL) |
| 4263 | return 0; /* No more breakpoint values */ |
| 4264 | |
| 4265 | /* We assume we'll never have several bpstats that correspond to a |
| 4266 | single breakpoint -- otherwise, this function might return the |
| 4267 | same number more than once and this will look ugly. */ |
| 4268 | b = (*bsp)->breakpoint_at; |
| 4269 | *bsp = (*bsp)->next; |
| 4270 | if (b == NULL) |
| 4271 | return -1; /* breakpoint that's been deleted since */ |
| 4272 | |
| 4273 | *num = b->number; /* We have its number */ |
| 4274 | return 1; |
| 4275 | } |
| 4276 | |
| 4277 | /* See breakpoint.h. */ |
| 4278 | |
| 4279 | void |
| 4280 | bpstat_clear_actions (void) |
| 4281 | { |
| 4282 | bpstat bs; |
| 4283 | |
| 4284 | if (inferior_ptid == null_ptid) |
| 4285 | return; |
| 4286 | |
| 4287 | thread_info *tp = inferior_thread (); |
| 4288 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) |
| 4289 | { |
| 4290 | bs->commands = NULL; |
| 4291 | bs->old_val.reset (nullptr); |
| 4292 | } |
| 4293 | } |
| 4294 | |
| 4295 | /* Called when a command is about to proceed the inferior. */ |
| 4296 | |
| 4297 | static void |
| 4298 | breakpoint_about_to_proceed (void) |
| 4299 | { |
| 4300 | if (inferior_ptid != null_ptid) |
| 4301 | { |
| 4302 | struct thread_info *tp = inferior_thread (); |
| 4303 | |
| 4304 | /* Allow inferior function calls in breakpoint commands to not |
| 4305 | interrupt the command list. When the call finishes |
| 4306 | successfully, the inferior will be standing at the same |
| 4307 | breakpoint as if nothing happened. */ |
| 4308 | if (tp->control.in_infcall) |
| 4309 | return; |
| 4310 | } |
| 4311 | |
| 4312 | breakpoint_proceeded = 1; |
| 4313 | } |
| 4314 | |
| 4315 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
| 4316 | or its equivalent. */ |
| 4317 | |
| 4318 | static int |
| 4319 | command_line_is_silent (struct command_line *cmd) |
| 4320 | { |
| 4321 | return cmd && (strcmp ("silent", cmd->line) == 0); |
| 4322 | } |
| 4323 | |
| 4324 | /* Execute all the commands associated with all the breakpoints at |
| 4325 | this location. Any of these commands could cause the process to |
| 4326 | proceed beyond this point, etc. We look out for such changes by |
| 4327 | checking the global "breakpoint_proceeded" after each command. |
| 4328 | |
| 4329 | Returns true if a breakpoint command resumed the inferior. In that |
| 4330 | case, it is the caller's responsibility to recall it again with the |
| 4331 | bpstat of the current thread. */ |
| 4332 | |
| 4333 | static int |
| 4334 | bpstat_do_actions_1 (bpstat *bsp) |
| 4335 | { |
| 4336 | bpstat bs; |
| 4337 | int again = 0; |
| 4338 | |
| 4339 | /* Avoid endless recursion if a `source' command is contained |
| 4340 | in bs->commands. */ |
| 4341 | if (executing_breakpoint_commands) |
| 4342 | return 0; |
| 4343 | |
| 4344 | scoped_restore save_executing |
| 4345 | = make_scoped_restore (&executing_breakpoint_commands, 1); |
| 4346 | |
| 4347 | scoped_restore preventer = prevent_dont_repeat (); |
| 4348 | |
| 4349 | /* This pointer will iterate over the list of bpstat's. */ |
| 4350 | bs = *bsp; |
| 4351 | |
| 4352 | breakpoint_proceeded = 0; |
| 4353 | for (; bs != NULL; bs = bs->next) |
| 4354 | { |
| 4355 | struct command_line *cmd = NULL; |
| 4356 | |
| 4357 | /* Take ownership of the BSP's command tree, if it has one. |
| 4358 | |
| 4359 | The command tree could legitimately contain commands like |
| 4360 | 'step' and 'next', which call clear_proceed_status, which |
| 4361 | frees stop_bpstat's command tree. To make sure this doesn't |
| 4362 | free the tree we're executing out from under us, we need to |
| 4363 | take ownership of the tree ourselves. Since a given bpstat's |
| 4364 | commands are only executed once, we don't need to copy it; we |
| 4365 | can clear the pointer in the bpstat, and make sure we free |
| 4366 | the tree when we're done. */ |
| 4367 | counted_command_line ccmd = bs->commands; |
| 4368 | bs->commands = NULL; |
| 4369 | if (ccmd != NULL) |
| 4370 | cmd = ccmd.get (); |
| 4371 | if (command_line_is_silent (cmd)) |
| 4372 | { |
| 4373 | /* The action has been already done by bpstat_stop_status. */ |
| 4374 | cmd = cmd->next; |
| 4375 | } |
| 4376 | |
| 4377 | while (cmd != NULL) |
| 4378 | { |
| 4379 | execute_control_command (cmd); |
| 4380 | |
| 4381 | if (breakpoint_proceeded) |
| 4382 | break; |
| 4383 | else |
| 4384 | cmd = cmd->next; |
| 4385 | } |
| 4386 | |
| 4387 | if (breakpoint_proceeded) |
| 4388 | { |
| 4389 | if (current_ui->async) |
| 4390 | /* If we are in async mode, then the target might be still |
| 4391 | running, not stopped at any breakpoint, so nothing for |
| 4392 | us to do here -- just return to the event loop. */ |
| 4393 | ; |
| 4394 | else |
| 4395 | /* In sync mode, when execute_control_command returns |
| 4396 | we're already standing on the next breakpoint. |
| 4397 | Breakpoint commands for that stop were not run, since |
| 4398 | execute_command does not run breakpoint commands -- |
| 4399 | only command_line_handler does, but that one is not |
| 4400 | involved in execution of breakpoint commands. So, we |
| 4401 | can now execute breakpoint commands. It should be |
| 4402 | noted that making execute_command do bpstat actions is |
| 4403 | not an option -- in this case we'll have recursive |
| 4404 | invocation of bpstat for each breakpoint with a |
| 4405 | command, and can easily blow up GDB stack. Instead, we |
| 4406 | return true, which will trigger the caller to recall us |
| 4407 | with the new stop_bpstat. */ |
| 4408 | again = 1; |
| 4409 | break; |
| 4410 | } |
| 4411 | } |
| 4412 | return again; |
| 4413 | } |
| 4414 | |
| 4415 | /* Helper for bpstat_do_actions. Get the current thread, if there's |
| 4416 | one, is alive and has execution. Return NULL otherwise. */ |
| 4417 | |
| 4418 | static thread_info * |
| 4419 | get_bpstat_thread () |
| 4420 | { |
| 4421 | if (inferior_ptid == null_ptid || !target_has_execution) |
| 4422 | return NULL; |
| 4423 | |
| 4424 | thread_info *tp = inferior_thread (); |
| 4425 | if (tp->state == THREAD_EXITED || tp->executing) |
| 4426 | return NULL; |
| 4427 | return tp; |
| 4428 | } |
| 4429 | |
| 4430 | void |
| 4431 | bpstat_do_actions (void) |
| 4432 | { |
| 4433 | auto cleanup_if_error = make_scope_exit (bpstat_clear_actions); |
| 4434 | thread_info *tp; |
| 4435 | |
| 4436 | /* Do any commands attached to breakpoint we are stopped at. */ |
| 4437 | while ((tp = get_bpstat_thread ()) != NULL) |
| 4438 | { |
| 4439 | /* Since in sync mode, bpstat_do_actions may resume the |
| 4440 | inferior, and only return when it is stopped at the next |
| 4441 | breakpoint, we keep doing breakpoint actions until it returns |
| 4442 | false to indicate the inferior was not resumed. */ |
| 4443 | if (!bpstat_do_actions_1 (&tp->control.stop_bpstat)) |
| 4444 | break; |
| 4445 | } |
| 4446 | |
| 4447 | cleanup_if_error.release (); |
| 4448 | } |
| 4449 | |
| 4450 | /* Print out the (old or new) value associated with a watchpoint. */ |
| 4451 | |
| 4452 | static void |
| 4453 | watchpoint_value_print (struct value *val, struct ui_file *stream) |
| 4454 | { |
| 4455 | if (val == NULL) |
| 4456 | fprintf_styled (stream, metadata_style.style (), _("<unreadable>")); |
| 4457 | else |
| 4458 | { |
| 4459 | struct value_print_options opts; |
| 4460 | get_user_print_options (&opts); |
| 4461 | value_print (val, stream, &opts); |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | /* Print the "Thread ID hit" part of "Thread ID hit Breakpoint N" if |
| 4466 | debugging multiple threads. */ |
| 4467 | |
| 4468 | void |
| 4469 | maybe_print_thread_hit_breakpoint (struct ui_out *uiout) |
| 4470 | { |
| 4471 | if (uiout->is_mi_like_p ()) |
| 4472 | return; |
| 4473 | |
| 4474 | uiout->text ("\n"); |
| 4475 | |
| 4476 | if (show_thread_that_caused_stop ()) |
| 4477 | { |
| 4478 | const char *name; |
| 4479 | struct thread_info *thr = inferior_thread (); |
| 4480 | |
| 4481 | uiout->text ("Thread "); |
| 4482 | uiout->field_string ("thread-id", print_thread_id (thr)); |
| 4483 | |
| 4484 | name = thr->name != NULL ? thr->name : target_thread_name (thr); |
| 4485 | if (name != NULL) |
| 4486 | { |
| 4487 | uiout->text (" \""); |
| 4488 | uiout->field_string ("name", name); |
| 4489 | uiout->text ("\""); |
| 4490 | } |
| 4491 | |
| 4492 | uiout->text (" hit "); |
| 4493 | } |
| 4494 | } |
| 4495 | |
| 4496 | /* Generic routine for printing messages indicating why we |
| 4497 | stopped. The behavior of this function depends on the value |
| 4498 | 'print_it' in the bpstat structure. Under some circumstances we |
| 4499 | may decide not to print anything here and delegate the task to |
| 4500 | normal_stop(). */ |
| 4501 | |
| 4502 | static enum print_stop_action |
| 4503 | print_bp_stop_message (bpstat bs) |
| 4504 | { |
| 4505 | switch (bs->print_it) |
| 4506 | { |
| 4507 | case print_it_noop: |
| 4508 | /* Nothing should be printed for this bpstat entry. */ |
| 4509 | return PRINT_UNKNOWN; |
| 4510 | break; |
| 4511 | |
| 4512 | case print_it_done: |
| 4513 | /* We still want to print the frame, but we already printed the |
| 4514 | relevant messages. */ |
| 4515 | return PRINT_SRC_AND_LOC; |
| 4516 | break; |
| 4517 | |
| 4518 | case print_it_normal: |
| 4519 | { |
| 4520 | struct breakpoint *b = bs->breakpoint_at; |
| 4521 | |
| 4522 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
| 4523 | which has since been deleted. */ |
| 4524 | if (b == NULL) |
| 4525 | return PRINT_UNKNOWN; |
| 4526 | |
| 4527 | /* Normal case. Call the breakpoint's print_it method. */ |
| 4528 | return b->ops->print_it (bs); |
| 4529 | } |
| 4530 | break; |
| 4531 | |
| 4532 | default: |
| 4533 | internal_error (__FILE__, __LINE__, |
| 4534 | _("print_bp_stop_message: unrecognized enum value")); |
| 4535 | break; |
| 4536 | } |
| 4537 | } |
| 4538 | |
| 4539 | /* A helper function that prints a shared library stopped event. */ |
| 4540 | |
| 4541 | static void |
| 4542 | print_solib_event (int is_catchpoint) |
| 4543 | { |
| 4544 | bool any_deleted = !current_program_space->deleted_solibs.empty (); |
| 4545 | bool any_added = !current_program_space->added_solibs.empty (); |
| 4546 | |
| 4547 | if (!is_catchpoint) |
| 4548 | { |
| 4549 | if (any_added || any_deleted) |
| 4550 | current_uiout->text (_("Stopped due to shared library event:\n")); |
| 4551 | else |
| 4552 | current_uiout->text (_("Stopped due to shared library event (no " |
| 4553 | "libraries added or removed)\n")); |
| 4554 | } |
| 4555 | |
| 4556 | if (current_uiout->is_mi_like_p ()) |
| 4557 | current_uiout->field_string ("reason", |
| 4558 | async_reason_lookup (EXEC_ASYNC_SOLIB_EVENT)); |
| 4559 | |
| 4560 | if (any_deleted) |
| 4561 | { |
| 4562 | current_uiout->text (_(" Inferior unloaded ")); |
| 4563 | ui_out_emit_list list_emitter (current_uiout, "removed"); |
| 4564 | for (int ix = 0; ix < current_program_space->deleted_solibs.size (); ix++) |
| 4565 | { |
| 4566 | const std::string &name = current_program_space->deleted_solibs[ix]; |
| 4567 | |
| 4568 | if (ix > 0) |
| 4569 | current_uiout->text (" "); |
| 4570 | current_uiout->field_string ("library", name); |
| 4571 | current_uiout->text ("\n"); |
| 4572 | } |
| 4573 | } |
| 4574 | |
| 4575 | if (any_added) |
| 4576 | { |
| 4577 | current_uiout->text (_(" Inferior loaded ")); |
| 4578 | ui_out_emit_list list_emitter (current_uiout, "added"); |
| 4579 | bool first = true; |
| 4580 | for (so_list *iter : current_program_space->added_solibs) |
| 4581 | { |
| 4582 | if (!first) |
| 4583 | current_uiout->text (" "); |
| 4584 | first = false; |
| 4585 | current_uiout->field_string ("library", iter->so_name); |
| 4586 | current_uiout->text ("\n"); |
| 4587 | } |
| 4588 | } |
| 4589 | } |
| 4590 | |
| 4591 | /* Print a message indicating what happened. This is called from |
| 4592 | normal_stop(). The input to this routine is the head of the bpstat |
| 4593 | list - a list of the eventpoints that caused this stop. KIND is |
| 4594 | the target_waitkind for the stopping event. This |
| 4595 | routine calls the generic print routine for printing a message |
| 4596 | about reasons for stopping. This will print (for example) the |
| 4597 | "Breakpoint n," part of the output. The return value of this |
| 4598 | routine is one of: |
| 4599 | |
| 4600 | PRINT_UNKNOWN: Means we printed nothing. |
| 4601 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
| 4602 | code to print the location. An example is |
| 4603 | "Breakpoint 1, " which should be followed by |
| 4604 | the location. |
| 4605 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
| 4606 | to also print the location part of the message. |
| 4607 | An example is the catch/throw messages, which |
| 4608 | don't require a location appended to the end. |
| 4609 | PRINT_NOTHING: We have done some printing and we don't need any |
| 4610 | further info to be printed. */ |
| 4611 | |
| 4612 | enum print_stop_action |
| 4613 | bpstat_print (bpstat bs, int kind) |
| 4614 | { |
| 4615 | enum print_stop_action val; |
| 4616 | |
| 4617 | /* Maybe another breakpoint in the chain caused us to stop. |
| 4618 | (Currently all watchpoints go on the bpstat whether hit or not. |
| 4619 | That probably could (should) be changed, provided care is taken |
| 4620 | with respect to bpstat_explains_signal). */ |
| 4621 | for (; bs; bs = bs->next) |
| 4622 | { |
| 4623 | val = print_bp_stop_message (bs); |
| 4624 | if (val == PRINT_SRC_ONLY |
| 4625 | || val == PRINT_SRC_AND_LOC |
| 4626 | || val == PRINT_NOTHING) |
| 4627 | return val; |
| 4628 | } |
| 4629 | |
| 4630 | /* If we had hit a shared library event breakpoint, |
| 4631 | print_bp_stop_message would print out this message. If we hit an |
| 4632 | OS-level shared library event, do the same thing. */ |
| 4633 | if (kind == TARGET_WAITKIND_LOADED) |
| 4634 | { |
| 4635 | print_solib_event (0); |
| 4636 | return PRINT_NOTHING; |
| 4637 | } |
| 4638 | |
| 4639 | /* We reached the end of the chain, or we got a null BS to start |
| 4640 | with and nothing was printed. */ |
| 4641 | return PRINT_UNKNOWN; |
| 4642 | } |
| 4643 | |
| 4644 | /* Evaluate the boolean expression EXP and return the result. */ |
| 4645 | |
| 4646 | static bool |
| 4647 | breakpoint_cond_eval (expression *exp) |
| 4648 | { |
| 4649 | struct value *mark = value_mark (); |
| 4650 | bool res = value_true (evaluate_expression (exp)); |
| 4651 | |
| 4652 | value_free_to_mark (mark); |
| 4653 | return res; |
| 4654 | } |
| 4655 | |
| 4656 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
| 4657 | |
| 4658 | bpstats::bpstats (struct bp_location *bl, bpstat **bs_link_pointer) |
| 4659 | : next (NULL), |
| 4660 | bp_location_at (bl), |
| 4661 | breakpoint_at (bl->owner), |
| 4662 | commands (NULL), |
| 4663 | print (0), |
| 4664 | stop (0), |
| 4665 | print_it (print_it_normal) |
| 4666 | { |
| 4667 | incref_bp_location (bl); |
| 4668 | **bs_link_pointer = this; |
| 4669 | *bs_link_pointer = &next; |
| 4670 | } |
| 4671 | |
| 4672 | bpstats::bpstats () |
| 4673 | : next (NULL), |
| 4674 | bp_location_at (NULL), |
| 4675 | breakpoint_at (NULL), |
| 4676 | commands (NULL), |
| 4677 | print (0), |
| 4678 | stop (0), |
| 4679 | print_it (print_it_normal) |
| 4680 | { |
| 4681 | } |
| 4682 | \f |
| 4683 | /* The target has stopped with waitstatus WS. Check if any hardware |
| 4684 | watchpoints have triggered, according to the target. */ |
| 4685 | |
| 4686 | int |
| 4687 | watchpoints_triggered (struct target_waitstatus *ws) |
| 4688 | { |
| 4689 | bool stopped_by_watchpoint = target_stopped_by_watchpoint (); |
| 4690 | CORE_ADDR addr; |
| 4691 | struct breakpoint *b; |
| 4692 | |
| 4693 | if (!stopped_by_watchpoint) |
| 4694 | { |
| 4695 | /* We were not stopped by a watchpoint. Mark all watchpoints |
| 4696 | as not triggered. */ |
| 4697 | ALL_BREAKPOINTS (b) |
| 4698 | if (is_hardware_watchpoint (b)) |
| 4699 | { |
| 4700 | struct watchpoint *w = (struct watchpoint *) b; |
| 4701 | |
| 4702 | w->watchpoint_triggered = watch_triggered_no; |
| 4703 | } |
| 4704 | |
| 4705 | return 0; |
| 4706 | } |
| 4707 | |
| 4708 | if (!target_stopped_data_address (current_top_target (), &addr)) |
| 4709 | { |
| 4710 | /* We were stopped by a watchpoint, but we don't know where. |
| 4711 | Mark all watchpoints as unknown. */ |
| 4712 | ALL_BREAKPOINTS (b) |
| 4713 | if (is_hardware_watchpoint (b)) |
| 4714 | { |
| 4715 | struct watchpoint *w = (struct watchpoint *) b; |
| 4716 | |
| 4717 | w->watchpoint_triggered = watch_triggered_unknown; |
| 4718 | } |
| 4719 | |
| 4720 | return 1; |
| 4721 | } |
| 4722 | |
| 4723 | /* The target could report the data address. Mark watchpoints |
| 4724 | affected by this data address as triggered, and all others as not |
| 4725 | triggered. */ |
| 4726 | |
| 4727 | ALL_BREAKPOINTS (b) |
| 4728 | if (is_hardware_watchpoint (b)) |
| 4729 | { |
| 4730 | struct watchpoint *w = (struct watchpoint *) b; |
| 4731 | struct bp_location *loc; |
| 4732 | |
| 4733 | w->watchpoint_triggered = watch_triggered_no; |
| 4734 | for (loc = b->loc; loc; loc = loc->next) |
| 4735 | { |
| 4736 | if (is_masked_watchpoint (b)) |
| 4737 | { |
| 4738 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
| 4739 | CORE_ADDR start = loc->address & w->hw_wp_mask; |
| 4740 | |
| 4741 | if (newaddr == start) |
| 4742 | { |
| 4743 | w->watchpoint_triggered = watch_triggered_yes; |
| 4744 | break; |
| 4745 | } |
| 4746 | } |
| 4747 | /* Exact match not required. Within range is sufficient. */ |
| 4748 | else if (target_watchpoint_addr_within_range (current_top_target (), |
| 4749 | addr, loc->address, |
| 4750 | loc->length)) |
| 4751 | { |
| 4752 | w->watchpoint_triggered = watch_triggered_yes; |
| 4753 | break; |
| 4754 | } |
| 4755 | } |
| 4756 | } |
| 4757 | |
| 4758 | return 1; |
| 4759 | } |
| 4760 | |
| 4761 | /* Possible return values for watchpoint_check. */ |
| 4762 | enum wp_check_result |
| 4763 | { |
| 4764 | /* The watchpoint has been deleted. */ |
| 4765 | WP_DELETED = 1, |
| 4766 | |
| 4767 | /* The value has changed. */ |
| 4768 | WP_VALUE_CHANGED = 2, |
| 4769 | |
| 4770 | /* The value has not changed. */ |
| 4771 | WP_VALUE_NOT_CHANGED = 3, |
| 4772 | |
| 4773 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
| 4774 | WP_IGNORE = 4, |
| 4775 | }; |
| 4776 | |
| 4777 | #define BP_TEMPFLAG 1 |
| 4778 | #define BP_HARDWAREFLAG 2 |
| 4779 | |
| 4780 | /* Evaluate watchpoint condition expression and check if its value |
| 4781 | changed. */ |
| 4782 | |
| 4783 | static wp_check_result |
| 4784 | watchpoint_check (bpstat bs) |
| 4785 | { |
| 4786 | struct watchpoint *b; |
| 4787 | struct frame_info *fr; |
| 4788 | int within_current_scope; |
| 4789 | |
| 4790 | /* BS is built from an existing struct breakpoint. */ |
| 4791 | gdb_assert (bs->breakpoint_at != NULL); |
| 4792 | b = (struct watchpoint *) bs->breakpoint_at; |
| 4793 | |
| 4794 | /* If this is a local watchpoint, we only want to check if the |
| 4795 | watchpoint frame is in scope if the current thread is the thread |
| 4796 | that was used to create the watchpoint. */ |
| 4797 | if (!watchpoint_in_thread_scope (b)) |
| 4798 | return WP_IGNORE; |
| 4799 | |
| 4800 | if (b->exp_valid_block == NULL) |
| 4801 | within_current_scope = 1; |
| 4802 | else |
| 4803 | { |
| 4804 | struct frame_info *frame = get_current_frame (); |
| 4805 | struct gdbarch *frame_arch = get_frame_arch (frame); |
| 4806 | CORE_ADDR frame_pc = get_frame_pc (frame); |
| 4807 | |
| 4808 | /* stack_frame_destroyed_p() returns a non-zero value if we're |
| 4809 | still in the function but the stack frame has already been |
| 4810 | invalidated. Since we can't rely on the values of local |
| 4811 | variables after the stack has been destroyed, we are treating |
| 4812 | the watchpoint in that state as `not changed' without further |
| 4813 | checking. Don't mark watchpoints as changed if the current |
| 4814 | frame is in an epilogue - even if they are in some other |
| 4815 | frame, our view of the stack is likely to be wrong and |
| 4816 | frame_find_by_id could error out. */ |
| 4817 | if (gdbarch_stack_frame_destroyed_p (frame_arch, frame_pc)) |
| 4818 | return WP_IGNORE; |
| 4819 | |
| 4820 | fr = frame_find_by_id (b->watchpoint_frame); |
| 4821 | within_current_scope = (fr != NULL); |
| 4822 | |
| 4823 | /* If we've gotten confused in the unwinder, we might have |
| 4824 | returned a frame that can't describe this variable. */ |
| 4825 | if (within_current_scope) |
| 4826 | { |
| 4827 | struct symbol *function; |
| 4828 | |
| 4829 | function = get_frame_function (fr); |
| 4830 | if (function == NULL |
| 4831 | || !contained_in (b->exp_valid_block, |
| 4832 | SYMBOL_BLOCK_VALUE (function))) |
| 4833 | within_current_scope = 0; |
| 4834 | } |
| 4835 | |
| 4836 | if (within_current_scope) |
| 4837 | /* If we end up stopping, the current frame will get selected |
| 4838 | in normal_stop. So this call to select_frame won't affect |
| 4839 | the user. */ |
| 4840 | select_frame (fr); |
| 4841 | } |
| 4842 | |
| 4843 | if (within_current_scope) |
| 4844 | { |
| 4845 | /* We use value_{,free_to_}mark because it could be a *long* |
| 4846 | time before we return to the command level and call |
| 4847 | free_all_values. We can't call free_all_values because we |
| 4848 | might be in the middle of evaluating a function call. */ |
| 4849 | |
| 4850 | int pc = 0; |
| 4851 | struct value *mark; |
| 4852 | struct value *new_val; |
| 4853 | |
| 4854 | if (is_masked_watchpoint (b)) |
| 4855 | /* Since we don't know the exact trigger address (from |
| 4856 | stopped_data_address), just tell the user we've triggered |
| 4857 | a mask watchpoint. */ |
| 4858 | return WP_VALUE_CHANGED; |
| 4859 | |
| 4860 | mark = value_mark (); |
| 4861 | fetch_subexp_value (b->exp.get (), &pc, &new_val, NULL, NULL, 0); |
| 4862 | |
| 4863 | if (b->val_bitsize != 0) |
| 4864 | new_val = extract_bitfield_from_watchpoint_value (b, new_val); |
| 4865 | |
| 4866 | /* We use value_equal_contents instead of value_equal because |
| 4867 | the latter coerces an array to a pointer, thus comparing just |
| 4868 | the address of the array instead of its contents. This is |
| 4869 | not what we want. */ |
| 4870 | if ((b->val != NULL) != (new_val != NULL) |
| 4871 | || (b->val != NULL && !value_equal_contents (b->val.get (), |
| 4872 | new_val))) |
| 4873 | { |
| 4874 | bs->old_val = b->val; |
| 4875 | b->val = release_value (new_val); |
| 4876 | b->val_valid = true; |
| 4877 | if (new_val != NULL) |
| 4878 | value_free_to_mark (mark); |
| 4879 | return WP_VALUE_CHANGED; |
| 4880 | } |
| 4881 | else |
| 4882 | { |
| 4883 | /* Nothing changed. */ |
| 4884 | value_free_to_mark (mark); |
| 4885 | return WP_VALUE_NOT_CHANGED; |
| 4886 | } |
| 4887 | } |
| 4888 | else |
| 4889 | { |
| 4890 | /* This seems like the only logical thing to do because |
| 4891 | if we temporarily ignored the watchpoint, then when |
| 4892 | we reenter the block in which it is valid it contains |
| 4893 | garbage (in the case of a function, it may have two |
| 4894 | garbage values, one before and one after the prologue). |
| 4895 | So we can't even detect the first assignment to it and |
| 4896 | watch after that (since the garbage may or may not equal |
| 4897 | the first value assigned). */ |
| 4898 | /* We print all the stop information in |
| 4899 | breakpoint_ops->print_it, but in this case, by the time we |
| 4900 | call breakpoint_ops->print_it this bp will be deleted |
| 4901 | already. So we have no choice but print the information |
| 4902 | here. */ |
| 4903 | |
| 4904 | SWITCH_THRU_ALL_UIS () |
| 4905 | { |
| 4906 | struct ui_out *uiout = current_uiout; |
| 4907 | |
| 4908 | if (uiout->is_mi_like_p ()) |
| 4909 | uiout->field_string |
| 4910 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); |
| 4911 | uiout->message ("\nWatchpoint %pF deleted because the program has " |
| 4912 | "left the block in\n" |
| 4913 | "which its expression is valid.\n", |
| 4914 | signed_field ("wpnum", b->number)); |
| 4915 | } |
| 4916 | |
| 4917 | /* Make sure the watchpoint's commands aren't executed. */ |
| 4918 | b->commands = NULL; |
| 4919 | watchpoint_del_at_next_stop (b); |
| 4920 | |
| 4921 | return WP_DELETED; |
| 4922 | } |
| 4923 | } |
| 4924 | |
| 4925 | /* Return true if it looks like target has stopped due to hitting |
| 4926 | breakpoint location BL. This function does not check if we should |
| 4927 | stop, only if BL explains the stop. */ |
| 4928 | |
| 4929 | static int |
| 4930 | bpstat_check_location (const struct bp_location *bl, |
| 4931 | const address_space *aspace, CORE_ADDR bp_addr, |
| 4932 | const struct target_waitstatus *ws) |
| 4933 | { |
| 4934 | struct breakpoint *b = bl->owner; |
| 4935 | |
| 4936 | /* BL is from an existing breakpoint. */ |
| 4937 | gdb_assert (b != NULL); |
| 4938 | |
| 4939 | return b->ops->breakpoint_hit (bl, aspace, bp_addr, ws); |
| 4940 | } |
| 4941 | |
| 4942 | /* Determine if the watched values have actually changed, and we |
| 4943 | should stop. If not, set BS->stop to 0. */ |
| 4944 | |
| 4945 | static void |
| 4946 | bpstat_check_watchpoint (bpstat bs) |
| 4947 | { |
| 4948 | const struct bp_location *bl; |
| 4949 | struct watchpoint *b; |
| 4950 | |
| 4951 | /* BS is built for existing struct breakpoint. */ |
| 4952 | bl = bs->bp_location_at; |
| 4953 | gdb_assert (bl != NULL); |
| 4954 | b = (struct watchpoint *) bs->breakpoint_at; |
| 4955 | gdb_assert (b != NULL); |
| 4956 | |
| 4957 | { |
| 4958 | int must_check_value = 0; |
| 4959 | |
| 4960 | if (b->type == bp_watchpoint) |
| 4961 | /* For a software watchpoint, we must always check the |
| 4962 | watched value. */ |
| 4963 | must_check_value = 1; |
| 4964 | else if (b->watchpoint_triggered == watch_triggered_yes) |
| 4965 | /* We have a hardware watchpoint (read, write, or access) |
| 4966 | and the target earlier reported an address watched by |
| 4967 | this watchpoint. */ |
| 4968 | must_check_value = 1; |
| 4969 | else if (b->watchpoint_triggered == watch_triggered_unknown |
| 4970 | && b->type == bp_hardware_watchpoint) |
| 4971 | /* We were stopped by a hardware watchpoint, but the target could |
| 4972 | not report the data address. We must check the watchpoint's |
| 4973 | value. Access and read watchpoints are out of luck; without |
| 4974 | a data address, we can't figure it out. */ |
| 4975 | must_check_value = 1; |
| 4976 | |
| 4977 | if (must_check_value) |
| 4978 | { |
| 4979 | wp_check_result e; |
| 4980 | |
| 4981 | try |
| 4982 | { |
| 4983 | e = watchpoint_check (bs); |
| 4984 | } |
| 4985 | catch (const gdb_exception &ex) |
| 4986 | { |
| 4987 | exception_fprintf (gdb_stderr, ex, |
| 4988 | "Error evaluating expression " |
| 4989 | "for watchpoint %d\n", |
| 4990 | b->number); |
| 4991 | |
| 4992 | SWITCH_THRU_ALL_UIS () |
| 4993 | { |
| 4994 | printf_filtered (_("Watchpoint %d deleted.\n"), |
| 4995 | b->number); |
| 4996 | } |
| 4997 | watchpoint_del_at_next_stop (b); |
| 4998 | e = WP_DELETED; |
| 4999 | } |
| 5000 | |
| 5001 | switch (e) |
| 5002 | { |
| 5003 | case WP_DELETED: |
| 5004 | /* We've already printed what needs to be printed. */ |
| 5005 | bs->print_it = print_it_done; |
| 5006 | /* Stop. */ |
| 5007 | break; |
| 5008 | case WP_IGNORE: |
| 5009 | bs->print_it = print_it_noop; |
| 5010 | bs->stop = 0; |
| 5011 | break; |
| 5012 | case WP_VALUE_CHANGED: |
| 5013 | if (b->type == bp_read_watchpoint) |
| 5014 | { |
| 5015 | /* There are two cases to consider here: |
| 5016 | |
| 5017 | 1. We're watching the triggered memory for reads. |
| 5018 | In that case, trust the target, and always report |
| 5019 | the watchpoint hit to the user. Even though |
| 5020 | reads don't cause value changes, the value may |
| 5021 | have changed since the last time it was read, and |
| 5022 | since we're not trapping writes, we will not see |
| 5023 | those, and as such we should ignore our notion of |
| 5024 | old value. |
| 5025 | |
| 5026 | 2. We're watching the triggered memory for both |
| 5027 | reads and writes. There are two ways this may |
| 5028 | happen: |
| 5029 | |
| 5030 | 2.1. This is a target that can't break on data |
| 5031 | reads only, but can break on accesses (reads or |
| 5032 | writes), such as e.g., x86. We detect this case |
| 5033 | at the time we try to insert read watchpoints. |
| 5034 | |
| 5035 | 2.2. Otherwise, the target supports read |
| 5036 | watchpoints, but, the user set an access or write |
| 5037 | watchpoint watching the same memory as this read |
| 5038 | watchpoint. |
| 5039 | |
| 5040 | If we're watching memory writes as well as reads, |
| 5041 | ignore watchpoint hits when we find that the |
| 5042 | value hasn't changed, as reads don't cause |
| 5043 | changes. This still gives false positives when |
| 5044 | the program writes the same value to memory as |
| 5045 | what there was already in memory (we will confuse |
| 5046 | it for a read), but it's much better than |
| 5047 | nothing. */ |
| 5048 | |
| 5049 | int other_write_watchpoint = 0; |
| 5050 | |
| 5051 | if (bl->watchpoint_type == hw_read) |
| 5052 | { |
| 5053 | struct breakpoint *other_b; |
| 5054 | |
| 5055 | ALL_BREAKPOINTS (other_b) |
| 5056 | if (other_b->type == bp_hardware_watchpoint |
| 5057 | || other_b->type == bp_access_watchpoint) |
| 5058 | { |
| 5059 | struct watchpoint *other_w = |
| 5060 | (struct watchpoint *) other_b; |
| 5061 | |
| 5062 | if (other_w->watchpoint_triggered |
| 5063 | == watch_triggered_yes) |
| 5064 | { |
| 5065 | other_write_watchpoint = 1; |
| 5066 | break; |
| 5067 | } |
| 5068 | } |
| 5069 | } |
| 5070 | |
| 5071 | if (other_write_watchpoint |
| 5072 | || bl->watchpoint_type == hw_access) |
| 5073 | { |
| 5074 | /* We're watching the same memory for writes, |
| 5075 | and the value changed since the last time we |
| 5076 | updated it, so this trap must be for a write. |
| 5077 | Ignore it. */ |
| 5078 | bs->print_it = print_it_noop; |
| 5079 | bs->stop = 0; |
| 5080 | } |
| 5081 | } |
| 5082 | break; |
| 5083 | case WP_VALUE_NOT_CHANGED: |
| 5084 | if (b->type == bp_hardware_watchpoint |
| 5085 | || b->type == bp_watchpoint) |
| 5086 | { |
| 5087 | /* Don't stop: write watchpoints shouldn't fire if |
| 5088 | the value hasn't changed. */ |
| 5089 | bs->print_it = print_it_noop; |
| 5090 | bs->stop = 0; |
| 5091 | } |
| 5092 | /* Stop. */ |
| 5093 | break; |
| 5094 | default: |
| 5095 | /* Can't happen. */ |
| 5096 | break; |
| 5097 | } |
| 5098 | } |
| 5099 | else /* must_check_value == 0 */ |
| 5100 | { |
| 5101 | /* This is a case where some watchpoint(s) triggered, but |
| 5102 | not at the address of this watchpoint, or else no |
| 5103 | watchpoint triggered after all. So don't print |
| 5104 | anything for this watchpoint. */ |
| 5105 | bs->print_it = print_it_noop; |
| 5106 | bs->stop = 0; |
| 5107 | } |
| 5108 | } |
| 5109 | } |
| 5110 | |
| 5111 | /* For breakpoints that are currently marked as telling gdb to stop, |
| 5112 | check conditions (condition proper, frame, thread and ignore count) |
| 5113 | of breakpoint referred to by BS. If we should not stop for this |
| 5114 | breakpoint, set BS->stop to 0. */ |
| 5115 | |
| 5116 | static void |
| 5117 | bpstat_check_breakpoint_conditions (bpstat bs, thread_info *thread) |
| 5118 | { |
| 5119 | const struct bp_location *bl; |
| 5120 | struct breakpoint *b; |
| 5121 | /* Assume stop. */ |
| 5122 | bool condition_result = true; |
| 5123 | struct expression *cond; |
| 5124 | |
| 5125 | gdb_assert (bs->stop); |
| 5126 | |
| 5127 | /* BS is built for existing struct breakpoint. */ |
| 5128 | bl = bs->bp_location_at; |
| 5129 | gdb_assert (bl != NULL); |
| 5130 | b = bs->breakpoint_at; |
| 5131 | gdb_assert (b != NULL); |
| 5132 | |
| 5133 | /* Even if the target evaluated the condition on its end and notified GDB, we |
| 5134 | need to do so again since GDB does not know if we stopped due to a |
| 5135 | breakpoint or a single step breakpoint. */ |
| 5136 | |
| 5137 | if (frame_id_p (b->frame_id) |
| 5138 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
| 5139 | { |
| 5140 | bs->stop = 0; |
| 5141 | return; |
| 5142 | } |
| 5143 | |
| 5144 | /* If this is a thread/task-specific breakpoint, don't waste cpu |
| 5145 | evaluating the condition if this isn't the specified |
| 5146 | thread/task. */ |
| 5147 | if ((b->thread != -1 && b->thread != thread->global_num) |
| 5148 | || (b->task != 0 && b->task != ada_get_task_number (thread))) |
| 5149 | { |
| 5150 | bs->stop = 0; |
| 5151 | return; |
| 5152 | } |
| 5153 | |
| 5154 | /* Evaluate extension language breakpoints that have a "stop" method |
| 5155 | implemented. */ |
| 5156 | bs->stop = breakpoint_ext_lang_cond_says_stop (b); |
| 5157 | |
| 5158 | if (is_watchpoint (b)) |
| 5159 | { |
| 5160 | struct watchpoint *w = (struct watchpoint *) b; |
| 5161 | |
| 5162 | cond = w->cond_exp.get (); |
| 5163 | } |
| 5164 | else |
| 5165 | cond = bl->cond.get (); |
| 5166 | |
| 5167 | if (cond && b->disposition != disp_del_at_next_stop) |
| 5168 | { |
| 5169 | int within_current_scope = 1; |
| 5170 | struct watchpoint * w; |
| 5171 | |
| 5172 | /* We use value_mark and value_free_to_mark because it could |
| 5173 | be a long time before we return to the command level and |
| 5174 | call free_all_values. We can't call free_all_values |
| 5175 | because we might be in the middle of evaluating a |
| 5176 | function call. */ |
| 5177 | struct value *mark = value_mark (); |
| 5178 | |
| 5179 | if (is_watchpoint (b)) |
| 5180 | w = (struct watchpoint *) b; |
| 5181 | else |
| 5182 | w = NULL; |
| 5183 | |
| 5184 | /* Need to select the frame, with all that implies so that |
| 5185 | the conditions will have the right context. Because we |
| 5186 | use the frame, we will not see an inlined function's |
| 5187 | variables when we arrive at a breakpoint at the start |
| 5188 | of the inlined function; the current frame will be the |
| 5189 | call site. */ |
| 5190 | if (w == NULL || w->cond_exp_valid_block == NULL) |
| 5191 | select_frame (get_current_frame ()); |
| 5192 | else |
| 5193 | { |
| 5194 | struct frame_info *frame; |
| 5195 | |
| 5196 | /* For local watchpoint expressions, which particular |
| 5197 | instance of a local is being watched matters, so we |
| 5198 | keep track of the frame to evaluate the expression |
| 5199 | in. To evaluate the condition however, it doesn't |
| 5200 | really matter which instantiation of the function |
| 5201 | where the condition makes sense triggers the |
| 5202 | watchpoint. This allows an expression like "watch |
| 5203 | global if q > 10" set in `func', catch writes to |
| 5204 | global on all threads that call `func', or catch |
| 5205 | writes on all recursive calls of `func' by a single |
| 5206 | thread. We simply always evaluate the condition in |
| 5207 | the innermost frame that's executing where it makes |
| 5208 | sense to evaluate the condition. It seems |
| 5209 | intuitive. */ |
| 5210 | frame = block_innermost_frame (w->cond_exp_valid_block); |
| 5211 | if (frame != NULL) |
| 5212 | select_frame (frame); |
| 5213 | else |
| 5214 | within_current_scope = 0; |
| 5215 | } |
| 5216 | if (within_current_scope) |
| 5217 | { |
| 5218 | try |
| 5219 | { |
| 5220 | condition_result = breakpoint_cond_eval (cond); |
| 5221 | } |
| 5222 | catch (const gdb_exception &ex) |
| 5223 | { |
| 5224 | exception_fprintf (gdb_stderr, ex, |
| 5225 | "Error in testing breakpoint condition:\n"); |
| 5226 | } |
| 5227 | } |
| 5228 | else |
| 5229 | { |
| 5230 | warning (_("Watchpoint condition cannot be tested " |
| 5231 | "in the current scope")); |
| 5232 | /* If we failed to set the right context for this |
| 5233 | watchpoint, unconditionally report it. */ |
| 5234 | } |
| 5235 | /* FIXME-someday, should give breakpoint #. */ |
| 5236 | value_free_to_mark (mark); |
| 5237 | } |
| 5238 | |
| 5239 | if (cond && !condition_result) |
| 5240 | { |
| 5241 | bs->stop = 0; |
| 5242 | } |
| 5243 | else if (b->ignore_count > 0) |
| 5244 | { |
| 5245 | b->ignore_count--; |
| 5246 | bs->stop = 0; |
| 5247 | /* Increase the hit count even though we don't stop. */ |
| 5248 | ++(b->hit_count); |
| 5249 | gdb::observers::breakpoint_modified.notify (b); |
| 5250 | } |
| 5251 | } |
| 5252 | |
| 5253 | /* Returns true if we need to track moribund locations of LOC's type |
| 5254 | on the current target. */ |
| 5255 | |
| 5256 | static int |
| 5257 | need_moribund_for_location_type (struct bp_location *loc) |
| 5258 | { |
| 5259 | return ((loc->loc_type == bp_loc_software_breakpoint |
| 5260 | && !target_supports_stopped_by_sw_breakpoint ()) |
| 5261 | || (loc->loc_type == bp_loc_hardware_breakpoint |
| 5262 | && !target_supports_stopped_by_hw_breakpoint ())); |
| 5263 | } |
| 5264 | |
| 5265 | /* See breakpoint.h. */ |
| 5266 | |
| 5267 | bpstat |
| 5268 | build_bpstat_chain (const address_space *aspace, CORE_ADDR bp_addr, |
| 5269 | const struct target_waitstatus *ws) |
| 5270 | { |
| 5271 | struct breakpoint *b; |
| 5272 | bpstat bs_head = NULL, *bs_link = &bs_head; |
| 5273 | |
| 5274 | ALL_BREAKPOINTS (b) |
| 5275 | { |
| 5276 | if (!breakpoint_enabled (b)) |
| 5277 | continue; |
| 5278 | |
| 5279 | for (bp_location *bl = b->loc; bl != NULL; bl = bl->next) |
| 5280 | { |
| 5281 | /* For hardware watchpoints, we look only at the first |
| 5282 | location. The watchpoint_check function will work on the |
| 5283 | entire expression, not the individual locations. For |
| 5284 | read watchpoints, the watchpoints_triggered function has |
| 5285 | checked all locations already. */ |
| 5286 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
| 5287 | break; |
| 5288 | |
| 5289 | if (!bl->enabled || bl->shlib_disabled) |
| 5290 | continue; |
| 5291 | |
| 5292 | if (!bpstat_check_location (bl, aspace, bp_addr, ws)) |
| 5293 | continue; |
| 5294 | |
| 5295 | /* Come here if it's a watchpoint, or if the break address |
| 5296 | matches. */ |
| 5297 | |
| 5298 | bpstat bs = new bpstats (bl, &bs_link); /* Alloc a bpstat to |
| 5299 | explain stop. */ |
| 5300 | |
| 5301 | /* Assume we stop. Should we find a watchpoint that is not |
| 5302 | actually triggered, or if the condition of the breakpoint |
| 5303 | evaluates as false, we'll reset 'stop' to 0. */ |
| 5304 | bs->stop = 1; |
| 5305 | bs->print = 1; |
| 5306 | |
| 5307 | /* If this is a scope breakpoint, mark the associated |
| 5308 | watchpoint as triggered so that we will handle the |
| 5309 | out-of-scope event. We'll get to the watchpoint next |
| 5310 | iteration. */ |
| 5311 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
| 5312 | { |
| 5313 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; |
| 5314 | |
| 5315 | w->watchpoint_triggered = watch_triggered_yes; |
| 5316 | } |
| 5317 | } |
| 5318 | } |
| 5319 | |
| 5320 | /* Check if a moribund breakpoint explains the stop. */ |
| 5321 | if (!target_supports_stopped_by_sw_breakpoint () |
| 5322 | || !target_supports_stopped_by_hw_breakpoint ()) |
| 5323 | { |
| 5324 | for (bp_location *loc : moribund_locations) |
| 5325 | { |
| 5326 | if (breakpoint_location_address_match (loc, aspace, bp_addr) |
| 5327 | && need_moribund_for_location_type (loc)) |
| 5328 | { |
| 5329 | bpstat bs = new bpstats (loc, &bs_link); |
| 5330 | /* For hits of moribund locations, we should just proceed. */ |
| 5331 | bs->stop = 0; |
| 5332 | bs->print = 0; |
| 5333 | bs->print_it = print_it_noop; |
| 5334 | } |
| 5335 | } |
| 5336 | } |
| 5337 | |
| 5338 | return bs_head; |
| 5339 | } |
| 5340 | |
| 5341 | /* See breakpoint.h. */ |
| 5342 | |
| 5343 | bpstat |
| 5344 | bpstat_stop_status (const address_space *aspace, |
| 5345 | CORE_ADDR bp_addr, thread_info *thread, |
| 5346 | const struct target_waitstatus *ws, |
| 5347 | bpstat stop_chain) |
| 5348 | { |
| 5349 | struct breakpoint *b = NULL; |
| 5350 | /* First item of allocated bpstat's. */ |
| 5351 | bpstat bs_head = stop_chain; |
| 5352 | bpstat bs; |
| 5353 | int need_remove_insert; |
| 5354 | int removed_any; |
| 5355 | |
| 5356 | /* First, build the bpstat chain with locations that explain a |
| 5357 | target stop, while being careful to not set the target running, |
| 5358 | as that may invalidate locations (in particular watchpoint |
| 5359 | locations are recreated). Resuming will happen here with |
| 5360 | breakpoint conditions or watchpoint expressions that include |
| 5361 | inferior function calls. */ |
| 5362 | if (bs_head == NULL) |
| 5363 | bs_head = build_bpstat_chain (aspace, bp_addr, ws); |
| 5364 | |
| 5365 | /* A bit of special processing for shlib breakpoints. We need to |
| 5366 | process solib loading here, so that the lists of loaded and |
| 5367 | unloaded libraries are correct before we handle "catch load" and |
| 5368 | "catch unload". */ |
| 5369 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5370 | { |
| 5371 | if (bs->breakpoint_at && bs->breakpoint_at->type == bp_shlib_event) |
| 5372 | { |
| 5373 | handle_solib_event (); |
| 5374 | break; |
| 5375 | } |
| 5376 | } |
| 5377 | |
| 5378 | /* Now go through the locations that caused the target to stop, and |
| 5379 | check whether we're interested in reporting this stop to higher |
| 5380 | layers, or whether we should resume the target transparently. */ |
| 5381 | |
| 5382 | removed_any = 0; |
| 5383 | |
| 5384 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5385 | { |
| 5386 | if (!bs->stop) |
| 5387 | continue; |
| 5388 | |
| 5389 | b = bs->breakpoint_at; |
| 5390 | b->ops->check_status (bs); |
| 5391 | if (bs->stop) |
| 5392 | { |
| 5393 | bpstat_check_breakpoint_conditions (bs, thread); |
| 5394 | |
| 5395 | if (bs->stop) |
| 5396 | { |
| 5397 | ++(b->hit_count); |
| 5398 | gdb::observers::breakpoint_modified.notify (b); |
| 5399 | |
| 5400 | /* We will stop here. */ |
| 5401 | if (b->disposition == disp_disable) |
| 5402 | { |
| 5403 | --(b->enable_count); |
| 5404 | if (b->enable_count <= 0) |
| 5405 | b->enable_state = bp_disabled; |
| 5406 | removed_any = 1; |
| 5407 | } |
| 5408 | if (b->silent) |
| 5409 | bs->print = 0; |
| 5410 | bs->commands = b->commands; |
| 5411 | if (command_line_is_silent (bs->commands |
| 5412 | ? bs->commands.get () : NULL)) |
| 5413 | bs->print = 0; |
| 5414 | |
| 5415 | b->ops->after_condition_true (bs); |
| 5416 | } |
| 5417 | |
| 5418 | } |
| 5419 | |
| 5420 | /* Print nothing for this entry if we don't stop or don't |
| 5421 | print. */ |
| 5422 | if (!bs->stop || !bs->print) |
| 5423 | bs->print_it = print_it_noop; |
| 5424 | } |
| 5425 | |
| 5426 | /* If we aren't stopping, the value of some hardware watchpoint may |
| 5427 | not have changed, but the intermediate memory locations we are |
| 5428 | watching may have. Don't bother if we're stopping; this will get |
| 5429 | done later. */ |
| 5430 | need_remove_insert = 0; |
| 5431 | if (! bpstat_causes_stop (bs_head)) |
| 5432 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5433 | if (!bs->stop |
| 5434 | && bs->breakpoint_at |
| 5435 | && is_hardware_watchpoint (bs->breakpoint_at)) |
| 5436 | { |
| 5437 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
| 5438 | |
| 5439 | update_watchpoint (w, 0 /* don't reparse. */); |
| 5440 | need_remove_insert = 1; |
| 5441 | } |
| 5442 | |
| 5443 | if (need_remove_insert) |
| 5444 | update_global_location_list (UGLL_MAY_INSERT); |
| 5445 | else if (removed_any) |
| 5446 | update_global_location_list (UGLL_DONT_INSERT); |
| 5447 | |
| 5448 | return bs_head; |
| 5449 | } |
| 5450 | |
| 5451 | static void |
| 5452 | handle_jit_event (void) |
| 5453 | { |
| 5454 | struct frame_info *frame; |
| 5455 | struct gdbarch *gdbarch; |
| 5456 | |
| 5457 | if (debug_infrun) |
| 5458 | fprintf_unfiltered (gdb_stdlog, "handling bp_jit_event\n"); |
| 5459 | |
| 5460 | /* Switch terminal for any messages produced by |
| 5461 | breakpoint_re_set. */ |
| 5462 | target_terminal::ours_for_output (); |
| 5463 | |
| 5464 | frame = get_current_frame (); |
| 5465 | gdbarch = get_frame_arch (frame); |
| 5466 | |
| 5467 | jit_event_handler (gdbarch); |
| 5468 | |
| 5469 | target_terminal::inferior (); |
| 5470 | } |
| 5471 | |
| 5472 | /* Prepare WHAT final decision for infrun. */ |
| 5473 | |
| 5474 | /* Decide what infrun needs to do with this bpstat. */ |
| 5475 | |
| 5476 | struct bpstat_what |
| 5477 | bpstat_what (bpstat bs_head) |
| 5478 | { |
| 5479 | struct bpstat_what retval; |
| 5480 | bpstat bs; |
| 5481 | |
| 5482 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5483 | retval.call_dummy = STOP_NONE; |
| 5484 | retval.is_longjmp = false; |
| 5485 | |
| 5486 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5487 | { |
| 5488 | /* Extract this BS's action. After processing each BS, we check |
| 5489 | if its action overrides all we've seem so far. */ |
| 5490 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5491 | enum bptype bptype; |
| 5492 | |
| 5493 | if (bs->breakpoint_at == NULL) |
| 5494 | { |
| 5495 | /* I suspect this can happen if it was a momentary |
| 5496 | breakpoint which has since been deleted. */ |
| 5497 | bptype = bp_none; |
| 5498 | } |
| 5499 | else |
| 5500 | bptype = bs->breakpoint_at->type; |
| 5501 | |
| 5502 | switch (bptype) |
| 5503 | { |
| 5504 | case bp_none: |
| 5505 | break; |
| 5506 | case bp_breakpoint: |
| 5507 | case bp_hardware_breakpoint: |
| 5508 | case bp_single_step: |
| 5509 | case bp_until: |
| 5510 | case bp_finish: |
| 5511 | case bp_shlib_event: |
| 5512 | if (bs->stop) |
| 5513 | { |
| 5514 | if (bs->print) |
| 5515 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5516 | else |
| 5517 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5518 | } |
| 5519 | else |
| 5520 | this_action = BPSTAT_WHAT_SINGLE; |
| 5521 | break; |
| 5522 | case bp_watchpoint: |
| 5523 | case bp_hardware_watchpoint: |
| 5524 | case bp_read_watchpoint: |
| 5525 | case bp_access_watchpoint: |
| 5526 | if (bs->stop) |
| 5527 | { |
| 5528 | if (bs->print) |
| 5529 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5530 | else |
| 5531 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5532 | } |
| 5533 | else |
| 5534 | { |
| 5535 | /* There was a watchpoint, but we're not stopping. |
| 5536 | This requires no further action. */ |
| 5537 | } |
| 5538 | break; |
| 5539 | case bp_longjmp: |
| 5540 | case bp_longjmp_call_dummy: |
| 5541 | case bp_exception: |
| 5542 | if (bs->stop) |
| 5543 | { |
| 5544 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
| 5545 | retval.is_longjmp = bptype != bp_exception; |
| 5546 | } |
| 5547 | else |
| 5548 | this_action = BPSTAT_WHAT_SINGLE; |
| 5549 | break; |
| 5550 | case bp_longjmp_resume: |
| 5551 | case bp_exception_resume: |
| 5552 | if (bs->stop) |
| 5553 | { |
| 5554 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
| 5555 | retval.is_longjmp = bptype == bp_longjmp_resume; |
| 5556 | } |
| 5557 | else |
| 5558 | this_action = BPSTAT_WHAT_SINGLE; |
| 5559 | break; |
| 5560 | case bp_step_resume: |
| 5561 | if (bs->stop) |
| 5562 | this_action = BPSTAT_WHAT_STEP_RESUME; |
| 5563 | else |
| 5564 | { |
| 5565 | /* It is for the wrong frame. */ |
| 5566 | this_action = BPSTAT_WHAT_SINGLE; |
| 5567 | } |
| 5568 | break; |
| 5569 | case bp_hp_step_resume: |
| 5570 | if (bs->stop) |
| 5571 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; |
| 5572 | else |
| 5573 | { |
| 5574 | /* It is for the wrong frame. */ |
| 5575 | this_action = BPSTAT_WHAT_SINGLE; |
| 5576 | } |
| 5577 | break; |
| 5578 | case bp_watchpoint_scope: |
| 5579 | case bp_thread_event: |
| 5580 | case bp_overlay_event: |
| 5581 | case bp_longjmp_master: |
| 5582 | case bp_std_terminate_master: |
| 5583 | case bp_exception_master: |
| 5584 | this_action = BPSTAT_WHAT_SINGLE; |
| 5585 | break; |
| 5586 | case bp_catchpoint: |
| 5587 | if (bs->stop) |
| 5588 | { |
| 5589 | if (bs->print) |
| 5590 | this_action = BPSTAT_WHAT_STOP_NOISY; |
| 5591 | else |
| 5592 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5593 | } |
| 5594 | else |
| 5595 | { |
| 5596 | /* Some catchpoints are implemented with breakpoints. |
| 5597 | For those, we need to step over the breakpoint. */ |
| 5598 | if (bs->bp_location_at->loc_type != bp_loc_other) |
| 5599 | this_action = BPSTAT_WHAT_SINGLE; |
| 5600 | } |
| 5601 | break; |
| 5602 | case bp_jit_event: |
| 5603 | this_action = BPSTAT_WHAT_SINGLE; |
| 5604 | break; |
| 5605 | case bp_call_dummy: |
| 5606 | /* Make sure the action is stop (silent or noisy), |
| 5607 | so infrun.c pops the dummy frame. */ |
| 5608 | retval.call_dummy = STOP_STACK_DUMMY; |
| 5609 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5610 | break; |
| 5611 | case bp_std_terminate: |
| 5612 | /* Make sure the action is stop (silent or noisy), |
| 5613 | so infrun.c pops the dummy frame. */ |
| 5614 | retval.call_dummy = STOP_STD_TERMINATE; |
| 5615 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5616 | break; |
| 5617 | case bp_tracepoint: |
| 5618 | case bp_fast_tracepoint: |
| 5619 | case bp_static_tracepoint: |
| 5620 | /* Tracepoint hits should not be reported back to GDB, and |
| 5621 | if one got through somehow, it should have been filtered |
| 5622 | out already. */ |
| 5623 | internal_error (__FILE__, __LINE__, |
| 5624 | _("bpstat_what: tracepoint encountered")); |
| 5625 | break; |
| 5626 | case bp_gnu_ifunc_resolver: |
| 5627 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ |
| 5628 | this_action = BPSTAT_WHAT_SINGLE; |
| 5629 | break; |
| 5630 | case bp_gnu_ifunc_resolver_return: |
| 5631 | /* The breakpoint will be removed, execution will restart from the |
| 5632 | PC of the former breakpoint. */ |
| 5633 | this_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 5634 | break; |
| 5635 | |
| 5636 | case bp_dprintf: |
| 5637 | if (bs->stop) |
| 5638 | this_action = BPSTAT_WHAT_STOP_SILENT; |
| 5639 | else |
| 5640 | this_action = BPSTAT_WHAT_SINGLE; |
| 5641 | break; |
| 5642 | |
| 5643 | default: |
| 5644 | internal_error (__FILE__, __LINE__, |
| 5645 | _("bpstat_what: unhandled bptype %d"), (int) bptype); |
| 5646 | } |
| 5647 | |
| 5648 | retval.main_action = std::max (retval.main_action, this_action); |
| 5649 | } |
| 5650 | |
| 5651 | return retval; |
| 5652 | } |
| 5653 | |
| 5654 | void |
| 5655 | bpstat_run_callbacks (bpstat bs_head) |
| 5656 | { |
| 5657 | bpstat bs; |
| 5658 | |
| 5659 | for (bs = bs_head; bs != NULL; bs = bs->next) |
| 5660 | { |
| 5661 | struct breakpoint *b = bs->breakpoint_at; |
| 5662 | |
| 5663 | if (b == NULL) |
| 5664 | continue; |
| 5665 | switch (b->type) |
| 5666 | { |
| 5667 | case bp_jit_event: |
| 5668 | handle_jit_event (); |
| 5669 | break; |
| 5670 | case bp_gnu_ifunc_resolver: |
| 5671 | gnu_ifunc_resolver_stop (b); |
| 5672 | break; |
| 5673 | case bp_gnu_ifunc_resolver_return: |
| 5674 | gnu_ifunc_resolver_return_stop (b); |
| 5675 | break; |
| 5676 | } |
| 5677 | } |
| 5678 | } |
| 5679 | |
| 5680 | /* See breakpoint.h. */ |
| 5681 | |
| 5682 | bool |
| 5683 | bpstat_should_step () |
| 5684 | { |
| 5685 | struct breakpoint *b; |
| 5686 | |
| 5687 | ALL_BREAKPOINTS (b) |
| 5688 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
| 5689 | return true; |
| 5690 | return false; |
| 5691 | } |
| 5692 | |
| 5693 | /* See breakpoint.h. */ |
| 5694 | |
| 5695 | bool |
| 5696 | bpstat_causes_stop (bpstat bs) |
| 5697 | { |
| 5698 | for (; bs != NULL; bs = bs->next) |
| 5699 | if (bs->stop) |
| 5700 | return true; |
| 5701 | |
| 5702 | return false; |
| 5703 | } |
| 5704 | |
| 5705 | \f |
| 5706 | |
| 5707 | /* Compute a string of spaces suitable to indent the next line |
| 5708 | so it starts at the position corresponding to the table column |
| 5709 | named COL_NAME in the currently active table of UIOUT. */ |
| 5710 | |
| 5711 | static char * |
| 5712 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) |
| 5713 | { |
| 5714 | static char wrap_indent[80]; |
| 5715 | int i, total_width, width, align; |
| 5716 | const char *text; |
| 5717 | |
| 5718 | total_width = 0; |
| 5719 | for (i = 1; uiout->query_table_field (i, &width, &align, &text); i++) |
| 5720 | { |
| 5721 | if (strcmp (text, col_name) == 0) |
| 5722 | { |
| 5723 | gdb_assert (total_width < sizeof wrap_indent); |
| 5724 | memset (wrap_indent, ' ', total_width); |
| 5725 | wrap_indent[total_width] = 0; |
| 5726 | |
| 5727 | return wrap_indent; |
| 5728 | } |
| 5729 | |
| 5730 | total_width += width + 1; |
| 5731 | } |
| 5732 | |
| 5733 | return NULL; |
| 5734 | } |
| 5735 | |
| 5736 | /* Determine if the locations of this breakpoint will have their conditions |
| 5737 | evaluated by the target, host or a mix of both. Returns the following: |
| 5738 | |
| 5739 | "host": Host evals condition. |
| 5740 | "host or target": Host or Target evals condition. |
| 5741 | "target": Target evals condition. |
| 5742 | */ |
| 5743 | |
| 5744 | static const char * |
| 5745 | bp_condition_evaluator (struct breakpoint *b) |
| 5746 | { |
| 5747 | struct bp_location *bl; |
| 5748 | char host_evals = 0; |
| 5749 | char target_evals = 0; |
| 5750 | |
| 5751 | if (!b) |
| 5752 | return NULL; |
| 5753 | |
| 5754 | if (!is_breakpoint (b)) |
| 5755 | return NULL; |
| 5756 | |
| 5757 | if (gdb_evaluates_breakpoint_condition_p () |
| 5758 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 5759 | return condition_evaluation_host; |
| 5760 | |
| 5761 | for (bl = b->loc; bl; bl = bl->next) |
| 5762 | { |
| 5763 | if (bl->cond_bytecode) |
| 5764 | target_evals++; |
| 5765 | else |
| 5766 | host_evals++; |
| 5767 | } |
| 5768 | |
| 5769 | if (host_evals && target_evals) |
| 5770 | return condition_evaluation_both; |
| 5771 | else if (target_evals) |
| 5772 | return condition_evaluation_target; |
| 5773 | else |
| 5774 | return condition_evaluation_host; |
| 5775 | } |
| 5776 | |
| 5777 | /* Determine the breakpoint location's condition evaluator. This is |
| 5778 | similar to bp_condition_evaluator, but for locations. */ |
| 5779 | |
| 5780 | static const char * |
| 5781 | bp_location_condition_evaluator (struct bp_location *bl) |
| 5782 | { |
| 5783 | if (bl && !is_breakpoint (bl->owner)) |
| 5784 | return NULL; |
| 5785 | |
| 5786 | if (gdb_evaluates_breakpoint_condition_p () |
| 5787 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 5788 | return condition_evaluation_host; |
| 5789 | |
| 5790 | if (bl && bl->cond_bytecode) |
| 5791 | return condition_evaluation_target; |
| 5792 | else |
| 5793 | return condition_evaluation_host; |
| 5794 | } |
| 5795 | |
| 5796 | /* Print the LOC location out of the list of B->LOC locations. */ |
| 5797 | |
| 5798 | static void |
| 5799 | print_breakpoint_location (struct breakpoint *b, |
| 5800 | struct bp_location *loc) |
| 5801 | { |
| 5802 | struct ui_out *uiout = current_uiout; |
| 5803 | |
| 5804 | scoped_restore_current_program_space restore_pspace; |
| 5805 | |
| 5806 | if (loc != NULL && loc->shlib_disabled) |
| 5807 | loc = NULL; |
| 5808 | |
| 5809 | if (loc != NULL) |
| 5810 | set_current_program_space (loc->pspace); |
| 5811 | |
| 5812 | if (b->display_canonical) |
| 5813 | uiout->field_string ("what", event_location_to_string (b->location.get ())); |
| 5814 | else if (loc && loc->symtab) |
| 5815 | { |
| 5816 | const struct symbol *sym = loc->symbol; |
| 5817 | |
| 5818 | if (sym) |
| 5819 | { |
| 5820 | uiout->text ("in "); |
| 5821 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym), |
| 5822 | function_name_style.style ()); |
| 5823 | uiout->text (" "); |
| 5824 | uiout->wrap_hint (wrap_indent_at_field (uiout, "what")); |
| 5825 | uiout->text ("at "); |
| 5826 | } |
| 5827 | uiout->field_string ("file", |
| 5828 | symtab_to_filename_for_display (loc->symtab), |
| 5829 | file_name_style.style ()); |
| 5830 | uiout->text (":"); |
| 5831 | |
| 5832 | if (uiout->is_mi_like_p ()) |
| 5833 | uiout->field_string ("fullname", symtab_to_fullname (loc->symtab)); |
| 5834 | |
| 5835 | uiout->field_signed ("line", loc->line_number); |
| 5836 | } |
| 5837 | else if (loc) |
| 5838 | { |
| 5839 | string_file stb; |
| 5840 | |
| 5841 | print_address_symbolic (loc->gdbarch, loc->address, &stb, |
| 5842 | demangle, ""); |
| 5843 | uiout->field_stream ("at", stb); |
| 5844 | } |
| 5845 | else |
| 5846 | { |
| 5847 | uiout->field_string ("pending", |
| 5848 | event_location_to_string (b->location.get ())); |
| 5849 | /* If extra_string is available, it could be holding a condition |
| 5850 | or dprintf arguments. In either case, make sure it is printed, |
| 5851 | too, but only for non-MI streams. */ |
| 5852 | if (!uiout->is_mi_like_p () && b->extra_string != NULL) |
| 5853 | { |
| 5854 | if (b->type == bp_dprintf) |
| 5855 | uiout->text (","); |
| 5856 | else |
| 5857 | uiout->text (" "); |
| 5858 | uiout->text (b->extra_string); |
| 5859 | } |
| 5860 | } |
| 5861 | |
| 5862 | if (loc && is_breakpoint (b) |
| 5863 | && breakpoint_condition_evaluation_mode () == condition_evaluation_target |
| 5864 | && bp_condition_evaluator (b) == condition_evaluation_both) |
| 5865 | { |
| 5866 | uiout->text (" ("); |
| 5867 | uiout->field_string ("evaluated-by", |
| 5868 | bp_location_condition_evaluator (loc)); |
| 5869 | uiout->text (")"); |
| 5870 | } |
| 5871 | } |
| 5872 | |
| 5873 | static const char * |
| 5874 | bptype_string (enum bptype type) |
| 5875 | { |
| 5876 | struct ep_type_description |
| 5877 | { |
| 5878 | enum bptype type; |
| 5879 | const char *description; |
| 5880 | }; |
| 5881 | static struct ep_type_description bptypes[] = |
| 5882 | { |
| 5883 | {bp_none, "?deleted?"}, |
| 5884 | {bp_breakpoint, "breakpoint"}, |
| 5885 | {bp_hardware_breakpoint, "hw breakpoint"}, |
| 5886 | {bp_single_step, "sw single-step"}, |
| 5887 | {bp_until, "until"}, |
| 5888 | {bp_finish, "finish"}, |
| 5889 | {bp_watchpoint, "watchpoint"}, |
| 5890 | {bp_hardware_watchpoint, "hw watchpoint"}, |
| 5891 | {bp_read_watchpoint, "read watchpoint"}, |
| 5892 | {bp_access_watchpoint, "acc watchpoint"}, |
| 5893 | {bp_longjmp, "longjmp"}, |
| 5894 | {bp_longjmp_resume, "longjmp resume"}, |
| 5895 | {bp_longjmp_call_dummy, "longjmp for call dummy"}, |
| 5896 | {bp_exception, "exception"}, |
| 5897 | {bp_exception_resume, "exception resume"}, |
| 5898 | {bp_step_resume, "step resume"}, |
| 5899 | {bp_hp_step_resume, "high-priority step resume"}, |
| 5900 | {bp_watchpoint_scope, "watchpoint scope"}, |
| 5901 | {bp_call_dummy, "call dummy"}, |
| 5902 | {bp_std_terminate, "std::terminate"}, |
| 5903 | {bp_shlib_event, "shlib events"}, |
| 5904 | {bp_thread_event, "thread events"}, |
| 5905 | {bp_overlay_event, "overlay events"}, |
| 5906 | {bp_longjmp_master, "longjmp master"}, |
| 5907 | {bp_std_terminate_master, "std::terminate master"}, |
| 5908 | {bp_exception_master, "exception master"}, |
| 5909 | {bp_catchpoint, "catchpoint"}, |
| 5910 | {bp_tracepoint, "tracepoint"}, |
| 5911 | {bp_fast_tracepoint, "fast tracepoint"}, |
| 5912 | {bp_static_tracepoint, "static tracepoint"}, |
| 5913 | {bp_dprintf, "dprintf"}, |
| 5914 | {bp_jit_event, "jit events"}, |
| 5915 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
| 5916 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, |
| 5917 | }; |
| 5918 | |
| 5919 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) |
| 5920 | || ((int) type != bptypes[(int) type].type)) |
| 5921 | internal_error (__FILE__, __LINE__, |
| 5922 | _("bptypes table does not describe type #%d."), |
| 5923 | (int) type); |
| 5924 | |
| 5925 | return bptypes[(int) type].description; |
| 5926 | } |
| 5927 | |
| 5928 | /* For MI, output a field named 'thread-groups' with a list as the value. |
| 5929 | For CLI, prefix the list with the string 'inf'. */ |
| 5930 | |
| 5931 | static void |
| 5932 | output_thread_groups (struct ui_out *uiout, |
| 5933 | const char *field_name, |
| 5934 | const std::vector<int> &inf_nums, |
| 5935 | int mi_only) |
| 5936 | { |
| 5937 | int is_mi = uiout->is_mi_like_p (); |
| 5938 | |
| 5939 | /* For backward compatibility, don't display inferiors in CLI unless |
| 5940 | there are several. Always display them for MI. */ |
| 5941 | if (!is_mi && mi_only) |
| 5942 | return; |
| 5943 | |
| 5944 | ui_out_emit_list list_emitter (uiout, field_name); |
| 5945 | |
| 5946 | for (size_t i = 0; i < inf_nums.size (); i++) |
| 5947 | { |
| 5948 | if (is_mi) |
| 5949 | { |
| 5950 | char mi_group[10]; |
| 5951 | |
| 5952 | xsnprintf (mi_group, sizeof (mi_group), "i%d", inf_nums[i]); |
| 5953 | uiout->field_string (NULL, mi_group); |
| 5954 | } |
| 5955 | else |
| 5956 | { |
| 5957 | if (i == 0) |
| 5958 | uiout->text (" inf "); |
| 5959 | else |
| 5960 | uiout->text (", "); |
| 5961 | |
| 5962 | uiout->text (plongest (inf_nums[i])); |
| 5963 | } |
| 5964 | } |
| 5965 | } |
| 5966 | |
| 5967 | /* Print B to gdb_stdout. If RAW_LOC, print raw breakpoint locations |
| 5968 | instead of going via breakpoint_ops::print_one. This makes "maint |
| 5969 | info breakpoints" show the software breakpoint locations of |
| 5970 | catchpoints, which are considered internal implementation |
| 5971 | detail. */ |
| 5972 | |
| 5973 | static void |
| 5974 | print_one_breakpoint_location (struct breakpoint *b, |
| 5975 | struct bp_location *loc, |
| 5976 | int loc_number, |
| 5977 | struct bp_location **last_loc, |
| 5978 | int allflag, bool raw_loc) |
| 5979 | { |
| 5980 | struct command_line *l; |
| 5981 | static char bpenables[] = "nynny"; |
| 5982 | |
| 5983 | struct ui_out *uiout = current_uiout; |
| 5984 | int header_of_multiple = 0; |
| 5985 | int part_of_multiple = (loc != NULL); |
| 5986 | struct value_print_options opts; |
| 5987 | |
| 5988 | get_user_print_options (&opts); |
| 5989 | |
| 5990 | gdb_assert (!loc || loc_number != 0); |
| 5991 | /* See comment in print_one_breakpoint concerning treatment of |
| 5992 | breakpoints with single disabled location. */ |
| 5993 | if (loc == NULL |
| 5994 | && (b->loc != NULL |
| 5995 | && (b->loc->next != NULL || !b->loc->enabled))) |
| 5996 | header_of_multiple = 1; |
| 5997 | if (loc == NULL) |
| 5998 | loc = b->loc; |
| 5999 | |
| 6000 | annotate_record (); |
| 6001 | |
| 6002 | /* 1 */ |
| 6003 | annotate_field (0); |
| 6004 | if (part_of_multiple) |
| 6005 | uiout->field_fmt ("number", "%d.%d", b->number, loc_number); |
| 6006 | else |
| 6007 | uiout->field_signed ("number", b->number); |
| 6008 | |
| 6009 | /* 2 */ |
| 6010 | annotate_field (1); |
| 6011 | if (part_of_multiple) |
| 6012 | uiout->field_skip ("type"); |
| 6013 | else |
| 6014 | uiout->field_string ("type", bptype_string (b->type)); |
| 6015 | |
| 6016 | /* 3 */ |
| 6017 | annotate_field (2); |
| 6018 | if (part_of_multiple) |
| 6019 | uiout->field_skip ("disp"); |
| 6020 | else |
| 6021 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 6022 | |
| 6023 | /* 4 */ |
| 6024 | annotate_field (3); |
| 6025 | if (part_of_multiple) |
| 6026 | uiout->field_string ("enabled", loc->enabled ? "y" : "n"); |
| 6027 | else |
| 6028 | uiout->field_fmt ("enabled", "%c", bpenables[(int) b->enable_state]); |
| 6029 | |
| 6030 | /* 5 and 6 */ |
| 6031 | if (!raw_loc && b->ops != NULL && b->ops->print_one != NULL) |
| 6032 | b->ops->print_one (b, last_loc); |
| 6033 | else |
| 6034 | { |
| 6035 | if (is_watchpoint (b)) |
| 6036 | { |
| 6037 | struct watchpoint *w = (struct watchpoint *) b; |
| 6038 | |
| 6039 | /* Field 4, the address, is omitted (which makes the columns |
| 6040 | not line up too nicely with the headers, but the effect |
| 6041 | is relatively readable). */ |
| 6042 | if (opts.addressprint) |
| 6043 | uiout->field_skip ("addr"); |
| 6044 | annotate_field (5); |
| 6045 | uiout->field_string ("what", w->exp_string); |
| 6046 | } |
| 6047 | else if (!is_catchpoint (b) || is_exception_catchpoint (b) |
| 6048 | || is_ada_exception_catchpoint (b)) |
| 6049 | { |
| 6050 | if (opts.addressprint) |
| 6051 | { |
| 6052 | annotate_field (4); |
| 6053 | if (header_of_multiple) |
| 6054 | uiout->field_string ("addr", "<MULTIPLE>", |
| 6055 | metadata_style.style ()); |
| 6056 | else if (b->loc == NULL || loc->shlib_disabled) |
| 6057 | uiout->field_string ("addr", "<PENDING>", |
| 6058 | metadata_style.style ()); |
| 6059 | else |
| 6060 | uiout->field_core_addr ("addr", |
| 6061 | loc->gdbarch, loc->address); |
| 6062 | } |
| 6063 | annotate_field (5); |
| 6064 | if (!header_of_multiple) |
| 6065 | print_breakpoint_location (b, loc); |
| 6066 | if (b->loc) |
| 6067 | *last_loc = b->loc; |
| 6068 | } |
| 6069 | } |
| 6070 | |
| 6071 | if (loc != NULL && !header_of_multiple) |
| 6072 | { |
| 6073 | std::vector<int> inf_nums; |
| 6074 | int mi_only = 1; |
| 6075 | |
| 6076 | for (inferior *inf : all_inferiors ()) |
| 6077 | { |
| 6078 | if (inf->pspace == loc->pspace) |
| 6079 | inf_nums.push_back (inf->num); |
| 6080 | } |
| 6081 | |
| 6082 | /* For backward compatibility, don't display inferiors in CLI unless |
| 6083 | there are several. Always display for MI. */ |
| 6084 | if (allflag |
| 6085 | || (!gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6086 | && (number_of_program_spaces () > 1 |
| 6087 | || number_of_inferiors () > 1) |
| 6088 | /* LOC is for existing B, it cannot be in |
| 6089 | moribund_locations and thus having NULL OWNER. */ |
| 6090 | && loc->owner->type != bp_catchpoint)) |
| 6091 | mi_only = 0; |
| 6092 | output_thread_groups (uiout, "thread-groups", inf_nums, mi_only); |
| 6093 | } |
| 6094 | |
| 6095 | if (!part_of_multiple) |
| 6096 | { |
| 6097 | if (b->thread != -1) |
| 6098 | { |
| 6099 | /* FIXME: This seems to be redundant and lost here; see the |
| 6100 | "stop only in" line a little further down. */ |
| 6101 | uiout->text (" thread "); |
| 6102 | uiout->field_signed ("thread", b->thread); |
| 6103 | } |
| 6104 | else if (b->task != 0) |
| 6105 | { |
| 6106 | uiout->text (" task "); |
| 6107 | uiout->field_signed ("task", b->task); |
| 6108 | } |
| 6109 | } |
| 6110 | |
| 6111 | uiout->text ("\n"); |
| 6112 | |
| 6113 | if (!part_of_multiple) |
| 6114 | b->ops->print_one_detail (b, uiout); |
| 6115 | |
| 6116 | if (part_of_multiple && frame_id_p (b->frame_id)) |
| 6117 | { |
| 6118 | annotate_field (6); |
| 6119 | uiout->text ("\tstop only in stack frame at "); |
| 6120 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
| 6121 | the frame ID. */ |
| 6122 | uiout->field_core_addr ("frame", |
| 6123 | b->gdbarch, b->frame_id.stack_addr); |
| 6124 | uiout->text ("\n"); |
| 6125 | } |
| 6126 | |
| 6127 | if (!part_of_multiple && b->cond_string) |
| 6128 | { |
| 6129 | annotate_field (7); |
| 6130 | if (is_tracepoint (b)) |
| 6131 | uiout->text ("\ttrace only if "); |
| 6132 | else |
| 6133 | uiout->text ("\tstop only if "); |
| 6134 | uiout->field_string ("cond", b->cond_string); |
| 6135 | |
| 6136 | /* Print whether the target is doing the breakpoint's condition |
| 6137 | evaluation. If GDB is doing the evaluation, don't print anything. */ |
| 6138 | if (is_breakpoint (b) |
| 6139 | && breakpoint_condition_evaluation_mode () |
| 6140 | == condition_evaluation_target) |
| 6141 | { |
| 6142 | uiout->message (" (%pF evals)", |
| 6143 | string_field ("evaluated-by", |
| 6144 | bp_condition_evaluator (b))); |
| 6145 | } |
| 6146 | uiout->text ("\n"); |
| 6147 | } |
| 6148 | |
| 6149 | if (!part_of_multiple && b->thread != -1) |
| 6150 | { |
| 6151 | /* FIXME should make an annotation for this. */ |
| 6152 | uiout->text ("\tstop only in thread "); |
| 6153 | if (uiout->is_mi_like_p ()) |
| 6154 | uiout->field_signed ("thread", b->thread); |
| 6155 | else |
| 6156 | { |
| 6157 | struct thread_info *thr = find_thread_global_id (b->thread); |
| 6158 | |
| 6159 | uiout->field_string ("thread", print_thread_id (thr)); |
| 6160 | } |
| 6161 | uiout->text ("\n"); |
| 6162 | } |
| 6163 | |
| 6164 | if (!part_of_multiple) |
| 6165 | { |
| 6166 | if (b->hit_count) |
| 6167 | { |
| 6168 | /* FIXME should make an annotation for this. */ |
| 6169 | if (is_catchpoint (b)) |
| 6170 | uiout->text ("\tcatchpoint"); |
| 6171 | else if (is_tracepoint (b)) |
| 6172 | uiout->text ("\ttracepoint"); |
| 6173 | else |
| 6174 | uiout->text ("\tbreakpoint"); |
| 6175 | uiout->text (" already hit "); |
| 6176 | uiout->field_signed ("times", b->hit_count); |
| 6177 | if (b->hit_count == 1) |
| 6178 | uiout->text (" time\n"); |
| 6179 | else |
| 6180 | uiout->text (" times\n"); |
| 6181 | } |
| 6182 | else |
| 6183 | { |
| 6184 | /* Output the count also if it is zero, but only if this is mi. */ |
| 6185 | if (uiout->is_mi_like_p ()) |
| 6186 | uiout->field_signed ("times", b->hit_count); |
| 6187 | } |
| 6188 | } |
| 6189 | |
| 6190 | if (!part_of_multiple && b->ignore_count) |
| 6191 | { |
| 6192 | annotate_field (8); |
| 6193 | uiout->message ("\tignore next %pF hits\n", |
| 6194 | signed_field ("ignore", b->ignore_count)); |
| 6195 | } |
| 6196 | |
| 6197 | /* Note that an enable count of 1 corresponds to "enable once" |
| 6198 | behavior, which is reported by the combination of enablement and |
| 6199 | disposition, so we don't need to mention it here. */ |
| 6200 | if (!part_of_multiple && b->enable_count > 1) |
| 6201 | { |
| 6202 | annotate_field (8); |
| 6203 | uiout->text ("\tdisable after "); |
| 6204 | /* Tweak the wording to clarify that ignore and enable counts |
| 6205 | are distinct, and have additive effect. */ |
| 6206 | if (b->ignore_count) |
| 6207 | uiout->text ("additional "); |
| 6208 | else |
| 6209 | uiout->text ("next "); |
| 6210 | uiout->field_signed ("enable", b->enable_count); |
| 6211 | uiout->text (" hits\n"); |
| 6212 | } |
| 6213 | |
| 6214 | if (!part_of_multiple && is_tracepoint (b)) |
| 6215 | { |
| 6216 | struct tracepoint *tp = (struct tracepoint *) b; |
| 6217 | |
| 6218 | if (tp->traceframe_usage) |
| 6219 | { |
| 6220 | uiout->text ("\ttrace buffer usage "); |
| 6221 | uiout->field_signed ("traceframe-usage", tp->traceframe_usage); |
| 6222 | uiout->text (" bytes\n"); |
| 6223 | } |
| 6224 | } |
| 6225 | |
| 6226 | l = b->commands ? b->commands.get () : NULL; |
| 6227 | if (!part_of_multiple && l) |
| 6228 | { |
| 6229 | annotate_field (9); |
| 6230 | ui_out_emit_tuple tuple_emitter (uiout, "script"); |
| 6231 | print_command_lines (uiout, l, 4); |
| 6232 | } |
| 6233 | |
| 6234 | if (is_tracepoint (b)) |
| 6235 | { |
| 6236 | struct tracepoint *t = (struct tracepoint *) b; |
| 6237 | |
| 6238 | if (!part_of_multiple && t->pass_count) |
| 6239 | { |
| 6240 | annotate_field (10); |
| 6241 | uiout->text ("\tpass count "); |
| 6242 | uiout->field_signed ("pass", t->pass_count); |
| 6243 | uiout->text (" \n"); |
| 6244 | } |
| 6245 | |
| 6246 | /* Don't display it when tracepoint or tracepoint location is |
| 6247 | pending. */ |
| 6248 | if (!header_of_multiple && loc != NULL && !loc->shlib_disabled) |
| 6249 | { |
| 6250 | annotate_field (11); |
| 6251 | |
| 6252 | if (uiout->is_mi_like_p ()) |
| 6253 | uiout->field_string ("installed", |
| 6254 | loc->inserted ? "y" : "n"); |
| 6255 | else |
| 6256 | { |
| 6257 | if (loc->inserted) |
| 6258 | uiout->text ("\t"); |
| 6259 | else |
| 6260 | uiout->text ("\tnot "); |
| 6261 | uiout->text ("installed on target\n"); |
| 6262 | } |
| 6263 | } |
| 6264 | } |
| 6265 | |
| 6266 | if (uiout->is_mi_like_p () && !part_of_multiple) |
| 6267 | { |
| 6268 | if (is_watchpoint (b)) |
| 6269 | { |
| 6270 | struct watchpoint *w = (struct watchpoint *) b; |
| 6271 | |
| 6272 | uiout->field_string ("original-location", w->exp_string); |
| 6273 | } |
| 6274 | else if (b->location != NULL |
| 6275 | && event_location_to_string (b->location.get ()) != NULL) |
| 6276 | uiout->field_string ("original-location", |
| 6277 | event_location_to_string (b->location.get ())); |
| 6278 | } |
| 6279 | } |
| 6280 | |
| 6281 | /* See breakpoint.h. */ |
| 6282 | |
| 6283 | bool fix_multi_location_breakpoint_output_globally = false; |
| 6284 | |
| 6285 | static void |
| 6286 | print_one_breakpoint (struct breakpoint *b, |
| 6287 | struct bp_location **last_loc, |
| 6288 | int allflag) |
| 6289 | { |
| 6290 | struct ui_out *uiout = current_uiout; |
| 6291 | bool use_fixed_output |
| 6292 | = (uiout->test_flags (fix_multi_location_breakpoint_output) |
| 6293 | || fix_multi_location_breakpoint_output_globally); |
| 6294 | |
| 6295 | gdb::optional<ui_out_emit_tuple> bkpt_tuple_emitter (gdb::in_place, uiout, "bkpt"); |
| 6296 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag, false); |
| 6297 | |
| 6298 | /* The mi2 broken format: the main breakpoint tuple ends here, the locations |
| 6299 | are outside. */ |
| 6300 | if (!use_fixed_output) |
| 6301 | bkpt_tuple_emitter.reset (); |
| 6302 | |
| 6303 | /* If this breakpoint has custom print function, |
| 6304 | it's already printed. Otherwise, print individual |
| 6305 | locations, if any. */ |
| 6306 | if (b->ops == NULL |
| 6307 | || b->ops->print_one == NULL |
| 6308 | || allflag) |
| 6309 | { |
| 6310 | /* If breakpoint has a single location that is disabled, we |
| 6311 | print it as if it had several locations, since otherwise it's |
| 6312 | hard to represent "breakpoint enabled, location disabled" |
| 6313 | situation. |
| 6314 | |
| 6315 | Note that while hardware watchpoints have several locations |
| 6316 | internally, that's not a property exposed to users. |
| 6317 | |
| 6318 | Likewise, while catchpoints may be implemented with |
| 6319 | breakpoints (e.g., catch throw), that's not a property |
| 6320 | exposed to users. We do however display the internal |
| 6321 | breakpoint locations with "maint info breakpoints". */ |
| 6322 | if (!is_hardware_watchpoint (b) |
| 6323 | && (!is_catchpoint (b) || is_exception_catchpoint (b) |
| 6324 | || is_ada_exception_catchpoint (b)) |
| 6325 | && (allflag |
| 6326 | || (b->loc && (b->loc->next || !b->loc->enabled)))) |
| 6327 | { |
| 6328 | gdb::optional<ui_out_emit_list> locations_list; |
| 6329 | |
| 6330 | /* For MI version <= 2, keep the behavior where GDB outputs an invalid |
| 6331 | MI record. For later versions, place breakpoint locations in a |
| 6332 | list. */ |
| 6333 | if (uiout->is_mi_like_p () && use_fixed_output) |
| 6334 | locations_list.emplace (uiout, "locations"); |
| 6335 | |
| 6336 | int n = 1; |
| 6337 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next, ++n) |
| 6338 | { |
| 6339 | ui_out_emit_tuple loc_tuple_emitter (uiout, NULL); |
| 6340 | print_one_breakpoint_location (b, loc, n, last_loc, |
| 6341 | allflag, allflag); |
| 6342 | } |
| 6343 | } |
| 6344 | } |
| 6345 | } |
| 6346 | |
| 6347 | static int |
| 6348 | breakpoint_address_bits (struct breakpoint *b) |
| 6349 | { |
| 6350 | int print_address_bits = 0; |
| 6351 | struct bp_location *loc; |
| 6352 | |
| 6353 | /* Software watchpoints that aren't watching memory don't have an |
| 6354 | address to print. */ |
| 6355 | if (is_no_memory_software_watchpoint (b)) |
| 6356 | return 0; |
| 6357 | |
| 6358 | for (loc = b->loc; loc; loc = loc->next) |
| 6359 | { |
| 6360 | int addr_bit; |
| 6361 | |
| 6362 | addr_bit = gdbarch_addr_bit (loc->gdbarch); |
| 6363 | if (addr_bit > print_address_bits) |
| 6364 | print_address_bits = addr_bit; |
| 6365 | } |
| 6366 | |
| 6367 | return print_address_bits; |
| 6368 | } |
| 6369 | |
| 6370 | /* See breakpoint.h. */ |
| 6371 | |
| 6372 | void |
| 6373 | print_breakpoint (breakpoint *b) |
| 6374 | { |
| 6375 | struct bp_location *dummy_loc = NULL; |
| 6376 | print_one_breakpoint (b, &dummy_loc, 0); |
| 6377 | } |
| 6378 | |
| 6379 | /* Return true if this breakpoint was set by the user, false if it is |
| 6380 | internal or momentary. */ |
| 6381 | |
| 6382 | int |
| 6383 | user_breakpoint_p (struct breakpoint *b) |
| 6384 | { |
| 6385 | return b->number > 0; |
| 6386 | } |
| 6387 | |
| 6388 | /* See breakpoint.h. */ |
| 6389 | |
| 6390 | int |
| 6391 | pending_breakpoint_p (struct breakpoint *b) |
| 6392 | { |
| 6393 | return b->loc == NULL; |
| 6394 | } |
| 6395 | |
| 6396 | /* Print information on breakpoints (including watchpoints and tracepoints). |
| 6397 | |
| 6398 | If non-NULL, BP_NUM_LIST is a list of numbers and number ranges as |
| 6399 | understood by number_or_range_parser. Only breakpoints included in this |
| 6400 | list are then printed. |
| 6401 | |
| 6402 | If SHOW_INTERNAL is true, print internal breakpoints. |
| 6403 | |
| 6404 | If FILTER is non-NULL, call it on each breakpoint and only include the |
| 6405 | ones for which it returns true. |
| 6406 | |
| 6407 | Return the total number of breakpoints listed. */ |
| 6408 | |
| 6409 | static int |
| 6410 | breakpoint_1 (const char *bp_num_list, bool show_internal, |
| 6411 | bool (*filter) (const struct breakpoint *)) |
| 6412 | { |
| 6413 | struct breakpoint *b; |
| 6414 | struct bp_location *last_loc = NULL; |
| 6415 | int nr_printable_breakpoints; |
| 6416 | struct value_print_options opts; |
| 6417 | int print_address_bits = 0; |
| 6418 | int print_type_col_width = 14; |
| 6419 | struct ui_out *uiout = current_uiout; |
| 6420 | |
| 6421 | get_user_print_options (&opts); |
| 6422 | |
| 6423 | /* Compute the number of rows in the table, as well as the size |
| 6424 | required for address fields. */ |
| 6425 | nr_printable_breakpoints = 0; |
| 6426 | ALL_BREAKPOINTS (b) |
| 6427 | { |
| 6428 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 6429 | if (filter && !filter (b)) |
| 6430 | continue; |
| 6431 | |
| 6432 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
| 6433 | accept. Skip the others. */ |
| 6434 | if (bp_num_list != NULL && *bp_num_list != '\0') |
| 6435 | { |
| 6436 | if (show_internal && parse_and_eval_long (bp_num_list) != b->number) |
| 6437 | continue; |
| 6438 | if (!show_internal && !number_is_in_list (bp_num_list, b->number)) |
| 6439 | continue; |
| 6440 | } |
| 6441 | |
| 6442 | if (show_internal || user_breakpoint_p (b)) |
| 6443 | { |
| 6444 | int addr_bit, type_len; |
| 6445 | |
| 6446 | addr_bit = breakpoint_address_bits (b); |
| 6447 | if (addr_bit > print_address_bits) |
| 6448 | print_address_bits = addr_bit; |
| 6449 | |
| 6450 | type_len = strlen (bptype_string (b->type)); |
| 6451 | if (type_len > print_type_col_width) |
| 6452 | print_type_col_width = type_len; |
| 6453 | |
| 6454 | nr_printable_breakpoints++; |
| 6455 | } |
| 6456 | } |
| 6457 | |
| 6458 | { |
| 6459 | ui_out_emit_table table_emitter (uiout, |
| 6460 | opts.addressprint ? 6 : 5, |
| 6461 | nr_printable_breakpoints, |
| 6462 | "BreakpointTable"); |
| 6463 | |
| 6464 | if (nr_printable_breakpoints > 0) |
| 6465 | annotate_breakpoints_headers (); |
| 6466 | if (nr_printable_breakpoints > 0) |
| 6467 | annotate_field (0); |
| 6468 | uiout->table_header (7, ui_left, "number", "Num"); /* 1 */ |
| 6469 | if (nr_printable_breakpoints > 0) |
| 6470 | annotate_field (1); |
| 6471 | uiout->table_header (print_type_col_width, ui_left, "type", "Type"); /* 2 */ |
| 6472 | if (nr_printable_breakpoints > 0) |
| 6473 | annotate_field (2); |
| 6474 | uiout->table_header (4, ui_left, "disp", "Disp"); /* 3 */ |
| 6475 | if (nr_printable_breakpoints > 0) |
| 6476 | annotate_field (3); |
| 6477 | uiout->table_header (3, ui_left, "enabled", "Enb"); /* 4 */ |
| 6478 | if (opts.addressprint) |
| 6479 | { |
| 6480 | if (nr_printable_breakpoints > 0) |
| 6481 | annotate_field (4); |
| 6482 | if (print_address_bits <= 32) |
| 6483 | uiout->table_header (10, ui_left, "addr", "Address"); /* 5 */ |
| 6484 | else |
| 6485 | uiout->table_header (18, ui_left, "addr", "Address"); /* 5 */ |
| 6486 | } |
| 6487 | if (nr_printable_breakpoints > 0) |
| 6488 | annotate_field (5); |
| 6489 | uiout->table_header (40, ui_noalign, "what", "What"); /* 6 */ |
| 6490 | uiout->table_body (); |
| 6491 | if (nr_printable_breakpoints > 0) |
| 6492 | annotate_breakpoints_table (); |
| 6493 | |
| 6494 | ALL_BREAKPOINTS (b) |
| 6495 | { |
| 6496 | QUIT; |
| 6497 | /* If we have a filter, only list the breakpoints it accepts. */ |
| 6498 | if (filter && !filter (b)) |
| 6499 | continue; |
| 6500 | |
| 6501 | /* If we have a BP_NUM_LIST string, it is a list of breakpoints to |
| 6502 | accept. Skip the others. */ |
| 6503 | |
| 6504 | if (bp_num_list != NULL && *bp_num_list != '\0') |
| 6505 | { |
| 6506 | if (show_internal) /* maintenance info breakpoint */ |
| 6507 | { |
| 6508 | if (parse_and_eval_long (bp_num_list) != b->number) |
| 6509 | continue; |
| 6510 | } |
| 6511 | else /* all others */ |
| 6512 | { |
| 6513 | if (!number_is_in_list (bp_num_list, b->number)) |
| 6514 | continue; |
| 6515 | } |
| 6516 | } |
| 6517 | /* We only print out user settable breakpoints unless the |
| 6518 | show_internal is set. */ |
| 6519 | if (show_internal || user_breakpoint_p (b)) |
| 6520 | print_one_breakpoint (b, &last_loc, show_internal); |
| 6521 | } |
| 6522 | } |
| 6523 | |
| 6524 | if (nr_printable_breakpoints == 0) |
| 6525 | { |
| 6526 | /* If there's a filter, let the caller decide how to report |
| 6527 | empty list. */ |
| 6528 | if (!filter) |
| 6529 | { |
| 6530 | if (bp_num_list == NULL || *bp_num_list == '\0') |
| 6531 | uiout->message ("No breakpoints or watchpoints.\n"); |
| 6532 | else |
| 6533 | uiout->message ("No breakpoint or watchpoint matching '%s'.\n", |
| 6534 | bp_num_list); |
| 6535 | } |
| 6536 | } |
| 6537 | else |
| 6538 | { |
| 6539 | if (last_loc && !server_command) |
| 6540 | set_next_address (last_loc->gdbarch, last_loc->address); |
| 6541 | } |
| 6542 | |
| 6543 | /* FIXME? Should this be moved up so that it is only called when |
| 6544 | there have been breakpoints? */ |
| 6545 | annotate_breakpoints_table_end (); |
| 6546 | |
| 6547 | return nr_printable_breakpoints; |
| 6548 | } |
| 6549 | |
| 6550 | /* Display the value of default-collect in a way that is generally |
| 6551 | compatible with the breakpoint list. */ |
| 6552 | |
| 6553 | static void |
| 6554 | default_collect_info (void) |
| 6555 | { |
| 6556 | struct ui_out *uiout = current_uiout; |
| 6557 | |
| 6558 | /* If it has no value (which is frequently the case), say nothing; a |
| 6559 | message like "No default-collect." gets in user's face when it's |
| 6560 | not wanted. */ |
| 6561 | if (!*default_collect) |
| 6562 | return; |
| 6563 | |
| 6564 | /* The following phrase lines up nicely with per-tracepoint collect |
| 6565 | actions. */ |
| 6566 | uiout->text ("default collect "); |
| 6567 | uiout->field_string ("default-collect", default_collect); |
| 6568 | uiout->text (" \n"); |
| 6569 | } |
| 6570 | |
| 6571 | static void |
| 6572 | info_breakpoints_command (const char *args, int from_tty) |
| 6573 | { |
| 6574 | breakpoint_1 (args, false, NULL); |
| 6575 | |
| 6576 | default_collect_info (); |
| 6577 | } |
| 6578 | |
| 6579 | static void |
| 6580 | info_watchpoints_command (const char *args, int from_tty) |
| 6581 | { |
| 6582 | int num_printed = breakpoint_1 (args, false, is_watchpoint); |
| 6583 | struct ui_out *uiout = current_uiout; |
| 6584 | |
| 6585 | if (num_printed == 0) |
| 6586 | { |
| 6587 | if (args == NULL || *args == '\0') |
| 6588 | uiout->message ("No watchpoints.\n"); |
| 6589 | else |
| 6590 | uiout->message ("No watchpoint matching '%s'.\n", args); |
| 6591 | } |
| 6592 | } |
| 6593 | |
| 6594 | static void |
| 6595 | maintenance_info_breakpoints (const char *args, int from_tty) |
| 6596 | { |
| 6597 | breakpoint_1 (args, true, NULL); |
| 6598 | |
| 6599 | default_collect_info (); |
| 6600 | } |
| 6601 | |
| 6602 | static int |
| 6603 | breakpoint_has_pc (struct breakpoint *b, |
| 6604 | struct program_space *pspace, |
| 6605 | CORE_ADDR pc, struct obj_section *section) |
| 6606 | { |
| 6607 | struct bp_location *bl = b->loc; |
| 6608 | |
| 6609 | for (; bl; bl = bl->next) |
| 6610 | { |
| 6611 | if (bl->pspace == pspace |
| 6612 | && bl->address == pc |
| 6613 | && (!overlay_debugging || bl->section == section)) |
| 6614 | return 1; |
| 6615 | } |
| 6616 | return 0; |
| 6617 | } |
| 6618 | |
| 6619 | /* Print a message describing any user-breakpoints set at PC. This |
| 6620 | concerns with logical breakpoints, so we match program spaces, not |
| 6621 | address spaces. */ |
| 6622 | |
| 6623 | static void |
| 6624 | describe_other_breakpoints (struct gdbarch *gdbarch, |
| 6625 | struct program_space *pspace, CORE_ADDR pc, |
| 6626 | struct obj_section *section, int thread) |
| 6627 | { |
| 6628 | int others = 0; |
| 6629 | struct breakpoint *b; |
| 6630 | |
| 6631 | ALL_BREAKPOINTS (b) |
| 6632 | others += (user_breakpoint_p (b) |
| 6633 | && breakpoint_has_pc (b, pspace, pc, section)); |
| 6634 | if (others > 0) |
| 6635 | { |
| 6636 | if (others == 1) |
| 6637 | printf_filtered (_("Note: breakpoint ")); |
| 6638 | else /* if (others == ???) */ |
| 6639 | printf_filtered (_("Note: breakpoints ")); |
| 6640 | ALL_BREAKPOINTS (b) |
| 6641 | if (user_breakpoint_p (b) && breakpoint_has_pc (b, pspace, pc, section)) |
| 6642 | { |
| 6643 | others--; |
| 6644 | printf_filtered ("%d", b->number); |
| 6645 | if (b->thread == -1 && thread != -1) |
| 6646 | printf_filtered (" (all threads)"); |
| 6647 | else if (b->thread != -1) |
| 6648 | printf_filtered (" (thread %d)", b->thread); |
| 6649 | printf_filtered ("%s%s ", |
| 6650 | ((b->enable_state == bp_disabled |
| 6651 | || b->enable_state == bp_call_disabled) |
| 6652 | ? " (disabled)" |
| 6653 | : ""), |
| 6654 | (others > 1) ? "," |
| 6655 | : ((others == 1) ? " and" : "")); |
| 6656 | } |
| 6657 | current_uiout->message (_("also set at pc %ps.\n"), |
| 6658 | styled_string (address_style.style (), |
| 6659 | paddress (gdbarch, pc))); |
| 6660 | } |
| 6661 | } |
| 6662 | \f |
| 6663 | |
| 6664 | /* Return true iff it is meaningful to use the address member of LOC. |
| 6665 | For some breakpoint types, the locations' address members are |
| 6666 | irrelevant and it makes no sense to attempt to compare them to |
| 6667 | other addresses (or use them for any other purpose either). |
| 6668 | |
| 6669 | More specifically, software watchpoints and catchpoints that are |
| 6670 | not backed by breakpoints always have a zero valued location |
| 6671 | address and we don't want to mark breakpoints of any of these types |
| 6672 | to be a duplicate of an actual breakpoint location at address |
| 6673 | zero. */ |
| 6674 | |
| 6675 | static bool |
| 6676 | bl_address_is_meaningful (bp_location *loc) |
| 6677 | { |
| 6678 | return loc->loc_type != bp_loc_other; |
| 6679 | } |
| 6680 | |
| 6681 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns |
| 6682 | true if LOC1 and LOC2 represent the same watchpoint location. */ |
| 6683 | |
| 6684 | static int |
| 6685 | watchpoint_locations_match (struct bp_location *loc1, |
| 6686 | struct bp_location *loc2) |
| 6687 | { |
| 6688 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
| 6689 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; |
| 6690 | |
| 6691 | /* Both of them must exist. */ |
| 6692 | gdb_assert (w1 != NULL); |
| 6693 | gdb_assert (w2 != NULL); |
| 6694 | |
| 6695 | /* If the target can evaluate the condition expression in hardware, |
| 6696 | then we we need to insert both watchpoints even if they are at |
| 6697 | the same place. Otherwise the watchpoint will only trigger when |
| 6698 | the condition of whichever watchpoint was inserted evaluates to |
| 6699 | true, not giving a chance for GDB to check the condition of the |
| 6700 | other watchpoint. */ |
| 6701 | if ((w1->cond_exp |
| 6702 | && target_can_accel_watchpoint_condition (loc1->address, |
| 6703 | loc1->length, |
| 6704 | loc1->watchpoint_type, |
| 6705 | w1->cond_exp.get ())) |
| 6706 | || (w2->cond_exp |
| 6707 | && target_can_accel_watchpoint_condition (loc2->address, |
| 6708 | loc2->length, |
| 6709 | loc2->watchpoint_type, |
| 6710 | w2->cond_exp.get ()))) |
| 6711 | return 0; |
| 6712 | |
| 6713 | /* Note that this checks the owner's type, not the location's. In |
| 6714 | case the target does not support read watchpoints, but does |
| 6715 | support access watchpoints, we'll have bp_read_watchpoint |
| 6716 | watchpoints with hw_access locations. Those should be considered |
| 6717 | duplicates of hw_read locations. The hw_read locations will |
| 6718 | become hw_access locations later. */ |
| 6719 | return (loc1->owner->type == loc2->owner->type |
| 6720 | && loc1->pspace->aspace == loc2->pspace->aspace |
| 6721 | && loc1->address == loc2->address |
| 6722 | && loc1->length == loc2->length); |
| 6723 | } |
| 6724 | |
| 6725 | /* See breakpoint.h. */ |
| 6726 | |
| 6727 | int |
| 6728 | breakpoint_address_match (const address_space *aspace1, CORE_ADDR addr1, |
| 6729 | const address_space *aspace2, CORE_ADDR addr2) |
| 6730 | { |
| 6731 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6732 | || aspace1 == aspace2) |
| 6733 | && addr1 == addr2); |
| 6734 | } |
| 6735 | |
| 6736 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
| 6737 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 |
| 6738 | matches ASPACE2. On targets that have global breakpoints, the address |
| 6739 | space doesn't really matter. */ |
| 6740 | |
| 6741 | static int |
| 6742 | breakpoint_address_match_range (const address_space *aspace1, |
| 6743 | CORE_ADDR addr1, |
| 6744 | int len1, const address_space *aspace2, |
| 6745 | CORE_ADDR addr2) |
| 6746 | { |
| 6747 | return ((gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6748 | || aspace1 == aspace2) |
| 6749 | && addr2 >= addr1 && addr2 < addr1 + len1); |
| 6750 | } |
| 6751 | |
| 6752 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be |
| 6753 | a ranged breakpoint. In most targets, a match happens only if ASPACE |
| 6754 | matches the breakpoint's address space. On targets that have global |
| 6755 | breakpoints, the address space doesn't really matter. */ |
| 6756 | |
| 6757 | static int |
| 6758 | breakpoint_location_address_match (struct bp_location *bl, |
| 6759 | const address_space *aspace, |
| 6760 | CORE_ADDR addr) |
| 6761 | { |
| 6762 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 6763 | aspace, addr) |
| 6764 | || (bl->length |
| 6765 | && breakpoint_address_match_range (bl->pspace->aspace, |
| 6766 | bl->address, bl->length, |
| 6767 | aspace, addr))); |
| 6768 | } |
| 6769 | |
| 6770 | /* Returns true if the [ADDR,ADDR+LEN) range in ASPACE overlaps |
| 6771 | breakpoint BL. BL may be a ranged breakpoint. In most targets, a |
| 6772 | match happens only if ASPACE matches the breakpoint's address |
| 6773 | space. On targets that have global breakpoints, the address space |
| 6774 | doesn't really matter. */ |
| 6775 | |
| 6776 | static int |
| 6777 | breakpoint_location_address_range_overlap (struct bp_location *bl, |
| 6778 | const address_space *aspace, |
| 6779 | CORE_ADDR addr, int len) |
| 6780 | { |
| 6781 | if (gdbarch_has_global_breakpoints (target_gdbarch ()) |
| 6782 | || bl->pspace->aspace == aspace) |
| 6783 | { |
| 6784 | int bl_len = bl->length != 0 ? bl->length : 1; |
| 6785 | |
| 6786 | if (mem_ranges_overlap (addr, len, bl->address, bl_len)) |
| 6787 | return 1; |
| 6788 | } |
| 6789 | return 0; |
| 6790 | } |
| 6791 | |
| 6792 | /* If LOC1 and LOC2's owners are not tracepoints, returns false directly. |
| 6793 | Then, if LOC1 and LOC2 represent the same tracepoint location, returns |
| 6794 | true, otherwise returns false. */ |
| 6795 | |
| 6796 | static int |
| 6797 | tracepoint_locations_match (struct bp_location *loc1, |
| 6798 | struct bp_location *loc2) |
| 6799 | { |
| 6800 | if (is_tracepoint (loc1->owner) && is_tracepoint (loc2->owner)) |
| 6801 | /* Since tracepoint locations are never duplicated with others', tracepoint |
| 6802 | locations at the same address of different tracepoints are regarded as |
| 6803 | different locations. */ |
| 6804 | return (loc1->address == loc2->address && loc1->owner == loc2->owner); |
| 6805 | else |
| 6806 | return 0; |
| 6807 | } |
| 6808 | |
| 6809 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
| 6810 | (bl_address_is_meaningful), returns true if LOC1 and LOC2 represent |
| 6811 | the same location. */ |
| 6812 | |
| 6813 | static int |
| 6814 | breakpoint_locations_match (struct bp_location *loc1, |
| 6815 | struct bp_location *loc2) |
| 6816 | { |
| 6817 | int hw_point1, hw_point2; |
| 6818 | |
| 6819 | /* Both of them must not be in moribund_locations. */ |
| 6820 | gdb_assert (loc1->owner != NULL); |
| 6821 | gdb_assert (loc2->owner != NULL); |
| 6822 | |
| 6823 | hw_point1 = is_hardware_watchpoint (loc1->owner); |
| 6824 | hw_point2 = is_hardware_watchpoint (loc2->owner); |
| 6825 | |
| 6826 | if (hw_point1 != hw_point2) |
| 6827 | return 0; |
| 6828 | else if (hw_point1) |
| 6829 | return watchpoint_locations_match (loc1, loc2); |
| 6830 | else if (is_tracepoint (loc1->owner) || is_tracepoint (loc2->owner)) |
| 6831 | return tracepoint_locations_match (loc1, loc2); |
| 6832 | else |
| 6833 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
| 6834 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, |
| 6835 | loc2->pspace->aspace, loc2->address) |
| 6836 | && loc1->length == loc2->length); |
| 6837 | } |
| 6838 | |
| 6839 | static void |
| 6840 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, |
| 6841 | int bnum, int have_bnum) |
| 6842 | { |
| 6843 | /* The longest string possibly returned by hex_string_custom |
| 6844 | is 50 chars. These must be at least that big for safety. */ |
| 6845 | char astr1[64]; |
| 6846 | char astr2[64]; |
| 6847 | |
| 6848 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
| 6849 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); |
| 6850 | if (have_bnum) |
| 6851 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
| 6852 | bnum, astr1, astr2); |
| 6853 | else |
| 6854 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
| 6855 | } |
| 6856 | |
| 6857 | /* Adjust a breakpoint's address to account for architectural |
| 6858 | constraints on breakpoint placement. Return the adjusted address. |
| 6859 | Note: Very few targets require this kind of adjustment. For most |
| 6860 | targets, this function is simply the identity function. */ |
| 6861 | |
| 6862 | static CORE_ADDR |
| 6863 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
| 6864 | CORE_ADDR bpaddr, enum bptype bptype) |
| 6865 | { |
| 6866 | if (bptype == bp_watchpoint |
| 6867 | || bptype == bp_hardware_watchpoint |
| 6868 | || bptype == bp_read_watchpoint |
| 6869 | || bptype == bp_access_watchpoint |
| 6870 | || bptype == bp_catchpoint) |
| 6871 | { |
| 6872 | /* Watchpoints and the various bp_catch_* eventpoints should not |
| 6873 | have their addresses modified. */ |
| 6874 | return bpaddr; |
| 6875 | } |
| 6876 | else if (bptype == bp_single_step) |
| 6877 | { |
| 6878 | /* Single-step breakpoints should not have their addresses |
| 6879 | modified. If there's any architectural constrain that |
| 6880 | applies to this address, then it should have already been |
| 6881 | taken into account when the breakpoint was created in the |
| 6882 | first place. If we didn't do this, stepping through e.g., |
| 6883 | Thumb-2 IT blocks would break. */ |
| 6884 | return bpaddr; |
| 6885 | } |
| 6886 | else |
| 6887 | { |
| 6888 | CORE_ADDR adjusted_bpaddr = bpaddr; |
| 6889 | |
| 6890 | if (gdbarch_adjust_breakpoint_address_p (gdbarch)) |
| 6891 | { |
| 6892 | /* Some targets have architectural constraints on the placement |
| 6893 | of breakpoint instructions. Obtain the adjusted address. */ |
| 6894 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
| 6895 | } |
| 6896 | |
| 6897 | adjusted_bpaddr = address_significant (gdbarch, adjusted_bpaddr); |
| 6898 | |
| 6899 | /* An adjusted breakpoint address can significantly alter |
| 6900 | a user's expectations. Print a warning if an adjustment |
| 6901 | is required. */ |
| 6902 | if (adjusted_bpaddr != bpaddr) |
| 6903 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); |
| 6904 | |
| 6905 | return adjusted_bpaddr; |
| 6906 | } |
| 6907 | } |
| 6908 | |
| 6909 | static bp_loc_type |
| 6910 | bp_location_from_bp_type (bptype type) |
| 6911 | { |
| 6912 | switch (type) |
| 6913 | { |
| 6914 | case bp_breakpoint: |
| 6915 | case bp_single_step: |
| 6916 | case bp_until: |
| 6917 | case bp_finish: |
| 6918 | case bp_longjmp: |
| 6919 | case bp_longjmp_resume: |
| 6920 | case bp_longjmp_call_dummy: |
| 6921 | case bp_exception: |
| 6922 | case bp_exception_resume: |
| 6923 | case bp_step_resume: |
| 6924 | case bp_hp_step_resume: |
| 6925 | case bp_watchpoint_scope: |
| 6926 | case bp_call_dummy: |
| 6927 | case bp_std_terminate: |
| 6928 | case bp_shlib_event: |
| 6929 | case bp_thread_event: |
| 6930 | case bp_overlay_event: |
| 6931 | case bp_jit_event: |
| 6932 | case bp_longjmp_master: |
| 6933 | case bp_std_terminate_master: |
| 6934 | case bp_exception_master: |
| 6935 | case bp_gnu_ifunc_resolver: |
| 6936 | case bp_gnu_ifunc_resolver_return: |
| 6937 | case bp_dprintf: |
| 6938 | return bp_loc_software_breakpoint; |
| 6939 | case bp_hardware_breakpoint: |
| 6940 | return bp_loc_hardware_breakpoint; |
| 6941 | case bp_hardware_watchpoint: |
| 6942 | case bp_read_watchpoint: |
| 6943 | case bp_access_watchpoint: |
| 6944 | return bp_loc_hardware_watchpoint; |
| 6945 | case bp_watchpoint: |
| 6946 | case bp_catchpoint: |
| 6947 | case bp_tracepoint: |
| 6948 | case bp_fast_tracepoint: |
| 6949 | case bp_static_tracepoint: |
| 6950 | return bp_loc_other; |
| 6951 | default: |
| 6952 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
| 6953 | } |
| 6954 | } |
| 6955 | |
| 6956 | bp_location::bp_location (breakpoint *owner, bp_loc_type type) |
| 6957 | { |
| 6958 | this->owner = owner; |
| 6959 | this->cond_bytecode = NULL; |
| 6960 | this->shlib_disabled = 0; |
| 6961 | this->enabled = 1; |
| 6962 | |
| 6963 | this->loc_type = type; |
| 6964 | |
| 6965 | if (this->loc_type == bp_loc_software_breakpoint |
| 6966 | || this->loc_type == bp_loc_hardware_breakpoint) |
| 6967 | mark_breakpoint_location_modified (this); |
| 6968 | |
| 6969 | this->refc = 1; |
| 6970 | } |
| 6971 | |
| 6972 | bp_location::bp_location (breakpoint *owner) |
| 6973 | : bp_location::bp_location (owner, |
| 6974 | bp_location_from_bp_type (owner->type)) |
| 6975 | { |
| 6976 | } |
| 6977 | |
| 6978 | /* Allocate a struct bp_location. */ |
| 6979 | |
| 6980 | static struct bp_location * |
| 6981 | allocate_bp_location (struct breakpoint *bpt) |
| 6982 | { |
| 6983 | return bpt->ops->allocate_location (bpt); |
| 6984 | } |
| 6985 | |
| 6986 | static void |
| 6987 | free_bp_location (struct bp_location *loc) |
| 6988 | { |
| 6989 | delete loc; |
| 6990 | } |
| 6991 | |
| 6992 | /* Increment reference count. */ |
| 6993 | |
| 6994 | static void |
| 6995 | incref_bp_location (struct bp_location *bl) |
| 6996 | { |
| 6997 | ++bl->refc; |
| 6998 | } |
| 6999 | |
| 7000 | /* Decrement reference count. If the reference count reaches 0, |
| 7001 | destroy the bp_location. Sets *BLP to NULL. */ |
| 7002 | |
| 7003 | static void |
| 7004 | decref_bp_location (struct bp_location **blp) |
| 7005 | { |
| 7006 | gdb_assert ((*blp)->refc > 0); |
| 7007 | |
| 7008 | if (--(*blp)->refc == 0) |
| 7009 | free_bp_location (*blp); |
| 7010 | *blp = NULL; |
| 7011 | } |
| 7012 | |
| 7013 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
| 7014 | |
| 7015 | static breakpoint * |
| 7016 | add_to_breakpoint_chain (std::unique_ptr<breakpoint> &&b) |
| 7017 | { |
| 7018 | struct breakpoint *b1; |
| 7019 | struct breakpoint *result = b.get (); |
| 7020 | |
| 7021 | /* Add this breakpoint to the end of the chain so that a list of |
| 7022 | breakpoints will come out in order of increasing numbers. */ |
| 7023 | |
| 7024 | b1 = breakpoint_chain; |
| 7025 | if (b1 == 0) |
| 7026 | breakpoint_chain = b.release (); |
| 7027 | else |
| 7028 | { |
| 7029 | while (b1->next) |
| 7030 | b1 = b1->next; |
| 7031 | b1->next = b.release (); |
| 7032 | } |
| 7033 | |
| 7034 | return result; |
| 7035 | } |
| 7036 | |
| 7037 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ |
| 7038 | |
| 7039 | static void |
| 7040 | init_raw_breakpoint_without_location (struct breakpoint *b, |
| 7041 | struct gdbarch *gdbarch, |
| 7042 | enum bptype bptype, |
| 7043 | const struct breakpoint_ops *ops) |
| 7044 | { |
| 7045 | gdb_assert (ops != NULL); |
| 7046 | |
| 7047 | b->ops = ops; |
| 7048 | b->type = bptype; |
| 7049 | b->gdbarch = gdbarch; |
| 7050 | b->language = current_language->la_language; |
| 7051 | b->input_radix = input_radix; |
| 7052 | b->related_breakpoint = b; |
| 7053 | } |
| 7054 | |
| 7055 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
| 7056 | that has type BPTYPE and has no locations as yet. */ |
| 7057 | |
| 7058 | static struct breakpoint * |
| 7059 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
| 7060 | enum bptype bptype, |
| 7061 | const struct breakpoint_ops *ops) |
| 7062 | { |
| 7063 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
| 7064 | |
| 7065 | init_raw_breakpoint_without_location (b.get (), gdbarch, bptype, ops); |
| 7066 | return add_to_breakpoint_chain (std::move (b)); |
| 7067 | } |
| 7068 | |
| 7069 | /* Initialize loc->function_name. */ |
| 7070 | |
| 7071 | static void |
| 7072 | set_breakpoint_location_function (struct bp_location *loc) |
| 7073 | { |
| 7074 | gdb_assert (loc->owner != NULL); |
| 7075 | |
| 7076 | if (loc->owner->type == bp_breakpoint |
| 7077 | || loc->owner->type == bp_hardware_breakpoint |
| 7078 | || is_tracepoint (loc->owner)) |
| 7079 | { |
| 7080 | const char *function_name; |
| 7081 | |
| 7082 | if (loc->msymbol != NULL |
| 7083 | && (MSYMBOL_TYPE (loc->msymbol) == mst_text_gnu_ifunc |
| 7084 | || MSYMBOL_TYPE (loc->msymbol) == mst_data_gnu_ifunc)) |
| 7085 | { |
| 7086 | struct breakpoint *b = loc->owner; |
| 7087 | |
| 7088 | function_name = MSYMBOL_LINKAGE_NAME (loc->msymbol); |
| 7089 | |
| 7090 | if (b->type == bp_breakpoint && b->loc == loc |
| 7091 | && loc->next == NULL && b->related_breakpoint == b) |
| 7092 | { |
| 7093 | /* Create only the whole new breakpoint of this type but do not |
| 7094 | mess more complicated breakpoints with multiple locations. */ |
| 7095 | b->type = bp_gnu_ifunc_resolver; |
| 7096 | /* Remember the resolver's address for use by the return |
| 7097 | breakpoint. */ |
| 7098 | loc->related_address = loc->address; |
| 7099 | } |
| 7100 | } |
| 7101 | else |
| 7102 | find_pc_partial_function (loc->address, &function_name, NULL, NULL); |
| 7103 | |
| 7104 | if (function_name) |
| 7105 | loc->function_name = xstrdup (function_name); |
| 7106 | } |
| 7107 | } |
| 7108 | |
| 7109 | /* Attempt to determine architecture of location identified by SAL. */ |
| 7110 | struct gdbarch * |
| 7111 | get_sal_arch (struct symtab_and_line sal) |
| 7112 | { |
| 7113 | if (sal.section) |
| 7114 | return get_objfile_arch (sal.section->objfile); |
| 7115 | if (sal.symtab) |
| 7116 | return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab)); |
| 7117 | |
| 7118 | return NULL; |
| 7119 | } |
| 7120 | |
| 7121 | /* Low level routine for partially initializing a breakpoint of type |
| 7122 | BPTYPE. The newly created breakpoint's address, section, source |
| 7123 | file name, and line number are provided by SAL. |
| 7124 | |
| 7125 | It is expected that the caller will complete the initialization of |
| 7126 | the newly created breakpoint struct as well as output any status |
| 7127 | information regarding the creation of a new breakpoint. */ |
| 7128 | |
| 7129 | static void |
| 7130 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, |
| 7131 | struct symtab_and_line sal, enum bptype bptype, |
| 7132 | const struct breakpoint_ops *ops) |
| 7133 | { |
| 7134 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
| 7135 | |
| 7136 | add_location_to_breakpoint (b, &sal); |
| 7137 | |
| 7138 | if (bptype != bp_catchpoint) |
| 7139 | gdb_assert (sal.pspace != NULL); |
| 7140 | |
| 7141 | /* Store the program space that was used to set the breakpoint, |
| 7142 | except for ordinary breakpoints, which are independent of the |
| 7143 | program space. */ |
| 7144 | if (bptype != bp_breakpoint && bptype != bp_hardware_breakpoint) |
| 7145 | b->pspace = sal.pspace; |
| 7146 | } |
| 7147 | |
| 7148 | /* set_raw_breakpoint is a low level routine for allocating and |
| 7149 | partially initializing a breakpoint of type BPTYPE. The newly |
| 7150 | created breakpoint's address, section, source file name, and line |
| 7151 | number are provided by SAL. The newly created and partially |
| 7152 | initialized breakpoint is added to the breakpoint chain and |
| 7153 | is also returned as the value of this function. |
| 7154 | |
| 7155 | It is expected that the caller will complete the initialization of |
| 7156 | the newly created breakpoint struct as well as output any status |
| 7157 | information regarding the creation of a new breakpoint. In |
| 7158 | particular, set_raw_breakpoint does NOT set the breakpoint |
| 7159 | number! Care should be taken to not allow an error to occur |
| 7160 | prior to completing the initialization of the breakpoint. If this |
| 7161 | should happen, a bogus breakpoint will be left on the chain. */ |
| 7162 | |
| 7163 | struct breakpoint * |
| 7164 | set_raw_breakpoint (struct gdbarch *gdbarch, |
| 7165 | struct symtab_and_line sal, enum bptype bptype, |
| 7166 | const struct breakpoint_ops *ops) |
| 7167 | { |
| 7168 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (bptype); |
| 7169 | |
| 7170 | init_raw_breakpoint (b.get (), gdbarch, sal, bptype, ops); |
| 7171 | return add_to_breakpoint_chain (std::move (b)); |
| 7172 | } |
| 7173 | |
| 7174 | /* Call this routine when stepping and nexting to enable a breakpoint |
| 7175 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
| 7176 | initiated the operation. */ |
| 7177 | |
| 7178 | void |
| 7179 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
| 7180 | { |
| 7181 | struct breakpoint *b, *b_tmp; |
| 7182 | int thread = tp->global_num; |
| 7183 | |
| 7184 | /* To avoid having to rescan all objfile symbols at every step, |
| 7185 | we maintain a list of continually-inserted but always disabled |
| 7186 | longjmp "master" breakpoints. Here, we simply create momentary |
| 7187 | clones of those and enable them for the requested thread. */ |
| 7188 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7189 | if (b->pspace == current_program_space |
| 7190 | && (b->type == bp_longjmp_master |
| 7191 | || b->type == bp_exception_master)) |
| 7192 | { |
| 7193 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
| 7194 | struct breakpoint *clone; |
| 7195 | |
| 7196 | /* longjmp_breakpoint_ops ensures INITIATING_FRAME is cleared again |
| 7197 | after their removal. */ |
| 7198 | clone = momentary_breakpoint_from_master (b, type, |
| 7199 | &momentary_breakpoint_ops, 1); |
| 7200 | clone->thread = thread; |
| 7201 | } |
| 7202 | |
| 7203 | tp->initiating_frame = frame; |
| 7204 | } |
| 7205 | |
| 7206 | /* Delete all longjmp breakpoints from THREAD. */ |
| 7207 | void |
| 7208 | delete_longjmp_breakpoint (int thread) |
| 7209 | { |
| 7210 | struct breakpoint *b, *b_tmp; |
| 7211 | |
| 7212 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7213 | if (b->type == bp_longjmp || b->type == bp_exception) |
| 7214 | { |
| 7215 | if (b->thread == thread) |
| 7216 | delete_breakpoint (b); |
| 7217 | } |
| 7218 | } |
| 7219 | |
| 7220 | void |
| 7221 | delete_longjmp_breakpoint_at_next_stop (int thread) |
| 7222 | { |
| 7223 | struct breakpoint *b, *b_tmp; |
| 7224 | |
| 7225 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7226 | if (b->type == bp_longjmp || b->type == bp_exception) |
| 7227 | { |
| 7228 | if (b->thread == thread) |
| 7229 | b->disposition = disp_del_at_next_stop; |
| 7230 | } |
| 7231 | } |
| 7232 | |
| 7233 | /* Place breakpoints of type bp_longjmp_call_dummy to catch longjmp for |
| 7234 | INFERIOR_PTID thread. Chain them all by RELATED_BREAKPOINT and return |
| 7235 | pointer to any of them. Return NULL if this system cannot place longjmp |
| 7236 | breakpoints. */ |
| 7237 | |
| 7238 | struct breakpoint * |
| 7239 | set_longjmp_breakpoint_for_call_dummy (void) |
| 7240 | { |
| 7241 | struct breakpoint *b, *retval = NULL; |
| 7242 | |
| 7243 | ALL_BREAKPOINTS (b) |
| 7244 | if (b->pspace == current_program_space && b->type == bp_longjmp_master) |
| 7245 | { |
| 7246 | struct breakpoint *new_b; |
| 7247 | |
| 7248 | new_b = momentary_breakpoint_from_master (b, bp_longjmp_call_dummy, |
| 7249 | &momentary_breakpoint_ops, |
| 7250 | 1); |
| 7251 | new_b->thread = inferior_thread ()->global_num; |
| 7252 | |
| 7253 | /* Link NEW_B into the chain of RETVAL breakpoints. */ |
| 7254 | |
| 7255 | gdb_assert (new_b->related_breakpoint == new_b); |
| 7256 | if (retval == NULL) |
| 7257 | retval = new_b; |
| 7258 | new_b->related_breakpoint = retval; |
| 7259 | while (retval->related_breakpoint != new_b->related_breakpoint) |
| 7260 | retval = retval->related_breakpoint; |
| 7261 | retval->related_breakpoint = new_b; |
| 7262 | } |
| 7263 | |
| 7264 | return retval; |
| 7265 | } |
| 7266 | |
| 7267 | /* Verify all existing dummy frames and their associated breakpoints for |
| 7268 | TP. Remove those which can no longer be found in the current frame |
| 7269 | stack. |
| 7270 | |
| 7271 | You should call this function only at places where it is safe to currently |
| 7272 | unwind the whole stack. Failed stack unwind would discard live dummy |
| 7273 | frames. */ |
| 7274 | |
| 7275 | void |
| 7276 | check_longjmp_breakpoint_for_call_dummy (struct thread_info *tp) |
| 7277 | { |
| 7278 | struct breakpoint *b, *b_tmp; |
| 7279 | |
| 7280 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7281 | if (b->type == bp_longjmp_call_dummy && b->thread == tp->global_num) |
| 7282 | { |
| 7283 | struct breakpoint *dummy_b = b->related_breakpoint; |
| 7284 | |
| 7285 | while (dummy_b != b && dummy_b->type != bp_call_dummy) |
| 7286 | dummy_b = dummy_b->related_breakpoint; |
| 7287 | if (dummy_b->type != bp_call_dummy |
| 7288 | || frame_find_by_id (dummy_b->frame_id) != NULL) |
| 7289 | continue; |
| 7290 | |
| 7291 | dummy_frame_discard (dummy_b->frame_id, tp); |
| 7292 | |
| 7293 | while (b->related_breakpoint != b) |
| 7294 | { |
| 7295 | if (b_tmp == b->related_breakpoint) |
| 7296 | b_tmp = b->related_breakpoint->next; |
| 7297 | delete_breakpoint (b->related_breakpoint); |
| 7298 | } |
| 7299 | delete_breakpoint (b); |
| 7300 | } |
| 7301 | } |
| 7302 | |
| 7303 | void |
| 7304 | enable_overlay_breakpoints (void) |
| 7305 | { |
| 7306 | struct breakpoint *b; |
| 7307 | |
| 7308 | ALL_BREAKPOINTS (b) |
| 7309 | if (b->type == bp_overlay_event) |
| 7310 | { |
| 7311 | b->enable_state = bp_enabled; |
| 7312 | update_global_location_list (UGLL_MAY_INSERT); |
| 7313 | overlay_events_enabled = 1; |
| 7314 | } |
| 7315 | } |
| 7316 | |
| 7317 | void |
| 7318 | disable_overlay_breakpoints (void) |
| 7319 | { |
| 7320 | struct breakpoint *b; |
| 7321 | |
| 7322 | ALL_BREAKPOINTS (b) |
| 7323 | if (b->type == bp_overlay_event) |
| 7324 | { |
| 7325 | b->enable_state = bp_disabled; |
| 7326 | update_global_location_list (UGLL_DONT_INSERT); |
| 7327 | overlay_events_enabled = 0; |
| 7328 | } |
| 7329 | } |
| 7330 | |
| 7331 | /* Set an active std::terminate breakpoint for each std::terminate |
| 7332 | master breakpoint. */ |
| 7333 | void |
| 7334 | set_std_terminate_breakpoint (void) |
| 7335 | { |
| 7336 | struct breakpoint *b, *b_tmp; |
| 7337 | |
| 7338 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7339 | if (b->pspace == current_program_space |
| 7340 | && b->type == bp_std_terminate_master) |
| 7341 | { |
| 7342 | momentary_breakpoint_from_master (b, bp_std_terminate, |
| 7343 | &momentary_breakpoint_ops, 1); |
| 7344 | } |
| 7345 | } |
| 7346 | |
| 7347 | /* Delete all the std::terminate breakpoints. */ |
| 7348 | void |
| 7349 | delete_std_terminate_breakpoint (void) |
| 7350 | { |
| 7351 | struct breakpoint *b, *b_tmp; |
| 7352 | |
| 7353 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7354 | if (b->type == bp_std_terminate) |
| 7355 | delete_breakpoint (b); |
| 7356 | } |
| 7357 | |
| 7358 | struct breakpoint * |
| 7359 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7360 | { |
| 7361 | struct breakpoint *b; |
| 7362 | |
| 7363 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
| 7364 | &internal_breakpoint_ops); |
| 7365 | |
| 7366 | b->enable_state = bp_enabled; |
| 7367 | /* location has to be used or breakpoint_re_set will delete me. */ |
| 7368 | b->location = new_address_location (b->loc->address, NULL, 0); |
| 7369 | |
| 7370 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 7371 | |
| 7372 | return b; |
| 7373 | } |
| 7374 | |
| 7375 | struct lang_and_radix |
| 7376 | { |
| 7377 | enum language lang; |
| 7378 | int radix; |
| 7379 | }; |
| 7380 | |
| 7381 | /* Create a breakpoint for JIT code registration and unregistration. */ |
| 7382 | |
| 7383 | struct breakpoint * |
| 7384 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7385 | { |
| 7386 | return create_internal_breakpoint (gdbarch, address, bp_jit_event, |
| 7387 | &internal_breakpoint_ops); |
| 7388 | } |
| 7389 | |
| 7390 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
| 7391 | |
| 7392 | void |
| 7393 | remove_jit_event_breakpoints (void) |
| 7394 | { |
| 7395 | struct breakpoint *b, *b_tmp; |
| 7396 | |
| 7397 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7398 | if (b->type == bp_jit_event |
| 7399 | && b->loc->pspace == current_program_space) |
| 7400 | delete_breakpoint (b); |
| 7401 | } |
| 7402 | |
| 7403 | void |
| 7404 | remove_solib_event_breakpoints (void) |
| 7405 | { |
| 7406 | struct breakpoint *b, *b_tmp; |
| 7407 | |
| 7408 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7409 | if (b->type == bp_shlib_event |
| 7410 | && b->loc->pspace == current_program_space) |
| 7411 | delete_breakpoint (b); |
| 7412 | } |
| 7413 | |
| 7414 | /* See breakpoint.h. */ |
| 7415 | |
| 7416 | void |
| 7417 | remove_solib_event_breakpoints_at_next_stop (void) |
| 7418 | { |
| 7419 | struct breakpoint *b, *b_tmp; |
| 7420 | |
| 7421 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 7422 | if (b->type == bp_shlib_event |
| 7423 | && b->loc->pspace == current_program_space) |
| 7424 | b->disposition = disp_del_at_next_stop; |
| 7425 | } |
| 7426 | |
| 7427 | /* Helper for create_solib_event_breakpoint / |
| 7428 | create_and_insert_solib_event_breakpoint. Allows specifying which |
| 7429 | INSERT_MODE to pass through to update_global_location_list. */ |
| 7430 | |
| 7431 | static struct breakpoint * |
| 7432 | create_solib_event_breakpoint_1 (struct gdbarch *gdbarch, CORE_ADDR address, |
| 7433 | enum ugll_insert_mode insert_mode) |
| 7434 | { |
| 7435 | struct breakpoint *b; |
| 7436 | |
| 7437 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
| 7438 | &internal_breakpoint_ops); |
| 7439 | update_global_location_list_nothrow (insert_mode); |
| 7440 | return b; |
| 7441 | } |
| 7442 | |
| 7443 | struct breakpoint * |
| 7444 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7445 | { |
| 7446 | return create_solib_event_breakpoint_1 (gdbarch, address, UGLL_MAY_INSERT); |
| 7447 | } |
| 7448 | |
| 7449 | /* See breakpoint.h. */ |
| 7450 | |
| 7451 | struct breakpoint * |
| 7452 | create_and_insert_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
| 7453 | { |
| 7454 | struct breakpoint *b; |
| 7455 | |
| 7456 | /* Explicitly tell update_global_location_list to insert |
| 7457 | locations. */ |
| 7458 | b = create_solib_event_breakpoint_1 (gdbarch, address, UGLL_INSERT); |
| 7459 | if (!b->loc->inserted) |
| 7460 | { |
| 7461 | delete_breakpoint (b); |
| 7462 | return NULL; |
| 7463 | } |
| 7464 | return b; |
| 7465 | } |
| 7466 | |
| 7467 | /* Disable any breakpoints that are on code in shared libraries. Only |
| 7468 | apply to enabled breakpoints, disabled ones can just stay disabled. */ |
| 7469 | |
| 7470 | void |
| 7471 | disable_breakpoints_in_shlibs (void) |
| 7472 | { |
| 7473 | struct bp_location *loc, **locp_tmp; |
| 7474 | |
| 7475 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 7476 | { |
| 7477 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 7478 | struct breakpoint *b = loc->owner; |
| 7479 | |
| 7480 | /* We apply the check to all breakpoints, including disabled for |
| 7481 | those with loc->duplicate set. This is so that when breakpoint |
| 7482 | becomes enabled, or the duplicate is removed, gdb will try to |
| 7483 | insert all breakpoints. If we don't set shlib_disabled here, |
| 7484 | we'll try to insert those breakpoints and fail. */ |
| 7485 | if (((b->type == bp_breakpoint) |
| 7486 | || (b->type == bp_jit_event) |
| 7487 | || (b->type == bp_hardware_breakpoint) |
| 7488 | || (is_tracepoint (b))) |
| 7489 | && loc->pspace == current_program_space |
| 7490 | && !loc->shlib_disabled |
| 7491 | && solib_name_from_address (loc->pspace, loc->address) |
| 7492 | ) |
| 7493 | { |
| 7494 | loc->shlib_disabled = 1; |
| 7495 | } |
| 7496 | } |
| 7497 | } |
| 7498 | |
| 7499 | /* Disable any breakpoints and tracepoints that are in SOLIB upon |
| 7500 | notification of unloaded_shlib. Only apply to enabled breakpoints, |
| 7501 | disabled ones can just stay disabled. */ |
| 7502 | |
| 7503 | static void |
| 7504 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
| 7505 | { |
| 7506 | struct bp_location *loc, **locp_tmp; |
| 7507 | int disabled_shlib_breaks = 0; |
| 7508 | |
| 7509 | ALL_BP_LOCATIONS (loc, locp_tmp) |
| 7510 | { |
| 7511 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
| 7512 | struct breakpoint *b = loc->owner; |
| 7513 | |
| 7514 | if (solib->pspace == loc->pspace |
| 7515 | && !loc->shlib_disabled |
| 7516 | && (((b->type == bp_breakpoint |
| 7517 | || b->type == bp_jit_event |
| 7518 | || b->type == bp_hardware_breakpoint) |
| 7519 | && (loc->loc_type == bp_loc_hardware_breakpoint |
| 7520 | || loc->loc_type == bp_loc_software_breakpoint)) |
| 7521 | || is_tracepoint (b)) |
| 7522 | && solib_contains_address_p (solib, loc->address)) |
| 7523 | { |
| 7524 | loc->shlib_disabled = 1; |
| 7525 | /* At this point, we cannot rely on remove_breakpoint |
| 7526 | succeeding so we must mark the breakpoint as not inserted |
| 7527 | to prevent future errors occurring in remove_breakpoints. */ |
| 7528 | loc->inserted = 0; |
| 7529 | |
| 7530 | /* This may cause duplicate notifications for the same breakpoint. */ |
| 7531 | gdb::observers::breakpoint_modified.notify (b); |
| 7532 | |
| 7533 | if (!disabled_shlib_breaks) |
| 7534 | { |
| 7535 | target_terminal::ours_for_output (); |
| 7536 | warning (_("Temporarily disabling breakpoints " |
| 7537 | "for unloaded shared library \"%s\""), |
| 7538 | solib->so_name); |
| 7539 | } |
| 7540 | disabled_shlib_breaks = 1; |
| 7541 | } |
| 7542 | } |
| 7543 | } |
| 7544 | |
| 7545 | /* Disable any breakpoints and tracepoints in OBJFILE upon |
| 7546 | notification of free_objfile. Only apply to enabled breakpoints, |
| 7547 | disabled ones can just stay disabled. */ |
| 7548 | |
| 7549 | static void |
| 7550 | disable_breakpoints_in_freed_objfile (struct objfile *objfile) |
| 7551 | { |
| 7552 | struct breakpoint *b; |
| 7553 | |
| 7554 | if (objfile == NULL) |
| 7555 | return; |
| 7556 | |
| 7557 | /* OBJF_SHARED|OBJF_USERLOADED objfiles are dynamic modules manually |
| 7558 | managed by the user with add-symbol-file/remove-symbol-file. |
| 7559 | Similarly to how breakpoints in shared libraries are handled in |
| 7560 | response to "nosharedlibrary", mark breakpoints in such modules |
| 7561 | shlib_disabled so they end up uninserted on the next global |
| 7562 | location list update. Shared libraries not loaded by the user |
| 7563 | aren't handled here -- they're already handled in |
| 7564 | disable_breakpoints_in_unloaded_shlib, called by solib.c's |
| 7565 | solib_unloaded observer. We skip objfiles that are not |
| 7566 | OBJF_SHARED as those aren't considered dynamic objects (e.g. the |
| 7567 | main objfile). */ |
| 7568 | if ((objfile->flags & OBJF_SHARED) == 0 |
| 7569 | || (objfile->flags & OBJF_USERLOADED) == 0) |
| 7570 | return; |
| 7571 | |
| 7572 | ALL_BREAKPOINTS (b) |
| 7573 | { |
| 7574 | struct bp_location *loc; |
| 7575 | int bp_modified = 0; |
| 7576 | |
| 7577 | if (!is_breakpoint (b) && !is_tracepoint (b)) |
| 7578 | continue; |
| 7579 | |
| 7580 | for (loc = b->loc; loc != NULL; loc = loc->next) |
| 7581 | { |
| 7582 | CORE_ADDR loc_addr = loc->address; |
| 7583 | |
| 7584 | if (loc->loc_type != bp_loc_hardware_breakpoint |
| 7585 | && loc->loc_type != bp_loc_software_breakpoint) |
| 7586 | continue; |
| 7587 | |
| 7588 | if (loc->shlib_disabled != 0) |
| 7589 | continue; |
| 7590 | |
| 7591 | if (objfile->pspace != loc->pspace) |
| 7592 | continue; |
| 7593 | |
| 7594 | if (loc->loc_type != bp_loc_hardware_breakpoint |
| 7595 | && loc->loc_type != bp_loc_software_breakpoint) |
| 7596 | continue; |
| 7597 | |
| 7598 | if (is_addr_in_objfile (loc_addr, objfile)) |
| 7599 | { |
| 7600 | loc->shlib_disabled = 1; |
| 7601 | /* At this point, we don't know whether the object was |
| 7602 | unmapped from the inferior or not, so leave the |
| 7603 | inserted flag alone. We'll handle failure to |
| 7604 | uninsert quietly, in case the object was indeed |
| 7605 | unmapped. */ |
| 7606 | |
| 7607 | mark_breakpoint_location_modified (loc); |
| 7608 | |
| 7609 | bp_modified = 1; |
| 7610 | } |
| 7611 | } |
| 7612 | |
| 7613 | if (bp_modified) |
| 7614 | gdb::observers::breakpoint_modified.notify (b); |
| 7615 | } |
| 7616 | } |
| 7617 | |
| 7618 | /* FORK & VFORK catchpoints. */ |
| 7619 | |
| 7620 | /* An instance of this type is used to represent a fork or vfork |
| 7621 | catchpoint. A breakpoint is really of this type iff its ops pointer points |
| 7622 | to CATCH_FORK_BREAKPOINT_OPS. */ |
| 7623 | |
| 7624 | struct fork_catchpoint : public breakpoint |
| 7625 | { |
| 7626 | /* Process id of a child process whose forking triggered this |
| 7627 | catchpoint. This field is only valid immediately after this |
| 7628 | catchpoint has triggered. */ |
| 7629 | ptid_t forked_inferior_pid; |
| 7630 | }; |
| 7631 | |
| 7632 | /* Implement the "insert" breakpoint_ops method for fork |
| 7633 | catchpoints. */ |
| 7634 | |
| 7635 | static int |
| 7636 | insert_catch_fork (struct bp_location *bl) |
| 7637 | { |
| 7638 | return target_insert_fork_catchpoint (inferior_ptid.pid ()); |
| 7639 | } |
| 7640 | |
| 7641 | /* Implement the "remove" breakpoint_ops method for fork |
| 7642 | catchpoints. */ |
| 7643 | |
| 7644 | static int |
| 7645 | remove_catch_fork (struct bp_location *bl, enum remove_bp_reason reason) |
| 7646 | { |
| 7647 | return target_remove_fork_catchpoint (inferior_ptid.pid ()); |
| 7648 | } |
| 7649 | |
| 7650 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork |
| 7651 | catchpoints. */ |
| 7652 | |
| 7653 | static int |
| 7654 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
| 7655 | const address_space *aspace, CORE_ADDR bp_addr, |
| 7656 | const struct target_waitstatus *ws) |
| 7657 | { |
| 7658 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
| 7659 | |
| 7660 | if (ws->kind != TARGET_WAITKIND_FORKED) |
| 7661 | return 0; |
| 7662 | |
| 7663 | c->forked_inferior_pid = ws->value.related_pid; |
| 7664 | return 1; |
| 7665 | } |
| 7666 | |
| 7667 | /* Implement the "print_it" breakpoint_ops method for fork |
| 7668 | catchpoints. */ |
| 7669 | |
| 7670 | static enum print_stop_action |
| 7671 | print_it_catch_fork (bpstat bs) |
| 7672 | { |
| 7673 | struct ui_out *uiout = current_uiout; |
| 7674 | struct breakpoint *b = bs->breakpoint_at; |
| 7675 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; |
| 7676 | |
| 7677 | annotate_catchpoint (b->number); |
| 7678 | maybe_print_thread_hit_breakpoint (uiout); |
| 7679 | if (b->disposition == disp_del) |
| 7680 | uiout->text ("Temporary catchpoint "); |
| 7681 | else |
| 7682 | uiout->text ("Catchpoint "); |
| 7683 | if (uiout->is_mi_like_p ()) |
| 7684 | { |
| 7685 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_FORK)); |
| 7686 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 7687 | } |
| 7688 | uiout->field_signed ("bkptno", b->number); |
| 7689 | uiout->text (" (forked process "); |
| 7690 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
| 7691 | uiout->text ("), "); |
| 7692 | return PRINT_SRC_AND_LOC; |
| 7693 | } |
| 7694 | |
| 7695 | /* Implement the "print_one" breakpoint_ops method for fork |
| 7696 | catchpoints. */ |
| 7697 | |
| 7698 | static void |
| 7699 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
| 7700 | { |
| 7701 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 7702 | struct value_print_options opts; |
| 7703 | struct ui_out *uiout = current_uiout; |
| 7704 | |
| 7705 | get_user_print_options (&opts); |
| 7706 | |
| 7707 | /* Field 4, the address, is omitted (which makes the columns not |
| 7708 | line up too nicely with the headers, but the effect is relatively |
| 7709 | readable). */ |
| 7710 | if (opts.addressprint) |
| 7711 | uiout->field_skip ("addr"); |
| 7712 | annotate_field (5); |
| 7713 | uiout->text ("fork"); |
| 7714 | if (c->forked_inferior_pid != null_ptid) |
| 7715 | { |
| 7716 | uiout->text (", process "); |
| 7717 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
| 7718 | uiout->spaces (1); |
| 7719 | } |
| 7720 | |
| 7721 | if (uiout->is_mi_like_p ()) |
| 7722 | uiout->field_string ("catch-type", "fork"); |
| 7723 | } |
| 7724 | |
| 7725 | /* Implement the "print_mention" breakpoint_ops method for fork |
| 7726 | catchpoints. */ |
| 7727 | |
| 7728 | static void |
| 7729 | print_mention_catch_fork (struct breakpoint *b) |
| 7730 | { |
| 7731 | printf_filtered (_("Catchpoint %d (fork)"), b->number); |
| 7732 | } |
| 7733 | |
| 7734 | /* Implement the "print_recreate" breakpoint_ops method for fork |
| 7735 | catchpoints. */ |
| 7736 | |
| 7737 | static void |
| 7738 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) |
| 7739 | { |
| 7740 | fprintf_unfiltered (fp, "catch fork"); |
| 7741 | print_recreate_thread (b, fp); |
| 7742 | } |
| 7743 | |
| 7744 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
| 7745 | |
| 7746 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
| 7747 | |
| 7748 | /* Implement the "insert" breakpoint_ops method for vfork |
| 7749 | catchpoints. */ |
| 7750 | |
| 7751 | static int |
| 7752 | insert_catch_vfork (struct bp_location *bl) |
| 7753 | { |
| 7754 | return target_insert_vfork_catchpoint (inferior_ptid.pid ()); |
| 7755 | } |
| 7756 | |
| 7757 | /* Implement the "remove" breakpoint_ops method for vfork |
| 7758 | catchpoints. */ |
| 7759 | |
| 7760 | static int |
| 7761 | remove_catch_vfork (struct bp_location *bl, enum remove_bp_reason reason) |
| 7762 | { |
| 7763 | return target_remove_vfork_catchpoint (inferior_ptid.pid ()); |
| 7764 | } |
| 7765 | |
| 7766 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork |
| 7767 | catchpoints. */ |
| 7768 | |
| 7769 | static int |
| 7770 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
| 7771 | const address_space *aspace, CORE_ADDR bp_addr, |
| 7772 | const struct target_waitstatus *ws) |
| 7773 | { |
| 7774 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
| 7775 | |
| 7776 | if (ws->kind != TARGET_WAITKIND_VFORKED) |
| 7777 | return 0; |
| 7778 | |
| 7779 | c->forked_inferior_pid = ws->value.related_pid; |
| 7780 | return 1; |
| 7781 | } |
| 7782 | |
| 7783 | /* Implement the "print_it" breakpoint_ops method for vfork |
| 7784 | catchpoints. */ |
| 7785 | |
| 7786 | static enum print_stop_action |
| 7787 | print_it_catch_vfork (bpstat bs) |
| 7788 | { |
| 7789 | struct ui_out *uiout = current_uiout; |
| 7790 | struct breakpoint *b = bs->breakpoint_at; |
| 7791 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 7792 | |
| 7793 | annotate_catchpoint (b->number); |
| 7794 | maybe_print_thread_hit_breakpoint (uiout); |
| 7795 | if (b->disposition == disp_del) |
| 7796 | uiout->text ("Temporary catchpoint "); |
| 7797 | else |
| 7798 | uiout->text ("Catchpoint "); |
| 7799 | if (uiout->is_mi_like_p ()) |
| 7800 | { |
| 7801 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_VFORK)); |
| 7802 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 7803 | } |
| 7804 | uiout->field_signed ("bkptno", b->number); |
| 7805 | uiout->text (" (vforked process "); |
| 7806 | uiout->field_signed ("newpid", c->forked_inferior_pid.pid ()); |
| 7807 | uiout->text ("), "); |
| 7808 | return PRINT_SRC_AND_LOC; |
| 7809 | } |
| 7810 | |
| 7811 | /* Implement the "print_one" breakpoint_ops method for vfork |
| 7812 | catchpoints. */ |
| 7813 | |
| 7814 | static void |
| 7815 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
| 7816 | { |
| 7817 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
| 7818 | struct value_print_options opts; |
| 7819 | struct ui_out *uiout = current_uiout; |
| 7820 | |
| 7821 | get_user_print_options (&opts); |
| 7822 | /* Field 4, the address, is omitted (which makes the columns not |
| 7823 | line up too nicely with the headers, but the effect is relatively |
| 7824 | readable). */ |
| 7825 | if (opts.addressprint) |
| 7826 | uiout->field_skip ("addr"); |
| 7827 | annotate_field (5); |
| 7828 | uiout->text ("vfork"); |
| 7829 | if (c->forked_inferior_pid != null_ptid) |
| 7830 | { |
| 7831 | uiout->text (", process "); |
| 7832 | uiout->field_signed ("what", c->forked_inferior_pid.pid ()); |
| 7833 | uiout->spaces (1); |
| 7834 | } |
| 7835 | |
| 7836 | if (uiout->is_mi_like_p ()) |
| 7837 | uiout->field_string ("catch-type", "vfork"); |
| 7838 | } |
| 7839 | |
| 7840 | /* Implement the "print_mention" breakpoint_ops method for vfork |
| 7841 | catchpoints. */ |
| 7842 | |
| 7843 | static void |
| 7844 | print_mention_catch_vfork (struct breakpoint *b) |
| 7845 | { |
| 7846 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); |
| 7847 | } |
| 7848 | |
| 7849 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
| 7850 | catchpoints. */ |
| 7851 | |
| 7852 | static void |
| 7853 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) |
| 7854 | { |
| 7855 | fprintf_unfiltered (fp, "catch vfork"); |
| 7856 | print_recreate_thread (b, fp); |
| 7857 | } |
| 7858 | |
| 7859 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
| 7860 | |
| 7861 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
| 7862 | |
| 7863 | /* An instance of this type is used to represent an solib catchpoint. |
| 7864 | A breakpoint is really of this type iff its ops pointer points to |
| 7865 | CATCH_SOLIB_BREAKPOINT_OPS. */ |
| 7866 | |
| 7867 | struct solib_catchpoint : public breakpoint |
| 7868 | { |
| 7869 | ~solib_catchpoint () override; |
| 7870 | |
| 7871 | /* True for "catch load", false for "catch unload". */ |
| 7872 | unsigned char is_load; |
| 7873 | |
| 7874 | /* Regular expression to match, if any. COMPILED is only valid when |
| 7875 | REGEX is non-NULL. */ |
| 7876 | char *regex; |
| 7877 | std::unique_ptr<compiled_regex> compiled; |
| 7878 | }; |
| 7879 | |
| 7880 | solib_catchpoint::~solib_catchpoint () |
| 7881 | { |
| 7882 | xfree (this->regex); |
| 7883 | } |
| 7884 | |
| 7885 | static int |
| 7886 | insert_catch_solib (struct bp_location *ignore) |
| 7887 | { |
| 7888 | return 0; |
| 7889 | } |
| 7890 | |
| 7891 | static int |
| 7892 | remove_catch_solib (struct bp_location *ignore, enum remove_bp_reason reason) |
| 7893 | { |
| 7894 | return 0; |
| 7895 | } |
| 7896 | |
| 7897 | static int |
| 7898 | breakpoint_hit_catch_solib (const struct bp_location *bl, |
| 7899 | const address_space *aspace, |
| 7900 | CORE_ADDR bp_addr, |
| 7901 | const struct target_waitstatus *ws) |
| 7902 | { |
| 7903 | struct solib_catchpoint *self = (struct solib_catchpoint *) bl->owner; |
| 7904 | struct breakpoint *other; |
| 7905 | |
| 7906 | if (ws->kind == TARGET_WAITKIND_LOADED) |
| 7907 | return 1; |
| 7908 | |
| 7909 | ALL_BREAKPOINTS (other) |
| 7910 | { |
| 7911 | struct bp_location *other_bl; |
| 7912 | |
| 7913 | if (other == bl->owner) |
| 7914 | continue; |
| 7915 | |
| 7916 | if (other->type != bp_shlib_event) |
| 7917 | continue; |
| 7918 | |
| 7919 | if (self->pspace != NULL && other->pspace != self->pspace) |
| 7920 | continue; |
| 7921 | |
| 7922 | for (other_bl = other->loc; other_bl != NULL; other_bl = other_bl->next) |
| 7923 | { |
| 7924 | if (other->ops->breakpoint_hit (other_bl, aspace, bp_addr, ws)) |
| 7925 | return 1; |
| 7926 | } |
| 7927 | } |
| 7928 | |
| 7929 | return 0; |
| 7930 | } |
| 7931 | |
| 7932 | static void |
| 7933 | check_status_catch_solib (struct bpstats *bs) |
| 7934 | { |
| 7935 | struct solib_catchpoint *self |
| 7936 | = (struct solib_catchpoint *) bs->breakpoint_at; |
| 7937 | |
| 7938 | if (self->is_load) |
| 7939 | { |
| 7940 | for (so_list *iter : current_program_space->added_solibs) |
| 7941 | { |
| 7942 | if (!self->regex |
| 7943 | || self->compiled->exec (iter->so_name, 0, NULL, 0) == 0) |
| 7944 | return; |
| 7945 | } |
| 7946 | } |
| 7947 | else |
| 7948 | { |
| 7949 | for (const std::string &iter : current_program_space->deleted_solibs) |
| 7950 | { |
| 7951 | if (!self->regex |
| 7952 | || self->compiled->exec (iter.c_str (), 0, NULL, 0) == 0) |
| 7953 | return; |
| 7954 | } |
| 7955 | } |
| 7956 | |
| 7957 | bs->stop = 0; |
| 7958 | bs->print_it = print_it_noop; |
| 7959 | } |
| 7960 | |
| 7961 | static enum print_stop_action |
| 7962 | print_it_catch_solib (bpstat bs) |
| 7963 | { |
| 7964 | struct breakpoint *b = bs->breakpoint_at; |
| 7965 | struct ui_out *uiout = current_uiout; |
| 7966 | |
| 7967 | annotate_catchpoint (b->number); |
| 7968 | maybe_print_thread_hit_breakpoint (uiout); |
| 7969 | if (b->disposition == disp_del) |
| 7970 | uiout->text ("Temporary catchpoint "); |
| 7971 | else |
| 7972 | uiout->text ("Catchpoint "); |
| 7973 | uiout->field_signed ("bkptno", b->number); |
| 7974 | uiout->text ("\n"); |
| 7975 | if (uiout->is_mi_like_p ()) |
| 7976 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 7977 | print_solib_event (1); |
| 7978 | return PRINT_SRC_AND_LOC; |
| 7979 | } |
| 7980 | |
| 7981 | static void |
| 7982 | print_one_catch_solib (struct breakpoint *b, struct bp_location **locs) |
| 7983 | { |
| 7984 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 7985 | struct value_print_options opts; |
| 7986 | struct ui_out *uiout = current_uiout; |
| 7987 | |
| 7988 | get_user_print_options (&opts); |
| 7989 | /* Field 4, the address, is omitted (which makes the columns not |
| 7990 | line up too nicely with the headers, but the effect is relatively |
| 7991 | readable). */ |
| 7992 | if (opts.addressprint) |
| 7993 | { |
| 7994 | annotate_field (4); |
| 7995 | uiout->field_skip ("addr"); |
| 7996 | } |
| 7997 | |
| 7998 | std::string msg; |
| 7999 | annotate_field (5); |
| 8000 | if (self->is_load) |
| 8001 | { |
| 8002 | if (self->regex) |
| 8003 | msg = string_printf (_("load of library matching %s"), self->regex); |
| 8004 | else |
| 8005 | msg = _("load of library"); |
| 8006 | } |
| 8007 | else |
| 8008 | { |
| 8009 | if (self->regex) |
| 8010 | msg = string_printf (_("unload of library matching %s"), self->regex); |
| 8011 | else |
| 8012 | msg = _("unload of library"); |
| 8013 | } |
| 8014 | uiout->field_string ("what", msg); |
| 8015 | |
| 8016 | if (uiout->is_mi_like_p ()) |
| 8017 | uiout->field_string ("catch-type", self->is_load ? "load" : "unload"); |
| 8018 | } |
| 8019 | |
| 8020 | static void |
| 8021 | print_mention_catch_solib (struct breakpoint *b) |
| 8022 | { |
| 8023 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8024 | |
| 8025 | printf_filtered (_("Catchpoint %d (%s)"), b->number, |
| 8026 | self->is_load ? "load" : "unload"); |
| 8027 | } |
| 8028 | |
| 8029 | static void |
| 8030 | print_recreate_catch_solib (struct breakpoint *b, struct ui_file *fp) |
| 8031 | { |
| 8032 | struct solib_catchpoint *self = (struct solib_catchpoint *) b; |
| 8033 | |
| 8034 | fprintf_unfiltered (fp, "%s %s", |
| 8035 | b->disposition == disp_del ? "tcatch" : "catch", |
| 8036 | self->is_load ? "load" : "unload"); |
| 8037 | if (self->regex) |
| 8038 | fprintf_unfiltered (fp, " %s", self->regex); |
| 8039 | fprintf_unfiltered (fp, "\n"); |
| 8040 | } |
| 8041 | |
| 8042 | static struct breakpoint_ops catch_solib_breakpoint_ops; |
| 8043 | |
| 8044 | /* Shared helper function (MI and CLI) for creating and installing |
| 8045 | a shared object event catchpoint. If IS_LOAD is non-zero then |
| 8046 | the events to be caught are load events, otherwise they are |
| 8047 | unload events. If IS_TEMP is non-zero the catchpoint is a |
| 8048 | temporary one. If ENABLED is non-zero the catchpoint is |
| 8049 | created in an enabled state. */ |
| 8050 | |
| 8051 | void |
| 8052 | add_solib_catchpoint (const char *arg, int is_load, int is_temp, int enabled) |
| 8053 | { |
| 8054 | struct gdbarch *gdbarch = get_current_arch (); |
| 8055 | |
| 8056 | if (!arg) |
| 8057 | arg = ""; |
| 8058 | arg = skip_spaces (arg); |
| 8059 | |
| 8060 | std::unique_ptr<solib_catchpoint> c (new solib_catchpoint ()); |
| 8061 | |
| 8062 | if (*arg != '\0') |
| 8063 | { |
| 8064 | c->compiled.reset (new compiled_regex (arg, REG_NOSUB, |
| 8065 | _("Invalid regexp"))); |
| 8066 | c->regex = xstrdup (arg); |
| 8067 | } |
| 8068 | |
| 8069 | c->is_load = is_load; |
| 8070 | init_catchpoint (c.get (), gdbarch, is_temp, NULL, |
| 8071 | &catch_solib_breakpoint_ops); |
| 8072 | |
| 8073 | c->enable_state = enabled ? bp_enabled : bp_disabled; |
| 8074 | |
| 8075 | install_breakpoint (0, std::move (c), 1); |
| 8076 | } |
| 8077 | |
| 8078 | /* A helper function that does all the work for "catch load" and |
| 8079 | "catch unload". */ |
| 8080 | |
| 8081 | static void |
| 8082 | catch_load_or_unload (const char *arg, int from_tty, int is_load, |
| 8083 | struct cmd_list_element *command) |
| 8084 | { |
| 8085 | int tempflag; |
| 8086 | const int enabled = 1; |
| 8087 | |
| 8088 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 8089 | |
| 8090 | add_solib_catchpoint (arg, is_load, tempflag, enabled); |
| 8091 | } |
| 8092 | |
| 8093 | static void |
| 8094 | catch_load_command_1 (const char *arg, int from_tty, |
| 8095 | struct cmd_list_element *command) |
| 8096 | { |
| 8097 | catch_load_or_unload (arg, from_tty, 1, command); |
| 8098 | } |
| 8099 | |
| 8100 | static void |
| 8101 | catch_unload_command_1 (const char *arg, int from_tty, |
| 8102 | struct cmd_list_element *command) |
| 8103 | { |
| 8104 | catch_load_or_unload (arg, from_tty, 0, command); |
| 8105 | } |
| 8106 | |
| 8107 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
| 8108 | is non-zero, then make the breakpoint temporary. If COND_STRING is |
| 8109 | not NULL, then store it in the breakpoint. OPS, if not NULL, is |
| 8110 | the breakpoint_ops structure associated to the catchpoint. */ |
| 8111 | |
| 8112 | void |
| 8113 | init_catchpoint (struct breakpoint *b, |
| 8114 | struct gdbarch *gdbarch, int tempflag, |
| 8115 | const char *cond_string, |
| 8116 | const struct breakpoint_ops *ops) |
| 8117 | { |
| 8118 | symtab_and_line sal; |
| 8119 | sal.pspace = current_program_space; |
| 8120 | |
| 8121 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
| 8122 | |
| 8123 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
| 8124 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 8125 | } |
| 8126 | |
| 8127 | void |
| 8128 | install_breakpoint (int internal, std::unique_ptr<breakpoint> &&arg, int update_gll) |
| 8129 | { |
| 8130 | breakpoint *b = add_to_breakpoint_chain (std::move (arg)); |
| 8131 | set_breakpoint_number (internal, b); |
| 8132 | if (is_tracepoint (b)) |
| 8133 | set_tracepoint_count (breakpoint_count); |
| 8134 | if (!internal) |
| 8135 | mention (b); |
| 8136 | gdb::observers::breakpoint_created.notify (b); |
| 8137 | |
| 8138 | if (update_gll) |
| 8139 | update_global_location_list (UGLL_MAY_INSERT); |
| 8140 | } |
| 8141 | |
| 8142 | static void |
| 8143 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
| 8144 | int tempflag, const char *cond_string, |
| 8145 | const struct breakpoint_ops *ops) |
| 8146 | { |
| 8147 | std::unique_ptr<fork_catchpoint> c (new fork_catchpoint ()); |
| 8148 | |
| 8149 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, ops); |
| 8150 | |
| 8151 | c->forked_inferior_pid = null_ptid; |
| 8152 | |
| 8153 | install_breakpoint (0, std::move (c), 1); |
| 8154 | } |
| 8155 | |
| 8156 | /* Exec catchpoints. */ |
| 8157 | |
| 8158 | /* An instance of this type is used to represent an exec catchpoint. |
| 8159 | A breakpoint is really of this type iff its ops pointer points to |
| 8160 | CATCH_EXEC_BREAKPOINT_OPS. */ |
| 8161 | |
| 8162 | struct exec_catchpoint : public breakpoint |
| 8163 | { |
| 8164 | ~exec_catchpoint () override; |
| 8165 | |
| 8166 | /* Filename of a program whose exec triggered this catchpoint. |
| 8167 | This field is only valid immediately after this catchpoint has |
| 8168 | triggered. */ |
| 8169 | char *exec_pathname; |
| 8170 | }; |
| 8171 | |
| 8172 | /* Exec catchpoint destructor. */ |
| 8173 | |
| 8174 | exec_catchpoint::~exec_catchpoint () |
| 8175 | { |
| 8176 | xfree (this->exec_pathname); |
| 8177 | } |
| 8178 | |
| 8179 | static int |
| 8180 | insert_catch_exec (struct bp_location *bl) |
| 8181 | { |
| 8182 | return target_insert_exec_catchpoint (inferior_ptid.pid ()); |
| 8183 | } |
| 8184 | |
| 8185 | static int |
| 8186 | remove_catch_exec (struct bp_location *bl, enum remove_bp_reason reason) |
| 8187 | { |
| 8188 | return target_remove_exec_catchpoint (inferior_ptid.pid ()); |
| 8189 | } |
| 8190 | |
| 8191 | static int |
| 8192 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
| 8193 | const address_space *aspace, CORE_ADDR bp_addr, |
| 8194 | const struct target_waitstatus *ws) |
| 8195 | { |
| 8196 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
| 8197 | |
| 8198 | if (ws->kind != TARGET_WAITKIND_EXECD) |
| 8199 | return 0; |
| 8200 | |
| 8201 | c->exec_pathname = xstrdup (ws->value.execd_pathname); |
| 8202 | return 1; |
| 8203 | } |
| 8204 | |
| 8205 | static enum print_stop_action |
| 8206 | print_it_catch_exec (bpstat bs) |
| 8207 | { |
| 8208 | struct ui_out *uiout = current_uiout; |
| 8209 | struct breakpoint *b = bs->breakpoint_at; |
| 8210 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8211 | |
| 8212 | annotate_catchpoint (b->number); |
| 8213 | maybe_print_thread_hit_breakpoint (uiout); |
| 8214 | if (b->disposition == disp_del) |
| 8215 | uiout->text ("Temporary catchpoint "); |
| 8216 | else |
| 8217 | uiout->text ("Catchpoint "); |
| 8218 | if (uiout->is_mi_like_p ()) |
| 8219 | { |
| 8220 | uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXEC)); |
| 8221 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 8222 | } |
| 8223 | uiout->field_signed ("bkptno", b->number); |
| 8224 | uiout->text (" (exec'd "); |
| 8225 | uiout->field_string ("new-exec", c->exec_pathname); |
| 8226 | uiout->text ("), "); |
| 8227 | |
| 8228 | return PRINT_SRC_AND_LOC; |
| 8229 | } |
| 8230 | |
| 8231 | static void |
| 8232 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
| 8233 | { |
| 8234 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
| 8235 | struct value_print_options opts; |
| 8236 | struct ui_out *uiout = current_uiout; |
| 8237 | |
| 8238 | get_user_print_options (&opts); |
| 8239 | |
| 8240 | /* Field 4, the address, is omitted (which makes the columns |
| 8241 | not line up too nicely with the headers, but the effect |
| 8242 | is relatively readable). */ |
| 8243 | if (opts.addressprint) |
| 8244 | uiout->field_skip ("addr"); |
| 8245 | annotate_field (5); |
| 8246 | uiout->text ("exec"); |
| 8247 | if (c->exec_pathname != NULL) |
| 8248 | { |
| 8249 | uiout->text (", program \""); |
| 8250 | uiout->field_string ("what", c->exec_pathname); |
| 8251 | uiout->text ("\" "); |
| 8252 | } |
| 8253 | |
| 8254 | if (uiout->is_mi_like_p ()) |
| 8255 | uiout->field_string ("catch-type", "exec"); |
| 8256 | } |
| 8257 | |
| 8258 | static void |
| 8259 | print_mention_catch_exec (struct breakpoint *b) |
| 8260 | { |
| 8261 | printf_filtered (_("Catchpoint %d (exec)"), b->number); |
| 8262 | } |
| 8263 | |
| 8264 | /* Implement the "print_recreate" breakpoint_ops method for exec |
| 8265 | catchpoints. */ |
| 8266 | |
| 8267 | static void |
| 8268 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) |
| 8269 | { |
| 8270 | fprintf_unfiltered (fp, "catch exec"); |
| 8271 | print_recreate_thread (b, fp); |
| 8272 | } |
| 8273 | |
| 8274 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
| 8275 | |
| 8276 | static int |
| 8277 | hw_breakpoint_used_count (void) |
| 8278 | { |
| 8279 | int i = 0; |
| 8280 | struct breakpoint *b; |
| 8281 | struct bp_location *bl; |
| 8282 | |
| 8283 | ALL_BREAKPOINTS (b) |
| 8284 | { |
| 8285 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
| 8286 | for (bl = b->loc; bl; bl = bl->next) |
| 8287 | { |
| 8288 | /* Special types of hardware breakpoints may use more than |
| 8289 | one register. */ |
| 8290 | i += b->ops->resources_needed (bl); |
| 8291 | } |
| 8292 | } |
| 8293 | |
| 8294 | return i; |
| 8295 | } |
| 8296 | |
| 8297 | /* Returns the resources B would use if it were a hardware |
| 8298 | watchpoint. */ |
| 8299 | |
| 8300 | static int |
| 8301 | hw_watchpoint_use_count (struct breakpoint *b) |
| 8302 | { |
| 8303 | int i = 0; |
| 8304 | struct bp_location *bl; |
| 8305 | |
| 8306 | if (!breakpoint_enabled (b)) |
| 8307 | return 0; |
| 8308 | |
| 8309 | for (bl = b->loc; bl; bl = bl->next) |
| 8310 | { |
| 8311 | /* Special types of hardware watchpoints may use more than |
| 8312 | one register. */ |
| 8313 | i += b->ops->resources_needed (bl); |
| 8314 | } |
| 8315 | |
| 8316 | return i; |
| 8317 | } |
| 8318 | |
| 8319 | /* Returns the sum the used resources of all hardware watchpoints of |
| 8320 | type TYPE in the breakpoints list. Also returns in OTHER_TYPE_USED |
| 8321 | the sum of the used resources of all hardware watchpoints of other |
| 8322 | types _not_ TYPE. */ |
| 8323 | |
| 8324 | static int |
| 8325 | hw_watchpoint_used_count_others (struct breakpoint *except, |
| 8326 | enum bptype type, int *other_type_used) |
| 8327 | { |
| 8328 | int i = 0; |
| 8329 | struct breakpoint *b; |
| 8330 | |
| 8331 | *other_type_used = 0; |
| 8332 | ALL_BREAKPOINTS (b) |
| 8333 | { |
| 8334 | if (b == except) |
| 8335 | continue; |
| 8336 | if (!breakpoint_enabled (b)) |
| 8337 | continue; |
| 8338 | |
| 8339 | if (b->type == type) |
| 8340 | i += hw_watchpoint_use_count (b); |
| 8341 | else if (is_hardware_watchpoint (b)) |
| 8342 | *other_type_used = 1; |
| 8343 | } |
| 8344 | |
| 8345 | return i; |
| 8346 | } |
| 8347 | |
| 8348 | void |
| 8349 | disable_watchpoints_before_interactive_call_start (void) |
| 8350 | { |
| 8351 | struct breakpoint *b; |
| 8352 | |
| 8353 | ALL_BREAKPOINTS (b) |
| 8354 | { |
| 8355 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
| 8356 | { |
| 8357 | b->enable_state = bp_call_disabled; |
| 8358 | update_global_location_list (UGLL_DONT_INSERT); |
| 8359 | } |
| 8360 | } |
| 8361 | } |
| 8362 | |
| 8363 | void |
| 8364 | enable_watchpoints_after_interactive_call_stop (void) |
| 8365 | { |
| 8366 | struct breakpoint *b; |
| 8367 | |
| 8368 | ALL_BREAKPOINTS (b) |
| 8369 | { |
| 8370 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
| 8371 | { |
| 8372 | b->enable_state = bp_enabled; |
| 8373 | update_global_location_list (UGLL_MAY_INSERT); |
| 8374 | } |
| 8375 | } |
| 8376 | } |
| 8377 | |
| 8378 | void |
| 8379 | disable_breakpoints_before_startup (void) |
| 8380 | { |
| 8381 | current_program_space->executing_startup = 1; |
| 8382 | update_global_location_list (UGLL_DONT_INSERT); |
| 8383 | } |
| 8384 | |
| 8385 | void |
| 8386 | enable_breakpoints_after_startup (void) |
| 8387 | { |
| 8388 | current_program_space->executing_startup = 0; |
| 8389 | breakpoint_re_set (); |
| 8390 | } |
| 8391 | |
| 8392 | /* Create a new single-step breakpoint for thread THREAD, with no |
| 8393 | locations. */ |
| 8394 | |
| 8395 | static struct breakpoint * |
| 8396 | new_single_step_breakpoint (int thread, struct gdbarch *gdbarch) |
| 8397 | { |
| 8398 | std::unique_ptr<breakpoint> b (new breakpoint ()); |
| 8399 | |
| 8400 | init_raw_breakpoint_without_location (b.get (), gdbarch, bp_single_step, |
| 8401 | &momentary_breakpoint_ops); |
| 8402 | |
| 8403 | b->disposition = disp_donttouch; |
| 8404 | b->frame_id = null_frame_id; |
| 8405 | |
| 8406 | b->thread = thread; |
| 8407 | gdb_assert (b->thread != 0); |
| 8408 | |
| 8409 | return add_to_breakpoint_chain (std::move (b)); |
| 8410 | } |
| 8411 | |
| 8412 | /* Set a momentary breakpoint of type TYPE at address specified by |
| 8413 | SAL. If FRAME_ID is valid, the breakpoint is restricted to that |
| 8414 | frame. */ |
| 8415 | |
| 8416 | breakpoint_up |
| 8417 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
| 8418 | struct frame_id frame_id, enum bptype type) |
| 8419 | { |
| 8420 | struct breakpoint *b; |
| 8421 | |
| 8422 | /* If FRAME_ID is valid, it should be a real frame, not an inlined or |
| 8423 | tail-called one. */ |
| 8424 | gdb_assert (!frame_id_artificial_p (frame_id)); |
| 8425 | |
| 8426 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
| 8427 | b->enable_state = bp_enabled; |
| 8428 | b->disposition = disp_donttouch; |
| 8429 | b->frame_id = frame_id; |
| 8430 | |
| 8431 | b->thread = inferior_thread ()->global_num; |
| 8432 | |
| 8433 | update_global_location_list_nothrow (UGLL_MAY_INSERT); |
| 8434 | |
| 8435 | return breakpoint_up (b); |
| 8436 | } |
| 8437 | |
| 8438 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
| 8439 | The new breakpoint will have type TYPE, use OPS as its |
| 8440 | breakpoint_ops, and will set enabled to LOC_ENABLED. */ |
| 8441 | |
| 8442 | static struct breakpoint * |
| 8443 | momentary_breakpoint_from_master (struct breakpoint *orig, |
| 8444 | enum bptype type, |
| 8445 | const struct breakpoint_ops *ops, |
| 8446 | int loc_enabled) |
| 8447 | { |
| 8448 | struct breakpoint *copy; |
| 8449 | |
| 8450 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
| 8451 | copy->loc = allocate_bp_location (copy); |
| 8452 | set_breakpoint_location_function (copy->loc); |
| 8453 | |
| 8454 | copy->loc->gdbarch = orig->loc->gdbarch; |
| 8455 | copy->loc->requested_address = orig->loc->requested_address; |
| 8456 | copy->loc->address = orig->loc->address; |
| 8457 | copy->loc->section = orig->loc->section; |
| 8458 | copy->loc->pspace = orig->loc->pspace; |
| 8459 | copy->loc->probe = orig->loc->probe; |
| 8460 | copy->loc->line_number = orig->loc->line_number; |
| 8461 | copy->loc->symtab = orig->loc->symtab; |
| 8462 | copy->loc->enabled = loc_enabled; |
| 8463 | copy->frame_id = orig->frame_id; |
| 8464 | copy->thread = orig->thread; |
| 8465 | copy->pspace = orig->pspace; |
| 8466 | |
| 8467 | copy->enable_state = bp_enabled; |
| 8468 | copy->disposition = disp_donttouch; |
| 8469 | copy->number = internal_breakpoint_number--; |
| 8470 | |
| 8471 | update_global_location_list_nothrow (UGLL_DONT_INSERT); |
| 8472 | return copy; |
| 8473 | } |
| 8474 | |
| 8475 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
| 8476 | ORIG is NULL. */ |
| 8477 | |
| 8478 | struct breakpoint * |
| 8479 | clone_momentary_breakpoint (struct breakpoint *orig) |
| 8480 | { |
| 8481 | /* If there's nothing to clone, then return nothing. */ |
| 8482 | if (orig == NULL) |
| 8483 | return NULL; |
| 8484 | |
| 8485 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops, 0); |
| 8486 | } |
| 8487 | |
| 8488 | breakpoint_up |
| 8489 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
| 8490 | enum bptype type) |
| 8491 | { |
| 8492 | struct symtab_and_line sal; |
| 8493 | |
| 8494 | sal = find_pc_line (pc, 0); |
| 8495 | sal.pc = pc; |
| 8496 | sal.section = find_pc_overlay (pc); |
| 8497 | sal.explicit_pc = 1; |
| 8498 | |
| 8499 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
| 8500 | } |
| 8501 | \f |
| 8502 | |
| 8503 | /* Tell the user we have just set a breakpoint B. */ |
| 8504 | |
| 8505 | static void |
| 8506 | mention (struct breakpoint *b) |
| 8507 | { |
| 8508 | b->ops->print_mention (b); |
| 8509 | current_uiout->text ("\n"); |
| 8510 | } |
| 8511 | \f |
| 8512 | |
| 8513 | static int bp_loc_is_permanent (struct bp_location *loc); |
| 8514 | |
| 8515 | static struct bp_location * |
| 8516 | add_location_to_breakpoint (struct breakpoint *b, |
| 8517 | const struct symtab_and_line *sal) |
| 8518 | { |
| 8519 | struct bp_location *loc, **tmp; |
| 8520 | CORE_ADDR adjusted_address; |
| 8521 | struct gdbarch *loc_gdbarch = get_sal_arch (*sal); |
| 8522 | |
| 8523 | if (loc_gdbarch == NULL) |
| 8524 | loc_gdbarch = b->gdbarch; |
| 8525 | |
| 8526 | /* Adjust the breakpoint's address prior to allocating a location. |
| 8527 | Once we call allocate_bp_location(), that mostly uninitialized |
| 8528 | location will be placed on the location chain. Adjustment of the |
| 8529 | breakpoint may cause target_read_memory() to be called and we do |
| 8530 | not want its scan of the location chain to find a breakpoint and |
| 8531 | location that's only been partially initialized. */ |
| 8532 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
| 8533 | sal->pc, b->type); |
| 8534 | |
| 8535 | /* Sort the locations by their ADDRESS. */ |
| 8536 | loc = allocate_bp_location (b); |
| 8537 | for (tmp = &(b->loc); *tmp != NULL && (*tmp)->address <= adjusted_address; |
| 8538 | tmp = &((*tmp)->next)) |
| 8539 | ; |
| 8540 | loc->next = *tmp; |
| 8541 | *tmp = loc; |
| 8542 | |
| 8543 | loc->requested_address = sal->pc; |
| 8544 | loc->address = adjusted_address; |
| 8545 | loc->pspace = sal->pspace; |
| 8546 | loc->probe.prob = sal->prob; |
| 8547 | loc->probe.objfile = sal->objfile; |
| 8548 | gdb_assert (loc->pspace != NULL); |
| 8549 | loc->section = sal->section; |
| 8550 | loc->gdbarch = loc_gdbarch; |
| 8551 | loc->line_number = sal->line; |
| 8552 | loc->symtab = sal->symtab; |
| 8553 | loc->symbol = sal->symbol; |
| 8554 | loc->msymbol = sal->msymbol; |
| 8555 | loc->objfile = sal->objfile; |
| 8556 | |
| 8557 | set_breakpoint_location_function (loc); |
| 8558 | |
| 8559 | /* While by definition, permanent breakpoints are already present in the |
| 8560 | code, we don't mark the location as inserted. Normally one would expect |
| 8561 | that GDB could rely on that breakpoint instruction to stop the program, |
| 8562 | thus removing the need to insert its own breakpoint, except that executing |
| 8563 | the breakpoint instruction can kill the target instead of reporting a |
| 8564 | SIGTRAP. E.g., on SPARC, when interrupts are disabled, executing the |
| 8565 | instruction resets the CPU, so QEMU 2.0.0 for SPARC correspondingly dies |
| 8566 | with "Trap 0x02 while interrupts disabled, Error state". Letting the |
| 8567 | breakpoint be inserted normally results in QEMU knowing about the GDB |
| 8568 | breakpoint, and thus trap before the breakpoint instruction is executed. |
| 8569 | (If GDB later needs to continue execution past the permanent breakpoint, |
| 8570 | it manually increments the PC, thus avoiding executing the breakpoint |
| 8571 | instruction.) */ |
| 8572 | if (bp_loc_is_permanent (loc)) |
| 8573 | loc->permanent = 1; |
| 8574 | |
| 8575 | return loc; |
| 8576 | } |
| 8577 | \f |
| 8578 | |
| 8579 | /* See breakpoint.h. */ |
| 8580 | |
| 8581 | int |
| 8582 | program_breakpoint_here_p (struct gdbarch *gdbarch, CORE_ADDR address) |
| 8583 | { |
| 8584 | int len; |
| 8585 | CORE_ADDR addr; |
| 8586 | const gdb_byte *bpoint; |
| 8587 | gdb_byte *target_mem; |
| 8588 | |
| 8589 | addr = address; |
| 8590 | bpoint = gdbarch_breakpoint_from_pc (gdbarch, &addr, &len); |
| 8591 | |
| 8592 | /* Software breakpoints unsupported? */ |
| 8593 | if (bpoint == NULL) |
| 8594 | return 0; |
| 8595 | |
| 8596 | target_mem = (gdb_byte *) alloca (len); |
| 8597 | |
| 8598 | /* Enable the automatic memory restoration from breakpoints while |
| 8599 | we read the memory. Otherwise we could say about our temporary |
| 8600 | breakpoints they are permanent. */ |
| 8601 | scoped_restore restore_memory |
| 8602 | = make_scoped_restore_show_memory_breakpoints (0); |
| 8603 | |
| 8604 | if (target_read_memory (address, target_mem, len) == 0 |
| 8605 | && memcmp (target_mem, bpoint, len) == 0) |
| 8606 | return 1; |
| 8607 | |
| 8608 | return 0; |
| 8609 | } |
| 8610 | |
| 8611 | /* Return 1 if LOC is pointing to a permanent breakpoint, |
| 8612 | return 0 otherwise. */ |
| 8613 | |
| 8614 | static int |
| 8615 | bp_loc_is_permanent (struct bp_location *loc) |
| 8616 | { |
| 8617 | gdb_assert (loc != NULL); |
| 8618 | |
| 8619 | /* If we have a non-breakpoint-backed catchpoint or a software |
| 8620 | watchpoint, just return 0. We should not attempt to read from |
| 8621 | the addresses the locations of these breakpoint types point to. |
| 8622 | program_breakpoint_here_p, below, will attempt to read |
| 8623 | memory. */ |
| 8624 | if (!bl_address_is_meaningful (loc)) |
| 8625 | return 0; |
| 8626 | |
| 8627 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 8628 | switch_to_program_space_and_thread (loc->pspace); |
| 8629 | return program_breakpoint_here_p (loc->gdbarch, loc->address); |
| 8630 | } |
| 8631 | |
| 8632 | /* Build a command list for the dprintf corresponding to the current |
| 8633 | settings of the dprintf style options. */ |
| 8634 | |
| 8635 | static void |
| 8636 | update_dprintf_command_list (struct breakpoint *b) |
| 8637 | { |
| 8638 | char *dprintf_args = b->extra_string; |
| 8639 | char *printf_line = NULL; |
| 8640 | |
| 8641 | if (!dprintf_args) |
| 8642 | return; |
| 8643 | |
| 8644 | dprintf_args = skip_spaces (dprintf_args); |
| 8645 | |
| 8646 | /* Allow a comma, as it may have terminated a location, but don't |
| 8647 | insist on it. */ |
| 8648 | if (*dprintf_args == ',') |
| 8649 | ++dprintf_args; |
| 8650 | dprintf_args = skip_spaces (dprintf_args); |
| 8651 | |
| 8652 | if (*dprintf_args != '"') |
| 8653 | error (_("Bad format string, missing '\"'.")); |
| 8654 | |
| 8655 | if (strcmp (dprintf_style, dprintf_style_gdb) == 0) |
| 8656 | printf_line = xstrprintf ("printf %s", dprintf_args); |
| 8657 | else if (strcmp (dprintf_style, dprintf_style_call) == 0) |
| 8658 | { |
| 8659 | if (!dprintf_function) |
| 8660 | error (_("No function supplied for dprintf call")); |
| 8661 | |
| 8662 | if (dprintf_channel && strlen (dprintf_channel) > 0) |
| 8663 | printf_line = xstrprintf ("call (void) %s (%s,%s)", |
| 8664 | dprintf_function, |
| 8665 | dprintf_channel, |
| 8666 | dprintf_args); |
| 8667 | else |
| 8668 | printf_line = xstrprintf ("call (void) %s (%s)", |
| 8669 | dprintf_function, |
| 8670 | dprintf_args); |
| 8671 | } |
| 8672 | else if (strcmp (dprintf_style, dprintf_style_agent) == 0) |
| 8673 | { |
| 8674 | if (target_can_run_breakpoint_commands ()) |
| 8675 | printf_line = xstrprintf ("agent-printf %s", dprintf_args); |
| 8676 | else |
| 8677 | { |
| 8678 | warning (_("Target cannot run dprintf commands, falling back to GDB printf")); |
| 8679 | printf_line = xstrprintf ("printf %s", dprintf_args); |
| 8680 | } |
| 8681 | } |
| 8682 | else |
| 8683 | internal_error (__FILE__, __LINE__, |
| 8684 | _("Invalid dprintf style.")); |
| 8685 | |
| 8686 | gdb_assert (printf_line != NULL); |
| 8687 | |
| 8688 | /* Manufacture a printf sequence. */ |
| 8689 | struct command_line *printf_cmd_line |
| 8690 | = new struct command_line (simple_control, printf_line); |
| 8691 | breakpoint_set_commands (b, counted_command_line (printf_cmd_line, |
| 8692 | command_lines_deleter ())); |
| 8693 | } |
| 8694 | |
| 8695 | /* Update all dprintf commands, making their command lists reflect |
| 8696 | current style settings. */ |
| 8697 | |
| 8698 | static void |
| 8699 | update_dprintf_commands (const char *args, int from_tty, |
| 8700 | struct cmd_list_element *c) |
| 8701 | { |
| 8702 | struct breakpoint *b; |
| 8703 | |
| 8704 | ALL_BREAKPOINTS (b) |
| 8705 | { |
| 8706 | if (b->type == bp_dprintf) |
| 8707 | update_dprintf_command_list (b); |
| 8708 | } |
| 8709 | } |
| 8710 | |
| 8711 | /* Create a breakpoint with SAL as location. Use LOCATION |
| 8712 | as a description of the location, and COND_STRING |
| 8713 | as condition expression. If LOCATION is NULL then create an |
| 8714 | "address location" from the address in the SAL. */ |
| 8715 | |
| 8716 | static void |
| 8717 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
| 8718 | gdb::array_view<const symtab_and_line> sals, |
| 8719 | event_location_up &&location, |
| 8720 | gdb::unique_xmalloc_ptr<char> filter, |
| 8721 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 8722 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 8723 | enum bptype type, enum bpdisp disposition, |
| 8724 | int thread, int task, int ignore_count, |
| 8725 | const struct breakpoint_ops *ops, int from_tty, |
| 8726 | int enabled, int internal, unsigned flags, |
| 8727 | int display_canonical) |
| 8728 | { |
| 8729 | int i; |
| 8730 | |
| 8731 | if (type == bp_hardware_breakpoint) |
| 8732 | { |
| 8733 | int target_resources_ok; |
| 8734 | |
| 8735 | i = hw_breakpoint_used_count (); |
| 8736 | target_resources_ok = |
| 8737 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 8738 | i + 1, 0); |
| 8739 | if (target_resources_ok == 0) |
| 8740 | error (_("No hardware breakpoint support in the target.")); |
| 8741 | else if (target_resources_ok < 0) |
| 8742 | error (_("Hardware breakpoints used exceeds limit.")); |
| 8743 | } |
| 8744 | |
| 8745 | gdb_assert (!sals.empty ()); |
| 8746 | |
| 8747 | for (const auto &sal : sals) |
| 8748 | { |
| 8749 | struct bp_location *loc; |
| 8750 | |
| 8751 | if (from_tty) |
| 8752 | { |
| 8753 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 8754 | if (!loc_gdbarch) |
| 8755 | loc_gdbarch = gdbarch; |
| 8756 | |
| 8757 | describe_other_breakpoints (loc_gdbarch, |
| 8758 | sal.pspace, sal.pc, sal.section, thread); |
| 8759 | } |
| 8760 | |
| 8761 | if (&sal == &sals[0]) |
| 8762 | { |
| 8763 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
| 8764 | b->thread = thread; |
| 8765 | b->task = task; |
| 8766 | |
| 8767 | b->cond_string = cond_string.release (); |
| 8768 | b->extra_string = extra_string.release (); |
| 8769 | b->ignore_count = ignore_count; |
| 8770 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 8771 | b->disposition = disposition; |
| 8772 | |
| 8773 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
| 8774 | b->loc->inserted = 1; |
| 8775 | |
| 8776 | if (type == bp_static_tracepoint) |
| 8777 | { |
| 8778 | struct tracepoint *t = (struct tracepoint *) b; |
| 8779 | struct static_tracepoint_marker marker; |
| 8780 | |
| 8781 | if (strace_marker_p (b)) |
| 8782 | { |
| 8783 | /* We already know the marker exists, otherwise, we |
| 8784 | wouldn't see a sal for it. */ |
| 8785 | const char *p |
| 8786 | = &event_location_to_string (b->location.get ())[3]; |
| 8787 | const char *endp; |
| 8788 | |
| 8789 | p = skip_spaces (p); |
| 8790 | |
| 8791 | endp = skip_to_space (p); |
| 8792 | |
| 8793 | t->static_trace_marker_id.assign (p, endp - p); |
| 8794 | |
| 8795 | printf_filtered (_("Probed static tracepoint " |
| 8796 | "marker \"%s\"\n"), |
| 8797 | t->static_trace_marker_id.c_str ()); |
| 8798 | } |
| 8799 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) |
| 8800 | { |
| 8801 | t->static_trace_marker_id = std::move (marker.str_id); |
| 8802 | |
| 8803 | printf_filtered (_("Probed static tracepoint " |
| 8804 | "marker \"%s\"\n"), |
| 8805 | t->static_trace_marker_id.c_str ()); |
| 8806 | } |
| 8807 | else |
| 8808 | warning (_("Couldn't determine the static " |
| 8809 | "tracepoint marker to probe")); |
| 8810 | } |
| 8811 | |
| 8812 | loc = b->loc; |
| 8813 | } |
| 8814 | else |
| 8815 | { |
| 8816 | loc = add_location_to_breakpoint (b, &sal); |
| 8817 | if ((flags & CREATE_BREAKPOINT_FLAGS_INSERTED) != 0) |
| 8818 | loc->inserted = 1; |
| 8819 | } |
| 8820 | |
| 8821 | if (b->cond_string) |
| 8822 | { |
| 8823 | const char *arg = b->cond_string; |
| 8824 | |
| 8825 | loc->cond = parse_exp_1 (&arg, loc->address, |
| 8826 | block_for_pc (loc->address), 0); |
| 8827 | if (*arg) |
| 8828 | error (_("Garbage '%s' follows condition"), arg); |
| 8829 | } |
| 8830 | |
| 8831 | /* Dynamic printf requires and uses additional arguments on the |
| 8832 | command line, otherwise it's an error. */ |
| 8833 | if (type == bp_dprintf) |
| 8834 | { |
| 8835 | if (b->extra_string) |
| 8836 | update_dprintf_command_list (b); |
| 8837 | else |
| 8838 | error (_("Format string required")); |
| 8839 | } |
| 8840 | else if (b->extra_string) |
| 8841 | error (_("Garbage '%s' at end of command"), b->extra_string); |
| 8842 | } |
| 8843 | |
| 8844 | b->display_canonical = display_canonical; |
| 8845 | if (location != NULL) |
| 8846 | b->location = std::move (location); |
| 8847 | else |
| 8848 | b->location = new_address_location (b->loc->address, NULL, 0); |
| 8849 | b->filter = std::move (filter); |
| 8850 | } |
| 8851 | |
| 8852 | static void |
| 8853 | create_breakpoint_sal (struct gdbarch *gdbarch, |
| 8854 | gdb::array_view<const symtab_and_line> sals, |
| 8855 | event_location_up &&location, |
| 8856 | gdb::unique_xmalloc_ptr<char> filter, |
| 8857 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 8858 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 8859 | enum bptype type, enum bpdisp disposition, |
| 8860 | int thread, int task, int ignore_count, |
| 8861 | const struct breakpoint_ops *ops, int from_tty, |
| 8862 | int enabled, int internal, unsigned flags, |
| 8863 | int display_canonical) |
| 8864 | { |
| 8865 | std::unique_ptr<breakpoint> b = new_breakpoint_from_type (type); |
| 8866 | |
| 8867 | init_breakpoint_sal (b.get (), gdbarch, |
| 8868 | sals, std::move (location), |
| 8869 | std::move (filter), |
| 8870 | std::move (cond_string), |
| 8871 | std::move (extra_string), |
| 8872 | type, disposition, |
| 8873 | thread, task, ignore_count, |
| 8874 | ops, from_tty, |
| 8875 | enabled, internal, flags, |
| 8876 | display_canonical); |
| 8877 | |
| 8878 | install_breakpoint (internal, std::move (b), 0); |
| 8879 | } |
| 8880 | |
| 8881 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
| 8882 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] |
| 8883 | value. COND_STRING, if not NULL, specified the condition to be |
| 8884 | used for all breakpoints. Essentially the only case where |
| 8885 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded |
| 8886 | function. In that case, it's still not possible to specify |
| 8887 | separate conditions for different overloaded functions, so |
| 8888 | we take just a single condition string. |
| 8889 | |
| 8890 | NOTE: If the function succeeds, the caller is expected to cleanup |
| 8891 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
| 8892 | array contents). If the function fails (error() is called), the |
| 8893 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, |
| 8894 | COND and SALS arrays and each of those arrays contents. */ |
| 8895 | |
| 8896 | static void |
| 8897 | create_breakpoints_sal (struct gdbarch *gdbarch, |
| 8898 | struct linespec_result *canonical, |
| 8899 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 8900 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 8901 | enum bptype type, enum bpdisp disposition, |
| 8902 | int thread, int task, int ignore_count, |
| 8903 | const struct breakpoint_ops *ops, int from_tty, |
| 8904 | int enabled, int internal, unsigned flags) |
| 8905 | { |
| 8906 | if (canonical->pre_expanded) |
| 8907 | gdb_assert (canonical->lsals.size () == 1); |
| 8908 | |
| 8909 | for (const auto &lsal : canonical->lsals) |
| 8910 | { |
| 8911 | /* Note that 'location' can be NULL in the case of a plain |
| 8912 | 'break', without arguments. */ |
| 8913 | event_location_up location |
| 8914 | = (canonical->location != NULL |
| 8915 | ? copy_event_location (canonical->location.get ()) : NULL); |
| 8916 | gdb::unique_xmalloc_ptr<char> filter_string |
| 8917 | (lsal.canonical != NULL ? xstrdup (lsal.canonical) : NULL); |
| 8918 | |
| 8919 | create_breakpoint_sal (gdbarch, lsal.sals, |
| 8920 | std::move (location), |
| 8921 | std::move (filter_string), |
| 8922 | std::move (cond_string), |
| 8923 | std::move (extra_string), |
| 8924 | type, disposition, |
| 8925 | thread, task, ignore_count, ops, |
| 8926 | from_tty, enabled, internal, flags, |
| 8927 | canonical->special_display); |
| 8928 | } |
| 8929 | } |
| 8930 | |
| 8931 | /* Parse LOCATION which is assumed to be a SAL specification possibly |
| 8932 | followed by conditionals. On return, SALS contains an array of SAL |
| 8933 | addresses found. LOCATION points to the end of the SAL (for |
| 8934 | linespec locations). |
| 8935 | |
| 8936 | The array and the line spec strings are allocated on the heap, it is |
| 8937 | the caller's responsibility to free them. */ |
| 8938 | |
| 8939 | static void |
| 8940 | parse_breakpoint_sals (const struct event_location *location, |
| 8941 | struct linespec_result *canonical) |
| 8942 | { |
| 8943 | struct symtab_and_line cursal; |
| 8944 | |
| 8945 | if (event_location_type (location) == LINESPEC_LOCATION) |
| 8946 | { |
| 8947 | const char *spec = get_linespec_location (location)->spec_string; |
| 8948 | |
| 8949 | if (spec == NULL) |
| 8950 | { |
| 8951 | /* The last displayed codepoint, if it's valid, is our default |
| 8952 | breakpoint address. */ |
| 8953 | if (last_displayed_sal_is_valid ()) |
| 8954 | { |
| 8955 | /* Set sal's pspace, pc, symtab, and line to the values |
| 8956 | corresponding to the last call to print_frame_info. |
| 8957 | Be sure to reinitialize LINE with NOTCURRENT == 0 |
| 8958 | as the breakpoint line number is inappropriate otherwise. |
| 8959 | find_pc_line would adjust PC, re-set it back. */ |
| 8960 | symtab_and_line sal = get_last_displayed_sal (); |
| 8961 | CORE_ADDR pc = sal.pc; |
| 8962 | |
| 8963 | sal = find_pc_line (pc, 0); |
| 8964 | |
| 8965 | /* "break" without arguments is equivalent to "break *PC" |
| 8966 | where PC is the last displayed codepoint's address. So |
| 8967 | make sure to set sal.explicit_pc to prevent GDB from |
| 8968 | trying to expand the list of sals to include all other |
| 8969 | instances with the same symtab and line. */ |
| 8970 | sal.pc = pc; |
| 8971 | sal.explicit_pc = 1; |
| 8972 | |
| 8973 | struct linespec_sals lsal; |
| 8974 | lsal.sals = {sal}; |
| 8975 | lsal.canonical = NULL; |
| 8976 | |
| 8977 | canonical->lsals.push_back (std::move (lsal)); |
| 8978 | return; |
| 8979 | } |
| 8980 | else |
| 8981 | error (_("No default breakpoint address now.")); |
| 8982 | } |
| 8983 | } |
| 8984 | |
| 8985 | /* Force almost all breakpoints to be in terms of the |
| 8986 | current_source_symtab (which is decode_line_1's default). |
| 8987 | This should produce the results we want almost all of the |
| 8988 | time while leaving default_breakpoint_* alone. |
| 8989 | |
| 8990 | ObjC: However, don't match an Objective-C method name which |
| 8991 | may have a '+' or '-' succeeded by a '['. */ |
| 8992 | cursal = get_current_source_symtab_and_line (); |
| 8993 | if (last_displayed_sal_is_valid ()) |
| 8994 | { |
| 8995 | const char *spec = NULL; |
| 8996 | |
| 8997 | if (event_location_type (location) == LINESPEC_LOCATION) |
| 8998 | spec = get_linespec_location (location)->spec_string; |
| 8999 | |
| 9000 | if (!cursal.symtab |
| 9001 | || (spec != NULL |
| 9002 | && strchr ("+-", spec[0]) != NULL |
| 9003 | && spec[1] != '[')) |
| 9004 | { |
| 9005 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
| 9006 | get_last_displayed_symtab (), |
| 9007 | get_last_displayed_line (), |
| 9008 | canonical, NULL, NULL); |
| 9009 | return; |
| 9010 | } |
| 9011 | } |
| 9012 | |
| 9013 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, NULL, |
| 9014 | cursal.symtab, cursal.line, canonical, NULL, NULL); |
| 9015 | } |
| 9016 | |
| 9017 | |
| 9018 | /* Convert each SAL into a real PC. Verify that the PC can be |
| 9019 | inserted as a breakpoint. If it can't throw an error. */ |
| 9020 | |
| 9021 | static void |
| 9022 | breakpoint_sals_to_pc (std::vector<symtab_and_line> &sals) |
| 9023 | { |
| 9024 | for (auto &sal : sals) |
| 9025 | resolve_sal_pc (&sal); |
| 9026 | } |
| 9027 | |
| 9028 | /* Fast tracepoints may have restrictions on valid locations. For |
| 9029 | instance, a fast tracepoint using a jump instead of a trap will |
| 9030 | likely have to overwrite more bytes than a trap would, and so can |
| 9031 | only be placed where the instruction is longer than the jump, or a |
| 9032 | multi-instruction sequence does not have a jump into the middle of |
| 9033 | it, etc. */ |
| 9034 | |
| 9035 | static void |
| 9036 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, |
| 9037 | gdb::array_view<const symtab_and_line> sals) |
| 9038 | { |
| 9039 | for (const auto &sal : sals) |
| 9040 | { |
| 9041 | struct gdbarch *sarch; |
| 9042 | |
| 9043 | sarch = get_sal_arch (sal); |
| 9044 | /* We fall back to GDBARCH if there is no architecture |
| 9045 | associated with SAL. */ |
| 9046 | if (sarch == NULL) |
| 9047 | sarch = gdbarch; |
| 9048 | std::string msg; |
| 9049 | if (!gdbarch_fast_tracepoint_valid_at (sarch, sal.pc, &msg)) |
| 9050 | error (_("May not have a fast tracepoint at %s%s"), |
| 9051 | paddress (sarch, sal.pc), msg.c_str ()); |
| 9052 | } |
| 9053 | } |
| 9054 | |
| 9055 | /* Given TOK, a string specification of condition and thread, as |
| 9056 | accepted by the 'break' command, extract the condition |
| 9057 | string and thread number and set *COND_STRING and *THREAD. |
| 9058 | PC identifies the context at which the condition should be parsed. |
| 9059 | If no condition is found, *COND_STRING is set to NULL. |
| 9060 | If no thread is found, *THREAD is set to -1. */ |
| 9061 | |
| 9062 | static void |
| 9063 | find_condition_and_thread (const char *tok, CORE_ADDR pc, |
| 9064 | char **cond_string, int *thread, int *task, |
| 9065 | char **rest) |
| 9066 | { |
| 9067 | *cond_string = NULL; |
| 9068 | *thread = -1; |
| 9069 | *task = 0; |
| 9070 | *rest = NULL; |
| 9071 | |
| 9072 | while (tok && *tok) |
| 9073 | { |
| 9074 | const char *end_tok; |
| 9075 | int toklen; |
| 9076 | const char *cond_start = NULL; |
| 9077 | const char *cond_end = NULL; |
| 9078 | |
| 9079 | tok = skip_spaces (tok); |
| 9080 | |
| 9081 | if ((*tok == '"' || *tok == ',') && rest) |
| 9082 | { |
| 9083 | *rest = savestring (tok, strlen (tok)); |
| 9084 | return; |
| 9085 | } |
| 9086 | |
| 9087 | end_tok = skip_to_space (tok); |
| 9088 | |
| 9089 | toklen = end_tok - tok; |
| 9090 | |
| 9091 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 9092 | { |
| 9093 | tok = cond_start = end_tok + 1; |
| 9094 | parse_exp_1 (&tok, pc, block_for_pc (pc), 0); |
| 9095 | cond_end = tok; |
| 9096 | *cond_string = savestring (cond_start, cond_end - cond_start); |
| 9097 | } |
| 9098 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 9099 | { |
| 9100 | const char *tmptok; |
| 9101 | struct thread_info *thr; |
| 9102 | |
| 9103 | tok = end_tok + 1; |
| 9104 | thr = parse_thread_id (tok, &tmptok); |
| 9105 | if (tok == tmptok) |
| 9106 | error (_("Junk after thread keyword.")); |
| 9107 | *thread = thr->global_num; |
| 9108 | tok = tmptok; |
| 9109 | } |
| 9110 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
| 9111 | { |
| 9112 | char *tmptok; |
| 9113 | |
| 9114 | tok = end_tok + 1; |
| 9115 | *task = strtol (tok, &tmptok, 0); |
| 9116 | if (tok == tmptok) |
| 9117 | error (_("Junk after task keyword.")); |
| 9118 | if (!valid_task_id (*task)) |
| 9119 | error (_("Unknown task %d."), *task); |
| 9120 | tok = tmptok; |
| 9121 | } |
| 9122 | else if (rest) |
| 9123 | { |
| 9124 | *rest = savestring (tok, strlen (tok)); |
| 9125 | return; |
| 9126 | } |
| 9127 | else |
| 9128 | error (_("Junk at end of arguments.")); |
| 9129 | } |
| 9130 | } |
| 9131 | |
| 9132 | /* Decode a static tracepoint marker spec. */ |
| 9133 | |
| 9134 | static std::vector<symtab_and_line> |
| 9135 | decode_static_tracepoint_spec (const char **arg_p) |
| 9136 | { |
| 9137 | const char *p = &(*arg_p)[3]; |
| 9138 | const char *endp; |
| 9139 | |
| 9140 | p = skip_spaces (p); |
| 9141 | |
| 9142 | endp = skip_to_space (p); |
| 9143 | |
| 9144 | std::string marker_str (p, endp - p); |
| 9145 | |
| 9146 | std::vector<static_tracepoint_marker> markers |
| 9147 | = target_static_tracepoint_markers_by_strid (marker_str.c_str ()); |
| 9148 | if (markers.empty ()) |
| 9149 | error (_("No known static tracepoint marker named %s"), |
| 9150 | marker_str.c_str ()); |
| 9151 | |
| 9152 | std::vector<symtab_and_line> sals; |
| 9153 | sals.reserve (markers.size ()); |
| 9154 | |
| 9155 | for (const static_tracepoint_marker &marker : markers) |
| 9156 | { |
| 9157 | symtab_and_line sal = find_pc_line (marker.address, 0); |
| 9158 | sal.pc = marker.address; |
| 9159 | sals.push_back (sal); |
| 9160 | } |
| 9161 | |
| 9162 | *arg_p = endp; |
| 9163 | return sals; |
| 9164 | } |
| 9165 | |
| 9166 | /* See breakpoint.h. */ |
| 9167 | |
| 9168 | int |
| 9169 | create_breakpoint (struct gdbarch *gdbarch, |
| 9170 | const struct event_location *location, |
| 9171 | const char *cond_string, |
| 9172 | int thread, const char *extra_string, |
| 9173 | int parse_extra, |
| 9174 | int tempflag, enum bptype type_wanted, |
| 9175 | int ignore_count, |
| 9176 | enum auto_boolean pending_break_support, |
| 9177 | const struct breakpoint_ops *ops, |
| 9178 | int from_tty, int enabled, int internal, |
| 9179 | unsigned flags) |
| 9180 | { |
| 9181 | struct linespec_result canonical; |
| 9182 | int pending = 0; |
| 9183 | int task = 0; |
| 9184 | int prev_bkpt_count = breakpoint_count; |
| 9185 | |
| 9186 | gdb_assert (ops != NULL); |
| 9187 | |
| 9188 | /* If extra_string isn't useful, set it to NULL. */ |
| 9189 | if (extra_string != NULL && *extra_string == '\0') |
| 9190 | extra_string = NULL; |
| 9191 | |
| 9192 | try |
| 9193 | { |
| 9194 | ops->create_sals_from_location (location, &canonical, type_wanted); |
| 9195 | } |
| 9196 | catch (const gdb_exception_error &e) |
| 9197 | { |
| 9198 | /* If caller is interested in rc value from parse, set |
| 9199 | value. */ |
| 9200 | if (e.error == NOT_FOUND_ERROR) |
| 9201 | { |
| 9202 | /* If pending breakpoint support is turned off, throw |
| 9203 | error. */ |
| 9204 | |
| 9205 | if (pending_break_support == AUTO_BOOLEAN_FALSE) |
| 9206 | throw; |
| 9207 | |
| 9208 | exception_print (gdb_stderr, e); |
| 9209 | |
| 9210 | /* If pending breakpoint support is auto query and the user |
| 9211 | selects no, then simply return the error code. */ |
| 9212 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
| 9213 | && !nquery (_("Make %s pending on future shared library load? "), |
| 9214 | bptype_string (type_wanted))) |
| 9215 | return 0; |
| 9216 | |
| 9217 | /* At this point, either the user was queried about setting |
| 9218 | a pending breakpoint and selected yes, or pending |
| 9219 | breakpoint behavior is on and thus a pending breakpoint |
| 9220 | is defaulted on behalf of the user. */ |
| 9221 | pending = 1; |
| 9222 | } |
| 9223 | else |
| 9224 | throw; |
| 9225 | } |
| 9226 | |
| 9227 | if (!pending && canonical.lsals.empty ()) |
| 9228 | return 0; |
| 9229 | |
| 9230 | /* Resolve all line numbers to PC's and verify that the addresses |
| 9231 | are ok for the target. */ |
| 9232 | if (!pending) |
| 9233 | { |
| 9234 | for (auto &lsal : canonical.lsals) |
| 9235 | breakpoint_sals_to_pc (lsal.sals); |
| 9236 | } |
| 9237 | |
| 9238 | /* Fast tracepoints may have additional restrictions on location. */ |
| 9239 | if (!pending && type_wanted == bp_fast_tracepoint) |
| 9240 | { |
| 9241 | for (const auto &lsal : canonical.lsals) |
| 9242 | check_fast_tracepoint_sals (gdbarch, lsal.sals); |
| 9243 | } |
| 9244 | |
| 9245 | /* Verify that condition can be parsed, before setting any |
| 9246 | breakpoints. Allocate a separate condition expression for each |
| 9247 | breakpoint. */ |
| 9248 | if (!pending) |
| 9249 | { |
| 9250 | gdb::unique_xmalloc_ptr<char> cond_string_copy; |
| 9251 | gdb::unique_xmalloc_ptr<char> extra_string_copy; |
| 9252 | |
| 9253 | if (parse_extra) |
| 9254 | { |
| 9255 | char *rest; |
| 9256 | char *cond; |
| 9257 | |
| 9258 | const linespec_sals &lsal = canonical.lsals[0]; |
| 9259 | |
| 9260 | /* Here we only parse 'arg' to separate condition |
| 9261 | from thread number, so parsing in context of first |
| 9262 | sal is OK. When setting the breakpoint we'll |
| 9263 | re-parse it in context of each sal. */ |
| 9264 | |
| 9265 | find_condition_and_thread (extra_string, lsal.sals[0].pc, |
| 9266 | &cond, &thread, &task, &rest); |
| 9267 | cond_string_copy.reset (cond); |
| 9268 | extra_string_copy.reset (rest); |
| 9269 | } |
| 9270 | else |
| 9271 | { |
| 9272 | if (type_wanted != bp_dprintf |
| 9273 | && extra_string != NULL && *extra_string != '\0') |
| 9274 | error (_("Garbage '%s' at end of location"), extra_string); |
| 9275 | |
| 9276 | /* Create a private copy of condition string. */ |
| 9277 | if (cond_string) |
| 9278 | cond_string_copy.reset (xstrdup (cond_string)); |
| 9279 | /* Create a private copy of any extra string. */ |
| 9280 | if (extra_string) |
| 9281 | extra_string_copy.reset (xstrdup (extra_string)); |
| 9282 | } |
| 9283 | |
| 9284 | ops->create_breakpoints_sal (gdbarch, &canonical, |
| 9285 | std::move (cond_string_copy), |
| 9286 | std::move (extra_string_copy), |
| 9287 | type_wanted, |
| 9288 | tempflag ? disp_del : disp_donttouch, |
| 9289 | thread, task, ignore_count, ops, |
| 9290 | from_tty, enabled, internal, flags); |
| 9291 | } |
| 9292 | else |
| 9293 | { |
| 9294 | std::unique_ptr <breakpoint> b = new_breakpoint_from_type (type_wanted); |
| 9295 | |
| 9296 | init_raw_breakpoint_without_location (b.get (), gdbarch, type_wanted, ops); |
| 9297 | b->location = copy_event_location (location); |
| 9298 | |
| 9299 | if (parse_extra) |
| 9300 | b->cond_string = NULL; |
| 9301 | else |
| 9302 | { |
| 9303 | /* Create a private copy of condition string. */ |
| 9304 | b->cond_string = cond_string != NULL ? xstrdup (cond_string) : NULL; |
| 9305 | b->thread = thread; |
| 9306 | } |
| 9307 | |
| 9308 | /* Create a private copy of any extra string. */ |
| 9309 | b->extra_string = extra_string != NULL ? xstrdup (extra_string) : NULL; |
| 9310 | b->ignore_count = ignore_count; |
| 9311 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 9312 | b->condition_not_parsed = 1; |
| 9313 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 9314 | if ((type_wanted != bp_breakpoint |
| 9315 | && type_wanted != bp_hardware_breakpoint) || thread != -1) |
| 9316 | b->pspace = current_program_space; |
| 9317 | |
| 9318 | install_breakpoint (internal, std::move (b), 0); |
| 9319 | } |
| 9320 | |
| 9321 | if (canonical.lsals.size () > 1) |
| 9322 | { |
| 9323 | warning (_("Multiple breakpoints were set.\nUse the " |
| 9324 | "\"delete\" command to delete unwanted breakpoints.")); |
| 9325 | prev_breakpoint_count = prev_bkpt_count; |
| 9326 | } |
| 9327 | |
| 9328 | update_global_location_list (UGLL_MAY_INSERT); |
| 9329 | |
| 9330 | return 1; |
| 9331 | } |
| 9332 | |
| 9333 | /* Set a breakpoint. |
| 9334 | ARG is a string describing breakpoint address, |
| 9335 | condition, and thread. |
| 9336 | FLAG specifies if a breakpoint is hardware on, |
| 9337 | and if breakpoint is temporary, using BP_HARDWARE_FLAG |
| 9338 | and BP_TEMPFLAG. */ |
| 9339 | |
| 9340 | static void |
| 9341 | break_command_1 (const char *arg, int flag, int from_tty) |
| 9342 | { |
| 9343 | int tempflag = flag & BP_TEMPFLAG; |
| 9344 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
| 9345 | ? bp_hardware_breakpoint |
| 9346 | : bp_breakpoint); |
| 9347 | struct breakpoint_ops *ops; |
| 9348 | |
| 9349 | event_location_up location = string_to_event_location (&arg, current_language); |
| 9350 | |
| 9351 | /* Matching breakpoints on probes. */ |
| 9352 | if (location != NULL |
| 9353 | && event_location_type (location.get ()) == PROBE_LOCATION) |
| 9354 | ops = &bkpt_probe_breakpoint_ops; |
| 9355 | else |
| 9356 | ops = &bkpt_breakpoint_ops; |
| 9357 | |
| 9358 | create_breakpoint (get_current_arch (), |
| 9359 | location.get (), |
| 9360 | NULL, 0, arg, 1 /* parse arg */, |
| 9361 | tempflag, type_wanted, |
| 9362 | 0 /* Ignore count */, |
| 9363 | pending_break_support, |
| 9364 | ops, |
| 9365 | from_tty, |
| 9366 | 1 /* enabled */, |
| 9367 | 0 /* internal */, |
| 9368 | 0); |
| 9369 | } |
| 9370 | |
| 9371 | /* Helper function for break_command_1 and disassemble_command. */ |
| 9372 | |
| 9373 | void |
| 9374 | resolve_sal_pc (struct symtab_and_line *sal) |
| 9375 | { |
| 9376 | CORE_ADDR pc; |
| 9377 | |
| 9378 | if (sal->pc == 0 && sal->symtab != NULL) |
| 9379 | { |
| 9380 | if (!find_line_pc (sal->symtab, sal->line, &pc)) |
| 9381 | error (_("No line %d in file \"%s\"."), |
| 9382 | sal->line, symtab_to_filename_for_display (sal->symtab)); |
| 9383 | sal->pc = pc; |
| 9384 | |
| 9385 | /* If this SAL corresponds to a breakpoint inserted using a line |
| 9386 | number, then skip the function prologue if necessary. */ |
| 9387 | if (sal->explicit_line) |
| 9388 | skip_prologue_sal (sal); |
| 9389 | } |
| 9390 | |
| 9391 | if (sal->section == 0 && sal->symtab != NULL) |
| 9392 | { |
| 9393 | const struct blockvector *bv; |
| 9394 | const struct block *b; |
| 9395 | struct symbol *sym; |
| 9396 | |
| 9397 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, |
| 9398 | SYMTAB_COMPUNIT (sal->symtab)); |
| 9399 | if (bv != NULL) |
| 9400 | { |
| 9401 | sym = block_linkage_function (b); |
| 9402 | if (sym != NULL) |
| 9403 | { |
| 9404 | fixup_symbol_section (sym, SYMTAB_OBJFILE (sal->symtab)); |
| 9405 | sal->section = SYMBOL_OBJ_SECTION (SYMTAB_OBJFILE (sal->symtab), |
| 9406 | sym); |
| 9407 | } |
| 9408 | else |
| 9409 | { |
| 9410 | /* It really is worthwhile to have the section, so we'll |
| 9411 | just have to look harder. This case can be executed |
| 9412 | if we have line numbers but no functions (as can |
| 9413 | happen in assembly source). */ |
| 9414 | |
| 9415 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 9416 | switch_to_program_space_and_thread (sal->pspace); |
| 9417 | |
| 9418 | bound_minimal_symbol msym = lookup_minimal_symbol_by_pc (sal->pc); |
| 9419 | if (msym.minsym) |
| 9420 | sal->section = MSYMBOL_OBJ_SECTION (msym.objfile, msym.minsym); |
| 9421 | } |
| 9422 | } |
| 9423 | } |
| 9424 | } |
| 9425 | |
| 9426 | void |
| 9427 | break_command (const char *arg, int from_tty) |
| 9428 | { |
| 9429 | break_command_1 (arg, 0, from_tty); |
| 9430 | } |
| 9431 | |
| 9432 | void |
| 9433 | tbreak_command (const char *arg, int from_tty) |
| 9434 | { |
| 9435 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
| 9436 | } |
| 9437 | |
| 9438 | static void |
| 9439 | hbreak_command (const char *arg, int from_tty) |
| 9440 | { |
| 9441 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
| 9442 | } |
| 9443 | |
| 9444 | static void |
| 9445 | thbreak_command (const char *arg, int from_tty) |
| 9446 | { |
| 9447 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
| 9448 | } |
| 9449 | |
| 9450 | static void |
| 9451 | stop_command (const char *arg, int from_tty) |
| 9452 | { |
| 9453 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
| 9454 | Usage: stop in <function | address>\n\ |
| 9455 | stop at <line>\n")); |
| 9456 | } |
| 9457 | |
| 9458 | static void |
| 9459 | stopin_command (const char *arg, int from_tty) |
| 9460 | { |
| 9461 | int badInput = 0; |
| 9462 | |
| 9463 | if (arg == NULL) |
| 9464 | badInput = 1; |
| 9465 | else if (*arg != '*') |
| 9466 | { |
| 9467 | const char *argptr = arg; |
| 9468 | int hasColon = 0; |
| 9469 | |
| 9470 | /* Look for a ':'. If this is a line number specification, then |
| 9471 | say it is bad, otherwise, it should be an address or |
| 9472 | function/method name. */ |
| 9473 | while (*argptr && !hasColon) |
| 9474 | { |
| 9475 | hasColon = (*argptr == ':'); |
| 9476 | argptr++; |
| 9477 | } |
| 9478 | |
| 9479 | if (hasColon) |
| 9480 | badInput = (*argptr != ':'); /* Not a class::method */ |
| 9481 | else |
| 9482 | badInput = isdigit (*arg); /* a simple line number */ |
| 9483 | } |
| 9484 | |
| 9485 | if (badInput) |
| 9486 | printf_filtered (_("Usage: stop in <function | address>\n")); |
| 9487 | else |
| 9488 | break_command_1 (arg, 0, from_tty); |
| 9489 | } |
| 9490 | |
| 9491 | static void |
| 9492 | stopat_command (const char *arg, int from_tty) |
| 9493 | { |
| 9494 | int badInput = 0; |
| 9495 | |
| 9496 | if (arg == NULL || *arg == '*') /* no line number */ |
| 9497 | badInput = 1; |
| 9498 | else |
| 9499 | { |
| 9500 | const char *argptr = arg; |
| 9501 | int hasColon = 0; |
| 9502 | |
| 9503 | /* Look for a ':'. If there is a '::' then get out, otherwise |
| 9504 | it is probably a line number. */ |
| 9505 | while (*argptr && !hasColon) |
| 9506 | { |
| 9507 | hasColon = (*argptr == ':'); |
| 9508 | argptr++; |
| 9509 | } |
| 9510 | |
| 9511 | if (hasColon) |
| 9512 | badInput = (*argptr == ':'); /* we have class::method */ |
| 9513 | else |
| 9514 | badInput = !isdigit (*arg); /* not a line number */ |
| 9515 | } |
| 9516 | |
| 9517 | if (badInput) |
| 9518 | printf_filtered (_("Usage: stop at LINE\n")); |
| 9519 | else |
| 9520 | break_command_1 (arg, 0, from_tty); |
| 9521 | } |
| 9522 | |
| 9523 | /* The dynamic printf command is mostly like a regular breakpoint, but |
| 9524 | with a prewired command list consisting of a single output command, |
| 9525 | built from extra arguments supplied on the dprintf command |
| 9526 | line. */ |
| 9527 | |
| 9528 | static void |
| 9529 | dprintf_command (const char *arg, int from_tty) |
| 9530 | { |
| 9531 | event_location_up location = string_to_event_location (&arg, current_language); |
| 9532 | |
| 9533 | /* If non-NULL, ARG should have been advanced past the location; |
| 9534 | the next character must be ','. */ |
| 9535 | if (arg != NULL) |
| 9536 | { |
| 9537 | if (arg[0] != ',' || arg[1] == '\0') |
| 9538 | error (_("Format string required")); |
| 9539 | else |
| 9540 | { |
| 9541 | /* Skip the comma. */ |
| 9542 | ++arg; |
| 9543 | } |
| 9544 | } |
| 9545 | |
| 9546 | create_breakpoint (get_current_arch (), |
| 9547 | location.get (), |
| 9548 | NULL, 0, arg, 1 /* parse arg */, |
| 9549 | 0, bp_dprintf, |
| 9550 | 0 /* Ignore count */, |
| 9551 | pending_break_support, |
| 9552 | &dprintf_breakpoint_ops, |
| 9553 | from_tty, |
| 9554 | 1 /* enabled */, |
| 9555 | 0 /* internal */, |
| 9556 | 0); |
| 9557 | } |
| 9558 | |
| 9559 | static void |
| 9560 | agent_printf_command (const char *arg, int from_tty) |
| 9561 | { |
| 9562 | error (_("May only run agent-printf on the target")); |
| 9563 | } |
| 9564 | |
| 9565 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
| 9566 | ranged breakpoints. */ |
| 9567 | |
| 9568 | static int |
| 9569 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, |
| 9570 | const address_space *aspace, |
| 9571 | CORE_ADDR bp_addr, |
| 9572 | const struct target_waitstatus *ws) |
| 9573 | { |
| 9574 | if (ws->kind != TARGET_WAITKIND_STOPPED |
| 9575 | || ws->value.sig != GDB_SIGNAL_TRAP) |
| 9576 | return 0; |
| 9577 | |
| 9578 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, |
| 9579 | bl->length, aspace, bp_addr); |
| 9580 | } |
| 9581 | |
| 9582 | /* Implement the "resources_needed" breakpoint_ops method for |
| 9583 | ranged breakpoints. */ |
| 9584 | |
| 9585 | static int |
| 9586 | resources_needed_ranged_breakpoint (const struct bp_location *bl) |
| 9587 | { |
| 9588 | return target_ranged_break_num_registers (); |
| 9589 | } |
| 9590 | |
| 9591 | /* Implement the "print_it" breakpoint_ops method for |
| 9592 | ranged breakpoints. */ |
| 9593 | |
| 9594 | static enum print_stop_action |
| 9595 | print_it_ranged_breakpoint (bpstat bs) |
| 9596 | { |
| 9597 | struct breakpoint *b = bs->breakpoint_at; |
| 9598 | struct bp_location *bl = b->loc; |
| 9599 | struct ui_out *uiout = current_uiout; |
| 9600 | |
| 9601 | gdb_assert (b->type == bp_hardware_breakpoint); |
| 9602 | |
| 9603 | /* Ranged breakpoints have only one location. */ |
| 9604 | gdb_assert (bl && bl->next == NULL); |
| 9605 | |
| 9606 | annotate_breakpoint (b->number); |
| 9607 | |
| 9608 | maybe_print_thread_hit_breakpoint (uiout); |
| 9609 | |
| 9610 | if (b->disposition == disp_del) |
| 9611 | uiout->text ("Temporary ranged breakpoint "); |
| 9612 | else |
| 9613 | uiout->text ("Ranged breakpoint "); |
| 9614 | if (uiout->is_mi_like_p ()) |
| 9615 | { |
| 9616 | uiout->field_string ("reason", |
| 9617 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 9618 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 9619 | } |
| 9620 | uiout->field_signed ("bkptno", b->number); |
| 9621 | uiout->text (", "); |
| 9622 | |
| 9623 | return PRINT_SRC_AND_LOC; |
| 9624 | } |
| 9625 | |
| 9626 | /* Implement the "print_one" breakpoint_ops method for |
| 9627 | ranged breakpoints. */ |
| 9628 | |
| 9629 | static void |
| 9630 | print_one_ranged_breakpoint (struct breakpoint *b, |
| 9631 | struct bp_location **last_loc) |
| 9632 | { |
| 9633 | struct bp_location *bl = b->loc; |
| 9634 | struct value_print_options opts; |
| 9635 | struct ui_out *uiout = current_uiout; |
| 9636 | |
| 9637 | /* Ranged breakpoints have only one location. */ |
| 9638 | gdb_assert (bl && bl->next == NULL); |
| 9639 | |
| 9640 | get_user_print_options (&opts); |
| 9641 | |
| 9642 | if (opts.addressprint) |
| 9643 | /* We don't print the address range here, it will be printed later |
| 9644 | by print_one_detail_ranged_breakpoint. */ |
| 9645 | uiout->field_skip ("addr"); |
| 9646 | annotate_field (5); |
| 9647 | print_breakpoint_location (b, bl); |
| 9648 | *last_loc = bl; |
| 9649 | } |
| 9650 | |
| 9651 | /* Implement the "print_one_detail" breakpoint_ops method for |
| 9652 | ranged breakpoints. */ |
| 9653 | |
| 9654 | static void |
| 9655 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, |
| 9656 | struct ui_out *uiout) |
| 9657 | { |
| 9658 | CORE_ADDR address_start, address_end; |
| 9659 | struct bp_location *bl = b->loc; |
| 9660 | string_file stb; |
| 9661 | |
| 9662 | gdb_assert (bl); |
| 9663 | |
| 9664 | address_start = bl->address; |
| 9665 | address_end = address_start + bl->length - 1; |
| 9666 | |
| 9667 | uiout->text ("\taddress range: "); |
| 9668 | stb.printf ("[%s, %s]", |
| 9669 | print_core_address (bl->gdbarch, address_start), |
| 9670 | print_core_address (bl->gdbarch, address_end)); |
| 9671 | uiout->field_stream ("addr", stb); |
| 9672 | uiout->text ("\n"); |
| 9673 | } |
| 9674 | |
| 9675 | /* Implement the "print_mention" breakpoint_ops method for |
| 9676 | ranged breakpoints. */ |
| 9677 | |
| 9678 | static void |
| 9679 | print_mention_ranged_breakpoint (struct breakpoint *b) |
| 9680 | { |
| 9681 | struct bp_location *bl = b->loc; |
| 9682 | struct ui_out *uiout = current_uiout; |
| 9683 | |
| 9684 | gdb_assert (bl); |
| 9685 | gdb_assert (b->type == bp_hardware_breakpoint); |
| 9686 | |
| 9687 | uiout->message (_("Hardware assisted ranged breakpoint %d from %s to %s."), |
| 9688 | b->number, paddress (bl->gdbarch, bl->address), |
| 9689 | paddress (bl->gdbarch, bl->address + bl->length - 1)); |
| 9690 | } |
| 9691 | |
| 9692 | /* Implement the "print_recreate" breakpoint_ops method for |
| 9693 | ranged breakpoints. */ |
| 9694 | |
| 9695 | static void |
| 9696 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) |
| 9697 | { |
| 9698 | fprintf_unfiltered (fp, "break-range %s, %s", |
| 9699 | event_location_to_string (b->location.get ()), |
| 9700 | event_location_to_string (b->location_range_end.get ())); |
| 9701 | print_recreate_thread (b, fp); |
| 9702 | } |
| 9703 | |
| 9704 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ |
| 9705 | |
| 9706 | static struct breakpoint_ops ranged_breakpoint_ops; |
| 9707 | |
| 9708 | /* Find the address where the end of the breakpoint range should be |
| 9709 | placed, given the SAL of the end of the range. This is so that if |
| 9710 | the user provides a line number, the end of the range is set to the |
| 9711 | last instruction of the given line. */ |
| 9712 | |
| 9713 | static CORE_ADDR |
| 9714 | find_breakpoint_range_end (struct symtab_and_line sal) |
| 9715 | { |
| 9716 | CORE_ADDR end; |
| 9717 | |
| 9718 | /* If the user provided a PC value, use it. Otherwise, |
| 9719 | find the address of the end of the given location. */ |
| 9720 | if (sal.explicit_pc) |
| 9721 | end = sal.pc; |
| 9722 | else |
| 9723 | { |
| 9724 | int ret; |
| 9725 | CORE_ADDR start; |
| 9726 | |
| 9727 | ret = find_line_pc_range (sal, &start, &end); |
| 9728 | if (!ret) |
| 9729 | error (_("Could not find location of the end of the range.")); |
| 9730 | |
| 9731 | /* find_line_pc_range returns the start of the next line. */ |
| 9732 | end--; |
| 9733 | } |
| 9734 | |
| 9735 | return end; |
| 9736 | } |
| 9737 | |
| 9738 | /* Implement the "break-range" CLI command. */ |
| 9739 | |
| 9740 | static void |
| 9741 | break_range_command (const char *arg, int from_tty) |
| 9742 | { |
| 9743 | const char *arg_start; |
| 9744 | struct linespec_result canonical_start, canonical_end; |
| 9745 | int bp_count, can_use_bp, length; |
| 9746 | CORE_ADDR end; |
| 9747 | struct breakpoint *b; |
| 9748 | |
| 9749 | /* We don't support software ranged breakpoints. */ |
| 9750 | if (target_ranged_break_num_registers () < 0) |
| 9751 | error (_("This target does not support hardware ranged breakpoints.")); |
| 9752 | |
| 9753 | bp_count = hw_breakpoint_used_count (); |
| 9754 | bp_count += target_ranged_break_num_registers (); |
| 9755 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 9756 | bp_count, 0); |
| 9757 | if (can_use_bp < 0) |
| 9758 | error (_("Hardware breakpoints used exceeds limit.")); |
| 9759 | |
| 9760 | arg = skip_spaces (arg); |
| 9761 | if (arg == NULL || arg[0] == '\0') |
| 9762 | error(_("No address range specified.")); |
| 9763 | |
| 9764 | arg_start = arg; |
| 9765 | event_location_up start_location = string_to_event_location (&arg, |
| 9766 | current_language); |
| 9767 | parse_breakpoint_sals (start_location.get (), &canonical_start); |
| 9768 | |
| 9769 | if (arg[0] != ',') |
| 9770 | error (_("Too few arguments.")); |
| 9771 | else if (canonical_start.lsals.empty ()) |
| 9772 | error (_("Could not find location of the beginning of the range.")); |
| 9773 | |
| 9774 | const linespec_sals &lsal_start = canonical_start.lsals[0]; |
| 9775 | |
| 9776 | if (canonical_start.lsals.size () > 1 |
| 9777 | || lsal_start.sals.size () != 1) |
| 9778 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
| 9779 | |
| 9780 | const symtab_and_line &sal_start = lsal_start.sals[0]; |
| 9781 | std::string addr_string_start (arg_start, arg - arg_start); |
| 9782 | |
| 9783 | arg++; /* Skip the comma. */ |
| 9784 | arg = skip_spaces (arg); |
| 9785 | |
| 9786 | /* Parse the end location. */ |
| 9787 | |
| 9788 | arg_start = arg; |
| 9789 | |
| 9790 | /* We call decode_line_full directly here instead of using |
| 9791 | parse_breakpoint_sals because we need to specify the start location's |
| 9792 | symtab and line as the default symtab and line for the end of the |
| 9793 | range. This makes it possible to have ranges like "foo.c:27, +14", |
| 9794 | where +14 means 14 lines from the start location. */ |
| 9795 | event_location_up end_location = string_to_event_location (&arg, |
| 9796 | current_language); |
| 9797 | decode_line_full (end_location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, |
| 9798 | sal_start.symtab, sal_start.line, |
| 9799 | &canonical_end, NULL, NULL); |
| 9800 | |
| 9801 | if (canonical_end.lsals.empty ()) |
| 9802 | error (_("Could not find location of the end of the range.")); |
| 9803 | |
| 9804 | const linespec_sals &lsal_end = canonical_end.lsals[0]; |
| 9805 | if (canonical_end.lsals.size () > 1 |
| 9806 | || lsal_end.sals.size () != 1) |
| 9807 | error (_("Cannot create a ranged breakpoint with multiple locations.")); |
| 9808 | |
| 9809 | const symtab_and_line &sal_end = lsal_end.sals[0]; |
| 9810 | |
| 9811 | end = find_breakpoint_range_end (sal_end); |
| 9812 | if (sal_start.pc > end) |
| 9813 | error (_("Invalid address range, end precedes start.")); |
| 9814 | |
| 9815 | length = end - sal_start.pc + 1; |
| 9816 | if (length < 0) |
| 9817 | /* Length overflowed. */ |
| 9818 | error (_("Address range too large.")); |
| 9819 | else if (length == 1) |
| 9820 | { |
| 9821 | /* This range is simple enough to be handled by |
| 9822 | the `hbreak' command. */ |
| 9823 | hbreak_command (&addr_string_start[0], 1); |
| 9824 | |
| 9825 | return; |
| 9826 | } |
| 9827 | |
| 9828 | /* Now set up the breakpoint. */ |
| 9829 | b = set_raw_breakpoint (get_current_arch (), sal_start, |
| 9830 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
| 9831 | set_breakpoint_count (breakpoint_count + 1); |
| 9832 | b->number = breakpoint_count; |
| 9833 | b->disposition = disp_donttouch; |
| 9834 | b->location = std::move (start_location); |
| 9835 | b->location_range_end = std::move (end_location); |
| 9836 | b->loc->length = length; |
| 9837 | |
| 9838 | mention (b); |
| 9839 | gdb::observers::breakpoint_created.notify (b); |
| 9840 | update_global_location_list (UGLL_MAY_INSERT); |
| 9841 | } |
| 9842 | |
| 9843 | /* Return non-zero if EXP is verified as constant. Returned zero |
| 9844 | means EXP is variable. Also the constant detection may fail for |
| 9845 | some constant expressions and in such case still falsely return |
| 9846 | zero. */ |
| 9847 | |
| 9848 | static int |
| 9849 | watchpoint_exp_is_const (const struct expression *exp) |
| 9850 | { |
| 9851 | int i = exp->nelts; |
| 9852 | |
| 9853 | while (i > 0) |
| 9854 | { |
| 9855 | int oplenp, argsp; |
| 9856 | |
| 9857 | /* We are only interested in the descriptor of each element. */ |
| 9858 | operator_length (exp, i, &oplenp, &argsp); |
| 9859 | i -= oplenp; |
| 9860 | |
| 9861 | switch (exp->elts[i].opcode) |
| 9862 | { |
| 9863 | case BINOP_ADD: |
| 9864 | case BINOP_SUB: |
| 9865 | case BINOP_MUL: |
| 9866 | case BINOP_DIV: |
| 9867 | case BINOP_REM: |
| 9868 | case BINOP_MOD: |
| 9869 | case BINOP_LSH: |
| 9870 | case BINOP_RSH: |
| 9871 | case BINOP_LOGICAL_AND: |
| 9872 | case BINOP_LOGICAL_OR: |
| 9873 | case BINOP_BITWISE_AND: |
| 9874 | case BINOP_BITWISE_IOR: |
| 9875 | case BINOP_BITWISE_XOR: |
| 9876 | case BINOP_EQUAL: |
| 9877 | case BINOP_NOTEQUAL: |
| 9878 | case BINOP_LESS: |
| 9879 | case BINOP_GTR: |
| 9880 | case BINOP_LEQ: |
| 9881 | case BINOP_GEQ: |
| 9882 | case BINOP_REPEAT: |
| 9883 | case BINOP_COMMA: |
| 9884 | case BINOP_EXP: |
| 9885 | case BINOP_MIN: |
| 9886 | case BINOP_MAX: |
| 9887 | case BINOP_INTDIV: |
| 9888 | case BINOP_CONCAT: |
| 9889 | case TERNOP_COND: |
| 9890 | case TERNOP_SLICE: |
| 9891 | |
| 9892 | case OP_LONG: |
| 9893 | case OP_FLOAT: |
| 9894 | case OP_LAST: |
| 9895 | case OP_COMPLEX: |
| 9896 | case OP_STRING: |
| 9897 | case OP_ARRAY: |
| 9898 | case OP_TYPE: |
| 9899 | case OP_TYPEOF: |
| 9900 | case OP_DECLTYPE: |
| 9901 | case OP_TYPEID: |
| 9902 | case OP_NAME: |
| 9903 | case OP_OBJC_NSSTRING: |
| 9904 | |
| 9905 | case UNOP_NEG: |
| 9906 | case UNOP_LOGICAL_NOT: |
| 9907 | case UNOP_COMPLEMENT: |
| 9908 | case UNOP_ADDR: |
| 9909 | case UNOP_HIGH: |
| 9910 | case UNOP_CAST: |
| 9911 | |
| 9912 | case UNOP_CAST_TYPE: |
| 9913 | case UNOP_REINTERPRET_CAST: |
| 9914 | case UNOP_DYNAMIC_CAST: |
| 9915 | /* Unary, binary and ternary operators: We have to check |
| 9916 | their operands. If they are constant, then so is the |
| 9917 | result of that operation. For instance, if A and B are |
| 9918 | determined to be constants, then so is "A + B". |
| 9919 | |
| 9920 | UNOP_IND is one exception to the rule above, because the |
| 9921 | value of *ADDR is not necessarily a constant, even when |
| 9922 | ADDR is. */ |
| 9923 | break; |
| 9924 | |
| 9925 | case OP_VAR_VALUE: |
| 9926 | /* Check whether the associated symbol is a constant. |
| 9927 | |
| 9928 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
| 9929 | possible that a buggy compiler could mark a variable as |
| 9930 | constant even when it is not, and TYPE_CONST would return |
| 9931 | true in this case, while SYMBOL_CLASS wouldn't. |
| 9932 | |
| 9933 | We also have to check for function symbols because they |
| 9934 | are always constant. */ |
| 9935 | { |
| 9936 | struct symbol *s = exp->elts[i + 2].symbol; |
| 9937 | |
| 9938 | if (SYMBOL_CLASS (s) != LOC_BLOCK |
| 9939 | && SYMBOL_CLASS (s) != LOC_CONST |
| 9940 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) |
| 9941 | return 0; |
| 9942 | break; |
| 9943 | } |
| 9944 | |
| 9945 | /* The default action is to return 0 because we are using |
| 9946 | the optimistic approach here: If we don't know something, |
| 9947 | then it is not a constant. */ |
| 9948 | default: |
| 9949 | return 0; |
| 9950 | } |
| 9951 | } |
| 9952 | |
| 9953 | return 1; |
| 9954 | } |
| 9955 | |
| 9956 | /* Watchpoint destructor. */ |
| 9957 | |
| 9958 | watchpoint::~watchpoint () |
| 9959 | { |
| 9960 | xfree (this->exp_string); |
| 9961 | xfree (this->exp_string_reparse); |
| 9962 | } |
| 9963 | |
| 9964 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
| 9965 | |
| 9966 | static void |
| 9967 | re_set_watchpoint (struct breakpoint *b) |
| 9968 | { |
| 9969 | struct watchpoint *w = (struct watchpoint *) b; |
| 9970 | |
| 9971 | /* Watchpoint can be either on expression using entirely global |
| 9972 | variables, or it can be on local variables. |
| 9973 | |
| 9974 | Watchpoints of the first kind are never auto-deleted, and even |
| 9975 | persist across program restarts. Since they can use variables |
| 9976 | from shared libraries, we need to reparse expression as libraries |
| 9977 | are loaded and unloaded. |
| 9978 | |
| 9979 | Watchpoints on local variables can also change meaning as result |
| 9980 | of solib event. For example, if a watchpoint uses both a local |
| 9981 | and a global variables in expression, it's a local watchpoint, |
| 9982 | but unloading of a shared library will make the expression |
| 9983 | invalid. This is not a very common use case, but we still |
| 9984 | re-evaluate expression, to avoid surprises to the user. |
| 9985 | |
| 9986 | Note that for local watchpoints, we re-evaluate it only if |
| 9987 | watchpoints frame id is still valid. If it's not, it means the |
| 9988 | watchpoint is out of scope and will be deleted soon. In fact, |
| 9989 | I'm not sure we'll ever be called in this case. |
| 9990 | |
| 9991 | If a local watchpoint's frame id is still valid, then |
| 9992 | w->exp_valid_block is likewise valid, and we can safely use it. |
| 9993 | |
| 9994 | Don't do anything about disabled watchpoints, since they will be |
| 9995 | reevaluated again when enabled. */ |
| 9996 | update_watchpoint (w, 1 /* reparse */); |
| 9997 | } |
| 9998 | |
| 9999 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
| 10000 | |
| 10001 | static int |
| 10002 | insert_watchpoint (struct bp_location *bl) |
| 10003 | { |
| 10004 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10005 | int length = w->exact ? 1 : bl->length; |
| 10006 | |
| 10007 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, |
| 10008 | w->cond_exp.get ()); |
| 10009 | } |
| 10010 | |
| 10011 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ |
| 10012 | |
| 10013 | static int |
| 10014 | remove_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
| 10015 | { |
| 10016 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10017 | int length = w->exact ? 1 : bl->length; |
| 10018 | |
| 10019 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, |
| 10020 | w->cond_exp.get ()); |
| 10021 | } |
| 10022 | |
| 10023 | static int |
| 10024 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
| 10025 | const address_space *aspace, CORE_ADDR bp_addr, |
| 10026 | const struct target_waitstatus *ws) |
| 10027 | { |
| 10028 | struct breakpoint *b = bl->owner; |
| 10029 | struct watchpoint *w = (struct watchpoint *) b; |
| 10030 | |
| 10031 | /* Continuable hardware watchpoints are treated as non-existent if the |
| 10032 | reason we stopped wasn't a hardware watchpoint (we didn't stop on |
| 10033 | some data address). Otherwise gdb won't stop on a break instruction |
| 10034 | in the code (not from a breakpoint) when a hardware watchpoint has |
| 10035 | been defined. Also skip watchpoints which we know did not trigger |
| 10036 | (did not match the data address). */ |
| 10037 | if (is_hardware_watchpoint (b) |
| 10038 | && w->watchpoint_triggered == watch_triggered_no) |
| 10039 | return 0; |
| 10040 | |
| 10041 | return 1; |
| 10042 | } |
| 10043 | |
| 10044 | static void |
| 10045 | check_status_watchpoint (bpstat bs) |
| 10046 | { |
| 10047 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
| 10048 | |
| 10049 | bpstat_check_watchpoint (bs); |
| 10050 | } |
| 10051 | |
| 10052 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10053 | hardware watchpoints. */ |
| 10054 | |
| 10055 | static int |
| 10056 | resources_needed_watchpoint (const struct bp_location *bl) |
| 10057 | { |
| 10058 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10059 | int length = w->exact? 1 : bl->length; |
| 10060 | |
| 10061 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
| 10062 | } |
| 10063 | |
| 10064 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
| 10065 | hardware watchpoints. */ |
| 10066 | |
| 10067 | static int |
| 10068 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
| 10069 | { |
| 10070 | /* Read and access watchpoints only work with hardware support. */ |
| 10071 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; |
| 10072 | } |
| 10073 | |
| 10074 | static enum print_stop_action |
| 10075 | print_it_watchpoint (bpstat bs) |
| 10076 | { |
| 10077 | struct breakpoint *b; |
| 10078 | enum print_stop_action result; |
| 10079 | struct watchpoint *w; |
| 10080 | struct ui_out *uiout = current_uiout; |
| 10081 | |
| 10082 | gdb_assert (bs->bp_location_at != NULL); |
| 10083 | |
| 10084 | b = bs->breakpoint_at; |
| 10085 | w = (struct watchpoint *) b; |
| 10086 | |
| 10087 | annotate_watchpoint (b->number); |
| 10088 | maybe_print_thread_hit_breakpoint (uiout); |
| 10089 | |
| 10090 | string_file stb; |
| 10091 | |
| 10092 | gdb::optional<ui_out_emit_tuple> tuple_emitter; |
| 10093 | switch (b->type) |
| 10094 | { |
| 10095 | case bp_watchpoint: |
| 10096 | case bp_hardware_watchpoint: |
| 10097 | if (uiout->is_mi_like_p ()) |
| 10098 | uiout->field_string |
| 10099 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 10100 | mention (b); |
| 10101 | tuple_emitter.emplace (uiout, "value"); |
| 10102 | uiout->text ("\nOld value = "); |
| 10103 | watchpoint_value_print (bs->old_val.get (), &stb); |
| 10104 | uiout->field_stream ("old", stb); |
| 10105 | uiout->text ("\nNew value = "); |
| 10106 | watchpoint_value_print (w->val.get (), &stb); |
| 10107 | uiout->field_stream ("new", stb); |
| 10108 | uiout->text ("\n"); |
| 10109 | /* More than one watchpoint may have been triggered. */ |
| 10110 | result = PRINT_UNKNOWN; |
| 10111 | break; |
| 10112 | |
| 10113 | case bp_read_watchpoint: |
| 10114 | if (uiout->is_mi_like_p ()) |
| 10115 | uiout->field_string |
| 10116 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 10117 | mention (b); |
| 10118 | tuple_emitter.emplace (uiout, "value"); |
| 10119 | uiout->text ("\nValue = "); |
| 10120 | watchpoint_value_print (w->val.get (), &stb); |
| 10121 | uiout->field_stream ("value", stb); |
| 10122 | uiout->text ("\n"); |
| 10123 | result = PRINT_UNKNOWN; |
| 10124 | break; |
| 10125 | |
| 10126 | case bp_access_watchpoint: |
| 10127 | if (bs->old_val != NULL) |
| 10128 | { |
| 10129 | if (uiout->is_mi_like_p ()) |
| 10130 | uiout->field_string |
| 10131 | ("reason", |
| 10132 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10133 | mention (b); |
| 10134 | tuple_emitter.emplace (uiout, "value"); |
| 10135 | uiout->text ("\nOld value = "); |
| 10136 | watchpoint_value_print (bs->old_val.get (), &stb); |
| 10137 | uiout->field_stream ("old", stb); |
| 10138 | uiout->text ("\nNew value = "); |
| 10139 | } |
| 10140 | else |
| 10141 | { |
| 10142 | mention (b); |
| 10143 | if (uiout->is_mi_like_p ()) |
| 10144 | uiout->field_string |
| 10145 | ("reason", |
| 10146 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10147 | tuple_emitter.emplace (uiout, "value"); |
| 10148 | uiout->text ("\nValue = "); |
| 10149 | } |
| 10150 | watchpoint_value_print (w->val.get (), &stb); |
| 10151 | uiout->field_stream ("new", stb); |
| 10152 | uiout->text ("\n"); |
| 10153 | result = PRINT_UNKNOWN; |
| 10154 | break; |
| 10155 | default: |
| 10156 | result = PRINT_UNKNOWN; |
| 10157 | } |
| 10158 | |
| 10159 | return result; |
| 10160 | } |
| 10161 | |
| 10162 | /* Implement the "print_mention" breakpoint_ops method for hardware |
| 10163 | watchpoints. */ |
| 10164 | |
| 10165 | static void |
| 10166 | print_mention_watchpoint (struct breakpoint *b) |
| 10167 | { |
| 10168 | struct watchpoint *w = (struct watchpoint *) b; |
| 10169 | struct ui_out *uiout = current_uiout; |
| 10170 | const char *tuple_name; |
| 10171 | |
| 10172 | switch (b->type) |
| 10173 | { |
| 10174 | case bp_watchpoint: |
| 10175 | uiout->text ("Watchpoint "); |
| 10176 | tuple_name = "wpt"; |
| 10177 | break; |
| 10178 | case bp_hardware_watchpoint: |
| 10179 | uiout->text ("Hardware watchpoint "); |
| 10180 | tuple_name = "wpt"; |
| 10181 | break; |
| 10182 | case bp_read_watchpoint: |
| 10183 | uiout->text ("Hardware read watchpoint "); |
| 10184 | tuple_name = "hw-rwpt"; |
| 10185 | break; |
| 10186 | case bp_access_watchpoint: |
| 10187 | uiout->text ("Hardware access (read/write) watchpoint "); |
| 10188 | tuple_name = "hw-awpt"; |
| 10189 | break; |
| 10190 | default: |
| 10191 | internal_error (__FILE__, __LINE__, |
| 10192 | _("Invalid hardware watchpoint type.")); |
| 10193 | } |
| 10194 | |
| 10195 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
| 10196 | uiout->field_signed ("number", b->number); |
| 10197 | uiout->text (": "); |
| 10198 | uiout->field_string ("exp", w->exp_string); |
| 10199 | } |
| 10200 | |
| 10201 | /* Implement the "print_recreate" breakpoint_ops method for |
| 10202 | watchpoints. */ |
| 10203 | |
| 10204 | static void |
| 10205 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) |
| 10206 | { |
| 10207 | struct watchpoint *w = (struct watchpoint *) b; |
| 10208 | |
| 10209 | switch (b->type) |
| 10210 | { |
| 10211 | case bp_watchpoint: |
| 10212 | case bp_hardware_watchpoint: |
| 10213 | fprintf_unfiltered (fp, "watch"); |
| 10214 | break; |
| 10215 | case bp_read_watchpoint: |
| 10216 | fprintf_unfiltered (fp, "rwatch"); |
| 10217 | break; |
| 10218 | case bp_access_watchpoint: |
| 10219 | fprintf_unfiltered (fp, "awatch"); |
| 10220 | break; |
| 10221 | default: |
| 10222 | internal_error (__FILE__, __LINE__, |
| 10223 | _("Invalid watchpoint type.")); |
| 10224 | } |
| 10225 | |
| 10226 | fprintf_unfiltered (fp, " %s", w->exp_string); |
| 10227 | print_recreate_thread (b, fp); |
| 10228 | } |
| 10229 | |
| 10230 | /* Implement the "explains_signal" breakpoint_ops method for |
| 10231 | watchpoints. */ |
| 10232 | |
| 10233 | static int |
| 10234 | explains_signal_watchpoint (struct breakpoint *b, enum gdb_signal sig) |
| 10235 | { |
| 10236 | /* A software watchpoint cannot cause a signal other than |
| 10237 | GDB_SIGNAL_TRAP. */ |
| 10238 | if (b->type == bp_watchpoint && sig != GDB_SIGNAL_TRAP) |
| 10239 | return 0; |
| 10240 | |
| 10241 | return 1; |
| 10242 | } |
| 10243 | |
| 10244 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
| 10245 | |
| 10246 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
| 10247 | |
| 10248 | /* Implement the "insert" breakpoint_ops method for |
| 10249 | masked hardware watchpoints. */ |
| 10250 | |
| 10251 | static int |
| 10252 | insert_masked_watchpoint (struct bp_location *bl) |
| 10253 | { |
| 10254 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10255 | |
| 10256 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, |
| 10257 | bl->watchpoint_type); |
| 10258 | } |
| 10259 | |
| 10260 | /* Implement the "remove" breakpoint_ops method for |
| 10261 | masked hardware watchpoints. */ |
| 10262 | |
| 10263 | static int |
| 10264 | remove_masked_watchpoint (struct bp_location *bl, enum remove_bp_reason reason) |
| 10265 | { |
| 10266 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10267 | |
| 10268 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, |
| 10269 | bl->watchpoint_type); |
| 10270 | } |
| 10271 | |
| 10272 | /* Implement the "resources_needed" breakpoint_ops method for |
| 10273 | masked hardware watchpoints. */ |
| 10274 | |
| 10275 | static int |
| 10276 | resources_needed_masked_watchpoint (const struct bp_location *bl) |
| 10277 | { |
| 10278 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
| 10279 | |
| 10280 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); |
| 10281 | } |
| 10282 | |
| 10283 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
| 10284 | masked hardware watchpoints. */ |
| 10285 | |
| 10286 | static int |
| 10287 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) |
| 10288 | { |
| 10289 | return 0; |
| 10290 | } |
| 10291 | |
| 10292 | /* Implement the "print_it" breakpoint_ops method for |
| 10293 | masked hardware watchpoints. */ |
| 10294 | |
| 10295 | static enum print_stop_action |
| 10296 | print_it_masked_watchpoint (bpstat bs) |
| 10297 | { |
| 10298 | struct breakpoint *b = bs->breakpoint_at; |
| 10299 | struct ui_out *uiout = current_uiout; |
| 10300 | |
| 10301 | /* Masked watchpoints have only one location. */ |
| 10302 | gdb_assert (b->loc && b->loc->next == NULL); |
| 10303 | |
| 10304 | annotate_watchpoint (b->number); |
| 10305 | maybe_print_thread_hit_breakpoint (uiout); |
| 10306 | |
| 10307 | switch (b->type) |
| 10308 | { |
| 10309 | case bp_hardware_watchpoint: |
| 10310 | if (uiout->is_mi_like_p ()) |
| 10311 | uiout->field_string |
| 10312 | ("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); |
| 10313 | break; |
| 10314 | |
| 10315 | case bp_read_watchpoint: |
| 10316 | if (uiout->is_mi_like_p ()) |
| 10317 | uiout->field_string |
| 10318 | ("reason", async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); |
| 10319 | break; |
| 10320 | |
| 10321 | case bp_access_watchpoint: |
| 10322 | if (uiout->is_mi_like_p ()) |
| 10323 | uiout->field_string |
| 10324 | ("reason", |
| 10325 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); |
| 10326 | break; |
| 10327 | default: |
| 10328 | internal_error (__FILE__, __LINE__, |
| 10329 | _("Invalid hardware watchpoint type.")); |
| 10330 | } |
| 10331 | |
| 10332 | mention (b); |
| 10333 | uiout->text (_("\n\ |
| 10334 | Check the underlying instruction at PC for the memory\n\ |
| 10335 | address and value which triggered this watchpoint.\n")); |
| 10336 | uiout->text ("\n"); |
| 10337 | |
| 10338 | /* More than one watchpoint may have been triggered. */ |
| 10339 | return PRINT_UNKNOWN; |
| 10340 | } |
| 10341 | |
| 10342 | /* Implement the "print_one_detail" breakpoint_ops method for |
| 10343 | masked hardware watchpoints. */ |
| 10344 | |
| 10345 | static void |
| 10346 | print_one_detail_masked_watchpoint (const struct breakpoint *b, |
| 10347 | struct ui_out *uiout) |
| 10348 | { |
| 10349 | struct watchpoint *w = (struct watchpoint *) b; |
| 10350 | |
| 10351 | /* Masked watchpoints have only one location. */ |
| 10352 | gdb_assert (b->loc && b->loc->next == NULL); |
| 10353 | |
| 10354 | uiout->text ("\tmask "); |
| 10355 | uiout->field_core_addr ("mask", b->loc->gdbarch, w->hw_wp_mask); |
| 10356 | uiout->text ("\n"); |
| 10357 | } |
| 10358 | |
| 10359 | /* Implement the "print_mention" breakpoint_ops method for |
| 10360 | masked hardware watchpoints. */ |
| 10361 | |
| 10362 | static void |
| 10363 | print_mention_masked_watchpoint (struct breakpoint *b) |
| 10364 | { |
| 10365 | struct watchpoint *w = (struct watchpoint *) b; |
| 10366 | struct ui_out *uiout = current_uiout; |
| 10367 | const char *tuple_name; |
| 10368 | |
| 10369 | switch (b->type) |
| 10370 | { |
| 10371 | case bp_hardware_watchpoint: |
| 10372 | uiout->text ("Masked hardware watchpoint "); |
| 10373 | tuple_name = "wpt"; |
| 10374 | break; |
| 10375 | case bp_read_watchpoint: |
| 10376 | uiout->text ("Masked hardware read watchpoint "); |
| 10377 | tuple_name = "hw-rwpt"; |
| 10378 | break; |
| 10379 | case bp_access_watchpoint: |
| 10380 | uiout->text ("Masked hardware access (read/write) watchpoint "); |
| 10381 | tuple_name = "hw-awpt"; |
| 10382 | break; |
| 10383 | default: |
| 10384 | internal_error (__FILE__, __LINE__, |
| 10385 | _("Invalid hardware watchpoint type.")); |
| 10386 | } |
| 10387 | |
| 10388 | ui_out_emit_tuple tuple_emitter (uiout, tuple_name); |
| 10389 | uiout->field_signed ("number", b->number); |
| 10390 | uiout->text (": "); |
| 10391 | uiout->field_string ("exp", w->exp_string); |
| 10392 | } |
| 10393 | |
| 10394 | /* Implement the "print_recreate" breakpoint_ops method for |
| 10395 | masked hardware watchpoints. */ |
| 10396 | |
| 10397 | static void |
| 10398 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) |
| 10399 | { |
| 10400 | struct watchpoint *w = (struct watchpoint *) b; |
| 10401 | char tmp[40]; |
| 10402 | |
| 10403 | switch (b->type) |
| 10404 | { |
| 10405 | case bp_hardware_watchpoint: |
| 10406 | fprintf_unfiltered (fp, "watch"); |
| 10407 | break; |
| 10408 | case bp_read_watchpoint: |
| 10409 | fprintf_unfiltered (fp, "rwatch"); |
| 10410 | break; |
| 10411 | case bp_access_watchpoint: |
| 10412 | fprintf_unfiltered (fp, "awatch"); |
| 10413 | break; |
| 10414 | default: |
| 10415 | internal_error (__FILE__, __LINE__, |
| 10416 | _("Invalid hardware watchpoint type.")); |
| 10417 | } |
| 10418 | |
| 10419 | sprintf_vma (tmp, w->hw_wp_mask); |
| 10420 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); |
| 10421 | print_recreate_thread (b, fp); |
| 10422 | } |
| 10423 | |
| 10424 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ |
| 10425 | |
| 10426 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
| 10427 | |
| 10428 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ |
| 10429 | |
| 10430 | static bool |
| 10431 | is_masked_watchpoint (const struct breakpoint *b) |
| 10432 | { |
| 10433 | return b->ops == &masked_watchpoint_breakpoint_ops; |
| 10434 | } |
| 10435 | |
| 10436 | /* accessflag: hw_write: watch write, |
| 10437 | hw_read: watch read, |
| 10438 | hw_access: watch access (read or write) */ |
| 10439 | static void |
| 10440 | watch_command_1 (const char *arg, int accessflag, int from_tty, |
| 10441 | int just_location, int internal) |
| 10442 | { |
| 10443 | struct breakpoint *scope_breakpoint = NULL; |
| 10444 | const struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
| 10445 | struct value *result; |
| 10446 | int saved_bitpos = 0, saved_bitsize = 0; |
| 10447 | const char *exp_start = NULL; |
| 10448 | const char *exp_end = NULL; |
| 10449 | const char *tok, *end_tok; |
| 10450 | int toklen = -1; |
| 10451 | const char *cond_start = NULL; |
| 10452 | const char *cond_end = NULL; |
| 10453 | enum bptype bp_type; |
| 10454 | int thread = -1; |
| 10455 | int pc = 0; |
| 10456 | /* Flag to indicate whether we are going to use masks for |
| 10457 | the hardware watchpoint. */ |
| 10458 | int use_mask = 0; |
| 10459 | CORE_ADDR mask = 0; |
| 10460 | |
| 10461 | /* Make sure that we actually have parameters to parse. */ |
| 10462 | if (arg != NULL && arg[0] != '\0') |
| 10463 | { |
| 10464 | const char *value_start; |
| 10465 | |
| 10466 | exp_end = arg + strlen (arg); |
| 10467 | |
| 10468 | /* Look for "parameter value" pairs at the end |
| 10469 | of the arguments string. */ |
| 10470 | for (tok = exp_end - 1; tok > arg; tok--) |
| 10471 | { |
| 10472 | /* Skip whitespace at the end of the argument list. */ |
| 10473 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 10474 | tok--; |
| 10475 | |
| 10476 | /* Find the beginning of the last token. |
| 10477 | This is the value of the parameter. */ |
| 10478 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 10479 | tok--; |
| 10480 | value_start = tok + 1; |
| 10481 | |
| 10482 | /* Skip whitespace. */ |
| 10483 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
| 10484 | tok--; |
| 10485 | |
| 10486 | end_tok = tok; |
| 10487 | |
| 10488 | /* Find the beginning of the second to last token. |
| 10489 | This is the parameter itself. */ |
| 10490 | while (tok > arg && (*tok != ' ' && *tok != '\t')) |
| 10491 | tok--; |
| 10492 | tok++; |
| 10493 | toklen = end_tok - tok + 1; |
| 10494 | |
| 10495 | if (toklen == 6 && startswith (tok, "thread")) |
| 10496 | { |
| 10497 | struct thread_info *thr; |
| 10498 | /* At this point we've found a "thread" token, which means |
| 10499 | the user is trying to set a watchpoint that triggers |
| 10500 | only in a specific thread. */ |
| 10501 | const char *endp; |
| 10502 | |
| 10503 | if (thread != -1) |
| 10504 | error(_("You can specify only one thread.")); |
| 10505 | |
| 10506 | /* Extract the thread ID from the next token. */ |
| 10507 | thr = parse_thread_id (value_start, &endp); |
| 10508 | |
| 10509 | /* Check if the user provided a valid thread ID. */ |
| 10510 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') |
| 10511 | invalid_thread_id_error (value_start); |
| 10512 | |
| 10513 | thread = thr->global_num; |
| 10514 | } |
| 10515 | else if (toklen == 4 && startswith (tok, "mask")) |
| 10516 | { |
| 10517 | /* We've found a "mask" token, which means the user wants to |
| 10518 | create a hardware watchpoint that is going to have the mask |
| 10519 | facility. */ |
| 10520 | struct value *mask_value, *mark; |
| 10521 | |
| 10522 | if (use_mask) |
| 10523 | error(_("You can specify only one mask.")); |
| 10524 | |
| 10525 | use_mask = just_location = 1; |
| 10526 | |
| 10527 | mark = value_mark (); |
| 10528 | mask_value = parse_to_comma_and_eval (&value_start); |
| 10529 | mask = value_as_address (mask_value); |
| 10530 | value_free_to_mark (mark); |
| 10531 | } |
| 10532 | else |
| 10533 | /* We didn't recognize what we found. We should stop here. */ |
| 10534 | break; |
| 10535 | |
| 10536 | /* Truncate the string and get rid of the "parameter value" pair before |
| 10537 | the arguments string is parsed by the parse_exp_1 function. */ |
| 10538 | exp_end = tok; |
| 10539 | } |
| 10540 | } |
| 10541 | else |
| 10542 | exp_end = arg; |
| 10543 | |
| 10544 | /* Parse the rest of the arguments. From here on out, everything |
| 10545 | is in terms of a newly allocated string instead of the original |
| 10546 | ARG. */ |
| 10547 | std::string expression (arg, exp_end - arg); |
| 10548 | exp_start = arg = expression.c_str (); |
| 10549 | innermost_block_tracker tracker; |
| 10550 | expression_up exp = parse_exp_1 (&arg, 0, 0, 0, &tracker); |
| 10551 | exp_end = arg; |
| 10552 | /* Remove trailing whitespace from the expression before saving it. |
| 10553 | This makes the eventual display of the expression string a bit |
| 10554 | prettier. */ |
| 10555 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) |
| 10556 | --exp_end; |
| 10557 | |
| 10558 | /* Checking if the expression is not constant. */ |
| 10559 | if (watchpoint_exp_is_const (exp.get ())) |
| 10560 | { |
| 10561 | int len; |
| 10562 | |
| 10563 | len = exp_end - exp_start; |
| 10564 | while (len > 0 && isspace (exp_start[len - 1])) |
| 10565 | len--; |
| 10566 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); |
| 10567 | } |
| 10568 | |
| 10569 | exp_valid_block = tracker.block (); |
| 10570 | struct value *mark = value_mark (); |
| 10571 | struct value *val_as_value = nullptr; |
| 10572 | fetch_subexp_value (exp.get (), &pc, &val_as_value, &result, NULL, |
| 10573 | just_location); |
| 10574 | |
| 10575 | if (val_as_value != NULL && just_location) |
| 10576 | { |
| 10577 | saved_bitpos = value_bitpos (val_as_value); |
| 10578 | saved_bitsize = value_bitsize (val_as_value); |
| 10579 | } |
| 10580 | |
| 10581 | value_ref_ptr val; |
| 10582 | if (just_location) |
| 10583 | { |
| 10584 | int ret; |
| 10585 | |
| 10586 | exp_valid_block = NULL; |
| 10587 | val = release_value (value_addr (result)); |
| 10588 | value_free_to_mark (mark); |
| 10589 | |
| 10590 | if (use_mask) |
| 10591 | { |
| 10592 | ret = target_masked_watch_num_registers (value_as_address (val.get ()), |
| 10593 | mask); |
| 10594 | if (ret == -1) |
| 10595 | error (_("This target does not support masked watchpoints.")); |
| 10596 | else if (ret == -2) |
| 10597 | error (_("Invalid mask or memory region.")); |
| 10598 | } |
| 10599 | } |
| 10600 | else if (val_as_value != NULL) |
| 10601 | val = release_value (val_as_value); |
| 10602 | |
| 10603 | tok = skip_spaces (arg); |
| 10604 | end_tok = skip_to_space (tok); |
| 10605 | |
| 10606 | toklen = end_tok - tok; |
| 10607 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 10608 | { |
| 10609 | tok = cond_start = end_tok + 1; |
| 10610 | innermost_block_tracker if_tracker; |
| 10611 | parse_exp_1 (&tok, 0, 0, 0, &if_tracker); |
| 10612 | |
| 10613 | /* The watchpoint expression may not be local, but the condition |
| 10614 | may still be. E.g.: `watch global if local > 0'. */ |
| 10615 | cond_exp_valid_block = if_tracker.block (); |
| 10616 | |
| 10617 | cond_end = tok; |
| 10618 | } |
| 10619 | if (*tok) |
| 10620 | error (_("Junk at end of command.")); |
| 10621 | |
| 10622 | frame_info *wp_frame = block_innermost_frame (exp_valid_block); |
| 10623 | |
| 10624 | /* Save this because create_internal_breakpoint below invalidates |
| 10625 | 'wp_frame'. */ |
| 10626 | frame_id watchpoint_frame = get_frame_id (wp_frame); |
| 10627 | |
| 10628 | /* If the expression is "local", then set up a "watchpoint scope" |
| 10629 | breakpoint at the point where we've left the scope of the watchpoint |
| 10630 | expression. Create the scope breakpoint before the watchpoint, so |
| 10631 | that we will encounter it first in bpstat_stop_status. */ |
| 10632 | if (exp_valid_block != NULL && wp_frame != NULL) |
| 10633 | { |
| 10634 | frame_id caller_frame_id = frame_unwind_caller_id (wp_frame); |
| 10635 | |
| 10636 | if (frame_id_p (caller_frame_id)) |
| 10637 | { |
| 10638 | gdbarch *caller_arch = frame_unwind_caller_arch (wp_frame); |
| 10639 | CORE_ADDR caller_pc = frame_unwind_caller_pc (wp_frame); |
| 10640 | |
| 10641 | scope_breakpoint |
| 10642 | = create_internal_breakpoint (caller_arch, caller_pc, |
| 10643 | bp_watchpoint_scope, |
| 10644 | &momentary_breakpoint_ops); |
| 10645 | |
| 10646 | /* create_internal_breakpoint could invalidate WP_FRAME. */ |
| 10647 | wp_frame = NULL; |
| 10648 | |
| 10649 | scope_breakpoint->enable_state = bp_enabled; |
| 10650 | |
| 10651 | /* Automatically delete the breakpoint when it hits. */ |
| 10652 | scope_breakpoint->disposition = disp_del; |
| 10653 | |
| 10654 | /* Only break in the proper frame (help with recursion). */ |
| 10655 | scope_breakpoint->frame_id = caller_frame_id; |
| 10656 | |
| 10657 | /* Set the address at which we will stop. */ |
| 10658 | scope_breakpoint->loc->gdbarch = caller_arch; |
| 10659 | scope_breakpoint->loc->requested_address = caller_pc; |
| 10660 | scope_breakpoint->loc->address |
| 10661 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
| 10662 | scope_breakpoint->loc->requested_address, |
| 10663 | scope_breakpoint->type); |
| 10664 | } |
| 10665 | } |
| 10666 | |
| 10667 | /* Now set up the breakpoint. We create all watchpoints as hardware |
| 10668 | watchpoints here even if hardware watchpoints are turned off, a call |
| 10669 | to update_watchpoint later in this function will cause the type to |
| 10670 | drop back to bp_watchpoint (software watchpoint) if required. */ |
| 10671 | |
| 10672 | if (accessflag == hw_read) |
| 10673 | bp_type = bp_read_watchpoint; |
| 10674 | else if (accessflag == hw_access) |
| 10675 | bp_type = bp_access_watchpoint; |
| 10676 | else |
| 10677 | bp_type = bp_hardware_watchpoint; |
| 10678 | |
| 10679 | std::unique_ptr<watchpoint> w (new watchpoint ()); |
| 10680 | |
| 10681 | if (use_mask) |
| 10682 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
| 10683 | &masked_watchpoint_breakpoint_ops); |
| 10684 | else |
| 10685 | init_raw_breakpoint_without_location (w.get (), NULL, bp_type, |
| 10686 | &watchpoint_breakpoint_ops); |
| 10687 | w->thread = thread; |
| 10688 | w->disposition = disp_donttouch; |
| 10689 | w->pspace = current_program_space; |
| 10690 | w->exp = std::move (exp); |
| 10691 | w->exp_valid_block = exp_valid_block; |
| 10692 | w->cond_exp_valid_block = cond_exp_valid_block; |
| 10693 | if (just_location) |
| 10694 | { |
| 10695 | struct type *t = value_type (val.get ()); |
| 10696 | CORE_ADDR addr = value_as_address (val.get ()); |
| 10697 | |
| 10698 | w->exp_string_reparse |
| 10699 | = current_language->la_watch_location_expression (t, addr).release (); |
| 10700 | |
| 10701 | w->exp_string = xstrprintf ("-location %.*s", |
| 10702 | (int) (exp_end - exp_start), exp_start); |
| 10703 | } |
| 10704 | else |
| 10705 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
| 10706 | |
| 10707 | if (use_mask) |
| 10708 | { |
| 10709 | w->hw_wp_mask = mask; |
| 10710 | } |
| 10711 | else |
| 10712 | { |
| 10713 | w->val = val; |
| 10714 | w->val_bitpos = saved_bitpos; |
| 10715 | w->val_bitsize = saved_bitsize; |
| 10716 | w->val_valid = true; |
| 10717 | } |
| 10718 | |
| 10719 | if (cond_start) |
| 10720 | w->cond_string = savestring (cond_start, cond_end - cond_start); |
| 10721 | else |
| 10722 | w->cond_string = 0; |
| 10723 | |
| 10724 | if (frame_id_p (watchpoint_frame)) |
| 10725 | { |
| 10726 | w->watchpoint_frame = watchpoint_frame; |
| 10727 | w->watchpoint_thread = inferior_ptid; |
| 10728 | } |
| 10729 | else |
| 10730 | { |
| 10731 | w->watchpoint_frame = null_frame_id; |
| 10732 | w->watchpoint_thread = null_ptid; |
| 10733 | } |
| 10734 | |
| 10735 | if (scope_breakpoint != NULL) |
| 10736 | { |
| 10737 | /* The scope breakpoint is related to the watchpoint. We will |
| 10738 | need to act on them together. */ |
| 10739 | w->related_breakpoint = scope_breakpoint; |
| 10740 | scope_breakpoint->related_breakpoint = w.get (); |
| 10741 | } |
| 10742 | |
| 10743 | if (!just_location) |
| 10744 | value_free_to_mark (mark); |
| 10745 | |
| 10746 | /* Finally update the new watchpoint. This creates the locations |
| 10747 | that should be inserted. */ |
| 10748 | update_watchpoint (w.get (), 1); |
| 10749 | |
| 10750 | install_breakpoint (internal, std::move (w), 1); |
| 10751 | } |
| 10752 | |
| 10753 | /* Return count of debug registers needed to watch the given expression. |
| 10754 | If the watchpoint cannot be handled in hardware return zero. */ |
| 10755 | |
| 10756 | static int |
| 10757 | can_use_hardware_watchpoint (const std::vector<value_ref_ptr> &vals) |
| 10758 | { |
| 10759 | int found_memory_cnt = 0; |
| 10760 | |
| 10761 | /* Did the user specifically forbid us to use hardware watchpoints? */ |
| 10762 | if (!can_use_hw_watchpoints) |
| 10763 | return 0; |
| 10764 | |
| 10765 | gdb_assert (!vals.empty ()); |
| 10766 | struct value *head = vals[0].get (); |
| 10767 | |
| 10768 | /* Make sure that the value of the expression depends only upon |
| 10769 | memory contents, and values computed from them within GDB. If we |
| 10770 | find any register references or function calls, we can't use a |
| 10771 | hardware watchpoint. |
| 10772 | |
| 10773 | The idea here is that evaluating an expression generates a series |
| 10774 | of values, one holding the value of every subexpression. (The |
| 10775 | expression a*b+c has five subexpressions: a, b, a*b, c, and |
| 10776 | a*b+c.) GDB's values hold almost enough information to establish |
| 10777 | the criteria given above --- they identify memory lvalues, |
| 10778 | register lvalues, computed values, etcetera. So we can evaluate |
| 10779 | the expression, and then scan the chain of values that leaves |
| 10780 | behind to decide whether we can detect any possible change to the |
| 10781 | expression's final value using only hardware watchpoints. |
| 10782 | |
| 10783 | However, I don't think that the values returned by inferior |
| 10784 | function calls are special in any way. So this function may not |
| 10785 | notice that an expression involving an inferior function call |
| 10786 | can't be watched with hardware watchpoints. FIXME. */ |
| 10787 | for (const value_ref_ptr &iter : vals) |
| 10788 | { |
| 10789 | struct value *v = iter.get (); |
| 10790 | |
| 10791 | if (VALUE_LVAL (v) == lval_memory) |
| 10792 | { |
| 10793 | if (v != head && value_lazy (v)) |
| 10794 | /* A lazy memory lvalue in the chain is one that GDB never |
| 10795 | needed to fetch; we either just used its address (e.g., |
| 10796 | `a' in `a.b') or we never needed it at all (e.g., `a' |
| 10797 | in `a,b'). This doesn't apply to HEAD; if that is |
| 10798 | lazy then it was not readable, but watch it anyway. */ |
| 10799 | ; |
| 10800 | else |
| 10801 | { |
| 10802 | /* Ahh, memory we actually used! Check if we can cover |
| 10803 | it with hardware watchpoints. */ |
| 10804 | struct type *vtype = check_typedef (value_type (v)); |
| 10805 | |
| 10806 | /* We only watch structs and arrays if user asked for it |
| 10807 | explicitly, never if they just happen to appear in a |
| 10808 | middle of some value chain. */ |
| 10809 | if (v == head |
| 10810 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
| 10811 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) |
| 10812 | { |
| 10813 | CORE_ADDR vaddr = value_address (v); |
| 10814 | int len; |
| 10815 | int num_regs; |
| 10816 | |
| 10817 | len = (target_exact_watchpoints |
| 10818 | && is_scalar_type_recursive (vtype))? |
| 10819 | 1 : TYPE_LENGTH (value_type (v)); |
| 10820 | |
| 10821 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
| 10822 | if (!num_regs) |
| 10823 | return 0; |
| 10824 | else |
| 10825 | found_memory_cnt += num_regs; |
| 10826 | } |
| 10827 | } |
| 10828 | } |
| 10829 | else if (VALUE_LVAL (v) != not_lval |
| 10830 | && deprecated_value_modifiable (v) == 0) |
| 10831 | return 0; /* These are values from the history (e.g., $1). */ |
| 10832 | else if (VALUE_LVAL (v) == lval_register) |
| 10833 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
| 10834 | } |
| 10835 | |
| 10836 | /* The expression itself looks suitable for using a hardware |
| 10837 | watchpoint, but give the target machine a chance to reject it. */ |
| 10838 | return found_memory_cnt; |
| 10839 | } |
| 10840 | |
| 10841 | void |
| 10842 | watch_command_wrapper (const char *arg, int from_tty, int internal) |
| 10843 | { |
| 10844 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
| 10845 | } |
| 10846 | |
| 10847 | /* A helper function that looks for the "-location" argument and then |
| 10848 | calls watch_command_1. */ |
| 10849 | |
| 10850 | static void |
| 10851 | watch_maybe_just_location (const char *arg, int accessflag, int from_tty) |
| 10852 | { |
| 10853 | int just_location = 0; |
| 10854 | |
| 10855 | if (arg |
| 10856 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) |
| 10857 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) |
| 10858 | just_location = 1; |
| 10859 | |
| 10860 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
| 10861 | } |
| 10862 | |
| 10863 | static void |
| 10864 | watch_command (const char *arg, int from_tty) |
| 10865 | { |
| 10866 | watch_maybe_just_location (arg, hw_write, from_tty); |
| 10867 | } |
| 10868 | |
| 10869 | void |
| 10870 | rwatch_command_wrapper (const char *arg, int from_tty, int internal) |
| 10871 | { |
| 10872 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
| 10873 | } |
| 10874 | |
| 10875 | static void |
| 10876 | rwatch_command (const char *arg, int from_tty) |
| 10877 | { |
| 10878 | watch_maybe_just_location (arg, hw_read, from_tty); |
| 10879 | } |
| 10880 | |
| 10881 | void |
| 10882 | awatch_command_wrapper (const char *arg, int from_tty, int internal) |
| 10883 | { |
| 10884 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
| 10885 | } |
| 10886 | |
| 10887 | static void |
| 10888 | awatch_command (const char *arg, int from_tty) |
| 10889 | { |
| 10890 | watch_maybe_just_location (arg, hw_access, from_tty); |
| 10891 | } |
| 10892 | \f |
| 10893 | |
| 10894 | /* Data for the FSM that manages the until(location)/advance commands |
| 10895 | in infcmd.c. Here because it uses the mechanisms of |
| 10896 | breakpoints. */ |
| 10897 | |
| 10898 | struct until_break_fsm : public thread_fsm |
| 10899 | { |
| 10900 | /* The thread that was current when the command was executed. */ |
| 10901 | int thread; |
| 10902 | |
| 10903 | /* The breakpoint set at the destination location. */ |
| 10904 | breakpoint_up location_breakpoint; |
| 10905 | |
| 10906 | /* Breakpoint set at the return address in the caller frame. May be |
| 10907 | NULL. */ |
| 10908 | breakpoint_up caller_breakpoint; |
| 10909 | |
| 10910 | until_break_fsm (struct interp *cmd_interp, int thread, |
| 10911 | breakpoint_up &&location_breakpoint, |
| 10912 | breakpoint_up &&caller_breakpoint) |
| 10913 | : thread_fsm (cmd_interp), |
| 10914 | thread (thread), |
| 10915 | location_breakpoint (std::move (location_breakpoint)), |
| 10916 | caller_breakpoint (std::move (caller_breakpoint)) |
| 10917 | { |
| 10918 | } |
| 10919 | |
| 10920 | void clean_up (struct thread_info *thread) override; |
| 10921 | bool should_stop (struct thread_info *thread) override; |
| 10922 | enum async_reply_reason do_async_reply_reason () override; |
| 10923 | }; |
| 10924 | |
| 10925 | /* Implementation of the 'should_stop' FSM method for the |
| 10926 | until(location)/advance commands. */ |
| 10927 | |
| 10928 | bool |
| 10929 | until_break_fsm::should_stop (struct thread_info *tp) |
| 10930 | { |
| 10931 | if (bpstat_find_breakpoint (tp->control.stop_bpstat, |
| 10932 | location_breakpoint.get ()) != NULL |
| 10933 | || (caller_breakpoint != NULL |
| 10934 | && bpstat_find_breakpoint (tp->control.stop_bpstat, |
| 10935 | caller_breakpoint.get ()) != NULL)) |
| 10936 | set_finished (); |
| 10937 | |
| 10938 | return true; |
| 10939 | } |
| 10940 | |
| 10941 | /* Implementation of the 'clean_up' FSM method for the |
| 10942 | until(location)/advance commands. */ |
| 10943 | |
| 10944 | void |
| 10945 | until_break_fsm::clean_up (struct thread_info *) |
| 10946 | { |
| 10947 | /* Clean up our temporary breakpoints. */ |
| 10948 | location_breakpoint.reset (); |
| 10949 | caller_breakpoint.reset (); |
| 10950 | delete_longjmp_breakpoint (thread); |
| 10951 | } |
| 10952 | |
| 10953 | /* Implementation of the 'async_reply_reason' FSM method for the |
| 10954 | until(location)/advance commands. */ |
| 10955 | |
| 10956 | enum async_reply_reason |
| 10957 | until_break_fsm::do_async_reply_reason () |
| 10958 | { |
| 10959 | return EXEC_ASYNC_LOCATION_REACHED; |
| 10960 | } |
| 10961 | |
| 10962 | void |
| 10963 | until_break_command (const char *arg, int from_tty, int anywhere) |
| 10964 | { |
| 10965 | struct frame_info *frame; |
| 10966 | struct gdbarch *frame_gdbarch; |
| 10967 | struct frame_id stack_frame_id; |
| 10968 | struct frame_id caller_frame_id; |
| 10969 | int thread; |
| 10970 | struct thread_info *tp; |
| 10971 | |
| 10972 | clear_proceed_status (0); |
| 10973 | |
| 10974 | /* Set a breakpoint where the user wants it and at return from |
| 10975 | this function. */ |
| 10976 | |
| 10977 | event_location_up location = string_to_event_location (&arg, current_language); |
| 10978 | |
| 10979 | std::vector<symtab_and_line> sals |
| 10980 | = (last_displayed_sal_is_valid () |
| 10981 | ? decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, NULL, |
| 10982 | get_last_displayed_symtab (), |
| 10983 | get_last_displayed_line ()) |
| 10984 | : decode_line_1 (location.get (), DECODE_LINE_FUNFIRSTLINE, |
| 10985 | NULL, NULL, 0)); |
| 10986 | |
| 10987 | if (sals.size () != 1) |
| 10988 | error (_("Couldn't get information on specified line.")); |
| 10989 | |
| 10990 | symtab_and_line &sal = sals[0]; |
| 10991 | |
| 10992 | if (*arg) |
| 10993 | error (_("Junk at end of arguments.")); |
| 10994 | |
| 10995 | resolve_sal_pc (&sal); |
| 10996 | |
| 10997 | tp = inferior_thread (); |
| 10998 | thread = tp->global_num; |
| 10999 | |
| 11000 | /* Note linespec handling above invalidates the frame chain. |
| 11001 | Installing a breakpoint also invalidates the frame chain (as it |
| 11002 | may need to switch threads), so do any frame handling before |
| 11003 | that. */ |
| 11004 | |
| 11005 | frame = get_selected_frame (NULL); |
| 11006 | frame_gdbarch = get_frame_arch (frame); |
| 11007 | stack_frame_id = get_stack_frame_id (frame); |
| 11008 | caller_frame_id = frame_unwind_caller_id (frame); |
| 11009 | |
| 11010 | /* Keep within the current frame, or in frames called by the current |
| 11011 | one. */ |
| 11012 | |
| 11013 | breakpoint_up caller_breakpoint; |
| 11014 | |
| 11015 | gdb::optional<delete_longjmp_breakpoint_cleanup> lj_deleter; |
| 11016 | |
| 11017 | if (frame_id_p (caller_frame_id)) |
| 11018 | { |
| 11019 | struct symtab_and_line sal2; |
| 11020 | struct gdbarch *caller_gdbarch; |
| 11021 | |
| 11022 | sal2 = find_pc_line (frame_unwind_caller_pc (frame), 0); |
| 11023 | sal2.pc = frame_unwind_caller_pc (frame); |
| 11024 | caller_gdbarch = frame_unwind_caller_arch (frame); |
| 11025 | caller_breakpoint = set_momentary_breakpoint (caller_gdbarch, |
| 11026 | sal2, |
| 11027 | caller_frame_id, |
| 11028 | bp_until); |
| 11029 | |
| 11030 | set_longjmp_breakpoint (tp, caller_frame_id); |
| 11031 | lj_deleter.emplace (thread); |
| 11032 | } |
| 11033 | |
| 11034 | /* set_momentary_breakpoint could invalidate FRAME. */ |
| 11035 | frame = NULL; |
| 11036 | |
| 11037 | breakpoint_up location_breakpoint; |
| 11038 | if (anywhere) |
| 11039 | /* If the user told us to continue until a specified location, |
| 11040 | we don't specify a frame at which we need to stop. */ |
| 11041 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
| 11042 | null_frame_id, bp_until); |
| 11043 | else |
| 11044 | /* Otherwise, specify the selected frame, because we want to stop |
| 11045 | only at the very same frame. */ |
| 11046 | location_breakpoint = set_momentary_breakpoint (frame_gdbarch, sal, |
| 11047 | stack_frame_id, bp_until); |
| 11048 | |
| 11049 | tp->thread_fsm = new until_break_fsm (command_interp (), tp->global_num, |
| 11050 | std::move (location_breakpoint), |
| 11051 | std::move (caller_breakpoint)); |
| 11052 | |
| 11053 | if (lj_deleter) |
| 11054 | lj_deleter->release (); |
| 11055 | |
| 11056 | proceed (-1, GDB_SIGNAL_DEFAULT); |
| 11057 | } |
| 11058 | |
| 11059 | /* This function attempts to parse an optional "if <cond>" clause |
| 11060 | from the arg string. If one is not found, it returns NULL. |
| 11061 | |
| 11062 | Else, it returns a pointer to the condition string. (It does not |
| 11063 | attempt to evaluate the string against a particular block.) And, |
| 11064 | it updates arg to point to the first character following the parsed |
| 11065 | if clause in the arg string. */ |
| 11066 | |
| 11067 | const char * |
| 11068 | ep_parse_optional_if_clause (const char **arg) |
| 11069 | { |
| 11070 | const char *cond_string; |
| 11071 | |
| 11072 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) |
| 11073 | return NULL; |
| 11074 | |
| 11075 | /* Skip the "if" keyword. */ |
| 11076 | (*arg) += 2; |
| 11077 | |
| 11078 | /* Skip any extra leading whitespace, and record the start of the |
| 11079 | condition string. */ |
| 11080 | *arg = skip_spaces (*arg); |
| 11081 | cond_string = *arg; |
| 11082 | |
| 11083 | /* Assume that the condition occupies the remainder of the arg |
| 11084 | string. */ |
| 11085 | (*arg) += strlen (cond_string); |
| 11086 | |
| 11087 | return cond_string; |
| 11088 | } |
| 11089 | |
| 11090 | /* Commands to deal with catching events, such as signals, exceptions, |
| 11091 | process start/exit, etc. */ |
| 11092 | |
| 11093 | typedef enum |
| 11094 | { |
| 11095 | catch_fork_temporary, catch_vfork_temporary, |
| 11096 | catch_fork_permanent, catch_vfork_permanent |
| 11097 | } |
| 11098 | catch_fork_kind; |
| 11099 | |
| 11100 | static void |
| 11101 | catch_fork_command_1 (const char *arg, int from_tty, |
| 11102 | struct cmd_list_element *command) |
| 11103 | { |
| 11104 | struct gdbarch *gdbarch = get_current_arch (); |
| 11105 | const char *cond_string = NULL; |
| 11106 | catch_fork_kind fork_kind; |
| 11107 | int tempflag; |
| 11108 | |
| 11109 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); |
| 11110 | tempflag = (fork_kind == catch_fork_temporary |
| 11111 | || fork_kind == catch_vfork_temporary); |
| 11112 | |
| 11113 | if (!arg) |
| 11114 | arg = ""; |
| 11115 | arg = skip_spaces (arg); |
| 11116 | |
| 11117 | /* The allowed syntax is: |
| 11118 | catch [v]fork |
| 11119 | catch [v]fork if <cond> |
| 11120 | |
| 11121 | First, check if there's an if clause. */ |
| 11122 | cond_string = ep_parse_optional_if_clause (&arg); |
| 11123 | |
| 11124 | if ((*arg != '\0') && !isspace (*arg)) |
| 11125 | error (_("Junk at end of arguments.")); |
| 11126 | |
| 11127 | /* If this target supports it, create a fork or vfork catchpoint |
| 11128 | and enable reporting of such events. */ |
| 11129 | switch (fork_kind) |
| 11130 | { |
| 11131 | case catch_fork_temporary: |
| 11132 | case catch_fork_permanent: |
| 11133 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 11134 | &catch_fork_breakpoint_ops); |
| 11135 | break; |
| 11136 | case catch_vfork_temporary: |
| 11137 | case catch_vfork_permanent: |
| 11138 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
| 11139 | &catch_vfork_breakpoint_ops); |
| 11140 | break; |
| 11141 | default: |
| 11142 | error (_("unsupported or unknown fork kind; cannot catch it")); |
| 11143 | break; |
| 11144 | } |
| 11145 | } |
| 11146 | |
| 11147 | static void |
| 11148 | catch_exec_command_1 (const char *arg, int from_tty, |
| 11149 | struct cmd_list_element *command) |
| 11150 | { |
| 11151 | struct gdbarch *gdbarch = get_current_arch (); |
| 11152 | int tempflag; |
| 11153 | const char *cond_string = NULL; |
| 11154 | |
| 11155 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
| 11156 | |
| 11157 | if (!arg) |
| 11158 | arg = ""; |
| 11159 | arg = skip_spaces (arg); |
| 11160 | |
| 11161 | /* The allowed syntax is: |
| 11162 | catch exec |
| 11163 | catch exec if <cond> |
| 11164 | |
| 11165 | First, check if there's an if clause. */ |
| 11166 | cond_string = ep_parse_optional_if_clause (&arg); |
| 11167 | |
| 11168 | if ((*arg != '\0') && !isspace (*arg)) |
| 11169 | error (_("Junk at end of arguments.")); |
| 11170 | |
| 11171 | std::unique_ptr<exec_catchpoint> c (new exec_catchpoint ()); |
| 11172 | init_catchpoint (c.get (), gdbarch, tempflag, cond_string, |
| 11173 | &catch_exec_breakpoint_ops); |
| 11174 | c->exec_pathname = NULL; |
| 11175 | |
| 11176 | install_breakpoint (0, std::move (c), 1); |
| 11177 | } |
| 11178 | |
| 11179 | void |
| 11180 | init_ada_exception_breakpoint (struct breakpoint *b, |
| 11181 | struct gdbarch *gdbarch, |
| 11182 | struct symtab_and_line sal, |
| 11183 | const char *addr_string, |
| 11184 | const struct breakpoint_ops *ops, |
| 11185 | int tempflag, |
| 11186 | int enabled, |
| 11187 | int from_tty) |
| 11188 | { |
| 11189 | if (from_tty) |
| 11190 | { |
| 11191 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
| 11192 | if (!loc_gdbarch) |
| 11193 | loc_gdbarch = gdbarch; |
| 11194 | |
| 11195 | describe_other_breakpoints (loc_gdbarch, |
| 11196 | sal.pspace, sal.pc, sal.section, -1); |
| 11197 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
| 11198 | version for exception catchpoints, because two catchpoints |
| 11199 | used for different exception names will use the same address. |
| 11200 | In this case, a "breakpoint ... also set at..." warning is |
| 11201 | unproductive. Besides, the warning phrasing is also a bit |
| 11202 | inappropriate, we should use the word catchpoint, and tell |
| 11203 | the user what type of catchpoint it is. The above is good |
| 11204 | enough for now, though. */ |
| 11205 | } |
| 11206 | |
| 11207 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
| 11208 | |
| 11209 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
| 11210 | b->disposition = tempflag ? disp_del : disp_donttouch; |
| 11211 | b->location = string_to_event_location (&addr_string, |
| 11212 | language_def (language_ada)); |
| 11213 | b->language = language_ada; |
| 11214 | } |
| 11215 | |
| 11216 | static void |
| 11217 | catch_command (const char *arg, int from_tty) |
| 11218 | { |
| 11219 | error (_("Catch requires an event name.")); |
| 11220 | } |
| 11221 | \f |
| 11222 | |
| 11223 | static void |
| 11224 | tcatch_command (const char *arg, int from_tty) |
| 11225 | { |
| 11226 | error (_("Catch requires an event name.")); |
| 11227 | } |
| 11228 | |
| 11229 | /* Compare two breakpoints and return a strcmp-like result. */ |
| 11230 | |
| 11231 | static int |
| 11232 | compare_breakpoints (const breakpoint *a, const breakpoint *b) |
| 11233 | { |
| 11234 | uintptr_t ua = (uintptr_t) a; |
| 11235 | uintptr_t ub = (uintptr_t) b; |
| 11236 | |
| 11237 | if (a->number < b->number) |
| 11238 | return -1; |
| 11239 | else if (a->number > b->number) |
| 11240 | return 1; |
| 11241 | |
| 11242 | /* Now sort by address, in case we see, e..g, two breakpoints with |
| 11243 | the number 0. */ |
| 11244 | if (ua < ub) |
| 11245 | return -1; |
| 11246 | return ua > ub ? 1 : 0; |
| 11247 | } |
| 11248 | |
| 11249 | /* Delete breakpoints by address or line. */ |
| 11250 | |
| 11251 | static void |
| 11252 | clear_command (const char *arg, int from_tty) |
| 11253 | { |
| 11254 | struct breakpoint *b; |
| 11255 | int default_match; |
| 11256 | |
| 11257 | std::vector<symtab_and_line> decoded_sals; |
| 11258 | symtab_and_line last_sal; |
| 11259 | gdb::array_view<symtab_and_line> sals; |
| 11260 | if (arg) |
| 11261 | { |
| 11262 | decoded_sals |
| 11263 | = decode_line_with_current_source (arg, |
| 11264 | (DECODE_LINE_FUNFIRSTLINE |
| 11265 | | DECODE_LINE_LIST_MODE)); |
| 11266 | default_match = 0; |
| 11267 | sals = decoded_sals; |
| 11268 | } |
| 11269 | else |
| 11270 | { |
| 11271 | /* Set sal's line, symtab, pc, and pspace to the values |
| 11272 | corresponding to the last call to print_frame_info. If the |
| 11273 | codepoint is not valid, this will set all the fields to 0. */ |
| 11274 | last_sal = get_last_displayed_sal (); |
| 11275 | if (last_sal.symtab == 0) |
| 11276 | error (_("No source file specified.")); |
| 11277 | |
| 11278 | default_match = 1; |
| 11279 | sals = last_sal; |
| 11280 | } |
| 11281 | |
| 11282 | /* We don't call resolve_sal_pc here. That's not as bad as it |
| 11283 | seems, because all existing breakpoints typically have both |
| 11284 | file/line and pc set. So, if clear is given file/line, we can |
| 11285 | match this to existing breakpoint without obtaining pc at all. |
| 11286 | |
| 11287 | We only support clearing given the address explicitly |
| 11288 | present in breakpoint table. Say, we've set breakpoint |
| 11289 | at file:line. There were several PC values for that file:line, |
| 11290 | due to optimization, all in one block. |
| 11291 | |
| 11292 | We've picked one PC value. If "clear" is issued with another |
| 11293 | PC corresponding to the same file:line, the breakpoint won't |
| 11294 | be cleared. We probably can still clear the breakpoint, but |
| 11295 | since the other PC value is never presented to user, user |
| 11296 | can only find it by guessing, and it does not seem important |
| 11297 | to support that. */ |
| 11298 | |
| 11299 | /* For each line spec given, delete bps which correspond to it. Do |
| 11300 | it in two passes, solely to preserve the current behavior that |
| 11301 | from_tty is forced true if we delete more than one |
| 11302 | breakpoint. */ |
| 11303 | |
| 11304 | std::vector<struct breakpoint *> found; |
| 11305 | for (const auto &sal : sals) |
| 11306 | { |
| 11307 | const char *sal_fullname; |
| 11308 | |
| 11309 | /* If exact pc given, clear bpts at that pc. |
| 11310 | If line given (pc == 0), clear all bpts on specified line. |
| 11311 | If defaulting, clear all bpts on default line |
| 11312 | or at default pc. |
| 11313 | |
| 11314 | defaulting sal.pc != 0 tests to do |
| 11315 | |
| 11316 | 0 1 pc |
| 11317 | 1 1 pc _and_ line |
| 11318 | 0 0 line |
| 11319 | 1 0 <can't happen> */ |
| 11320 | |
| 11321 | sal_fullname = (sal.symtab == NULL |
| 11322 | ? NULL : symtab_to_fullname (sal.symtab)); |
| 11323 | |
| 11324 | /* Find all matching breakpoints and add them to 'found'. */ |
| 11325 | ALL_BREAKPOINTS (b) |
| 11326 | { |
| 11327 | int match = 0; |
| 11328 | /* Are we going to delete b? */ |
| 11329 | if (b->type != bp_none && !is_watchpoint (b)) |
| 11330 | { |
| 11331 | struct bp_location *loc = b->loc; |
| 11332 | for (; loc; loc = loc->next) |
| 11333 | { |
| 11334 | /* If the user specified file:line, don't allow a PC |
| 11335 | match. This matches historical gdb behavior. */ |
| 11336 | int pc_match = (!sal.explicit_line |
| 11337 | && sal.pc |
| 11338 | && (loc->pspace == sal.pspace) |
| 11339 | && (loc->address == sal.pc) |
| 11340 | && (!section_is_overlay (loc->section) |
| 11341 | || loc->section == sal.section)); |
| 11342 | int line_match = 0; |
| 11343 | |
| 11344 | if ((default_match || sal.explicit_line) |
| 11345 | && loc->symtab != NULL |
| 11346 | && sal_fullname != NULL |
| 11347 | && sal.pspace == loc->pspace |
| 11348 | && loc->line_number == sal.line |
| 11349 | && filename_cmp (symtab_to_fullname (loc->symtab), |
| 11350 | sal_fullname) == 0) |
| 11351 | line_match = 1; |
| 11352 | |
| 11353 | if (pc_match || line_match) |
| 11354 | { |
| 11355 | match = 1; |
| 11356 | break; |
| 11357 | } |
| 11358 | } |
| 11359 | } |
| 11360 | |
| 11361 | if (match) |
| 11362 | found.push_back (b); |
| 11363 | } |
| 11364 | } |
| 11365 | |
| 11366 | /* Now go thru the 'found' chain and delete them. */ |
| 11367 | if (found.empty ()) |
| 11368 | { |
| 11369 | if (arg) |
| 11370 | error (_("No breakpoint at %s."), arg); |
| 11371 | else |
| 11372 | error (_("No breakpoint at this line.")); |
| 11373 | } |
| 11374 | |
| 11375 | /* Remove duplicates from the vec. */ |
| 11376 | std::sort (found.begin (), found.end (), |
| 11377 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
| 11378 | { |
| 11379 | return compare_breakpoints (bp_a, bp_b) < 0; |
| 11380 | }); |
| 11381 | found.erase (std::unique (found.begin (), found.end (), |
| 11382 | [] (const breakpoint *bp_a, const breakpoint *bp_b) |
| 11383 | { |
| 11384 | return compare_breakpoints (bp_a, bp_b) == 0; |
| 11385 | }), |
| 11386 | found.end ()); |
| 11387 | |
| 11388 | if (found.size () > 1) |
| 11389 | from_tty = 1; /* Always report if deleted more than one. */ |
| 11390 | if (from_tty) |
| 11391 | { |
| 11392 | if (found.size () == 1) |
| 11393 | printf_unfiltered (_("Deleted breakpoint ")); |
| 11394 | else |
| 11395 | printf_unfiltered (_("Deleted breakpoints ")); |
| 11396 | } |
| 11397 | |
| 11398 | for (breakpoint *iter : found) |
| 11399 | { |
| 11400 | if (from_tty) |
| 11401 | printf_unfiltered ("%d ", iter->number); |
| 11402 | delete_breakpoint (iter); |
| 11403 | } |
| 11404 | if (from_tty) |
| 11405 | putchar_unfiltered ('\n'); |
| 11406 | } |
| 11407 | \f |
| 11408 | /* Delete breakpoint in BS if they are `delete' breakpoints and |
| 11409 | all breakpoints that are marked for deletion, whether hit or not. |
| 11410 | This is called after any breakpoint is hit, or after errors. */ |
| 11411 | |
| 11412 | void |
| 11413 | breakpoint_auto_delete (bpstat bs) |
| 11414 | { |
| 11415 | struct breakpoint *b, *b_tmp; |
| 11416 | |
| 11417 | for (; bs; bs = bs->next) |
| 11418 | if (bs->breakpoint_at |
| 11419 | && bs->breakpoint_at->disposition == disp_del |
| 11420 | && bs->stop) |
| 11421 | delete_breakpoint (bs->breakpoint_at); |
| 11422 | |
| 11423 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 11424 | { |
| 11425 | if (b->disposition == disp_del_at_next_stop) |
| 11426 | delete_breakpoint (b); |
| 11427 | } |
| 11428 | } |
| 11429 | |
| 11430 | /* A comparison function for bp_location AP and BP being interfaced to |
| 11431 | qsort. Sort elements primarily by their ADDRESS (no matter what |
| 11432 | bl_address_is_meaningful says), secondarily by ordering first |
| 11433 | permanent elements and terciarily just ensuring the array is sorted |
| 11434 | stable way despite qsort being an unstable algorithm. */ |
| 11435 | |
| 11436 | static int |
| 11437 | bp_locations_compare (const void *ap, const void *bp) |
| 11438 | { |
| 11439 | const struct bp_location *a = *(const struct bp_location **) ap; |
| 11440 | const struct bp_location *b = *(const struct bp_location **) bp; |
| 11441 | |
| 11442 | if (a->address != b->address) |
| 11443 | return (a->address > b->address) - (a->address < b->address); |
| 11444 | |
| 11445 | /* Sort locations at the same address by their pspace number, keeping |
| 11446 | locations of the same inferior (in a multi-inferior environment) |
| 11447 | grouped. */ |
| 11448 | |
| 11449 | if (a->pspace->num != b->pspace->num) |
| 11450 | return ((a->pspace->num > b->pspace->num) |
| 11451 | - (a->pspace->num < b->pspace->num)); |
| 11452 | |
| 11453 | /* Sort permanent breakpoints first. */ |
| 11454 | if (a->permanent != b->permanent) |
| 11455 | return (a->permanent < b->permanent) - (a->permanent > b->permanent); |
| 11456 | |
| 11457 | /* Make the internal GDB representation stable across GDB runs |
| 11458 | where A and B memory inside GDB can differ. Breakpoint locations of |
| 11459 | the same type at the same address can be sorted in arbitrary order. */ |
| 11460 | |
| 11461 | if (a->owner->number != b->owner->number) |
| 11462 | return ((a->owner->number > b->owner->number) |
| 11463 | - (a->owner->number < b->owner->number)); |
| 11464 | |
| 11465 | return (a > b) - (a < b); |
| 11466 | } |
| 11467 | |
| 11468 | /* Set bp_locations_placed_address_before_address_max and |
| 11469 | bp_locations_shadow_len_after_address_max according to the current |
| 11470 | content of the bp_locations array. */ |
| 11471 | |
| 11472 | static void |
| 11473 | bp_locations_target_extensions_update (void) |
| 11474 | { |
| 11475 | struct bp_location *bl, **blp_tmp; |
| 11476 | |
| 11477 | bp_locations_placed_address_before_address_max = 0; |
| 11478 | bp_locations_shadow_len_after_address_max = 0; |
| 11479 | |
| 11480 | ALL_BP_LOCATIONS (bl, blp_tmp) |
| 11481 | { |
| 11482 | CORE_ADDR start, end, addr; |
| 11483 | |
| 11484 | if (!bp_location_has_shadow (bl)) |
| 11485 | continue; |
| 11486 | |
| 11487 | start = bl->target_info.placed_address; |
| 11488 | end = start + bl->target_info.shadow_len; |
| 11489 | |
| 11490 | gdb_assert (bl->address >= start); |
| 11491 | addr = bl->address - start; |
| 11492 | if (addr > bp_locations_placed_address_before_address_max) |
| 11493 | bp_locations_placed_address_before_address_max = addr; |
| 11494 | |
| 11495 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ |
| 11496 | |
| 11497 | gdb_assert (bl->address < end); |
| 11498 | addr = end - bl->address; |
| 11499 | if (addr > bp_locations_shadow_len_after_address_max) |
| 11500 | bp_locations_shadow_len_after_address_max = addr; |
| 11501 | } |
| 11502 | } |
| 11503 | |
| 11504 | /* Download tracepoint locations if they haven't been. */ |
| 11505 | |
| 11506 | static void |
| 11507 | download_tracepoint_locations (void) |
| 11508 | { |
| 11509 | struct breakpoint *b; |
| 11510 | enum tribool can_download_tracepoint = TRIBOOL_UNKNOWN; |
| 11511 | |
| 11512 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 11513 | |
| 11514 | ALL_TRACEPOINTS (b) |
| 11515 | { |
| 11516 | struct bp_location *bl; |
| 11517 | struct tracepoint *t; |
| 11518 | int bp_location_downloaded = 0; |
| 11519 | |
| 11520 | if ((b->type == bp_fast_tracepoint |
| 11521 | ? !may_insert_fast_tracepoints |
| 11522 | : !may_insert_tracepoints)) |
| 11523 | continue; |
| 11524 | |
| 11525 | if (can_download_tracepoint == TRIBOOL_UNKNOWN) |
| 11526 | { |
| 11527 | if (target_can_download_tracepoint ()) |
| 11528 | can_download_tracepoint = TRIBOOL_TRUE; |
| 11529 | else |
| 11530 | can_download_tracepoint = TRIBOOL_FALSE; |
| 11531 | } |
| 11532 | |
| 11533 | if (can_download_tracepoint == TRIBOOL_FALSE) |
| 11534 | break; |
| 11535 | |
| 11536 | for (bl = b->loc; bl; bl = bl->next) |
| 11537 | { |
| 11538 | /* In tracepoint, locations are _never_ duplicated, so |
| 11539 | should_be_inserted is equivalent to |
| 11540 | unduplicated_should_be_inserted. */ |
| 11541 | if (!should_be_inserted (bl) || bl->inserted) |
| 11542 | continue; |
| 11543 | |
| 11544 | switch_to_program_space_and_thread (bl->pspace); |
| 11545 | |
| 11546 | target_download_tracepoint (bl); |
| 11547 | |
| 11548 | bl->inserted = 1; |
| 11549 | bp_location_downloaded = 1; |
| 11550 | } |
| 11551 | t = (struct tracepoint *) b; |
| 11552 | t->number_on_target = b->number; |
| 11553 | if (bp_location_downloaded) |
| 11554 | gdb::observers::breakpoint_modified.notify (b); |
| 11555 | } |
| 11556 | } |
| 11557 | |
| 11558 | /* Swap the insertion/duplication state between two locations. */ |
| 11559 | |
| 11560 | static void |
| 11561 | swap_insertion (struct bp_location *left, struct bp_location *right) |
| 11562 | { |
| 11563 | const int left_inserted = left->inserted; |
| 11564 | const int left_duplicate = left->duplicate; |
| 11565 | const int left_needs_update = left->needs_update; |
| 11566 | const struct bp_target_info left_target_info = left->target_info; |
| 11567 | |
| 11568 | /* Locations of tracepoints can never be duplicated. */ |
| 11569 | if (is_tracepoint (left->owner)) |
| 11570 | gdb_assert (!left->duplicate); |
| 11571 | if (is_tracepoint (right->owner)) |
| 11572 | gdb_assert (!right->duplicate); |
| 11573 | |
| 11574 | left->inserted = right->inserted; |
| 11575 | left->duplicate = right->duplicate; |
| 11576 | left->needs_update = right->needs_update; |
| 11577 | left->target_info = right->target_info; |
| 11578 | right->inserted = left_inserted; |
| 11579 | right->duplicate = left_duplicate; |
| 11580 | right->needs_update = left_needs_update; |
| 11581 | right->target_info = left_target_info; |
| 11582 | } |
| 11583 | |
| 11584 | /* Force the re-insertion of the locations at ADDRESS. This is called |
| 11585 | once a new/deleted/modified duplicate location is found and we are evaluating |
| 11586 | conditions on the target's side. Such conditions need to be updated on |
| 11587 | the target. */ |
| 11588 | |
| 11589 | static void |
| 11590 | force_breakpoint_reinsertion (struct bp_location *bl) |
| 11591 | { |
| 11592 | struct bp_location **locp = NULL, **loc2p; |
| 11593 | struct bp_location *loc; |
| 11594 | CORE_ADDR address = 0; |
| 11595 | int pspace_num; |
| 11596 | |
| 11597 | address = bl->address; |
| 11598 | pspace_num = bl->pspace->num; |
| 11599 | |
| 11600 | /* This is only meaningful if the target is |
| 11601 | evaluating conditions and if the user has |
| 11602 | opted for condition evaluation on the target's |
| 11603 | side. */ |
| 11604 | if (gdb_evaluates_breakpoint_condition_p () |
| 11605 | || !target_supports_evaluation_of_breakpoint_conditions ()) |
| 11606 | return; |
| 11607 | |
| 11608 | /* Flag all breakpoint locations with this address and |
| 11609 | the same program space as the location |
| 11610 | as "its condition has changed". We need to |
| 11611 | update the conditions on the target's side. */ |
| 11612 | ALL_BP_LOCATIONS_AT_ADDR (loc2p, locp, address) |
| 11613 | { |
| 11614 | loc = *loc2p; |
| 11615 | |
| 11616 | if (!is_breakpoint (loc->owner) |
| 11617 | || pspace_num != loc->pspace->num) |
| 11618 | continue; |
| 11619 | |
| 11620 | /* Flag the location appropriately. We use a different state to |
| 11621 | let everyone know that we already updated the set of locations |
| 11622 | with addr bl->address and program space bl->pspace. This is so |
| 11623 | we don't have to keep calling these functions just to mark locations |
| 11624 | that have already been marked. */ |
| 11625 | loc->condition_changed = condition_updated; |
| 11626 | |
| 11627 | /* Free the agent expression bytecode as well. We will compute |
| 11628 | it later on. */ |
| 11629 | loc->cond_bytecode.reset (); |
| 11630 | } |
| 11631 | } |
| 11632 | /* Called whether new breakpoints are created, or existing breakpoints |
| 11633 | deleted, to update the global location list and recompute which |
| 11634 | locations are duplicate of which. |
| 11635 | |
| 11636 | The INSERT_MODE flag determines whether locations may not, may, or |
| 11637 | shall be inserted now. See 'enum ugll_insert_mode' for more |
| 11638 | info. */ |
| 11639 | |
| 11640 | static void |
| 11641 | update_global_location_list (enum ugll_insert_mode insert_mode) |
| 11642 | { |
| 11643 | struct breakpoint *b; |
| 11644 | struct bp_location **locp, *loc; |
| 11645 | /* Last breakpoint location address that was marked for update. */ |
| 11646 | CORE_ADDR last_addr = 0; |
| 11647 | /* Last breakpoint location program space that was marked for update. */ |
| 11648 | int last_pspace_num = -1; |
| 11649 | |
| 11650 | /* Used in the duplicates detection below. When iterating over all |
| 11651 | bp_locations, points to the first bp_location of a given address. |
| 11652 | Breakpoints and watchpoints of different types are never |
| 11653 | duplicates of each other. Keep one pointer for each type of |
| 11654 | breakpoint/watchpoint, so we only need to loop over all locations |
| 11655 | once. */ |
| 11656 | struct bp_location *bp_loc_first; /* breakpoint */ |
| 11657 | struct bp_location *wp_loc_first; /* hardware watchpoint */ |
| 11658 | struct bp_location *awp_loc_first; /* access watchpoint */ |
| 11659 | struct bp_location *rwp_loc_first; /* read watchpoint */ |
| 11660 | |
| 11661 | /* Saved former bp_locations array which we compare against the newly |
| 11662 | built bp_locations from the current state of ALL_BREAKPOINTS. */ |
| 11663 | struct bp_location **old_locp; |
| 11664 | unsigned old_locations_count; |
| 11665 | gdb::unique_xmalloc_ptr<struct bp_location *> old_locations (bp_locations); |
| 11666 | |
| 11667 | old_locations_count = bp_locations_count; |
| 11668 | bp_locations = NULL; |
| 11669 | bp_locations_count = 0; |
| 11670 | |
| 11671 | ALL_BREAKPOINTS (b) |
| 11672 | for (loc = b->loc; loc; loc = loc->next) |
| 11673 | bp_locations_count++; |
| 11674 | |
| 11675 | bp_locations = XNEWVEC (struct bp_location *, bp_locations_count); |
| 11676 | locp = bp_locations; |
| 11677 | ALL_BREAKPOINTS (b) |
| 11678 | for (loc = b->loc; loc; loc = loc->next) |
| 11679 | *locp++ = loc; |
| 11680 | qsort (bp_locations, bp_locations_count, sizeof (*bp_locations), |
| 11681 | bp_locations_compare); |
| 11682 | |
| 11683 | bp_locations_target_extensions_update (); |
| 11684 | |
| 11685 | /* Identify bp_location instances that are no longer present in the |
| 11686 | new list, and therefore should be freed. Note that it's not |
| 11687 | necessary that those locations should be removed from inferior -- |
| 11688 | if there's another location at the same address (previously |
| 11689 | marked as duplicate), we don't need to remove/insert the |
| 11690 | location. |
| 11691 | |
| 11692 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
| 11693 | and former bp_location array state respectively. */ |
| 11694 | |
| 11695 | locp = bp_locations; |
| 11696 | for (old_locp = old_locations.get (); |
| 11697 | old_locp < old_locations.get () + old_locations_count; |
| 11698 | old_locp++) |
| 11699 | { |
| 11700 | struct bp_location *old_loc = *old_locp; |
| 11701 | struct bp_location **loc2p; |
| 11702 | |
| 11703 | /* Tells if 'old_loc' is found among the new locations. If |
| 11704 | not, we have to free it. */ |
| 11705 | int found_object = 0; |
| 11706 | /* Tells if the location should remain inserted in the target. */ |
| 11707 | int keep_in_target = 0; |
| 11708 | int removed = 0; |
| 11709 | |
| 11710 | /* Skip LOCP entries which will definitely never be needed. |
| 11711 | Stop either at or being the one matching OLD_LOC. */ |
| 11712 | while (locp < bp_locations + bp_locations_count |
| 11713 | && (*locp)->address < old_loc->address) |
| 11714 | locp++; |
| 11715 | |
| 11716 | for (loc2p = locp; |
| 11717 | (loc2p < bp_locations + bp_locations_count |
| 11718 | && (*loc2p)->address == old_loc->address); |
| 11719 | loc2p++) |
| 11720 | { |
| 11721 | /* Check if this is a new/duplicated location or a duplicated |
| 11722 | location that had its condition modified. If so, we want to send |
| 11723 | its condition to the target if evaluation of conditions is taking |
| 11724 | place there. */ |
| 11725 | if ((*loc2p)->condition_changed == condition_modified |
| 11726 | && (last_addr != old_loc->address |
| 11727 | || last_pspace_num != old_loc->pspace->num)) |
| 11728 | { |
| 11729 | force_breakpoint_reinsertion (*loc2p); |
| 11730 | last_pspace_num = old_loc->pspace->num; |
| 11731 | } |
| 11732 | |
| 11733 | if (*loc2p == old_loc) |
| 11734 | found_object = 1; |
| 11735 | } |
| 11736 | |
| 11737 | /* We have already handled this address, update it so that we don't |
| 11738 | have to go through updates again. */ |
| 11739 | last_addr = old_loc->address; |
| 11740 | |
| 11741 | /* Target-side condition evaluation: Handle deleted locations. */ |
| 11742 | if (!found_object) |
| 11743 | force_breakpoint_reinsertion (old_loc); |
| 11744 | |
| 11745 | /* If this location is no longer present, and inserted, look if |
| 11746 | there's maybe a new location at the same address. If so, |
| 11747 | mark that one inserted, and don't remove this one. This is |
| 11748 | needed so that we don't have a time window where a breakpoint |
| 11749 | at certain location is not inserted. */ |
| 11750 | |
| 11751 | if (old_loc->inserted) |
| 11752 | { |
| 11753 | /* If the location is inserted now, we might have to remove |
| 11754 | it. */ |
| 11755 | |
| 11756 | if (found_object && should_be_inserted (old_loc)) |
| 11757 | { |
| 11758 | /* The location is still present in the location list, |
| 11759 | and still should be inserted. Don't do anything. */ |
| 11760 | keep_in_target = 1; |
| 11761 | } |
| 11762 | else |
| 11763 | { |
| 11764 | /* This location still exists, but it won't be kept in the |
| 11765 | target since it may have been disabled. We proceed to |
| 11766 | remove its target-side condition. */ |
| 11767 | |
| 11768 | /* The location is either no longer present, or got |
| 11769 | disabled. See if there's another location at the |
| 11770 | same address, in which case we don't need to remove |
| 11771 | this one from the target. */ |
| 11772 | |
| 11773 | /* OLD_LOC comes from existing struct breakpoint. */ |
| 11774 | if (bl_address_is_meaningful (old_loc)) |
| 11775 | { |
| 11776 | for (loc2p = locp; |
| 11777 | (loc2p < bp_locations + bp_locations_count |
| 11778 | && (*loc2p)->address == old_loc->address); |
| 11779 | loc2p++) |
| 11780 | { |
| 11781 | struct bp_location *loc2 = *loc2p; |
| 11782 | |
| 11783 | if (breakpoint_locations_match (loc2, old_loc)) |
| 11784 | { |
| 11785 | /* Read watchpoint locations are switched to |
| 11786 | access watchpoints, if the former are not |
| 11787 | supported, but the latter are. */ |
| 11788 | if (is_hardware_watchpoint (old_loc->owner)) |
| 11789 | { |
| 11790 | gdb_assert (is_hardware_watchpoint (loc2->owner)); |
| 11791 | loc2->watchpoint_type = old_loc->watchpoint_type; |
| 11792 | } |
| 11793 | |
| 11794 | /* loc2 is a duplicated location. We need to check |
| 11795 | if it should be inserted in case it will be |
| 11796 | unduplicated. */ |
| 11797 | if (loc2 != old_loc |
| 11798 | && unduplicated_should_be_inserted (loc2)) |
| 11799 | { |
| 11800 | swap_insertion (old_loc, loc2); |
| 11801 | keep_in_target = 1; |
| 11802 | break; |
| 11803 | } |
| 11804 | } |
| 11805 | } |
| 11806 | } |
| 11807 | } |
| 11808 | |
| 11809 | if (!keep_in_target) |
| 11810 | { |
| 11811 | if (remove_breakpoint (old_loc)) |
| 11812 | { |
| 11813 | /* This is just about all we can do. We could keep |
| 11814 | this location on the global list, and try to |
| 11815 | remove it next time, but there's no particular |
| 11816 | reason why we will succeed next time. |
| 11817 | |
| 11818 | Note that at this point, old_loc->owner is still |
| 11819 | valid, as delete_breakpoint frees the breakpoint |
| 11820 | only after calling us. */ |
| 11821 | printf_filtered (_("warning: Error removing " |
| 11822 | "breakpoint %d\n"), |
| 11823 | old_loc->owner->number); |
| 11824 | } |
| 11825 | removed = 1; |
| 11826 | } |
| 11827 | } |
| 11828 | |
| 11829 | if (!found_object) |
| 11830 | { |
| 11831 | if (removed && target_is_non_stop_p () |
| 11832 | && need_moribund_for_location_type (old_loc)) |
| 11833 | { |
| 11834 | /* This location was removed from the target. In |
| 11835 | non-stop mode, a race condition is possible where |
| 11836 | we've removed a breakpoint, but stop events for that |
| 11837 | breakpoint are already queued and will arrive later. |
| 11838 | We apply an heuristic to be able to distinguish such |
| 11839 | SIGTRAPs from other random SIGTRAPs: we keep this |
| 11840 | breakpoint location for a bit, and will retire it |
| 11841 | after we see some number of events. The theory here |
| 11842 | is that reporting of events should, "on the average", |
| 11843 | be fair, so after a while we'll see events from all |
| 11844 | threads that have anything of interest, and no longer |
| 11845 | need to keep this breakpoint location around. We |
| 11846 | don't hold locations forever so to reduce chances of |
| 11847 | mistaking a non-breakpoint SIGTRAP for a breakpoint |
| 11848 | SIGTRAP. |
| 11849 | |
| 11850 | The heuristic failing can be disastrous on |
| 11851 | decr_pc_after_break targets. |
| 11852 | |
| 11853 | On decr_pc_after_break targets, like e.g., x86-linux, |
| 11854 | if we fail to recognize a late breakpoint SIGTRAP, |
| 11855 | because events_till_retirement has reached 0 too |
| 11856 | soon, we'll fail to do the PC adjustment, and report |
| 11857 | a random SIGTRAP to the user. When the user resumes |
| 11858 | the inferior, it will most likely immediately crash |
| 11859 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
| 11860 | corrupted, because of being resumed e.g., in the |
| 11861 | middle of a multi-byte instruction, or skipped a |
| 11862 | one-byte instruction. This was actually seen happen |
| 11863 | on native x86-linux, and should be less rare on |
| 11864 | targets that do not support new thread events, like |
| 11865 | remote, due to the heuristic depending on |
| 11866 | thread_count. |
| 11867 | |
| 11868 | Mistaking a random SIGTRAP for a breakpoint trap |
| 11869 | causes similar symptoms (PC adjustment applied when |
| 11870 | it shouldn't), but then again, playing with SIGTRAPs |
| 11871 | behind the debugger's back is asking for trouble. |
| 11872 | |
| 11873 | Since hardware watchpoint traps are always |
| 11874 | distinguishable from other traps, so we don't need to |
| 11875 | apply keep hardware watchpoint moribund locations |
| 11876 | around. We simply always ignore hardware watchpoint |
| 11877 | traps we can no longer explain. */ |
| 11878 | |
| 11879 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
| 11880 | old_loc->owner = NULL; |
| 11881 | |
| 11882 | moribund_locations.push_back (old_loc); |
| 11883 | } |
| 11884 | else |
| 11885 | { |
| 11886 | old_loc->owner = NULL; |
| 11887 | decref_bp_location (&old_loc); |
| 11888 | } |
| 11889 | } |
| 11890 | } |
| 11891 | |
| 11892 | /* Rescan breakpoints at the same address and section, marking the |
| 11893 | first one as "first" and any others as "duplicates". This is so |
| 11894 | that the bpt instruction is only inserted once. If we have a |
| 11895 | permanent breakpoint at the same place as BPT, make that one the |
| 11896 | official one, and the rest as duplicates. Permanent breakpoints |
| 11897 | are sorted first for the same address. |
| 11898 | |
| 11899 | Do the same for hardware watchpoints, but also considering the |
| 11900 | watchpoint's type (regular/access/read) and length. */ |
| 11901 | |
| 11902 | bp_loc_first = NULL; |
| 11903 | wp_loc_first = NULL; |
| 11904 | awp_loc_first = NULL; |
| 11905 | rwp_loc_first = NULL; |
| 11906 | ALL_BP_LOCATIONS (loc, locp) |
| 11907 | { |
| 11908 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
| 11909 | non-NULL. */ |
| 11910 | struct bp_location **loc_first_p; |
| 11911 | b = loc->owner; |
| 11912 | |
| 11913 | if (!unduplicated_should_be_inserted (loc) |
| 11914 | || !bl_address_is_meaningful (loc) |
| 11915 | /* Don't detect duplicate for tracepoint locations because they are |
| 11916 | never duplicated. See the comments in field `duplicate' of |
| 11917 | `struct bp_location'. */ |
| 11918 | || is_tracepoint (b)) |
| 11919 | { |
| 11920 | /* Clear the condition modification flag. */ |
| 11921 | loc->condition_changed = condition_unchanged; |
| 11922 | continue; |
| 11923 | } |
| 11924 | |
| 11925 | if (b->type == bp_hardware_watchpoint) |
| 11926 | loc_first_p = &wp_loc_first; |
| 11927 | else if (b->type == bp_read_watchpoint) |
| 11928 | loc_first_p = &rwp_loc_first; |
| 11929 | else if (b->type == bp_access_watchpoint) |
| 11930 | loc_first_p = &awp_loc_first; |
| 11931 | else |
| 11932 | loc_first_p = &bp_loc_first; |
| 11933 | |
| 11934 | if (*loc_first_p == NULL |
| 11935 | || (overlay_debugging && loc->section != (*loc_first_p)->section) |
| 11936 | || !breakpoint_locations_match (loc, *loc_first_p)) |
| 11937 | { |
| 11938 | *loc_first_p = loc; |
| 11939 | loc->duplicate = 0; |
| 11940 | |
| 11941 | if (is_breakpoint (loc->owner) && loc->condition_changed) |
| 11942 | { |
| 11943 | loc->needs_update = 1; |
| 11944 | /* Clear the condition modification flag. */ |
| 11945 | loc->condition_changed = condition_unchanged; |
| 11946 | } |
| 11947 | continue; |
| 11948 | } |
| 11949 | |
| 11950 | |
| 11951 | /* This and the above ensure the invariant that the first location |
| 11952 | is not duplicated, and is the inserted one. |
| 11953 | All following are marked as duplicated, and are not inserted. */ |
| 11954 | if (loc->inserted) |
| 11955 | swap_insertion (loc, *loc_first_p); |
| 11956 | loc->duplicate = 1; |
| 11957 | |
| 11958 | /* Clear the condition modification flag. */ |
| 11959 | loc->condition_changed = condition_unchanged; |
| 11960 | } |
| 11961 | |
| 11962 | if (insert_mode == UGLL_INSERT || breakpoints_should_be_inserted_now ()) |
| 11963 | { |
| 11964 | if (insert_mode != UGLL_DONT_INSERT) |
| 11965 | insert_breakpoint_locations (); |
| 11966 | else |
| 11967 | { |
| 11968 | /* Even though the caller told us to not insert new |
| 11969 | locations, we may still need to update conditions on the |
| 11970 | target's side of breakpoints that were already inserted |
| 11971 | if the target is evaluating breakpoint conditions. We |
| 11972 | only update conditions for locations that are marked |
| 11973 | "needs_update". */ |
| 11974 | update_inserted_breakpoint_locations (); |
| 11975 | } |
| 11976 | } |
| 11977 | |
| 11978 | if (insert_mode != UGLL_DONT_INSERT) |
| 11979 | download_tracepoint_locations (); |
| 11980 | } |
| 11981 | |
| 11982 | void |
| 11983 | breakpoint_retire_moribund (void) |
| 11984 | { |
| 11985 | for (int ix = 0; ix < moribund_locations.size (); ++ix) |
| 11986 | { |
| 11987 | struct bp_location *loc = moribund_locations[ix]; |
| 11988 | if (--(loc->events_till_retirement) == 0) |
| 11989 | { |
| 11990 | decref_bp_location (&loc); |
| 11991 | unordered_remove (moribund_locations, ix); |
| 11992 | --ix; |
| 11993 | } |
| 11994 | } |
| 11995 | } |
| 11996 | |
| 11997 | static void |
| 11998 | update_global_location_list_nothrow (enum ugll_insert_mode insert_mode) |
| 11999 | { |
| 12000 | |
| 12001 | try |
| 12002 | { |
| 12003 | update_global_location_list (insert_mode); |
| 12004 | } |
| 12005 | catch (const gdb_exception_error &e) |
| 12006 | { |
| 12007 | } |
| 12008 | } |
| 12009 | |
| 12010 | /* Clear BKP from a BPS. */ |
| 12011 | |
| 12012 | static void |
| 12013 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
| 12014 | { |
| 12015 | bpstat bs; |
| 12016 | |
| 12017 | for (bs = bps; bs; bs = bs->next) |
| 12018 | if (bs->breakpoint_at == bpt) |
| 12019 | { |
| 12020 | bs->breakpoint_at = NULL; |
| 12021 | bs->old_val = NULL; |
| 12022 | /* bs->commands will be freed later. */ |
| 12023 | } |
| 12024 | } |
| 12025 | |
| 12026 | /* Callback for iterate_over_threads. */ |
| 12027 | static int |
| 12028 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
| 12029 | { |
| 12030 | struct breakpoint *bpt = (struct breakpoint *) data; |
| 12031 | |
| 12032 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
| 12033 | return 0; |
| 12034 | } |
| 12035 | |
| 12036 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention |
| 12037 | callbacks. */ |
| 12038 | |
| 12039 | static void |
| 12040 | say_where (struct breakpoint *b) |
| 12041 | { |
| 12042 | struct value_print_options opts; |
| 12043 | |
| 12044 | get_user_print_options (&opts); |
| 12045 | |
| 12046 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
| 12047 | single string. */ |
| 12048 | if (b->loc == NULL) |
| 12049 | { |
| 12050 | /* For pending locations, the output differs slightly based |
| 12051 | on b->extra_string. If this is non-NULL, it contains either |
| 12052 | a condition or dprintf arguments. */ |
| 12053 | if (b->extra_string == NULL) |
| 12054 | { |
| 12055 | printf_filtered (_(" (%s) pending."), |
| 12056 | event_location_to_string (b->location.get ())); |
| 12057 | } |
| 12058 | else if (b->type == bp_dprintf) |
| 12059 | { |
| 12060 | printf_filtered (_(" (%s,%s) pending."), |
| 12061 | event_location_to_string (b->location.get ()), |
| 12062 | b->extra_string); |
| 12063 | } |
| 12064 | else |
| 12065 | { |
| 12066 | printf_filtered (_(" (%s %s) pending."), |
| 12067 | event_location_to_string (b->location.get ()), |
| 12068 | b->extra_string); |
| 12069 | } |
| 12070 | } |
| 12071 | else |
| 12072 | { |
| 12073 | if (opts.addressprint || b->loc->symtab == NULL) |
| 12074 | printf_filtered (" at %ps", |
| 12075 | styled_string (address_style.style (), |
| 12076 | paddress (b->loc->gdbarch, |
| 12077 | b->loc->address))); |
| 12078 | if (b->loc->symtab != NULL) |
| 12079 | { |
| 12080 | /* If there is a single location, we can print the location |
| 12081 | more nicely. */ |
| 12082 | if (b->loc->next == NULL) |
| 12083 | { |
| 12084 | const char *filename |
| 12085 | = symtab_to_filename_for_display (b->loc->symtab); |
| 12086 | printf_filtered (": file %ps, line %d.", |
| 12087 | styled_string (file_name_style.style (), |
| 12088 | filename), |
| 12089 | b->loc->line_number); |
| 12090 | } |
| 12091 | else |
| 12092 | /* This is not ideal, but each location may have a |
| 12093 | different file name, and this at least reflects the |
| 12094 | real situation somewhat. */ |
| 12095 | printf_filtered (": %s.", |
| 12096 | event_location_to_string (b->location.get ())); |
| 12097 | } |
| 12098 | |
| 12099 | if (b->loc->next) |
| 12100 | { |
| 12101 | struct bp_location *loc = b->loc; |
| 12102 | int n = 0; |
| 12103 | for (; loc; loc = loc->next) |
| 12104 | ++n; |
| 12105 | printf_filtered (" (%d locations)", n); |
| 12106 | } |
| 12107 | } |
| 12108 | } |
| 12109 | |
| 12110 | bp_location::~bp_location () |
| 12111 | { |
| 12112 | xfree (function_name); |
| 12113 | } |
| 12114 | |
| 12115 | /* Destructor for the breakpoint base class. */ |
| 12116 | |
| 12117 | breakpoint::~breakpoint () |
| 12118 | { |
| 12119 | xfree (this->cond_string); |
| 12120 | xfree (this->extra_string); |
| 12121 | } |
| 12122 | |
| 12123 | static struct bp_location * |
| 12124 | base_breakpoint_allocate_location (struct breakpoint *self) |
| 12125 | { |
| 12126 | return new bp_location (self); |
| 12127 | } |
| 12128 | |
| 12129 | static void |
| 12130 | base_breakpoint_re_set (struct breakpoint *b) |
| 12131 | { |
| 12132 | /* Nothing to re-set. */ |
| 12133 | } |
| 12134 | |
| 12135 | #define internal_error_pure_virtual_called() \ |
| 12136 | gdb_assert_not_reached ("pure virtual function called") |
| 12137 | |
| 12138 | static int |
| 12139 | base_breakpoint_insert_location (struct bp_location *bl) |
| 12140 | { |
| 12141 | internal_error_pure_virtual_called (); |
| 12142 | } |
| 12143 | |
| 12144 | static int |
| 12145 | base_breakpoint_remove_location (struct bp_location *bl, |
| 12146 | enum remove_bp_reason reason) |
| 12147 | { |
| 12148 | internal_error_pure_virtual_called (); |
| 12149 | } |
| 12150 | |
| 12151 | static int |
| 12152 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, |
| 12153 | const address_space *aspace, |
| 12154 | CORE_ADDR bp_addr, |
| 12155 | const struct target_waitstatus *ws) |
| 12156 | { |
| 12157 | internal_error_pure_virtual_called (); |
| 12158 | } |
| 12159 | |
| 12160 | static void |
| 12161 | base_breakpoint_check_status (bpstat bs) |
| 12162 | { |
| 12163 | /* Always stop. */ |
| 12164 | } |
| 12165 | |
| 12166 | /* A "works_in_software_mode" breakpoint_ops method that just internal |
| 12167 | errors. */ |
| 12168 | |
| 12169 | static int |
| 12170 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) |
| 12171 | { |
| 12172 | internal_error_pure_virtual_called (); |
| 12173 | } |
| 12174 | |
| 12175 | /* A "resources_needed" breakpoint_ops method that just internal |
| 12176 | errors. */ |
| 12177 | |
| 12178 | static int |
| 12179 | base_breakpoint_resources_needed (const struct bp_location *bl) |
| 12180 | { |
| 12181 | internal_error_pure_virtual_called (); |
| 12182 | } |
| 12183 | |
| 12184 | static enum print_stop_action |
| 12185 | base_breakpoint_print_it (bpstat bs) |
| 12186 | { |
| 12187 | internal_error_pure_virtual_called (); |
| 12188 | } |
| 12189 | |
| 12190 | static void |
| 12191 | base_breakpoint_print_one_detail (const struct breakpoint *self, |
| 12192 | struct ui_out *uiout) |
| 12193 | { |
| 12194 | /* nothing */ |
| 12195 | } |
| 12196 | |
| 12197 | static void |
| 12198 | base_breakpoint_print_mention (struct breakpoint *b) |
| 12199 | { |
| 12200 | internal_error_pure_virtual_called (); |
| 12201 | } |
| 12202 | |
| 12203 | static void |
| 12204 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) |
| 12205 | { |
| 12206 | internal_error_pure_virtual_called (); |
| 12207 | } |
| 12208 | |
| 12209 | static void |
| 12210 | base_breakpoint_create_sals_from_location |
| 12211 | (const struct event_location *location, |
| 12212 | struct linespec_result *canonical, |
| 12213 | enum bptype type_wanted) |
| 12214 | { |
| 12215 | internal_error_pure_virtual_called (); |
| 12216 | } |
| 12217 | |
| 12218 | static void |
| 12219 | base_breakpoint_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12220 | struct linespec_result *c, |
| 12221 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 12222 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 12223 | enum bptype type_wanted, |
| 12224 | enum bpdisp disposition, |
| 12225 | int thread, |
| 12226 | int task, int ignore_count, |
| 12227 | const struct breakpoint_ops *o, |
| 12228 | int from_tty, int enabled, |
| 12229 | int internal, unsigned flags) |
| 12230 | { |
| 12231 | internal_error_pure_virtual_called (); |
| 12232 | } |
| 12233 | |
| 12234 | static std::vector<symtab_and_line> |
| 12235 | base_breakpoint_decode_location (struct breakpoint *b, |
| 12236 | const struct event_location *location, |
| 12237 | struct program_space *search_pspace) |
| 12238 | { |
| 12239 | internal_error_pure_virtual_called (); |
| 12240 | } |
| 12241 | |
| 12242 | /* The default 'explains_signal' method. */ |
| 12243 | |
| 12244 | static int |
| 12245 | base_breakpoint_explains_signal (struct breakpoint *b, enum gdb_signal sig) |
| 12246 | { |
| 12247 | return 1; |
| 12248 | } |
| 12249 | |
| 12250 | /* The default "after_condition_true" method. */ |
| 12251 | |
| 12252 | static void |
| 12253 | base_breakpoint_after_condition_true (struct bpstats *bs) |
| 12254 | { |
| 12255 | /* Nothing to do. */ |
| 12256 | } |
| 12257 | |
| 12258 | struct breakpoint_ops base_breakpoint_ops = |
| 12259 | { |
| 12260 | base_breakpoint_allocate_location, |
| 12261 | base_breakpoint_re_set, |
| 12262 | base_breakpoint_insert_location, |
| 12263 | base_breakpoint_remove_location, |
| 12264 | base_breakpoint_breakpoint_hit, |
| 12265 | base_breakpoint_check_status, |
| 12266 | base_breakpoint_resources_needed, |
| 12267 | base_breakpoint_works_in_software_mode, |
| 12268 | base_breakpoint_print_it, |
| 12269 | NULL, |
| 12270 | base_breakpoint_print_one_detail, |
| 12271 | base_breakpoint_print_mention, |
| 12272 | base_breakpoint_print_recreate, |
| 12273 | base_breakpoint_create_sals_from_location, |
| 12274 | base_breakpoint_create_breakpoints_sal, |
| 12275 | base_breakpoint_decode_location, |
| 12276 | base_breakpoint_explains_signal, |
| 12277 | base_breakpoint_after_condition_true, |
| 12278 | }; |
| 12279 | |
| 12280 | /* Default breakpoint_ops methods. */ |
| 12281 | |
| 12282 | static void |
| 12283 | bkpt_re_set (struct breakpoint *b) |
| 12284 | { |
| 12285 | /* FIXME: is this still reachable? */ |
| 12286 | if (breakpoint_event_location_empty_p (b)) |
| 12287 | { |
| 12288 | /* Anything without a location can't be re-set. */ |
| 12289 | delete_breakpoint (b); |
| 12290 | return; |
| 12291 | } |
| 12292 | |
| 12293 | breakpoint_re_set_default (b); |
| 12294 | } |
| 12295 | |
| 12296 | static int |
| 12297 | bkpt_insert_location (struct bp_location *bl) |
| 12298 | { |
| 12299 | CORE_ADDR addr = bl->target_info.reqstd_address; |
| 12300 | |
| 12301 | bl->target_info.kind = breakpoint_kind (bl, &addr); |
| 12302 | bl->target_info.placed_address = addr; |
| 12303 | |
| 12304 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 12305 | return target_insert_hw_breakpoint (bl->gdbarch, &bl->target_info); |
| 12306 | else |
| 12307 | return target_insert_breakpoint (bl->gdbarch, &bl->target_info); |
| 12308 | } |
| 12309 | |
| 12310 | static int |
| 12311 | bkpt_remove_location (struct bp_location *bl, enum remove_bp_reason reason) |
| 12312 | { |
| 12313 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
| 12314 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); |
| 12315 | else |
| 12316 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info, reason); |
| 12317 | } |
| 12318 | |
| 12319 | static int |
| 12320 | bkpt_breakpoint_hit (const struct bp_location *bl, |
| 12321 | const address_space *aspace, CORE_ADDR bp_addr, |
| 12322 | const struct target_waitstatus *ws) |
| 12323 | { |
| 12324 | if (ws->kind != TARGET_WAITKIND_STOPPED |
| 12325 | || ws->value.sig != GDB_SIGNAL_TRAP) |
| 12326 | return 0; |
| 12327 | |
| 12328 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
| 12329 | aspace, bp_addr)) |
| 12330 | return 0; |
| 12331 | |
| 12332 | if (overlay_debugging /* unmapped overlay section */ |
| 12333 | && section_is_overlay (bl->section) |
| 12334 | && !section_is_mapped (bl->section)) |
| 12335 | return 0; |
| 12336 | |
| 12337 | return 1; |
| 12338 | } |
| 12339 | |
| 12340 | static int |
| 12341 | dprintf_breakpoint_hit (const struct bp_location *bl, |
| 12342 | const address_space *aspace, CORE_ADDR bp_addr, |
| 12343 | const struct target_waitstatus *ws) |
| 12344 | { |
| 12345 | if (dprintf_style == dprintf_style_agent |
| 12346 | && target_can_run_breakpoint_commands ()) |
| 12347 | { |
| 12348 | /* An agent-style dprintf never causes a stop. If we see a trap |
| 12349 | for this address it must be for a breakpoint that happens to |
| 12350 | be set at the same address. */ |
| 12351 | return 0; |
| 12352 | } |
| 12353 | |
| 12354 | return bkpt_breakpoint_hit (bl, aspace, bp_addr, ws); |
| 12355 | } |
| 12356 | |
| 12357 | static int |
| 12358 | bkpt_resources_needed (const struct bp_location *bl) |
| 12359 | { |
| 12360 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); |
| 12361 | |
| 12362 | return 1; |
| 12363 | } |
| 12364 | |
| 12365 | static enum print_stop_action |
| 12366 | bkpt_print_it (bpstat bs) |
| 12367 | { |
| 12368 | struct breakpoint *b; |
| 12369 | const struct bp_location *bl; |
| 12370 | int bp_temp; |
| 12371 | struct ui_out *uiout = current_uiout; |
| 12372 | |
| 12373 | gdb_assert (bs->bp_location_at != NULL); |
| 12374 | |
| 12375 | bl = bs->bp_location_at; |
| 12376 | b = bs->breakpoint_at; |
| 12377 | |
| 12378 | bp_temp = b->disposition == disp_del; |
| 12379 | if (bl->address != bl->requested_address) |
| 12380 | breakpoint_adjustment_warning (bl->requested_address, |
| 12381 | bl->address, |
| 12382 | b->number, 1); |
| 12383 | annotate_breakpoint (b->number); |
| 12384 | maybe_print_thread_hit_breakpoint (uiout); |
| 12385 | |
| 12386 | if (uiout->is_mi_like_p ()) |
| 12387 | { |
| 12388 | uiout->field_string ("reason", |
| 12389 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); |
| 12390 | uiout->field_string ("disp", bpdisp_text (b->disposition)); |
| 12391 | } |
| 12392 | if (bp_temp) |
| 12393 | uiout->message ("Temporary breakpoint %pF, ", |
| 12394 | signed_field ("bkptno", b->number)); |
| 12395 | else |
| 12396 | uiout->message ("Breakpoint %pF, ", |
| 12397 | signed_field ("bkptno", b->number)); |
| 12398 | |
| 12399 | return PRINT_SRC_AND_LOC; |
| 12400 | } |
| 12401 | |
| 12402 | static void |
| 12403 | bkpt_print_mention (struct breakpoint *b) |
| 12404 | { |
| 12405 | if (current_uiout->is_mi_like_p ()) |
| 12406 | return; |
| 12407 | |
| 12408 | switch (b->type) |
| 12409 | { |
| 12410 | case bp_breakpoint: |
| 12411 | case bp_gnu_ifunc_resolver: |
| 12412 | if (b->disposition == disp_del) |
| 12413 | printf_filtered (_("Temporary breakpoint")); |
| 12414 | else |
| 12415 | printf_filtered (_("Breakpoint")); |
| 12416 | printf_filtered (_(" %d"), b->number); |
| 12417 | if (b->type == bp_gnu_ifunc_resolver) |
| 12418 | printf_filtered (_(" at gnu-indirect-function resolver")); |
| 12419 | break; |
| 12420 | case bp_hardware_breakpoint: |
| 12421 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
| 12422 | break; |
| 12423 | case bp_dprintf: |
| 12424 | printf_filtered (_("Dprintf %d"), b->number); |
| 12425 | break; |
| 12426 | } |
| 12427 | |
| 12428 | say_where (b); |
| 12429 | } |
| 12430 | |
| 12431 | static void |
| 12432 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
| 12433 | { |
| 12434 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) |
| 12435 | fprintf_unfiltered (fp, "tbreak"); |
| 12436 | else if (tp->type == bp_breakpoint) |
| 12437 | fprintf_unfiltered (fp, "break"); |
| 12438 | else if (tp->type == bp_hardware_breakpoint |
| 12439 | && tp->disposition == disp_del) |
| 12440 | fprintf_unfiltered (fp, "thbreak"); |
| 12441 | else if (tp->type == bp_hardware_breakpoint) |
| 12442 | fprintf_unfiltered (fp, "hbreak"); |
| 12443 | else |
| 12444 | internal_error (__FILE__, __LINE__, |
| 12445 | _("unhandled breakpoint type %d"), (int) tp->type); |
| 12446 | |
| 12447 | fprintf_unfiltered (fp, " %s", |
| 12448 | event_location_to_string (tp->location.get ())); |
| 12449 | |
| 12450 | /* Print out extra_string if this breakpoint is pending. It might |
| 12451 | contain, for example, conditions that were set by the user. */ |
| 12452 | if (tp->loc == NULL && tp->extra_string != NULL) |
| 12453 | fprintf_unfiltered (fp, " %s", tp->extra_string); |
| 12454 | |
| 12455 | print_recreate_thread (tp, fp); |
| 12456 | } |
| 12457 | |
| 12458 | static void |
| 12459 | bkpt_create_sals_from_location (const struct event_location *location, |
| 12460 | struct linespec_result *canonical, |
| 12461 | enum bptype type_wanted) |
| 12462 | { |
| 12463 | create_sals_from_location_default (location, canonical, type_wanted); |
| 12464 | } |
| 12465 | |
| 12466 | static void |
| 12467 | bkpt_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12468 | struct linespec_result *canonical, |
| 12469 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 12470 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 12471 | enum bptype type_wanted, |
| 12472 | enum bpdisp disposition, |
| 12473 | int thread, |
| 12474 | int task, int ignore_count, |
| 12475 | const struct breakpoint_ops *ops, |
| 12476 | int from_tty, int enabled, |
| 12477 | int internal, unsigned flags) |
| 12478 | { |
| 12479 | create_breakpoints_sal_default (gdbarch, canonical, |
| 12480 | std::move (cond_string), |
| 12481 | std::move (extra_string), |
| 12482 | type_wanted, |
| 12483 | disposition, thread, task, |
| 12484 | ignore_count, ops, from_tty, |
| 12485 | enabled, internal, flags); |
| 12486 | } |
| 12487 | |
| 12488 | static std::vector<symtab_and_line> |
| 12489 | bkpt_decode_location (struct breakpoint *b, |
| 12490 | const struct event_location *location, |
| 12491 | struct program_space *search_pspace) |
| 12492 | { |
| 12493 | return decode_location_default (b, location, search_pspace); |
| 12494 | } |
| 12495 | |
| 12496 | /* Virtual table for internal breakpoints. */ |
| 12497 | |
| 12498 | static void |
| 12499 | internal_bkpt_re_set (struct breakpoint *b) |
| 12500 | { |
| 12501 | switch (b->type) |
| 12502 | { |
| 12503 | /* Delete overlay event and longjmp master breakpoints; they |
| 12504 | will be reset later by breakpoint_re_set. */ |
| 12505 | case bp_overlay_event: |
| 12506 | case bp_longjmp_master: |
| 12507 | case bp_std_terminate_master: |
| 12508 | case bp_exception_master: |
| 12509 | delete_breakpoint (b); |
| 12510 | break; |
| 12511 | |
| 12512 | /* This breakpoint is special, it's set up when the inferior |
| 12513 | starts and we really don't want to touch it. */ |
| 12514 | case bp_shlib_event: |
| 12515 | |
| 12516 | /* Like bp_shlib_event, this breakpoint type is special. Once |
| 12517 | it is set up, we do not want to touch it. */ |
| 12518 | case bp_thread_event: |
| 12519 | break; |
| 12520 | } |
| 12521 | } |
| 12522 | |
| 12523 | static void |
| 12524 | internal_bkpt_check_status (bpstat bs) |
| 12525 | { |
| 12526 | if (bs->breakpoint_at->type == bp_shlib_event) |
| 12527 | { |
| 12528 | /* If requested, stop when the dynamic linker notifies GDB of |
| 12529 | events. This allows the user to get control and place |
| 12530 | breakpoints in initializer routines for dynamically loaded |
| 12531 | objects (among other things). */ |
| 12532 | bs->stop = stop_on_solib_events; |
| 12533 | bs->print = stop_on_solib_events; |
| 12534 | } |
| 12535 | else |
| 12536 | bs->stop = 0; |
| 12537 | } |
| 12538 | |
| 12539 | static enum print_stop_action |
| 12540 | internal_bkpt_print_it (bpstat bs) |
| 12541 | { |
| 12542 | struct breakpoint *b; |
| 12543 | |
| 12544 | b = bs->breakpoint_at; |
| 12545 | |
| 12546 | switch (b->type) |
| 12547 | { |
| 12548 | case bp_shlib_event: |
| 12549 | /* Did we stop because the user set the stop_on_solib_events |
| 12550 | variable? (If so, we report this as a generic, "Stopped due |
| 12551 | to shlib event" message.) */ |
| 12552 | print_solib_event (0); |
| 12553 | break; |
| 12554 | |
| 12555 | case bp_thread_event: |
| 12556 | /* Not sure how we will get here. |
| 12557 | GDB should not stop for these breakpoints. */ |
| 12558 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
| 12559 | break; |
| 12560 | |
| 12561 | case bp_overlay_event: |
| 12562 | /* By analogy with the thread event, GDB should not stop for these. */ |
| 12563 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
| 12564 | break; |
| 12565 | |
| 12566 | case bp_longjmp_master: |
| 12567 | /* These should never be enabled. */ |
| 12568 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); |
| 12569 | break; |
| 12570 | |
| 12571 | case bp_std_terminate_master: |
| 12572 | /* These should never be enabled. */ |
| 12573 | printf_filtered (_("std::terminate Master Breakpoint: " |
| 12574 | "gdb should not stop!\n")); |
| 12575 | break; |
| 12576 | |
| 12577 | case bp_exception_master: |
| 12578 | /* These should never be enabled. */ |
| 12579 | printf_filtered (_("Exception Master Breakpoint: " |
| 12580 | "gdb should not stop!\n")); |
| 12581 | break; |
| 12582 | } |
| 12583 | |
| 12584 | return PRINT_NOTHING; |
| 12585 | } |
| 12586 | |
| 12587 | static void |
| 12588 | internal_bkpt_print_mention (struct breakpoint *b) |
| 12589 | { |
| 12590 | /* Nothing to mention. These breakpoints are internal. */ |
| 12591 | } |
| 12592 | |
| 12593 | /* Virtual table for momentary breakpoints */ |
| 12594 | |
| 12595 | static void |
| 12596 | momentary_bkpt_re_set (struct breakpoint *b) |
| 12597 | { |
| 12598 | /* Keep temporary breakpoints, which can be encountered when we step |
| 12599 | over a dlopen call and solib_add is resetting the breakpoints. |
| 12600 | Otherwise these should have been blown away via the cleanup chain |
| 12601 | or by breakpoint_init_inferior when we rerun the executable. */ |
| 12602 | } |
| 12603 | |
| 12604 | static void |
| 12605 | momentary_bkpt_check_status (bpstat bs) |
| 12606 | { |
| 12607 | /* Nothing. The point of these breakpoints is causing a stop. */ |
| 12608 | } |
| 12609 | |
| 12610 | static enum print_stop_action |
| 12611 | momentary_bkpt_print_it (bpstat bs) |
| 12612 | { |
| 12613 | return PRINT_UNKNOWN; |
| 12614 | } |
| 12615 | |
| 12616 | static void |
| 12617 | momentary_bkpt_print_mention (struct breakpoint *b) |
| 12618 | { |
| 12619 | /* Nothing to mention. These breakpoints are internal. */ |
| 12620 | } |
| 12621 | |
| 12622 | /* Ensure INITIATING_FRAME is cleared when no such breakpoint exists. |
| 12623 | |
| 12624 | It gets cleared already on the removal of the first one of such placed |
| 12625 | breakpoints. This is OK as they get all removed altogether. */ |
| 12626 | |
| 12627 | longjmp_breakpoint::~longjmp_breakpoint () |
| 12628 | { |
| 12629 | thread_info *tp = find_thread_global_id (this->thread); |
| 12630 | |
| 12631 | if (tp != NULL) |
| 12632 | tp->initiating_frame = null_frame_id; |
| 12633 | } |
| 12634 | |
| 12635 | /* Specific methods for probe breakpoints. */ |
| 12636 | |
| 12637 | static int |
| 12638 | bkpt_probe_insert_location (struct bp_location *bl) |
| 12639 | { |
| 12640 | int v = bkpt_insert_location (bl); |
| 12641 | |
| 12642 | if (v == 0) |
| 12643 | { |
| 12644 | /* The insertion was successful, now let's set the probe's semaphore |
| 12645 | if needed. */ |
| 12646 | bl->probe.prob->set_semaphore (bl->probe.objfile, bl->gdbarch); |
| 12647 | } |
| 12648 | |
| 12649 | return v; |
| 12650 | } |
| 12651 | |
| 12652 | static int |
| 12653 | bkpt_probe_remove_location (struct bp_location *bl, |
| 12654 | enum remove_bp_reason reason) |
| 12655 | { |
| 12656 | /* Let's clear the semaphore before removing the location. */ |
| 12657 | bl->probe.prob->clear_semaphore (bl->probe.objfile, bl->gdbarch); |
| 12658 | |
| 12659 | return bkpt_remove_location (bl, reason); |
| 12660 | } |
| 12661 | |
| 12662 | static void |
| 12663 | bkpt_probe_create_sals_from_location (const struct event_location *location, |
| 12664 | struct linespec_result *canonical, |
| 12665 | enum bptype type_wanted) |
| 12666 | { |
| 12667 | struct linespec_sals lsal; |
| 12668 | |
| 12669 | lsal.sals = parse_probes (location, NULL, canonical); |
| 12670 | lsal.canonical |
| 12671 | = xstrdup (event_location_to_string (canonical->location.get ())); |
| 12672 | canonical->lsals.push_back (std::move (lsal)); |
| 12673 | } |
| 12674 | |
| 12675 | static std::vector<symtab_and_line> |
| 12676 | bkpt_probe_decode_location (struct breakpoint *b, |
| 12677 | const struct event_location *location, |
| 12678 | struct program_space *search_pspace) |
| 12679 | { |
| 12680 | std::vector<symtab_and_line> sals = parse_probes (location, search_pspace, NULL); |
| 12681 | if (sals.empty ()) |
| 12682 | error (_("probe not found")); |
| 12683 | return sals; |
| 12684 | } |
| 12685 | |
| 12686 | /* The breakpoint_ops structure to be used in tracepoints. */ |
| 12687 | |
| 12688 | static void |
| 12689 | tracepoint_re_set (struct breakpoint *b) |
| 12690 | { |
| 12691 | breakpoint_re_set_default (b); |
| 12692 | } |
| 12693 | |
| 12694 | static int |
| 12695 | tracepoint_breakpoint_hit (const struct bp_location *bl, |
| 12696 | const address_space *aspace, CORE_ADDR bp_addr, |
| 12697 | const struct target_waitstatus *ws) |
| 12698 | { |
| 12699 | /* By definition, the inferior does not report stops at |
| 12700 | tracepoints. */ |
| 12701 | return 0; |
| 12702 | } |
| 12703 | |
| 12704 | static void |
| 12705 | tracepoint_print_one_detail (const struct breakpoint *self, |
| 12706 | struct ui_out *uiout) |
| 12707 | { |
| 12708 | struct tracepoint *tp = (struct tracepoint *) self; |
| 12709 | if (!tp->static_trace_marker_id.empty ()) |
| 12710 | { |
| 12711 | gdb_assert (self->type == bp_static_tracepoint); |
| 12712 | |
| 12713 | uiout->message ("\tmarker id is %pF\n", |
| 12714 | string_field ("static-tracepoint-marker-string-id", |
| 12715 | tp->static_trace_marker_id.c_str ())); |
| 12716 | } |
| 12717 | } |
| 12718 | |
| 12719 | static void |
| 12720 | tracepoint_print_mention (struct breakpoint *b) |
| 12721 | { |
| 12722 | if (current_uiout->is_mi_like_p ()) |
| 12723 | return; |
| 12724 | |
| 12725 | switch (b->type) |
| 12726 | { |
| 12727 | case bp_tracepoint: |
| 12728 | printf_filtered (_("Tracepoint")); |
| 12729 | printf_filtered (_(" %d"), b->number); |
| 12730 | break; |
| 12731 | case bp_fast_tracepoint: |
| 12732 | printf_filtered (_("Fast tracepoint")); |
| 12733 | printf_filtered (_(" %d"), b->number); |
| 12734 | break; |
| 12735 | case bp_static_tracepoint: |
| 12736 | printf_filtered (_("Static tracepoint")); |
| 12737 | printf_filtered (_(" %d"), b->number); |
| 12738 | break; |
| 12739 | default: |
| 12740 | internal_error (__FILE__, __LINE__, |
| 12741 | _("unhandled tracepoint type %d"), (int) b->type); |
| 12742 | } |
| 12743 | |
| 12744 | say_where (b); |
| 12745 | } |
| 12746 | |
| 12747 | static void |
| 12748 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
| 12749 | { |
| 12750 | struct tracepoint *tp = (struct tracepoint *) self; |
| 12751 | |
| 12752 | if (self->type == bp_fast_tracepoint) |
| 12753 | fprintf_unfiltered (fp, "ftrace"); |
| 12754 | else if (self->type == bp_static_tracepoint) |
| 12755 | fprintf_unfiltered (fp, "strace"); |
| 12756 | else if (self->type == bp_tracepoint) |
| 12757 | fprintf_unfiltered (fp, "trace"); |
| 12758 | else |
| 12759 | internal_error (__FILE__, __LINE__, |
| 12760 | _("unhandled tracepoint type %d"), (int) self->type); |
| 12761 | |
| 12762 | fprintf_unfiltered (fp, " %s", |
| 12763 | event_location_to_string (self->location.get ())); |
| 12764 | print_recreate_thread (self, fp); |
| 12765 | |
| 12766 | if (tp->pass_count) |
| 12767 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
| 12768 | } |
| 12769 | |
| 12770 | static void |
| 12771 | tracepoint_create_sals_from_location (const struct event_location *location, |
| 12772 | struct linespec_result *canonical, |
| 12773 | enum bptype type_wanted) |
| 12774 | { |
| 12775 | create_sals_from_location_default (location, canonical, type_wanted); |
| 12776 | } |
| 12777 | |
| 12778 | static void |
| 12779 | tracepoint_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12780 | struct linespec_result *canonical, |
| 12781 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 12782 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 12783 | enum bptype type_wanted, |
| 12784 | enum bpdisp disposition, |
| 12785 | int thread, |
| 12786 | int task, int ignore_count, |
| 12787 | const struct breakpoint_ops *ops, |
| 12788 | int from_tty, int enabled, |
| 12789 | int internal, unsigned flags) |
| 12790 | { |
| 12791 | create_breakpoints_sal_default (gdbarch, canonical, |
| 12792 | std::move (cond_string), |
| 12793 | std::move (extra_string), |
| 12794 | type_wanted, |
| 12795 | disposition, thread, task, |
| 12796 | ignore_count, ops, from_tty, |
| 12797 | enabled, internal, flags); |
| 12798 | } |
| 12799 | |
| 12800 | static std::vector<symtab_and_line> |
| 12801 | tracepoint_decode_location (struct breakpoint *b, |
| 12802 | const struct event_location *location, |
| 12803 | struct program_space *search_pspace) |
| 12804 | { |
| 12805 | return decode_location_default (b, location, search_pspace); |
| 12806 | } |
| 12807 | |
| 12808 | struct breakpoint_ops tracepoint_breakpoint_ops; |
| 12809 | |
| 12810 | /* The breakpoint_ops structure to be use on tracepoints placed in a |
| 12811 | static probe. */ |
| 12812 | |
| 12813 | static void |
| 12814 | tracepoint_probe_create_sals_from_location |
| 12815 | (const struct event_location *location, |
| 12816 | struct linespec_result *canonical, |
| 12817 | enum bptype type_wanted) |
| 12818 | { |
| 12819 | /* We use the same method for breakpoint on probes. */ |
| 12820 | bkpt_probe_create_sals_from_location (location, canonical, type_wanted); |
| 12821 | } |
| 12822 | |
| 12823 | static std::vector<symtab_and_line> |
| 12824 | tracepoint_probe_decode_location (struct breakpoint *b, |
| 12825 | const struct event_location *location, |
| 12826 | struct program_space *search_pspace) |
| 12827 | { |
| 12828 | /* We use the same method for breakpoint on probes. */ |
| 12829 | return bkpt_probe_decode_location (b, location, search_pspace); |
| 12830 | } |
| 12831 | |
| 12832 | static struct breakpoint_ops tracepoint_probe_breakpoint_ops; |
| 12833 | |
| 12834 | /* Dprintf breakpoint_ops methods. */ |
| 12835 | |
| 12836 | static void |
| 12837 | dprintf_re_set (struct breakpoint *b) |
| 12838 | { |
| 12839 | breakpoint_re_set_default (b); |
| 12840 | |
| 12841 | /* extra_string should never be non-NULL for dprintf. */ |
| 12842 | gdb_assert (b->extra_string != NULL); |
| 12843 | |
| 12844 | /* 1 - connect to target 1, that can run breakpoint commands. |
| 12845 | 2 - create a dprintf, which resolves fine. |
| 12846 | 3 - disconnect from target 1 |
| 12847 | 4 - connect to target 2, that can NOT run breakpoint commands. |
| 12848 | |
| 12849 | After steps #3/#4, you'll want the dprintf command list to |
| 12850 | be updated, because target 1 and 2 may well return different |
| 12851 | answers for target_can_run_breakpoint_commands(). |
| 12852 | Given absence of finer grained resetting, we get to do |
| 12853 | it all the time. */ |
| 12854 | if (b->extra_string != NULL) |
| 12855 | update_dprintf_command_list (b); |
| 12856 | } |
| 12857 | |
| 12858 | /* Implement the "print_recreate" breakpoint_ops method for dprintf. */ |
| 12859 | |
| 12860 | static void |
| 12861 | dprintf_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
| 12862 | { |
| 12863 | fprintf_unfiltered (fp, "dprintf %s,%s", |
| 12864 | event_location_to_string (tp->location.get ()), |
| 12865 | tp->extra_string); |
| 12866 | print_recreate_thread (tp, fp); |
| 12867 | } |
| 12868 | |
| 12869 | /* Implement the "after_condition_true" breakpoint_ops method for |
| 12870 | dprintf. |
| 12871 | |
| 12872 | dprintf's are implemented with regular commands in their command |
| 12873 | list, but we run the commands here instead of before presenting the |
| 12874 | stop to the user, as dprintf's don't actually cause a stop. This |
| 12875 | also makes it so that the commands of multiple dprintfs at the same |
| 12876 | address are all handled. */ |
| 12877 | |
| 12878 | static void |
| 12879 | dprintf_after_condition_true (struct bpstats *bs) |
| 12880 | { |
| 12881 | struct bpstats tmp_bs; |
| 12882 | struct bpstats *tmp_bs_p = &tmp_bs; |
| 12883 | |
| 12884 | /* dprintf's never cause a stop. This wasn't set in the |
| 12885 | check_status hook instead because that would make the dprintf's |
| 12886 | condition not be evaluated. */ |
| 12887 | bs->stop = 0; |
| 12888 | |
| 12889 | /* Run the command list here. Take ownership of it instead of |
| 12890 | copying. We never want these commands to run later in |
| 12891 | bpstat_do_actions, if a breakpoint that causes a stop happens to |
| 12892 | be set at same address as this dprintf, or even if running the |
| 12893 | commands here throws. */ |
| 12894 | tmp_bs.commands = bs->commands; |
| 12895 | bs->commands = NULL; |
| 12896 | |
| 12897 | bpstat_do_actions_1 (&tmp_bs_p); |
| 12898 | |
| 12899 | /* 'tmp_bs.commands' will usually be NULL by now, but |
| 12900 | bpstat_do_actions_1 may return early without processing the whole |
| 12901 | list. */ |
| 12902 | } |
| 12903 | |
| 12904 | /* The breakpoint_ops structure to be used on static tracepoints with |
| 12905 | markers (`-m'). */ |
| 12906 | |
| 12907 | static void |
| 12908 | strace_marker_create_sals_from_location (const struct event_location *location, |
| 12909 | struct linespec_result *canonical, |
| 12910 | enum bptype type_wanted) |
| 12911 | { |
| 12912 | struct linespec_sals lsal; |
| 12913 | const char *arg_start, *arg; |
| 12914 | |
| 12915 | arg = arg_start = get_linespec_location (location)->spec_string; |
| 12916 | lsal.sals = decode_static_tracepoint_spec (&arg); |
| 12917 | |
| 12918 | std::string str (arg_start, arg - arg_start); |
| 12919 | const char *ptr = str.c_str (); |
| 12920 | canonical->location |
| 12921 | = new_linespec_location (&ptr, symbol_name_match_type::FULL); |
| 12922 | |
| 12923 | lsal.canonical |
| 12924 | = xstrdup (event_location_to_string (canonical->location.get ())); |
| 12925 | canonical->lsals.push_back (std::move (lsal)); |
| 12926 | } |
| 12927 | |
| 12928 | static void |
| 12929 | strace_marker_create_breakpoints_sal (struct gdbarch *gdbarch, |
| 12930 | struct linespec_result *canonical, |
| 12931 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 12932 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 12933 | enum bptype type_wanted, |
| 12934 | enum bpdisp disposition, |
| 12935 | int thread, |
| 12936 | int task, int ignore_count, |
| 12937 | const struct breakpoint_ops *ops, |
| 12938 | int from_tty, int enabled, |
| 12939 | int internal, unsigned flags) |
| 12940 | { |
| 12941 | const linespec_sals &lsal = canonical->lsals[0]; |
| 12942 | |
| 12943 | /* If the user is creating a static tracepoint by marker id |
| 12944 | (strace -m MARKER_ID), then store the sals index, so that |
| 12945 | breakpoint_re_set can try to match up which of the newly |
| 12946 | found markers corresponds to this one, and, don't try to |
| 12947 | expand multiple locations for each sal, given than SALS |
| 12948 | already should contain all sals for MARKER_ID. */ |
| 12949 | |
| 12950 | for (size_t i = 0; i < lsal.sals.size (); i++) |
| 12951 | { |
| 12952 | event_location_up location |
| 12953 | = copy_event_location (canonical->location.get ()); |
| 12954 | |
| 12955 | std::unique_ptr<tracepoint> tp (new tracepoint ()); |
| 12956 | init_breakpoint_sal (tp.get (), gdbarch, lsal.sals[i], |
| 12957 | std::move (location), NULL, |
| 12958 | std::move (cond_string), |
| 12959 | std::move (extra_string), |
| 12960 | type_wanted, disposition, |
| 12961 | thread, task, ignore_count, ops, |
| 12962 | from_tty, enabled, internal, flags, |
| 12963 | canonical->special_display); |
| 12964 | /* Given that its possible to have multiple markers with |
| 12965 | the same string id, if the user is creating a static |
| 12966 | tracepoint by marker id ("strace -m MARKER_ID"), then |
| 12967 | store the sals index, so that breakpoint_re_set can |
| 12968 | try to match up which of the newly found markers |
| 12969 | corresponds to this one */ |
| 12970 | tp->static_trace_marker_id_idx = i; |
| 12971 | |
| 12972 | install_breakpoint (internal, std::move (tp), 0); |
| 12973 | } |
| 12974 | } |
| 12975 | |
| 12976 | static std::vector<symtab_and_line> |
| 12977 | strace_marker_decode_location (struct breakpoint *b, |
| 12978 | const struct event_location *location, |
| 12979 | struct program_space *search_pspace) |
| 12980 | { |
| 12981 | struct tracepoint *tp = (struct tracepoint *) b; |
| 12982 | const char *s = get_linespec_location (location)->spec_string; |
| 12983 | |
| 12984 | std::vector<symtab_and_line> sals = decode_static_tracepoint_spec (&s); |
| 12985 | if (sals.size () > tp->static_trace_marker_id_idx) |
| 12986 | { |
| 12987 | sals[0] = sals[tp->static_trace_marker_id_idx]; |
| 12988 | sals.resize (1); |
| 12989 | return sals; |
| 12990 | } |
| 12991 | else |
| 12992 | error (_("marker %s not found"), tp->static_trace_marker_id.c_str ()); |
| 12993 | } |
| 12994 | |
| 12995 | static struct breakpoint_ops strace_marker_breakpoint_ops; |
| 12996 | |
| 12997 | static int |
| 12998 | strace_marker_p (struct breakpoint *b) |
| 12999 | { |
| 13000 | return b->ops == &strace_marker_breakpoint_ops; |
| 13001 | } |
| 13002 | |
| 13003 | /* Delete a breakpoint and clean up all traces of it in the data |
| 13004 | structures. */ |
| 13005 | |
| 13006 | void |
| 13007 | delete_breakpoint (struct breakpoint *bpt) |
| 13008 | { |
| 13009 | struct breakpoint *b; |
| 13010 | |
| 13011 | gdb_assert (bpt != NULL); |
| 13012 | |
| 13013 | /* Has this bp already been deleted? This can happen because |
| 13014 | multiple lists can hold pointers to bp's. bpstat lists are |
| 13015 | especial culprits. |
| 13016 | |
| 13017 | One example of this happening is a watchpoint's scope bp. When |
| 13018 | the scope bp triggers, we notice that the watchpoint is out of |
| 13019 | scope, and delete it. We also delete its scope bp. But the |
| 13020 | scope bp is marked "auto-deleting", and is already on a bpstat. |
| 13021 | That bpstat is then checked for auto-deleting bp's, which are |
| 13022 | deleted. |
| 13023 | |
| 13024 | A real solution to this problem might involve reference counts in |
| 13025 | bp's, and/or giving them pointers back to their referencing |
| 13026 | bpstat's, and teaching delete_breakpoint to only free a bp's |
| 13027 | storage when no more references were extent. A cheaper bandaid |
| 13028 | was chosen. */ |
| 13029 | if (bpt->type == bp_none) |
| 13030 | return; |
| 13031 | |
| 13032 | /* At least avoid this stale reference until the reference counting |
| 13033 | of breakpoints gets resolved. */ |
| 13034 | if (bpt->related_breakpoint != bpt) |
| 13035 | { |
| 13036 | struct breakpoint *related; |
| 13037 | struct watchpoint *w; |
| 13038 | |
| 13039 | if (bpt->type == bp_watchpoint_scope) |
| 13040 | w = (struct watchpoint *) bpt->related_breakpoint; |
| 13041 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
| 13042 | w = (struct watchpoint *) bpt; |
| 13043 | else |
| 13044 | w = NULL; |
| 13045 | if (w != NULL) |
| 13046 | watchpoint_del_at_next_stop (w); |
| 13047 | |
| 13048 | /* Unlink bpt from the bpt->related_breakpoint ring. */ |
| 13049 | for (related = bpt; related->related_breakpoint != bpt; |
| 13050 | related = related->related_breakpoint); |
| 13051 | related->related_breakpoint = bpt->related_breakpoint; |
| 13052 | bpt->related_breakpoint = bpt; |
| 13053 | } |
| 13054 | |
| 13055 | /* watch_command_1 creates a watchpoint but only sets its number if |
| 13056 | update_watchpoint succeeds in creating its bp_locations. If there's |
| 13057 | a problem in that process, we'll be asked to delete the half-created |
| 13058 | watchpoint. In that case, don't announce the deletion. */ |
| 13059 | if (bpt->number) |
| 13060 | gdb::observers::breakpoint_deleted.notify (bpt); |
| 13061 | |
| 13062 | if (breakpoint_chain == bpt) |
| 13063 | breakpoint_chain = bpt->next; |
| 13064 | |
| 13065 | ALL_BREAKPOINTS (b) |
| 13066 | if (b->next == bpt) |
| 13067 | { |
| 13068 | b->next = bpt->next; |
| 13069 | break; |
| 13070 | } |
| 13071 | |
| 13072 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
| 13073 | been freed. */ |
| 13074 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat |
| 13075 | in all threads for now. Note that we cannot just remove bpstats |
| 13076 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
| 13077 | commands are associated with the bpstat; if we remove it here, |
| 13078 | then the later call to bpstat_do_actions (&stop_bpstat); in |
| 13079 | event-top.c won't do anything, and temporary breakpoints with |
| 13080 | commands won't work. */ |
| 13081 | |
| 13082 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
| 13083 | |
| 13084 | /* Now that breakpoint is removed from breakpoint list, update the |
| 13085 | global location list. This will remove locations that used to |
| 13086 | belong to this breakpoint. Do this before freeing the breakpoint |
| 13087 | itself, since remove_breakpoint looks at location's owner. It |
| 13088 | might be better design to have location completely |
| 13089 | self-contained, but it's not the case now. */ |
| 13090 | update_global_location_list (UGLL_DONT_INSERT); |
| 13091 | |
| 13092 | /* On the chance that someone will soon try again to delete this |
| 13093 | same bp, we mark it as deleted before freeing its storage. */ |
| 13094 | bpt->type = bp_none; |
| 13095 | delete bpt; |
| 13096 | } |
| 13097 | |
| 13098 | /* Iterator function to call a user-provided callback function once |
| 13099 | for each of B and its related breakpoints. */ |
| 13100 | |
| 13101 | static void |
| 13102 | iterate_over_related_breakpoints (struct breakpoint *b, |
| 13103 | gdb::function_view<void (breakpoint *)> function) |
| 13104 | { |
| 13105 | struct breakpoint *related; |
| 13106 | |
| 13107 | related = b; |
| 13108 | do |
| 13109 | { |
| 13110 | struct breakpoint *next; |
| 13111 | |
| 13112 | /* FUNCTION may delete RELATED. */ |
| 13113 | next = related->related_breakpoint; |
| 13114 | |
| 13115 | if (next == related) |
| 13116 | { |
| 13117 | /* RELATED is the last ring entry. */ |
| 13118 | function (related); |
| 13119 | |
| 13120 | /* FUNCTION may have deleted it, so we'd never reach back to |
| 13121 | B. There's nothing left to do anyway, so just break |
| 13122 | out. */ |
| 13123 | break; |
| 13124 | } |
| 13125 | else |
| 13126 | function (related); |
| 13127 | |
| 13128 | related = next; |
| 13129 | } |
| 13130 | while (related != b); |
| 13131 | } |
| 13132 | |
| 13133 | static void |
| 13134 | delete_command (const char *arg, int from_tty) |
| 13135 | { |
| 13136 | struct breakpoint *b, *b_tmp; |
| 13137 | |
| 13138 | dont_repeat (); |
| 13139 | |
| 13140 | if (arg == 0) |
| 13141 | { |
| 13142 | int breaks_to_delete = 0; |
| 13143 | |
| 13144 | /* Delete all breakpoints if no argument. Do not delete |
| 13145 | internal breakpoints, these have to be deleted with an |
| 13146 | explicit breakpoint number argument. */ |
| 13147 | ALL_BREAKPOINTS (b) |
| 13148 | if (user_breakpoint_p (b)) |
| 13149 | { |
| 13150 | breaks_to_delete = 1; |
| 13151 | break; |
| 13152 | } |
| 13153 | |
| 13154 | /* Ask user only if there are some breakpoints to delete. */ |
| 13155 | if (!from_tty |
| 13156 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
| 13157 | { |
| 13158 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 13159 | if (user_breakpoint_p (b)) |
| 13160 | delete_breakpoint (b); |
| 13161 | } |
| 13162 | } |
| 13163 | else |
| 13164 | map_breakpoint_numbers |
| 13165 | (arg, [&] (breakpoint *br) |
| 13166 | { |
| 13167 | iterate_over_related_breakpoints (br, delete_breakpoint); |
| 13168 | }); |
| 13169 | } |
| 13170 | |
| 13171 | /* Return true if all locations of B bound to PSPACE are pending. If |
| 13172 | PSPACE is NULL, all locations of all program spaces are |
| 13173 | considered. */ |
| 13174 | |
| 13175 | static int |
| 13176 | all_locations_are_pending (struct breakpoint *b, struct program_space *pspace) |
| 13177 | { |
| 13178 | struct bp_location *loc; |
| 13179 | |
| 13180 | for (loc = b->loc; loc != NULL; loc = loc->next) |
| 13181 | if ((pspace == NULL |
| 13182 | || loc->pspace == pspace) |
| 13183 | && !loc->shlib_disabled |
| 13184 | && !loc->pspace->executing_startup) |
| 13185 | return 0; |
| 13186 | return 1; |
| 13187 | } |
| 13188 | |
| 13189 | /* Subroutine of update_breakpoint_locations to simplify it. |
| 13190 | Return non-zero if multiple fns in list LOC have the same name. |
| 13191 | Null names are ignored. */ |
| 13192 | |
| 13193 | static int |
| 13194 | ambiguous_names_p (struct bp_location *loc) |
| 13195 | { |
| 13196 | struct bp_location *l; |
| 13197 | htab_t htab = htab_create_alloc (13, htab_hash_string, streq_hash, NULL, |
| 13198 | xcalloc, xfree); |
| 13199 | |
| 13200 | for (l = loc; l != NULL; l = l->next) |
| 13201 | { |
| 13202 | const char **slot; |
| 13203 | const char *name = l->function_name; |
| 13204 | |
| 13205 | /* Allow for some names to be NULL, ignore them. */ |
| 13206 | if (name == NULL) |
| 13207 | continue; |
| 13208 | |
| 13209 | slot = (const char **) htab_find_slot (htab, (const void *) name, |
| 13210 | INSERT); |
| 13211 | /* NOTE: We can assume slot != NULL here because xcalloc never |
| 13212 | returns NULL. */ |
| 13213 | if (*slot != NULL) |
| 13214 | { |
| 13215 | htab_delete (htab); |
| 13216 | return 1; |
| 13217 | } |
| 13218 | *slot = name; |
| 13219 | } |
| 13220 | |
| 13221 | htab_delete (htab); |
| 13222 | return 0; |
| 13223 | } |
| 13224 | |
| 13225 | /* When symbols change, it probably means the sources changed as well, |
| 13226 | and it might mean the static tracepoint markers are no longer at |
| 13227 | the same address or line numbers they used to be at last we |
| 13228 | checked. Losing your static tracepoints whenever you rebuild is |
| 13229 | undesirable. This function tries to resync/rematch gdb static |
| 13230 | tracepoints with the markers on the target, for static tracepoints |
| 13231 | that have not been set by marker id. Static tracepoint that have |
| 13232 | been set by marker id are reset by marker id in breakpoint_re_set. |
| 13233 | The heuristic is: |
| 13234 | |
| 13235 | 1) For a tracepoint set at a specific address, look for a marker at |
| 13236 | the old PC. If one is found there, assume to be the same marker. |
| 13237 | If the name / string id of the marker found is different from the |
| 13238 | previous known name, assume that means the user renamed the marker |
| 13239 | in the sources, and output a warning. |
| 13240 | |
| 13241 | 2) For a tracepoint set at a given line number, look for a marker |
| 13242 | at the new address of the old line number. If one is found there, |
| 13243 | assume to be the same marker. If the name / string id of the |
| 13244 | marker found is different from the previous known name, assume that |
| 13245 | means the user renamed the marker in the sources, and output a |
| 13246 | warning. |
| 13247 | |
| 13248 | 3) If a marker is no longer found at the same address or line, it |
| 13249 | may mean the marker no longer exists. But it may also just mean |
| 13250 | the code changed a bit. Maybe the user added a few lines of code |
| 13251 | that made the marker move up or down (in line number terms). Ask |
| 13252 | the target for info about the marker with the string id as we knew |
| 13253 | it. If found, update line number and address in the matching |
| 13254 | static tracepoint. This will get confused if there's more than one |
| 13255 | marker with the same ID (possible in UST, although unadvised |
| 13256 | precisely because it confuses tools). */ |
| 13257 | |
| 13258 | static struct symtab_and_line |
| 13259 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) |
| 13260 | { |
| 13261 | struct tracepoint *tp = (struct tracepoint *) b; |
| 13262 | struct static_tracepoint_marker marker; |
| 13263 | CORE_ADDR pc; |
| 13264 | |
| 13265 | pc = sal.pc; |
| 13266 | if (sal.line) |
| 13267 | find_line_pc (sal.symtab, sal.line, &pc); |
| 13268 | |
| 13269 | if (target_static_tracepoint_marker_at (pc, &marker)) |
| 13270 | { |
| 13271 | if (tp->static_trace_marker_id != marker.str_id) |
| 13272 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
| 13273 | b->number, tp->static_trace_marker_id.c_str (), |
| 13274 | marker.str_id.c_str ()); |
| 13275 | |
| 13276 | tp->static_trace_marker_id = std::move (marker.str_id); |
| 13277 | |
| 13278 | return sal; |
| 13279 | } |
| 13280 | |
| 13281 | /* Old marker wasn't found on target at lineno. Try looking it up |
| 13282 | by string ID. */ |
| 13283 | if (!sal.explicit_pc |
| 13284 | && sal.line != 0 |
| 13285 | && sal.symtab != NULL |
| 13286 | && !tp->static_trace_marker_id.empty ()) |
| 13287 | { |
| 13288 | std::vector<static_tracepoint_marker> markers |
| 13289 | = target_static_tracepoint_markers_by_strid |
| 13290 | (tp->static_trace_marker_id.c_str ()); |
| 13291 | |
| 13292 | if (!markers.empty ()) |
| 13293 | { |
| 13294 | struct symbol *sym; |
| 13295 | struct static_tracepoint_marker *tpmarker; |
| 13296 | struct ui_out *uiout = current_uiout; |
| 13297 | struct explicit_location explicit_loc; |
| 13298 | |
| 13299 | tpmarker = &markers[0]; |
| 13300 | |
| 13301 | tp->static_trace_marker_id = std::move (tpmarker->str_id); |
| 13302 | |
| 13303 | warning (_("marker for static tracepoint %d (%s) not " |
| 13304 | "found at previous line number"), |
| 13305 | b->number, tp->static_trace_marker_id.c_str ()); |
| 13306 | |
| 13307 | symtab_and_line sal2 = find_pc_line (tpmarker->address, 0); |
| 13308 | sym = find_pc_sect_function (tpmarker->address, NULL); |
| 13309 | uiout->text ("Now in "); |
| 13310 | if (sym) |
| 13311 | { |
| 13312 | uiout->field_string ("func", SYMBOL_PRINT_NAME (sym), |
| 13313 | function_name_style.style ()); |
| 13314 | uiout->text (" at "); |
| 13315 | } |
| 13316 | uiout->field_string ("file", |
| 13317 | symtab_to_filename_for_display (sal2.symtab), |
| 13318 | file_name_style.style ()); |
| 13319 | uiout->text (":"); |
| 13320 | |
| 13321 | if (uiout->is_mi_like_p ()) |
| 13322 | { |
| 13323 | const char *fullname = symtab_to_fullname (sal2.symtab); |
| 13324 | |
| 13325 | uiout->field_string ("fullname", fullname); |
| 13326 | } |
| 13327 | |
| 13328 | uiout->field_signed ("line", sal2.line); |
| 13329 | uiout->text ("\n"); |
| 13330 | |
| 13331 | b->loc->line_number = sal2.line; |
| 13332 | b->loc->symtab = sym != NULL ? sal2.symtab : NULL; |
| 13333 | |
| 13334 | b->location.reset (NULL); |
| 13335 | initialize_explicit_location (&explicit_loc); |
| 13336 | explicit_loc.source_filename |
| 13337 | = ASTRDUP (symtab_to_filename_for_display (sal2.symtab)); |
| 13338 | explicit_loc.line_offset.offset = b->loc->line_number; |
| 13339 | explicit_loc.line_offset.sign = LINE_OFFSET_NONE; |
| 13340 | b->location = new_explicit_location (&explicit_loc); |
| 13341 | |
| 13342 | /* Might be nice to check if function changed, and warn if |
| 13343 | so. */ |
| 13344 | } |
| 13345 | } |
| 13346 | return sal; |
| 13347 | } |
| 13348 | |
| 13349 | /* Returns 1 iff locations A and B are sufficiently same that |
| 13350 | we don't need to report breakpoint as changed. */ |
| 13351 | |
| 13352 | static int |
| 13353 | locations_are_equal (struct bp_location *a, struct bp_location *b) |
| 13354 | { |
| 13355 | while (a && b) |
| 13356 | { |
| 13357 | if (a->address != b->address) |
| 13358 | return 0; |
| 13359 | |
| 13360 | if (a->shlib_disabled != b->shlib_disabled) |
| 13361 | return 0; |
| 13362 | |
| 13363 | if (a->enabled != b->enabled) |
| 13364 | return 0; |
| 13365 | |
| 13366 | a = a->next; |
| 13367 | b = b->next; |
| 13368 | } |
| 13369 | |
| 13370 | if ((a == NULL) != (b == NULL)) |
| 13371 | return 0; |
| 13372 | |
| 13373 | return 1; |
| 13374 | } |
| 13375 | |
| 13376 | /* Split all locations of B that are bound to PSPACE out of B's |
| 13377 | location list to a separate list and return that list's head. If |
| 13378 | PSPACE is NULL, hoist out all locations of B. */ |
| 13379 | |
| 13380 | static struct bp_location * |
| 13381 | hoist_existing_locations (struct breakpoint *b, struct program_space *pspace) |
| 13382 | { |
| 13383 | struct bp_location head; |
| 13384 | struct bp_location *i = b->loc; |
| 13385 | struct bp_location **i_link = &b->loc; |
| 13386 | struct bp_location *hoisted = &head; |
| 13387 | |
| 13388 | if (pspace == NULL) |
| 13389 | { |
| 13390 | i = b->loc; |
| 13391 | b->loc = NULL; |
| 13392 | return i; |
| 13393 | } |
| 13394 | |
| 13395 | head.next = NULL; |
| 13396 | |
| 13397 | while (i != NULL) |
| 13398 | { |
| 13399 | if (i->pspace == pspace) |
| 13400 | { |
| 13401 | *i_link = i->next; |
| 13402 | i->next = NULL; |
| 13403 | hoisted->next = i; |
| 13404 | hoisted = i; |
| 13405 | } |
| 13406 | else |
| 13407 | i_link = &i->next; |
| 13408 | i = *i_link; |
| 13409 | } |
| 13410 | |
| 13411 | return head.next; |
| 13412 | } |
| 13413 | |
| 13414 | /* Create new breakpoint locations for B (a hardware or software |
| 13415 | breakpoint) based on SALS and SALS_END. If SALS_END.NELTS is not |
| 13416 | zero, then B is a ranged breakpoint. Only recreates locations for |
| 13417 | FILTER_PSPACE. Locations of other program spaces are left |
| 13418 | untouched. */ |
| 13419 | |
| 13420 | void |
| 13421 | update_breakpoint_locations (struct breakpoint *b, |
| 13422 | struct program_space *filter_pspace, |
| 13423 | gdb::array_view<const symtab_and_line> sals, |
| 13424 | gdb::array_view<const symtab_and_line> sals_end) |
| 13425 | { |
| 13426 | struct bp_location *existing_locations; |
| 13427 | |
| 13428 | if (!sals_end.empty () && (sals.size () != 1 || sals_end.size () != 1)) |
| 13429 | { |
| 13430 | /* Ranged breakpoints have only one start location and one end |
| 13431 | location. */ |
| 13432 | b->enable_state = bp_disabled; |
| 13433 | printf_unfiltered (_("Could not reset ranged breakpoint %d: " |
| 13434 | "multiple locations found\n"), |
| 13435 | b->number); |
| 13436 | return; |
| 13437 | } |
| 13438 | |
| 13439 | /* If there's no new locations, and all existing locations are |
| 13440 | pending, don't do anything. This optimizes the common case where |
| 13441 | all locations are in the same shared library, that was unloaded. |
| 13442 | We'd like to retain the location, so that when the library is |
| 13443 | loaded again, we don't loose the enabled/disabled status of the |
| 13444 | individual locations. */ |
| 13445 | if (all_locations_are_pending (b, filter_pspace) && sals.empty ()) |
| 13446 | return; |
| 13447 | |
| 13448 | existing_locations = hoist_existing_locations (b, filter_pspace); |
| 13449 | |
| 13450 | for (const auto &sal : sals) |
| 13451 | { |
| 13452 | struct bp_location *new_loc; |
| 13453 | |
| 13454 | switch_to_program_space_and_thread (sal.pspace); |
| 13455 | |
| 13456 | new_loc = add_location_to_breakpoint (b, &sal); |
| 13457 | |
| 13458 | /* Reparse conditions, they might contain references to the |
| 13459 | old symtab. */ |
| 13460 | if (b->cond_string != NULL) |
| 13461 | { |
| 13462 | const char *s; |
| 13463 | |
| 13464 | s = b->cond_string; |
| 13465 | try |
| 13466 | { |
| 13467 | new_loc->cond = parse_exp_1 (&s, sal.pc, |
| 13468 | block_for_pc (sal.pc), |
| 13469 | 0); |
| 13470 | } |
| 13471 | catch (const gdb_exception_error &e) |
| 13472 | { |
| 13473 | warning (_("failed to reevaluate condition " |
| 13474 | "for breakpoint %d: %s"), |
| 13475 | b->number, e.what ()); |
| 13476 | new_loc->enabled = 0; |
| 13477 | } |
| 13478 | } |
| 13479 | |
| 13480 | if (!sals_end.empty ()) |
| 13481 | { |
| 13482 | CORE_ADDR end = find_breakpoint_range_end (sals_end[0]); |
| 13483 | |
| 13484 | new_loc->length = end - sals[0].pc + 1; |
| 13485 | } |
| 13486 | } |
| 13487 | |
| 13488 | /* If possible, carry over 'disable' status from existing |
| 13489 | breakpoints. */ |
| 13490 | { |
| 13491 | struct bp_location *e = existing_locations; |
| 13492 | /* If there are multiple breakpoints with the same function name, |
| 13493 | e.g. for inline functions, comparing function names won't work. |
| 13494 | Instead compare pc addresses; this is just a heuristic as things |
| 13495 | may have moved, but in practice it gives the correct answer |
| 13496 | often enough until a better solution is found. */ |
| 13497 | int have_ambiguous_names = ambiguous_names_p (b->loc); |
| 13498 | |
| 13499 | for (; e; e = e->next) |
| 13500 | { |
| 13501 | if (!e->enabled && e->function_name) |
| 13502 | { |
| 13503 | struct bp_location *l = b->loc; |
| 13504 | if (have_ambiguous_names) |
| 13505 | { |
| 13506 | for (; l; l = l->next) |
| 13507 | if (breakpoint_locations_match (e, l)) |
| 13508 | { |
| 13509 | l->enabled = 0; |
| 13510 | break; |
| 13511 | } |
| 13512 | } |
| 13513 | else |
| 13514 | { |
| 13515 | for (; l; l = l->next) |
| 13516 | if (l->function_name |
| 13517 | && strcmp (e->function_name, l->function_name) == 0) |
| 13518 | { |
| 13519 | l->enabled = 0; |
| 13520 | break; |
| 13521 | } |
| 13522 | } |
| 13523 | } |
| 13524 | } |
| 13525 | } |
| 13526 | |
| 13527 | if (!locations_are_equal (existing_locations, b->loc)) |
| 13528 | gdb::observers::breakpoint_modified.notify (b); |
| 13529 | } |
| 13530 | |
| 13531 | /* Find the SaL locations corresponding to the given LOCATION. |
| 13532 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ |
| 13533 | |
| 13534 | static std::vector<symtab_and_line> |
| 13535 | location_to_sals (struct breakpoint *b, struct event_location *location, |
| 13536 | struct program_space *search_pspace, int *found) |
| 13537 | { |
| 13538 | struct gdb_exception exception; |
| 13539 | |
| 13540 | gdb_assert (b->ops != NULL); |
| 13541 | |
| 13542 | std::vector<symtab_and_line> sals; |
| 13543 | |
| 13544 | try |
| 13545 | { |
| 13546 | sals = b->ops->decode_location (b, location, search_pspace); |
| 13547 | } |
| 13548 | catch (gdb_exception_error &e) |
| 13549 | { |
| 13550 | int not_found_and_ok = 0; |
| 13551 | |
| 13552 | /* For pending breakpoints, it's expected that parsing will |
| 13553 | fail until the right shared library is loaded. User has |
| 13554 | already told to create pending breakpoints and don't need |
| 13555 | extra messages. If breakpoint is in bp_shlib_disabled |
| 13556 | state, then user already saw the message about that |
| 13557 | breakpoint being disabled, and don't want to see more |
| 13558 | errors. */ |
| 13559 | if (e.error == NOT_FOUND_ERROR |
| 13560 | && (b->condition_not_parsed |
| 13561 | || (b->loc != NULL |
| 13562 | && search_pspace != NULL |
| 13563 | && b->loc->pspace != search_pspace) |
| 13564 | || (b->loc && b->loc->shlib_disabled) |
| 13565 | || (b->loc && b->loc->pspace->executing_startup) |
| 13566 | || b->enable_state == bp_disabled)) |
| 13567 | not_found_and_ok = 1; |
| 13568 | |
| 13569 | if (!not_found_and_ok) |
| 13570 | { |
| 13571 | /* We surely don't want to warn about the same breakpoint |
| 13572 | 10 times. One solution, implemented here, is disable |
| 13573 | the breakpoint on error. Another solution would be to |
| 13574 | have separate 'warning emitted' flag. Since this |
| 13575 | happens only when a binary has changed, I don't know |
| 13576 | which approach is better. */ |
| 13577 | b->enable_state = bp_disabled; |
| 13578 | throw; |
| 13579 | } |
| 13580 | |
| 13581 | exception = std::move (e); |
| 13582 | } |
| 13583 | |
| 13584 | if (exception.reason == 0 || exception.error != NOT_FOUND_ERROR) |
| 13585 | { |
| 13586 | for (auto &sal : sals) |
| 13587 | resolve_sal_pc (&sal); |
| 13588 | if (b->condition_not_parsed && b->extra_string != NULL) |
| 13589 | { |
| 13590 | char *cond_string, *extra_string; |
| 13591 | int thread, task; |
| 13592 | |
| 13593 | find_condition_and_thread (b->extra_string, sals[0].pc, |
| 13594 | &cond_string, &thread, &task, |
| 13595 | &extra_string); |
| 13596 | gdb_assert (b->cond_string == NULL); |
| 13597 | if (cond_string) |
| 13598 | b->cond_string = cond_string; |
| 13599 | b->thread = thread; |
| 13600 | b->task = task; |
| 13601 | if (extra_string) |
| 13602 | { |
| 13603 | xfree (b->extra_string); |
| 13604 | b->extra_string = extra_string; |
| 13605 | } |
| 13606 | b->condition_not_parsed = 0; |
| 13607 | } |
| 13608 | |
| 13609 | if (b->type == bp_static_tracepoint && !strace_marker_p (b)) |
| 13610 | sals[0] = update_static_tracepoint (b, sals[0]); |
| 13611 | |
| 13612 | *found = 1; |
| 13613 | } |
| 13614 | else |
| 13615 | *found = 0; |
| 13616 | |
| 13617 | return sals; |
| 13618 | } |
| 13619 | |
| 13620 | /* The default re_set method, for typical hardware or software |
| 13621 | breakpoints. Reevaluate the breakpoint and recreate its |
| 13622 | locations. */ |
| 13623 | |
| 13624 | static void |
| 13625 | breakpoint_re_set_default (struct breakpoint *b) |
| 13626 | { |
| 13627 | struct program_space *filter_pspace = current_program_space; |
| 13628 | std::vector<symtab_and_line> expanded, expanded_end; |
| 13629 | |
| 13630 | int found; |
| 13631 | std::vector<symtab_and_line> sals = location_to_sals (b, b->location.get (), |
| 13632 | filter_pspace, &found); |
| 13633 | if (found) |
| 13634 | expanded = std::move (sals); |
| 13635 | |
| 13636 | if (b->location_range_end != NULL) |
| 13637 | { |
| 13638 | std::vector<symtab_and_line> sals_end |
| 13639 | = location_to_sals (b, b->location_range_end.get (), |
| 13640 | filter_pspace, &found); |
| 13641 | if (found) |
| 13642 | expanded_end = std::move (sals_end); |
| 13643 | } |
| 13644 | |
| 13645 | update_breakpoint_locations (b, filter_pspace, expanded, expanded_end); |
| 13646 | } |
| 13647 | |
| 13648 | /* Default method for creating SALs from an address string. It basically |
| 13649 | calls parse_breakpoint_sals. Return 1 for success, zero for failure. */ |
| 13650 | |
| 13651 | static void |
| 13652 | create_sals_from_location_default (const struct event_location *location, |
| 13653 | struct linespec_result *canonical, |
| 13654 | enum bptype type_wanted) |
| 13655 | { |
| 13656 | parse_breakpoint_sals (location, canonical); |
| 13657 | } |
| 13658 | |
| 13659 | /* Call create_breakpoints_sal for the given arguments. This is the default |
| 13660 | function for the `create_breakpoints_sal' method of |
| 13661 | breakpoint_ops. */ |
| 13662 | |
| 13663 | static void |
| 13664 | create_breakpoints_sal_default (struct gdbarch *gdbarch, |
| 13665 | struct linespec_result *canonical, |
| 13666 | gdb::unique_xmalloc_ptr<char> cond_string, |
| 13667 | gdb::unique_xmalloc_ptr<char> extra_string, |
| 13668 | enum bptype type_wanted, |
| 13669 | enum bpdisp disposition, |
| 13670 | int thread, |
| 13671 | int task, int ignore_count, |
| 13672 | const struct breakpoint_ops *ops, |
| 13673 | int from_tty, int enabled, |
| 13674 | int internal, unsigned flags) |
| 13675 | { |
| 13676 | create_breakpoints_sal (gdbarch, canonical, |
| 13677 | std::move (cond_string), |
| 13678 | std::move (extra_string), |
| 13679 | type_wanted, disposition, |
| 13680 | thread, task, ignore_count, ops, from_tty, |
| 13681 | enabled, internal, flags); |
| 13682 | } |
| 13683 | |
| 13684 | /* Decode the line represented by S by calling decode_line_full. This is the |
| 13685 | default function for the `decode_location' method of breakpoint_ops. */ |
| 13686 | |
| 13687 | static std::vector<symtab_and_line> |
| 13688 | decode_location_default (struct breakpoint *b, |
| 13689 | const struct event_location *location, |
| 13690 | struct program_space *search_pspace) |
| 13691 | { |
| 13692 | struct linespec_result canonical; |
| 13693 | |
| 13694 | decode_line_full (location, DECODE_LINE_FUNFIRSTLINE, search_pspace, |
| 13695 | NULL, 0, &canonical, multiple_symbols_all, |
| 13696 | b->filter.get ()); |
| 13697 | |
| 13698 | /* We should get 0 or 1 resulting SALs. */ |
| 13699 | gdb_assert (canonical.lsals.size () < 2); |
| 13700 | |
| 13701 | if (!canonical.lsals.empty ()) |
| 13702 | { |
| 13703 | const linespec_sals &lsal = canonical.lsals[0]; |
| 13704 | return std::move (lsal.sals); |
| 13705 | } |
| 13706 | return {}; |
| 13707 | } |
| 13708 | |
| 13709 | /* Reset a breakpoint. */ |
| 13710 | |
| 13711 | static void |
| 13712 | breakpoint_re_set_one (breakpoint *b) |
| 13713 | { |
| 13714 | input_radix = b->input_radix; |
| 13715 | set_language (b->language); |
| 13716 | |
| 13717 | b->ops->re_set (b); |
| 13718 | } |
| 13719 | |
| 13720 | /* Re-set breakpoint locations for the current program space. |
| 13721 | Locations bound to other program spaces are left untouched. */ |
| 13722 | |
| 13723 | void |
| 13724 | breakpoint_re_set (void) |
| 13725 | { |
| 13726 | struct breakpoint *b, *b_tmp; |
| 13727 | |
| 13728 | { |
| 13729 | scoped_restore_current_language save_language; |
| 13730 | scoped_restore save_input_radix = make_scoped_restore (&input_radix); |
| 13731 | scoped_restore_current_pspace_and_thread restore_pspace_thread; |
| 13732 | |
| 13733 | /* breakpoint_re_set_one sets the current_language to the language |
| 13734 | of the breakpoint it is resetting (see prepare_re_set_context) |
| 13735 | before re-evaluating the breakpoint's location. This change can |
| 13736 | unfortunately get undone by accident if the language_mode is set |
| 13737 | to auto, and we either switch frames, or more likely in this context, |
| 13738 | we select the current frame. |
| 13739 | |
| 13740 | We prevent this by temporarily turning the language_mode to |
| 13741 | language_mode_manual. We restore it once all breakpoints |
| 13742 | have been reset. */ |
| 13743 | scoped_restore save_language_mode = make_scoped_restore (&language_mode); |
| 13744 | language_mode = language_mode_manual; |
| 13745 | |
| 13746 | /* Note: we must not try to insert locations until after all |
| 13747 | breakpoints have been re-set. Otherwise, e.g., when re-setting |
| 13748 | breakpoint 1, we'd insert the locations of breakpoint 2, which |
| 13749 | hadn't been re-set yet, and thus may have stale locations. */ |
| 13750 | |
| 13751 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 13752 | { |
| 13753 | try |
| 13754 | { |
| 13755 | breakpoint_re_set_one (b); |
| 13756 | } |
| 13757 | catch (const gdb_exception &ex) |
| 13758 | { |
| 13759 | exception_fprintf (gdb_stderr, ex, |
| 13760 | "Error in re-setting breakpoint %d: ", |
| 13761 | b->number); |
| 13762 | } |
| 13763 | } |
| 13764 | |
| 13765 | jit_breakpoint_re_set (); |
| 13766 | } |
| 13767 | |
| 13768 | create_overlay_event_breakpoint (); |
| 13769 | create_longjmp_master_breakpoint (); |
| 13770 | create_std_terminate_master_breakpoint (); |
| 13771 | create_exception_master_breakpoint (); |
| 13772 | |
| 13773 | /* Now we can insert. */ |
| 13774 | update_global_location_list (UGLL_MAY_INSERT); |
| 13775 | } |
| 13776 | \f |
| 13777 | /* Reset the thread number of this breakpoint: |
| 13778 | |
| 13779 | - If the breakpoint is for all threads, leave it as-is. |
| 13780 | - Else, reset it to the current thread for inferior_ptid. */ |
| 13781 | void |
| 13782 | breakpoint_re_set_thread (struct breakpoint *b) |
| 13783 | { |
| 13784 | if (b->thread != -1) |
| 13785 | { |
| 13786 | b->thread = inferior_thread ()->global_num; |
| 13787 | |
| 13788 | /* We're being called after following a fork. The new fork is |
| 13789 | selected as current, and unless this was a vfork will have a |
| 13790 | different program space from the original thread. Reset that |
| 13791 | as well. */ |
| 13792 | b->loc->pspace = current_program_space; |
| 13793 | } |
| 13794 | } |
| 13795 | |
| 13796 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 13797 | If from_tty is nonzero, it prints a message to that effect, |
| 13798 | which ends with a period (no newline). */ |
| 13799 | |
| 13800 | void |
| 13801 | set_ignore_count (int bptnum, int count, int from_tty) |
| 13802 | { |
| 13803 | struct breakpoint *b; |
| 13804 | |
| 13805 | if (count < 0) |
| 13806 | count = 0; |
| 13807 | |
| 13808 | ALL_BREAKPOINTS (b) |
| 13809 | if (b->number == bptnum) |
| 13810 | { |
| 13811 | if (is_tracepoint (b)) |
| 13812 | { |
| 13813 | if (from_tty && count != 0) |
| 13814 | printf_filtered (_("Ignore count ignored for tracepoint %d."), |
| 13815 | bptnum); |
| 13816 | return; |
| 13817 | } |
| 13818 | |
| 13819 | b->ignore_count = count; |
| 13820 | if (from_tty) |
| 13821 | { |
| 13822 | if (count == 0) |
| 13823 | printf_filtered (_("Will stop next time " |
| 13824 | "breakpoint %d is reached."), |
| 13825 | bptnum); |
| 13826 | else if (count == 1) |
| 13827 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
| 13828 | bptnum); |
| 13829 | else |
| 13830 | printf_filtered (_("Will ignore next %d " |
| 13831 | "crossings of breakpoint %d."), |
| 13832 | count, bptnum); |
| 13833 | } |
| 13834 | gdb::observers::breakpoint_modified.notify (b); |
| 13835 | return; |
| 13836 | } |
| 13837 | |
| 13838 | error (_("No breakpoint number %d."), bptnum); |
| 13839 | } |
| 13840 | |
| 13841 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
| 13842 | |
| 13843 | static void |
| 13844 | ignore_command (const char *args, int from_tty) |
| 13845 | { |
| 13846 | const char *p = args; |
| 13847 | int num; |
| 13848 | |
| 13849 | if (p == 0) |
| 13850 | error_no_arg (_("a breakpoint number")); |
| 13851 | |
| 13852 | num = get_number (&p); |
| 13853 | if (num == 0) |
| 13854 | error (_("bad breakpoint number: '%s'"), args); |
| 13855 | if (*p == 0) |
| 13856 | error (_("Second argument (specified ignore-count) is missing.")); |
| 13857 | |
| 13858 | set_ignore_count (num, |
| 13859 | longest_to_int (value_as_long (parse_and_eval (p))), |
| 13860 | from_tty); |
| 13861 | if (from_tty) |
| 13862 | printf_filtered ("\n"); |
| 13863 | } |
| 13864 | \f |
| 13865 | |
| 13866 | /* Call FUNCTION on each of the breakpoints with numbers in the range |
| 13867 | defined by BP_NUM_RANGE (an inclusive range). */ |
| 13868 | |
| 13869 | static void |
| 13870 | map_breakpoint_number_range (std::pair<int, int> bp_num_range, |
| 13871 | gdb::function_view<void (breakpoint *)> function) |
| 13872 | { |
| 13873 | if (bp_num_range.first == 0) |
| 13874 | { |
| 13875 | warning (_("bad breakpoint number at or near '%d'"), |
| 13876 | bp_num_range.first); |
| 13877 | } |
| 13878 | else |
| 13879 | { |
| 13880 | struct breakpoint *b, *tmp; |
| 13881 | |
| 13882 | for (int i = bp_num_range.first; i <= bp_num_range.second; i++) |
| 13883 | { |
| 13884 | bool match = false; |
| 13885 | |
| 13886 | ALL_BREAKPOINTS_SAFE (b, tmp) |
| 13887 | if (b->number == i) |
| 13888 | { |
| 13889 | match = true; |
| 13890 | function (b); |
| 13891 | break; |
| 13892 | } |
| 13893 | if (!match) |
| 13894 | printf_unfiltered (_("No breakpoint number %d.\n"), i); |
| 13895 | } |
| 13896 | } |
| 13897 | } |
| 13898 | |
| 13899 | /* Call FUNCTION on each of the breakpoints whose numbers are given in |
| 13900 | ARGS. */ |
| 13901 | |
| 13902 | static void |
| 13903 | map_breakpoint_numbers (const char *args, |
| 13904 | gdb::function_view<void (breakpoint *)> function) |
| 13905 | { |
| 13906 | if (args == NULL || *args == '\0') |
| 13907 | error_no_arg (_("one or more breakpoint numbers")); |
| 13908 | |
| 13909 | number_or_range_parser parser (args); |
| 13910 | |
| 13911 | while (!parser.finished ()) |
| 13912 | { |
| 13913 | int num = parser.get_number (); |
| 13914 | map_breakpoint_number_range (std::make_pair (num, num), function); |
| 13915 | } |
| 13916 | } |
| 13917 | |
| 13918 | /* Return the breakpoint location structure corresponding to the |
| 13919 | BP_NUM and LOC_NUM values. */ |
| 13920 | |
| 13921 | static struct bp_location * |
| 13922 | find_location_by_number (int bp_num, int loc_num) |
| 13923 | { |
| 13924 | struct breakpoint *b; |
| 13925 | |
| 13926 | ALL_BREAKPOINTS (b) |
| 13927 | if (b->number == bp_num) |
| 13928 | { |
| 13929 | break; |
| 13930 | } |
| 13931 | |
| 13932 | if (!b || b->number != bp_num) |
| 13933 | error (_("Bad breakpoint number '%d'"), bp_num); |
| 13934 | |
| 13935 | if (loc_num == 0) |
| 13936 | error (_("Bad breakpoint location number '%d'"), loc_num); |
| 13937 | |
| 13938 | int n = 0; |
| 13939 | for (bp_location *loc = b->loc; loc != NULL; loc = loc->next) |
| 13940 | if (++n == loc_num) |
| 13941 | return loc; |
| 13942 | |
| 13943 | error (_("Bad breakpoint location number '%d'"), loc_num); |
| 13944 | } |
| 13945 | |
| 13946 | /* Modes of operation for extract_bp_num. */ |
| 13947 | enum class extract_bp_kind |
| 13948 | { |
| 13949 | /* Extracting a breakpoint number. */ |
| 13950 | bp, |
| 13951 | |
| 13952 | /* Extracting a location number. */ |
| 13953 | loc, |
| 13954 | }; |
| 13955 | |
| 13956 | /* Extract a breakpoint or location number (as determined by KIND) |
| 13957 | from the string starting at START. TRAILER is a character which |
| 13958 | can be found after the number. If you don't want a trailer, use |
| 13959 | '\0'. If END_OUT is not NULL, it is set to point after the parsed |
| 13960 | string. This always returns a positive integer. */ |
| 13961 | |
| 13962 | static int |
| 13963 | extract_bp_num (extract_bp_kind kind, const char *start, |
| 13964 | int trailer, const char **end_out = NULL) |
| 13965 | { |
| 13966 | const char *end = start; |
| 13967 | int num = get_number_trailer (&end, trailer); |
| 13968 | if (num < 0) |
| 13969 | error (kind == extract_bp_kind::bp |
| 13970 | ? _("Negative breakpoint number '%.*s'") |
| 13971 | : _("Negative breakpoint location number '%.*s'"), |
| 13972 | int (end - start), start); |
| 13973 | if (num == 0) |
| 13974 | error (kind == extract_bp_kind::bp |
| 13975 | ? _("Bad breakpoint number '%.*s'") |
| 13976 | : _("Bad breakpoint location number '%.*s'"), |
| 13977 | int (end - start), start); |
| 13978 | |
| 13979 | if (end_out != NULL) |
| 13980 | *end_out = end; |
| 13981 | return num; |
| 13982 | } |
| 13983 | |
| 13984 | /* Extract a breakpoint or location range (as determined by KIND) in |
| 13985 | the form NUM1-NUM2 stored at &ARG[arg_offset]. Returns a std::pair |
| 13986 | representing the (inclusive) range. The returned pair's elements |
| 13987 | are always positive integers. */ |
| 13988 | |
| 13989 | static std::pair<int, int> |
| 13990 | extract_bp_or_bp_range (extract_bp_kind kind, |
| 13991 | const std::string &arg, |
| 13992 | std::string::size_type arg_offset) |
| 13993 | { |
| 13994 | std::pair<int, int> range; |
| 13995 | const char *bp_loc = &arg[arg_offset]; |
| 13996 | std::string::size_type dash = arg.find ('-', arg_offset); |
| 13997 | if (dash != std::string::npos) |
| 13998 | { |
| 13999 | /* bp_loc is a range (x-z). */ |
| 14000 | if (arg.length () == dash + 1) |
| 14001 | error (kind == extract_bp_kind::bp |
| 14002 | ? _("Bad breakpoint number at or near: '%s'") |
| 14003 | : _("Bad breakpoint location number at or near: '%s'"), |
| 14004 | bp_loc); |
| 14005 | |
| 14006 | const char *end; |
| 14007 | const char *start_first = bp_loc; |
| 14008 | const char *start_second = &arg[dash + 1]; |
| 14009 | range.first = extract_bp_num (kind, start_first, '-'); |
| 14010 | range.second = extract_bp_num (kind, start_second, '\0', &end); |
| 14011 | |
| 14012 | if (range.first > range.second) |
| 14013 | error (kind == extract_bp_kind::bp |
| 14014 | ? _("Inverted breakpoint range at '%.*s'") |
| 14015 | : _("Inverted breakpoint location range at '%.*s'"), |
| 14016 | int (end - start_first), start_first); |
| 14017 | } |
| 14018 | else |
| 14019 | { |
| 14020 | /* bp_loc is a single value. */ |
| 14021 | range.first = extract_bp_num (kind, bp_loc, '\0'); |
| 14022 | range.second = range.first; |
| 14023 | } |
| 14024 | return range; |
| 14025 | } |
| 14026 | |
| 14027 | /* Extract the breakpoint/location range specified by ARG. Returns |
| 14028 | the breakpoint range in BP_NUM_RANGE, and the location range in |
| 14029 | BP_LOC_RANGE. |
| 14030 | |
| 14031 | ARG may be in any of the following forms: |
| 14032 | |
| 14033 | x where 'x' is a breakpoint number. |
| 14034 | x-y where 'x' and 'y' specify a breakpoint numbers range. |
| 14035 | x.y where 'x' is a breakpoint number and 'y' a location number. |
| 14036 | x.y-z where 'x' is a breakpoint number and 'y' and 'z' specify a |
| 14037 | location number range. |
| 14038 | */ |
| 14039 | |
| 14040 | static void |
| 14041 | extract_bp_number_and_location (const std::string &arg, |
| 14042 | std::pair<int, int> &bp_num_range, |
| 14043 | std::pair<int, int> &bp_loc_range) |
| 14044 | { |
| 14045 | std::string::size_type dot = arg.find ('.'); |
| 14046 | |
| 14047 | if (dot != std::string::npos) |
| 14048 | { |
| 14049 | /* Handle 'x.y' and 'x.y-z' cases. */ |
| 14050 | |
| 14051 | if (arg.length () == dot + 1 || dot == 0) |
| 14052 | error (_("Bad breakpoint number at or near: '%s'"), arg.c_str ()); |
| 14053 | |
| 14054 | bp_num_range.first |
| 14055 | = extract_bp_num (extract_bp_kind::bp, arg.c_str (), '.'); |
| 14056 | bp_num_range.second = bp_num_range.first; |
| 14057 | |
| 14058 | bp_loc_range = extract_bp_or_bp_range (extract_bp_kind::loc, |
| 14059 | arg, dot + 1); |
| 14060 | } |
| 14061 | else |
| 14062 | { |
| 14063 | /* Handle x and x-y cases. */ |
| 14064 | |
| 14065 | bp_num_range = extract_bp_or_bp_range (extract_bp_kind::bp, arg, 0); |
| 14066 | bp_loc_range.first = 0; |
| 14067 | bp_loc_range.second = 0; |
| 14068 | } |
| 14069 | } |
| 14070 | |
| 14071 | /* Enable or disable a breakpoint location BP_NUM.LOC_NUM. ENABLE |
| 14072 | specifies whether to enable or disable. */ |
| 14073 | |
| 14074 | static void |
| 14075 | enable_disable_bp_num_loc (int bp_num, int loc_num, bool enable) |
| 14076 | { |
| 14077 | struct bp_location *loc = find_location_by_number (bp_num, loc_num); |
| 14078 | if (loc != NULL) |
| 14079 | { |
| 14080 | if (loc->enabled != enable) |
| 14081 | { |
| 14082 | loc->enabled = enable; |
| 14083 | mark_breakpoint_location_modified (loc); |
| 14084 | } |
| 14085 | if (target_supports_enable_disable_tracepoint () |
| 14086 | && current_trace_status ()->running && loc->owner |
| 14087 | && is_tracepoint (loc->owner)) |
| 14088 | target_disable_tracepoint (loc); |
| 14089 | } |
| 14090 | update_global_location_list (UGLL_DONT_INSERT); |
| 14091 | |
| 14092 | gdb::observers::breakpoint_modified.notify (loc->owner); |
| 14093 | } |
| 14094 | |
| 14095 | /* Enable or disable a range of breakpoint locations. BP_NUM is the |
| 14096 | number of the breakpoint, and BP_LOC_RANGE specifies the |
| 14097 | (inclusive) range of location numbers of that breakpoint to |
| 14098 | enable/disable. ENABLE specifies whether to enable or disable the |
| 14099 | location. */ |
| 14100 | |
| 14101 | static void |
| 14102 | enable_disable_breakpoint_location_range (int bp_num, |
| 14103 | std::pair<int, int> &bp_loc_range, |
| 14104 | bool enable) |
| 14105 | { |
| 14106 | for (int i = bp_loc_range.first; i <= bp_loc_range.second; i++) |
| 14107 | enable_disable_bp_num_loc (bp_num, i, enable); |
| 14108 | } |
| 14109 | |
| 14110 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 14111 | If from_tty is nonzero, it prints a message to that effect, |
| 14112 | which ends with a period (no newline). */ |
| 14113 | |
| 14114 | void |
| 14115 | disable_breakpoint (struct breakpoint *bpt) |
| 14116 | { |
| 14117 | /* Never disable a watchpoint scope breakpoint; we want to |
| 14118 | hit them when we leave scope so we can delete both the |
| 14119 | watchpoint and its scope breakpoint at that time. */ |
| 14120 | if (bpt->type == bp_watchpoint_scope) |
| 14121 | return; |
| 14122 | |
| 14123 | bpt->enable_state = bp_disabled; |
| 14124 | |
| 14125 | /* Mark breakpoint locations modified. */ |
| 14126 | mark_breakpoint_modified (bpt); |
| 14127 | |
| 14128 | if (target_supports_enable_disable_tracepoint () |
| 14129 | && current_trace_status ()->running && is_tracepoint (bpt)) |
| 14130 | { |
| 14131 | struct bp_location *location; |
| 14132 | |
| 14133 | for (location = bpt->loc; location; location = location->next) |
| 14134 | target_disable_tracepoint (location); |
| 14135 | } |
| 14136 | |
| 14137 | update_global_location_list (UGLL_DONT_INSERT); |
| 14138 | |
| 14139 | gdb::observers::breakpoint_modified.notify (bpt); |
| 14140 | } |
| 14141 | |
| 14142 | /* Enable or disable the breakpoint(s) or breakpoint location(s) |
| 14143 | specified in ARGS. ARGS may be in any of the formats handled by |
| 14144 | extract_bp_number_and_location. ENABLE specifies whether to enable |
| 14145 | or disable the breakpoints/locations. */ |
| 14146 | |
| 14147 | static void |
| 14148 | enable_disable_command (const char *args, int from_tty, bool enable) |
| 14149 | { |
| 14150 | if (args == 0) |
| 14151 | { |
| 14152 | struct breakpoint *bpt; |
| 14153 | |
| 14154 | ALL_BREAKPOINTS (bpt) |
| 14155 | if (user_breakpoint_p (bpt)) |
| 14156 | { |
| 14157 | if (enable) |
| 14158 | enable_breakpoint (bpt); |
| 14159 | else |
| 14160 | disable_breakpoint (bpt); |
| 14161 | } |
| 14162 | } |
| 14163 | else |
| 14164 | { |
| 14165 | std::string num = extract_arg (&args); |
| 14166 | |
| 14167 | while (!num.empty ()) |
| 14168 | { |
| 14169 | std::pair<int, int> bp_num_range, bp_loc_range; |
| 14170 | |
| 14171 | extract_bp_number_and_location (num, bp_num_range, bp_loc_range); |
| 14172 | |
| 14173 | if (bp_loc_range.first == bp_loc_range.second |
| 14174 | && bp_loc_range.first == 0) |
| 14175 | { |
| 14176 | /* Handle breakpoint ids with formats 'x' or 'x-z'. */ |
| 14177 | map_breakpoint_number_range (bp_num_range, |
| 14178 | enable |
| 14179 | ? enable_breakpoint |
| 14180 | : disable_breakpoint); |
| 14181 | } |
| 14182 | else |
| 14183 | { |
| 14184 | /* Handle breakpoint ids with formats 'x.y' or |
| 14185 | 'x.y-z'. */ |
| 14186 | enable_disable_breakpoint_location_range |
| 14187 | (bp_num_range.first, bp_loc_range, enable); |
| 14188 | } |
| 14189 | num = extract_arg (&args); |
| 14190 | } |
| 14191 | } |
| 14192 | } |
| 14193 | |
| 14194 | /* The disable command disables the specified breakpoints/locations |
| 14195 | (or all defined breakpoints) so they're no longer effective in |
| 14196 | stopping the inferior. ARGS may be in any of the forms defined in |
| 14197 | extract_bp_number_and_location. */ |
| 14198 | |
| 14199 | static void |
| 14200 | disable_command (const char *args, int from_tty) |
| 14201 | { |
| 14202 | enable_disable_command (args, from_tty, false); |
| 14203 | } |
| 14204 | |
| 14205 | static void |
| 14206 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition, |
| 14207 | int count) |
| 14208 | { |
| 14209 | int target_resources_ok; |
| 14210 | |
| 14211 | if (bpt->type == bp_hardware_breakpoint) |
| 14212 | { |
| 14213 | int i; |
| 14214 | i = hw_breakpoint_used_count (); |
| 14215 | target_resources_ok = |
| 14216 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
| 14217 | i + 1, 0); |
| 14218 | if (target_resources_ok == 0) |
| 14219 | error (_("No hardware breakpoint support in the target.")); |
| 14220 | else if (target_resources_ok < 0) |
| 14221 | error (_("Hardware breakpoints used exceeds limit.")); |
| 14222 | } |
| 14223 | |
| 14224 | if (is_watchpoint (bpt)) |
| 14225 | { |
| 14226 | /* Initialize it just to avoid a GCC false warning. */ |
| 14227 | enum enable_state orig_enable_state = bp_disabled; |
| 14228 | |
| 14229 | try |
| 14230 | { |
| 14231 | struct watchpoint *w = (struct watchpoint *) bpt; |
| 14232 | |
| 14233 | orig_enable_state = bpt->enable_state; |
| 14234 | bpt->enable_state = bp_enabled; |
| 14235 | update_watchpoint (w, 1 /* reparse */); |
| 14236 | } |
| 14237 | catch (const gdb_exception &e) |
| 14238 | { |
| 14239 | bpt->enable_state = orig_enable_state; |
| 14240 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
| 14241 | bpt->number); |
| 14242 | return; |
| 14243 | } |
| 14244 | } |
| 14245 | |
| 14246 | bpt->enable_state = bp_enabled; |
| 14247 | |
| 14248 | /* Mark breakpoint locations modified. */ |
| 14249 | mark_breakpoint_modified (bpt); |
| 14250 | |
| 14251 | if (target_supports_enable_disable_tracepoint () |
| 14252 | && current_trace_status ()->running && is_tracepoint (bpt)) |
| 14253 | { |
| 14254 | struct bp_location *location; |
| 14255 | |
| 14256 | for (location = bpt->loc; location; location = location->next) |
| 14257 | target_enable_tracepoint (location); |
| 14258 | } |
| 14259 | |
| 14260 | bpt->disposition = disposition; |
| 14261 | bpt->enable_count = count; |
| 14262 | update_global_location_list (UGLL_MAY_INSERT); |
| 14263 | |
| 14264 | gdb::observers::breakpoint_modified.notify (bpt); |
| 14265 | } |
| 14266 | |
| 14267 | |
| 14268 | void |
| 14269 | enable_breakpoint (struct breakpoint *bpt) |
| 14270 | { |
| 14271 | enable_breakpoint_disp (bpt, bpt->disposition, 0); |
| 14272 | } |
| 14273 | |
| 14274 | /* The enable command enables the specified breakpoints/locations (or |
| 14275 | all defined breakpoints) so they once again become (or continue to |
| 14276 | be) effective in stopping the inferior. ARGS may be in any of the |
| 14277 | forms defined in extract_bp_number_and_location. */ |
| 14278 | |
| 14279 | static void |
| 14280 | enable_command (const char *args, int from_tty) |
| 14281 | { |
| 14282 | enable_disable_command (args, from_tty, true); |
| 14283 | } |
| 14284 | |
| 14285 | static void |
| 14286 | enable_once_command (const char *args, int from_tty) |
| 14287 | { |
| 14288 | map_breakpoint_numbers |
| 14289 | (args, [&] (breakpoint *b) |
| 14290 | { |
| 14291 | iterate_over_related_breakpoints |
| 14292 | (b, [&] (breakpoint *bpt) |
| 14293 | { |
| 14294 | enable_breakpoint_disp (bpt, disp_disable, 1); |
| 14295 | }); |
| 14296 | }); |
| 14297 | } |
| 14298 | |
| 14299 | static void |
| 14300 | enable_count_command (const char *args, int from_tty) |
| 14301 | { |
| 14302 | int count; |
| 14303 | |
| 14304 | if (args == NULL) |
| 14305 | error_no_arg (_("hit count")); |
| 14306 | |
| 14307 | count = get_number (&args); |
| 14308 | |
| 14309 | map_breakpoint_numbers |
| 14310 | (args, [&] (breakpoint *b) |
| 14311 | { |
| 14312 | iterate_over_related_breakpoints |
| 14313 | (b, [&] (breakpoint *bpt) |
| 14314 | { |
| 14315 | enable_breakpoint_disp (bpt, disp_disable, count); |
| 14316 | }); |
| 14317 | }); |
| 14318 | } |
| 14319 | |
| 14320 | static void |
| 14321 | enable_delete_command (const char *args, int from_tty) |
| 14322 | { |
| 14323 | map_breakpoint_numbers |
| 14324 | (args, [&] (breakpoint *b) |
| 14325 | { |
| 14326 | iterate_over_related_breakpoints |
| 14327 | (b, [&] (breakpoint *bpt) |
| 14328 | { |
| 14329 | enable_breakpoint_disp (bpt, disp_del, 1); |
| 14330 | }); |
| 14331 | }); |
| 14332 | } |
| 14333 | \f |
| 14334 | static void |
| 14335 | set_breakpoint_cmd (const char *args, int from_tty) |
| 14336 | { |
| 14337 | } |
| 14338 | |
| 14339 | static void |
| 14340 | show_breakpoint_cmd (const char *args, int from_tty) |
| 14341 | { |
| 14342 | } |
| 14343 | |
| 14344 | /* Invalidate last known value of any hardware watchpoint if |
| 14345 | the memory which that value represents has been written to by |
| 14346 | GDB itself. */ |
| 14347 | |
| 14348 | static void |
| 14349 | invalidate_bp_value_on_memory_change (struct inferior *inferior, |
| 14350 | CORE_ADDR addr, ssize_t len, |
| 14351 | const bfd_byte *data) |
| 14352 | { |
| 14353 | struct breakpoint *bp; |
| 14354 | |
| 14355 | ALL_BREAKPOINTS (bp) |
| 14356 | if (bp->enable_state == bp_enabled |
| 14357 | && bp->type == bp_hardware_watchpoint) |
| 14358 | { |
| 14359 | struct watchpoint *wp = (struct watchpoint *) bp; |
| 14360 | |
| 14361 | if (wp->val_valid && wp->val != nullptr) |
| 14362 | { |
| 14363 | struct bp_location *loc; |
| 14364 | |
| 14365 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
| 14366 | if (loc->loc_type == bp_loc_hardware_watchpoint |
| 14367 | && loc->address + loc->length > addr |
| 14368 | && addr + len > loc->address) |
| 14369 | { |
| 14370 | wp->val = NULL; |
| 14371 | wp->val_valid = false; |
| 14372 | } |
| 14373 | } |
| 14374 | } |
| 14375 | } |
| 14376 | |
| 14377 | /* Create and insert a breakpoint for software single step. */ |
| 14378 | |
| 14379 | void |
| 14380 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
| 14381 | const address_space *aspace, |
| 14382 | CORE_ADDR next_pc) |
| 14383 | { |
| 14384 | struct thread_info *tp = inferior_thread (); |
| 14385 | struct symtab_and_line sal; |
| 14386 | CORE_ADDR pc = next_pc; |
| 14387 | |
| 14388 | if (tp->control.single_step_breakpoints == NULL) |
| 14389 | { |
| 14390 | tp->control.single_step_breakpoints |
| 14391 | = new_single_step_breakpoint (tp->global_num, gdbarch); |
| 14392 | } |
| 14393 | |
| 14394 | sal = find_pc_line (pc, 0); |
| 14395 | sal.pc = pc; |
| 14396 | sal.section = find_pc_overlay (pc); |
| 14397 | sal.explicit_pc = 1; |
| 14398 | add_location_to_breakpoint (tp->control.single_step_breakpoints, &sal); |
| 14399 | |
| 14400 | update_global_location_list (UGLL_INSERT); |
| 14401 | } |
| 14402 | |
| 14403 | /* Insert single step breakpoints according to the current state. */ |
| 14404 | |
| 14405 | int |
| 14406 | insert_single_step_breakpoints (struct gdbarch *gdbarch) |
| 14407 | { |
| 14408 | struct regcache *regcache = get_current_regcache (); |
| 14409 | std::vector<CORE_ADDR> next_pcs; |
| 14410 | |
| 14411 | next_pcs = gdbarch_software_single_step (gdbarch, regcache); |
| 14412 | |
| 14413 | if (!next_pcs.empty ()) |
| 14414 | { |
| 14415 | struct frame_info *frame = get_current_frame (); |
| 14416 | const address_space *aspace = get_frame_address_space (frame); |
| 14417 | |
| 14418 | for (CORE_ADDR pc : next_pcs) |
| 14419 | insert_single_step_breakpoint (gdbarch, aspace, pc); |
| 14420 | |
| 14421 | return 1; |
| 14422 | } |
| 14423 | else |
| 14424 | return 0; |
| 14425 | } |
| 14426 | |
| 14427 | /* See breakpoint.h. */ |
| 14428 | |
| 14429 | int |
| 14430 | breakpoint_has_location_inserted_here (struct breakpoint *bp, |
| 14431 | const address_space *aspace, |
| 14432 | CORE_ADDR pc) |
| 14433 | { |
| 14434 | struct bp_location *loc; |
| 14435 | |
| 14436 | for (loc = bp->loc; loc != NULL; loc = loc->next) |
| 14437 | if (loc->inserted |
| 14438 | && breakpoint_location_address_match (loc, aspace, pc)) |
| 14439 | return 1; |
| 14440 | |
| 14441 | return 0; |
| 14442 | } |
| 14443 | |
| 14444 | /* Check whether a software single-step breakpoint is inserted at |
| 14445 | PC. */ |
| 14446 | |
| 14447 | int |
| 14448 | single_step_breakpoint_inserted_here_p (const address_space *aspace, |
| 14449 | CORE_ADDR pc) |
| 14450 | { |
| 14451 | struct breakpoint *bpt; |
| 14452 | |
| 14453 | ALL_BREAKPOINTS (bpt) |
| 14454 | { |
| 14455 | if (bpt->type == bp_single_step |
| 14456 | && breakpoint_has_location_inserted_here (bpt, aspace, pc)) |
| 14457 | return 1; |
| 14458 | } |
| 14459 | return 0; |
| 14460 | } |
| 14461 | |
| 14462 | /* Tracepoint-specific operations. */ |
| 14463 | |
| 14464 | /* Set tracepoint count to NUM. */ |
| 14465 | static void |
| 14466 | set_tracepoint_count (int num) |
| 14467 | { |
| 14468 | tracepoint_count = num; |
| 14469 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
| 14470 | } |
| 14471 | |
| 14472 | static void |
| 14473 | trace_command (const char *arg, int from_tty) |
| 14474 | { |
| 14475 | struct breakpoint_ops *ops; |
| 14476 | |
| 14477 | event_location_up location = string_to_event_location (&arg, |
| 14478 | current_language); |
| 14479 | if (location != NULL |
| 14480 | && event_location_type (location.get ()) == PROBE_LOCATION) |
| 14481 | ops = &tracepoint_probe_breakpoint_ops; |
| 14482 | else |
| 14483 | ops = &tracepoint_breakpoint_ops; |
| 14484 | |
| 14485 | create_breakpoint (get_current_arch (), |
| 14486 | location.get (), |
| 14487 | NULL, 0, arg, 1 /* parse arg */, |
| 14488 | 0 /* tempflag */, |
| 14489 | bp_tracepoint /* type_wanted */, |
| 14490 | 0 /* Ignore count */, |
| 14491 | pending_break_support, |
| 14492 | ops, |
| 14493 | from_tty, |
| 14494 | 1 /* enabled */, |
| 14495 | 0 /* internal */, 0); |
| 14496 | } |
| 14497 | |
| 14498 | static void |
| 14499 | ftrace_command (const char *arg, int from_tty) |
| 14500 | { |
| 14501 | event_location_up location = string_to_event_location (&arg, |
| 14502 | current_language); |
| 14503 | create_breakpoint (get_current_arch (), |
| 14504 | location.get (), |
| 14505 | NULL, 0, arg, 1 /* parse arg */, |
| 14506 | 0 /* tempflag */, |
| 14507 | bp_fast_tracepoint /* type_wanted */, |
| 14508 | 0 /* Ignore count */, |
| 14509 | pending_break_support, |
| 14510 | &tracepoint_breakpoint_ops, |
| 14511 | from_tty, |
| 14512 | 1 /* enabled */, |
| 14513 | 0 /* internal */, 0); |
| 14514 | } |
| 14515 | |
| 14516 | /* strace command implementation. Creates a static tracepoint. */ |
| 14517 | |
| 14518 | static void |
| 14519 | strace_command (const char *arg, int from_tty) |
| 14520 | { |
| 14521 | struct breakpoint_ops *ops; |
| 14522 | event_location_up location; |
| 14523 | |
| 14524 | /* Decide if we are dealing with a static tracepoint marker (`-m'), |
| 14525 | or with a normal static tracepoint. */ |
| 14526 | if (arg && startswith (arg, "-m") && isspace (arg[2])) |
| 14527 | { |
| 14528 | ops = &strace_marker_breakpoint_ops; |
| 14529 | location = new_linespec_location (&arg, symbol_name_match_type::FULL); |
| 14530 | } |
| 14531 | else |
| 14532 | { |
| 14533 | ops = &tracepoint_breakpoint_ops; |
| 14534 | location = string_to_event_location (&arg, current_language); |
| 14535 | } |
| 14536 | |
| 14537 | create_breakpoint (get_current_arch (), |
| 14538 | location.get (), |
| 14539 | NULL, 0, arg, 1 /* parse arg */, |
| 14540 | 0 /* tempflag */, |
| 14541 | bp_static_tracepoint /* type_wanted */, |
| 14542 | 0 /* Ignore count */, |
| 14543 | pending_break_support, |
| 14544 | ops, |
| 14545 | from_tty, |
| 14546 | 1 /* enabled */, |
| 14547 | 0 /* internal */, 0); |
| 14548 | } |
| 14549 | |
| 14550 | /* Set up a fake reader function that gets command lines from a linked |
| 14551 | list that was acquired during tracepoint uploading. */ |
| 14552 | |
| 14553 | static struct uploaded_tp *this_utp; |
| 14554 | static int next_cmd; |
| 14555 | |
| 14556 | static char * |
| 14557 | read_uploaded_action (void) |
| 14558 | { |
| 14559 | char *rslt = nullptr; |
| 14560 | |
| 14561 | if (next_cmd < this_utp->cmd_strings.size ()) |
| 14562 | { |
| 14563 | rslt = this_utp->cmd_strings[next_cmd].get (); |
| 14564 | next_cmd++; |
| 14565 | } |
| 14566 | |
| 14567 | return rslt; |
| 14568 | } |
| 14569 | |
| 14570 | /* Given information about a tracepoint as recorded on a target (which |
| 14571 | can be either a live system or a trace file), attempt to create an |
| 14572 | equivalent GDB tracepoint. This is not a reliable process, since |
| 14573 | the target does not necessarily have all the information used when |
| 14574 | the tracepoint was originally defined. */ |
| 14575 | |
| 14576 | struct tracepoint * |
| 14577 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
| 14578 | { |
| 14579 | const char *addr_str; |
| 14580 | char small_buf[100]; |
| 14581 | struct tracepoint *tp; |
| 14582 | |
| 14583 | if (utp->at_string) |
| 14584 | addr_str = utp->at_string.get (); |
| 14585 | else |
| 14586 | { |
| 14587 | /* In the absence of a source location, fall back to raw |
| 14588 | address. Since there is no way to confirm that the address |
| 14589 | means the same thing as when the trace was started, warn the |
| 14590 | user. */ |
| 14591 | warning (_("Uploaded tracepoint %d has no " |
| 14592 | "source location, using raw address"), |
| 14593 | utp->number); |
| 14594 | xsnprintf (small_buf, sizeof (small_buf), "*%s", hex_string (utp->addr)); |
| 14595 | addr_str = small_buf; |
| 14596 | } |
| 14597 | |
| 14598 | /* There's not much we can do with a sequence of bytecodes. */ |
| 14599 | if (utp->cond && !utp->cond_string) |
| 14600 | warning (_("Uploaded tracepoint %d condition " |
| 14601 | "has no source form, ignoring it"), |
| 14602 | utp->number); |
| 14603 | |
| 14604 | event_location_up location = string_to_event_location (&addr_str, |
| 14605 | current_language); |
| 14606 | if (!create_breakpoint (get_current_arch (), |
| 14607 | location.get (), |
| 14608 | utp->cond_string.get (), -1, addr_str, |
| 14609 | 0 /* parse cond/thread */, |
| 14610 | 0 /* tempflag */, |
| 14611 | utp->type /* type_wanted */, |
| 14612 | 0 /* Ignore count */, |
| 14613 | pending_break_support, |
| 14614 | &tracepoint_breakpoint_ops, |
| 14615 | 0 /* from_tty */, |
| 14616 | utp->enabled /* enabled */, |
| 14617 | 0 /* internal */, |
| 14618 | CREATE_BREAKPOINT_FLAGS_INSERTED)) |
| 14619 | return NULL; |
| 14620 | |
| 14621 | /* Get the tracepoint we just created. */ |
| 14622 | tp = get_tracepoint (tracepoint_count); |
| 14623 | gdb_assert (tp != NULL); |
| 14624 | |
| 14625 | if (utp->pass > 0) |
| 14626 | { |
| 14627 | xsnprintf (small_buf, sizeof (small_buf), "%d %d", utp->pass, |
| 14628 | tp->number); |
| 14629 | |
| 14630 | trace_pass_command (small_buf, 0); |
| 14631 | } |
| 14632 | |
| 14633 | /* If we have uploaded versions of the original commands, set up a |
| 14634 | special-purpose "reader" function and call the usual command line |
| 14635 | reader, then pass the result to the breakpoint command-setting |
| 14636 | function. */ |
| 14637 | if (!utp->cmd_strings.empty ()) |
| 14638 | { |
| 14639 | counted_command_line cmd_list; |
| 14640 | |
| 14641 | this_utp = utp; |
| 14642 | next_cmd = 0; |
| 14643 | |
| 14644 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL); |
| 14645 | |
| 14646 | breakpoint_set_commands (tp, std::move (cmd_list)); |
| 14647 | } |
| 14648 | else if (!utp->actions.empty () |
| 14649 | || !utp->step_actions.empty ()) |
| 14650 | warning (_("Uploaded tracepoint %d actions " |
| 14651 | "have no source form, ignoring them"), |
| 14652 | utp->number); |
| 14653 | |
| 14654 | /* Copy any status information that might be available. */ |
| 14655 | tp->hit_count = utp->hit_count; |
| 14656 | tp->traceframe_usage = utp->traceframe_usage; |
| 14657 | |
| 14658 | return tp; |
| 14659 | } |
| 14660 | |
| 14661 | /* Print information on tracepoint number TPNUM_EXP, or all if |
| 14662 | omitted. */ |
| 14663 | |
| 14664 | static void |
| 14665 | info_tracepoints_command (const char *args, int from_tty) |
| 14666 | { |
| 14667 | struct ui_out *uiout = current_uiout; |
| 14668 | int num_printed; |
| 14669 | |
| 14670 | num_printed = breakpoint_1 (args, false, is_tracepoint); |
| 14671 | |
| 14672 | if (num_printed == 0) |
| 14673 | { |
| 14674 | if (args == NULL || *args == '\0') |
| 14675 | uiout->message ("No tracepoints.\n"); |
| 14676 | else |
| 14677 | uiout->message ("No tracepoint matching '%s'.\n", args); |
| 14678 | } |
| 14679 | |
| 14680 | default_collect_info (); |
| 14681 | } |
| 14682 | |
| 14683 | /* The 'enable trace' command enables tracepoints. |
| 14684 | Not supported by all targets. */ |
| 14685 | static void |
| 14686 | enable_trace_command (const char *args, int from_tty) |
| 14687 | { |
| 14688 | enable_command (args, from_tty); |
| 14689 | } |
| 14690 | |
| 14691 | /* The 'disable trace' command disables tracepoints. |
| 14692 | Not supported by all targets. */ |
| 14693 | static void |
| 14694 | disable_trace_command (const char *args, int from_tty) |
| 14695 | { |
| 14696 | disable_command (args, from_tty); |
| 14697 | } |
| 14698 | |
| 14699 | /* Remove a tracepoint (or all if no argument). */ |
| 14700 | static void |
| 14701 | delete_trace_command (const char *arg, int from_tty) |
| 14702 | { |
| 14703 | struct breakpoint *b, *b_tmp; |
| 14704 | |
| 14705 | dont_repeat (); |
| 14706 | |
| 14707 | if (arg == 0) |
| 14708 | { |
| 14709 | int breaks_to_delete = 0; |
| 14710 | |
| 14711 | /* Delete all breakpoints if no argument. |
| 14712 | Do not delete internal or call-dummy breakpoints, these |
| 14713 | have to be deleted with an explicit breakpoint number |
| 14714 | argument. */ |
| 14715 | ALL_TRACEPOINTS (b) |
| 14716 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
| 14717 | { |
| 14718 | breaks_to_delete = 1; |
| 14719 | break; |
| 14720 | } |
| 14721 | |
| 14722 | /* Ask user only if there are some breakpoints to delete. */ |
| 14723 | if (!from_tty |
| 14724 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) |
| 14725 | { |
| 14726 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 14727 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
| 14728 | delete_breakpoint (b); |
| 14729 | } |
| 14730 | } |
| 14731 | else |
| 14732 | map_breakpoint_numbers |
| 14733 | (arg, [&] (breakpoint *br) |
| 14734 | { |
| 14735 | iterate_over_related_breakpoints (br, delete_breakpoint); |
| 14736 | }); |
| 14737 | } |
| 14738 | |
| 14739 | /* Helper function for trace_pass_command. */ |
| 14740 | |
| 14741 | static void |
| 14742 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
| 14743 | { |
| 14744 | tp->pass_count = count; |
| 14745 | gdb::observers::breakpoint_modified.notify (tp); |
| 14746 | if (from_tty) |
| 14747 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), |
| 14748 | tp->number, count); |
| 14749 | } |
| 14750 | |
| 14751 | /* Set passcount for tracepoint. |
| 14752 | |
| 14753 | First command argument is passcount, second is tracepoint number. |
| 14754 | If tracepoint number omitted, apply to most recently defined. |
| 14755 | Also accepts special argument "all". */ |
| 14756 | |
| 14757 | static void |
| 14758 | trace_pass_command (const char *args, int from_tty) |
| 14759 | { |
| 14760 | struct tracepoint *t1; |
| 14761 | ULONGEST count; |
| 14762 | |
| 14763 | if (args == 0 || *args == 0) |
| 14764 | error (_("passcount command requires an " |
| 14765 | "argument (count + optional TP num)")); |
| 14766 | |
| 14767 | count = strtoulst (args, &args, 10); /* Count comes first, then TP num. */ |
| 14768 | |
| 14769 | args = skip_spaces (args); |
| 14770 | if (*args && strncasecmp (args, "all", 3) == 0) |
| 14771 | { |
| 14772 | struct breakpoint *b; |
| 14773 | |
| 14774 | args += 3; /* Skip special argument "all". */ |
| 14775 | if (*args) |
| 14776 | error (_("Junk at end of arguments.")); |
| 14777 | |
| 14778 | ALL_TRACEPOINTS (b) |
| 14779 | { |
| 14780 | t1 = (struct tracepoint *) b; |
| 14781 | trace_pass_set_count (t1, count, from_tty); |
| 14782 | } |
| 14783 | } |
| 14784 | else if (*args == '\0') |
| 14785 | { |
| 14786 | t1 = get_tracepoint_by_number (&args, NULL); |
| 14787 | if (t1) |
| 14788 | trace_pass_set_count (t1, count, from_tty); |
| 14789 | } |
| 14790 | else |
| 14791 | { |
| 14792 | number_or_range_parser parser (args); |
| 14793 | while (!parser.finished ()) |
| 14794 | { |
| 14795 | t1 = get_tracepoint_by_number (&args, &parser); |
| 14796 | if (t1) |
| 14797 | trace_pass_set_count (t1, count, from_tty); |
| 14798 | } |
| 14799 | } |
| 14800 | } |
| 14801 | |
| 14802 | struct tracepoint * |
| 14803 | get_tracepoint (int num) |
| 14804 | { |
| 14805 | struct breakpoint *t; |
| 14806 | |
| 14807 | ALL_TRACEPOINTS (t) |
| 14808 | if (t->number == num) |
| 14809 | return (struct tracepoint *) t; |
| 14810 | |
| 14811 | return NULL; |
| 14812 | } |
| 14813 | |
| 14814 | /* Find the tracepoint with the given target-side number (which may be |
| 14815 | different from the tracepoint number after disconnecting and |
| 14816 | reconnecting). */ |
| 14817 | |
| 14818 | struct tracepoint * |
| 14819 | get_tracepoint_by_number_on_target (int num) |
| 14820 | { |
| 14821 | struct breakpoint *b; |
| 14822 | |
| 14823 | ALL_TRACEPOINTS (b) |
| 14824 | { |
| 14825 | struct tracepoint *t = (struct tracepoint *) b; |
| 14826 | |
| 14827 | if (t->number_on_target == num) |
| 14828 | return t; |
| 14829 | } |
| 14830 | |
| 14831 | return NULL; |
| 14832 | } |
| 14833 | |
| 14834 | /* Utility: parse a tracepoint number and look it up in the list. |
| 14835 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
| 14836 | If the argument is missing, the most recent tracepoint |
| 14837 | (tracepoint_count) is returned. */ |
| 14838 | |
| 14839 | struct tracepoint * |
| 14840 | get_tracepoint_by_number (const char **arg, |
| 14841 | number_or_range_parser *parser) |
| 14842 | { |
| 14843 | struct breakpoint *t; |
| 14844 | int tpnum; |
| 14845 | const char *instring = arg == NULL ? NULL : *arg; |
| 14846 | |
| 14847 | if (parser != NULL) |
| 14848 | { |
| 14849 | gdb_assert (!parser->finished ()); |
| 14850 | tpnum = parser->get_number (); |
| 14851 | } |
| 14852 | else if (arg == NULL || *arg == NULL || ! **arg) |
| 14853 | tpnum = tracepoint_count; |
| 14854 | else |
| 14855 | tpnum = get_number (arg); |
| 14856 | |
| 14857 | if (tpnum <= 0) |
| 14858 | { |
| 14859 | if (instring && *instring) |
| 14860 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), |
| 14861 | instring); |
| 14862 | else |
| 14863 | printf_filtered (_("No previous tracepoint\n")); |
| 14864 | return NULL; |
| 14865 | } |
| 14866 | |
| 14867 | ALL_TRACEPOINTS (t) |
| 14868 | if (t->number == tpnum) |
| 14869 | { |
| 14870 | return (struct tracepoint *) t; |
| 14871 | } |
| 14872 | |
| 14873 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
| 14874 | return NULL; |
| 14875 | } |
| 14876 | |
| 14877 | void |
| 14878 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) |
| 14879 | { |
| 14880 | if (b->thread != -1) |
| 14881 | fprintf_unfiltered (fp, " thread %d", b->thread); |
| 14882 | |
| 14883 | if (b->task != 0) |
| 14884 | fprintf_unfiltered (fp, " task %d", b->task); |
| 14885 | |
| 14886 | fprintf_unfiltered (fp, "\n"); |
| 14887 | } |
| 14888 | |
| 14889 | /* Save information on user settable breakpoints (watchpoints, etc) to |
| 14890 | a new script file named FILENAME. If FILTER is non-NULL, call it |
| 14891 | on each breakpoint and only include the ones for which it returns |
| 14892 | true. */ |
| 14893 | |
| 14894 | static void |
| 14895 | save_breakpoints (const char *filename, int from_tty, |
| 14896 | bool (*filter) (const struct breakpoint *)) |
| 14897 | { |
| 14898 | struct breakpoint *tp; |
| 14899 | int any = 0; |
| 14900 | int extra_trace_bits = 0; |
| 14901 | |
| 14902 | if (filename == 0 || *filename == 0) |
| 14903 | error (_("Argument required (file name in which to save)")); |
| 14904 | |
| 14905 | /* See if we have anything to save. */ |
| 14906 | ALL_BREAKPOINTS (tp) |
| 14907 | { |
| 14908 | /* Skip internal and momentary breakpoints. */ |
| 14909 | if (!user_breakpoint_p (tp)) |
| 14910 | continue; |
| 14911 | |
| 14912 | /* If we have a filter, only save the breakpoints it accepts. */ |
| 14913 | if (filter && !filter (tp)) |
| 14914 | continue; |
| 14915 | |
| 14916 | any = 1; |
| 14917 | |
| 14918 | if (is_tracepoint (tp)) |
| 14919 | { |
| 14920 | extra_trace_bits = 1; |
| 14921 | |
| 14922 | /* We can stop searching. */ |
| 14923 | break; |
| 14924 | } |
| 14925 | } |
| 14926 | |
| 14927 | if (!any) |
| 14928 | { |
| 14929 | warning (_("Nothing to save.")); |
| 14930 | return; |
| 14931 | } |
| 14932 | |
| 14933 | gdb::unique_xmalloc_ptr<char> expanded_filename (tilde_expand (filename)); |
| 14934 | |
| 14935 | stdio_file fp; |
| 14936 | |
| 14937 | if (!fp.open (expanded_filename.get (), "w")) |
| 14938 | error (_("Unable to open file '%s' for saving (%s)"), |
| 14939 | expanded_filename.get (), safe_strerror (errno)); |
| 14940 | |
| 14941 | if (extra_trace_bits) |
| 14942 | save_trace_state_variables (&fp); |
| 14943 | |
| 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 | tp->ops->print_recreate (tp, &fp); |
| 14955 | |
| 14956 | /* Note, we can't rely on tp->number for anything, as we can't |
| 14957 | assume the recreated breakpoint numbers will match. Use $bpnum |
| 14958 | instead. */ |
| 14959 | |
| 14960 | if (tp->cond_string) |
| 14961 | fp.printf (" condition $bpnum %s\n", tp->cond_string); |
| 14962 | |
| 14963 | if (tp->ignore_count) |
| 14964 | fp.printf (" ignore $bpnum %d\n", tp->ignore_count); |
| 14965 | |
| 14966 | if (tp->type != bp_dprintf && tp->commands) |
| 14967 | { |
| 14968 | fp.puts (" commands\n"); |
| 14969 | |
| 14970 | current_uiout->redirect (&fp); |
| 14971 | try |
| 14972 | { |
| 14973 | print_command_lines (current_uiout, tp->commands.get (), 2); |
| 14974 | } |
| 14975 | catch (const gdb_exception &ex) |
| 14976 | { |
| 14977 | current_uiout->redirect (NULL); |
| 14978 | throw; |
| 14979 | } |
| 14980 | |
| 14981 | current_uiout->redirect (NULL); |
| 14982 | fp.puts (" end\n"); |
| 14983 | } |
| 14984 | |
| 14985 | if (tp->enable_state == bp_disabled) |
| 14986 | fp.puts ("disable $bpnum\n"); |
| 14987 | |
| 14988 | /* If this is a multi-location breakpoint, check if the locations |
| 14989 | should be individually disabled. Watchpoint locations are |
| 14990 | special, and not user visible. */ |
| 14991 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) |
| 14992 | { |
| 14993 | struct bp_location *loc; |
| 14994 | int n = 1; |
| 14995 | |
| 14996 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) |
| 14997 | if (!loc->enabled) |
| 14998 | fp.printf ("disable $bpnum.%d\n", n); |
| 14999 | } |
| 15000 | } |
| 15001 | |
| 15002 | if (extra_trace_bits && *default_collect) |
| 15003 | fp.printf ("set default-collect %s\n", default_collect); |
| 15004 | |
| 15005 | if (from_tty) |
| 15006 | printf_filtered (_("Saved to file '%s'.\n"), expanded_filename.get ()); |
| 15007 | } |
| 15008 | |
| 15009 | /* The `save breakpoints' command. */ |
| 15010 | |
| 15011 | static void |
| 15012 | save_breakpoints_command (const char *args, int from_tty) |
| 15013 | { |
| 15014 | save_breakpoints (args, from_tty, NULL); |
| 15015 | } |
| 15016 | |
| 15017 | /* The `save tracepoints' command. */ |
| 15018 | |
| 15019 | static void |
| 15020 | save_tracepoints_command (const char *args, int from_tty) |
| 15021 | { |
| 15022 | save_breakpoints (args, from_tty, is_tracepoint); |
| 15023 | } |
| 15024 | |
| 15025 | /* Create a vector of all tracepoints. */ |
| 15026 | |
| 15027 | std::vector<breakpoint *> |
| 15028 | all_tracepoints (void) |
| 15029 | { |
| 15030 | std::vector<breakpoint *> tp_vec; |
| 15031 | struct breakpoint *tp; |
| 15032 | |
| 15033 | ALL_TRACEPOINTS (tp) |
| 15034 | { |
| 15035 | tp_vec.push_back (tp); |
| 15036 | } |
| 15037 | |
| 15038 | return tp_vec; |
| 15039 | } |
| 15040 | |
| 15041 | \f |
| 15042 | /* This help string is used to consolidate all the help string for specifying |
| 15043 | locations used by several commands. */ |
| 15044 | |
| 15045 | #define LOCATION_HELP_STRING \ |
| 15046 | "Linespecs are colon-separated lists of location parameters, such as\n\ |
| 15047 | source filename, function name, label name, and line number.\n\ |
| 15048 | Example: To specify the start of a label named \"the_top\" in the\n\ |
| 15049 | function \"fact\" in the file \"factorial.c\", use\n\ |
| 15050 | \"factorial.c:fact:the_top\".\n\ |
| 15051 | \n\ |
| 15052 | Address locations begin with \"*\" and specify an exact address in the\n\ |
| 15053 | program. Example: To specify the fourth byte past the start function\n\ |
| 15054 | \"main\", use \"*main + 4\".\n\ |
| 15055 | \n\ |
| 15056 | Explicit locations are similar to linespecs but use an option/argument\n\ |
| 15057 | syntax to specify location parameters.\n\ |
| 15058 | Example: To specify the start of the label named \"the_top\" in the\n\ |
| 15059 | function \"fact\" in the file \"factorial.c\", use \"-source factorial.c\n\ |
| 15060 | -function fact -label the_top\".\n\ |
| 15061 | \n\ |
| 15062 | By default, a specified function is matched against the program's\n\ |
| 15063 | functions in all scopes. For C++, this means in all namespaces and\n\ |
| 15064 | classes. For Ada, this means in all packages. E.g., in C++,\n\ |
| 15065 | \"func()\" matches \"A::func()\", \"A::B::func()\", etc. The\n\ |
| 15066 | \"-qualified\" flag overrides this behavior, making GDB interpret the\n\ |
| 15067 | specified name as a complete fully-qualified name instead." |
| 15068 | |
| 15069 | /* This help string is used for the break, hbreak, tbreak and thbreak |
| 15070 | commands. It is defined as a macro to prevent duplication. |
| 15071 | COMMAND should be a string constant containing the name of the |
| 15072 | command. */ |
| 15073 | |
| 15074 | #define BREAK_ARGS_HELP(command) \ |
| 15075 | command" [PROBE_MODIFIER] [LOCATION] [thread THREADNUM] [if CONDITION]\n\ |
| 15076 | PROBE_MODIFIER shall be present if the command is to be placed in a\n\ |
| 15077 | probe point. Accepted values are `-probe' (for a generic, automatically\n\ |
| 15078 | guessed probe type), `-probe-stap' (for a SystemTap probe) or \n\ |
| 15079 | `-probe-dtrace' (for a DTrace probe).\n\ |
| 15080 | LOCATION may be a linespec, address, or explicit location as described\n\ |
| 15081 | below.\n\ |
| 15082 | \n\ |
| 15083 | With no LOCATION, uses current execution address of the selected\n\ |
| 15084 | stack frame. This is useful for breaking on return to a stack frame.\n\ |
| 15085 | \n\ |
| 15086 | THREADNUM is the number from \"info threads\".\n\ |
| 15087 | CONDITION is a boolean expression.\n\ |
| 15088 | \n" LOCATION_HELP_STRING "\n\n\ |
| 15089 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
| 15090 | conditions are different.\n\ |
| 15091 | \n\ |
| 15092 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." |
| 15093 | |
| 15094 | /* List of subcommands for "catch". */ |
| 15095 | static struct cmd_list_element *catch_cmdlist; |
| 15096 | |
| 15097 | /* List of subcommands for "tcatch". */ |
| 15098 | static struct cmd_list_element *tcatch_cmdlist; |
| 15099 | |
| 15100 | void |
| 15101 | add_catch_command (const char *name, const char *docstring, |
| 15102 | cmd_const_sfunc_ftype *sfunc, |
| 15103 | completer_ftype *completer, |
| 15104 | void *user_data_catch, |
| 15105 | void *user_data_tcatch) |
| 15106 | { |
| 15107 | struct cmd_list_element *command; |
| 15108 | |
| 15109 | command = add_cmd (name, class_breakpoint, docstring, |
| 15110 | &catch_cmdlist); |
| 15111 | set_cmd_sfunc (command, sfunc); |
| 15112 | set_cmd_context (command, user_data_catch); |
| 15113 | set_cmd_completer (command, completer); |
| 15114 | |
| 15115 | command = add_cmd (name, class_breakpoint, docstring, |
| 15116 | &tcatch_cmdlist); |
| 15117 | set_cmd_sfunc (command, sfunc); |
| 15118 | set_cmd_context (command, user_data_tcatch); |
| 15119 | set_cmd_completer (command, completer); |
| 15120 | } |
| 15121 | |
| 15122 | static void |
| 15123 | save_command (const char *arg, int from_tty) |
| 15124 | { |
| 15125 | printf_unfiltered (_("\"save\" must be followed by " |
| 15126 | "the name of a save subcommand.\n")); |
| 15127 | help_list (save_cmdlist, "save ", all_commands, gdb_stdout); |
| 15128 | } |
| 15129 | |
| 15130 | struct breakpoint * |
| 15131 | iterate_over_breakpoints (gdb::function_view<bool (breakpoint *)> callback) |
| 15132 | { |
| 15133 | struct breakpoint *b, *b_tmp; |
| 15134 | |
| 15135 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
| 15136 | { |
| 15137 | if (callback (b)) |
| 15138 | return b; |
| 15139 | } |
| 15140 | |
| 15141 | return NULL; |
| 15142 | } |
| 15143 | |
| 15144 | /* Zero if any of the breakpoint's locations could be a location where |
| 15145 | functions have been inlined, nonzero otherwise. */ |
| 15146 | |
| 15147 | static int |
| 15148 | is_non_inline_function (struct breakpoint *b) |
| 15149 | { |
| 15150 | /* The shared library event breakpoint is set on the address of a |
| 15151 | non-inline function. */ |
| 15152 | if (b->type == bp_shlib_event) |
| 15153 | return 1; |
| 15154 | |
| 15155 | return 0; |
| 15156 | } |
| 15157 | |
| 15158 | /* Nonzero if the specified PC cannot be a location where functions |
| 15159 | have been inlined. */ |
| 15160 | |
| 15161 | int |
| 15162 | pc_at_non_inline_function (const address_space *aspace, CORE_ADDR pc, |
| 15163 | const struct target_waitstatus *ws) |
| 15164 | { |
| 15165 | struct breakpoint *b; |
| 15166 | struct bp_location *bl; |
| 15167 | |
| 15168 | ALL_BREAKPOINTS (b) |
| 15169 | { |
| 15170 | if (!is_non_inline_function (b)) |
| 15171 | continue; |
| 15172 | |
| 15173 | for (bl = b->loc; bl != NULL; bl = bl->next) |
| 15174 | { |
| 15175 | if (!bl->shlib_disabled |
| 15176 | && bpstat_check_location (bl, aspace, pc, ws)) |
| 15177 | return 1; |
| 15178 | } |
| 15179 | } |
| 15180 | |
| 15181 | return 0; |
| 15182 | } |
| 15183 | |
| 15184 | /* Remove any references to OBJFILE which is going to be freed. */ |
| 15185 | |
| 15186 | void |
| 15187 | breakpoint_free_objfile (struct objfile *objfile) |
| 15188 | { |
| 15189 | struct bp_location **locp, *loc; |
| 15190 | |
| 15191 | ALL_BP_LOCATIONS (loc, locp) |
| 15192 | if (loc->symtab != NULL && SYMTAB_OBJFILE (loc->symtab) == objfile) |
| 15193 | loc->symtab = NULL; |
| 15194 | } |
| 15195 | |
| 15196 | void |
| 15197 | initialize_breakpoint_ops (void) |
| 15198 | { |
| 15199 | static int initialized = 0; |
| 15200 | |
| 15201 | struct breakpoint_ops *ops; |
| 15202 | |
| 15203 | if (initialized) |
| 15204 | return; |
| 15205 | initialized = 1; |
| 15206 | |
| 15207 | /* The breakpoint_ops structure to be inherit by all kinds of |
| 15208 | breakpoints (real breakpoints, i.e., user "break" breakpoints, |
| 15209 | internal and momentary breakpoints, etc.). */ |
| 15210 | ops = &bkpt_base_breakpoint_ops; |
| 15211 | *ops = base_breakpoint_ops; |
| 15212 | ops->re_set = bkpt_re_set; |
| 15213 | ops->insert_location = bkpt_insert_location; |
| 15214 | ops->remove_location = bkpt_remove_location; |
| 15215 | ops->breakpoint_hit = bkpt_breakpoint_hit; |
| 15216 | ops->create_sals_from_location = bkpt_create_sals_from_location; |
| 15217 | ops->create_breakpoints_sal = bkpt_create_breakpoints_sal; |
| 15218 | ops->decode_location = bkpt_decode_location; |
| 15219 | |
| 15220 | /* The breakpoint_ops structure to be used in regular breakpoints. */ |
| 15221 | ops = &bkpt_breakpoint_ops; |
| 15222 | *ops = bkpt_base_breakpoint_ops; |
| 15223 | ops->re_set = bkpt_re_set; |
| 15224 | ops->resources_needed = bkpt_resources_needed; |
| 15225 | ops->print_it = bkpt_print_it; |
| 15226 | ops->print_mention = bkpt_print_mention; |
| 15227 | ops->print_recreate = bkpt_print_recreate; |
| 15228 | |
| 15229 | /* Ranged breakpoints. */ |
| 15230 | ops = &ranged_breakpoint_ops; |
| 15231 | *ops = bkpt_breakpoint_ops; |
| 15232 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; |
| 15233 | ops->resources_needed = resources_needed_ranged_breakpoint; |
| 15234 | ops->print_it = print_it_ranged_breakpoint; |
| 15235 | ops->print_one = print_one_ranged_breakpoint; |
| 15236 | ops->print_one_detail = print_one_detail_ranged_breakpoint; |
| 15237 | ops->print_mention = print_mention_ranged_breakpoint; |
| 15238 | ops->print_recreate = print_recreate_ranged_breakpoint; |
| 15239 | |
| 15240 | /* Internal breakpoints. */ |
| 15241 | ops = &internal_breakpoint_ops; |
| 15242 | *ops = bkpt_base_breakpoint_ops; |
| 15243 | ops->re_set = internal_bkpt_re_set; |
| 15244 | ops->check_status = internal_bkpt_check_status; |
| 15245 | ops->print_it = internal_bkpt_print_it; |
| 15246 | ops->print_mention = internal_bkpt_print_mention; |
| 15247 | |
| 15248 | /* Momentary breakpoints. */ |
| 15249 | ops = &momentary_breakpoint_ops; |
| 15250 | *ops = bkpt_base_breakpoint_ops; |
| 15251 | ops->re_set = momentary_bkpt_re_set; |
| 15252 | ops->check_status = momentary_bkpt_check_status; |
| 15253 | ops->print_it = momentary_bkpt_print_it; |
| 15254 | ops->print_mention = momentary_bkpt_print_mention; |
| 15255 | |
| 15256 | /* Probe breakpoints. */ |
| 15257 | ops = &bkpt_probe_breakpoint_ops; |
| 15258 | *ops = bkpt_breakpoint_ops; |
| 15259 | ops->insert_location = bkpt_probe_insert_location; |
| 15260 | ops->remove_location = bkpt_probe_remove_location; |
| 15261 | ops->create_sals_from_location = bkpt_probe_create_sals_from_location; |
| 15262 | ops->decode_location = bkpt_probe_decode_location; |
| 15263 | |
| 15264 | /* Watchpoints. */ |
| 15265 | ops = &watchpoint_breakpoint_ops; |
| 15266 | *ops = base_breakpoint_ops; |
| 15267 | ops->re_set = re_set_watchpoint; |
| 15268 | ops->insert_location = insert_watchpoint; |
| 15269 | ops->remove_location = remove_watchpoint; |
| 15270 | ops->breakpoint_hit = breakpoint_hit_watchpoint; |
| 15271 | ops->check_status = check_status_watchpoint; |
| 15272 | ops->resources_needed = resources_needed_watchpoint; |
| 15273 | ops->works_in_software_mode = works_in_software_mode_watchpoint; |
| 15274 | ops->print_it = print_it_watchpoint; |
| 15275 | ops->print_mention = print_mention_watchpoint; |
| 15276 | ops->print_recreate = print_recreate_watchpoint; |
| 15277 | ops->explains_signal = explains_signal_watchpoint; |
| 15278 | |
| 15279 | /* Masked watchpoints. */ |
| 15280 | ops = &masked_watchpoint_breakpoint_ops; |
| 15281 | *ops = watchpoint_breakpoint_ops; |
| 15282 | ops->insert_location = insert_masked_watchpoint; |
| 15283 | ops->remove_location = remove_masked_watchpoint; |
| 15284 | ops->resources_needed = resources_needed_masked_watchpoint; |
| 15285 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; |
| 15286 | ops->print_it = print_it_masked_watchpoint; |
| 15287 | ops->print_one_detail = print_one_detail_masked_watchpoint; |
| 15288 | ops->print_mention = print_mention_masked_watchpoint; |
| 15289 | ops->print_recreate = print_recreate_masked_watchpoint; |
| 15290 | |
| 15291 | /* Tracepoints. */ |
| 15292 | ops = &tracepoint_breakpoint_ops; |
| 15293 | *ops = base_breakpoint_ops; |
| 15294 | ops->re_set = tracepoint_re_set; |
| 15295 | ops->breakpoint_hit = tracepoint_breakpoint_hit; |
| 15296 | ops->print_one_detail = tracepoint_print_one_detail; |
| 15297 | ops->print_mention = tracepoint_print_mention; |
| 15298 | ops->print_recreate = tracepoint_print_recreate; |
| 15299 | ops->create_sals_from_location = tracepoint_create_sals_from_location; |
| 15300 | ops->create_breakpoints_sal = tracepoint_create_breakpoints_sal; |
| 15301 | ops->decode_location = tracepoint_decode_location; |
| 15302 | |
| 15303 | /* Probe tracepoints. */ |
| 15304 | ops = &tracepoint_probe_breakpoint_ops; |
| 15305 | *ops = tracepoint_breakpoint_ops; |
| 15306 | ops->create_sals_from_location = tracepoint_probe_create_sals_from_location; |
| 15307 | ops->decode_location = tracepoint_probe_decode_location; |
| 15308 | |
| 15309 | /* Static tracepoints with marker (`-m'). */ |
| 15310 | ops = &strace_marker_breakpoint_ops; |
| 15311 | *ops = tracepoint_breakpoint_ops; |
| 15312 | ops->create_sals_from_location = strace_marker_create_sals_from_location; |
| 15313 | ops->create_breakpoints_sal = strace_marker_create_breakpoints_sal; |
| 15314 | ops->decode_location = strace_marker_decode_location; |
| 15315 | |
| 15316 | /* Fork catchpoints. */ |
| 15317 | ops = &catch_fork_breakpoint_ops; |
| 15318 | *ops = base_breakpoint_ops; |
| 15319 | ops->insert_location = insert_catch_fork; |
| 15320 | ops->remove_location = remove_catch_fork; |
| 15321 | ops->breakpoint_hit = breakpoint_hit_catch_fork; |
| 15322 | ops->print_it = print_it_catch_fork; |
| 15323 | ops->print_one = print_one_catch_fork; |
| 15324 | ops->print_mention = print_mention_catch_fork; |
| 15325 | ops->print_recreate = print_recreate_catch_fork; |
| 15326 | |
| 15327 | /* Vfork catchpoints. */ |
| 15328 | ops = &catch_vfork_breakpoint_ops; |
| 15329 | *ops = base_breakpoint_ops; |
| 15330 | ops->insert_location = insert_catch_vfork; |
| 15331 | ops->remove_location = remove_catch_vfork; |
| 15332 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; |
| 15333 | ops->print_it = print_it_catch_vfork; |
| 15334 | ops->print_one = print_one_catch_vfork; |
| 15335 | ops->print_mention = print_mention_catch_vfork; |
| 15336 | ops->print_recreate = print_recreate_catch_vfork; |
| 15337 | |
| 15338 | /* Exec catchpoints. */ |
| 15339 | ops = &catch_exec_breakpoint_ops; |
| 15340 | *ops = base_breakpoint_ops; |
| 15341 | ops->insert_location = insert_catch_exec; |
| 15342 | ops->remove_location = remove_catch_exec; |
| 15343 | ops->breakpoint_hit = breakpoint_hit_catch_exec; |
| 15344 | ops->print_it = print_it_catch_exec; |
| 15345 | ops->print_one = print_one_catch_exec; |
| 15346 | ops->print_mention = print_mention_catch_exec; |
| 15347 | ops->print_recreate = print_recreate_catch_exec; |
| 15348 | |
| 15349 | /* Solib-related catchpoints. */ |
| 15350 | ops = &catch_solib_breakpoint_ops; |
| 15351 | *ops = base_breakpoint_ops; |
| 15352 | ops->insert_location = insert_catch_solib; |
| 15353 | ops->remove_location = remove_catch_solib; |
| 15354 | ops->breakpoint_hit = breakpoint_hit_catch_solib; |
| 15355 | ops->check_status = check_status_catch_solib; |
| 15356 | ops->print_it = print_it_catch_solib; |
| 15357 | ops->print_one = print_one_catch_solib; |
| 15358 | ops->print_mention = print_mention_catch_solib; |
| 15359 | ops->print_recreate = print_recreate_catch_solib; |
| 15360 | |
| 15361 | ops = &dprintf_breakpoint_ops; |
| 15362 | *ops = bkpt_base_breakpoint_ops; |
| 15363 | ops->re_set = dprintf_re_set; |
| 15364 | ops->resources_needed = bkpt_resources_needed; |
| 15365 | ops->print_it = bkpt_print_it; |
| 15366 | ops->print_mention = bkpt_print_mention; |
| 15367 | ops->print_recreate = dprintf_print_recreate; |
| 15368 | ops->after_condition_true = dprintf_after_condition_true; |
| 15369 | ops->breakpoint_hit = dprintf_breakpoint_hit; |
| 15370 | } |
| 15371 | |
| 15372 | /* Chain containing all defined "enable breakpoint" subcommands. */ |
| 15373 | |
| 15374 | static struct cmd_list_element *enablebreaklist = NULL; |
| 15375 | |
| 15376 | /* See breakpoint.h. */ |
| 15377 | |
| 15378 | cmd_list_element *commands_cmd_element = nullptr; |
| 15379 | |
| 15380 | void |
| 15381 | _initialize_breakpoint (void) |
| 15382 | { |
| 15383 | struct cmd_list_element *c; |
| 15384 | |
| 15385 | initialize_breakpoint_ops (); |
| 15386 | |
| 15387 | gdb::observers::solib_unloaded.attach (disable_breakpoints_in_unloaded_shlib); |
| 15388 | gdb::observers::free_objfile.attach (disable_breakpoints_in_freed_objfile); |
| 15389 | gdb::observers::memory_changed.attach (invalidate_bp_value_on_memory_change); |
| 15390 | |
| 15391 | breakpoint_chain = 0; |
| 15392 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful |
| 15393 | before a breakpoint is set. */ |
| 15394 | breakpoint_count = 0; |
| 15395 | |
| 15396 | tracepoint_count = 0; |
| 15397 | |
| 15398 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
| 15399 | Set ignore-count of breakpoint number N to COUNT.\n\ |
| 15400 | Usage is `ignore N COUNT'.")); |
| 15401 | |
| 15402 | commands_cmd_element = add_com ("commands", class_breakpoint, |
| 15403 | commands_command, _("\ |
| 15404 | Set commands to be executed when the given breakpoints are hit.\n\ |
| 15405 | Give a space-separated breakpoint list as argument after \"commands\".\n\ |
| 15406 | A list element can be a breakpoint number (e.g. `5') or a range of numbers\n\ |
| 15407 | (e.g. `5-7').\n\ |
| 15408 | With no argument, the targeted breakpoint is the last one set.\n\ |
| 15409 | The commands themselves follow starting on the next line.\n\ |
| 15410 | Type a line containing \"end\" to indicate the end of them.\n\ |
| 15411 | Give \"silent\" as the first line to make the breakpoint silent;\n\ |
| 15412 | then no output is printed when it is hit, except what the commands print.")); |
| 15413 | |
| 15414 | c = add_com ("condition", class_breakpoint, condition_command, _("\ |
| 15415 | Specify breakpoint number N to break only if COND is true.\n\ |
| 15416 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
| 15417 | expression to be evaluated whenever breakpoint N is reached.")); |
| 15418 | set_cmd_completer (c, condition_completer); |
| 15419 | |
| 15420 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
| 15421 | Set a temporary breakpoint.\n\ |
| 15422 | Like \"break\" except the breakpoint is only temporary,\n\ |
| 15423 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ |
| 15424 | by using \"enable delete\" on the breakpoint number.\n\ |
| 15425 | \n" |
| 15426 | BREAK_ARGS_HELP ("tbreak"))); |
| 15427 | set_cmd_completer (c, location_completer); |
| 15428 | |
| 15429 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
| 15430 | Set a hardware assisted breakpoint.\n\ |
| 15431 | Like \"break\" except the breakpoint requires hardware support,\n\ |
| 15432 | some target hardware may not have this support.\n\ |
| 15433 | \n" |
| 15434 | BREAK_ARGS_HELP ("hbreak"))); |
| 15435 | set_cmd_completer (c, location_completer); |
| 15436 | |
| 15437 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
| 15438 | Set a temporary hardware assisted breakpoint.\n\ |
| 15439 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
| 15440 | so it will be deleted when hit.\n\ |
| 15441 | \n" |
| 15442 | BREAK_ARGS_HELP ("thbreak"))); |
| 15443 | set_cmd_completer (c, location_completer); |
| 15444 | |
| 15445 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
| 15446 | Enable all or some breakpoints.\n\ |
| 15447 | Usage: enable [BREAKPOINTNUM]...\n\ |
| 15448 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 15449 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 15450 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 15451 | With a subcommand you can enable temporarily."), |
| 15452 | &enablelist, "enable ", 1, &cmdlist); |
| 15453 | |
| 15454 | add_com_alias ("en", "enable", class_breakpoint, 1); |
| 15455 | |
| 15456 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
| 15457 | Enable all or some breakpoints.\n\ |
| 15458 | Usage: enable breakpoints [BREAKPOINTNUM]...\n\ |
| 15459 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 15460 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 15461 | May be abbreviated to simply \"enable\"."), |
| 15462 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
| 15463 | |
| 15464 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 15465 | Enable some breakpoints for one hit.\n\ |
| 15466 | Usage: enable breakpoints once BREAKPOINTNUM...\n\ |
| 15467 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 15468 | &enablebreaklist); |
| 15469 | |
| 15470 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 15471 | Enable some breakpoints and delete when hit.\n\ |
| 15472 | Usage: enable breakpoints delete BREAKPOINTNUM...\n\ |
| 15473 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 15474 | &enablebreaklist); |
| 15475 | |
| 15476 | add_cmd ("count", no_class, enable_count_command, _("\ |
| 15477 | Enable some breakpoints for COUNT hits.\n\ |
| 15478 | Usage: enable breakpoints count COUNT BREAKPOINTNUM...\n\ |
| 15479 | If a breakpoint is hit while enabled in this fashion,\n\ |
| 15480 | the count is decremented; when it reaches zero, the breakpoint is disabled."), |
| 15481 | &enablebreaklist); |
| 15482 | |
| 15483 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
| 15484 | Enable some breakpoints and delete when hit.\n\ |
| 15485 | Usage: enable delete BREAKPOINTNUM...\n\ |
| 15486 | If a breakpoint is hit while enabled in this fashion, it is deleted."), |
| 15487 | &enablelist); |
| 15488 | |
| 15489 | add_cmd ("once", no_class, enable_once_command, _("\ |
| 15490 | Enable some breakpoints for one hit.\n\ |
| 15491 | Usage: enable once BREAKPOINTNUM...\n\ |
| 15492 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), |
| 15493 | &enablelist); |
| 15494 | |
| 15495 | add_cmd ("count", no_class, enable_count_command, _("\ |
| 15496 | Enable some breakpoints for COUNT hits.\n\ |
| 15497 | Usage: enable count COUNT BREAKPOINTNUM...\n\ |
| 15498 | If a breakpoint is hit while enabled in this fashion,\n\ |
| 15499 | the count is decremented; when it reaches zero, the breakpoint is disabled."), |
| 15500 | &enablelist); |
| 15501 | |
| 15502 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
| 15503 | Disable all or some breakpoints.\n\ |
| 15504 | Usage: disable [BREAKPOINTNUM]...\n\ |
| 15505 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15506 | To disable all breakpoints, give no argument.\n\ |
| 15507 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
| 15508 | &disablelist, "disable ", 1, &cmdlist); |
| 15509 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
| 15510 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
| 15511 | |
| 15512 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
| 15513 | Disable all or some breakpoints.\n\ |
| 15514 | Usage: disable breakpoints [BREAKPOINTNUM]...\n\ |
| 15515 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15516 | To disable all breakpoints, give no argument.\n\ |
| 15517 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
| 15518 | This command may be abbreviated \"disable\"."), |
| 15519 | &disablelist); |
| 15520 | |
| 15521 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
| 15522 | Delete all or some breakpoints.\n\ |
| 15523 | Usage: delete [BREAKPOINTNUM]...\n\ |
| 15524 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15525 | To delete all breakpoints, give no argument.\n\ |
| 15526 | \n\ |
| 15527 | Also a prefix command for deletion of other GDB objects."), |
| 15528 | &deletelist, "delete ", 1, &cmdlist); |
| 15529 | add_com_alias ("d", "delete", class_breakpoint, 1); |
| 15530 | add_com_alias ("del", "delete", class_breakpoint, 1); |
| 15531 | |
| 15532 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
| 15533 | Delete all or some breakpoints or auto-display expressions.\n\ |
| 15534 | Usage: delete breakpoints [BREAKPOINTNUM]...\n\ |
| 15535 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 15536 | To delete all breakpoints, give no argument.\n\ |
| 15537 | This command may be abbreviated \"delete\"."), |
| 15538 | &deletelist); |
| 15539 | |
| 15540 | add_com ("clear", class_breakpoint, clear_command, _("\ |
| 15541 | Clear breakpoint at specified location.\n\ |
| 15542 | Argument may be a linespec, explicit, or address location as described below.\n\ |
| 15543 | \n\ |
| 15544 | With no argument, clears all breakpoints in the line that the selected frame\n\ |
| 15545 | is executing in.\n" |
| 15546 | "\n" LOCATION_HELP_STRING "\n\n\ |
| 15547 | See also the \"delete\" command which clears breakpoints by number.")); |
| 15548 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
| 15549 | |
| 15550 | c = add_com ("break", class_breakpoint, break_command, _("\ |
| 15551 | Set breakpoint at specified location.\n" |
| 15552 | BREAK_ARGS_HELP ("break"))); |
| 15553 | set_cmd_completer (c, location_completer); |
| 15554 | |
| 15555 | add_com_alias ("b", "break", class_run, 1); |
| 15556 | add_com_alias ("br", "break", class_run, 1); |
| 15557 | add_com_alias ("bre", "break", class_run, 1); |
| 15558 | add_com_alias ("brea", "break", class_run, 1); |
| 15559 | |
| 15560 | if (dbx_commands) |
| 15561 | { |
| 15562 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
| 15563 | Break in function/address or break at a line in the current file."), |
| 15564 | &stoplist, "stop ", 1, &cmdlist); |
| 15565 | add_cmd ("in", class_breakpoint, stopin_command, |
| 15566 | _("Break in function or address."), &stoplist); |
| 15567 | add_cmd ("at", class_breakpoint, stopat_command, |
| 15568 | _("Break at a line in the current file."), &stoplist); |
| 15569 | add_com ("status", class_info, info_breakpoints_command, _("\ |
| 15570 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 15571 | The \"Type\" column indicates one of:\n\ |
| 15572 | \tbreakpoint - normal breakpoint\n\ |
| 15573 | \twatchpoint - watchpoint\n\ |
| 15574 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 15575 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 15576 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 15577 | address and file/line number respectively.\n\ |
| 15578 | \n\ |
| 15579 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 15580 | are set to the address of the last breakpoint listed unless the command\n\ |
| 15581 | is prefixed with \"server \".\n\n\ |
| 15582 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 15583 | breakpoint set.")); |
| 15584 | } |
| 15585 | |
| 15586 | add_info ("breakpoints", info_breakpoints_command, _("\ |
| 15587 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
| 15588 | The \"Type\" column indicates one of:\n\ |
| 15589 | \tbreakpoint - normal breakpoint\n\ |
| 15590 | \twatchpoint - watchpoint\n\ |
| 15591 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 15592 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 15593 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 15594 | address and file/line number respectively.\n\ |
| 15595 | \n\ |
| 15596 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 15597 | are set to the address of the last breakpoint listed unless the command\n\ |
| 15598 | is prefixed with \"server \".\n\n\ |
| 15599 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 15600 | breakpoint set.")); |
| 15601 | |
| 15602 | add_info_alias ("b", "breakpoints", 1); |
| 15603 | |
| 15604 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
| 15605 | Status of all breakpoints, or breakpoint number NUMBER.\n\ |
| 15606 | The \"Type\" column indicates one of:\n\ |
| 15607 | \tbreakpoint - normal breakpoint\n\ |
| 15608 | \twatchpoint - watchpoint\n\ |
| 15609 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ |
| 15610 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ |
| 15611 | \tuntil - internal breakpoint used by the \"until\" command\n\ |
| 15612 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
| 15613 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 15614 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 15615 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 15616 | address and file/line number respectively.\n\ |
| 15617 | \n\ |
| 15618 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 15619 | are set to the address of the last breakpoint listed unless the command\n\ |
| 15620 | is prefixed with \"server \".\n\n\ |
| 15621 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 15622 | breakpoint set."), |
| 15623 | &maintenanceinfolist); |
| 15624 | |
| 15625 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
| 15626 | Set catchpoints to catch events."), |
| 15627 | &catch_cmdlist, "catch ", |
| 15628 | 0/*allow-unknown*/, &cmdlist); |
| 15629 | |
| 15630 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ |
| 15631 | Set temporary catchpoints to catch events."), |
| 15632 | &tcatch_cmdlist, "tcatch ", |
| 15633 | 0/*allow-unknown*/, &cmdlist); |
| 15634 | |
| 15635 | add_catch_command ("fork", _("Catch calls to fork."), |
| 15636 | catch_fork_command_1, |
| 15637 | NULL, |
| 15638 | (void *) (uintptr_t) catch_fork_permanent, |
| 15639 | (void *) (uintptr_t) catch_fork_temporary); |
| 15640 | add_catch_command ("vfork", _("Catch calls to vfork."), |
| 15641 | catch_fork_command_1, |
| 15642 | NULL, |
| 15643 | (void *) (uintptr_t) catch_vfork_permanent, |
| 15644 | (void *) (uintptr_t) catch_vfork_temporary); |
| 15645 | add_catch_command ("exec", _("Catch calls to exec."), |
| 15646 | catch_exec_command_1, |
| 15647 | NULL, |
| 15648 | CATCH_PERMANENT, |
| 15649 | CATCH_TEMPORARY); |
| 15650 | add_catch_command ("load", _("Catch loads of shared libraries.\n\ |
| 15651 | Usage: catch load [REGEX]\n\ |
| 15652 | If REGEX is given, only stop for libraries matching the regular expression."), |
| 15653 | catch_load_command_1, |
| 15654 | NULL, |
| 15655 | CATCH_PERMANENT, |
| 15656 | CATCH_TEMPORARY); |
| 15657 | add_catch_command ("unload", _("Catch unloads of shared libraries.\n\ |
| 15658 | Usage: catch unload [REGEX]\n\ |
| 15659 | If REGEX is given, only stop for libraries matching the regular expression."), |
| 15660 | catch_unload_command_1, |
| 15661 | NULL, |
| 15662 | CATCH_PERMANENT, |
| 15663 | CATCH_TEMPORARY); |
| 15664 | |
| 15665 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
| 15666 | Set a watchpoint for an expression.\n\ |
| 15667 | Usage: watch [-l|-location] EXPRESSION\n\ |
| 15668 | A watchpoint stops execution of your program whenever the value of\n\ |
| 15669 | an expression changes.\n\ |
| 15670 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 15671 | the memory to which it refers.")); |
| 15672 | set_cmd_completer (c, expression_completer); |
| 15673 | |
| 15674 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
| 15675 | Set a read watchpoint for an expression.\n\ |
| 15676 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
| 15677 | A watchpoint stops execution of your program whenever the value of\n\ |
| 15678 | an expression is read.\n\ |
| 15679 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 15680 | the memory to which it refers.")); |
| 15681 | set_cmd_completer (c, expression_completer); |
| 15682 | |
| 15683 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
| 15684 | Set a watchpoint for an expression.\n\ |
| 15685 | Usage: awatch [-l|-location] EXPRESSION\n\ |
| 15686 | A watchpoint stops execution of your program whenever the value of\n\ |
| 15687 | an expression is either read or written.\n\ |
| 15688 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ |
| 15689 | the memory to which it refers.")); |
| 15690 | set_cmd_completer (c, expression_completer); |
| 15691 | |
| 15692 | add_info ("watchpoints", info_watchpoints_command, _("\ |
| 15693 | Status of specified watchpoints (all watchpoints if no argument).")); |
| 15694 | |
| 15695 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
| 15696 | respond to changes - contrary to the description. */ |
| 15697 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
| 15698 | &can_use_hw_watchpoints, _("\ |
| 15699 | Set debugger's willingness to use watchpoint hardware."), _("\ |
| 15700 | Show debugger's willingness to use watchpoint hardware."), _("\ |
| 15701 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
| 15702 | such is available. (However, any hardware watchpoints that were\n\ |
| 15703 | created before setting this to nonzero, will continue to use watchpoint\n\ |
| 15704 | hardware.)"), |
| 15705 | NULL, |
| 15706 | show_can_use_hw_watchpoints, |
| 15707 | &setlist, &showlist); |
| 15708 | |
| 15709 | can_use_hw_watchpoints = 1; |
| 15710 | |
| 15711 | /* Tracepoint manipulation commands. */ |
| 15712 | |
| 15713 | c = add_com ("trace", class_breakpoint, trace_command, _("\ |
| 15714 | Set a tracepoint at specified location.\n\ |
| 15715 | \n" |
| 15716 | BREAK_ARGS_HELP ("trace") "\n\ |
| 15717 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 15718 | set_cmd_completer (c, location_completer); |
| 15719 | |
| 15720 | add_com_alias ("tp", "trace", class_alias, 0); |
| 15721 | add_com_alias ("tr", "trace", class_alias, 1); |
| 15722 | add_com_alias ("tra", "trace", class_alias, 1); |
| 15723 | add_com_alias ("trac", "trace", class_alias, 1); |
| 15724 | |
| 15725 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
| 15726 | Set a fast tracepoint at specified location.\n\ |
| 15727 | \n" |
| 15728 | BREAK_ARGS_HELP ("ftrace") "\n\ |
| 15729 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 15730 | set_cmd_completer (c, location_completer); |
| 15731 | |
| 15732 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
| 15733 | Set a static tracepoint at location or marker.\n\ |
| 15734 | \n\ |
| 15735 | strace [LOCATION] [if CONDITION]\n\ |
| 15736 | LOCATION may be a linespec, explicit, or address location (described below) \n\ |
| 15737 | or -m MARKER_ID.\n\n\ |
| 15738 | If a marker id is specified, probe the marker with that name. With\n\ |
| 15739 | no LOCATION, uses current execution address of the selected stack frame.\n\ |
| 15740 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ |
| 15741 | This collects arbitrary user data passed in the probe point call to the\n\ |
| 15742 | tracing library. You can inspect it when analyzing the trace buffer,\n\ |
| 15743 | by printing the $_sdata variable like any other convenience variable.\n\ |
| 15744 | \n\ |
| 15745 | CONDITION is a boolean expression.\n\ |
| 15746 | \n" LOCATION_HELP_STRING "\n\n\ |
| 15747 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
| 15748 | conditions are different.\n\ |
| 15749 | \n\ |
| 15750 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ |
| 15751 | Do \"help tracepoints\" for info on other tracepoint commands.")); |
| 15752 | set_cmd_completer (c, location_completer); |
| 15753 | |
| 15754 | add_info ("tracepoints", info_tracepoints_command, _("\ |
| 15755 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
| 15756 | Convenience variable \"$tpnum\" contains the number of the\n\ |
| 15757 | last tracepoint set.")); |
| 15758 | |
| 15759 | add_info_alias ("tp", "tracepoints", 1); |
| 15760 | |
| 15761 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ |
| 15762 | Delete specified tracepoints.\n\ |
| 15763 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 15764 | No argument means delete all tracepoints."), |
| 15765 | &deletelist); |
| 15766 | add_alias_cmd ("tr", "tracepoints", class_trace, 1, &deletelist); |
| 15767 | |
| 15768 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ |
| 15769 | Disable specified tracepoints.\n\ |
| 15770 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 15771 | No argument means disable all tracepoints."), |
| 15772 | &disablelist); |
| 15773 | deprecate_cmd (c, "disable"); |
| 15774 | |
| 15775 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ |
| 15776 | Enable specified tracepoints.\n\ |
| 15777 | Arguments are tracepoint numbers, separated by spaces.\n\ |
| 15778 | No argument means enable all tracepoints."), |
| 15779 | &enablelist); |
| 15780 | deprecate_cmd (c, "enable"); |
| 15781 | |
| 15782 | add_com ("passcount", class_trace, trace_pass_command, _("\ |
| 15783 | Set the passcount for a tracepoint.\n\ |
| 15784 | The trace will end when the tracepoint has been passed 'count' times.\n\ |
| 15785 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ |
| 15786 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); |
| 15787 | |
| 15788 | add_prefix_cmd ("save", class_breakpoint, save_command, |
| 15789 | _("Save breakpoint definitions as a script."), |
| 15790 | &save_cmdlist, "save ", |
| 15791 | 0/*allow-unknown*/, &cmdlist); |
| 15792 | |
| 15793 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ |
| 15794 | Save current breakpoint definitions as a script.\n\ |
| 15795 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
| 15796 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
| 15797 | session to restore them."), |
| 15798 | &save_cmdlist); |
| 15799 | set_cmd_completer (c, filename_completer); |
| 15800 | |
| 15801 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ |
| 15802 | Save current tracepoint definitions as a script.\n\ |
| 15803 | Use the 'source' command in another debug session to restore them."), |
| 15804 | &save_cmdlist); |
| 15805 | set_cmd_completer (c, filename_completer); |
| 15806 | |
| 15807 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
| 15808 | deprecate_cmd (c, "save tracepoints"); |
| 15809 | |
| 15810 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
| 15811 | Breakpoint specific settings.\n\ |
| 15812 | Configure various breakpoint-specific variables such as\n\ |
| 15813 | pending breakpoint behavior."), |
| 15814 | &breakpoint_set_cmdlist, "set breakpoint ", |
| 15815 | 0/*allow-unknown*/, &setlist); |
| 15816 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
| 15817 | Breakpoint specific settings.\n\ |
| 15818 | Configure various breakpoint-specific variables such as\n\ |
| 15819 | pending breakpoint behavior."), |
| 15820 | &breakpoint_show_cmdlist, "show breakpoint ", |
| 15821 | 0/*allow-unknown*/, &showlist); |
| 15822 | |
| 15823 | add_setshow_auto_boolean_cmd ("pending", no_class, |
| 15824 | &pending_break_support, _("\ |
| 15825 | Set debugger's behavior regarding pending breakpoints."), _("\ |
| 15826 | Show debugger's behavior regarding pending breakpoints."), _("\ |
| 15827 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
| 15828 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ |
| 15829 | an error. If auto, an unrecognized breakpoint location results in a\n\ |
| 15830 | user-query to see if a pending breakpoint should be created."), |
| 15831 | NULL, |
| 15832 | show_pending_break_support, |
| 15833 | &breakpoint_set_cmdlist, |
| 15834 | &breakpoint_show_cmdlist); |
| 15835 | |
| 15836 | pending_break_support = AUTO_BOOLEAN_AUTO; |
| 15837 | |
| 15838 | add_setshow_boolean_cmd ("auto-hw", no_class, |
| 15839 | &automatic_hardware_breakpoints, _("\ |
| 15840 | Set automatic usage of hardware breakpoints."), _("\ |
| 15841 | Show automatic usage of hardware breakpoints."), _("\ |
| 15842 | If set, the debugger will automatically use hardware breakpoints for\n\ |
| 15843 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ |
| 15844 | a warning will be emitted for such breakpoints."), |
| 15845 | NULL, |
| 15846 | show_automatic_hardware_breakpoints, |
| 15847 | &breakpoint_set_cmdlist, |
| 15848 | &breakpoint_show_cmdlist); |
| 15849 | |
| 15850 | add_setshow_boolean_cmd ("always-inserted", class_support, |
| 15851 | &always_inserted_mode, _("\ |
| 15852 | Set mode for inserting breakpoints."), _("\ |
| 15853 | Show mode for inserting breakpoints."), _("\ |
| 15854 | When this mode is on, breakpoints are inserted immediately as soon as\n\ |
| 15855 | they're created, kept inserted even when execution stops, and removed\n\ |
| 15856 | only when the user deletes them. When this mode is off (the default),\n\ |
| 15857 | breakpoints are inserted only when execution continues, and removed\n\ |
| 15858 | when execution stops."), |
| 15859 | NULL, |
| 15860 | &show_always_inserted_mode, |
| 15861 | &breakpoint_set_cmdlist, |
| 15862 | &breakpoint_show_cmdlist); |
| 15863 | |
| 15864 | add_setshow_enum_cmd ("condition-evaluation", class_breakpoint, |
| 15865 | condition_evaluation_enums, |
| 15866 | &condition_evaluation_mode_1, _("\ |
| 15867 | Set mode of breakpoint condition evaluation."), _("\ |
| 15868 | Show mode of breakpoint condition evaluation."), _("\ |
| 15869 | When this is set to \"host\", breakpoint conditions will be\n\ |
| 15870 | evaluated on the host's side by GDB. When it is set to \"target\",\n\ |
| 15871 | breakpoint conditions will be downloaded to the target (if the target\n\ |
| 15872 | supports such feature) and conditions will be evaluated on the target's side.\n\ |
| 15873 | If this is set to \"auto\" (default), this will be automatically set to\n\ |
| 15874 | \"target\" if it supports condition evaluation, otherwise it will\n\ |
| 15875 | be set to \"gdb\""), |
| 15876 | &set_condition_evaluation_mode, |
| 15877 | &show_condition_evaluation_mode, |
| 15878 | &breakpoint_set_cmdlist, |
| 15879 | &breakpoint_show_cmdlist); |
| 15880 | |
| 15881 | add_com ("break-range", class_breakpoint, break_range_command, _("\ |
| 15882 | Set a breakpoint for an address range.\n\ |
| 15883 | break-range START-LOCATION, END-LOCATION\n\ |
| 15884 | where START-LOCATION and END-LOCATION can be one of the following:\n\ |
| 15885 | LINENUM, for that line in the current file,\n\ |
| 15886 | FILE:LINENUM, for that line in that file,\n\ |
| 15887 | +OFFSET, for that number of lines after the current line\n\ |
| 15888 | or the start of the range\n\ |
| 15889 | FUNCTION, for the first line in that function,\n\ |
| 15890 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ |
| 15891 | *ADDRESS, for the instruction at that address.\n\ |
| 15892 | \n\ |
| 15893 | The breakpoint will stop execution of the inferior whenever it executes\n\ |
| 15894 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ |
| 15895 | range (including START-LOCATION and END-LOCATION).")); |
| 15896 | |
| 15897 | c = add_com ("dprintf", class_breakpoint, dprintf_command, _("\ |
| 15898 | Set a dynamic printf at specified location.\n\ |
| 15899 | dprintf location,format string,arg1,arg2,...\n\ |
| 15900 | location may be a linespec, explicit, or address location.\n" |
| 15901 | "\n" LOCATION_HELP_STRING)); |
| 15902 | set_cmd_completer (c, location_completer); |
| 15903 | |
| 15904 | add_setshow_enum_cmd ("dprintf-style", class_support, |
| 15905 | dprintf_style_enums, &dprintf_style, _("\ |
| 15906 | Set the style of usage for dynamic printf."), _("\ |
| 15907 | Show the style of usage for dynamic printf."), _("\ |
| 15908 | This setting chooses how GDB will do a dynamic printf.\n\ |
| 15909 | If the value is \"gdb\", then the printing is done by GDB to its own\n\ |
| 15910 | console, as with the \"printf\" command.\n\ |
| 15911 | If the value is \"call\", the print is done by calling a function in your\n\ |
| 15912 | program; by default printf(), but you can choose a different function or\n\ |
| 15913 | output stream by setting dprintf-function and dprintf-channel."), |
| 15914 | update_dprintf_commands, NULL, |
| 15915 | &setlist, &showlist); |
| 15916 | |
| 15917 | dprintf_function = xstrdup ("printf"); |
| 15918 | add_setshow_string_cmd ("dprintf-function", class_support, |
| 15919 | &dprintf_function, _("\ |
| 15920 | Set the function to use for dynamic printf."), _("\ |
| 15921 | Show the function to use for dynamic printf."), NULL, |
| 15922 | update_dprintf_commands, NULL, |
| 15923 | &setlist, &showlist); |
| 15924 | |
| 15925 | dprintf_channel = xstrdup (""); |
| 15926 | add_setshow_string_cmd ("dprintf-channel", class_support, |
| 15927 | &dprintf_channel, _("\ |
| 15928 | Set the channel to use for dynamic printf."), _("\ |
| 15929 | Show the channel to use for dynamic printf."), NULL, |
| 15930 | update_dprintf_commands, NULL, |
| 15931 | &setlist, &showlist); |
| 15932 | |
| 15933 | add_setshow_boolean_cmd ("disconnected-dprintf", no_class, |
| 15934 | &disconnected_dprintf, _("\ |
| 15935 | Set whether dprintf continues after GDB disconnects."), _("\ |
| 15936 | Show whether dprintf continues after GDB disconnects."), _("\ |
| 15937 | Use this to let dprintf commands continue to hit and produce output\n\ |
| 15938 | even if GDB disconnects or detaches from the target."), |
| 15939 | NULL, |
| 15940 | NULL, |
| 15941 | &setlist, &showlist); |
| 15942 | |
| 15943 | add_com ("agent-printf", class_vars, agent_printf_command, _("\ |
| 15944 | Target agent only formatted printing, like the C \"printf\" function.\n\ |
| 15945 | Usage: agent-printf \"format string\", ARG1, ARG2, ARG3, ..., ARGN\n\ |
| 15946 | This supports most C printf format specifications, like %s, %d, etc.\n\ |
| 15947 | This is useful for formatted output in user-defined commands.")); |
| 15948 | |
| 15949 | automatic_hardware_breakpoints = true; |
| 15950 | |
| 15951 | gdb::observers::about_to_proceed.attach (breakpoint_about_to_proceed); |
| 15952 | gdb::observers::thread_exit.attach (remove_threaded_breakpoints); |
| 15953 | } |