| 1 | /* Everything about breakpoints, for GDB. |
| 2 | Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GDB. |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <ctype.h> |
| 22 | #include "defs.h" |
| 23 | #include "symtab.h" |
| 24 | #include "frame.h" |
| 25 | #include "breakpoint.h" |
| 26 | #include "gdbtypes.h" |
| 27 | #include "expression.h" |
| 28 | #include "gdbcore.h" |
| 29 | #include "gdbcmd.h" |
| 30 | #include "value.h" |
| 31 | #include "ctype.h" |
| 32 | #include "command.h" |
| 33 | #include "inferior.h" |
| 34 | #include "target.h" |
| 35 | #include "language.h" |
| 36 | #include <string.h> |
| 37 | |
| 38 | /* local function prototypes */ |
| 39 | |
| 40 | static void |
| 41 | catch_command_1 PARAMS ((char *, int, int)); |
| 42 | |
| 43 | static void |
| 44 | enable_delete_command PARAMS ((char *, int)); |
| 45 | |
| 46 | static void |
| 47 | enable_delete_breakpoint PARAMS ((struct breakpoint *)); |
| 48 | |
| 49 | static void |
| 50 | enable_once_command PARAMS ((char *, int)); |
| 51 | |
| 52 | static void |
| 53 | enable_once_breakpoint PARAMS ((struct breakpoint *)); |
| 54 | |
| 55 | static void |
| 56 | disable_command PARAMS ((char *, int)); |
| 57 | |
| 58 | static void |
| 59 | disable_breakpoint PARAMS ((struct breakpoint *)); |
| 60 | |
| 61 | static void |
| 62 | enable_command PARAMS ((char *, int)); |
| 63 | |
| 64 | static void |
| 65 | enable_breakpoint PARAMS ((struct breakpoint *)); |
| 66 | |
| 67 | static void |
| 68 | map_breakpoint_numbers PARAMS ((char *, void (*)(struct breakpoint *))); |
| 69 | |
| 70 | static void |
| 71 | ignore_command PARAMS ((char *, int)); |
| 72 | |
| 73 | static int |
| 74 | breakpoint_re_set_one PARAMS ((char *)); |
| 75 | |
| 76 | static void |
| 77 | delete_command PARAMS ((char *, int)); |
| 78 | |
| 79 | static void |
| 80 | clear_command PARAMS ((char *, int)); |
| 81 | |
| 82 | static void |
| 83 | catch_command PARAMS ((char *, int)); |
| 84 | |
| 85 | static struct symtabs_and_lines |
| 86 | get_catch_sals PARAMS ((int)); |
| 87 | |
| 88 | static void |
| 89 | watch_command PARAMS ((char *, int)); |
| 90 | |
| 91 | static void |
| 92 | tbreak_command PARAMS ((char *, int)); |
| 93 | |
| 94 | static void |
| 95 | break_command_1 PARAMS ((char *, int, int)); |
| 96 | |
| 97 | static void |
| 98 | mention PARAMS ((struct breakpoint *)); |
| 99 | |
| 100 | static struct breakpoint * |
| 101 | set_raw_breakpoint PARAMS ((struct symtab_and_line)); |
| 102 | |
| 103 | static void |
| 104 | check_duplicates PARAMS ((CORE_ADDR)); |
| 105 | |
| 106 | static void |
| 107 | describe_other_breakpoints PARAMS ((CORE_ADDR)); |
| 108 | |
| 109 | static void |
| 110 | watchpoints_info PARAMS ((char *, int)); |
| 111 | |
| 112 | static void |
| 113 | breakpoints_info PARAMS ((char *, int)); |
| 114 | |
| 115 | static void |
| 116 | breakpoint_1 PARAMS ((int, enum bptype)); |
| 117 | |
| 118 | static bpstat |
| 119 | bpstat_alloc PARAMS ((struct breakpoint *, bpstat)); |
| 120 | |
| 121 | static int |
| 122 | breakpoint_cond_eval PARAMS ((char *)); |
| 123 | |
| 124 | static void |
| 125 | cleanup_executing_breakpoints PARAMS ((int)); |
| 126 | |
| 127 | static void |
| 128 | commands_command PARAMS ((char *, int)); |
| 129 | |
| 130 | static void |
| 131 | condition_command PARAMS ((char *, int)); |
| 132 | |
| 133 | static int |
| 134 | get_number PARAMS ((char **)); |
| 135 | |
| 136 | static void |
| 137 | set_breakpoint_count PARAMS ((int)); |
| 138 | |
| 139 | |
| 140 | extern int addressprint; /* Print machine addresses? */ |
| 141 | extern int demangle; /* Print de-mangled symbol names? */ |
| 142 | |
| 143 | /* Are we executing breakpoint commands? */ |
| 144 | static int executing_breakpoint_commands; |
| 145 | |
| 146 | /* Walk the following statement or block through all breakpoints. |
| 147 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current |
| 148 | breakpoint. */ |
| 149 | |
| 150 | #define ALL_BREAKPOINTS(b) for (b = breakpoint_chain; b; b = b->next) |
| 151 | |
| 152 | #define ALL_BREAKPOINTS_SAFE(b,tmp) \ |
| 153 | for (b = breakpoint_chain; \ |
| 154 | b? (tmp=b->next, 1): 0; \ |
| 155 | b = tmp) |
| 156 | |
| 157 | /* Chain of all breakpoints defined. */ |
| 158 | |
| 159 | struct breakpoint *breakpoint_chain; |
| 160 | |
| 161 | /* Number of last breakpoint made. */ |
| 162 | |
| 163 | static int breakpoint_count; |
| 164 | |
| 165 | /* Set breakpoint count to NUM. */ |
| 166 | static void |
| 167 | set_breakpoint_count (num) |
| 168 | int num; |
| 169 | { |
| 170 | breakpoint_count = num; |
| 171 | set_internalvar (lookup_internalvar ("bpnum"), |
| 172 | value_from_longest (builtin_type_int, (LONGEST) num)); |
| 173 | } |
| 174 | |
| 175 | /* Default address, symtab and line to put a breakpoint at |
| 176 | for "break" command with no arg. |
| 177 | if default_breakpoint_valid is zero, the other three are |
| 178 | not valid, and "break" with no arg is an error. |
| 179 | |
| 180 | This set by print_stack_frame, which calls set_default_breakpoint. */ |
| 181 | |
| 182 | int default_breakpoint_valid; |
| 183 | CORE_ADDR default_breakpoint_address; |
| 184 | struct symtab *default_breakpoint_symtab; |
| 185 | int default_breakpoint_line; |
| 186 | |
| 187 | /* Flag indicating extra verbosity for xgdb. */ |
| 188 | extern int xgdb_verbose; |
| 189 | \f |
| 190 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. |
| 191 | Advance *PP after the string and any trailing whitespace. |
| 192 | |
| 193 | Currently the string can either be a number or "$" followed by the name |
| 194 | of a convenience variable. Making it an expression wouldn't work well |
| 195 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). */ |
| 196 | static int |
| 197 | get_number (pp) |
| 198 | char **pp; |
| 199 | { |
| 200 | int retval; |
| 201 | char *p = *pp; |
| 202 | |
| 203 | if (p == NULL) |
| 204 | /* Empty line means refer to the last breakpoint. */ |
| 205 | return breakpoint_count; |
| 206 | else if (*p == '$') |
| 207 | { |
| 208 | /* Make a copy of the name, so we can null-terminate it |
| 209 | to pass to lookup_internalvar(). */ |
| 210 | char *varname; |
| 211 | char *start = ++p; |
| 212 | value val; |
| 213 | |
| 214 | while (isalnum (*p) || *p == '_') |
| 215 | p++; |
| 216 | varname = (char *) alloca (p - start + 1); |
| 217 | strncpy (varname, start, p - start); |
| 218 | varname[p - start] = '\0'; |
| 219 | val = value_of_internalvar (lookup_internalvar (varname)); |
| 220 | if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT) |
| 221 | error ( |
| 222 | "Convenience variables used to specify breakpoints must have integer values." |
| 223 | ); |
| 224 | retval = (int) value_as_long (val); |
| 225 | } |
| 226 | else |
| 227 | { |
| 228 | while (*p >= '0' && *p <= '9') |
| 229 | ++p; |
| 230 | if (p == *pp) |
| 231 | /* There is no number here. (e.g. "cond a == b"). */ |
| 232 | error_no_arg ("breakpoint number"); |
| 233 | retval = atoi (*pp); |
| 234 | } |
| 235 | if (!(isspace (*p) || *p == '\0')) |
| 236 | error ("breakpoint number expected"); |
| 237 | while (isspace (*p)) |
| 238 | p++; |
| 239 | *pp = p; |
| 240 | return retval; |
| 241 | } |
| 242 | \f |
| 243 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
| 244 | |
| 245 | static void |
| 246 | condition_command (arg, from_tty) |
| 247 | char *arg; |
| 248 | int from_tty; |
| 249 | { |
| 250 | register struct breakpoint *b; |
| 251 | char *p; |
| 252 | register int bnum; |
| 253 | |
| 254 | if (arg == 0) |
| 255 | error_no_arg ("breakpoint number"); |
| 256 | |
| 257 | p = arg; |
| 258 | bnum = get_number (&p); |
| 259 | |
| 260 | ALL_BREAKPOINTS (b) |
| 261 | if (b->number == bnum) |
| 262 | { |
| 263 | if (b->cond) |
| 264 | { |
| 265 | free (b->cond); |
| 266 | b->cond = 0; |
| 267 | } |
| 268 | if (b->cond_string != NULL) |
| 269 | free (b->cond_string); |
| 270 | |
| 271 | if (*p == 0) |
| 272 | { |
| 273 | b->cond = 0; |
| 274 | b->cond_string = NULL; |
| 275 | if (from_tty) |
| 276 | printf ("Breakpoint %d now unconditional.\n", bnum); |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | arg = p; |
| 281 | /* I don't know if it matters whether this is the string the user |
| 282 | typed in or the decompiled expression. */ |
| 283 | b->cond_string = savestring (arg, strlen (arg)); |
| 284 | b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0); |
| 285 | if (*arg) |
| 286 | error ("Junk at end of expression"); |
| 287 | } |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | error ("No breakpoint number %d.", bnum); |
| 292 | } |
| 293 | |
| 294 | /* ARGSUSED */ |
| 295 | static void |
| 296 | commands_command (arg, from_tty) |
| 297 | char *arg; |
| 298 | int from_tty; |
| 299 | { |
| 300 | register struct breakpoint *b; |
| 301 | char *p; |
| 302 | register int bnum; |
| 303 | struct command_line *l; |
| 304 | |
| 305 | /* If we allowed this, we would have problems with when to |
| 306 | free the storage, if we change the commands currently |
| 307 | being read from. */ |
| 308 | |
| 309 | if (executing_breakpoint_commands) |
| 310 | error ("Can't use the \"commands\" command among a breakpoint's commands."); |
| 311 | |
| 312 | p = arg; |
| 313 | bnum = get_number (&p); |
| 314 | if (p && *p) |
| 315 | error ("Unexpected extra arguments following breakpoint number."); |
| 316 | |
| 317 | ALL_BREAKPOINTS (b) |
| 318 | if (b->number == bnum) |
| 319 | { |
| 320 | if (from_tty && input_from_terminal_p ()) |
| 321 | { |
| 322 | printf ("Type commands for when breakpoint %d is hit, one per line.\n\ |
| 323 | End with a line saying just \"end\".\n", bnum); |
| 324 | fflush (stdout); |
| 325 | } |
| 326 | l = read_command_lines (); |
| 327 | free_command_lines (&b->commands); |
| 328 | b->commands = l; |
| 329 | return; |
| 330 | } |
| 331 | error ("No breakpoint number %d.", bnum); |
| 332 | } |
| 333 | \f |
| 334 | extern int memory_breakpoint_size; /* from mem-break.c */ |
| 335 | |
| 336 | /* Like target_read_memory() but if breakpoints are inserted, return |
| 337 | the shadow contents instead of the breakpoints themselves. |
| 338 | |
| 339 | Read "memory data" from whatever target or inferior we have. |
| 340 | Returns zero if successful, errno value if not. EIO is used |
| 341 | for address out of bounds. If breakpoints are inserted, returns |
| 342 | shadow contents, not the breakpoints themselves. From breakpoint.c. */ |
| 343 | |
| 344 | int |
| 345 | read_memory_nobpt (memaddr, myaddr, len) |
| 346 | CORE_ADDR memaddr; |
| 347 | char *myaddr; |
| 348 | unsigned len; |
| 349 | { |
| 350 | int status; |
| 351 | struct breakpoint *b; |
| 352 | |
| 353 | if (memory_breakpoint_size < 0) |
| 354 | /* No breakpoints on this machine. */ |
| 355 | return target_read_memory (memaddr, myaddr, len); |
| 356 | |
| 357 | ALL_BREAKPOINTS (b) |
| 358 | { |
| 359 | if (b->type == bp_watchpoint || !b->inserted) |
| 360 | continue; |
| 361 | else if (b->address + memory_breakpoint_size <= memaddr) |
| 362 | /* The breakpoint is entirely before the chunk of memory |
| 363 | we are reading. */ |
| 364 | continue; |
| 365 | else if (b->address >= memaddr + len) |
| 366 | /* The breakpoint is entirely after the chunk of memory we |
| 367 | are reading. */ |
| 368 | continue; |
| 369 | else |
| 370 | { |
| 371 | /* Copy the breakpoint from the shadow contents, and recurse |
| 372 | for the things before and after. */ |
| 373 | |
| 374 | /* Addresses and length of the part of the breakpoint that |
| 375 | we need to copy. */ |
| 376 | CORE_ADDR membpt = b->address; |
| 377 | unsigned int bptlen = memory_breakpoint_size; |
| 378 | /* Offset within shadow_contents. */ |
| 379 | int bptoffset = 0; |
| 380 | |
| 381 | if (membpt < memaddr) |
| 382 | { |
| 383 | /* Only copy the second part of the breakpoint. */ |
| 384 | bptlen -= memaddr - membpt; |
| 385 | bptoffset = memaddr - membpt; |
| 386 | membpt = memaddr; |
| 387 | } |
| 388 | |
| 389 | if (membpt + bptlen > memaddr + len) |
| 390 | { |
| 391 | /* Only copy the first part of the breakpoint. */ |
| 392 | bptlen -= (membpt + bptlen) - (memaddr + len); |
| 393 | } |
| 394 | |
| 395 | bcopy (b->shadow_contents + bptoffset, |
| 396 | myaddr + membpt - memaddr, bptlen); |
| 397 | |
| 398 | if (membpt > memaddr) |
| 399 | { |
| 400 | /* Copy the section of memory before the breakpoint. */ |
| 401 | status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr); |
| 402 | if (status != 0) |
| 403 | return status; |
| 404 | } |
| 405 | |
| 406 | if (membpt + bptlen < memaddr + len) |
| 407 | { |
| 408 | /* Copy the section of memory after the breakpoint. */ |
| 409 | status = read_memory_nobpt |
| 410 | (membpt + bptlen, |
| 411 | myaddr + membpt + bptlen - memaddr, |
| 412 | memaddr + len - (membpt + bptlen)); |
| 413 | if (status != 0) |
| 414 | return status; |
| 415 | } |
| 416 | return 0; |
| 417 | } |
| 418 | } |
| 419 | /* Nothing overlaps. Just call read_memory_noerr. */ |
| 420 | return target_read_memory (memaddr, myaddr, len); |
| 421 | } |
| 422 | \f |
| 423 | /* insert_breakpoints is used when starting or continuing the program. |
| 424 | remove_breakpoints is used when the program stops. |
| 425 | Both return zero if successful, |
| 426 | or an `errno' value if could not write the inferior. */ |
| 427 | |
| 428 | int |
| 429 | insert_breakpoints () |
| 430 | { |
| 431 | register struct breakpoint *b; |
| 432 | int val = 0; |
| 433 | int disabled_breaks = 0; |
| 434 | |
| 435 | ALL_BREAKPOINTS (b) |
| 436 | if (b->type != bp_watchpoint |
| 437 | && b->enable != disabled |
| 438 | && ! b->inserted |
| 439 | && ! b->duplicate) |
| 440 | { |
| 441 | val = target_insert_breakpoint(b->address, b->shadow_contents); |
| 442 | if (val) |
| 443 | { |
| 444 | /* Can't set the breakpoint. */ |
| 445 | #if defined (DISABLE_UNSETTABLE_BREAK) |
| 446 | if (DISABLE_UNSETTABLE_BREAK (b->address)) |
| 447 | { |
| 448 | val = 0; |
| 449 | b->enable = disabled; |
| 450 | if (!disabled_breaks) |
| 451 | { |
| 452 | fprintf (stderr, |
| 453 | "Cannot insert breakpoint %d:\n", b->number); |
| 454 | printf_filtered ("Disabling shared library breakpoints:\n"); |
| 455 | } |
| 456 | disabled_breaks = 1; |
| 457 | printf_filtered ("%d ", b->number); |
| 458 | } |
| 459 | else |
| 460 | #endif |
| 461 | { |
| 462 | fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number); |
| 463 | #ifdef ONE_PROCESS_WRITETEXT |
| 464 | fprintf (stderr, |
| 465 | "The same program may be running in another process.\n"); |
| 466 | #endif |
| 467 | memory_error (val, b->address); /* which bombs us out */ |
| 468 | } |
| 469 | } |
| 470 | else |
| 471 | b->inserted = 1; |
| 472 | } |
| 473 | if (disabled_breaks) |
| 474 | printf_filtered ("\n"); |
| 475 | return val; |
| 476 | } |
| 477 | |
| 478 | int |
| 479 | remove_breakpoints () |
| 480 | { |
| 481 | register struct breakpoint *b; |
| 482 | int val; |
| 483 | |
| 484 | #ifdef BREAKPOINT_DEBUG |
| 485 | printf ("Removing breakpoints.\n"); |
| 486 | #endif /* BREAKPOINT_DEBUG */ |
| 487 | |
| 488 | ALL_BREAKPOINTS (b) |
| 489 | if (b->type != bp_watchpoint && b->inserted) |
| 490 | { |
| 491 | val = target_remove_breakpoint(b->address, b->shadow_contents); |
| 492 | if (val) |
| 493 | return val; |
| 494 | b->inserted = 0; |
| 495 | #ifdef BREAKPOINT_DEBUG |
| 496 | printf ("Removed breakpoint at %s", |
| 497 | local_hex_string(b->address)); |
| 498 | printf (", shadow %s", |
| 499 | local_hex_string(b->shadow_contents[0])); |
| 500 | printf (", %s.\n", |
| 501 | local_hex_string(b->shadow_contents[1])); |
| 502 | #endif /* BREAKPOINT_DEBUG */ |
| 503 | } |
| 504 | |
| 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | /* Clear the "inserted" flag in all breakpoints. |
| 509 | This is done when the inferior is loaded. */ |
| 510 | |
| 511 | void |
| 512 | mark_breakpoints_out () |
| 513 | { |
| 514 | register struct breakpoint *b; |
| 515 | |
| 516 | ALL_BREAKPOINTS (b) |
| 517 | b->inserted = 0; |
| 518 | } |
| 519 | |
| 520 | /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC. |
| 521 | When continuing from a location with a breakpoint, |
| 522 | we actually single step once before calling insert_breakpoints. */ |
| 523 | |
| 524 | int |
| 525 | breakpoint_here_p (pc) |
| 526 | CORE_ADDR pc; |
| 527 | { |
| 528 | register struct breakpoint *b; |
| 529 | |
| 530 | ALL_BREAKPOINTS (b) |
| 531 | if (b->enable != disabled && b->address == pc) |
| 532 | return 1; |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | \f |
| 537 | /* bpstat stuff. External routines' interfaces are documented |
| 538 | in breakpoint.h. */ |
| 539 | |
| 540 | /* Clear a bpstat so that it says we are not at any breakpoint. |
| 541 | Also free any storage that is part of a bpstat. */ |
| 542 | |
| 543 | void |
| 544 | bpstat_clear (bsp) |
| 545 | bpstat *bsp; |
| 546 | { |
| 547 | bpstat p; |
| 548 | bpstat q; |
| 549 | |
| 550 | if (bsp == 0) |
| 551 | return; |
| 552 | p = *bsp; |
| 553 | while (p != NULL) |
| 554 | { |
| 555 | q = p->next; |
| 556 | if (p->old_val != NULL) |
| 557 | value_free (p->old_val); |
| 558 | free (p); |
| 559 | p = q; |
| 560 | } |
| 561 | *bsp = NULL; |
| 562 | } |
| 563 | |
| 564 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that |
| 565 | is part of the bpstat is copied as well. */ |
| 566 | |
| 567 | bpstat |
| 568 | bpstat_copy (bs) |
| 569 | bpstat bs; |
| 570 | { |
| 571 | bpstat p = NULL; |
| 572 | bpstat tmp; |
| 573 | bpstat retval; |
| 574 | |
| 575 | if (bs == NULL) |
| 576 | return bs; |
| 577 | |
| 578 | for (; bs != NULL; bs = bs->next) |
| 579 | { |
| 580 | tmp = (bpstat) xmalloc (sizeof (*tmp)); |
| 581 | bcopy (bs, tmp, sizeof (*tmp)); |
| 582 | if (p == NULL) |
| 583 | /* This is the first thing in the chain. */ |
| 584 | retval = tmp; |
| 585 | else |
| 586 | p->next = tmp; |
| 587 | p = tmp; |
| 588 | } |
| 589 | p->next = NULL; |
| 590 | return retval; |
| 591 | } |
| 592 | |
| 593 | /* Find the bpstat associated with this breakpoint */ |
| 594 | |
| 595 | bpstat |
| 596 | bpstat_find_breakpoint(bsp, breakpoint) |
| 597 | bpstat bsp; |
| 598 | struct breakpoint *breakpoint; |
| 599 | { |
| 600 | if (bsp == NULL) return NULL; |
| 601 | |
| 602 | for (;bsp != NULL; bsp = bsp->next) { |
| 603 | if (bsp->breakpoint_at == breakpoint) return bsp; |
| 604 | } |
| 605 | return NULL; |
| 606 | } |
| 607 | |
| 608 | /* Return the breakpoint number of the first breakpoint we are stopped |
| 609 | at. *BSP upon return is a bpstat which points to the remaining |
| 610 | breakpoints stopped at (but which is not guaranteed to be good for |
| 611 | anything but further calls to bpstat_num). |
| 612 | Return 0 if passed a bpstat which does not indicate any breakpoints. */ |
| 613 | |
| 614 | int |
| 615 | bpstat_num (bsp) |
| 616 | bpstat *bsp; |
| 617 | { |
| 618 | struct breakpoint *b; |
| 619 | |
| 620 | if ((*bsp) == NULL) |
| 621 | return 0; /* No more breakpoint values */ |
| 622 | else |
| 623 | { |
| 624 | b = (*bsp)->breakpoint_at; |
| 625 | *bsp = (*bsp)->next; |
| 626 | if (b == NULL) |
| 627 | return -1; /* breakpoint that's been deleted since */ |
| 628 | else |
| 629 | return b->number; /* We have its number */ |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | /* Modify BS so that the actions will not be performed. */ |
| 634 | |
| 635 | void |
| 636 | bpstat_clear_actions (bs) |
| 637 | bpstat bs; |
| 638 | { |
| 639 | for (; bs != NULL; bs = bs->next) |
| 640 | { |
| 641 | bs->commands = NULL; |
| 642 | if (bs->old_val != NULL) |
| 643 | { |
| 644 | value_free (bs->old_val); |
| 645 | bs->old_val = NULL; |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
| 651 | /* ARGSUSED */ |
| 652 | static void |
| 653 | cleanup_executing_breakpoints (ignore) |
| 654 | int ignore; |
| 655 | { |
| 656 | executing_breakpoint_commands = 0; |
| 657 | } |
| 658 | |
| 659 | /* Execute all the commands associated with all the breakpoints at this |
| 660 | location. Any of these commands could cause the process to proceed |
| 661 | beyond this point, etc. We look out for such changes by checking |
| 662 | the global "breakpoint_proceeded" after each command. */ |
| 663 | |
| 664 | void |
| 665 | bpstat_do_actions (bsp) |
| 666 | bpstat *bsp; |
| 667 | { |
| 668 | bpstat bs; |
| 669 | struct cleanup *old_chain; |
| 670 | |
| 671 | executing_breakpoint_commands = 1; |
| 672 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); |
| 673 | |
| 674 | top: |
| 675 | bs = *bsp; |
| 676 | |
| 677 | breakpoint_proceeded = 0; |
| 678 | for (; bs != NULL; bs = bs->next) |
| 679 | { |
| 680 | while (bs->commands) |
| 681 | { |
| 682 | char *line = bs->commands->line; |
| 683 | bs->commands = bs->commands->next; |
| 684 | execute_command (line, 0); |
| 685 | /* If the inferior is proceeded by the command, bomb out now. |
| 686 | The bpstat chain has been blown away by wait_for_inferior. |
| 687 | But since execution has stopped again, there is a new bpstat |
| 688 | to look at, so start over. */ |
| 689 | if (breakpoint_proceeded) |
| 690 | goto top; |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | executing_breakpoint_commands = 0; |
| 695 | discard_cleanups (old_chain); |
| 696 | } |
| 697 | |
| 698 | /* Print a message indicating what happened. Returns nonzero to |
| 699 | say that only the source line should be printed after this (zero |
| 700 | return means print the frame as well as the source line). */ |
| 701 | |
| 702 | int |
| 703 | bpstat_print (bs) |
| 704 | bpstat bs; |
| 705 | { |
| 706 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
| 707 | which has since been deleted. */ |
| 708 | if (bs == NULL |
| 709 | || bs->breakpoint_at == NULL |
| 710 | || (bs->breakpoint_at->type != bp_breakpoint |
| 711 | && bs->breakpoint_at->type != bp_watchpoint)) |
| 712 | return 0; |
| 713 | |
| 714 | /* If bpstat_stop_status says don't print, OK, we won't. An example |
| 715 | circumstance is when we single-stepped for both a watchpoint and |
| 716 | for a "stepi" instruction. The bpstat says that the watchpoint |
| 717 | explains the stop, but we shouldn't print because the watchpoint's |
| 718 | value didn't change -- and the real reason we are stopping here |
| 719 | rather than continuing to step (as the watchpoint would've had us do) |
| 720 | is because of the "stepi". */ |
| 721 | if (!bs->print) |
| 722 | return 0; |
| 723 | |
| 724 | if (bs->breakpoint_at->type == bp_breakpoint) |
| 725 | { |
| 726 | /* I think the user probably only wants to see one breakpoint |
| 727 | number, not all of them. */ |
| 728 | printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number); |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | if (bs->old_val != NULL) |
| 733 | { |
| 734 | printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number); |
| 735 | print_expression (bs->breakpoint_at->exp, stdout); |
| 736 | printf_filtered ("\nOld value = "); |
| 737 | value_print (bs->old_val, stdout, 0, Val_pretty_default); |
| 738 | printf_filtered ("\nNew value = "); |
| 739 | value_print (bs->breakpoint_at->val, stdout, 0, |
| 740 | Val_pretty_default); |
| 741 | printf_filtered ("\n"); |
| 742 | value_free (bs->old_val); |
| 743 | bs->old_val = NULL; |
| 744 | return 1; |
| 745 | } |
| 746 | |
| 747 | /* Maybe another breakpoint in the chain caused us to stop. |
| 748 | (Currently all watchpoints go on the bpstat whether hit or |
| 749 | not. That probably could (should) be changed, provided care is taken |
| 750 | with respect to bpstat_explains_signal). */ |
| 751 | if (bs->next) |
| 752 | return bpstat_print (bs->next); |
| 753 | |
| 754 | fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n"); |
| 755 | return 0; |
| 756 | } |
| 757 | |
| 758 | /* Evaluate the expression EXP and return 1 if value is zero. |
| 759 | This is used inside a catch_errors to evaluate the breakpoint condition. |
| 760 | The argument is a "struct expression *" that has been cast to char * to |
| 761 | make it pass through catch_errors. */ |
| 762 | |
| 763 | static int |
| 764 | breakpoint_cond_eval (exp) |
| 765 | char *exp; |
| 766 | { |
| 767 | return !value_true (evaluate_expression ((struct expression *)exp)); |
| 768 | } |
| 769 | |
| 770 | /* Allocate a new bpstat and chain it to the current one. */ |
| 771 | |
| 772 | static bpstat |
| 773 | bpstat_alloc (b, cbs) |
| 774 | register struct breakpoint *b; |
| 775 | bpstat cbs; /* Current "bs" value */ |
| 776 | { |
| 777 | bpstat bs; |
| 778 | |
| 779 | bs = (bpstat) xmalloc (sizeof (*bs)); |
| 780 | cbs->next = bs; |
| 781 | bs->breakpoint_at = b; |
| 782 | /* If the condition is false, etc., don't do the commands. */ |
| 783 | bs->commands = NULL; |
| 784 | bs->momentary = b->disposition == delete; |
| 785 | bs->old_val = NULL; |
| 786 | return bs; |
| 787 | } |
| 788 | |
| 789 | /* Determine whether we stopped at a breakpoint, etc, or whether we |
| 790 | don't understand this stop. Result is a chain of bpstat's such that: |
| 791 | |
| 792 | if we don't understand the stop, the result is a null pointer. |
| 793 | |
| 794 | if we understand why we stopped, the result is not null, and |
| 795 | the first element of the chain contains summary "stop" and |
| 796 | "print" flags for the whole chain. |
| 797 | |
| 798 | Each element of the chain refers to a particular breakpoint or |
| 799 | watchpoint at which we have stopped. (We may have stopped for |
| 800 | several reasons.) |
| 801 | |
| 802 | Each element of the chain has valid next, breakpoint_at, |
| 803 | commands, FIXME??? fields. |
| 804 | |
| 805 | */ |
| 806 | |
| 807 | |
| 808 | bpstat |
| 809 | bpstat_stop_status (pc, frame_address) |
| 810 | CORE_ADDR *pc; |
| 811 | FRAME_ADDR frame_address; |
| 812 | { |
| 813 | register struct breakpoint *b; |
| 814 | int stop = 0; |
| 815 | int print = 0; |
| 816 | CORE_ADDR bp_addr; |
| 817 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
| 818 | /* True if we've hit a breakpoint (as opposed to a watchpoint). */ |
| 819 | int real_breakpoint = 0; |
| 820 | #endif |
| 821 | /* Root of the chain of bpstat's */ |
| 822 | struct bpstat root_bs[1]; |
| 823 | /* Pointer to the last thing in the chain currently. */ |
| 824 | bpstat bs = root_bs; |
| 825 | |
| 826 | /* Get the address where the breakpoint would have been. */ |
| 827 | bp_addr = *pc - DECR_PC_AFTER_BREAK; |
| 828 | |
| 829 | ALL_BREAKPOINTS (b) |
| 830 | { |
| 831 | int this_bp_stop; |
| 832 | int this_bp_print; |
| 833 | |
| 834 | if (b->enable == disabled) |
| 835 | continue; |
| 836 | |
| 837 | if (b->type != bp_watchpoint && b->address != bp_addr) |
| 838 | continue; |
| 839 | |
| 840 | /* Come here if it's a watchpoint, or if the break address matches */ |
| 841 | |
| 842 | bs = bpstat_alloc (b, bs); /* Alloc a bpstat to explain stop */ |
| 843 | |
| 844 | this_bp_stop = 1; |
| 845 | this_bp_print = 1; |
| 846 | |
| 847 | if (b->type == bp_watchpoint) |
| 848 | { |
| 849 | int within_current_scope; |
| 850 | if (b->exp_valid_block != NULL) |
| 851 | within_current_scope = |
| 852 | contained_in (get_selected_block (), b->exp_valid_block); |
| 853 | else |
| 854 | within_current_scope = 1; |
| 855 | |
| 856 | if (within_current_scope) |
| 857 | { |
| 858 | /* We use value_{,free_to_}mark because it could be a |
| 859 | *long* time before we return to the command level and |
| 860 | call free_all_values. */ |
| 861 | |
| 862 | value mark = value_mark (); |
| 863 | value new_val = evaluate_expression (b->exp); |
| 864 | if (!value_equal (b->val, new_val)) |
| 865 | { |
| 866 | release_value (new_val); |
| 867 | value_free_to_mark (mark); |
| 868 | bs->old_val = b->val; |
| 869 | b->val = new_val; |
| 870 | /* We will stop here */ |
| 871 | } |
| 872 | else |
| 873 | { |
| 874 | /* Nothing changed, don't do anything. */ |
| 875 | value_free_to_mark (mark); |
| 876 | continue; |
| 877 | /* We won't stop here */ |
| 878 | } |
| 879 | } |
| 880 | else |
| 881 | { |
| 882 | /* This seems like the only logical thing to do because |
| 883 | if we temporarily ignored the watchpoint, then when |
| 884 | we reenter the block in which it is valid it contains |
| 885 | garbage (in the case of a function, it may have two |
| 886 | garbage values, one before and one after the prologue). |
| 887 | So we can't even detect the first assignment to it and |
| 888 | watch after that (since the garbage may or may not equal |
| 889 | the first value assigned). */ |
| 890 | b->enable = disabled; |
| 891 | printf_filtered ("\ |
| 892 | Watchpoint %d disabled because the program has left the block in\n\ |
| 893 | which its expression is valid.\n", b->number); |
| 894 | /* We won't stop here */ |
| 895 | /* FIXME, maybe we should stop here!!! */ |
| 896 | continue; |
| 897 | } |
| 898 | } |
| 899 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
| 900 | else |
| 901 | real_breakpoint = 1; |
| 902 | #endif |
| 903 | |
| 904 | if (b->frame && b->frame != frame_address) |
| 905 | this_bp_stop = 0; |
| 906 | else |
| 907 | { |
| 908 | int value_is_zero; |
| 909 | |
| 910 | if (b->cond) |
| 911 | { |
| 912 | /* Need to select the frame, with all that implies |
| 913 | so that the conditions will have the right context. */ |
| 914 | select_frame (get_current_frame (), 0); |
| 915 | value_is_zero |
| 916 | = catch_errors (breakpoint_cond_eval, (char *)(b->cond), |
| 917 | "Error in testing breakpoint condition:\n"); |
| 918 | /* FIXME-someday, should give breakpoint # */ |
| 919 | free_all_values (); |
| 920 | } |
| 921 | if (b->cond && value_is_zero) |
| 922 | { |
| 923 | this_bp_stop = 0; |
| 924 | } |
| 925 | else if (b->ignore_count > 0) |
| 926 | { |
| 927 | b->ignore_count--; |
| 928 | this_bp_stop = 0; |
| 929 | } |
| 930 | else |
| 931 | { |
| 932 | /* We will stop here */ |
| 933 | if (b->disposition == disable) |
| 934 | b->enable = disabled; |
| 935 | bs->commands = b->commands; |
| 936 | if (b->silent) |
| 937 | this_bp_print = 0; |
| 938 | if (bs->commands && !strcmp ("silent", bs->commands->line)) |
| 939 | { |
| 940 | bs->commands = bs->commands->next; |
| 941 | this_bp_print = 0; |
| 942 | } |
| 943 | } |
| 944 | } |
| 945 | if (this_bp_stop) |
| 946 | stop = 1; |
| 947 | if (this_bp_print) |
| 948 | print = 1; |
| 949 | } |
| 950 | |
| 951 | bs->next = NULL; /* Terminate the chain */ |
| 952 | bs = root_bs->next; /* Re-grab the head of the chain */ |
| 953 | if (bs) |
| 954 | { |
| 955 | bs->stop = stop; |
| 956 | bs->print = print; |
| 957 | #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS) |
| 958 | if (real_breakpoint) |
| 959 | { |
| 960 | *pc = bp_addr; |
| 961 | #if defined (SHIFT_INST_REGS) |
| 962 | { |
| 963 | CORE_ADDR pc = read_register (PC_REGNUM); |
| 964 | CORE_ADDR npc = read_register (NPC_REGNUM); |
| 965 | if (pc != npc) |
| 966 | { |
| 967 | write_register (NNPC_REGNUM, npc); |
| 968 | write_register (NPC_REGNUM, pc); |
| 969 | } |
| 970 | } |
| 971 | #else /* No SHIFT_INST_REGS. */ |
| 972 | write_pc (bp_addr); |
| 973 | #endif /* No SHIFT_INST_REGS. */ |
| 974 | } |
| 975 | #endif /* DECR_PC_AFTER_BREAK != 0. */ |
| 976 | } |
| 977 | return bs; |
| 978 | } |
| 979 | |
| 980 | /* Nonzero if we should step constantly (e.g. watchpoints on machines |
| 981 | without hardware support). This isn't related to a specific bpstat, |
| 982 | just to things like whether watchpoints are set. */ |
| 983 | |
| 984 | int |
| 985 | bpstat_should_step () |
| 986 | { |
| 987 | struct breakpoint *b; |
| 988 | ALL_BREAKPOINTS (b) |
| 989 | if (b->enable == enabled && b->type == bp_watchpoint) |
| 990 | return 1; |
| 991 | return 0; |
| 992 | } |
| 993 | \f |
| 994 | /* Print information on breakpoint number BNUM, or -1 if all. |
| 995 | If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS |
| 996 | is nonzero, process only watchpoints. */ |
| 997 | |
| 998 | static void |
| 999 | breakpoint_1 (bnum, type) |
| 1000 | int bnum; |
| 1001 | enum bptype type; |
| 1002 | { |
| 1003 | register struct breakpoint *b; |
| 1004 | register struct command_line *l; |
| 1005 | register struct symbol *sym; |
| 1006 | CORE_ADDR last_addr = (CORE_ADDR)-1; |
| 1007 | int found_a_breakpoint = 0; |
| 1008 | static char *bptypes[] = {"breakpoint", "until", "finish", "watchpoint", |
| 1009 | "longjmp", "longjmp resume"}; |
| 1010 | static char *bpdisps[] = {"del", "dis", ""}; |
| 1011 | static char bpenables[] = "ny"; |
| 1012 | |
| 1013 | if (!breakpoint_chain) |
| 1014 | { |
| 1015 | printf_filtered ("No breakpoints or watchpoints.\n"); |
| 1016 | return; |
| 1017 | } |
| 1018 | |
| 1019 | ALL_BREAKPOINTS (b) |
| 1020 | if (bnum == -1 |
| 1021 | || bnum == b->number) |
| 1022 | { |
| 1023 | if (!found_a_breakpoint++) |
| 1024 | printf_filtered ("Num Type Disp Enb %sWhat\n", |
| 1025 | addressprint ? "Address " : ""); |
| 1026 | |
| 1027 | printf_filtered ("%-3d %-10s %-4s %-3c ", |
| 1028 | b->number, |
| 1029 | bptypes[b->type], |
| 1030 | bpdisps[b->disposition], |
| 1031 | bpenables[b->enable]); |
| 1032 | switch (b->type) |
| 1033 | { |
| 1034 | case bp_watchpoint: |
| 1035 | print_expression (b->exp, stdout); |
| 1036 | break; |
| 1037 | case bp_breakpoint: |
| 1038 | if (addressprint) |
| 1039 | printf_filtered ("%s ", local_hex_string_custom(b->address, "08")); |
| 1040 | |
| 1041 | last_addr = b->address; |
| 1042 | if (b->symtab) |
| 1043 | { |
| 1044 | sym = find_pc_function (b->address); |
| 1045 | if (sym) |
| 1046 | { |
| 1047 | fputs_filtered ("in ", stdout); |
| 1048 | fputs_demangled (SYMBOL_NAME (sym), stdout, 1); |
| 1049 | fputs_filtered (" at ", stdout); |
| 1050 | } |
| 1051 | fputs_filtered (b->symtab->filename, stdout); |
| 1052 | printf_filtered (":%d", b->line_number); |
| 1053 | } |
| 1054 | else |
| 1055 | print_address_symbolic (b->address, stdout, demangle, " "); |
| 1056 | } |
| 1057 | |
| 1058 | printf_filtered ("\n"); |
| 1059 | |
| 1060 | if (b->frame) |
| 1061 | printf_filtered ("\tstop only in stack frame at %s\n", |
| 1062 | local_hex_string(b->frame)); |
| 1063 | if (b->cond) |
| 1064 | { |
| 1065 | printf_filtered ("\tstop only if "); |
| 1066 | print_expression (b->cond, stdout); |
| 1067 | printf_filtered ("\n"); |
| 1068 | } |
| 1069 | if (b->ignore_count) |
| 1070 | printf_filtered ("\tignore next %d hits\n", b->ignore_count); |
| 1071 | if ((l = b->commands)) |
| 1072 | while (l) |
| 1073 | { |
| 1074 | fputs_filtered ("\t", stdout); |
| 1075 | fputs_filtered (l->line, stdout); |
| 1076 | fputs_filtered ("\n", stdout); |
| 1077 | l = l->next; |
| 1078 | } |
| 1079 | } |
| 1080 | |
| 1081 | if (!found_a_breakpoint |
| 1082 | && bnum != -1) |
| 1083 | printf_filtered ("No breakpoint or watchpoint number %d.\n", bnum); |
| 1084 | else |
| 1085 | /* Compare against (CORE_ADDR)-1 in case some compiler decides |
| 1086 | that a comparison of an unsigned with -1 is always false. */ |
| 1087 | if (last_addr != (CORE_ADDR)-1) |
| 1088 | set_next_address (last_addr); |
| 1089 | } |
| 1090 | |
| 1091 | /* ARGSUSED */ |
| 1092 | static void |
| 1093 | breakpoints_info (bnum_exp, from_tty) |
| 1094 | char *bnum_exp; |
| 1095 | int from_tty; |
| 1096 | { |
| 1097 | int bnum = -1; |
| 1098 | |
| 1099 | if (bnum_exp) |
| 1100 | bnum = parse_and_eval_address (bnum_exp); |
| 1101 | |
| 1102 | breakpoint_1 (bnum, bp_breakpoint); |
| 1103 | } |
| 1104 | |
| 1105 | /* ARGSUSED */ |
| 1106 | static void |
| 1107 | watchpoints_info (bnum_exp, from_tty) |
| 1108 | char *bnum_exp; |
| 1109 | int from_tty; |
| 1110 | { |
| 1111 | int bnum = -1; |
| 1112 | |
| 1113 | if (bnum_exp) |
| 1114 | bnum = parse_and_eval_address (bnum_exp); |
| 1115 | |
| 1116 | breakpoint_1 (bnum, bp_watchpoint); |
| 1117 | } |
| 1118 | |
| 1119 | /* Print a message describing any breakpoints set at PC. */ |
| 1120 | |
| 1121 | static void |
| 1122 | describe_other_breakpoints (pc) |
| 1123 | register CORE_ADDR pc; |
| 1124 | { |
| 1125 | register int others = 0; |
| 1126 | register struct breakpoint *b; |
| 1127 | |
| 1128 | ALL_BREAKPOINTS (b) |
| 1129 | if (b->address == pc) |
| 1130 | others++; |
| 1131 | if (others > 0) |
| 1132 | { |
| 1133 | printf ("Note: breakpoint%s ", (others > 1) ? "s" : ""); |
| 1134 | ALL_BREAKPOINTS (b) |
| 1135 | if (b->address == pc) |
| 1136 | { |
| 1137 | others--; |
| 1138 | printf ("%d%s%s ", |
| 1139 | b->number, |
| 1140 | (b->enable == disabled) ? " (disabled)" : "", |
| 1141 | (others > 1) ? "," : ((others == 1) ? " and" : "")); |
| 1142 | } |
| 1143 | printf ("also set at pc %s.\n", local_hex_string(pc)); |
| 1144 | } |
| 1145 | } |
| 1146 | \f |
| 1147 | /* Set the default place to put a breakpoint |
| 1148 | for the `break' command with no arguments. */ |
| 1149 | |
| 1150 | void |
| 1151 | set_default_breakpoint (valid, addr, symtab, line) |
| 1152 | int valid; |
| 1153 | CORE_ADDR addr; |
| 1154 | struct symtab *symtab; |
| 1155 | int line; |
| 1156 | { |
| 1157 | default_breakpoint_valid = valid; |
| 1158 | default_breakpoint_address = addr; |
| 1159 | default_breakpoint_symtab = symtab; |
| 1160 | default_breakpoint_line = line; |
| 1161 | } |
| 1162 | |
| 1163 | /* Rescan breakpoints at address ADDRESS, |
| 1164 | marking the first one as "first" and any others as "duplicates". |
| 1165 | This is so that the bpt instruction is only inserted once. */ |
| 1166 | |
| 1167 | static void |
| 1168 | check_duplicates (address) |
| 1169 | CORE_ADDR address; |
| 1170 | { |
| 1171 | register struct breakpoint *b; |
| 1172 | register int count = 0; |
| 1173 | |
| 1174 | if (address == 0) /* Watchpoints are uninteresting */ |
| 1175 | return; |
| 1176 | |
| 1177 | ALL_BREAKPOINTS (b) |
| 1178 | if (b->enable != disabled && b->address == address) |
| 1179 | { |
| 1180 | count++; |
| 1181 | b->duplicate = count > 1; |
| 1182 | } |
| 1183 | } |
| 1184 | |
| 1185 | /* Low level routine to set a breakpoint. |
| 1186 | Takes as args the three things that every breakpoint must have. |
| 1187 | Returns the breakpoint object so caller can set other things. |
| 1188 | Does not set the breakpoint number! |
| 1189 | Does not print anything. |
| 1190 | |
| 1191 | ==> This routine should not be called if there is a chance of later |
| 1192 | error(); otherwise it leaves a bogus breakpoint on the chain. Validate |
| 1193 | your arguments BEFORE calling this routine! */ |
| 1194 | |
| 1195 | static struct breakpoint * |
| 1196 | set_raw_breakpoint (sal) |
| 1197 | struct symtab_and_line sal; |
| 1198 | { |
| 1199 | register struct breakpoint *b, *b1; |
| 1200 | |
| 1201 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); |
| 1202 | bzero (b, sizeof *b); |
| 1203 | b->address = sal.pc; |
| 1204 | b->symtab = sal.symtab; |
| 1205 | b->line_number = sal.line; |
| 1206 | b->enable = enabled; |
| 1207 | b->next = 0; |
| 1208 | b->silent = 0; |
| 1209 | b->ignore_count = 0; |
| 1210 | b->commands = NULL; |
| 1211 | b->frame = 0; |
| 1212 | |
| 1213 | /* Add this breakpoint to the end of the chain |
| 1214 | so that a list of breakpoints will come out in order |
| 1215 | of increasing numbers. */ |
| 1216 | |
| 1217 | b1 = breakpoint_chain; |
| 1218 | if (b1 == 0) |
| 1219 | breakpoint_chain = b; |
| 1220 | else |
| 1221 | { |
| 1222 | while (b1->next) |
| 1223 | b1 = b1->next; |
| 1224 | b1->next = b; |
| 1225 | } |
| 1226 | |
| 1227 | check_duplicates (sal.pc); |
| 1228 | |
| 1229 | return b; |
| 1230 | } |
| 1231 | |
| 1232 | struct breakpoint *longjmp_breakpoint = NULL; |
| 1233 | struct breakpoint *_longjmp_breakpoint = NULL; |
| 1234 | struct breakpoint *siglongjmp_breakpoint = NULL; |
| 1235 | struct breakpoint *longjmp_resume_breakpoint = NULL; |
| 1236 | |
| 1237 | static void |
| 1238 | create_longjmp_breakpoint_1(func_name, bpt) |
| 1239 | char *func_name; |
| 1240 | struct breakpoint **bpt; |
| 1241 | { |
| 1242 | int i; |
| 1243 | struct symtab_and_line sal; |
| 1244 | struct breakpoint *b; |
| 1245 | |
| 1246 | if (*bpt != NULL) |
| 1247 | { |
| 1248 | delete_breakpoint(*bpt); |
| 1249 | *bpt = NULL; |
| 1250 | } |
| 1251 | |
| 1252 | if (func_name != NULL) |
| 1253 | { |
| 1254 | struct minimal_symbol *m; |
| 1255 | |
| 1256 | m = lookup_minimal_symbol(func_name, (struct objfile *)NULL); |
| 1257 | if (m) |
| 1258 | sal.pc = m->address; |
| 1259 | else |
| 1260 | return; |
| 1261 | } |
| 1262 | else |
| 1263 | sal.pc = 0; |
| 1264 | |
| 1265 | sal.symtab = NULL; |
| 1266 | sal.line = 0; |
| 1267 | if (*bpt != NULL) |
| 1268 | b = *bpt; |
| 1269 | else |
| 1270 | b = set_raw_breakpoint(sal); |
| 1271 | |
| 1272 | if (!b) return; |
| 1273 | |
| 1274 | b->type = bp_longjmp; |
| 1275 | b->disposition = donttouch; |
| 1276 | b->enable = disabled; |
| 1277 | b->silent = 1; |
| 1278 | *bpt = b; |
| 1279 | } |
| 1280 | |
| 1281 | /* Call this routine each time we read a new executable or symbol table |
| 1282 | file. */ |
| 1283 | |
| 1284 | #ifdef GET_LONGJMP_TARGET |
| 1285 | void |
| 1286 | create_longjmp_breakpoint() |
| 1287 | { |
| 1288 | create_longjmp_breakpoint_1("longjmp", &longjmp_breakpoint); |
| 1289 | create_longjmp_breakpoint_1("_longjmp", &_longjmp_breakpoint); |
| 1290 | create_longjmp_breakpoint_1("siglongjmp", &siglongjmp_breakpoint); |
| 1291 | |
| 1292 | if ((longjmp_breakpoint || _longjmp_breakpoint || siglongjmp_breakpoint) |
| 1293 | && !longjmp_resume_breakpoint) |
| 1294 | { |
| 1295 | create_longjmp_breakpoint_1(NULL, &longjmp_resume_breakpoint); |
| 1296 | if (longjmp_resume_breakpoint) |
| 1297 | longjmp_resume_breakpoint->type = bp_longjmp_resume; |
| 1298 | } |
| 1299 | } |
| 1300 | #else |
| 1301 | void |
| 1302 | create_longjmp_breakpoint() |
| 1303 | { |
| 1304 | } |
| 1305 | #endif |
| 1306 | |
| 1307 | /* Call this routine when stepping and nexting to enable a breakpoint if we do |
| 1308 | a longjmp(). When we hit that breakpoint, call |
| 1309 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
| 1310 | |
| 1311 | void |
| 1312 | enable_longjmp_breakpoint() |
| 1313 | { |
| 1314 | if (longjmp_breakpoint) |
| 1315 | longjmp_breakpoint->enable = enabled; |
| 1316 | if (_longjmp_breakpoint) |
| 1317 | _longjmp_breakpoint->enable = enabled; |
| 1318 | if (siglongjmp_breakpoint) |
| 1319 | siglongjmp_breakpoint->enable = enabled; |
| 1320 | } |
| 1321 | |
| 1322 | void |
| 1323 | disable_longjmp_breakpoint() |
| 1324 | { |
| 1325 | if (longjmp_breakpoint) |
| 1326 | longjmp_breakpoint->enable = disabled; |
| 1327 | if (_longjmp_breakpoint) |
| 1328 | _longjmp_breakpoint->enable = disabled; |
| 1329 | if (siglongjmp_breakpoint) |
| 1330 | siglongjmp_breakpoint->enable = disabled; |
| 1331 | if (longjmp_resume_breakpoint) |
| 1332 | longjmp_resume_breakpoint->enable = disabled; |
| 1333 | } |
| 1334 | |
| 1335 | /* Call this after hitting the longjmp() breakpoint. Use this to set a new |
| 1336 | breakpoint at the target of the jmp_buf. |
| 1337 | */ |
| 1338 | |
| 1339 | void |
| 1340 | set_longjmp_resume_breakpoint(pc, frame) |
| 1341 | CORE_ADDR pc; |
| 1342 | FRAME frame; |
| 1343 | { |
| 1344 | longjmp_resume_breakpoint->address = pc; |
| 1345 | longjmp_resume_breakpoint->enable = enabled; |
| 1346 | if (frame != NULL) |
| 1347 | longjmp_resume_breakpoint->frame = FRAME_FP(frame); |
| 1348 | else |
| 1349 | longjmp_resume_breakpoint->frame = 0; |
| 1350 | } |
| 1351 | |
| 1352 | /* Set a breakpoint that will evaporate an end of command |
| 1353 | at address specified by SAL. |
| 1354 | Restrict it to frame FRAME if FRAME is nonzero. */ |
| 1355 | |
| 1356 | struct breakpoint * |
| 1357 | set_momentary_breakpoint (sal, frame, type) |
| 1358 | struct symtab_and_line sal; |
| 1359 | FRAME frame; |
| 1360 | enum bptype type; |
| 1361 | { |
| 1362 | register struct breakpoint *b; |
| 1363 | b = set_raw_breakpoint (sal); |
| 1364 | b->type = type; |
| 1365 | b->enable = enabled; |
| 1366 | b->disposition = donttouch; |
| 1367 | b->frame = (frame ? FRAME_FP (frame) : 0); |
| 1368 | return b; |
| 1369 | } |
| 1370 | |
| 1371 | #if 0 |
| 1372 | void |
| 1373 | clear_momentary_breakpoints () |
| 1374 | { |
| 1375 | register struct breakpoint *b; |
| 1376 | ALL_BREAKPOINTS (b) |
| 1377 | if (b->disposition == delete) |
| 1378 | { |
| 1379 | delete_breakpoint (b); |
| 1380 | break; |
| 1381 | } |
| 1382 | } |
| 1383 | #endif |
| 1384 | \f |
| 1385 | /* Tell the user we have just set a breakpoint B. */ |
| 1386 | static void |
| 1387 | mention (b) |
| 1388 | struct breakpoint *b; |
| 1389 | { |
| 1390 | switch (b->type) |
| 1391 | { |
| 1392 | case bp_watchpoint: |
| 1393 | printf_filtered ("Watchpoint %d: ", b->number); |
| 1394 | print_expression (b->exp, stdout); |
| 1395 | break; |
| 1396 | case bp_breakpoint: |
| 1397 | printf_filtered ("Breakpoint %d at %s", b->number, |
| 1398 | local_hex_string(b->address)); |
| 1399 | if (b->symtab) |
| 1400 | printf_filtered (": file %s, line %d.", |
| 1401 | b->symtab->filename, b->line_number); |
| 1402 | } |
| 1403 | printf_filtered ("\n"); |
| 1404 | } |
| 1405 | |
| 1406 | #if 0 |
| 1407 | /* Nobody calls this currently. */ |
| 1408 | /* Set a breakpoint from a symtab and line. |
| 1409 | If TEMPFLAG is nonzero, it is a temporary breakpoint. |
| 1410 | ADDR_STRING is a malloc'd string holding the name of where we are |
| 1411 | setting the breakpoint. This is used later to re-set it after the |
| 1412 | program is relinked and symbols are reloaded. |
| 1413 | Print the same confirmation messages that the breakpoint command prints. */ |
| 1414 | |
| 1415 | void |
| 1416 | set_breakpoint (s, line, tempflag, addr_string) |
| 1417 | struct symtab *s; |
| 1418 | int line; |
| 1419 | int tempflag; |
| 1420 | char *addr_string; |
| 1421 | { |
| 1422 | register struct breakpoint *b; |
| 1423 | struct symtab_and_line sal; |
| 1424 | |
| 1425 | sal.symtab = s; |
| 1426 | sal.line = line; |
| 1427 | sal.pc = 0; |
| 1428 | resolve_sal_pc (&sal); /* Might error out */ |
| 1429 | describe_other_breakpoints (sal.pc); |
| 1430 | |
| 1431 | b = set_raw_breakpoint (sal); |
| 1432 | set_breakpoint_count (breakpoint_count + 1); |
| 1433 | b->number = breakpoint_count; |
| 1434 | b->type = bp_breakpoint; |
| 1435 | b->cond = 0; |
| 1436 | b->addr_string = addr_string; |
| 1437 | b->enable = enabled; |
| 1438 | b->disposition = tempflag ? delete : donttouch; |
| 1439 | |
| 1440 | mention (b); |
| 1441 | } |
| 1442 | #endif /* 0 */ |
| 1443 | \f |
| 1444 | /* Set a breakpoint according to ARG (function, linenum or *address) |
| 1445 | and make it temporary if TEMPFLAG is nonzero. */ |
| 1446 | |
| 1447 | static void |
| 1448 | break_command_1 (arg, tempflag, from_tty) |
| 1449 | char *arg; |
| 1450 | int tempflag, from_tty; |
| 1451 | { |
| 1452 | struct symtabs_and_lines sals; |
| 1453 | struct symtab_and_line sal; |
| 1454 | register struct expression *cond = 0; |
| 1455 | register struct breakpoint *b; |
| 1456 | |
| 1457 | /* Pointers in arg to the start, and one past the end, of the condition. */ |
| 1458 | char *cond_start = NULL; |
| 1459 | char *cond_end; |
| 1460 | /* Pointers in arg to the start, and one past the end, |
| 1461 | of the address part. */ |
| 1462 | char *addr_start = NULL; |
| 1463 | char *addr_end; |
| 1464 | |
| 1465 | int i; |
| 1466 | |
| 1467 | sals.sals = NULL; |
| 1468 | sals.nelts = 0; |
| 1469 | |
| 1470 | sal.line = sal.pc = sal.end = 0; |
| 1471 | sal.symtab = 0; |
| 1472 | |
| 1473 | /* If no arg given, or if first arg is 'if ', use the default breakpoint. */ |
| 1474 | |
| 1475 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' |
| 1476 | && (arg[2] == ' ' || arg[2] == '\t'))) |
| 1477 | { |
| 1478 | if (default_breakpoint_valid) |
| 1479 | { |
| 1480 | sals.sals = (struct symtab_and_line *) |
| 1481 | xmalloc (sizeof (struct symtab_and_line)); |
| 1482 | sal.pc = default_breakpoint_address; |
| 1483 | sal.line = default_breakpoint_line; |
| 1484 | sal.symtab = default_breakpoint_symtab; |
| 1485 | sals.sals[0] = sal; |
| 1486 | sals.nelts = 1; |
| 1487 | } |
| 1488 | else |
| 1489 | error ("No default breakpoint address now."); |
| 1490 | } |
| 1491 | else |
| 1492 | { |
| 1493 | addr_start = arg; |
| 1494 | |
| 1495 | /* Force almost all breakpoints to be in terms of the |
| 1496 | current_source_symtab (which is decode_line_1's default). This |
| 1497 | should produce the results we want almost all of the time while |
| 1498 | leaving default_breakpoint_* alone. */ |
| 1499 | if (default_breakpoint_valid |
| 1500 | && (!current_source_symtab |
| 1501 | || (arg && (*arg == '+' || *arg == '-')))) |
| 1502 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, |
| 1503 | default_breakpoint_line); |
| 1504 | else |
| 1505 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0); |
| 1506 | |
| 1507 | addr_end = arg; |
| 1508 | } |
| 1509 | |
| 1510 | if (! sals.nelts) |
| 1511 | return; |
| 1512 | |
| 1513 | /* Resolve all line numbers to PC's, and verify that conditions |
| 1514 | can be parsed, before setting any breakpoints. */ |
| 1515 | for (i = 0; i < sals.nelts; i++) |
| 1516 | { |
| 1517 | resolve_sal_pc (&sals.sals[i]); |
| 1518 | |
| 1519 | while (arg && *arg) |
| 1520 | { |
| 1521 | if (arg[0] == 'i' && arg[1] == 'f' |
| 1522 | && (arg[2] == ' ' || arg[2] == '\t')) |
| 1523 | { |
| 1524 | arg += 2; |
| 1525 | cond_start = arg; |
| 1526 | cond = parse_exp_1 (&arg, block_for_pc (sals.sals[i].pc), 0); |
| 1527 | cond_end = arg; |
| 1528 | } |
| 1529 | else |
| 1530 | error ("Junk at end of arguments."); |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | /* Now set all the breakpoints. */ |
| 1535 | for (i = 0; i < sals.nelts; i++) |
| 1536 | { |
| 1537 | sal = sals.sals[i]; |
| 1538 | |
| 1539 | if (from_tty) |
| 1540 | describe_other_breakpoints (sal.pc); |
| 1541 | |
| 1542 | b = set_raw_breakpoint (sal); |
| 1543 | set_breakpoint_count (breakpoint_count + 1); |
| 1544 | b->number = breakpoint_count; |
| 1545 | b->type = bp_breakpoint; |
| 1546 | b->cond = cond; |
| 1547 | |
| 1548 | if (addr_start) |
| 1549 | b->addr_string = savestring (addr_start, addr_end - addr_start); |
| 1550 | if (cond_start) |
| 1551 | b->cond_string = savestring (cond_start, cond_end - cond_start); |
| 1552 | |
| 1553 | b->enable = enabled; |
| 1554 | b->disposition = tempflag ? delete : donttouch; |
| 1555 | |
| 1556 | mention (b); |
| 1557 | } |
| 1558 | |
| 1559 | if (sals.nelts > 1) |
| 1560 | { |
| 1561 | printf ("Multiple breakpoints were set.\n"); |
| 1562 | printf ("Use the \"delete\" command to delete unwanted breakpoints.\n"); |
| 1563 | } |
| 1564 | free (sals.sals); |
| 1565 | } |
| 1566 | |
| 1567 | /* Helper function for break_command_1 and disassemble_command. */ |
| 1568 | |
| 1569 | void |
| 1570 | resolve_sal_pc (sal) |
| 1571 | struct symtab_and_line *sal; |
| 1572 | { |
| 1573 | CORE_ADDR pc; |
| 1574 | |
| 1575 | if (sal->pc == 0 && sal->symtab != 0) |
| 1576 | { |
| 1577 | pc = find_line_pc (sal->symtab, sal->line); |
| 1578 | if (pc == 0) |
| 1579 | error ("No line %d in file \"%s\".", |
| 1580 | sal->line, sal->symtab->filename); |
| 1581 | sal->pc = pc; |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | void |
| 1586 | break_command (arg, from_tty) |
| 1587 | char *arg; |
| 1588 | int from_tty; |
| 1589 | { |
| 1590 | break_command_1 (arg, 0, from_tty); |
| 1591 | } |
| 1592 | |
| 1593 | static void |
| 1594 | tbreak_command (arg, from_tty) |
| 1595 | char *arg; |
| 1596 | int from_tty; |
| 1597 | { |
| 1598 | break_command_1 (arg, 1, from_tty); |
| 1599 | } |
| 1600 | |
| 1601 | /* ARGSUSED */ |
| 1602 | static void |
| 1603 | watch_command (arg, from_tty) |
| 1604 | char *arg; |
| 1605 | int from_tty; |
| 1606 | { |
| 1607 | struct breakpoint *b; |
| 1608 | struct symtab_and_line sal; |
| 1609 | struct expression *exp; |
| 1610 | struct block *exp_valid_block; |
| 1611 | struct value *val; |
| 1612 | |
| 1613 | sal.pc = 0; |
| 1614 | sal.symtab = NULL; |
| 1615 | sal.line = 0; |
| 1616 | |
| 1617 | /* Parse arguments. */ |
| 1618 | innermost_block = NULL; |
| 1619 | exp = parse_expression (arg); |
| 1620 | exp_valid_block = innermost_block; |
| 1621 | val = evaluate_expression (exp); |
| 1622 | release_value (val); |
| 1623 | |
| 1624 | /* Now set up the breakpoint. */ |
| 1625 | b = set_raw_breakpoint (sal); |
| 1626 | set_breakpoint_count (breakpoint_count + 1); |
| 1627 | b->number = breakpoint_count; |
| 1628 | b->type = bp_watchpoint; |
| 1629 | b->disposition = donttouch; |
| 1630 | b->exp = exp; |
| 1631 | b->exp_valid_block = exp_valid_block; |
| 1632 | b->val = val; |
| 1633 | b->cond = 0; |
| 1634 | b->cond_string = NULL; |
| 1635 | mention (b); |
| 1636 | } |
| 1637 | \f |
| 1638 | /* |
| 1639 | * Helper routine for the until_command routine in infcmd.c. Here |
| 1640 | * because it uses the mechanisms of breakpoints. |
| 1641 | */ |
| 1642 | /* ARGSUSED */ |
| 1643 | void |
| 1644 | until_break_command (arg, from_tty) |
| 1645 | char *arg; |
| 1646 | int from_tty; |
| 1647 | { |
| 1648 | struct symtabs_and_lines sals; |
| 1649 | struct symtab_and_line sal; |
| 1650 | FRAME prev_frame = get_prev_frame (selected_frame); |
| 1651 | struct breakpoint *breakpoint; |
| 1652 | struct cleanup *old_chain; |
| 1653 | |
| 1654 | clear_proceed_status (); |
| 1655 | |
| 1656 | /* Set a breakpoint where the user wants it and at return from |
| 1657 | this function */ |
| 1658 | |
| 1659 | if (default_breakpoint_valid) |
| 1660 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, |
| 1661 | default_breakpoint_line); |
| 1662 | else |
| 1663 | sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0); |
| 1664 | |
| 1665 | if (sals.nelts != 1) |
| 1666 | error ("Couldn't get information on specified line."); |
| 1667 | |
| 1668 | sal = sals.sals[0]; |
| 1669 | free (sals.sals); /* malloc'd, so freed */ |
| 1670 | |
| 1671 | if (*arg) |
| 1672 | error ("Junk at end of arguments."); |
| 1673 | |
| 1674 | resolve_sal_pc (&sal); |
| 1675 | |
| 1676 | breakpoint = set_momentary_breakpoint (sal, selected_frame, bp_until); |
| 1677 | |
| 1678 | old_chain = make_cleanup(delete_breakpoint, breakpoint); |
| 1679 | |
| 1680 | /* Keep within the current frame */ |
| 1681 | |
| 1682 | if (prev_frame) |
| 1683 | { |
| 1684 | struct frame_info *fi; |
| 1685 | |
| 1686 | fi = get_frame_info (prev_frame); |
| 1687 | sal = find_pc_line (fi->pc, 0); |
| 1688 | sal.pc = fi->pc; |
| 1689 | breakpoint = set_momentary_breakpoint (sal, prev_frame, bp_until); |
| 1690 | make_cleanup(delete_breakpoint, breakpoint); |
| 1691 | } |
| 1692 | |
| 1693 | proceed (-1, -1, 0); |
| 1694 | do_cleanups(old_chain); |
| 1695 | } |
| 1696 | \f |
| 1697 | #if 0 |
| 1698 | /* These aren't used; I don't konw what they were for. */ |
| 1699 | /* Set a breakpoint at the catch clause for NAME. */ |
| 1700 | static int |
| 1701 | catch_breakpoint (name) |
| 1702 | char *name; |
| 1703 | { |
| 1704 | } |
| 1705 | |
| 1706 | static int |
| 1707 | disable_catch_breakpoint () |
| 1708 | { |
| 1709 | } |
| 1710 | |
| 1711 | static int |
| 1712 | delete_catch_breakpoint () |
| 1713 | { |
| 1714 | } |
| 1715 | |
| 1716 | static int |
| 1717 | enable_catch_breakpoint () |
| 1718 | { |
| 1719 | } |
| 1720 | #endif /* 0 */ |
| 1721 | |
| 1722 | struct sal_chain |
| 1723 | { |
| 1724 | struct sal_chain *next; |
| 1725 | struct symtab_and_line sal; |
| 1726 | }; |
| 1727 | |
| 1728 | #if 0 |
| 1729 | /* This isn't used; I don't know what it was for. */ |
| 1730 | /* For each catch clause identified in ARGS, run FUNCTION |
| 1731 | with that clause as an argument. */ |
| 1732 | static struct symtabs_and_lines |
| 1733 | map_catch_names (args, function) |
| 1734 | char *args; |
| 1735 | int (*function)(); |
| 1736 | { |
| 1737 | register char *p = args; |
| 1738 | register char *p1; |
| 1739 | struct symtabs_and_lines sals; |
| 1740 | #if 0 |
| 1741 | struct sal_chain *sal_chain = 0; |
| 1742 | #endif |
| 1743 | |
| 1744 | if (p == 0) |
| 1745 | error_no_arg ("one or more catch names"); |
| 1746 | |
| 1747 | sals.nelts = 0; |
| 1748 | sals.sals = NULL; |
| 1749 | |
| 1750 | while (*p) |
| 1751 | { |
| 1752 | p1 = p; |
| 1753 | /* Don't swallow conditional part. */ |
| 1754 | if (p1[0] == 'i' && p1[1] == 'f' |
| 1755 | && (p1[2] == ' ' || p1[2] == '\t')) |
| 1756 | break; |
| 1757 | |
| 1758 | if (isalpha (*p1)) |
| 1759 | { |
| 1760 | p1++; |
| 1761 | while (isalnum (*p1) || *p1 == '_' || *p1 == '$') |
| 1762 | p1++; |
| 1763 | } |
| 1764 | |
| 1765 | if (*p1 && *p1 != ' ' && *p1 != '\t') |
| 1766 | error ("Arguments must be catch names."); |
| 1767 | |
| 1768 | *p1 = 0; |
| 1769 | #if 0 |
| 1770 | if (function (p)) |
| 1771 | { |
| 1772 | struct sal_chain *next |
| 1773 | = (struct sal_chain *)alloca (sizeof (struct sal_chain)); |
| 1774 | next->next = sal_chain; |
| 1775 | next->sal = get_catch_sal (p); |
| 1776 | sal_chain = next; |
| 1777 | goto win; |
| 1778 | } |
| 1779 | #endif |
| 1780 | printf ("No catch clause for exception %s.\n", p); |
| 1781 | #if 0 |
| 1782 | win: |
| 1783 | #endif |
| 1784 | p = p1; |
| 1785 | while (*p == ' ' || *p == '\t') p++; |
| 1786 | } |
| 1787 | } |
| 1788 | #endif /* 0 */ |
| 1789 | |
| 1790 | /* This shares a lot of code with `print_frame_label_vars' from stack.c. */ |
| 1791 | |
| 1792 | static struct symtabs_and_lines |
| 1793 | get_catch_sals (this_level_only) |
| 1794 | int this_level_only; |
| 1795 | { |
| 1796 | register struct blockvector *bl; |
| 1797 | register struct block *block; |
| 1798 | int index, have_default = 0; |
| 1799 | struct frame_info *fi; |
| 1800 | CORE_ADDR pc; |
| 1801 | struct symtabs_and_lines sals; |
| 1802 | struct sal_chain *sal_chain = 0; |
| 1803 | char *blocks_searched; |
| 1804 | |
| 1805 | /* Not sure whether an error message is always the correct response, |
| 1806 | but it's better than a core dump. */ |
| 1807 | if (selected_frame == NULL) |
| 1808 | error ("No selected frame."); |
| 1809 | block = get_frame_block (selected_frame); |
| 1810 | fi = get_frame_info (selected_frame); |
| 1811 | pc = fi->pc; |
| 1812 | |
| 1813 | sals.nelts = 0; |
| 1814 | sals.sals = NULL; |
| 1815 | |
| 1816 | if (block == 0) |
| 1817 | error ("No symbol table info available.\n"); |
| 1818 | |
| 1819 | bl = blockvector_for_pc (BLOCK_END (block) - 4, &index); |
| 1820 | blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); |
| 1821 | bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char)); |
| 1822 | |
| 1823 | while (block != 0) |
| 1824 | { |
| 1825 | CORE_ADDR end = BLOCK_END (block) - 4; |
| 1826 | int last_index; |
| 1827 | |
| 1828 | if (bl != blockvector_for_pc (end, &index)) |
| 1829 | error ("blockvector blotch"); |
| 1830 | if (BLOCKVECTOR_BLOCK (bl, index) != block) |
| 1831 | error ("blockvector botch"); |
| 1832 | last_index = BLOCKVECTOR_NBLOCKS (bl); |
| 1833 | index += 1; |
| 1834 | |
| 1835 | /* Don't print out blocks that have gone by. */ |
| 1836 | while (index < last_index |
| 1837 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc) |
| 1838 | index++; |
| 1839 | |
| 1840 | while (index < last_index |
| 1841 | && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end) |
| 1842 | { |
| 1843 | if (blocks_searched[index] == 0) |
| 1844 | { |
| 1845 | struct block *b = BLOCKVECTOR_BLOCK (bl, index); |
| 1846 | int nsyms; |
| 1847 | register int i; |
| 1848 | register struct symbol *sym; |
| 1849 | |
| 1850 | nsyms = BLOCK_NSYMS (b); |
| 1851 | |
| 1852 | for (i = 0; i < nsyms; i++) |
| 1853 | { |
| 1854 | sym = BLOCK_SYM (b, i); |
| 1855 | if (! strcmp (SYMBOL_NAME (sym), "default")) |
| 1856 | { |
| 1857 | if (have_default) |
| 1858 | continue; |
| 1859 | have_default = 1; |
| 1860 | } |
| 1861 | if (SYMBOL_CLASS (sym) == LOC_LABEL) |
| 1862 | { |
| 1863 | struct sal_chain *next = (struct sal_chain *) |
| 1864 | alloca (sizeof (struct sal_chain)); |
| 1865 | next->next = sal_chain; |
| 1866 | next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0); |
| 1867 | sal_chain = next; |
| 1868 | } |
| 1869 | } |
| 1870 | blocks_searched[index] = 1; |
| 1871 | } |
| 1872 | index++; |
| 1873 | } |
| 1874 | if (have_default) |
| 1875 | break; |
| 1876 | if (sal_chain && this_level_only) |
| 1877 | break; |
| 1878 | |
| 1879 | /* After handling the function's top-level block, stop. |
| 1880 | Don't continue to its superblock, the block of |
| 1881 | per-file symbols. */ |
| 1882 | if (BLOCK_FUNCTION (block)) |
| 1883 | break; |
| 1884 | block = BLOCK_SUPERBLOCK (block); |
| 1885 | } |
| 1886 | |
| 1887 | if (sal_chain) |
| 1888 | { |
| 1889 | struct sal_chain *tmp_chain; |
| 1890 | |
| 1891 | /* Count the number of entries. */ |
| 1892 | for (index = 0, tmp_chain = sal_chain; tmp_chain; |
| 1893 | tmp_chain = tmp_chain->next) |
| 1894 | index++; |
| 1895 | |
| 1896 | sals.nelts = index; |
| 1897 | sals.sals = (struct symtab_and_line *) |
| 1898 | xmalloc (index * sizeof (struct symtab_and_line)); |
| 1899 | for (index = 0; sal_chain; sal_chain = sal_chain->next, index++) |
| 1900 | sals.sals[index] = sal_chain->sal; |
| 1901 | } |
| 1902 | |
| 1903 | return sals; |
| 1904 | } |
| 1905 | |
| 1906 | /* Commands to deal with catching exceptions. */ |
| 1907 | |
| 1908 | static void |
| 1909 | catch_command_1 (arg, tempflag, from_tty) |
| 1910 | char *arg; |
| 1911 | int tempflag; |
| 1912 | int from_tty; |
| 1913 | { |
| 1914 | /* First, translate ARG into something we can deal with in terms |
| 1915 | of breakpoints. */ |
| 1916 | |
| 1917 | struct symtabs_and_lines sals; |
| 1918 | struct symtab_and_line sal; |
| 1919 | register struct expression *cond = 0; |
| 1920 | register struct breakpoint *b; |
| 1921 | char *save_arg; |
| 1922 | int i; |
| 1923 | |
| 1924 | sal.line = sal.pc = sal.end = 0; |
| 1925 | sal.symtab = 0; |
| 1926 | |
| 1927 | /* If no arg given, or if first arg is 'if ', all active catch clauses |
| 1928 | are breakpointed. */ |
| 1929 | |
| 1930 | if (!arg || (arg[0] == 'i' && arg[1] == 'f' |
| 1931 | && (arg[2] == ' ' || arg[2] == '\t'))) |
| 1932 | { |
| 1933 | /* Grab all active catch clauses. */ |
| 1934 | sals = get_catch_sals (0); |
| 1935 | } |
| 1936 | else |
| 1937 | { |
| 1938 | /* Grab selected catch clauses. */ |
| 1939 | error ("catch NAME not implemeneted"); |
| 1940 | #if 0 |
| 1941 | /* This isn't used; I don't know what it was for. */ |
| 1942 | sals = map_catch_names (arg, catch_breakpoint); |
| 1943 | #endif |
| 1944 | } |
| 1945 | |
| 1946 | if (! sals.nelts) |
| 1947 | return; |
| 1948 | |
| 1949 | save_arg = arg; |
| 1950 | for (i = 0; i < sals.nelts; i++) |
| 1951 | { |
| 1952 | resolve_sal_pc (&sals.sals[i]); |
| 1953 | |
| 1954 | while (arg && *arg) |
| 1955 | { |
| 1956 | if (arg[0] == 'i' && arg[1] == 'f' |
| 1957 | && (arg[2] == ' ' || arg[2] == '\t')) |
| 1958 | cond = parse_exp_1 ((arg += 2, &arg), |
| 1959 | block_for_pc (sals.sals[i].pc), 0); |
| 1960 | else |
| 1961 | error ("Junk at end of arguments."); |
| 1962 | } |
| 1963 | arg = save_arg; |
| 1964 | } |
| 1965 | |
| 1966 | for (i = 0; i < sals.nelts; i++) |
| 1967 | { |
| 1968 | sal = sals.sals[i]; |
| 1969 | |
| 1970 | if (from_tty) |
| 1971 | describe_other_breakpoints (sal.pc); |
| 1972 | |
| 1973 | b = set_raw_breakpoint (sal); |
| 1974 | set_breakpoint_count (breakpoint_count + 1); |
| 1975 | b->number = breakpoint_count; |
| 1976 | b->type = bp_breakpoint; |
| 1977 | b->cond = cond; |
| 1978 | b->enable = enabled; |
| 1979 | b->disposition = tempflag ? delete : donttouch; |
| 1980 | |
| 1981 | printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address)); |
| 1982 | if (b->symtab) |
| 1983 | printf (": file %s, line %d.", b->symtab->filename, b->line_number); |
| 1984 | printf ("\n"); |
| 1985 | } |
| 1986 | |
| 1987 | if (sals.nelts > 1) |
| 1988 | { |
| 1989 | printf ("Multiple breakpoints were set.\n"); |
| 1990 | printf ("Use the \"delete\" command to delete unwanted breakpoints.\n"); |
| 1991 | } |
| 1992 | free (sals.sals); |
| 1993 | } |
| 1994 | |
| 1995 | #if 0 |
| 1996 | /* These aren't used; I don't know what they were for. */ |
| 1997 | /* Disable breakpoints on all catch clauses described in ARGS. */ |
| 1998 | static void |
| 1999 | disable_catch (args) |
| 2000 | char *args; |
| 2001 | { |
| 2002 | /* Map the disable command to catch clauses described in ARGS. */ |
| 2003 | } |
| 2004 | |
| 2005 | /* Enable breakpoints on all catch clauses described in ARGS. */ |
| 2006 | static void |
| 2007 | enable_catch (args) |
| 2008 | char *args; |
| 2009 | { |
| 2010 | /* Map the disable command to catch clauses described in ARGS. */ |
| 2011 | } |
| 2012 | |
| 2013 | /* Delete breakpoints on all catch clauses in the active scope. */ |
| 2014 | static void |
| 2015 | delete_catch (args) |
| 2016 | char *args; |
| 2017 | { |
| 2018 | /* Map the delete command to catch clauses described in ARGS. */ |
| 2019 | } |
| 2020 | #endif /* 0 */ |
| 2021 | |
| 2022 | static void |
| 2023 | catch_command (arg, from_tty) |
| 2024 | char *arg; |
| 2025 | int from_tty; |
| 2026 | { |
| 2027 | catch_command_1 (arg, 0, from_tty); |
| 2028 | } |
| 2029 | \f |
| 2030 | static void |
| 2031 | clear_command (arg, from_tty) |
| 2032 | char *arg; |
| 2033 | int from_tty; |
| 2034 | { |
| 2035 | register struct breakpoint *b, *b1; |
| 2036 | struct symtabs_and_lines sals; |
| 2037 | struct symtab_and_line sal; |
| 2038 | register struct breakpoint *found; |
| 2039 | int i; |
| 2040 | |
| 2041 | if (arg) |
| 2042 | { |
| 2043 | sals = decode_line_spec (arg, 1); |
| 2044 | } |
| 2045 | else |
| 2046 | { |
| 2047 | sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); |
| 2048 | sal.line = default_breakpoint_line; |
| 2049 | sal.symtab = default_breakpoint_symtab; |
| 2050 | sal.pc = 0; |
| 2051 | if (sal.symtab == 0) |
| 2052 | error ("No source file specified."); |
| 2053 | |
| 2054 | sals.sals[0] = sal; |
| 2055 | sals.nelts = 1; |
| 2056 | } |
| 2057 | |
| 2058 | for (i = 0; i < sals.nelts; i++) |
| 2059 | { |
| 2060 | /* If exact pc given, clear bpts at that pc. |
| 2061 | But if sal.pc is zero, clear all bpts on specified line. */ |
| 2062 | sal = sals.sals[i]; |
| 2063 | found = (struct breakpoint *) 0; |
| 2064 | while (breakpoint_chain |
| 2065 | && (sal.pc ? breakpoint_chain->address == sal.pc |
| 2066 | : (breakpoint_chain->symtab == sal.symtab |
| 2067 | && breakpoint_chain->line_number == sal.line))) |
| 2068 | { |
| 2069 | b1 = breakpoint_chain; |
| 2070 | breakpoint_chain = b1->next; |
| 2071 | b1->next = found; |
| 2072 | found = b1; |
| 2073 | } |
| 2074 | |
| 2075 | ALL_BREAKPOINTS (b) |
| 2076 | while (b->next |
| 2077 | && b->next->type != bp_watchpoint |
| 2078 | && (sal.pc ? b->next->address == sal.pc |
| 2079 | : (b->next->symtab == sal.symtab |
| 2080 | && b->next->line_number == sal.line))) |
| 2081 | { |
| 2082 | b1 = b->next; |
| 2083 | b->next = b1->next; |
| 2084 | b1->next = found; |
| 2085 | found = b1; |
| 2086 | } |
| 2087 | |
| 2088 | if (found == 0) |
| 2089 | { |
| 2090 | if (arg) |
| 2091 | error ("No breakpoint at %s.", arg); |
| 2092 | else |
| 2093 | error ("No breakpoint at this line."); |
| 2094 | } |
| 2095 | |
| 2096 | if (found->next) from_tty = 1; /* Always report if deleted more than one */ |
| 2097 | if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : ""); |
| 2098 | while (found) |
| 2099 | { |
| 2100 | if (from_tty) printf ("%d ", found->number); |
| 2101 | b1 = found->next; |
| 2102 | delete_breakpoint (found); |
| 2103 | found = b1; |
| 2104 | } |
| 2105 | if (from_tty) putchar ('\n'); |
| 2106 | } |
| 2107 | free (sals.sals); |
| 2108 | } |
| 2109 | \f |
| 2110 | /* Delete breakpoint in BS if they are `delete' breakpoints. |
| 2111 | This is called after any breakpoint is hit, or after errors. */ |
| 2112 | |
| 2113 | void |
| 2114 | breakpoint_auto_delete (bs) |
| 2115 | bpstat bs; |
| 2116 | { |
| 2117 | for (; bs; bs = bs->next) |
| 2118 | if (bs->breakpoint_at && bs->breakpoint_at->disposition == delete) |
| 2119 | delete_breakpoint (bs->breakpoint_at); |
| 2120 | } |
| 2121 | |
| 2122 | /* Delete a breakpoint and clean up all traces of it in the data structures. */ |
| 2123 | |
| 2124 | void |
| 2125 | delete_breakpoint (bpt) |
| 2126 | struct breakpoint *bpt; |
| 2127 | { |
| 2128 | register struct breakpoint *b; |
| 2129 | register bpstat bs; |
| 2130 | |
| 2131 | if (bpt->inserted) |
| 2132 | target_remove_breakpoint(bpt->address, bpt->shadow_contents); |
| 2133 | |
| 2134 | if (breakpoint_chain == bpt) |
| 2135 | breakpoint_chain = bpt->next; |
| 2136 | |
| 2137 | ALL_BREAKPOINTS (b) |
| 2138 | if (b->next == bpt) |
| 2139 | { |
| 2140 | b->next = bpt->next; |
| 2141 | break; |
| 2142 | } |
| 2143 | |
| 2144 | check_duplicates (bpt->address); |
| 2145 | |
| 2146 | free_command_lines (&bpt->commands); |
| 2147 | if (bpt->cond) |
| 2148 | free (bpt->cond); |
| 2149 | if (bpt->cond_string != NULL) |
| 2150 | free (bpt->cond_string); |
| 2151 | if (bpt->addr_string != NULL) |
| 2152 | free (bpt->addr_string); |
| 2153 | |
| 2154 | if (xgdb_verbose && bpt->type == bp_breakpoint) |
| 2155 | printf ("breakpoint #%d deleted\n", bpt->number); |
| 2156 | |
| 2157 | /* Be sure no bpstat's are pointing at it after it's been freed. */ |
| 2158 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat for now. */ |
| 2159 | for (bs = stop_bpstat; bs; bs = bs->next) |
| 2160 | if (bs->breakpoint_at == bpt) |
| 2161 | bs->breakpoint_at = NULL; |
| 2162 | free (bpt); |
| 2163 | } |
| 2164 | |
| 2165 | static void |
| 2166 | delete_command (arg, from_tty) |
| 2167 | char *arg; |
| 2168 | int from_tty; |
| 2169 | { |
| 2170 | |
| 2171 | if (arg == 0) |
| 2172 | { |
| 2173 | /* Ask user only if there are some breakpoints to delete. */ |
| 2174 | if (!from_tty |
| 2175 | || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0))) |
| 2176 | { |
| 2177 | /* No arg; clear all breakpoints. */ |
| 2178 | while (breakpoint_chain) |
| 2179 | delete_breakpoint (breakpoint_chain); |
| 2180 | } |
| 2181 | } |
| 2182 | else |
| 2183 | map_breakpoint_numbers (arg, delete_breakpoint); |
| 2184 | } |
| 2185 | |
| 2186 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
| 2187 | The value we return ends up being the return value from catch_errors. |
| 2188 | Unused in this case. */ |
| 2189 | |
| 2190 | static int |
| 2191 | breakpoint_re_set_one (bint) |
| 2192 | char *bint; |
| 2193 | { |
| 2194 | struct breakpoint *b = (struct breakpoint *)bint; /* get past catch_errs */ |
| 2195 | int i; |
| 2196 | struct symtabs_and_lines sals; |
| 2197 | char *s; |
| 2198 | enum enable save_enable; |
| 2199 | |
| 2200 | if (b->type != bp_watchpoint && b->addr_string != NULL) |
| 2201 | { |
| 2202 | /* In case we have a problem, disable this breakpoint. We'll restore |
| 2203 | its status if we succeed. */ |
| 2204 | save_enable = b->enable; |
| 2205 | b->enable = disabled; |
| 2206 | |
| 2207 | s = b->addr_string; |
| 2208 | sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0); |
| 2209 | for (i = 0; i < sals.nelts; i++) |
| 2210 | { |
| 2211 | resolve_sal_pc (&sals.sals[i]); |
| 2212 | b->symtab = sals.sals[i].symtab; |
| 2213 | b->line_number = sals.sals[i].line; |
| 2214 | b->address = sals.sals[i].pc; |
| 2215 | |
| 2216 | if (b->cond_string != NULL) |
| 2217 | { |
| 2218 | s = b->cond_string; |
| 2219 | b->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), 0); |
| 2220 | } |
| 2221 | |
| 2222 | check_duplicates (b->address); |
| 2223 | |
| 2224 | b->enable = save_enable; /* Restore it, this worked. */ |
| 2225 | mention (b); |
| 2226 | } |
| 2227 | free (sals.sals); |
| 2228 | } |
| 2229 | else |
| 2230 | { |
| 2231 | /* Anything without a string can't be re-set. */ |
| 2232 | delete_breakpoint (b); |
| 2233 | } |
| 2234 | return 0; |
| 2235 | } |
| 2236 | |
| 2237 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
| 2238 | void |
| 2239 | breakpoint_re_set () |
| 2240 | { |
| 2241 | struct breakpoint *b, *temp; |
| 2242 | static char message1[] = "Error in re-setting breakpoint %d:\n"; |
| 2243 | char message[sizeof (message1) + 30 /* slop */]; |
| 2244 | |
| 2245 | ALL_BREAKPOINTS_SAFE (b, temp) |
| 2246 | { |
| 2247 | b->symtab = 0; /* Be sure we don't point to old dead symtab */ |
| 2248 | sprintf (message, message1, b->number); /* Format possible error msg */ |
| 2249 | (void) catch_errors (breakpoint_re_set_one, (char *) b, message); |
| 2250 | } |
| 2251 | |
| 2252 | /* Blank line to finish off all those mention() messages we just printed. */ |
| 2253 | printf_filtered ("\n"); |
| 2254 | } |
| 2255 | \f |
| 2256 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
| 2257 | If from_tty is nonzero, it prints a message to that effect, |
| 2258 | which ends with a period (no newline). */ |
| 2259 | |
| 2260 | void |
| 2261 | set_ignore_count (bptnum, count, from_tty) |
| 2262 | int bptnum, count, from_tty; |
| 2263 | { |
| 2264 | register struct breakpoint *b; |
| 2265 | |
| 2266 | if (count < 0) |
| 2267 | count = 0; |
| 2268 | |
| 2269 | ALL_BREAKPOINTS (b) |
| 2270 | if (b->number == bptnum) |
| 2271 | { |
| 2272 | b->ignore_count = count; |
| 2273 | if (!from_tty) |
| 2274 | return; |
| 2275 | else if (count == 0) |
| 2276 | printf ("Will stop next time breakpoint %d is reached.", bptnum); |
| 2277 | else if (count == 1) |
| 2278 | printf ("Will ignore next crossing of breakpoint %d.", bptnum); |
| 2279 | else |
| 2280 | printf ("Will ignore next %d crossings of breakpoint %d.", |
| 2281 | count, bptnum); |
| 2282 | return; |
| 2283 | } |
| 2284 | |
| 2285 | error ("No breakpoint number %d.", bptnum); |
| 2286 | } |
| 2287 | |
| 2288 | /* Clear the ignore counts of all breakpoints. */ |
| 2289 | void |
| 2290 | breakpoint_clear_ignore_counts () |
| 2291 | { |
| 2292 | struct breakpoint *b; |
| 2293 | |
| 2294 | ALL_BREAKPOINTS (b) |
| 2295 | b->ignore_count = 0; |
| 2296 | } |
| 2297 | |
| 2298 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
| 2299 | |
| 2300 | static void |
| 2301 | ignore_command (args, from_tty) |
| 2302 | char *args; |
| 2303 | int from_tty; |
| 2304 | { |
| 2305 | char *p = args; |
| 2306 | register int num; |
| 2307 | |
| 2308 | if (p == 0) |
| 2309 | error_no_arg ("a breakpoint number"); |
| 2310 | |
| 2311 | num = get_number (&p); |
| 2312 | |
| 2313 | if (*p == 0) |
| 2314 | error ("Second argument (specified ignore-count) is missing."); |
| 2315 | |
| 2316 | set_ignore_count (num, |
| 2317 | longest_to_int (value_as_long (parse_and_eval (p))), |
| 2318 | from_tty); |
| 2319 | printf ("\n"); |
| 2320 | } |
| 2321 | \f |
| 2322 | /* Call FUNCTION on each of the breakpoints |
| 2323 | whose numbers are given in ARGS. */ |
| 2324 | |
| 2325 | static void |
| 2326 | map_breakpoint_numbers (args, function) |
| 2327 | char *args; |
| 2328 | void (*function) PARAMS ((struct breakpoint *)); |
| 2329 | { |
| 2330 | register char *p = args; |
| 2331 | char *p1; |
| 2332 | register int num; |
| 2333 | register struct breakpoint *b; |
| 2334 | |
| 2335 | if (p == 0) |
| 2336 | error_no_arg ("one or more breakpoint numbers"); |
| 2337 | |
| 2338 | while (*p) |
| 2339 | { |
| 2340 | p1 = p; |
| 2341 | |
| 2342 | num = get_number (&p1); |
| 2343 | |
| 2344 | ALL_BREAKPOINTS (b) |
| 2345 | if (b->number == num) |
| 2346 | { |
| 2347 | function (b); |
| 2348 | goto win; |
| 2349 | } |
| 2350 | printf ("No breakpoint number %d.\n", num); |
| 2351 | win: |
| 2352 | p = p1; |
| 2353 | } |
| 2354 | } |
| 2355 | |
| 2356 | static void |
| 2357 | enable_breakpoint (bpt) |
| 2358 | struct breakpoint *bpt; |
| 2359 | { |
| 2360 | bpt->enable = enabled; |
| 2361 | |
| 2362 | if (xgdb_verbose && bpt->type == bp_breakpoint) |
| 2363 | printf ("breakpoint #%d enabled\n", bpt->number); |
| 2364 | |
| 2365 | check_duplicates (bpt->address); |
| 2366 | if (bpt->type == bp_watchpoint) |
| 2367 | { |
| 2368 | if (bpt->exp_valid_block != NULL |
| 2369 | && !contained_in (get_selected_block (), bpt->exp_valid_block)) |
| 2370 | { |
| 2371 | printf_filtered ("\ |
| 2372 | Cannot enable watchpoint %d because the block in which its expression\n\ |
| 2373 | is valid is not currently in scope.\n", bpt->number); |
| 2374 | return; |
| 2375 | } |
| 2376 | |
| 2377 | value_free (bpt->val); |
| 2378 | |
| 2379 | bpt->val = evaluate_expression (bpt->exp); |
| 2380 | release_value (bpt->val); |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | /* ARGSUSED */ |
| 2385 | static void |
| 2386 | enable_command (args, from_tty) |
| 2387 | char *args; |
| 2388 | int from_tty; |
| 2389 | { |
| 2390 | struct breakpoint *bpt; |
| 2391 | if (args == 0) |
| 2392 | ALL_BREAKPOINTS (bpt) |
| 2393 | enable_breakpoint (bpt); |
| 2394 | else |
| 2395 | map_breakpoint_numbers (args, enable_breakpoint); |
| 2396 | } |
| 2397 | |
| 2398 | static void |
| 2399 | disable_breakpoint (bpt) |
| 2400 | struct breakpoint *bpt; |
| 2401 | { |
| 2402 | bpt->enable = disabled; |
| 2403 | |
| 2404 | if (xgdb_verbose && bpt->type == bp_breakpoint) |
| 2405 | printf ("breakpoint #%d disabled\n", bpt->number); |
| 2406 | |
| 2407 | check_duplicates (bpt->address); |
| 2408 | } |
| 2409 | |
| 2410 | /* ARGSUSED */ |
| 2411 | static void |
| 2412 | disable_command (args, from_tty) |
| 2413 | char *args; |
| 2414 | int from_tty; |
| 2415 | { |
| 2416 | register struct breakpoint *bpt; |
| 2417 | if (args == 0) |
| 2418 | ALL_BREAKPOINTS (bpt) |
| 2419 | disable_breakpoint (bpt); |
| 2420 | else |
| 2421 | map_breakpoint_numbers (args, disable_breakpoint); |
| 2422 | } |
| 2423 | |
| 2424 | static void |
| 2425 | enable_once_breakpoint (bpt) |
| 2426 | struct breakpoint *bpt; |
| 2427 | { |
| 2428 | bpt->enable = enabled; |
| 2429 | bpt->disposition = disable; |
| 2430 | |
| 2431 | check_duplicates (bpt->address); |
| 2432 | } |
| 2433 | |
| 2434 | /* ARGSUSED */ |
| 2435 | static void |
| 2436 | enable_once_command (args, from_tty) |
| 2437 | char *args; |
| 2438 | int from_tty; |
| 2439 | { |
| 2440 | map_breakpoint_numbers (args, enable_once_breakpoint); |
| 2441 | } |
| 2442 | |
| 2443 | static void |
| 2444 | enable_delete_breakpoint (bpt) |
| 2445 | struct breakpoint *bpt; |
| 2446 | { |
| 2447 | bpt->enable = enabled; |
| 2448 | bpt->disposition = delete; |
| 2449 | |
| 2450 | check_duplicates (bpt->address); |
| 2451 | } |
| 2452 | |
| 2453 | /* ARGSUSED */ |
| 2454 | static void |
| 2455 | enable_delete_command (args, from_tty) |
| 2456 | char *args; |
| 2457 | int from_tty; |
| 2458 | { |
| 2459 | map_breakpoint_numbers (args, enable_delete_breakpoint); |
| 2460 | } |
| 2461 | \f |
| 2462 | /* |
| 2463 | * Use default_breakpoint_'s, or nothing if they aren't valid. |
| 2464 | */ |
| 2465 | struct symtabs_and_lines |
| 2466 | decode_line_spec_1 (string, funfirstline) |
| 2467 | char *string; |
| 2468 | int funfirstline; |
| 2469 | { |
| 2470 | struct symtabs_and_lines sals; |
| 2471 | if (string == 0) |
| 2472 | error ("Empty line specification."); |
| 2473 | if (default_breakpoint_valid) |
| 2474 | sals = decode_line_1 (&string, funfirstline, |
| 2475 | default_breakpoint_symtab, default_breakpoint_line); |
| 2476 | else |
| 2477 | sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0); |
| 2478 | if (*string) |
| 2479 | error ("Junk at end of line specification: %s", string); |
| 2480 | return sals; |
| 2481 | } |
| 2482 | \f |
| 2483 | |
| 2484 | /* Chain containing all defined enable commands. */ |
| 2485 | |
| 2486 | extern struct cmd_list_element |
| 2487 | *enablelist, *disablelist, |
| 2488 | *deletelist, *enablebreaklist; |
| 2489 | |
| 2490 | extern struct cmd_list_element *cmdlist; |
| 2491 | |
| 2492 | void |
| 2493 | _initialize_breakpoint () |
| 2494 | { |
| 2495 | breakpoint_chain = 0; |
| 2496 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful |
| 2497 | before a breakpoint is set. */ |
| 2498 | breakpoint_count = 0; |
| 2499 | |
| 2500 | add_com ("ignore", class_breakpoint, ignore_command, |
| 2501 | "Set ignore-count of breakpoint number N to COUNT."); |
| 2502 | |
| 2503 | add_com ("commands", class_breakpoint, commands_command, |
| 2504 | "Set commands to be executed when a breakpoint is hit.\n\ |
| 2505 | Give breakpoint number as argument after \"commands\".\n\ |
| 2506 | With no argument, the targeted breakpoint is the last one set.\n\ |
| 2507 | The commands themselves follow starting on the next line.\n\ |
| 2508 | Type a line containing \"end\" to indicate the end of them.\n\ |
| 2509 | Give \"silent\" as the first line to make the breakpoint silent;\n\ |
| 2510 | then no output is printed when it is hit, except what the commands print."); |
| 2511 | |
| 2512 | add_com ("condition", class_breakpoint, condition_command, |
| 2513 | "Specify breakpoint number N to break only if COND is true.\n\ |
| 2514 | N is an integer; COND is an expression to be evaluated whenever\n\ |
| 2515 | breakpoint N is reached. "); |
| 2516 | |
| 2517 | add_com ("tbreak", class_breakpoint, tbreak_command, |
| 2518 | "Set a temporary breakpoint. Args like \"break\" command.\n\ |
| 2519 | Like \"break\" except the breakpoint is only enabled temporarily,\n\ |
| 2520 | so it will be disabled when hit. Equivalent to \"break\" followed\n\ |
| 2521 | by using \"enable once\" on the breakpoint number."); |
| 2522 | |
| 2523 | add_prefix_cmd ("enable", class_breakpoint, enable_command, |
| 2524 | "Enable some breakpoints.\n\ |
| 2525 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 2526 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ |
| 2527 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 2528 | With a subcommand you can enable temporarily.", |
| 2529 | &enablelist, "enable ", 1, &cmdlist); |
| 2530 | |
| 2531 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, |
| 2532 | "Enable some breakpoints.\n\ |
| 2533 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
| 2534 | This is used to cancel the effect of the \"disable\" command.\n\ |
| 2535 | May be abbreviated to simply \"enable\".\n", |
| 2536 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
| 2537 | |
| 2538 | add_cmd ("once", no_class, enable_once_command, |
| 2539 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 2540 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\ |
| 2541 | See the \"tbreak\" command which sets a breakpoint and enables it once.", |
| 2542 | &enablebreaklist); |
| 2543 | |
| 2544 | add_cmd ("delete", no_class, enable_delete_command, |
| 2545 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 2546 | If a breakpoint is hit while enabled in this fashion, it is deleted.", |
| 2547 | &enablebreaklist); |
| 2548 | |
| 2549 | add_cmd ("delete", no_class, enable_delete_command, |
| 2550 | "Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ |
| 2551 | If a breakpoint is hit while enabled in this fashion, it is deleted.", |
| 2552 | &enablelist); |
| 2553 | |
| 2554 | add_cmd ("once", no_class, enable_once_command, |
| 2555 | "Enable breakpoints for one hit. Give breakpoint numbers.\n\ |
| 2556 | If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\ |
| 2557 | See the \"tbreak\" command which sets a breakpoint and enables it once.", |
| 2558 | &enablelist); |
| 2559 | |
| 2560 | add_prefix_cmd ("disable", class_breakpoint, disable_command, |
| 2561 | "Disable some breakpoints.\n\ |
| 2562 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 2563 | To disable all breakpoints, give no argument.\n\ |
| 2564 | A disabled breakpoint is not forgotten, but has no effect until reenabled.", |
| 2565 | &disablelist, "disable ", 1, &cmdlist); |
| 2566 | add_com_alias ("dis", "disable", class_breakpoint, 1); |
| 2567 | add_com_alias ("disa", "disable", class_breakpoint, 1); |
| 2568 | |
| 2569 | add_cmd ("breakpoints", class_alias, disable_command, |
| 2570 | "Disable some breakpoints.\n\ |
| 2571 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 2572 | To disable all breakpoints, give no argument.\n\ |
| 2573 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ |
| 2574 | This command may be abbreviated \"disable\".", |
| 2575 | &disablelist); |
| 2576 | |
| 2577 | add_prefix_cmd ("delete", class_breakpoint, delete_command, |
| 2578 | "Delete some breakpoints or auto-display expressions.\n\ |
| 2579 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 2580 | To delete all breakpoints, give no argument.\n\ |
| 2581 | \n\ |
| 2582 | Also a prefix command for deletion of other GDB objects.\n\ |
| 2583 | The \"unset\" command is also an alias for \"delete\".", |
| 2584 | &deletelist, "delete ", 1, &cmdlist); |
| 2585 | add_com_alias ("d", "delete", class_breakpoint, 1); |
| 2586 | |
| 2587 | add_cmd ("breakpoints", class_alias, delete_command, |
| 2588 | "Delete some breakpoints or auto-display expressions.\n\ |
| 2589 | Arguments are breakpoint numbers with spaces in between.\n\ |
| 2590 | To delete all breakpoints, give no argument.\n\ |
| 2591 | This command may be abbreviated \"delete\".", |
| 2592 | &deletelist); |
| 2593 | |
| 2594 | add_com ("clear", class_breakpoint, clear_command, |
| 2595 | "Clear breakpoint at specified line or function.\n\ |
| 2596 | Argument may be line number, function name, or \"*\" and an address.\n\ |
| 2597 | If line number is specified, all breakpoints in that line are cleared.\n\ |
| 2598 | If function is specified, breakpoints at beginning of function are cleared.\n\ |
| 2599 | If an address is specified, breakpoints at that address are cleared.\n\n\ |
| 2600 | With no argument, clears all breakpoints in the line that the selected frame\n\ |
| 2601 | is executing in.\n\ |
| 2602 | \n\ |
| 2603 | See also the \"delete\" command which clears breakpoints by number."); |
| 2604 | |
| 2605 | add_com ("break", class_breakpoint, break_command, |
| 2606 | "Set breakpoint at specified line or function.\n\ |
| 2607 | Argument may be line number, function name, or \"*\" and an address.\n\ |
| 2608 | If line number is specified, break at start of code for that line.\n\ |
| 2609 | If function is specified, break at start of code for that function.\n\ |
| 2610 | If an address is specified, break at that exact address.\n\ |
| 2611 | With no arg, uses current execution address of selected stack frame.\n\ |
| 2612 | This is useful for breaking on return to a stack frame.\n\ |
| 2613 | \n\ |
| 2614 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ |
| 2615 | \n\ |
| 2616 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); |
| 2617 | add_com_alias ("b", "break", class_run, 1); |
| 2618 | add_com_alias ("br", "break", class_run, 1); |
| 2619 | add_com_alias ("bre", "break", class_run, 1); |
| 2620 | add_com_alias ("brea", "break", class_run, 1); |
| 2621 | |
| 2622 | add_info ("breakpoints", breakpoints_info, |
| 2623 | "Status of all breakpoints, or breakpoint number NUMBER.\n\ |
| 2624 | Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\ |
| 2625 | \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\ |
| 2626 | Then come the address and the file/line number.\n\n\ |
| 2627 | Convenience variable \"$_\" and default examine address for \"x\"\n\ |
| 2628 | are set to the address of the last breakpoint listed.\n\n\ |
| 2629 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
| 2630 | breakpoint set."); |
| 2631 | |
| 2632 | add_com ("catch", class_breakpoint, catch_command, |
| 2633 | "Set breakpoints to catch exceptions that are raised.\n\ |
| 2634 | Argument may be a single exception to catch, multiple exceptions\n\ |
| 2635 | to catch, or the default exception \"default\". If no arguments\n\ |
| 2636 | are given, breakpoints are set at all exception handlers catch clauses\n\ |
| 2637 | within the current scope.\n\ |
| 2638 | \n\ |
| 2639 | A condition specified for the catch applies to all breakpoints set\n\ |
| 2640 | with this command\n\ |
| 2641 | \n\ |
| 2642 | Do \"help breakpoints\" for info on other commands dealing with breakpoints."); |
| 2643 | |
| 2644 | add_com ("watch", class_breakpoint, watch_command, |
| 2645 | "Set a watchpoint for an expression.\n\ |
| 2646 | A watchpoint stops execution of your program whenever the value of\n\ |
| 2647 | an expression changes."); |
| 2648 | |
| 2649 | add_info ("watchpoints", watchpoints_info, |
| 2650 | "Status of all watchpoints, or watchpoint number NUMBER.\n\ |
| 2651 | Second column is \"y\" for enabled watchpoints, \"n\" for disabled."); |
| 2652 | } |