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