Annotation of gdb/breakpoint.c, revision 1.1.1.3

1.1       root        1: /* Everything about breakpoints, for GDB.
                      2:    Copyright (C) 1986, 1987 Free Software Foundation, Inc.
                      3: 
                      4: GDB is distributed in the hope that it will be useful, but WITHOUT ANY
                      5: WARRANTY.  No author or distributor accepts responsibility to anyone
                      6: for the consequences of using it or for whether it serves any
                      7: particular purpose or works at all, unless he says so in writing.
                      8: Refer to the GDB General Public License for full details.
                      9: 
                     10: Everyone is granted permission to copy, modify and redistribute GDB,
                     11: but only under the conditions described in the GDB General Public
                     12: License.  A copy of this license is supposed to have been given to you
                     13: along with GDB so you can know your rights and responsibilities.  It
                     14: should be in a file named COPYING.  Among other things, the copyright
                     15: notice and this notice must be preserved on all copies.
                     16: 
                     17: In other words, go ahead and share GDB, but don't try to stop
                     18: anyone else from sharing it farther.  Help stamp out software hoarding!
                     19: */
                     20: 
                     21: #include "defs.h"
                     22: #include "initialize.h"
                     23: #include "param.h"
                     24: #include "symtab.h"
                     25: #include "frame.h"
                     26: 
                     27: #include <stdio.h>
                     28: 
                     29: /* This is the sequence of bytes we insert for a breakpoint.  */
                     30: 
                     31: static char break_insn[] = BREAKPOINT;
                     32: 
                     33: /* States of enablement of breakpoint.
                     34:    `temporary' means disable when hit.
                     35:    `once' means delete when hit.  */
                     36: 
                     37: enum enable { disabled, enabled, temporary, delete};
                     38: 
                     39: struct breakpoint
                     40: {
                     41:   struct breakpoint *next;
                     42:   /* Number assigned to distinguish breakpoints.  */
                     43:   int number;
                     44:   /* Address to break at.  */
                     45:   CORE_ADDR address;
                     46:   /* Line number of this address.  Redundant.  */
                     47:   int line_number;
                     48:   /* Symtab of file of this address.  Redundant.  */
                     49:   struct symtab *symtab;
                     50:   /* Zero means disabled; remember the info but don't break here.  */
                     51:   enum enable enable;
                     52:   /* Number of stops at this breakpoint that should
                     53:      be continued automatically before really stopping.  */
                     54:   int ignore_count;
                     55:   /* "Real" contents of byte where breakpoint has been inserted.
                     56:      Valid only when breakpoints are in the program.  */
                     57:   char shadow_contents[sizeof break_insn];
                     58:   /* Nonzero if this breakpoint is now inserted.  */
                     59:   char inserted;
                     60:   /* Nonzero if this is not the first breakpoint in the list
                     61:      for the given address.  */
                     62:   char duplicate;
                     63:   /* Chain of command lines to execute when this breakpoint is hit.  */
                     64:   struct command_line *commands;
                     65:   /* Stack depth (frame).  If nonzero, break only if fp equals this.  */
                     66:   FRAME frame;
                     67:   /* Conditional.  Break only if this expression's value is nonzero.  */
                     68:   struct expression *cond;
                     69: };
                     70: 
                     71: #define ALL_BREAKPOINTS(b)  for (b = breakpoint_chain; b; b = b->next)
                     72: 
                     73: /* Chain of all breakpoints defined.  */
                     74: 
                     75: struct breakpoint *breakpoint_chain;
                     76: 
                     77: /* Number of last breakpoint made.  */
                     78: 
                     79: static int breakpoint_count;
                     80: 
                     81: /* Default address, symtab and line to put a breakpoint at
                     82:    for "break" command with no arg.
                     83:    if default_breakpoint_valid is zero, the other three are
                     84:    not valid, and "break" with no arg is an error.
                     85: 
                     86:    This set by print_stack_frame, which calls set_default_breakpoint.  */
                     87: 
                     88: int default_breakpoint_valid;
                     89: CORE_ADDR default_breakpoint_address;
                     90: struct symtab *default_breakpoint_symtab;
                     91: int default_breakpoint_line;
                     92: 
                     93: /* Remaining commands (not yet executed)
                     94:    of last breakpoint hit.  */
                     95: 
                     96: struct command_line *breakpoint_commands;
                     97: 
                     98: START_FILE
                     99: 
                    100: extern char *read_line ();
                    101: 
                    102: static void delete_breakpoint ();
                    103: void clear_momentary_breakpoints ();
                    104: void breakpoint_auto_delete ();
                    105: 
                    106: /* condition N EXP -- set break condition of breakpoint N to EXP.  */
                    107: 
                    108: static void
                    109: condition_command (arg, from_tty)
                    110:      char *arg;
                    111:      int from_tty;
                    112: {
                    113:   register struct breakpoint *b;
                    114:   register char *p;
                    115:   register int bnum;
                    116:   register struct expression *expr;
                    117: 
                    118:   if (arg == 0)
                    119:     error_no_arg ("breakpoint number");
                    120: 
                    121:   p = arg;
                    122:   while (*p >= '0' && *p <= '9') p++;
                    123:   bnum = atoi (arg);
                    124: 
                    125:   ALL_BREAKPOINTS (b)
                    126:     if (b->number == bnum)
                    127:       {
                    128:        if (b->cond)
                    129:          free (b->cond);
                    130:        if (*p == 0)
                    131:          {
                    132:            b->cond = 0;
                    133:            if (from_tty)
                    134:              printf ("Breakpoint %d now unconditional.\n", bnum);
                    135:          }
                    136:        else
                    137:          {
                    138:            if (*p != ' ' && *p != '\t')
                    139:              error ("Arguments must be an integer (breakpoint number) and an expression.");
                    140: 
                    141:            /* Find start of expression */
                    142:            while (*p == ' ' || *p == '\t') p++;
                    143: 
                    144:            arg = p;
1.1.1.3 ! root      145:            b->cond = (struct expression *) parse_c_1 (&arg, block_for_pc (b->address), 0);
        !           146:            if (*arg)
        !           147:              error ("Junk at end of expression");
1.1       root      148:          }
                    149:        return;
                    150:       }
                    151: 
                    152:   error ("No breakpoint number %d.", bnum);
                    153: }
                    154: 
                    155: static void
                    156: commands_command (arg)
                    157:      char *arg;
                    158: {
                    159:   register struct breakpoint *b;
                    160:   register char *p, *p1;
                    161:   register int bnum;
                    162:   struct command_line *l;
                    163: 
                    164:   if (arg == 0)
                    165:     error_no_arg ("breakpoint number");
                    166: 
                    167:   /* If we allowed this, we would have problems with when to
                    168:      free the storage, if we change the commands currently
                    169:      being read from.  */
                    170: 
                    171:   if (breakpoint_commands)
                    172:     error ("Can't use the \"commands\" command among a breakpoint's commands.");
                    173: 
                    174:   p = arg;
                    175:   if (! (*p >= '0' && *p <= '9'))
                    176:     error ("Argument must be integer (a breakpoint number).");
                    177: 
                    178:   while (*p >= '0' && *p <= '9') p++;
                    179:   if (*p)
                    180:     error ("Unexpected extra arguments following breakpoint number.");
                    181: 
                    182:   bnum = atoi (arg);
                    183: 
                    184:   ALL_BREAKPOINTS (b)
                    185:     if (b->number == bnum)
                    186:       {
                    187:        if (input_from_terminal_p ())
                    188:          printf ("Type commands for when breakpoint %d is hit, one per line.\n\
                    189: End with a line saying just \"end\".\n", bnum);
                    190:        l = read_command_lines ();
                    191:        free_command_lines (&b->commands);
                    192:        b->commands = l;
                    193:        return;
                    194:       }
                    195:   error ("No breakpoint number %d.", bnum);
                    196: }
                    197: 
                    198: /* Called from command loop to execute the commands
                    199:    associated with the breakpoint we just stopped at.  */
                    200: 
                    201: void
                    202: do_breakpoint_commands ()
                    203: {
                    204:   while (breakpoint_commands)
                    205:     {
1.1.1.2   root      206:       char *line = breakpoint_commands->line;
                    207:       breakpoint_commands = breakpoint_commands->next;
                    208:       execute_command (line, 0);
                    209:       /* If command was "cont", breakpoint_commands is now 0,
                    210:         of if we stopped at yet another breakpoint which has commands,
                    211:         it is now the commands for the new breakpoint.  */
1.1       root      212:     }
                    213:   clear_momentary_breakpoints ();
                    214: }
                    215: 
                    216: /* Used when the program is proceeded, to eliminate any remaining
                    217:    commands attached to the previous breakpoint we stopped at.  */
                    218: 
                    219: void
                    220: clear_breakpoint_commands ()
                    221: {
                    222:   breakpoint_commands = 0;
                    223:   breakpoint_auto_delete (0);
                    224: }
