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