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