1.1.1.2   root      225: 
                    226: /* Functions to get and set the current list of pending
                    227:    breakpoint commands.  These are used by run_stack_dummy
                    228:    to preserve the commands around a function call.  */
                    229: 
                    230: struct command_line *
                    231: get_breakpoint_commands ()
                    232: {
                    233:   return breakpoint_commands;
                    234: }
                    235: 
                    236: void
                    237: set_breakpoint_commands (cmds)
                    238:      struct command_line *cmds;
                    239: {
                    240:   breakpoint_commands = cmds;
                    241: }
1.1       root      242: 
                    243: /* insert_breakpoints is used when starting or continuing the program.
                    244:    remove_breakpoints is used when the program stops.
1.1.1.2   root      245:    Both return zero if successful,
                    246:    or an `errno' value if could not write the inferior.  */
1.1       root      247: 
                    248: int
                    249: insert_breakpoints ()
                    250: {
                    251:   register struct breakpoint *b;
1.1.1.2   root      252:   int val;
1.1       root      253: 
                    254: /*   printf ("Inserting breakpoints.\n"); */
                    255:   ALL_BREAKPOINTS (b)
                    256:     if (b->enable != disabled && ! b->inserted && ! b->duplicate)
                    257:       {
                    258:        read_memory (b->address, b->shadow_contents, sizeof break_insn);
1.1.1.2   root      259:        val = write_memory (b->address, break_insn, sizeof break_insn);
                    260:        if (val)
                    261:          return val;
1.1       root      262: /*     printf ("Inserted breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
                    263:                b->address, b->shadow_contents[0], b->shadow_contents[1]); */
                    264:        b->inserted = 1;
                    265:       }
                    266:   return 0;
                    267: }
                    268: 
                    269: int
                    270: remove_breakpoints ()
                    271: {
                    272:   register struct breakpoint *b;
1.1.1.2   root      273:   int val;
1.1       root      274: 
                    275: /*   printf ("Removing breakpoints.\n"); */
                    276:   ALL_BREAKPOINTS (b)
                    277:     if (b->inserted)
                    278:       {
1.1.1.2   root      279:        val = write_memory (b->address, b->shadow_contents, sizeof break_insn);
                    280:        if (val)
                    281:          return val;
1.1       root      282:        b->inserted = 0;
                    283: /*     printf ("Removed breakpoint at 0x%x, shadow 0x%x, 0x%x.\n",
                    284:                b->address, b->shadow_contents[0], b->shadow_contents[1]); */
                    285:       }
                    286: 
                    287:   return 0;
                    288: }
                    289: 
                    290: /* Clear the "inserted" flag in all breakpoints.
                    291:    This is done when the inferior is loaded.  */
                    292: 
                    293: int
                    294: mark_breakpoints_out ()
                    295: {
                    296:   register struct breakpoint *b;
                    297: 
                    298:   ALL_BREAKPOINTS (b)
                    299:     b->inserted = 0;
                    300: }
                    301: 
                    302: /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
                    303:    When continuing from a location with a breakpoint,
                    304:    we actually single step once before calling insert_breakpoints.  */
                    305: 
                    306: int
                    307: breakpoint_here_p (pc)
                    308:      CORE_ADDR pc;
                    309: {
                    310:   register struct breakpoint *b;
                    311: 
                    312:   ALL_BREAKPOINTS (b)
                    313:     if (b->enable != disabled && b->address == pc)
                    314:       return 1;
                    315: 
                    316:   return 0;
                    317: }
                    318: 
                    319: /* Return 0 if PC is not the address just after a breakpoint,
                    320:    or -1 if breakpoint says do not stop now,
                    321:    or -2 if breakpoint says it has deleted itself and don't stop,
                    322:    or -3 if hit a breakpoint number -3 (delete when program stops),
                    323:    or else the number of the breakpoint,
                    324:    with 0x1000000 added for a silent breakpoint.  */
                    325: 
                    326: int
                    327: breakpoint_stop_status (pc, frame)
                    328:      CORE_ADDR pc;
                    329:      FRAME frame;
                    330: {
                    331:   register struct breakpoint *b;
                    332:   register int cont = 0;
                    333: 
                    334:   /* Get the address where the breakpoint would have been.  */
                    335:   pc -= DECR_PC_AFTER_BREAK;
                    336: 
                    337:   ALL_BREAKPOINTS (b)
                    338:     if (b->enable != disabled && b->address == pc)
                    339:       {
                    340:        if (b->frame && b->frame != frame)
                    341:          cont = -1;
                    342:        else
                    343:          {
                    344:            int value_zero;
                    345:            if (b->cond)
                    346:              {
                    347:                value_zero = value_zerop (evaluate_expression (b->cond));
                    348:                free_all_values ();
                    349:              }
                    350:            if (b->cond && value_zero)
                    351:              {
                    352:                cont = -1;
                    353:              }
                    354:            else if (b->ignore_count > 0)
                    355:              {
                    356:                b->ignore_count--;
                    357:                cont = -1;
                    358:              }
                    359:            else
                    360:              {
                    361:                if (b->enable == temporary)
                    362:                  b->enable = disabled;
                    363:                breakpoint_commands = b->commands;
                    364:                if (breakpoint_commands
                    365:                    && !strcmp ("silent", breakpoint_commands->line))
                    366:                  {
                    367:                    breakpoint_commands = breakpoint_commands->next;
                    368:                    return 0x1000000 + b->number;
                    369:                  }
                    370:                return b->number;
                    371:              }
                    372:          }
                    373:       }
                    374: 
                    375:   return cont;
                    376: }
                    377: 
                    378: static void
                    379: breakpoint_1 (bnum)
                    380:      int bnum;
                    381: {
                    382:   register struct breakpoint *b;
                    383:   register struct command_line *l;
                    384:   register struct symbol *sym;
                    385:   CORE_ADDR last_addr = -1;
                    386: 
                    387:   ALL_BREAKPOINTS (b)
                    388:     if (bnum == -1 || bnum == b->number)
                    389:       {
                    390:        printf ("#%-3d %c  0x%08x ", b->number,
                    391:                "nyod"[(int) b->enable],
                    392:                b->address);
                    393:        last_addr = b->address;
                    394:        if (b->symtab)
                    395:          {
                    396:            sym = find_pc_function (b->address);
                    397:            if (sym)
                    398:              printf (" in %s (%s line %d)", SYMBOL_NAME (sym),
                    399:                      b->symtab->filename, b->line_number);
                    400:            else
                    401:              printf ("%s line %d", b->symtab->filename, b->line_number);
                    402:          }
                    403:        printf ("\n");
                    404: 
                    405:        if (b->ignore_count)
                    406:          printf ("\tignore next %d hits\n", b->ignore_count);
                    407:        if (b->frame)
                    408:          printf ("\tstop only in stack frame at 0x%x\n", b->frame);
                    409:        if (b->cond)
                    410:          {
                    411:            printf ("\tbreak only if ");
                    412:            print_expression (b->cond, stdout);
                    413:            printf ("\n");
                    414:          }
                    415:        if (l = b->commands)
                    416:          while (l)
                    417:            {
                    418:              printf ("\t%s\n", l->line);
                    419:              l = l->next;
                    420:            }
                    421:       }
                    422: 
                    423:   if (last_addr != -1)
                    424:     set_next_address (last_addr);
                    425: }
                    426: 
                    427: static void
                    428: breakpoints_info (bnum_exp)
                    429:      char *bnum_exp;
                    430: {
                    431:   int bnum = -1;
                    432: 
                    433:   if (bnum_exp)
                    434:     bnum = parse_and_eval_address (bnum_exp);
                    435:   else if (breakpoint_chain == 0)
                    436:     printf ("No breakpoints.\n");
                    437:   else
                    438:     printf ("Breakpoints:\n\
                    439: Num Enb   Address    Where\n");
                    440: 
                    441:   breakpoint_1 (bnum);
                    442: }
