| 1 | /* Everything about breakpoints, for GDB. |
| 2 | Copyright 1986, 1987, 1989, 1990, 1991, 1992, 1993, 1994, 1995 |
| 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 20 | |
| 21 | #include "defs.h" |
| 22 | #include <ctype.h> |
| 23 | #include "symtab.h" |
| 24 | #include "frame.h" |
| 25 | #include "breakpoint.h" |
| 26 | #include "gdbtypes.h" |
| 27 | #include "expression.h" |
| 28 | #include "gdbcore.h" |
| 29 | #include "gdbcmd.h" |
| 30 | #include "value.h" |
| 31 | #include "ctype.h" |
| 32 | #include "command.h" |
| 33 | #include "inferior.h" |
| 34 | #include "thread.h" |
| 35 | #include "target.h" |
| 36 | #include "language.h" |
| 37 | #include <string.h> |
| 38 | #include "demangle.h" |
| 39 | #include "annotate.h" |
| 40 | |
| 41 | /* local function prototypes */ |
| 42 | |
| 43 | static void |
| 44 | catch_command_1 PARAMS ((char *, int, int)); |
| 45 | |
| 46 | static void |
| 47 | enable_delete_command PARAMS ((char *, int)); |
| 48 | |
| 49 | static void |
| 50 | enable_delete_breakpoint PARAMS ((struct breakpoint *)); |
| 51 | |
| 52 | static void |
| 53 | enable_once_command PARAMS ((char *, int)); |
| 54 | |
| 55 | static void |
| 56 | enable_once_breakpoint PARAMS ((struct breakpoint *)); |
| 57 | |
| 58 | static void |
| 59 | disable_command PARAMS ((char *, int)); |
| 60 | |
| 61 | static void |
| 62 | enable_command PARAMS ((char *, int)); |
| 63 | |
| 64 | static void |
| 65 | map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *))); |
| 66 | |
| 67 | static void |
| 68 | ignore_command PARAMS ((char *, int)); |
| 69 | |
| 70 | static int |
| 71 | breakpoint_re_set_one PARAMS ((char *)); |
| 72 | |
| 73 | static void |
| 74 | delete_command PARAMS ((char *, int)); |
| 75 | |
| 76 | static void |
| 77 | clear_command PARAMS ((char *, int)); |
| 78 | |
| 79 | static void |
| 80 | catch_command PARAMS ((char *, int)); |
| 81 | |
| 82 | static struct symtabs_and_lines |
| 83 | get_catch_sals PARAMS ((int)); |
| 84 | |
| 85 | static void |
| 86 | watch_command PARAMS ((char *, int)); |
| 87 | |
| 88 | static int |
| 89 | can_use_hardware_watchpoint PARAMS ((struct value *)); |
| 90 | |
| 91 | static void |
| 92 | tbreak_command PARAMS ((char *, int)); |
| 93 | |
| 94 | static void |
| 95 | break_command_1 PARAMS ((char *, int, int)); |
| 96 | |
| 97 | static void |
| 98 | mention PARAMS ((struct breakpoint *)); |
| 99 | |
| 100 | static struct breakpoint * |
| 101 | set_raw_breakpoint PARAMS ((struct symtab_and_line)); |
| 102 | |
| 103 | static void |
| 104 | check_duplicates PARAMS ((CORE_ADDR)); |
| 105 | |
| 106 | static void |
| 107 | describe_other_breakpoints PARAMS ((CORE_ADDR)); |
| 108 | |
| 109 | static void |
| 110 | breakpoints_info PARAMS ((char *, int)); |
| 111 | |
| 112 | static void |
| 113 | breakpoint_1 PARAMS ((int, int)); |
| 114 | |
| 115 | static bpstat |
| 116 | bpstat_alloc PARAMS ((struct breakpoint *, bpstat)); |
| 117 | |
| 118 | static int |
| 119 | breakpoint_cond_eval PARAMS ((char *)); |
| 120 | |
| 121 | static void |
| 122 | cleanup_executing_breakpoints PARAMS ((int)); |
| 123 | |
| 124 | static void |
| 125 | commands_command PARAMS ((char *, int)); |
| 126 | |
| 127 | static void |
| 128 | condition_command PARAMS ((char *, int)); |
| 129 | |
| 130 | static int |
| 131 | get_number PARAMS ((char **)); |
| 132 | |
| 133 | static void |
| 134 | set_breakpoint_count PARAMS ((int)); |
| 135 | |
| 136 | static int |
| 137 | remove_breakpoint PARAMS ((struct breakpoint *)); |
| 138 | |
| 139 | extern int addressprint; /* Print machine addresses? */ |
| 140 | |
| 141 | /* Are we executing breakpoint commands? */ |
| 142 | static int executing_breakpoint_commands; |
| 143 | |
| 144 | /* Walk the following statement or block through all breakpoints. |
| 145 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current |
| 146 | breakpoint. */ |
| 147 | |
| 148 | #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next) |
| 149 | |
| 150 | #define ALL_BREAKPOINTS_SAFE(b,tmp) \ |
| 151 | for (b = breakpoint_chain; \ |
| 152 | b? (tmp=b->next, 1): 0; \ |
| 153 | b = tmp) |
| 154 | |
| 155 | /* Provide defaults for systems that don't support hardware watchpoints. */ |
| 156 | |
| 157 | #ifndef TARGET_CAN_USE_HARDWARE_WATCHPOINT |
| 158 | |
| 159 | /* Returns non-zero if we can set a hardware watchpoint of type TYPE. TYPE is |
| 160 | one of bp_hardware_watchpoint, bp_read_watchpoint, bp_write_watchpoint, or |
| 161 | bp_hardware_breakpoint. CNT is the number of such watchpoints used so far |
| 162 | (including this one?). OTHERTYPE is who knows what... */ |
| 163 | |
| 164 | #define TARGET_CAN_USE_HARDWARE_WATCHPOINT(TYPE,CNT,OTHERTYPE) 0 |
| 165 | |
| 166 | /* Set/clear a hardware watchpoint starting at ADDR, for LEN bytes. TYPE is 1 |
| 167 | for read and 2 for read/write accesses. Returns 0 for success, non-zero for |
| 168 | failure. */ |
| 169 | |
| 170 | #define target_remove_watchpoint(ADDR,LEN,TYPE) -1 |
| 171 | #define target_insert_watchpoint(ADDR,LEN,TYPE) -1 |
| 172 | #endif |
| 173 | |
| 174 | #ifndef target_insert_hw_breakpoint |
| 175 | #define target_remove_hw_breakpoint(ADDR,SHADOW) -1 |
| 176 | #define target_insert_hw_breakpoint(ADDR,SHADOW) -1 |
| 177 | #endif |
| 178 | |
| 179 | #ifndef target_stopped_data_address |
| 180 | #define target_stopped_data_address() 0 |
| 181 | #endif |
| 182 | |
| 183 | /* True if breakpoint hit counts should be displayed in breakpoint info. */ |
| 184 | |
| 185 | int show_breakpoint_hit_counts = 1; |
| 186 | |
| 187 | /* Chain of all breakpoints defined. */ |
| 188 | |
| 189 | struct breakpoint *breakpoint_chain; |
| 190 | |
| 191 | /* Number of last breakpoint made. */ |
| 192 | |
| 193 | static int breakpoint_count; |
| 194 | |
| 195 | /* Set breakpoint count to NUM. */ |
| 196 | |
| 197 | static void |
| 198 | set_breakpoint_count (num) |
| 199 | int num; |
| 200 | { |
| 201 | breakpoint_count = num; |
| 202 | set_internalvar (lookup_internalvar ("bpnum"), |
| 203 | value_from_longest (builtin_type_int, (LONGEST) num)); |
| 204 | } |
| 205 | |
| 206 | /* Used in run_command to zero the hit count when a new run starts. */ |
| 207 | |
| 208 | void |
| 209 | clear_breakpoint_hit_counts () |
| 210 | { |
| 211 | struct breakpoint *b; |
| 212 | |
| 213 | ALL_BREAKPOINTS (b) |
| 214 | b->hit_count = 0; |
| 215 | } |
| 216 | |
| 217 | /* Default address, symtab and line to put a breakpoint at |
| 218 | for "break" command with no arg. |
| 219 | if default_breakpoint_valid is zero, the other three are |
| 220 | not valid, and "break" with no arg is an error. |
| 221 | |
| 222 | This set by print_stack_frame, which calls set_default_breakpoint. */ |
| 223 | |
| 224 | int default_breakpoint_valid; |
| 225 | CORE_ADDR default_breakpoint_address; |
| 226 | struct symtab *default_breakpoint_symtab; |
| 227 | int default_breakpoint_line; |
| 228 | \f |
| 229 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. |
| 230 | Advance *PP after the string and any trailing whitespace. |
| 231 | |
| 232 | Currently the string can either be a number or "$" followed by the name |
| 233 | of a convenience variable. Making it an expression wouldn't work well |
| 234 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */ |
| 235 | static int |
| 236 | get_number (pp) |
| 237 | char **pp; |
| 238 | { |
| 239 | int retval; |
| 240 | char *p = *pp; |
| 241 | |
| 242 | if (p == NULL) |
| 243 | /* Empty line means refer to the last breakpoint. */ |
| 244 | return breakpoint_count; |
| 245 | else if (*p == '$') |
| 246 | { |
| 247 | /* Make a copy of the name, so we can null-terminate it |
| 248 | to pass to lookup_internalvar(). */ |
| 249 | char *varname; |
| 250 | char *start = ++p; |
| 251 | value_ptr val; |
| 252 | |
| 253 | while (isalnum (*p) || *p == '_') |
| 254 | p++; |
| 255 | varname = (char *) alloca (p - start + 1); |
| 256 | strncpy (varname, start, p - start); |
| 257 | varname[p - start] = '\0'; |
| 258 | val = value_of_internalvar (lookup_internalvar (varname)); |
| 259 | if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT) |
| 260 | error ( |
| 261 | "Convenience variables used to specify breakpoints must have integer values." |
| 262 | ); |
| 263 | retval = (int) value_as_long (val); |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | if (*p == '-') |
| 268 | ++p; |
| 269 | while (*p >= '0' && *p <= '9') |
| 270 | ++p; |
| 271 | if (p == *pp) |
| 272 | /* There is no number here. (e.g. "cond a == b"). */ |
| 273 | error_no_arg ("breakpoint number"); |
| 274 | retval = atoi (*pp); |
| 275 | } |
| 276 | if (!(isspace (*p) || *p == '\0')) |
| 277 | error ("breakpoint number expected"); |
| 278 | while (isspace (*p)) |
| 279 | p++; |
| 280 | *pp = p; |
| 281 | return retval; |
| 282 | } |
| 283 | \f |
| 284 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
| 285 | |
| 286 | static void |
| 287 | condition_command (arg, from_tty) |
| 288 | char *arg; |
| 289 | int from_tty; |
| 290 | { |
| 291 | register struct breakpoint *b; |
| 292 | char *p; |
| 293 | register int bnum; |
| 294 | |
| 295 | if (arg == 0) |
| 296 | error_no_arg ("breakpoint number"); |
| 297 | |
| 298 | p = arg; |
| 299 | bnum = get_number (&p); |
| 300 | |
| 301 | ALL_BREAKPOINTS (b) |
| 302 | if (b->number == bnum) |
| 303 | { |
| 304 | if (b->cond) |
| 305 | { |
| 306 | free ((PTR)b->cond); |
| 307 | b->cond = 0; |
| 308 | } |
| 309 | if (b->cond_string != NULL) |
| 310 | free ((PTR)b->cond_string); |
| 311 | |
| 312 | if (*p == 0) |
| 313 | { |
| 314 | b->cond = 0; |
| 315 | b->cond_string = NULL; |
| 316 | if (from_tty) |
| 317 | printf_filtered ("Breakpoint %d now unconditional.\n", bnum); |
| 318 | } |
| 319 | else |
| 320 | { |
| 321 | arg = p; |
| 322 | /* I don't know if it matters whether this is the string the user |
| 323 | typed in or the decompiled expression. */ |
| 324 | b->cond_string = savestring (arg, strlen (arg)); |
| 325 | b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0); |
| 326 | if (*arg) |
| 327 | error ("Junk at end of expression"); |
| 328 | } |
| 329 | breakpoints_changed (); |
| 330 | return; |
| 331 | } |
| 332 | |
| 333 | error ("No breakpoint number %d.", bnum); |
| 334 | } |
| 335 | |
| 336 | /* ARGSUSED */ |
| 337 | static void |
| 338 | commands_command (arg, from_tty) |
| 339 | char *arg; |
| 340 | int from_tty; |
| 341 | { |
| 342 | register struct breakpoint *b; |
| 343 | char *p; |
| 344 | register int bnum; |
| 345 | struct command_line *l; |
| 346 | |
| 347 | /* If we allowed this, we would have problems with when to |
| 348 | free the storage, if we change the commands currently |
| 349 | being read from. */ |
| 350 | |
| 351 | if (executing_breakpoint_commands) |
| 352 | error ("Can't use the \"commands\" command among a breakpoint's commands."); |
| 353 | |
| 354 | p = arg; |
| 355 | bnum = get_number (&p); |
| 356 | if (p && *p) |
| 357 | error ("Unexpected extra arguments following breakpoint number."); |
| 358 | |
| 359 | ALL_BREAKPOINTS (b) |
| 360 | if (b->number == bnum) |
| 361 | { |
| 362 | if (from_tty && input_from_terminal_p ()) |
| 363 | printf_filtered ("Type commands for when breakpoint %d is hit, one per line.\n\ |
| 364 | End with a line saying just \"end\".\n", bnum); |
| 365 | l = read_command_lines (); |
| 366 | free_command_lines (&b->commands); |
| 367 | b->commands = l; |
| 368 | breakpoints_changed (); |
| 369 | return; |
| 370 | } |
| 371 | error ("No breakpoint number %d.", bnum); |
| 372 | } |
| 373 | \f |
| 374 | extern int memory_breakpoint_size; /* from mem-break.c */ |
| 375 | |
| 376 | /* Like target_read_memory() but if breakpoints are inserted, return |
| 377 | the shadow contents instead of the breakpoints themselves. |
| 378 | |
| 379 | Read "memory data" from whatever target or inferior we have. |
| 380 | Returns zero if successful, errno value if not. EIO is used |
| 381 | for address out of bounds. If breakpoints are inserted, returns |
| 382 | shadow contents, not the breakpoints themselves. From breakpoint.c. */ |
| 383 | |
| 384 | int |
| 385 | read_memory_nobpt (memaddr, myaddr, len) |
| 386 | CORE_ADDR memaddr; |
| 387 | char *myaddr; |
| 388 | unsigned len; |
| 389 | { |
| 390 | int status; |
| 391 | struct breakpoint *b; |
| 392 | |
| 393 | if (memory_breakpoint_size < 0) |
| 394 | /* No breakpoints on this machine. FIXME: This should be |
| 395 | dependent on the debugging target. Probably want |
| 396 | target_insert_breakpoint to return a size, saying how many |
| 397 | bytes of the shadow contents are used, or perhaps have |
| 398 | something like target_xfer_shadow. */ |
| 399 | return target_read_memory (memaddr, myaddr, len); |
| 400 | |
| 401 | ALL_BREAKPOINTS (b) |
| 402 | { |
| 403 | if (b->type == bp_watchpoint |
| 404 | || b->type == bp_hardware_watchpoint |
| 405 | || b->type == bp_read_watchpoint |
| 406 | || b->type == bp_access_watchpoint |
| 407 | || !b->inserted) |
| 408 | continue; |
| 409 | else if (b->address + memory_breakpoint_size <= memaddr) |
| 410 | /* The breakpoint is entirely before the chunk of memory |
| 411 | we are reading. */ |
| 412 | continue; |
| 413 | else if (b->address >= memaddr + len) |
| 414 | /* The breakpoint is entirely after the chunk of memory we |
| 415 | are reading. */ |
| 416 | continue; |
| 417 | else |
| 418 | { |
| 419 | /* Copy the breakpoint from the shadow contents, and recurse |
| 420 | for the things before and after. */ |
| 421 | |
| 422 | /* Addresses and length of the part of the breakpoint that |
| 423 | we need to copy. */ |
| 424 | CORE_ADDR membpt = b->address; |
| 425 | unsigned int bptlen = memory_breakpoint_size; |
| 426 | /* Offset within shadow_contents. */ |
| 427 | int bptoffset = 0; |
| 428 | |
| 429 | if (membpt < memaddr) |
| 430 | { |
| 431 | /* Only copy the second part of the breakpoint. */ |
| 432 | bptlen -= memaddr - membpt; |
| 433 | bptoffset = memaddr - membpt; |
| 434 | membpt = memaddr; |
| 435 | } |
| 436 | |
| 437 | if (membpt + bptlen > memaddr + len) |
| 438 | { |
| 439 | /* Only copy the first part of the breakpoint. */ |
| 440 | bptlen -= (membpt + bptlen) - (memaddr + len); |
| 441 | } |
| 442 | |
| 443 | memcpy (myaddr + membpt - memaddr, |
| 444 | b->shadow_contents + bptoffset, bptlen); |
| 445 | |
| 446 | if (membpt > memaddr) |
| 447 | { |
| 448 | /* Copy the section of memory before the breakpoint. */ |
| 449 | status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr); |
| 450 | if (status != 0) |
| 451 | return status; |
| 452 | } |
| 453 | |
| 454 | if (membpt + bptlen < memaddr + len) |
| 455 | { |
| 456 | /* Copy the section of memory after the breakpoint. */ |
| 457 | status = read_memory_nobpt |
| 458 | (membpt + bptlen, |
| 459 | myaddr + membpt + bptlen - memaddr, |
| 460 | memaddr + len - (membpt + bptlen)); |
| 461 | if (status != 0) |
| 462 | return status; |
| 463 | } |
| 464 | return 0; |
| 465 | } |
| 466 | } |
| 467 | /* Nothing overlaps. Just call read_memory_noerr. */ |
| 468 | return target_read_memory (memaddr, myaddr, len); |
| 469 | } |
| 470 | \f |
| 471 | /* insert_breakpoints is used when starting or continuing the program. |
| 472 | remove_breakpoints is used when the program stops. |
| 473 | Both return zero if successful, |
| 474 | or an `errno' value if could not write the inferior. */ |
| 475 | |
| 476 | int |
| 477 | insert_breakpoints () |
| 478 | { |
| 479 | register struct breakpoint *b; |
| 480 | int val = 0; |
| 481 | int disabled_breaks = 0; |
| 482 | |
| 483 | ALL_BREAKPOINTS (b) |
| 484 | if (b->type != bp_watchpoint |
| 485 | && b->type != bp_hardware_watchpoint |
| 486 | && b->type != bp_read_watchpoint |
| 487 | && b->type != bp_access_watchpoint |
| 488 | && b->enable != disabled |
| 489 | && ! b->inserted |
| 490 | && ! b->duplicate) |
| 491 | { |
| 492 | if (b->type == bp_hardware_breakpoint) |
| 493 | val = target_insert_hw_breakpoint(b->address, b->shadow_contents); |
| 494 | else |
| 495 | val = target_insert_breakpoint(b->address, b->shadow_contents); |
| 496 | if (val) |
| 497 | { |
| 498 | /* Can't set the breakpoint. */ |
| 499 | #if defined (DISABLE_UNSETTABLE_BREAK) |
| 500 | if (DISABLE_UNSETTABLE_BREAK (b->address)) |
| 501 | { |
| 502 | val = 0; |
| 503 | b->enable = disabled; |
| 504 | if (!disabled_breaks) |
| 505 | { |
| 506 | target_terminal_ours_for_output (); |
| 507 | fprintf_unfiltered (gdb_stderr, |
| 508 | "Cannot insert breakpoint %d:\n", b->number); |
| 509 | printf_filtered ("Disabling shared library breakpoints:\n"); |
| 510 | } |
| 511 | disabled_breaks = 1; |
| 512 | printf_filtered ("%d ", b->number); |
| 513 | } |
| 514 | else |
| 515 | #endif |
| 516 | { |
| 517 | target_terminal_ours_for_output (); |
| 518 | fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number); |
| 519 | #ifdef ONE_PROCESS_WRITETEXT |
| 520 | fprintf_unfiltered (gdb_stderr, |
| 521 | "The same program may be running in another process.\n"); |
| 522 | #endif |
| 523 | memory_error (val, b->address); /* which bombs us out */ |
| 524 | } |
| 525 | } |
| 526 | else |
| 527 | b->inserted = 1; |
| 528 | } |
| 529 | else if ((b->type == bp_hardware_watchpoint || |
| 530 | b->type == bp_read_watchpoint || |
| 531 | b->type == bp_access_watchpoint) |
| 532 | && b->enable == enabled |
| 533 | && ! b->inserted |
| 534 | && ! b->duplicate) |
| 535 | { |
| 536 | struct frame_info *saved_frame; |
| 537 | int saved_level, within_current_scope; |
| 538 | value_ptr mark = value_mark (); |
| 539 | value_ptr v; |
| 540 | |
| 541 | /* Save the current frame and level so we can restore it after |
| 542 | evaluating the watchpoint expression on its own frame. */ |
| 543 | saved_frame = selected_frame; |
| 544 | saved_level = selected_frame_level; |
| 545 | |
| 546 | /* Determine if the watchpoint is within scope. */ |
| 547 | if (b->exp_valid_block == NULL) |
| 548 | within_current_scope = 1; |
| 549 | else |
| 550 | { |
| 551 | struct frame_info *fi = |
| 552 | find_frame_addr_in_frame_chain (b->watchpoint_frame); |
| 553 | within_current_scope = (fi != NULL); |
| 554 | if (within_current_scope) |
| 555 | select_frame (fi, -1); |
| 556 | } |
| 557 | |
| 558 | if (within_current_scope) |
| 559 | { |
| 560 | /* Evaluate the expression and cut the chain of values |
| 561 | produced off from the value chain. */ |
| 562 | v = evaluate_expression (b->exp); |
| 563 | value_release_to_mark (mark); |
| 564 | |
| 565 | b->val_chain = v; |
| 566 | b->inserted = 1; |
| 567 | |
| 568 | /* Look at each value on the value chain. */ |
| 569 | for ( ; v; v=v->next) |
| 570 | { |
| 571 | /* If it's a memory location, then we must watch it. */ |
| 572 | if (v->lval == lval_memory) |
| 573 | { |
| 574 | int addr, len, type; |
| 575 | |
| 576 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); |
| 577 | len = TYPE_LENGTH (VALUE_TYPE (v)); |
| 578 | type = 0; |
| 579 | if (b->type == bp_read_watchpoint) |
| 580 | type = 1; |
| 581 | else if (b->type == bp_access_watchpoint) |
| 582 | type = 2; |
| 583 | |
| 584 | val = target_insert_watchpoint (addr, len, type); |
| 585 | if (val == -1) |
| 586 | { |
| 587 | b->inserted = 0; |
| 588 | break; |
| 589 | } |
| 590 | val = 0; |
| 591 | } |
| 592 | } |
| 593 | /* Failure to insert a watchpoint on any memory value in the |
| 594 | value chain brings us here. */ |
| 595 | if (!b->inserted) |
| 596 | warning ("Hardware watchpoint %d: Could not insert watchpoint\n", |
| 597 | b->number); |
| 598 | } |
| 599 | else |
| 600 | { |
| 601 | printf_filtered ("\ |
| 602 | Hardware watchpoint %d deleted because the program has left the block in\n\ |
| 603 | which its expression is valid.\n", b->number); |
| 604 | if (b->related_breakpoint) |
| 605 | delete_breakpoint (b->related_breakpoint); |
| 606 | delete_breakpoint (b); |
| 607 | } |
| 608 | |
| 609 | /* Restore the frame and level. */ |
| 610 | select_frame (saved_frame, saved_level); |
| 611 | } |
| 612 | if (disabled_breaks) |
| 613 | printf_filtered ("\n"); |
| 614 | return val; |
| 615 | } |
| 616 | |
| 617 | |
| 618 | int |
| 619 | remove_breakpoints () |
| 620 | { |
| 621 | register struct breakpoint *b; |
| 622 | int val; |
| 623 | |
| 624 | ALL_BREAKPOINTS (b) |
| 625 | { |
| 626 | if (b->inserted) |
| 627 | { |
| 628 | val = remove_breakpoint (b); |
| 629 | if (val != 0) |
| 630 | return val; |
| 631 | } |
| 632 | } |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | |
| 637 | static int |
| 638 | remove_breakpoint (b) |
| 639 | struct breakpoint *b; |
| 640 | { |
| 641 | int val; |
| 642 | |
| 643 | if (b->type != bp_watchpoint |
| 644 | && b->type != bp_hardware_watchpoint |
| 645 | && b->type != bp_read_watchpoint |
| 646 | && b->type != bp_access_watchpoint) |
| 647 | { |
| 648 | if (b->type == bp_hardware_breakpoint) |
| 649 | val = target_remove_hw_breakpoint(b->address, b->shadow_contents); |
| 650 | else |
| 651 | val = target_remove_breakpoint(b->address, b->shadow_contents); |
| 652 | if (val) |
| 653 | return val; |
| 654 | b->inserted = 0; |
| 655 | } |
| 656 | else if ((b->type == bp_hardware_watchpoint || |
| 657 | b->type == bp_read_watchpoint || |
| 658 | b->type == bp_access_watchpoint) |
| 659 | && b->enable == enabled |
| 660 | && ! b->duplicate) |
| 661 | { |
| 662 | value_ptr v, n; |
| 663 | |
| 664 | b->inserted = 0; |
| 665 | /* Walk down the saved value chain. */ |
| 666 | for (v = b->val_chain; v; v = v->next) |
| 667 | { |
| 668 | /* For each memory reference remove the watchpoint |
| 669 | at that address. */ |
| 670 | if (v->lval == lval_memory) |
| 671 | { |
| 672 | int addr, len; |
| 673 | |
| 674 | addr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); |
| 675 | len = TYPE_LENGTH (VALUE_TYPE (v)); |
| 676 | val = target_remove_watchpoint (addr, len, b->type); |
| 677 | if (val == -1) |
| 678 | b->inserted = 1; |
| 679 | val = 0; |
| 680 | } |
| 681 | } |
| 682 | /* Failure to remove any of the hardware watchpoints comes here. */ |
| 683 | if (b->inserted) |
| 684 | error ("Hardware watchpoint %d: Could not remove watchpoint\n", |
| 685 | b->number); |
| 686 | |
| 687 | /* Free the saved value chain. We will construct a new one |
| 688 | the next time the watchpoint is inserted. */ |
| 689 | for (v = b->val_chain; v; v = n) |
| 690 | { |
| 691 | n = v->next; |
| 692 | value_free (v); |
| 693 | } |
| 694 | b->val_chain = NULL; |
| 695 | } |
| 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | /* Clear the "inserted" flag in all breakpoints. */ |
| 700 | |
| 701 | void |
| 702 | mark_breakpoints_out () |
| 703 | { |
| 704 | register struct breakpoint *b; |
| 705 | |
| 706 | ALL_BREAKPOINTS (b) |
| 707 | b->inserted = 0; |
| 708 | } |
| 709 | |
| 710 | /* Clear the "inserted" flag in all breakpoints and delete any breakpoints |
| 711 | which should go away between runs of the program. */ |
| 712 | |
| 713 | void |
| 714 | breakpoint_init_inferior () |
| 715 | { |
| 716 | register struct breakpoint *b, *temp; |
| 717 | |
| 718 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 719 | { |
| 720 | b->inserted = 0; |
| 721 | |
| 722 | /* If the call dummy breakpoint is at the entry point it will |
| 723 | cause problems when the inferior is rerun, so we better |
| 724 | get rid of it. */ |
| 725 | if (b->type == bp_call_dummy) |
| 726 | delete_breakpoint (b); |
| 727 | |
| 728 | /* Likewise for scope breakpoints. */ |
| 729 | if (b->type == bp_watchpoint_scope) |
| 730 | delete_breakpoint (b); |
| 731 | |
| 732 | /* Likewise for watchpoints on local expressions. */ |
| 733 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint || |
| 734 | b->type == bp_read_watchpoint || b->type == bp_access_watchpoint) |
| 735 | && b->exp_valid_block != NULL) |
| 736 | delete_breakpoint (b); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC. |
| 741 | When continuing from a location with a breakpoint, |
| 742 | we actually single step once before calling insert_breakpoints. */ |
| 743 | |
| 744 | int |
| 745 | breakpoint_here_p (pc) |
| 746 | CORE_ADDR pc; |
| 747 | { |
| 748 | register struct breakpoint *b; |
| 749 | |
| 750 | ALL_BREAKPOINTS (b) |
| 751 | if (b->enable != disabled && b->address == pc) |
| 752 | return 1; |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | /* Return nonzero if FRAME is a dummy frame. We can't use PC_IN_CALL_DUMMY |
| 758 | because figuring out the saved SP would take too much time, at least using |
| 759 | get_saved_register on the 68k. This means that for this function to |
| 760 | work right a port must use the bp_call_dummy breakpoint. */ |
| 761 | |
| 762 | int |
| 763 | frame_in_dummy (frame) |
| 764 | struct frame_info *frame; |
| 765 | { |
| 766 | struct breakpoint *b; |
| 767 | |
| 768 | #ifdef CALL_DUMMY |
| 769 | ALL_BREAKPOINTS (b) |
| 770 | { |
| 771 | static unsigned LONGEST dummy[] = CALL_DUMMY; |
| 772 | |
| 773 | if (b->type == bp_call_dummy |
| 774 | && b->frame == frame->frame |
| 775 | |
| 776 | /* We need to check the PC as well as the frame on the sparc, |
| 777 | for signals.exp in the testsuite. */ |
| 778 | && (frame->pc |
| 779 | >= (b->address |
| 780 | - sizeof (dummy) / sizeof (LONGEST) * REGISTER_SIZE)) |
| 781 | && frame->pc <= b->address) |
| 782 | return 1; |
| 783 | } |
| 784 | #endif /* CALL_DUMMY */ |
| 785 | return 0; |
| 786 | } |
| 787 | |
| 788 | /* breakpoint_match_thread (PC, PID) returns true if the breakpoint at PC |
| 789 | is valid for process/thread PID. */ |
| 790 | |
| 791 | int |
| 792 | breakpoint_thread_match (pc, pid) |
| 793 | CORE_ADDR pc; |
| 794 | int pid; |
| 795 | { |
| 796 | struct breakpoint *b; |
| 797 | int thread; |
| 798 | |
| 799 | thread = pid_to_thread_id (pid); |
| 800 | |
| 801 | ALL_BREAKPOINTS (b) |
| 802 | if (b->enable != disabled |
| 803 | && b->address == pc |
| 804 | && (b->thread == -1 || b->thread == thread)) |
| 805 | return 1; |
| 806 | |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | \f |
| 811 | /* bpstat stuff. External routines' interfaces are documented |
| 812 | in breakpoint.h. */ |
| 813 | |
| 814 | /* Clear a bpstat so that it says we are not at any breakpoint. |
| 815 | Also free any storage that is part of a bpstat. */ |
| 816 | |
| 817 | void |
| 818 | bpstat_clear (bsp) |
| 819 | bpstat *bsp; |
| 820 | { |
| 821 | bpstat p; |
| 822 | bpstat q; |
| 823 | |
| 824 | if (bsp == 0) |
| 825 | return; |
| 826 | p = *bsp; |
| 827 | while (p != NULL) |
| 828 | { |
| 829 | q = p->next; |
| 830 | if (p->old_val != NULL) |
| 831 | value_free (p->old_val); |
| 832 | free ((PTR)p); |
| 833 | p = q; |
| 834 | } |
| 835 | *bsp = NULL; |
| 836 | } |
| 837 | |
| 838 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
| 839 | is part of the bpstat is copied as well. */ |
| 840 | |
| 841 | bpstat |
| 842 | bpstat_copy (bs) |
| 843 | bpstat bs; |
| 844 | { |
| 845 | bpstat p = NULL; |
| 846 | bpstat tmp; |
| 847 | bpstat retval = NULL; |
| 848 | |
| 849 | if (bs == NULL) |
| 850 | return bs; |
| 851 | |
| 852 | for (; bs != NULL; bs = bs->next) |
| 853 | { |
| 854 | tmp = (bpstat) xmalloc (sizeof (*tmp)); |
| 855 | memcpy (tmp, bs, sizeof (*tmp)); |
| 856 | if (p == NULL) |
| 857 | /* This is the first thing in the chain. */ |
| 858 | retval = tmp; |
| 859 | else |
| 860 | p->next = tmp; |
| 861 | p = tmp; |
| 862 | } |
| 863 | p->next = NULL; |
| 864 | return retval; |
| 865 | } |
| 866 | |
| 867 | /* Find the bpstat associated with this breakpoint */ |
| 868 | |
| 869 | bpstat |
| 870 | bpstat_find_breakpoint(bsp, breakpoint) |
| 871 | bpstat bsp; |
| 872 | struct breakpoint *breakpoint; |
| 873 | { |
| 874 | if (bsp == NULL) return NULL; |
| 875 | |
| 876 | for (;bsp != NULL; bsp = bsp->next) { |
| 877 | if (bsp->breakpoint_at == breakpoint) return bsp; |
| 878 | } |
| 879 | return NULL; |
| 880 | } |
| 881 | |
| 882 | /* Return the breakpoint number of the first breakpoint we are stopped |
| 883 | at. *BSP upon return is a bpstat which points to the remaining |
| 884 | breakpoints stopped at (but which is not guaranteed to be good for |
| 885 | anything but further calls to bpstat_num). |
| 886 | Return 0 if passed a bpstat which does not indicate any breakpoints. */ |
| 887 | |
| 888 | int |
| 889 | bpstat_num (bsp) |
| 890 | bpstat *bsp; |
| 891 | { |
| 892 | struct breakpoint *b; |
| 893 | |
| 894 | if ((*bsp) == NULL) |
| 895 | return 0; /* No more breakpoint values */ |
| 896 | else |
| 897 | { |
| 898 | b = (*bsp)->breakpoint_at; |
| 899 | *bsp = (*bsp)->next; |
| 900 | if (b == NULL) |
| 901 | return -1; /* breakpoint that's been deleted since */ |
| 902 | else |
| 903 | return b->number; /* We have its number */ |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /* Modify BS so that the actions will not be performed. */ |
| 908 | |
| 909 | void |
| 910 | bpstat_clear_actions (bs) |
| 911 | bpstat bs; |
| 912 | { |
| 913 | for (; bs != NULL; bs = bs->next) |
| 914 | { |
| 915 | bs->commands = NULL; |
| 916 | if (bs->old_val != NULL) |
| 917 | { |
| 918 | value_free (bs->old_val); |
| 919 | bs->old_val = NULL; |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
| 925 | /* ARGSUSED */ |
| 926 | static void |
| 927 | cleanup_executing_breakpoints (ignore) |
| 928 | int ignore; |
| 929 | { |
| 930 | executing_breakpoint_commands = 0; |
| 931 | } |
| 932 | |
| 933 | /* Execute all the commands associated with all the breakpoints at this |
| 934 | location. Any of these commands could cause the process to proceed |
| 935 | beyond this point, etc. We look out for such changes by checking |
| 936 | the global "breakpoint_proceeded" after each command. */ |
| 937 | |
| 938 | void |
| 939 | bpstat_do_actions (bsp) |
| 940 | bpstat *bsp; |
| 941 | { |
| 942 | bpstat bs; |
| 943 | struct cleanup *old_chain; |
| 944 | struct command_line *cmd; |
| 945 | |
| 946 | executing_breakpoint_commands = 1; |
| 947 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); |
| 948 | |
| 949 | top: |
| 950 | bs = *bsp; |
| 951 | |
| 952 | breakpoint_proceeded = 0; |
| 953 | for (; bs != NULL; bs = bs->next) |
| 954 | { |
| 955 | cmd = bs->commands; |
| 956 | while (cmd != NULL) |
| 957 | { |
| 958 | execute_control_command (cmd); |
| 959 | cmd = cmd->next; |
| 960 | } |
| 961 | if (breakpoint_proceeded) |
| 962 | /* The inferior is proceeded by the command; bomb out now. |
| 963 | The bpstat chain has been blown away by wait_for_inferior. |
| 964 | But since execution has stopped again, there is a new bpstat |
| 965 | to look at, so start over. */ |
| 966 | goto top; |
| 967 | else |
| 968 | bs->commands = NULL; |
| 969 | } |
| 970 | |
| 971 | executing_breakpoint_commands = 0; |
| 972 | discard_cleanups (old_chain); |
| 973 | } |
| 974 | |
| 975 | /* This is the normal print_it function for a bpstat. In the future, |
| 976 | much of this logic could (should?) be moved to bpstat_stop_status, |
| 977 | by having it set different print_it functions. */ |
| 978 | |
| 979 | static int |
| 980 | print_it_normal (bs) |
| 981 | bpstat bs; |
| 982 | { |
| 983 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
| 984 | which has since been deleted. */ |
| 985 | if (bs->breakpoint_at == NULL |
| 986 | || (bs->breakpoint_at->type != bp_breakpoint |
| 987 | && bs->breakpoint_at->type != bp_hardware_breakpoint |
| 988 | && bs->breakpoint_at->type != bp_watchpoint |
| 989 | && bs->breakpoint_at->type != bp_read_watchpoint |
| 990 | && bs->breakpoint_at->type != bp_access_watchpoint |
| 991 | && bs->breakpoint_at->type != bp_hardware_watchpoint)) |
| 992 | return 0; |
| 993 | |
| 994 | if (bs->breakpoint_at->type == bp_breakpoint || |
| 995 | bs->breakpoint_at->type == bp_hardware_breakpoint) |
| 996 | { |
| 997 | /* I think the user probably only wants to see one breakpoint |
| 998 | number, not all of them. */ |
| 999 | annotate_breakpoint (bs->breakpoint_at->number); |
| 1000 | printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number); |
| 1001 | return 0; |
| 1002 | } |
| 1003 | else if ((bs->old_val != NULL) && |
| 1004 | (bs->breakpoint_at->type == bp_watchpoint || |
| 1005 | bs->breakpoint_at->type == bp_access_watchpoint || |
| 1006 | bs->breakpoint_at->type == bp_hardware_watchpoint)) |
| 1007 | { |
| 1008 | annotate_watchpoint (bs->breakpoint_at->number); |
| 1009 | mention (bs->breakpoint_at); |
| 1010 | printf_filtered ("\nOld value = "); |
| 1011 | value_print (bs->old_val, gdb_stdout, 0, Val_pretty_default); |
| 1012 | printf_filtered ("\nNew value = "); |
| 1013 | value_print (bs->breakpoint_at->val, gdb_stdout, 0, |
| 1014 | Val_pretty_default); |
| 1015 | printf_filtered ("\n"); |
| 1016 | value_free (bs->old_val); |
| 1017 | bs->old_val = NULL; |
| 1018 | /* More than one watchpoint may have been triggered. */ |
| 1019 | return -1; |
| 1020 | } |
| 1021 | else if (bs->breakpoint_at->type == bp_access_watchpoint || |
| 1022 | bs->breakpoint_at->type == bp_read_watchpoint) |
| 1023 | { |
| 1024 | mention (bs->breakpoint_at); |
| 1025 | printf_filtered ("\nValue = "); |
| 1026 | value_print (bs->breakpoint_at->val, gdb_stdout, 0, |
| 1027 | Val_pretty_default); |
| 1028 | printf_filtered ("\n"); |
| 1029 | return -1; |
| 1030 | } |
| 1031 | /* We can't deal with it. Maybe another member of the bpstat chain can. */ |
| 1032 | return -1; |
| 1033 | } |
| 1034 | |
| 1035 | /* Print a message indicating what happened. Returns nonzero to |
| 1036 | say that only the source line should be printed after this (zero |
| 1037 | return means print the frame as well as the source line). */ |
| 1038 | /* Currently we always return zero. */ |
| 1039 | int |
| 1040 | bpstat_print (bs) |
| 1041 | bpstat bs; |
| 1042 | { |
| 1043 | int val; |
| 1044 | |
| 1045 | if (bs == NULL) |
| 1046 | return 0; |
| 1047 | |
| 1048 | val = (*bs->print_it) (bs); |
| 1049 | if (val >= 0) |
| 1050 | return val; |
| 1051 | |
| 1052 | /* Maybe another breakpoint in the chain caused us to stop. |
| 1053 | (Currently all watchpoints go on the bpstat whether hit or |
| 1054 | not. That probably could (should) be changed, provided care is taken |
| 1055 | with respect to bpstat_explains_signal). */ |
| 1056 | if (bs->next) |
| 1057 | return bpstat_print (bs->next); |
| 1058 | |
| 1059 | /* We reached the end of the chain without printing anything. */ |
| 1060 | return 0; |
| 1061 | } |
| 1062 | |
| 1063 | /* Evaluate the expression EXP and return 1 if value is zero. |
| 1064 | This is used inside a catch_errors to evaluate the breakpoint condition. |
| 1065 | The argument is a "struct expression *" that has been cast to char * to |
| 1066 | make it pass through catch_errors. */ |
| 1067 | |
| 1068 | static int |
| 1069 | breakpoint_cond_eval (exp) |
| 1070 | char *exp; |
| 1071 | { |
| 1072 | value_ptr mark = value_mark (); |
| 1073 | int i = !value_true (evaluate_expression ((struct expression *)exp)); |
| 1074 | value_free_to_mark (mark); |
| 1075 | return i; |
| 1076 | } |
| 1077 | |
| 1078 | /* Allocate a new bpstat and chain it to the current one. */ |
| 1079 | |
| 1080 | static bpstat |
| 1081 | bpstat_alloc (b, cbs) |
| 1082 | register struct breakpoint *b; |
| 1083 | bpstat cbs; /* Current "bs" value */ |
| 1084 | { |
| 1085 | bpstat bs; |
| 1086 | |
| 1087 | bs = (bpstat) xmalloc (sizeof (*bs)); |
| 1088 | cbs->next = bs; |
| 1089 | bs->breakpoint_at = b; |
| 1090 | /* If the condition is false, etc., don't do the commands. */ |
| 1091 | bs->commands = NULL; |
| 1092 | bs->old_val = NULL; |
| 1093 | bs->print_it = print_it_normal; |
| 1094 | return bs; |
| 1095 | } |
| 1096 | \f |
| 1097 | /* Possible return values for watchpoint_check (this can't be an enum |
| 1098 | because of check_errors). */ |
| 1099 | /* The watchpoint has been deleted. */ |
| 1100 | #define WP_DELETED 1 |
| 1101 | /* The value has changed. */ |
| 1102 | #define WP_VALUE_CHANGED 2 |
| 1103 | /* The value has not changed. */ |
| 1104 | #define WP_VALUE_NOT_CHANGED 3 |
| 1105 | |
| 1106 | #define BP_TEMPFLAG 1 |
| 1107 | #define BP_HARDWAREFLAG 2 |
| 1108 | |
| 1109 | /* Check watchpoint condition. */ |
| 1110 | |
| 1111 | static int |
| 1112 | watchpoint_check (p) |
| 1113 | char *p; |
| 1114 | { |
| 1115 | bpstat bs = (bpstat) p; |
| 1116 | struct breakpoint *b; |
| 1117 | struct frame_info *saved_frame, *fr; |
| 1118 | int within_current_scope, saved_level; |
| 1119 | |
| 1120 | b = bs->breakpoint_at; |
| 1121 | |
| 1122 | if (b->exp_valid_block == NULL) |
| 1123 | within_current_scope = 1; |
| 1124 | else |
| 1125 | { |
| 1126 | /* There is no current frame at this moment. If we're going to have |
| 1127 | any chance of handling watchpoints on local variables, we'll need |
| 1128 | the frame chain (so we can determine if we're in scope). */ |
| 1129 | reinit_frame_cache(); |
| 1130 | fr = find_frame_addr_in_frame_chain (b->watchpoint_frame); |
| 1131 | within_current_scope = (fr != NULL); |
| 1132 | if (within_current_scope) |
| 1133 | /* If we end up stopping, the current frame will get selected |
| 1134 | in normal_stop. So this call to select_frame won't affect |
| 1135 | the user. */ |
| 1136 | select_frame (fr, -1); |
| 1137 | } |
| 1138 | |
| 1139 | if (within_current_scope) |
| 1140 | { |
| 1141 | /* We use value_{,free_to_}mark because it could be a |
| 1142 | *long* time before we return to the command level and |
| 1143 | call free_all_values. We can't call free_all_values because |
| 1144 | we might be in the middle of evaluating a function call. */ |
| 1145 | |
| 1146 | value_ptr mark = value_mark (); |
| 1147 | value_ptr new_val = evaluate_expression (bs->breakpoint_at->exp); |
| 1148 | if (!value_equal (b->val, new_val)) |
| 1149 | { |
| 1150 | release_value (new_val); |
| 1151 | value_free_to_mark (mark); |
| 1152 | bs->old_val = b->val; |
| 1153 | b->val = new_val; |
| 1154 | /* We will stop here */ |
| 1155 | return WP_VALUE_CHANGED; |
| 1156 | } |
| 1157 | else |
| 1158 | { |
| 1159 | /* Nothing changed, don't do anything. */ |
| 1160 | value_free_to_mark (mark); |
| 1161 | /* We won't stop here */ |
| 1162 | return WP_VALUE_NOT_CHANGED; |
| 1163 | } |
| 1164 | } |
| 1165 | else |
| 1166 | { |
| 1167 | /* This seems like the only logical thing to do because |
| 1168 | if we temporarily ignored the watchpoint, then when |
| 1169 | we reenter the block in which it is valid it contains |
| 1170 | garbage (in the case of a function, it may have two |
| 1171 | garbage values, one before and one after the prologue). |
| 1172 | So we can't even detect the first assignment to it and |
| 1173 | watch after that (since the garbage may or may not equal |
| 1174 | the first value assigned). */ |
| 1175 | printf_filtered ("\ |
| 1176 | Watchpoint %d deleted because the program has left the block in\n\ |
| 1177 | which its expression is valid.\n", bs->breakpoint_at->number); |
| 1178 | if (b->related_breakpoint) |
| 1179 | delete_breakpoint (b->related_breakpoint); |
| 1180 | delete_breakpoint (b); |
| 1181 | |
| 1182 | return WP_DELETED; |
| 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | /* This is used when everything which needs to be printed has |
| 1187 | already been printed. But we still want to print the frame. */ |
| 1188 | static int |
| 1189 | print_it_done (bs) |
| 1190 | bpstat bs; |
| 1191 | { |
| 1192 | return 0; |
| 1193 | } |
| 1194 | |
| 1195 | /* This is used when nothing should be printed for this bpstat entry. */ |
| 1196 | |
| 1197 | static int |
| 1198 | print_it_noop (bs) |
| 1199 | bpstat bs; |
| 1200 | { |
| 1201 | return -1; |
| 1202 | } |
| 1203 | |
| 1204 | /* Get a bpstat associated with having just stopped at address *PC |
| 1205 | and frame address CORE_ADDRESS. Update *PC to point at the |
| 1206 | breakpoint (if we hit a breakpoint). NOT_A_BREAKPOINT is nonzero |
| 1207 | if this is known to not be a real breakpoint (it could still be a |
| 1208 | watchpoint, though). */ |
| 1209 | |
| 1210 | /* Determine whether we stopped at a breakpoint, etc, or whether we |
| 1211 | don't understand this stop. Result is a chain of bpstat's such that: |
| 1212 | |
| 1213 | if we don't understand the stop, the result is a null pointer. |
| 1214 | |
| 1215 | if we understand why we stopped, the result is not null. |
| 1216 | |
| 1217 | Each element of the chain refers to a particular breakpoint or |
| 1218 | watchpoint at which we have stopped. (We may have stopped for |
| 1219 | several reasons concurrently.) |
| 1220 | |
| 1221 | Each element of the chain has valid next, breakpoint_at, |
| 1222 | commands, FIXME??? fields. |
| 1223 | |
| 1224 | */ |
| 1225 | |
| 1226 | bpstat |
| 1227 | bpstat_stop_status (pc, not_a_breakpoint) |
| 1228 | CORE_ADDR *pc; |
| 1229 | int not_a_breakpoint; |
| 1230 | { |
| 1231 | register struct breakpoint *b; |
| 1232 | CORE_ADDR bp_addr; |
| 1233 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
| 1234 | /* True if we've hit a breakpoint (as opposed to a watchpoint). */ |
| 1235 | int real_breakpoint = 0; |
| 1236 | #endif |
| 1237 | /* Root of the chain of bpstat's */ |
| 1238 | struct bpstats root_bs[1]; |
| 1239 | /* Pointer to the last thing in the chain currently. */ |
| 1240 | bpstat bs = root_bs; |
| 1241 | static char message1[] = |
| 1242 | "Error evaluating expression for watchpoint %d\n"; |
| 1243 | char message[sizeof (message1) + 30 /* slop */]; |
| 1244 | |
| 1245 | /* Get the address where the breakpoint would have been. */ |
| 1246 | bp_addr = *pc - DECR_PC_AFTER_BREAK; |
| 1247 | |
| 1248 | ALL_BREAKPOINTS (b) |
| 1249 | { |
| 1250 | if (b->enable == disabled) |
| 1251 | continue; |
| 1252 | |
| 1253 | if (b->type != bp_watchpoint |
| 1254 | && b->type != bp_hardware_watchpoint |
| 1255 | && b->type != bp_read_watchpoint |
| 1256 | && b->type != bp_access_watchpoint |
| 1257 | && b->type != bp_hardware_breakpoint |
| 1258 | && b->address != bp_addr) |
| 1259 | continue; |
| 1260 | |
| 1261 | /* If defined, then we need to decr pc by this much after a hardware break- |
| 1262 | point. Presumably should override DECR_PC_AFTER_BREAK, though it doesn't |
| 1263 | now... */ |
| 1264 | |
| 1265 | #ifndef DECR_PC_AFTER_HW_BREAK |
| 1266 | #define DECR_PC_AFTER_HW_BREAK 0 |
| 1267 | #endif |
| 1268 | |
| 1269 | if (b->type == bp_hardware_breakpoint |
| 1270 | && b->address != (bp_addr - DECR_PC_AFTER_HW_BREAK)) |
| 1271 | continue; |
| 1272 | |
| 1273 | if (b->type != bp_watchpoint |
| 1274 | && b->type != bp_hardware_watchpoint |
| 1275 | && b->type != bp_read_watchpoint |
| 1276 | && b->type != bp_access_watchpoint |
| 1277 | && not_a_breakpoint) |
| 1278 | continue; |
| 1279 | |
| 1280 | /* Come here if it's a watchpoint, or if the break address matches */ |
| 1281 | |
| 1282 | ++(b->hit_count); |
| 1283 | |
| 1284 | bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ |
| 1285 | |
| 1286 | bs->stop = 1; |
| 1287 | bs->print = 1; |
| 1288 | |
| 1289 | sprintf (message, message1, b->number); |
| 1290 | if (b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) |
| 1291 | { |
| 1292 | switch (catch_errors (watchpoint_check, (char *) bs, message, |
| 1293 | RETURN_MASK_ALL)) |
| 1294 | { |
| 1295 | case WP_DELETED: |
| 1296 | /* We've already printed what needs to be printed. */ |
| 1297 | bs->print_it = print_it_done; |
| 1298 | /* Stop. */ |
| 1299 | break; |
| 1300 | case WP_VALUE_CHANGED: |
| 1301 | /* Stop. */ |
| 1302 | break; |
| 1303 | case WP_VALUE_NOT_CHANGED: |
| 1304 | /* Don't stop. */ |
| 1305 | bs->print_it = print_it_noop; |
| 1306 | bs->stop = 0; |
| 1307 | continue; |
| 1308 | default: |
| 1309 | /* Can't happen. */ |
| 1310 | /* FALLTHROUGH */ |
| 1311 | case 0: |
| 1312 | /* Error from catch_errors. */ |
| 1313 | printf_filtered ("Watchpoint %d deleted.\n", b->number); |
| 1314 | if (b->related_breakpoint) |
| 1315 | delete_breakpoint (b->related_breakpoint); |
| 1316 | delete_breakpoint (b); |
| 1317 | /* We've already printed what needs to be printed. */ |
| 1318 | bs->print_it = print_it_done; |
| 1319 | |
| 1320 | /* Stop. */ |
| 1321 | break; |
| 1322 | } |
| 1323 | } |
| 1324 | else if (b->type == bp_read_watchpoint || b->type == bp_access_watchpoint) |
| 1325 | { |
| 1326 | CORE_ADDR addr; |
| 1327 | value_ptr v; |
| 1328 | int found = 0; |
| 1329 | |
| 1330 | addr = target_stopped_data_address(); |
| 1331 | if (addr == 0) continue; |
| 1332 | for (v = b->val_chain; v; v = v->next) |
| 1333 | { |
| 1334 | if (v->lval == lval_memory) |
| 1335 | { |
| 1336 | CORE_ADDR vaddr; |
| 1337 | |
| 1338 | vaddr = VALUE_ADDRESS (v) + VALUE_OFFSET (v); |
| 1339 | if (addr == vaddr) |
| 1340 | found = 1; |
| 1341 | } |
| 1342 | } |
| 1343 | if (found) |
| 1344 | switch (catch_errors (watchpoint_check, (char *) bs, message, |
| 1345 | RETURN_MASK_ALL)) |
| 1346 | { |
| 1347 | case WP_DELETED: |
| 1348 | /* We've already printed what needs to be printed. */ |
| 1349 | bs->print_it = print_it_done; |
| 1350 | /* Stop. */ |
| 1351 | break; |
| 1352 | case WP_VALUE_CHANGED: |
| 1353 | case WP_VALUE_NOT_CHANGED: |
| 1354 | /* Stop. */ |
| 1355 | break; |
| 1356 | default: |
| 1357 | /* Can't happen. */ |
| 1358 | case 0: |
| 1359 | /* Error from catch_errors. */ |
| 1360 | printf_filtered ("Watchpoint %d deleted.\n", b->number); |
| 1361 | if (b->related_breakpoint) |
| 1362 | delete_breakpoint (b->related_breakpoint); |
| 1363 | delete_breakpoint (b); |
| 1364 | /* We've already printed what needs to be printed. */ |
| 1365 | bs->print_it = print_it_done; |
| 1366 | break; |
| 1367 | } |
| 1368 | } |
| 1369 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
| 1370 | else |
| 1371 | real_breakpoint = 1; |
| 1372 | #endif |
| 1373 | |
| 1374 | if (b->frame && b->frame != (get_current_frame ())->frame) |
| 1375 | bs->stop = 0; |
| 1376 | else |
| 1377 | { |
| 1378 | int value_is_zero = 0; |
| 1379 | |
| 1380 | if (b->cond) |
| 1381 | { |
| 1382 | /* Need to select the frame, with all that implies |
| 1383 | so that the conditions will have the right context. */ |
| 1384 | select_frame (get_current_frame (), 0); |
| 1385 | value_is_zero |
| 1386 | = catch_errors (breakpoint_cond_eval, (char *)(b->cond), |
| 1387 | "Error in testing breakpoint condition:\n", |
| 1388 | RETURN_MASK_ALL); |
| 1389 | /* FIXME-someday, should give breakpoint # */ |
| 1390 | free_all_values (); |
| 1391 | } |
| 1392 | if (b->cond && value_is_zero) |
| 1393 | { |
| 1394 | bs->stop = 0; |
| 1395 | } |
| 1396 | else if (b->ignore_count > 0) |
| 1397 | { |
| 1398 | b->ignore_count--; |
| 1399 | bs->stop = 0; |
| 1400 | } |
| 1401 | else |
| 1402 | { |
| 1403 | /* We will stop here */ |
| 1404 | if (b->disposition == disable) |
| 1405 | b->enable = disabled; |
| 1406 | bs->commands = b->commands; |
| 1407 | if (b->silent) |
| 1408 | bs->print = 0; |
| 1409 | if (bs->commands && STREQ ("silent", bs->commands->line)) |
| 1410 | { |
| 1411 | bs->commands = bs->commands->next; |
| 1412 | bs->print = 0; |
| 1413 | } |
| 1414 | } |
| 1415 | } |
| 1416 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
| 1417 | if (bs->stop == 0 || bs->print == 0) |
| 1418 | bs->print_it = print_it_noop; |
| 1419 | } |
| 1420 | |
| 1421 | bs->next = NULL; /* Terminate the chain */ |
| 1422 | bs = root_bs->next; /* Re-grab the head of the chain */ |
| 1423 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
| 1424 | if (bs) |
| 1425 | { |
| 1426 | if (real_breakpoint) |
| 1427 | { |
| 1428 | *pc = bp_addr; |
| 1429 | #if defined (SHIFT_INST_REGS) |
| 1430 | SHIFT_INST_REGS(); |
| 1431 | #else /* No SHIFT_INST_REGS. */ |
| 1432 | write_pc (bp_addr); |
| 1433 | #endif /* No SHIFT_INST_REGS. */ |
| 1434 | } |
| 1435 | } |
| 1436 | #endif /* DECR_PC_AFTER_BREAK != 0. */ |
| 1437 | |
| 1438 | /* The value of a hardware watchpoint hasn't changed, but the |
| 1439 | intermediate memory locations we are watching may have. */ |
| 1440 | if (bs && ! bs->stop && |
| 1441 | (bs->breakpoint_at->type == bp_hardware_watchpoint || |
| 1442 | bs->breakpoint_at->type == bp_read_watchpoint || |
| 1443 | bs->breakpoint_at->type == bp_access_watchpoint)) |
| 1444 | { |
| 1445 | remove_breakpoints (); |
| 1446 | insert_breakpoints (); |
| 1447 | } |
| 1448 | return bs; |
| 1449 | } |
| 1450 | \f |
| 1451 | /* Tell what to do about this bpstat. */ |
| 1452 | struct bpstat_what |
| 1453 | bpstat_what (bs) |
| 1454 | bpstat bs; |
| 1455 | { |
| 1456 | /* Classify each bpstat as one of the following. */ |
| 1457 | enum class { |
| 1458 | /* This bpstat element has no effect on the main_action. */ |
| 1459 | no_effect = 0, |
| 1460 | |
| 1461 | /* There was a watchpoint, stop but don't print. */ |
| 1462 | wp_silent, |
| 1463 | |
| 1464 | /* There was a watchpoint, stop and print. */ |
| 1465 | wp_noisy, |
| 1466 | |
| 1467 | /* There was a breakpoint but we're not stopping. */ |
| 1468 | bp_nostop, |
| 1469 | |
| 1470 | /* There was a breakpoint, stop but don't print. */ |
| 1471 | bp_silent, |
| 1472 | |
| 1473 | /* There was a breakpoint, stop and print. */ |
| 1474 | bp_noisy, |
| 1475 | |
| 1476 | /* We hit the longjmp breakpoint. */ |
| 1477 | long_jump, |
| 1478 | |
| 1479 | /* We hit the longjmp_resume breakpoint. */ |
| 1480 | long_resume, |
| 1481 | |
| 1482 | /* We hit the step_resume breakpoint. */ |
| 1483 | step_resume, |
| 1484 | |
| 1485 | /* We hit the through_sigtramp breakpoint. */ |
| 1486 | through_sig, |
| 1487 | |
| 1488 | /* This is just used to count how many enums there are. */ |
| 1489 | class_last |
| 1490 | }; |
| 1491 | |
| 1492 | /* Here is the table which drives this routine. So that we can |
| 1493 | format it pretty, we define some abbreviations for the |
| 1494 | enum bpstat_what codes. */ |
| 1495 | #define keep_c BPSTAT_WHAT_KEEP_CHECKING |
| 1496 | #define stop_s BPSTAT_WHAT_STOP_SILENT |
| 1497 | #define stop_n BPSTAT_WHAT_STOP_NOISY |
| 1498 | #define single BPSTAT_WHAT_SINGLE |
| 1499 | #define setlr BPSTAT_WHAT_SET_LONGJMP_RESUME |
| 1500 | #define clrlr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME |
| 1501 | #define clrlrs BPSTAT_WHAT_CLEAR_LONGJMP_RESUME_SINGLE |
| 1502 | #define sr BPSTAT_WHAT_STEP_RESUME |
| 1503 | #define ts BPSTAT_WHAT_THROUGH_SIGTRAMP |
| 1504 | |
| 1505 | /* "Can't happen." Might want to print an error message. |
| 1506 | abort() is not out of the question, but chances are GDB is just |
| 1507 | a bit confused, not unusable. */ |
| 1508 | #define err BPSTAT_WHAT_STOP_NOISY |
| 1509 | |
| 1510 | /* Given an old action and a class, come up with a new action. */ |
| 1511 | /* One interesting property of this table is that wp_silent is the same |
| 1512 | as bp_silent and wp_noisy is the same as bp_noisy. That is because |
| 1513 | after stopping, the check for whether to step over a breakpoint |
| 1514 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without |
| 1515 | reference to how we stopped. We retain separate wp_silent and bp_silent |
| 1516 | codes in case we want to change that someday. */ |
| 1517 | |
| 1518 | /* step_resume entries: a step resume breakpoint overrides another |
| 1519 | breakpoint of signal handling (see comment in wait_for_inferior |
| 1520 | at first IN_SIGTRAMP where we set the step_resume breakpoint). */ |
| 1521 | /* We handle the through_sigtramp_breakpoint the same way; having both |
| 1522 | one of those and a step_resume_breakpoint is probably very rare (?). */ |
| 1523 | |
| 1524 | static const enum bpstat_what_main_action |
| 1525 | table[(int)class_last][(int)BPSTAT_WHAT_LAST] = |
| 1526 | { |
| 1527 | /* old action */ |
| 1528 | /* keep_c stop_s stop_n single setlr clrlr clrlrs sr ts |
| 1529 | */ |
| 1530 | /*no_effect*/ {keep_c,stop_s,stop_n,single, setlr , clrlr , clrlrs, sr, ts}, |
| 1531 | /*wp_silent*/ {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts}, |
| 1532 | /*wp_noisy*/ {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts}, |
| 1533 | /*bp_nostop*/ {single,stop_s,stop_n,single, setlr , clrlrs, clrlrs, sr, ts}, |
| 1534 | /*bp_silent*/ {stop_s,stop_s,stop_n,stop_s, stop_s, stop_s, stop_s, sr, ts}, |
| 1535 | /*bp_noisy*/ {stop_n,stop_n,stop_n,stop_n, stop_n, stop_n, stop_n, sr, ts}, |
| 1536 | /*long_jump*/ {setlr ,stop_s,stop_n,setlr , err , err , err , sr, ts}, |
| 1537 | /*long_resume*/ {clrlr ,stop_s,stop_n,clrlrs, err , err , err , sr, ts}, |
| 1538 | /*step_resume*/ {sr ,sr ,sr ,sr , sr , sr , sr , sr, ts}, |
| 1539 | /*through_sig*/ {ts ,ts ,ts ,ts , ts , ts , ts , ts, ts} |
| 1540 | }; |
| 1541 | #undef keep_c |
| 1542 | #undef stop_s |
| 1543 | #undef stop_n |
| 1544 | #undef single |
| 1545 | #undef setlr |
| 1546 | #undef clrlr |
| 1547 | #undef clrlrs |
| 1548 | #undef err |
| 1549 | #undef sr |
| 1550 | #undef ts |
| 1551 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
| 1552 | struct bpstat_what retval; |
| 1553 | |
| 1554 | retval.call_dummy = 0; |
| 1555 | for (; bs != NULL; bs = bs->next) |
| 1556 | { |
| 1557 | enum class bs_class = no_effect; |
| 1558 | if (bs->breakpoint_at == NULL) |
| 1559 | /* I suspect this can happen if it was a momentary breakpoint |
| 1560 | which has since been deleted. */ |
| 1561 | continue; |
| 1562 | switch (bs->breakpoint_at->type) |
| 1563 | { |
| 1564 | case bp_breakpoint: |
| 1565 | case bp_hardware_breakpoint: |
| 1566 | case bp_until: |
| 1567 | case bp_finish: |
| 1568 | if (bs->stop) |
| 1569 | { |
| 1570 | if (bs->print) |
| 1571 | bs_class = bp_noisy; |
| 1572 | else |
| 1573 | bs_class = bp_silent; |
| 1574 | } |
| 1575 | else |
| 1576 | bs_class = bp_nostop; |
| 1577 | break; |
| 1578 | case bp_watchpoint: |
| 1579 | case bp_hardware_watchpoint: |
| 1580 | case bp_read_watchpoint: |
| 1581 | case bp_access_watchpoint: |
| 1582 | if (bs->stop) |
| 1583 | { |
| 1584 | if (bs->print) |
| 1585 | bs_class = wp_noisy; |
| 1586 | else |
| 1587 | bs_class = wp_silent; |
| 1588 | } |
| 1589 | else |
| 1590 | /* There was a watchpoint, but we're not stopping. This requires |
| 1591 | no further action. */ |
| 1592 | bs_class = no_effect; |
| 1593 | break; |
| 1594 | case bp_longjmp: |
| 1595 | bs_class = long_jump; |
| 1596 | break; |
| 1597 | case bp_longjmp_resume: |
| 1598 | bs_class = long_resume; |
| 1599 | break; |
| 1600 | case bp_step_resume: |
| 1601 | if (bs->stop) |
| 1602 | { |
| 1603 | bs_class = step_resume; |
| 1604 | } |
| 1605 | else |
| 1606 | /* It is for the wrong frame. */ |
| 1607 | bs_class = bp_nostop; |
| 1608 | break; |
| 1609 | case bp_through_sigtramp: |
| 1610 | bs_class = through_sig; |
| 1611 | break; |
| 1612 | case bp_watchpoint_scope: |
| 1613 | bs_class = bp_nostop; |
| 1614 | break; |
| 1615 | |
| 1616 | case bp_call_dummy: |
| 1617 | /* Make sure the action is stop (silent or noisy), so infrun.c |
| 1618 | pops the dummy frame. */ |
| 1619 | bs_class = bp_silent; |
| 1620 | retval.call_dummy = 1; |
| 1621 | break; |
| 1622 | } |
| 1623 | current_action = table[(int)bs_class][(int)current_action]; |
| 1624 | } |
| 1625 | retval.main_action = current_action; |
| 1626 | return retval; |
| 1627 | } |
| 1628 | |
| 1629 | /* Nonzero if we should step constantly (e.g. watchpoints on machines |
| 1630 | without hardware support). This isn't related to a specific bpstat, |
| 1631 | just to things like whether watchpoints are set. */ |
| 1632 | |
| 1633 | int |
| 1634 | bpstat_should_step () |
| 1635 | { |
| 1636 | struct breakpoint *b; |
| 1637 | ALL_BREAKPOINTS (b) |
| 1638 | if (b->enable == enabled && b->type == bp_watchpoint) |
| 1639 | return 1; |
| 1640 | return 0; |
| 1641 | } |
| 1642 | \f |
| 1643 | /* Print information on breakpoint number BNUM, or -1 if all. |
| 1644 | If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS |
| 1645 | is nonzero, process only watchpoints. */ |
| 1646 | |
| 1647 | static void |
| 1648 | breakpoint_1 (bnum, allflag) |
| 1649 | int bnum; |
| 1650 | int allflag; |
| 1651 | { |
| 1652 | register struct breakpoint *b; |
| 1653 | register struct command_line *l; |
| 1654 | register struct symbol *sym; |
| 1655 | CORE_ADDR last_addr = (CORE_ADDR)-1; |
| 1656 | int found_a_breakpoint = 0; |
| 1657 | static char *bptypes[] = {"breakpoint", "hw breakpoint", |
| 1658 | "until", "finish", "watchpoint", |
| 1659 | "hw watchpoint", "read watchpoint", |
| 1660 | "acc watchpoint", "longjmp", |
| 1661 | "longjmp resume", "step resume", |
| 1662 | "watchpoint scope", "call dummy" }; |
| 1663 | static char *bpdisps[] = {"del", "dis", "keep"}; |
| 1664 | static char bpenables[] = "ny"; |
| 1665 | char wrap_indent[80]; |
| 1666 | |
| 1667 | ALL_BREAKPOINTS (b) |
| 1668 | if (bnum == -1 |
| 1669 | || bnum == b->number) |
| 1670 | { |
| 1671 | /* We only print out user settable breakpoints unless the allflag is set. */ |
| 1672 | if (!allflag |
| 1673 | && b->type != bp_breakpoint |
| 1674 | && b->type != bp_hardware_breakpoint |
| 1675 | && b->type != bp_watchpoint |
| 1676 | && b->type != bp_read_watchpoint |
| 1677 | && b->type != bp_access_watchpoint |
| 1678 | && b->type != bp_hardware_watchpoint) |
| 1679 | continue; |
| 1680 | |
| 1681 | if (!found_a_breakpoint++) |
| 1682 | { |
| 1683 | annotate_breakpoints_headers (); |
| 1684 | |
| 1685 | annotate_field (0); |
| 1686 | printf_filtered ("Num "); |
| 1687 | annotate_field (1); |
| 1688 | printf_filtered ("Type "); |
| 1689 | annotate_field (2); |
| 1690 | printf_filtered ("Disp "); |
| 1691 | annotate_field (3); |
| 1692 | printf_filtered ("Enb "); |
| 1693 | if (addressprint) |
| 1694 | { |
| 1695 | annotate_field (4); |
| 1696 | printf_filtered ("Address "); |
| 1697 | } |
| 1698 | annotate_field (5); |
| 1699 | printf_filtered ("What\n"); |
| 1700 | |
| 1701 | annotate_breakpoints_table (); |
| 1702 | } |
| 1703 | |
| 1704 | annotate_record (); |
| 1705 | annotate_field (0); |
| 1706 | printf_filtered ("%-3d ", b->number); |
| 1707 | annotate_field (1); |
| 1708 | printf_filtered ("%-14s ", bptypes[(int)b->type]); |
| 1709 | annotate_field (2); |
| 1710 | printf_filtered ("%-4s ", bpdisps[(int)b->disposition]); |
| 1711 | annotate_field (3); |
| 1712 | printf_filtered ("%-3c ", bpenables[(int)b->enable]); |
| 1713 | |
| 1714 | strcpy (wrap_indent, " "); |
| 1715 | if (addressprint) |
| 1716 | strcat (wrap_indent, " "); |
| 1717 | switch (b->type) |
| 1718 | { |
| 1719 | case bp_watchpoint: |
| 1720 | case bp_hardware_watchpoint: |
| 1721 | case bp_read_watchpoint: |
| 1722 | case bp_access_watchpoint: |
| 1723 | /* Field 4, the address, is omitted (which makes the columns |
| 1724 | not line up too nicely with the headers, but the effect |
| 1725 | is relatively readable). */ |
| 1726 | annotate_field (5); |
| 1727 | print_expression (b->exp, gdb_stdout); |
| 1728 | break; |
| 1729 | |
| 1730 | case bp_breakpoint: |
| 1731 | case bp_hardware_breakpoint: |
| 1732 | case bp_until: |
| 1733 | case bp_finish: |
| 1734 | case bp_longjmp: |
| 1735 | case bp_longjmp_resume: |
| 1736 | case bp_step_resume: |
| 1737 | case bp_through_sigtramp: |
| 1738 | case bp_watchpoint_scope: |
| 1739 | case bp_call_dummy: |
| 1740 | if (addressprint) |
| 1741 | { |
| 1742 | annotate_field (4); |
| 1743 | /* FIXME-32x64: need a print_address_numeric with |
| 1744 | field width */ |
| 1745 | printf_filtered |
| 1746 | ("%s ", |
| 1747 | local_hex_string_custom |
| 1748 | ((unsigned long) b->address, "08l")); |
| 1749 | } |
| 1750 | |
| 1751 | annotate_field (5); |
| 1752 | |
| 1753 | last_addr = b->address; |
| 1754 | if (b->source_file) |
| 1755 | { |
| 1756 | sym = find_pc_function (b->address); |
| 1757 | if (sym) |
| 1758 | { |
| 1759 | fputs_filtered ("in ", gdb_stdout); |
| 1760 | fputs_filtered (SYMBOL_SOURCE_NAME (sym), gdb_stdout); |
| 1761 | wrap_here (wrap_indent); |
| 1762 | fputs_filtered (" at ", gdb_stdout); |
| 1763 | } |
| 1764 | fputs_filtered (b->source_file, gdb_stdout); |
| 1765 | printf_filtered (":%d", b->line_number); |
| 1766 | } |
| 1767 | else |
| 1768 | print_address_symbolic (b->address, gdb_stdout, demangle, " "); |
| 1769 | break; |
| 1770 | } |
| 1771 | |
| 1772 | printf_filtered ("\n"); |
| 1773 | |
| 1774 | if (b->frame) |
| 1775 | { |
| 1776 | annotate_field (6); |
| 1777 | |
| 1778 | printf_filtered ("\tstop only in stack frame at "); |
| 1779 | print_address_numeric (b->frame, 1, gdb_stdout); |
| 1780 | printf_filtered ("\n"); |
| 1781 | } |
| 1782 | |
| 1783 | if (b->cond) |
| 1784 | { |
| 1785 | annotate_field (7); |
| 1786 | |
| 1787 | printf_filtered ("\tstop only if "); |
| 1788 | print_expression (b->cond, gdb_stdout); |
| 1789 | printf_filtered ("\n"); |
| 1790 | } |
| 1791 | |
| 1792 | if (show_breakpoint_hit_counts && b->hit_count) |
| 1793 | { |
| 1794 | /* FIXME should make an annotation for this */ |
| 1795 | |
| 1796 | printf_filtered ("\tbreakpoint already hit %d time%s\n", |
| 1797 | b->hit_count, (b->hit_count == 1 ? "" : "s")); |
| 1798 | } |
| 1799 | |
| 1800 | if (b->ignore_count) |
| 1801 | { |
| 1802 | annotate_field (8); |
| 1803 | |
| 1804 | printf_filtered ("\tignore next %d hits\n", b->ignore_count); |
| 1805 | } |
| 1806 | |
| 1807 | if ((l = b->commands)) |
| 1808 | { |
| 1809 | annotate_field (9); |
| 1810 | |
| 1811 | while (l) |
| 1812 | { |
| 1813 | print_command_line (l, 4); |
| 1814 | l = l->next; |
| 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | if (!found_a_breakpoint) |
| 1820 | { |
| 1821 | if (bnum == -1) |
| 1822 | printf_filtered ("No breakpoints or watchpoints.\n"); |
| 1823 | else |
| 1824 | printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum); |
| 1825 | } |
| 1826 | else |
| 1827 | /* Compare against (CORE_ADDR)-1 in case some compiler decides |
| 1828 | that a comparison of an unsigned with -1 is always false. */ |
| 1829 | if (last_addr != (CORE_ADDR)-1) |
| 1830 | set_next_address (last_addr); |
| 1831 | |
| 1832 | annotate_breakpoints_table_end (); |
| 1833 | } |
| 1834 | |
| 1835 | /* ARGSUSED */ |
| 1836 | static void |
| 1837 | breakpoints_info (bnum_exp, from_tty) |
| 1838 | char *bnum_exp; |
| 1839 | int from_tty; |
| 1840 | { |
| 1841 | int bnum = -1; |
| 1842 | |
| 1843 | if (bnum_exp) |
| 1844 | bnum = parse_and_eval_address (bnum_exp); |
| 1845 | |
| 1846 | breakpoint_1 (bnum, 0); |
| 1847 | } |
| 1848 | |
| 1849 | #if MAINTENANCE_CMDS |
| 1850 | |
| 1851 | /* ARGSUSED */ |
| 1852 | static void |
| 1853 | maintenance_info_breakpoints (bnum_exp, from_tty) |
| 1854 | char *bnum_exp; |
| 1855 | int from_tty; |
| 1856 | { |
| 1857 | int bnum = -1; |
| 1858 | |
| 1859 | if (bnum_exp) |
| 1860 | bnum = parse_and_eval_address (bnum_exp); |
| 1861 | |
| 1862 | breakpoint_1 (bnum, 1); |
| 1863 | } |
| 1864 | |
| 1865 | #endif |
| 1866 | |
| 1867 | /* Print a message describing any breakpoints set at PC. */ |
| 1868 | |
| 1869 | static void |
| 1870 | describe_other_breakpoints (pc) |
| 1871 | register CORE_ADDR pc; |
| 1872 | { |
| 1873 | register int others = 0; |
| 1874 | register struct breakpoint *b; |
| 1875 | |
| 1876 | ALL_BREAKPOINTS (b) |
| 1877 | if (b->address == pc) |
| 1878 | others++; |
| 1879 | if (others > 0) |
| 1880 | { |
| 1881 | printf_filtered ("Note: breakpoint%s ", (others > 1) ? "s" : ""); |
| 1882 | ALL_BREAKPOINTS (b) |
| 1883 | if (b->address == pc) |
| 1884 | { |
| 1885 | others--; |
| 1886 | printf_filtered |
| 1887 | ("%d%s%s ", |
| 1888 | b->number, |
| 1889 | (b->enable == disabled) ? " (disabled)" : "", |
| 1890 | (others > 1) ? "," : ((others == 1) ? " and" : "")); |
| 1891 | } |
| 1892 | printf_filtered ("also set at pc "); |
| 1893 | print_address_numeric (pc, 1, gdb_stdout); |
| 1894 | printf_filtered (".\n"); |
| 1895 | } |
| 1896 | } |
| 1897 | \f |
| 1898 | /* Set the default place to put a breakpoint |
| 1899 | for the `break' command with no arguments. */ |
| 1900 | |
| 1901 | void |
| 1902 | set_default_breakpoint (valid, addr, symtab, line) |
| 1903 | int valid; |
| 1904 | CORE_ADDR addr; |
| 1905 | struct symtab *symtab; |
| 1906 | int line; |
| 1907 | { |
| 1908 | default_breakpoint_valid = valid; |
| 1909 | default_breakpoint_address = addr; |
| 1910 | default_breakpoint_symtab = symtab; |
| 1911 | default_breakpoint_line = line; |
| 1912 | } |
| 1913 | |
| 1914 | /* Rescan breakpoints at address ADDRESS, |
| 1915 | marking the first one as "first" and any others as "duplicates". |
| 1916 | This is so that the bpt instruction is only inserted once. */ |
| 1917 | |
| 1918 | static void |
| 1919 | check_duplicates (address) |
| 1920 | CORE_ADDR address; |
| 1921 | { |
| 1922 | register struct breakpoint *b; |
| 1923 | register int count = 0; |
| 1924 | |
| 1925 | if (address == 0) /* Watchpoints are uninteresting */ |
| 1926 | return; |
| 1927 | |
| 1928 | ALL_BREAKPOINTS (b) |
| 1929 | if (b->enable != disabled && b->address == address) |
| 1930 | { |
| 1931 | count++; |
| 1932 | b->duplicate = count > 1; |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | /* Low level routine to set a breakpoint. |
| 1937 | Takes as args the three things that every breakpoint must have. |
| 1938 | Returns the breakpoint object so caller can set other things. |
| 1939 | Does not set the breakpoint number! |
| 1940 | Does not print anything. |
| 1941 | |
| 1942 | ==> This routine should not be called if there is a chance of later |
| 1943 | error(); otherwise it leaves a bogus breakpoint on the chain. Validate |
| 1944 | your arguments BEFORE calling this routine! */ |
| 1945 | |
| 1946 | static struct breakpoint * |
| 1947 | set_raw_breakpoint (sal) |
| 1948 | struct symtab_and_line sal; |
| 1949 | { |
| 1950 | register struct breakpoint *b, *b1; |
| 1951 | |
| 1952 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); |
| 1953 | memset (b, 0, sizeof (*b)); |
| 1954 | b->address = sal.pc; |
| 1955 | if (sal.symtab == NULL) |
| 1956 | b->source_file = NULL; |
| 1957 | else |
| 1958 | b->source_file = savestring (sal.symtab->filename, |
| 1959 | strlen (sal.symtab->filename)); |
| 1960 | b->language = current_language->la_language; |
| 1961 | b->input_radix = input_radix; |
| 1962 | b->thread = -1; |
| 1963 | b->line_number = sal.line; |
| 1964 | b->enable = enabled; |
| 1965 | b->next = 0; |
| 1966 | b->silent = 0; |
| 1967 | b->ignore_count = 0; |
| 1968 | b->commands = NULL; |
| 1969 | b->frame = 0; |
| 1970 | |
| 1971 | /* Add this breakpoint to the end of the chain |
| 1972 | so that a list of breakpoints will come out in order |
| 1973 | of increasing numbers. */ |
| 1974 | |
| 1975 | b1 = breakpoint_chain; |
| 1976 | if (b1 == 0) |
| 1977 | breakpoint_chain = b; |
| 1978 | else |
| 1979 | { |
| 1980 | while (b1->next) |
| 1981 | b1 = b1->next; |
| 1982 | b1->next = b; |
| 1983 | } |
| 1984 | |
| 1985 | check_duplicates (sal.pc); |
| 1986 | breakpoints_changed (); |
| 1987 | |
| 1988 | return b; |
| 1989 | } |
| 1990 | |
| 1991 | static void |
| 1992 | create_longjmp_breakpoint(func_name) |
| 1993 | char *func_name; |
| 1994 | { |
| 1995 | struct symtab_and_line sal; |
| 1996 | struct breakpoint *b; |
| 1997 | static int internal_breakpoint_number = -1; |
| 1998 | |
| 1999 | if (func_name != NULL) |
| 2000 | { |
| 2001 | struct minimal_symbol *m; |
| 2002 | |
| 2003 | m = lookup_minimal_symbol_text (func_name, NULL, (struct objfile *)NULL); |
| 2004 | if (m) |
| 2005 | sal.pc = SYMBOL_VALUE_ADDRESS (m); |
| 2006 | else |
| 2007 | return; |
| 2008 | } |
| 2009 | else |
| 2010 | sal.pc = 0; |
| 2011 | |
| 2012 | sal.symtab = NULL; |
| 2013 | sal.line = 0; |
| 2014 | |
| 2015 | b = set_raw_breakpoint(sal); |
| 2016 | if (!b) return; |
| 2017 | |
| 2018 | b->type = func_name != NULL ? bp_longjmp : bp_longjmp_resume; |
| 2019 | b->disposition = donttouch; |
| 2020 | b->enable = disabled; |
| 2021 | b->silent = 1; |
| 2022 | if (func_name) |
| 2023 | b->addr_string = strsave(func_name); |
| 2024 | b->number = internal_breakpoint_number--; |
| 2025 | } |
| 2026 | |
| 2027 | /* Call this routine when stepping and nexting to enable a breakpoint if we do |
| 2028 | a longjmp(). When we hit that breakpoint, call |
| 2029 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
| 2030 | |
| 2031 | void |
| 2032 | enable_longjmp_breakpoint() |
| 2033 | { |
| 2034 | register struct breakpoint *b; |
| 2035 | |
| 2036 | ALL_BREAKPOINTS (b) |
| 2037 | if (b->type == bp_longjmp) |
| 2038 | { |
| 2039 | b->enable = enabled; |
| 2040 | check_duplicates (b->address); |
| 2041 | } |
| 2042 | } |
| 2043 | |
| 2044 | void |
| 2045 | disable_longjmp_breakpoint() |
| 2046 | { |
| 2047 | register struct breakpoint *b; |
| 2048 | |
| 2049 | ALL_BREAKPOINTS (b) |
| 2050 | if ( b->type == bp_longjmp |
| 2051 | || b->type == bp_longjmp_resume) |
| 2052 | { |
| 2053 | b->enable = disabled; |
| 2054 | check_duplicates (b->address); |
| 2055 | } |
| 2056 | } |
| 2057 | |
| 2058 | int |
| 2059 | hw_breakpoint_used_count() |
| 2060 | { |
| 2061 | register struct breakpoint *b; |
| 2062 | int i = 0; |
| 2063 | |
| 2064 | ALL_BREAKPOINTS (b) |
| 2065 | { |
| 2066 | if (b->type == bp_hardware_breakpoint && b->enable == enabled) |
| 2067 | i++; |
| 2068 | } |
| 2069 | |
| 2070 | return i; |
| 2071 | } |
| 2072 | |
| 2073 | int |
| 2074 | hw_watchpoint_used_count(type, other_type_used) |
| 2075 | enum bptype type; |
| 2076 | int *other_type_used; |
| 2077 | { |
| 2078 | register struct breakpoint *b; |
| 2079 | int i = 0; |
| 2080 | |
| 2081 | *other_type_used = 0; |
| 2082 | ALL_BREAKPOINTS (b) |
| 2083 | { |
| 2084 | if (b->enable == enabled) |
| 2085 | { |
| 2086 | if (b->type == type) i++; |
| 2087 | else if ((b->type == bp_hardware_watchpoint || |
| 2088 | b->type == bp_read_watchpoint || |
| 2089 | b->type == bp_access_watchpoint) |
| 2090 | && b->enable == enabled) |
| 2091 | *other_type_used = 1; |
| 2092 | } |
| 2093 | } |
| 2094 | return i; |
| 2095 | } |
| 2096 | |
| 2097 | /* Call this after hitting the longjmp() breakpoint. Use this to set a new |
| 2098 | breakpoint at the target of the jmp_buf. |
| 2099 | |
| 2100 | FIXME - This ought to be done by setting a temporary breakpoint that gets |
| 2101 | deleted automatically... |
| 2102 | */ |
| 2103 | |
| 2104 | void |
| 2105 | set_longjmp_resume_breakpoint(pc, frame) |
| 2106 | CORE_ADDR pc; |
| 2107 | struct frame_info *frame; |
| 2108 | { |
| 2109 | register struct breakpoint *b; |
| 2110 | |
| 2111 | ALL_BREAKPOINTS (b) |
| 2112 | if (b->type == bp_longjmp_resume) |
| 2113 | { |
| 2114 | b->address = pc; |
| 2115 | b->enable = enabled; |
| 2116 | if (frame != NULL) |
| 2117 | b->frame = frame->frame; |
| 2118 | else |
| 2119 | b->frame = 0; |
| 2120 | check_duplicates (b->address); |
| 2121 | return; |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | /* Set a breakpoint that will evaporate an end of command |
| 2126 | at address specified by SAL. |
| 2127 | Restrict it to frame FRAME if FRAME is nonzero. */ |
| 2128 | |
| 2129 | struct breakpoint * |
| 2130 | set_momentary_breakpoint (sal, frame, type) |
| 2131 | struct symtab_and_line sal; |
| 2132 | struct frame_info *frame; |
| 2133 | enum bptype type; |
| 2134 | { |
| 2135 | register struct breakpoint *b; |
| 2136 | b = set_raw_breakpoint (sal); |
| 2137 | b->type = type; |
| 2138 | b->enable = enabled; |
| 2139 | b->disposition = donttouch; |
| 2140 | b->frame = (frame ? frame->frame : 0); |
| 2141 | return b; |
| 2142 | } |
| 2143 | |
| 2144 | #if 0 |
| 2145 | void |
| 2146 | clear_momentary_breakpoints () |
| 2147 | { |
| 2148 | register struct breakpoint *b; |
| 2149 | ALL_BREAKPOINTS (b) |
| 2150 | if (b->disposition == delete) |
| 2151 | { |
| 2152 | delete_breakpoint (b); |
| 2153 | break; |
| 2154 | } |
| 2155 | } |
| 2156 | #endif |
| 2157 | \f |
| 2158 | /* Tell the user we have just set a breakpoint B. */ |
| 2159 | |
| 2160 | static void |
| 2161 | mention (b) |
| 2162 | struct breakpoint *b; |
| 2163 | { |
| 2164 | int say_where = 0; |
| 2165 | |
| 2166 | /* FIXME: This is misplaced; mention() is called by things (like hitting a |
| 2167 | watchpoint) other than breakpoint creation. It should be possible to |
| 2168 | clean this up and at the same time replace the random calls to |
| 2169 | breakpoint_changed with this hook, as has already been done for |
| 2170 | delete_breakpoint_hook and so on. */ |
| 2171 | if (create_breakpoint_hook) |
| 2172 | create_breakpoint_hook (b); |
| 2173 | |
| 2174 | switch (b->type) |
| 2175 | { |
| 2176 | case bp_watchpoint: |
| 2177 | printf_filtered ("Watchpoint %d: ", b->number); |
| 2178 | print_expression (b->exp, gdb_stdout); |
| 2179 | break; |
| 2180 | case bp_hardware_watchpoint: |
| 2181 | printf_filtered ("Hardware watchpoint %d: ", b->number); |
| 2182 | print_expression (b->exp, gdb_stdout); |
| 2183 | break; |
| 2184 | case bp_read_watchpoint: |
| 2185 | printf_filtered ("Hardware read watchpoint %d: ", b->number); |
| 2186 | print_expression (b->exp, gdb_stdout); |
| 2187 | break; |
| 2188 | case bp_access_watchpoint: |
| 2189 | printf_filtered ("Hardware access(read/write) watchpoint %d: ",b->number); |
| 2190 | print_expression (b->exp, gdb_stdout); |
| 2191 | break; |
| 2192 | case bp_breakpoint: |
| 2193 | printf_filtered ("Breakpoint %d", b->number); |
| 2194 | say_where = 1; |
| 2195 | break; |
| 2196 | case bp_hardware_breakpoint: |
| 2197 | printf_filtered ("Hardware assisted breakpoint %d", b->number); |
| 2198 | say_where = 1; |
| 2199 | break; |
| 2200 | case bp_until: |
| 2201 | case bp_finish: |
| 2202 | case bp_longjmp: |
| 2203 | case bp_longjmp_resume: |
| 2204 | case bp_step_resume: |
| 2205 | case bp_through_sigtramp: |
| 2206 | case bp_call_dummy: |
| 2207 | case bp_watchpoint_scope: |
| 2208 | break; |
| 2209 | } |
| 2210 | if (say_where) |
| 2211 | { |
| 2212 | if (addressprint || b->source_file == NULL) |
| 2213 | { |
| 2214 | printf_filtered (" at "); |
| 2215 | print_address_numeric (b->address, 1, gdb_stdout); |
| 2216 | } |
| 2217 | if (b->source_file) |
| 2218 | printf_filtered (": file %s, line %d.", |
| 2219 | b->source_file, b->line_number); |
| 2220 | } |
| 2221 | printf_filtered ("\n"); |
| 2222 | } |
| 2223 | |
| 2224 | #if 0 |
| 2225 | /* Nobody calls this currently. */ |
| 2226 | /* Set a breakpoint from a symtab and line. |
| 2227 | If TEMPFLAG is nonzero, it is a temporary breakpoint. |
| 2228 | ADDR_STRING is a malloc'd string holding the name of where we are |
| 2229 | setting the breakpoint. This is used later to re-set it after the |
| 2230 | program is relinked and symbols are reloaded. |
| 2231 | Print the same confirmation messages that the breakpoint command prints. */ |
| 2232 | |
| 2233 | void |
| 2234 | set_breakpoint (s, line, tempflag, addr_string) |
| 2235 | struct symtab *s; |
| 2236 | int line; |
| 2237 | int tempflag; |
| 2238 | char *addr_string; |
| 2239 | { |
| 2240 | register struct breakpoint *b; |
| 2241 | struct symtab_and_line sal; |
| 2242 | |
| 2243 | sal.symtab = s; |
| 2244 | sal.line = line; |
| 2245 | sal.pc = 0; |
| 2246 | resolve_sal_pc (&sal); /* Might error out */ |
| 2247 | describe_other_breakpoints (sal.pc); |
| 2248 | |
| 2249 | b = set_raw_breakpoint (sal); |
| 2250 | set_breakpoint_count (breakpoint_count + 1); |
| 2251 | b->number = breakpoint_count; |
| 2252 | b->type = bp_breakpoint; |
| 2253 | b->cond = 0; |
| 2254 | b->addr_string = addr_string; |
| 2255 | b->enable = enabled; |
| 2256 | b->disposition = tempflag ? delete : donttouch; |
| 2257 | |
| 2258 | mention (b); |
| 2259 | } |
| 2260 | #endif /* 0 */ |
| 2261 | \f |
| 2262 | /* Set a breakpoint according to ARG (function, linenum or *address) |
| 2263 | flag: first bit : 0 non-temporary, 1 temporary. |
| 2264 | second bit : 0 normal breakpoint, 1 hardware breakpoint. */ |
| 2265 | |
| 2266 | static void |
| 2267 | break_command_1 (arg, flag, from_tty) |
| 2268 | char *arg; |
| 2269 | int flag, from_tty; |
| 2270 | { |
| 2271 | int tempflag, hardwareflag; |
| 2272 | struct symtabs_and_lines sals; |
| 2273 | struct symtab_and_line sal; |
| 2274 | register struct expression *cond = 0; |
| 2275 | register struct breakpoint *b; |
| 2276 | |
| 2277 | /* Pointers in arg to the start, and one past the end, of the condition. */ |
| 2278 | char *cond_start = NULL; |
| 2279 | char *cond_end = NULL; |
| 2280 | /* Pointers in arg to the start, and one past the end, |
| 2281 | of the address part. */ |
| 2282 | char *addr_start = NULL; |
| 2283 | char *addr_end = NULL; |
| 2284 | struct cleanup *old_chain; |
| 2285 | struct cleanup *canonical_strings_chain = NULL; |
| 2286 | char **canonical = (char **)NULL; |
| 2287 | int i; |
| 2288 | int thread; |
| 2289 | |
| 2290 | hardwareflag = flag & BP_HARDWAREFLAG; |
| 2291 | tempflag = flag & BP_TEMPFLAG; |
| 2292 | |
| 2293 | sals.sals = NULL; |
| 2294 | sals.nelts = 0; |
| 2295 | |
| 2296 | sal.line = sal.pc = sal.end = 0; |
| 2297 | sal.symtab = 0; |
| 2298 | |
| 2299 | /* If no arg given, or if first arg is 'if ', use the default breakpoint. */ |
| 2300 | |
| 2301 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' |
| 2302 | && (arg[2] == ' ' || arg[2] == '\t'))) |
| 2303 | { |
| 2304 | if (default_breakpoint_valid) |
| 2305 | { |
| 2306 | sals.sals = (struct symtab_and_line *) |
| 2307 | xmalloc (sizeof (struct symtab_and_line)); |
| 2308 | sal.pc = default_breakpoint_address; |
| 2309 | sal.line = default_breakpoint_line; |
| 2310 | sal.symtab = default_breakpoint_symtab; |
| 2311 | sals.sals[0] = sal; |
| 2312 | sals.nelts = 1; |
| 2313 | } |
| 2314 | else |
| 2315 | error ("No default breakpoint address now."); |
| 2316 | } |
| 2317 | else |
| 2318 | { |
| 2319 | addr_start = arg; |
| 2320 | |
| 2321 | /* Force almost all breakpoints to be in terms of the |
| 2322 | current_source_symtab (which is decode_line_1's default). This |
| 2323 | should produce the results we want almost all of the time while |
| 2324 | leaving default_breakpoint_* alone. */ |
| 2325 | if (default_breakpoint_valid |
| 2326 | && (!current_source_symtab |
| 2327 | || (arg && (*arg == '+' || *arg == '-')))) |
| 2328 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, |
| 2329 | default_breakpoint_line, &canonical); |
| 2330 | else |
| 2331 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, &canonical); |
| 2332 | |
| 2333 | addr_end = arg; |
| 2334 | } |
| 2335 | |
| 2336 | if (! sals.nelts) |
| 2337 | return; |
| 2338 | |
| 2339 | /* Make sure that all storage allocated in decode_line_1 gets freed in case |
| 2340 | the following `for' loop errors out. */ |
| 2341 | old_chain = make_cleanup (free, sals.sals); |
| 2342 | if (canonical != (char **)NULL) |
| 2343 | { |
| 2344 | make_cleanup (free, canonical); |
| 2345 | canonical_strings_chain = make_cleanup (null_cleanup, 0); |
| 2346 | for (i = 0; i < sals.nelts; i++) |
| 2347 | { |
| 2348 | if (canonical[i] != NULL) |
| 2349 | make_cleanup (free, canonical[i]); |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | thread = -1; /* No specific thread yet */ |
| 2354 | |
| 2355 | /* Resolve all line numbers to PC's, and verify that conditions |
| 2356 | can be parsed, before setting any breakpoints. */ |
| 2357 | for (i = 0; i < sals.nelts; i++) |
| 2358 | { |
| 2359 | char *tok, *end_tok; |
| 2360 | int toklen; |
| 2361 | |
| 2362 | resolve_sal_pc (&sals.sals[i]); |
| 2363 | |
| 2364 | tok = arg; |
| 2365 | |
| 2366 | while (tok && *tok) |
| 2367 | { |
| 2368 | while (*tok == ' ' || *tok == '\t') |
| 2369 | tok++; |
| 2370 | |
| 2371 | end_tok = tok; |
| 2372 | |
| 2373 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') |
| 2374 | end_tok++; |
| 2375 | |
| 2376 | toklen = end_tok - tok; |
| 2377 | |
| 2378 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 2379 | { |
| 2380 | tok = cond_start = end_tok + 1; |
| 2381 | cond = parse_exp_1 (&tok, block_for_pc (sals.sals[i].pc), 0); |
| 2382 | cond_end = tok; |
| 2383 | } |
| 2384 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) |
| 2385 | { |
| 2386 | char *tmptok; |
| 2387 | |
| 2388 | tok = end_tok + 1; |
| 2389 | tmptok = tok; |
| 2390 | thread = strtol (tok, &tok, 0); |
| 2391 | if (tok == tmptok) |
| 2392 | error ("Junk after thread keyword."); |
| 2393 | if (!valid_thread_id (thread)) |
| 2394 | error ("Unknown thread %d\n", thread); |
| 2395 | } |
| 2396 | else |
| 2397 | error ("Junk at end of arguments."); |
| 2398 | } |
| 2399 | } |
| 2400 | if (hardwareflag) |
| 2401 | { |
| 2402 | int i, target_resources_ok; |
| 2403 | |
| 2404 | i = hw_breakpoint_used_count (); |
| 2405 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT ( |
| 2406 | bp_hardware_breakpoint, i + sals.nelts, 0); |
| 2407 | if (target_resources_ok == 0) |
| 2408 | error ("No hardware breakpoint support in the target."); |
| 2409 | else if (target_resources_ok < 0) |
| 2410 | error ("Hardware breakpoints used exceeds limit."); |
| 2411 | } |
| 2412 | |
| 2413 | /* Remove the canonical strings from the cleanup, they are needed below. */ |
| 2414 | if (canonical != (char **)NULL) |
| 2415 | discard_cleanups (canonical_strings_chain); |
| 2416 | |
| 2417 | /* Now set all the breakpoints. */ |
| 2418 | for (i = 0; i < sals.nelts; i++) |
| 2419 | { |
| 2420 | sal = sals.sals[i]; |
| 2421 | |
| 2422 | if (from_tty) |
| 2423 | describe_other_breakpoints (sal.pc); |
| 2424 | |
| 2425 | b = set_raw_breakpoint (sal); |
| 2426 | set_breakpoint_count (breakpoint_count + 1); |
| 2427 | b->number = breakpoint_count; |
| 2428 | b->type = hardwareflag ? bp_hardware_breakpoint : bp_breakpoint; |
| 2429 | b->cond = cond; |
| 2430 | b->thread = thread; |
| 2431 | |
| 2432 | /* If a canonical line spec is needed use that instead of the |
| 2433 | command string. */ |
| 2434 | if (canonical != (char **)NULL && canonical[i] != NULL) |
| 2435 | b->addr_string = canonical[i]; |
| 2436 | else if (addr_start) |
| 2437 | b->addr_string = savestring (addr_start, addr_end - addr_start); |
| 2438 | if (cond_start) |
| 2439 | b->cond_string = savestring (cond_start, cond_end - cond_start); |
| 2440 | |
| 2441 | b->enable = enabled; |
| 2442 | b->disposition = tempflag ? del : donttouch; |
| 2443 | |
| 2444 | mention (b); |
| 2445 | } |
| 2446 | |
| 2447 | if (sals.nelts > 1) |
| 2448 | { |
| 2449 | printf_filtered ("Multiple breakpoints were set.\n"); |
| 2450 | printf_filtered ("Use the \"delete\" command to delete unwanted breakpoints.\n"); |
| 2451 | } |
| 2452 | do_cleanups (old_chain); |
| 2453 | } |
| 2454 | |
| 2455 | /* Helper function for break_command_1 and disassemble_command. */ |
| 2456 | |
| 2457 | void |
| 2458 | resolve_sal_pc (sal) |
| 2459 | struct symtab_and_line *sal; |
| 2460 | { |
| 2461 | CORE_ADDR pc; |
| 2462 | |
| 2463 | if (sal->pc == 0 && sal->symtab != 0) |
| 2464 | { |
| 2465 | pc = find_line_pc (sal->symtab, sal->line); |
| 2466 | if (pc == 0) |
| 2467 | error ("No line %d in file \"%s\".", |
| 2468 | sal->line, sal->symtab->filename); |
| 2469 | sal->pc = pc; |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | void |
| 2474 | break_command (arg, from_tty) |
| 2475 | char *arg; |
| 2476 | int from_tty; |
| 2477 | { |
| 2478 | break_command_1 (arg, 0, from_tty); |
| 2479 | } |
| 2480 | |
| 2481 | static void |
| 2482 | tbreak_command (arg, from_tty) |
| 2483 | char *arg; |
| 2484 | int from_tty; |
| 2485 | { |
| 2486 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
| 2487 | } |
| 2488 | |
| 2489 | static void |
| 2490 | hbreak_command (arg, from_tty) |
| 2491 | char *arg; |
| 2492 | int from_tty; |
| 2493 | { |
| 2494 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
| 2495 | } |
| 2496 | |
| 2497 | static void |
| 2498 | thbreak_command (arg, from_tty) |
| 2499 | char *arg; |
| 2500 | int from_tty; |
| 2501 | { |
| 2502 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
| 2503 | } |
| 2504 | |
| 2505 | /* ARGSUSED */ |
| 2506 | /* accessflag: 0: watch write, 1: watch read, 2: watch access(read or write) |
| 2507 | */ |
| 2508 | static void |
| 2509 | watch_command_1 (arg, accessflag, from_tty) |
| 2510 | char *arg; |
| 2511 | int accessflag; |
| 2512 | int from_tty; |
| 2513 | { |
| 2514 | struct breakpoint *b; |
| 2515 | struct symtab_and_line sal; |
| 2516 | struct expression *exp; |
| 2517 | struct block *exp_valid_block; |
| 2518 | struct value *val, *mark; |
| 2519 | struct frame_info *frame, *prev_frame; |
| 2520 | char *exp_start = NULL; |
| 2521 | char *exp_end = NULL; |
| 2522 | char *tok, *end_tok; |
| 2523 | int toklen; |
| 2524 | char *cond_start = NULL; |
| 2525 | char *cond_end = NULL; |
| 2526 | struct expression *cond = NULL; |
| 2527 | int i, other_type_used, target_resources_ok; |
| 2528 | enum bptype bp_type; |
| 2529 | int mem_cnt = 0; |
| 2530 | |
| 2531 | sal.pc = 0; |
| 2532 | sal.symtab = NULL; |
| 2533 | sal.line = 0; |
| 2534 | |
| 2535 | /* Parse arguments. */ |
| 2536 | innermost_block = NULL; |
| 2537 | exp_start = arg; |
| 2538 | exp = parse_exp_1 (&arg, 0, 0); |
| 2539 | exp_end = arg; |
| 2540 | exp_valid_block = innermost_block; |
| 2541 | mark = value_mark (); |
| 2542 | val = evaluate_expression (exp); |
| 2543 | release_value (val); |
| 2544 | if (VALUE_LAZY (val)) |
| 2545 | value_fetch_lazy (val); |
| 2546 | |
| 2547 | tok = arg; |
| 2548 | while (*tok == ' ' || *tok == '\t') |
| 2549 | tok++; |
| 2550 | end_tok = tok; |
| 2551 | |
| 2552 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') |
| 2553 | end_tok++; |
| 2554 | |
| 2555 | toklen = end_tok - tok; |
| 2556 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) |
| 2557 | { |
| 2558 | tok = cond_start = end_tok + 1; |
| 2559 | cond = parse_exp_1 (&tok, 0, 0); |
| 2560 | cond_end = tok; |
| 2561 | } |
| 2562 | if (*tok) |
| 2563 | error("Junk at end of command."); |
| 2564 | |
| 2565 | if (accessflag == 1) bp_type = bp_read_watchpoint; |
| 2566 | else if (accessflag == 2) bp_type = bp_access_watchpoint; |
| 2567 | else bp_type = bp_hardware_watchpoint; |
| 2568 | |
| 2569 | mem_cnt = can_use_hardware_watchpoint (val); |
| 2570 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) |
| 2571 | error ("Expression cannot be implemented with read/access watchpoint."); |
| 2572 | if (mem_cnt != 0) { |
| 2573 | i = hw_watchpoint_used_count (bp_type, &other_type_used); |
| 2574 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( |
| 2575 | bp_type, i + mem_cnt, other_type_used); |
| 2576 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
| 2577 | error ("Target does not have this type of hardware watchpoint support."); |
| 2578 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
| 2579 | error ("Target resources have been allocated for other types of watchpoints."); |
| 2580 | } |
| 2581 | |
| 2582 | /* Now set up the breakpoint. */ |
| 2583 | b = set_raw_breakpoint (sal); |
| 2584 | set_breakpoint_count (breakpoint_count + 1); |
| 2585 | b->number = breakpoint_count; |
| 2586 | b->disposition = donttouch; |
| 2587 | b->exp = exp; |
| 2588 | b->exp_valid_block = exp_valid_block; |
| 2589 | b->exp_string = savestring (exp_start, exp_end - exp_start); |
| 2590 | b->val = val; |
| 2591 | b->cond = cond; |
| 2592 | if (cond_start) |
| 2593 | b->cond_string = savestring (cond_start, cond_end - cond_start); |
| 2594 | else |
| 2595 | b->cond_string = 0; |
| 2596 | |
| 2597 | frame = block_innermost_frame (exp_valid_block); |
| 2598 | if (frame) |
| 2599 | { |
| 2600 | prev_frame = get_prev_frame (frame); |
| 2601 | b->watchpoint_frame = frame->frame; |
| 2602 | } |
| 2603 | else |
| 2604 | b->watchpoint_frame = (CORE_ADDR)0; |
| 2605 | |
| 2606 | if (mem_cnt && target_resources_ok > 0) |
| 2607 | b->type = bp_type; |
| 2608 | else |
| 2609 | b->type = bp_watchpoint; |
| 2610 | |
| 2611 | /* If the expression is "local", then set up a "watchpoint scope" |
| 2612 | breakpoint at the point where we've left the scope of the watchpoint |
| 2613 | expression. */ |
| 2614 | if (innermost_block) |
| 2615 | { |
| 2616 | struct breakpoint *scope_breakpoint; |
| 2617 | struct symtab_and_line scope_sal; |
| 2618 | |
| 2619 | if (prev_frame) |
| 2620 | { |
| 2621 | scope_sal.pc = get_frame_pc (prev_frame); |
| 2622 | scope_sal.symtab = NULL; |
| 2623 | scope_sal.line = 0; |
| 2624 | |
| 2625 | scope_breakpoint = set_raw_breakpoint (scope_sal); |
| 2626 | set_breakpoint_count (breakpoint_count + 1); |
| 2627 | scope_breakpoint->number = breakpoint_count; |
| 2628 | |
| 2629 | scope_breakpoint->type = bp_watchpoint_scope; |
| 2630 | scope_breakpoint->enable = enabled; |
| 2631 | |
| 2632 | /* Automatically delete the breakpoint when it hits. */ |
| 2633 | scope_breakpoint->disposition = del; |
| 2634 | |
| 2635 | /* Only break in the proper frame (help with recursion). */ |
| 2636 | scope_breakpoint->frame = prev_frame->frame; |
| 2637 | |
| 2638 | /* Set the address at which we will stop. */ |
| 2639 | scope_breakpoint->address = get_frame_pc (prev_frame); |
| 2640 | |
| 2641 | /* The scope breakpoint is related to the watchpoint. We |
| 2642 | will need to act on them together. */ |
| 2643 | b->related_breakpoint = scope_breakpoint; |
| 2644 | } |
| 2645 | } |
| 2646 | value_free_to_mark (mark); |
| 2647 | mention (b); |
| 2648 | } |
| 2649 | |
| 2650 | /* Return count of locations need to be watched and can be handled |
| 2651 | in hardware. If the watchpoint can not be handled |
| 2652 | in hardware return zero. */ |
| 2653 | |
| 2654 | static int |
| 2655 | can_use_hardware_watchpoint (v) |
| 2656 | struct value *v; |
| 2657 | { |
| 2658 | int found_memory_cnt = 0; |
| 2659 | |
| 2660 | /* Make sure all the intermediate values are in memory. Also make sure |
| 2661 | we found at least one memory expression. Guards against watch 0x12345, |
| 2662 | which is meaningless, but could cause errors if one tries to insert a |
| 2663 | hardware watchpoint for the constant expression. */ |
| 2664 | for ( ; v; v = v->next) |
| 2665 | { |
| 2666 | if (v->lval == lval_memory) |
| 2667 | { |
| 2668 | if (TYPE_LENGTH (VALUE_TYPE (v)) <= REGISTER_SIZE) |
| 2669 | found_memory_cnt++; |
| 2670 | } |
| 2671 | else if (v->lval != not_lval && v->modifiable == 0) |
| 2672 | return 0; |
| 2673 | } |
| 2674 | |
| 2675 | /* The expression itself looks suitable for using a hardware |
| 2676 | watchpoint, but give the target machine a chance to reject it. */ |
| 2677 | return found_memory_cnt; |
| 2678 | } |
| 2679 | |
| 2680 | static void watch_command (arg, from_tty) |
| 2681 | char *arg; |
| 2682 | int from_tty; |
| 2683 | { |
| 2684 | watch_command_1 (arg, 0, from_tty); |
| 2685 | } |
| 2686 | |
| 2687 | static void rwatch_command (arg, from_tty) |
| 2688 | char *arg; |
| 2689 | int from_tty; |
| 2690 | { |
| 2691 | watch_command_1 (arg, 1, from_tty); |
| 2692 | } |
| 2693 | |
| 2694 | static void awatch_command (arg, from_tty) |
| 2695 | char *arg; |
| 2696 | int from_tty; |
| 2697 | { |
| 2698 | watch_command_1 (arg, 2, from_tty); |
| 2699 | } |
| 2700 | |
| 2701 | \f |
| 2702 | /* Helper routine for the until_command routine in infcmd.c. Here |
| 2703 | because it uses the mechanisms of breakpoints. */ |
| 2704 | |
| 2705 | /* ARGSUSED */ |
| 2706 | void |
| 2707 | until_break_command (arg, from_tty) |
| 2708 | char *arg; |
| 2709 | int from_tty; |
| 2710 | { |
| 2711 | struct symtabs_and_lines sals; |
| 2712 | struct symtab_and_line sal; |
| 2713 | struct frame_info *prev_frame = get_prev_frame (selected_frame); |
| 2714 | struct breakpoint *breakpoint; |
| 2715 | struct cleanup *old_chain; |
| 2716 | |
| 2717 | clear_proceed_status (); |
| 2718 | |
| 2719 | /* Set a breakpoint where the user wants it and at return from |
| 2720 | this function */ |
| 2721 | |
| 2722 | if (default_breakpoint_valid) |
| 2723 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, |
| 2724 | default_breakpoint_line, (char ***)NULL); |
| 2725 | else |
| 2726 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0, (char ***)NULL); |
| 2727 | |
| 2728 | if (sals.nelts != 1) |
| 2729 | error ("Couldn't get information on specified line."); |
| 2730 | |
| 2731 | sal = sals.sals[0]; |
| 2732 | free ((PTR)sals.sals); /* malloc'd, so freed */ |
| 2733 | |
| 2734 | if (*arg) |
| 2735 | error ("Junk at end of arguments."); |
| 2736 | |
| 2737 | resolve_sal_pc (&sal); |
| 2738 | |
| 2739 | breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until); |
| 2740 | |
| 2741 | old_chain = make_cleanup(delete_breakpoint, breakpoint); |
| 2742 | |
| 2743 | /* Keep within the current frame */ |
| 2744 | |
| 2745 | if (prev_frame) |
| 2746 | { |
| 2747 | sal = find_pc_line (prev_frame->pc, 0); |
| 2748 | sal.pc = prev_frame->pc; |
| 2749 | breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until); |
| 2750 | make_cleanup(delete_breakpoint, breakpoint); |
| 2751 | } |
| 2752 | |
| 2753 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
| 2754 | do_cleanups(old_chain); |
| 2755 | } |
| 2756 | \f |
| 2757 | #if 0 |
| 2758 | /* These aren't used; I don't konw what they were for. */ |
| 2759 | /* Set a breakpoint at the catch clause for NAME. */ |
| 2760 | static int |
| 2761 | catch_breakpoint (name) |
| 2762 | char *name; |
| 2763 | { |
| 2764 | } |
| 2765 | |
| 2766 | static int |
| 2767 | disable_catch_breakpoint () |
| 2768 | { |
| 2769 | } |
| 2770 | |
| 2771 | static int |
| 2772 | delete_catch_breakpoint () |
| 2773 | { |
| 2774 | } |
| 2775 | |
| 2776 | static int |
| 2777 | enable_catch_breakpoint () |
| 2778 | { |
| 2779 | } |
| 2780 | #endif /* 0 */ |
| 2781 | |
| 2782 | struct sal_chain |
| 2783 | { |
| 2784 | struct sal_chain *next; |
| 2785 | struct symtab_and_line sal; |
| 2786 | }; |
| 2787 | |
| 2788 | #if 0 |
| 2789 | /* This isn't used; I don't know what it was for. */ |
| 2790 | /* For each catch clause identified in ARGS, run FUNCTION |
| 2791 | with that clause as an argument. */ |
| 2792 | static struct symtabs_and_lines |
| 2793 | map_catch_names (args, function) |
| 2794 | char *args; |
| 2795 | int (*function)(); |
| 2796 | { |
| 2797 | register char *p = args; |
| 2798 | register char *p1; |
| 2799 | struct symtabs_and_lines sals; |
| 2800 | #if 0 |
| 2801 | struct sal_chain *sal_chain = 0; |
| 2802 | #endif |
| 2803 | |
| 2804 | if (p == 0) |
| 2805 | error_no_arg ("one or more catch names"); |
| 2806 | |
| 2807 | sals.nelts = 0; |
| 2808 | sals.sals = NULL; |
| 2809 | |
| 2810 | while (*p) |
| 2811 | { |
| 2812 | p1 = p; |
| 2813 | /* Don't swallow conditional part. */ |
| 2814 | if (p1[0] == 'i' && p1[1] == 'f' |
| 2815 | && (p1[2] == ' ' || p1[2] == '\t')) |
| 2816 | break; |
| 2817 | |
| 2818 | if (isalpha (*p1)) |
| 2819 | { |
| 2820 | p1++; |
| 2821 | while (isalnum (*p1) || *p1 == '_' || *p1 == '$') |
| 2822 | p1++; |
| 2823 | } |
| 2824 | |
| 2825 | if (*p1 && *p1 != ' ' && *p1 != '\t') |
| 2826 | error ("Arguments must be catch names."); |
| 2827 | |
| 2828 | *p1 = 0; |
| 2829 | #if 0 |
| 2830 | if (function (p)) |
| 2831 | { |
| 2832 | struct sal_chain *next |
| 2833 | = (struct sal_chain *)alloca (sizeof (struct sal_chain)); |
| 2834 | next->next = sal_chain; |
| 2835 | next->sal = get_catch_sal (p); |
| 2836 | sal_chain = next; |
| 2837 | goto win; |
| 2838 | } |
| 2839 | #endif |
| 2840 | printf_unfiltered ("No catch clause for exception %s.\n", p); |
| 2841 | #if 0 |
| 2842 | win: |
| 2843 | #endif |
| 2844 | p = p1; |
| 2845 | while (*p == ' ' || *p == '\t') p++; |
| 2846 | } |
| 2847 | } |
| 2848 | #endif /* 0 */ |
| 2849 | |
| 2850 | /* This shares a lot of code with `print_frame_label_vars' from stack.c. */ |
| 2851 | |
| 2852 | static struct symtabs_and_lines |
| 2853 | get_catch_sals (this_level_only) |
| 2854 | int this_level_only; |
| 2855 | { |
| 2856 | register struct blockvector *bl; |
| 2857 | register struct block *block; |
| 2858 | int index, have_default = 0; |
| 2859 | CORE_ADDR pc; |
| 2860 | struct symtabs_and_lines sals; |
| 2861 | struct sal_chain *sal_chain = 0; |
| 2862 | char *blocks_searched; |
| 2863 | |
| 2864 | /* Not sure whether an error message is always the correct response, |
| 2865 | but it's better than a core dump. */ |
| 2866 | if (selected_frame == NULL) |
| 2867 | error ("No selected frame."); |
| 2868 | block = get_frame_block (selected_frame); |
| 2869 | pc = selected_frame->pc; |
| 2870 | |
| 2871 | sals.nelts = 0; |
| 2872 | sals.sals = NULL; |
| 2873 | |
| 2874 | if (block == 0) |
| 2875 | error ("No symbol table info available.\n"); |
| 2876 | |
| 2877 | bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); |
| 2878 | blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); |
| 2879 | memset (blocks_searched, 0, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); |
| 2880 | |
| 2881 | while (block != 0) |
| 2882 | { |
| 2883 | CORE_ADDR end = BLOCK_END (block) - 4; |
| 2884 | int last_index; |
| 2885 | |
| 2886 | if (bl != blockvector_for_pc (end, &index)) |
| 2887 | error ("blockvector blotch"); |
| 2888 | if (BLOCKVECTOR_BLOCK (bl, index) != block) |
| 2889 | error ("blockvector botch"); |
| 2890 | last_index = BLOCKVECTOR_NBLOCKS (bl); |
| 2891 | index += 1; |
| 2892 | |
| 2893 | /* Don't print out blocks that have gone by. */ |
| 2894 | while (index < last_index |
| 2895 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) |
| 2896 | index++; |
| 2897 | |
| 2898 | while (index < last_index |
| 2899 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) |
| 2900 | { |
| 2901 | if (blocks_searched[index] == 0) |
| 2902 | { |
| 2903 | struct block *b = BLOCKVECTOR_BLOCK (bl, index); |
| 2904 | int nsyms; |
| 2905 | register int i; |
| 2906 | register struct symbol *sym; |
| 2907 | |
| 2908 | nsyms = BLOCK_NSYMS (b); |
| 2909 | |
| 2910 | for (i = 0; i < nsyms; i++) |
| 2911 | { |
| 2912 | sym = BLOCK_SYM (b, i); |
| 2913 | if (STREQ (SYMBOL_NAME (sym), "default")) |
| 2914 | { |
| 2915 | if (have_default) |
| 2916 | continue; |
| 2917 | have_default = 1; |
| 2918 | } |
| 2919 | if (SYMBOL_CLASS (sym) == LOC_LABEL) |
| 2920 | { |
| 2921 | struct sal_chain *next = (struct sal_chain *) |
| 2922 | alloca (sizeof (struct sal_chain)); |
| 2923 | next->next = sal_chain; |
| 2924 | next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); |
| 2925 | sal_chain = next; |
| 2926 | } |
| 2927 | } |
| 2928 | blocks_searched[index] = 1; |
| 2929 | } |
| 2930 | index++; |
| 2931 | } |
| 2932 | if (have_default) |
| 2933 | break; |
| 2934 | if (sal_chain && this_level_only) |
| 2935 | break; |
| 2936 | |
| 2937 | /* After handling the function's top-level block, stop. |
| 2938 | Don't continue to its superblock, the block of |
| 2939 | per-file symbols. */ |
| 2940 | if (BLOCK_FUNCTION (block)) |
| 2941 | break; |
| 2942 | block = BLOCK_SUPERBLOCK (block); |
| 2943 | } |
| 2944 | |
| 2945 | if (sal_chain) |
| 2946 | { |
| 2947 | struct sal_chain *tmp_chain; |
| 2948 | |
| 2949 | /* Count the number of entries. */ |
| 2950 | for (index = 0, tmp_chain = sal_chain; tmp_chain; |
| 2951 | tmp_chain = tmp_chain->next) |
| 2952 | index++; |
| 2953 | |
| 2954 | sals.nelts = index; |
| 2955 | sals.sals = (struct symtab_and_line *) |
| 2956 | xmalloc (index * sizeof (struct symtab_and_line)); |
| 2957 | for (index = 0; sal_chain; sal_chain = sal_chain->next, index++) |
| 2958 | sals.sals[index] = sal_chain->sal; |
| 2959 | } |
| 2960 | |
| 2961 | return sals; |
| 2962 | } |
| 2963 | |
| 2964 | /* Commands to deal with catching exceptions. */ |
| 2965 | |
| 2966 | static void |
| 2967 | catch_command_1 (arg, tempflag, from_tty) |
| 2968 | char *arg; |
| 2969 | int tempflag; |
| 2970 | int from_tty; |
| 2971 | { |
| 2972 | /* First, translate ARG into something we can deal with in terms |
| 2973 | of breakpoints. */ |
| 2974 | |
| 2975 | struct symtabs_and_lines sals; |
| 2976 | struct symtab_and_line sal; |
| 2977 | register struct expression *cond = 0; |
| 2978 | register struct breakpoint *b; |
| 2979 | char *save_arg; |
| 2980 | int i; |
| 2981 | |
| 2982 | sal.line = sal.pc = sal.end = 0; |
| 2983 | sal.symtab = 0; |
| 2984 | |
| 2985 | /* If no arg given, or if first arg is 'if ', all active catch clauses |
| 2986 | are breakpointed. */ |
| 2987 | |
| 2988 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' |
| 2989 | && (arg[2] == ' ' || arg[2] == '\t'))) |
| 2990 | { |
| 2991 | /* Grab all active catch clauses. */ |
| 2992 | sals = get_catch_sals (0); |
| 2993 | } |
| 2994 | else |
| 2995 | { |
| 2996 | /* Grab selected catch clauses. */ |
| 2997 | error ("catch NAME not implemented"); |
| 2998 | #if 0 |
| 2999 | /* This isn't used; I don't know what it was for. */ |
| 3000 | sals = map_catch_names (arg, catch_breakpoint); |
| 3001 | #endif |
| 3002 | } |
| 3003 | |
| 3004 | if (! sals.nelts) |
| 3005 | return; |
| 3006 | |
| 3007 | save_arg = arg; |
| 3008 | for (i = 0; i < sals.nelts; i++) |
| 3009 | { |
| 3010 | resolve_sal_pc (&sals.sals[i]); |
| 3011 | |
| 3012 | while (arg && *arg) |
| 3013 | { |
| 3014 | if (arg[0] == 'i' && arg[1] == 'f' |
| 3015 | && (arg[2] == ' ' || arg[2] == '\t')) |
| 3016 | cond = parse_exp_1 ((arg += 2, &arg), |
| 3017 | block_for_pc (sals.sals[i].pc), 0); |
| 3018 | else |
| 3019 | error ("Junk at end of arguments."); |
| 3020 | } |
| 3021 | arg = save_arg; |
| 3022 | } |
| 3023 | |
| 3024 | for (i = 0; i < sals.nelts; i++) |
| 3025 | { |
| 3026 | sal = sals.sals[i]; |
| 3027 | |
| 3028 | if (from_tty) |
| 3029 | describe_other_breakpoints (sal.pc); |
| 3030 | |
| 3031 | b = set_raw_breakpoint (sal); |
| 3032 | set_breakpoint_count (breakpoint_count + 1); |
| 3033 | b->number = breakpoint_count; |
| 3034 | b->type = bp_breakpoint; |
| 3035 | b->cond = cond; |
| 3036 | b->enable = enabled; |
| 3037 | b->disposition = tempflag ? del : donttouch; |
| 3038 | |
| 3039 | mention (b); |
| 3040 | } |
| 3041 | |
| 3042 | if (sals.nelts > 1) |
| 3043 | { |
| 3044 | printf_unfiltered ("Multiple breakpoints were set.\n"); |
| 3045 | printf_unfiltered ("Use the \"delete\" command to delete unwanted breakpoints.\n"); |
| 3046 | } |
| 3047 | free ((PTR)sals.sals); |
| 3048 | } |
| 3049 | |
| 3050 | /* Used by the gui, could be made a worker for other things. */ |
| 3051 | |
| 3052 | struct breakpoint * |
| 3053 | set_breakpoint_sal (sal) |
| 3054 | struct symtab_and_line sal; |
| 3055 | { |
| 3056 | struct breakpoint *b; |
| 3057 | b = set_raw_breakpoint (sal); |
| 3058 | set_breakpoint_count (breakpoint_count + 1); |
| 3059 | b->number = breakpoint_count; |
| 3060 | b->type = bp_breakpoint; |
| 3061 | b->cond = 0; |
| 3062 | b->thread = -1; |
| 3063 | return b; |
| 3064 | } |
| 3065 | |
| 3066 | #if 0 |
| 3067 | /* These aren't used; I don't know what they were for. */ |
| 3068 | /* Disable breakpoints on all catch clauses described in ARGS. */ |
| 3069 | static void |
| 3070 | disable_catch (args) |
| 3071 | char *args; |
| 3072 | { |
| 3073 | /* Map the disable command to catch clauses described in ARGS. */ |
| 3074 | } |
| 3075 | |
| 3076 | /* Enable breakpoints on all catch clauses described in ARGS. */ |
| 3077 | static void |
| 3078 | enable_catch (args) |
| 3079 | char *args; |
| 3080 | { |
| 3081 | /* Map the disable command to catch clauses described in ARGS. */ |
| 3082 | } |
| 3083 | |
| 3084 | /* Delete breakpoints on all catch clauses in the active scope. */ |
| 3085 | static void |
| 3086 | delete_catch (args) |
| 3087 | char *args; |
| 3088 | { |
| 3089 | /* Map the delete command to catch clauses described in ARGS. */ |
| 3090 | } |
| 3091 | #endif /* 0 */ |
| 3092 | |
| 3093 | static void |
| 3094 | catch_command (arg, from_tty) |
| 3095 | char *arg; |
| 3096 | int from_tty; |
| 3097 | { |
| 3098 | catch_command_1 (arg, 0, from_tty); |
| 3099 | } |
| 3100 | \f |
| 3101 | static void |
| 3102 | clear_command (arg, from_tty) |
| 3103 | char *arg; |
| 3104 | int from_tty; |
| 3105 | { |
| 3106 | register struct breakpoint *b, *b1; |
| 3107 | struct symtabs_and_lines sals; |
| 3108 | struct symtab_and_line sal; |
| 3109 | register struct breakpoint *found; |
| 3110 | int i; |
| 3111 | |
| 3112 | if (arg) |
| 3113 | { |
| 3114 | sals = decode_line_spec (arg, 1); |
| 3115 | } |
| 3116 | else |
| 3117 | { |
| 3118 | sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); |
| 3119 | sal.line = default_breakpoint_line; |
| 3120 | sal.symtab = default_breakpoint_symtab; |
| 3121 | sal.pc = 0; |
| 3122 | if (sal.symtab == 0) |
| 3123 | error ("No source file specified."); |
| 3124 | |
| 3125 | sals.sals[0] = sal; |
| 3126 | sals.nelts = 1; |
| 3127 | } |
| 3128 | |
| 3129 | for (i = 0; i < sals.nelts; i++) |
| 3130 | { |
| 3131 | /* If exact pc given, clear bpts at that pc. |
| 3132 | But if sal.pc is zero, clear all bpts on specified line. */ |
| 3133 | sal = sals.sals[i]; |
| 3134 | found = (struct breakpoint *) 0; |
| 3135 | while (breakpoint_chain |
| 3136 | && (sal.pc |
| 3137 | ? breakpoint_chain->address == sal.pc |
| 3138 | : (breakpoint_chain->source_file != NULL |
| 3139 | && sal.symtab != NULL |
| 3140 | && STREQ (breakpoint_chain->source_file, |
| 3141 | sal.symtab->filename) |
| 3142 | && breakpoint_chain->line_number == sal.line))) |
| 3143 | { |
| 3144 | b1 = breakpoint_chain; |
| 3145 | breakpoint_chain = b1->next; |
| 3146 | b1->next = found; |
| 3147 | found = b1; |
| 3148 | } |
| 3149 | |
| 3150 | ALL_BREAKPOINTS (b) |
| 3151 | while (b->next |
| 3152 | && b->next->type != bp_watchpoint |
| 3153 | && b->next->type != bp_hardware_watchpoint |
| 3154 | && b->next->type != bp_read_watchpoint |
| 3155 | && b->next->type != bp_access_watchpoint |
| 3156 | && (sal.pc |
| 3157 | ? b->next->address == sal.pc |
| 3158 | : (b->next->source_file != NULL |
| 3159 | && sal.symtab != NULL |
| 3160 | && STREQ (b->next->source_file, sal.symtab->filename) |
| 3161 | && b->next->line_number == sal.line))) |
| 3162 | { |
| 3163 | b1 = b->next; |
| 3164 | b->next = b1->next; |
| 3165 | b1->next = found; |
| 3166 | found = b1; |
| 3167 | } |
| 3168 | |
| 3169 | if (found == 0) |
| 3170 | { |
| 3171 | if (arg) |
| 3172 | error ("No breakpoint at %s.", arg); |
| 3173 | else |
| 3174 | error ("No breakpoint at this line."); |
| 3175 | } |
| 3176 | |
| 3177 | if (found->next) from_tty = 1; /* Always report if deleted more than one */ |
| 3178 | if (from_tty) printf_unfiltered ("Deleted breakpoint%s ", found->next ? "s" : ""); |
| 3179 | breakpoints_changed (); |
| 3180 | while (found) |
| 3181 | { |
| 3182 | if (from_tty) printf_unfiltered ("%d ", found->number); |
| 3183 | b1 = found->next; |
| 3184 | delete_breakpoint (found); |
| 3185 | found = b1; |
| 3186 | } |
| 3187 | if (from_tty) putchar_unfiltered ('\n'); |
| 3188 | } |
| 3189 | free ((PTR)sals.sals); |
| 3190 | } |
| 3191 | \f |
| 3192 | /* Delete breakpoint in BS if they are `delete' breakpoints. |
| 3193 | This is called after any breakpoint is hit, or after errors. */ |
| 3194 | |
| 3195 | void |
| 3196 | breakpoint_auto_delete (bs) |
| 3197 | bpstat bs; |
| 3198 | { |
| 3199 | for (; bs; bs = bs->next) |
| 3200 | if (bs->breakpoint_at && bs->breakpoint_at->disposition == del |
| 3201 | && bs->stop) |
| 3202 | delete_breakpoint (bs->breakpoint_at); |
| 3203 | } |
| 3204 | |
| 3205 | /* Delete a breakpoint and clean up all traces of it in the data structures. */ |
| 3206 | |
| 3207 | void |
| 3208 | delete_breakpoint (bpt) |
| 3209 | struct breakpoint *bpt; |
| 3210 | { |
| 3211 | register struct breakpoint *b; |
| 3212 | register bpstat bs; |
| 3213 | |
| 3214 | if (delete_breakpoint_hook) |
| 3215 | delete_breakpoint_hook (bpt); |
| 3216 | |
| 3217 | if (bpt->inserted) |
| 3218 | remove_breakpoint (bpt); |
| 3219 | |
| 3220 | if (breakpoint_chain == bpt) |
| 3221 | breakpoint_chain = bpt->next; |
| 3222 | |
| 3223 | ALL_BREAKPOINTS (b) |
| 3224 | if (b->next == bpt) |
| 3225 | { |
| 3226 | b->next = bpt->next; |
| 3227 | break; |
| 3228 | } |
| 3229 | |
| 3230 | check_duplicates (bpt->address); |
| 3231 | /* If this breakpoint was inserted, and there is another breakpoint |
| 3232 | at the same address, we need to insert the other breakpoint. */ |
| 3233 | if (bpt->inserted |
| 3234 | && bpt->type != bp_hardware_watchpoint |
| 3235 | && bpt->type != bp_read_watchpoint |
| 3236 | && bpt->type != bp_access_watchpoint) |
| 3237 | { |
| 3238 | ALL_BREAKPOINTS (b) |
| 3239 | if (b->address == bpt->address |
| 3240 | && !b->duplicate |
| 3241 | && b->enable != disabled) |
| 3242 | { |
| 3243 | int val; |
| 3244 | val = target_insert_breakpoint (b->address, b->shadow_contents); |
| 3245 | if (val != 0) |
| 3246 | { |
| 3247 | target_terminal_ours_for_output (); |
| 3248 | fprintf_unfiltered (gdb_stderr, "Cannot insert breakpoint %d:\n", b->number); |
| 3249 | memory_error (val, b->address); /* which bombs us out */ |
| 3250 | } |
| 3251 | else |
| 3252 | b->inserted = 1; |
| 3253 | } |
| 3254 | } |
| 3255 | |
| 3256 | free_command_lines (&bpt->commands); |
| 3257 | if (bpt->cond) |
| 3258 | free (bpt->cond); |
| 3259 | if (bpt->cond_string != NULL) |
| 3260 | free (bpt->cond_string); |
| 3261 | if (bpt->addr_string != NULL) |
| 3262 | free (bpt->addr_string); |
| 3263 | if (bpt->exp_string != NULL) |
| 3264 | free (bpt->exp_string); |
| 3265 | if (bpt->source_file != NULL) |
| 3266 | free (bpt->source_file); |
| 3267 | |
| 3268 | /* Be sure no bpstat's are pointing at it after it's been freed. */ |
| 3269 | /* FIXME, how can we find all bpstat's? |
| 3270 | We just check stop_bpstat for now. */ |
| 3271 | for (bs = stop_bpstat; bs; bs = bs->next) |
| 3272 | if (bs->breakpoint_at == bpt) |
| 3273 | bs->breakpoint_at = NULL; |
| 3274 | free ((PTR)bpt); |
| 3275 | } |
| 3276 | |
| 3277 | static void |
| 3278 | delete_command (arg, from_tty) |
| 3279 | char *arg; |
| 3280 | int from_tty; |
| 3281 | { |
| 3282 | |
| 3283 | if (arg == 0) |
| 3284 | { |
| 3285 | /* Ask user only if there are some breakpoints to delete. */ |
| 3286 | if (!from_tty |
| 3287 | || (breakpoint_chain && query ("Delete all breakpoints? "))) |
| 3288 | { |
| 3289 | /* No arg; clear all breakpoints. */ |
| 3290 | while (breakpoint_chain) |
| 3291 | delete_breakpoint (breakpoint_chain); |
| 3292 | } |
| 3293 | } |
| 3294 | else |
| 3295 | map_breakpoint_numbers (arg, delete_breakpoint); |
| 3296 | } |
| 3297 | |
| 3298 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
| 3299 | The value we return ends up being the return value from catch_errors. |
| 3300 | Unused in this case. */ |
| 3301 | |
| 3302 | static int |
| 3303 | breakpoint_re_set_one (bint) |
| 3304 | char *bint; |
| 3305 | { |
| 3306 | struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */ |
| 3307 | struct value *mark; |
| 3308 | int i; |
| 3309 | struct symtabs_and_lines sals; |
| 3310 | char *s; |
| 3311 | enum enable save_enable; |
| 3312 | |
| 3313 | switch (b->type) |
| 3314 | { |
| 3315 | case bp_breakpoint: |
| 3316 | case bp_hardware_breakpoint: |
| 3317 | if (b->addr_string == NULL) |
| 3318 | { |
| 3319 | /* Anything without a string can't be re-set. */ |
| 3320 | delete_breakpoint (b); |
| 3321 | return 0; |
| 3322 | } |
| 3323 | /* In case we have a problem, disable this breakpoint. We'll restore |
| 3324 | its status if we succeed. */ |
| 3325 | save_enable = b->enable; |
| 3326 | b->enable = disabled; |
| 3327 | |
| 3328 | set_language (b->language); |
| 3329 | input_radix = b->input_radix; |
| 3330 | s = b->addr_string; |
| 3331 | sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0, (char ***)NULL); |
| 3332 | for (i = 0; i < sals.nelts; i++) |
| 3333 | { |
| 3334 | resolve_sal_pc (&sals.sals[i]); |
| 3335 | |
| 3336 | /* Reparse conditions, they might contain references to the |
| 3337 | old symtab. */ |
| 3338 | if (b->cond_string != NULL) |
| 3339 | { |
| 3340 | s = b->cond_string; |
| 3341 | if (b->cond) |
| 3342 | free ((PTR)b->cond); |
| 3343 | b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0); |
| 3344 | } |
| 3345 | |
| 3346 | /* We need to re-set the breakpoint if the address changes...*/ |
| 3347 | if (b->address != sals.sals[i].pc |
| 3348 | /* ...or new and old breakpoints both have source files, and |
| 3349 | the source file name or the line number changes... */ |
| 3350 | || (b->source_file != NULL |
| 3351 | && sals.sals[i].symtab != NULL |
| 3352 | && (!STREQ (b->source_file, sals.sals[i].symtab->filename) |
| 3353 | || b->line_number != sals.sals[i].line) |
| 3354 | ) |
| 3355 | /* ...or we switch between having a source file and not having |
| 3356 | one. */ |
| 3357 | || ((b->source_file == NULL) != (sals.sals[i].symtab == NULL)) |
| 3358 | ) |
| 3359 | { |
| 3360 | if (b->source_file != NULL) |
| 3361 | free (b->source_file); |
| 3362 | if (sals.sals[i].symtab == NULL) |
| 3363 | b->source_file = NULL; |
| 3364 | else |
| 3365 | b->source_file = |
| 3366 | savestring (sals.sals[i].symtab->filename, |
| 3367 | strlen (sals.sals[i].symtab->filename)); |
| 3368 | b->line_number = sals.sals[i].line; |
| 3369 | b->address = sals.sals[i].pc; |
| 3370 | |
| 3371 | check_duplicates (b->address); |
| 3372 | |
| 3373 | mention (b); |
| 3374 | |
| 3375 | /* Might be better to do this just once per breakpoint_re_set, |
| 3376 | rather than once for every breakpoint. */ |
| 3377 | breakpoints_changed (); |
| 3378 | } |
| 3379 | b->enable = save_enable; /* Restore it, this worked. */ |
| 3380 | } |
| 3381 | free ((PTR)sals.sals); |
| 3382 | break; |
| 3383 | |
| 3384 | case bp_watchpoint: |
| 3385 | case bp_hardware_watchpoint: |
| 3386 | case bp_read_watchpoint: |
| 3387 | case bp_access_watchpoint: |
| 3388 | innermost_block = NULL; |
| 3389 | /* The issue arises of what context to evaluate this in. The same |
| 3390 | one as when it was set, but what does that mean when symbols have |
| 3391 | been re-read? We could save the filename and functionname, but |
| 3392 | if the context is more local than that, the best we could do would |
| 3393 | be something like how many levels deep and which index at that |
| 3394 | particular level, but that's going to be less stable than filenames |
| 3395 | or functionnames. */ |
| 3396 | /* So for now, just use a global context. */ |
| 3397 | b->exp = parse_expression (b->exp_string); |
| 3398 | b->exp_valid_block = innermost_block; |
| 3399 | mark = value_mark (); |
| 3400 | b->val = evaluate_expression (b->exp); |
| 3401 | release_value (b->val); |
| 3402 | if (VALUE_LAZY (b->val)) |
| 3403 | value_fetch_lazy (b->val); |
| 3404 | |
| 3405 | if (b->cond_string != NULL) |
| 3406 | { |
| 3407 | s = b->cond_string; |
| 3408 | b->cond = parse_exp_1 (&s, (struct block *)0, 0); |
| 3409 | } |
| 3410 | if (b->enable == enabled) |
| 3411 | mention (b); |
| 3412 | value_free_to_mark (mark); |
| 3413 | break; |
| 3414 | |
| 3415 | default: |
| 3416 | printf_filtered ("Deleting unknown breakpoint type %d\n", b->type); |
| 3417 | /* fall through */ |
| 3418 | case bp_until: |
| 3419 | case bp_finish: |
| 3420 | case bp_longjmp: |
| 3421 | case bp_longjmp_resume: |
| 3422 | case bp_watchpoint_scope: |
| 3423 | case bp_call_dummy: |
| 3424 | delete_breakpoint (b); |
| 3425 | break; |
| 3426 | } |
| 3427 | |
| 3428 | return 0; |
| 3429 | } |
| 3430 | |
| 3431 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
| 3432 | void |
| 3433 | breakpoint_re_set () |
| 3434 | { |
| 3435 | struct breakpoint *b, *temp; |
| 3436 | enum language save_language; |
| 3437 | int save_input_radix; |
| 3438 | static char message1[] = "Error in re-setting breakpoint %d:\n"; |
| 3439 | char message[sizeof (message1) + 30 /* slop */]; |
| 3440 | |
| 3441 | save_language = current_language->la_language; |
| 3442 | save_input_radix = input_radix; |
| 3443 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 3444 | { |
| 3445 | sprintf (message, message1, b->number); /* Format possible error msg */ |
| 3446 | catch_errors (breakpoint_re_set_one, (char *) b, message, |
| 3447 | RETURN_MASK_ALL); |
| 3448 | } |
| 3449 | set_language (save_language); |
| 3450 | input_radix = save_input_radix; |
| 3451 | |
| 3452 | create_longjmp_breakpoint("longjmp"); |
| 3453 | create_longjmp_breakpoint("_longjmp"); |
| 3454 | create_longjmp_breakpoint("siglongjmp"); |
| 3455 | create_longjmp_breakpoint(NULL); |
| 3456 | |
| 3457 | #if 0 |
| 3458 | /* Took this out (temporaliy at least), since it produces an extra |
| 3459 | blank line at startup. This messes up the gdbtests. -PB */ |
| 3460 | /* Blank line to finish off all those mention() messages we just printed. */ |
| 3461 | printf_filtered ("\n"); |
| 3462 | #endif |
| 3463 | } |
| 3464 | \f |
| 3465 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 3466 | If from_tty is nonzero, it prints a message to that effect, |
| 3467 | which ends with a period (no newline). */ |
| 3468 | |
| 3469 | void |
| 3470 | set_ignore_count (bptnum, count, from_tty) |
| 3471 | int bptnum, count, from_tty; |
| 3472 | { |
| 3473 | register struct breakpoint *b; |
| 3474 | |
| 3475 | if (count < 0) |
| 3476 | count = 0; |
| 3477 | |
| 3478 | ALL_BREAKPOINTS (b) |
| 3479 | if (b->number == bptnum) |
| 3480 | { |
| 3481 | b->ignore_count = count; |
| 3482 | if (!from_tty) |
| 3483 | return; |
| 3484 | else if (count == 0) |
| 3485 | printf_filtered ("Will stop next time breakpoint %d is reached.", |
| 3486 | bptnum); |
| 3487 | else if (count == 1) |
| 3488 | printf_filtered ("Will ignore next crossing of breakpoint %d.", |
| 3489 | bptnum); |
| 3490 | else |
| 3491 | printf_filtered ("Will ignore next %d crossings of breakpoint %d.", |
| 3492 | count, bptnum); |
| 3493 | breakpoints_changed (); |
| 3494 | return; |
| 3495 | } |
| 3496 | |
| 3497 | error ("No breakpoint number %d.", bptnum); |
| 3498 | } |
| 3499 | |
| 3500 | /* Clear the ignore counts of all breakpoints. */ |
| 3501 | void |
| 3502 | breakpoint_clear_ignore_counts () |
| 3503 | { |
| 3504 | struct breakpoint *b; |
| 3505 | |
| 3506 | ALL_BREAKPOINTS (b) |
| 3507 | b->ignore_count = 0; |
| 3508 | } |
| 3509 | |
| 3510 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
| 3511 | |
| 3512 | static void |
| 3513 | ignore_command (args, from_tty) |
| 3514 | char *args; |
| 3515 | int from_tty; |
| 3516 | { |
| 3517 | char *p = args; |
| 3518 | register int num; |
| 3519 | |
| 3520 | if (p == 0) |
| 3521 | error_no_arg ("a breakpoint number"); |
| 3522 | |
| 3523 | num = get_number (&p); |
| 3524 | |
| 3525 | if (*p == 0) |
| 3526 | error ("Second argument (specified ignore-count) is missing."); |
| 3527 | |
| 3528 | set_ignore_count (num, |
| 3529 | longest_to_int (value_as_long (parse_and_eval (p))), |
| 3530 | from_tty); |
| 3531 | printf_filtered ("\n"); |
| 3532 | breakpoints_changed (); |
| 3533 | } |
| 3534 | \f |
| 3535 | /* Call FUNCTION on each of the breakpoints |
| 3536 | whose numbers are given in ARGS. */ |
| 3537 | |
| 3538 | static void |
| 3539 | map_breakpoint_numbers (args, function) |
| 3540 | char *args; |
| 3541 | void (*function) PARAMS ((struct breakpoint *)); |
| 3542 | { |
| 3543 | register char *p = args; |
| 3544 | char *p1; |
| 3545 | register int num; |
| 3546 | register struct breakpoint *b; |
| 3547 | |
| 3548 | if (p == 0) |
| 3549 | error_no_arg ("one or more breakpoint numbers"); |
| 3550 | |
| 3551 | while (*p) |
| 3552 | { |
| 3553 | p1 = p; |
| 3554 | |
| 3555 | num = get_number (&p1); |
| 3556 | |
| 3557 | ALL_BREAKPOINTS (b) |
| 3558 | if (b->number == num) |
| 3559 | { |
| 3560 | struct breakpoint *related_breakpoint = b->related_breakpoint; |
| 3561 | function (b); |
| 3562 | if (related_breakpoint) |
| 3563 | function (related_breakpoint); |
| 3564 | goto win; |
| 3565 | } |
| 3566 | printf_unfiltered ("No breakpoint number %d.\n", num); |
| 3567 | win: |
| 3568 | p = p1; |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | void |
| 3573 | enable_breakpoint (bpt) |
| 3574 | struct breakpoint *bpt; |
| 3575 | { |
| 3576 | struct frame_info *save_selected_frame = NULL; |
| 3577 | int save_selected_frame_level = -1; |
| 3578 | int target_resources_ok, other_type_used; |
| 3579 | struct value *mark; |
| 3580 | |
| 3581 | if (bpt->type == bp_hardware_breakpoint) |
| 3582 | { |
| 3583 | int i; |
| 3584 | i = hw_breakpoint_used_count(); |
| 3585 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( |
| 3586 | bp_hardware_breakpoint, i+1, 0); |
| 3587 | if (target_resources_ok == 0) |
| 3588 | error ("No hardware breakpoint support in the target."); |
| 3589 | else if (target_resources_ok < 0) |
| 3590 | error ("Hardware breakpoints used exceeds limit."); |
| 3591 | } |
| 3592 | bpt->enable = enabled; |
| 3593 | check_duplicates (bpt->address); |
| 3594 | |
| 3595 | if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint || |
| 3596 | bpt->type == bp_read_watchpoint || bpt->type == bp_access_watchpoint) |
| 3597 | { |
| 3598 | if (bpt->exp_valid_block != NULL) |
| 3599 | { |
| 3600 | struct frame_info *fr = |
| 3601 | find_frame_addr_in_frame_chain (bpt->watchpoint_frame); |
| 3602 | if (fr == NULL) |
| 3603 | { |
| 3604 | printf_filtered ("\ |
| 3605 | Cannot enable watchpoint %d because the block in which its expression\n\ |
| 3606 | is valid is not currently in scope.\n", bpt->number); |
| 3607 | bpt->enable = disabled; |
| 3608 | return; |
| 3609 | } |
| 3610 | |
| 3611 | save_selected_frame = selected_frame; |
| 3612 | save_selected_frame_level = selected_frame_level; |
| 3613 | select_frame (fr, -1); |
| 3614 | } |
| 3615 | |
| 3616 | value_free (bpt->val); |
| 3617 | mark = value_mark (); |
| 3618 | bpt->val = evaluate_expression (bpt->exp); |
| 3619 | release_value (bpt->val); |
| 3620 | if (VALUE_LAZY (bpt->val)) |
| 3621 | value_fetch_lazy (bpt->val); |
| 3622 | |
| 3623 | if (bpt->type == bp_hardware_watchpoint || |
| 3624 | bpt->type == bp_read_watchpoint || |
| 3625 | bpt->type == bp_access_watchpoint) |
| 3626 | { |
| 3627 | int i = hw_watchpoint_used_count (bpt->type, &other_type_used); |
| 3628 | int mem_cnt = can_use_hardware_watchpoint (bpt->val); |
| 3629 | |
| 3630 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( |
| 3631 | bpt->type, i + mem_cnt, other_type_used); |
| 3632 | /* we can consider of type is bp_hardware_watchpoint, convert to |
| 3633 | bp_watchpoint in the following condition */ |
| 3634 | if (target_resources_ok < 0) |
| 3635 | { |
| 3636 | printf_filtered("\ |
| 3637 | Cannot enable watchpoint %d because target watch resources\n\ |
| 3638 | have been allocated for other watchpoints.\n", bpt->number); |
| 3639 | bpt->enable = disabled; |
| 3640 | value_free_to_mark (mark); |
| 3641 | return; |
| 3642 | } |
| 3643 | } |
| 3644 | |
| 3645 | if (save_selected_frame_level >= 0) |
| 3646 | select_frame (save_selected_frame, save_selected_frame_level); |
| 3647 | value_free_to_mark (mark); |
| 3648 | } |
| 3649 | |
| 3650 | if (modify_breakpoint_hook) |
| 3651 | modify_breakpoint_hook (bpt); |
| 3652 | } |
| 3653 | |
| 3654 | /* ARGSUSED */ |
| 3655 | static void |
| 3656 | enable_command (args, from_tty) |
| 3657 | char *args; |
| 3658 | int from_tty; |
| 3659 | { |
| 3660 | struct breakpoint *bpt; |
| 3661 | if (args == 0) |
| 3662 | ALL_BREAKPOINTS (bpt) |
| 3663 | switch (bpt->type) |
| 3664 | { |
| 3665 | case bp_breakpoint: |
| 3666 | case bp_hardware_breakpoint: |
| 3667 | case bp_watchpoint: |
| 3668 | case bp_hardware_watchpoint: |
| 3669 | case bp_read_watchpoint: |
| 3670 | case bp_access_watchpoint: |
| 3671 | enable_breakpoint (bpt); |
| 3672 | default: |
| 3673 | continue; |
| 3674 | } |
| 3675 | else |
| 3676 | map_breakpoint_numbers (args, enable_breakpoint); |
| 3677 | } |
| 3678 | |
| 3679 | void |
| 3680 | disable_breakpoint (bpt) |
| 3681 | struct breakpoint *bpt; |
| 3682 | { |
| 3683 | /* Never disable a watchpoint scope breakpoint; we want to |
| 3684 | hit them when we leave scope so we can delete both the |
| 3685 | watchpoint and its scope breakpoint at that time. */ |
| 3686 | if (bpt->type == bp_watchpoint_scope) |
| 3687 | return; |
| 3688 | |
| 3689 | bpt->enable = disabled; |
| 3690 | |
| 3691 | check_duplicates (bpt->address); |
| 3692 | |
| 3693 | if (modify_breakpoint_hook) |
| 3694 | modify_breakpoint_hook (bpt); |
| 3695 | } |
| 3696 | |
| 3697 | /* ARGSUSED */ |
| 3698 | static void |
| 3699 | disable_command (args, from_tty) |
| 3700 | char *args; |
| 3701 | int from_tty; |
| 3702 | { |
| 3703 | register struct breakpoint *bpt; |
| 3704 | if (args == 0) |
| 3705 | ALL_BREAKPOINTS (bpt) |
| 3706 | switch (bpt->type) |
| 3707 | { |
| 3708 | case bp_breakpoint: |
| 3709 | case bp_hardware_breakpoint: |
| 3710 | case bp_watchpoint: |
| 3711 | case bp_hardware_watchpoint: |
| 3712 | case bp_read_watchpoint: |
| 3713 | case bp_access_watchpoint: |
| 3714 | disable_breakpoint (bpt); |
| 3715 | default: |
| 3716 | continue; |
| 3717 | } |
| 3718 | else |
| 3719 | map_breakpoint_numbers (args, disable_breakpoint); |
| 3720 | } |
| 3721 | |
| 3722 | static void |
| 3723 | enable_once_breakpoint (bpt) |
| 3724 | struct breakpoint *bpt; |
| 3725 | { |
| 3726 | struct frame_info *save_selected_frame = NULL; |
| 3727 | int save_selected_frame_level = -1; |
| 3728 | int target_resources_ok, other_type_used; |
| 3729 | struct value *mark; |
| 3730 | |
| 3731 | if (bpt->type == bp_hardware_breakpoint) |
| 3732 | { |
| 3733 | int i; |
| 3734 | i = hw_breakpoint_used_count(); |
| 3735 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( |
| 3736 | bp_hardware_breakpoint, i+1, 0); |
| 3737 | if (target_resources_ok == 0) |
| 3738 | error ("No hardware breakpoint support in the target."); |
| 3739 | else if (target_resources_ok < 0) |
| 3740 | error ("Hardware breakpoints used exceeds limit."); |
| 3741 | } |
| 3742 | |
| 3743 | bpt->enable = enabled; |
| 3744 | bpt->disposition = disable; |
| 3745 | check_duplicates (bpt->address); |
| 3746 | breakpoints_changed (); |
| 3747 | |
| 3748 | if (bpt->type == bp_watchpoint || bpt->type == bp_hardware_watchpoint || |
| 3749 | bpt->type == bp_read_watchpoint || bpt->type == bp_access_watchpoint) |
| 3750 | { |
| 3751 | if (bpt->exp_valid_block != NULL) |
| 3752 | { |
| 3753 | struct frame_info *fr = |
| 3754 | find_frame_addr_in_frame_chain (bpt->watchpoint_frame); |
| 3755 | if (fr == NULL) |
| 3756 | { |
| 3757 | printf_filtered ("\ |
| 3758 | Cannot enable watchpoint %d because the block in which its expression\n\ |
| 3759 | is valid is not currently in scope.\n", bpt->number); |
| 3760 | bpt->enable = disabled; |
| 3761 | return; |
| 3762 | } |
| 3763 | |
| 3764 | save_selected_frame = selected_frame; |
| 3765 | save_selected_frame_level = selected_frame_level; |
| 3766 | select_frame (fr, -1); |
| 3767 | } |
| 3768 | |
| 3769 | value_free (bpt->val); |
| 3770 | mark = value_mark (); |
| 3771 | bpt->val = evaluate_expression (bpt->exp); |
| 3772 | release_value (bpt->val); |
| 3773 | if (VALUE_LAZY (bpt->val)) |
| 3774 | value_fetch_lazy (bpt->val); |
| 3775 | |
| 3776 | if (bpt->type == bp_hardware_watchpoint || |
| 3777 | bpt->type == bp_read_watchpoint || |
| 3778 | bpt->type == bp_access_watchpoint) |
| 3779 | { |
| 3780 | int i = hw_watchpoint_used_count (bpt->type, &other_type_used); |
| 3781 | int mem_cnt = can_use_hardware_watchpoint(bpt->val); |
| 3782 | target_resources_ok = TARGET_CAN_USE_HARDWARE_WATCHPOINT( |
| 3783 | bpt->type, i+mem_cnt, other_type_used); |
| 3784 | /* we can consider of type is bp_hardware_watchpoint, convert to |
| 3785 | bp_watchpoint in the following condition */ |
| 3786 | if (target_resources_ok < 0) |
| 3787 | { |
| 3788 | printf_filtered("\ |
| 3789 | Cannot enable watchpoint %d because target watch resources\n\ |
| 3790 | have been allocated for other watchpoints.\n", bpt->number); |
| 3791 | bpt->enable = disabled; |
| 3792 | value_free_to_mark (mark); |
| 3793 | } |
| 3794 | } |
| 3795 | |
| 3796 | if (save_selected_frame_level >= 0) |
| 3797 | select_frame (save_selected_frame, save_selected_frame_level); |
| 3798 | value_free_to_mark (mark); |
| 3799 | } |
| 3800 | } |
| 3801 | |
| 3802 | /* ARGSUSED */ |
| 3803 | static void |
| 3804 | enable_once_command (args, from_tty) |
| 3805 | char *args; |
| 3806 | int from_tty; |
| 3807 | { |
| 3808 | map_breakpoint_numbers (args, enable_once_breakpoint); |
| 3809 | } |
| 3810 | |
| 3811 | static void |
| 3812 | enable_delete_breakpoint (bpt) |
| 3813 | struct breakpoint *bpt; |
| 3814 | { |
| 3815 | bpt->enable = enabled; |
| 3816 | bpt->disposition = del; |
| 3817 | |
| 3818 | check_duplicates (bpt->address); |
| 3819 | breakpoints_changed (); |
| 3820 | } |
| 3821 | |
| 3822 | /* ARGSUSED */ |
| 3823 | static void |
| 3824 | enable_delete_command (args, from_tty) |
| 3825 | char *args; |
| 3826 | int from_tty; |
| 3827 | { |
| 3828 | map_breakpoint_numbers (args, enable_delete_breakpoint); |
| 3829 | } |
| 3830 | \f |
| 3831 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
| 3832 | |
| 3833 | struct symtabs_and_lines |
| 3834 | decode_line_spec_1 (string, funfirstline) |
| 3835 | char *string; |
| 3836 | int funfirstline; |
| 3837 | { |
| 3838 | struct symtabs_and_lines sals; |
| 3839 | if (string == 0) |
| 3840 | error ("Empty line specification."); |
| 3841 | if (default_breakpoint_valid) |
| 3842 | sals = decode_line_1 (&string, funfirstline, |
| 3843 | default_breakpoint_symtab, default_breakpoint_line, |
| 3844 | (char ***)NULL); |
| 3845 | else |
| 3846 | sals = decode_line_1 (&string, funfirstline, |
| 3847 | (struct symtab *)NULL, 0, (char ***)NULL); |
| 3848 | if (*string) |
| 3849 | error ("Junk at end of line specification: %s", string); |
| 3850 | return sals; |
| 3851 | } |
| 3852 | \f |
| 3853 | void |
| 3854 | _initialize_breakpoint () |
| 3855 | { |
| 3856 | breakpoint_chain = 0; |
| 3857 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful |
| 3858 | before a breakpoint is set. */ |
| 3859 | breakpoint_count = 0; |
| 3860 | |
| 3861 | add_com ("ignore", class_breakpoint, ignore_command, |
| 3862 | "Set ignore-count of breakpoint number N to COUNT.\n\ |
| 3863 | Usage is `ignore N COUNT'."); |
| 3864 | |
| 3865 | add_com ("commands", class_breakpoint, commands_command, |
| 3866 | "Set commands to be executed when a breakpoint is hit.\n\ |
| 3867 | Give breakpoint number as argument after \"commands\".\n\ |
| 3868 | With no argument, the targeted breakpoint is the last one set.\n\ |
| 3869 | The commands themselves follow starting on the next line.\n\ |
| 3870 | Type a line containing \"end\" to indicate the end of them.\n\ |
| 3871 | Give \"silent\" as the first line to make the breakpoint silent;\n\ |
| 3872 | then no output is printed when it is hit, except what the commands print."); |
| 3873 | |
| 3874 | add_com ("condition", class_breakpoint, condition_command, |
| 3875 | "Specify breakpoint number N to break only if COND is true.\n\ |
| 3876 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
| 3877 | expression to be evaluated whenever breakpoint N is reached. "); |
| 3878 | |
| 3879 | add_com ("tbreak", class_breakpoint, tbreak_command, |
| 3880 | "Set a temporary breakpoint. Args like \"break\" command.\n\ |
| 3881 | Like \"break\" except the breakpoint is only temporary,\n\ |
| 3882 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ |
| 3883 | by using \"enable delete\" on the breakpoint number."); |
| 3884 | |
| 3885 | add_com ("hbreak", class_breakpoint, hbreak_command, |
| 3886 | "Set a hardware assisted breakpoint. Args like \"break\" command.\n\ |
| 3887 | Like \"break\" except the breakpoint requires hardware support,\n\ |
| 3888 | some target hardware may not have this support."); |
| 3889 | |
| 3890 | add_com ("thbreak", class_breakpoint, thbreak_command, |
| 3891 | "Set a temporary hardware assisted breakpoint. Args like \"break\" command.\n\ |
| 3892 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
| 3893 | so it will be deleted when hit."); |
| 3894 | |
| 3895 | add_prefix_cmd ("enable", class_breakpoint, enable_command, |
| 3896 | "Enable some breakpoints.\n\ |
| 3897 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 3898 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 3899 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 3900 | With a subcommand you can enable temporarily.", |
| 3901 | &enablelist, "enable ", 1, &cmdlist); |
| 3902 | |
| 3903 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, |
| 3904 | "Enable some breakpoints.\n\ |
| 3905 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 3906 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 3907 | May be abbreviated to simply \"enable\".\n", |
| 3908 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
| 3909 | |
| 3910 | add_cmd ("once", no_class, enable_once_command, |
| 3911 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 3912 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", |
| 3913 | &enablebreaklist); |
| 3914 | |
| 3915 | add_cmd ("delete", no_class, enable_delete_command, |
| 3916 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 3917 | If a breakpoint is hit while enabled in this fashion, it is deleted.", |
| 3918 | &enablebreaklist); |
| 3919 | |
| 3920 | add_cmd ("delete", no_class, enable_delete_command, |
| 3921 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 3922 | If a breakpoint is hit while enabled in this fashion, it is deleted.", |
| 3923 | &enablelist); |
| 3924 | |
| 3925 | add_cmd ("once", no_class, enable_once_command, |
| 3926 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 3927 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.", |
| 3928 | &enablelist); |
| 3929 | |
| 3930 | add_prefix_cmd ("disable", class_breakpoint, disable_command, |
| 3931 | "Disable some breakpoints.\n\ |
| 3932 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 3933 | To disable all breakpoints, give no argument.\n\ |
| 3934 | A disabled breakpoint is not forgotten, but has no effect until reenabled.", |
| 3935 | &disablelist, "disable ", 1, &cmdlist); |
| 3936 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
| 3937 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
| 3938 | |
| 3939 | add_cmd ("breakpoints", class_alias, disable_command, |
| 3940 | "Disable some breakpoints.\n\ |
| 3941 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 3942 | To disable all breakpoints, give no argument.\n\ |
| 3943 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ |
| 3944 | This command may be abbreviated \"disable\".", |
| 3945 | &disablelist); |
| 3946 | |
| 3947 | add_prefix_cmd ("delete", class_breakpoint, delete_command, |
| 3948 | "Delete some breakpoints or auto-display expressions.\n\ |
| 3949 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 3950 | To delete all breakpoints, give no argument.\n\ |
| 3951 | \n\ |
| 3952 | Also a prefix command for deletion of other GDB objects.\n\ |
| 3953 | The \"unset\" command is also an alias for \"delete\".", |
| 3954 | &deletelist, "delete ", 1, &cmdlist); |
| 3955 | add_com_alias ("d", "delete", class_breakpoint, 1); |
| 3956 | |
| 3957 | add_cmd ("breakpoints", class_alias, delete_command, |
| 3958 | "Delete some breakpoints or auto-display expressions.\n\ |
| 3959 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 3960 | To delete all breakpoints, give no argument.\n\ |
| 3961 | This command may be abbreviated \"delete\".", |
| 3962 | &deletelist); |
| 3963 | |
| 3964 | add_com ("clear", class_breakpoint, clear_command, |
| 3965 | concat ("Clear breakpoint at specified line or function.\n\ |
| 3966 | Argument may be line number, function name, or \"*\" and an address.\n\ |
| 3967 | If line number is specified, all breakpoints in that line are cleared.\n\ |
| 3968 | If function is specified, breakpoints at beginning of function are cleared.\n\ |
| 3969 | If an address is specified, breakpoints at that address are cleared.\n\n", |
| 3970 | "With no argument, clears all breakpoints in the line that the selected frame\n\ |
| 3971 | is executing in.\n\ |
| 3972 | \n\ |
| 3973 | See also the \"delete\" command which clears breakpoints by number.", NULL)); |
| 3974 | |
| 3975 | add_com ("break", class_breakpoint, break_command, |
| 3976 | concat ("Set breakpoint at specified line or function.\n\ |
| 3977 | Argument may be line number, function name, or \"*\" and an address.\n\ |
| 3978 | If line number is specified, break at start of code for that line.\n\ |
| 3979 | If function is specified, break at start of code for that function.\n\ |
| 3980 | If an address is specified, break at that exact address.\n", |
| 3981 | "With no arg, uses current execution address of selected stack frame.\n\ |
| 3982 | This is useful for breaking on return to a stack frame.\n\ |
| 3983 | \n\ |
| 3984 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ |
| 3985 | \n\ |
| 3986 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.", NULL)); |
| 3987 | add_com_alias ("b", "break", class_run, 1); |
| 3988 | add_com_alias ("br", "break", class_run, 1); |
| 3989 | add_com_alias ("bre", "break", class_run, 1); |
| 3990 | add_com_alias ("brea", "break", class_run, 1); |
| 3991 | |
| 3992 | add_info ("breakpoints", breakpoints_info, |
| 3993 | concat ("Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ |
| 3994 | The \"Type\" column indicates one of:\n\ |
| 3995 | \tbreakpoint - normal breakpoint\n\ |
| 3996 | \twatchpoint - watchpoint\n\ |
| 3997 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 3998 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 3999 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 4000 | address and file/line number respectively.\n\n", |
| 4001 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 4002 | are set to the address of the last breakpoint listed.\n\n\ |
| 4003 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 4004 | breakpoint set.", NULL)); |
| 4005 | |
| 4006 | #if MAINTENANCE_CMDS |
| 4007 | |
| 4008 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, |
| 4009 | concat ("Status of all breakpoints, or breakpoint number NUMBER.\n\ |
| 4010 | The \"Type\" column indicates one of:\n\ |
| 4011 | \tbreakpoint - normal breakpoint\n\ |
| 4012 | \twatchpoint - watchpoint\n\ |
| 4013 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ |
| 4014 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ |
| 4015 | \tuntil - internal breakpoint used by the \"until\" command\n\ |
| 4016 | \tfinish - internal breakpoint used by the \"finish\" command\n", |
| 4017 | "The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ |
| 4018 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
| 4019 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ |
| 4020 | address and file/line number respectively.\n\n", |
| 4021 | "Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 4022 | are set to the address of the last breakpoint listed.\n\n\ |
| 4023 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 4024 | breakpoint set.", NULL), |
| 4025 | &maintenanceinfolist); |
| 4026 | |
| 4027 | #endif /* MAINTENANCE_CMDS */ |
| 4028 | |
| 4029 | add_com ("catch", class_breakpoint, catch_command, |
| 4030 | "Set breakpoints to catch exceptions that are raised.\n\ |
| 4031 | Argument may be a single exception to catch, multiple exceptions\n\ |
| 4032 | to catch, or the default exception \"default\". If no arguments\n\ |
| 4033 | are given, breakpoints are set at all exception handlers catch clauses\n\ |
| 4034 | within the current scope.\n\ |
| 4035 | \n\ |
| 4036 | A condition specified for the catch applies to all breakpoints set\n\ |
| 4037 | with this command\n\ |
| 4038 | \n\ |
| 4039 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); |
| 4040 | |
| 4041 | add_com ("watch", class_breakpoint, watch_command, |
| 4042 | "Set a watchpoint for an expression.\n\ |
| 4043 | A watchpoint stops execution of your program whenever the value of\n\ |
| 4044 | an expression changes."); |
| 4045 | |
| 4046 | add_com ("rwatch", class_breakpoint, rwatch_command, |
| 4047 | "Set a read watchpoint for an expression.\n\ |
| 4048 | A watchpoint stops execution of your program whenever the value of\n\ |
| 4049 | an expression is read."); |
| 4050 | |
| 4051 | add_com ("awatch", class_breakpoint, awatch_command, |
| 4052 | "Set a watchpoint for an expression.\n\ |
| 4053 | A watchpoint stops execution of your program whenever the value of\n\ |
| 4054 | an expression is either read or written."); |
| 4055 | |
| 4056 | add_info ("watchpoints", breakpoints_info, |
| 4057 | "Synonym for ``info breakpoints''."); |
| 4058 | |
| 4059 | } |