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