1.1.1.2   root      443: 
                    444: /* Print a message describing any breakpoints set at PC.  */
                    445: 
                    446: static void
                    447: describe_other_breakpoints (pc)
                    448:      register CORE_ADDR pc;
                    449: {
                    450:   register int others = 0;
                    451:   register struct breakpoint *b;
                    452: 
                    453:   ALL_BREAKPOINTS (b)
                    454:     if (b->address == pc)
                    455:       others++;
                    456:   if (others > 0)
                    457:     {
                    458:       printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
                    459:       ALL_BREAKPOINTS (b)
                    460:        if (b->address == pc)
                    461:          {
                    462:            others--;
                    463:            printf ("%d%s%s ",
                    464:                    b->number,
                    465:                    (b->enable == disabled) ? " (disabled)" : "",
                    466:                    (others > 1) ? "," : ((others == 1) ? " and" : ""));
                    467:          }
                    468:       printf (" also set at pc 0x%x\n", pc);
                    469:     }
                    470: }
1.1       root      471: 
1.1.1.2   root      472: /* Set the default place to put a breakpoint
                    473:    for the `break' command with no arguments.  */
                    474: 
1.1       root      475: void
                    476: set_default_breakpoint (valid, addr, symtab, line)
                    477:      int valid;
                    478:      CORE_ADDR addr;
                    479:      struct symtab *symtab;
                    480:      int line;
                    481: {
                    482:   default_breakpoint_valid = valid;
                    483:   default_breakpoint_address = addr;
                    484:   default_breakpoint_symtab = symtab;
                    485:   default_breakpoint_line = line;
                    486: }
                    487: 
                    488: /* Rescan breakpoints at address ADDRESS,
                    489:    marking the first one as "first" and any others as "duplicates".
                    490:    This is so that the bpt instruction is only inserted once.  */
                    491: 
                    492: static void
                    493: check_duplicates (address)
                    494:      CORE_ADDR address;
                    495: {
                    496:   register struct breakpoint *b;
                    497:   register int count = 0;
                    498: 
                    499:   ALL_BREAKPOINTS (b)
                    500:     if (b->enable != disabled && b->address == address)
                    501:       {
                    502:        count++;
                    503:        b->duplicate = count > 1;
                    504:       }
                    505: }
                    506: 
                    507: /* Low level routine to set a breakpoint.
                    508:    Takes as args the three things that every breakpoint must have.
                    509:    Returns the breakpoint object so caller can set other things.
                    510:    Does not set the breakpoint number!
                    511:    Does not print anything.  */
                    512: 
                    513: static struct breakpoint *
                    514: set_raw_breakpoint (sal)
                    515:      struct symtab_and_line sal;
                    516: {
                    517:   register struct breakpoint *b, *b1;
                    518: 
                    519:   b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
                    520:   bzero (b, sizeof *b);
                    521:   b->address = sal.pc;
                    522:   b->symtab = sal.symtab;
                    523:   b->line_number = sal.line;
                    524:   b->enable = enabled;
                    525:   b->next = 0;
                    526: 
                    527:   /* Add this breakpoint to the end of the chain
                    528:      so that a list of breakpoints will come out in order
                    529:      of increasing numbers.  */
                    530: 
                    531:   b1 = breakpoint_chain;
                    532:   if (b1 == 0)
                    533:     breakpoint_chain = b;
                    534:   else
                    535:     {
                    536:       while (b1->next)
                    537:        b1 = b1->next;
                    538:       b1->next = b;
                    539:     }
                    540: 
                    541:   check_duplicates (sal.pc);
                    542: 
                    543:   return b;
                    544: }
                    545: 
                    546: /* Set a breakpoint that will evaporate an end of command
                    547:    at address specified by SAL.
                    548:    Restrict it to frame FRAME if FRAME is nonzero.  */
                    549: 
                    550: void
                    551: set_momentary_breakpoint (sal, frame)
                    552:      struct symtab_and_line sal;
                    553:      FRAME frame;
                    554: {
                    555:   register struct breakpoint *b;
                    556:   b = set_raw_breakpoint (sal);
                    557:   b->number = -3;
                    558:   b->enable = delete;
                    559:   b->frame = frame;
                    560: }
                    561: 
                    562: void
                    563: clear_momentary_breakpoints ()
                    564: {
                    565:   register struct breakpoint *b;
                    566:   ALL_BREAKPOINTS (b)
                    567:     if (b->number == -3)
                    568:       {
                    569:        delete_breakpoint (b);
                    570:        break;
                    571:       }
                    572: }
                    573: 
1.1.1.2   root      574: /* Set a breakpoint from a symtab and line.
                    575:    If TEMPFLAG is nonzero, it is a temporary breakpoint.
                    576:    Print the same confirmation messages that the breakpoint command prints.  */
                    577: 
                    578: void
                    579: set_breakpoint (s, line, tempflag)
                    580:      struct symtab *s;
                    581:      int line;
                    582:      int tempflag;
                    583: {
                    584:   register struct breakpoint *b;
                    585:   struct symtab_and_line sal;
                    586:   
                    587:   sal.symtab = s;
                    588:   sal.line = line;
                    589:   sal.pc = find_line_pc (sal.symtab, sal.line);
                    590:   if (sal.pc == 0)
                    591:     error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename);
                    592:   else
                    593:     {
                    594:       describe_other_breakpoints (sal.pc);
                    595: 
                    596:       b = set_raw_breakpoint (sal);
                    597:       b->number = ++breakpoint_count;
                    598:       b->cond = 0;
                    599:       if (tempflag)
                    600:        b->enable = temporary;
                    601: 
                    602:       printf ("Breakpoint %d at 0x%x", b->number, b->address);
                    603:       if (b->symtab)
                    604:        printf (": file %s, line %d.", b->symtab->filename, b->line_number);
                    605:       printf ("\n");
                    606:     }
                    607: }
                    608: 
1.1       root      609: /* Set a breakpoint according to ARG (function, linenum or *address)
1.1.1.3 ! root      610:    and make it temporary if TEMPFLAG is nonzero.
        !           611: 
        !           612:    LINE_NUM is for C++.  */
1.1       root      613: 
                    614: static void
1.1.1.3 ! root      615: break_command_1 (arg, tempflag, from_tty, line_num)
1.1       root      616:      char *arg;
1.1.1.3 ! root      617:      int tempflag, from_tty, line_num;
1.1       root      618: {
1.1.1.3 ! root      619:   struct symtabs_and_lines sals;
1.1       root      620:   struct symtab_and_line sal;
                    621:   register struct expression *cond = 0;
                    622:   register struct breakpoint *b;
1.1.1.3 ! root      623:   char *save_arg;
        !           624:   int i;
        !           625: 
        !           626:   sals.sals = NULL;
        !           627:   sals.nelts = 0;
1.1       root      628: 
1.1.1.3 ! root      629:   sal.line = sal.pc = sal.end = 0;
        !           630:   sal.symtab = 0;
1.1       root      631: 
                    632:   if (arg)
                    633:     {
1.1.1.3 ! root      634:       CORE_ADDR pc;
        !           635:       sals = decode_line_1 (&arg, 1, 0, 0);
1.1       root      636: 
1.1.1.3 ! root      637:       if (! sals.nelts) return;
        !           638:       save_arg = arg;
        !           639:       for (i = 0; i < sals.nelts; i++)
1.1       root      640:        {
1.1.1.3 ! root      641:          sal = sals.sals[i];
        !           642:          if (sal.pc == 0 && sal.symtab != 0)
        !           643:            {
        !           644:              pc = find_line_pc (sal.symtab, sal.line);
        !           645:              if (pc == 0)
        !           646:                error ("No line %d in file \"%s\".",
        !           647:                       sal.line, sal.symtab->filename);
        !           648:            }
        !           649:          else pc = sal.pc;
1.1       root      650: 
1.1.1.3 ! root      651:          while (*arg)
        !           652:            {
        !           653:              if (arg[0] == 'i' && arg[1] == 'f'
        !           654:                  && (arg[2] == ' ' || arg[2] == '\t'))
        !           655:                cond = (struct expression *) parse_c_1 ((arg += 2, &arg),
        !           656:                                                        block_for_pc (pc), 0);
        !           657:              else
        !           658:                error ("Junk at end of arguments.");
        !           659:            }
        !           660:          arg = save_arg;
        !           661:          sals.sals[i].pc = pc;
1.1       root      662:        }
                    663:     }
                    664:   else if (default_breakpoint_valid)
                    665:     {
1.1.1.3 ! root      666:       sals.sals = (struct symtab_and_line *) malloc (sizeof (struct symtab_and_line));
1.1       root      667:       sal.pc = default_breakpoint_address;
                    668:       sal.line = default_breakpoint_line;
                    669:       sal.symtab = default_breakpoint_symtab;
1.1.1.3 ! root      670:       sals.sals[0] = sal;
        !           671:       sals.nelts = 1;
1.1       root      672:     }
                    673:   else
                    674:     error ("No default breakpoint address now.");
                    675: 
1.1.1.3 ! root      676:   for (i = 0; i < sals.nelts; i++)
        !           677:     {
        !           678:       sal = sals.sals[i];
        !           679:       sal.line += line_num;  /** C++  **/
        !           680:       if (line_num != 0)
        !           681:        {                       /* get the pc for a particular line  */
        !           682:          sal.pc = find_line_pc (sal.symtab, sal.line);
        !           683:        }
1.1.1.2   root      684: 
1.1.1.3 ! root      685:       if (from_tty)
        !           686:        describe_other_breakpoints (sal.pc);
        !           687: 
        !           688:       b = set_raw_breakpoint (sal);
        !           689:       b->number = ++breakpoint_count;
        !           690:       b->cond = cond;
        !           691:       if (tempflag)
        !           692:        b->enable = temporary;
        !           693: 
        !           694:       printf ("Breakpoint %d at 0x%x", b->number, b->address);
        !           695:       if (b->symtab)
        !           696:        printf (": file %s, line %d.", b->symtab->filename, b->line_number);
        !           697:       printf ("\n");
        !           698:     }
        !           699:   free (sals.sals);
1.1       root      700: }
                    701: 
                    702: static void
                    703: break_command (arg, from_tty)
                    704:      char *arg;
                    705:      int from_tty;
                    706: {
1.1.1.3 ! root      707:   break_command_1 (arg, 0, from_tty, 0);
1.1       root      708: }
                    709: 
                    710: static void
                    711: tbreak_command (arg, from_tty)
                    712:      char *arg;
                    713:      int from_tty;
                    714: {
1.1.1.3 ! root      715:   break_command_1 (arg, 1, from_tty, 0);
1.1       root      716: }
                    717: 
                    718: static void
                    719: clear_command (arg, from_tty)
                    720:      char *arg;
                    721:      int from_tty;
                    722: {
                    723:   register struct breakpoint *b, *b1;
1.1.1.3 ! root      724:   struct symtabs_and_lines sals;
1.1       root      725:   struct symtab_and_line sal;
                    726:   register struct breakpoint *found;
1.1.1.3 ! root      727:   int i;
1.1       root      728: 
                    729:   if (arg)
1.1.1.3 ! root      730:     {
        !           731:       sals = decode_line_spec (arg, 1);
        !           732:     }
1.1       root      733:   else
                    734:     {
1.1.1.3 ! root      735:       sals.sals = (struct symtab_and_line *) malloc (sizeof (struct symtab_and_line));
1.1       root      736:       sal.line = default_breakpoint_line;
                    737:       sal.symtab = default_breakpoint_symtab;
                    738:       sal.pc = 0;
                    739:       if (sal.symtab == 0)
                    740:        error ("No source file specified.");
                    741: 
1.1.1.3 ! root      742:       sals.sals[0] = sal;
        !           743:       sals.nelts = 1;
1.1       root      744:     }
                    745: 
1.1.1.3 ! root      746:   for (i = 0; i < sals.nelts; i++)
        !           747:     {
        !           748:       /* If exact pc given, clear bpts at that pc.
        !           749:         But if sal.pc is zero, clear all bpts on specified line.  */
        !           750:       sal = sals.sals[i];
        !           751:       found = (struct breakpoint *) 0;
        !           752:       while (breakpoint_chain
        !           753:             && (sal.pc ? breakpoint_chain->address == sal.pc
        !           754:                 : (breakpoint_chain->symtab == sal.symtab
        !           755:                    && breakpoint_chain->line_number == sal.line)))
        !           756:        {
        !           757:          b1 = breakpoint_chain;
        !           758:          breakpoint_chain = b1->next;
        !           759:          b1->next = found;
        !           760:          found = b1;
        !           761:        }
        !           762: 
        !           763:       ALL_BREAKPOINTS (b)
        !           764:        while (b->next
        !           765:               && (sal.pc ? b->next->address == sal.pc
        !           766:                   : (b->next->symtab == sal.symtab
        !           767:                      && b->next->line_number == sal.line)))
        !           768:          {
        !           769:            b1 = b->next;
        !           770:            b->next = b1->next;
        !           771:            b1->next = found;
        !           772:            found = b1;
        !           773:          }
1.1       root      774: 
1.1.1.3 ! root      775:       if (found == 0)
        !           776:        error ("No breakpoint at %s.", arg);
1.1       root      777: 
1.1.1.3 ! root      778:       if (found->next) from_tty = 1; /* Always report if deleted more than one */
        !           779:       if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
        !           780:       while (found)
        !           781:        {
        !           782:          if (from_tty) printf ("%d ", found->number);
        !           783:          b1 = found->next;
        !           784:          delete_breakpoint (found);
        !           785:          found = b1;
        !           786:        }
        !           787:       if (from_tty) putchar ('\n');
1.1       root      788:     }
1.1.1.3 ! root      789:   free (sals.sals);
1.1       root      790: }
                    791: 
                    792: /* Delete breakpoint number BNUM if it is a `delete' breakpoint.
                    793:    This is called after breakpoint BNUM has been hit.
                    794:    Also delete any breakpoint numbered -3 unless there are breakpoint
                    795:    commands to be executed.  */
                    796: 
                    797: void
                    798: breakpoint_auto_delete (bnum)
                    799:      int bnum;
                    800: {
                    801:   register struct breakpoint *b;
                    802:   if (bnum != 0)
                    803:     ALL_BREAKPOINTS (b)
                    804:       if (b->number == bnum)
                    805:        {
                    806:          if (b->enable == delete)
                    807:            delete_breakpoint (b);
                    808:          break;
                    809:        }
                    810:   if (breakpoint_commands == 0)
                    811:     clear_momentary_breakpoints ();
                    812: }
                    813: 
                    814: static void
                    815: delete_breakpoint (bpt)
                    816:      struct breakpoint *bpt;
                    817: {
                    818:   register struct breakpoint *b;
                    819: 
                    820:   if (bpt->inserted)
                    821:     write_memory (bpt->address, bpt->shadow_contents, sizeof break_insn);
                    822: 
                    823:   if (breakpoint_chain == bpt)
                    824:     breakpoint_chain = bpt->next;
                    825: 
                    826:   ALL_BREAKPOINTS (b)
                    827:     if (b->next == bpt)
                    828:       {
                    829:        b->next = bpt->next;
                    830:        break;
                    831:       }
                    832: 
                    833:   check_duplicates (bpt->address);
                    834: 
                    835:   free_command_lines (&bpt->commands);
                    836:   if (bpt->cond)
                    837:     free (bpt->cond);
                    838:   free (bpt);
                    839: }
                    840: 
                    841: void map_breakpoint_numbers ();
                    842: 
                    843: static void
                    844: delete_command (arg, from_tty)
                    845:      char *arg;
                    846:      int from_tty;
                    847: {
                    848:   register struct breakpoint *b, *b1;
                    849: 
                    850:   if (arg == 0)
                    851:     {
                    852:       if (!from_tty || query ("Delete all breakpoints? "))
                    853:        {
                    854:          /* No arg; clear all breakpoints.  */
                    855:          while (breakpoint_chain)
                    856:            delete_breakpoint (breakpoint_chain);
                    857:        }
                    858:     }
                    859:   else
                    860:     map_breakpoint_numbers (arg, delete_breakpoint);
                    861: }
                    862: 
                    863: /* Delete all breakpoints.
                    864:    Done when new symtabs are loaded, since the break condition expressions
                    865:    may become invalid, and the breakpoints are probably wrong anyway.  */
                    866: 
                    867: void
                    868: clear_breakpoints ()
                    869: {
                    870:   delete_command (0, 0);
                    871: }
                    872: 
                    873: /* Set ignore-count of breakpoint number BPTNUM to COUNT.
                    874:    If from_tty is nonzero, it prints a message to that effect,
                    875:    which ends with a period (no newline).  */
                    876: 
                    877: void
                    878: set_ignore_count (bptnum, count, from_tty)
                    879:      int bptnum, count, from_tty;
                    880: {
                    881:   register struct breakpoint *b;
                    882: 
                    883:   if (count < 0)
                    884:     count = 0;
                    885: 
                    886:   ALL_BREAKPOINTS (b)
                    887:     if (b->number == bptnum)
                    888:       {
                    889:        b->ignore_count = count;
                    890:        if (!from_tty)
                    891:          return;
                    892:        else if (count == 0)
                    893:          printf ("Will stop next time breakpoint %d is reached.", bptnum);
                    894:        else if (count == 1)
                    895:          printf ("Will ignore next crossing of breakpoint %d.", bptnum);
                    896:        else
                    897:          printf ("Will ignore next %d crossings of breakpoint %d.",
                    898:                  count, bptnum);
                    899:        return;
                    900:       }
                    901: 
                    902:   error ("No breakpoint number %d.", bptnum);
                    903: }
                    904: 
                    905: /* Command to set ignore-count of breakpoint N to COUNT.  */
                    906: 
                    907: static void
                    908: ignore_command (args, from_tty)
                    909:      char *args;
                    910:      int from_tty;
                    911: {
                    912:   register char *p;
                    913:   register int num;
1.1.1.2   root      914: 
                    915:   if (p == 0)
                    916:     error_no_arg ("a breakpoint number");
1.1       root      917:   
                    918:   p = args;
                    919:   while (*p >= '0' && *p <= '9') p++;
                    920:   if (*p && *p != ' ' && *p != '\t')
                    921:     error ("First argument must be a breakpoint number.");
                    922: 
                    923:   num = atoi (args);
                    924: 
                    925:   if (*p == 0)
                    926:     error ("Second argument (specified ignore-count) is missing.");
                    927: 
                    928:   set_ignore_count (num, parse_and_eval_address (p), from_tty);
                    929:   printf ("\n");
                    930: }
                    931: 
                    932: /* Call FUNCTION on each of the breakpoints
                    933:    whose numbers are given in ARGS.  */
                    934: 
                    935: static void
                    936: map_breakpoint_numbers (args, function)
                    937:      char *args;
                    938:      void (*function) ();
                    939: {
                    940:   register char *p = args;
                    941:   register char *p1;
                    942:   register int num;
                    943:   register struct breakpoint *b;
                    944: 
                    945:   if (p == 0)
                    946:     error_no_arg ("one or more breakpoint numbers");
                    947: 
                    948:   while (*p)
                    949:     {
                    950:       p1 = p;
                    951:       while (*p1 >= '0' && *p1 <= '9') p1++;
                    952:       if (*p1 && *p1 != ' ' && *p1 != '\t')
                    953:        error ("Arguments must be breakpoint numbers.");
                    954: 
                    955:       num = atoi (p);
                    956: 
                    957:       ALL_BREAKPOINTS (b)
                    958:        if (b->number == num)
                    959:          {
                    960:            function (b);
                    961:            goto win;
                    962:          }
                    963:       printf ("No breakpoint number %d.\n", num);
                    964:     win:
                    965:       p = p1;
                    966:       while (*p == ' ' || *p == '\t') p++;
                    967:     }
                    968: }
                    969: 
                    970: static void
                    971: enable_breakpoint (bpt)
                    972:      struct breakpoint *bpt;
                    973: {
                    974:   bpt->enable = enabled;
                    975: 
                    976:   check_duplicates (bpt->address);
                    977: }
                    978: 
                    979: static void
                    980: enable_command (args)
                    981:      char *args;
                    982: {
                    983:   map_breakpoint_numbers (args, enable_breakpoint);
                    984: }
                    985: 
                    986: static void
                    987: disable_breakpoint (bpt)
                    988:      struct breakpoint *bpt;
                    989: {
                    990:   bpt->enable = disabled;
                    991: 
                    992:   check_duplicates (bpt->address);
                    993: }
                    994: 
                    995: static void
                    996: disable_command (args)
                    997:      char *args;
                    998: {
                    999:   register struct breakpoint *bpt;
                   1000:   if (args == 0)
                   1001:     ALL_BREAKPOINTS (bpt)
                   1002:       disable_breakpoint (bpt);
                   1003:   else
                   1004:     map_breakpoint_numbers (args, disable_breakpoint);
                   1005: }
                   1006: 
                   1007: static void
                   1008: enable_once_breakpoint (bpt)
                   1009:      struct breakpoint *bpt;
                   1010: {
                   1011:   bpt->enable = temporary;
                   1012: 
                   1013:   check_duplicates (bpt->address);
                   1014: }
                   1015: 
                   1016: static void
                   1017: enable_once_command (args)
                   1018:      char *args;
                   1019: {
                   1020:   map_breakpoint_numbers (args, enable_once_breakpoint);
                   1021: }
                   1022: 
                   1023: static void
                   1024: enable_delete_breakpoint (bpt)
                   1025:      struct breakpoint *bpt;
                   1026: {
                   1027:   bpt->enable = delete;
                   1028: 
                   1029:   check_duplicates (bpt->address);
                   1030: }
                   1031: 
                   1032: static void
                   1033: enable_delete_command (args)
                   1034:      char *args;
                   1035: {
                   1036:   map_breakpoint_numbers (args, enable_delete_breakpoint);
                   1037: }
                   1038: 
                   1039: 
                   1040: /* Chain containing all defined enable commands.  */
                   1041: 
                   1042: struct cmd_list_element *enablelist;
                   1043: 
                   1044: extern struct cmd_list_element *cmdlist;
                   1045: 
                   1046: static
                   1047: initialize ()
                   1048: {
                   1049:   breakpoint_chain = 0;
                   1050:   breakpoint_count = 0;
                   1051:   enablelist = 0;
                   1052: 
                   1053:   add_com ("ignore", class_breakpoint, ignore_command,
                   1054:           "Set ignore-count of breakpoint number N to COUNT.");
                   1055: 
                   1056:   add_com ("commands", class_breakpoint, commands_command,
                   1057:           "Set commands to be executed when a breakpoint is hit.\n\
                   1058: Give breakpoint number as argument after \"commands\".\n\
                   1059: The commands themselves follow starting on the next line.\n\
                   1060: Type a line containing \"end\" to indicate the end of them.\n\
                   1061: Give \"silent\" as the first line to make the breakpoint silent;\n\
                   1062: then no output is printed when it is hit, except what the commands print.");
                   1063: 
                   1064:   add_com ("condition", class_breakpoint, condition_command,
                   1065:           "Specify breakpoint number N to break only if COND is true.\n\
                   1066: N is an integer; COND is a C expression to be evaluated whenever\n\
                   1067: breakpoint N is reached.  Actually break only when COND is nonzero.");
                   1068: 
                   1069:   add_com ("tbreak", class_breakpoint, tbreak_command,
                   1070:           "Set a temporary breakpoint.  Args like \"break\" command.\n\
                   1071: Like \"break\" except the breakpoint is only enabled temporarily,\n\
                   1072: so it will be disabled when hit.  Equivalent to \"break\" followed\n\
                   1073: by using \"enable once\" on the breakpoint number.");
                   1074: 
                   1075:   add_prefix_cmd ("enable", class_breakpoint, enable_command,
                   1076:                  "Enable some breakpoints.  Give breakpoint numbers as arguments.\n\
                   1077: With no subcommand, breakpoints are enabled until you command otherwise.\n\
                   1078: This is used to cancel the effect of the \"disable\" command.\n\
                   1079: With a subcommand you can enable temporarily.",
                   1080:                  &enablelist, "enable ", 1, &cmdlist);
                   1081: 
                   1082:   add_cmd ("delete", 0, enable_delete_command,
                   1083:           "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
                   1084: If a breakpoint is hit while enabled in this fashion, it is deleted.",
                   1085:           &enablelist);
                   1086: 
                   1087:   add_cmd ("once", 0, enable_once_command,
                   1088:           "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
                   1089: If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
                   1090: See the \"tbreak\" command which sets a breakpoint and enables it once.",
                   1091:           &enablelist);
                   1092: 
                   1093:   add_com ("disable", class_breakpoint, disable_command,
                   1094:           "Disable some breakpoints.  Give breakpoint numbers as arguments.\n\
                   1095: With no arguments, disable all breakpoints.\n\
                   1096: A disabled breakpoint is not forgotten,\n\
                   1097: but it has no effect until enabled again.");
                   1098:   add_com_alias ("dis", "disable", class_breakpoint, 1);
                   1099: 
                   1100:   add_com ("delete", class_breakpoint, delete_command,
                   1101:           "Delete breakpoints, specifying breakpoint numbers; or all breakpoints.\n\
                   1102: Arguments are breakpoint numbers with spaces in between.\n\
                   1103: To delete all breakpoints, give no argument.");
                   1104:   add_com_alias ("d", "delete", class_breakpoint, 1);
                   1105: 
                   1106:   add_com ("clear", class_breakpoint, clear_command,
                   1107:           "Clear breakpoint at specified line or function.\n\
                   1108: Argument may be line number, function name, or \"*\" and an address.\n\
                   1109: If line number is specified, all breakpoints in that line are cleared.\n\
                   1110: If function is specified, breakpoints at beginning of function are cleared.\n\
                   1111: If an address is specified, breakpoints at that address are cleared.\n\n\
                   1112: With no argument, clears all breakpoints in the line that the selected frame\n\
                   1113: is executing in.\n\
                   1114: \n\
                   1115: See also the \"delete\" command which clears breakpoints by number.");
                   1116: 
                   1117:   add_com ("break", class_breakpoint, break_command,
                   1118:           "Set breakpoint at specified line or function.\n\
                   1119: Argument may be line number, function name, or \"*\" and an address.\n\
                   1120: If line number is specified, break at start of code for that line.\n\
                   1121: If function is specified, break at start of code for that function.\n\
                   1122: If an address is specified, break at that exact address.\n\
                   1123: With no arg, uses current execution address of selected stack frame.\n\
                   1124: This is useful for breaking on return to a stack frame.\n\
                   1125: \n\
                   1126: Multiple breakpoints at one place are permitted, and useful if conditional.\n\
                   1127: \n\
                   1128: Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
                   1129:   add_com_alias ("b", "break", class_run, 1);
                   1130:   add_com_alias ("br", "break", class_run, 1);
                   1131:   add_com_alias ("bre", "break", class_run, 1);
                   1132:   add_com_alias ("brea", "break", class_run, 1);
                   1133: 
                   1134:   add_info ("breakpoints", breakpoints_info,
                   1135:            "Status of all breakpoints, or breakpoint number NUMBER.\n\
1.1.1.2   root     1136: Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
1.1       root     1137: \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
                   1138: Then come the address and the file/line number.\n\n\
                   1139: Convenience variable \"$_\" and default examine address for \"x\"\n\
                   1140: are set to the address of the last breakpoint listed.");
                   1141: }
                   1142: 
                   1143: END_FILE

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.